A Discrete-Event Network Simulator
API
dsr-options.cc
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2011 Yufei Cheng
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  * Author: Yufei Cheng <yfcheng@ittc.ku.edu>
19  *
20  * James P.G. Sterbenz <jpgs@ittc.ku.edu>, director
21  * ResiliNets Research Group http://wiki.ittc.ku.edu/resilinets
22  * Information and Telecommunication Technology Center (ITTC)
23  * and Department of Electrical Engineering and Computer Science
24  * The University of Kansas Lawrence, KS USA.
25  *
26  * Work supported in part by NSF FIND (Future Internet Design) Program
27  * under grant CNS-0626918 (Postmodern Internet Architecture),
28  * NSF grant CNS-1050226 (Multilayer Network Resilience Analysis and Experimentation on GENI),
29  * US Department of Defense (DoD), and ITTC at The University of Kansas.
30  */
31 
32 #define NS_LOG_APPEND_CONTEXT \
33  if (GetObject<Node> ()) { std::clog << "[node " << GetObject<Node> ()->GetId () << "] "; }
34 
35 #include <list>
36 #include <ctime>
37 #include <map>
38 
39 #include "ns3/ptr.h"
40 #include "ns3/log.h"
41 #include "ns3/assert.h"
42 #include "ns3/fatal-error.h"
43 #include "ns3/node.h"
44 #include "ns3/uinteger.h"
45 #include "ns3/trace-source-accessor.h"
46 #include "ns3/udp-header.h"
47 #include "ns3/pointer.h"
48 #include "ns3/node-list.h"
49 #include "ns3/uinteger.h"
50 #include "ns3/object-vector.h"
51 #include "ns3/ipv4-l3-protocol.h"
52 #include "ns3/ipv4-interface.h"
53 #include "ns3/ipv4-header.h"
54 #include "ns3/ipv4-address.h"
55 #include "ns3/ipv4-route.h"
56 #include "ns3/icmpv4-l4-protocol.h"
57 #include "ns3/ip-l4-protocol.h"
58 
59 #include "dsr-option-header.h"
60 #include "dsr-options.h"
61 #include "dsr-rcache.h"
62 
63 namespace ns3 {
64 
65 NS_LOG_COMPONENT_DEFINE ("DsrOptions");
66 
67 namespace dsr {
68 
69 NS_OBJECT_ENSURE_REGISTERED (DsrOptions);
70 
72 {
73  static TypeId tid = TypeId ("ns3::dsr::DsrOptions")
74  .SetParent<Object> ()
75  .AddAttribute ("OptionNumber", "The Dsr option number.",
76  UintegerValue (0),
78  MakeUintegerChecker<uint8_t> ())
79  .AddTraceSource ("Drop",
80  "Packet dropped.",
82  "ns3::Packet::TracedCallback")
83  .AddTraceSource ("Rx",
84  "Receive DSR packet.",
86  "ns3::Packet::TracedCallback")
87  ;
88  return tid;
89 }
90 
92 {
94 }
95 
97 {
99 }
100 
102 {
103  NS_LOG_FUNCTION (this << node);
104  m_node = node;
105 }
106 
108 {
110  return m_node;
111 }
112 
113 bool DsrOptions::ContainAddressAfter (Ipv4Address ipv4Address, Ipv4Address destAddress, std::vector<Ipv4Address> &nodeList)
114 {
115  NS_LOG_FUNCTION (this << ipv4Address << destAddress);
116  std::vector<Ipv4Address>::iterator it = find (nodeList.begin (), nodeList.end (), destAddress);
117 
118  for (std::vector<Ipv4Address>::iterator i = it; i != nodeList.end (); ++i)
119  {
120  if ((ipv4Address == (*i)) && ((*i) != nodeList.back ()))
121  {
122  return true;
123  }
124  }
125  return false;
126 }
127 
128 std::vector<Ipv4Address>
129 DsrOptions::CutRoute (Ipv4Address ipv4Address, std::vector<Ipv4Address> &nodeList)
130 {
131  NS_LOG_FUNCTION (this << ipv4Address);
132  std::vector<Ipv4Address>::iterator it = find (nodeList.begin (), nodeList.end (), ipv4Address);
133  std::vector<Ipv4Address> cutRoute;
134  for (std::vector<Ipv4Address>::iterator i = it; i != nodeList.end (); ++i)
135  {
136  cutRoute.push_back (*i);
137  }
138  return cutRoute;
139 }
140 
142 {
143  NS_LOG_FUNCTION (this << nextHop << srcAddress);
144  m_ipv4Route = Create<Ipv4Route> ();
145  m_ipv4Route->SetDestination (nextHop);
146  m_ipv4Route->SetGateway (nextHop);
147  m_ipv4Route->SetSource (srcAddress);
148  return m_ipv4Route;
149 }
150 
151 bool DsrOptions::ReverseRoutes (std::vector<Ipv4Address> & vec)
152 {
153  NS_LOG_FUNCTION (this);
154  std::vector<Ipv4Address> vec2 (vec);
155  vec.clear (); // To ensure vec is empty before start
156  for (std::vector<Ipv4Address>::reverse_iterator ri = vec2.rbegin (); ri
157  != vec2.rend (); ++ri)
158  {
159  vec.push_back (*ri);
160  }
161 
162  if ((vec.size () == vec2.size ()) && (vec.front () == vec2.back ()))
163  {
164  return true;
165  }
166  return false;
167 }
168 
169 Ipv4Address DsrOptions::SearchNextHop (Ipv4Address ipv4Address, std::vector<Ipv4Address>& vec)
170 {
171  NS_LOG_FUNCTION (this << ipv4Address);
172  Ipv4Address nextHop;
173  NS_LOG_DEBUG ("the vector size " << vec.size ());
174  if (vec.size () == 2)
175  {
176  NS_LOG_DEBUG ("The two nodes are neighbors");
177  nextHop = vec[1];
178  return nextHop;
179  }
180  else
181  {
182  if (ipv4Address == vec.back ())
183  {
184  NS_LOG_DEBUG ("We have reached to the final destination " << ipv4Address << " " << vec.back ());
185  return ipv4Address;
186  }
187  for (std::vector<Ipv4Address>::const_iterator i = vec.begin (); i != vec.end (); ++i)
188  {
189  if (ipv4Address == (*i))
190  {
191  nextHop = *(++i);
192  return nextHop;
193  }
194  }
195  }
196  NS_LOG_DEBUG ("next hop address not found, route corrupted");
197  Ipv4Address none = "0.0.0.0";
198  return none;
199 }
200 
201 Ipv4Address DsrOptions::ReverseSearchNextHop (Ipv4Address ipv4Address, std::vector<Ipv4Address>& vec)
202 {
203  NS_LOG_FUNCTION (this << ipv4Address);
204  Ipv4Address nextHop;
205  if (vec.size () == 2)
206  {
207  NS_LOG_DEBUG ("The two nodes are neighbors");
208  nextHop = vec[0];
209  return nextHop;
210  }
211  else
212  {
213  for (std::vector<Ipv4Address>::reverse_iterator ri = vec.rbegin (); ri != vec.rend (); ++ri)
214  {
215  if (ipv4Address == (*ri))
216  {
217  nextHop = *(++ri);
218  return nextHop;
219  }
220  }
221  }
222  NS_LOG_DEBUG ("next hop address not found, route corrupted");
223  Ipv4Address none = "0.0.0.0";
224  return none;
225 }
226 
227 Ipv4Address DsrOptions::ReverseSearchNextTwoHop (Ipv4Address ipv4Address, std::vector<Ipv4Address>& vec)
228 {
229  NS_LOG_FUNCTION (this << ipv4Address);
230  Ipv4Address nextTwoHop;
231  NS_LOG_DEBUG ("The vector size " << vec.size ());
232  NS_ASSERT (vec.size () > 2);
233  for (std::vector<Ipv4Address>::reverse_iterator ri = vec.rbegin (); ri != vec.rend (); ++ri)
234  {
235  if (ipv4Address == (*ri))
236  {
237  nextTwoHop = *(ri + 2);
238  return nextTwoHop;
239  }
240  }
241  NS_FATAL_ERROR ("next hop address not found, route corrupted");
242  Ipv4Address none = "0.0.0.0";
243  return none;
244 }
245 
246 void DsrOptions::PrintVector (std::vector<Ipv4Address>& vec)
247 {
248  NS_LOG_FUNCTION (this);
249  /*
250  * Check elements in a route vector
251  */
252  if (!vec.size ())
253  {
254  NS_LOG_DEBUG ("The vector is empty");
255  }
256  else
257  {
258  NS_LOG_DEBUG ("Print all the elements in a vector");
259  for (std::vector<Ipv4Address>::const_iterator i = vec.begin (); i != vec.end (); ++i)
260  {
261  NS_LOG_DEBUG ("The ip address " << *i);
262  }
263  }
264 }
265 
266 bool DsrOptions::IfDuplicates (std::vector<Ipv4Address>& vec, std::vector<Ipv4Address>& vec2)
267 {
268  NS_LOG_FUNCTION (this);
269  for (std::vector<Ipv4Address>::const_iterator i = vec.begin (); i != vec.end (); ++i)
270  {
271  for (std::vector<Ipv4Address>::const_iterator j = vec2.begin (); j != vec2.end (); ++j)
272  {
273  if ((*i) == (*j))
274  {
275  return true;
276  }
277  else
278  {
279  continue;
280  }
281  }
282  }
283  return false;
284 }
285 
286 bool DsrOptions::CheckDuplicates (Ipv4Address ipv4Address, std::vector<Ipv4Address>& vec)
287 {
288  NS_LOG_FUNCTION (this << ipv4Address);
289  for (std::vector<Ipv4Address>::const_iterator i = vec.begin (); i != vec.end (); ++i)
290  {
291  if ((*i) == ipv4Address)
292  {
293  return true;
294  }
295  else
296  {
297  continue;
298  }
299  }
300  return false;
301 }
302 
303 void DsrOptions::RemoveDuplicates (std::vector<Ipv4Address>& vec)
304 {
305  NS_LOG_FUNCTION (this);
306  //Remove duplicate ip address from the route if any, should not happen with normal behavior nodes
307  std::vector<Ipv4Address> vec2 (vec); // declare vec2 as a copy of the vec
308  PrintVector (vec2); // Print all the ip address in the route
309  vec.clear (); // clear vec
310  for (std::vector<Ipv4Address>::const_iterator i = vec2.begin (); i != vec2.end (); ++i)
311  {
312  if (vec.empty ())
313  {
314  vec.push_back (*i);
315  continue;
316  }
317  else
318  {
319  for (std::vector<Ipv4Address>::iterator j = vec.begin (); j != vec.end (); ++j)
320  {
321  if ((*i) == (*j))
322  {
323  if ((j + 1) != vec.end ())
324  {
325  vec.erase (j + 1, vec.end ()); // Automatic shorten the route
326  break;
327  }
328  else
329  {
330  break;
331  }
332  }
333  else if (j == (vec.end () - 1))
334  {
335  vec.push_back (*i);
336  break;
337  }
338  else
339  {
340  continue;
341  }
342  }
343  }
344  }
345 }
346 
347 uint32_t
349 {
350  NS_LOG_FUNCTION (this << address);
351  int32_t nNodes = NodeList::GetNNodes ();
352  for (int32_t i = 0; i < nNodes; ++i)
353  {
354  Ptr<Node> node = NodeList::GetNode (i);
355  Ptr<Ipv4> ipv4 = node->GetObject<Ipv4> ();
356  if (ipv4->GetAddress (1, 0).GetLocal () == address)
357  {
358  return i;
359  }
360  }
361  return 255;
362 }
363 
365 {
366  NS_LOG_FUNCTION (this << ipv4Address);
367  int32_t nNodes = NodeList::GetNNodes ();
368  for (int32_t i = 0; i < nNodes; ++i)
369  {
370  Ptr<Node> node = NodeList::GetNode (i);
371  Ptr<Ipv4> ipv4 = node->GetObject<Ipv4> ();
372  int32_t ifIndex = ipv4->GetInterfaceForAddress (ipv4Address);
373  if (ifIndex != -1)
374  {
375  return node;
376  }
377  }
378  return 0;
379 }
380 
382 
384 {
385  static TypeId tid = TypeId ("ns3::dsr::DsrOptionPad1")
386  .SetParent<DsrOptions> ()
387  .AddConstructor<DsrOptionPad1> ()
388  ;
389  return tid;
390 }
391 
393 {
395 }
396 
398 {
400 }
401 
403 {
405 
406  return OPT_NUMBER;
407 }
408 
409 uint8_t DsrOptionPad1::Process (Ptr<Packet> packet, Ptr<Packet> dsrP, Ipv4Address ipv4Address, Ipv4Address source, Ipv4Header const& ipv4Header, uint8_t protocol, bool& isPromisc, Ipv4Address promiscSource)
410 {
411  NS_LOG_FUNCTION (this << packet << dsrP << ipv4Address << source << ipv4Header << (uint32_t)protocol << isPromisc);
412  Ptr<Packet> p = packet->Copy ();
413  DsrOptionPad1Header pad1Header;
414  p->RemoveHeader (pad1Header);
415 
416  isPromisc = false;
417 
418  return pad1Header.GetSerializedSize ();
419 }
420 
422 
424 {
425  static TypeId tid = TypeId ("ns3::dsr::DsrOptionPadn")
426  .SetParent<DsrOptions> ()
427  .AddConstructor<DsrOptionPadn> ()
428  ;
429  return tid;
430 }
431 
433 {
435 }
436 
438 {
440 }
441 
443 {
445  return OPT_NUMBER;
446 }
447 
448 uint8_t DsrOptionPadn::Process (Ptr<Packet> packet, Ptr<Packet> dsrP, Ipv4Address ipv4Address, Ipv4Address source, Ipv4Header const& ipv4Header, uint8_t protocol, bool& isPromisc, Ipv4Address promiscSource)
449 {
450  NS_LOG_FUNCTION (this << packet << dsrP << ipv4Address << source << ipv4Header << (uint32_t)protocol << isPromisc);
451 
452  Ptr<Packet> p = packet->Copy ();
453  DsrOptionPadnHeader padnHeader;
454  p->RemoveHeader (padnHeader);
455 
456  isPromisc = false;
457 
458  return padnHeader.GetSerializedSize ();
459 }
460 
462 
464 {
465  static TypeId tid = TypeId ("ns3::dsr::DsrOptionRreq")
466  .SetParent<DsrOptions> ()
467  .AddConstructor<DsrOptionRreq> ()
468  ;
469  return tid;
470 }
471 
473 {
474  return GetTypeId ();
475 }
476 
478 {
480 }
481 
483 {
485 }
486 
488 {
490 
491  return OPT_NUMBER;
492 }
493 
494 uint8_t DsrOptionRreq::Process (Ptr<Packet> packet, Ptr<Packet> dsrP, Ipv4Address ipv4Address, Ipv4Address source, Ipv4Header const& ipv4Header, uint8_t protocol, bool& isPromisc, Ipv4Address promiscSource)
495 {
496  NS_LOG_FUNCTION (this << packet << dsrP << ipv4Address << source << ipv4Header << (uint32_t)protocol << isPromisc);
497  // Fields from IP header
498  Ipv4Address srcAddress = ipv4Header.GetSource ();
499  /*
500  * \ when the ip source address is equal to the address of our own, this is request packet originated
501  * \ by the node itself, discard it
502  */
503  if (source == ipv4Address)
504  {
505  NS_LOG_DEBUG ("Discard the packet since it was originated from same source address");
506  m_dropTrace (packet); // call the drop trace to show in the tracing
507  return 0;
508  }
509  /*
510  * Get the node associated with the ipv4 address and get several objects from the node and leave for further use
511  */
512  Ptr<Node> node = GetNodeWithAddress (ipv4Address);
514 
515  Ptr<Packet> p = packet->Copy (); // Note: The packet here doesn't contain the fixed size dsr header
516  /*
517  * \brief Get the number of routers' address field before removing the header
518  * \peek the packet and get the value
519  */
520  uint8_t buf[2];
521  p->CopyData (buf, sizeof(buf));
522  uint8_t numberAddress = (buf[1] - 6) / 4;
523  NS_LOG_DEBUG ("The number of Ip addresses " << (uint32_t)numberAddress);
524  if (numberAddress >= 255)
525  {
526  NS_LOG_DEBUG ("Discard the packet, malformed header since two many ip addresses in route");
527  m_dropTrace (packet); // call the drop trace to show in the tracing
528  return 0;
529  }
530 
531  /*
532  * Create the dsr rreq header
533  */
534  DsrOptionRreqHeader rreq;
535  /*
536  * Set the number of addresses with the value from peek data and remove the rreq header
537  */
538  rreq.SetNumberAddress (numberAddress);
539  // Remove the route request header
540  p->RemoveHeader (rreq);
541  // Verify the option length
542  uint8_t length = rreq.GetLength ();
543  if (length % 2 != 0)
544  {
545  NS_LOG_LOGIC ("Malformed header. Drop!");
546  m_dropTrace (packet); // call drop trace
547  return 0;
548  }
549  // Check the rreq id for verifying the request id
550  uint16_t requestId = rreq.GetId ();
551  // The target address is where we want to send the data packets
552  Ipv4Address targetAddress = rreq.GetTarget ();
553  // Get the node list and source address from the route request header
554  std::vector<Ipv4Address> mainVector = rreq.GetNodesAddresses ();
555  std::vector<Ipv4Address> nodeList (mainVector);
556  // Get the real source address of this request, it will be used when checking if we have received the save
557  // route request before or not
558  Ipv4Address sourceAddress = nodeList.front ();
559  PrintVector (nodeList);
560  /*
561  * Construct the dsr routing header for later use
562  */
563  DsrRoutingHeader dsrRoutingHeader;
564  dsrRoutingHeader.SetNextHeader (protocol);
565  dsrRoutingHeader.SetMessageType (1);
566  dsrRoutingHeader.SetSourceId (GetIDfromIP (source));
567  dsrRoutingHeader.SetDestId (255);
568 
569  // check whether we have received this request or not, if not, it will save the request in the table for
570  // later use, if not found, return false, and push the newly received source request entry in the cache
571 
572  // Get the TTL value, this is used to test if the packet will be forwarded or not
573  uint8_t ttl = ipv4Header.GetTtl ();
574  bool dupRequest = false; // initialize the duplicate request check value
575  if (ttl)
576  {
577  // if the ttl value is not 0, then this request will be forwarded, then we need to
578  // save it in the source entry
579  dupRequest = dsr->FindSourceEntry (sourceAddress, targetAddress, requestId);
580  }
581  /*
582  * Before processing the route request, we need to check two things
583  * 1. if this is the exact same request we have just received, ignore it
584  * 2. if our address is already in the path list, ignore it
585  * 3. otherwise process further
586  */
587 
588  if (dupRequest)
589  {
590  // We have received this same route reqeust before, not forwarding it now
591  NS_LOG_LOGIC ("Duplicate request. Drop!");
592  m_dropTrace (packet); // call drop trace
593  return 0;
594  }
595 
596  else if (CheckDuplicates (ipv4Address, nodeList))
597  {
598  /*
599  * if the route contains the node address already, drop the request packet
600  */
601  m_dropTrace (packet); // call drop trace
602  NS_LOG_DEBUG ("Our node address is already seen in the route, drop the request");
603  return 0;
604  }
605  else
606  {
607  // A node ignores all RREQs received from any node in its blacklist
608  RouteCacheEntry toPrev;
609  bool isRouteInCache = dsr->LookupRoute (targetAddress,
610  toPrev);
611  RouteCacheEntry::IP_VECTOR ip = toPrev.GetVector (); // The route from our own route cache to dst
612  PrintVector (ip);
613  std::vector<Ipv4Address> saveRoute (nodeList);
614  PrintVector (saveRoute);
615  bool areThereDuplicates = IfDuplicates (ip,
616  saveRoute);
617  /*
618  * When the reverse route is created or updated, the following actions on the route are also carried out:
619  * 3. the next hop in the routing table becomes the node from which the RREQ was received
620  * 4. the hop count is copied from the Hop Count in the RREQ message;
621  */
622 
623  // A node generates a RREP if either:
624  // (i) it is itself the destination,
625  /*
626  * The target address equal to our own ip address
627  */
628  NS_LOG_DEBUG ("The target address over here " << targetAddress << " and the ip address " << ipv4Address << " and the source address " << mainVector[0]);
629  if (targetAddress == ipv4Address)
630  {
631  Ipv4Address nextHop; // Declare the next hop address to use
632  if (nodeList.size () == 1)
633  {
634  NS_LOG_DEBUG ("These two nodes are neighbors");
635  m_finalRoute.clear ();
637  m_finalRoute.push_back (source); // push back the request originator's address
638  m_finalRoute.push_back (ipv4Address); // push back our own address
639  nextHop = srcAddress;
640  }
641  else
642  {
643  std::vector<Ipv4Address> changeRoute (nodeList);
644  changeRoute.push_back (ipv4Address); // push back our own address
645  m_finalRoute.clear (); // get a clear route vector
646  for (std::vector<Ipv4Address>::iterator i = changeRoute.begin (); i != changeRoute.end (); ++i)
647  {
648  m_finalRoute.push_back (*i); // Get the full route from source to destination
649  }
651  nextHop = ReverseSearchNextHop (ipv4Address, m_finalRoute); // get the next hop
652  }
653 
654  DsrOptionRrepHeader rrep;
655  rrep.SetNodesAddress (m_finalRoute); // Set the node addresses in the route reply header
656  NS_LOG_DEBUG ("The nextHop address " << nextHop);
657  Ipv4Address replyDst = m_finalRoute.front ();
658  /*
659  * This part add dsr header to the packet and send route reply packet
660  */
661  DsrRoutingHeader dsrRoutingHeader;
662  dsrRoutingHeader.SetNextHeader (protocol);
663  dsrRoutingHeader.SetMessageType (1);
664  dsrRoutingHeader.SetSourceId (GetIDfromIP (ipv4Address));
665  dsrRoutingHeader.SetDestId (GetIDfromIP (replyDst));
666  // Set the route for route reply
667  SetRoute (nextHop, ipv4Address);
668 
669  uint8_t length = rrep.GetLength (); // Get the length of the rrep header excluding the type header
670  dsrRoutingHeader.SetPayloadLength (length + 2);
671  dsrRoutingHeader.AddDsrOption (rrep);
672  Ptr<Packet> newPacket = Create<Packet> ();
673  newPacket->AddHeader (dsrRoutingHeader);
674  dsr->ScheduleInitialReply (newPacket, ipv4Address, nextHop, m_ipv4Route);
675  /*
676  * Create the route entry to the rreq originator and save it to route cache, also need to reverse the route
677  */
680  {
682  Ipv4Address dst = m_finalRoute.back ();
683  bool addRoute = false;
684  if (numberAddress > 0)
685  {
686  RouteCacheEntry toSource (/*IP_VECTOR=*/ m_finalRoute, /*dst=*/
687  dst, /*expire time=*/ ActiveRouteTimeout);
688  if (dsr->IsLinkCache ())
689  {
690  addRoute = dsr->AddRoute_Link (m_finalRoute, ipv4Address);
691  }
692  else
693  {
694  addRoute = dsr->AddRoute (toSource);
695  }
696  }
697  else
698  {
699  NS_LOG_DEBUG ("Abnormal RouteRequest");
700  return 0;
701  }
702 
703  if (addRoute)
704  {
705  /*
706  * Found a route to the dst, construct the source route option header
707  */
708  DsrOptionSRHeader sourceRoute;
709  NS_LOG_DEBUG ("The route length " << m_finalRoute.size ());
710  sourceRoute.SetNodesAddress (m_finalRoute);
711 
715  // if (dsr->IsLinkCache ())
716  // {
717  // dsr->UseExtends (m_finalRoute);
718  // }
719  sourceRoute.SetSegmentsLeft ((m_finalRoute.size () - 2));
720  // The salvage value here is 0
721  sourceRoute.SetSalvage (0);
722  Ipv4Address nextHop = SearchNextHop (ipv4Address, m_finalRoute); // Get the next hop address
723  NS_LOG_DEBUG ("The nextHop address " << nextHop);
724 
725  if (nextHop == "0.0.0.0")
726  {
727  dsr->PacketNewRoute (dsrP, ipv4Address, dst, protocol);
728  return 0;
729  }
730  SetRoute (nextHop, ipv4Address);
731  /*
732  * Send the data packet from the send buffer
733  */
734  dsr->SendPacketFromBuffer (sourceRoute, nextHop, protocol);
735  // Cancel the route request timer for destination after sending the data packet
736  dsr->CancelRreqTimer (dst, true);
737  }
738  else
739  {
740  NS_LOG_DEBUG ("The route is failed to add in cache");
741  return 0;
742  }
743  }
744  else
745  {
746  NS_LOG_DEBUG ("Unable to reverse route");
747  return 0;
748  }
749  isPromisc = false;
750  return rreq.GetSerializedSize ();
751  }
752 
753  /*
754  * (ii) or it has an active route to the destination, send reply based on request header and route cache,
755  * need to delay based on a random value from d = H * (h - 1 + r), which can avoid possible route
756  * reply storm. Also, verify if two vectors do not contain duplicates (part of the route to the
757  * destination from route cache and route collected so far). If so, do not use the route found
758  * and forward the route request.
759  */
760  else if (isRouteInCache && !areThereDuplicates)
761  {
762  m_finalRoute.clear (); // Clear the final route vector
766  for (std::vector<Ipv4Address>::iterator i = saveRoute.begin (); i != saveRoute.end (); ++i)
767  {
768  m_finalRoute.push_back (*i);
769  }
773  for (std::vector<Ipv4Address>::iterator j = ip.begin (); j != ip.end (); ++j)
774  {
775  m_finalRoute.push_back (*j);
776  }
777  /*
778  * Create the route entry to the rreq originator and save it to route cache, also need to reverse the route
779  */
780  bool addRoute = false;
781  std::vector<Ipv4Address> reverseRoute (m_finalRoute);
782 
783  if (ReverseRoutes (reverseRoute))
784  {
785  saveRoute.push_back (ipv4Address);
786  ReverseRoutes (saveRoute);
787  Ipv4Address dst = saveRoute.back ();
788  NS_LOG_DEBUG ("This is the route save in route cache");
789  PrintVector (saveRoute);
790 
791  RouteCacheEntry toSource (/*IP_VECTOR=*/ saveRoute, /*dst=*/ dst, /*expire time=*/ ActiveRouteTimeout);
792  NS_ASSERT (saveRoute.front () == ipv4Address);
793  // Add the route entry in the route cache
794  if (dsr->IsLinkCache ())
795  {
796  addRoute = dsr->AddRoute_Link (saveRoute, ipv4Address);
797  }
798  else
799  {
800  addRoute = dsr->AddRoute (toSource);
801  }
802 
803  if (addRoute)
804  {
805  NS_LOG_LOGIC ("We have added the route and search send buffer for packet with destination " << dst);
806  /*
807  * Found a route the dst, construct the source route option header
808  */
809  DsrOptionSRHeader sourceRoute;
810  PrintVector (saveRoute);
811 
812  sourceRoute.SetNodesAddress (saveRoute);
813  // if (dsr->IsLinkCache ())
814  // {
815  // dsr->UseExtends (saveRoute);
816  // }
817  sourceRoute.SetSegmentsLeft ((saveRoute.size () - 2));
818  uint8_t salvage = 0;
819  sourceRoute.SetSalvage (salvage);
820  Ipv4Address nextHop = SearchNextHop (ipv4Address, saveRoute); // Get the next hop address
821  NS_LOG_DEBUG ("The nextHop address " << nextHop);
822 
823  if (nextHop == "0.0.0.0")
824  {
825  dsr->PacketNewRoute (dsrP, ipv4Address, dst, protocol);
826  return 0;
827  }
828  SetRoute (nextHop, ipv4Address);
829  /*
830  * Schedule the packet retry
831  */
832  dsr->SendPacketFromBuffer (sourceRoute, nextHop, protocol);
833  // Cancel the route request timer for destination
834  dsr->CancelRreqTimer (dst, true);
835  }
836  else
837  {
838  NS_LOG_DEBUG ("The route is failed to add in cache");
839  return 0;
840  }
841  }
842  else
843  {
844  NS_LOG_DEBUG ("Unable to reverse the route");
845  return 0;
846  }
847 
848  /*
849  * Need to first pin down the next hop address before removing duplicates
850  */
851  Ipv4Address nextHop = ReverseSearchNextHop (ipv4Address, m_finalRoute);
852  /*
853  * First remove the duplicate ip address to automatically shorten the route, and then reversely
854  * search the next hop address
855  */
856  // Set the route
857  SetRoute (nextHop, ipv4Address);
858 
859  uint16_t hops = m_finalRoute.size ();
860  DsrOptionRrepHeader rrep;
861  rrep.SetNodesAddress (m_finalRoute); // Set the node addresses in the route reply header
862  // Get the real source of the reply
863  Ipv4Address realSource = m_finalRoute.back ();
865  NS_LOG_DEBUG ("This is the full route from " << realSource << " to " << m_finalRoute.front ());
866  /*
867  * This part add dsr header to the packet and send route reply packet
868  */
869  DsrRoutingHeader dsrRoutingHeader;
870  dsrRoutingHeader.SetNextHeader (protocol);
871  dsrRoutingHeader.SetMessageType (1);
872  dsrRoutingHeader.SetSourceId (GetIDfromIP (realSource));
873  dsrRoutingHeader.SetDestId (255);
874 
875  uint8_t length = rrep.GetLength (); // Get the length of the rrep header excluding the type header
876  dsrRoutingHeader.SetPayloadLength (length + 2);
877  dsrRoutingHeader.AddDsrOption (rrep);
878  Ptr<Packet> newPacket = Create<Packet> ();
879  newPacket->AddHeader (dsrRoutingHeader);
880  dsr->ScheduleCachedReply (newPacket, ipv4Address, nextHop, m_ipv4Route, hops);
881  isPromisc = false;
882  return rreq.GetSerializedSize ();
883  }
884  /*
885  * (iii) no route in any type has been found
886  */
887  else
888  {
889  mainVector.push_back (ipv4Address);
890  NS_ASSERT (mainVector.front () == source);
891  NS_LOG_DEBUG ("Print out the main vector");
892  PrintVector (mainVector);
893  rreq.SetNodesAddress (mainVector);
894 
895  Ptr<Packet> errP = p->Copy ();
896  if (errP->GetSize ())
897  {
898  NS_LOG_DEBUG ("Error header included");
900  p->RemoveHeader (rerr);
901  Ipv4Address errorSrc = rerr.GetErrorSrc ();
902  Ipv4Address unreachNode = rerr.GetUnreachNode ();
903  Ipv4Address errorDst = rerr.GetErrorDst ();
904 
905  if ((errorSrc == srcAddress) && (unreachNode == ipv4Address))
906  {
907  NS_LOG_DEBUG ("The error link back to work again");
908  uint16_t length = rreq.GetLength ();
909  NS_LOG_DEBUG ("The RREQ header length " << length);
910  dsrRoutingHeader.AddDsrOption (rreq);
911  dsrRoutingHeader.SetPayloadLength (length + 2);
912  }
913  else
914  {
915  dsr->DeleteAllRoutesIncludeLink (errorSrc, unreachNode, ipv4Address);
916 
917  DsrOptionRerrUnreachHeader newUnreach;
918  newUnreach.SetErrorType (1);
919  newUnreach.SetErrorSrc (errorSrc);
920  newUnreach.SetUnreachNode (unreachNode);
921  newUnreach.SetErrorDst (errorDst);
922  newUnreach.SetSalvage (rerr.GetSalvage ()); // Set the value about whether to salvage a packet or not
923  uint16_t length = rreq.GetLength () + newUnreach.GetLength ();
924  NS_LOG_DEBUG ("The RREQ and newUnreach header length " << length);
925  dsrRoutingHeader.SetPayloadLength (length + 4);
926  dsrRoutingHeader.AddDsrOption (rreq);
927  dsrRoutingHeader.AddDsrOption (newUnreach);
928  }
929  }
930  else
931  {
932  uint16_t length = rreq.GetLength ();
933  NS_LOG_DEBUG ("The RREQ header length " << length);
934  dsrRoutingHeader.AddDsrOption (rreq);
935  dsrRoutingHeader.SetPayloadLength (length + 2);
936  }
937  // Get the TTL value
938  uint8_t ttl = ipv4Header.GetTtl ();
939  /*
940  * Decrease the TTL value in the packet tag by one, this tag will go to ip layer 3 send function
941  * and drop packet when TTL value equals to 0
942  */
943  NS_LOG_DEBUG ("The ttl value here " << (uint32_t)ttl);
944  if (ttl)
945  {
946  Ptr<Packet> interP = Create<Packet> ();
947  SocketIpTtlTag tag;
948  tag.SetTtl (ttl - 1);
949  interP->AddPacketTag (tag);
950  interP->AddHeader (dsrRoutingHeader);
951  dsr->ScheduleInterRequest (interP);
952  isPromisc = false;
953  }
954  return rreq.GetSerializedSize ();
955  }
956  }
957  //unreachable: return rreq.GetSerializedSize ();
958 }
959 
961 
963 {
964  static TypeId tid = TypeId ("ns3::dsr::DsrOptionRrep")
965  .SetParent<DsrOptions> ()
966  .AddConstructor<DsrOptionRrep> ()
967  ;
968  return tid;
969 }
970 
972 {
974 }
975 
977 {
979 }
980 
982 {
983  return GetTypeId ();
984 }
985 
987 {
989 
990  return OPT_NUMBER;
991 }
992 
993 uint8_t DsrOptionRrep::Process (Ptr<Packet> packet, Ptr<Packet> dsrP, Ipv4Address ipv4Address, Ipv4Address source, Ipv4Header const& ipv4Header, uint8_t protocol, bool& isPromisc, Ipv4Address promiscSource)
994 {
995  NS_LOG_FUNCTION (this << packet << dsrP << ipv4Address << source << ipv4Header << (uint32_t)protocol << isPromisc);
996 
997  Ptr<Packet> p = packet->Copy ();
998 
999  // Get the number of routers' address field
1000  uint8_t buf[2];
1001  p->CopyData (buf, sizeof(buf));
1002  uint8_t numberAddress = (buf[1] - 2) / 4;
1003 
1004  DsrOptionRrepHeader rrep;
1005  rrep.SetNumberAddress (numberAddress); // Set the number of ip address in the header to reserver space for deserialize header
1006  p->RemoveHeader (rrep);
1007 
1008  Ptr<Node> node = GetNodeWithAddress (ipv4Address);
1010 
1011  NS_LOG_DEBUG ("The next header value " << (uint32_t)protocol);
1012 
1013  std::vector<Ipv4Address> nodeList = rrep.GetNodesAddress ();
1017  Ipv4Address targetAddress = nodeList.front ();
1018  // If the RREP option has reached to the destination
1019  if (targetAddress == ipv4Address)
1020  {
1021  RemoveDuplicates (nodeList); // This is for the route reply from intermediate node since we didn't remove
1022  // duplicate there
1023  if (nodeList.size () == 0)
1024  {
1025  NS_LOG_DEBUG ("The route we have contains 0 entries");
1026  return 0;
1027  }
1031  Ipv4Address dst = nodeList.back ();
1037  RouteCacheEntry toDestination (/*IP_VECTOR=*/ nodeList, /*dst=*/ dst, /*expire time=*/ ActiveRouteTimeout);
1038  NS_ASSERT (nodeList.front () == ipv4Address);
1039  bool addRoute = false;
1040  if (dsr->IsLinkCache ())
1041  {
1042  addRoute = dsr->AddRoute_Link (nodeList, ipv4Address);
1043  }
1044  else
1045  {
1046  addRoute = dsr->AddRoute (toDestination);
1047  }
1048 
1049  if (addRoute)
1050  {
1051  NS_LOG_DEBUG ("We have added the route and search send buffer for packet with destination " << dst);
1055  DsrOptionSRHeader sourceRoute;
1056  NS_LOG_DEBUG ("The route length " << nodeList.size ());
1057  sourceRoute.SetNodesAddress (nodeList);
1058  sourceRoute.SetSegmentsLeft ((nodeList.size () - 2));
1059  sourceRoute.SetSalvage (0);
1060  Ipv4Address nextHop = SearchNextHop (ipv4Address, nodeList); // Get the next hop address
1061  NS_LOG_DEBUG ("The nextHop address " << nextHop);
1062  if (nextHop == "0.0.0.0")
1063  {
1064  dsr->PacketNewRoute (dsrP, ipv4Address, dst, protocol);
1065  return 0;
1066  }
1067  PrintVector (nodeList);
1068  SetRoute (nextHop, ipv4Address);
1069  // Cancel the route request timer for destination
1070  dsr->CancelRreqTimer (dst, true);
1074  dsr->SendPacketFromBuffer (sourceRoute, nextHop, protocol);
1075  }
1076  else
1077  {
1078  NS_LOG_DEBUG ("Failed to add the route");
1079  return 0;
1080  }
1081  }
1082  else
1083  {
1084  uint8_t length = rrep.GetLength () - 2; // The get length - 2 is to get aligned for the malformed header check
1085  NS_LOG_DEBUG ("The length of rrep option " << (uint32_t)length);
1086 
1087  if (length % 2 != 0)
1088  {
1089  NS_LOG_LOGIC ("Malformed header. Drop!");
1090  m_dropTrace (packet);
1091  return 0;
1092  }
1093  PrintVector (nodeList);
1094  /*
1095  * This node is only an intermediate node, but it needs to save the possible route to the destination when cutting the route
1096  */
1097  std::vector<Ipv4Address> routeCopy = nodeList;
1098  std::vector<Ipv4Address> cutRoute = CutRoute (ipv4Address, nodeList);
1099  PrintVector (cutRoute);
1100  if (cutRoute.size () >= 2)
1101  {
1102  Ipv4Address dst = cutRoute.back ();
1103  NS_LOG_DEBUG ("The route destination after cut " << dst);
1104  RouteCacheEntry toDestination (/*IP_VECTOR=*/ cutRoute, /*dst=*/ dst, /*expire time=*/ ActiveRouteTimeout);
1105  NS_ASSERT (cutRoute.front () == ipv4Address);
1106  bool addRoute = false;
1107  if (dsr->IsLinkCache ())
1108  {
1109  addRoute = dsr->AddRoute_Link (nodeList, ipv4Address);
1110  }
1111  else
1112  {
1113  addRoute = dsr->AddRoute (toDestination);
1114  }
1115  if (addRoute)
1116  {
1117  dsr->CancelRreqTimer (dst, true);
1118  }
1119  else
1120  {
1121  NS_LOG_DEBUG ("The route not added");
1122  }
1123  }
1124  else
1125  {
1126  NS_LOG_DEBUG ("The route is corrupted");
1127  }
1128  /*
1129  * Reverse search the vector for next hop address
1130  */
1131  Ipv4Address nextHop = ReverseSearchNextHop (ipv4Address, routeCopy);
1132  NS_ASSERT (routeCopy.back () == source);
1133  PrintVector (routeCopy);
1134  NS_LOG_DEBUG ("The nextHop address " << nextHop << " and the source in the route reply " << source);
1135  /*
1136  * Set the route entry we will use to send reply
1137  */
1138  SetRoute (nextHop, ipv4Address);
1139  /*
1140  * This part add dsr routing header to the packet and send reply
1141  */
1142  DsrRoutingHeader dsrRoutingHeader;
1143  dsrRoutingHeader.SetNextHeader (protocol);
1144 
1145  length = rrep.GetLength (); // Get the length of the rrep header excluding the type header
1146  NS_LOG_DEBUG ("The reply header length " << (uint32_t)length);
1147  dsrRoutingHeader.SetPayloadLength (length + 2);
1148  dsrRoutingHeader.SetMessageType (1);
1149  dsrRoutingHeader.SetSourceId (GetIDfromIP (source));
1150  dsrRoutingHeader.SetDestId (GetIDfromIP (targetAddress));
1151  dsrRoutingHeader.AddDsrOption (rrep);
1152  Ptr<Packet> newPacket = Create<Packet> ();
1153  newPacket->AddHeader (dsrRoutingHeader);
1154  dsr->SendReply (newPacket, ipv4Address, nextHop, m_ipv4Route);
1155  isPromisc = false;
1156  }
1157  return rrep.GetSerializedSize ();
1158 }
1159 
1161 
1163 {
1164  static TypeId tid = TypeId ("ns3::dsr::DsrOptionSR")
1165  .SetParent<DsrOptions> ()
1166  .AddConstructor<DsrOptionSR> ()
1167  ;
1168  return tid;
1169 }
1170 
1172 {
1174 }
1175 
1177 {
1179 }
1180 
1182 {
1183  return GetTypeId ();
1184 }
1185 
1187 {
1189  return OPT_NUMBER;
1190 }
1191 
1192 uint8_t DsrOptionSR::Process (Ptr<Packet> packet, Ptr<Packet> dsrP, Ipv4Address ipv4Address, Ipv4Address source, Ipv4Header const& ipv4Header, uint8_t protocol, bool& isPromisc, Ipv4Address promiscSource)
1193 {
1194  NS_LOG_FUNCTION (this << packet << dsrP << ipv4Address << source << ipv4Address << ipv4Header << (uint32_t)protocol << isPromisc);
1195  Ptr<Packet> p = packet->Copy ();
1196  // Get the number of routers' address field
1197  uint8_t buf[2];
1198  p->CopyData (buf, sizeof(buf));
1199  uint8_t numberAddress = (buf[1] - 2) / 4;
1200  DsrOptionSRHeader sourceRoute;
1201  sourceRoute.SetNumberAddress (numberAddress);
1202  p->RemoveHeader (sourceRoute);
1203 
1204  // The route size saved in the source route
1205  std::vector<Ipv4Address> nodeList = sourceRoute.GetNodesAddress ();
1206  uint8_t segsLeft = sourceRoute.GetSegmentsLeft ();
1207  uint8_t salvage = sourceRoute.GetSalvage ();
1208  /*
1209  * Get the node from IP address and get the DSR extension object
1210  */
1211  Ptr<Node> node = GetNodeWithAddress (ipv4Address);
1213  /*
1214  * Get the source and destination address from ipv4 header
1215  */
1216  Ipv4Address srcAddress = ipv4Header.GetSource ();
1217  Ipv4Address destAddress = ipv4Header.GetDestination ();
1218 
1219  // Get the node list destination
1220  Ipv4Address destination = nodeList.back ();
1221  /*
1222  * If it's a promiscuous receive data packet,
1223  * 1. see if automatic route shortening possible or not
1224  * 2. see if it is a passive acknowledgment
1225  */
1226  if (isPromisc)
1227  {
1228  NS_LOG_LOGIC ("We process promiscuous receipt data packet");
1229  if (ContainAddressAfter (ipv4Address, destAddress, nodeList))
1230  {
1231  NS_LOG_LOGIC ("Send back the gratuitous reply");
1232  dsr->SendGratuitousReply (source, srcAddress, nodeList, protocol);
1233  }
1234 
1235  uint16_t fragmentOffset = ipv4Header.GetFragmentOffset ();
1236  uint16_t identification = ipv4Header.GetIdentification ();
1237 
1238  if (destAddress != destination)
1239  {
1240  NS_LOG_DEBUG ("Process the promiscuously received packet");
1241  bool findPassive = false;
1242  int32_t nNodes = NodeList::GetNNodes ();
1243  for (int32_t i = 0; i < nNodes; ++i)
1244  {
1245  NS_LOG_DEBUG ("Working with node " << i);
1246 
1247  Ptr<Node> node = NodeList::GetNode (i);
1248  Ptr<dsr::DsrRouting> dsrNode = node->GetObject<dsr::DsrRouting> ();
1249  // The source and destination addresses here are the real source and destination for the packet
1250  findPassive = dsrNode->PassiveEntryCheck (packet, source, destination, segsLeft, fragmentOffset, identification, false);
1251  if (findPassive)
1252  {
1253  break;
1254  }
1255  }
1256 
1257  if (findPassive)
1258  {
1259  NS_LOG_DEBUG ("We find one previously received passive entry");
1260  /*
1261  * Get the node from IP address and get the DSR extension object
1262  * the srcAddress would be the source address from ip header
1263  */
1264  PrintVector (nodeList);
1265 
1266  NS_LOG_DEBUG ("promisc source " << promiscSource);
1267  Ptr<Node> node = GetNodeWithAddress (promiscSource);
1268  Ptr<dsr::DsrRouting> dsrSrc = node->GetObject<dsr::DsrRouting> ();
1269  dsrSrc->CancelPassiveTimer (packet, source, destination, segsLeft);
1270  }
1271  else
1272  {
1273  NS_LOG_DEBUG ("Saved the entry for further use");
1274  dsr->PassiveEntryCheck (packet, source, destination, segsLeft, fragmentOffset, identification, true);
1275  }
1276  }
1278  return 0;
1279  }
1280  else
1281  {
1282  /*
1283  * Get the number of address from the source route header
1284  */
1285  uint8_t length = sourceRoute.GetLength ();
1286  uint8_t nextAddressIndex;
1287  Ipv4Address nextAddress;
1288 
1289  // Get the option type value
1290  uint32_t size = p->GetSize ();
1291  uint8_t *data = new uint8_t[size];
1292  p->CopyData (data, size);
1293  uint8_t optionType = 0;
1294  optionType = *(data);
1297  if (optionType == 160)
1298  {
1299  NS_LOG_LOGIC ("Remove the ack request header and add ack header to the packet");
1300  // Here we remove the ack packet to the previous hop
1301  DsrOptionAckReqHeader ackReq;
1302  p->RemoveHeader (ackReq);
1303  uint16_t ackId = ackReq.GetAckId ();
1304  /*
1305  * Send back acknowledgment packet to the earlier hop
1306  * If the node list is not empty, find the previous hop from the node list,
1307  * otherwise, use srcAddress
1308  */
1309  Ipv4Address ackAddress = srcAddress;
1310  if (!nodeList.empty ())
1311  {
1312  if (segsLeft > numberAddress) // The segmentsLeft field should not be larger than the total number of ip addresses
1313  {
1314  NS_LOG_LOGIC ("Malformed header. Drop!");
1315  m_dropTrace (packet);
1316  return 0;
1317  }
1318  // -fstrict-overflow sensitive, see bug 1868
1319  if (numberAddress - segsLeft < 2) // The index is invalid
1320  {
1321  NS_LOG_LOGIC ("Malformed header. Drop!");
1322  m_dropTrace (packet);
1323  return 0;
1324  }
1325  ackAddress = nodeList[numberAddress - segsLeft - 2];
1326  }
1327  m_ipv4Route = SetRoute (ackAddress, ipv4Address);
1328  NS_LOG_DEBUG ("Send back ACK to the earlier hop " << ackAddress << " from us " << ipv4Address);
1329  dsr->SendAck (ackId, ackAddress, source, destination, protocol, m_ipv4Route);
1330  }
1331  /*
1332  * After send back ACK, check if the segments left value has turned to 0 or not, if yes, update the route entry
1333  * and return header length
1334  */
1335  if (segsLeft == 0)
1336  {
1337  NS_LOG_DEBUG ("This is the final destination");
1338  isPromisc = false;
1339  return sourceRoute.GetSerializedSize ();
1340  }
1341 
1342  if (length % 2 != 0)
1343  {
1344  NS_LOG_LOGIC ("Malformed header. Drop!");
1345  m_dropTrace (packet);
1346  return 0;
1347  }
1348 
1349  if (segsLeft > numberAddress) // The segmentsLeft field should not be larger than the total number of ip addresses
1350  {
1351  NS_LOG_LOGIC ("Malformed header. Drop!");
1352  m_dropTrace (packet);
1353  return 0;
1354  }
1355 
1356  DsrOptionSRHeader newSourceRoute;
1357  newSourceRoute.SetSegmentsLeft (segsLeft - 1);
1358  newSourceRoute.SetSalvage (salvage);
1359  newSourceRoute.SetNodesAddress (nodeList);
1360  nextAddressIndex = numberAddress - segsLeft;
1361  nextAddress = newSourceRoute.GetNodeAddress (nextAddressIndex);
1362  NS_LOG_DEBUG ("The next address of source route option " << nextAddress << " and the nextAddressIndex: " << (uint32_t)nextAddressIndex << " and the segments left : " << (uint32_t)segsLeft);
1363  /*
1364  * Get the target Address in the node list
1365  */
1366  Ipv4Address targetAddress = nodeList.back ();
1367  Ipv4Address realSource = nodeList.front ();
1368  /*
1369  * Search the vector for next hop address
1370  */
1371  Ipv4Address nextHop = SearchNextHop (ipv4Address, nodeList);
1372  PrintVector (nodeList);
1373 
1374  if (nextHop == "0.0.0.0")
1375  {
1376  NS_LOG_DEBUG ("Before new packet " << *dsrP);
1377  dsr->PacketNewRoute (dsrP, realSource, targetAddress, protocol);
1378  return 0;
1379  }
1380 
1381  if (ipv4Address == nextHop)
1382  {
1383  NS_LOG_DEBUG ("We have reached the destination");
1384  newSourceRoute.SetSegmentsLeft (0);
1385  return newSourceRoute.GetSerializedSize ();
1386  }
1387  // Verify the multicast address, leave it here for now
1388  if (nextAddress.IsMulticast () || destAddress.IsMulticast ())
1389  {
1390  m_dropTrace (packet);
1391  return 0;
1392  }
1393  // Set the route and forward the data packet
1394  SetRoute (nextAddress, ipv4Address);
1395  NS_LOG_DEBUG ("dsr packet size " << dsrP->GetSize ());
1396  dsr->ForwardPacket (dsrP, newSourceRoute, ipv4Header, realSource, nextAddress, targetAddress, protocol, m_ipv4Route);
1397  }
1398  return sourceRoute.GetSerializedSize ();
1399 }
1400 
1402 
1404 {
1405  static TypeId tid = TypeId ("ns3::dsr::DsrOptionRerr")
1406  .SetParent<DsrOptions> ()
1407  .AddConstructor<DsrOptionRerr> ()
1408  ;
1409  return tid;
1410 }
1411 
1413 {
1415 }
1416 
1418 {
1420 }
1421 
1423 {
1424  return GetTypeId ();
1425 }
1426 
1428 {
1430  return OPT_NUMBER;
1431 }
1432 
1433 uint8_t DsrOptionRerr::Process (Ptr<Packet> packet, Ptr<Packet> dsrP, Ipv4Address ipv4Address, Ipv4Address source, Ipv4Header const& ipv4Header, uint8_t protocol, bool& isPromisc, Ipv4Address promiscSource)
1434 {
1435  NS_LOG_FUNCTION (this << packet << dsrP << ipv4Address << source << ipv4Header << (uint32_t)protocol << isPromisc);
1436  Ptr<Packet> p = packet->Copy ();
1437  uint32_t size = p->GetSize ();
1438  uint8_t *data = new uint8_t[size];
1439  p->CopyData (data, size);
1440  uint8_t errorType = *(data + 2);
1441  /*
1442  * Get the node from Ip address and get the dsr extension object
1443  */
1444  Ptr<Node> node = GetNodeWithAddress (ipv4Address);
1446  /*
1447  * The error serialized size
1448  */
1449  uint32_t rerrSize;
1450  NS_LOG_DEBUG ("The error type value here " << (uint32_t)errorType);
1451  if (errorType == 1) // unreachable ip address
1452  {
1453  /*
1454  * Remove the route error header from the packet, and get the error type
1455  */
1456  DsrOptionRerrUnreachHeader rerrUnreach;
1457  p->RemoveHeader (rerrUnreach);
1458  /*
1459  * Get the error destination address
1460  */
1461  Ipv4Address unreachAddress = rerrUnreach.GetUnreachNode ();
1462  Ipv4Address errorSource = rerrUnreach.GetErrorSrc ();
1463 
1464  NS_LOG_DEBUG ("The error source is " << rerrUnreach.GetErrorDst () << "and the unreachable node is " << unreachAddress);
1465  /*
1466  * Get the serialized size of the rerr header
1467  */
1468  rerrSize = rerrUnreach.GetSerializedSize ();
1469  /*
1470  * Delete all the routes including the unreachable node address from the route cache
1471  */
1472  Ptr<Node> node = GetNodeWithAddress (ipv4Address);
1473  dsr->DeleteAllRoutesIncludeLink (errorSource, unreachAddress, ipv4Address);
1474 
1475  Ptr<Packet> newP = p->Copy ();
1476  uint32_t serialized = DoSendError (newP, rerrUnreach, rerrSize, ipv4Address, protocol);
1477  return serialized;
1478  }
1479  else
1480  {
1481  /*
1482  * Two other type of error headers:
1483  * 1. flow state not supported type-specific information
1484  * 2. unsupported option with option number
1485  */
1486  /*
1487  * Remove the route error header from the packet, and get the error type
1488  */
1489  DsrOptionRerrUnsupportHeader rerrUnsupport;
1490  p->RemoveHeader (rerrUnsupport);
1491  rerrSize = rerrUnsupport.GetSerializedSize ();
1492 
1494 // uint32_t serialized = DoSendError (p, rerrUnsupport, rerrSize, ipv4Address, protocol);
1495  uint32_t serialized = 0;
1496  return serialized;
1497  }
1498 }
1499 
1500 uint8_t DsrOptionRerr::DoSendError (Ptr<Packet> p, DsrOptionRerrUnreachHeader &rerr, uint32_t rerrSize, Ipv4Address ipv4Address, uint8_t protocol)
1501 {
1502  // Get the number of routers' address field
1503  uint8_t buf[2];
1504  p->CopyData (buf, sizeof(buf));
1505  uint8_t numberAddress = (buf[1] - 2) / 4;
1506 
1507  // Here remove the source route header and schedule next hop error transmission
1508  NS_LOG_DEBUG ("The number of addresses " << (uint32_t)numberAddress);
1509  DsrOptionSRHeader sourceRoute;
1510  sourceRoute.SetNumberAddress (numberAddress);
1511  p->RemoveHeader (sourceRoute);
1512  NS_ASSERT (p->GetSize () == 0);
1513  /*
1514  * Get the node from ip address and the dsr extension object
1515  */
1516  Ptr<Node> node = GetNodeWithAddress (ipv4Address);
1517  Ptr<dsr::DsrRouting> dsr = node->GetObject<dsr::DsrRouting> ();
1518  /*
1519  * Get the segments left field and the next address
1520  */
1521  uint8_t segmentsLeft = sourceRoute.GetSegmentsLeft ();
1522  uint8_t length = sourceRoute.GetLength ();
1523  uint8_t nextAddressIndex;
1524  Ipv4Address nextAddress;
1525  /*
1526  * Get the route size and the error target address
1527  */
1528  std::vector<Ipv4Address> nodeList = sourceRoute.GetNodesAddress ();
1529  Ipv4Address targetAddress = nodeList.back ();
1530  /*
1531  * The total serialized size for both the rerr and source route headers
1532  */
1533  uint32_t serializedSize = rerrSize + sourceRoute.GetSerializedSize ();
1534 
1535  if (length % 2 != 0)
1536  {
1537  NS_LOG_LOGIC ("Malformed header. Drop!");
1538  m_dropTrace (p);
1539  return 0;
1540  }
1541 
1542  if (segmentsLeft > numberAddress)
1543  {
1544  NS_LOG_LOGIC ("Malformed header. Drop!");
1545  m_dropTrace (p);
1546  return 0;
1547  }
1548  /*
1549  * When the error packet has reached to the destination
1550  */
1551  if (segmentsLeft == 0 && targetAddress == ipv4Address)
1552  {
1553  NS_LOG_INFO ("This is the destination of the error, send error request");
1554  dsr->SendErrorRequest (rerr, protocol);
1555  return serializedSize;
1556  }
1557 
1558  // Get the next Router Address
1559  DsrOptionSRHeader newSourceRoute;
1560  newSourceRoute.SetSegmentsLeft (segmentsLeft - 1);
1561  nextAddressIndex = numberAddress - segmentsLeft;
1562  nextAddress = sourceRoute.GetNodeAddress (nextAddressIndex);
1563  newSourceRoute.SetSalvage (sourceRoute.GetSalvage ());
1564  newSourceRoute.SetNodesAddress (nodeList);
1565  nextAddress = newSourceRoute.GetNodeAddress (nextAddressIndex);
1566 
1568  if (nextAddress.IsMulticast () || targetAddress.IsMulticast ())
1569  {
1570  m_dropTrace (p);
1571  return serializedSize;
1572  }
1573 
1574  // Set the route entry
1575  SetRoute (nextAddress, ipv4Address);
1576  dsr->ForwardErrPacket (rerr, newSourceRoute, nextAddress, protocol, m_ipv4Route);
1577  return serializedSize;
1578 }
1579 
1581 
1583 {
1584  static TypeId tid = TypeId ("ns3::dsr::DsrOptionAckReq")
1585  .SetParent<DsrOptions> ()
1586  .AddConstructor<DsrOptionAckReq> ()
1587  ;
1588  return tid;
1589 }
1590 
1592 {
1594 }
1595 
1597 {
1599 }
1600 
1602 {
1603  return GetTypeId ();
1604 }
1605 
1607 {
1609  return OPT_NUMBER;
1610 }
1611 
1612 uint8_t DsrOptionAckReq::Process (Ptr<Packet> packet, Ptr<Packet> dsrP, Ipv4Address ipv4Address, Ipv4Address source, Ipv4Header const& ipv4Header, uint8_t protocol, bool& isPromisc, Ipv4Address promiscSource)
1613 {
1614  NS_LOG_FUNCTION (this << packet << dsrP << ipv4Address << source << ipv4Header << (uint32_t)protocol << isPromisc);
1615  /*
1616  * Current implementation of the ack request header processing is coded in source route header processing
1617  */
1618  /*
1619  * Remove the ack request header
1620  */
1621  Ptr<Packet> p = packet->Copy ();
1622  DsrOptionAckReqHeader ackReq;
1623  p->RemoveHeader (ackReq);
1624  /*
1625  * Get the node with ip address and get the dsr extension and reoute cache objects
1626  */
1627  Ptr<Node> node = GetNodeWithAddress (ipv4Address);
1629 
1630  NS_LOG_DEBUG ("The next header value " << (uint32_t)protocol);
1631 
1632  return ackReq.GetSerializedSize ();
1633 }
1634 
1636 
1638 {
1639  static TypeId tid = TypeId ("ns3::dsr::DsrOptionAck")
1640  .SetParent<DsrOptions> ()
1641  .AddConstructor<DsrOptionAck> ()
1642  ;
1643  return tid;
1644 }
1645 
1647 {
1649 }
1650 
1652 {
1654 }
1655 
1657 {
1658  return GetTypeId ();
1659 }
1660 
1662 {
1664  return OPT_NUMBER;
1665 }
1666 
1667 uint8_t DsrOptionAck::Process (Ptr<Packet> packet, Ptr<Packet> dsrP, Ipv4Address ipv4Address, Ipv4Address source, Ipv4Header const& ipv4Header, uint8_t protocol, bool& isPromisc, Ipv4Address promiscSource)
1668 {
1669  NS_LOG_FUNCTION (this << packet << dsrP << ipv4Address << source << ipv4Header << (uint32_t)protocol << isPromisc);
1670  /*
1671  * Remove the ACK header
1672  */
1673  Ptr<Packet> p = packet->Copy ();
1674  DsrOptionAckHeader ack;
1675  p->RemoveHeader (ack);
1676  /*
1677  * Get the ACK source and destination address
1678  */
1679  Ipv4Address realSrc = ack.GetRealSrc ();
1680  Ipv4Address realDst = ack.GetRealDst ();
1681  uint16_t ackId = ack.GetAckId ();
1682  /*
1683  * Get the node with ip address and get the dsr extension and route cache objects
1684  */
1685  Ptr<Node> node = GetNodeWithAddress (ipv4Address);
1687  dsr->UpdateRouteEntry (realDst);
1688  /*
1689  * Cancel the packet retransmit timer when receiving the ack packet
1690  */
1691  dsr->CallCancelPacketTimer (ackId, ipv4Header, realSrc, realDst);
1692  return ack.GetSerializedSize ();
1693 }
1694 
1695 } // namespace dsr
1696 } // namespace ns3
uint32_t RemoveHeader(Header &header)
Deserialize and remove the header from the internal buffer.
Definition: packet.cc:268
static const uint8_t OPT_NUMBER
Dsr Route Error option number.
Definition: dsr-options.h:434
virtual uint8_t Process(Ptr< Packet > packet, Ptr< Packet > dsrP, Ipv4Address ipv4Address, Ipv4Address source, Ipv4Header const &ipv4Header, uint8_t protocol, bool &isPromisc, Ipv4Address promiscSource)
Process method.
virtual uint8_t GetOptionNumber() const
Get the option number.
uint16_t GetAckId() const
Set the Ack id number.
static const uint8_t OPT_NUMBER
Rreq option number.
Definition: dsr-options.h:325
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by "...
static uint32_t GetNNodes(void)
Definition: node-list.cc:246
static const uint8_t OPT_NUMBER
Dsr ack request option number.
Definition: dsr-options.h:481
virtual TypeId GetInstanceTypeId() const
Get the instance type ID.
static TypeId GetTypeId()
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition: object-base.h:44
Ipv4Address GetTarget()
Get the target ipv4 address.
static Ptr< Node > GetNode(uint32_t n)
Definition: node-list.cc:240
Ipv4Address GetNodeAddress(uint8_t index) const
Get a Node IPv4 Address.
Introspection did not find any typical Config paths.
Definition: dsr-options.h:74
virtual Ipv4Address GetErrorSrc() const
Get the route error source address.
static TypeId GetTypeId()
Definition: dsr-options.cc:423
uint16_t GetId() const
Set the request id number.
void AddPacketTag(const Tag &tag) const
Add a packet tag.
Definition: packet.cc:836
virtual uint8_t GetOptionNumber() const =0
Get the option number.
Introspection did not find any typical Config paths.
std::vector< Ipv4Address > GetNodesAddresses() const
Get the vector of ipv4 address.
void SetNextHeader(uint8_t protocol)
Set the "Next header" field.
Ipv4Address GetDestination(void) const
Definition: ipv4-header.cc:304
virtual void SetErrorSrc(Ipv4Address errorSrcAddress)
Set the route error source address.
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file...
Definition: assert.h:61
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:201
uint16_t GetIdentification(void) const
Definition: ipv4-header.cc:69
virtual uint8_t Process(Ptr< Packet > packet, Ptr< Packet > dsrP, Ipv4Address ipv4Address, Ipv4Address source, Ipv4Header const &ipv4Header, uint8_t protocol, bool &isPromisc, Ipv4Address promiscSource)
Process method.
uint32_t GetSize(void) const
Returns the the size in bytes of the packet (including the zero-filled initial payload).
Definition: packet.h:766
void SetSegmentsLeft(uint8_t segmentsLeft)
virtual uint32_t GetSerializedSize() const
Get the serialized size of the packet.
bool IsMulticast(void) const
#define NS_LOG_INFO(msg)
Use NS_LOG to output a message of level LOG_INFO.
Definition: log.h:244
#define NS_FATAL_ERROR(msg)
Fatal error handling.
Definition: fatal-error.h:100
Ipv4Address GetSource(void) const
Definition: ipv4-header.cc:291
void SetSourceId(uint16_t sourceId)
brief Set the source ID of the header.
#define NS_LOG_FUNCTION_NOARGS()
Output the name of the function.
std::vector< Ipv4Address > GetNodesAddress() const
Get the vector of ipv4 address.
virtual uint8_t Process(Ptr< Packet > packet, Ptr< Packet > dsrP, Ipv4Address ipv4Address, Ipv4Address source, Ipv4Header const &ipv4Header, uint8_t protocol, bool &isPromisc, Ipv4Address promiscSource)
Process method.
Introspection did not find any typical Config paths.
Definition: dsr-options.h:428
virtual uint32_t GetSerializedSize() const
Get the serialized size of the packet.
This class implements a tag that carries the socket-specific TTL of a packet to the IP layer...
Definition: socket.h:999
virtual TypeId GetInstanceTypeId() const
Get the instance type ID.
Definition: dsr-options.cc:472
Source Route (SR) Message Format.
void SetNode(Ptr< Node > node)
Set the node.
Definition: dsr-options.cc:101
void SetDestId(uint16_t destId)
brief Set the dest ID of the header.
static const uint8_t OPT_NUMBER
Pad1 option number.
Definition: dsr-options.h:283
uint8_t DoSendError(Ptr< Packet > p, DsrOptionRerrUnreachHeader &rerr, uint32_t rerrSize, Ipv4Address ipv4Address, uint8_t protocol)
Do Send error message.
uint8_t GetLength() const
Get the option length.
Acknowledgement Request (ACK_RREQ) Message Format.
uint32_t GetIDfromIP(Ipv4Address address)
Get the node id with Ipv4Address.
Definition: dsr-options.cc:348
Ipv4Address GetUnreachNode() const
Get the unreachable node ip address.
Ptr< const TraceSourceAccessor > MakeTraceSourceAccessor(T a)
Create a TraceSourceAccessor which will control access to the underlying trace source.
void SetSource(Ipv4Address src)
Definition: ipv4-route.cc:49
Packet header for IPv4.
Definition: ipv4-header.h:31
virtual void SetSalvage(uint8_t salvage)
Set the salvage value of the packet.
std::vector< Ipv4Address > GetNodesAddress() const
Get the vector of ipv4 address.
Route Reply (RREP) Message Format.
virtual uint8_t GetOptionNumber() const
Get the option number.
void SetTtl(uint8_t ttl)
Set the tag's TTL.
Definition: socket.cc:582
virtual void SetErrorDst(Ipv4Address errorDstAddress)
Set the error destination ip address.
Introspection did not find any typical Config paths.
Definition: dsr-options.h:360
static TypeId GetTypeId()
Definition: dsr-options.cc:962
uint16_t GetAckId() const
Set the Ack request id number.
void SetGateway(Ipv4Address gw)
Definition: ipv4-route.cc:63
Hold an unsigned integer type.
Definition: uinteger.h:44
DsrOptionRreq()
Constructor.
Definition: dsr-options.cc:477
std::vector< Ipv4Address > IP_VECTOR
Define the vector to hold Ip address.
Definition: dsr-rcache.h:177
uint8_t data[writeSize]
Ipv4Address ReverseSearchNextTwoHop(Ipv4Address ipv4Address, std::vector< Ipv4Address > &vec)
Reverse search for the next two hop in the route.
Definition: dsr-options.cc:227
virtual uint8_t Process(Ptr< Packet > packet, Ptr< Packet > dsrP, Ipv4Address ipv4Address, Ipv4Address source, Ipv4Header const &ipv4Header, uint8_t protocol, bool &isPromisc, Ipv4Address promiscSource)
Process method.
Definition: dsr-options.cc:993
TracedCallback< Ptr< const Packet > > m_dropTrace
Drop trace callback.
Definition: dsr-options.h:231
static const uint8_t OPT_NUMBER
Router alert option number.
Definition: dsr-options.h:366
void SetErrorType(uint8_t errorType)
Set the route error type.
void SetNodesAddress(std::vector< Ipv4Address > ipv4Address)
Set the vector of ipv4 address.
static TypeId GetTypeId()
virtual uint8_t Process(Ptr< Packet > packet, Ptr< Packet > dsrP, Ipv4Address ipv4Address, Ipv4Address source, Ipv4Header const &ipv4Header, uint8_t protocol, bool &isPromisc, Ipv4Address promiscSource)
Process method.
Definition: dsr-options.cc:448
static const uint8_t OPT_NUMBER
PadN option number.
Definition: dsr-options.h:304
Definition: dsr-rcache.h:174
#define NS_LOG_LOGIC(msg)
Use NS_LOG to output a message of level LOG_LOGIC.
Definition: log.h:252
virtual ~DsrOptionRreq()
Destructor.
Definition: dsr-options.cc:482
std::vector< Ipv4Address > m_finalRoute
The vector of final Ipv4 address.
Definition: dsr-options.h:259
Ipv4Address GetRealSrc() const
Get Error source ip address.
virtual uint32_t GetSerializedSize() const
Get the serialized size of the packet.
Acknowledgement (ACK) Message Format.
virtual TypeId GetInstanceTypeId() const
Get the instance type ID.
Access to the Ipv4 forwarding table, interfaces, and configuration.
Definition: ipv4.h:76
Ptr< Packet > Copy(void) const
performs a COW copy of the packet.
Definition: packet.cc:122
void RemoveDuplicates(std::vector< Ipv4Address > &vec)
Remove the duplicates from the route.
Definition: dsr-options.cc:303
Time ActiveRouteTimeout
The active route timeout value.
Definition: dsr-options.h:263
void PrintVector(std::vector< Ipv4Address > &vec)
Print out the elements in the route vector.
Definition: dsr-options.cc:246
virtual uint32_t GetSerializedSize() const
Get the serialized size of the packet.
virtual uint32_t GetSerializedSize() const
Get the serialized size of the packet.
void SetPayloadLength(uint16_t length)
brief Set the payload length of the header.
Route Error (RERR) Unsupported option Message Format.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
virtual uint32_t GetSerializedSize() const
Get the serialized size of the packet.
Route Request (RREQ) Message Format.
DsrOptions()
Constructor.
Definition: dsr-options.cc:91
void SetNodesAddress(std::vector< Ipv4Address > ipv4Address)
Set the vector of ipv4 address.
static const uint8_t OPT_NUMBER
The Dsr Ack option number.
Definition: dsr-options.h:517
Ipv4Address SearchNextHop(Ipv4Address ipv4Address, std::vector< Ipv4Address > &vec)
Search for the next hop in the route.
Definition: dsr-options.cc:169
virtual Ipv4Address GetErrorDst() const
Get the error destination ip address.
Introspection did not find any typical Config paths.
Definition: dsr-options.h:396
Ipv4Address GetRealDst() const
Get Error source ip address.
IP_VECTOR GetVector() const
Definition: dsr-rcache.h:211
void SetMessageType(uint8_t messageType)
brief Set the message type of the header.
virtual uint32_t GetSerializedSize() const
Get the serialized size of the packet.
void SetUnreachNode(Ipv4Address unreachNode)
Set the unreachable node ip address.
TracedCallback< const DsrOptionSRHeader & > m_rxPacketTrace
The receive trace back, only triggered when final destination receive data packet.
Definition: dsr-options.h:267
static TypeId GetTypeId()
void SetNodesAddress(std::vector< Ipv4Address > ipv4Address)
Set the vector of ipv4 address.
virtual ~DsrOptions()
Destructor.
Definition: dsr-options.cc:96
Ipv4 addresses are stored in host order in this class.
Definition: ipv4-address.h:40
virtual uint8_t Process(Ptr< Packet > packet, Ptr< Packet > dsrP, Ipv4Address ipv4Address, Ipv4Address source, Ipv4Header const &ipv4Header, uint8_t protocol, bool &isPromisc, Ipv4Address promiscSource)
Process method.
Definition: dsr-options.cc:409
Ptr< Node > m_node
Definition: dsr-options.h:270
static TypeId GetTypeId()
Definition: dsr-options.cc:383
Introspection did not find any typical Config paths.
Definition: dsr-options.h:319
Introspection did not find any typical Config paths.
Definition: dsr-options.h:298
uint16_t GetFragmentOffset(void) const
Definition: ipv4-header.cc:246
void AddDsrOption(DsrOptionHeader const &option)
Serialize the option, prepending pad1 or padn option as necessary.
bool CheckDuplicates(Ipv4Address ipv4Address, std::vector< Ipv4Address > &vec)
Check if the route already contains the node ip address.
Definition: dsr-options.cc:286
bool ReverseRoutes(std::vector< Ipv4Address > &vec)
Reverse the routes.
Definition: dsr-options.cc:151
virtual uint8_t Process(Ptr< Packet > packet, Ptr< Packet > dsrP, Ipv4Address ipv4Address, Ipv4Address source, Ipv4Header const &ipv4Header, uint8_t protocol, bool &isPromisc, Ipv4Address promiscSource)
Process method.
Definition: dsr-options.cc:494
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
Definition: log.h:236
Route Error (RERR) Unreachable node address option Message Format.
Ptr< Ipv4Route > m_ipv4Route
The ipv4 route.
Definition: dsr-options.h:247
void SetNumberAddress(uint8_t n)
Set the number of ipv4 address.
virtual TypeId GetInstanceTypeId() const
Get the instance type ID.
Ipv4Address ReverseSearchNextHop(Ipv4Address ipv4Address, std::vector< Ipv4Address > &vec)
Reverse search for the next hop in the route.
Definition: dsr-options.cc:201
Introspection did not find any typical Config paths.
virtual TypeId GetInstanceTypeId() const
Get the instance type ID.
static TypeId GetTypeId(void)
Get the type identificator.
Definition: dsr-options.cc:71
void SetNumberAddress(uint8_t n)
Set the number of ipv4 address.
bool ContainAddressAfter(Ipv4Address ipv4Address, Ipv4Address destAddress, std::vector< Ipv4Address > &nodeList)
Search for the ipv4 address in the node list.
Definition: dsr-options.cc:113
virtual uint8_t GetOptionNumber() const
Get the option number.
virtual uint8_t GetOptionNumber() const
Get the option number.
Definition: dsr-options.cc:402
virtual uint8_t GetOptionNumber() const
Get the option number.
Definition: dsr-options.cc:442
Introspection did not find any typical Config paths.
Definition: dsr-options.h:511
void SetNumberAddress(uint8_t n)
Set the number of ipv4 address.
virtual TypeId GetInstanceTypeId() const
Get the instance type ID.
Definition: dsr-options.cc:981
uint32_t CopyData(uint8_t *buffer, uint32_t size) const
Copy the packet contents to a byte buffer.
Definition: packet.cc:368
static const uint8_t OPT_NUMBER
Source Route option number.
Definition: dsr-options.h:402
virtual uint32_t GetSerializedSize() const
Get the serialized size of the packet.
uint8_t GetTtl(void) const
Definition: ipv4-header.cc:265
Introspection did not find any typical Config paths.
Definition: dsr-options.h:475
virtual uint32_t GetSerializedSize() const
Get the serialized size of the packet.
virtual uint8_t GetOptionNumber() const
Get the option number.
Definition: dsr-options.cc:986
A base class which provides memory management and object aggregation.
Definition: object.h:87
tuple address
Definition: first.py:37
Introspection did not find any typical Config paths.
Definition: dsr-options.h:277
Ptr< Node > GetNode() const
Get the node.
Definition: dsr-options.cc:107
virtual Ptr< Ipv4Route > SetRoute(Ipv4Address nextHop, Ipv4Address srcAddress)
Set the route to use for data packets, used by the option headers when sending data/control packets...
Definition: dsr-options.cc:141
Header of Dsr Routing.
bool IfDuplicates(std::vector< Ipv4Address > &vec, std::vector< Ipv4Address > &vec2)
Check if the two vectors contain duplicate or not.
Definition: dsr-options.cc:266
Ptr< Node > GetNodeWithAddress(Ipv4Address ipv4Address)
Get the node object with Ipv4Address.
Definition: dsr-options.cc:364
static TypeId GetTypeId()
virtual uint8_t Process(Ptr< Packet > packet, Ptr< Packet > dsrP, Ipv4Address ipv4Address, Ipv4Address source, Ipv4Header const &ipv4Header, uint8_t protocol, bool &isPromisc, Ipv4Address promiscSource)
Process method.
virtual uint8_t GetSalvage() const
Get the salvage value of the packet.
Ptr< T > GetObject(void) const
Get a pointer to the requested aggregated Object.
Definition: object.h:455
Ptr< const AttributeAccessor > MakeUintegerAccessor(T1 a1)
Create an AttributeAccessor for a class data member, or a lone class get functor or set method...
Definition: uinteger.h:45
Dsr Routing base.
Definition: dsr-routing.h:95
a unique identifier for an interface.
Definition: type-id.h:51
void SetSalvage(uint8_t salvage)
TypeId SetParent(TypeId tid)
Definition: type-id.cc:631
void AddHeader(const Header &header)
Add header to this packet.
Definition: packet.cc:253
void SetDestination(Ipv4Address dest)
Definition: ipv4-route.cc:35
std::vector< Ipv4Address > CutRoute(Ipv4Address ipv4Address, std::vector< Ipv4Address > &nodeList)
Cut the route from ipv4Address to the end of the route vector.
Definition: dsr-options.cc:129
virtual uint8_t GetOptionNumber() const
Get the option number.
Definition: dsr-options.cc:487
static TypeId GetTypeId()
Definition: dsr-options.cc:463
virtual uint8_t GetOptionNumber() const
Get the option number.