From 0dca6fc55cbc03766b7502d3d2217846798349c6 Mon Sep 17 00:00:00 2001 From: Mathieu Lacage Date: Fri, 12 Jun 2009 13:44:19 -0700 Subject: [PATCH] Remove static routing dependencies in code --- bindings/python/ns3_module_internet_stack.py | 69 ++++++++--- bindings/python/ns3_module_node.py | 35 ++++-- bindings/python/ns3_module_olsr.py | 29 ++++- src/helper/internet-stack-helper.cc | 2 - src/helper/olsr-helper.cc | 1 - src/internet-stack/ipv4-l3-protocol.cc | 71 +++-------- src/internet-stack/ipv4-l3-protocol.h | 1 - src/internet-stack/ipv4-list-routing-impl.cc | 104 ++++++++++++---- src/internet-stack/ipv4-list-routing-impl.h | 13 +- .../ipv4-static-routing-impl.cc | 117 ++++++++++++++---- src/internet-stack/ipv4-static-routing-impl.h | 14 ++- src/internet-stack/tcp-socket-impl.cc | 9 +- src/internet-stack/tcp-test.cc | 2 - src/internet-stack/udp-test.cc | 2 - src/node/ipv4-routing-protocol.h | 44 +++++++ src/node/ipv4-static-routing.h | 4 - src/node/ipv4.h | 2 +- .../global-route-manager-impl.cc | 1 - .../global-routing/ipv4-global-routing.cc | 35 +++--- .../global-routing/ipv4-global-routing.h | 10 +- src/routing/olsr/olsr-routing-protocol.cc | 29 +++-- src/routing/olsr/olsr-routing-protocol.h | 9 +- 22 files changed, 406 insertions(+), 197 deletions(-) diff --git a/bindings/python/ns3_module_internet_stack.py b/bindings/python/ns3_module_internet_stack.py index a2626bc91..22ae33a65 100644 --- a/bindings/python/ns3_module_internet_stack.py +++ b/bindings/python/ns3_module_internet_stack.py @@ -541,6 +541,31 @@ def register_Ns3Ipv4StaticRoutingImpl_methods(root_module, cls): 'bool', [param('ns3::Ptr< ns3::Packet const >', 'p'), param('ns3::Ipv4Header const &', 'header'), param('ns3::Ptr< ns3::NetDevice const >', 'idev'), param('ns3::Callback< void, ns3::Ptr< ns3::Ipv4Route >, ns3::Ptr< ns3::Packet const >, ns3::Ipv4Header const &, ns3::empty, ns3::empty, ns3::empty, ns3::empty, ns3::empty, ns3::empty >', 'ucb'), param('ns3::Callback< void, ns3::Ptr< ns3::Ipv4MulticastRoute >, ns3::Ptr< ns3::Packet const >, ns3::Ipv4Header const &, ns3::empty, ns3::empty, ns3::empty, ns3::empty, ns3::empty, ns3::empty >', 'mcb'), param('ns3::Callback< void, ns3::Ptr< ns3::Packet const >, ns3::Ipv4Header const &, unsigned int, ns3::empty, ns3::empty, ns3::empty, ns3::empty, ns3::empty, ns3::empty >', 'lcb'), param('ns3::Callback< void, ns3::Ptr< ns3::Packet const >, ns3::Ipv4Header const &, ns3::empty, ns3::empty, ns3::empty, ns3::empty, ns3::empty, ns3::empty, ns3::empty >', 'ecb')], is_virtual=True) + ## ipv4-static-routing-impl.h: void ns3::Ipv4StaticRoutingImpl::NotifyInterfaceUp(uint32_t interface) [member function] + cls.add_method('NotifyInterfaceUp', + 'void', + [param('uint32_t', 'interface')], + is_virtual=True) + ## ipv4-static-routing-impl.h: void ns3::Ipv4StaticRoutingImpl::NotifyInterfaceDown(uint32_t interface) [member function] + cls.add_method('NotifyInterfaceDown', + 'void', + [param('uint32_t', 'interface')], + is_virtual=True) + ## ipv4-static-routing-impl.h: void ns3::Ipv4StaticRoutingImpl::NotifyAddAddress(uint32_t interface, ns3::Ipv4InterfaceAddress address) [member function] + cls.add_method('NotifyAddAddress', + 'void', + [param('uint32_t', 'interface'), param('ns3::Ipv4InterfaceAddress', 'address')], + is_virtual=True) + ## ipv4-static-routing-impl.h: void ns3::Ipv4StaticRoutingImpl::NotifyRemoveAddress(uint32_t interface, ns3::Ipv4InterfaceAddress address) [member function] + cls.add_method('NotifyRemoveAddress', + 'void', + [param('uint32_t', 'interface'), param('ns3::Ipv4InterfaceAddress', 'address')], + is_virtual=True) + ## ipv4-static-routing-impl.h: void ns3::Ipv4StaticRoutingImpl::SetIpv4(ns3::Ptr ipv4) [member function] + cls.add_method('SetIpv4', + 'void', + [param('ns3::Ptr< ns3::Ipv4 >', 'ipv4')], + is_virtual=True) ## ipv4-static-routing-impl.h: void ns3::Ipv4StaticRoutingImpl::AddHostRouteTo(ns3::Ipv4Address dest, ns3::Ipv4Address nextHop, uint32_t interface) [member function] cls.add_method('AddHostRouteTo', 'void', @@ -616,16 +641,6 @@ def register_Ns3Ipv4StaticRoutingImpl_methods(root_module, cls): 'void', [param('uint32_t', 'index')], is_virtual=True) - ## ipv4-static-routing-impl.h: void ns3::Ipv4StaticRoutingImpl::SetNode(ns3::Ptr node) [member function] - cls.add_method('SetNode', - 'void', - [param('ns3::Ptr< ns3::Node >', 'node')], - is_virtual=True) - ## ipv4-static-routing-impl.h: ns3::Ptr ns3::Ipv4StaticRoutingImpl::GetNode() const [member function] - cls.add_method('GetNode', - 'ns3::Ptr< ns3::Node >', - [], - is_const=True, is_virtual=True) ## ipv4-static-routing-impl.h: void ns3::Ipv4StaticRoutingImpl::DoDispose() [member function] cls.add_method('DoDispose', 'void', @@ -653,6 +668,31 @@ def register_Ns3Ipv4ListRoutingImpl_methods(root_module, cls): 'bool', [param('ns3::Ptr< ns3::Packet const >', 'p'), param('ns3::Ipv4Header const &', 'header'), param('ns3::Ptr< ns3::NetDevice const >', 'idev'), param('ns3::Callback< void, ns3::Ptr< ns3::Ipv4Route >, ns3::Ptr< ns3::Packet const >, ns3::Ipv4Header const &, ns3::empty, ns3::empty, ns3::empty, ns3::empty, ns3::empty, ns3::empty >', 'ucb'), param('ns3::Callback< void, ns3::Ptr< ns3::Ipv4MulticastRoute >, ns3::Ptr< ns3::Packet const >, ns3::Ipv4Header const &, ns3::empty, ns3::empty, ns3::empty, ns3::empty, ns3::empty, ns3::empty >', 'mcb'), param('ns3::Callback< void, ns3::Ptr< ns3::Packet const >, ns3::Ipv4Header const &, unsigned int, ns3::empty, ns3::empty, ns3::empty, ns3::empty, ns3::empty, ns3::empty >', 'lcb'), param('ns3::Callback< void, ns3::Ptr< ns3::Packet const >, ns3::Ipv4Header const &, ns3::empty, ns3::empty, ns3::empty, ns3::empty, ns3::empty, ns3::empty, ns3::empty >', 'ecb')], is_virtual=True) + ## ipv4-list-routing-impl.h: void ns3::Ipv4ListRoutingImpl::NotifyInterfaceUp(uint32_t interface) [member function] + cls.add_method('NotifyInterfaceUp', + 'void', + [param('uint32_t', 'interface')], + is_virtual=True) + ## ipv4-list-routing-impl.h: void ns3::Ipv4ListRoutingImpl::NotifyInterfaceDown(uint32_t interface) [member function] + cls.add_method('NotifyInterfaceDown', + 'void', + [param('uint32_t', 'interface')], + is_virtual=True) + ## ipv4-list-routing-impl.h: void ns3::Ipv4ListRoutingImpl::NotifyAddAddress(uint32_t interface, ns3::Ipv4InterfaceAddress address) [member function] + cls.add_method('NotifyAddAddress', + 'void', + [param('uint32_t', 'interface'), param('ns3::Ipv4InterfaceAddress', 'address')], + is_virtual=True) + ## ipv4-list-routing-impl.h: void ns3::Ipv4ListRoutingImpl::NotifyRemoveAddress(uint32_t interface, ns3::Ipv4InterfaceAddress address) [member function] + cls.add_method('NotifyRemoveAddress', + 'void', + [param('uint32_t', 'interface'), param('ns3::Ipv4InterfaceAddress', 'address')], + is_virtual=True) + ## ipv4-list-routing-impl.h: void ns3::Ipv4ListRoutingImpl::SetIpv4(ns3::Ptr ipv4) [member function] + cls.add_method('SetIpv4', + 'void', + [param('ns3::Ptr< ns3::Ipv4 >', 'ipv4')], + is_virtual=True) ## ipv4-list-routing-impl.h: void ns3::Ipv4ListRoutingImpl::AddRoutingProtocol(ns3::Ptr routingProtocol, int16_t priority) [member function] cls.add_method('AddRoutingProtocol', 'void', @@ -673,15 +713,6 @@ def register_Ns3Ipv4ListRoutingImpl_methods(root_module, cls): 'ns3::Ptr< ns3::Ipv4StaticRouting >', [], is_const=True, is_virtual=True) - ## ipv4-list-routing-impl.h: void ns3::Ipv4ListRoutingImpl::SetNode(ns3::Ptr node) [member function] - cls.add_method('SetNode', - 'void', - [param('ns3::Ptr< ns3::Node >', 'node')]) - ## ipv4-list-routing-impl.h: ns3::Ptr ns3::Ipv4ListRoutingImpl::GetNode() const [member function] - cls.add_method('GetNode', - 'ns3::Ptr< ns3::Node >', - [], - is_const=True) ## ipv4-list-routing-impl.h: void ns3::Ipv4ListRoutingImpl::DoDispose() [member function] cls.add_method('DoDispose', 'void', diff --git a/bindings/python/ns3_module_node.py b/bindings/python/ns3_module_node.py index 7e33b5bd3..b0b200198 100644 --- a/bindings/python/ns3_module_node.py +++ b/bindings/python/ns3_module_node.py @@ -2855,6 +2855,31 @@ def register_Ns3Ipv4RoutingProtocol_methods(root_module, cls): 'bool', [param('ns3::Ptr< ns3::Packet const >', 'p'), param('ns3::Ipv4Header const &', 'header'), param('ns3::Ptr< ns3::NetDevice const >', 'idev'), param('ns3::Callback< void, ns3::Ptr< ns3::Ipv4Route >, ns3::Ptr< ns3::Packet const >, ns3::Ipv4Header const &, ns3::empty, ns3::empty, ns3::empty, ns3::empty, ns3::empty, ns3::empty >', 'ucb'), param('ns3::Callback< void, ns3::Ptr< ns3::Ipv4MulticastRoute >, ns3::Ptr< ns3::Packet const >, ns3::Ipv4Header const &, ns3::empty, ns3::empty, ns3::empty, ns3::empty, ns3::empty, ns3::empty >', 'mcb'), param('ns3::Callback< void, ns3::Ptr< ns3::Packet const >, ns3::Ipv4Header const &, unsigned int, ns3::empty, ns3::empty, ns3::empty, ns3::empty, ns3::empty, ns3::empty >', 'lcb'), param('ns3::Callback< void, ns3::Ptr< ns3::Packet const >, ns3::Ipv4Header const &, ns3::empty, ns3::empty, ns3::empty, ns3::empty, ns3::empty, ns3::empty, ns3::empty >', 'ecb')], is_pure_virtual=True, is_virtual=True) + ## ipv4-routing-protocol.h: void ns3::Ipv4RoutingProtocol::NotifyInterfaceUp(uint32_t interface) [member function] + cls.add_method('NotifyInterfaceUp', + 'void', + [param('uint32_t', 'interface')], + is_pure_virtual=True, is_virtual=True) + ## ipv4-routing-protocol.h: void ns3::Ipv4RoutingProtocol::NotifyInterfaceDown(uint32_t interface) [member function] + cls.add_method('NotifyInterfaceDown', + 'void', + [param('uint32_t', 'interface')], + is_pure_virtual=True, is_virtual=True) + ## ipv4-routing-protocol.h: void ns3::Ipv4RoutingProtocol::NotifyAddAddress(uint32_t interface, ns3::Ipv4InterfaceAddress address) [member function] + cls.add_method('NotifyAddAddress', + 'void', + [param('uint32_t', 'interface'), param('ns3::Ipv4InterfaceAddress', 'address')], + is_pure_virtual=True, is_virtual=True) + ## ipv4-routing-protocol.h: void ns3::Ipv4RoutingProtocol::NotifyRemoveAddress(uint32_t interface, ns3::Ipv4InterfaceAddress address) [member function] + cls.add_method('NotifyRemoveAddress', + 'void', + [param('uint32_t', 'interface'), param('ns3::Ipv4InterfaceAddress', 'address')], + is_pure_virtual=True, is_virtual=True) + ## ipv4-routing-protocol.h: void ns3::Ipv4RoutingProtocol::SetIpv4(ns3::Ptr ipv4) [member function] + cls.add_method('SetIpv4', + 'void', + [param('ns3::Ptr< ns3::Ipv4 >', 'ipv4')], + is_pure_virtual=True, is_virtual=True) return def register_Ns3Ipv4StaticRouting_methods(root_module, cls): @@ -2942,16 +2967,6 @@ def register_Ns3Ipv4StaticRouting_methods(root_module, cls): 'void', [param('uint32_t', 'index')], is_pure_virtual=True, is_virtual=True) - ## ipv4-static-routing.h: void ns3::Ipv4StaticRouting::SetNode(ns3::Ptr node) [member function] - cls.add_method('SetNode', - 'void', - [param('ns3::Ptr< ns3::Node >', 'node')], - is_pure_virtual=True, is_virtual=True) - ## ipv4-static-routing.h: ns3::Ptr ns3::Ipv4StaticRouting::GetNode() const [member function] - cls.add_method('GetNode', - 'ns3::Ptr< ns3::Node >', - [], - is_pure_virtual=True, is_const=True, is_virtual=True) return def register_Ns3NetDevice_methods(root_module, cls): diff --git a/bindings/python/ns3_module_olsr.py b/bindings/python/ns3_module_olsr.py index f712840d3..cb68f71df 100644 --- a/bindings/python/ns3_module_olsr.py +++ b/bindings/python/ns3_module_olsr.py @@ -747,10 +747,6 @@ def register_Ns3OlsrRoutingProtocol_methods(root_module, cls): is_static=True) ## olsr-routing-protocol.h: ns3::olsr::RoutingProtocol::RoutingProtocol() [constructor] cls.add_constructor([]) - ## olsr-routing-protocol.h: void ns3::olsr::RoutingProtocol::SetNode(ns3::Ptr node) [member function] - cls.add_method('SetNode', - 'void', - [param('ns3::Ptr< ns3::Node >', 'node')]) ## olsr-routing-protocol.h: void ns3::olsr::RoutingProtocol::Start() [member function] cls.add_method('Start', 'void', @@ -769,6 +765,31 @@ def register_Ns3OlsrRoutingProtocol_methods(root_module, cls): 'bool', [param('ns3::Ptr< ns3::Packet const >', 'p'), param('ns3::Ipv4Header const &', 'header'), param('ns3::Ptr< ns3::NetDevice const >', 'idev'), param('ns3::Callback< void, ns3::Ptr< ns3::Ipv4Route >, ns3::Ptr< ns3::Packet const >, ns3::Ipv4Header const &, ns3::empty, ns3::empty, ns3::empty, ns3::empty, ns3::empty, ns3::empty >', 'ucb'), param('ns3::Callback< void, ns3::Ptr< ns3::Ipv4MulticastRoute >, ns3::Ptr< ns3::Packet const >, ns3::Ipv4Header const &, ns3::empty, ns3::empty, ns3::empty, ns3::empty, ns3::empty, ns3::empty >', 'mcb'), param('ns3::Callback< void, ns3::Ptr< ns3::Packet const >, ns3::Ipv4Header const &, unsigned int, ns3::empty, ns3::empty, ns3::empty, ns3::empty, ns3::empty, ns3::empty >', 'lcb'), param('ns3::Callback< void, ns3::Ptr< ns3::Packet const >, ns3::Ipv4Header const &, ns3::empty, ns3::empty, ns3::empty, ns3::empty, ns3::empty, ns3::empty, ns3::empty >', 'ecb')], visibility='private', is_virtual=True) + ## olsr-routing-protocol.h: void ns3::olsr::RoutingProtocol::NotifyInterfaceUp(uint32_t interface) [member function] + cls.add_method('NotifyInterfaceUp', + 'void', + [param('uint32_t', 'interface')], + visibility='private', is_virtual=True) + ## olsr-routing-protocol.h: void ns3::olsr::RoutingProtocol::NotifyInterfaceDown(uint32_t interface) [member function] + cls.add_method('NotifyInterfaceDown', + 'void', + [param('uint32_t', 'interface')], + visibility='private', is_virtual=True) + ## olsr-routing-protocol.h: void ns3::olsr::RoutingProtocol::NotifyAddAddress(uint32_t interface, ns3::Ipv4InterfaceAddress address) [member function] + cls.add_method('NotifyAddAddress', + 'void', + [param('uint32_t', 'interface'), param('ns3::Ipv4InterfaceAddress', 'address')], + visibility='private', is_virtual=True) + ## olsr-routing-protocol.h: void ns3::olsr::RoutingProtocol::NotifyRemoveAddress(uint32_t interface, ns3::Ipv4InterfaceAddress address) [member function] + cls.add_method('NotifyRemoveAddress', + 'void', + [param('uint32_t', 'interface'), param('ns3::Ipv4InterfaceAddress', 'address')], + visibility='private', is_virtual=True) + ## olsr-routing-protocol.h: void ns3::olsr::RoutingProtocol::SetIpv4(ns3::Ptr ipv4) [member function] + cls.add_method('SetIpv4', + 'void', + [param('ns3::Ptr< ns3::Ipv4 >', 'ipv4')], + visibility='private', is_virtual=True) ## olsr-routing-protocol.h: void ns3::olsr::RoutingProtocol::DoDispose() [member function] cls.add_method('DoDispose', 'void', diff --git a/src/helper/internet-stack-helper.cc b/src/helper/internet-stack-helper.cc index f99c38962..fab320827 100644 --- a/src/helper/internet-stack-helper.cc +++ b/src/helper/internet-stack-helper.cc @@ -244,10 +244,8 @@ InternetStackHelper::Install (Ptr node) const // XXX cut this over to use of TypeIds and factories Ptr ipv4RoutingImpl = CreateObject (); Ptr ipv4staticRoutingImpl = CreateObject (); - ipv4staticRoutingImpl->SetNode (node); ipv4RoutingImpl->AddRoutingProtocol (ipv4staticRoutingImpl, 0); ipv4->SetRoutingProtocol (ipv4RoutingImpl); - ipv4RoutingImpl->SetNode (node); } void diff --git a/src/helper/olsr-helper.cc b/src/helper/olsr-helper.cc index c90897bf0..f2e9ace97 100644 --- a/src/helper/olsr-helper.cc +++ b/src/helper/olsr-helper.cc @@ -76,7 +76,6 @@ OlsrHelper::Install (Ptr node) Ptr ipv4Routing = DynamicCast (ipv4->GetRoutingProtocol ()); NS_ASSERT (ipv4Routing); ipv4Routing->AddRoutingProtocol (agent, 10); - agent->SetNode (node); agent->Start (); } void diff --git a/src/internet-stack/ipv4-l3-protocol.cc b/src/internet-stack/ipv4-l3-protocol.cc index d9799fe70..78d06fc1b 100644 --- a/src/internet-stack/ipv4-l3-protocol.cc +++ b/src/internet-stack/ipv4-l3-protocol.cc @@ -163,12 +163,7 @@ Ipv4L3Protocol::SetRoutingProtocol (Ptr routingProtocol) { NS_LOG_FUNCTION (this); m_routingProtocol = routingProtocol; - // XXX should check all interfaces to see if any were set to Up state - // prior to a routing protocol being added - if (GetStaticRouting () != 0) - { - GetStaticRouting ()->AddHostRouteTo (Ipv4Address::GetLoopback (), 0); - } + m_routingProtocol->SetIpv4 (this); } @@ -230,11 +225,11 @@ Ipv4L3Protocol::SetupLoopback (void) Ptr node = GetObject (); node->RegisterProtocolHandler (MakeCallback (&Ipv4L3Protocol::Receive, this), Ipv4L3Protocol::PROT_NUMBER, device); - if (GetStaticRouting () != 0) - { - GetStaticRouting ()->AddHostRouteTo (Ipv4Address::GetLoopback (), index); - } interface->SetUp (); + if (m_routingProtocol != 0) + { + m_routingProtocol->NotifyInterfaceUp (index); + } } void @@ -244,26 +239,6 @@ Ipv4L3Protocol::SetDefaultTtl (uint8_t ttl) m_defaultTtl = ttl; } -// XXX need to remove dependencies on Ipv4StaticRouting from this class -Ptr -Ipv4L3Protocol::GetStaticRouting (void) const -{ - NS_LOG_FUNCTION_NOARGS (); - Ptr staticRouting; - if (m_routingProtocol != 0) - { - Ptr sr = DynamicCast (m_routingProtocol); - if (sr != 0) - { - return sr; - } - Ptr lr = DynamicCast (m_routingProtocol); - NS_ASSERT (lr); - staticRouting = lr->GetStaticRouting (); - } - return staticRouting; -} - uint32_t Ipv4L3Protocol::AddInterface (Ptr device) { @@ -761,7 +736,12 @@ Ipv4L3Protocol::AddAddress (uint32_t i, Ipv4InterfaceAddress address) { NS_LOG_FUNCTION (this << i << address); Ptr interface = GetInterface (i); - return interface->AddAddress (address); + uint32_t index = interface->AddAddress (address); + if (m_routingProtocol != 0) + { + m_routingProtocol->NotifyAddAddress (i, address); + } + return index; } Ipv4InterfaceAddress @@ -819,18 +799,9 @@ Ipv4L3Protocol::SetUp (uint32_t i) Ptr interface = GetInterface (i); interface->SetUp (); - // If interface address and network mask have been set, add a route - // to the network of the interface (like e.g. ifconfig does on a - // Linux box) - for (uint32_t j = 0; j < interface->GetNAddresses (); j++) + if (m_routingProtocol != 0) { - if (((interface->GetAddress (j).GetLocal ()) != (Ipv4Address ())) - && (interface->GetAddress (j).GetMask ()) != (Ipv4Mask ())) - { - NS_ASSERT_MSG (GetStaticRouting(), "SetUp:: No static routing"); - GetStaticRouting ()->AddNetworkRouteTo (interface->GetAddress (j).GetLocal ().CombineMask (interface->GetAddress (j).GetMask ()), - interface->GetAddress (j).GetMask (), i); - } + m_routingProtocol->NotifyInterfaceUp (i); } } @@ -841,21 +812,9 @@ Ipv4L3Protocol::SetDown (uint32_t ifaceIndex) Ptr interface = GetInterface (ifaceIndex); interface->SetDown (); - // Remove all static routes that are going through this interface - bool modified = true; - while (modified) + if (m_routingProtocol != 0) { - modified = false; - for (uint32_t i = 0; i < GetStaticRouting ()->GetNRoutes (); i++) - { - Ipv4RoutingTableEntry route = GetStaticRouting ()->GetRoute (i); - if (route.GetInterface () == ifaceIndex) - { - GetStaticRouting ()->RemoveRoute (i); - modified = true; - break; - } - } + m_routingProtocol->NotifyInterfaceDown (ifaceIndex); } } diff --git a/src/internet-stack/ipv4-l3-protocol.h b/src/internet-stack/ipv4-l3-protocol.h index ae26ba232..cca227d7a 100644 --- a/src/internet-stack/ipv4-l3-protocol.h +++ b/src/internet-stack/ipv4-l3-protocol.h @@ -218,7 +218,6 @@ private: TracedCallback > m_dropTrace; Ptr m_routingProtocol; - Ptr GetStaticRouting (void) const; SocketList m_sockets; }; diff --git a/src/internet-stack/ipv4-list-routing-impl.cc b/src/internet-stack/ipv4-list-routing-impl.cc index 466bda81f..f42ee4cfb 100644 --- a/src/internet-stack/ipv4-list-routing-impl.cc +++ b/src/internet-stack/ipv4-list-routing-impl.cc @@ -42,7 +42,7 @@ Ipv4ListRoutingImpl::GetTypeId (void) Ipv4ListRoutingImpl::Ipv4ListRoutingImpl () - : m_node (0) + : m_ipv4 (0) { NS_LOG_FUNCTION_NOARGS (); } @@ -65,7 +65,7 @@ Ipv4ListRoutingImpl::DoDispose (void) (*rprotoIter).second = 0; } m_routingProtocols.clear (); - m_node = 0; + m_ipv4 = 0; } Ptr @@ -102,18 +102,17 @@ Ipv4ListRoutingImpl::RouteInput (Ptr p, const Ipv4Header &header, { bool retVal = false; NS_LOG_FUNCTION (p << header << idev); - NS_LOG_LOGIC ("RouteInput logic for node: " << m_node->GetId ()); + NS_LOG_LOGIC ("RouteInput logic for node: " << m_ipv4->GetObject ()->GetId ()); - Ptr ipv4 = m_node->GetObject (); - NS_ASSERT (ipv4); - uint32_t iif = ipv4->GetInterfaceForDevice (idev); + NS_ASSERT (m_ipv4 != 0); + uint32_t iif = m_ipv4->GetInterfaceForDevice (idev); // Multicast recognition; handle local delivery here // if (header.GetDestination().IsMulticast ()) { #ifdef NOTYET - if (ipv4->MulticastCheckGroup (iif, header.GetDestination ())) + if (m_ipv4->MulticastCheckGroup (iif, header.GetDestination ())) #endif if (true) { @@ -152,11 +151,11 @@ Ipv4ListRoutingImpl::RouteInput (Ptr p, const Ipv4Header &header, // destination unicast address does not match one of the iif addresses, // but we check our other interfaces. This could be an option // (to remove the outer loop immediately below and just check iif). - for (uint32_t j = 0; j < ipv4->GetNInterfaces (); j++) + for (uint32_t j = 0; j < m_ipv4->GetNInterfaces (); j++) { - for (uint32_t i = 0; i < ipv4->GetNAddresses (j); i++) + for (uint32_t i = 0; i < m_ipv4->GetNAddresses (j); i++) { - Ipv4InterfaceAddress iaddr = ipv4->GetAddress (j, i); + Ipv4InterfaceAddress iaddr = m_ipv4->GetAddress (j, i); Ipv4Address addr = iaddr.GetLocal (); if (addr.IsEqual (header.GetDestination ())) { @@ -195,13 +194,79 @@ Ipv4ListRoutingImpl::RouteInput (Ptr p, const Ipv4Header &header, return retVal; } +void +Ipv4ListRoutingImpl::NotifyInterfaceUp (uint32_t interface) +{ + NS_LOG_FUNCTION (this << interface); + for (Ipv4RoutingProtocolList::const_iterator rprotoIter = + m_routingProtocols.begin (); + rprotoIter != m_routingProtocols.end (); + rprotoIter++) + { + (*rprotoIter).second->NotifyInterfaceUp (interface); + } +} +void +Ipv4ListRoutingImpl::NotifyInterfaceDown (uint32_t interface) +{ + NS_LOG_FUNCTION (this << interface); + for (Ipv4RoutingProtocolList::const_iterator rprotoIter = + m_routingProtocols.begin (); + rprotoIter != m_routingProtocols.end (); + rprotoIter++) + { + (*rprotoIter).second->NotifyInterfaceDown (interface); + } +} +void +Ipv4ListRoutingImpl::NotifyAddAddress (uint32_t interface, Ipv4InterfaceAddress address) +{ + NS_LOG_FUNCTION(this << interface << address); + for (Ipv4RoutingProtocolList::const_iterator rprotoIter = + m_routingProtocols.begin (); + rprotoIter != m_routingProtocols.end (); + rprotoIter++) + { + (*rprotoIter).second->NotifyAddAddress (interface, address); + } +} +void +Ipv4ListRoutingImpl::NotifyRemoveAddress (uint32_t interface, Ipv4InterfaceAddress address) +{ + NS_LOG_FUNCTION(this << interface << address); + for (Ipv4RoutingProtocolList::const_iterator rprotoIter = + m_routingProtocols.begin (); + rprotoIter != m_routingProtocols.end (); + rprotoIter++) + { + (*rprotoIter).second->NotifyRemoveAddress (interface, address); + } +} +void +Ipv4ListRoutingImpl::SetIpv4 (Ptr ipv4) +{ + NS_LOG_FUNCTION(this << ipv4); + NS_ASSERT (m_ipv4 == 0); + for (Ipv4RoutingProtocolList::const_iterator rprotoIter = + m_routingProtocols.begin (); + rprotoIter != m_routingProtocols.end (); + rprotoIter++) + { + (*rprotoIter).second->SetIpv4 (ipv4); + } + m_ipv4 = ipv4; +} + void Ipv4ListRoutingImpl::AddRoutingProtocol (Ptr routingProtocol, int16_t priority) { NS_LOG_FUNCTION (this << routingProtocol->GetInstanceTypeId () << priority); - m_routingProtocols.push_back - (std::pair > (-priority, routingProtocol)); + m_routingProtocols.push_back (std::make_pair (-priority, routingProtocol)); m_routingProtocols.sort (); + if (m_ipv4 != 0) + { + routingProtocol->SetIpv4 (m_ipv4); + } } uint32_t @@ -253,19 +318,4 @@ Ipv4ListRoutingImpl::GetStaticRouting (void) const } -void -Ipv4ListRoutingImpl::SetNode (Ptr node) -{ - NS_LOG_FUNCTION_NOARGS (); - m_node = node; -} - -Ptr -Ipv4ListRoutingImpl::GetNode (void) const -{ - NS_LOG_FUNCTION_NOARGS (); - return m_node; -} - - }//namespace ns3 diff --git a/src/internet-stack/ipv4-list-routing-impl.h b/src/internet-stack/ipv4-list-routing-impl.h index b323ccae8..1a6bd01a2 100644 --- a/src/internet-stack/ipv4-list-routing-impl.h +++ b/src/internet-stack/ipv4-list-routing-impl.h @@ -39,6 +39,11 @@ public: virtual bool RouteInput (Ptr p, const Ipv4Header &header, Ptr idev, UnicastForwardCallback ucb, MulticastForwardCallback mcb, LocalDeliverCallback lcb, ErrorCallback ecb); + virtual void NotifyInterfaceUp (uint32_t interface); + virtual void NotifyInterfaceDown (uint32_t interface); + virtual void NotifyAddAddress (uint32_t interface, Ipv4InterfaceAddress address); + virtual void NotifyRemoveAddress (uint32_t interface, Ipv4InterfaceAddress address); + virtual void SetIpv4 (Ptr ipv4); virtual void AddRoutingProtocol (Ptr routingProtocol, int16_t priority); @@ -47,16 +52,12 @@ public: virtual Ptr GetRoutingProtocol (uint32_t index, int16_t& priority) const; virtual Ptr GetStaticRouting (void) const; - - void SetNode (Ptr node); - Ptr GetNode (void) const; - protected: void DoDispose (void); private: - typedef std::list< std::pair< int, Ptr > > Ipv4RoutingProtocolList; + typedef std::list< std::pair< int16_t, Ptr > > Ipv4RoutingProtocolList; Ipv4RoutingProtocolList m_routingProtocols; - Ptr m_node; + Ptr m_ipv4; }; diff --git a/src/internet-stack/ipv4-static-routing-impl.cc b/src/internet-stack/ipv4-static-routing-impl.cc index 65aff1474..d0a2d3ede 100644 --- a/src/internet-stack/ipv4-static-routing-impl.cc +++ b/src/internet-stack/ipv4-static-routing-impl.cc @@ -42,7 +42,7 @@ Ipv4StaticRoutingImpl::GetTypeId (void) } Ipv4StaticRoutingImpl::Ipv4StaticRoutingImpl () -: m_defaultRoute (0), m_node (0) +: m_defaultRoute (0), m_ipv4 (0) { NS_LOG_FUNCTION_NOARGS (); } @@ -222,15 +222,14 @@ Ipv4StaticRoutingImpl::LookupStatic (Ipv4Address dest) if ((*i)->GetDest ().IsEqual (dest)) { NS_LOG_LOGIC ("Found global host route" << *i); - Ptr ipv4 = m_node->GetObject (); Ipv4RoutingTableEntry* route = (*i); rtentry = Create (); rtentry->SetDestination (route->GetDest ()); // XXX handle multi-address case - rtentry->SetSource (ipv4->GetAddress (route->GetInterface(), 0).GetLocal ()); + rtentry->SetSource (m_ipv4->GetAddress (route->GetInterface(), 0).GetLocal ()); rtentry->SetGateway (route->GetGateway ()); uint32_t interfaceIdx = route->GetInterface (); - rtentry->SetOutputDevice (ipv4->GetNetDevice (interfaceIdx)); + rtentry->SetOutputDevice (m_ipv4->GetNetDevice (interfaceIdx)); return rtentry; } } @@ -244,15 +243,14 @@ Ipv4StaticRoutingImpl::LookupStatic (Ipv4Address dest) if (mask.IsMatch (dest, entry)) { NS_LOG_LOGIC ("Found global network route" << *j); - Ptr ipv4 = m_node->GetObject (); Ipv4RoutingTableEntry* route = (*j); rtentry = Create (); rtentry->SetDestination (route->GetDest ()); // XXX handle multi-address case - rtentry->SetSource (ipv4->GetAddress (route->GetInterface(), 0).GetLocal ()); + rtentry->SetSource (m_ipv4->GetAddress (route->GetInterface(), 0).GetLocal ()); rtentry->SetGateway (route->GetGateway ()); uint32_t interfaceIdx = route->GetInterface (); - rtentry->SetOutputDevice (ipv4->GetNetDevice (interfaceIdx)); + rtentry->SetOutputDevice (m_ipv4->GetNetDevice (interfaceIdx)); return rtentry; } } @@ -260,15 +258,14 @@ Ipv4StaticRoutingImpl::LookupStatic (Ipv4Address dest) { NS_ASSERT (m_defaultRoute->IsDefault ()); NS_LOG_LOGIC ("Found global network route" << m_defaultRoute); - Ptr ipv4 = m_node->GetObject (); Ipv4RoutingTableEntry* route = m_defaultRoute; rtentry = Create (); rtentry->SetDestination (route->GetDest ()); // XXX handle multi-address case - rtentry->SetSource (ipv4->GetAddress (route->GetInterface(), 0).GetLocal ()); + rtentry->SetSource (m_ipv4->GetAddress (route->GetInterface(), 0).GetLocal ()); rtentry->SetGateway (route->GetGateway ()); uint32_t interfaceIdx = route->GetInterface (); - rtentry->SetOutputDevice (ipv4->GetNetDevice (interfaceIdx)); + rtentry->SetOutputDevice (m_ipv4->GetNetDevice (interfaceIdx)); return rtentry; } return 0; @@ -307,7 +304,6 @@ Ipv4StaticRoutingImpl::LookupStatic ( interface == route->GetInputInterface ()) { NS_LOG_LOGIC ("Found multicast route" << *i); - Ptr ipv4 = m_node->GetObject (); mrtentry = Create (); mrtentry->SetGroup (route->GetGroup ()); mrtentry->SetOrigin (route->GetOrigin ()); @@ -480,13 +476,12 @@ Ipv4StaticRoutingImpl::RouteInput (Ptr p, const Ipv4Header &ipHea LocalDeliverCallback lcb, ErrorCallback ecb) { NS_LOG_FUNCTION (this << p << ipHeader << ipHeader.GetSource () << ipHeader.GetDestination () << idev); - Ptr ipv4 = m_node->GetObject (); if (ipHeader.GetDestination ().IsMulticast ()) { NS_LOG_LOGIC ("Multicast destination"); Ptr mrtentry = LookupStatic(ipHeader.GetSource (), - ipHeader.GetDestination (), ipv4->GetInterfaceForDevice (idev)); + ipHeader.GetDestination (), m_ipv4->GetInterfaceForDevice (idev)); if (mrtentry) { @@ -550,22 +545,100 @@ Ipv4StaticRoutingImpl::DoDispose (void) { delete (*i); } + m_ipv4 = 0; Ipv4RoutingProtocol::DoDispose (); } -void -Ipv4StaticRoutingImpl::SetNode (Ptr node) +void +Ipv4StaticRoutingImpl::NotifyInterfaceUp (uint32_t i) { - NS_LOG_FUNCTION_NOARGS (); - m_node = node; + // If interface address and network mask have been set, add a route + // to the network of the interface (like e.g. ifconfig does on a + // Linux box) + for (uint32_t j = 0; j < m_ipv4->GetNAddresses (i); j++) + { + if (m_ipv4->GetAddress (i,j).GetLocal () != Ipv4Address () && + m_ipv4->GetAddress (i,j).GetMask () != Ipv4Mask ()) + { + AddNetworkRouteTo (m_ipv4->GetAddress (i,j).GetLocal ().CombineMask (m_ipv4->GetAddress (i,j).GetMask ()), + m_ipv4->GetAddress (i,j).GetMask (), i); + } + } } -Ptr -Ipv4StaticRoutingImpl::GetNode (void) const +void +Ipv4StaticRoutingImpl::NotifyInterfaceDown (uint32_t i) { - NS_LOG_FUNCTION_NOARGS (); - return m_node; -} + // Remove all static routes that are going through this interface + for (uint32_t j = 0; j < GetNRoutes (); j++) + { + Ipv4RoutingTableEntry route = GetRoute (j); + if (route.GetInterface () == i) + { + RemoveRoute (j); + } + } +} +void +Ipv4StaticRoutingImpl::NotifyAddAddress (uint32_t interface, Ipv4InterfaceAddress address) +{ + NS_LOG_FUNCTION (this << interface); + if (!m_ipv4->IsUp (interface)) + { + return; + } + + Ipv4Address networkAddress = address.GetLocal ().CombineMask (address.GetMask ()); + Ipv4Mask networkMask = address.GetMask (); + if (address.GetLocal () != Ipv4Address () && + address.GetMask () != Ipv4Mask ()) + { + AddNetworkRouteTo (networkAddress, + networkMask, interface); + } +} +void +Ipv4StaticRoutingImpl::NotifyRemoveAddress (uint32_t interface, Ipv4InterfaceAddress address) +{ + if (!m_ipv4->IsUp (interface)) + { + return; + } + Ipv4Address networkAddress = address.GetLocal ().CombineMask (address.GetMask ()); + Ipv4Mask networkMask = address.GetMask (); + // Remove all static routes that are going through this interface + // which reference this network + for (uint32_t j = 0; j < GetNRoutes (); j++) + { + Ipv4RoutingTableEntry route = GetRoute (j); + if (route.GetInterface () == interface && + route.IsNetwork () && + route.GetDestNetwork () == networkAddress && + route.GetDestNetworkMask () == networkMask) + { + RemoveRoute (j); + } + } +} + +void +Ipv4StaticRoutingImpl::SetIpv4 (Ptr ipv4) +{ + NS_LOG_FUNCTION (this << ipv4); + NS_ASSERT (m_ipv4 == 0 && ipv4 != 0); + m_ipv4 = ipv4; + for (uint32_t i = 0; i < m_ipv4->GetNInterfaces (); i++) + { + if (m_ipv4->IsUp (i)) + { + NotifyInterfaceUp (i); + } + else + { + NotifyInterfaceDown (i); + } + } +} }//namespace ns3 diff --git a/src/internet-stack/ipv4-static-routing-impl.h b/src/internet-stack/ipv4-static-routing-impl.h index 1bfca98ef..b701f085e 100644 --- a/src/internet-stack/ipv4-static-routing-impl.h +++ b/src/internet-stack/ipv4-static-routing-impl.h @@ -56,6 +56,13 @@ public: UnicastForwardCallback ucb, MulticastForwardCallback mcb, LocalDeliverCallback lcb, ErrorCallback ecb); + virtual void NotifyInterfaceUp (uint32_t interface); + virtual void NotifyInterfaceDown (uint32_t interface); + virtual void NotifyAddAddress (uint32_t interface, Ipv4InterfaceAddress address); + virtual void NotifyRemoveAddress (uint32_t interface, Ipv4InterfaceAddress address); + virtual void SetIpv4 (Ptr ipv4); + + /** * \brief Add a host route to the static routing table. * @@ -332,11 +339,8 @@ public: */ void RemoveMulticastRoute (uint32_t index); - void SetNode (Ptr node); - Ptr GetNode (void) const; - protected: - void DoDispose (void); + virtual void DoDispose (void); private: typedef std::list HostRoutes; @@ -359,7 +363,7 @@ private: Ipv4RoutingTableEntry *m_defaultRoute; MulticastRoutes m_multicastRoutes; - Ptr m_node; + Ptr m_ipv4; }; } // Namespace ns3 diff --git a/src/internet-stack/tcp-socket-impl.cc b/src/internet-stack/tcp-socket-impl.cc index 8d3c5a691..12b6fcfbf 100644 --- a/src/internet-stack/tcp-socket-impl.cc +++ b/src/internet-stack/tcp-socket-impl.cc @@ -25,15 +25,16 @@ #include "ns3/ipv4.h" #include "ns3/ipv4-interface-address.h" #include "ns3/ipv4-route.h" -#include "tcp-socket-impl.h" -#include "tcp-l4-protocol.h" -#include "ipv4-end-point.h" +#include "ns3/ipv4-routing-protocol.h" #include "ns3/simulation-singleton.h" -#include "tcp-typedefs.h" #include "ns3/simulator.h" #include "ns3/packet.h" #include "ns3/uinteger.h" #include "ns3/trace-source-accessor.h" +#include "tcp-typedefs.h" +#include "tcp-socket-impl.h" +#include "tcp-l4-protocol.h" +#include "ipv4-end-point.h" #include diff --git a/src/internet-stack/tcp-test.cc b/src/internet-stack/tcp-test.cc index 0eeac0c6b..85ca606b1 100644 --- a/src/internet-stack/tcp-test.cc +++ b/src/internet-stack/tcp-test.cc @@ -59,9 +59,7 @@ AddInternetStack (Ptr node) //Routing for Ipv4 Ptr ipv4RoutingImpl = CreateObject (); ipv4->SetRoutingProtocol (ipv4RoutingImpl); - ipv4RoutingImpl->SetNode (node); Ptr ipv4staticRoutingImpl = CreateObject (); - ipv4staticRoutingImpl->SetNode (node); ipv4RoutingImpl->AddRoutingProtocol (ipv4staticRoutingImpl, 0); node->AggregateObject(ipv4); //ICMP diff --git a/src/internet-stack/udp-test.cc b/src/internet-stack/udp-test.cc index 1387d0cac..a8a0aabf6 100644 --- a/src/internet-stack/udp-test.cc +++ b/src/internet-stack/udp-test.cc @@ -59,9 +59,7 @@ AddInternetStack (Ptr node) //Routing for Ipv4 Ptr ipv4RoutingImpl = CreateObject (); ipv4->SetRoutingProtocol (ipv4RoutingImpl); - ipv4RoutingImpl->SetNode (node); Ptr ipv4staticRoutingImpl = CreateObject (); - ipv4staticRoutingImpl->SetNode (node); ipv4RoutingImpl->AddRoutingProtocol (ipv4staticRoutingImpl, 0); node->AggregateObject(ipv4); //ICMP diff --git a/src/node/ipv4-routing-protocol.h b/src/node/ipv4-routing-protocol.h index faeb52985..8a940838e 100644 --- a/src/node/ipv4-routing-protocol.h +++ b/src/node/ipv4-routing-protocol.h @@ -23,6 +23,8 @@ #include "ns3/object.h" #include "ns3/socket.h" #include "ipv4-header.h" +#include "ipv4-interface-address.h" +#include "ipv4.h" namespace ns3 { @@ -91,6 +93,48 @@ public: virtual bool RouteInput (Ptr p, const Ipv4Header &header, Ptr idev, UnicastForwardCallback ucb, MulticastForwardCallback mcb, LocalDeliverCallback lcb, ErrorCallback ecb) = 0; + + /** + * \param interface the index of the interface we are being notified about + * + * Protocols are expected to implement this method to be notified of the state change of + * an interface in a node. + */ + virtual void NotifyInterfaceUp (uint32_t interface) = 0; + /** + * \param interface the index of the interface we are being notified about + * + * Protocols are expected to implement this method to be notified of the state change of + * an interface in a node. + */ + virtual void NotifyInterfaceDown (uint32_t interface) = 0; + + /** + * \param interface the index of the interface we are being notified about + * \param address a new address being added to an interface + * + * Protocols are expected to implement this method to be notified whenever + * a new address is added to an interface. Typically used to add a 'network route' on an + * interface. Can be invoked on an up or down interface. + */ + virtual void NotifyAddAddress (uint32_t interface, Ipv4InterfaceAddress address) = 0; + + /** + * \param interface the index of the interface we are being notified about + * \param address a new address being added to an interface + * + * Protocols are expected to implement this method to be notified whenever + * a new address is removed from an interface. Typically used to remove the 'network route' of an + * interface. Can be invoked on an up or down interface. + */ + virtual void NotifyRemoveAddress (uint32_t interface, Ipv4InterfaceAddress address) = 0; + + /** + * \param ipv4 the ipv4 object this routing protocol is being associated with + * + * Typically, invoked directly or indirectly from ns3::Ipv4::SetRoutingProtocol + */ + virtual void SetIpv4 (Ptr ipv4) = 0; }; } //namespace ns3 diff --git a/src/node/ipv4-static-routing.h b/src/node/ipv4-static-routing.h index 076ed6f05..5acfe4cc1 100644 --- a/src/node/ipv4-static-routing.h +++ b/src/node/ipv4-static-routing.h @@ -357,10 +357,6 @@ public: * \see Ipv4StaticRouting::AddRoute */ virtual void RemoveMulticastRoute (uint32_t index) = 0; - - virtual void SetNode (Ptr node) = 0; - virtual Ptr GetNode (void) const = 0; - }; } // Namespace ns3 diff --git a/src/node/ipv4.h b/src/node/ipv4.h index 27fc89888..3e46c60ba 100644 --- a/src/node/ipv4.h +++ b/src/node/ipv4.h @@ -24,7 +24,6 @@ #include "ns3/object.h" #include "ns3/socket.h" #include "ns3/callback.h" -#include "ipv4-routing-protocol.h" #include "ipv4-address.h" #include "ipv4-interface-address.h" @@ -33,6 +32,7 @@ namespace ns3 { class Node; class NetDevice; class Packet; +class Ipv4RoutingProtocol; /** * \ingroup node diff --git a/src/routing/global-routing/global-route-manager-impl.cc b/src/routing/global-routing/global-route-manager-impl.cc index d311026c9..d808911a9 100644 --- a/src/routing/global-routing/global-route-manager-impl.cc +++ b/src/routing/global-routing/global-route-manager-impl.cc @@ -416,7 +416,6 @@ GlobalRouteManagerImpl::SelectRouterNodes () NS_LOG_LOGIC ("Adding GlobalRouting Protocol to node " << node->GetId ()); Ptr globalRouting = CreateObject (); - globalRouting->SetNode (node); // Here, we check whether there is an existing Ipv4RoutingProtocol object // to add this protocol to. Ptr ipv4 = node->GetObject (); diff --git a/src/routing/global-routing/ipv4-global-routing.cc b/src/routing/global-routing/ipv4-global-routing.cc index e6577ce34..3a8d8e04d 100644 --- a/src/routing/global-routing/ipv4-global-routing.cc +++ b/src/routing/global-routing/ipv4-global-routing.cc @@ -139,14 +139,13 @@ Ipv4GlobalRouting::LookupGlobal (Ipv4Address dest) } if (found == true) { - Ptr ipv4 = m_node->GetObject (); rtentry = Create (); rtentry->SetDestination (route->GetDest ()); // XXX handle multi-address case - rtentry->SetSource (ipv4->GetAddress (route->GetInterface(), 0).GetLocal ()); + rtentry->SetSource (m_ipv4->GetAddress (route->GetInterface(), 0).GetLocal ()); rtentry->SetGateway (route->GetGateway ()); uint32_t interfaceIdx = route->GetInterface (); - rtentry->SetOutputDevice (ipv4->GetNetDevice (interfaceIdx)); + rtentry->SetOutputDevice (m_ipv4->GetNetDevice (interfaceIdx)); return rtentry; } else @@ -318,21 +317,25 @@ Ipv4GlobalRouting::RouteInput (Ptr p, const Ipv4Header &ipHeader, // route request. } } - -void -Ipv4GlobalRouting::SetNode (Ptr node) +void +Ipv4GlobalRouting::NotifyInterfaceUp (uint32_t i) +{} +void +Ipv4GlobalRouting::NotifyInterfaceDown (uint32_t i) +{} +void +Ipv4GlobalRouting::NotifyAddAddress (uint32_t interface, Ipv4InterfaceAddress address) +{} +void +Ipv4GlobalRouting::NotifyRemoveAddress (uint32_t interface, Ipv4InterfaceAddress address) +{} +void +Ipv4GlobalRouting::SetIpv4 (Ptr ipv4) { - NS_LOG_FUNCTION_NOARGS (); - m_node = node; + NS_LOG_FUNCTION(this << ipv4); + NS_ASSERT (m_ipv4 == 0 && ipv4 != 0); + m_ipv4 = ipv4; } -Ptr -Ipv4GlobalRouting::GetNode (void) const -{ - NS_LOG_FUNCTION_NOARGS (); - return m_node; -} - - }//namespace ns3 diff --git a/src/routing/global-routing/ipv4-global-routing.h b/src/routing/global-routing/ipv4-global-routing.h index ab040b068..072f156e1 100644 --- a/src/routing/global-routing/ipv4-global-routing.h +++ b/src/routing/global-routing/ipv4-global-routing.h @@ -85,6 +85,11 @@ public: virtual bool RouteInput (Ptr p, const Ipv4Header &header, Ptr idev, UnicastForwardCallback ucb, MulticastForwardCallback mcb, LocalDeliverCallback lcb, ErrorCallback ecb); + virtual void NotifyInterfaceUp (uint32_t interface); + virtual void NotifyInterfaceDown (uint32_t interface); + virtual void NotifyAddAddress (uint32_t interface, Ipv4InterfaceAddress address); + virtual void NotifyRemoveAddress (uint32_t interface, Ipv4InterfaceAddress address); + virtual void SetIpv4 (Ptr ipv4); /** * \brief Add a host route to the global routing table. @@ -189,9 +194,6 @@ public: */ void RemoveRoute (uint32_t i); - void SetNode (Ptr node); - Ptr GetNode (void) const; - protected: void DoDispose (void); @@ -208,7 +210,7 @@ private: HostRoutes m_hostRoutes; NetworkRoutes m_networkRoutes; - Ptr m_node; + Ptr m_ipv4; }; } // Namespace ns3 diff --git a/src/routing/olsr/olsr-routing-protocol.cc b/src/routing/olsr/olsr-routing-protocol.cc index 6eb0034bd..2f72cd1e5 100644 --- a/src/routing/olsr/olsr-routing-protocol.cc +++ b/src/routing/olsr/olsr-routing-protocol.cc @@ -185,19 +185,21 @@ RoutingProtocol::GetTypeId (void) RoutingProtocol::RoutingProtocol () - : - m_helloTimer (Timer::CANCEL_ON_DESTROY), - m_tcTimer (Timer::CANCEL_ON_DESTROY), - m_midTimer (Timer::CANCEL_ON_DESTROY), - m_queuedMessagesTimer (Timer::CANCEL_ON_DESTROY) + : m_ipv4 (0), + m_helloTimer (Timer::CANCEL_ON_DESTROY), + m_tcTimer (Timer::CANCEL_ON_DESTROY), + m_midTimer (Timer::CANCEL_ON_DESTROY), + m_queuedMessagesTimer (Timer::CANCEL_ON_DESTROY) {} RoutingProtocol::~RoutingProtocol () {} void -RoutingProtocol::SetNode (Ptr node) +RoutingProtocol::SetIpv4 (Ptr ipv4) { + NS_ASSERT (ipv4 != 0); + NS_ASSERT (m_ipv4 == 0); NS_LOG_DEBUG ("Created olsr::RoutingProtocol"); m_helloTimer.SetFunction (&RoutingProtocol::HelloTimerExpire, this); m_tcTimer.SetFunction (&RoutingProtocol::TcTimerExpire, this); @@ -210,8 +212,7 @@ RoutingProtocol::SetNode (Ptr node) m_linkTupleTimerFirstTime = true; - m_ipv4 = node->GetObject (); - NS_ASSERT (m_ipv4); + m_ipv4 = ipv4; } void RoutingProtocol::DoDispose () @@ -2651,6 +2652,18 @@ bool RoutingProtocol::RouteInput (Ptr p, return false; } } +void +RoutingProtocol::NotifyInterfaceUp (uint32_t i) +{} +void +RoutingProtocol::NotifyInterfaceDown (uint32_t i) +{} +void +RoutingProtocol::NotifyAddAddress (uint32_t interface, Ipv4InterfaceAddress address) +{} +void +RoutingProtocol::NotifyRemoveAddress (uint32_t interface, Ipv4InterfaceAddress address) +{} /// diff --git a/src/routing/olsr/olsr-routing-protocol.h b/src/routing/olsr/olsr-routing-protocol.h index 0724a2b95..bcf8aedf8 100644 --- a/src/routing/olsr/olsr-routing-protocol.h +++ b/src/routing/olsr/olsr-routing-protocol.h @@ -36,6 +36,7 @@ #include "ns3/timer.h" #include "ns3/traced-callback.h" #include "ns3/ipv4.h" +#include "ns3/ipv4-routing-protocol.h" #include #include @@ -67,8 +68,6 @@ public: RoutingProtocol (); virtual ~RoutingProtocol (); - void SetNode (Ptr node); - void Start (); void SetMainInterface (uint32_t interface); @@ -125,6 +124,12 @@ private: virtual bool RouteInput (Ptr p, const Ipv4Header &header, Ptr idev, UnicastForwardCallback ucb, MulticastForwardCallback mcb, LocalDeliverCallback lcb, ErrorCallback ecb); + virtual void NotifyInterfaceUp (uint32_t interface); + virtual void NotifyInterfaceDown (uint32_t interface); + virtual void NotifyAddAddress (uint32_t interface, Ipv4InterfaceAddress address); + virtual void NotifyRemoveAddress (uint32_t interface, Ipv4InterfaceAddress address); + virtual void SetIpv4 (Ptr ipv4); + void DoDispose ();