author | Josh Pelkey <jpelkey@gatech.edu> |
Thu, 07 Jan 2010 19:35:39 -0500 | |
changeset 5899 | a46168c7f4a2 |
parent 5898 | 408970e134cb |
child 5910 | 681058254595 |
permissions | -rw-r--r-- |
5224 | 1 |
/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */ |
2 |
/* |
|
3 |
* Copyright (c) 2009 The Georgia Institute of Technology |
|
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 |
* Authors: Josh Pelkey <jpelkey@gatech.edu> |
|
19 |
*/ |
|
20 |
||
21 |
#include <queue> |
|
22 |
||
23 |
#include "ns3/log.h" |
|
24 |
#include "ns3/abort.h" |
|
25 |
#include "ns3/ipv4-list-routing.h" |
|
26 |
||
27 |
#include "ipv4-nix-vector-routing.h" |
|
28 |
||
29 |
NS_LOG_COMPONENT_DEFINE ("Ipv4NixVectorRouting"); |
|
30 |
||
31 |
namespace ns3 { |
|
32 |
||
33 |
NS_OBJECT_ENSURE_REGISTERED (Ipv4NixVectorRouting); |
|
34 |
||
35 |
TypeId |
|
36 |
Ipv4NixVectorRouting::GetTypeId (void) |
|
37 |
{ |
|
38 |
static TypeId tid = TypeId ("ns3::Ipv4NixVectorRouting") |
|
39 |
.SetParent<Ipv4RoutingProtocol> () |
|
40 |
.AddConstructor<Ipv4NixVectorRouting> () |
|
41 |
; |
|
42 |
return tid; |
|
43 |
} |
|
44 |
||
45 |
Ipv4NixVectorRouting::Ipv4NixVectorRouting () |
|
46 |
:m_totalNeighbors (0) |
|
47 |
{ |
|
48 |
NS_LOG_FUNCTION_NOARGS (); |
|
49 |
} |
|
50 |
||
51 |
Ipv4NixVectorRouting::~Ipv4NixVectorRouting () |
|
52 |
{ |
|
53 |
NS_LOG_FUNCTION_NOARGS (); |
|
54 |
} |
|
55 |
||
56 |
void |
|
57 |
Ipv4NixVectorRouting::SetIpv4 (Ptr<Ipv4> ipv4) |
|
58 |
{ |
|
59 |
NS_ASSERT (ipv4 != 0); |
|
60 |
NS_ASSERT (m_ipv4 == 0); |
|
61 |
NS_LOG_DEBUG ("Created Ipv4NixVectorProtocol"); |
|
62 |
||
63 |
m_ipv4 = ipv4; |
|
64 |
} |
|
65 |
||
66 |
void |
|
67 |
Ipv4NixVectorRouting::DoDispose () |
|
68 |
{ |
|
69 |
NS_LOG_FUNCTION_NOARGS (); |
|
70 |
||
71 |
m_node = 0; |
|
72 |
m_ipv4 = 0; |
|
73 |
||
74 |
Ipv4RoutingProtocol::DoDispose (); |
|
75 |
} |
|
76 |
||
77 |
||
78 |
void |
|
79 |
Ipv4NixVectorRouting::SetNode (Ptr<Node> node) |
|
80 |
{ |
|
81 |
NS_LOG_FUNCTION_NOARGS (); |
|
82 |
||
83 |
m_node = node; |
|
84 |
} |
|
85 |
||
86 |
void |
|
87 |
Ipv4NixVectorRouting::FlushGlobalNixRoutingCache () |
|
88 |
{ |
|
89 |
NS_LOG_FUNCTION_NOARGS (); |
|
90 |
NodeList::Iterator listEnd = NodeList::End (); |
|
91 |
for (NodeList::Iterator i = NodeList::Begin (); i != listEnd; i++) |
|
92 |
{ |
|
93 |
Ptr<Node> node = *i; |
|
94 |
Ptr<Ipv4NixVectorRouting> rp = node->GetObject<Ipv4NixVectorRouting> (); |
|
95 |
if (!rp) |
|
96 |
{ |
|
97 |
continue; |
|
98 |
} |
|
99 |
NS_LOG_LOGIC ("Flushing Nix caches."); |
|
100 |
rp->FlushNixCache (); |
|
101 |
rp->FlushIpv4RouteCache (); |
|
102 |
} |
|
103 |
} |
|
104 |
||
105 |
void |
|
106 |
Ipv4NixVectorRouting::FlushNixCache () |
|
107 |
{ |
|
108 |
NS_LOG_FUNCTION_NOARGS (); |
|
109 |
m_nixCache.clear (); |
|
110 |
} |
|
111 |
||
112 |
void |
|
113 |
Ipv4NixVectorRouting::FlushIpv4RouteCache () |
|
114 |
{ |
|
115 |
NS_LOG_FUNCTION_NOARGS (); |
|
116 |
m_ipv4RouteCache.clear (); |
|
117 |
} |
|
118 |
||
119 |
Ptr<NixVector> |
|
5899
a46168c7f4a2
Forgot code freeze. Revert nix-vector bug fix for bug 779
Josh Pelkey <jpelkey@gatech.edu>
parents:
5898
diff
changeset
|
120 |
Ipv4NixVectorRouting::GetNixVector (Ptr<Node> source, Ipv4Address dest) |
5224 | 121 |
{ |
122 |
NS_LOG_FUNCTION_NOARGS (); |
|
123 |
||
124 |
Ptr<NixVector> nixVector = CreateObject<NixVector> (); |
|
125 |
||
126 |
// not in cache, must build the nix vector |
|
127 |
// First, we have to figure out the nodes |
|
128 |
// associated with these IPs |
|
129 |
Ptr<Node> destNode = GetNodeByIp (dest); |
|
130 |
if (destNode == 0) |
|
131 |
{ |
|
132 |
NS_LOG_ERROR ("No routing path exists"); |
|
133 |
return 0; |
|
134 |
} |
|
135 |
||
136 |
// if source == dest, then we have a special case |
|
137 |
// because the node is sending to itself. have to |
|
138 |
// build the nix vector a little differently |
|
139 |
if (source == destNode) |
|
140 |
{ |
|
141 |
BuildNixVectorLocal(nixVector); |
|
142 |
return nixVector; |
|
143 |
} |
|
144 |
else |
|
145 |
{ |
|
146 |
// otherwise proceed as normal |
|
147 |
// and build the nix vector |
|
148 |
std::vector< Ptr<Node> > parentVector; |
|
5899
a46168c7f4a2
Forgot code freeze. Revert nix-vector bug fix for bug 779
Josh Pelkey <jpelkey@gatech.edu>
parents:
5898
diff
changeset
|
149 |
BFS (NodeList::GetNNodes (), source, destNode, parentVector); |
5224 | 150 |
|
151 |
if (BuildNixVector (parentVector, source->GetId (), destNode->GetId (), nixVector)) |
|
152 |
{ |
|
153 |
return nixVector; |
|
154 |
} |
|
155 |
else |
|
156 |
{ |
|
157 |
NS_LOG_ERROR ("No routing path exists"); |
|
158 |
return 0; |
|
159 |
} |
|
160 |
} |
|
161 |
} |
|
162 |
||
163 |
Ptr<NixVector> |
|
164 |
Ipv4NixVectorRouting::GetNixVectorInCache (Ipv4Address address) |
|
165 |
{ |
|
166 |
NS_LOG_FUNCTION_NOARGS (); |
|
167 |
||
168 |
NixMap_t::iterator iter = m_nixCache.find (address); |
|
169 |
if (iter != m_nixCache.end ()) |
|
170 |
{ |
|
171 |
NS_LOG_LOGIC ("Found Nix-vector in cache."); |
|
172 |
return iter->second; |
|
173 |
} |
|
174 |
||
175 |
// not in cache |
|
176 |
return 0; |
|
177 |
} |
|
178 |
||
179 |
Ptr<Ipv4Route> |
|
180 |
Ipv4NixVectorRouting::GetIpv4RouteInCache (Ipv4Address address) |
|
181 |
{ |
|
182 |
NS_LOG_FUNCTION_NOARGS (); |
|
183 |
||
184 |
Ipv4RouteMap_t::iterator iter = m_ipv4RouteCache.find (address); |
|
185 |
if (iter != m_ipv4RouteCache.end ()) |
|
186 |
{ |
|
187 |
NS_LOG_LOGIC ("Found Ipv4Route in cache."); |
|
188 |
return iter->second; |
|
189 |
} |
|
190 |
||
191 |
// not in cache |
|
192 |
return 0; |
|
193 |
} |
|
194 |
||
195 |
bool |
|
196 |
Ipv4NixVectorRouting::BuildNixVectorLocal (Ptr<NixVector> nixVector) |
|
197 |
{ |
|
198 |
NS_LOG_FUNCTION_NOARGS (); |
|
199 |
||
200 |
uint32_t numberOfDevices = m_node->GetNDevices (); |
|
201 |
||
202 |
// here we are building a nix vector to |
|
203 |
// ourself, so we need to find the loopback |
|
204 |
// interface and add that to the nix vector |
|
205 |
Ipv4Address loopback ("127.0.0.1"); |
|
206 |
for (uint32_t i = 0; i < numberOfDevices; i++) |
|
207 |
{ |
|
208 |
uint32_t interfaceIndex = (m_ipv4)->GetInterfaceForDevice(m_node->GetDevice(i)); |
|
209 |
Ipv4InterfaceAddress ifAddr = m_ipv4->GetAddress (interfaceIndex, 0); |
|
210 |
if (ifAddr.GetLocal() == loopback) |
|
211 |
{ |
|
212 |
NS_LOG_LOGIC ("Adding loopback to nix."); |
|
213 |
NS_LOG_LOGIC ("Adding Nix: " << i << " with " << nixVector->BitCount (numberOfDevices) |
|
214 |
<< " bits, for node " << m_node->GetId()); |
|
215 |
nixVector->AddNeighborIndex (i, nixVector->BitCount (numberOfDevices)); |
|
216 |
return true; |
|
217 |
} |
|
218 |
} |
|
219 |
return false; |
|
220 |
} |
|
221 |
||
222 |
bool |
|
223 |
Ipv4NixVectorRouting::BuildNixVector (const std::vector< Ptr<Node> > & parentVector, uint32_t source, uint32_t dest, Ptr<NixVector> nixVector) |
|
224 |
{ |
|
225 |
NS_LOG_FUNCTION_NOARGS (); |
|
226 |
||
227 |
if (source == dest) |
|
228 |
{ |
|
229 |
return true; |
|
230 |
} |
|
231 |
||
232 |
if (parentVector.at (dest) == 0) |
|
233 |
{ |
|
234 |
return false; |
|
235 |
} |
|
236 |
||
237 |
Ptr<Node> parentNode = parentVector.at (dest); |
|
238 |
||
239 |
uint32_t numberOfDevices = parentNode->GetNDevices (); |
|
240 |
uint32_t destId = 0; |
|
241 |
uint32_t totalNeighbors = 0; |
|
242 |
||
243 |
// scan through the net devices on the parent node |
|
244 |
// and then look at the nodes adjacent to them |
|
245 |
for (uint32_t i = 0; i < numberOfDevices; i++) |
|
246 |
{ |
|
247 |
// Get a net device from the node |
|
248 |
// as well as the channel, and figure |
|
249 |
// out the adjacent net devices |
|
250 |
Ptr<NetDevice> localNetDevice = parentNode->GetDevice (i); |
|
251 |
if (localNetDevice->IsBridge ()) |
|
252 |
{ |
|
253 |
continue; |
|
254 |
} |
|
255 |
Ptr<Channel> channel = localNetDevice->GetChannel (); |
|
256 |
if (channel == 0) |
|
257 |
{ |
|
258 |
continue; |
|
259 |
} |
|
260 |
||
261 |
// this function takes in the local net dev, and channnel, and |
|
262 |
// writes to the netDeviceContainer the adjacent net devs |
|
263 |
NetDeviceContainer netDeviceContainer; |
|
264 |
GetAdjacentNetDevices (localNetDevice, channel, netDeviceContainer); |
|
265 |
||
266 |
// Finally we can get the adjacent nodes |
|
267 |
// and scan through them. If we find the |
|
268 |
// node that matches "dest" then we can add |
|
269 |
// the index to the nix vector. |
|
270 |
// the index corresponds to the neighbor index |
|
271 |
uint32_t offset = 0; |
|
272 |
for (NetDeviceContainer::Iterator iter = netDeviceContainer.Begin (); iter != netDeviceContainer.End (); iter++) |
|
273 |
{ |
|
274 |
Ptr<Node> remoteNode = (*iter)->GetNode (); |
|
275 |
||
276 |
if (remoteNode->GetId () == dest) |
|
277 |
{ |
|
278 |
destId = totalNeighbors + offset; |
|
279 |
} |
|
280 |
offset += 1; |
|
281 |
} |
|
282 |
||
283 |
totalNeighbors += netDeviceContainer.GetN (); |
|
284 |
} |
|
285 |
NS_LOG_LOGIC ("Adding Nix: " << destId << " with " |
|
286 |
<< nixVector->BitCount (totalNeighbors) << " bits, for node " << parentNode->GetId()); |
|
287 |
nixVector->AddNeighborIndex (destId, nixVector->BitCount (totalNeighbors)); |
|
288 |
||
289 |
// recurse through parent vector, grabbing the path |
|
290 |
// and building the nix vector |
|
291 |
BuildNixVector (parentVector, source, (parentVector.at (dest))->GetId (), nixVector); |
|
292 |
return true; |
|
293 |
} |
|
294 |
||
295 |
void |
|
296 |
Ipv4NixVectorRouting::GetAdjacentNetDevices (Ptr<NetDevice> netDevice, Ptr<Channel> channel, NetDeviceContainer & netDeviceContainer) |
|
297 |
{ |
|
298 |
NS_LOG_FUNCTION_NOARGS (); |
|
299 |
||
300 |
for (uint32_t i = 0; i < channel->GetNDevices (); i++) |
|
301 |
{ |
|
302 |
Ptr<NetDevice> remoteDevice = channel->GetDevice (i); |
|
303 |
if (remoteDevice != netDevice) |
|
304 |
{ |
|
305 |
Ptr<BridgeNetDevice> bd = NetDeviceIsBridged (remoteDevice); |
|
306 |
// we have a bridged device, we need to add all |
|
307 |
// bridged devices |
|
308 |
if (bd) |
|
309 |
{ |
|
310 |
NS_LOG_LOGIC ("Looking through bridge ports of bridge net device " << bd); |
|
311 |
for (uint32_t j = 0; j < bd->GetNBridgePorts (); ++j) |
|
312 |
{ |
|
313 |
Ptr<NetDevice> ndBridged = bd->GetBridgePort (j); |
|
314 |
if (ndBridged == remoteDevice) |
|
315 |
{ |
|
316 |
NS_LOG_LOGIC ("That bridge port is me, don't walk backward"); |
|
317 |
continue; |
|
318 |
} |
|
319 |
Ptr<Channel> chBridged = ndBridged->GetChannel (); |
|
320 |
if (channel == 0) |
|
321 |
{ |
|
322 |
continue; |
|
323 |
} |
|
324 |
GetAdjacentNetDevices (ndBridged, chBridged, netDeviceContainer); |
|
325 |
} |
|
326 |
} |
|
327 |
else |
|
328 |
{ |
|
329 |
netDeviceContainer.Add (channel->GetDevice (i)); |
|
330 |
} |
|
331 |
} |
|
332 |
} |
|
333 |
} |
|
334 |
||
335 |
Ptr<Node> |
|
336 |
Ipv4NixVectorRouting::GetNodeByIp (Ipv4Address dest) |
|
337 |
{ |
|
338 |
NS_LOG_FUNCTION_NOARGS (); |
|
339 |
||
340 |
NodeContainer allNodes = NodeContainer::GetGlobal (); |
|
341 |
Ptr<Node> destNode; |
|
342 |
||
343 |
for (NodeContainer::Iterator i = allNodes.Begin (); i != allNodes.End (); ++i) |
|
344 |
{ |
|
345 |
Ptr<Node> node = *i; |
|
346 |
Ptr<Ipv4> ipv4 = node->GetObject<Ipv4> (); |
|
347 |
if (ipv4->GetInterfaceForAddress (dest) != -1) |
|
348 |
{ |
|
349 |
destNode = node; |
|
350 |
break; |
|
351 |
} |
|
352 |
} |
|
353 |
||
354 |
if (!destNode) |
|
355 |
{ |
|
356 |
NS_LOG_ERROR ("Couldn't find dest node given the IP" << dest); |
|
357 |
return 0; |
|
358 |
} |
|
359 |
||
360 |
return destNode; |
|
361 |
} |
|
362 |
||
363 |
uint32_t |
|
364 |
Ipv4NixVectorRouting::FindTotalNeighbors () |
|
365 |
{ |
|
366 |
uint32_t numberOfDevices = m_node->GetNDevices (); |
|
367 |
uint32_t totalNeighbors = 0; |
|
368 |
||
369 |
// scan through the net devices on the parent node |
|
370 |
// and then look at the nodes adjacent to them |
|
371 |
for (uint32_t i = 0; i < numberOfDevices; i++) |
|
372 |
{ |
|
373 |
// Get a net device from the node |
|
374 |
// as well as the channel, and figure |
|
375 |
// out the adjacent net devices |
|
376 |
Ptr<NetDevice> localNetDevice = m_node->GetDevice (i); |
|
377 |
Ptr<Channel> channel = localNetDevice->GetChannel (); |
|
378 |
if (channel == 0) |
|
379 |
{ |
|
380 |
continue; |
|
381 |
} |
|
382 |
||
383 |
// this function takes in the local net dev, and channnel, and |
|
384 |
// writes to the netDeviceContainer the adjacent net devs |
|
385 |
NetDeviceContainer netDeviceContainer; |
|
386 |
GetAdjacentNetDevices (localNetDevice, channel, netDeviceContainer); |
|
387 |
||
388 |
totalNeighbors += netDeviceContainer.GetN (); |
|
389 |
} |
|
390 |
||
391 |
return totalNeighbors; |
|
392 |
} |
|
393 |
||
394 |
Ptr<BridgeNetDevice> |
|
395 |
Ipv4NixVectorRouting::NetDeviceIsBridged (Ptr<NetDevice> nd) const |
|
396 |
{ |
|
397 |
NS_LOG_FUNCTION (nd); |
|
398 |
||
399 |
Ptr<Node> node = nd->GetNode (); |
|
400 |
uint32_t nDevices = node->GetNDevices(); |
|
401 |
||
402 |
// |
|
403 |
// There is no bit on a net device that says it is being bridged, so we have |
|
404 |
// to look for bridges on the node to which the device is attached. If we |
|
405 |
// find a bridge, we need to look through its bridge ports (the devices it |
|
406 |
// bridges) to see if we find the device in question. |
|
407 |
// |
|
408 |
for (uint32_t i = 0; i < nDevices; ++i) |
|
409 |
{ |
|
410 |
Ptr<NetDevice> ndTest = node->GetDevice(i); |
|
411 |
NS_LOG_LOGIC ("Examine device " << i << " " << ndTest); |
|
412 |
||
413 |
if (ndTest->IsBridge ()) |
|
414 |
{ |
|
415 |
NS_LOG_LOGIC ("device " << i << " is a bridge net device"); |
|
416 |
Ptr<BridgeNetDevice> bnd = ndTest->GetObject<BridgeNetDevice> (); |
|
417 |
NS_ABORT_MSG_UNLESS (bnd, "Ipv4NixVectorRouting::NetDeviceIsBridged (): GetObject for <BridgeNetDevice> failed"); |
|
418 |
||
419 |
for (uint32_t j = 0; j < bnd->GetNBridgePorts (); ++j) |
|
420 |
{ |
|
421 |
NS_LOG_LOGIC ("Examine bridge port " << j << " " << bnd->GetBridgePort (j)); |
|
422 |
if (bnd->GetBridgePort (j) == nd) |
|
423 |
{ |
|
424 |
NS_LOG_LOGIC ("Net device " << nd << " is bridged by " << bnd); |
|
425 |
return bnd; |
|
426 |
} |
|
427 |
} |
|
428 |
} |
|
429 |
} |
|
430 |
NS_LOG_LOGIC ("Net device " << nd << " is not bridged"); |
|
431 |
return 0; |
|
432 |
} |
|
433 |
||
434 |
uint32_t |
|
435 |
Ipv4NixVectorRouting::FindNetDeviceForNixIndex (uint32_t nodeIndex, Ipv4Address & gatewayIp) |
|
436 |
{ |
|
437 |
uint32_t numberOfDevices = m_node->GetNDevices (); |
|
438 |
uint32_t index = 0; |
|
439 |
uint32_t totalNeighbors = 0; |
|
440 |
||
441 |
// scan through the net devices on the parent node |
|
442 |
// and then look at the nodes adjacent to them |
|
443 |
for (uint32_t i = 0; i < numberOfDevices; i++) |
|
444 |
{ |
|
445 |
// Get a net device from the node |
|
446 |
// as well as the channel, and figure |
|
447 |
// out the adjacent net devices |
|
448 |
Ptr<NetDevice> localNetDevice = m_node->GetDevice (i); |
|
449 |
Ptr<Channel> channel = localNetDevice->GetChannel (); |
|
450 |
if (channel == 0) |
|
451 |
{ |
|
452 |
continue; |
|
453 |
} |
|
454 |
||
455 |
// this function takes in the local net dev, and channnel, and |
|
456 |
// writes to the netDeviceContainer the adjacent net devs |
|
457 |
NetDeviceContainer netDeviceContainer; |
|
458 |
GetAdjacentNetDevices (localNetDevice, channel, netDeviceContainer); |
|
459 |
||
460 |
// check how many neighbors we have |
|
461 |
if (nodeIndex < (totalNeighbors + netDeviceContainer.GetN ())) |
|
462 |
{ |
|
463 |
// found the proper net device |
|
464 |
index = i; |
|
465 |
Ptr<NetDevice> gatewayDevice = netDeviceContainer.Get (nodeIndex-totalNeighbors); |
|
466 |
Ptr<Node> gatewayNode = gatewayDevice->GetNode (); |
|
467 |
Ptr<Ipv4> ipv4 = gatewayNode->GetObject<Ipv4> (); |
|
468 |
||
469 |
uint32_t interfaceIndex = (ipv4)->GetInterfaceForDevice(gatewayDevice); |
|
470 |
Ipv4InterfaceAddress ifAddr = ipv4->GetAddress (interfaceIndex, 0); |
|
471 |
gatewayIp = ifAddr.GetLocal (); |
|
472 |
break; |
|
473 |
} |
|
474 |
totalNeighbors += netDeviceContainer.GetN (); |
|
475 |
} |
|
476 |
||
477 |
return index; |
|
478 |
} |
|
479 |
||
480 |
Ptr<Ipv4Route> |
|
5856
7fd20c798a7d
bug 742: Implementation of SO_BINDTODEVICE
Antti Mäkelä <zarhan@cc.hut.fi>
parents:
5224
diff
changeset
|
481 |
Ipv4NixVectorRouting::RouteOutput (Ptr<Packet> p, const Ipv4Header &header, Ptr<NetDevice> oif, Socket::SocketErrno &sockerr) |
5224 | 482 |
{ |
483 |
NS_LOG_FUNCTION_NOARGS (); |
|
484 |
Ptr<Ipv4Route> rtentry; |
|
485 |
Ptr<NixVector> nixVectorInCache; |
|
486 |
Ptr<NixVector> nixVectorForPacket; |
|
487 |
||
488 |
NS_LOG_DEBUG ("Dest IP from header: " << header.GetDestination ()); |
|
489 |
// check if cache |
|
490 |
nixVectorInCache = GetNixVectorInCache(header.GetDestination ()); |
|
491 |
||
492 |
// not in cache |
|
493 |
if (!nixVectorInCache) |
|
494 |
{ |
|
495 |
NS_LOG_LOGIC ("Nix-vector not in cache, build: "); |
|
496 |
// Build the nix-vector, given this node and the |
|
497 |
// dest IP address |
|
5899
a46168c7f4a2
Forgot code freeze. Revert nix-vector bug fix for bug 779
Josh Pelkey <jpelkey@gatech.edu>
parents:
5898
diff
changeset
|
498 |
nixVectorInCache = GetNixVector (m_node, header.GetDestination ()); |
5224 | 499 |
|
500 |
// cache it |
|
501 |
m_nixCache.insert (NixMap_t::value_type (header.GetDestination (), nixVectorInCache)); |
|
502 |
} |
|
503 |
||
504 |
// path exists |
|
505 |
if (nixVectorInCache) |
|
506 |
{ |
|
507 |
NS_LOG_LOGIC ("Nix-vector contents: " << *nixVectorInCache); |
|
508 |
||
509 |
// create a new nix vector to be used, |
|
510 |
// we want to keep the cached version clean |
|
511 |
nixVectorForPacket = CreateObject<NixVector> (); |
|
512 |
nixVectorForPacket = nixVectorInCache->Copy(); |
|
513 |
||
514 |
// Get the interface number that we go out of, by extracting |
|
515 |
// from the nix-vector |
|
516 |
if (m_totalNeighbors == 0) |
|
517 |
{ |
|
518 |
m_totalNeighbors = FindTotalNeighbors (); |
|
519 |
} |
|
520 |
||
521 |
// Get the interface number that we go out of, by extracting |
|
522 |
// from the nix-vector |
|
523 |
uint32_t numberOfBits = nixVectorForPacket->BitCount (m_totalNeighbors); |
|
524 |
uint32_t nodeIndex = nixVectorForPacket->ExtractNeighborIndex (numberOfBits); |
|
525 |
||
5899
a46168c7f4a2
Forgot code freeze. Revert nix-vector bug fix for bug 779
Josh Pelkey <jpelkey@gatech.edu>
parents:
5898
diff
changeset
|
526 |
// Possibly search here in a cache for this node index |
a46168c7f4a2
Forgot code freeze. Revert nix-vector bug fix for bug 779
Josh Pelkey <jpelkey@gatech.edu>
parents:
5898
diff
changeset
|
527 |
// and look for a Ipv4Route. If we have it, don't |
a46168c7f4a2
Forgot code freeze. Revert nix-vector bug fix for bug 779
Josh Pelkey <jpelkey@gatech.edu>
parents:
5898
diff
changeset
|
528 |
// need to do the next 3 lines. |
5224 | 529 |
rtentry = GetIpv4RouteInCache (header.GetDestination ()); |
5899
a46168c7f4a2
Forgot code freeze. Revert nix-vector bug fix for bug 779
Josh Pelkey <jpelkey@gatech.edu>
parents:
5898
diff
changeset
|
530 |
// not in cache |
a46168c7f4a2
Forgot code freeze. Revert nix-vector bug fix for bug 779
Josh Pelkey <jpelkey@gatech.edu>
parents:
5898
diff
changeset
|
531 |
if (!rtentry) |
5224 | 532 |
{ |
533 |
NS_LOG_LOGIC ("Ipv4Route not in cache, build: "); |
|
534 |
Ipv4Address gatewayIp; |
|
535 |
uint32_t index = FindNetDeviceForNixIndex (nodeIndex, gatewayIp); |
|
536 |
||
5899
a46168c7f4a2
Forgot code freeze. Revert nix-vector bug fix for bug 779
Josh Pelkey <jpelkey@gatech.edu>
parents:
5898
diff
changeset
|
537 |
uint32_t interfaceIndex = (m_ipv4)->GetInterfaceForDevice(m_node->GetDevice(index)); |
5224 | 538 |
Ipv4InterfaceAddress ifAddr = m_ipv4->GetAddress (interfaceIndex, 0); |
539 |
||
540 |
// start filling in the Ipv4Route info |
|
541 |
rtentry = Create<Ipv4Route> (); |
|
542 |
rtentry->SetSource (ifAddr.GetLocal ()); |
|
543 |
||
544 |
rtentry->SetGateway (gatewayIp); |
|
545 |
rtentry->SetDestination (header.GetDestination ()); |
|
5899
a46168c7f4a2
Forgot code freeze. Revert nix-vector bug fix for bug 779
Josh Pelkey <jpelkey@gatech.edu>
parents:
5898
diff
changeset
|
546 |
rtentry->SetOutputDevice (m_ipv4->GetNetDevice (interfaceIndex)); |
5224 | 547 |
|
548 |
sockerr = Socket::ERROR_NOTERROR; |
|
549 |
||
550 |
// add rtentry to cache |
|
551 |
m_ipv4RouteCache.insert(Ipv4RouteMap_t::value_type(header.GetDestination (), rtentry)); |
|
552 |
} |
|
553 |
||
554 |
NS_LOG_LOGIC ("Nix-vector contents: " << *nixVectorInCache << " : Remaining bits: " << nixVectorForPacket->GetRemainingBits()); |
|
555 |
||
556 |
// Add nix-vector in the packet class |
|
557 |
// make sure the packet exists first |
|
558 |
if (p) |
|
559 |
{ |
|
560 |
NS_LOG_LOGIC ("Adding Nix-vector to packet: " << *nixVectorForPacket); |
|
561 |
p->SetNixVector (nixVectorForPacket); |
|
562 |
} |
|
563 |
} |
|
564 |
else // path doesn't exist |
|
565 |
{ |
|
566 |
NS_LOG_ERROR ("No path to the dest: " << header.GetDestination ()); |
|
567 |
sockerr = Socket::ERROR_NOROUTETOHOST; |
|
568 |
} |
|
569 |
||
570 |
return rtentry; |
|
571 |
} |
|
572 |
||
573 |
bool |
|
574 |
Ipv4NixVectorRouting::RouteInput (Ptr<const Packet> p, const Ipv4Header &header, Ptr<const NetDevice> idev, |
|
575 |
UnicastForwardCallback ucb, MulticastForwardCallback mcb, |
|
576 |
LocalDeliverCallback lcb, ErrorCallback ecb) |
|
577 |
{ |
|
578 |
NS_LOG_FUNCTION_NOARGS (); |
|
579 |
||
580 |
Ptr<Ipv4Route> rtentry; |
|
581 |
||
582 |
// Get the nix-vector from the packet |
|
583 |
Ptr<NixVector> nixVector = p->GetNixVector(); |
|
584 |
||
5899
a46168c7f4a2
Forgot code freeze. Revert nix-vector bug fix for bug 779
Josh Pelkey <jpelkey@gatech.edu>
parents:
5898
diff
changeset
|
585 |
// make sure it exists, if not something |
a46168c7f4a2
Forgot code freeze. Revert nix-vector bug fix for bug 779
Josh Pelkey <jpelkey@gatech.edu>
parents:
5898
diff
changeset
|
586 |
// went wrong |
a46168c7f4a2
Forgot code freeze. Revert nix-vector bug fix for bug 779
Josh Pelkey <jpelkey@gatech.edu>
parents:
5898
diff
changeset
|
587 |
if (!nixVector) |
5898
408970e134cb
Fix bug 779: NixVectorRouting ignores specified outgoing interface in RouteOutput
Josh Pelkey <jpelkey@gatech.edu>
parents:
5856
diff
changeset
|
588 |
{ |
5899
a46168c7f4a2
Forgot code freeze. Revert nix-vector bug fix for bug 779
Josh Pelkey <jpelkey@gatech.edu>
parents:
5898
diff
changeset
|
589 |
NS_LOG_ERROR ("Nix-vector wasn't in the packet! Rebuild."); |
a46168c7f4a2
Forgot code freeze. Revert nix-vector bug fix for bug 779
Josh Pelkey <jpelkey@gatech.edu>
parents:
5898
diff
changeset
|
590 |
|
a46168c7f4a2
Forgot code freeze. Revert nix-vector bug fix for bug 779
Josh Pelkey <jpelkey@gatech.edu>
parents:
5898
diff
changeset
|
591 |
Ptr<NixVector> nixVectorInCache; |
a46168c7f4a2
Forgot code freeze. Revert nix-vector bug fix for bug 779
Josh Pelkey <jpelkey@gatech.edu>
parents:
5898
diff
changeset
|
592 |
|
a46168c7f4a2
Forgot code freeze. Revert nix-vector bug fix for bug 779
Josh Pelkey <jpelkey@gatech.edu>
parents:
5898
diff
changeset
|
593 |
NS_LOG_DEBUG ("Dest IP from header: " << header.GetDestination ()); |
a46168c7f4a2
Forgot code freeze. Revert nix-vector bug fix for bug 779
Josh Pelkey <jpelkey@gatech.edu>
parents:
5898
diff
changeset
|
594 |
|
a46168c7f4a2
Forgot code freeze. Revert nix-vector bug fix for bug 779
Josh Pelkey <jpelkey@gatech.edu>
parents:
5898
diff
changeset
|
595 |
// check if cache |
a46168c7f4a2
Forgot code freeze. Revert nix-vector bug fix for bug 779
Josh Pelkey <jpelkey@gatech.edu>
parents:
5898
diff
changeset
|
596 |
nixVectorInCache = GetNixVectorInCache(header.GetDestination ()); |
a46168c7f4a2
Forgot code freeze. Revert nix-vector bug fix for bug 779
Josh Pelkey <jpelkey@gatech.edu>
parents:
5898
diff
changeset
|
597 |
|
a46168c7f4a2
Forgot code freeze. Revert nix-vector bug fix for bug 779
Josh Pelkey <jpelkey@gatech.edu>
parents:
5898
diff
changeset
|
598 |
// not in cache |
a46168c7f4a2
Forgot code freeze. Revert nix-vector bug fix for bug 779
Josh Pelkey <jpelkey@gatech.edu>
parents:
5898
diff
changeset
|
599 |
if (!nixVectorInCache) |
a46168c7f4a2
Forgot code freeze. Revert nix-vector bug fix for bug 779
Josh Pelkey <jpelkey@gatech.edu>
parents:
5898
diff
changeset
|
600 |
{ |
a46168c7f4a2
Forgot code freeze. Revert nix-vector bug fix for bug 779
Josh Pelkey <jpelkey@gatech.edu>
parents:
5898
diff
changeset
|
601 |
NS_LOG_LOGIC ("RouteInput(): Nix-vector not in cache, build: "); |
a46168c7f4a2
Forgot code freeze. Revert nix-vector bug fix for bug 779
Josh Pelkey <jpelkey@gatech.edu>
parents:
5898
diff
changeset
|
602 |
|
a46168c7f4a2
Forgot code freeze. Revert nix-vector bug fix for bug 779
Josh Pelkey <jpelkey@gatech.edu>
parents:
5898
diff
changeset
|
603 |
// Build the nix-vector, given this node and the |
a46168c7f4a2
Forgot code freeze. Revert nix-vector bug fix for bug 779
Josh Pelkey <jpelkey@gatech.edu>
parents:
5898
diff
changeset
|
604 |
// dest IP address |
a46168c7f4a2
Forgot code freeze. Revert nix-vector bug fix for bug 779
Josh Pelkey <jpelkey@gatech.edu>
parents:
5898
diff
changeset
|
605 |
nixVectorInCache = GetNixVector (m_node, header.GetDestination ()); |
a46168c7f4a2
Forgot code freeze. Revert nix-vector bug fix for bug 779
Josh Pelkey <jpelkey@gatech.edu>
parents:
5898
diff
changeset
|
606 |
} |
a46168c7f4a2
Forgot code freeze. Revert nix-vector bug fix for bug 779
Josh Pelkey <jpelkey@gatech.edu>
parents:
5898
diff
changeset
|
607 |
|
a46168c7f4a2
Forgot code freeze. Revert nix-vector bug fix for bug 779
Josh Pelkey <jpelkey@gatech.edu>
parents:
5898
diff
changeset
|
608 |
// path exists |
a46168c7f4a2
Forgot code freeze. Revert nix-vector bug fix for bug 779
Josh Pelkey <jpelkey@gatech.edu>
parents:
5898
diff
changeset
|
609 |
if (nixVectorInCache) |
a46168c7f4a2
Forgot code freeze. Revert nix-vector bug fix for bug 779
Josh Pelkey <jpelkey@gatech.edu>
parents:
5898
diff
changeset
|
610 |
{ |
a46168c7f4a2
Forgot code freeze. Revert nix-vector bug fix for bug 779
Josh Pelkey <jpelkey@gatech.edu>
parents:
5898
diff
changeset
|
611 |
NS_LOG_LOGIC ("Nix-vector contents: " << *nixVectorInCache); |
a46168c7f4a2
Forgot code freeze. Revert nix-vector bug fix for bug 779
Josh Pelkey <jpelkey@gatech.edu>
parents:
5898
diff
changeset
|
612 |
|
a46168c7f4a2
Forgot code freeze. Revert nix-vector bug fix for bug 779
Josh Pelkey <jpelkey@gatech.edu>
parents:
5898
diff
changeset
|
613 |
// cache it |
a46168c7f4a2
Forgot code freeze. Revert nix-vector bug fix for bug 779
Josh Pelkey <jpelkey@gatech.edu>
parents:
5898
diff
changeset
|
614 |
m_nixCache.insert(NixMap_t::value_type(header.GetDestination (), nixVectorInCache)); |
5224 | 615 |
|
5899
a46168c7f4a2
Forgot code freeze. Revert nix-vector bug fix for bug 779
Josh Pelkey <jpelkey@gatech.edu>
parents:
5898
diff
changeset
|
616 |
// create a new nix vector to be used, |
a46168c7f4a2
Forgot code freeze. Revert nix-vector bug fix for bug 779
Josh Pelkey <jpelkey@gatech.edu>
parents:
5898
diff
changeset
|
617 |
// we want to keep the cached version clean |
a46168c7f4a2
Forgot code freeze. Revert nix-vector bug fix for bug 779
Josh Pelkey <jpelkey@gatech.edu>
parents:
5898
diff
changeset
|
618 |
Ptr<NixVector> nixVectorForPacket; |
a46168c7f4a2
Forgot code freeze. Revert nix-vector bug fix for bug 779
Josh Pelkey <jpelkey@gatech.edu>
parents:
5898
diff
changeset
|
619 |
nixVectorForPacket = CreateObject<NixVector> (); |
a46168c7f4a2
Forgot code freeze. Revert nix-vector bug fix for bug 779
Josh Pelkey <jpelkey@gatech.edu>
parents:
5898
diff
changeset
|
620 |
nixVectorForPacket = nixVectorInCache->Copy(); |
a46168c7f4a2
Forgot code freeze. Revert nix-vector bug fix for bug 779
Josh Pelkey <jpelkey@gatech.edu>
parents:
5898
diff
changeset
|
621 |
|
a46168c7f4a2
Forgot code freeze. Revert nix-vector bug fix for bug 779
Josh Pelkey <jpelkey@gatech.edu>
parents:
5898
diff
changeset
|
622 |
// Get the interface number that we go out of, by extracting |
a46168c7f4a2
Forgot code freeze. Revert nix-vector bug fix for bug 779
Josh Pelkey <jpelkey@gatech.edu>
parents:
5898
diff
changeset
|
623 |
// from the nix-vector |
a46168c7f4a2
Forgot code freeze. Revert nix-vector bug fix for bug 779
Josh Pelkey <jpelkey@gatech.edu>
parents:
5898
diff
changeset
|
624 |
if (m_totalNeighbors == 0) |
a46168c7f4a2
Forgot code freeze. Revert nix-vector bug fix for bug 779
Josh Pelkey <jpelkey@gatech.edu>
parents:
5898
diff
changeset
|
625 |
{ |
a46168c7f4a2
Forgot code freeze. Revert nix-vector bug fix for bug 779
Josh Pelkey <jpelkey@gatech.edu>
parents:
5898
diff
changeset
|
626 |
m_totalNeighbors = FindTotalNeighbors (); |
a46168c7f4a2
Forgot code freeze. Revert nix-vector bug fix for bug 779
Josh Pelkey <jpelkey@gatech.edu>
parents:
5898
diff
changeset
|
627 |
} |
a46168c7f4a2
Forgot code freeze. Revert nix-vector bug fix for bug 779
Josh Pelkey <jpelkey@gatech.edu>
parents:
5898
diff
changeset
|
628 |
uint32_t numberOfBits = nixVectorForPacket->BitCount (m_totalNeighbors); |
a46168c7f4a2
Forgot code freeze. Revert nix-vector bug fix for bug 779
Josh Pelkey <jpelkey@gatech.edu>
parents:
5898
diff
changeset
|
629 |
uint32_t nodeIndex = nixVectorForPacket->ExtractNeighborIndex (numberOfBits); |
a46168c7f4a2
Forgot code freeze. Revert nix-vector bug fix for bug 779
Josh Pelkey <jpelkey@gatech.edu>
parents:
5898
diff
changeset
|
630 |
|
a46168c7f4a2
Forgot code freeze. Revert nix-vector bug fix for bug 779
Josh Pelkey <jpelkey@gatech.edu>
parents:
5898
diff
changeset
|
631 |
rtentry = GetIpv4RouteInCache (header.GetDestination ()); |
a46168c7f4a2
Forgot code freeze. Revert nix-vector bug fix for bug 779
Josh Pelkey <jpelkey@gatech.edu>
parents:
5898
diff
changeset
|
632 |
// not in cache |
a46168c7f4a2
Forgot code freeze. Revert nix-vector bug fix for bug 779
Josh Pelkey <jpelkey@gatech.edu>
parents:
5898
diff
changeset
|
633 |
if (!rtentry) |
a46168c7f4a2
Forgot code freeze. Revert nix-vector bug fix for bug 779
Josh Pelkey <jpelkey@gatech.edu>
parents:
5898
diff
changeset
|
634 |
{ |
a46168c7f4a2
Forgot code freeze. Revert nix-vector bug fix for bug 779
Josh Pelkey <jpelkey@gatech.edu>
parents:
5898
diff
changeset
|
635 |
NS_LOG_LOGIC ("Ipv4Route not in cache, build: "); |
a46168c7f4a2
Forgot code freeze. Revert nix-vector bug fix for bug 779
Josh Pelkey <jpelkey@gatech.edu>
parents:
5898
diff
changeset
|
636 |
Ipv4Address gatewayIp; |
a46168c7f4a2
Forgot code freeze. Revert nix-vector bug fix for bug 779
Josh Pelkey <jpelkey@gatech.edu>
parents:
5898
diff
changeset
|
637 |
uint32_t index = FindNetDeviceForNixIndex (nodeIndex, gatewayIp); |
a46168c7f4a2
Forgot code freeze. Revert nix-vector bug fix for bug 779
Josh Pelkey <jpelkey@gatech.edu>
parents:
5898
diff
changeset
|
638 |
|
a46168c7f4a2
Forgot code freeze. Revert nix-vector bug fix for bug 779
Josh Pelkey <jpelkey@gatech.edu>
parents:
5898
diff
changeset
|
639 |
uint32_t interfaceIndex = (m_ipv4)->GetInterfaceForDevice(m_node->GetDevice(index)); |
a46168c7f4a2
Forgot code freeze. Revert nix-vector bug fix for bug 779
Josh Pelkey <jpelkey@gatech.edu>
parents:
5898
diff
changeset
|
640 |
Ipv4InterfaceAddress ifAddr = m_ipv4->GetAddress (interfaceIndex, 0); |
a46168c7f4a2
Forgot code freeze. Revert nix-vector bug fix for bug 779
Josh Pelkey <jpelkey@gatech.edu>
parents:
5898
diff
changeset
|
641 |
|
a46168c7f4a2
Forgot code freeze. Revert nix-vector bug fix for bug 779
Josh Pelkey <jpelkey@gatech.edu>
parents:
5898
diff
changeset
|
642 |
// start filling in the Ipv4Route info |
a46168c7f4a2
Forgot code freeze. Revert nix-vector bug fix for bug 779
Josh Pelkey <jpelkey@gatech.edu>
parents:
5898
diff
changeset
|
643 |
rtentry = Create<Ipv4Route> (); |
a46168c7f4a2
Forgot code freeze. Revert nix-vector bug fix for bug 779
Josh Pelkey <jpelkey@gatech.edu>
parents:
5898
diff
changeset
|
644 |
rtentry->SetSource (ifAddr.GetLocal ()); |
a46168c7f4a2
Forgot code freeze. Revert nix-vector bug fix for bug 779
Josh Pelkey <jpelkey@gatech.edu>
parents:
5898
diff
changeset
|
645 |
|
a46168c7f4a2
Forgot code freeze. Revert nix-vector bug fix for bug 779
Josh Pelkey <jpelkey@gatech.edu>
parents:
5898
diff
changeset
|
646 |
rtentry->SetGateway (Ipv4Address(gatewayIp)); |
a46168c7f4a2
Forgot code freeze. Revert nix-vector bug fix for bug 779
Josh Pelkey <jpelkey@gatech.edu>
parents:
5898
diff
changeset
|
647 |
rtentry->SetDestination (header.GetDestination ()); |
a46168c7f4a2
Forgot code freeze. Revert nix-vector bug fix for bug 779
Josh Pelkey <jpelkey@gatech.edu>
parents:
5898
diff
changeset
|
648 |
rtentry->SetOutputDevice (m_ipv4->GetNetDevice (interfaceIndex)); |
a46168c7f4a2
Forgot code freeze. Revert nix-vector bug fix for bug 779
Josh Pelkey <jpelkey@gatech.edu>
parents:
5898
diff
changeset
|
649 |
|
a46168c7f4a2
Forgot code freeze. Revert nix-vector bug fix for bug 779
Josh Pelkey <jpelkey@gatech.edu>
parents:
5898
diff
changeset
|
650 |
// add rtentry to cache |
a46168c7f4a2
Forgot code freeze. Revert nix-vector bug fix for bug 779
Josh Pelkey <jpelkey@gatech.edu>
parents:
5898
diff
changeset
|
651 |
m_ipv4RouteCache.insert(Ipv4RouteMap_t::value_type(header.GetDestination (), rtentry)); |
a46168c7f4a2
Forgot code freeze. Revert nix-vector bug fix for bug 779
Josh Pelkey <jpelkey@gatech.edu>
parents:
5898
diff
changeset
|
652 |
} |
5224 | 653 |
|
5899
a46168c7f4a2
Forgot code freeze. Revert nix-vector bug fix for bug 779
Josh Pelkey <jpelkey@gatech.edu>
parents:
5898
diff
changeset
|
654 |
NS_LOG_LOGIC ("Nix-vector contents: " << *nixVectorInCache << " : Remaining bits: " << nixVectorForPacket->GetRemainingBits()); |
a46168c7f4a2
Forgot code freeze. Revert nix-vector bug fix for bug 779
Josh Pelkey <jpelkey@gatech.edu>
parents:
5898
diff
changeset
|
655 |
|
a46168c7f4a2
Forgot code freeze. Revert nix-vector bug fix for bug 779
Josh Pelkey <jpelkey@gatech.edu>
parents:
5898
diff
changeset
|
656 |
// Add nix-vector in the packet class |
a46168c7f4a2
Forgot code freeze. Revert nix-vector bug fix for bug 779
Josh Pelkey <jpelkey@gatech.edu>
parents:
5898
diff
changeset
|
657 |
// have to copy the packet first b/c |
a46168c7f4a2
Forgot code freeze. Revert nix-vector bug fix for bug 779
Josh Pelkey <jpelkey@gatech.edu>
parents:
5898
diff
changeset
|
658 |
// it is const |
a46168c7f4a2
Forgot code freeze. Revert nix-vector bug fix for bug 779
Josh Pelkey <jpelkey@gatech.edu>
parents:
5898
diff
changeset
|
659 |
Ptr<Packet> newPacket = Create<Packet> (); |
a46168c7f4a2
Forgot code freeze. Revert nix-vector bug fix for bug 779
Josh Pelkey <jpelkey@gatech.edu>
parents:
5898
diff
changeset
|
660 |
newPacket = p->Copy(); |
a46168c7f4a2
Forgot code freeze. Revert nix-vector bug fix for bug 779
Josh Pelkey <jpelkey@gatech.edu>
parents:
5898
diff
changeset
|
661 |
|
a46168c7f4a2
Forgot code freeze. Revert nix-vector bug fix for bug 779
Josh Pelkey <jpelkey@gatech.edu>
parents:
5898
diff
changeset
|
662 |
NS_LOG_LOGIC ("Adding Nix-vector to packet: " << *nixVectorForPacket); |
a46168c7f4a2
Forgot code freeze. Revert nix-vector bug fix for bug 779
Josh Pelkey <jpelkey@gatech.edu>
parents:
5898
diff
changeset
|
663 |
newPacket->SetNixVector(nixVectorForPacket); |
5224 | 664 |
|
5899
a46168c7f4a2
Forgot code freeze. Revert nix-vector bug fix for bug 779
Josh Pelkey <jpelkey@gatech.edu>
parents:
5898
diff
changeset
|
665 |
// call the unicast callback |
a46168c7f4a2
Forgot code freeze. Revert nix-vector bug fix for bug 779
Josh Pelkey <jpelkey@gatech.edu>
parents:
5898
diff
changeset
|
666 |
// local deliver is handled by Ipv4StaticRoutingImpl |
a46168c7f4a2
Forgot code freeze. Revert nix-vector bug fix for bug 779
Josh Pelkey <jpelkey@gatech.edu>
parents:
5898
diff
changeset
|
667 |
// so this code is never even called if the packet is |
a46168c7f4a2
Forgot code freeze. Revert nix-vector bug fix for bug 779
Josh Pelkey <jpelkey@gatech.edu>
parents:
5898
diff
changeset
|
668 |
// destined for this node. |
a46168c7f4a2
Forgot code freeze. Revert nix-vector bug fix for bug 779
Josh Pelkey <jpelkey@gatech.edu>
parents:
5898
diff
changeset
|
669 |
ucb (rtentry, newPacket, header); |
a46168c7f4a2
Forgot code freeze. Revert nix-vector bug fix for bug 779
Josh Pelkey <jpelkey@gatech.edu>
parents:
5898
diff
changeset
|
670 |
return true; |
a46168c7f4a2
Forgot code freeze. Revert nix-vector bug fix for bug 779
Josh Pelkey <jpelkey@gatech.edu>
parents:
5898
diff
changeset
|
671 |
} |
a46168c7f4a2
Forgot code freeze. Revert nix-vector bug fix for bug 779
Josh Pelkey <jpelkey@gatech.edu>
parents:
5898
diff
changeset
|
672 |
else // path doesn't exist |
a46168c7f4a2
Forgot code freeze. Revert nix-vector bug fix for bug 779
Josh Pelkey <jpelkey@gatech.edu>
parents:
5898
diff
changeset
|
673 |
{ |
a46168c7f4a2
Forgot code freeze. Revert nix-vector bug fix for bug 779
Josh Pelkey <jpelkey@gatech.edu>
parents:
5898
diff
changeset
|
674 |
NS_LOG_ERROR ("No path to the dest: " << header.GetDestination ()); |
a46168c7f4a2
Forgot code freeze. Revert nix-vector bug fix for bug 779
Josh Pelkey <jpelkey@gatech.edu>
parents:
5898
diff
changeset
|
675 |
return false; |
a46168c7f4a2
Forgot code freeze. Revert nix-vector bug fix for bug 779
Josh Pelkey <jpelkey@gatech.edu>
parents:
5898
diff
changeset
|
676 |
} |
5224 | 677 |
} |
5899
a46168c7f4a2
Forgot code freeze. Revert nix-vector bug fix for bug 779
Josh Pelkey <jpelkey@gatech.edu>
parents:
5898
diff
changeset
|
678 |
else |
a46168c7f4a2
Forgot code freeze. Revert nix-vector bug fix for bug 779
Josh Pelkey <jpelkey@gatech.edu>
parents:
5898
diff
changeset
|
679 |
{ |
a46168c7f4a2
Forgot code freeze. Revert nix-vector bug fix for bug 779
Josh Pelkey <jpelkey@gatech.edu>
parents:
5898
diff
changeset
|
680 |
// Get the interface number that we go out of, by extracting |
a46168c7f4a2
Forgot code freeze. Revert nix-vector bug fix for bug 779
Josh Pelkey <jpelkey@gatech.edu>
parents:
5898
diff
changeset
|
681 |
// from the nix-vector |
a46168c7f4a2
Forgot code freeze. Revert nix-vector bug fix for bug 779
Josh Pelkey <jpelkey@gatech.edu>
parents:
5898
diff
changeset
|
682 |
if (m_totalNeighbors == 0) |
a46168c7f4a2
Forgot code freeze. Revert nix-vector bug fix for bug 779
Josh Pelkey <jpelkey@gatech.edu>
parents:
5898
diff
changeset
|
683 |
{ |
a46168c7f4a2
Forgot code freeze. Revert nix-vector bug fix for bug 779
Josh Pelkey <jpelkey@gatech.edu>
parents:
5898
diff
changeset
|
684 |
m_totalNeighbors = FindTotalNeighbors (); |
a46168c7f4a2
Forgot code freeze. Revert nix-vector bug fix for bug 779
Josh Pelkey <jpelkey@gatech.edu>
parents:
5898
diff
changeset
|
685 |
} |
a46168c7f4a2
Forgot code freeze. Revert nix-vector bug fix for bug 779
Josh Pelkey <jpelkey@gatech.edu>
parents:
5898
diff
changeset
|
686 |
uint32_t numberOfBits = nixVector->BitCount (m_totalNeighbors); |
a46168c7f4a2
Forgot code freeze. Revert nix-vector bug fix for bug 779
Josh Pelkey <jpelkey@gatech.edu>
parents:
5898
diff
changeset
|
687 |
uint32_t nodeIndex = nixVector->ExtractNeighborIndex (numberOfBits); |
5224 | 688 |
|
5899
a46168c7f4a2
Forgot code freeze. Revert nix-vector bug fix for bug 779
Josh Pelkey <jpelkey@gatech.edu>
parents:
5898
diff
changeset
|
689 |
rtentry = GetIpv4RouteInCache (header.GetDestination ()); |
a46168c7f4a2
Forgot code freeze. Revert nix-vector bug fix for bug 779
Josh Pelkey <jpelkey@gatech.edu>
parents:
5898
diff
changeset
|
690 |
// not in cache |
a46168c7f4a2
Forgot code freeze. Revert nix-vector bug fix for bug 779
Josh Pelkey <jpelkey@gatech.edu>
parents:
5898
diff
changeset
|
691 |
if (!rtentry) |
a46168c7f4a2
Forgot code freeze. Revert nix-vector bug fix for bug 779
Josh Pelkey <jpelkey@gatech.edu>
parents:
5898
diff
changeset
|
692 |
{ |
a46168c7f4a2
Forgot code freeze. Revert nix-vector bug fix for bug 779
Josh Pelkey <jpelkey@gatech.edu>
parents:
5898
diff
changeset
|
693 |
NS_LOG_LOGIC ("Ipv4Route not in cache, build: "); |
a46168c7f4a2
Forgot code freeze. Revert nix-vector bug fix for bug 779
Josh Pelkey <jpelkey@gatech.edu>
parents:
5898
diff
changeset
|
694 |
Ipv4Address gatewayIp; |
a46168c7f4a2
Forgot code freeze. Revert nix-vector bug fix for bug 779
Josh Pelkey <jpelkey@gatech.edu>
parents:
5898
diff
changeset
|
695 |
uint32_t index = FindNetDeviceForNixIndex (nodeIndex, gatewayIp); |
a46168c7f4a2
Forgot code freeze. Revert nix-vector bug fix for bug 779
Josh Pelkey <jpelkey@gatech.edu>
parents:
5898
diff
changeset
|
696 |
uint32_t interfaceIndex = (m_ipv4)->GetInterfaceForDevice(m_node->GetDevice(index)); |
a46168c7f4a2
Forgot code freeze. Revert nix-vector bug fix for bug 779
Josh Pelkey <jpelkey@gatech.edu>
parents:
5898
diff
changeset
|
697 |
Ipv4InterfaceAddress ifAddr = m_ipv4->GetAddress (interfaceIndex, 0); |
5224 | 698 |
|
5899
a46168c7f4a2
Forgot code freeze. Revert nix-vector bug fix for bug 779
Josh Pelkey <jpelkey@gatech.edu>
parents:
5898
diff
changeset
|
699 |
// start filling in the Ipv4Route info |
a46168c7f4a2
Forgot code freeze. Revert nix-vector bug fix for bug 779
Josh Pelkey <jpelkey@gatech.edu>
parents:
5898
diff
changeset
|
700 |
rtentry = Create<Ipv4Route> (); |
a46168c7f4a2
Forgot code freeze. Revert nix-vector bug fix for bug 779
Josh Pelkey <jpelkey@gatech.edu>
parents:
5898
diff
changeset
|
701 |
rtentry->SetSource (ifAddr.GetLocal ()); |
a46168c7f4a2
Forgot code freeze. Revert nix-vector bug fix for bug 779
Josh Pelkey <jpelkey@gatech.edu>
parents:
5898
diff
changeset
|
702 |
|
a46168c7f4a2
Forgot code freeze. Revert nix-vector bug fix for bug 779
Josh Pelkey <jpelkey@gatech.edu>
parents:
5898
diff
changeset
|
703 |
rtentry->SetGateway (gatewayIp); |
a46168c7f4a2
Forgot code freeze. Revert nix-vector bug fix for bug 779
Josh Pelkey <jpelkey@gatech.edu>
parents:
5898
diff
changeset
|
704 |
rtentry->SetDestination (header.GetDestination ()); |
a46168c7f4a2
Forgot code freeze. Revert nix-vector bug fix for bug 779
Josh Pelkey <jpelkey@gatech.edu>
parents:
5898
diff
changeset
|
705 |
rtentry->SetOutputDevice (m_ipv4->GetNetDevice (interfaceIndex)); |
a46168c7f4a2
Forgot code freeze. Revert nix-vector bug fix for bug 779
Josh Pelkey <jpelkey@gatech.edu>
parents:
5898
diff
changeset
|
706 |
|
a46168c7f4a2
Forgot code freeze. Revert nix-vector bug fix for bug 779
Josh Pelkey <jpelkey@gatech.edu>
parents:
5898
diff
changeset
|
707 |
// add rtentry to cache |
a46168c7f4a2
Forgot code freeze. Revert nix-vector bug fix for bug 779
Josh Pelkey <jpelkey@gatech.edu>
parents:
5898
diff
changeset
|
708 |
m_ipv4RouteCache.insert(Ipv4RouteMap_t::value_type(header.GetDestination (), rtentry)); |
a46168c7f4a2
Forgot code freeze. Revert nix-vector bug fix for bug 779
Josh Pelkey <jpelkey@gatech.edu>
parents:
5898
diff
changeset
|
709 |
} |
5224 | 710 |
|
5899
a46168c7f4a2
Forgot code freeze. Revert nix-vector bug fix for bug 779
Josh Pelkey <jpelkey@gatech.edu>
parents:
5898
diff
changeset
|
711 |
NS_LOG_LOGIC ("At Node " << m_node->GetId() << ", Extracting " << numberOfBits << |
a46168c7f4a2
Forgot code freeze. Revert nix-vector bug fix for bug 779
Josh Pelkey <jpelkey@gatech.edu>
parents:
5898
diff
changeset
|
712 |
" bits from Nix-vector: " << nixVector << " : " << *nixVector); |
a46168c7f4a2
Forgot code freeze. Revert nix-vector bug fix for bug 779
Josh Pelkey <jpelkey@gatech.edu>
parents:
5898
diff
changeset
|
713 |
|
a46168c7f4a2
Forgot code freeze. Revert nix-vector bug fix for bug 779
Josh Pelkey <jpelkey@gatech.edu>
parents:
5898
diff
changeset
|
714 |
// call the unicast callback |
a46168c7f4a2
Forgot code freeze. Revert nix-vector bug fix for bug 779
Josh Pelkey <jpelkey@gatech.edu>
parents:
5898
diff
changeset
|
715 |
// local deliver is handled by Ipv4StaticRoutingImpl |
a46168c7f4a2
Forgot code freeze. Revert nix-vector bug fix for bug 779
Josh Pelkey <jpelkey@gatech.edu>
parents:
5898
diff
changeset
|
716 |
// so this code is never even called if the packet is |
a46168c7f4a2
Forgot code freeze. Revert nix-vector bug fix for bug 779
Josh Pelkey <jpelkey@gatech.edu>
parents:
5898
diff
changeset
|
717 |
// destined for this node. |
a46168c7f4a2
Forgot code freeze. Revert nix-vector bug fix for bug 779
Josh Pelkey <jpelkey@gatech.edu>
parents:
5898
diff
changeset
|
718 |
ucb (rtentry, p, header); |
a46168c7f4a2
Forgot code freeze. Revert nix-vector bug fix for bug 779
Josh Pelkey <jpelkey@gatech.edu>
parents:
5898
diff
changeset
|
719 |
|
a46168c7f4a2
Forgot code freeze. Revert nix-vector bug fix for bug 779
Josh Pelkey <jpelkey@gatech.edu>
parents:
5898
diff
changeset
|
720 |
return true; |
a46168c7f4a2
Forgot code freeze. Revert nix-vector bug fix for bug 779
Josh Pelkey <jpelkey@gatech.edu>
parents:
5898
diff
changeset
|
721 |
} |
5224 | 722 |
} |
723 |
||
724 |
// virtual functions from Ipv4RoutingProtocol |
|
725 |
void |
|
726 |
Ipv4NixVectorRouting::NotifyInterfaceUp (uint32_t i) |
|
727 |
{ |
|
728 |
FlushGlobalNixRoutingCache (); |
|
729 |
} |
|
730 |
void |
|
731 |
Ipv4NixVectorRouting::NotifyInterfaceDown (uint32_t i) |
|
732 |
{ |
|
733 |
FlushGlobalNixRoutingCache (); |
|
734 |
} |
|
735 |
void |
|
736 |
Ipv4NixVectorRouting::NotifyAddAddress (uint32_t interface, Ipv4InterfaceAddress address) |
|
737 |
{ |
|
738 |
FlushGlobalNixRoutingCache (); |
|
739 |
} |
|
740 |
void |
|
741 |
Ipv4NixVectorRouting::NotifyRemoveAddress (uint32_t interface, Ipv4InterfaceAddress address) |
|
742 |
{ |
|
743 |
FlushGlobalNixRoutingCache (); |
|
744 |
} |
|
745 |
||
746 |
bool |
|
5899
a46168c7f4a2
Forgot code freeze. Revert nix-vector bug fix for bug 779
Josh Pelkey <jpelkey@gatech.edu>
parents:
5898
diff
changeset
|
747 |
Ipv4NixVectorRouting::BFS (uint32_t numberOfNodes, Ptr<Node> source, Ptr<Node> dest, std::vector< Ptr<Node> > & parentVector) |
5224 | 748 |
{ |
749 |
NS_LOG_FUNCTION_NOARGS (); |
|
750 |
||
751 |
NS_LOG_LOGIC ("Going from Node " << source->GetId() << " to Node " << dest->GetId()); |
|
752 |
std::queue< Ptr<Node> > greyNodeList; // discovered nodes with unexplored children |
|
753 |
||
754 |
// reset the parent vector |
|
755 |
parentVector.clear (); |
|
756 |
parentVector.reserve (sizeof (Ptr<Node>)*numberOfNodes); |
|
757 |
parentVector.insert (parentVector.begin (), sizeof (Ptr<Node>)*numberOfNodes, 0); // initialize to 0 |
|
758 |
||
759 |
// Add the source node to the queue, set its parent to itself |
|
760 |
greyNodeList.push (source); |
|
761 |
parentVector.at (source->GetId()) = source; |
|
762 |
||
763 |
// BFS loop |
|
764 |
while (greyNodeList.size () != 0) |
|
765 |
{ |
|
766 |
Ptr<Node> currNode = greyNodeList.front (); |
|
767 |
Ptr<Ipv4> ipv4 = currNode->GetObject<Ipv4> (); |
|
768 |
||
769 |
if (currNode == dest) |
|
770 |
{ |
|
771 |
NS_LOG_LOGIC ("Made it to Node " << currNode->GetId()); |
|
772 |
return true; |
|
773 |
} |
|
774 |
||
5899
a46168c7f4a2
Forgot code freeze. Revert nix-vector bug fix for bug 779
Josh Pelkey <jpelkey@gatech.edu>
parents:
5898
diff
changeset
|
775 |
|
a46168c7f4a2
Forgot code freeze. Revert nix-vector bug fix for bug 779
Josh Pelkey <jpelkey@gatech.edu>
parents:
5898
diff
changeset
|
776 |
// Iterate over the current node's adjacent vertices |
a46168c7f4a2
Forgot code freeze. Revert nix-vector bug fix for bug 779
Josh Pelkey <jpelkey@gatech.edu>
parents:
5898
diff
changeset
|
777 |
// and push them into the queue |
a46168c7f4a2
Forgot code freeze. Revert nix-vector bug fix for bug 779
Josh Pelkey <jpelkey@gatech.edu>
parents:
5898
diff
changeset
|
778 |
for (uint32_t i = 0; i < (currNode->GetNDevices ()); i++) |
5224 | 779 |
{ |
5899
a46168c7f4a2
Forgot code freeze. Revert nix-vector bug fix for bug 779
Josh Pelkey <jpelkey@gatech.edu>
parents:
5898
diff
changeset
|
780 |
// Get a net device from the node |
a46168c7f4a2
Forgot code freeze. Revert nix-vector bug fix for bug 779
Josh Pelkey <jpelkey@gatech.edu>
parents:
5898
diff
changeset
|
781 |
// as well as the channel, and figure |
a46168c7f4a2
Forgot code freeze. Revert nix-vector bug fix for bug 779
Josh Pelkey <jpelkey@gatech.edu>
parents:
5898
diff
changeset
|
782 |
// out the adjacent net device |
a46168c7f4a2
Forgot code freeze. Revert nix-vector bug fix for bug 779
Josh Pelkey <jpelkey@gatech.edu>
parents:
5898
diff
changeset
|
783 |
Ptr<NetDevice> localNetDevice = currNode->GetDevice (i); |
a46168c7f4a2
Forgot code freeze. Revert nix-vector bug fix for bug 779
Josh Pelkey <jpelkey@gatech.edu>
parents:
5898
diff
changeset
|
784 |
|
5224 | 785 |
// make sure that we can go this way |
786 |
if (ipv4) |
|
787 |
{ |
|
5899
a46168c7f4a2
Forgot code freeze. Revert nix-vector bug fix for bug 779
Josh Pelkey <jpelkey@gatech.edu>
parents:
5898
diff
changeset
|
788 |
uint32_t interfaceIndex = (ipv4)->GetInterfaceForDevice(currNode->GetDevice(i)); |
5224 | 789 |
if (!(ipv4->IsUp (interfaceIndex))) |
790 |
{ |
|
791 |
NS_LOG_LOGIC ("Ipv4Interface is down"); |
|
5899
a46168c7f4a2
Forgot code freeze. Revert nix-vector bug fix for bug 779
Josh Pelkey <jpelkey@gatech.edu>
parents:
5898
diff
changeset
|
792 |
continue; |
5224 | 793 |
} |
794 |
} |
|
5899
a46168c7f4a2
Forgot code freeze. Revert nix-vector bug fix for bug 779
Josh Pelkey <jpelkey@gatech.edu>
parents:
5898
diff
changeset
|
795 |
if (!(localNetDevice->IsLinkUp ())) |
a46168c7f4a2
Forgot code freeze. Revert nix-vector bug fix for bug 779
Josh Pelkey <jpelkey@gatech.edu>
parents:
5898
diff
changeset
|
796 |
{ |
a46168c7f4a2
Forgot code freeze. Revert nix-vector bug fix for bug 779
Josh Pelkey <jpelkey@gatech.edu>
parents:
5898
diff
changeset
|
797 |
NS_LOG_LOGIC ("Link is down."); |
a46168c7f4a2
Forgot code freeze. Revert nix-vector bug fix for bug 779
Josh Pelkey <jpelkey@gatech.edu>
parents:
5898
diff
changeset
|
798 |
continue; |
a46168c7f4a2
Forgot code freeze. Revert nix-vector bug fix for bug 779
Josh Pelkey <jpelkey@gatech.edu>
parents:
5898
diff
changeset
|
799 |
} |
a46168c7f4a2
Forgot code freeze. Revert nix-vector bug fix for bug 779
Josh Pelkey <jpelkey@gatech.edu>
parents:
5898
diff
changeset
|
800 |
Ptr<Channel> channel = localNetDevice->GetChannel (); |
5224 | 801 |
if (channel == 0) |
802 |
{ |
|
5899
a46168c7f4a2
Forgot code freeze. Revert nix-vector bug fix for bug 779
Josh Pelkey <jpelkey@gatech.edu>
parents:
5898
diff
changeset
|
803 |
continue; |
5224 | 804 |
} |
805 |
||
806 |
// this function takes in the local net dev, and channnel, and |
|
807 |
// writes to the netDeviceContainer the adjacent net devs |
|
808 |
NetDeviceContainer netDeviceContainer; |
|
5899
a46168c7f4a2
Forgot code freeze. Revert nix-vector bug fix for bug 779
Josh Pelkey <jpelkey@gatech.edu>
parents:
5898
diff
changeset
|
809 |
GetAdjacentNetDevices (localNetDevice, channel, netDeviceContainer); |
5224 | 810 |
|
811 |
// Finally we can get the adjacent nodes |
|
812 |
// and scan through them. We push them |
|
813 |
// to the greyNode queue, if they aren't |
|
814 |
// already there. |
|
815 |
for (NetDeviceContainer::Iterator iter = netDeviceContainer.Begin (); iter != netDeviceContainer.End (); iter++) |
|
816 |
{ |
|
817 |
Ptr<Node> remoteNode = (*iter)->GetNode (); |
|
818 |
||
819 |
// check to see if this node has been pushed before |
|
820 |
// by checking to see if it has a parent |
|
821 |
// if it doesn't (null or 0), then set its parent and |
|
822 |
// push to the queue |
|
823 |
if (parentVector.at (remoteNode->GetId ()) == 0) |
|
824 |
{ |
|
825 |
parentVector.at (remoteNode->GetId ()) = currNode; |
|
826 |
greyNodeList.push (remoteNode); |
|
827 |
} |
|
828 |
} |
|
829 |
} |
|
830 |
||
831 |
// Pop off the head grey node. We have all its children. |
|
832 |
// It is now black. |
|
833 |
greyNodeList.pop (); |
|
834 |
} |
|
835 |
||
836 |
// Didn't find the dest... |
|
837 |
return false; |
|
838 |
} |
|
839 |
||
840 |
} // namespace ns3 |