Ptr<Packet> RedQueue::DoDequeue (void) { NS_LOG_FUNCTION (this); if (m_packets.empty ()) { NS_LOG_LOGIC ("Queue empty"); m_idle = 1; m_idleTime = Simulator::Now (); return 0; } else { m_idle = 0; Ptr<Packet> p = m_packets.front (); m_packets.pop_front (); m_bytesInQueue -= p->GetSize (); NS_LOG_LOGIC ("Popped " << p); NS_LOG_LOGIC ("Number packets " << m_packets.size ()); NS_LOG_LOGIC ("Number bytes " << m_bytesInQueue); return p; } }
void A2A4RsrqHandoverAlgorithm::DoInitialize () { NS_LOG_FUNCTION (this); NS_LOG_LOGIC (this << " requesting Event A2 measurements" << " (threshold=" << (uint16_t) m_servingCellThreshold << ")"); LteRrcSap::ReportConfigEutra reportConfigA2; reportConfigA2.eventId = LteRrcSap::ReportConfigEutra::EVENT_A2; reportConfigA2.threshold1.choice = LteRrcSap::ThresholdEutra::THRESHOLD_RSRQ; reportConfigA2.threshold1.range = m_servingCellThreshold; reportConfigA2.triggerQuantity = LteRrcSap::ReportConfigEutra::RSRQ; reportConfigA2.reportInterval = LteRrcSap::ReportConfigEutra::MS240; m_a2MeasId = m_handoverManagementSapUser->AddUeMeasReportConfigForHandover (reportConfigA2); NS_LOG_LOGIC (this << " requesting Event A4 measurements" << " (threshold=0)"); LteRrcSap::ReportConfigEutra reportConfigA4; reportConfigA4.eventId = LteRrcSap::ReportConfigEutra::EVENT_A4; reportConfigA4.threshold1.choice = LteRrcSap::ThresholdEutra::THRESHOLD_RSRQ; reportConfigA4.threshold1.range = 0; // intentionally very low threshold reportConfigA4.triggerQuantity = LteRrcSap::ReportConfigEutra::RSRQ; reportConfigA4.reportInterval = LteRrcSap::ReportConfigEutra::MS480; m_a4MeasId = m_handoverManagementSapUser->AddUeMeasReportConfigForHandover (reportConfigA4); LteHandoverAlgorithm::DoInitialize (); }
void A2A4RsrqHandoverAlgorithm::EvaluateHandover (uint16_t rnti, uint8_t servingCellRsrq) { NS_LOG_FUNCTION (this << rnti << (uint16_t) servingCellRsrq); MeasurementTable_t::iterator it1; it1 = m_neighbourCellMeasures.find (rnti); if (it1 == m_neighbourCellMeasures.end ()) { NS_LOG_WARN ("Skipping handover evaluation for RNTI " << rnti << " because neighbour cells information is not found"); } else { // Find the best neighbour cell (eNB) NS_LOG_LOGIC ("Number of neighbour cells = " << it1->second.size ()); uint16_t bestNeighbourCellId = 0; uint8_t bestNeighbourRsrq = 0; MeasurementRow_t::iterator it2; for (it2 = it1->second.begin (); it2 != it1->second.end (); ++it2) { if ((it2->second->m_rsrq > bestNeighbourRsrq) && IsValidNeighbour (it2->first)) { bestNeighbourCellId = it2->first; bestNeighbourRsrq = it2->second->m_rsrq; } } // Trigger Handover, if needed if (bestNeighbourCellId > 0) { NS_LOG_LOGIC ("Best neighbour cellId " << bestNeighbourCellId); if ((bestNeighbourRsrq - servingCellRsrq) >= m_neighbourCellOffset) { NS_LOG_LOGIC ("Trigger Handover to cellId " << bestNeighbourCellId); NS_LOG_LOGIC ("target cell RSRQ " << (uint16_t) bestNeighbourRsrq); NS_LOG_LOGIC ("serving cell RSRQ " << (uint16_t) servingCellRsrq); // Inform eNodeB RRC about handover m_handoverManagementSapUser->TriggerHandover (rnti, bestNeighbourCellId); } } } // end of else of if (it1 == m_neighbourCellMeasures.end ()) } // end of EvaluateMeasurementReport
void LtePdcp::DoTransmitPdcpSdu (Ptr<Packet> p) { NS_LOG_FUNCTION (this << m_rnti << (uint32_t) m_lcid << p->GetSize ()); LtePdcpHeader pdcpHeader; pdcpHeader.SetSequenceNumber (m_txSequenceNumber); m_txSequenceNumber++; if (m_txSequenceNumber > m_maxPdcpSn) { m_txSequenceNumber = 0; } pdcpHeader.SetDcBit (LtePdcpHeader::DATA_PDU); NS_LOG_LOGIC ("PDCP header: " << pdcpHeader); p->AddHeader (pdcpHeader); // Sender timestamp PdcpTag pdcpTag (Simulator::Now ()); p->AddByteTag (pdcpTag); m_txPdu (m_rnti, m_lcid, p->GetSize ()); LteRlcSapProvider::TransmitPdcpPduParameters params; params.rnti = m_rnti; params.lcid = m_lcid; params.pdcpPdu = p; m_rlcSapProvider->TransmitPdcpPdu (params); }
void RadvdHelper::AddAnnouncedPrefix (uint32_t interface, Ipv6Address prefix, uint32_t prefixLength) { NS_LOG_FUNCTION(this << int(interface) << prefix << int(prefixLength)); if (prefixLength != 64) { NS_LOG_WARN("Adding a non-64 prefix is generally a bad idea. Autoconfiguration might not work."); } bool prefixFound = false; if (m_radvdInterfaces.find(interface) == m_radvdInterfaces.end()) { m_radvdInterfaces[interface] = Create<RadvdInterface> (interface); } else { RadvdInterface::RadvdPrefixList prefixList = m_radvdInterfaces[interface]->GetPrefixes(); RadvdInterface::RadvdPrefixListCI iter; for (iter=prefixList.begin(); iter!=prefixList.end(); iter++) { if ((*iter)->GetNetwork() == prefix) { NS_LOG_LOGIC("Not adding the same prefix twice, skipping " << prefix << " " << int(prefixLength)); prefixFound = true; break; } } } if (!prefixFound) { Ptr<RadvdPrefix> routerPrefix = Create<RadvdPrefix> (prefix, prefixLength); m_radvdInterfaces[interface]->AddPrefix(routerPrefix); } }
void LtePdcp::DoReceivePdu (Ptr<Packet> p) { NS_LOG_FUNCTION (this << m_rnti << (uint32_t) m_lcid << p->GetSize ()); // Receiver timestamp PdcpTag pdcpTag; Time delay; if (p->FindFirstMatchingByteTag (pdcpTag)) { delay = Simulator::Now() - pdcpTag.GetSenderTimestamp (); } m_rxPdu(m_rnti, m_lcid, p->GetSize (), delay.GetNanoSeconds ()); LtePdcpHeader pdcpHeader; p->RemoveHeader (pdcpHeader); NS_LOG_LOGIC ("PDCP header: " << pdcpHeader); m_rxSequenceNumber = pdcpHeader.GetSequenceNumber () + 1; if (m_rxSequenceNumber > m_maxPdcpSn) { m_rxSequenceNumber = 0; } LtePdcpSapUser::ReceivePdcpSduParameters params; params.pdcpSdu = p; params.rnti = m_rnti; params.lcid = m_lcid; m_pdcpSapUser->ReceivePdcpSdu (params); }
void SpectrumInterference::ConditionallyEvaluateChunk () { NS_LOG_FUNCTION (this); NS_LOG_LOGIC ("m_receiving: " << m_receiving ); NS_LOG_LOGIC ("m_lastChangeTime: " << m_lastChangeTime << " Now: " << Now ()); bool condition = m_receiving && (Now () > m_lastChangeTime); NS_LOG_LOGIC ("if condition: " << condition); if (condition) { SpectrumValue sinr = (*m_rxSignal) / ((*m_allSignals) - (*m_rxSignal) + (*m_noise)); Time duration = Now () - m_lastChangeTime; NS_LOG_LOGIC ("calling m_errorModel->EvaluateChunk (sinr, duration)"); m_errorModel->EvaluateChunk (sinr, duration); } }
void FdNetDevice::SetEncapsulationMode (enum EncapsulationMode mode) { NS_LOG_FUNCTION (mode); m_encapMode = mode; NS_LOG_LOGIC ("m_encapMode = " << m_encapMode); }
// Check if packet p needs to be dropped due to probability mark uint32_t RedQueue::DropEarly (Ptr<Packet> p, uint32_t qSize) { NS_LOG_FUNCTION (this << p << qSize); m_vProb1 = CalculatePNew (m_qAvg, m_maxTh, m_isGentle, m_vA, m_vB, m_vC, m_vD, m_curMaxP); m_vProb = ModifyP (m_vProb1, m_count, m_countBytes, m_meanPktSize, m_isWait, p->GetSize ()); // Drop probability is computed, pick random number and act if (m_cautious == 1) { /* * Don't drop/mark if the instantaneous queue is much below the average. * For experimental purposes only. * pkts: the number of packets arriving in 50 ms */ double pkts = m_ptc * 0.05; double fraction = std::pow ((1 - m_qW), pkts); if ((double) qSize < fraction * m_qAvg) { // Queue could have been empty for 0.05 seconds return 0; } } double u = m_uv->GetValue (); if (m_cautious == 2) { /* * Decrease the drop probability if the instantaneous * queue is much below the average. * For experimental purposes only. * pkts: the number of packets arriving in 50 ms */ double pkts = m_ptc * 0.05; double fraction = std::pow ((1 - m_qW), pkts); double ratio = qSize / (fraction * m_qAvg); if (ratio < 1.0) { u *= 1.0 / ratio; } } if (u <= m_vProb) { NS_LOG_LOGIC ("u <= m_vProb; u " << u << "; m_vProb " << m_vProb); // DROP or MARK m_count = 0; m_countBytes = 0; /// \todo Implement set bit to mark return 1; // drop } return 0; // no drop/mark }
Ptr<const Packet> RedQueue::DoPeek (void) const { NS_LOG_FUNCTION (this); if (m_packets.empty ()) { NS_LOG_LOGIC ("Queue empty"); return 0; } Ptr<Packet> p = m_packets.front (); NS_LOG_LOGIC ("Number packets " << m_packets.size ()); NS_LOG_LOGIC ("Number bytes " << m_bytesInQueue); return p; }
void PacketQueue::Drop (QueueEntry en, std::string reason) { NS_LOG_LOGIC (reason << en.GetPacket ()->GetUid () << " " << en.GetIpv4Header ().GetDestination ()); // en.GetErrorCallback () (en.GetPacket (), en.GetIpv4Header (), // Socket::ERROR_NOROUTETOHOST); return; }
bool CsmaChannel::TransmitEnd () { NS_LOG_FUNCTION (this << m_currentPkt << m_currentSrc); NS_LOG_INFO ("UID is " << m_currentPkt->GetUid () << ")"); NS_ASSERT (m_state == TRANSMITTING); m_state = PROPAGATING; bool retVal = true; if (!IsActive (m_currentSrc)) { NS_LOG_ERROR ("CsmaChannel::TransmitEnd(): Seclected source was detached before the end of the transmission"); retVal = false; } NS_LOG_LOGIC ("Schedule event in " << m_delay.GetSeconds () << " sec"); NS_LOG_LOGIC ("Receive"); std::vector<CsmaDeviceRec>::iterator it; uint32_t devId = 0; for (it = m_deviceList.begin (); it < m_deviceList.end (); it++) { if (it->IsActive ()) { // schedule reception events Simulator::ScheduleWithContext (it->devicePtr->GetNode ()->GetId (), m_delay, &CsmaNetDevice::Receive, it->devicePtr, m_currentPkt->Copy (), m_deviceList[m_currentSrc].devicePtr); } devId++; } // also schedule for the tx side to go back to IDLE Simulator::Schedule (m_delay, &CsmaChannel::PropagationCompleteEvent, this); return retVal; }
TcpNewReno::TcpNewReno (const TcpNewReno& sock) : TcpSocketBase (sock), m_cWnd (sock.m_cWnd), m_ssThresh (sock.m_ssThresh), m_initialCWnd (sock.m_initialCWnd), m_retxThresh (sock.m_retxThresh), m_inFastRec (false), m_limitedTx (sock.m_limitedTx) { NS_LOG_FUNCTION (this); NS_LOG_LOGIC ("Invoked the copy constructor"); }
void FibHelper::AddRoute(Ptr<Node> node, const Name& prefix, shared_ptr<Face> face, int32_t metric) { NS_LOG_LOGIC("[" << node->GetId() << "]$ route add " << prefix << " via " << face->getLocalUri() << " metric " << metric); ControlParameters parameters; parameters.setName(prefix); parameters.setFaceId(face->getId()); parameters.setCost(metric); AddNextHop(parameters, node); }
void LteAnr::DoInitialize () { NS_LOG_FUNCTION (this); NS_LOG_LOGIC (this << " requesting Event A4 measurements" << " (threshold=" << (uint16_t) m_threshold << ")"); LteRrcSap::ReportConfigEutra reportConfig; reportConfig.eventId = LteRrcSap::ReportConfigEutra::EVENT_A4; reportConfig.threshold1.choice = LteRrcSap::ThresholdEutra::THRESHOLD_RSRQ; reportConfig.threshold1.range = m_threshold; reportConfig.triggerQuantity = LteRrcSap::ReportConfigEutra::RSRQ; reportConfig.reportInterval = LteRrcSap::ReportConfigEutra::MS480; m_measId = m_anrSapUser->AddUeMeasReportConfigForAnr (reportConfig); }
shared_ptr<NetDeviceFace> StackHelper::PointToPointNetDeviceCallback(Ptr<Node> node, Ptr<L3Protocol> ndn, Ptr<NetDevice> device) const { NS_LOG_DEBUG("Creating point-to-point NetDeviceFace on node " << node->GetId()); shared_ptr<NetDeviceFace> face = std::make_shared<NetDeviceFace>(node, device); ndn->addFace(face); NS_LOG_LOGIC("Node " << node->GetId() << ": added NetDeviceFace as face #" << face->getLocalUri()); return face; }
void Ipv4AddressHelper::SetBase ( const Ipv4Address network, const Ipv4Mask mask, const Ipv4Address address) { NS_LOG_FUNCTION_NOARGS (); m_network = network.Get (); m_mask = mask.Get (); m_base = m_address = address.Get (); // // Some quick reasonableness testing. // NS_ASSERT_MSG ((m_network & ~m_mask) == 0, "Ipv4AddressHelper::SetBase(): Inconsistent network and mask"); // // Figure out how much to shift network numbers to get them aligned, and what // the maximum allowed address is with respect to the current mask. // m_shift = NumAddressBits (m_mask); m_max = (1 << m_shift) - 2; NS_ASSERT_MSG (m_shift <= 32, "Ipv4AddressHelper::SetBase(): Unreasonable address length"); // // Shift the network down into the normalized position. // m_network >>= m_shift; NS_LOG_LOGIC ("m_network == " << m_network); NS_LOG_LOGIC ("m_mask == " << m_mask); NS_LOG_LOGIC ("m_address == " << m_address); }
void FibHelper::RemoveRoute(Ptr<Node> node, const Name& prefix, shared_ptr<Face> face) { NS_LOG_LOGIC("[" << node->GetId() << "]$ route del " << prefix << " via " << face->getLocalUri()); // Get L3Protocol object Ptr<L3Protocol> L3protocol = node->GetObject<L3Protocol>(); // Get the forwarder instance shared_ptr<nfd::Forwarder> m_forwarder = L3protocol->getForwarder(); ControlParameters parameters; parameters.setName(prefix); parameters.setFaceId(face->getId()); RemoveNextHop(parameters, node); }
uint32_t Ipv4AddressHelper::NumAddressBits (uint32_t maskbits) const { NS_LOG_FUNCTION_NOARGS (); for (uint32_t i = 0; i < N_BITS; ++i) { if (maskbits & 1) { NS_LOG_LOGIC ("NumAddressBits -> " << i); return i; } maskbits >>= 1; } NS_ASSERT_MSG (false, "Ipv4AddressHelper::NumAddressBits(): Bad Mask"); return 0; }
void FibHelper::AddRoute(Ptr<Node> node, const ::ndn::Name& prefix, shared_ptr<Face> face, int32_t metric) { NS_LOG_LOGIC("[" << node->GetId() << "]$ route add " << prefix << " via " << face->getLocalUri() << " metric " << metric); // Get L3Protocol object Ptr<L3Protocol> L3protocol = node->GetObject<L3Protocol>(); // Get the forwarder instance shared_ptr<nfd::Forwarder> m_forwarder = L3protocol->getForwarder(); ControlParameters parameters; parameters.setName(prefix); parameters.setFaceId(face->getId()); parameters.setCost(metric); AddNextHop(parameters, node); }
FdReader::Data FdNetDeviceFdReader::DoRead (void) { NS_LOG_FUNCTION (this); uint8_t *buf = (uint8_t *)malloc (m_bufferSize); NS_ABORT_MSG_IF (buf == 0, "malloc() failed"); NS_LOG_LOGIC ("Calling read on fd " << m_fd); ssize_t len = read (m_fd, buf, m_bufferSize); if (len <= 0) { free (buf); buf = 0; len = 0; } return FdReader::Data (buf, len); }
void AccountingConsumer::SetNumberOfContents(uint32_t numOfContents) { m_N = numOfContents; NS_LOG_DEBUG(m_q << " and " << m_s << " and " << m_N); m_Pcum = std::vector<double>(m_N + 1); m_Pcum[0] = 0.0; for (uint32_t i = 1; i <= m_N; i++) { m_Pcum[i] = m_Pcum[i - 1] + 1.0 / std::pow(i + m_q, m_s); } for (uint32_t i = 1; i <= m_N; i++) { m_Pcum[i] = m_Pcum[i] / m_Pcum[m_N]; NS_LOG_LOGIC("Cumulative probability [" << i << "]=" << m_Pcum[i]); } }
/* New ACK (up to seqnum seq) received. Increase cwnd and call TcpSocketBase::NewAck() */ void TcpNewReno::NewAck (const SequenceNumber32& seq) { NS_LOG_FUNCTION (this << seq); NS_LOG_LOGIC ("TcpNewReno receieved ACK for seq " << seq << " cwnd " << m_cWnd << " ssthresh " << m_ssThresh); // Check for exit condition of fast recovery if (m_inFastRec && seq < m_recover) { // Partial ACK, partial window deflation (RFC2582 sec.3 bullet #5 paragraph 3) m_cWnd -= seq - m_txBuffer.HeadSequence (); m_cWnd += m_segmentSize; // increase cwnd NS_LOG_INFO ("Partial ACK in fast recovery: cwnd set to " << m_cWnd); TcpSocketBase::NewAck (seq); // update m_nextTxSequence and send new data if allowed by window DoRetransmit (); // Assume the next seq is lost. Retransmit lost packet return; } else if (m_inFastRec && seq >= m_recover) { // Full ACK (RFC2582 sec.3 bullet #5 paragraph 2, option 1) m_cWnd = std::min (m_ssThresh, BytesInFlight () + m_segmentSize); m_inFastRec = false; NS_LOG_INFO ("Received full ACK. Leaving fast recovery with cwnd set to " << m_cWnd); } // Increase of cwnd based on current phase (slow start or congestion avoidance) if (m_cWnd < m_ssThresh) { // Slow start mode, add one segSize to cWnd. Default m_ssThresh is 65535. (RFC2001, sec.1) m_cWnd += m_segmentSize; NS_LOG_INFO ("In SlowStart, updated to cwnd " << m_cWnd << " ssthresh " << m_ssThresh); } else { // Congestion avoidance mode, increase by (segSize*segSize)/cwnd. (RFC2581, sec.3.1) // To increase cwnd for one segSize per RTT, it should be (ackBytes*segSize)/cwnd double adder = static_cast<double> (m_segmentSize * m_segmentSize) / m_cWnd.Get (); adder = std::max (1.0, adder); m_cWnd += static_cast<uint32_t> (adder); NS_LOG_INFO ("In CongAvoid, updated to cwnd " << m_cWnd << " ssthresh " << m_ssThresh); } // Complete newAck processing TcpSocketBase::NewAck (seq); }
/* Retransmit timeout */ void TcpNewReno::Retransmit (void) { NS_LOG_FUNCTION (this); NS_LOG_LOGIC (this << " ReTxTimeout Expired at time " << Simulator::Now ().GetSeconds ()); m_inFastRec = false; // If erroneous timeout in closed/timed-wait state, just return if (m_state == CLOSED || m_state == TIME_WAIT) return; // If all data are received (non-closing socket and nothing to send), just return if (m_state <= ESTABLISHED && m_txBuffer.HeadSequence () >= m_highTxMark) return; // According to RFC2581 sec.3.1, upon RTO, ssthresh is set to half of flight // size and cwnd is set to 1*MSS, then the lost packet is retransmitted and // TCP back to slow start m_ssThresh = std::max (2 * m_segmentSize, BytesInFlight () / 2); m_cWnd = m_segmentSize; m_nextTxSequence = m_txBuffer.HeadSequence (); // Restart from highest Ack NS_LOG_INFO ("RTO. Reset cwnd to " << m_cWnd << ", ssthresh to " << m_ssThresh << ", restart from seqnum " << m_nextTxSequence); m_rtt->IncreaseMultiplier (); // Double the next RTO DoRetransmit (); // Retransmit the packet }
uint32_t AccountingConsumer::GetNextSeq() { uint32_t content_index = 1; //[1, m_N] double p_sum = 0; double p_random = m_SeqRng.GetValue(); while (p_random == 0) { p_random = m_SeqRng.GetValue(); } // if (p_random == 0) NS_LOG_LOGIC("p_random=" << p_random); for (uint32_t i = 1; i <= m_N; i++) { p_sum = m_Pcum[i]; // m_Pcum[i] = m_Pcum[i-1] + p[i], p[0] = 0; e.g.: p_cum[1] = p[1], // p_cum[2] = p[1] + p[2] if (p_random <= p_sum) { content_index = i; break; } // if } // for // content_index = 1; NS_LOG_DEBUG("RandomNumber=" << content_index); return content_index; }
bool CsmaChannel::TransmitStart (Ptr<Packet> p, uint32_t srcId) { NS_LOG_FUNCTION (this << p << srcId); NS_LOG_INFO ("UID is " << p->GetUid () << ")"); if (m_state != IDLE) { NS_LOG_WARN ("CsmaChannel::TransmitStart(): State is not IDLE"); return false; } if (!IsActive (srcId)) { NS_LOG_ERROR ("CsmaChannel::TransmitStart(): Seclected source is not currently attached to network"); return false; } NS_LOG_LOGIC ("switch to TRANSMITTING"); m_currentPkt = p; m_currentSrc = srcId; m_state = TRANSMITTING; return true; }
bool FdNetDevice::SendFrom (Ptr<Packet> packet, const Address& src, const Address& dest, uint16_t protocolNumber) { NS_LOG_FUNCTION (this << packet << src << dest << protocolNumber); NS_LOG_LOGIC ("packet " << packet); NS_LOG_LOGIC ("UID is " << packet->GetUid ()); if (IsLinkUp () == false) { m_macTxDropTrace (packet); return false; } Mac48Address destination = Mac48Address::ConvertFrom (dest); Mac48Address source = Mac48Address::ConvertFrom (src); NS_LOG_LOGIC ("Transmit packet with UID " << packet->GetUid ()); NS_LOG_LOGIC ("Transmit packet from " << source); NS_LOG_LOGIC ("Transmit packet to " << destination); EthernetHeader header (false); header.SetSource (source); header.SetDestination (destination); if (m_encapMode == LLC) { LlcSnapHeader llc; llc.SetType (protocolNumber); packet->AddHeader (llc); header.SetLengthType (packet->GetSize ()); } else { header.SetLengthType (protocolNumber); } packet->AddHeader (header); // // there's not much meaning associated with the different layers in this // device, so don't be surprised when they're all stacked together in // essentially one place. We do this for trace consistency across devices. // m_macTxTrace (packet); m_promiscSnifferTrace (packet); m_snifferTrace (packet); NS_LOG_LOGIC ("calling write"); NS_ASSERT_MSG (packet->GetSize () <= m_mtu, "FdNetDevice::SendFrom(): Packet too big " << packet->GetSize ()); ssize_t len = (ssize_t) packet->GetSize (); uint8_t *buffer = (uint8_t*)malloc (len); packet->CopyData (buffer, len); // We need to add the PI header if (m_encapMode == DIXPI) { AddPIHeader (buffer, len); } ssize_t written = write (m_fd, buffer, len); free (buffer); if (written == -1 || written != len) { m_macTxDropTrace (packet); return false; } return true; }
void FdNetDevice::ForwardUp (uint8_t *buf, ssize_t len) { NS_LOG_FUNCTION (this << buf << len); if (m_pendingReadCount > 0) { { CriticalSection cs (m_pendingReadMutex); --m_pendingReadCount; } } // We need to remove the PI header and ignore it if (m_encapMode == DIXPI) { RemovePIHeader (buf, len); } // // Create a packet out of the buffer we received and free that buffer. // Ptr<Packet> packet = Create<Packet> (reinterpret_cast<const uint8_t *> (buf), len); free (buf); buf = 0; // // Trace sinks will expect complete packets, not packets without some of the // headers // Ptr<Packet> originalPacket = packet->Copy (); Mac48Address destination; Mac48Address source; uint16_t protocol; bool isBroadcast = false; bool isMulticast = false; EthernetHeader header (false); // // This device could be running in an environment where completely unexpected // kinds of packets are flying around, so we need to harden things a bit and // filter out packets we think are completely bogus, so we always check to see // that the packet is long enough to contain the header we want to remove. // if (packet->GetSize () < header.GetSerializedSize ()) { m_phyRxDropTrace (originalPacket); return; } packet->RemoveHeader (header); destination = header.GetDestination (); source = header.GetSource (); isBroadcast = header.GetDestination ().IsBroadcast (); isMulticast = header.GetDestination ().IsGroup (); protocol = header.GetLengthType (); // // If the length/type is less than 1500, it corresponds to a length // interpretation packet. In this case, it is an 802.3 packet and // will also have an 802.2 LLC header. If greater than 1500, we // find the protocol number (Ethernet type) directly. // if (m_encapMode == LLC and header.GetLengthType () <= 1500) { LlcSnapHeader llc; // // Check to see that the packet is long enough to possibly contain the // header we want to remove before just naively calling. // if (packet->GetSize () < llc.GetSerializedSize ()) { m_phyRxDropTrace (originalPacket); return; } packet->RemoveHeader (llc); protocol = llc.GetType (); } NS_LOG_LOGIC ("Pkt source is " << source); NS_LOG_LOGIC ("Pkt destination is " << destination); PacketType packetType; if (isBroadcast) { packetType = NS3_PACKET_BROADCAST; } else if (isMulticast) { packetType = NS3_PACKET_MULTICAST; } else if (destination == m_address) { packetType = NS3_PACKET_HOST; } else { packetType = NS3_PACKET_OTHERHOST; } // // For all kinds of packetType we receive, we hit the promiscuous sniffer // hook and pass a copy up to the promiscuous callback. Pass a copy to // make sure that nobody messes with our packet. // m_promiscSnifferTrace (originalPacket); if (!m_promiscRxCallback.IsNull ()) { m_macPromiscRxTrace (originalPacket); m_promiscRxCallback (this, packet, protocol, source, destination, packetType); } // // If this packet is not destined for some other host, it must be for us // as either a broadcast, multicast or unicast. We need to hit the mac // packet received trace hook and forward the packet up the stack. // if (packetType != NS3_PACKET_OTHERHOST) { m_snifferTrace (originalPacket); m_macRxTrace (originalPacket); m_rxCallback (this, packet, protocol, source); } }
void LteAnr::DoReportUeMeas (LteRrcSap::MeasResults measResults) { uint8_t measId = measResults.measId; NS_LOG_FUNCTION (this << m_servingCellId << (uint16_t) measId); if (measId != m_measId) { NS_LOG_WARN (this << " Skipping unexpected measurement identity " << (uint16_t) measId); } else { if (measResults.haveMeasResultNeighCells && !(measResults.measResultListEutra.empty ())) { for (std::list <LteRrcSap::MeasResultEutra>::iterator it = measResults.measResultListEutra.begin (); it != measResults.measResultListEutra.end (); ++it) { // Keep new RSRQ value reported for the neighbour cell NS_ASSERT_MSG (it->haveRsrqResult == true, "RSRQ measure missing for cellId " << it->physCellId); // Update Neighbour Relation Table NeighbourRelationTable_t::iterator itNrt = m_neighbourRelationTable.find (it->physCellId); if (itNrt != m_neighbourRelationTable.end ()) { // Update neighbour relation entry NS_LOG_LOGIC (this << " updating NRT of cell " << m_servingCellId << " with entry of cell " << it->physCellId); if (itNrt->second.noX2 == false) { NS_LOG_LOGIC (this << " enabling handover" << " from cell " << m_servingCellId << " to cell " << it->physCellId); itNrt->second.noHo = false; } itNrt->second.detectedAsNeighbour = true; } else { // Discovered new neighbour NS_LOG_LOGIC (this << " inserting NRT of cell " << m_servingCellId << " with newly discovered neighbouring cell " << it->physCellId); NeighbourRelation_t neighbourRelation; neighbourRelation.noRemove = false; neighbourRelation.noHo = true; neighbourRelation.noX2 = true; neighbourRelation.detectedAsNeighbour = true; m_neighbourRelationTable[it->physCellId] = neighbourRelation; } } // end of for (it = measResults.measResultListEutra.begin ()) } // end of if (measResults.haveMeasResultNeighCells && !(measResults.measResultListEutra.empty ())) else { NS_LOG_WARN (this << " Event A4 received without measurement results from neighbouring cells"); /// \todo Remove neighbours in the NRT. } } // end of else of if (measId != m_measId) } // end of DoReportUeMeas
bool RedQueue::DoEnqueue (Ptr<Packet> p) { NS_LOG_FUNCTION (this << p); if (!m_hasRedStarted ) { NS_LOG_INFO ("Initializing RED params."); InitializeParams (); m_hasRedStarted = true; } uint32_t nQueued = 0; if (GetMode () == QUEUE_MODE_BYTES) { NS_LOG_DEBUG ("Enqueue in bytes mode"); nQueued = m_bytesInQueue; } else if (GetMode () == QUEUE_MODE_PACKETS) { NS_LOG_DEBUG ("Enqueue in packets mode"); nQueued = m_packets.size (); } // simulate number of packets arrival during idle period uint32_t m = 0; if (m_idle == 1) { NS_LOG_DEBUG ("RED Queue is idle."); Time now = Simulator::Now (); if (m_cautious == 3) { double ptc = m_ptc * m_meanPktSize / m_idlePktSize; m = uint32_t (ptc * (now - m_idleTime).GetSeconds ()); } else { m = uint32_t (m_ptc * (now - m_idleTime).GetSeconds ()); } m_idle = 0; } m_qAvg = Estimator (nQueued, m + 1, m_qAvg, m_qW); NS_LOG_DEBUG ("\t bytesInQueue " << m_bytesInQueue << "\tQavg " << m_qAvg); NS_LOG_DEBUG ("\t packetsInQueue " << m_packets.size () << "\tQavg " << m_qAvg); m_count++; m_countBytes += p->GetSize (); uint32_t dropType = DTYPE_NONE; if (m_qAvg >= m_minTh && nQueued > 1) { if ((!m_isGentle && m_qAvg >= m_maxTh) || (m_isGentle && m_qAvg >= 2 * m_maxTh)) { NS_LOG_DEBUG ("adding DROP FORCED MARK"); dropType = DTYPE_FORCED; } else if (m_old == 0) { /* * The average queue size has just crossed the * threshold from below to above "minthresh", or * from above "minthresh" with an empty queue to * above "minthresh" with a nonempty queue. */ m_count = 1; m_countBytes = p->GetSize (); m_old = 1; } else if (DropEarly (p, nQueued)) { NS_LOG_LOGIC ("DropEarly returns 1"); dropType = DTYPE_UNFORCED; } } else { // No packets are being dropped m_vProb = 0.0; m_old = 0; } if (nQueued >= m_queueLimit) { NS_LOG_DEBUG ("\t Dropping due to Queue Full " << nQueued); dropType = DTYPE_FORCED; m_stats.qLimDrop++; } if (dropType == DTYPE_UNFORCED) { NS_LOG_DEBUG ("\t Dropping due to Prob Mark " << m_qAvg); m_stats.unforcedDrop++; Drop (p); return false; } else if (dropType == DTYPE_FORCED) { NS_LOG_DEBUG ("\t Dropping due to Hard Mark " << m_qAvg); m_stats.forcedDrop++; Drop (p); if (m_isNs1Compat) { m_count = 0; m_countBytes = 0; } return false; } m_bytesInQueue += p->GetSize (); m_packets.push_back (p); NS_LOG_LOGIC ("Number packets " << m_packets.size ()); NS_LOG_LOGIC ("Number bytes " << m_bytesInQueue); return true; }