internet: time arithmetic

This commit is contained in:
Peter D. Barnes, Jr
2020-12-14 03:42:14 +01:00
committed by Tommaso Pecorella
parent 6461d9c13e
commit 52d0368ad9
11 changed files with 46 additions and 46 deletions

View File

@@ -93,39 +93,39 @@ Ipv4RoutingHelper::PrintEvery (Time printInterval, Ptr<Node> node, Ptr<OutputStr
}
void
Ipv4RoutingHelper::PrintNeighborCacheAllAt (Time printTime, Ptr<OutputStreamWrapper> stream)
Ipv4RoutingHelper::PrintNeighborCacheAllAt (Time printTime, Ptr<OutputStreamWrapper> stream, Time::Unit unit /* = Time::S */)
{
for (uint32_t i = 0; i < NodeList::GetNNodes (); i++)
{
Ptr<Node> 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<OutputStreamWrapper> stream)
Ipv4RoutingHelper::PrintNeighborCacheAllEvery (Time printInterval, Ptr<OutputStreamWrapper> stream, Time::Unit unit)
{
for (uint32_t i = 0; i < NodeList::GetNNodes (); i++)
{
Ptr<Node> 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> node, Ptr<OutputStreamWrapper> stream)
Ipv4RoutingHelper::PrintNeighborCacheAt (Time printTime, Ptr<Node> node, Ptr<OutputStreamWrapper> 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> node, Ptr<OutputStreamWrapper> stream)
Ipv4RoutingHelper::PrintNeighborCacheEvery (Time printInterval,Ptr<Node> node, Ptr<OutputStreamWrapper> 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> node, Ptr<OutputStreamWrapper> stream)
Ipv4RoutingHelper::PrintArpCache (Ptr<Node> node, Ptr<OutputStreamWrapper> stream, Time::Unit unit)
{
Ptr<Ipv4L3Protocol> ipv4 = node->GetObject<Ipv4L3Protocol> ();
if (ipv4)
@@ -156,7 +156,7 @@ Ipv4RoutingHelper::PrintArpCache (Ptr<Node> node, Ptr<OutputStreamWrapper> strea
}
void
Ipv4RoutingHelper::PrintArpCacheEvery (Time printInterval, Ptr<Node> node, Ptr<OutputStreamWrapper> stream)
Ipv4RoutingHelper::PrintArpCacheEvery (Time printInterval, Ptr<Node> node, Ptr<OutputStreamWrapper> stream, Time::Unit unit)
{
Ptr<Ipv4L3Protocol> ipv4 = node->GetObject<Ipv4L3Protocol> ();
if (ipv4)
@@ -183,7 +183,7 @@ Ipv4RoutingHelper::PrintArpCacheEvery (Time printInterval, Ptr<Node> node, Ptr<O
arpCache->PrintArpCache (stream);
}
}
Simulator::Schedule (printInterval, &Ipv4RoutingHelper::PrintArpCacheEvery, printInterval, node, stream);
Simulator::Schedule (printInterval, &Ipv4RoutingHelper::PrintArpCacheEvery, printInterval, node, stream, unit);
}
}

View File

@@ -128,7 +128,7 @@ public:
\endverbatim
* Note that the MAC address is printed as "type"-"size"-"actual address"
*/
static void PrintNeighborCacheAllAt (Time printTime, Ptr<OutputStreamWrapper> stream);
static void PrintNeighborCacheAllAt (Time printTime, Ptr<OutputStreamWrapper> 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<OutputStreamWrapper> stream);
static void PrintNeighborCacheAllEvery (Time printInterval, Ptr<OutputStreamWrapper> 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> node, Ptr<OutputStreamWrapper> stream);
static void PrintNeighborCacheAt (Time printTime, Ptr<Node> node, Ptr<OutputStreamWrapper> 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> node, Ptr<OutputStreamWrapper> stream);
static void PrintNeighborCacheEvery (Time printInterval, Ptr<Node> node, Ptr<OutputStreamWrapper> stream, Time::Unit unit = Time::S);
/**
* \brief Request a specified routing protocol &lt;T&gt; 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> node, Ptr<OutputStreamWrapper> stream);
static void PrintArpCache (Ptr<Node> node, Ptr<OutputStreamWrapper> 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> node, Ptr<OutputStreamWrapper> stream);
static void PrintArpCacheEvery (Time printInterval, Ptr<Node> node, Ptr<OutputStreamWrapper> stream, Time::Unit unit = Time::S);
};

View File

@@ -93,39 +93,39 @@ Ipv6RoutingHelper::PrintEvery (Time printInterval, Ptr<Node> node, Ptr<OutputStr
}
void
Ipv6RoutingHelper::PrintNeighborCacheAllAt (Time printTime, Ptr<OutputStreamWrapper> stream)
Ipv6RoutingHelper::PrintNeighborCacheAllAt (Time printTime, Ptr<OutputStreamWrapper> stream, Time::Unit unit /* = Time::S */)
{
for (uint32_t i = 0; i < NodeList::GetNNodes (); i++)
{
Ptr<Node> 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<OutputStreamWrapper> stream)
Ipv6RoutingHelper::PrintNeighborCacheAllEvery (Time printInterval, Ptr<OutputStreamWrapper> stream, Time::Unit unit /* = Time::S */)
{
for (uint32_t i = 0; i < NodeList::GetNNodes (); i++)
{
Ptr<Node> 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> node, Ptr<OutputStreamWrapper> stream)
Ipv6RoutingHelper::PrintNeighborCacheAt (Time printTime, Ptr<Node> node, Ptr<OutputStreamWrapper> 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> node, Ptr<OutputStreamWrapper> stream)
Ipv6RoutingHelper::PrintNeighborCacheEvery (Time printInterval,Ptr<Node> node, Ptr<OutputStreamWrapper> 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> node, Ptr<OutputStreamWrapper> stream)
Ipv6RoutingHelper::PrintNdiscCache (Ptr<Node> node, Ptr<OutputStreamWrapper> stream, Time::Unit unit /* = Time::S */)
{
Ptr<Ipv6L3Protocol> ipv6 = node->GetObject<Ipv6L3Protocol> ();
if (ipv6)
@@ -142,7 +142,7 @@ Ipv6RoutingHelper::PrintNdiscCache (Ptr<Node> node, Ptr<OutputStreamWrapper> str
{
*os << static_cast<int> (node->GetId ());
}
*os << " at time " << Simulator::Now ().GetSeconds () << "\n";
*os << " at time " << Simulator::Now ().As (unit) << "\n";
for (uint32_t i=0; i<ipv6->GetNInterfaces(); i++)
{
@@ -156,7 +156,7 @@ Ipv6RoutingHelper::PrintNdiscCache (Ptr<Node> node, Ptr<OutputStreamWrapper> str
}
void
Ipv6RoutingHelper::PrintNdiscCacheEvery (Time printInterval, Ptr<Node> node, Ptr<OutputStreamWrapper> stream)
Ipv6RoutingHelper::PrintNdiscCacheEvery (Time printInterval, Ptr<Node> node, Ptr<OutputStreamWrapper> stream, Time::Unit unit /* = Time::S */)
{
Ptr<Ipv6L3Protocol> ipv6 = node->GetObject<Ipv6L3Protocol> ();
if (ipv6)
@@ -173,7 +173,7 @@ Ipv6RoutingHelper::PrintNdiscCacheEvery (Time printInterval, Ptr<Node> node, Ptr
{
*os << static_cast<int> (node->GetId ());
}
*os << " at time " << Simulator::Now ().GetSeconds () << "\n";
*os << " at time " << Simulator::Now ().As (unit) << "\n";
for (uint32_t i=0; i<ipv6->GetNInterfaces(); i++)
{
@@ -183,7 +183,7 @@ Ipv6RoutingHelper::PrintNdiscCacheEvery (Time printInterval, Ptr<Node> node, Ptr
ndiscCache->PrintNdiscCache (stream);
}
}
Simulator::Schedule (printInterval, &Ipv6RoutingHelper::PrintNdiscCacheEvery, printInterval, node, stream);
Simulator::Schedule (printInterval, &Ipv6RoutingHelper::PrintNdiscCacheEvery, printInterval, node, stream, unit);
}
}

View File

@@ -129,7 +129,7 @@ public:
\endverbatim
* Note that the MAC address is printed as "type"-"size"-"actual address"
*/
static void PrintNeighborCacheAllAt (Time printTime, Ptr<OutputStreamWrapper> stream);
static void PrintNeighborCacheAllAt (Time printTime, Ptr<OutputStreamWrapper> 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<OutputStreamWrapper> stream);
static void PrintNeighborCacheAllEvery (Time printInterval, Ptr<OutputStreamWrapper> 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> node, Ptr<OutputStreamWrapper> stream);
static void PrintNeighborCacheAt (Time printTime, Ptr<Node> node, Ptr<OutputStreamWrapper> 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> node, Ptr<OutputStreamWrapper> stream);
static void PrintNeighborCacheEvery (Time printInterval, Ptr<Node> node, Ptr<OutputStreamWrapper> stream, Time::Unit unit = Time::S);
/**
* \brief Request a specified routing protocol &lt;T&gt; 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> node, Ptr<OutputStreamWrapper> stream);
static void PrintNdiscCache (Ptr<Node> node, Ptr<OutputStreamWrapper> 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> node, Ptr<OutputStreamWrapper> stream);
static void PrintNdiscCacheEvery (Time printInterval, Ptr<Node> node, Ptr<OutputStreamWrapper> stream, Time::Unit unit = Time::S);
};
/**

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@@ -260,7 +260,7 @@ TcpBytesInFlightTest::Tx (const Ptr<const Packet> 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);

View File

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