get rid of Scalar and co.
authorMathieu Lacage <mathieu.lacage@sophia.inria.fr>
Wed, 25 Aug 2010 16:45:59 +0200
changeset 7040 444bb5c76bff
parent 7039 c3854df95603
child 7041 70c8f8e0b08d
get rid of Scalar and co.
src/applications/onoff/onoff-application.cc
src/contrib/delay-jitter-estimation.cc
src/contrib/delay-jitter-estimation.h
src/contrib/flow-monitor/flow-probe.h
src/contrib/stats/time-data-calculators.cc
src/devices/csma/backoff.cc
src/devices/mesh/dot11s/hwmp-protocol.cc
src/devices/spectrum/waveform-generator.cc
src/devices/spectrum/waveform-generator.h
src/devices/wifi/mac-low.cc
src/devices/wimax/bs-uplink-scheduler-mbqos.cc
src/internet-stack/rtt-estimator.cc
src/internet-stack/rtt-estimator.h
src/internet-stack/tcp-socket-impl.cc
src/routing/aodv/aodv-routing-protocol.cc
src/routing/aodv/test/aodv-regression.cc
src/routing/olsr/olsr-routing-protocol.cc
src/simulator/int64x64-cairo.cc
src/simulator/int64x64-cairo.h
src/simulator/int64x64.cc
src/simulator/int64x64.h
src/simulator/nstime.h
src/simulator/time.cc
--- a/src/applications/onoff/onoff-application.cc	Wed Aug 25 10:44:21 2010 +0200
+++ b/src/applications/onoff/onoff-application.cc	Wed Aug 25 16:45:59 2010 +0200
@@ -167,8 +167,8 @@
     { // Cancel the pending send packet event
       // Calculate residual bits since last packet sent
       Time delta(Simulator::Now() - m_lastStartTime);
-      Scalar bits = delta * Scalar (m_cbrRate.GetBitRate ()) / Seconds (1.0);
-      m_residualBits += bits;
+      int64x64_t bits = delta.To(Time::S) * m_cbrRate.GetBitRate ();
+      m_residualBits += bits.GetHigh ();
     }
   Simulator::Cancel(m_sendEvent);
   Simulator::Cancel(m_startStopEvent);
--- a/src/contrib/delay-jitter-estimation.cc	Wed Aug 25 10:44:21 2010 +0200
+++ b/src/contrib/delay-jitter-estimation.cc	Wed Aug 25 16:45:59 2010 +0200
@@ -76,7 +76,7 @@
 DelayJitterEstimation::DelayJitterEstimation ()
   : m_previousRx (Simulator::Now ()),
     m_previousRxTx (Simulator::Now ()),
-    m_jitter (Seconds (0.0)),
+    m_jitter (0),
     m_delay (Seconds (0.0))
 {}
 void 
@@ -98,7 +98,7 @@
   tag.GetTxTime ();
 
   Time delta = (Simulator::Now () - m_previousRx) - (tag.GetTxTime () - m_previousRxTx);
-  m_jitter += (Abs (delta) - m_jitter ) / Scalar (16.0);
+  m_jitter += (Abs (delta).To () - m_jitter) / 16;
   m_previousRx = Simulator::Now ();
   m_previousRxTx = tag.GetTxTime ();
   m_delay = Simulator::Now () - tag.GetTxTime ();
@@ -109,10 +109,10 @@
 {
   return m_delay;
 }
-Time
+uint64_t
 DelayJitterEstimation::GetLastJitter (void) const
 {
-  return m_jitter;
+  return m_jitter.GetHigh ();
 }
 
 } // namespace ns3
--- a/src/contrib/delay-jitter-estimation.h	Wed Aug 25 10:44:21 2010 +0200
+++ b/src/contrib/delay-jitter-estimation.h	Wed Aug 25 16:45:59 2010 +0200
@@ -45,12 +45,12 @@
    *
    * \returns the updated jitter.
    */
-  Time GetLastJitter (void) const;
+  uint64_t GetLastJitter (void) const;
 
 private:
   Time m_previousRx;
   Time m_previousRxTx;
-  Time m_jitter;
+  int64x64_t m_jitter;
   Time m_delay;
 };
 
--- a/src/contrib/flow-monitor/flow-probe.h	Wed Aug 25 10:44:21 2010 +0200
+++ b/src/contrib/flow-monitor/flow-probe.h	Wed Aug 25 16:45:59 2010 +0200
@@ -57,7 +57,7 @@
     std::vector<uint32_t> packetsDropped;
     /// bytesDropped[reasonCode] => number of dropped bytes
     std::vector<uint64_t> bytesDropped;
-    /// divide by 'Scalar (packets)' to get the average delay from the
+    /// divide by 'packets' to get the average delay from the
     /// first (entry) probe up to this one (partial delay)
     Time delayFromFirstProbeSum;
     /// Number of bytes seen of this flow
--- a/src/contrib/stats/time-data-calculators.cc	Wed Aug 25 10:44:21 2010 +0200
+++ b/src/contrib/stats/time-data-calculators.cc	Wed Aug 25 16:45:59 2010 +0200
@@ -73,7 +73,7 @@
   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/Scalar(m_count));
+    callback.OutputSingleton(m_context, m_key + "-average", m_total.To () / m_count);
     callback.OutputSingleton(m_context, m_key + "-max", m_max);
     callback.OutputSingleton(m_context, m_key + "-min", m_min);
   }
--- a/src/devices/csma/backoff.cc	Wed Aug 25 10:44:21 2010 +0200
+++ b/src/devices/csma/backoff.cc	Wed Aug 25 16:45:59 2010 +0200
@@ -67,8 +67,8 @@
 
   uint32_t backoffSlots = (uint32_t)m_rng.GetValue(minSlot, maxSlot);
 
-  backoff = Scalar (backoffSlots) * m_slotTime;
-  return (backoff);
+  backoff = backoffSlots * m_slotTime.To ();
+  return backoff;
 }
 
 void 
