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_ROUTE_H 20 #define IPV4_ROUTE_H 21 22 #include <list> 23 #include <map> 24 #include <ostream> 25 26 #include "ns3/simple-ref-count.h" 27 #include "ns3/ipv4-address.h" 28 29 namespace ns3 { 30 31 class NetDevice; 32 33 /** 34 * \ingroup ipv4Routing 35 * 36 *\brief IPv4 route cache entry (similar to Linux struct rtable) 37 * 38 * This is a reference counted object. In the future, we will add other 39 * entries from struct dst_entry, struct rtable, and struct dst_ops as needed. 40 */ 41 class Ipv4Route : public SimpleRefCount<Ipv4Route> 42 { 43 public: 44 Ipv4Route (); 45 46 /** 47 * \param dest Destination Ipv4Address 48 */ 49 void SetDestination (Ipv4Address dest); 50 /** 51 * \return Destination Ipv4Address of the route 52 */ 53 Ipv4Address GetDestination (void) const; 54 55 /** 56 * \param src Source Ipv4Address 57 */ 58 void SetSource (Ipv4Address src); 59 /** 60 * \return Source Ipv4Address of the route 61 */ 62 Ipv4Address GetSource (void) const; 63 64 /** 65 * \param gw Gateway (next hop) Ipv4Address 66 */ 67 void SetGateway (Ipv4Address gw); 68 /** 69 * \return Ipv4Address of the gateway (next hop) 70 */ 71 Ipv4Address GetGateway (void) const; 72 73 /** 74 * Equivalent in Linux to dst_entry.dev 75 * 76 * \param outputDevice pointer to NetDevice for outgoing packets 77 */ 78 void SetOutputDevice (Ptr<NetDevice> outputDevice); 79 /** 80 * \return pointer to NetDevice for outgoing packets 81 */ 82 Ptr<NetDevice> GetOutputDevice (void) const; 83 84 #ifdef NOTYET 85 // rtable.idev 86 void SetInputIfIndex (uint32_t iif); 87 uint32_t GetInputIfIndex (void) const; 88 #endif 89 90 private: 91 Ipv4Address m_dest; //!< Destination address. 92 Ipv4Address m_source; //!< Source address. 93 Ipv4Address m_gateway; //!< Gateway address. 94 Ptr<NetDevice> m_outputDevice; //!< Output device. 95 #ifdef NOTYET 96 uint32_t m_inputIfIndex; 97 #endif 98 }; 99 100 /** 101 * \brief Stream insertion operator. 102 * 103 * \param os the reference to the output stream 104 * \param route the Ipv4 route 105 * \returns the reference to the output stream 106 */ 107 std::ostream& operator<< (std::ostream& os, Ipv4Route const& route); 108 109 /** 110 * \ingroup ipv4Routing 111 * 112 * \brief Ipv4 multicast route cache entry (similar to Linux struct mfc_cache) 113 */ 114 class Ipv4MulticastRoute : public SimpleRefCount<Ipv4MulticastRoute> 115 { 116 public: 117 Ipv4MulticastRoute (); 118 119 /** 120 * \param group Ipv4Address of the multicast group 121 */ 122 void SetGroup (const Ipv4Address group); 123 /** 124 * \return Ipv4Address of the multicast group 125 */ 126 Ipv4Address GetGroup (void) const; 127 128 /** 129 * \param origin Ipv4Address of the origin address 130 */ 131 void SetOrigin (const Ipv4Address origin); 132 /** 133 * \return Ipv4Address of the origin address 134 */ 135 Ipv4Address GetOrigin (void) const; 136 137 /** 138 * \param iif Parent (input interface) for this route 139 */ 140 void SetParent (uint32_t iif); 141 /** 142 * \return Parent (input interface) for this route 143 */ 144 uint32_t GetParent (void) const; 145 146 /** 147 * \param oif Outgoing interface index 148 * \param ttl time-to-live for this route 149 */ 150 void SetOutputTtl (uint32_t oif, uint32_t ttl); 151 152 /** 153 * \return map of output interface Ids and TTLs for this route 154 */ 155 std::map<uint32_t, uint32_t> GetOutputTtlMap () const; 156 157 static const uint32_t MAX_INTERFACES = 16; //!< Maximum number of multicast interfaces on a router 158 static const uint32_t MAX_TTL = 255; //!< Maximum time-to-live (TTL) 159 160 private: 161 Ipv4Address m_group; //!< Group 162 Ipv4Address m_origin; //!< Source of packet 163 uint32_t m_parent; //!< Source interface 164 std::map<uint32_t, uint32_t> m_ttls; //!< Time to Live container 165 }; 166 167 } // namespace ns3 168 169 #endif /* IPV4_ROUTE_H */ 170