author | Tom Henderson <tomh@tomh.org> |
Tue, 10 Jul 2007 15:03:39 -0700 | |
changeset 1067 | 704eb2583865 |
parent 1061 | 007ef746ec4d |
child 1070 | fa5ec2180ec4 |
permissions | -rw-r--r-- |
1028
56460b160cef
beginnings of static routing
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
1 |
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
56460b160cef
beginnings of static routing
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
2 |
/* |
56460b160cef
beginnings of static routing
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
3 |
* This program is free software; you can redistribute it and/or modify |
56460b160cef
beginnings of static routing
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
4 |
* it under the terms of the GNU General Public License version 2 as |
56460b160cef
beginnings of static routing
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
5 |
* published by the Free Software Foundation; |
56460b160cef
beginnings of static routing
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
6 |
* |
56460b160cef
beginnings of static routing
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
7 |
* This program is distributed in the hope that it will be useful, |
56460b160cef
beginnings of static routing
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
8 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
56460b160cef
beginnings of static routing
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
9 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
56460b160cef
beginnings of static routing
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
10 |
* GNU General Public License for more details. |
56460b160cef
beginnings of static routing
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
11 |
* |
56460b160cef
beginnings of static routing
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
12 |
* You should have received a copy of the GNU General Public License |
56460b160cef
beginnings of static routing
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
13 |
* along with this program; if not, write to the Free Software |
56460b160cef
beginnings of static routing
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
14 |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
56460b160cef
beginnings of static routing
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
15 |
*/ |
56460b160cef
beginnings of static routing
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
16 |
|
56460b160cef
beginnings of static routing
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
17 |
#include "ns3/debug.h" |
1048 | 18 |
#include "ns3/assert.h" |
19 |
#include "ns3/channel.h" |
|
20 |
#include "ns3/net-device.h" |
|
1035 | 21 |
#include "ns3/internet-node.h" |
1048 | 22 |
#include "ns3/ipv4.h" |
1028
56460b160cef
beginnings of static routing
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
23 |
#include "static-router.h" |
56460b160cef
beginnings of static routing
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
24 |
|
56460b160cef
beginnings of static routing
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
25 |
NS_DEBUG_COMPONENT_DEFINE ("StaticRouter"); |
56460b160cef
beginnings of static routing
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
26 |
|
56460b160cef
beginnings of static routing
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
27 |
namespace ns3 { |
56460b160cef
beginnings of static routing
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
28 |
|
1048 | 29 |
StaticRouterLSA::StaticRouterLSA() |
30 |
: |
|
31 |
m_linkStateId("0.0.0.0"), |
|
32 |
m_advertisingRtr("0.0.0.0"), |
|
33 |
m_linkRecords() |
|
1045
c2c43e021fb7
Add ctor/dtor to StaticRouterLSA, add the Add() method to add link records, misc. cleanup
Tom Henderson <tomh@tomh.org>
parents:
1035
diff
changeset
|
34 |
{ |
c2c43e021fb7
Add ctor/dtor to StaticRouterLSA, add the Add() method to add link records, misc. cleanup
Tom Henderson <tomh@tomh.org>
parents:
1035
diff
changeset
|
35 |
NS_DEBUG("StaticRouterLSA::StaticRouterLSA ()"); |
c2c43e021fb7
Add ctor/dtor to StaticRouterLSA, add the Add() method to add link records, misc. cleanup
Tom Henderson <tomh@tomh.org>
parents:
1035
diff
changeset
|
36 |
} |
1048 | 37 |
|
1056 | 38 |
StaticRouterLSA::StaticRouterLSA (StaticRouterLSA& lsa) |
39 |
: m_linkStateId(lsa.m_linkStateId), m_advertisingRtr(lsa.m_advertisingRtr) |
|
40 |
{ |
|
41 |
NS_DEBUG("StaticRouterLSA Copy Constructor"); |
|
42 |
NS_ASSERT_MSG(IsEmpty(), "The LSA must be empty before copy"); |
|
43 |
||
44 |
for ( ListOfLinkRecords_t::iterator i = lsa.m_linkRecords.begin (); |
|
45 |
i != lsa.m_linkRecords.end (); |
|
46 |
i++) |
|
47 |
{ |
|
48 |
StaticRouterLinkRecord *pSrc = *i; |
|
49 |
StaticRouterLinkRecord *pDst = new StaticRouterLinkRecord; |
|
50 |
pDst->m_linkId = pSrc->m_linkId; |
|
51 |
pDst->m_linkData = pSrc->m_linkData; |
|
1067
704eb2583865
Iterate link records (16.1(2))
Tom Henderson <tomh@tomh.org>
parents:
1061
diff
changeset
|
52 |
pDst->m_linkType = pSrc->m_linkType; |
1056 | 53 |
m_linkRecords.push_back(pDst); |
54 |
pDst = 0; |
|
55 |
} |
|
56 |
} |
|
57 |
||
58 |
StaticRouterLSA& |
|
1060 | 59 |
StaticRouterLSA::operator= (StaticRouterLSA& lsa) |
1056 | 60 |
{ |
61 |
NS_DEBUG("StaticRouterLSA Operator ="); |
|
1057
2620020dc72c
first working router
Craig Dowell <craigdo@ee.washington.edu>
parents:
1056
diff
changeset
|
62 |
NS_ASSERT_MSG(IsEmpty(), "The LSA must be empty before assignment"); |
2620020dc72c
first working router
Craig Dowell <craigdo@ee.washington.edu>
parents:
1056
diff
changeset
|
63 |
|
2620020dc72c
first working router
Craig Dowell <craigdo@ee.washington.edu>
parents:
1056
diff
changeset
|
64 |
m_linkStateId = lsa.m_linkStateId; |
2620020dc72c
first working router
Craig Dowell <craigdo@ee.washington.edu>
parents:
1056
diff
changeset
|
65 |
m_advertisingRtr = lsa.m_advertisingRtr; |
2620020dc72c
first working router
Craig Dowell <craigdo@ee.washington.edu>
parents:
1056
diff
changeset
|
66 |
|
2620020dc72c
first working router
Craig Dowell <craigdo@ee.washington.edu>
parents:
1056
diff
changeset
|
67 |
for ( ListOfLinkRecords_t::iterator i = lsa.m_linkRecords.begin (); |
2620020dc72c
first working router
Craig Dowell <craigdo@ee.washington.edu>
parents:
1056
diff
changeset
|
68 |
i != lsa.m_linkRecords.end (); |
2620020dc72c
first working router
Craig Dowell <craigdo@ee.washington.edu>
parents:
1056
diff
changeset
|
69 |
i++) |
2620020dc72c
first working router
Craig Dowell <craigdo@ee.washington.edu>
parents:
1056
diff
changeset
|
70 |
{ |
2620020dc72c
first working router
Craig Dowell <craigdo@ee.washington.edu>
parents:
1056
diff
changeset
|
71 |
StaticRouterLinkRecord *pSrc = *i; |
2620020dc72c
first working router
Craig Dowell <craigdo@ee.washington.edu>
parents:
1056
diff
changeset
|
72 |
StaticRouterLinkRecord *pDst = new StaticRouterLinkRecord; |
2620020dc72c
first working router
Craig Dowell <craigdo@ee.washington.edu>
parents:
1056
diff
changeset
|
73 |
pDst->m_linkId = pSrc->m_linkId; |
2620020dc72c
first working router
Craig Dowell <craigdo@ee.washington.edu>
parents:
1056
diff
changeset
|
74 |
pDst->m_linkData = pSrc->m_linkData; |
1067
704eb2583865
Iterate link records (16.1(2))
Tom Henderson <tomh@tomh.org>
parents:
1061
diff
changeset
|
75 |
pDst->m_linkType = pSrc->m_linkType; |
1057
2620020dc72c
first working router
Craig Dowell <craigdo@ee.washington.edu>
parents:
1056
diff
changeset
|
76 |
m_linkRecords.push_back(pDst); |
2620020dc72c
first working router
Craig Dowell <craigdo@ee.washington.edu>
parents:
1056
diff
changeset
|
77 |
pDst = 0; |
2620020dc72c
first working router
Craig Dowell <craigdo@ee.washington.edu>
parents:
1056
diff
changeset
|
78 |
} |
2620020dc72c
first working router
Craig Dowell <craigdo@ee.washington.edu>
parents:
1056
diff
changeset
|
79 |
|
1056 | 80 |
return *this; |
81 |
} |
|
82 |
||
1048 | 83 |
StaticRouterLSA::~StaticRouterLSA() |
1045
c2c43e021fb7
Add ctor/dtor to StaticRouterLSA, add the Add() method to add link records, misc. cleanup
Tom Henderson <tomh@tomh.org>
parents:
1035
diff
changeset
|
84 |
{ |
c2c43e021fb7
Add ctor/dtor to StaticRouterLSA, add the Add() method to add link records, misc. cleanup
Tom Henderson <tomh@tomh.org>
parents:
1035
diff
changeset
|
85 |
NS_DEBUG("StaticRouterLSA::~StaticRouterLSA ()"); |
1056 | 86 |
ClearLinkRecords (); |
87 |
} |
|
1048 | 88 |
|
1056 | 89 |
void |
90 |
StaticRouterLSA::ClearLinkRecords(void) |
|
91 |
{ |
|
1048 | 92 |
for ( ListOfLinkRecords_t::iterator i = m_linkRecords.begin (); |
93 |
i != m_linkRecords.end (); |
|
94 |
i++) |
|
95 |
{ |
|
1056 | 96 |
NS_DEBUG("StaticRouterLSA::ClearLinkRecords (): free link record"); |
1048 | 97 |
|
98 |
StaticRouterLinkRecord *p = *i; |
|
99 |
delete p; |
|
100 |
p = 0; |
|
101 |
||
102 |
*i = 0; |
|
103 |
} |
|
1056 | 104 |
NS_DEBUG("StaticRouterLSA::ClearLinkRecords(): clear list"); |
1048 | 105 |
m_linkRecords.clear(); |
1045
c2c43e021fb7
Add ctor/dtor to StaticRouterLSA, add the Add() method to add link records, misc. cleanup
Tom Henderson <tomh@tomh.org>
parents:
1035
diff
changeset
|
106 |
} |
c2c43e021fb7
Add ctor/dtor to StaticRouterLSA, add the Add() method to add link records, misc. cleanup
Tom Henderson <tomh@tomh.org>
parents:
1035
diff
changeset
|
107 |
|
1048 | 108 |
uint32_t |
109 |
StaticRouterLSA::AddLinkRecord (StaticRouterLinkRecord* lr) |
|
1045
c2c43e021fb7
Add ctor/dtor to StaticRouterLSA, add the Add() method to add link records, misc. cleanup
Tom Henderson <tomh@tomh.org>
parents:
1035
diff
changeset
|
110 |
{ |
1048 | 111 |
m_linkRecords.push_back (lr); |
112 |
return m_linkRecords.size (); |
|
1045
c2c43e021fb7
Add ctor/dtor to StaticRouterLSA, add the Add() method to add link records, misc. cleanup
Tom Henderson <tomh@tomh.org>
parents:
1035
diff
changeset
|
113 |
} |
c2c43e021fb7
Add ctor/dtor to StaticRouterLSA, add the Add() method to add link records, misc. cleanup
Tom Henderson <tomh@tomh.org>
parents:
1035
diff
changeset
|
114 |
|
1056 | 115 |
bool |
116 |
StaticRouterLSA::IsEmpty (void) |
|
117 |
{ |
|
118 |
return m_linkRecords.size () == 0; |
|
119 |
} |
|
120 |
||
121 |
void |
|
122 |
StaticRouterLSA::Print (std::ostream &os) |
|
123 |
{ |
|
124 |
os << "m_linkStateId = " << m_linkStateId << std::endl << |
|
125 |
"m_advertisingRtr = " << m_advertisingRtr << std::endl; |
|
126 |
||
127 |
for ( ListOfLinkRecords_t::iterator i = m_linkRecords.begin (); |
|
128 |
i != m_linkRecords.end (); |
|
129 |
i++) |
|
130 |
{ |
|
131 |
StaticRouterLinkRecord *p = *i; |
|
132 |
os << "----------" << std::endl; |
|
133 |
os << "m_linkId = " << p->m_linkId << std::endl; |
|
134 |
os << "m_linkData = " << p->m_linkData << std::endl; |
|
135 |
} |
|
136 |
} |
|
137 |
||
138 |
std::ostream& operator<< (std::ostream& os, StaticRouterLSA& lsa) |
|
139 |
{ |
|
140 |
lsa.Print (os); |
|
141 |
return os; |
|
142 |
} |
|
143 |
||
1028
56460b160cef
beginnings of static routing
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
144 |
const InterfaceId StaticRouter::iid = |
56460b160cef
beginnings of static routing
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
145 |
MakeInterfaceId ("StaticRouter", Object::iid); |
56460b160cef
beginnings of static routing
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
146 |
|
1035 | 147 |
StaticRouter::StaticRouter (Ptr<Node> node) |
1056 | 148 |
: m_node(node), m_LSAs() |
1028
56460b160cef
beginnings of static routing
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
149 |
{ |
1048 | 150 |
NS_DEBUG("StaticRouter::StaticRouter ()"); |
1028
56460b160cef
beginnings of static routing
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
151 |
SetInterfaceId (StaticRouter::iid); |
1056 | 152 |
m_routerId.Set(RoutingEnvironment::AllocateRouterId()); |
1028
56460b160cef
beginnings of static routing
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
153 |
} |
56460b160cef
beginnings of static routing
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
154 |
|
56460b160cef
beginnings of static routing
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
155 |
StaticRouter::~StaticRouter () |
56460b160cef
beginnings of static routing
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
156 |
{ |
56460b160cef
beginnings of static routing
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
157 |
NS_DEBUG("StaticRouter::~StaticRouter ()"); |
1056 | 158 |
ClearLSAs(); |
159 |
} |
|
160 |
||
161 |
void |
|
162 |
StaticRouter::ClearLSAs () |
|
163 |
{ |
|
164 |
NS_DEBUG("StaticRouter::ClearLSAs ()"); |
|
165 |
||
166 |
for ( ListOfLSAs_t::iterator i = m_LSAs.begin (); |
|
167 |
i != m_LSAs.end (); |
|
168 |
i++) |
|
169 |
{ |
|
170 |
NS_DEBUG("StaticRouter::ClearLSAs (): free LSA"); |
|
171 |
||
172 |
StaticRouterLSA *p = *i; |
|
173 |
delete p; |
|
174 |
p = 0; |
|
175 |
||
176 |
*i = 0; |
|
177 |
} |
|
178 |
NS_DEBUG("StaticRouter::ClearLSAs (): clear list"); |
|
179 |
m_LSAs.clear(); |
|
180 |
} |
|
181 |
||
182 |
Ipv4Address |
|
183 |
StaticRouter::GetRouterId (void) |
|
184 |
{ |
|
185 |
return m_routerId; |
|
1028
56460b160cef
beginnings of static routing
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
186 |
} |
56460b160cef
beginnings of static routing
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
187 |
|
1048 | 188 |
// |
1061
007ef746ec4d
made GetNumLSAs cheap, added DiscoverLSAs as expensive call.
Craig Dowell <craigdo@ee.washington.edu>
parents:
1060
diff
changeset
|
189 |
// Go out and discover any adjacent routers and build the Link State |
007ef746ec4d
made GetNumLSAs cheap, added DiscoverLSAs as expensive call.
Craig Dowell <craigdo@ee.washington.edu>
parents:
1060
diff
changeset
|
190 |
// Advertisements that reflect them and their associated networks. |
1048 | 191 |
// |
192 |
uint32_t |
|
1061
007ef746ec4d
made GetNumLSAs cheap, added DiscoverLSAs as expensive call.
Craig Dowell <craigdo@ee.washington.edu>
parents:
1060
diff
changeset
|
193 |
StaticRouter::DiscoverLSAs (void) |
1048 | 194 |
{ |
1061
007ef746ec4d
made GetNumLSAs cheap, added DiscoverLSAs as expensive call.
Craig Dowell <craigdo@ee.washington.edu>
parents:
1060
diff
changeset
|
195 |
NS_DEBUG("StaticRouter::DiscoverLSAs ()"); |
1048 | 196 |
NS_ASSERT_MSG(m_node, "<Node> interface not set"); |
1056 | 197 |
ClearLSAs (); |
1048 | 198 |
// |
199 |
// We're aggregated to a node. We need to ask the node for a pointer to its |
|
200 |
// Ipv4 interface. This is where the information regarding the attached |
|
201 |
// interfaces lives. |
|
202 |
// |
|
1050 | 203 |
Ptr<Ipv4> ipv4Local = m_node->QueryInterface<Ipv4> (Ipv4::iid); |
204 |
NS_ASSERT_MSG(ipv4Local, "QI for <Ipv4> interface failed"); |
|
1048 | 205 |
// |
1056 | 206 |
// We need to ask the node for the number of net devices attached. This isn't |
207 |
// necessarily equal to the number of links to adjacent nodes (other routers) |
|
208 |
// as the number of devices may include those for stub networks (e.g., |
|
209 |
// ethernets, etc.). So we have to walk through the list of net devices and |
|
210 |
// pay attention to those that are directly connected to another router through |
|
211 |
// a point-to-point channel. |
|
1048 | 212 |
// |
1050 | 213 |
uint32_t numDevices = m_node->GetNDevices(); |
1061
007ef746ec4d
made GetNumLSAs cheap, added DiscoverLSAs as expensive call.
Craig Dowell <craigdo@ee.washington.edu>
parents:
1060
diff
changeset
|
214 |
NS_DEBUG("StaticRouter::DiscoverLSAs (): numDevices = " << numDevices); |
1050 | 215 |
// |
216 |
// Loop through the devices looking for those connected to a point-to-point |
|
1056 | 217 |
// channel. |
1050 | 218 |
// |
219 |
for (uint32_t i = 0; i < numDevices; ++i) |
|
1048 | 220 |
{ |
1056 | 221 |
Ptr<NetDevice> ndLocal = m_node->GetDevice(i); |
1048 | 222 |
|
1056 | 223 |
if (!ndLocal->IsPointToPoint ()) |
1048 | 224 |
{ |
1061
007ef746ec4d
made GetNumLSAs cheap, added DiscoverLSAs as expensive call.
Craig Dowell <craigdo@ee.washington.edu>
parents:
1060
diff
changeset
|
225 |
NS_DEBUG("StaticRouter::DiscoverLSAs (): non-point-to-point device"); |
1048 | 226 |
continue; |
227 |
} |
|
228 |
||
1061
007ef746ec4d
made GetNumLSAs cheap, added DiscoverLSAs as expensive call.
Craig Dowell <craigdo@ee.washington.edu>
parents:
1060
diff
changeset
|
229 |
NS_DEBUG("StaticRouter::DiscoverLSAs (): Point-to-point device"); |
1050 | 230 |
// |
231 |
// Now, we have to find the Ipv4 interface whose netdevice is the one we |
|
1056 | 232 |
// just found. This is still the IP on the local side of the channel. There |
233 |
// is a function to do this used down in the guts of the stack, but it's not |
|
1050 | 234 |
// exported so we had to whip up an equivalent. |
235 |
// |
|
1056 | 236 |
uint32_t ifIndexLocal = FindIfIndexForDevice(m_node, ndLocal); |
1050 | 237 |
// |
238 |
// Now that we have the Ipv4 interface index, we can get the address and mask |
|
239 |
// we need. |
|
240 |
// |
|
241 |
Ipv4Address addrLocal = ipv4Local->GetAddress(ifIndexLocal); |
|
242 |
Ipv4Mask maskLocal = ipv4Local->GetNetworkMask(ifIndexLocal); |
|
243 |
NS_DEBUG("Working with local address " << addrLocal); |
|
1052
e10e6bbba40e
forgot to remove a header include
Craig Dowell <craigdo@ee.washington.edu>
parents:
1050
diff
changeset
|
244 |
// |
1056 | 245 |
// Now, we're going to walk over to the remote net device on the other end of |
246 |
// the point-to-point channel we now know we have. This is where our adjacent |
|
247 |
// router (to use OSPF lingo) is running. |
|
1048 | 248 |
// |
1056 | 249 |
Ptr<Channel> ch = ndLocal->GetChannel(); |
250 |
Ptr<NetDevice> ndRemote = GetAdjacent(ndLocal, ch); |
|
1048 | 251 |
// |
1052
e10e6bbba40e
forgot to remove a header include
Craig Dowell <craigdo@ee.washington.edu>
parents:
1050
diff
changeset
|
252 |
// The adjacent net device is aggregated to a node. We need to ask that net |
e10e6bbba40e
forgot to remove a header include
Craig Dowell <craigdo@ee.washington.edu>
parents:
1050
diff
changeset
|
253 |
// device for its node, then ask that node for its Ipv4 interface. |
e10e6bbba40e
forgot to remove a header include
Craig Dowell <craigdo@ee.washington.edu>
parents:
1050
diff
changeset
|
254 |
// |
1050 | 255 |
Ptr<Node> nodeRemote = ndRemote->GetNode(); |
256 |
Ptr<Ipv4> ipv4Remote = nodeRemote->QueryInterface<Ipv4> (Ipv4::iid); |
|
257 |
NS_ASSERT_MSG(ipv4Remote, "QI for remote <Ipv4> interface failed"); |
|
258 |
// |
|
1056 | 259 |
// Per the OSPF spec, we're going to need the remote router ID, so we might as |
260 |
// well get it now. |
|
261 |
// |
|
262 |
Ptr<StaticRouter> srRemote = |
|
263 |
nodeRemote->QueryInterface<StaticRouter> (StaticRouter::iid); |
|
264 |
NS_ASSERT_MSG(srRemote, "QI for remote <StaticRouter> failed"); |
|
265 |
Ipv4Address rtrIdRemote = srRemote->GetRouterId(); |
|
266 |
NS_DEBUG("Working with remote router " << rtrIdRemote); |
|
267 |
// |
|
1050 | 268 |
// Now, just like we did above, we need to get the IP interface index for the |
269 |
// net device on the other end of the point-to-point channel. |
|
1048 | 270 |
// |
1050 | 271 |
uint32_t ifIndexRemote = FindIfIndexForDevice(nodeRemote, ndRemote); |
272 |
// |
|
1052
e10e6bbba40e
forgot to remove a header include
Craig Dowell <craigdo@ee.washington.edu>
parents:
1050
diff
changeset
|
273 |
// Now that we have the Ipv4 interface, we can get the (remote) address and |
e10e6bbba40e
forgot to remove a header include
Craig Dowell <craigdo@ee.washington.edu>
parents:
1050
diff
changeset
|
274 |
// mask we need. |
1048 | 275 |
// |
1050 | 276 |
Ipv4Address addrRemote = ipv4Remote->GetAddress(ifIndexRemote); |
277 |
Ipv4Mask maskRemote = ipv4Remote->GetNetworkMask(ifIndexRemote); |
|
278 |
NS_DEBUG("Working with remote address " << addrRemote); |
|
1056 | 279 |
// |
1060 | 280 |
// Now we can fill out the link state advertisement for this link. There |
281 |
// are always two link records; the first is a point-to-point record |
|
282 |
// describing the link and the second is a stub network record with the |
|
283 |
// network number. |
|
1056 | 284 |
// |
285 |
StaticRouterLSA *pLSA = new StaticRouterLSA; |
|
286 |
pLSA->m_linkStateId = m_routerId; |
|
287 |
pLSA->m_advertisingRtr = m_routerId; |
|
288 |
||
289 |
StaticRouterLinkRecord *plr = new StaticRouterLinkRecord; |
|
290 |
plr->m_linkType = StaticRouterLinkRecord::PointToPoint; |
|
291 |
plr->m_linkId = rtrIdRemote; |
|
292 |
plr->m_linkData = addrLocal; |
|
293 |
pLSA->AddLinkRecord(plr); |
|
294 |
plr = 0; |
|
295 |
||
296 |
plr = new StaticRouterLinkRecord; |
|
297 |
plr->m_linkType = StaticRouterLinkRecord::StubNetwork; |
|
298 |
plr->m_linkId = addrRemote; |
|
299 |
plr->m_linkData.Set(maskRemote.GetHostOrder()); // Frown |
|
300 |
pLSA->AddLinkRecord(plr); |
|
301 |
plr = 0; |
|
302 |
||
303 |
m_LSAs.push_back (pLSA); |
|
304 |
NS_DEBUG(*pLSA); |
|
1048 | 305 |
} |
306 |
||
1056 | 307 |
return m_LSAs.size (); |
1048 | 308 |
} |
309 |
||
1061
007ef746ec4d
made GetNumLSAs cheap, added DiscoverLSAs as expensive call.
Craig Dowell <craigdo@ee.washington.edu>
parents:
1060
diff
changeset
|
310 |
uint32_t |
007ef746ec4d
made GetNumLSAs cheap, added DiscoverLSAs as expensive call.
Craig Dowell <craigdo@ee.washington.edu>
parents:
1060
diff
changeset
|
311 |
StaticRouter::GetNumLSAs (void) |
007ef746ec4d
made GetNumLSAs cheap, added DiscoverLSAs as expensive call.
Craig Dowell <craigdo@ee.washington.edu>
parents:
1060
diff
changeset
|
312 |
{ |
007ef746ec4d
made GetNumLSAs cheap, added DiscoverLSAs as expensive call.
Craig Dowell <craigdo@ee.washington.edu>
parents:
1060
diff
changeset
|
313 |
NS_DEBUG("StaticRouter::GetNumLSAs ()"); |
007ef746ec4d
made GetNumLSAs cheap, added DiscoverLSAs as expensive call.
Craig Dowell <craigdo@ee.washington.edu>
parents:
1060
diff
changeset
|
314 |
return m_LSAs.size (); |
007ef746ec4d
made GetNumLSAs cheap, added DiscoverLSAs as expensive call.
Craig Dowell <craigdo@ee.washington.edu>
parents:
1060
diff
changeset
|
315 |
} |
007ef746ec4d
made GetNumLSAs cheap, added DiscoverLSAs as expensive call.
Craig Dowell <craigdo@ee.washington.edu>
parents:
1060
diff
changeset
|
316 |
|
1060 | 317 |
// |
318 |
// Get the nth link state advertisement from this router. |
|
319 |
// |
|
1048 | 320 |
bool |
321 |
StaticRouter::GetLSA (uint32_t n, StaticRouterLSA &lsa) |
|
322 |
{ |
|
1056 | 323 |
NS_ASSERT_MSG(lsa.IsEmpty(), "Must pass empty LSA"); |
1060 | 324 |
// |
325 |
// All of the work was done in GetNumLSAs. All we have to do here is to |
|
326 |
// walk the list of link state advertisements created there and return the |
|
327 |
// one the client is interested in. |
|
328 |
// |
|
1056 | 329 |
ListOfLSAs_t::iterator i = m_LSAs.begin (); |
330 |
uint32_t j = 0; |
|
331 |
||
332 |
for (; i != m_LSAs.end (); i++, j++) |
|
333 |
{ |
|
334 |
if (j == n) |
|
335 |
{ |
|
336 |
StaticRouterLSA *p = *i; |
|
337 |
lsa = *p; |
|
338 |
return true; |
|
339 |
} |
|
340 |
} |
|
1060 | 341 |
|
1048 | 342 |
return false; |
343 |
} |
|
344 |
||
1060 | 345 |
// |
346 |
// Link through the given channel and find the net device that's on the |
|
347 |
// other end. This only makes sense with a point-to-point channel. |
|
348 |
// |
|
1048 | 349 |
Ptr<NetDevice> |
350 |
StaticRouter::GetAdjacent(Ptr<NetDevice> nd, Ptr<Channel> ch) |
|
351 |
{ |
|
352 |
// |
|
353 |
// Double-check that channel agrees with device that it's a point-to-point |
|
354 |
// |
|
355 |
NS_ASSERT(ch->GetType () == Channel::PointToPoint); |
|
356 |
||
357 |
uint32_t nDevices = ch->GetNDevices(); |
|
358 |
NS_ASSERT_MSG(nDevices == 2, |
|
359 |
"Point to point channel with other than two devices is not expected"); |
|
360 |
// |
|
361 |
// This is a point to point channel with two endpoints. Get both of them. |
|
362 |
// |
|
363 |
Ptr<NetDevice> nd1 = ch->GetDevice(0); |
|
364 |
Ptr<NetDevice> nd2 = ch->GetDevice(1); |
|
365 |
// |
|
366 |
// One of the endpoints is going to be "us" -- that is the net device attached |
|
367 |
// to the node on which we're running -- i.e., "nd". The other endpoint (the |
|
368 |
// one to which we are connected via the channel) is the adjacent router. |
|
369 |
// |
|
370 |
if (nd1 == nd) |
|
371 |
{ |
|
372 |
return nd2; |
|
373 |
} |
|
374 |
else if (nd2 == nd) |
|
375 |
{ |
|
376 |
return nd1; |
|
377 |
} |
|
378 |
else |
|
379 |
{ |
|
380 |
NS_ASSERT_MSG(0, |
|
381 |
"Neither channel endpoint thinks it is connected to this net device"); |
|
382 |
return 0; |
|
383 |
} |
|
384 |
} |
|
385 |
||
1060 | 386 |
// |
387 |
// Given a node and a net device, find the IPV4 interface index that |
|
388 |
// corresponds to that net device. |
|
389 |
// |
|
1050 | 390 |
uint32_t |
391 |
StaticRouter::FindIfIndexForDevice(Ptr<Node> node, Ptr<NetDevice> nd) |
|
392 |
{ |
|
393 |
Ptr<Ipv4> ipv4 = node->QueryInterface<Ipv4> (Ipv4::iid); |
|
394 |
NS_ASSERT_MSG(ipv4, "QI for <Ipv4> interface failed"); |
|
395 |
for (uint32_t i = 0; i < ipv4->GetNInterfaces(); ++i ) |
|
396 |
{ |
|
397 |
if (ipv4->GetNetDevice(i) == nd) |
|
398 |
{ |
|
399 |
return i; |
|
400 |
} |
|
401 |
} |
|
402 |
||
403 |
NS_ASSERT_MSG(0, "Cannot find interface for device"); |
|
404 |
return 0; |
|
405 |
} |
|
406 |
||
1028
56460b160cef
beginnings of static routing
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
407 |
} // namespace ns3 |