--- a/src/devices/mesh/dot11s/hwmp-protocol.cc	Wed Aug 25 10:44:21 2010 +0200
+++ b/src/devices/mesh/dot11s/hwmp-protocol.cc	Wed Aug 25 16:45:59 2010 +0200
@@ -963,7 +963,7 @@
   if (i == m_preqTimeouts.end ())
     {
       m_preqTimeouts[dst].preqTimeout = Simulator::Schedule (
-          m_dot11MeshHWMPnetDiameterTraversalTime * Scalar (2),
+          Time (m_dot11MeshHWMPnetDiameterTraversalTime.To () * 2),
           &HwmpProtocol::RetryPathDiscovery, this, dst, 1);
       m_preqTimeouts[dst].whenScheduled = Simulator::Now ();
       return true;
@@ -1009,7 +1009,7 @@
       i->second->RequestDestination (dst, originator_seqno, dst_seqno);
     }
   m_preqTimeouts[dst].preqTimeout = Simulator::Schedule (
-      Scalar (2 * (numOfRetry + 1)) *  m_dot11MeshHWMPnetDiameterTraversalTime,
+      Time ((2 * (numOfRetry + 1)) *  m_dot11MeshHWMPnetDiameterTraversalTime.To ()),
       &HwmpProtocol::RetryPathDiscovery, this, dst, numOfRetry);
 }
 //Proactive PREQ routines:
--- a/src/devices/spectrum/waveform-generator.cc	Wed Aug 25 10:44:21 2010 +0200
+++ b/src/devices/spectrum/waveform-generator.cc	Wed Aug 25 16:45:59 2010 +0200
@@ -173,7 +173,7 @@
 void
 WaveformGenerator::SetDutyCycle (double dutyCycle)
 {
-  m_dutyCycle = Scalar (dutyCycle);
+  m_dutyCycle = dutyCycle;
 }
 
 double WaveformGenerator::GetDutyCycle () const
@@ -189,7 +189,7 @@
   NS_LOG_FUNCTION (this);
 
   Ptr<PacketBurst> pb = Create<PacketBurst> ();
-  Time duration = m_period * m_dutyCycle;
+  Time duration = m_period.To () * m_dutyCycle;
   
   NS_LOG_LOGIC ("generating waveform : " << *m_txPowerSpectralDensity);
   m_phyTxStartTrace (0);
--- a/src/devices/spectrum/waveform-generator.h	Wed Aug 25 10:44:21 2010 +0200
+++ b/src/devices/spectrum/waveform-generator.h	Wed Aug 25 16:45:59 2010 +0200
@@ -136,7 +136,7 @@
 
   Ptr<SpectrumValue> m_txPowerSpectralDensity;
   Time   m_period;
-  Scalar m_dutyCycle;
+  double m_dutyCycle;
   Time m_startTime;
   bool m_active;
 
--- a/src/devices/wifi/mac-low.cc	Wed Aug 25 10:44:21 2010 +0200
+++ b/src/devices/wifi/mac-low.cc	Wed Aug 25 16:45:59 2010 +0200
@@ -987,7 +987,7 @@
     {
       txTime += m_phy->CalculateTxDuration (GetRtsSize (), rtsMode, WIFI_PREAMBLE_LONG);
       txTime += GetCtsDuration (hdr->GetAddr1 (), rtsMode);
-      txTime += GetSifs () * Scalar (2);
+      txTime += GetSifs ().To () * 2;
     }
   uint32_t dataSize = GetSize (packet, hdr);
   txTime += m_phy->CalculateTxDuration (dataSize, dataMode, WIFI_PREAMBLE_LONG);
@@ -1047,7 +1047,7 @@
           cts.SetType (WIFI_MAC_CTL_CTS);
           Time navCounterResetCtsMissedDelay = 
             m_phy->CalculateTxDuration (cts.GetSerializedSize (), txMode, preamble) +
-            Scalar (2) * GetSifs () + Scalar (2) * GetSlotTime ();
+            2 * GetSifs ().To () + 2 * GetSlotTime ().To ();
           m_navCounterResetCtsMissed = Simulator::Schedule (navCounterResetCtsMissedDelay,
                                                             &MacLow::NavCounterResetCtsMissed, this,
                                                             Simulator::Now ());
--- a/src/devices/wimax/bs-uplink-scheduler-mbqos.cc	Wed Aug 25 10:44:21 2010 +0200
+++ b/src/devices/wimax/bs-uplink-scheduler-mbqos.cc	Wed Aug 25 16:45:59 2010 +0200
@@ -314,7 +314,7 @@
                       uInterval =
                         MilliSeconds ((*(ssRecord->GetServiceFlows (ServiceFlow::SF_TYPE_UGS).begin ()))->GetUnsolicitedGrantInterval ());
 
