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