From f2cd231aec06e5219847cded97f081f95c1d4efc Mon Sep 17 00:00:00 2001 From: Alexander Afanasyev Date: Tue, 9 Jul 2013 22:49:30 +0200 Subject: [PATCH] Bug 1296 - Enhancement in Ipv[4,6]RoutingHelper --- RELEASE_NOTES | 1 + src/internet/helper/ipv4-routing-helper.cc | 25 ++++++++++++++++++++++ src/internet/helper/ipv4-routing-helper.h | 13 +++++++++++ src/internet/helper/ipv6-routing-helper.cc | 24 +++++++++++++++++++++ src/internet/helper/ipv6-routing-helper.h | 12 +++++++++++ 5 files changed, 75 insertions(+) diff --git a/RELEASE_NOTES b/RELEASE_NOTES index a333b460a..f568c1ed4 100644 --- a/RELEASE_NOTES +++ b/RELEASE_NOTES @@ -26,6 +26,7 @@ New user-visible features Bugs fixed ---------- - Bug 760 - IP address removal can be painful +- Bug 1296 - Enhancement in Ipv[4,6]RoutingHelper - Bug 1390 - ICMPv6 Redirect are handled correctly only for /64 networks - Bug 1643 - NdiscCache creation and existence checks - Bug 1646 - ICMPv6 Redirect are sent from global address instead of link-local diff --git a/src/internet/helper/ipv4-routing-helper.cc b/src/internet/helper/ipv4-routing-helper.cc index 3617358f8..b4c6537df 100644 --- a/src/internet/helper/ipv4-routing-helper.cc +++ b/src/internet/helper/ipv4-routing-helper.cc @@ -17,10 +17,12 @@ * * Author: Mathieu Lacage */ + #include "ns3/node.h" #include "ns3/node-list.h" #include "ns3/simulator.h" #include "ns3/ipv4-routing-protocol.h" +#include "ns3/ipv4-list-routing.h" #include "ipv4-routing-helper.h" namespace ns3 { @@ -80,4 +82,27 @@ Ipv4RoutingHelper::PrintEvery (Time printInterval, Ptr node, Ptr +Ptr Ipv4RoutingHelper::GetRouting (Ptr protocol) +{ + Ptr ret = DynamicCast (protocol); + if (ret == 0) + { + // trying to check if protocol is a list routing + Ptr lrp = DynamicCast (protocol); + if (lrp != 0) + { + for (uint32_t i = 0; i < lrp->GetNRoutingProtocols (); i++) + { + int16_t priority; + ret = GetRouting (lrp->GetRoutingProtocol (i, priority)); // potential recursion, if inside ListRouting is ListRouting + if (ret != 0) + break; + } + } + } + + return ret; +} + } // namespace ns3 diff --git a/src/internet/helper/ipv4-routing-helper.h b/src/internet/helper/ipv4-routing-helper.h index 8abfab2fe..06b069195 100644 --- a/src/internet/helper/ipv4-routing-helper.h +++ b/src/internet/helper/ipv4-routing-helper.h @@ -17,6 +17,7 @@ * * Author: Mathieu Lacage */ + #ifndef IPV4_ROUTING_HELPER_H #define IPV4_ROUTING_HELPER_H @@ -107,6 +108,18 @@ public: */ void PrintRoutingTableEvery (Time printInterval, Ptr node, Ptr stream) const; + /** + * \brief Request a specified routing protocol from Ipv4RoutingProtocol protocol + * + * If protocol is Ipv4ListRouting, then protocol will be searched in the list, + * otherwise a simple DynamicCast will be performed + * + * \param protocol Smart pointer to Ipv4RoutingProtocol object + * \return a Smart Pointer to the requested protocol (zero if the protocol can't be found) + */ + template + static Ptr GetRouting (Ptr protocol); + private: void Print (Ptr node, Ptr stream) const; void PrintEvery (Time printInterval, Ptr node, Ptr stream) const; diff --git a/src/internet/helper/ipv6-routing-helper.cc b/src/internet/helper/ipv6-routing-helper.cc index c8754b012..8c7d6a89d 100644 --- a/src/internet/helper/ipv6-routing-helper.cc +++ b/src/internet/helper/ipv6-routing-helper.cc @@ -22,6 +22,7 @@ #include "ns3/node-list.h" #include "ns3/simulator.h" #include "ns3/ipv6-routing-protocol.h" +#include "ns3/ipv6-list-routing.h" #include "ipv6-routing-helper.h" namespace ns3 { @@ -81,4 +82,27 @@ Ipv6RoutingHelper::PrintEvery (Time printInterval, Ptr node, Ptr +Ptr Ipv6RoutingHelper::GetRouting (Ptr protocol) +{ + Ptr ret = DynamicCast (protocol); + if (ret == 0) + { + // trying to check if protocol is a list routing + Ptr lrp = DynamicCast (protocol); + if (lrp != 0) + { + for (uint32_t i = 0; i < lrp->GetNRoutingProtocols (); i++) + { + int16_t priority; + ret = GetRouting (lrp->GetRoutingProtocol (i, priority)); // potential recursion, if inside ListRouting is ListRouting + if (ret != 0) + break; + } + } + } + + return ret; +} + } // namespace ns3 diff --git a/src/internet/helper/ipv6-routing-helper.h b/src/internet/helper/ipv6-routing-helper.h index 4651c91ea..d066a2428 100644 --- a/src/internet/helper/ipv6-routing-helper.h +++ b/src/internet/helper/ipv6-routing-helper.h @@ -110,6 +110,18 @@ public: */ void PrintRoutingTableEvery (Time printInterval, Ptr node, Ptr stream) const; + /** + * \brief Request a specified routing protocol from Ipv6RoutingProtocol protocol + * + * If protocol is Ipv6ListRouting, then protocol will be searched in the list, + * otherwise a simple DynamicCast will be performed + * + * \param protocol Smart pointer to Ipv6RoutingProtocol object + * \return a Smart Pointer to the requested protocol (zero if the protocol can't be found) + */ + template + static Ptr GetRouting (Ptr protocol); + private: void Print (Ptr node, Ptr stream) const; void PrintEvery (Time printInterval, Ptr node, Ptr stream) const;