-                      Scalar frame = ((timestamp - Simulator::Now ()) / frame_duration);
+                      int64x64_t frame = ((timestamp - Simulator::Now ()).To () / frame_duration.To ());
 
                       if (frame <= 1)
                         {
@@ -668,7 +668,7 @@
               Time deadline = job->GetDeadline ();
               Time frame_duration = GetBs ()->GetPhy ()->GetFrameDuration ();
 
-              Scalar frame = ((deadline - Simulator::Now ()) / frame_duration);
+              int64x64_t frame = ((deadline - Simulator::Now ()).To () / frame_duration.To ());
 
               NS_LOG_DEBUG ("At " << Simulator::Now ().GetSeconds () << " reserved traffic rate: "
                                 << job->GetServiceFlow ()->GetMinReservedTrafficRate ()
--- a/src/internet-stack/rtt-estimator.cc	Wed Aug 25 10:44:21 2010 +0200
+++ b/src/internet-stack/rtt-estimator.cc	Wed Aug 25 16:45:59 2010 +0200
@@ -49,17 +49,41 @@
     .AddAttribute ("InitialEstimation", 
                    "XXX",
                    TimeValue (Seconds (1.0)),
-                   MakeTimeAccessor (&RttEstimator::est),
+                   MakeTimeAccessor (&RttEstimator::SetEstimate,
+                                     &RttEstimator::GetEstimate),
                    MakeTimeChecker ())
     .AddAttribute ("MinRTO", 
                    "Minimum retransmit timeout value",
                    TimeValue (Seconds (0.2)),
-                   MakeTimeAccessor (&RttEstimator::minrto),
+                   MakeTimeAccessor (&RttEstimator::SetMinRto,
+                                     &RttEstimator::GetMinRto),
                    MakeTimeChecker ())
     ;
   return tid;
 }
 
+void 
+RttEstimator::SetMinRto (Time minRto)
+{
+  minrto = minRto.To ();
+}
+Time 
+RttEstimator::GetMinRto (void) const
+{
+  return minrto;
+}
+void 
+RttEstimator::SetEstimate (Time estimate)
+{
+  est = estimate.To ();
+}
+Time 
+RttEstimator::GetEstimate (void) const
+{
+  return est;
+}
+
+
 //RttHistory methods
 RttHistory::RttHistory (SequenceNumber32 s, uint32_t c, Time t)
   : seq (s), count (c), time (t), retx (false)
@@ -161,7 +185,7 @@
 void RttEstimator::Reset ()
 { // Reset to initial state
   next = 1;
-  est = Seconds (1.0); // XXX: we should go back to the 'initial value' here. Need to add support in Object for this.
+  est = 1; // XXX: we should go back to the 'initial value' here. Need to add support in Object for this.
   history.clear ();         // Remove all info from the history
   nSamples = 0;
   ResetMultiplier ();
@@ -191,7 +215,7 @@
 }
 
 RttMeanDeviation::RttMeanDeviation() :
-  variance (ns3::Seconds(0)) 
+  variance (0) 
 { 
 }
 
@@ -202,18 +226,18 @@
 
 void RttMeanDeviation::Measurement (Time m)
 {
+  int64x64_t sample = m.To ();
   if (nSamples)
     { // Not first
-      Time err = m - est;
-      est = est + Scalar (gain) * err;         // estimated rtt
-      err = Abs (err);        // absolute value of error
-      variance = variance + Scalar (gain) * (err - variance); // variance of rtt
+      int64x64_t err = sample - est;
+      est = est + gain * err;         // estimated rtt
+      variance = variance + gain * (Abs (err) - variance); // variance of rtt
     }
   else
     { // First sample
-      est = m;                        // Set estimate to current
-      //variance = m / 2;               // And variance to current / 2
-      variance = m; // try this
+      est = sample;                        // Set estimate to current
+      //variance = sample / 2;               // And variance to current / 2
+      variance = sample; // try this
     }
   nSamples++;
 }
@@ -222,14 +246,14 @@
 {
   // If not enough samples, justjust return 2 times estimate   
   //if (nSamples < 2) return est * 2;
-  Time retval;
-  if (variance < est / Scalar (4.0))
+  int64x64_t retval;
+  if (variance < est / 4.0)
     {
-      retval = est * Scalar (2 * multiplier);            // At least twice current est
+      retval = est * 2 * multiplier;            // At least twice current est
     }
   else
     {
-      retval = (est + Scalar (4) * variance) * Scalar (multiplier); // As suggested by Jacobson
+      retval = (est + 4 * variance) * multiplier; // As suggested by Jacobson
     }
   retval = Max (retval, minrto);
   return retval;
@@ -242,7 +266,7 @@
 
 void RttMeanDeviation::Reset ()
 { // Reset to initial state
-  variance = Seconds (0.0);
+  variance = 0;
   RttEstimator::Reset ();
 }
 }//namepsace ns3
--- a/src/internet-stack/rtt-estimator.h	Wed Aug 25 10:44:21 2010 +0200
+++ b/src/internet-stack/rtt-estimator.h	Wed Aug 25 16:45:59 2010 +0200
@@ -62,7 +62,6 @@
   virtual Time AckSeq(SequenceNumber32);
   virtual void ClearSent();
   virtual void   Measurement(Time t) = 0;
-  virtual Time Estimate() = 0;
   virtual Time RetransmitTimeout() = 0;
   void Init(SequenceNumber32 s) { next = s;}
   virtual Ptr<RttEstimator> Copy() const = 0;
@@ -70,13 +69,18 @@
   virtual void ResetMultiplier();
   virtual void Reset();
 
+  void SetMinRto (Time minRto);
+  Time GetMinRto (void) const;
+  void SetEstimate (Time estimate);
+  Time GetEstimate (void) const;
+
 private:
   SequenceNumber32        next;    // Next expected sequence to be sent
   RttHistory_t history; // List of sent packet
   double m_maxMultiplier;
 public:
-  Time       est;     // Current estimate
-  Time       minrto; // minimum value of the timeout
+  int64x64_t       est;     // Current estimate
+  int64x64_t       minrto; // minimum value of the timeout
   uint32_t      nSamples;// Number of samples
   double       multiplier;   // RTO Multiplier
 };
@@ -100,8 +104,6 @@
     //Doc:Arg1 {\tt RttMeanDeviation} object to copy.
 
   void Measurement (Time);
-  Time Estimate () { return est;}
-  Time Variance () { return variance;}
   Time RetransmitTimeout ();
   Ptr<RttEstimator> Copy () const;
   void Reset ();
@@ -109,7 +111,7 @@
 
 public:
   double       gain;       // Filter gain
-  Time       variance;   // Current variance
+  int64x64_t   variance;   // Current variance
 };
 }//namespace ns3
 #endif
