From 55359e47eadaf8715fc3e84c94e6ad324a3ebdb9 Mon Sep 17 00:00:00 2001 From: "La Tuan Minh (GCI 2019)" <> Date: Thu, 2 Apr 2020 15:46:13 -0700 Subject: [PATCH] uan: refactor uses of Time::GetSeconds --- src/uan/examples/uan-cw-example.cc | 4 +-- src/uan/model/uan-mac-aloha.cc | 2 +- src/uan/model/uan-mac-cw.cc | 28 ++++++++++----------- src/uan/model/uan-mac-rc-gw.cc | 24 +++++++++--------- src/uan/model/uan-mac-rc.cc | 40 +++++++++++++++--------------- src/uan/model/uan-phy-dual.cc | 8 +++--- src/uan/model/uan-phy-gen.cc | 32 ++++++++++++------------ src/uan/model/uan-prop-model.cc | 4 +-- src/uan/model/uan-transducer-hd.cc | 2 +- 9 files changed, 72 insertions(+), 72 deletions(-) diff --git a/src/uan/examples/uan-cw-example.cc b/src/uan/examples/uan-cw-example.cc index d68ac9ad5..9f7192d1b 100644 --- a/src/uan/examples/uan-cw-example.cc +++ b/src/uan/examples/uan-cw-example.cc @@ -77,7 +77,7 @@ Experiment::Experiment () void Experiment::ResetData () { - NS_LOG_DEBUG (Simulator::Now ().GetSeconds () << " Resetting data"); + NS_LOG_DEBUG (Now ().As (Time::S) << " Resetting data"); m_throughputs.push_back (m_bytesTotal * 8.0 / m_simTime.GetSeconds ()); m_bytesTotal = 0; } @@ -106,7 +106,7 @@ void Experiment::UpdatePositions (NodeContainer &nodes) { - NS_LOG_DEBUG (Simulator::Now ().GetSeconds () << " Updating positions"); + NS_LOG_DEBUG (Now ().As (Time::S) << " Updating positions"); NodeContainer::Iterator it = nodes.Begin (); Ptr uv = CreateObject (); for (; it != nodes.End (); it++) diff --git a/src/uan/model/uan-mac-aloha.cc b/src/uan/model/uan-mac-aloha.cc index 34d280b80..9c6a665b7 100644 --- a/src/uan/model/uan-mac-aloha.cc +++ b/src/uan/model/uan-mac-aloha.cc @@ -79,7 +79,7 @@ UanMacAloha::GetTypeId (void) bool UanMacAloha::Enqueue (Ptr packet, uint16_t protocolNumber, const Address &dest) { - NS_LOG_DEBUG ("" << Simulator::Now ().GetSeconds () << " MAC " << Mac8Address::ConvertFrom (GetAddress ()) << " Queueing packet for " << Mac8Address::ConvertFrom (dest)); + NS_LOG_DEBUG ("" << Now ().As (Time::S) << " MAC " << Mac8Address::ConvertFrom (GetAddress ()) << " Queueing packet for " << Mac8Address::ConvertFrom (dest)); if (!m_phy->IsStateTx ()) { diff --git a/src/uan/model/uan-mac-cw.cc b/src/uan/model/uan-mac-cw.cc index 4a73ffdc0..3f957331e 100644 --- a/src/uan/model/uan-mac-cw.cc +++ b/src/uan/model/uan-mac-cw.cc @@ -114,7 +114,7 @@ UanMacCw::Enqueue (Ptr packet, uint16_t protocolNumber, const Address &d switch (m_state) { case CCABUSY: - NS_LOG_DEBUG ("Time " << Simulator::Now ().GetSeconds () << " MAC " << GetAddress () << " Starting enqueue CCABUSY"); + NS_LOG_DEBUG ("Time " << Now ().As (Time::S) << " MAC " << GetAddress () << " Starting enqueue CCABUSY"); if (m_txEndEvent.IsRunning ()) { NS_LOG_DEBUG ("State is TX"); @@ -150,15 +150,15 @@ UanMacCw::Enqueue (Ptr packet, uint16_t protocolNumber, const Address &d m_pktTxProt = GetTxModeIndex (); m_state = CCABUSY; uint32_t cw = (uint32_t) m_rv->GetValue (0,m_cw); - m_savedDelayS = Seconds ((double)(cw) * m_slotTime.GetSeconds ()); + m_savedDelayS = cw * m_slotTime; m_sendTime = Simulator::Now () + m_savedDelayS; - NS_LOG_DEBUG ("Time " << Simulator::Now ().GetSeconds () << ": Addr " << GetAddress () << ": Enqueuing new packet while busy: (Chose CW " << cw << ", Sending at " << m_sendTime.GetSeconds () << " Packet size: " << packet->GetSize ()); + NS_LOG_DEBUG ("Time " << Now ().As (Time::S) << ": Addr " << GetAddress () << ": Enqueuing new packet while busy: (Chose CW " << cw << ", Sending at " << m_sendTime.As (Time::S) << " Packet size: " << packet->GetSize ()); NS_ASSERT (m_phy->GetTransducer ()->GetArrivalList ().size () >= 1 || m_phy->IsStateTx ()); } else { NS_ASSERT (m_state != TX); - NS_LOG_DEBUG ("Time " << Simulator::Now ().GetSeconds () << ": Addr " << GetAddress () << ": Enqueuing new packet while idle (sending)"); + NS_LOG_DEBUG ("Time " << Now ().As (Time::S) << ": Addr " << GetAddress () << ": Enqueuing new packet while idle (sending)"); NS_ASSERT (m_phy->GetTransducer ()->GetArrivalList ().size () == 0 && !m_phy->IsStateTx ()); m_state = TX; m_phy->SendPacket (packet,GetTxModeIndex ()); @@ -197,7 +197,7 @@ UanMacCw::NotifyRxStart (void) if (m_state == RUNNING) { - NS_LOG_DEBUG ("Time " << Simulator::Now ().GetSeconds () << " Addr " << GetAddress () << ": Switching to channel busy"); + NS_LOG_DEBUG ("Time " << Now ().As (Time::S) << " Addr " << GetAddress () << ": Switching to channel busy"); SaveTimer (); m_state = CCABUSY; } @@ -208,7 +208,7 @@ UanMacCw::NotifyRxEndOk (void) { if (m_state == CCABUSY && !m_phy->IsStateCcaBusy ()) { - NS_LOG_DEBUG ("Time " << Simulator::Now ().GetSeconds () << " Addr " << GetAddress () << ": Switching to channel idle"); + NS_LOG_DEBUG ("Time " << Now ().As (Time::S) << " Addr " << GetAddress () << ": Switching to channel idle"); m_state = RUNNING; StartTimer (); @@ -220,7 +220,7 @@ UanMacCw::NotifyRxEndError (void) { if (m_state == CCABUSY && !m_phy->IsStateCcaBusy ()) { - NS_LOG_DEBUG ("Time " << Simulator::Now ().GetSeconds () << " Addr " << GetAddress () << ": Switching to channel idle"); + NS_LOG_DEBUG ("Time " << Now ().As (Time::S) << " Addr " << GetAddress () << ": Switching to channel idle"); m_state = RUNNING; StartTimer (); @@ -232,7 +232,7 @@ UanMacCw::NotifyCcaStart (void) { if (m_state == RUNNING) { - NS_LOG_DEBUG ("Time " << Simulator::Now ().GetSeconds () << " Addr " << GetAddress () << ": Switching to channel busy"); + NS_LOG_DEBUG ("Time " << Now ().As (Time::S) << " Addr " << GetAddress () << ": Switching to channel busy"); m_state = CCABUSY; SaveTimer (); @@ -244,7 +244,7 @@ UanMacCw::NotifyCcaEnd (void) { if (m_state == CCABUSY) { - NS_LOG_DEBUG ("Time " << Simulator::Now ().GetSeconds () << " Addr " << GetAddress () << ": Switching to channel idle"); + NS_LOG_DEBUG ("Time " << Now ().As (Time::S) << " Addr " << GetAddress () << ": Switching to channel idle"); m_state = RUNNING; StartTimer (); @@ -261,7 +261,7 @@ UanMacCw::NotifyTxStart (Time duration) } m_txEndEvent = Simulator::Schedule (duration, &UanMacCw::EndTx, this); - NS_LOG_DEBUG ("Time " << Simulator::Now ().GetSeconds () << " scheduling TxEndEvent with delay " << duration.GetSeconds ()); + NS_LOG_DEBUG ("Time " << Now ().As (Time::S) << " scheduling TxEndEvent with delay " << duration.As (Time::S)); if (m_state == RUNNING) { NS_ASSERT (0); @@ -292,7 +292,7 @@ UanMacCw::EndTx (void) { if (m_phy->IsStateIdle ()) { - NS_LOG_DEBUG ("Time " << Simulator::Now ().GetSeconds () << " Addr " << GetAddress () << ": Switching to channel idle (After TX!)"); + NS_LOG_DEBUG ("Time " << Now ().As (Time::S) << " Addr " << GetAddress () << ": Switching to channel idle (After TX!)"); m_state = RUNNING; StartTimer (); } @@ -342,7 +342,7 @@ UanMacCw::PhyRxPacketError (Ptr packet, double sinr) void UanMacCw::SaveTimer (void) { - NS_LOG_DEBUG ("Time " << Simulator::Now ().GetSeconds () << " Addr " << GetAddress () << " Saving timer (Delay = " << (m_savedDelayS = m_sendTime - Simulator::Now ()).GetSeconds () << ")"); + NS_LOG_DEBUG ("Time " << Now ().As (Time::S) << " Addr " << GetAddress () << " Saving timer (Delay = " << (m_savedDelayS = m_sendTime - Now ()).As (Time::S) << ")"); NS_ASSERT (m_pktTx); NS_ASSERT (m_sendTime >= Simulator::Now ()); m_savedDelayS = m_sendTime - Simulator::Now (); @@ -362,14 +362,14 @@ UanMacCw::StartTimer (void) else { m_sendEvent = Simulator::Schedule (m_savedDelayS, &UanMacCw::SendPacket, this); - NS_LOG_DEBUG ("Time " << Simulator::Now ().GetSeconds () << " Addr " << GetAddress () << " Starting timer (New send time = " << this->m_sendTime.GetSeconds () << ")"); + NS_LOG_DEBUG ("Time " << Now ().As (Time::S) << " Addr " << GetAddress () << " Starting timer (New send time = " << this->m_sendTime.As (Time::S) << ")"); } } void UanMacCw::SendPacket (void) { - NS_LOG_DEBUG ("Time " << Simulator::Now ().GetSeconds () << " Addr " << GetAddress () << " Transmitting "); + NS_LOG_DEBUG ("Time " << Now ().As (Time::S) << " Addr " << GetAddress () << " Transmitting "); NS_ASSERT (m_state == RUNNING); m_state = TX; m_phy->SendPacket (m_pktTx,m_pktTxProt); diff --git a/src/uan/model/uan-mac-rc-gw.cc b/src/uan/model/uan-mac-rc-gw.cc index ffa68fdc8..0b31a5257 100644 --- a/src/uan/model/uan-mac-rc-gw.cc +++ b/src/uan/model/uan-mac-rc-gw.cc @@ -226,11 +226,11 @@ UanMacRcGw::ReceivePacket (Ptr pkt, double sinr, UanTxMode mode) m_propDelay[ch.GetSrc ()] = dh.GetPropDelay (); if (m_ackData.find (ch.GetSrc ()) == m_ackData.end ()) { - NS_LOG_DEBUG (Simulator::Now ().GetSeconds () << " GATEWAY Received unexpected data packet"); + NS_LOG_DEBUG (Now ().As (Time::S) << " GATEWAY Received unexpected data packet"); } else { - NS_LOG_DEBUG (Simulator::Now ().GetSeconds () << " GW Received data packet from " << ch.GetSrc () << " length = " << pkt->GetSize ()); + NS_LOG_DEBUG (Now ().As (Time::S) << " GW Received data packet from " << ch.GetSrc () << " length = " << pkt->GetSize ()); m_ackData[ch.GetSrc ()].rxFrames.insert (dh.GetFrameNo ()); } m_forwardUpCb (pkt, ch.GetProtocolNumber (), ch.GetSrc ()); @@ -255,7 +255,7 @@ UanMacRcGw::ReceivePacket (Ptr pkt, double sinr, UanTxMode mode) req.frameNo = rh.GetFrameNo (); req.retryNo = rh.GetRetryNo (); req.length = rh.GetLength (); - NS_LOG_DEBUG (Simulator::Now ().GetSeconds () << " GW storing reservation from " << ch.GetSrc () << " with length " << req.length); + NS_LOG_DEBUG (Now ().As (Time::S) << " GW storing reservation from " << ch.GetSrc () << " with length " << req.length); m_requests.insert (std::make_pair (ch.GetSrc (), req)); std::map::iterator it = m_propDelay.find (ch.GetSrc ()); if (it == m_propDelay.end ()) @@ -291,11 +291,11 @@ UanMacRcGw::StartCycle (void) if (numRts) { - NS_LOG_DEBUG (Simulator::Now ().GetSeconds () << " Simulator starting non-empty cycle"); + NS_LOG_DEBUG (Now ().As (Time::S) << " Simulator starting non-empty cycle"); } else { - NS_LOG_DEBUG (Simulator::Now ().GetSeconds () << " Simulator starting EMPTY cycle"); + NS_LOG_DEBUG (Now ().As (Time::S) << " Simulator starting EMPTY cycle"); } // Calculate dataRate @@ -414,8 +414,8 @@ UanMacRcGw::StartCycle (void) Time earliestArr = ctsTxTimeTotal + pdelay + pdelay + m_sifs; Time arrivalTime = std::max (earliestArr, nextEarliest); - NS_LOG_DEBUG (Simulator::Now ().GetSeconds () << " GW: Scheduling request for prop. delay " << pdelay.GetSeconds () << " for " << (*it).second << " Earliest possible arrival=" << earliestArr.GetSeconds () << " Next arrival time=" << nextEarliest.GetSeconds ()); - nextEarliest = arrivalTime + Seconds (req.length * 8.0 / dataRate) + Seconds (m_sifs.GetSeconds () * req.numFrames); + NS_LOG_DEBUG (Now ().As (Time::S) << " GW: Scheduling request for prop. delay " << pdelay.As (Time::S) << " for " << (*it).second << " Earliest possible arrival=" << earliestArr.As (Time::S) << " Next arrival time=" << nextEarliest.As (Time::S)); + nextEarliest = arrivalTime + Seconds (req.length * 8.0 / dataRate) + m_sifs * req.numFrames; UanHeaderRcCts ctsh; ctsh.SetAddress (dest); @@ -425,9 +425,9 @@ UanMacRcGw::StartCycle (void) ctsh.SetDelayToTx (arrivalTime); cts->AddHeader (ctsh); - NS_LOG_DEBUG (Simulator::Now ().GetSeconds () << + NS_LOG_DEBUG (Now ().As (Time::S) << " GW Scheduling reception for " << (uint32_t) req.numFrames << - " frames at " << (Simulator::Now () + arrivalTime).GetSeconds () << " (delaytiltx of " << arrivalTime.GetSeconds () << ") Total length is " << req.length << " with txtime " << req.length * 8 / dataRate << " seconds"); + " frames at " << (Simulator::Now () + arrivalTime).As (Time::S) << " (delaytiltx of " << arrivalTime.As (Time::S) << ") Total length is " << req.length << " with txtime " << req.length * 8 / dataRate << " seconds"); } UanHeaderRcCtsGlobal ctsg; @@ -460,7 +460,7 @@ void UanMacRcGw::EndCycle () { - NS_LOG_DEBUG (Simulator::Now ().GetSeconds () << " GW Ending cycle"); + NS_LOG_DEBUG (Now ().As (Time::S) << " GW Ending cycle"); Time nextAck = Seconds (0); @@ -529,7 +529,7 @@ UanMacRcGw::SendPacket (Ptr pkt, uint32_t rate) type = "UNKNOWN"; break; } - NS_LOG_DEBUG (Simulator::Now ().GetSeconds () << " GW sending " << type << " packet with size " << pkt->GetSize () << " to " << ch.GetDest () << " at rate " << rate); + NS_LOG_DEBUG (Now ().As (Time::S) << " GW sending " << type << " packet with size " << pkt->GetSize () << " to " << ch.GetDest () << " at rate " << rate); m_phy->SendPacket (pkt, rate); } @@ -710,7 +710,7 @@ UanMacRcGw::FindOptA (void) a++; } } - NS_LOG_DEBUG (Simulator::Now ().GetSeconds () << " GW: Found optimum a = " << a); + NS_LOG_DEBUG (Now ().As (Time::S) << " GW: Found optimum a = " << a); return a; } diff --git a/src/uan/model/uan-mac-rc.cc b/src/uan/model/uan-mac-rc.cc index f6f891815..0b503ea90 100644 --- a/src/uan/model/uan-mac-rc.cc +++ b/src/uan/model/uan-mac-rc.cc @@ -342,7 +342,7 @@ UanMacRc::ReceiveOkFromPhy (Ptr pkt, double sinr, UanTxMode mode) if (ch.GetDest () == Mac8Address::ConvertFrom (GetAddress ())) { - NS_LOG_DEBUG (Simulator::Now ().GetSeconds () << " Node " << Mac8Address::ConvertFrom (GetAddress ()) << + NS_LOG_DEBUG (Now ().As (Time::S) << " Node " << Mac8Address::ConvertFrom (GetAddress ()) << " UanMacRc Receiving DATA packet from PHY"); UanHeaderRcData dh; pkt->RemoveHeader (dh); @@ -366,14 +366,14 @@ UanMacRc::ReceiveOkFromPhy (Ptr pkt, double sinr, UanTxMode mode) Time winDelay = ctsg.GetWindowTime (); - if (winDelay.GetSeconds () > 0) + if (winDelay > 0) { m_rtsBlocked = false; Simulator::Schedule (winDelay, &UanMacRc::BlockRtsing, this); } else { - NS_FATAL_ERROR (Simulator::Now ().GetSeconds () << " Node " << + NS_FATAL_ERROR (Now ().As (Time::S) << " Node " << Mac8Address::ConvertFrom (GetAddress ()) << " Received window period < 0"); } @@ -395,7 +395,7 @@ UanMacRc::ReceiveOkFromPhy (Ptr pkt, double sinr, UanTxMode mode) } else { - NS_LOG_DEBUG (Simulator::Now ().GetSeconds () << " Node " << + NS_LOG_DEBUG (Now ().As (Time::S) << " Node " << Mac8Address::ConvertFrom (GetAddress ()) << " received CTS while state != RTSSENT or GWPING"); } @@ -437,12 +437,12 @@ UanMacRc::ScheduleData (const UanHeaderRcCts &ctsh, const UanHeaderRcCtsGlobal & } if (it == m_resList.end ()) { - NS_LOG_DEBUG (Simulator::Now ().GetSeconds () << " Node " << + NS_LOG_DEBUG (Now ().As (Time::S) << " Node " << Mac8Address::ConvertFrom (GetAddress ()) << " received CTS packet with no corresponding reservation!"); return; } - NS_LOG_DEBUG (Simulator::Now ().GetSeconds () << + NS_LOG_DEBUG (Now ().As (Time::S) << " Node " << Mac8Address::ConvertFrom (GetAddress ()) << " received CTS packet. Scheduling data"); it->SetTransmitted (); @@ -481,23 +481,23 @@ UanMacRc::ScheduleData (const UanHeaderRcCts &ctsh, const UanHeaderRcCtsGlobal & pkt->AddHeader (ch); Time eventTime = startDelay + frameDelay; - if (eventTime.GetSeconds () < 0) + if (eventTime < 0) { - if (eventTime.GetSeconds () > -0.001) + if (eventTime > -0.001) { - eventTime = Seconds (0); + eventTime = Time (); } else { - NS_FATAL_ERROR ("Scheduling error resulted in very negative data transmission time! eventTime = " << eventTime.GetSeconds ()); + NS_FATAL_ERROR ("Scheduling error resulted in very negative data transmission time! eventTime = " << eventTime.As (Time::S)); } } - NS_LOG_DEBUG (Simulator::Now ().GetSeconds () << + NS_LOG_DEBUG (Now ().As (Time::S) << " Node " << Mac8Address::ConvertFrom (GetAddress ()) << - " scheduling with delay " << eventTime.GetSeconds () << - " propDelay " << m_learnedProp.GetSeconds () << - " start delay " << startDelay.GetSeconds () << - " arrival time " << arrTime.GetSeconds ()); + " scheduling with delay " << eventTime.As (Time::S) << + " propDelay " << m_learnedProp.As (Time::S) << + " start delay " << startDelay.As (Time::S) << + " arrival time " << arrTime.As (Time::S)); Simulator::Schedule (eventTime, &UanMacRc::SendPacket, this, pkt, m_currentRate); frameDelay = frameDelay + m_sifs + Seconds (pkt->GetSize () / currentBps); } @@ -545,7 +545,7 @@ UanMacRc::SendPacket (Ptr pkt, uint32_t rate) type = "UNKNOWN"; break; } - NS_LOG_DEBUG (Simulator::Now ().GetSeconds () << + NS_LOG_DEBUG (Now ().As (Time::S) << " Node " << Mac8Address::ConvertFrom (GetAddress ()) << " transmitting " << pkt->GetSize () << " byte packet of type " << type << " with rate " << rate << @@ -588,7 +588,7 @@ UanMacRc::ProcessAck (Ptr ack) uint8_t pnum = 0; for (; nit != nacks.end (); nit++) { - NS_LOG_DEBUG (Simulator::Now ().GetSeconds () << " Node " << + NS_LOG_DEBUG (Now ().As (Time::S) << " Node " << Mac8Address::ConvertFrom (GetAddress ()) << " Received NACK for " << (uint32_t) *nit); while (pnum < *nit) @@ -603,7 +603,7 @@ UanMacRc::ProcessAck (Ptr ack) } else { - NS_LOG_DEBUG (Simulator::Now ().GetSeconds () << " Node " << + NS_LOG_DEBUG (Now ().As (Time::S) << " Node " << Mac8Address::ConvertFrom (GetAddress ()) << " received ACK for all frames"); } @@ -639,7 +639,7 @@ UanMacRc::Associate (void) Ptr pkt = Create (0); pkt->AddHeader (CreateRtsHeader (res)); pkt->AddHeader (UanHeaderCommon (Mac8Address::ConvertFrom (GetAddress ()), Mac8Address::GetBroadcast (), static_cast(TYPE_GWPING), 0)); - NS_LOG_DEBUG (Simulator::Now ().GetSeconds () << " Sending first GWPING " << *pkt); + NS_LOG_DEBUG (Now ().As (Time::S) << " Sending first GWPING " << *pkt); SendPacket (pkt,m_currentRate + m_numRates); } m_state = GWPSENT; @@ -754,7 +754,7 @@ UanMacRc::RtsTimeout (void) if (m_resList.empty ()) { - NS_FATAL_ERROR (Simulator::Now ().GetSeconds () << " Node " << + NS_FATAL_ERROR (Now ().As (Time::S) << " Node " << Mac8Address::ConvertFrom (GetAddress ()) << " tried to retry RTS with empty reservation list"); } diff --git a/src/uan/model/uan-phy-dual.cc b/src/uan/model/uan-phy-dual.cc index cbaae2bc9..b8ea1abdc 100644 --- a/src/uan/model/uan-phy-dual.cc +++ b/src/uan/model/uan-phy-dual.cc @@ -111,7 +111,7 @@ UanPhyCalcSinrDual::CalcSinrDb (Ptr pkt, double totalIntDb = KpToDb (intKp + DbToKp (ambNoiseDb)); - NS_LOG_DEBUG (Simulator::Now ().GetSeconds () << " Calculating SINR: RxPower = " << rxPowerDb << " dB. Number of interferers = " << arrivalList.size () << " Interference + noise power = " << totalIntDb << " dB. SINR = " << rxPowerDb - totalIntDb << " dB."); + NS_LOG_DEBUG (Now ().As (Time::S) << " Calculating SINR: RxPower = " << rxPowerDb << " dB. Number of interferers = " << arrivalList.size () << " Interference + noise power = " << totalIntDb << " dB. SINR = " << rxPowerDb - totalIntDb << " dB."); return rxPowerDb - totalIntDb; } @@ -253,14 +253,14 @@ UanPhyDual::SendPacket (Ptr pkt, uint32_t modeNum) { if (modeNum <= m_phy1->GetNModes () - 1) { - NS_LOG_DEBUG (Simulator::Now ().GetSeconds () << " Sending packet on Phy1 with mode number " << modeNum); + NS_LOG_DEBUG (Now ().As (Time::S) << " Sending packet on Phy1 with mode number " << modeNum); m_txLogger (pkt, m_phy1->GetTxPowerDb (), m_phy1->GetMode (modeNum)); m_phy1->SendPacket (pkt, modeNum); } else { - NS_LOG_DEBUG (Simulator::Now ().GetSeconds () << " Sending packet on Phy2 with mode number " << modeNum - m_phy1->GetNModes ()); + NS_LOG_DEBUG (Now ().As (Time::S) << " Sending packet on Phy2 with mode number " << modeNum - m_phy1->GetNModes ()); m_txLogger (pkt, m_phy2->GetTxPowerDb (), m_phy2->GetMode (modeNum - m_phy1->GetNModes ())); m_phy2->SendPacket (pkt, modeNum - m_phy1->GetNModes ()); } @@ -613,7 +613,7 @@ UanPhyDual::SetSinrModelPhy2 (Ptr sinr) void UanPhyDual::RxOkFromSubPhy (Ptr pkt, double sinr, UanTxMode mode) { - NS_LOG_DEBUG (Simulator::Now ().GetSeconds () << " Received packet"); + NS_LOG_DEBUG (Now ().As (Time::S) << " Received packet"); m_recOkCb (pkt, sinr, mode); m_rxOkLogger (pkt, sinr, mode); } diff --git a/src/uan/model/uan-phy-gen.cc b/src/uan/model/uan-phy-gen.cc index 938125235..b01dc9c8f 100644 --- a/src/uan/model/uan-phy-gen.cc +++ b/src/uan/model/uan-phy-gen.cc @@ -136,13 +136,13 @@ UanPhyCalcSinrFhFsk::CalcSinrDb (Ptr pkt, NS_FATAL_ERROR ("Calculating SINR for unsupported mode type"); } - double ts = 1.0 / mode.GetPhyRateSps (); - double clearingTime = (m_hops - 1.0) * ts; - double csp = pdp.SumTapsFromMaxNc (Seconds (0), Seconds (ts)); + Time ts = Seconds (1.0 / mode.GetPhyRateSps ()); + Time clearingTime = (m_hops - 1.0) * ts; + double csp = pdp.SumTapsFromMaxNc (Time (), ts); // Get maximum arrival offset double maxAmp = -1; - double maxTapDelay = 0.0; + Time maxTapDelay (0); UanPdp::Iterator pit = pdp.GetBegin (); for (; pit != pdp.GetEnd (); pit++) { @@ -151,7 +151,7 @@ UanPhyCalcSinrFhFsk::CalcSinrDb (Ptr pkt, maxAmp = std::abs (pit->GetAmp ()); // Modified in order to subtract delay of first tap (maxTapDelay appears to be used later in code // as delay from first reception, not from TX time) - maxTapDelay = pit->GetDelay ().GetSeconds () - pdp.GetTap(0).GetDelay().GetSeconds(); + maxTapDelay = pit->GetDelay () - pdp.GetTap(0).GetDelay(); } } @@ -159,22 +159,22 @@ UanPhyCalcSinrFhFsk::CalcSinrDb (Ptr pkt, double effRxPowerDb = rxPowerDb + KpToDb (csp); //It appears to be just the first elements of the sum in Parrish paper, // "System Design Considerations for Undersea Networks: Link and Multiple Access Protocols", eq. 14 - double isiUpa = DbToKp(rxPowerDb) * pdp.SumTapsFromMaxNc (Seconds (ts + clearingTime), Seconds (ts)); // added DpToKp() + double isiUpa = DbToKp(rxPowerDb) * pdp.SumTapsFromMaxNc (ts + clearingTime, ts); // added DpToKp() UanTransducer::ArrivalList::const_iterator it = arrivalList.begin (); double intKp = -DbToKp (effRxPowerDb); for (; it != arrivalList.end (); it++) { UanPdp intPdp = it->GetPdp (); - double tDelta = std::abs (arrTime.GetSeconds () + maxTapDelay - it->GetArrivalTime ().GetSeconds ()); + Time tDelta = Abs (arrTime + maxTapDelay - it->GetArrivalTime ()); // We want tDelta in terms of a single symbol (i.e. if tDelta = 7.3 symbol+clearing // times, the offset in terms of the arriving symbol power is // 0.3 symbol+clearing times. - int32_t syms = (uint32_t)( (double) tDelta / (ts + clearingTime)); + int32_t syms = (uint32_t)(tDelta / (ts + clearingTime)).GetHigh (); tDelta = tDelta - syms * (ts + clearingTime); // Align to pktRx - if (arrTime + Seconds (maxTapDelay) > it->GetArrivalTime ()) + if (arrTime + maxTapDelay > it->GetArrivalTime ()) { tDelta = ts + clearingTime - tDelta; } @@ -183,20 +183,20 @@ UanPhyCalcSinrFhFsk::CalcSinrDb (Ptr pkt, if (tDelta < ts) // Case where there is overlap of a symbol due to interferer arriving just after desired signal { //Appears to be just the first two elements of the sum in Parrish paper, eq. 14 - intPower += intPdp.SumTapsNc (Seconds (0), Seconds (ts - tDelta)); - intPower += intPdp.SumTapsNc (Seconds (ts - tDelta + clearingTime), - Seconds (2 * ts - tDelta + clearingTime)); + intPower += intPdp.SumTapsNc (Time (), ts - tDelta); + intPower += intPdp.SumTapsNc (ts - tDelta + clearingTime, + 2 * ts - tDelta + clearingTime); } else // Account for case where there's overlap of a symbol due to interferer arriving with a tDelta of a symbol + clearing time later { // Appears to be just the first two elements of the sum in Parrish paper, eq. 14 - Time start = Seconds (ts + clearingTime - tDelta); - Time end = /*start +*/ Seconds (ts); // Should only sum over portion of ts that overlaps, not entire ts + Time start = ts + clearingTime - tDelta; + Time end = /*start +*/ ts; // Should only sum over portion of ts that overlaps, not entire ts intPower += intPdp.SumTapsNc (start, end); - start = start + Seconds (ts + clearingTime); + start = start + ts + clearingTime; //Should only sum over portion of ts that overlaps, not entire ts - end = end + Seconds (ts + clearingTime); //start + Seconds (ts); + end = end + ts + clearingTime; //start + Seconds (ts); intPower += intPdp.SumTapsNc (start, end); } intKp += DbToKp (it->GetRxPowerDb ()) * intPower; diff --git a/src/uan/model/uan-prop-model.cc b/src/uan/model/uan-prop-model.cc index 71e98af72..5f6a7c4e8 100644 --- a/src/uan/model/uan-prop-model.cc +++ b/src/uan/model/uan-prop-model.cc @@ -153,7 +153,7 @@ UanPdp::SetTap (std::complex amp, uint32_t index) m_taps.resize (index + 1); } - Time delay = Seconds (index * m_resolution.GetSeconds ()); + Time delay = index * m_resolution; m_taps[index] = Tap (delay, amp); } const Tap & @@ -208,7 +208,7 @@ UanPdp::SumTapsFromMaxC (Time delay, Time duration) const return std::complex (0.0, 0.0); } - uint32_t numTaps = static_cast (duration.GetSeconds () / m_resolution.GetSeconds () + 0.5); + uint32_t numTaps = (duration / m_resolution + 0.5).GetHigh (); double maxAmp = -1; uint32_t maxTapIndex = 0; diff --git a/src/uan/model/uan-transducer-hd.cc b/src/uan/model/uan-transducer-hd.cc index 08276376e..370748ae8 100644 --- a/src/uan/model/uan-transducer-hd.cc +++ b/src/uan/model/uan-transducer-hd.cc @@ -167,7 +167,7 @@ UanTransducerHd::Receive (Ptr packet, m_arrivalList.push_back (arrival); Time txDelay = Seconds (packet->GetSize () * 8.0 / txMode.GetDataRateBps ()); Simulator::Schedule (txDelay, &UanTransducerHd::RemoveArrival, this, arrival); - NS_LOG_DEBUG (Simulator::Now ().GetSeconds () << " Transducer in receive"); + NS_LOG_DEBUG (Now ().As (Time::S) << " Transducer in receive"); if (m_state == RX) { NS_LOG_DEBUG ("Transducer state = RX");