From b8caa20a8a86a38d0ef8b397f314aa758894b440 Mon Sep 17 00:00:00 2001
From: Tommaso Pecorella
Date: Sat, 17 Mar 2012 23:23:56 +0100
Subject: [PATCH] Enhancement 1393 - IPv6 Routing Helper RT Print functions
---
CHANGES.html | 6 +-
RELEASE_NOTES | 5 +-
src/internet/helper/ipv6-routing-helper.cc | 55 +++++++++++++++++++
src/internet/helper/ipv6-routing-helper.h | 52 ++++++++++++++++++
src/internet/model/ipv4-routing-protocol.h | 5 ++
src/internet/model/ipv6-list-routing.cc | 18 ++++++
src/internet/model/ipv6-list-routing.h | 7 +++
src/internet/model/ipv6-routing-protocol.h | 8 +++
src/internet/model/ipv6-static-routing.cc | 33 +++++++++--
src/internet/model/ipv6-static-routing.h | 13 ++++-
.../test/ipv6-list-routing-test-suite.cc | 2 +
11 files changed, 194 insertions(+), 10 deletions(-)
diff --git a/CHANGES.html b/CHANGES.html
index 5bc10a5d8..0e89123f6 100644
--- a/CHANGES.html
+++ b/CHANGES.html
@@ -41,7 +41,7 @@ This file is a best-effort approach to solving this issue; we will do
our best but can guarantee that there will be things that fall through
the cracks, unfortunately. If you, as a user, can suggest improvements
to this file based on your experience, please contribute a patch or drop
-us a note on ns-developers mailing list.
+us a note on ns-developers mailing list.
Changes from ns-3.13 to ns-3-dev
@@ -74,6 +74,10 @@ It now includes the destination IPv6 address of the end point which was
needed for TCP. This lead to a small change in the UDP and ICMPv6 L4
protocols as well.
+
+Ipv6RoutingHelper can now print the IPv6 Routing Tables at specific
+intervals or time. Exactly like Ipv4RoutingHelper do.
+
Changes to build system:
diff --git a/RELEASE_NOTES b/RELEASE_NOTES
index 2193e43a8..51fea8fff 100644
--- a/RELEASE_NOTES
+++ b/RELEASE_NOTES
@@ -24,7 +24,10 @@ New user-visible features
- Dual-stacked IPv6 sockets are implemented. An IPv6 socket can accept an IPv4
connection, returning the senders address as an IPv4-mapped address
(IPV6_V6ONLY socket option is not implemented).
-
+- Ipv6RoutingHelper is now in-line with Ipv4RoutingHelper concerning the RT
+ print functions. Various minor changes made in Ipv6RoutingProtocol and derived
+ classes to make this possible.
+
Bugs fixed
----------
- bug 1319 - Fix Ipv6RawSocketImpl Icmpv6 filter
diff --git a/src/internet/helper/ipv6-routing-helper.cc b/src/internet/helper/ipv6-routing-helper.cc
index 09bf7edff..c8754b012 100644
--- a/src/internet/helper/ipv6-routing-helper.cc
+++ b/src/internet/helper/ipv6-routing-helper.cc
@@ -18,6 +18,10 @@
* Author: Mathieu Lacage
*/
+#include "ns3/node.h"
+#include "ns3/node-list.h"
+#include "ns3/simulator.h"
+#include "ns3/ipv6-routing-protocol.h"
#include "ipv6-routing-helper.h"
namespace ns3 {
@@ -26,4 +30,55 @@ Ipv6RoutingHelper::~Ipv6RoutingHelper ()
{
}
+void
+Ipv6RoutingHelper::PrintRoutingTableAllAt (Time printTime, Ptr stream) const
+{
+ for (uint32_t i = 0; i < NodeList::GetNNodes (); i++)
+ {
+ Ptr node = NodeList::GetNode (i);
+ Simulator::Schedule (printTime, &Ipv6RoutingHelper::Print, this, node, stream);
+ }
+}
+
+void
+Ipv6RoutingHelper::PrintRoutingTableAllEvery (Time printInterval, Ptr stream) const
+{
+ for (uint32_t i = 0; i < NodeList::GetNNodes (); i++)
+ {
+ Ptr node = NodeList::GetNode (i);
+ Simulator::Schedule (printInterval, &Ipv6RoutingHelper::PrintEvery, this, printInterval, node, stream);
+ }
+}
+
+void
+Ipv6RoutingHelper::PrintRoutingTableAt (Time printTime, Ptr node, Ptr stream) const
+{
+ Simulator::Schedule (printTime, &Ipv6RoutingHelper::Print, this, node, stream);
+}
+
+void
+Ipv6RoutingHelper::PrintRoutingTableEvery (Time printInterval,Ptr node, Ptr stream) const
+{
+ Simulator::Schedule (printInterval, &Ipv6RoutingHelper::PrintEvery, this, printInterval, node, stream);
+}
+
+void
+Ipv6RoutingHelper::Print (Ptr node, Ptr stream) const
+{
+ Ptr ipv6 = node->GetObject ();
+ Ptr rp = ipv6->GetRoutingProtocol ();
+ NS_ASSERT (rp);
+ rp->PrintRoutingTable (stream);
+}
+
+void
+Ipv6RoutingHelper::PrintEvery (Time printInterval, Ptr node, Ptr stream) const
+{
+ Ptr ipv6 = node->GetObject ();
+ Ptr rp = ipv6->GetRoutingProtocol ();
+ NS_ASSERT (rp);
+ rp->PrintRoutingTable (stream);
+ Simulator::Schedule (printInterval, &Ipv6RoutingHelper::PrintEvery, this, printInterval, node, stream);
+}
+
} // namespace ns3
diff --git a/src/internet/helper/ipv6-routing-helper.h b/src/internet/helper/ipv6-routing-helper.h
index 1a670d025..4651c91ea 100644
--- a/src/internet/helper/ipv6-routing-helper.h
+++ b/src/internet/helper/ipv6-routing-helper.h
@@ -22,6 +22,8 @@
#define IPV6_ROUTING_HELPER_H
#include "ns3/ptr.h"
+#include "ns3/nstime.h"
+#include "ns3/output-stream-wrapper.h"
namespace ns3 {
@@ -61,6 +63,56 @@ public:
* \returns a newly-created routing protocol
*/
virtual Ptr Create (Ptr node) const = 0;
+
+ /**
+ * \brief prints the routing tables of all nodes at a particular time.
+ * \param printTime the time at which the routing table is supposed to be printed.
+ * \param stream The output stream object to use
+ *
+ * This method calls the PrintRoutingTable() method of the
+ * Ipv6RoutingProtocol stored in the Ipv6 object, for all nodes at the
+ * specified time; the output format is routing protocol-specific.
+ */
+ void PrintRoutingTableAllAt (Time printTime, Ptr stream) const;
+
+ /**
+ * \brief prints the routing tables of all nodes at regular intervals specified by user.
+ * \param printInterval the time interval for which the routing table is supposed to be printed.
+ * \param stream The output stream object to use
+ *
+ * This method calls the PrintRoutingTable() method of the
+ * Ipv6RoutingProtocol stored in the Ipv6 object, for all nodes at the
+ * specified time interval; the output format is routing protocol-specific.
+ */
+ void PrintRoutingTableAllEvery (Time printInterval, Ptr stream) const;
+
+ /**
+ * \brief prints the routing tables of a node at a particular time.
+ * \param printTime the time at which the routing table is supposed to be printed.
+ * \param node The node ptr for which we need the routing table to be printed
+ * \param stream The output stream object to use
+ *
+ * This method calls the PrintRoutingTable() method of the
+ * Ipv6RoutingProtocol stored in the Ipv6 object, for the selected node
+ * at the specified time; the output format is routing protocol-specific.
+ */
+ void PrintRoutingTableAt (Time printTime, Ptr node, Ptr stream) const;
+
+ /**
+ * \brief prints the routing tables of a node at regular intervals specified by user.
+ * \param printInterval the time interval for which the routing table is supposed to be printed.
+ * \param node The node ptr for which we need the routing table to be printed
+ * \param stream The output stream object to use
+ *
+ * This method calls the PrintRoutingTable() method of the
+ * Ipv6RoutingProtocol stored in the Ipv6 object, for the selected node
+ * at the specified interval; the output format is routing protocol-specific.
+ */
+ void PrintRoutingTableEvery (Time printInterval, Ptr node, Ptr stream) const;
+
+private:
+ void Print (Ptr node, Ptr stream) const;
+ void PrintEvery (Time printInterval, Ptr node, Ptr stream) const;
};
} // namespace ns3
diff --git a/src/internet/model/ipv4-routing-protocol.h b/src/internet/model/ipv4-routing-protocol.h
index 57f18c9d0..53bced4ef 100644
--- a/src/internet/model/ipv4-routing-protocol.h
+++ b/src/internet/model/ipv4-routing-protocol.h
@@ -142,6 +142,11 @@ public:
*/
virtual void SetIpv4 (Ptr ipv4) = 0;
+ /**
+ * \brief Print the Routing Table entries
+ *
+ * \param stream the ostream the Routing table is printed to
+ */
virtual void PrintRoutingTable (Ptr stream) const = 0;
};
diff --git a/src/internet/model/ipv6-list-routing.cc b/src/internet/model/ipv6-list-routing.cc
index f6f5a4e4b..0bc7ab59a 100644
--- a/src/internet/model/ipv6-list-routing.cc
+++ b/src/internet/model/ipv6-list-routing.cc
@@ -23,6 +23,7 @@
#include "ns3/node.h"
#include "ns3/ipv6-static-routing.h"
#include "ipv6-list-routing.h"
+#include "ns3/simulator.h"
NS_LOG_COMPONENT_DEFINE ("Ipv6ListRouting");
@@ -269,6 +270,23 @@ void Ipv6ListRouting::NotifyRemoveRoute (Ipv6Address dst, Ipv6Prefix mask, Ipv6A
}
}
+void
+Ipv6ListRouting::PrintRoutingTable (Ptr stream) const
+{
+ NS_LOG_FUNCTION (this);
+
+ *stream->GetStream () << "Node: " << m_ipv6->GetObject ()->GetId ()
+ << " Time: " << Simulator::Now ().GetSeconds () << "s "
+ << "Ipv6ListRouting table" << std::endl;
+ for (Ipv6RoutingProtocolList::const_iterator i = m_routingProtocols.begin ();
+ i != m_routingProtocols.end (); i++)
+ {
+ *stream->GetStream () << " Priority: " << (*i).first << " Protocol: " << (*i).second->GetInstanceTypeId () << std::endl;
+ (*i).second->PrintRoutingTable (stream);
+ }
+ *stream->GetStream () << std::endl;
+}
+
void
Ipv6ListRouting::SetIpv6 (Ptr ipv6)
{
diff --git a/src/internet/model/ipv6-list-routing.h b/src/internet/model/ipv6-list-routing.h
index 0e01955f5..29ed332ff 100644
--- a/src/internet/model/ipv6-list-routing.h
+++ b/src/internet/model/ipv6-list-routing.h
@@ -104,6 +104,13 @@ public:
virtual void NotifyRemoveRoute (Ipv6Address dst, Ipv6Prefix mask, Ipv6Address nextHop, uint32_t interface, Ipv6Address prefixToUse = Ipv6Address::GetZero ());
virtual void SetIpv6 (Ptr ipv6);
+ /**
+ * \brief Print the Routing Table entries
+ *
+ * \param stream the ostream the Routing table is printed to
+ */
+ virtual void PrintRoutingTable (Ptr stream) const;
+
protected:
/**
* \brief Dispose this object.
diff --git a/src/internet/model/ipv6-routing-protocol.h b/src/internet/model/ipv6-routing-protocol.h
index 4713b3155..1d1b31d1f 100644
--- a/src/internet/model/ipv6-routing-protocol.h
+++ b/src/internet/model/ipv6-routing-protocol.h
@@ -29,6 +29,7 @@
#include "ipv6-header.h"
#include "ipv6-interface-address.h"
#include "ipv6.h"
+#include "ns3/output-stream-wrapper.h"
namespace ns3 {
@@ -171,6 +172,13 @@ public:
* \param ipv6 the ipv6 object this routing protocol is being associated with
*/
virtual void SetIpv6 (Ptr ipv6) = 0;
+
+ /**
+ * \brief Print the Routing Table entries
+ *
+ * \param stream the ostream the Routing table is printed to
+ */
+ virtual void PrintRoutingTable (Ptr stream) const = 0;
};
} // namespace ns3
diff --git a/src/internet/model/ipv6-static-routing.cc b/src/internet/model/ipv6-static-routing.cc
index 90be08299..7da19c8da 100644
--- a/src/internet/model/ipv6-static-routing.cc
+++ b/src/internet/model/ipv6-static-routing.cc
@@ -18,8 +18,11 @@
* Author: Sebastien Vincent
*/
+#include
#include "ns3/log.h"
+#include "ns3/node.h"
#include "ns3/packet.h"
+#include "ns3/simulator.h"
#include "ns3/ipv6-route.h"
#include "ns3/net-device.h"
@@ -71,6 +74,26 @@ void Ipv6StaticRouting::SetIpv6 (Ptr ipv6)
}
}
+// Formatted like output of "route -n" command
+void
+Ipv6StaticRouting::PrintRoutingTable (Ptr stream) const
+{
+ NS_LOG_FUNCTION (this);
+ std::ostream* os = stream->GetStream ();
+ if (GetNRoutes () > 0)
+ {
+ *os << "Node: " << m_ipv6->GetObject ()->GetId ()
+ << " Time: " << Simulator::Now ().GetSeconds () << "s "
+ << "Ipv6StaticRouting table" << std::endl;
+
+ for (uint32_t j = 0; j < GetNRoutes (); j++)
+ {
+ Ipv6RoutingTableEntry route = GetRoute (j);
+ *os << route << std::endl;
+ }
+ }
+}
+
void Ipv6StaticRouting::AddHostRouteTo (Ipv6Address dst, Ipv6Address nextHop, uint32_t interface, Ipv6Address prefixToUse, uint32_t metric)
{
NS_LOG_FUNCTION (this << dst << nextHop << interface << prefixToUse << metric);
@@ -369,7 +392,7 @@ Ptr Ipv6StaticRouting::LookupStatic (Ipv6Address origin, Ipv
return mrtentry;
}
-uint32_t Ipv6StaticRouting::GetNRoutes ()
+uint32_t Ipv6StaticRouting::GetNRoutes () const
{
return m_networkRoutes.size ();
}
@@ -412,12 +435,12 @@ Ipv6RoutingTableEntry Ipv6StaticRouting::GetDefaultRoute ()
}
}
-Ipv6RoutingTableEntry Ipv6StaticRouting::GetRoute (uint32_t index)
+Ipv6RoutingTableEntry Ipv6StaticRouting::GetRoute (uint32_t index) const
{
NS_LOG_FUNCTION (this << index);
uint32_t tmp = 0;
- for (NetworkRoutesI it = m_networkRoutes.begin (); it != m_networkRoutes.end (); it++)
+ for (NetworkRoutesCI it = m_networkRoutes.begin (); it != m_networkRoutes.end (); it++)
{
if (tmp == index)
{
@@ -430,12 +453,12 @@ Ipv6RoutingTableEntry Ipv6StaticRouting::GetRoute (uint32_t index)
return 0;
}
-uint32_t Ipv6StaticRouting::GetMetric (uint32_t index)
+uint32_t Ipv6StaticRouting::GetMetric (uint32_t index) const
{
NS_LOG_FUNCTION_NOARGS ();
uint32_t tmp = 0;
- for (NetworkRoutesI it = m_networkRoutes.begin (); it != m_networkRoutes.end (); it++)
+ for (NetworkRoutesCI it = m_networkRoutes.begin (); it != m_networkRoutes.end (); it++)
{
if (tmp == index)
{
diff --git a/src/internet/model/ipv6-static-routing.h b/src/internet/model/ipv6-static-routing.h
index 2fda63097..8e075a68f 100644
--- a/src/internet/model/ipv6-static-routing.h
+++ b/src/internet/model/ipv6-static-routing.h
@@ -132,7 +132,7 @@ public:
* \brief Get the number or entries in the routing table.
* \return number of entries
*/
- uint32_t GetNRoutes ();
+ uint32_t GetNRoutes () const;
/**
* \brief Get the default route.
@@ -147,14 +147,14 @@ public:
* \param i index
* \return the route whose index is i
*/
- Ipv6RoutingTableEntry GetRoute (uint32_t i);
+ Ipv6RoutingTableEntry GetRoute (uint32_t i) const;
/**
* \brief Get a metric for route from the static unicast routing table.
* \param index The index (into the routing table) of the route to retrieve.
* \return If route is set, the metric is returned. If not, an infinity metric (0xffffffff) is returned
*/
- uint32_t GetMetric (uint32_t index);
+ uint32_t GetMetric (uint32_t index) const;
/**
* \brief Remove a route from the routing table.
@@ -236,6 +236,13 @@ public:
virtual void NotifyRemoveRoute (Ipv6Address dst, Ipv6Prefix mask, Ipv6Address nextHop, uint32_t interface, Ipv6Address prefixToUse = Ipv6Address::GetZero ());
virtual void SetIpv6 (Ptr ipv6);
+ /**
+ * \brief Print the Routing Table entries
+ *
+ * \param stream the ostream the Routing table is printed to
+ */
+ virtual void PrintRoutingTable (Ptr stream) const;
+
protected:
/**
* \brief Dispose this object.
diff --git a/src/internet/test/ipv6-list-routing-test-suite.cc b/src/internet/test/ipv6-list-routing-test-suite.cc
index 1a16834a9..c6b645115 100644
--- a/src/internet/test/ipv6-list-routing-test-suite.cc
+++ b/src/internet/test/ipv6-list-routing-test-suite.cc
@@ -38,6 +38,7 @@ public:
GetZero ()) {}
void NotifyRemoveRoute (Ipv6Address dst, Ipv6Prefix mask, Ipv6Address nextHop, uint32_t interface, Ipv6Address prefixToUse) {}
void SetIpv6 (Ptr ipv6) {}
+ virtual void PrintRoutingTable (Ptr stream) const {};
};
class Ipv6BRouting : public Ipv6RoutingProtocol {
@@ -54,6 +55,7 @@ public:
GetZero ()) {}
void NotifyRemoveRoute (Ipv6Address dst, Ipv6Prefix mask, Ipv6Address nextHop, uint32_t interface, Ipv6Address prefixToUse) {}
void SetIpv6 (Ptr ipv6) {}
+ virtual void PrintRoutingTable (Ptr stream) const {};
};
class Ipv6ListRoutingNegativeTestCase : public TestCase