24 |
24 |
25 NS_DEBUG_COMPONENT_DEFINE ("StaticRouter"); |
25 NS_DEBUG_COMPONENT_DEFINE ("StaticRouter"); |
26 |
26 |
27 namespace ns3 { |
27 namespace ns3 { |
28 |
28 |
|
29 StaticRouterLinkRecord::StaticRouterLinkRecord () |
|
30 : |
|
31 m_linkId ("0.0.0.0"), |
|
32 m_linkData ("0.0.0.0"), |
|
33 m_linkType (Unknown), |
|
34 m_metric (0) |
|
35 { |
|
36 NS_DEBUG("StaticRouterLinkRecord::StaticRouterLinkRecord ()"); |
|
37 } |
|
38 |
|
39 StaticRouterLinkRecord::StaticRouterLinkRecord ( |
|
40 LinkType linkType, |
|
41 Ipv4Address linkId, |
|
42 Ipv4Address linkData, |
|
43 uint32_t metric) |
|
44 : |
|
45 m_linkId (linkId), |
|
46 m_linkData (linkData), |
|
47 m_linkType (linkType), |
|
48 m_metric (metric) |
|
49 { |
|
50 NS_DEBUG("StaticRouterLinkRecord::StaticRouterLinkRecord (" << |
|
51 linkType << ", " << linkId << ", " << linkData << ", " << metric << ")"); |
|
52 } |
|
53 |
|
54 StaticRouterLinkRecord::~StaticRouterLinkRecord () |
|
55 { |
|
56 NS_DEBUG("StaticRouterLinkRecord::~StaticRouterLinkRecord ()"); |
|
57 } |
|
58 |
|
59 Ipv4Address |
|
60 StaticRouterLinkRecord::GetLinkId (void) const |
|
61 { |
|
62 NS_DEBUG("StaticRouterLinkRecord::GetLinkId ()"); |
|
63 return m_linkId; |
|
64 } |
|
65 |
|
66 void |
|
67 StaticRouterLinkRecord::SetLinkId (Ipv4Address addr) |
|
68 { |
|
69 NS_DEBUG("StaticRouterLinkRecord::SetLinkId ()"); |
|
70 m_linkId = addr; |
|
71 } |
|
72 |
|
73 Ipv4Address |
|
74 StaticRouterLinkRecord::GetLinkData (void) const |
|
75 { |
|
76 NS_DEBUG("StaticRouterLinkRecord::GetLinkData ()"); |
|
77 return m_linkData; |
|
78 } |
|
79 |
|
80 void |
|
81 StaticRouterLinkRecord::SetLinkData (Ipv4Address addr) |
|
82 { |
|
83 NS_DEBUG("StaticRouterLinkRecord::SetLinkData ()"); |
|
84 m_linkData = addr; |
|
85 } |
|
86 |
|
87 StaticRouterLinkRecord::LinkType |
|
88 StaticRouterLinkRecord::GetLinkType (void) const |
|
89 { |
|
90 NS_DEBUG("StaticRouterLinkRecord::GetLinkType ()"); |
|
91 return m_linkType; |
|
92 } |
|
93 |
|
94 void |
|
95 StaticRouterLinkRecord::SetLinkType ( |
|
96 StaticRouterLinkRecord::LinkType linkType) |
|
97 { |
|
98 NS_DEBUG("StaticRouterLinkRecord::SetLinkType ()"); |
|
99 m_linkType = linkType; |
|
100 } |
|
101 |
|
102 uint32_t |
|
103 StaticRouterLinkRecord::GetMetric (void) const |
|
104 { |
|
105 NS_DEBUG("StaticRouterLinkRecord::GetMetric ()"); |
|
106 return m_metric; |
|
107 } |
|
108 |
|
109 void |
|
110 StaticRouterLinkRecord::SetMetric (uint32_t metric) |
|
111 { |
|
112 NS_DEBUG("StaticRouterLinkRecord::SetMetric ()"); |
|
113 m_metric = metric; |
|
114 } |
|
115 |
29 StaticRouterLSA::StaticRouterLSA() |
116 StaticRouterLSA::StaticRouterLSA() |
30 : |
117 : |
31 m_linkStateId("0.0.0.0"), |
118 m_linkStateId("0.0.0.0"), |
32 m_advertisingRtr("0.0.0.0"), |
119 m_advertisingRtr("0.0.0.0"), |
33 m_linkRecords(), |
120 m_linkRecords(), |
34 m_stat(StaticRouterLSA::LSA_SPF_NOT_EXPLORED) |
121 m_status(StaticRouterLSA::LSA_SPF_NOT_EXPLORED) |
35 { |
122 { |
36 NS_DEBUG("StaticRouterLSA::StaticRouterLSA ()"); |
123 NS_DEBUG("StaticRouterLSA::StaticRouterLSA ()"); |
|
124 } |
|
125 |
|
126 StaticRouterLSA::StaticRouterLSA ( |
|
127 StaticRouterLSA::SPFStatus status, |
|
128 Ipv4Address linkStateId, |
|
129 Ipv4Address advertisingRtr) |
|
130 : |
|
131 m_linkStateId(linkStateId), |
|
132 m_advertisingRtr(advertisingRtr), |
|
133 m_linkRecords(), |
|
134 m_status(status) |
|
135 { |
|
136 NS_DEBUG("StaticRouterLSA::StaticRouterLSA (" << status << ", " << |
|
137 linkStateId << ", " << advertisingRtr << ")"); |
37 } |
138 } |
38 |
139 |
39 StaticRouterLSA::StaticRouterLSA (StaticRouterLSA& lsa) |
140 StaticRouterLSA::StaticRouterLSA (StaticRouterLSA& lsa) |
40 : m_linkStateId(lsa.m_linkStateId), m_advertisingRtr(lsa.m_advertisingRtr), |
141 : m_linkStateId(lsa.m_linkStateId), m_advertisingRtr(lsa.m_advertisingRtr), |
41 m_stat(lsa.m_stat) |
142 m_status(lsa.m_status) |
42 { |
143 { |
43 NS_ASSERT_MSG(IsEmpty(), |
144 NS_ASSERT_MSG(IsEmpty(), |
44 "StaticRouterLSA::StaticRouterLSA (): Non-empty LSA in constructor"); |
145 "StaticRouterLSA::StaticRouterLSA (): Non-empty LSA in constructor"); |
45 CopyLinkRecords (lsa); |
146 CopyLinkRecords (lsa); |
46 } |
147 } |
47 |
148 |
48 StaticRouterLSA& |
149 StaticRouterLSA& |
49 StaticRouterLSA::operator= (StaticRouterLSA& lsa) |
150 StaticRouterLSA::operator= (const StaticRouterLSA& lsa) |
50 { |
151 { |
51 m_linkStateId = lsa.m_linkStateId; |
152 m_linkStateId = lsa.m_linkStateId; |
52 m_advertisingRtr = lsa.m_advertisingRtr; |
153 m_advertisingRtr = lsa.m_advertisingRtr; |
53 m_stat = lsa.m_stat; |
154 m_status = lsa.m_status; |
54 |
155 |
55 ClearLinkRecords (); |
156 ClearLinkRecords (); |
56 CopyLinkRecords (lsa); |
157 CopyLinkRecords (lsa); |
57 return *this; |
158 return *this; |
58 } |
159 } |
59 |
160 |
60 void |
161 void |
61 StaticRouterLSA::CopyLinkRecords (StaticRouterLSA& lsa) |
162 StaticRouterLSA::CopyLinkRecords (const StaticRouterLSA& lsa) |
62 { |
163 { |
63 for ( ListOfLinkRecords_t::iterator i = lsa.m_linkRecords.begin (); |
164 for (ListOfLinkRecords_t::const_iterator i = lsa.m_linkRecords.begin (); |
64 i != lsa.m_linkRecords.end (); |
165 i != lsa.m_linkRecords.end (); |
65 i++) |
166 i++) |
66 { |
167 { |
67 StaticRouterLinkRecord *pSrc = *i; |
168 StaticRouterLinkRecord *pSrc = *i; |
68 StaticRouterLinkRecord *pDst = new StaticRouterLinkRecord; |
169 StaticRouterLinkRecord *pDst = new StaticRouterLinkRecord; |
69 pDst->m_linkId = pSrc->m_linkId; |
170 |
70 pDst->m_linkData = pSrc->m_linkData; |
171 pDst->SetLinkType (pSrc->GetLinkType ()); |
71 pDst->m_linkType = pSrc->m_linkType; |
172 pDst->SetLinkId (pSrc->GetLinkId ()); |
|
173 pDst->SetLinkData (pSrc->GetLinkData ()); |
|
174 |
72 m_linkRecords.push_back(pDst); |
175 m_linkRecords.push_back(pDst); |
73 pDst = 0; |
176 pDst = 0; |
74 } |
177 } |
75 } |
178 } |
76 |
179 |
127 } |
230 } |
128 NS_ASSERT_MSG(false, "StaticRouterLSA::GetLinkRecord (): invalid index"); |
231 NS_ASSERT_MSG(false, "StaticRouterLSA::GetLinkRecord (): invalid index"); |
129 return 0; |
232 return 0; |
130 } |
233 } |
131 |
234 |
132 |
|
133 bool |
235 bool |
134 StaticRouterLSA::IsEmpty (void) |
236 StaticRouterLSA::IsEmpty (void) const |
135 { |
237 { |
136 return m_linkRecords.size () == 0; |
238 return m_linkRecords.size () == 0; |
137 } |
239 } |
138 |
240 |
|
241 Ipv4Address |
|
242 StaticRouterLSA::GetLinkStateId (void) const |
|
243 { |
|
244 return m_linkStateId; |
|
245 } |
|
246 |
|
247 void |
|
248 StaticRouterLSA::SetLinkStateId (Ipv4Address addr) |
|
249 { |
|
250 m_linkStateId = addr; |
|
251 } |
|
252 |
|
253 Ipv4Address |
|
254 StaticRouterLSA::GetAdvertisingRouter (void) const |
|
255 { |
|
256 return m_advertisingRtr; |
|
257 } |
|
258 |
|
259 void |
|
260 StaticRouterLSA::SetAdvertisingRouter (Ipv4Address addr) |
|
261 { |
|
262 m_advertisingRtr = addr; |
|
263 } |
|
264 |
|
265 StaticRouterLSA::SPFStatus |
|
266 StaticRouterLSA::GetStatus (void) const |
|
267 { |
|
268 return m_status; |
|
269 } |
|
270 |
|
271 void |
|
272 StaticRouterLSA::SetStatus (StaticRouterLSA::SPFStatus status) |
|
273 { |
|
274 m_status = status; |
|
275 } |
|
276 |
139 void |
277 void |
140 StaticRouterLSA::Print (std::ostream &os) |
278 StaticRouterLSA::Print (std::ostream &os) const |
141 { |
279 { |
142 os << "m_linkStateId = " << m_linkStateId << std::endl << |
280 os << "m_linkStateId = " << m_linkStateId << std::endl << |
143 "m_advertisingRtr = " << m_advertisingRtr << std::endl; |
281 "m_advertisingRtr = " << m_advertisingRtr << std::endl; |
144 |
282 |
145 for ( ListOfLinkRecords_t::iterator i = m_linkRecords.begin (); |
283 for ( ListOfLinkRecords_t::const_iterator i = m_linkRecords.begin (); |
146 i != m_linkRecords.end (); |
284 i != m_linkRecords.end (); |
147 i++) |
285 i++) |
148 { |
286 { |
149 StaticRouterLinkRecord *p = *i; |
287 StaticRouterLinkRecord *p = *i; |
150 os << "----------" << std::endl; |
288 os << "----------" << std::endl; |
151 os << "m_linkId = " << p->m_linkId << std::endl; |
289 os << "m_linkId = " << p->GetLinkId () << std::endl; |
152 os << "m_linkData = " << p->m_linkData << std::endl; |
290 os << "m_linkData = " << p->GetLinkData () << std::endl; |
153 } |
291 } |
154 } |
292 } |
155 |
293 |
156 std::ostream& operator<< (std::ostream& os, StaticRouterLSA& lsa) |
294 std::ostream& operator<< (std::ostream& os, StaticRouterLSA& lsa) |
157 { |
295 { |
228 // What this means is that there is going to be one advertisement with some |
366 // What this means is that there is going to be one advertisement with some |
229 // number of link records. This means that GetNumLSAs will actually always |
367 // number of link records. This means that GetNumLSAs will actually always |
230 // return exactly one. |
368 // return exactly one. |
231 // |
369 // |
232 StaticRouterLSA *pLSA = new StaticRouterLSA; |
370 StaticRouterLSA *pLSA = new StaticRouterLSA; |
233 pLSA->m_linkStateId = m_routerId; |
371 pLSA->SetLinkStateId (m_routerId); |
234 pLSA->m_advertisingRtr = m_routerId; |
372 pLSA->SetAdvertisingRouter (m_routerId); |
235 pLSA->m_stat = StaticRouterLSA::LSA_SPF_NOT_EXPLORED; |
373 pLSA->SetStatus (StaticRouterLSA::LSA_SPF_NOT_EXPLORED); |
236 // |
374 // |
237 // We need to ask the node for the number of net devices attached. This isn't |
375 // We need to ask the node for the number of net devices attached. This isn't |
238 // necessarily equal to the number of links to adjacent nodes (other routers) |
376 // necessarily equal to the number of links to adjacent nodes (other routers) |
239 // as the number of devices may include those for stub networks (e.g., |
377 // as the number of devices may include those for stub networks (e.g., |
240 // ethernets, etc.). So we have to walk through the list of net devices and |
378 // ethernets, etc.). So we have to walk through the list of net devices and |
313 // Now we can fill out the link records for this link. There are always two |
451 // Now we can fill out the link records for this link. There are always two |
314 // link records; the first is a point-to-point record describing the link and |
452 // link records; the first is a point-to-point record describing the link and |
315 // the second is a stub network record with the network number. |
453 // the second is a stub network record with the network number. |
316 // |
454 // |
317 StaticRouterLinkRecord *plr = new StaticRouterLinkRecord; |
455 StaticRouterLinkRecord *plr = new StaticRouterLinkRecord; |
318 plr->m_linkType = StaticRouterLinkRecord::PointToPoint; |
456 plr->SetLinkType (StaticRouterLinkRecord::PointToPoint); |
319 plr->m_linkId = rtrIdRemote; |
457 plr->SetLinkId (rtrIdRemote); |
320 plr->m_linkData = addrLocal; |
458 plr->SetLinkData (addrLocal); |
321 pLSA->AddLinkRecord(plr); |
459 pLSA->AddLinkRecord(plr); |
322 plr = 0; |
460 plr = 0; |
323 |
461 |
324 plr = new StaticRouterLinkRecord; |
462 plr = new StaticRouterLinkRecord; |
325 plr->m_linkType = StaticRouterLinkRecord::StubNetwork; |
463 plr->SetLinkType (StaticRouterLinkRecord::StubNetwork); |
326 plr->m_linkId = addrRemote; |
464 plr->SetLinkId (addrRemote); |
327 plr->m_linkData.Set(maskRemote.GetHostOrder()); // Frown |
465 plr->SetLinkData (Ipv4Address(maskRemote.GetHostOrder())); // Frown |
328 pLSA->AddLinkRecord(plr); |
466 pLSA->AddLinkRecord(plr); |
329 plr = 0; |
467 plr = 0; |
330 } |
468 } |
331 // |
469 // |
332 // The LSA goes on a list of LSAs in case we want to begin exporting other |
470 // The LSA goes on a list of LSAs in case we want to begin exporting other |
335 NS_DEBUG(*pLSA); |
473 NS_DEBUG(*pLSA); |
336 return m_LSAs.size (); |
474 return m_LSAs.size (); |
337 } |
475 } |
338 |
476 |
339 uint32_t |
477 uint32_t |
340 StaticRouter::GetNumLSAs (void) |
478 StaticRouter::GetNumLSAs (void) const |
341 { |
479 { |
342 NS_DEBUG("StaticRouter::GetNumLSAs ()"); |
480 NS_DEBUG("StaticRouter::GetNumLSAs ()"); |
343 return m_LSAs.size (); |
481 return m_LSAs.size (); |
344 } |
482 } |
345 |
483 |
346 // |
484 // |
347 // Get the nth link state advertisement from this router. |
485 // Get the nth link state advertisement from this router. |
348 // |
486 // |
349 bool |
487 bool |
350 StaticRouter::GetLSA (uint32_t n, StaticRouterLSA &lsa) |
488 StaticRouter::GetLSA (uint32_t n, StaticRouterLSA &lsa) const |
351 { |
489 { |
352 NS_ASSERT_MSG(lsa.IsEmpty(), "StaticRouter::GetLSA (): Must pass empty LSA"); |
490 NS_ASSERT_MSG(lsa.IsEmpty(), "StaticRouter::GetLSA (): Must pass empty LSA"); |
353 // |
491 // |
354 // All of the work was done in GetNumLSAs. All we have to do here is to |
492 // All of the work was done in GetNumLSAs. All we have to do here is to |
355 // walk the list of link state advertisements created there and return the |
493 // walk the list of link state advertisements created there and return the |
356 // one the client is interested in. |
494 // one the client is interested in. |
357 // |
495 // |
358 ListOfLSAs_t::iterator i = m_LSAs.begin (); |
496 ListOfLSAs_t::const_iterator i = m_LSAs.begin (); |
359 uint32_t j = 0; |
497 uint32_t j = 0; |
360 |
498 |
361 for (; i != m_LSAs.end (); i++, j++) |
499 for (; i != m_LSAs.end (); i++, j++) |
362 { |
500 { |
363 if (j == n) |
501 if (j == n) |