1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ 2 /* 3 * Copyright (c) 2009 University of Washington 4 * 5 * This program is free software; you can redistribute it and/or modify 6 * it under the terms of the GNU General Public License version 2 as 7 * published by the Free Software Foundation; 8 * 9 * This program is distributed in the hope that it will be useful, 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 * GNU General Public License for more details. 13 * 14 * You should have received a copy of the GNU General Public License 15 * along with this program; if not, write to the Free Software 16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 17 */ 18 19 #ifndef IPV4_LIST_ROUTING_H 20 #define IPV4_LIST_ROUTING_H 21 22 #include <list> 23 #include "ns3/ipv4-routing-protocol.h" 24 #include "ns3/simulator.h" 25 #include "ns3/nstime.h" 26 27 namespace ns3 { 28 29 /** 30 * \ingroup ipv4Routing 31 * 32 * \brief IPv4 list routing. 33 * 34 * This class is a specialization of Ipv4RoutingProtocol that allows 35 * other instances of Ipv4RoutingProtocol to be inserted in a 36 * prioritized list. Routing protocols in the list are consulted one 37 * by one, from highest to lowest priority, until a routing protocol 38 * is found that will take the packet (this corresponds to a non-zero 39 * return value to RouteOutput, or a return value of true to RouteInput). 40 * The order by which routing protocols with the same priority value 41 * are consulted is undefined. 42 * 43 */ 44 class Ipv4ListRouting : public Ipv4RoutingProtocol 45 { 46 public: 47 /** 48 * \brief Get the type ID of this class. 49 * \return type ID 50 */ 51 static TypeId GetTypeId (void); 52 53 Ipv4ListRouting (); 54 virtual ~Ipv4ListRouting (); 55 56 /** 57 * \brief Register a new routing protocol to be used in this IPv4 stack 58 * 59 * \param routingProtocol new routing protocol implementation object 60 * \param priority priority to give to this routing protocol. 61 * Values may range between -32768 and +32767. 62 */ 63 virtual void AddRoutingProtocol (Ptr<Ipv4RoutingProtocol> routingProtocol, int16_t priority); 64 /** 65 * \return number of routing protocols in the list 66 */ 67 virtual uint32_t GetNRoutingProtocols (void) const; 68 /** 69 * Return pointer to routing protocol stored at index, with the 70 * first protocol (index 0) the highest priority, the next one (index 1) 71 * the second highest priority, and so on. The priority parameter is an 72 * output parameter and it returns the integer priority of the protocol. 73 * 74 * \return pointer to routing protocol indexed by 75 * \param index index of protocol to return 76 * \param priority output parameter, set to the priority of the protocol 77 being returned 78 */ 79 virtual Ptr<Ipv4RoutingProtocol> GetRoutingProtocol (uint32_t index, int16_t& priority) const; 80 81 // Below are from Ipv4RoutingProtocol 82 virtual Ptr<Ipv4Route> RouteOutput (Ptr<Packet> p, const Ipv4Header &header, Ptr<NetDevice> oif, Socket::SocketErrno &sockerr); 83 84 virtual bool RouteInput (Ptr<const Packet> p, const Ipv4Header &header, Ptr<const NetDevice> idev, 85 UnicastForwardCallback ucb, MulticastForwardCallback mcb, 86 LocalDeliverCallback lcb, ErrorCallback ecb); 87 virtual void NotifyInterfaceUp (uint32_t interface); 88 virtual void NotifyInterfaceDown (uint32_t interface); 89 virtual void NotifyAddAddress (uint32_t interface, Ipv4InterfaceAddress address); 90 virtual void NotifyRemoveAddress (uint32_t interface, Ipv4InterfaceAddress address); 91 virtual void SetIpv4 (Ptr<Ipv4> ipv4); 92 virtual void PrintRoutingTable (Ptr<OutputStreamWrapper> stream, Time::Unit unit = Time::S) const; 93 94 protected: 95 virtual void DoDispose (void); 96 virtual void DoInitialize (void); 97 private: 98 /** 99 * \brief Container identifying an IPv4 Routing Protocol entry in the list. 100 */ 101 typedef std::pair<int16_t, Ptr<Ipv4RoutingProtocol> > Ipv4RoutingProtocolEntry; 102 /** 103 * \brief Container of the IPv4 Routing Protocols. 104 */ 105 typedef std::list<Ipv4RoutingProtocolEntry> Ipv4RoutingProtocolList; 106 Ipv4RoutingProtocolList m_routingProtocols; //!< List of routing protocols. 107 108 /** 109 * \brief Compare two routing protocols. 110 * \param a first object to compare 111 * \param b second object to compare 112 * \return true if they are the same, false otherwise 113 */ 114 static bool Compare (const Ipv4RoutingProtocolEntry& a, const Ipv4RoutingProtocolEntry& b); 115 Ptr<Ipv4> m_ipv4; //!< Ipv4 this protocol is associated with. 116 117 118 }; 119 120 } // namespace ns3 121 122 #endif /* IPV4_LIST_ROUTING_H */ 123