Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(8)

Side by Side Diff: src/routing/nix-vector-routing/ipv4-nix-vector-routing.cc

Issue 117046: Ns-3 Nix-vector Routing
Patch Set: Created 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
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
25 #include "ipv4-nix-vector-routing.h"
26
27 NS_LOG_COMPONENT_DEFINE ("Ipv4NixVectorRouting");
28
29 namespace ns3 {
30
31 NS_OBJECT_ENSURE_REGISTERED (Ipv4NixVectorRouting);
32
33 TypeId
34 Ipv4NixVectorRouting::GetTypeId (void)
35 {
36 static TypeId tid = TypeId ("ns3::Ipv4NixVectorRouting")
37 .SetParent<Ipv4RoutingProtocol> ()
38 .AddConstructor<Ipv4NixVectorRouting> ()
39 ;
40 return tid;
41 }
42
43 Ipv4NixVectorRouting::Ipv4NixVectorRouting ()
44 :m_totalNeighbors (0)
45 {
46 NS_LOG_FUNCTION_NOARGS ();
47 }
48
49 Ipv4NixVectorRouting::~Ipv4NixVectorRouting ()
50 {
51 NS_LOG_FUNCTION_NOARGS ();
52 }
53
54 void
55 Ipv4NixVectorRouting::SetIpv4 (Ptr<Ipv4> ipv4)
56 {
57 NS_ASSERT (ipv4 != 0);
58 NS_ASSERT (m_ipv4 == 0);
59 NS_LOG_DEBUG ("Created Ipv4NixVectorProtocol");
60
61 m_ipv4 = ipv4;
62 }
63
64 void
65 Ipv4NixVectorRouting::DoDispose ()
66 {
67 NS_LOG_FUNCTION_NOARGS ();
68
69 m_node = 0;
70 m_ipv4 = 0;
71
72 Ipv4RoutingProtocol::DoDispose ();
73 }
74
75
76 void
77 Ipv4NixVectorRouting::SetNode (Ptr<Node> node)
78 {
79 NS_LOG_FUNCTION_NOARGS ();
80
81 m_node = node;
82 }
83
84 Ptr<NixVector>
85 Ipv4NixVectorRouting::GetNixVector (Ptr<Node> source, Ipv4Address dest)
86 {
87 NS_LOG_FUNCTION_NOARGS ();
88
89 Ptr<NixVector> nixVector = CreateObject<NixVector> ();
90
91 // not in cache, must build the nix vector
92 // First, we have to figure out the nodes
93 // associated with these IPs
94 Ptr<Node> destNode = GetNodeByIp (dest);
95 if (destNode == 0)
96 {
97 NS_LOG_ERROR ("No routing path exists");
98 return 0;
99 }
100
101 // if source == dest, then we have a special case
102 // because the node is sending to itself. have to
103 // build the nix vector a little differently
104 if (source == destNode)
105 {
106 BuildNixVectorLocal(nixVector);
107 return nixVector;
108 }
109 else
110 {
111 // otherwise proceed as normal
112 // and build the nix vector
113 std::vector< Ptr<Node> > parentVector;
114 BFS (NodeList::GetNNodes (), source, destNode, parentVector);
115
116 if (BuildNixVector (parentVector, source->GetId (), destNode->GetId (), nixV ector))
craigdo 2009/09/11 22:38:17 Coding standard says use {} Other instances bel
jpelkey 2009/09/12 18:34:14 On 2009/09/11 22:38:17, craigdo wrote: > Coding st
Tom Henderson 2009/09/14 03:59:44 On 2009/09/11 22:38:17, craigdo wrote: > Coding st
jpelkey 2009/09/15 04:12:54 On 2009/09/14 03:59:44, Tom H. wrote: > On 2009/09
117 return nixVector;
118 else
119 {
120 NS_LOG_ERROR ("No routing path exists");
121 return 0;
122 }
123 }
124 }
125
126 Ptr<NixVector>
127 Ipv4NixVectorRouting::GetNixVectorInCache (Ipv4Address address)
128 {
129 NS_LOG_FUNCTION_NOARGS ();
130
131 NixMap_t::iterator iter = m_nixCache.find (address);
132 if (iter != m_nixCache.end ())
133 {
134 NS_LOG_LOGIC ("Found Nix-vector in cache.");
135 return iter->second;
136 }
137
138 // not in cache
139 return 0;
140 }
141
142 Ptr<Ipv4Route>
143 Ipv4NixVectorRouting::GetIpv4RouteInCache (Ipv4Address address)
144 {
145 NS_LOG_FUNCTION_NOARGS ();
146
147 Ipv4RouteMap_t::iterator iter = m_ipv4RouteCache.find (address);
148 if (iter != m_ipv4RouteCache.end ())
149 {
150 NS_LOG_LOGIC ("Found Ipv4Route in cache.");
151 return iter->second;
152 }
153
154 // not in cache
155 return 0;
156 }
157
158 bool
159 Ipv4NixVectorRouting::BuildNixVectorLocal (Ptr<NixVector> nixVector)
160 {
161 NS_LOG_FUNCTION_NOARGS ();
162
163 uint32_t numberOfDevices = m_node->GetNDevices ();
164
165 // here we are building a nix vector to
166 // ourself, so we need to find the loopback
167 // interface and add that to the nix vector
168 Ipv4Address loopback ("127.0.0.1");
169 for (uint32_t i = 0; i < numberOfDevices; i++)
170 {
171 uint32_t interfaceIndex = (m_ipv4)->GetInterfaceForDevice(m_node->GetDevice( i));
172 Ipv4InterfaceAddress ifAddr = m_ipv4->GetAddress (interfaceIndex, 0);
173 if (ifAddr.GetLocal() == loopback)
174 {
175 NS_LOG_LOGIC ("Adding loopback to nix.");
176 NS_LOG_LOGIC ("Adding Nix: " << i << " with " << nixVector->BitCount (numb erOfDevices) << " bits, for node " << m_node->GetId());
177 nixVector->AddNeighborIndex (i, nixVector->BitCount (numberOfDevices));
178 return true;
179 }
180 }
181 return false;
182 }
183
184 bool
185 Ipv4NixVectorRouting::BuildNixVector (const std::vector< Ptr<Node> > & parentVec tor, uint32_t source, uint32_t dest, Ptr<NixVector> nixVector)
186 {
187 NS_LOG_FUNCTION_NOARGS ();
188
189 if (source == dest)
190 return true;
191
192 if (parentVector.at(dest) == 0)
Tom Henderson 2009/09/14 03:59:44 at (dest)
jpelkey 2009/09/15 04:12:54 On 2009/09/14 03:59:44, Tom H. wrote: > at (dest)
193 return false;
194
195 Ptr<Node> parentNode = parentVector.at (dest);
196
197 uint32_t numberOfDevices = parentNode->GetNDevices ();
198 uint32_t destId = 0;
199 uint32_t totalNeighbors = 0;
200
201 // scan through the net devices on the parent node
202 // and then look at the nodes adjacent to them
203 for (uint32_t i = 0; i < numberOfDevices; i++)
204 {
205 // Get a net device from the node
206 // as well as the channel, and figure
207 // out the adjacent net devices
208 Ptr<NetDevice> localNetDevice = parentNode->GetDevice (i);
209 Ptr<Channel> channel = localNetDevice->GetChannel ();
210 if (channel == 0)
211 {
212 continue;
213 }
214
215 // this function takes in the local net dev, and channnel, and
216 // writes to the netDeviceContainer the adjacent net devs
217 NetDeviceContainer netDeviceContainer;
218 GetAdjacentNetDevices (localNetDevice, channel, netDeviceContainer);
219
220 // Finally we can get the adjacent nodes
221 // and scan through them. If we find the
222 // node that matches "dest" then we can add
223 // the index to the nix vector.
224 // the index corresponds to the neighbor index
225 uint32_t offset = 0;
226 for (NetDeviceContainer::Iterator iter = netDeviceContainer.Begin (); iter ! = netDeviceContainer.End (); iter++)
227 {
228 Ptr<Node> remoteNode = (*iter)->GetNode ();
229
230 if (remoteNode->GetId () == dest)
231 {
232 destId = totalNeighbors + offset;
233 break;
234 }
235 offset += 1;
236 }
237
238 totalNeighbors += netDeviceContainer.GetN ();
239 }
240 m_totalNeighbors = totalNeighbors;
241 NS_LOG_LOGIC ("Adding Nix: " << destId << " with " << nixVector->BitCount (tot alNeighbors) << " bits, for node " << parentNode->GetId());
242 nixVector->AddNeighborIndex (destId, nixVector->BitCount (totalNeighbors));
243
244 // recurse through parent vector, grabbin the path
Tom Henderson 2009/09/14 03:59:44 grabbing
jpelkey 2009/09/15 04:12:54 On 2009/09/14 03:59:44, Tom H. wrote: > grabbing
245 // and building the nix vector
246 BuildNixVector (parentVector, source, (parentVector.at (dest))->GetId (), nixV ector);
247 return true;
248 }
249
250 void
251 Ipv4NixVectorRouting::GetAdjacentNetDevices (Ptr<NetDevice> netDevice, Ptr<Chann el> channel, NetDeviceContainer & netDeviceContainer)
252 {
253 //NS_LOG_FUNCTION_NOARGS ();
Tom Henderson 2009/09/14 03:59:44 why commented out?
jpelkey 2009/09/15 04:12:54 On 2009/09/14 03:59:44, Tom H. wrote: > why commen
254
255 for (uint32_t i = 0; i < channel->GetNDevices (); i++)
256 if (channel->GetDevice (i) != netDevice)
257 netDeviceContainer.Add(channel->GetDevice (i));
Tom Henderson 2009/09/14 03:59:44 Add (channel...)
jpelkey 2009/09/15 04:12:54 On 2009/09/14 03:59:44, Tom H. wrote: > Add (chann
258 }
259
260 Ptr<Node>
261 Ipv4NixVectorRouting::GetNodeByIp (Ipv4Address dest)
262 {
263 NS_LOG_FUNCTION_NOARGS ();
264
265 NodeContainer allNodes = NodeContainer::GetGlobal ();
266 Ptr<Node> destNode;
267
268 for (NodeContainer::Iterator i = allNodes.Begin (); i != allNodes.End (); ++i)
269 {
270 Ptr<Node> node = *i;
271 Ptr<Ipv4> ipv4 = node->GetObject<Ipv4> ();
272 if (ipv4->GetInterfaceForAddress (dest) != -1)
273 {
274 destNode = node;
275 break;
276 }
277 }
278
279 if (!destNode)
280 {
281 NS_LOG_ERROR ("Couldn't find dest node given the IP" << dest);
282 return 0;
283 }
284
285 return destNode;
286 }
287
288 uint32_t
289 Ipv4NixVectorRouting::FindTotalNeighbors ()
290 {
291 uint32_t numberOfDevices = m_node->GetNDevices ();
292 uint32_t totalNeighbors = 0;
293
294 // scan through the net devices on the parent node
295 // and then look at the nodes adjacent to them
296 for (uint32_t i = 0; i < numberOfDevices; i++)
297 {
298 // Get a net device from the node
299 // as well as the channel, and figure
300 // out the adjacent net devices
301 Ptr<NetDevice> localNetDevice = m_node->GetDevice (i);
302 Ptr<Channel> channel = localNetDevice->GetChannel ();
303 if (channel == 0)
304 {
305 continue;
306 }
307
308 // this function takes in the local net dev, and channnel, and
309 // writes to the netDeviceContainer the adjacent net devs
310 NetDeviceContainer netDeviceContainer;
311 GetAdjacentNetDevices (localNetDevice, channel, netDeviceContainer);
312
313 totalNeighbors += netDeviceContainer.GetN ();
314 }
315
316 return totalNeighbors;
317 }
318
319 uint32_t
320 Ipv4NixVectorRouting::FindNetDeviceForNixIndex (uint32_t nodeIndex, Ipv4Address & gatewayIp)
321 {
322 uint32_t numberOfDevices = m_node->GetNDevices ();
323 uint32_t index = 0;
324 uint32_t totalNeighbors = 0;
325
326 // scan through the net devices on the parent node
327 // and then look at the nodes adjacent to them
328 for (uint32_t i = 0; i < numberOfDevices; i++)
329 {
330 // Get a net device from the node
331 // as well as the channel, and figure
332 // out the adjacent net devices
333 Ptr<NetDevice> localNetDevice = m_node->GetDevice (i);
334 Ptr<Channel> channel = localNetDevice->GetChannel ();
335 if (channel == 0)
336 {
337 continue;
338 }
339
340 // this function takes in the local net dev, and channnel, and
341 // writes to the netDeviceContainer the adjacent net devs
342 NetDeviceContainer netDeviceContainer;
343 GetAdjacentNetDevices (localNetDevice, channel, netDeviceContainer);
344
345 // check how many neighbors we have
346 if (nodeIndex < (totalNeighbors + netDeviceContainer.GetN ()))
347 {
348 // found the proper net device
349 index = i;
350 Ptr<NetDevice> gatewayDevice = netDeviceContainer.Get (nodeIndex-totalNeig hbors);
351 Ptr<Node> gatewayNode = gatewayDevice->GetNode ();
352 Ptr<Ipv4> ipv4 = gatewayNode->GetObject<Ipv4> ();
353
354 uint32_t interfaceIndex = (ipv4)->GetInterfaceForDevice(gatewayDevice);
355 Ipv4InterfaceAddress ifAddr = ipv4->GetAddress (interfaceIndex, 0);
356 gatewayIp = ifAddr.GetLocal ();
357 break;
358 }
359 totalNeighbors += netDeviceContainer.GetN ();
360 }
361
362 return index;
363 }
364
365 Ptr<Ipv4Route>
366 Ipv4NixVectorRouting::RouteOutput (Ptr<Packet> p, const Ipv4Header &header, uint 32_t oif, Socket::SocketErrno &sockerr)
367 {
368 NS_LOG_FUNCTION_NOARGS ();
369 Ptr<Ipv4Route> rtentry;
370 Ptr<NixVector> nixVectorInCache;
371 Ptr<NixVector> nixVectorForPacket;
372
373 NS_LOG_DEBUG ("Dest IP from header: " << header.GetDestination());
374 // check if cache
375 nixVectorInCache = GetNixVectorInCache(header.GetDestination());
Tom Henderson 2009/09/14 03:59:44 Destination () (multiple places in this file)
jpelkey 2009/09/15 04:12:54 On 2009/09/14 03:59:44, Tom H. wrote: > Destinatio
376
377 // not in cache
378 if (!nixVectorInCache)
379 {
380 NS_LOG_LOGIC ("Nix-vector not in cache, build: ");
381 // Build the nix-vector, given this node and the
382 // dest IP address
383 nixVectorInCache = GetNixVector (m_node, header.GetDestination());
384
385 // cache it
386 m_nixCache.insert(NixMap_t::value_type(header.GetDestination(), nixVectorInC ache));
Tom Henderson 2009/09/14 03:59:44 insert (NixMap_t...
jpelkey 2009/09/15 04:12:54 On 2009/09/14 03:59:44, Tom H. wrote: > insert (Ni
387 }
388
389 // path exists
390 if (nixVectorInCache)
391 {
392 NS_LOG_LOGIC ("Nix-vector contents: " << *nixVectorInCache);
393
394 // create a new nix vector to be used,
395 // we want to keep the cached version clean
396 nixVectorForPacket = CreateObject<NixVector> ();
397 nixVectorForPacket = nixVectorInCache->Copy();
398
399
400 // Get the interface number that we go out of, by extracting
401 // from the nix-vector
402 uint32_t numberOfBits = nixVectorForPacket->BitCount (m_totalNeighbors);
403 uint32_t nodeIndex = nixVectorForPacket->ExtractNeighborIndex (numberOfBits) ;
404
405 // Possibly search here in a cache for this node index
406 // and look for a Ipv4Route. If we have it, don't
407 // need to do the next 3 lines.
408 rtentry = GetIpv4RouteInCache (header.GetDestination ());
409 // not in cache
410 if (!rtentry)
411 {
412 NS_LOG_LOGIC ("Ipv4Route not in cache, build: ");
413 Ipv4Address gatewayIp;
414 uint32_t index = FindNetDeviceForNixIndex (nodeIndex, gatewayIp);
415
416 uint32_t interfaceIndex = (m_ipv4)->GetInterfaceForDevice(m_node->GetDevic e(index));
417 Ipv4InterfaceAddress ifAddr = m_ipv4->GetAddress (interfaceIndex, 0);
418
419 // start filling in the Ipv4Route info
420 rtentry = Create<Ipv4Route> ();
421 rtentry->SetSource (ifAddr.GetLocal ());
422
423 // Have to set a gateway here (defaulting to zero)
424 // otherwise RouteOutput gets called twice
425 rtentry->SetGateway (gatewayIp);
426 rtentry->SetDestination (header.GetDestination ());
427 rtentry->SetOutputDevice (m_ipv4->GetNetDevice (interfaceIndex));
428
429 sockerr = Socket::ERROR_NOTERROR;
430
431 // add rtentry to cache
432 m_ipv4RouteCache.insert(Ipv4RouteMap_t::value_type(header.GetDestination() , rtentry));
433 }
434
435 NS_LOG_LOGIC ("Nix-vector contents: " << *nixVectorInCache << " : Remaining bits: " << nixVectorForPacket->GetRemainingBits());
436
437 // Add nix-vector in the packet class
438 // make sure the packet exists first
439 if (p)
440 {
441 NS_LOG_LOGIC ("Adding Nix-vector to packet: " << *nixVectorForPacket);
442 p->SetNixVector(nixVectorForPacket);
Tom Henderson 2009/09/14 03:59:44 SetNixVector (...)
jpelkey 2009/09/15 04:12:54 On 2009/09/14 03:59:44, Tom H. wrote: > SetNixVect
443 }
444 }
445 else // path doesn't exist
446 {
447 NS_LOG_ERROR ("No path to the dest: " << header.GetDestination());
448 sockerr = Socket::ERROR_NOROUTETOHOST;
449 }
450
451 return rtentry;
452 }
453
454 bool
455 Ipv4NixVectorRouting::RouteInput (Ptr<const Packet> p, const Ipv4Header &header, Ptr<const NetDevice> idev,
456 UnicastForwardCallback ucb, MulticastForwardCallbac k mcb,
457 LocalDeliverCallback lcb, ErrorCallback ecb)
458 {
459 NS_LOG_FUNCTION_NOARGS ();
460
461 Ptr<Ipv4Route> rtentry;
462
463 // Get the nix-vector from the packet
464 Ptr<NixVector> nixVector = p->GetNixVector();
465
466 // make sure it exists, if not something
467 // went wrong
468 if (!nixVector)
469 {
470 NS_LOG_ERROR ("Nix-vector wasn't in the packet! Rebuild.");
471
472 Ptr<NixVector> nixVectorInCache;
473
474 NS_LOG_DEBUG ("Dest IP from header: " << header.GetDestination());
475
476 // check if cache
477 nixVectorInCache = GetNixVectorInCache(header.GetDestination());
478
479 // not in cache
480 if (!nixVectorInCache)
481 {
482 NS_LOG_LOGIC ("RouteInput(): Nix-vector not in cache, build: ");
483
484 // Build the nix-vector, given this node and the
485 // dest IP address
486 nixVectorInCache = GetNixVector (m_node, header.GetDestination());
487 }
488
489 // path exists
490 if (nixVectorInCache)
491 {
492 NS_LOG_LOGIC ("Nix-vector contents: " << *nixVectorInCache);
493
494 // cache it
495 m_nixCache.insert(NixMap_t::value_type(header.GetDestination(), nixVectorI nCache));
496
497 // create a new nix vector to be used,
498 // we want to keep the cached version clean
499 Ptr<NixVector> nixVectorForPacket;
500 nixVectorForPacket = CreateObject<NixVector> ();
501 nixVectorForPacket = nixVectorInCache->Copy();
502
503 // Get the interface number that we go out of, by extracting
504 // from the nix-vector
505 if (m_totalNeighbors == 0)
506 {
507 m_totalNeighbors = FindTotalNeighbors ();
508 }
509 uint32_t numberOfBits = nixVectorForPacket->BitCount (m_totalNeighbors);
510 uint32_t nodeIndex = nixVectorForPacket->ExtractNeighborIndex (numberOfBit s);
511
512 rtentry = GetIpv4RouteInCache (header.GetDestination ());
513 // not in cache
514 if (!rtentry)
515 {
516 NS_LOG_LOGIC ("Ipv4Route not in cache, build: ");
517 Ipv4Address gatewayIp;
518 uint32_t index = FindNetDeviceForNixIndex (nodeIndex, gatewayIp);
519
520 uint32_t interfaceIndex = (m_ipv4)->GetInterfaceForDevice(m_node->GetDev ice(index));
521 Ipv4InterfaceAddress ifAddr = m_ipv4->GetAddress (interfaceIndex, 0);
522
523 // start filling in the Ipv4Route info
524 rtentry = Create<Ipv4Route> ();
525 rtentry->SetSource (ifAddr.GetLocal ());
526
527 // Have to set a gateway here (defaulting to zero)
528 // otherwise RouteOutput gets called twice
529 rtentry->SetGateway (Ipv4Address((uint32_t)0));
530 rtentry->SetDestination (header.GetDestination ());
531 rtentry->SetOutputDevice (m_ipv4->GetNetDevice (interfaceIndex));
532
533 // add rtentry to cache
534 m_ipv4RouteCache.insert(Ipv4RouteMap_t::value_type(header.GetDestination (), rtentry));
535 }
536
537 NS_LOG_LOGIC ("Nix-vector contents: " << *nixVectorInCache << " : Remainin g bits: " << nixVectorForPacket->GetRemainingBits());
538
539 // Add nix-vector in the packet class
540 // have to copy the packet first b/c
541 // it is const
542 Ptr<Packet> newPacket = Create<Packet> ();
543 newPacket = p->Copy();
544
545 NS_LOG_LOGIC ("Adding Nix-vector to packet: " << *nixVectorForPacket);
546 newPacket->SetNixVector(nixVectorForPacket);
547
548 // call the unicast callback
549 // local deliver is handled by Ipv4StaticRoutingImpl
550 // so this code is never even called if the packet is
551 // destined for this node.
552 ucb (rtentry, newPacket, header);
553 return true;
554 }
555 else // path doesn't exist
556 {
557 NS_LOG_ERROR ("No path to the dest: " << header.GetDestination());
558 return false;
559 }
560 }
561 else
562 {
563 // Get the interface number that we go out of, by extracting
564 // from the nix-vector
565 // TOTAL NEIGHBORS HASN'T BEEN DETERMINED YET
566 if (m_totalNeighbors == 0)
567 {
568 m_totalNeighbors = FindTotalNeighbors ();
569 }
570 uint32_t numberOfBits = nixVector->BitCount (m_totalNeighbors);
571 uint32_t nodeIndex = nixVector->ExtractNeighborIndex (numberOfBits);
572
573 rtentry = GetIpv4RouteInCache (header.GetDestination ());
574 // not in cache
575 if (!rtentry)
576 {
577 NS_LOG_LOGIC ("Ipv4Route not in cache, build: ");
578 Ipv4Address gatewayIp;
579 uint32_t index = FindNetDeviceForNixIndex (nodeIndex, gatewayIp);
580 uint32_t interfaceIndex = (m_ipv4)->GetInterfaceForDevice(m_node->GetDevic e(index));
581 Ipv4InterfaceAddress ifAddr = m_ipv4->GetAddress (interfaceIndex, 0);
582
583 // start filling in the Ipv4Route info
584 rtentry = Create<Ipv4Route> ();
585 rtentry->SetSource (ifAddr.GetLocal ());
586
587 // Have to set a gateway here (defaulting to zero)
588 // otherwise RouteOutput gets called twice
589 rtentry->SetGateway (gatewayIp);
590 rtentry->SetDestination (header.GetDestination());
591 rtentry->SetOutputDevice (m_ipv4->GetNetDevice (interfaceIndex));
592
593 // add rtentry to cache
594 m_ipv4RouteCache.insert(Ipv4RouteMap_t::value_type(header.GetDestination() , rtentry));
595 }
596
597 NS_LOG_LOGIC ("At Node " << m_node->GetId() << ", Extracting " << numberOfBi ts <<
598 " bits from Nix-vector: " << nixVector << " : " << *nix Vector);
599
600 // call the unicast callback
601 // local deliver is handled by Ipv4StaticRoutingImpl
602 // so this code is never even called if the packet is
603 // destined for this node.
604 ucb (rtentry, p, header);
605
606 return true;
607 }
608 }
609
610 // virtual functions from Ipv4RoutingProtocol
611 void
612 Ipv4NixVectorRouting::NotifyInterfaceUp (uint32_t i)
613 {}
614 void
615 Ipv4NixVectorRouting::NotifyInterfaceDown (uint32_t i)
616 {}
Tom Henderson 2009/09/14 03:59:44 Shouldn't these events flush any caches? What hap
jpelkey 2009/09/15 04:12:54 On 2009/09/14 03:59:44, Tom H. wrote: > Shouldn't
Tom Henderson 2009/09/15 04:20:52 Could this be due to > nix-vector taking zero simu
617 void
618 Ipv4NixVectorRouting::NotifyAddAddress (uint32_t interface, Ipv4InterfaceAddress address)
619 {}
620 void
621 Ipv4NixVectorRouting::NotifyRemoveAddress (uint32_t interface, Ipv4InterfaceAddr ess address)
622 {}
623
624 bool
625 Ipv4NixVectorRouting::BFS (uint32_t numberOfNodes, Ptr<Node> source, Ptr<Node> d est, std::vector< Ptr<Node> > & parentVector)
626 {
627 NS_LOG_FUNCTION_NOARGS ();
628
629 NS_LOG_LOGIC ("Going from Node " << source->GetId() << " to Node " << dest->Ge tId());
630 std::queue< Ptr<Node> > greyNodeList; // discovered nodes with unexplored chi ldren
631
632 // reset the parent vector
633 parentVector.clear ();
634 parentVector.reserve (sizeof (Ptr<Node>)*numberOfNodes);
635 parentVector.insert (parentVector.begin (), sizeof (Ptr<Node>)*numberOfNodes, 0); // initialize to 0
636
637 // Add the source node to the queue, set its parent to itself
638 greyNodeList.push (source);
639 parentVector.at (source->GetId()) = source;
640
641 // BFS loop
642 while (greyNodeList.size () != 0)
643 {
644 Ptr<Node> currNode = greyNodeList.front ();
645
646 if (currNode == dest)
647 {
648 NS_LOG_LOGIC ("Made it to Node " << currNode->GetId());
649 return true;
650 }
651
652
653 // Iterate over the current node's adjacent vertices
654 // and push them into the queue
655 for (uint32_t i = 0; i < (currNode->GetNDevices ()); i++)
656 {
657 // Get a net device from the node
658 // as well as the channel, and figure
659 // out the adjacent net device
660 Ptr<NetDevice> localNetDevice = currNode->GetDevice (i);
661 Ptr<Channel> channel = localNetDevice->GetChannel ();
662 if (channel == 0)
663 {
664 continue;
665 }
666
667 // this function takes in the local net dev, and channnel, and
668 // writes to the netDeviceContainer the adjacent net devs
669 NetDeviceContainer netDeviceContainer;
670 GetAdjacentNetDevices (localNetDevice, channel, netDeviceContainer);
671
672 // Finally we can get the adjacent nodes
673 // and scan through them. We push them
674 // to the greyNode queue, if they aren't
675 // already there.
676 for (NetDeviceContainer::Iterator iter = netDeviceContainer.Begin (); iter != netDeviceContainer.End (); iter++)
677 {
678 Ptr<Node> remoteNode = (*iter)->GetNode ();
679
680 // check to see if this node has been pushed before
681 // by checking to see if it has a parent
682 // if it doesn't (null or 0), then set its parent and
683 // push to the queue
684 if (parentVector.at (remoteNode->GetId ()) == 0)
685 {
686 parentVector.at (remoteNode->GetId ()) = currNode;
687 greyNodeList.push (remoteNode);
688 }
689 }
690 }
691
692 // Pop off the head grey node. We have all its children.
693 // It is now black.
694 greyNodeList.pop ();
695
696 }
697
698 // Didn't find the dest...
699 return false;
700 }
701 } // namespace ns3
OLDNEW

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld r511