--- a/src/internet-stack/tcp-socket-impl.cc	Wed Aug 25 10:44:21 2010 +0200
+++ b/src/internet-stack/tcp-socket-impl.cc	Wed Aug 25 16:45:59 2010 +0200
@@ -1651,7 +1651,7 @@
 void TcpSocketImpl::PersistTimeout ()
 {
   NS_LOG_LOGIC ("PersistTimeout expired at "<<Simulator::Now ().GetSeconds ());
-  m_persistTime = Scalar(2)*m_persistTime;
+  m_persistTime = 2 * m_persistTime.To ();
   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
--- a/src/routing/aodv/aodv-routing-protocol.cc	Wed Aug 25 10:44:21 2010 +0200
+++ b/src/routing/aodv/aodv-routing-protocol.cc	Wed Aug 25 16:45:59 2010 +0200
@@ -99,15 +99,15 @@
   ActiveRouteTimeout (Seconds (3)),
   NetDiameter (35),
   NodeTraversalTime (MilliSeconds (40)),
-  NetTraversalTime (Scalar (2 * NetDiameter) * NodeTraversalTime),
-  PathDiscoveryTime ( Scalar (2) * NetTraversalTime),
-  MyRouteTimeout (Scalar (2) * std::max (PathDiscoveryTime, ActiveRouteTimeout)),
+  NetTraversalTime (2 * NetDiameter * NodeTraversalTime.To ()),
+  PathDiscoveryTime ( 2 * NetTraversalTime.To ()),
+  MyRouteTimeout (2 * std::max (PathDiscoveryTime, ActiveRouteTimeout).To ()),
   HelloInterval(Seconds (1)),
   AllowedHelloLoss (2),
-  DeletePeriod (Scalar(5) * std::max(ActiveRouteTimeout, HelloInterval)),
+  DeletePeriod (5 * std::max(ActiveRouteTimeout, HelloInterval).To ()),
   NextHopWait (NodeTraversalTime + MilliSeconds (10)),
   TimeoutBuffer (2),
-  BlackListTimeout(Scalar (RreqRetries) * NetTraversalTime),
+  BlackListTimeout(RreqRetries * NetTraversalTime.To ()),
   MaxQueueLen (64),
   MaxQueueTime (Seconds(30)),
   DestinationOnly (false),
@@ -816,7 +816,8 @@
   if (EnableHello)
     {
       m_htimer.Cancel ();
-      m_htimer.Schedule (HelloInterval - Scalar (0.01) * MilliSeconds (UniformVariable ().GetInteger (0, 10)));
+      int rng = UniformVariable ().GetInteger (0, 10);
+      m_htimer.Schedule (HelloInterval - 0.01 * MilliSeconds (rng).To ());
     }
 }
 
@@ -836,7 +837,7 @@
   m_routingTable.LookupRoute (dst, rt);
   rt.IncrementRreqCnt ();
   m_routingTable.Update (rt);
-  m_addressReqTimer[dst].Schedule (Scalar (rt.GetRreqCnt ()) * NetTraversalTime);
+  m_addressReqTimer[dst].Schedule (rt.GetRreqCnt () * NetTraversalTime.To ());
 }
 
 void
@@ -970,7 +971,7 @@
       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=*/Scalar (2) * NetTraversalTime - Scalar (2 * hop) * NodeTraversalTime);
+                                  /*nextHop*/src, /*timeLife=*/2 * NetTraversalTime.To () - 2 * hop * NodeTraversalTime.To ());
       m_routingTable.AddRoute (newEntry);
     }
   else
@@ -987,7 +988,7 @@
       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 (Scalar (2) * NetTraversalTime - Scalar (2 * hop) * NodeTraversalTime, toOrigin.GetLifeTime ()));
+      toOrigin.SetLifeTime (std::max (Time (2 * NetTraversalTime.To () - 2 * hop * NodeTraversalTime.To ()), toOrigin.GetLifeTime ()));
       m_routingTable.Update (toOrigin);
     }
   NS_LOG_LOGIC (receiver << " receive RREQ to destination " << rreqHeader.GetDst ());
@@ -1053,7 +1054,8 @@
   if (EnableHello)
     {
       m_htimer.Cancel ();
-      m_htimer.Schedule (HelloInterval - Scalar(0.1)*MilliSeconds(UniformVariable().GetInteger (0, 10)));
+      int rng = UniformVariable().GetInteger (0, 10);
+      m_htimer.Schedule (HelloInterval - 0.1 * MilliSeconds(rng).To ());
     }
 }
 
@@ -1300,7 +1302,7 @@
     }
   else
     {
-      toNeighbor.SetLifeTime (std::max (Scalar (AllowedHelloLoss) * HelloInterval, toNeighbor.GetLifeTime ()));
+      toNeighbor.SetLifeTime (std::max (Time (AllowedHelloLoss * HelloInterval.To ()), toNeighbor.GetLifeTime ()));
       toNeighbor.SetSeqNo (rrepHeader.GetDstSeqno ());
       toNeighbor.SetValidSeqNo (true);
       toNeighbor.SetFlag (VALID);
@@ -1310,7 +1312,7 @@
     }
   if (EnableHello)
     {
-      m_nb.Update (rrepHeader.GetDst (), Scalar (AllowedHelloLoss) * HelloInterval);
+      m_nb.Update (rrepHeader.GetDst (), AllowedHelloLoss * HelloInterval.To ());
     }
 }
 
@@ -1420,7 +1422,8 @@
   NS_LOG_FUNCTION (this);
   SendHello ();
   m_htimer.Cancel ();
-  Time t = Scalar(0.01)*MilliSeconds(UniformVariable().GetInteger (0, 100));
+  int rng = UniformVariable().GetInteger (0, 100);
+  Time t = 0.01 * MilliSeconds(rng).To ();
   m_htimer.Schedule (HelloInterval - t);
 }
 
@@ -1454,7 +1457,7 @@
       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=*/Scalar (AllowedHelloLoss) * HelloInterval);
+                              /*origin=*/iface.GetLocal (),/*lifetime=*/AllowedHelloLoss * HelloInterval.To ());
       Ptr<Packet> packet = Create<Packet> ();
       packet->AddHeader (helloHeader);
       TypeHeader tHeader (AODVTYPE_RREP);
