22 #include "ns3/ipv4-route.h"
24 #include "ns3/ipv4-static-routing.h"
25 #include "ipv4-list-routing.h"
31 NS_OBJECT_ENSURE_REGISTERED (Ipv4ListRouting);
34 Ipv4ListRouting::GetTypeId (
void)
36 static TypeId tid = TypeId (
"ns3::Ipv4ListRouting")
37 .SetParent<Ipv4RoutingProtocol> ()
38 .AddConstructor<Ipv4ListRouting> ()
44 Ipv4ListRouting::Ipv4ListRouting ()
50 Ipv4ListRouting::~Ipv4ListRouting ()
59 for (Ipv4RoutingProtocolList::iterator rprotoIter = m_routingProtocols.begin ();
60 rprotoIter != m_routingProtocols.end (); rprotoIter++)
65 (*rprotoIter).second = 0;
67 m_routingProtocols.clear ();
75 *stream->
GetStream () <<
"Node: " << m_ipv4->GetObject<
Node> ()->GetId ()
77 <<
"Ipv4ListRouting table" << std::endl;
78 for (Ipv4RoutingProtocolList::const_iterator i = m_routingProtocols.begin ();
79 i != m_routingProtocols.end (); i++)
81 *stream->
GetStream () <<
" Priority: " << (*i).first <<
" Protocol: " << (*i).second->GetInstanceTypeId () << std::endl;
82 (*i).second->PrintRoutingTable (stream);
91 for (Ipv4RoutingProtocolList::iterator rprotoIter = m_routingProtocols.begin ();
92 rprotoIter != m_routingProtocols.end (); rprotoIter++)
95 protocol->Initialize ();
107 for (Ipv4RoutingProtocolList::const_iterator i = m_routingProtocols.begin ();
108 i != m_routingProtocols.end (); i++)
110 NS_LOG_LOGIC (
"Checking protocol " << (*i).second->GetInstanceTypeId () <<
" with priority " << (*i).first);
112 route = (*i).second->RouteOutput (p, header, oif, sockerr);
116 sockerr = Socket::ERROR_NOTERROR;
122 sockerr = Socket::ERROR_NOROUTETOHOST;
132 NS_LOG_FUNCTION (
this << p << header << idev << &ucb << &mcb << &lcb << &ecb);
138 NS_ASSERT (m_ipv4->GetInterfaceForDevice (idev) >= 0);
139 uint32_t iif = m_ipv4->GetInterfaceForDevice (idev);
141 retVal = m_ipv4->IsDestinationAddress (header.
GetDestination (), iif);
148 lcb (packetCopy, header, iif);
154 lcb (p, header, iif);
159 if (m_ipv4->IsForwarding (iif) ==
false)
161 NS_LOG_LOGIC (
"Forwarding disabled for this interface");
162 ecb (p, header, Socket::ERROR_NOROUTETOHOST);
171 downstreamLcb = MakeNullCallback<void, Ptr<const Packet>,
const Ipv4Header &, uint32_t > ();
173 for (Ipv4RoutingProtocolList::const_iterator rprotoIter =
174 m_routingProtocols.begin ();
175 rprotoIter != m_routingProtocols.end ();
178 if ((*rprotoIter).second->RouteInput (p, header, idev, ucb, mcb, downstreamLcb, ecb))
180 NS_LOG_LOGIC (
"Route found to forward packet in protocol " << (*rprotoIter).second->GetInstanceTypeId ().GetName ());
192 for (Ipv4RoutingProtocolList::const_iterator rprotoIter =
193 m_routingProtocols.begin ();
194 rprotoIter != m_routingProtocols.end ();
197 (*rprotoIter).second->NotifyInterfaceUp (interface);
204 for (Ipv4RoutingProtocolList::const_iterator rprotoIter =
205 m_routingProtocols.begin ();
206 rprotoIter != m_routingProtocols.end ();
209 (*rprotoIter).second->NotifyInterfaceDown (interface);
216 for (Ipv4RoutingProtocolList::const_iterator rprotoIter =
217 m_routingProtocols.begin ();
218 rprotoIter != m_routingProtocols.end ();
221 (*rprotoIter).second->NotifyAddAddress (interface, address);
228 for (Ipv4RoutingProtocolList::const_iterator rprotoIter =
229 m_routingProtocols.begin ();
230 rprotoIter != m_routingProtocols.end ();
233 (*rprotoIter).second->NotifyRemoveAddress (interface, address);
241 for (Ipv4RoutingProtocolList::const_iterator rprotoIter =
242 m_routingProtocols.begin ();
243 rprotoIter != m_routingProtocols.end ();
246 (*rprotoIter).second->SetIpv4 (ipv4);
254 NS_LOG_FUNCTION (
this << routingProtocol->GetInstanceTypeId () << priority);
255 m_routingProtocols.push_back (std::make_pair (priority, routingProtocol));
256 m_routingProtocols.sort ( Compare );
259 routingProtocol->SetIpv4 (m_ipv4);
267 return m_routingProtocols.size ();
274 if (index > m_routingProtocols.size ())
276 NS_FATAL_ERROR (
"Ipv4ListRouting::GetRoutingProtocol(): index " << index <<
" out of range");
279 for (Ipv4RoutingProtocolList::const_iterator rprotoIter = m_routingProtocols.begin ();
280 rprotoIter != m_routingProtocols.end (); rprotoIter++, i++)
284 priority = (*rprotoIter).first;
285 return (*rprotoIter).second;
292 Ipv4ListRouting::Compare (
const Ipv4RoutingProtocolEntry& a,
const Ipv4RoutingProtocolEntry& b)
295 return a.first > b.first;
#define NS_LOG_FUNCTION(parameters)
virtual void PrintRoutingTable(Ptr< OutputStreamWrapper > stream) const
Print the Routing Table entries.
virtual Ptr< Ipv4RoutingProtocol > GetRoutingProtocol(uint32_t index, int16_t &priority) const
virtual void SetIpv4(Ptr< Ipv4 > ipv4)
virtual void AddRoutingProtocol(Ptr< Ipv4RoutingProtocol > routingProtocol, int16_t priority)
Register a new routing protocol to be used in this IPv4 stack.
#define NS_ASSERT(condition)
#define NS_LOG_COMPONENT_DEFINE(name)
bool IsMulticast(void) const
virtual void NotifyRemoveAddress(uint32_t interface, Ipv4InterfaceAddress address)
#define NS_LOG_FUNCTION_NOARGS()
#define NS_FATAL_ERROR(msg)
fatal error handling
double GetSeconds(void) const
#define NS_LOG_LOGIC(msg)
Ptr< Packet > Copy(void) const
virtual uint32_t GetNRoutingProtocols(void) const
virtual void NotifyInterfaceUp(uint32_t interface)
virtual bool RouteInput(Ptr< const Packet > p, const Ipv4Header &header, Ptr< const NetDevice > idev, UnicastForwardCallback ucb, MulticastForwardCallback mcb, LocalDeliverCallback lcb, ErrorCallback ecb)
Route an input packet (to be forwarded or locally delivered)
virtual Ptr< Ipv4Route > RouteOutput(Ptr< Packet > p, const Ipv4Header &header, Ptr< NetDevice > oif, Socket::SocketErrno &sockerr)
Query routing cache for an existing route, for an outbound packet.
uint32_t GetId(void) const
a class to store IPv4 address information on an interface
virtual void NotifyInterfaceDown(uint32_t interface)
std::ostream * GetStream(void)
virtual void DoInitialize(void)
virtual void NotifyAddAddress(uint32_t interface, Ipv4InterfaceAddress address)