From 52d0368ad97534e663c5e1aaff7b325859b1fb3e Mon Sep 17 00:00:00 2001 From: "Peter D. Barnes, Jr" Date: Mon, 14 Dec 2020 03:42:14 +0100 Subject: [PATCH] internet: time arithmetic --- src/internet/helper/ipv4-routing-helper.cc | 22 ++++++++-------- src/internet/helper/ipv4-routing-helper.h | 12 ++++----- src/internet/helper/ipv6-routing-helper.cc | 26 +++++++++---------- src/internet/helper/ipv6-routing-helper.h | 12 ++++----- src/internet/model/nsc-tcp-l4-protocol.cc | 2 +- src/internet/model/nsc-tcp-socket-impl.cc | 2 +- src/internet/model/rtt-estimator.cc | 3 +-- src/internet/model/tcp-tx-item.cc | 4 +-- src/internet/model/tcp-tx-item.h | 3 ++- src/internet/test/tcp-bytes-in-flight-test.cc | 2 +- .../test/example-ping-lr-wpan.reflog | 4 +-- 11 files changed, 46 insertions(+), 46 deletions(-) diff --git a/src/internet/helper/ipv4-routing-helper.cc b/src/internet/helper/ipv4-routing-helper.cc index c4943b4e2..185cdb2d1 100644 --- a/src/internet/helper/ipv4-routing-helper.cc +++ b/src/internet/helper/ipv4-routing-helper.cc @@ -93,39 +93,39 @@ Ipv4RoutingHelper::PrintEvery (Time printInterval, Ptr node, Ptr stream) +Ipv4RoutingHelper::PrintNeighborCacheAllAt (Time printTime, Ptr stream, Time::Unit unit /* = Time::S */) { for (uint32_t i = 0; i < NodeList::GetNNodes (); i++) { Ptr node = NodeList::GetNode (i); - Simulator::Schedule (printTime, &Ipv4RoutingHelper::PrintArpCache, node, stream); + Simulator::Schedule (printTime, &Ipv4RoutingHelper::PrintArpCache, node, stream, unit); } } void -Ipv4RoutingHelper::PrintNeighborCacheAllEvery (Time printInterval, Ptr stream) +Ipv4RoutingHelper::PrintNeighborCacheAllEvery (Time printInterval, Ptr stream, Time::Unit unit) { for (uint32_t i = 0; i < NodeList::GetNNodes (); i++) { Ptr node = NodeList::GetNode (i); - Simulator::Schedule (printInterval, &Ipv4RoutingHelper::PrintArpCacheEvery, printInterval, node, stream); + Simulator::Schedule (printInterval, &Ipv4RoutingHelper::PrintArpCacheEvery, printInterval, node, stream, unit); } } void -Ipv4RoutingHelper::PrintNeighborCacheAt (Time printTime, Ptr node, Ptr stream) +Ipv4RoutingHelper::PrintNeighborCacheAt (Time printTime, Ptr node, Ptr stream, Time::Unit unit) { - Simulator::Schedule (printTime, &Ipv4RoutingHelper::PrintArpCache, node, stream); + Simulator::Schedule (printTime, &Ipv4RoutingHelper::PrintArpCache, node, stream, unit); } void -Ipv4RoutingHelper::PrintNeighborCacheEvery (Time printInterval,Ptr node, Ptr stream) +Ipv4RoutingHelper::PrintNeighborCacheEvery (Time printInterval,Ptr node, Ptr stream, Time::Unit unit) { - Simulator::Schedule (printInterval, &Ipv4RoutingHelper::PrintArpCacheEvery, printInterval, node, stream); + Simulator::Schedule (printInterval, &Ipv4RoutingHelper::PrintArpCacheEvery, printInterval, node, stream, unit); } void -Ipv4RoutingHelper::PrintArpCache (Ptr node, Ptr stream) +Ipv4RoutingHelper::PrintArpCache (Ptr node, Ptr stream, Time::Unit unit) { Ptr ipv4 = node->GetObject (); if (ipv4) @@ -156,7 +156,7 @@ Ipv4RoutingHelper::PrintArpCache (Ptr node, Ptr strea } void -Ipv4RoutingHelper::PrintArpCacheEvery (Time printInterval, Ptr node, Ptr stream) +Ipv4RoutingHelper::PrintArpCacheEvery (Time printInterval, Ptr node, Ptr stream, Time::Unit unit) { Ptr ipv4 = node->GetObject (); if (ipv4) @@ -183,7 +183,7 @@ Ipv4RoutingHelper::PrintArpCacheEvery (Time printInterval, Ptr node, PtrPrintArpCache (stream); } } - Simulator::Schedule (printInterval, &Ipv4RoutingHelper::PrintArpCacheEvery, printInterval, node, stream); + Simulator::Schedule (printInterval, &Ipv4RoutingHelper::PrintArpCacheEvery, printInterval, node, stream, unit); } } diff --git a/src/internet/helper/ipv4-routing-helper.h b/src/internet/helper/ipv4-routing-helper.h index d5e0776cb..804db2de5 100644 --- a/src/internet/helper/ipv4-routing-helper.h +++ b/src/internet/helper/ipv4-routing-helper.h @@ -128,7 +128,7 @@ public: \endverbatim * Note that the MAC address is printed as "type"-"size"-"actual address" */ - static void PrintNeighborCacheAllAt (Time printTime, Ptr stream); + static void PrintNeighborCacheAllAt (Time printTime, Ptr stream, Time::Unit unit = Time::S); /** * \brief prints the neighbor cache of all nodes at regular intervals specified by user. @@ -143,7 +143,7 @@ public: \endverbatim * Note that the MAC address is printed as "type"-"size"-"actual address" */ - static void PrintNeighborCacheAllEvery (Time printInterval, Ptr stream); + static void PrintNeighborCacheAllEvery (Time printInterval, Ptr stream, Time::Unit unit = Time::S); /** * \brief prints the neighbor cache of a node at a particular time. @@ -159,7 +159,7 @@ public: \endverbatim * Note that the MAC address is printed as "type"-"size"-"actual address" */ - static void PrintNeighborCacheAt (Time printTime, Ptr node, Ptr stream); + static void PrintNeighborCacheAt (Time printTime, Ptr node, Ptr stream, Time::Unit unit = Time::S); /** * \brief prints the neighbor cache of a node at regular intervals specified by user. @@ -175,7 +175,7 @@ public: \endverbatim * Note that the MAC address is printed as "type"-"size"-"actual address" */ - static void PrintNeighborCacheEvery (Time printInterval, Ptr node, Ptr stream); + static void PrintNeighborCacheEvery (Time printInterval, Ptr node, Ptr stream, Time::Unit unit = Time::S); /** * \brief Request a specified routing protocol <T> from Ipv4RoutingProtocol protocol @@ -228,7 +228,7 @@ private: \endverbatim * Note that the MAC address is printed as "type"-"size"-"actual address" */ - static void PrintArpCache (Ptr node, Ptr stream); + static void PrintArpCache (Ptr node, Ptr stream, Time::Unit unit = Time::S); /** * \brief prints the neighbor cache of a node at regular intervals specified by user. @@ -244,7 +244,7 @@ private: \endverbatim * Note that the MAC address is printed as "type"-"size"-"actual address" */ - static void PrintArpCacheEvery (Time printInterval, Ptr node, Ptr stream); + static void PrintArpCacheEvery (Time printInterval, Ptr node, Ptr stream, Time::Unit unit = Time::S); }; diff --git a/src/internet/helper/ipv6-routing-helper.cc b/src/internet/helper/ipv6-routing-helper.cc index 6ae748ea6..e5bab4bd2 100644 --- a/src/internet/helper/ipv6-routing-helper.cc +++ b/src/internet/helper/ipv6-routing-helper.cc @@ -93,39 +93,39 @@ Ipv6RoutingHelper::PrintEvery (Time printInterval, Ptr node, Ptr stream) +Ipv6RoutingHelper::PrintNeighborCacheAllAt (Time printTime, Ptr stream, Time::Unit unit /* = Time::S */) { for (uint32_t i = 0; i < NodeList::GetNNodes (); i++) { Ptr node = NodeList::GetNode (i); - Simulator::Schedule (printTime, &Ipv6RoutingHelper::PrintNdiscCache, node, stream); + Simulator::Schedule (printTime, &Ipv6RoutingHelper::PrintNdiscCache, node, stream, unit); } } void -Ipv6RoutingHelper::PrintNeighborCacheAllEvery (Time printInterval, Ptr stream) +Ipv6RoutingHelper::PrintNeighborCacheAllEvery (Time printInterval, Ptr stream, Time::Unit unit /* = Time::S */) { for (uint32_t i = 0; i < NodeList::GetNNodes (); i++) { Ptr node = NodeList::GetNode (i); - Simulator::Schedule (printInterval, &Ipv6RoutingHelper::PrintNdiscCacheEvery, printInterval, node, stream); + Simulator::Schedule (printInterval, &Ipv6RoutingHelper::PrintNdiscCacheEvery, printInterval, node, stream, unit); } } void -Ipv6RoutingHelper::PrintNeighborCacheAt (Time printTime, Ptr node, Ptr stream) +Ipv6RoutingHelper::PrintNeighborCacheAt (Time printTime, Ptr node, Ptr stream, Time::Unit unit /* = Time::S */) { - Simulator::Schedule (printTime, &Ipv6RoutingHelper::PrintNdiscCache, node, stream); + Simulator::Schedule (printTime, &Ipv6RoutingHelper::PrintNdiscCache, node, stream, unit); } void -Ipv6RoutingHelper::PrintNeighborCacheEvery (Time printInterval,Ptr node, Ptr stream) +Ipv6RoutingHelper::PrintNeighborCacheEvery (Time printInterval,Ptr node, Ptr stream, Time::Unit unit /* = Time::S */) { - Simulator::Schedule (printInterval, &Ipv6RoutingHelper::PrintNdiscCacheEvery, printInterval, node, stream); + Simulator::Schedule (printInterval, &Ipv6RoutingHelper::PrintNdiscCacheEvery, printInterval, node, stream, unit); } void -Ipv6RoutingHelper::PrintNdiscCache (Ptr node, Ptr stream) +Ipv6RoutingHelper::PrintNdiscCache (Ptr node, Ptr stream, Time::Unit unit /* = Time::S */) { Ptr ipv6 = node->GetObject (); if (ipv6) @@ -142,7 +142,7 @@ Ipv6RoutingHelper::PrintNdiscCache (Ptr node, Ptr str { *os << static_cast (node->GetId ()); } - *os << " at time " << Simulator::Now ().GetSeconds () << "\n"; + *os << " at time " << Simulator::Now ().As (unit) << "\n"; for (uint32_t i=0; iGetNInterfaces(); i++) { @@ -156,7 +156,7 @@ Ipv6RoutingHelper::PrintNdiscCache (Ptr node, Ptr str } void -Ipv6RoutingHelper::PrintNdiscCacheEvery (Time printInterval, Ptr node, Ptr stream) +Ipv6RoutingHelper::PrintNdiscCacheEvery (Time printInterval, Ptr node, Ptr stream, Time::Unit unit /* = Time::S */) { Ptr ipv6 = node->GetObject (); if (ipv6) @@ -173,7 +173,7 @@ Ipv6RoutingHelper::PrintNdiscCacheEvery (Time printInterval, Ptr node, Ptr { *os << static_cast (node->GetId ()); } - *os << " at time " << Simulator::Now ().GetSeconds () << "\n"; + *os << " at time " << Simulator::Now ().As (unit) << "\n"; for (uint32_t i=0; iGetNInterfaces(); i++) { @@ -183,7 +183,7 @@ Ipv6RoutingHelper::PrintNdiscCacheEvery (Time printInterval, Ptr node, Ptr ndiscCache->PrintNdiscCache (stream); } } - Simulator::Schedule (printInterval, &Ipv6RoutingHelper::PrintNdiscCacheEvery, printInterval, node, stream); + Simulator::Schedule (printInterval, &Ipv6RoutingHelper::PrintNdiscCacheEvery, printInterval, node, stream, unit); } } diff --git a/src/internet/helper/ipv6-routing-helper.h b/src/internet/helper/ipv6-routing-helper.h index 6056f983a..dcc960d7f 100644 --- a/src/internet/helper/ipv6-routing-helper.h +++ b/src/internet/helper/ipv6-routing-helper.h @@ -129,7 +129,7 @@ public: \endverbatim * Note that the MAC address is printed as "type"-"size"-"actual address" */ - static void PrintNeighborCacheAllAt (Time printTime, Ptr stream); + static void PrintNeighborCacheAllAt (Time printTime, Ptr stream, Time::Unit unit = Time::S); /** * \brief prints the neighbor cache of all nodes at regular intervals specified by user. @@ -144,7 +144,7 @@ public: \endverbatim * Note that the MAC address is printed as "type"-"size"-"actual address" */ - static void PrintNeighborCacheAllEvery (Time printInterval, Ptr stream); + static void PrintNeighborCacheAllEvery (Time printInterval, Ptr stream, Time::Unit unit = Time::S); /** * \brief prints the neighbor cache of a node at a particular time. @@ -160,7 +160,7 @@ public: \endverbatim * Note that the MAC address is printed as "type"-"size"-"actual address" */ - static void PrintNeighborCacheAt (Time printTime, Ptr node, Ptr stream); + static void PrintNeighborCacheAt (Time printTime, Ptr node, Ptr stream, Time::Unit unit = Time::S); /** * \brief prints the neighbor cache of a node at regular intervals specified by user. @@ -176,7 +176,7 @@ public: \endverbatim * Note that the MAC address is printed as "type"-"size"-"actual address" */ - static void PrintNeighborCacheEvery (Time printInterval, Ptr node, Ptr stream); + static void PrintNeighborCacheEvery (Time printInterval, Ptr node, Ptr stream, Time::Unit unit = Time::S); /** * \brief Request a specified routing protocol <T> from Ipv6RoutingProtocol protocol @@ -229,7 +229,7 @@ private: \endverbatim * Note that the MAC address is printed as "type"-"size"-"actual address" */ - static void PrintNdiscCache (Ptr node, Ptr stream); + static void PrintNdiscCache (Ptr node, Ptr stream, Time::Unit unit = Time::S); /** * \brief prints the neighbor cache of a node at regular intervals specified by user. @@ -245,7 +245,7 @@ private: \endverbatim * Note that the MAC address is printed as "type"-"size"-"actual address" */ - static void PrintNdiscCacheEvery (Time printInterval, Ptr node, Ptr stream); + static void PrintNdiscCacheEvery (Time printInterval, Ptr node, Ptr stream, Time::Unit unit = Time::S); }; /** diff --git a/src/internet/model/nsc-tcp-l4-protocol.cc b/src/internet/model/nsc-tcp-l4-protocol.cc index 005b885bb..3205a72f1 100644 --- a/src/internet/model/nsc-tcp-l4-protocol.cc +++ b/src/internet/model/nsc-tcp-l4-protocol.cc @@ -119,7 +119,7 @@ NscInterfaceImpl::gettime (unsigned int *sec, unsigned int *usec) #undef NS_LOG_APPEND_CONTEXT #define NS_LOG_APPEND_CONTEXT \ - if (m_node) { std::clog << Simulator::Now ().GetSeconds () << " [node " << m_node->GetId () << "] "; } + if (m_node) { std::clog << Simulator::Now ().As (Time::S) << " [node " << m_node->GetId () << "] "; } TypeId NscTcpL4Protocol::GetTypeId (void) diff --git a/src/internet/model/nsc-tcp-socket-impl.cc b/src/internet/model/nsc-tcp-socket-impl.cc index bddb46634..d989b8e6c 100644 --- a/src/internet/model/nsc-tcp-socket-impl.cc +++ b/src/internet/model/nsc-tcp-socket-impl.cc @@ -18,7 +18,7 @@ */ #define NS_LOG_APPEND_CONTEXT \ - if (m_node) { std::clog << Simulator::Now ().GetSeconds () << " [node " << m_node->GetId () << "] "; } + if (m_node) { std::clog << Simulator::Now ().As (Time::S) << " [node " << m_node->GetId () << "] "; } #include "ns3/node.h" #include "ns3/inet-socket-address.h" diff --git a/src/internet/model/rtt-estimator.cc b/src/internet/model/rtt-estimator.cc index 36780d2ba..317024da0 100644 --- a/src/internet/model/rtt-estimator.cc +++ b/src/internet/model/rtt-estimator.cc @@ -211,8 +211,7 @@ RttMeanDeviation::FloatingPointUpdate (Time m) // RTTVAR <- (1 - beta) * RTTVAR + beta * |SRTT - R'| Time difference = Abs (err) - m_estimatedVariation; - m_estimatedVariation += Time::FromDouble (difference.ToDouble (Time::S) * m_beta, Time::S); - + m_estimatedVariation += difference * m_beta; return; } diff --git a/src/internet/model/tcp-tx-item.cc b/src/internet/model/tcp-tx-item.cc index 2d38d057c..f312c48a0 100644 --- a/src/internet/model/tcp-tx-item.cc +++ b/src/internet/model/tcp-tx-item.cc @@ -21,7 +21,7 @@ namespace ns3 { void -TcpTxItem::Print (std::ostream &os) const +TcpTxItem::Print (std::ostream &os, Time::Unit unit /* = Time::S */) const { bool comma = false; os << "[" << m_startSeq << ";" << m_startSeq + GetSeqSize () << "|" @@ -55,7 +55,7 @@ TcpTxItem::Print (std::ostream &os) const { os << ","; } - os << "[" << m_lastSent.GetSeconds () << "]"; + os << "[" << m_lastSent.As (unit) << "]"; } uint32_t diff --git a/src/internet/model/tcp-tx-item.h b/src/internet/model/tcp-tx-item.h index 60a81ddb9..f2c5814cf 100644 --- a/src/internet/model/tcp-tx-item.h +++ b/src/internet/model/tcp-tx-item.h @@ -37,8 +37,9 @@ public: /** * \brief Print the time * \param os ostream + * \param unit Time::Unit */ - void Print (std::ostream &os) const; + void Print (std::ostream &os, Time::Unit unit = Time::S) const; /** * \brief Get the size in the sequence number space diff --git a/src/internet/test/tcp-bytes-in-flight-test.cc b/src/internet/test/tcp-bytes-in-flight-test.cc index 9c2bdc89e..ef800f296 100644 --- a/src/internet/test/tcp-bytes-in-flight-test.cc +++ b/src/internet/test/tcp-bytes-in-flight-test.cc @@ -260,7 +260,7 @@ TcpBytesInFlightTest::Tx (const Ptr p, const TcpHeader &h, SocketW // count retransmission only one time m_guessedBytesInFlight += p->GetSize (); } - retr = h.GetSequenceNumber (); + retr = h.GetSequenceNumber (); NS_LOG_DEBUG ("TX size=" << p->GetSize () << " seq=" << h.GetSequenceNumber () << " m_guessedBytesInFlight=" << m_guessedBytesInFlight); diff --git a/src/sixlowpan/test/example-ping-lr-wpan.reflog b/src/sixlowpan/test/example-ping-lr-wpan.reflog index 257f9af04..4c43d7a75 100644 --- a/src/sixlowpan/test/example-ping-lr-wpan.reflog +++ b/src/sixlowpan/test/example-ping-lr-wpan.reflog @@ -1,6 +1,6 @@ Device 0: pseudo-Mac-48 02:00:00:00:00:01, IPv6 Address 2001:2::ff:fe00:1 Device 1: pseudo-Mac-48 02:00:00:00:00:02, IPv6 Address 2001:2::ff:fe00:2 -NDISC Cache of node 0 at time 9 +NDISC Cache of node 0 at time +9s 2001:2::ff:fe00:2 dev 2 lladdr 00-06-02:00:00:00:00:02 REACHABLE -NDISC Cache of node 1 at time 9 +NDISC Cache of node 1 at time +9s 2001:2::ff:fe00:1 dev 2 lladdr 00-06-02:00:00:00:00:01 REACHABLE