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