--- a/src/routing/aodv/test/aodv-regression.cc	Wed Aug 25 10:44:21 2010 +0200
+++ b/src/routing/aodv/test/aodv-regression.cc	Wed Aug 25 16:45:59 2010 +0200
@@ -101,7 +101,7 @@
   // 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 / Scalar(3.0), &MobilityModel::SetPosition, mob, Vector (1e5, 1e5, 1e5));
+  Simulator::Schedule (m_time.To () / 3, &MobilityModel::SetPosition, mob, Vector (1e5, 1e5, 1e5));
 
   Simulator::Stop (m_time);
   Simulator::Run ();
--- a/src/routing/olsr/olsr-routing-protocol.cc	Wed Aug 25 10:44:21 2010 +0200
+++ b/src/routing/olsr/olsr-routing-protocol.cc	Wed Aug 25 16:45:59 2010 +0200
@@ -73,15 +73,15 @@
 /********** Holding times **********/
 
 /// Neighbor holding time.
-#define OLSR_NEIGHB_HOLD_TIME	(Scalar (3) * OLSR_REFRESH_INTERVAL)
+#define OLSR_NEIGHB_HOLD_TIME	(3 * OLSR_REFRESH_INTERVAL.To ())
 /// Top holding time.
-#define OLSR_TOP_HOLD_TIME	(Scalar (3) * m_tcInterval)
+#define OLSR_TOP_HOLD_TIME	(3 * m_tcInterval.To ())
 /// Dup holding time.
 #define OLSR_DUP_HOLD_TIME	Seconds (30)
 /// MID holding time.
-#define OLSR_MID_HOLD_TIME	(Scalar (3) * m_midInterval)
+#define OLSR_MID_HOLD_TIME	(3 * m_midInterval.To ())
 /// HNA holding time.
-#define OLSR_HNA_HOLD_TIME  (Scalar (3) * m_hnaInterval)
+#define OLSR_HNA_HOLD_TIME  (3 * m_hnaInterval.To ())
 
 /********** Link types **********/
 
--- a/src/simulator/int64x64-cairo.cc	Wed Aug 25 10:44:21 2010 +0200
+++ b/src/simulator/int64x64-cairo.cc	Wed Aug 25 16:45:59 2010 +0200
@@ -61,14 +61,14 @@
   //			2^128 a.h b.h + 2^64*(a.h b.l+b.h a.l) + a.l b.l
   // get the low part a.l b.l
   // multiply the fractional part
-  loPart = _cairo_int64x64_128_mul (a.lo, b.lo);
+  loPart = _cairo_uint64x64_128_mul (a.lo, b.lo);
   // compute the middle part 2^64*(a.h b.l+b.h a.l)
-  midPart = _cairo_uint128_add (_cairo_int64x64_128_mul (a.lo, b.hi),
-                                _cairo_int64x64_128_mul (a.hi, b.lo));
+  midPart = _cairo_uint128_add (_cairo_uint64x64_128_mul (a.lo, b.hi),
+                                _cairo_uint64x64_128_mul (a.hi, b.lo));
   // truncate the low part
   result.lo = _cairo_uint64_add (loPart.hi,midPart.lo);
   // compute the high part 2^128 a.h b.h
-  hiPart = _cairo_int64x64_128_mul (a.hi, b.hi);
+  hiPart = _cairo_uint64x64_128_mul (a.hi, b.hi);
   // truncate the high part and only use the low part
   result.hi = _cairo_uint64_add (hiPart.lo,midPart.hi);
   // if the high part is not zero, put a warning
@@ -124,9 +124,9 @@
 {
   cairo_uint128_t result;
   cairo_uint128_t hi, mid;
-  hi = _cairo_int64x64_128_mul (a.hi, b.hi);
-  mid = _cairo_uint128_add (_cairo_int64x64_128_mul (a.hi, b.lo),
-                           _cairo_int64x64_128_mul (a.lo, b.hi));
+  hi = _cairo_uint64x64_128_mul (a.hi, b.hi);
+  mid = _cairo_uint128_add (_cairo_uint64x64_128_mul (a.hi, b.lo),
+                           _cairo_uint64x64_128_mul (a.lo, b.hi));
   mid.lo = mid.hi;
   mid.hi = 0;
   result = _cairo_uint128_add (hi,mid);
--- a/src/simulator/int64x64-cairo.h	Wed Aug 25 10:44:21 2010 +0200
+++ b/src/simulator/int64x64-cairo.h	Wed Aug 25 16:45:59 2010 +0200
@@ -20,7 +20,7 @@
     _v.hi = 0;
     _v.lo = 0;
   }
-  explicit inline int64x64_t (double value)
+  inline int64x64_t (double value)
   {
 #define HPCAIRO_MAX_64 18446744073709551615.0
     double fhi = floor (value);
@@ -30,22 +30,37 @@
     _v.lo = lo;
 #undef HPCAIRO_MAX_64
   }
-  explicit inline int64x64_t (int v)
+  inline int64x64_t (int v)
+  {
+    _v.hi = v;
+    _v.lo = 0;
+  }
+  inline int64x64_t (long int v)
+  {
+    _v.hi = v;
+    _v.lo = 0;
+  }
+  inline int64x64_t (long long int v)
   {
     _v.hi = v;
     _v.lo = 0;
   }
-  explicit inline int64x64_t (long int v)
+  inline int64x64_t (unsigned int v)
   {
     _v.hi = v;
     _v.lo = 0;
   }
-  explicit inline int64x64_t (long long int v)
+  inline int64x64_t (unsigned long int v)
   {
     _v.hi = v;
     _v.lo = 0;
   }
