From cb0c39eddaa54405123da08eb8f71f73502008d0 Mon Sep 17 00:00:00 2001 From: Mathieu Lacage Date: Wed, 25 Aug 2010 21:31:43 +0200 Subject: [PATCH] introduce implicit conversion operator --- src/contrib/delay-jitter-estimation.cc | 2 +- src/contrib/stats/time-data-calculators.cc | 2 +- src/devices/csma/backoff.cc | 3 +- src/devices/mesh/dot11s/hwmp-protocol.cc | 4 +-- src/devices/spectrum/waveform-generator.cc | 2 +- src/devices/wifi/mac-low.cc | 4 +-- .../wimax/bs-uplink-scheduler-mbqos.cc | 8 +++--- src/internet-stack/rtt-estimator.cc | 17 ++++++----- src/internet-stack/tcp-socket-impl.cc | 2 +- src/routing/aodv/aodv-routing-protocol.cc | 28 +++++++++---------- src/routing/aodv/test/aodv-regression.cc | 2 +- src/routing/olsr/olsr-routing-protocol.cc | 8 +++--- src/simulator/nstime.h | 10 +++---- src/simulator/time.cc | 2 +- 14 files changed, 46 insertions(+), 48 deletions(-) diff --git a/src/contrib/delay-jitter-estimation.cc b/src/contrib/delay-jitter-estimation.cc index 06c21b017..b96a3c25d 100644 --- a/src/contrib/delay-jitter-estimation.cc +++ b/src/contrib/delay-jitter-estimation.cc @@ -98,7 +98,7 @@ DelayJitterEstimation::RecordRx (Ptr packet) tag.GetTxTime (); Time delta = (Simulator::Now () - m_previousRx) - (tag.GetTxTime () - m_previousRxTx); - m_jitter += (Abs (delta).To () - m_jitter) / 16; + m_jitter += (Abs (delta) - m_jitter) / 16; m_previousRx = Simulator::Now (); m_previousRxTx = tag.GetTxTime (); m_delay = Simulator::Now () - tag.GetTxTime (); diff --git a/src/contrib/stats/time-data-calculators.cc b/src/contrib/stats/time-data-calculators.cc index 5fef006e3..41214ead0 100644 --- a/src/contrib/stats/time-data-calculators.cc +++ b/src/contrib/stats/time-data-calculators.cc @@ -73,7 +73,7 @@ TimeMinMaxAvgTotalCalculator::Output(DataOutputCallback &callback) const callback.OutputSingleton(m_context, m_key + "-count", m_count); if (m_count > 0) { callback.OutputSingleton(m_context, m_key + "-total", m_total); - callback.OutputSingleton(m_context, m_key + "-average", m_total.To () / m_count); + callback.OutputSingleton(m_context, m_key + "-average", Time (m_total / m_count)); callback.OutputSingleton(m_context, m_key + "-max", m_max); callback.OutputSingleton(m_context, m_key + "-min", m_min); } diff --git a/src/devices/csma/backoff.cc b/src/devices/csma/backoff.cc index 98b64fdfd..a8b80426d 100644 --- a/src/devices/csma/backoff.cc +++ b/src/devices/csma/backoff.cc @@ -46,7 +46,6 @@ Backoff::Backoff(Time slotTime, uint32_t minSlots, uint32_t maxSlots, uint32_t c Time Backoff::GetBackoffTime (void) { - Time backoff; uint32_t ceiling; if ((m_ceiling > 0) &&(m_numBackoffRetries > m_ceiling)) @@ -67,7 +66,7 @@ Backoff::GetBackoffTime (void) uint32_t backoffSlots = (uint32_t)m_rng.GetValue(minSlot, maxSlot); - backoff = backoffSlots * m_slotTime.To (); + Time backoff = Time (backoffSlots * m_slotTime); return backoff; } diff --git a/src/devices/mesh/dot11s/hwmp-protocol.cc b/src/devices/mesh/dot11s/hwmp-protocol.cc index 74147ea4c..9e49f3c20 100644 --- a/src/devices/mesh/dot11s/hwmp-protocol.cc +++ b/src/devices/mesh/dot11s/hwmp-protocol.cc @@ -963,7 +963,7 @@ HwmpProtocol::ShouldSendPreq (Mac48Address dst) if (i == m_preqTimeouts.end ()) { m_preqTimeouts[dst].preqTimeout = Simulator::Schedule ( - Time (m_dot11MeshHWMPnetDiameterTraversalTime.To () * 2), + Time (m_dot11MeshHWMPnetDiameterTraversalTime * 2), &HwmpProtocol::RetryPathDiscovery, this, dst, 1); m_preqTimeouts[dst].whenScheduled = Simulator::Now (); return true; @@ -1009,7 +1009,7 @@ HwmpProtocol::RetryPathDiscovery (Mac48Address dst, uint8_t numOfRetry) i->second->RequestDestination (dst, originator_seqno, dst_seqno); } m_preqTimeouts[dst].preqTimeout = Simulator::Schedule ( - Time ((2 * (numOfRetry + 1)) * m_dot11MeshHWMPnetDiameterTraversalTime.To ()), + Time ((2 * (numOfRetry + 1)) * m_dot11MeshHWMPnetDiameterTraversalTime), &HwmpProtocol::RetryPathDiscovery, this, dst, numOfRetry); } //Proactive PREQ routines: diff --git a/src/devices/spectrum/waveform-generator.cc b/src/devices/spectrum/waveform-generator.cc index 87fe33782..90eaf16c8 100644 --- a/src/devices/spectrum/waveform-generator.cc +++ b/src/devices/spectrum/waveform-generator.cc @@ -189,7 +189,7 @@ WaveformGenerator::GenerateWaveform () NS_LOG_FUNCTION (this); Ptr pb = Create (); - Time duration = m_period.To () * m_dutyCycle; + Time duration = Time (m_period * m_dutyCycle); NS_LOG_LOGIC ("generating waveform : " << *m_txPowerSpectralDensity); m_phyTxStartTrace (0); diff --git a/src/devices/wifi/mac-low.cc b/src/devices/wifi/mac-low.cc index 524c4f07f..f0aa263b3 100644 --- a/src/devices/wifi/mac-low.cc +++ b/src/devices/wifi/mac-low.cc @@ -987,7 +987,7 @@ MacLow::CalculateOverallTxTime (Ptr packet, { txTime += m_phy->CalculateTxDuration (GetRtsSize (), rtsMode, WIFI_PREAMBLE_LONG); txTime += GetCtsDuration (hdr->GetAddr1 (), rtsMode); - txTime += GetSifs ().To () * 2; + txTime += Time (GetSifs () * 2); } uint32_t dataSize = GetSize (packet, hdr); txTime += m_phy->CalculateTxDuration (dataSize, dataMode, WIFI_PREAMBLE_LONG); @@ -1047,7 +1047,7 @@ MacLow::NotifyNav (const WifiMacHeader &hdr, WifiMode txMode, WifiPreamble pream cts.SetType (WIFI_MAC_CTL_CTS); Time navCounterResetCtsMissedDelay = m_phy->CalculateTxDuration (cts.GetSerializedSize (), txMode, preamble) + - 2 * GetSifs ().To () + 2 * GetSlotTime ().To (); + Time (2 * GetSifs ()) + Time (2 * GetSlotTime ()); m_navCounterResetCtsMissed = Simulator::Schedule (navCounterResetCtsMissedDelay, &MacLow::NavCounterResetCtsMissed, this, Simulator::Now ()); diff --git a/src/devices/wimax/bs-uplink-scheduler-mbqos.cc b/src/devices/wimax/bs-uplink-scheduler-mbqos.cc index c05658330..24450eda1 100644 --- a/src/devices/wimax/bs-uplink-scheduler-mbqos.cc +++ b/src/devices/wimax/bs-uplink-scheduler-mbqos.cc @@ -313,8 +313,8 @@ UplinkSchedulerMBQoS::Schedule (void) Time uInterval = MilliSeconds ((*(ssRecord->GetServiceFlows (ServiceFlow::SF_TYPE_UGS).begin ()))->GetUnsolicitedGrantInterval ()); - - int64x64_t frame = ((timestamp - Simulator::Now ()).To () / frame_duration.To ()); + + Time frame = Time ((timestamp - Simulator::Now ()) / frame_duration); if (frame <= 1) { @@ -668,8 +668,8 @@ UplinkSchedulerMBQoS::CheckDeadline (uint32_t &availableSymbols) Time deadline = job->GetDeadline (); Time frame_duration = GetBs ()->GetPhy ()->GetFrameDuration (); - int64x64_t frame = ((deadline - Simulator::Now ()).To () / frame_duration.To ()); - + Time frame = Time ((deadline - Simulator::Now ()) / frame_duration); + NS_LOG_DEBUG ("At " << Simulator::Now ().GetSeconds () << " reserved traffic rate: " << job->GetServiceFlow ()->GetMinReservedTrafficRate () <<" deadline: "<GetDeadline ().GetSeconds () << " frame start: "<m_frameStartTime.GetSeconds () diff --git a/src/internet-stack/rtt-estimator.cc b/src/internet-stack/rtt-estimator.cc index a02d2ce1e..c8c8e2601 100644 --- a/src/internet-stack/rtt-estimator.cc +++ b/src/internet-stack/rtt-estimator.cc @@ -65,22 +65,22 @@ RttEstimator::GetTypeId (void) void RttEstimator::SetMinRto (Time minRto) { - minrto = minRto.To (); + minrto = minRto; } Time RttEstimator::GetMinRto (void) const { - return minrto; + return Time (minrto); } void RttEstimator::SetEstimate (Time estimate) { - est = estimate.To (); + est = estimate; } Time RttEstimator::GetEstimate (void) const { - return est; + return Time (est); } @@ -226,18 +226,17 @@ RttMeanDeviation::RttMeanDeviation (const RttMeanDeviation& c) void RttMeanDeviation::Measurement (Time m) { - int64x64_t sample = m.To (); if (nSamples) { // Not first - int64x64_t err = sample - est; + int64x64_t err = m - est; est = est + gain * err; // estimated rtt variance = variance + gain * (Abs (err) - variance); // variance of rtt } else { // First sample - est = sample; // Set estimate to current + est = m; // Set estimate to current //variance = sample / 2; // And variance to current / 2 - variance = sample; // try this + variance = m; // try this } nSamples++; } @@ -256,7 +255,7 @@ Time RttMeanDeviation::RetransmitTimeout () retval = (est + 4 * variance) * multiplier; // As suggested by Jacobson } retval = Max (retval, minrto); - return retval; + return Time (retval); } Ptr RttMeanDeviation::Copy () const diff --git a/src/internet-stack/tcp-socket-impl.cc b/src/internet-stack/tcp-socket-impl.cc index 0978c1065..3c26a5570 100644 --- a/src/internet-stack/tcp-socket-impl.cc +++ b/src/internet-stack/tcp-socket-impl.cc @@ -1651,7 +1651,7 @@ void TcpSocketImpl::LastAckTimeout () void TcpSocketImpl::PersistTimeout () { NS_LOG_LOGIC ("PersistTimeout expired at "< p, Ipv4Address receiver, Ipv4Address s Ptr dev = m_ipv4->GetNetDevice (m_ipv4->GetInterfaceForAddress (receiver)); RoutingTableEntry newEntry (/*device=*/dev, /*dst=*/origin, /*validSeno=*/true, /*seqNo=*/rreqHeader.GetOriginSeqno (), /*iface=*/m_ipv4->GetAddress (m_ipv4->GetInterfaceForAddress (receiver), 0), /*hops=*/hop, - /*nextHop*/src, /*timeLife=*/2 * NetTraversalTime.To () - 2 * hop * NodeTraversalTime.To ()); + /*nextHop*/src, /*timeLife=*/Time (2 * NetTraversalTime - 2 * hop * NodeTraversalTime)); m_routingTable.AddRoute (newEntry); } else @@ -988,7 +988,7 @@ RoutingProtocol::RecvRequest (Ptr p, Ipv4Address receiver, Ipv4Address s toOrigin.SetOutputDevice (m_ipv4->GetNetDevice (m_ipv4->GetInterfaceForAddress (receiver))); toOrigin.SetInterface (m_ipv4->GetAddress (m_ipv4->GetInterfaceForAddress (receiver), 0)); toOrigin.SetHop (hop); - toOrigin.SetLifeTime (std::max (Time (2 * NetTraversalTime.To () - 2 * hop * NodeTraversalTime.To ()), toOrigin.GetLifeTime ())); + toOrigin.SetLifeTime (std::max (Time (2 * NetTraversalTime - 2 * hop * NodeTraversalTime), toOrigin.GetLifeTime ())); m_routingTable.Update (toOrigin); } NS_LOG_LOGIC (receiver << " receive RREQ to destination " << rreqHeader.GetDst ()); @@ -1055,7 +1055,7 @@ RoutingProtocol::RecvRequest (Ptr p, Ipv4Address receiver, Ipv4Address s { m_htimer.Cancel (); int rng = UniformVariable().GetInteger (0, 10); - m_htimer.Schedule (HelloInterval - 0.1 * MilliSeconds(rng).To ()); + m_htimer.Schedule (Time (HelloInterval - 0.1 * MilliSeconds(rng))); } } @@ -1302,7 +1302,7 @@ RoutingProtocol::ProcessHello (RrepHeader const & rrepHeader, Ipv4Address receiv } else { - toNeighbor.SetLifeTime (std::max (Time (AllowedHelloLoss * HelloInterval.To ()), toNeighbor.GetLifeTime ())); + toNeighbor.SetLifeTime (std::max (Time (AllowedHelloLoss * HelloInterval), toNeighbor.GetLifeTime ())); toNeighbor.SetSeqNo (rrepHeader.GetDstSeqno ()); toNeighbor.SetValidSeqNo (true); toNeighbor.SetFlag (VALID); @@ -1312,7 +1312,7 @@ RoutingProtocol::ProcessHello (RrepHeader const & rrepHeader, Ipv4Address receiv } if (EnableHello) { - m_nb.Update (rrepHeader.GetDst (), AllowedHelloLoss * HelloInterval.To ()); + m_nb.Update (rrepHeader.GetDst (), Time (AllowedHelloLoss * HelloInterval)); } } @@ -1423,7 +1423,7 @@ RoutingProtocol::HelloTimerExpire () SendHello (); m_htimer.Cancel (); int rng = UniformVariable().GetInteger (0, 100); - Time t = 0.01 * MilliSeconds(rng).To (); + Time t = Time (0.01 * MilliSeconds(rng)); m_htimer.Schedule (HelloInterval - t); } @@ -1457,7 +1457,7 @@ RoutingProtocol::SendHello () Ptr socket = j->first; Ipv4InterfaceAddress iface = j->second; RrepHeader helloHeader (/*prefix size=*/0, /*hops=*/0, /*dst=*/iface.GetLocal (), /*dst seqno=*/m_seqNo, - /*origin=*/iface.GetLocal (),/*lifetime=*/AllowedHelloLoss * HelloInterval.To ()); + /*origin=*/iface.GetLocal (),/*lifetime=*/Time (AllowedHelloLoss * HelloInterval)); Ptr packet = Create (); packet->AddHeader (helloHeader); TypeHeader tHeader (AODVTYPE_RREP); diff --git a/src/routing/aodv/test/aodv-regression.cc b/src/routing/aodv/test/aodv-regression.cc index a4b4c210a..7f46da753 100644 --- a/src/routing/aodv/test/aodv-regression.cc +++ b/src/routing/aodv/test/aodv-regression.cc @@ -101,7 +101,7 @@ ChainRegressionTest::DoRun () // At m_time / 3 move central node away and see what will happen Ptr node = m_nodes->Get (m_size / 2); Ptr mob = node->GetObject (); - Simulator::Schedule (m_time.To () / 3, &MobilityModel::SetPosition, mob, Vector (1e5, 1e5, 1e5)); + Simulator::Schedule (Time (m_time / 3), &MobilityModel::SetPosition, mob, Vector (1e5, 1e5, 1e5)); Simulator::Stop (m_time); Simulator::Run (); diff --git a/src/routing/olsr/olsr-routing-protocol.cc b/src/routing/olsr/olsr-routing-protocol.cc index ddd781835..d85beaf34 100644 --- a/src/routing/olsr/olsr-routing-protocol.cc +++ b/src/routing/olsr/olsr-routing-protocol.cc @@ -73,15 +73,15 @@ /********** Holding times **********/ /// Neighbor holding time. -#define OLSR_NEIGHB_HOLD_TIME (3 * OLSR_REFRESH_INTERVAL.To ()) +#define OLSR_NEIGHB_HOLD_TIME Time (3 * OLSR_REFRESH_INTERVAL) /// Top holding time. -#define OLSR_TOP_HOLD_TIME (3 * m_tcInterval.To ()) +#define OLSR_TOP_HOLD_TIME Time (3 * m_tcInterval) /// Dup holding time. #define OLSR_DUP_HOLD_TIME Seconds (30) /// MID holding time. -#define OLSR_MID_HOLD_TIME (3 * m_midInterval.To ()) +#define OLSR_MID_HOLD_TIME Time (3 * m_midInterval) /// HNA holding time. -#define OLSR_HNA_HOLD_TIME (3 * m_hnaInterval.To ()) +#define OLSR_HNA_HOLD_TIME Time (3 * m_hnaInterval) /********** Link types **********/ diff --git a/src/simulator/nstime.h b/src/simulator/nstime.h index 76db04dc0..5aa3939c3 100644 --- a/src/simulator/nstime.h +++ b/src/simulator/nstime.h @@ -430,17 +430,17 @@ public: } return retval; } - inline Time (const int64x64_t &value) + inline operator int64x64_t () const + { + return int64x64_t (m_data); + } + explicit inline Time (const int64x64_t &value) : m_data (value.GetHigh ()) {} inline static Time From (const int64x64_t &value) { return Time (value); } - inline int64x64_t To (void) const - { - return int64x64_t (m_data); - } private: struct Information diff --git a/src/simulator/time.cc b/src/simulator/time.cc index 50688b77d..9c0ac1c8d 100644 --- a/src/simulator/time.cc +++ b/src/simulator/time.cc @@ -165,7 +165,7 @@ operator<< (std::ostream& os, const Time & time) unit = "unreachable"; break; } - int64x64_t v = time.To (); + int64x64_t v = time; os << v << unit; return os; }