1 // -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- |
|
2 // |
|
3 // Copyright (c) 2008 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 |
|
20 #ifndef IPV4_GLOBAL_ROUTING_H |
|
21 #define IPV4_GLOBAL_ROUTING_H |
|
22 |
|
23 #include <list> |
|
24 #include <stdint.h> |
|
25 #include "ns3/ipv4-address.h" |
|
26 #include "ns3/ipv4-header.h" |
|
27 #include "ns3/ptr.h" |
|
28 #include "ns3/ipv4.h" |
|
29 #include "ns3/ipv4-routing-protocol.h" |
|
30 |
|
31 namespace ns3 { |
|
32 |
|
33 class Packet; |
|
34 class NetDevice; |
|
35 class Ipv4Interface; |
|
36 class Ipv4Address; |
|
37 class Ipv4Header; |
|
38 class Ipv4RoutingTableEntry; |
|
39 class Ipv4MulticastRoutingTableEntry; |
|
40 class Node; |
|
41 |
|
42 |
|
43 /** |
|
44 * \brief Global routing protocol for IP version 4 stacks. |
|
45 * |
|
46 * In ns-3 we have the concept of a pluggable routing protocol. Routing |
|
47 * protocols are added to a list maintained by the Ipv4L3Protocol. Every |
|
48 * stack gets one routing protocol for free -- the Ipv4StaticRouting routing |
|
49 * protocol is added in the constructor of the Ipv4L3Protocol (this is the |
|
50 * piece of code that implements the functionality of the IP layer). |
|
51 * |
|
52 * As an option to running a dynamic routing protocol, a GlobalRouteManager |
|
53 * object has been created to allow users to build routes for all participating |
|
54 * nodes. One can think of this object as a "routing oracle"; it has |
|
55 * an omniscient view of the topology, and can construct shortest path |
|
56 * routes between all pairs of nodes. These routes must be stored |
|
57 * somewhere in the node, so therefore this class Ipv4GlobalRouting |
|
58 * is used as one of the pluggable routing protocols. It is kept distinct |
|
59 * from Ipv4StaticRouting because these routes may be dynamically cleared |
|
60 * and rebuilt in the middle of the simulation, while manually entered |
|
61 * routes into the Ipv4StaticRouting may need to be kept distinct. |
|
62 * |
|
63 * This class deals with Ipv4 unicast routes only. |
|
64 * |
|
65 * \see Ipv4RoutingProtocol |
|
66 * \see GlobalRouteManager |
|
67 */ |
|
68 class Ipv4GlobalRouting : public Ipv4RoutingProtocol |
|
69 { |
|
70 public: |
|
71 static TypeId GetTypeId (void); |
|
72 /** |
|
73 * \brief Construct an empty Ipv4GlobalRouting routing protocol, |
|
74 * |
|
75 * The Ipv4GlobalRouting class supports host and network unicast routes. |
|
76 * This method initializes the lists containing these routes to empty. |
|
77 * |
|
78 * \see Ipv4GlobalRouting |
|
79 */ |
|
80 Ipv4GlobalRouting (); |
|
81 virtual ~Ipv4GlobalRouting (); |
|
82 |
|
83 virtual Ptr<Ipv4Route> RouteOutput (const Ipv4Header &header, uint32_t oif, Socket::SocketErrno &sockerr); |
|
84 |
|
85 virtual bool RouteInput (Ptr<const Packet> p, const Ipv4Header &header, Ptr<const NetDevice> idev, |
|
86 UnicastForwardCallback ucb, MulticastForwardCallback mcb, |
|
87 LocalDeliverCallback lcb, ErrorCallback ecb); |
|
88 |
|
89 /** |
|
90 * \brief Add a host route to the global routing table. |
|
91 * |
|
92 * \param dest The Ipv4Address destination for this route. |
|
93 * \param nextHop The Ipv4Address of the next hop in the route. |
|
94 * \param interface The network interface index used to send packets to the |
|
95 * destination. |
|
96 * |
|
97 * \see Ipv4Address |
|
98 */ |
|
99 void AddHostRouteTo (Ipv4Address dest, |
|
100 Ipv4Address nextHop, |
|
101 uint32_t interface); |
|
102 /** |
|
103 * \brief Add a host route to the global routing table. |
|
104 * |
|
105 * \param dest The Ipv4Address destination for this route. |
|
106 * \param interface The network interface index used to send packets to the |
|
107 * destination. |
|
108 * |
|
109 * \see Ipv4Address |
|
110 */ |
|
111 void AddHostRouteTo (Ipv4Address dest, |
|
112 uint32_t interface); |
|
113 |
|
114 /** |
|
115 * \brief Add a network route to the global routing table. |
|
116 * |
|
117 * \param network The Ipv4Address network for this route. |
|
118 * \param networkMask The Ipv4Mask to extract the network. |
|
119 * \param nextHop The next hop in the route to the destination network. |
|
120 * \param interface The network interface index used to send packets to the |
|
121 * destination. |
|
122 * |
|
123 * \see Ipv4Address |
|
124 */ |
|
125 void AddNetworkRouteTo (Ipv4Address network, |
|
126 Ipv4Mask networkMask, |
|
127 Ipv4Address nextHop, |
|
128 uint32_t interface); |
|
129 |
|
130 /** |
|
131 * \brief Add a network route to the global routing table. |
|
132 * |
|
133 * \param network The Ipv4Address network for this route. |
|
134 * \param networkMask The Ipv4Mask to extract the network. |
|
135 * \param interface The network interface index used to send packets to the |
|
136 * destination. |
|
137 * |
|
138 * \see Ipv4Address |
|
139 */ |
|
140 void AddNetworkRouteTo (Ipv4Address network, |
|
141 Ipv4Mask networkMask, |
|
142 uint32_t interface); |
|
143 |
|
144 /** |
|
145 * \brief Get the number of individual unicast routes that have been added |
|
146 * to the routing table. |
|
147 * |
|
148 * \warning The default route counts as one of the routes. |
|
149 */ |
|
150 uint32_t GetNRoutes (void); |
|
151 |
|
152 /** |
|
153 * \brief Get a route from the global unicast routing table. |
|
154 * |
|
155 * Externally, the unicast global routing table appears simply as a table with |
|
156 * n entries. The one sublety of note is that if a default route has been set |
|
157 * it will appear as the zeroth entry in the table. This means that if you |
|
158 * add only a default route, the table will have one entry that can be accessed |
|
159 * either by explicity calling GetDefaultRoute () or by calling GetRoute (0). |
|
160 * |
|
161 * Similarly, if the default route has been set, calling RemoveRoute (0) will |
|
162 * remove the default route. |
|
163 * |
|
164 * \param i The index (into the routing table) of the route to retrieve. If |
|
165 * the default route has been set, it will occupy index zero. |
|
166 * \return If route is set, a pointer to that Ipv4RoutingTableEntry is returned, otherwise |
|
167 * a zero pointer is returned. |
|
168 * |
|
169 * \see Ipv4RoutingTableEntry |
|
170 * \see Ipv4GlobalRouting::RemoveRoute |
|
171 */ |
|
172 Ipv4RoutingTableEntry *GetRoute (uint32_t i); |
|
173 |
|
174 /** |
|
175 * \brief Remove a route from the global unicast routing table. |
|
176 * |
|
177 * Externally, the unicast global routing table appears simply as a table with |
|
178 * n entries. The one sublety of note is that if a default route has been set |
|
179 * it will appear as the zeroth entry in the table. This means that if the |
|
180 * default route has been set, calling RemoveRoute (0) will remove the |
|
181 * default route. |
|
182 * |
|
183 * \param i The index (into the routing table) of the route to remove. If |
|
184 * the default route has been set, it will occupy index zero. |
|
185 * |
|
186 * \see Ipv4RoutingTableEntry |
|
187 * \see Ipv4GlobalRouting::GetRoute |
|
188 * \see Ipv4GlobalRouting::AddRoute |
|
189 */ |
|
190 void RemoveRoute (uint32_t i); |
|
191 |
|
192 void SetNode (Ptr<Node> node); |
|
193 Ptr<Node> GetNode (void) const; |
|
194 |
|
195 protected: |
|
196 void DoDispose (void); |
|
197 |
|
198 private: |
|
199 typedef std::list<Ipv4RoutingTableEntry *> HostRoutes; |
|
200 typedef std::list<Ipv4RoutingTableEntry *>::const_iterator HostRoutesCI; |
|
201 typedef std::list<Ipv4RoutingTableEntry *>::iterator HostRoutesI; |
|
202 typedef std::list<Ipv4RoutingTableEntry *> NetworkRoutes; |
|
203 typedef std::list<Ipv4RoutingTableEntry *>::const_iterator NetworkRoutesCI; |
|
204 typedef std::list<Ipv4RoutingTableEntry *>::iterator NetworkRoutesI; |
|
205 |
|
206 Ptr<Ipv4Route> LookupGlobal (Ipv4Address dest); |
|
207 |
|
208 HostRoutes m_hostRoutes; |
|
209 NetworkRoutes m_networkRoutes; |
|
210 |
|
211 Ptr<Node> m_node; |
|
212 }; |
|
213 |
|
214 } // Namespace ns3 |
|
215 |
|
216 #endif /* IPV4_GLOBAL_ROUTING_H */ |
|