author | Craig Dowell <craigdo@ee.washington.edu> |
Wed, 19 Nov 2008 21:21:14 -0800 | |
changeset 3939 | 206f627bd5af |
parent 3938 | 972310213d07 |
child 3940 | 49b432aefbd0 |
permissions | -rw-r--r-- |
1111 | 1 |
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
2 |
/* |
|
1457
562a7017ed93
Copyrights/licenses for routing code
Tom Henderson <tomh@tomh.org>
parents:
1280
diff
changeset
|
3 |
* Copyright 2007 University of Washington |
562a7017ed93
Copyrights/licenses for routing code
Tom Henderson <tomh@tomh.org>
parents:
1280
diff
changeset
|
4 |
* |
1111 | 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 |
|
1457
562a7017ed93
Copyrights/licenses for routing code
Tom Henderson <tomh@tomh.org>
parents:
1280
diff
changeset
|
17 |
* |
562a7017ed93
Copyrights/licenses for routing code
Tom Henderson <tomh@tomh.org>
parents:
1280
diff
changeset
|
18 |
* Authors: Craig Dowell (craigdo@ee.washington.edu) |
562a7017ed93
Copyrights/licenses for routing code
Tom Henderson <tomh@tomh.org>
parents:
1280
diff
changeset
|
19 |
* Tom Henderson (tomhend@u.washington.edu) |
1111 | 20 |
*/ |
21 |
||
1115
453f36d7bead
small readability change
Craig Dowell <craigdo@ee.washington.edu>
parents:
1113
diff
changeset
|
22 |
#ifndef GLOBAL_ROUTER_INTERFACE_H |
453f36d7bead
small readability change
Craig Dowell <craigdo@ee.washington.edu>
parents:
1113
diff
changeset
|
23 |
#define GLOBAL_ROUTER_INTERFACE_H |
1111 | 24 |
|
25 |
#include <stdint.h> |
|
26 |
#include <list> |
|
27 |
#include "ns3/object.h" |
|
28 |
#include "ns3/ptr.h" |
|
29 |
#include "ns3/node.h" |
|
30 |
#include "ns3/channel.h" |
|
31 |
#include "ns3/ipv4-address.h" |
|
3939
206f627bd5af
factor DiscoverLSAs into understandable modules
Craig Dowell <craigdo@ee.washington.edu>
parents:
3938
diff
changeset
|
32 |
#include "ns3/net-device-container.h" |
1113
5b63b39161e7
remove routing environment, move router interface creation to global-route-manager
Craig Dowell <craigdo@ee.washington.edu>
parents:
1112
diff
changeset
|
33 |
#include "ns3/global-route-manager.h" |
1111 | 34 |
|
35 |
namespace ns3 { |
|
36 |
||
37 |
/** |
|
38 |
* @brief A single link record for a link state advertisement. |
|
39 |
* |
|
1278 | 40 |
* The GlobalRoutingLinkRecord is modeled after the OSPF link record field of |
1111 | 41 |
* a Link State Advertisement. Right now we will only see two types of link |
42 |
* records corresponding to a stub network and a point-to-point link (channel). |
|
43 |
*/ |
|
1278 | 44 |
class GlobalRoutingLinkRecord |
1111 | 45 |
{ |
46 |
public: |
|
47 |
/** |
|
48 |
* @enum LinkType |
|
1278 | 49 |
* @brief Enumeration of the possible types of Global Routing Link Records. |
1111 | 50 |
* |
51 |
* These values are defined in the OSPF spec. We currently only use |
|
52 |
* PointToPoint and StubNetwork types. |
|
53 |
*/ |
|
54 |
enum LinkType { |
|
55 |
Unknown = 0, /**< Uninitialized Link Record */ |
|
56 |
PointToPoint, /**< Record representing a point to point channel */ |
|
57 |
TransitNetwork, /**< Unused -- for future OSPF compatibility */ |
|
58 |
StubNetwork, /**< Record represents a leaf node network */ |
|
59 |
VirtualLink /**< Unused -- for future OSPF compatibility */ |
|
60 |
}; |
|
1115
453f36d7bead
small readability change
Craig Dowell <craigdo@ee.washington.edu>
parents:
1113
diff
changeset
|
61 |
|
1111 | 62 |
/** |
1278 | 63 |
* @brief Construct an empty ("uninitialized") Global Routing Link Record. |
1111 | 64 |
* |
65 |
* The Link ID and Link Data Ipv4 addresses are set to "0.0.0.0"; |
|
66 |
* The Link Type is set to Unknown; |
|
67 |
* The metric is set to 0. |
|
68 |
*/ |
|
1278 | 69 |
GlobalRoutingLinkRecord (); |
1115
453f36d7bead
small readability change
Craig Dowell <craigdo@ee.washington.edu>
parents:
1113
diff
changeset
|
70 |
|
1111 | 71 |
/** |
1278 | 72 |
* Construct an initialized Global Routing Link Record. |
1111 | 73 |
* |
74 |
* @param linkType The type of link record to construct. |
|
75 |
* @param linkId The link ID for the record. |
|
76 |
* @param linkData The link data field for the record. |
|
77 |
* @param metric The metric field for the record. |
|
78 |
* @see LinkType |
|
79 |
* @see SetLinkId |
|
80 |
* @see SetLinkData |
|
81 |
*/ |
|
1278 | 82 |
GlobalRoutingLinkRecord ( |
1111 | 83 |
LinkType linkType, |
84 |
Ipv4Address linkId, |
|
85 |
Ipv4Address linkData, |
|
1776
0d5be0c3d229
Add support for non-unit-cost metrics for Ipv4Interfaces (for use in routing); add example script simple-alternate-routing.cc
Tom Henderson <tomh@tomh.org>
parents:
1457
diff
changeset
|
86 |
uint16_t metric); |
1115
453f36d7bead
small readability change
Craig Dowell <craigdo@ee.washington.edu>
parents:
1113
diff
changeset
|
87 |
|
1111 | 88 |
/** |
1278 | 89 |
* @brief Destroy a Global Routing Link Record. |
1111 | 90 |
* |
91 |
* Currently does nothing. Here as a placeholder only. |
|
92 |
*/ |
|
1278 | 93 |
~GlobalRoutingLinkRecord (); |
1115
453f36d7bead
small readability change
Craig Dowell <craigdo@ee.washington.edu>
parents:
1113
diff
changeset
|
94 |
|
1111 | 95 |
/** |
1278 | 96 |
* Get the Link ID field of the Global Routing Link Record. |
1111 | 97 |
* |
98 |
* For an OSPF type 1 link (PointToPoint) the Link ID will be the Router ID |
|
99 |
* of the neighboring router. |
|
100 |
* |
|
101 |
* For an OSPF type 3 link (StubNetwork), the Link ID will be the adjacent |
|
102 |
* neighbor's IP address |
|
103 |
* |
|
104 |
* @returns The Ipv4Address corresponding to the Link ID field of the record. |
|
105 |
*/ |
|
106 |
Ipv4Address GetLinkId(void) const; |
|
1115
453f36d7bead
small readability change
Craig Dowell <craigdo@ee.washington.edu>
parents:
1113
diff
changeset
|
107 |
|
1111 | 108 |
/** |
1278 | 109 |
* @brief Set the Link ID field of the Global Routing Link Record. |
1111 | 110 |
* |
111 |
* For an OSPF type 1 link (PointToPoint) the Link ID must be the Router ID |
|
112 |
* of the neighboring router. |
|
113 |
* |
|
114 |
* For an OSPF type 3 link (StubNetwork), the Link ID must be the adjacent |
|
115 |
* neighbor's IP address |
|
116 |
* |
|
117 |
* @param addr An Ipv4Address to store in the Link ID field of the record. |
|
118 |
*/ |
|
119 |
void SetLinkId(Ipv4Address addr); |
|
1115
453f36d7bead
small readability change
Craig Dowell <craigdo@ee.washington.edu>
parents:
1113
diff
changeset
|
120 |
|
1111 | 121 |
/** |
1278 | 122 |
* @brief Get the Link Data field of the Global Routing Link Record. |
1111 | 123 |
* |
124 |
* For an OSPF type 1 link (PointToPoint) the Link Data will be the IP |
|
125 |
* address of the node of the local side of the link. |
|
126 |
* |
|
127 |
* For an OSPF type 3 link (StubNetwork), the Link Data will be the |
|
128 |
* network mask |
|
129 |
* |
|
130 |
* @returns The Ipv4Address corresponding to the Link Data field of the record. |
|
131 |
*/ |
|
132 |
Ipv4Address GetLinkData(void) const; |
|
1115
453f36d7bead
small readability change
Craig Dowell <craigdo@ee.washington.edu>
parents:
1113
diff
changeset
|
133 |
|
1111 | 134 |
/** |
1278 | 135 |
* @brief Set the Link Data field of the Global Routing Link Record. |
1111 | 136 |
* |
137 |
* For an OSPF type 1 link (PointToPoint) the Link Data must be the IP |
|
138 |
* address of the node of the local side of the link. |
|
139 |
* |
|
140 |
* For an OSPF type 3 link (StubNetwork), the Link Data must be set to the |
|
141 |
* network mask |
|
142 |
* |
|
143 |
* @param addr An Ipv4Address to store in the Link Data field of the record. |
|
144 |
*/ |
|
145 |
void SetLinkData(Ipv4Address addr); |
|
1115
453f36d7bead
small readability change
Craig Dowell <craigdo@ee.washington.edu>
parents:
1113
diff
changeset
|
146 |
|
1111 | 147 |
/** |
1278 | 148 |
* @brief Get the Link Type field of the Global Routing Link Record. |
1111 | 149 |
* |
150 |
* The Link Type describes the kind of link a given record represents. The |
|
151 |
* values are defined by OSPF. |
|
152 |
* |
|
153 |
* @see LinkType |
|
1278 | 154 |
* @returns The LinkType of the current Global Routing Link Record. |
1111 | 155 |
*/ |
156 |
LinkType GetLinkType(void) const; |
|
1115
453f36d7bead
small readability change
Craig Dowell <craigdo@ee.washington.edu>
parents:
1113
diff
changeset
|
157 |
|
1111 | 158 |
/** |
1278 | 159 |
* @brief Set the Link Type field of the Global Routing Link Record. |
1111 | 160 |
* |
161 |
* The Link Type describes the kind of link a given record represents. The |
|
162 |
* values are defined by OSPF. |
|
163 |
* |
|
164 |
* @see LinkType |
|
1278 | 165 |
* @param linkType The new LinkType for the current Global Routing Link Record. |
1111 | 166 |
*/ |
167 |
void SetLinkType(LinkType linkType); |
|
1115
453f36d7bead
small readability change
Craig Dowell <craigdo@ee.washington.edu>
parents:
1113
diff
changeset
|
168 |
|
1111 | 169 |
/** |
1278 | 170 |
* @brief Get the Metric Data field of the Global Routing Link Record. |
1111 | 171 |
* |
172 |
* The metric is an abstract cost associated with forwarding a packet across |
|
173 |
* a link. A sum of metrics must have a well-defined meaning. That is, you |
|
174 |
* shouldn't use bandwidth as a metric (how does the sum of the bandwidth of |
|
175 |
* two hops relate to the cost of sending a packet); rather you should use |
|
176 |
* something like delay. |
|
177 |
* |
|
1278 | 178 |
* @returns The metric field of the Global Routing Link Record. |
1111 | 179 |
*/ |
1776
0d5be0c3d229
Add support for non-unit-cost metrics for Ipv4Interfaces (for use in routing); add example script simple-alternate-routing.cc
Tom Henderson <tomh@tomh.org>
parents:
1457
diff
changeset
|
180 |
uint16_t GetMetric(void) const; |
1115
453f36d7bead
small readability change
Craig Dowell <craigdo@ee.washington.edu>
parents:
1113
diff
changeset
|
181 |
|
1111 | 182 |
/** |
1278 | 183 |
* @brief Set the Metric Data field of the Global Routing Link Record. |
1111 | 184 |
* |
185 |
* The metric is an abstract cost associated with forwarding a packet across |
|
186 |
* a link. A sum of metrics must have a well-defined meaning. That is, you |
|
187 |
* shouldn't use bandwidth as a metric (how does the sum of the bandwidth of |
|
188 |
* two hops relate to the cost of sending a packet); rather you should use |
|
189 |
* something like delay. |
|
190 |
* |
|
1278 | 191 |
* @param metric The new metric for the current Global Routing Link Record. |
1111 | 192 |
*/ |
1776
0d5be0c3d229
Add support for non-unit-cost metrics for Ipv4Interfaces (for use in routing); add example script simple-alternate-routing.cc
Tom Henderson <tomh@tomh.org>
parents:
1457
diff
changeset
|
193 |
void SetMetric(uint16_t metric); |
1111 | 194 |
|
195 |
private: |
|
196 |
/** |
|
197 |
* m_linkId and m_linkData are defined by OSPF to have different meanings |
|
198 |
* depending on the type of link a given link records represents. They work |
|
199 |
* together. |
|
200 |
* |
|
201 |
* For Type 1 link (PointToPoint), set m_linkId to Router ID of |
|
202 |
* neighboring router. |
|
203 |
* |
|
204 |
* For Type 3 link (Stub), set m_linkId to neighbor's IP address |
|
205 |
*/ |
|
206 |
Ipv4Address m_linkId; |
|
1115
453f36d7bead
small readability change
Craig Dowell <craigdo@ee.washington.edu>
parents:
1113
diff
changeset
|
207 |
|
1111 | 208 |
/** |
209 |
* m_linkId and m_linkData are defined by OSPF to have different meanings |
|
210 |
* depending on the type of link a given link records represents. They work |
|
211 |
* together. |
|
212 |
* |
|
213 |
* For Type 1 link (PointToPoint), set m_linkData to local IP address |
|
214 |
* |
|
215 |
* For Type 3 link (Stub), set m_linkData to mask |
|
216 |
*/ |
|
217 |
Ipv4Address m_linkData; // for links to RouterLSA, |
|
1115
453f36d7bead
small readability change
Craig Dowell <craigdo@ee.washington.edu>
parents:
1113
diff
changeset
|
218 |
|
1111 | 219 |
/** |
1278 | 220 |
* The type of the Global Routing Link Record. Defined in the OSPF spec. |
1111 | 221 |
* We currently only use PointToPoint and StubNetwork types. |
222 |
*/ |
|
223 |
LinkType m_linkType; |
|
1115
453f36d7bead
small readability change
Craig Dowell <craigdo@ee.washington.edu>
parents:
1113
diff
changeset
|
224 |
|
1111 | 225 |
/** |
226 |
* The metric for a given link. |
|
227 |
* |
|
228 |
* A metric is abstract cost associated with forwarding a packet across a |
|
229 |
* link. A sum of metrics must have a well-defined meaning. That is, you |
|
230 |
* shouldn't use bandwidth as a metric (how does the sum of the bandwidth |
|
231 |
* of two hops relate to the cost of sending a packet); rather you should |
|
232 |
* use something like delay. |
|
233 |
*/ |
|
1776
0d5be0c3d229
Add support for non-unit-cost metrics for Ipv4Interfaces (for use in routing); add example script simple-alternate-routing.cc
Tom Henderson <tomh@tomh.org>
parents:
1457
diff
changeset
|
234 |
uint16_t m_metric; |
1111 | 235 |
}; |
236 |
||
237 |
/** |
|
238 |
* @brief a Link State Advertisement (LSA) for a router, used in global |
|
239 |
* routing. |
|
240 |
* |
|
241 |
* Roughly equivalent to a global incarnation of the OSPF link state header |
|
242 |
* combined with a list of Link Records. Since it's global, there's |
|
243 |
* no need for age or sequence number. See RFC 2328, Appendix A. |
|
244 |
*/ |
|
1278 | 245 |
class GlobalRoutingLSA |
1111 | 246 |
{ |
247 |
public: |
|
248 |
/** |
|
1278 | 249 |
* @enum LSType |
250 |
* @brief corresponds to LS type field of RFC 2328 OSPF LSA header |
|
251 |
*/ |
|
252 |
enum LSType { |
|
253 |
Unknown = 0, /**< Uninitialized Type */ |
|
254 |
RouterLSA, |
|
255 |
NetworkLSA, |
|
256 |
SummaryLSA, |
|
257 |
SummaryLSA_ASBR, |
|
258 |
ASExternalLSAs |
|
259 |
}; |
|
260 |
/** |
|
1111 | 261 |
* @enum SPFStatus |
1278 | 262 |
* @brief Enumeration of the possible values of the status flag in the Routing |
1111 | 263 |
* Link State Advertisements. |
264 |
*/ |
|
265 |
enum SPFStatus { |
|
266 |
LSA_SPF_NOT_EXPLORED = 0, /**< New vertex not yet considered */ |
|
267 |
LSA_SPF_CANDIDATE, /**< Vertex is in the SPF candidate queue */ |
|
268 |
LSA_SPF_IN_SPFTREE /**< Vertex is in the SPF tree */ |
|
269 |
}; |
|
270 |
/** |
|
1278 | 271 |
* @brief Create a blank Global Routing Link State Advertisement. |
1111 | 272 |
* |
273 |
* On completion Ipv4Address variables initialized to 0.0.0.0 and the |
|
274 |
* list of Link State Records is empty. |
|
275 |
*/ |
|
1278 | 276 |
GlobalRoutingLSA(); |
1115
453f36d7bead
small readability change
Craig Dowell <craigdo@ee.washington.edu>
parents:
1113
diff
changeset
|
277 |
|
1111 | 278 |
/** |
1278 | 279 |
* @brief Create an initialized Global Routing Link State Advertisement. |
1111 | 280 |
* |
281 |
* On completion the list of Link State Records is empty. |
|
282 |
* |
|
283 |
* @param status The status to of the new LSA. |
|
284 |
* @param linkStateId The Ipv4Address for the link state ID field. |
|
285 |
* @param advertisingRtr The Ipv4Address for the advertising router field. |
|
286 |
*/ |
|
1278 | 287 |
GlobalRoutingLSA(SPFStatus status, Ipv4Address linkStateId, |
1111 | 288 |
Ipv4Address advertisingRtr); |
1115
453f36d7bead
small readability change
Craig Dowell <craigdo@ee.washington.edu>
parents:
1113
diff
changeset
|
289 |
|
1111 | 290 |
/** |
1278 | 291 |
* @brief Copy constructor for a Global Routing Link State Advertisement. |
1111 | 292 |
* |
293 |
* Takes a piece of memory and constructs a semantically identical copy of |
|
294 |
* the given LSA. |
|
295 |
* |
|
296 |
* @param lsa The existing LSA to be used as the source. |
|
297 |
*/ |
|
1278 | 298 |
GlobalRoutingLSA (GlobalRoutingLSA& lsa); |
1115
453f36d7bead
small readability change
Craig Dowell <craigdo@ee.washington.edu>
parents:
1113
diff
changeset
|
299 |
|
1111 | 300 |
/** |
1278 | 301 |
* @brief Destroy an existing Global Routing Link State Advertisement. |
1111 | 302 |
* |
1278 | 303 |
* Any Global Routing Link Records present in the list are freed. |
1111 | 304 |
*/ |
1278 | 305 |
~GlobalRoutingLSA(); |
1115
453f36d7bead
small readability change
Craig Dowell <craigdo@ee.washington.edu>
parents:
1113
diff
changeset
|
306 |
|
1111 | 307 |
/** |
1278 | 308 |
* @brief Assignment operator for a Global Routing Link State Advertisement. |
1111 | 309 |
* |
1278 | 310 |
* Takes an existing Global Routing Link State Advertisement and overwrites |
1111 | 311 |
* it to make a semantically identical copy of a given prototype LSA. |
312 |
* |
|
1278 | 313 |
* If there are any Global Routing Link Records present in the existing |
1111 | 314 |
* LSA, they are freed before the assignment happens. |
315 |
* |
|
316 |
* @param lsa The existing LSA to be used as the source. |
|
317 |
* @returns Reference to the overwritten LSA. |
|
318 |
*/ |
|
1278 | 319 |
GlobalRoutingLSA& operator= (const GlobalRoutingLSA& lsa); |
1115
453f36d7bead
small readability change
Craig Dowell <craigdo@ee.washington.edu>
parents:
1113
diff
changeset
|
320 |
|
1111 | 321 |
/** |
1278 | 322 |
* @brief Copy any Global Routing Link Records in a given Global Routing Link |
1111 | 323 |
* State Advertisement to the current LSA. |
324 |
* |
|
325 |
* Existing Link Records are not deleted -- this is a concatenation of Link |
|
326 |
* Records. |
|
327 |
* |
|
328 |
* @see ClearLinkRecords () |
|
329 |
* @param lsa The LSA to copy the Link Records from. |
|
330 |
*/ |
|
1278 | 331 |
void CopyLinkRecords (const GlobalRoutingLSA& lsa); |
1115
453f36d7bead
small readability change
Craig Dowell <craigdo@ee.washington.edu>
parents:
1113
diff
changeset
|
332 |
|
1111 | 333 |
/** |
1278 | 334 |
* @brief Add a given Global Routing Link Record to the LSA. |
1111 | 335 |
* |
1278 | 336 |
* @param lr The Global Routing Link Record to be added. |
1111 | 337 |
* @returns The number of link records in the list. |
338 |
*/ |
|
1278 | 339 |
uint32_t AddLinkRecord (GlobalRoutingLinkRecord* lr); |
1115
453f36d7bead
small readability change
Craig Dowell <craigdo@ee.washington.edu>
parents:
1113
diff
changeset
|
340 |
|
1111 | 341 |
/** |
1278 | 342 |
* @brief Return the number of Global Routing Link Records in the LSA. |
1111 | 343 |
* |
344 |
* @returns The number of link records in the list. |
|
345 |
*/ |
|
346 |
uint32_t GetNLinkRecords (void) const; |
|
1115
453f36d7bead
small readability change
Craig Dowell <craigdo@ee.washington.edu>
parents:
1113
diff
changeset
|
347 |
|
1111 | 348 |
/** |
1278 | 349 |
* @brief Return a pointer to the specified Global Routing Link Record. |
1111 | 350 |
* |
351 |
* @param n The LSA number desired. |
|
352 |
* @returns The number of link records in the list. |
|
353 |
*/ |
|
1278 | 354 |
GlobalRoutingLinkRecord* GetLinkRecord (uint32_t n) const; |
1115
453f36d7bead
small readability change
Craig Dowell <craigdo@ee.washington.edu>
parents:
1113
diff
changeset
|
355 |
|
1111 | 356 |
/** |
1278 | 357 |
* @brief Release all of the Global Routing Link Records present in the Global |
358 |
* Routing Link State Advertisement and make the list of link records empty. |
|
1111 | 359 |
*/ |
360 |
void ClearLinkRecords(void); |
|
1115
453f36d7bead
small readability change
Craig Dowell <craigdo@ee.washington.edu>
parents:
1113
diff
changeset
|
361 |
|
1111 | 362 |
/** |
1278 | 363 |
* @brief Check to see if the list of Global Routing Link Records present in the |
364 |
* Global Routing Link State Advertisement is empty. |
|
1111 | 365 |
* |
366 |
* @returns True if the list is empty, false otherwise. |
|
367 |
*/ |
|
368 |
bool IsEmpty(void) const; |
|
1115
453f36d7bead
small readability change
Craig Dowell <craigdo@ee.washington.edu>
parents:
1113
diff
changeset
|
369 |
|
1111 | 370 |
/** |
1278 | 371 |
* @brief Print the contents of the Global Routing Link State Advertisement and |
372 |
* any Global Routing Link Records present in the list. Quite verbose. |
|
1111 | 373 |
*/ |
374 |
void Print (std::ostream &os) const; |
|
1115
453f36d7bead
small readability change
Craig Dowell <craigdo@ee.washington.edu>
parents:
1113
diff
changeset
|
375 |
|
1111 | 376 |
/** |
1278 | 377 |
* @brief Return the LSType field of the LSA |
378 |
*/ |
|
379 |
LSType GetLSType (void) const; |
|
380 |
/** |
|
381 |
* @brief Set the LS type field of the LSA |
|
382 |
*/ |
|
383 |
void SetLSType (LSType typ); |
|
384 |
||
385 |
/** |
|
1111 | 386 |
* @brief Get the Link State ID as defined by the OSPF spec. We always set it |
387 |
* to the router ID of the router making the advertisement. |
|
388 |
* |
|
389 |
* @see RoutingEnvironment::AllocateRouterId () |
|
1278 | 390 |
* @see GlobalRouting::GetRouterId () |
1111 | 391 |
* @returns The Ipv4Address stored as the link state ID. |
392 |
*/ |
|
393 |
Ipv4Address GetLinkStateId (void) const; |
|
1115
453f36d7bead
small readability change
Craig Dowell <craigdo@ee.washington.edu>
parents:
1113
diff
changeset
|
394 |
|
1111 | 395 |
/** |
396 |
* @brief Set the Link State ID is defined by the OSPF spec. We always set it |
|
397 |
* to the router ID of the router making the advertisement. |
|
398 |
* |
|
399 |
* @see RoutingEnvironment::AllocateRouterId () |
|
1278 | 400 |
* @see GlobalRouting::GetRouterId () |
1111 | 401 |
*/ |
402 |
void SetLinkStateId (Ipv4Address addr); |
|
1115
453f36d7bead
small readability change
Craig Dowell <craigdo@ee.washington.edu>
parents:
1113
diff
changeset
|
403 |
|
1111 | 404 |
/** |
405 |
* @brief Get the Advertising Router as defined by the OSPF spec. We always |
|
406 |
* set it to the router ID of the router making the advertisement. |
|
407 |
* |
|
408 |
* @see RoutingEnvironment::AllocateRouterId () |
|
1278 | 409 |
* @see GlobalRouting::GetRouterId () |
1111 | 410 |
* @returns The Ipv4Address stored as the advetising router. |
411 |
*/ |
|
412 |
Ipv4Address GetAdvertisingRouter (void) const; |
|
1115
453f36d7bead
small readability change
Craig Dowell <craigdo@ee.washington.edu>
parents:
1113
diff
changeset
|
413 |
|
1111 | 414 |
/** |
415 |
* @brief Set the Advertising Router as defined by the OSPF spec. We always |
|
416 |
* set it to the router ID of the router making the advertisement. |
|
417 |
* |
|
418 |
* @see RoutingEnvironment::AllocateRouterId () |
|
1278 | 419 |
* @see GlobalRouting::GetRouterId () |
1111 | 420 |
*/ |
421 |
void SetAdvertisingRouter (Ipv4Address rtr); |
|
1115
453f36d7bead
small readability change
Craig Dowell <craigdo@ee.washington.edu>
parents:
1113
diff
changeset
|
422 |
|
1111 | 423 |
/** |
1278 | 424 |
* @brief For a Network LSA, set the Network Mask field that precedes |
425 |
* the list of attached routers. |
|
426 |
*/ |
|
427 |
void SetNetworkLSANetworkMask (Ipv4Mask mask); |
|
428 |
||
429 |
/** |
|
430 |
* @brief For a Network LSA, get the Network Mask field that precedes |
|
431 |
* the list of attached routers. |
|
432 |
* |
|
433 |
* @returns the NetworkLSANetworkMask |
|
434 |
*/ |
|
435 |
Ipv4Mask GetNetworkLSANetworkMask (void) const; |
|
436 |
||
437 |
/** |
|
438 |
* @brief Add an attached router to the list in the NetworkLSA |
|
439 |
* |
|
1280 | 440 |
* @param addr The Ipv4Address of the interface on the network link |
1278 | 441 |
* @returns The number of addresses in the list. |
442 |
*/ |
|
443 |
uint32_t AddAttachedRouter (Ipv4Address addr); |
|
444 |
||
445 |
/** |
|
446 |
* @brief Return the number of attached routers listed in the NetworkLSA |
|
447 |
* |
|
448 |
* @returns The number of attached routers. |
|
449 |
*/ |
|
450 |
uint32_t GetNAttachedRouters (void) const; |
|
451 |
||
452 |
/** |
|
453 |
* @brief Return an Ipv4Address corresponding to the specified attached router |
|
454 |
* |
|
455 |
* @param n The attached router number desired (number in the list). |
|
456 |
* @returns The Ipv4Address of the requested router |
|
457 |
*/ |
|
458 |
Ipv4Address GetAttachedRouter (uint32_t n) const; |
|
459 |
||
460 |
/** |
|
1111 | 461 |
* @brief Get the SPF status of the advertisement. |
462 |
* |
|
463 |
* @see SPFStatus |
|
464 |
* @returns The SPFStatus of the LSA. |
|
465 |
*/ |
|
466 |
SPFStatus GetStatus (void) const; |
|
1115
453f36d7bead
small readability change
Craig Dowell <craigdo@ee.washington.edu>
parents:
1113
diff
changeset
|
467 |
|
1111 | 468 |
/** |
469 |
* @brief Set the SPF status of the advertisement |
|
470 |
* |
|
471 |
* @see SPFStatus |
|
472 |
*/ |
|
473 |
void SetStatus (SPFStatus status); |
|
474 |
||
475 |
private: |
|
476 |
/** |
|
1278 | 477 |
* The type of the LSA. Each LSA type has a separate advertisement |
478 |
* format. |
|
479 |
*/ |
|
480 |
LSType m_lsType; |
|
481 |
/** |
|
1111 | 482 |
* The Link State ID is defined by the OSPF spec. We always set it to the |
483 |
* router ID of the router making the advertisement. |
|
484 |
* |
|
485 |
* @see RoutingEnvironment::AllocateRouterId () |
|
1278 | 486 |
* @see GlobalRouting::GetRouterId () |
1111 | 487 |
*/ |
488 |
Ipv4Address m_linkStateId; |
|
1115
453f36d7bead
small readability change
Craig Dowell <craigdo@ee.washington.edu>
parents:
1113
diff
changeset
|
489 |
|
1111 | 490 |
/** |
491 |
* The Advertising Router is defined by the OSPF spec. We always set it to |
|
492 |
* the router ID of the router making the advertisement. |
|
493 |
* |
|
494 |
* @see RoutingEnvironment::AllocateRouterId () |
|
1278 | 495 |
* @see GlobalRouting::GetRouterId () |
1111 | 496 |
*/ |
497 |
Ipv4Address m_advertisingRtr; |
|
1115
453f36d7bead
small readability change
Craig Dowell <craigdo@ee.washington.edu>
parents:
1113
diff
changeset
|
498 |
|
1111 | 499 |
/** |
500 |
* A convenience typedef to avoid too much writers cramp. |
|
501 |
*/ |
|
1278 | 502 |
typedef std::list<GlobalRoutingLinkRecord*> ListOfLinkRecords_t; |
1115
453f36d7bead
small readability change
Craig Dowell <craigdo@ee.washington.edu>
parents:
1113
diff
changeset
|
503 |
|
1111 | 504 |
/** |
505 |
* Each Link State Advertisement contains a number of Link Records that |
|
506 |
* describe the kinds of links that are attached to a given node. We |
|
507 |
* consider PointToPoint and StubNetwork links. |
|
508 |
* |
|
509 |
* m_linkRecords is an STL list container to hold the Link Records that have |
|
510 |
* been discovered and prepared for the advertisement. |
|
511 |
* |
|
1278 | 512 |
* @see GlobalRouting::DiscoverLSAs () |
1111 | 513 |
*/ |
514 |
ListOfLinkRecords_t m_linkRecords; |
|
1115
453f36d7bead
small readability change
Craig Dowell <craigdo@ee.washington.edu>
parents:
1113
diff
changeset
|
515 |
|
1111 | 516 |
/** |
1278 | 517 |
* Each Network LSA contains the network mask of the attached network |
518 |
*/ |
|
519 |
Ipv4Mask m_networkLSANetworkMask; |
|
520 |
||
521 |
/** |
|
522 |
* A convenience typedef to avoid too much writers cramp. |
|
523 |
*/ |
|
524 |
typedef std::list<Ipv4Address> ListOfAttachedRouters_t; |
|
525 |
||
526 |
/** |
|
527 |
* Each Network LSA contains a list of attached routers |
|
528 |
* |
|
529 |
* m_attachedRouters is an STL list container to hold the addresses that have |
|
530 |
* been discovered and prepared for the advertisement. |
|
531 |
* |
|
532 |
* @see GlobalRouting::DiscoverLSAs () |
|
533 |
*/ |
|
534 |
ListOfAttachedRouters_t m_attachedRouters; |
|
535 |
||
536 |
/** |
|
1111 | 537 |
* This is a tristate flag used internally in the SPF computation to mark |
538 |
* if an SPFVertex (a data structure representing a vertex in the SPF tree |
|
539 |
* -- a router) is new, is a candidate for a shortest path, or is in its |
|
540 |
* proper position in the tree. |
|
541 |
*/ |
|
542 |
SPFStatus m_status; |
|
543 |
}; |
|
544 |
||
1278 | 545 |
std::ostream& operator<< (std::ostream& os, GlobalRoutingLSA& lsa); |
1111 | 546 |
|
547 |
/** |
|
548 |
* @brief An interface aggregated to a node to provide global routing info |
|
549 |
* |
|
550 |
* An interface aggregated to a node that provides global routing information |
|
551 |
* to a global route manager. The presence of the interface indicates that |
|
552 |
* the node is a router. The interface is the mechanism by which the router |
|
553 |
* advertises its connections to neighboring routers. We're basically |
|
554 |
* allowing the route manager to query for link state advertisements. |
|
555 |
*/ |
|
556 |
class GlobalRouter : public Object |
|
557 |
{ |
|
558 |
public: |
|
559 |
/** |
|
560 |
* @brief The Interface ID of the Global Router interface. |
|
561 |
* |
|
2257
71a58e70c671
QueryInterface -> GetObject
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2251
diff
changeset
|
562 |
* @see Object::GetObject () |
1111 | 563 |
*/ |
2251
04963d8cca51
iid (void) -> GetTypeId (void)
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2250
diff
changeset
|
564 |
static TypeId GetTypeId (void); |
1115
453f36d7bead
small readability change
Craig Dowell <craigdo@ee.washington.edu>
parents:
1113
diff
changeset
|
565 |
|
1111 | 566 |
/** |
1881
24285ca5e94f
fix bug 113 on m_node parameter for GlobalRouter
Tom Henderson <tomh@tomh.org>
parents:
1776
diff
changeset
|
567 |
* @brief Create a Global Router class |
1111 | 568 |
*/ |
1881
24285ca5e94f
fix bug 113 on m_node parameter for GlobalRouter
Tom Henderson <tomh@tomh.org>
parents:
1776
diff
changeset
|
569 |
GlobalRouter (); |
1115
453f36d7bead
small readability change
Craig Dowell <craigdo@ee.washington.edu>
parents:
1113
diff
changeset
|
570 |
|
1111 | 571 |
/** |
572 |
* @brief Get the Router ID associated with this Global Router. |
|
573 |
* |
|
574 |
* The Router IDs are allocated in the RoutingEnvironment -- one per Router, |
|
575 |
* starting at 0.0.0.1 and incrementing with each instantiation of a router. |
|
576 |
* |
|
577 |
* @see RoutingEnvironment::AllocateRouterId () |
|
578 |
* @returns The Router ID associated with the Global Router. |
|
579 |
*/ |
|
580 |
Ipv4Address GetRouterId (void) const; |
|
1115
453f36d7bead
small readability change
Craig Dowell <craigdo@ee.washington.edu>
parents:
1113
diff
changeset
|
581 |
|
1111 | 582 |
/** |
583 |
* @brief Walk the connected channels, discover the adjacent routers and build |
|
1278 | 584 |
* the associated number of Global Routing Link State Advertisements that |
1111 | 585 |
* this router can export. |
586 |
* |
|
587 |
* This is a fairly expensive operation in that every time it is called |
|
588 |
* the current list of LSAs is built by walking connected point-to-point |
|
589 |
* channels and peeking into adjacent IPV4 stacks to get address information. |
|
590 |
* This is done to allow for limited dymanics of the Global Routing |
|
591 |
* environment. By that we mean that you can discover new link state |
|
592 |
* advertisements after a network topology change by calling DiscoverLSAs |
|
593 |
* and then by reading those advertisements. |
|
594 |
* |
|
1278 | 595 |
* @see GlobalRoutingLSA |
1111 | 596 |
* @see GlobalRouter::GetLSA () |
1278 | 597 |
* @returns The number of Global Routing Link State Advertisements. |
1111 | 598 |
*/ |
599 |
uint32_t DiscoverLSAs (void); |
|
1115
453f36d7bead
small readability change
Craig Dowell <craigdo@ee.washington.edu>
parents:
1113
diff
changeset
|
600 |
|
1111 | 601 |
/** |
1278 | 602 |
* @brief Get the Number of Global Routing Link State Advertisements that this |
1111 | 603 |
* router can export. |
604 |
* |
|
605 |
* To get meaningful information you must have previously called DiscoverLSAs. |
|
606 |
* After you know how many LSAs are present in the router, you may call |
|
607 |
* GetLSA () to retrieve the actual advertisement. |
|
608 |
* |
|
609 |
* @see GlobalRouterLSA |
|
1278 | 610 |
* @see GlobalRouting::DiscoverLSAs () |
611 |
* @see GlobalRouting::GetLSA () |
|
612 |
* @returns The number of Global Routing Link State Advertisements. |
|
1111 | 613 |
*/ |
614 |
uint32_t GetNumLSAs (void) const; |
|
1115
453f36d7bead
small readability change
Craig Dowell <craigdo@ee.washington.edu>
parents:
1113
diff
changeset
|
615 |
|
1111 | 616 |
/** |
1278 | 617 |
* @brief Get a Global Routing Link State Advertisements that this router has |
1111 | 618 |
* said that it can export. |
619 |
* |
|
620 |
* This is a fairly inexpensive expensive operation in that the hard work |
|
1278 | 621 |
* was done in GetNumLSAs. We just copy the indicated Global Routing Link |
622 |
* State Advertisement into the requested GlobalRoutingLSA object. |
|
1111 | 623 |
* |
624 |
* You must call GlobalRouter::GetNumLSAs before calling this method in |
|
625 |
* order to discover the adjacent routers and build the advertisements. |
|
626 |
* GetNumLSAs will return the number of LSAs this router advertises. |
|
627 |
* The parameter n (requested LSA number) must be in the range 0 to |
|
628 |
* GetNumLSAs() - 1. |
|
629 |
* |
|
1278 | 630 |
* @see GlobalRoutingLSA |
631 |
* @see GlobalRouting::GetNumLSAs () |
|
1111 | 632 |
* @param n The index number of the LSA you want to read. |
1278 | 633 |
* @param lsa The GlobalRoutingLSA class to receive the LSA information. |
1111 | 634 |
* @returns The number of Global Router Link State Advertisements. |
635 |
*/ |
|
1278 | 636 |
bool GetLSA (uint32_t n, GlobalRoutingLSA &lsa) const; |
1111 | 637 |
|
1210
599a311daef6
fix opt warnings, let compiler do tail call optimization in csma nd, remove protected access from router iface
Craig Dowell <craigdo@ee.washington.edu>
parents:
1202
diff
changeset
|
638 |
private: |
1111 | 639 |
virtual ~GlobalRouter (); |
640 |
void ClearLSAs (void); |
|
641 |
||
642 |
Ptr<NetDevice> GetAdjacent(Ptr<NetDevice> nd, Ptr<Channel> ch) const; |
|
3937
04f9377661b8
convince global routing not to crash in the presence of bridges
Craig Dowell <craigdo@ee.washington.edu>
parents:
2257
diff
changeset
|
643 |
bool FindIfIndexForDevice(Ptr<Node> node, Ptr<NetDevice> nd, uint32_t &index) const; |
3938
972310213d07
Admit possibility that not all nodes are routers.
Craig Dowell <craigdo@ee.washington.edu>
parents:
3937
diff
changeset
|
644 |
Ipv4Address FindDesignatedRouterForLink (Ptr<NetDevice> ndLocal) const; |
972310213d07
Admit possibility that not all nodes are routers.
Craig Dowell <craigdo@ee.washington.edu>
parents:
3937
diff
changeset
|
645 |
bool AnotherRouterOnLink (Ptr<NetDevice> nd) const; |
3939
206f627bd5af
factor DiscoverLSAs into understandable modules
Craig Dowell <craigdo@ee.washington.edu>
parents:
3938
diff
changeset
|
646 |
void ProcessBroadcastLink (Ptr<NetDevice> nd, GlobalRoutingLSA *pLSA, NetDeviceContainer &c); |
206f627bd5af
factor DiscoverLSAs into understandable modules
Craig Dowell <craigdo@ee.washington.edu>
parents:
3938
diff
changeset
|
647 |
void ProcessPointToPointLink (Ptr<NetDevice> ndLocal, GlobalRoutingLSA *pLSA); |
206f627bd5af
factor DiscoverLSAs into understandable modules
Craig Dowell <craigdo@ee.washington.edu>
parents:
3938
diff
changeset
|
648 |
void BuildNetworkLSAs (NetDeviceContainer c); |
206f627bd5af
factor DiscoverLSAs into understandable modules
Craig Dowell <craigdo@ee.washington.edu>
parents:
3938
diff
changeset
|
649 |
bool IsNetDeviceBridged (Ptr<NetDevice> nd) const; |
206f627bd5af
factor DiscoverLSAs into understandable modules
Craig Dowell <craigdo@ee.washington.edu>
parents:
3938
diff
changeset
|
650 |
|
1111 | 651 |
|
1278 | 652 |
typedef std::list<GlobalRoutingLSA*> ListOfLSAs_t; |
1111 | 653 |
ListOfLSAs_t m_LSAs; |
654 |
||
655 |
Ipv4Address m_routerId; |
|
656 |
||
1202
953cc2fadcef
fix memory leak
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1121
diff
changeset
|
657 |
// inherited from Object |
953cc2fadcef
fix memory leak
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1121
diff
changeset
|
658 |
virtual void DoDispose (void); |
1210
599a311daef6
fix opt warnings, let compiler do tail call optimization in csma nd, remove protected access from router iface
Craig Dowell <craigdo@ee.washington.edu>
parents:
1202
diff
changeset
|
659 |
|
1111 | 660 |
/** |
661 |
* @brief Global Router copy construction is disallowed. |
|
662 |
*/ |
|
663 |
GlobalRouter (GlobalRouter& sr); |
|
1210
599a311daef6
fix opt warnings, let compiler do tail call optimization in csma nd, remove protected access from router iface
Craig Dowell <craigdo@ee.washington.edu>
parents:
1202
diff
changeset
|
664 |
|
1111 | 665 |
/** |
666 |
* @brief Global Router assignment operator is disallowed. |
|
667 |
*/ |
|
668 |
GlobalRouter& operator= (GlobalRouter& sr); |
|
669 |
}; |
|
670 |
||
671 |
} // namespace ns3 |
|
672 |
||
1115
453f36d7bead
small readability change
Craig Dowell <craigdo@ee.washington.edu>
parents:
1113
diff
changeset
|
673 |
#endif /* GLOBAL_ROUTER_INTERFACE_H */ |