introduce implicit conversion operator

This commit is contained in:
Mathieu Lacage
2010-08-25 21:31:43 +02:00
parent 22474ffee1
commit cb0c39edda
14 changed files with 46 additions and 48 deletions

View File

@@ -98,7 +98,7 @@ DelayJitterEstimation::RecordRx (Ptr<const Packet> 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 ();

View File

@@ -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);
}

View File

@@ -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;
}

View File

@@ -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:

View File

@@ -189,7 +189,7 @@ WaveformGenerator::GenerateWaveform ()
NS_LOG_FUNCTION (this);
Ptr<PacketBurst> pb = Create<PacketBurst> ();
Time duration = m_period.To () * m_dutyCycle;
Time duration = Time (m_period * m_dutyCycle);
NS_LOG_LOGIC ("generating waveform : " << *m_txPowerSpectralDensity);
m_phyTxStartTrace (0);

View File

@@ -987,7 +987,7 @@ MacLow::CalculateOverallTxTime (Ptr<const Packet> 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 ());

View File

@@ -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: "<<job->GetDeadline ().GetSeconds () << " frame start: "<<GetBs ()->m_frameStartTime.GetSeconds ()

View File

@@ -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<RttEstimator> RttMeanDeviation::Copy () const

View File

@@ -1651,7 +1651,7 @@ void TcpSocketImpl::LastAckTimeout ()
void TcpSocketImpl::PersistTimeout ()
{
NS_LOG_LOGIC ("PersistTimeout expired at "<<Simulator::Now ().GetSeconds ());
m_persistTime = 2 * m_persistTime.To ();
m_persistTime = Time (2 * m_persistTime);
m_persistTime = std::min(Seconds(60),m_persistTime); //maxes out at 60
//the persist timeout sends exactly one byte probes
//this is explicit in stevens, and kind of in rfc793 p42, rfc1122 sec4.2.2.17

View File

@@ -99,15 +99,15 @@ RoutingProtocol::RoutingProtocol () :
ActiveRouteTimeout (Seconds (3)),
NetDiameter (35),
NodeTraversalTime (MilliSeconds (40)),
NetTraversalTime (2 * NetDiameter * NodeTraversalTime.To ()),
PathDiscoveryTime ( 2 * NetTraversalTime.To ()),
MyRouteTimeout (2 * std::max (PathDiscoveryTime, ActiveRouteTimeout).To ()),
NetTraversalTime (2 * NetDiameter * NodeTraversalTime),
PathDiscoveryTime ( 2 * NetTraversalTime),
MyRouteTimeout (2 * std::max (PathDiscoveryTime, ActiveRouteTimeout)),
HelloInterval(Seconds (1)),
AllowedHelloLoss (2),
DeletePeriod (5 * std::max(ActiveRouteTimeout, HelloInterval).To ()),
DeletePeriod (5 * std::max(ActiveRouteTimeout, HelloInterval)),
NextHopWait (NodeTraversalTime + MilliSeconds (10)),
TimeoutBuffer (2),
BlackListTimeout(RreqRetries * NetTraversalTime.To ()),
BlackListTimeout(RreqRetries * NetTraversalTime),
MaxQueueLen (64),
MaxQueueTime (Seconds(30)),
DestinationOnly (false),
@@ -817,7 +817,7 @@ RoutingProtocol::SendRequest (Ipv4Address dst)
{
m_htimer.Cancel ();
int rng = UniformVariable ().GetInteger (0, 10);
m_htimer.Schedule (HelloInterval - 0.01 * MilliSeconds (rng).To ());
m_htimer.Schedule (HelloInterval - Time (0.01 * MilliSeconds (rng)));
}
}
@@ -837,7 +837,7 @@ RoutingProtocol::ScheduleRreqRetry (Ipv4Address dst)
m_routingTable.LookupRoute (dst, rt);
rt.IncrementRreqCnt ();
m_routingTable.Update (rt);
m_addressReqTimer[dst].Schedule (rt.GetRreqCnt () * NetTraversalTime.To ());
m_addressReqTimer[dst].Schedule (Time (rt.GetRreqCnt () * NetTraversalTime));
}
void
@@ -971,7 +971,7 @@ RoutingProtocol::RecvRequest (Ptr<Packet> p, Ipv4Address receiver, Ipv4Address s
Ptr<NetDevice> 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<Packet> 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<Packet> 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> 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> packet = Create<Packet> ();
packet->AddHeader (helloHeader);
TypeHeader tHeader (AODVTYPE_RREP);

View File

@@ -101,7 +101,7 @@ ChainRegressionTest::DoRun ()
// At m_time / 3 move central node away and see what will happen
Ptr<Node> node = m_nodes->Get (m_size / 2);
Ptr<MobilityModel> mob = node->GetObject<MobilityModel> ();
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 ();

View File

@@ -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 **********/

View File

@@ -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

View File

@@ -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;
}