PageRenderTime 54ms CodeModel.GetById 27ms RepoModel.GetById 1ms app.codeStats 0ms

/src/internet/model/ipv6-static-routing.h

https://github.com/scarletttu/ns-3-codel-dev
C Header | 305 lines | 72 code | 44 blank | 189 comment | 0 complexity | a251e8ac7335a73883547c39d46da53b MD5 | raw file
Possible License(s): GPL-2.0
  1. /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
  2. /*
  3. * Copyright (c) 2007-2009 Strasbourg University
  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. * Author: Sebastien Vincent <vincent@clarinet.u-strasbg.fr>
  19. */
  20. #ifndef IPV6_STATIC_ROUTING_H
  21. #define IPV6_STATIC_ROUTING_H
  22. #include <stdint.h>
  23. #include <list>
  24. #include "ns3/ptr.h"
  25. #include "ns3/ipv6-address.h"
  26. #include "ns3/ipv6.h"
  27. #include "ns3/ipv6-header.h"
  28. #include "ns3/ipv6-routing-protocol.h"
  29. namespace ns3 {
  30. class Packet;
  31. class NetDevice;
  32. class Ipv6Interface;
  33. class Ipv6Route;
  34. class Node;
  35. class Ipv6RoutingTableEntry;
  36. class Ipv6MulticastRoutingTableEntry;
  37. /**
  38. * \ingroup internet
  39. * \defgroup ipv6StaticRouting Ipv6StaticRouting
  40. */
  41. /**
  42. * \ingroup ipv6StaticRouting
  43. * \class Ipv6StaticRouting
  44. * \brief Static routing protocol for IP version 6 stack.
  45. * \see Ipv6RoutingProtocol
  46. * \see Ipv6ListRouting
  47. */
  48. class Ipv6StaticRouting : public Ipv6RoutingProtocol
  49. {
  50. public:
  51. /**
  52. * \brief The interface Id associated with this class.
  53. * \return type identifier
  54. */
  55. static TypeId GetTypeId ();
  56. /**
  57. * \brief Constructor.
  58. */
  59. Ipv6StaticRouting ();
  60. /**
  61. * \brief Destructor.
  62. */
  63. virtual ~Ipv6StaticRouting ();
  64. /**
  65. * \brief Add route to host.
  66. * \param dest destination address
  67. * \param nextHop next hop address to route the packet
  68. * \param interface interface index
  69. * \param prefixToUse prefix that should be used for source address for this destination
  70. * \param metric metric of route in case of multiple routes to same destination
  71. */
  72. void AddHostRouteTo (Ipv6Address dest, Ipv6Address nextHop, uint32_t interface, Ipv6Address prefixToUse = Ipv6Address ("::"), uint32_t metric = 0);
  73. /**
  74. * \brief Add route to host.
  75. * \param dest destination address.
  76. * \param interface interface index
  77. * \param metric metric of route in case of multiple routes to same destination
  78. */
  79. void AddHostRouteTo (Ipv6Address dest, uint32_t interface, uint32_t metric = 0);
  80. /**
  81. * \brief Add route to network.
  82. * \param network network address
  83. * \param networkPrefix network prefix*
  84. * \param nextHop next hop address to route the packet
  85. * \param interface interface index
  86. * \param metric metric of route in case of multiple routes to same destination
  87. */
  88. void AddNetworkRouteTo (Ipv6Address network, Ipv6Prefix networkPrefix, Ipv6Address nextHop, uint32_t interface, uint32_t metric = 0);
  89. /**
  90. * \brief Add route to network.
  91. * \param network network address
  92. * \param networkPrefix network prefix*
  93. * \param nextHop next hop address to route the packet
  94. * \param interface interface index
  95. * \param prefixToUse prefix that should be used for source address for this destination
  96. * \param metric metric of route in case of multiple routes to same destination
  97. */
  98. void AddNetworkRouteTo (Ipv6Address network, Ipv6Prefix networkPrefix, Ipv6Address nextHop, uint32_t interface, Ipv6Address prefixToUse, uint32_t metric = 0);
  99. /**
  100. * \brief Add route to network.
  101. * \param network network address
  102. * \param networkPrefix network prefix
  103. * \param interface interface index
  104. * \param metric metric of route in case of multiple routes to same destination
  105. */
  106. void AddNetworkRouteTo (Ipv6Address network, Ipv6Prefix networkPrefix, uint32_t interface, uint32_t metric = 0);
  107. /**
  108. * \brief Set the default route.
  109. * \param nextHop next hop address to route the packet
  110. * \param interface interface index
  111. * \param prefixToUse prefix to use (i.e for multihoming)
  112. * \param metric metric of route in case of multiple routes to same destination
  113. */
  114. void SetDefaultRoute (Ipv6Address nextHop, uint32_t interface, Ipv6Address prefixToUse = Ipv6Address ("::"), uint32_t metric = 0);
  115. /**
  116. * \brief Get the number or entries in the routing table.
  117. * \return number of entries
  118. */
  119. uint32_t GetNRoutes () const;
  120. /**
  121. * \brief Get the default route.
  122. *
  123. * If multiple default routes exist, the one with lowest metric is returned.
  124. * \return default Ipv6Route
  125. */
  126. Ipv6RoutingTableEntry GetDefaultRoute ();
  127. /**
  128. * \brief Get a specified route.
  129. * \param i index
  130. * \return the route whose index is i
  131. */
  132. Ipv6RoutingTableEntry GetRoute (uint32_t i) const;
  133. /**
  134. * \brief Get a metric for route from the static unicast routing table.
  135. * \param index The index (into the routing table) of the route to retrieve.
  136. * \return If route is set, the metric is returned. If not, an infinity metric (0xffffffff) is returned
  137. */
  138. uint32_t GetMetric (uint32_t index) const;
  139. /**
  140. * \brief Remove a route from the routing table.
  141. * \param i index
  142. */
  143. void RemoveRoute (uint32_t i);
  144. /**
  145. * \brief Remove a route from the routing table.
  146. * \param network IPv6 network
  147. * \param prefix IPv6 prefix
  148. * \param ifIndex interface index
  149. * \param prefixToUse IPv6 prefix to use with this route (multihoming)
  150. */
  151. void RemoveRoute (Ipv6Address network, Ipv6Prefix prefix, uint32_t ifIndex, Ipv6Address prefixToUse);
  152. /**
  153. * \brief Add a multicast route for a given multicast source and group.
  154. * \param origin IPv6 address of the source
  155. * \param group the multicast group address.
  156. * \param inputInterface the interface index
  157. * \param outputInterfaces the list of output interface indices over which the packet
  158. * should be sent (excluding the inputInterface).
  159. */
  160. void AddMulticastRoute (Ipv6Address origin, Ipv6Address group, uint32_t inputInterface, std::vector<uint32_t> outputInterfaces);
  161. /**
  162. * \brief Set the default multicast route.
  163. * \param outputInterface default output interface
  164. */
  165. void SetDefaultMulticastRoute (uint32_t outputInterface);
  166. /**
  167. * \brief Get the number of entries in the multicast routing table.
  168. * \return number of entries
  169. */
  170. uint32_t GetNMulticastRoutes () const;
  171. /**
  172. * \brief Get the specified multicast route.
  173. * \param i index
  174. * \return the route whose index is i
  175. */
  176. Ipv6MulticastRoutingTableEntry GetMulticastRoute (uint32_t i) const;
  177. /**
  178. * \brief Remove a static multicast route.
  179. * \param origin IPv6 address of the source
  180. * \param group the multicast group address.
  181. * \param inputInterface the input interface index
  182. */
  183. bool RemoveMulticastRoute (Ipv6Address origin, Ipv6Address group, uint32_t inputInterface);
  184. /**
  185. * \brief Remove a multicast route.
  186. * \param i index of route to remove
  187. */
  188. void RemoveMulticastRoute (uint32_t i);
  189. /**
  190. * \brief If the destination is already present in network destination list.
  191. * \param dest destination address
  192. * \param interfaceIndex interface index
  193. * \return true if dest is already in list, false otherwise
  194. */
  195. bool HasNetworkDest (Ipv6Address dest, uint32_t interfaceIndex);
  196. virtual Ptr<Ipv6Route> RouteOutput (Ptr<Packet> p, const Ipv6Header &header, Ptr<NetDevice> oif, Socket::SocketErrno &sockerr);
  197. virtual bool RouteInput (Ptr<const Packet> p, const Ipv6Header &header, Ptr<const NetDevice> idev,
  198. UnicastForwardCallback ucb, MulticastForwardCallback mcb,
  199. LocalDeliverCallback lcb, ErrorCallback ecb);
  200. virtual void NotifyInterfaceUp (uint32_t interface);
  201. virtual void NotifyInterfaceDown (uint32_t interface);
  202. virtual void NotifyAddAddress (uint32_t interface, Ipv6InterfaceAddress address);
  203. virtual void NotifyRemoveAddress (uint32_t interface, Ipv6InterfaceAddress address);
  204. virtual void NotifyAddRoute (Ipv6Address dst, Ipv6Prefix mask, Ipv6Address nextHop, uint32_t interface, Ipv6Address prefixToUse = Ipv6Address::GetZero ());
  205. virtual void NotifyRemoveRoute (Ipv6Address dst, Ipv6Prefix mask, Ipv6Address nextHop, uint32_t interface, Ipv6Address prefixToUse = Ipv6Address::GetZero ());
  206. virtual void SetIpv6 (Ptr<Ipv6> ipv6);
  207. /**
  208. * \brief Print the Routing Table entries
  209. *
  210. * \param stream the ostream the Routing table is printed to
  211. */
  212. virtual void PrintRoutingTable (Ptr<OutputStreamWrapper> stream) const;
  213. protected:
  214. /**
  215. * \brief Dispose this object.
  216. */
  217. virtual void DoDispose ();
  218. private:
  219. typedef std::list<std::pair <Ipv6RoutingTableEntry *, uint32_t> > NetworkRoutes;
  220. typedef std::list<std::pair <Ipv6RoutingTableEntry *, uint32_t> >::const_iterator NetworkRoutesCI;
  221. typedef std::list<std::pair <Ipv6RoutingTableEntry *, uint32_t> >::iterator NetworkRoutesI;
  222. typedef std::list<Ipv6MulticastRoutingTableEntry *> MulticastRoutes;
  223. typedef std::list<Ipv6MulticastRoutingTableEntry *>::const_iterator MulticastRoutesCI;
  224. typedef std::list<Ipv6MulticastRoutingTableEntry *>::iterator MulticastRoutesI;
  225. /**
  226. * \brief Lookup in the forwarding table for destination.
  227. * \param dest destination address
  228. * \param interface output interface if any (put 0 otherwise)
  229. * \return Ipv6Route to route the packet to reach dest address
  230. */
  231. Ptr<Ipv6Route> LookupStatic (Ipv6Address dest, Ptr<NetDevice> = 0);
  232. /**
  233. * \brief Lookup in the multicast forwarding table for destination.
  234. * \param origin source address
  235. * \param group group multicast address
  236. * \param ifIndex interface index
  237. * \return Ipv6MulticastRoute to route the packet to reach dest address
  238. */
  239. Ptr<Ipv6MulticastRoute> LookupStatic (Ipv6Address origin, Ipv6Address group, uint32_t ifIndex);
  240. /**
  241. * \brief Choose the source address to use with destination address.
  242. * \param interface interface index
  243. * \param dest IPv6 destination address
  244. * \return IPv6 source address to use
  245. */
  246. Ipv6Address SourceAddressSelection (uint32_t interface, Ipv6Address dest);
  247. /**
  248. * \brief the forwarding table for network.
  249. */
  250. NetworkRoutes m_networkRoutes;
  251. /**
  252. * \brief the forwarding table for multicast.
  253. */
  254. MulticastRoutes m_multicastRoutes;
  255. /**
  256. * \brief Ipv6 reference.
  257. */
  258. Ptr<Ipv6> m_ipv6;
  259. };
  260. } /* namespace ns3 */
  261. #endif /* IPV6_STATIC_ROUTING_H */