void DownlinkPacketScheduler::UpdateAverageTransmissionRate (void) { RrcEntity *rrc = GetMacEntity ()->GetDevice ()->GetProtocolStack ()->GetRrcEntity (); RrcEntity::RadioBearersContainer* bearers = rrc->GetRadioBearerContainer (); for (std::vector<RadioBearer* >::iterator it = bearers->begin (); it != bearers->end (); it++) { RadioBearer *bearer = (*it); bearer->UpdateAverageTransmissionRate (); } }
void AmRlcEntity::SendArqRlcIdealControlMessage (ArqRlcIdealControlMessage msg) { #ifdef RLC_DEBUG std::cout << "AM RLC -- SendArqRlcIdealControlMessage, node " << GetRadioBearerInstance ()->GetDestination ()->GetIDNetworkNode () << " bearer "<< GetRlcEntityIndex () << std::endl; std::cout << "\t ack " << msg.GetAck() << ", startB " << msg.GetStartByte () << ", endB " << msg.GetEndByte () << std::endl; #endif //send AM RLC ACK to the receiver RLC under ideal control channel RadioBearerSink* thisBearer = (RadioBearerSink*) GetRadioBearerInstance (); ApplicationSink *thisApplication = (ApplicationSink*) thisBearer->GetApplication (); RadioBearer* remoteBearer = thisApplication->GetSourceApplication ()->GetRadioBearer (); AmRlcEntity* remoteRlc = (AmRlcEntity*) remoteBearer->GetRlcEntity(); remoteRlc->ReceiveArqRlcIdealControlMessage (msg); }
void DownlinkPacketScheduler::SelectFlowsToSchedule () { #ifdef SCHEDULER_DEBUG std::cout << "\t Select Flows to schedule" << std::endl; #endif ClearFlowsToSchedule (); RrcEntity *rrc = GetMacEntity ()->GetDevice ()->GetProtocolStack ()->GetRrcEntity (); RrcEntity::RadioBearersContainer* bearers = rrc->GetRadioBearerContainer (); for (std::vector<RadioBearer* >::iterator it = bearers->begin (); it != bearers->end (); it++) { //SELECT FLOWS TO SCHEDULE RadioBearer *bearer = (*it); if (bearer->HasPackets () && bearer->GetDestination ()->GetNodeState () == NetworkNode::STATE_ACTIVE) { //compute data to transmit int dataToTransmit; if (bearer->GetApplication ()->GetApplicationType () == Application::APPLICATION_TYPE_INFINITE_BUFFER) { dataToTransmit = 100000000; } else { dataToTransmit = bearer->GetQueueSize (); } //compute spectral efficiency ENodeB *enb = (ENodeB*) GetMacEntity ()->GetDevice (); ENodeB::UserEquipmentRecord *ueRecord = enb->GetUserEquipmentRecord (bearer->GetDestination ()->GetIDNetworkNode ()); std::vector<double> spectralEfficiency; std::vector<int> cqiFeedbacks = ueRecord->GetCQI (); int numberOfCqi = cqiFeedbacks.size (); for (int i = 0; i < numberOfCqi; i++) { double sEff = GetMacEntity ()->GetAmcModule ()->GetEfficiencyFromCQI (cqiFeedbacks.at (i)); spectralEfficiency.push_back (sEff); } //create flow to scheduler record InsertFlowToSchedule(bearer, dataToTransmit, spectralEfficiency, cqiFeedbacks); } else {} } }
PacketBurst* AmRlcEntity::TransmissionProcedure (int availableBytes) { #ifdef RLC_DEBUG std::cout << "AM RLC tx procedure for node " << GetRadioBearerInstance ()->GetSource ()->GetIDNetworkNode ()<< " bearer "<< GetRlcEntityIndex () << std::endl; #endif PacketBurst* pb = new PacketBurst (); AmStateVariables* amRlcState = GetAmStateVariables (); //STEP 1 CHECK FOR RE-TRANSMISSION #ifdef RLC_DEBUG std::cout << "--> STEP 1: CHECK FOR RE-TRANSMISSION" << std::endl; PrintSentAMDs (); #endif int nbSentAMDs = GetSentAMDs()->size(); if (nbSentAMDs != 0) { int amdId = 0; while (availableBytes > 0 && amdId < nbSentAMDs) { AmdRecord* amdRecord = GetSentAMDs()->at (amdId); if (amdRecord->m_packet->GetSize () + 6 <= availableBytes) //6 = MAC + CRC overhead { amdRecord->m_retx_count++; #ifdef RLC_DEBUG std::cout << "send the whole unacknowledged AMD PDU" << std::endl; #endif Packet* p = amdRecord->m_packet->Copy (); MACHeader *mac = new MACHeader (GetRadioBearerInstance ()->GetSource ()->GetIDNetworkNode (), GetRadioBearerInstance ()->GetDestination ()->GetIDNetworkNode ()); p->AddMACHeader(mac); p->AddHeaderSize (3); if (_RLC_TRACING_) { std::cout << "TX AM_RLC SIZE" << p->GetSize () << " B " << GetRlcEntityIndex () << " PDU_SN " << p->GetRLCHeader ()->GetRlcPduSequenceNumber() << std::endl; } pb->AddPacket (p); availableBytes -= p->GetSize (); amdId++; } else if (availableBytes > 8) // 8 = RLC + MAC + CRC { amdRecord->m_retx_count++; #ifdef RLC_DEBUG std::cout << "there is not enough bandwidth for this AMD PDU. Do another fragmentation" << "--> bytes: " << availableBytes << std::endl; #endif Packet* p1 = amdRecord->m_packet->Copy (); Packet* p2 = amdRecord->m_packet; int sentBytes = availableBytes - 7; p1->GetRLCHeader ()->SetEndByte (p1->GetRLCHeader ()->GetStartByte () + sentBytes - 1); p1->SetSize (2 + sentBytes); //consider both RLC and sent bytes p2->GetRLCHeader ()->SetStartByte (p1->GetRLCHeader ()->GetStartByte () + sentBytes); p2->SetSize (p2->GetSize () - sentBytes); //decrease the packet size by the quota of sent bytes p1->GetRLCHeader ()->SetTheLatestFragment (false); p1->GetRLCHeader ()->SetAFragment (true); p2->GetRLCHeader ()->SetAFragment (true); MACHeader *mac = new MACHeader (GetRadioBearerInstance ()->GetSource ()->GetIDNetworkNode (), GetRadioBearerInstance ()->GetDestination ()->GetIDNetworkNode ()); p1->AddMACHeader(mac); p1->AddHeaderSize (3); //CRC if (_RLC_TRACING_) { std::cout << "TX AM_RLC SIZE" << p1->GetSize () << " B " << GetRlcEntityIndex () << " PDU_SN " << p1->GetRLCHeader ()->GetRlcPduSequenceNumber() << std::endl; } pb->AddPacket (p1->Copy ()); AmdRecord* newAmdRecord = new AmdRecord (p1, p1->GetRLCHeader ()->GetRlcPduSequenceNumber ()); newAmdRecord->m_retx_count = amdRecord->m_retx_count; GetSentAMDs ()->insert(GetSentAMDs ()->begin() + amdId, newAmdRecord); #ifdef RLC_DEBUG PrintSentAMDs (); #endif availableBytes = 0; } else { availableBytes = 0; } } } if (availableBytes <= 0 ) return pb; //STEP 2 NEW TRANSMISSION #ifdef RLC_DEBUG std::cout << "--> STEP 2: CHECK FOR NEW TRANSMISSION" << std::endl; #endif RadioBearer *bearer = (RadioBearer*) GetRadioBearerInstance (); MacQueue *queue = bearer->GetMacQueue (); if (bearer->GetApplication ()->GetApplicationType () == Application::APPLICATION_TYPE_INFINITE_BUFFER) { //CREATE PACKET FOR THE INFINITE BUFFER SOURCE while (true) { Packet *packet = bearer->CreatePacket (availableBytes); packet->GetRLCHeader ()->SetRlcEntityIndex (GetRlcEntityIndex ()); // set sn int currentSN = amRlcState->m_vt_s; packet->GetRLCHeader ()->SetRlcPduSequenceNumber (currentSN); //update am rlc state variables amRlcState->m_vt_s++; //Add MAC header MACHeader *mac = new MACHeader (GetRadioBearerInstance ()->GetSource ()->GetIDNetworkNode (), GetRadioBearerInstance ()->GetDestination ()->GetIDNetworkNode ()); packet->AddMACHeader(mac); packet->AddHeaderSize (3); if (availableBytes > 1503) { packet->SetSize (1503); packet->GetPacketTags ()->SetApplicationSize (1490); availableBytes -= 1503; if (_RLC_TRACING_) { std::cout << "TX AM_RLC SIZE " << packet->GetSize () << " B " << GetRlcEntityIndex () << " PDU_SN " << packet->GetRLCHeader ()->GetRlcPduSequenceNumber() << " Frag " << packet->GetRLCHeader ()->IsAFragment () << " LastFrag " << packet->GetRLCHeader ()->IsTheLatestFragment() << " startB " << packet->GetRLCHeader ()->GetStartByte () << " endB " << packet->GetRLCHeader ()->GetEndByte () << std::endl; } pb->AddPacket (packet); } else if (availableBytes > 13) { packet->SetSize (availableBytes); packet->GetPacketTags ()->SetApplicationSize (availableBytes - 13); availableBytes = 0; if (_RLC_TRACING_) { std::cout << "TX 2 AM_RLC SIZE " << packet->GetSize () << " B " << GetRlcEntityIndex () << " PDU_SN " << packet->GetRLCHeader ()->GetRlcPduSequenceNumber() << " Frag " << packet->GetRLCHeader ()->IsAFragment () << " LastFrag " << packet->GetRLCHeader ()->IsTheLatestFragment() << " startB " << packet->GetRLCHeader ()->GetStartByte () << " endB " << packet->GetRLCHeader ()->GetEndByte () << std::endl; } pb->AddPacket (packet); break; } else { availableBytes = 0; break; } } } else { while (availableBytes > 0 && !queue->IsEmpty ()) { Packet* packet = queue->GetPacketToTramsit (availableBytes); if (packet != NULL) { #ifdef RLC_DEBUG std::cout << "SEND PACKET id " << packet->GetID() << " frag n " << packet->GetRLCHeader ()->GetFragmentNumber ()<< std::endl; #endif //Set the id of the receiver RLC entity packet->GetRLCHeader ()->SetRlcEntityIndex (GetRlcEntityIndex ()); //amRlcState->PrintTxVariables (); // set sn int currentSN = amRlcState->m_vt_s; packet->GetRLCHeader ()->SetRlcPduSequenceNumber (currentSN); //update am rlc state variables amRlcState->m_vt_s++; //amRlcState->PrintTxVariables (); #ifdef RLC_DEBUG std::cout << "_____ pkt " << packet->GetID() << " frag " << packet->GetRLCHeader ()->GetFragmentNumber () << " sn " << packet->GetRLCHeader ()->GetRlcPduSequenceNumber () << " startB " << packet->GetRLCHeader ()->GetStartByte () << " endB " << packet->GetRLCHeader ()->GetEndByte () << std::endl; PrintSentAMDs (); #endif AmdRecord *amdRecord = new AmdRecord (packet->Copy (), currentSN); GetSentAMDs ()->push_back (amdRecord); #ifdef RLC_DEBUG PrintSentAMDs (); #endif //Add MAC header MACHeader *mac = new MACHeader (GetRadioBearerInstance ()->GetSource ()->GetIDNetworkNode (), GetRadioBearerInstance ()->GetDestination ()->GetIDNetworkNode ()); packet->AddMACHeader(mac); packet->AddHeaderSize (3); if (_RLC_TRACING_) { std::cout << "TX AM_RLC SIZE " << packet->GetSize () << " B " << GetRlcEntityIndex () << " PDU_SN " << packet->GetRLCHeader ()->GetRlcPduSequenceNumber() << std::endl; } pb->AddPacket (packet); availableBytes -= packet->GetSize (); } else { availableBytes = 0; } } } return pb; }
PacketBurst* UmRlcEntity::TransmissionProcedure (int availableBytes) { #ifdef RLC_DEBUG std::cout << "UM RLC tx procedure for node " << GetRadioBearerInstance ()->GetSource ()->GetIDNetworkNode ()<< std::endl; #endif PacketBurst* pb = new PacketBurst (); RadioBearer *bearer = (RadioBearer*) GetRadioBearerInstance (); MacQueue *queue = bearer->GetMacQueue (); if (bearer->GetApplication ()->GetApplicationType () == Application::APPLICATION_TYPE_INFINITE_BUFFER) { //CREATE PACKET FOR THE INFINITE BUFFER SOURCE while (true) { Packet *packet = bearer->CreatePacket (availableBytes); //Set the id of the receiver RLC entity packet->GetRLCHeader ()->SetRlcEntityIndex (GetRlcEntityIndex ()); packet->GetRLCHeader ()->SetRlcPduSequenceNumber (GetRlcPduSequenceNumber ()); int newSequenceNumber = GetRlcPduSequenceNumber () + 1; SetRlcPduSequenceNumber (newSequenceNumber); //Add MAC header MACHeader *mac = new MACHeader (GetRadioBearerInstance ()->GetSource ()->GetIDNetworkNode (), GetRadioBearerInstance ()->GetDestination ()->GetIDNetworkNode ()); packet->AddMACHeader(mac); packet->AddHeaderSize (3); //CRC if (availableBytes > 1503) { packet->SetSize (1503); packet->GetPacketTags ()->SetApplicationSize (1490); //Set the id of the receiver RLC entity packet->GetRLCHeader ()->SetRlcEntityIndex (GetRlcEntityIndex ()); packet->GetRLCHeader ()->SetRlcPduSequenceNumber (GetRlcPduSequenceNumber ()); int newSequenceNumber = GetRlcPduSequenceNumber () + 1; SetRlcPduSequenceNumber (newSequenceNumber); availableBytes -= 1503; pb->AddPacket (packet); if (_RLC_TRACING_) { std::cout << "TX UM_RLC SIZE" << packet->GetSize () << " B " << GetRlcEntityIndex () << " PDU_SN " << packet->GetRLCHeader ()->GetRlcPduSequenceNumber() << std::endl; } } else if (availableBytes > 13) { packet->SetSize (availableBytes); packet->GetPacketTags ()->SetApplicationSize (availableBytes - 13); //Set the id of the receiver RLC entity packet->GetRLCHeader ()->SetRlcEntityIndex (GetRlcEntityIndex ()); packet->GetRLCHeader ()->SetRlcPduSequenceNumber (GetRlcPduSequenceNumber ()); int newSequenceNumber = GetRlcPduSequenceNumber () + 1; SetRlcPduSequenceNumber (newSequenceNumber); availableBytes = 0; pb->AddPacket (packet); if (_RLC_TRACING_) { std::cout << "TX UM_RLC SIZE" << packet->GetSize () << " B " << GetRlcEntityIndex () << " PDU_SN " << packet->GetRLCHeader ()->GetRlcPduSequenceNumber() << std::endl; } break; } else { availableBytes = 0; break; } } } else { while (availableBytes > 0 && !queue->IsEmpty ()) { Packet* packet = queue->GetPacketToTramsit (availableBytes); if (packet != NULL) { //Set the id of the receiver RLC entity packet->GetRLCHeader ()->SetRlcEntityIndex (GetRlcEntityIndex ()); packet->GetRLCHeader ()->SetRlcPduSequenceNumber (GetRlcPduSequenceNumber ()); int newSequenceNumber = GetRlcPduSequenceNumber () + 1; SetRlcPduSequenceNumber (newSequenceNumber); if (_RLC_TRACING_) { std::cout << "TX UM_RLC SIZE" << packet->GetSize () << " B " << GetRlcEntityIndex () << " PDU_SN " << packet->GetRLCHeader ()->GetRlcPduSequenceNumber() << std::endl; } //Add MAC header MACHeader *mac = new MACHeader (GetRadioBearerInstance ()->GetSource ()->GetIDNetworkNode (), GetRadioBearerInstance ()->GetDestination ()->GetIDNetworkNode ()); packet->AddMACHeader(mac); packet->AddHeaderSize (3); //CRC pb->AddPacket (packet); availableBytes -= packet->GetSize (); } else { availableBytes = 0; } } } return pb; }
void NetworkManager::TransferBearerInfo (UserEquipment* ue, NetworkNode* target) { #ifdef HANDOVER_DEBUG std::cout << "** HO ** \t TransferBearerInfo for user " << ue->GetIDNetworkNode () << std::endl; #endif if ( (target->GetNodeType() == NetworkNode::TYPE_ENODEB && ue->GetTargetNode ()->GetNodeType() == NetworkNode::TYPE_ENODEB) || (target->GetNodeType() == NetworkNode::TYPE_HOME_BASE_STATION && ue->GetTargetNode ()->GetNodeType() == NetworkNode::TYPE_ENODEB) || (target->GetNodeType() == NetworkNode::TYPE_ENODEB && ue->GetTargetNode ()->GetNodeType() == NetworkNode::TYPE_HOME_BASE_STATION)) { ENodeB *oldTargetNode = (ENodeB*) ue->GetTargetNode (); ENodeB *newTargetNode = (ENodeB*) target; // 1 - update spectrum, channels and propagation loss model #ifdef HANDOVER_DEBUG std::cout << "update spectrum, channels and propagation loss model"<< std::endl; #endif ue->GetPhy ()->SetBandwidthManager (newTargetNode->GetPhy ()->GetBandwidthManager ()); LteChannel *oldDl = oldTargetNode->GetPhy ()->GetDlChannel (); LteChannel *oldUl = oldTargetNode->GetPhy ()->GetUlChannel (); LteChannel *newDl = newTargetNode->GetPhy ()->GetDlChannel (); LteChannel *newUl = newTargetNode->GetPhy ()->GetUlChannel (); ue->GetPhy ()->SetDlChannel (newDl); if (oldDl->IsAttached (ue)) { newDl->AddDevice (ue); oldDl->DelDevice (ue); } if (newDl->GetPropagationLossModel () != NULL) { newDl->GetPropagationLossModel ()-> AddChannelRealization (CreateChannelRealization (newTargetNode, ue)); oldDl->GetPropagationLossModel ()->DelChannelRealization (oldTargetNode,ue); } ue->GetPhy ()->SetUlChannel (newUl); if (oldUl->IsAttached (ue)) { newUl->AddDevice (ue); oldUl->DelDevice (ue); } if (newUl->GetPropagationLossModel () != NULL) { newUl->GetPropagationLossModel ()->AddChannelRealization ( CreateChannelRealization (ue, newTargetNode)); oldUl->GetPropagationLossModel ()->DelChannelRealization (ue,oldTargetNode);; } // 2 - add ue record to the new Enb #ifdef HANDOVER_DEBUG std::cout << "add ue record to the new Enb"<< std::endl; #endif newTargetNode->RegisterUserEquipment (ue); // 3 - delete ue record form the old enb #ifdef HANDOVER_DEBUG std::cout << "delete ue record form the old enb"<< std::endl; #endif oldTargetNode->DeleteUserEquipment (ue); // 4 - update cell and new target enb for the ue #ifdef HANDOVER_DEBUG std::cout << "update cell and new target enb for the ue"<< std::endl; #endif ue->SetTargetNode (newTargetNode); // MOVE RRC CONTEXT FOR THE OLD TARGET NODE TO THE NEWER ONE #ifdef HANDOVER_DEBUG std::cout << "MOVE RRC CONTEXT"<< std::endl; #endif RrcEntity * oldEnbRrc = oldTargetNode->GetProtocolStack ()->GetRrcEntity (); RrcEntity * newEnbRrc = newTargetNode->GetProtocolStack ()->GetRrcEntity (); RrcEntity * ueRrc = ue->GetProtocolStack ()->GetRrcEntity (); // --> move dl bearers #ifdef HANDOVER_DEBUG std::cout << "\t DL radio bearers " << oldEnbRrc->GetRadioBearerContainer ()->size () << std::endl; #endif std::vector<RadioBearer* > *dlBearerToDelete = new std::vector<RadioBearer* > (); for (std::vector<RadioBearer* >::iterator it = oldEnbRrc->GetRadioBearerContainer ()->begin(); it != oldEnbRrc->GetRadioBearerContainer ()->end (); it++) { RadioBearer *bearer = (*it); if (bearer->GetDestination ()->GetIDNetworkNode () == ue->GetIDNetworkNode ()) { bearer->SetSource (newTargetNode); bearer->GetRlcEntity ()->SetDevice (newTargetNode); newEnbRrc->AddRadioBearer (bearer); dlBearerToDelete->push_back (bearer); } } for (std::vector<RadioBearer* >::iterator it = dlBearerToDelete->begin(); it != dlBearerToDelete->end (); it++) { RadioBearer *bearer = (*it); oldEnbRrc->DelRadioBearer (bearer); } dlBearerToDelete->clear (); delete dlBearerToDelete; // --> move ul bearers #ifdef HANDOVER_DEBUG std::cout << "\t UL radio bearers"<< std::endl; #endif std::vector<RadioBearerSink* > *ulBearerToDelete = new std::vector<RadioBearerSink* > (); for (std::vector<RadioBearerSink* >::iterator it = oldEnbRrc->GetRadioBearerSinkContainer ()->begin(); it != oldEnbRrc->GetRadioBearerSinkContainer ()->end (); it++) { RadioBearerSink *bearer = (*it); if (bearer->GetSource ()->GetIDNetworkNode () == ue->GetIDNetworkNode ()) { bearer->SetDestination (newTargetNode); newEnbRrc->AddRadioBearerSink (bearer); ulBearerToDelete->push_back (bearer); } } for (std::vector<RadioBearerSink* >::iterator it = ulBearerToDelete->begin(); it != ulBearerToDelete->end (); it++) { RadioBearerSink *bearer = (*it); oldEnbRrc->DelRadioBearerSink (bearer); } ulBearerToDelete->clear (); delete ulBearerToDelete; // UPDATE THE RRC CONTEXT FOR THE UE #ifdef HANDOVER_DEBUG std::cout << "\t UE updates DL radio bearers "<< std::endl; #endif for (std::vector<RadioBearerSink* >::iterator it = ueRrc->GetRadioBearerSinkContainer ()->begin(); it != ueRrc->GetRadioBearerSinkContainer ()->end (); it++) { RadioBearerSink *bearer = (*it); bearer->SetSource (newTargetNode); } #ifdef HANDOVER_DEBUG std::cout << "\t UE updates UL radio bearers "<< std::endl; #endif for (std::vector<RadioBearer* >::iterator it = ueRrc->GetRadioBearerContainer ()->begin(); it != ueRrc->GetRadioBearerContainer ()->end (); it++) { RadioBearer *bearer = (*it); bearer->SetDestination (newTargetNode); } } }