-  explicit inline int64x64_t (int64_t hi, uint64_t lo)
+  inline int64x64_t (unsigned long long int v)
+  {
+    _v.hi = v;
+    _v.lo = 0;
+  }
+  inline int64x64_t (int64_t hi, uint64_t lo)
   {
     _v.hi = hi;
     _v.lo = lo;
@@ -96,10 +111,6 @@
   friend int64x64_t &operator -= (int64x64_t &lhs, const int64x64_t &rhs);
   friend int64x64_t &operator *= (int64x64_t &lhs, const int64x64_t &rhs);
   friend int64x64_t &operator /= (int64x64_t &lhs, const int64x64_t &rhs);
-  friend int64x64_t operator + (const int64x64_t &lhs, const int64x64_t &rhs);
-  friend int64x64_t operator - (const int64x64_t &lhs, const int64x64_t &rhs);
-  friend int64x64_t operator * (const int64x64_t &lhs, const int64x64_t &rhs);
-  friend int64x64_t operator / (const int64x64_t &lhs, const int64x64_t &rhs);
   friend int64x64_t operator + (const int64x64_t &lhs);
   friend int64x64_t operator - (const int64x64_t &lhs);
   friend int64x64_t operator ! (const int64x64_t &lhs);
--- a/src/simulator/int64x64.cc	Wed Aug 25 10:44:21 2010 +0200
+++ b/src/simulator/int64x64.cc	Wed Aug 25 16:45:59 2010 +0200
@@ -275,6 +275,10 @@
   // Below, the division loses precision because 2/3 is not
   // representable exactly in 64.64 integers. So, we got
   // something super close but the final rounding kills us.
+  a = V(2);
+  b = V(3);
+  a /= b;
+  a *= b;
   CHECK_EXPECTED (V(2) / V(3) * V(3), 1);
 
   // The example below shows that we really do not lose
--- a/src/simulator/int64x64.h	Wed Aug 25 10:44:21 2010 +0200
+++ b/src/simulator/int64x64.h	Wed Aug 25 16:45:59 2010 +0200
@@ -15,37 +15,88 @@
 
 namespace ns3 {
 
-inline int64x64_t operator + (const int64x64_t &lhs, const int64x64_t &rhs)
-{
-  int64x64_t tmp = lhs;
-  tmp += rhs;
-  return tmp;
-}
-
-inline int64x64_t operator - (const int64x64_t &lhs, const int64x64_t &rhs)
-{
-  int64x64_t tmp = lhs;
-  tmp -= rhs;
-  return tmp;
-}
+#define INT64X64_OP_ARITH_TYPE(op,type)					\
+  inline int64x64_t operator op (const int64x64_t &lhs, const type &rhs) \
+  {									\
+    int64x64_t tmp = lhs;						\
+    tmp op##= int64x64_t (rhs);						\
+    return tmp;								\
+  }									\
+  inline int64x64_t operator op (const type &lhs, const int64x64_t &rhs) \
+  {									\
+    int64x64_t tmp = int64x64_t (lhs);					\
+    tmp op##= rhs;							\
+    return tmp;								\
+  }
 
-inline int64x64_t operator * (const int64x64_t &lhs, const int64x64_t &rhs)
-{
-  int64x64_t tmp = lhs;
-  tmp *= rhs;
-  return tmp;
-}
+#define INT64X64_OP_ARITH(op)						\
+  inline int64x64_t operator op (const int64x64_t &lhs, const int64x64_t &rhs) \
+  {									\
+    int64x64_t tmp = lhs;						\
+    tmp op##= rhs;							\
+    return tmp;								\
+  }									\
+  INT64X64_OP_ARITH_TYPE(op,double)					\
+    INT64X64_OP_ARITH_TYPE(op,signed char)				\
+    INT64X64_OP_ARITH_TYPE(op,signed short)				\
+    INT64X64_OP_ARITH_TYPE(op,signed int)				\
+    INT64X64_OP_ARITH_TYPE(op,signed long int)				\
+    INT64X64_OP_ARITH_TYPE(op,signed long long int)			\
+    INT64X64_OP_ARITH_TYPE(op,unsigned char)				\
+    INT64X64_OP_ARITH_TYPE(op,unsigned short)				\
+    INT64X64_OP_ARITH_TYPE(op,unsigned int)				\
+    INT64X64_OP_ARITH_TYPE(op,unsigned long int)			\
+    INT64X64_OP_ARITH_TYPE(op,unsigned long long int)
 
-inline int64x64_t operator / (const int64x64_t &lhs, const int64x64_t &rhs)
-{
-  int64x64_t tmp = lhs;
-  tmp /= rhs;
-  return tmp;
-}
+#define INT64X64_OP_CMP_TYPE(op,type)					\
+  inline bool operator op (const int64x64_t &lhs, const type &rhs)	\
+  {									\
+    return lhs op int64x64_t (rhs);					\
+  }									\
+  inline bool operator op (const type &lhs, const int64x64_t &rhs)	\
+  {									\
+    return int64x64_t (lhs) op rhs;					\
+  }
+
+#define INT64X64_OP_CMP(op)						\
+  INT64X64_OP_CMP_TYPE(op,double)					\
+    INT64X64_OP_CMP_TYPE(op,signed int)					\
+    INT64X64_OP_CMP_TYPE(op,signed long int)				\
+    INT64X64_OP_CMP_TYPE(op,signed long long int)			\
+    INT64X64_OP_CMP_TYPE(op,unsigned int)				\
+    INT64X64_OP_CMP_TYPE(op,unsigned long int)				\
+    INT64X64_OP_CMP_TYPE(op,unsigned long long int)
+
+
+INT64X64_OP_ARITH(+)
+INT64X64_OP_ARITH(-)
+INT64X64_OP_ARITH(*)
+INT64X64_OP_ARITH(/)
+INT64X64_OP_CMP(==)
+INT64X64_OP_CMP(!=)
+INT64X64_OP_CMP(<)
+INT64X64_OP_CMP(<=)
+INT64X64_OP_CMP(>)
+INT64X64_OP_CMP(>=)
 
 std::ostream &operator << (std::ostream &os, const int64x64_t &val);
 std::istream &operator << (std::istream &is, int64x64_t &val);
 
+inline int64x64_t Abs (const int64x64_t &value)
+{
+  return (value < 0)?-value:value;
+}
+
+inline int64x64_t Min (const int64x64_t &a, const int64x64_t &b)
+{
+  return (a < b)?a:b;
+}
+
+inline int64x64_t Max (const int64x64_t &a, const int64x64_t &b)
+{
+  return (a > b)?a:b;
+}
+
 } // namespace ns3
 
 #endif /* INT64X64_H */
--- a/src/simulator/nstime.h	Wed Aug 25 10:44:21 2010 +0200
+++ b/src/simulator/nstime.h	Wed Aug 25 16:45:59 2010 +0200
@@ -23,14 +23,13 @@
 #include "ns3/assert.h"
 #include "ns3/attribute.h"
 #include "ns3/attribute-helper.h"
+#include "int64x64.h"
 #include <stdint.h>
 #include <math.h>
 #include <ostream>
 
 namespace ns3 {
 
-typedef uint64_t Scalar;
-
 /**
  * \ingroup simulator
  * \defgroup time Time
@@ -52,7 +51,7 @@
  * multiply multiple TimeUnit objects. The return type of any such
  * arithmetic expression is always a TimeUnit object.
  *
- * The ns3::Scalar, ns3::Time, ns3::TimeSquare, and ns3::TimeInvert classes
+ * The ns3::uint64_t, ns3::Time, ns3::TimeSquare, and ns3::TimeInvert classes
  * are aliases for the TimeUnit<0>, TimeUnit<1>, TimeUnit<2> and TimeUnit<-1>
  * types respectively.
  *
@@ -65,7 +64,7 @@
  * Time<3> t5 = t3 * t1;
  * Time<-2> t6 = t1 / t5;
  * TimeSquare t7 = t3;
- * Scalar s = t4;
+ * uint64_t s = t4;
  * \endcode
  *
  * If you try to assign the result of an expression which does not
@@ -90,7 +89,7 @@
  * ==, !=, <, >, <=, >=. It is thus easy to add, substract, or
  * multiply multiple Time objects.
  *
- * The ns3::Scalar, ns3::TimeSquare, and ns3::TimeInvert classes
+ * The ns3::uint64_t, ns3::TimeSquare, and ns3::TimeInvert classes
  * are backward-compatibility aliases for ns3::Time.
  *
  * For example:
@@ -262,7 +261,7 @@
    */
   inline double GetSeconds (void) const
   {
-    return ToDouble (*this, Time::S);
+    return ToDouble (Time::S);
   }
 
   /**
@@ -271,7 +270,7 @@
    */
   inline int64_t GetMilliSeconds (void) const
   {
-    return ToInteger (*this, Time::MS);
+    return ToInteger (Time::MS);
   }
   /**
    * \returns an approximation in microseconds of the time stored in this
@@ -279,7 +278,7 @@
    */
   inline int64_t GetMicroSeconds (void) const
   {
-    return ToInteger (*this, Time::US);
+    return ToInteger (Time::US);
   }
   /**
    * \returns an approximation in nanoseconds of the time stored in this
@@ -287,7 +286,7 @@
    */
   inline int64_t GetNanoSeconds (void) const
   {
-    return ToInteger (*this, Time::NS);
+    return ToInteger (Time::NS);
   }
   /**
    * \returns an approximation in picoseconds of the time stored in this
@@ -295,7 +294,7 @@
    */
   inline int64_t GetPicoSeconds (void) const
   {
-    return ToInteger (*this, Time::PS);
+    return ToInteger (Time::PS);
   }
   /**
    * \returns an approximation in femtoseconds of the time stored in this
@@ -303,7 +302,7 @@
    */
   inline int64_t GetFemtoSeconds (void) const
   {
-    return ToInteger (*this, Time::FS);
+    return ToInteger (Time::FS);
   }
   /**
    * \returns an approximation of the time stored in this
@@ -359,32 +358,16 @@
     return Time (value);
   }
   /**
-   * \param value to convert into a Time object
-   * \param timeUnit the unit of the value to convert
-   * \return a new Time object
-   *
-   * \sa FromInteger, ToInteger, ToDouble
-   */
-  inline static Time FromDouble (double value, enum Unit timeUnit)
-  {
-    struct Information *info = PeekInformation (timeUnit);
-    // DO NOT REMOVE this temporary variable. It's here
-    // to work around a compiler bug in gcc 3.4
-    double retval = value;
-    retval *= info->timeFrom;
-    return Time (retval);
-  }
-  /**
    * \param time a Time object
    * \param timeUnit the unit of the value to return
    *
    * Convert the input time into an integer value according to the requested
    * time unit.
    */
-  inline static int64_t ToInteger (const Time &time, enum Unit timeUnit)
+  inline int64_t ToInteger (enum Unit timeUnit) const
   {
     struct Information *info = PeekInformation (timeUnit);
-    int64_t v = time.m_data;
+    int64_t v = m_data;
     if (info->toMul)
       {
         v *= info->factor;
@@ -396,19 +379,68 @@
     return v;
   }
   /**
+   * \param value to convert into a Time object
+   * \param timeUnit the unit of the value to convert
+   * \return a new Time object
+   *
+   * \sa FromInteger, ToInteger, ToDouble
+   */
+  inline static Time FromDouble (double value, enum Unit timeUnit)
+  {
+    return From (int64x64_t (value), timeUnit);
+  }
+  /**
    * \param time a Time object
    * \param timeUnit the unit of the value to return
    *
    * Convert the input time into a floating point value according to the requested
    * time unit.
    */
-  inline static double ToDouble (const Time &time, enum Unit timeUnit)
+  inline double ToDouble (enum Unit timeUnit) const
+  {
+    return To (timeUnit).GetDouble ();
+  }
+  static inline Time From (const int64x64_t &from, enum Unit timeUnit)
   {
     struct Information *info = PeekInformation (timeUnit);
-    double retval = time.m_data;
-    retval *= info->timeTo;
+    // DO NOT REMOVE this temporary variable. It's here
+    // to work around a compiler bug in gcc 3.4
+    int64x64_t retval = from; 
+    if (info->fromMul)
+      {
+        retval *= info->timeFrom;
+      }
+    else
+      {
+        retval.MulByInvert (info->timeFrom);
+      }
+    return Time (retval);
+  }
+  inline int64x64_t To (enum Unit timeUnit) const
+  {
+    struct Information *info = PeekInformation (timeUnit);
+    int64x64_t retval = int64x64_t (m_data);
+    if (info->toMul)
+      {
+        retval *= info->timeTo;
+      }
+    else
+      {
+        retval.MulByInvert (info->timeTo);
+      }
     return retval;
   }
+  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
@@ -416,8 +448,8 @@
     bool toMul;
     bool fromMul;
     uint64_t factor;
-    double timeTo;
-    double timeFrom;
+    int64x64_t timeTo;
+    int64x64_t timeFrom;
   };
   struct Resolution
   {
@@ -446,14 +478,8 @@
   friend bool operator > (const Time &lhs, const Time &rhs);
   friend Time operator + (const Time &lhs, const Time &rhs);
   friend Time operator - (const Time &lhs, const Time &rhs);
-  friend Time operator * (const Time &lhs, Scalar rhs);
-  friend Time operator * (Scalar lhs, const Time &rhs);
-  friend Time operator / (const Time &lhs, Scalar rhs);
-  friend Scalar operator / (const Time &lhs, const Time &rhs);
   friend Time &operator += (Time &lhs, const Time &rhs);
   friend Time &operator -= (Time &lhs, const Time &rhs);
-  friend Time &operator *= (Time &lhs, Scalar rhs);
-  friend Time &operator /= (Time &lhs, Scalar rhs);
   friend Time Abs (const Time &time);
   friend Time Max (const Time &ta, const Time &tb);
   friend Time Min (const Time &ta, const Time &tb);
@@ -499,27 +525,6 @@
 {
   return Time (lhs.m_data - rhs.m_data);
 }
-inline Time operator * (const Time &lhs, Scalar rhs)
-{
-  Time retval = lhs;
-  retval *= rhs;
-  return retval;
-}
-inline Time operator * (Scalar lhs, const Time &rhs)
-{
-  return rhs * lhs;
-}
-inline Time operator / (const Time &lhs, Scalar rhs)
-{
-  Time retval = lhs;
-  retval /= rhs;
-  return retval;
-}
-inline Scalar operator / (const Time &lhs, const Time &rhs)
-{
-  int64_t retval = lhs.GetTimeStep () / rhs.GetTimeStep ();
-  return retval;
-}
 inline Time &operator += (Time &lhs, const Time &rhs)
 {
   lhs.m_data += rhs.m_data;
@@ -530,16 +535,6 @@
   lhs.m_data -= rhs.m_data;
   return lhs;
 }
-inline Time &operator *= (Time &lhs, Scalar rhs)
-{
-  lhs.m_data *= rhs;
-  return lhs;
-}
-inline Time &operator /= (Time &lhs, Scalar rhs)
-{
-  lhs.m_data /= rhs;
-  return lhs;
-}
 
 /**
  * \anchor ns3-Time-Abs
@@ -584,7 +579,7 @@
  * For example:
  * \code
  * Time t = Seconds (2.0);
- * Simulator::Schedule (NanoSeconds (5.0), ...);
+ * Simulator::Schedule (Seconds (5.0), ...);
  * \endcode
  * \param seconds seconds value
  */
@@ -664,15 +659,38 @@
   return Time::FromInteger (fs, Time::FS);
 }
 
+
+inline Time Seconds (int64x64_t seconds)
+{
+  return Time::From (seconds, Time::S);
+}
+inline Time MilliSeconds (int64x64_t ms)
+{
+  return Time::From (ms, Time::MS);
+}
+inline Time MicroSeconds (int64x64_t us)
+{
+  return Time::From (us, Time::US);
+}
+inline Time NanoSeconds (int64x64_t ns)
+{
+  return Time::From (ns, Time::NS);
+}
+inline Time PicoSeconds (int64x64_t ps)
+{
+  return Time::From (ps, Time::PS);
+}
+inline Time FemtoSeconds (int64x64_t fs)
+{
+  return Time::From (fs, Time::FS);
+}
+
 // internal function not publicly documented
 inline Time TimeStep (uint64_t ts)
 {
   return Time (ts);
 }
 
-typedef Time TimeInvert;
-typedef Time TimeSquare;
-
 /**
  * \class ns3::TimeValue
  * \brief hold objects of type ns3::Time
--- a/src/simulator/time.cc	Wed Aug 25 10:44:21 2010 +0200
+++ b/src/simulator/time.cc	Wed Aug 25 16:45:59 2010 +0200
@@ -106,23 +106,23 @@
       info->factor = factor;
       if (shift == 0)
 	{
-	  info->timeFrom = 1.0;
-	  info->timeTo = 1.0;
+	  info->timeFrom = int64x64_t (1);
+	  info->timeTo = int64x64_t (1);
 	  info->toMul = true;
 	  info->fromMul = true;
 	}
       else if (shift > 0)
 	{
-	  info->timeFrom = factor;
-	  info->timeTo = 1.0 / factor;
+	  info->timeFrom = int64x64_t (factor);
+	  info->timeTo = int64x64_t::Invert (factor);
 	  info->toMul = false;
 	  info->fromMul = true;
 	}
       else
 	{
 	  NS_ASSERT (shift < 0);
-	  info->timeFrom = 1.0 / factor;
-	  info->timeTo = factor;
+	  info->timeFrom = int64x64_t::Invert (factor);
+	  info->timeTo = int64x64_t (factor);
 	  info->toMul = true;
 	  info->fromMul = false;
 	}
@@ -165,7 +165,7 @@
       unit = "unreachable";
       break;
     }
-  double v = Time::ToDouble (time, Time::GetResolution ());
+  int64x64_t v = time.To ();
   os << v << unit;
   return os;
 }