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 https://resilinets.org/
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#include "ns3/ptr.h"
39#include "ns3/log.h"
40#include "ns3/assert.h"
41#include "ns3/fatal-error.h"
42#include "ns3/node.h"
43#include "ns3/uinteger.h"
44#include "ns3/trace-source-accessor.h"
45#include "ns3/udp-header.h"
46#include "ns3/pointer.h"
47#include "ns3/node-list.h"
48#include "ns3/object-vector.h"
49#include "ns3/ipv4-l3-protocol.h"
50#include "ns3/ipv4-interface.h"
51#include "ns3/ipv4-header.h"
52#include "ns3/ipv4-address.h"
53#include "ns3/ipv4-route.h"
54#include "ns3/icmpv4-l4-protocol.h"
55#include "ns3/ip-l4-protocol.h"
56#include "dsr-option-header.h"
57#include "dsr-options.h"
58#include "dsr-rcache.h"
59
60namespace ns3 {
61
62NS_LOG_COMPONENT_DEFINE ("DsrOptions");
63
64namespace dsr {
65
67
69{
70 static TypeId tid = TypeId ("ns3::dsr::DsrOptions")
71 .SetParent<Object> ()
72 .SetGroupName ("Dsr")
73 .AddAttribute ("OptionNumber", "The Dsr option number.",
74 UintegerValue (0),
76 MakeUintegerChecker<uint8_t> ())
77 .AddTraceSource ("Drop",
78 "Packet dropped.",
80 "ns3::Packet::TracedCallback")
81 .AddTraceSource ("Rx",
82 "Receive DSR packet.",
84 "ns3::dsr::DsrOptionSRHeader::TracedCallback")
85 ;
86 return tid;
87}
88
90{
92}
93
95{
97}
98
100{
101 NS_LOG_FUNCTION (this << node);
102 m_node = node;
103}
104
106{
108 return m_node;
109}
110
111bool DsrOptions::ContainAddressAfter (Ipv4Address ipv4Address, Ipv4Address destAddress, std::vector<Ipv4Address> &nodeList)
112{
113 NS_LOG_FUNCTION (this << ipv4Address << destAddress);
114 std::vector<Ipv4Address>::iterator it = find (nodeList.begin (), nodeList.end (), destAddress);
115
116 for (std::vector<Ipv4Address>::iterator i = it; i != nodeList.end (); ++i)
117 {
118 if ((ipv4Address == (*i)) && ((*i) != nodeList.back ()))
119 {
120 return true;
121 }
122 }
123 return false;
124}
125
126std::vector<Ipv4Address>
127DsrOptions::CutRoute (Ipv4Address ipv4Address, std::vector<Ipv4Address> &nodeList)
128{
129 NS_LOG_FUNCTION (this << ipv4Address);
130 std::vector<Ipv4Address>::iterator it = find (nodeList.begin (), nodeList.end (), ipv4Address);
131 std::vector<Ipv4Address> cutRoute;
132 for (std::vector<Ipv4Address>::iterator i = it; i != nodeList.end (); ++i)
133 {
134 cutRoute.push_back (*i);
135 }
136 return cutRoute;
137}
138
140{
141 NS_LOG_FUNCTION (this << nextHop << srcAddress);
142 m_ipv4Route = Create<Ipv4Route> ();
143 m_ipv4Route->SetDestination (nextHop);
144 m_ipv4Route->SetGateway (nextHop);
145 m_ipv4Route->SetSource (srcAddress);
146 return m_ipv4Route;
147}
148
149bool DsrOptions::ReverseRoutes (std::vector<Ipv4Address> & vec)
150{
151 NS_LOG_FUNCTION (this);
152 std::vector<Ipv4Address> vec2 (vec);
153 vec.clear (); // To ensure vec is empty before start
154 for (std::vector<Ipv4Address>::reverse_iterator ri = vec2.rbegin (); ri
155 != vec2.rend (); ++ri)
156 {
157 vec.push_back (*ri);
158 }
159
160 if ((vec.size () == vec2.size ()) && (vec.front () == vec2.back ()))
161 {
162 return true;
163 }
164 return false;
165}
166
167Ipv4Address DsrOptions::SearchNextHop (Ipv4Address ipv4Address, std::vector<Ipv4Address>& vec)
168{
169 NS_LOG_FUNCTION (this << ipv4Address);
170 Ipv4Address nextHop;
171 NS_LOG_DEBUG ("the vector size " << vec.size ());
172 if (vec.size () == 2)
173 {
174 NS_LOG_DEBUG ("The two nodes are neighbors");
175 nextHop = vec[1];
176 return nextHop;
177 }
178 else
179 {
180 if (ipv4Address == vec.back ())
181 {
182 NS_LOG_DEBUG ("We have reached to the final destination " << ipv4Address << " " << vec.back ());
183 return ipv4Address;
184 }
185 for (std::vector<Ipv4Address>::const_iterator i = vec.begin (); i != vec.end (); ++i)
186 {
187 if (ipv4Address == (*i))
188 {
189 nextHop = *(++i);
190 return nextHop;
191 }
192 }
193 }
194 NS_LOG_DEBUG ("next hop address not found, route corrupted");
195 Ipv4Address none = "0.0.0.0";
196 return none;
197}
198
199Ipv4Address DsrOptions::ReverseSearchNextHop (Ipv4Address ipv4Address, std::vector<Ipv4Address>& vec)
200{
201 NS_LOG_FUNCTION (this << ipv4Address);
202 Ipv4Address nextHop;
203 if (vec.size () == 2)
204 {
205 NS_LOG_DEBUG ("The two nodes are neighbors");
206 nextHop = vec[0];
207 return nextHop;
208 }
209 else
210 {
211 for (std::vector<Ipv4Address>::reverse_iterator ri = vec.rbegin (); ri != vec.rend (); ++ri)
212 {
213 if (ipv4Address == (*ri))
214 {
215 nextHop = *(++ri);
216 return nextHop;
217 }
218 }
219 }
220 NS_LOG_DEBUG ("next hop address not found, route corrupted");
221 Ipv4Address none = "0.0.0.0";
222 return none;
223}
224
225Ipv4Address DsrOptions::ReverseSearchNextTwoHop (Ipv4Address ipv4Address, std::vector<Ipv4Address>& vec)
226{
227 NS_LOG_FUNCTION (this << ipv4Address);
228 Ipv4Address nextTwoHop;
229 NS_LOG_DEBUG ("The vector size " << vec.size ());
230 NS_ASSERT (vec.size () > 2);
231 for (std::vector<Ipv4Address>::reverse_iterator ri = vec.rbegin (); ri != vec.rend (); ++ri)
232 {
233 if (ipv4Address == (*ri))
234 {
235 nextTwoHop = *(ri + 2);
236 return nextTwoHop;
237 }
238 }
239 NS_FATAL_ERROR ("next hop address not found, route corrupted");
240 Ipv4Address none = "0.0.0.0";
241 return none;
242}
243
244void DsrOptions::PrintVector (std::vector<Ipv4Address>& vec)
245{
246 NS_LOG_FUNCTION (this);
247 /*
248 * Check elements in a route vector
249 */
250 if (!vec.size ())
251 {
252 NS_LOG_DEBUG ("The vector is empty");
253 }
254 else
255 {
256 NS_LOG_DEBUG ("Print all the elements in a vector");
257 for (std::vector<Ipv4Address>::const_iterator i = vec.begin (); i != vec.end (); ++i)
258 {
259 NS_LOG_DEBUG ("The ip address " << *i);
260 }
261 }
262}
263
264bool DsrOptions::IfDuplicates (std::vector<Ipv4Address>& vec, std::vector<Ipv4Address>& vec2)
265{
266 NS_LOG_FUNCTION (this);
267 for (std::vector<Ipv4Address>::const_iterator i = vec.begin (); i != vec.end (); ++i)
268 {
269 for (std::vector<Ipv4Address>::const_iterator j = vec2.begin (); j != vec2.end (); ++j)
270 {
271 if ((*i) == (*j))
272 {
273 return true;
274 }
275 else
276 {
277 continue;
278 }
279 }
280 }
281 return false;
282}
283
284bool DsrOptions::CheckDuplicates (Ipv4Address ipv4Address, std::vector<Ipv4Address>& vec)
285{
286 NS_LOG_FUNCTION (this << ipv4Address);
287 for (std::vector<Ipv4Address>::const_iterator i = vec.begin (); i != vec.end (); ++i)
288 {
289 if ((*i) == ipv4Address)
290 {
291 return true;
292 }
293 else
294 {
295 continue;
296 }
297 }
298 return false;
299}
300
301void DsrOptions::RemoveDuplicates (std::vector<Ipv4Address>& vec)
302{
303 NS_LOG_FUNCTION (this);
304 //Remove duplicate ip address from the route if any, should not happen with normal behavior nodes
305 std::vector<Ipv4Address> vec2 (vec); // declare vec2 as a copy of the vec
306 PrintVector (vec2); // Print all the ip address in the route
307 vec.clear (); // clear vec
308 for (std::vector<Ipv4Address>::const_iterator i = vec2.begin (); i != vec2.end (); ++i)
309 {
310 if (vec.empty ())
311 {
312 vec.push_back (*i);
313 continue;
314 }
315 else
316 {
317 for (std::vector<Ipv4Address>::iterator j = vec.begin (); j != vec.end (); ++j)
318 {
319 if ((*i) == (*j))
320 {
321 if ((j + 1) != vec.end ())
322 {
323 vec.erase (j + 1, vec.end ()); // Automatic shorten the route
324 break;
325 }
326 else
327 {
328 break;
329 }
330 }
331 else if (j == (vec.end () - 1))
332 {
333 vec.push_back (*i);
334 break;
335 }
336 else
337 {
338 continue;
339 }
340 }
341 }
342 }
343}
344
347{
348 NS_LOG_FUNCTION (this << address);
349 int32_t nNodes = NodeList::GetNNodes ();
350 for (int32_t i = 0; i < nNodes; ++i)
351 {
352 Ptr<Node> node = NodeList::GetNode (i);
353 Ptr<Ipv4> ipv4 = node->GetObject<Ipv4> ();
354 if (ipv4->GetAddress (1, 0).GetLocal () == address)
355 {
356 return i;
357 }
358 }
359 return 255;
360}
361
363{
364 NS_LOG_FUNCTION (this << ipv4Address);
365 int32_t nNodes = NodeList::GetNNodes ();
366 for (int32_t i = 0; i < nNodes; ++i)
367 {
368 Ptr<Node> node = NodeList::GetNode (i);
369 Ptr<Ipv4> ipv4 = node->GetObject<Ipv4> ();
370 int32_t ifIndex = ipv4->GetInterfaceForAddress (ipv4Address);
371 if (ifIndex != -1)
372 {
373 return node;
374 }
375 }
376 return 0;
377}
378
380
382{
383 static TypeId tid = TypeId ("ns3::dsr::DsrOptionPad1")
385 .SetGroupName ("Dsr")
386 .AddConstructor<DsrOptionPad1> ()
387 ;
388 return tid;
389}
390
392{
394}
395
397{
399}
400
402{
404
405 return OPT_NUMBER;
406}
407
408uint8_t DsrOptionPad1::Process (Ptr<Packet> packet, Ptr<Packet> dsrP, Ipv4Address ipv4Address, Ipv4Address source, Ipv4Header const& ipv4Header, uint8_t protocol, bool& isPromisc, Ipv4Address promiscSource)
409{
410 NS_LOG_FUNCTION (this << packet << dsrP << ipv4Address << source << ipv4Header << (uint32_t)protocol << isPromisc);
411 Ptr<Packet> p = packet->Copy ();
412 DsrOptionPad1Header pad1Header;
413 p->RemoveHeader (pad1Header);
414
415 isPromisc = false;
416
417 return pad1Header.GetSerializedSize ();
418}
419
421
423{
424 static TypeId tid = TypeId ("ns3::dsr::DsrOptionPadn")
426 .SetGroupName ("Dsr")
427 .AddConstructor<DsrOptionPadn> ()
428 ;
429 return tid;
430}
431
433{
435}
436
438{
440}
441
443{
445 return OPT_NUMBER;
446}
447
448uint8_t DsrOptionPadn::Process (Ptr<Packet> packet, Ptr<Packet> dsrP, Ipv4Address ipv4Address, Ipv4Address source, Ipv4Header const& ipv4Header, uint8_t protocol, bool& isPromisc, Ipv4Address promiscSource)
449{
450 NS_LOG_FUNCTION (this << packet << dsrP << ipv4Address << source << ipv4Header << (uint32_t)protocol << isPromisc);
451
452 Ptr<Packet> p = packet->Copy ();
453 DsrOptionPadnHeader padnHeader;
454 p->RemoveHeader (padnHeader);
455
456 isPromisc = false;
457
458 return padnHeader.GetSerializedSize ();
459}
460
462
464{
465 static TypeId tid = TypeId ("ns3::dsr::DsrOptionRreq")
467 .SetGroupName ("Dsr")
468 .AddConstructor<DsrOptionRreq> ()
469 ;
470 return tid;
471}
472
474{
475 return GetTypeId ();
476}
477
479{
481}
482
484{
486}
487
489{
491
492 return OPT_NUMBER;
493}
494
495uint8_t DsrOptionRreq::Process (Ptr<Packet> packet, Ptr<Packet> dsrP, Ipv4Address ipv4Address, Ipv4Address source, Ipv4Header const& ipv4Header, uint8_t protocol, bool& isPromisc, Ipv4Address promiscSource)
496{
497 NS_LOG_FUNCTION (this << packet << dsrP << ipv4Address << source << ipv4Header << (uint32_t)protocol << isPromisc);
498 // Fields from IP header
499 Ipv4Address srcAddress = ipv4Header.GetSource ();
500 /*
501 * \ when the ip source address is equal to the address of our own, this is request packet originated
502 * \ by the node itself, discard it
503 */
504 if (source == ipv4Address)
505 {
506 NS_LOG_DEBUG ("Discard the packet since it was originated from same source address");
507 m_dropTrace (packet); // call the drop trace to show in the tracing
508 return 0;
509 }
510 /*
511 * Get the node associated with the ipv4 address and get several objects from the node and leave for further use
512 */
513 Ptr<Node> node = GetNodeWithAddress (ipv4Address);
515
516 Ptr<Packet> p = packet->Copy (); // Note: The packet here doesn't contain the fixed size dsr header
517 /*
518 * \brief Get the number of routers' address field before removing the header
519 * \peek the packet and get the value
520 */
521 uint8_t buf[2];
522 p->CopyData (buf, sizeof(buf));
523 uint8_t numberAddress = (buf[1] - 6) / 4;
524 NS_LOG_DEBUG ("The number of Ip addresses " << (uint32_t)numberAddress);
525 if (numberAddress >= 255)
526 {
527 NS_LOG_DEBUG ("Discard the packet, malformed header since two many ip addresses in route");
528 m_dropTrace (packet); // call the drop trace to show in the tracing
529 return 0;
530 }
531
532 /*
533 * Create the dsr rreq header
534 */
536 /*
537 * Set the number of addresses with the value from peek data and remove the rreq header
538 */
539 rreq.SetNumberAddress (numberAddress);
540 // Remove the route request header
541 p->RemoveHeader (rreq);
542 // Verify the option length
543 uint8_t length = rreq.GetLength ();
544 if (length % 2 != 0)
545 {
546 NS_LOG_LOGIC ("Malformed header. Drop!");
547 m_dropTrace (packet); // call drop trace
548 return 0;
549 }
550 // Check the rreq id for verifying the request id
551 uint16_t requestId = rreq.GetId ();
552 // The target address is where we want to send the data packets
553 Ipv4Address targetAddress = rreq.GetTarget ();
554 // Get the node list and source address from the route request header
555 std::vector<Ipv4Address> mainVector = rreq.GetNodesAddresses ();
556 std::vector<Ipv4Address> nodeList (mainVector);
557 // Get the real source address of this request, it will be used when checking if we have received the save
558 // route request before or not
559 Ipv4Address sourceAddress = nodeList.front ();
560 PrintVector (nodeList);
561 /*
562 * Construct the dsr routing header for later use
563 */
564 DsrRoutingHeader dsrRoutingHeader;
565 dsrRoutingHeader.SetNextHeader (protocol);
566 dsrRoutingHeader.SetMessageType (1);
567 dsrRoutingHeader.SetSourceId (GetIDfromIP (source));
568 dsrRoutingHeader.SetDestId (255);
569
570 // check whether we have received this request or not, if not, it will save the request in the table for
571 // later use, if not found, return false, and push the newly received source request entry in the cache
572
573 // Get the TTL value, this is used to test if the packet will be forwarded or not
574 uint8_t ttl = ipv4Header.GetTtl ();
575 bool dupRequest = false; // initialize the duplicate request check value
576 if (ttl)
577 {
578 // if the ttl value is not 0, then this request will be forwarded, then we need to
579 // save it in the source entry
580 dupRequest = dsr->FindSourceEntry (sourceAddress, targetAddress, requestId);
581 }
582 /*
583 * Before processing the route request, we need to check two things
584 * 1. if this is the exact same request we have just received, ignore it
585 * 2. if our address is already in the path list, ignore it
586 * 3. otherwise process further
587 */
588
589 if (dupRequest)
590 {
591 // We have received this same route request before, not forwarding it now
592 NS_LOG_LOGIC ("Duplicate request. Drop!");
593 m_dropTrace (packet); // call drop trace
594 return 0;
595 }
596
597 else if (CheckDuplicates (ipv4Address, nodeList))
598 {
599 /*
600 * if the route contains the node address already, drop the request packet
601 */
602 m_dropTrace (packet); // call drop trace
603 NS_LOG_DEBUG ("Our node address is already seen in the route, drop the request");
604 return 0;
605 }
606 else
607 {
608 // A node ignores all RREQs received from any node in its blacklist
609 DsrRouteCacheEntry toPrev;
610 bool isRouteInCache = dsr->LookupRoute (targetAddress,
611 toPrev);
612 DsrRouteCacheEntry::IP_VECTOR ip = toPrev.GetVector (); // The route from our own route cache to dst
613 PrintVector (ip);
614 std::vector<Ipv4Address> saveRoute (nodeList);
615 PrintVector (saveRoute);
616 bool areThereDuplicates = IfDuplicates (ip,
617 saveRoute);
618 /*
619 * When the reverse route is created or updated, the following actions on the route are also carried out:
620 * 3. the next hop in the routing table becomes the node from which the RREQ was received
621 * 4. the hop count is copied from the Hop Count in the RREQ message;
622 */
623
624 // A node generates a RREP if either:
625 // (i) it is itself the destination,
626 /*
627 * The target address equal to our own ip address
628 */
629 NS_LOG_DEBUG ("The target address over here " << targetAddress << " and the ip address " << ipv4Address << " and the source address " << mainVector[0]);
630 if (targetAddress == ipv4Address)
631 {
632 Ipv4Address nextHop; // Declare the next hop address to use
633 if (nodeList.size () == 1)
634 {
635 NS_LOG_DEBUG ("These two nodes are neighbors");
636 m_finalRoute.clear ();
638 m_finalRoute.push_back (source); // push back the request originator's address
639 m_finalRoute.push_back (ipv4Address); // push back our own address
640 nextHop = srcAddress;
641 }
642 else
643 {
644 std::vector<Ipv4Address> changeRoute (nodeList);
645 changeRoute.push_back (ipv4Address); // push back our own address
646 m_finalRoute.clear (); // get a clear route vector
647 for (std::vector<Ipv4Address>::iterator i = changeRoute.begin (); i != changeRoute.end (); ++i)
648 {
649 m_finalRoute.push_back (*i); // Get the full route from source to destination
650 }
652 nextHop = ReverseSearchNextHop (ipv4Address, m_finalRoute); // get the next hop
653 }
654
656 rrep.SetNodesAddress (m_finalRoute); // Set the node addresses in the route reply header
657 NS_LOG_DEBUG ("The nextHop address " << nextHop);
658 Ipv4Address replyDst = m_finalRoute.front ();
659 /*
660 * This part add dsr header to the packet and send route reply packet
661 */
662 DsrRoutingHeader dsrRoutingHeader;
663 dsrRoutingHeader.SetNextHeader (protocol);
664 dsrRoutingHeader.SetMessageType (1);
665 dsrRoutingHeader.SetSourceId (GetIDfromIP (ipv4Address));
666 dsrRoutingHeader.SetDestId (GetIDfromIP (replyDst));
667 // Set the route for route reply
668 SetRoute (nextHop, ipv4Address);
669
670 uint8_t length = rrep.GetLength (); // Get the length of the rrep header excluding the type header
671 dsrRoutingHeader.SetPayloadLength (length + 2);
672 dsrRoutingHeader.AddDsrOption (rrep);
673 Ptr<Packet> newPacket = Create<Packet> ();
674 newPacket->AddHeader (dsrRoutingHeader);
675 dsr->ScheduleInitialReply (newPacket, ipv4Address, nextHop, m_ipv4Route);
676 /*
677 * Create the route entry to the rreq originator and save it to route cache, also need to reverse the route
678 */
681 {
683 Ipv4Address dst = m_finalRoute.back ();
684 bool addRoute = false;
685 if (numberAddress > 0)
686 {
687 DsrRouteCacheEntry toSource (/*ip=*/ m_finalRoute,
688 /*dst=*/ dst,
689 /*exp=*/ ActiveRouteTimeout);
690 if (dsr->IsLinkCache ())
691 {
692 addRoute = dsr->AddRoute_Link (m_finalRoute, ipv4Address);
693 }
694 else
695 {
696 addRoute = dsr->AddRoute (toSource);
697 }
698 }
699 else
700 {
701 NS_LOG_DEBUG ("Abnormal RouteRequest");
702 return 0;
703 }
704
705 if (addRoute)
706 {
707 /*
708 * Found a route to the dst, construct the source route option header
709 */
710 DsrOptionSRHeader sourceRoute;
711 NS_LOG_DEBUG ("The route length " << m_finalRoute.size ());
712 sourceRoute.SetNodesAddress (m_finalRoute);
713
717 // if (dsr->IsLinkCache ())
718 // {
719 // dsr->UseExtends (m_finalRoute);
720 // }
721 sourceRoute.SetSegmentsLeft ((m_finalRoute.size () - 2));
722 // The salvage value here is 0
723 sourceRoute.SetSalvage (0);
724 Ipv4Address nextHop = SearchNextHop (ipv4Address, m_finalRoute); // Get the next hop address
725 NS_LOG_DEBUG ("The nextHop address " << nextHop);
726
727 if (nextHop == "0.0.0.0")
728 {
729 dsr->PacketNewRoute (dsrP, ipv4Address, dst, protocol);
730 return 0;
731 }
732 SetRoute (nextHop, ipv4Address);
733 /*
734 * Send the data packet from the send buffer
735 */
736 dsr->SendPacketFromBuffer (sourceRoute, nextHop, protocol);
737 // Cancel the route request timer for destination after sending the data packet
738 dsr->CancelRreqTimer (dst, true);
739 }
740 else
741 {
742 NS_LOG_DEBUG ("The route is failed to add in cache");
743 return 0;
744 }
745 }
746 else
747 {
748 NS_LOG_DEBUG ("Unable to reverse route");
749 return 0;
750 }
751 isPromisc = false;
752 return rreq.GetSerializedSize ();
753 }
754
755 /*
756 * (ii) or it has an active route to the destination, send reply based on request header and route cache,
757 * need to delay based on a random value from d = H * (h - 1 + r), which can avoid possible route
758 * reply storm. Also, verify if two vectors do not contain duplicates (part of the route to the
759 * destination from route cache and route collected so far). If so, do not use the route found
760 * and forward the route request.
761 */
762 else if (isRouteInCache && !areThereDuplicates)
763 {
764 m_finalRoute.clear (); // Clear the final route vector
768 for (std::vector<Ipv4Address>::iterator i = saveRoute.begin (); i != saveRoute.end (); ++i)
769 {
770 m_finalRoute.push_back (*i);
771 }
775 for (std::vector<Ipv4Address>::iterator j = ip.begin (); j != ip.end (); ++j)
776 {
777 m_finalRoute.push_back (*j);
778 }
779 /*
780 * Create the route entry to the rreq originator and save it to route cache, also need to reverse the route
781 */
782 bool addRoute = false;
783 std::vector<Ipv4Address> reverseRoute (m_finalRoute);
784
785 if (ReverseRoutes (reverseRoute))
786 {
787 saveRoute.push_back (ipv4Address);
788 ReverseRoutes (saveRoute);
789 Ipv4Address dst = saveRoute.back ();
790 NS_LOG_DEBUG ("This is the route save in route cache");
791 PrintVector (saveRoute);
792
793 DsrRouteCacheEntry toSource (/*ip=*/ saveRoute,
794 /*dst=*/ dst,
795 /*exp=*/ 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 ();
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
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")
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
998uint8_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
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=*/ nodeList,
1043 /*dst=*/ dst,
1044 /*exp=*/ ActiveRouteTimeout);
1045 NS_ASSERT (nodeList.front () == ipv4Address);
1046 bool addRoute = false;
1047 if (dsr->IsLinkCache ())
1048 {
1049 addRoute = dsr->AddRoute_Link (nodeList, ipv4Address);
1050 }
1051 else
1052 {
1053 addRoute = dsr->AddRoute (toDestination);
1054 }
1055
1056 if (addRoute)
1057 {
1058 NS_LOG_DEBUG ("We have added the route and search send buffer for packet with destination " << dst);
1062 DsrOptionSRHeader sourceRoute;
1063 NS_LOG_DEBUG ("The route length " << nodeList.size ());
1064 sourceRoute.SetNodesAddress (nodeList);
1065 sourceRoute.SetSegmentsLeft ((nodeList.size () - 2));
1066 sourceRoute.SetSalvage (0);
1067 Ipv4Address nextHop = SearchNextHop (ipv4Address, nodeList); // Get the next hop address
1068 NS_LOG_DEBUG ("The nextHop address " << nextHop);
1069 if (nextHop == "0.0.0.0")
1070 {
1071 dsr->PacketNewRoute (dsrP, ipv4Address, dst, protocol);
1072 return 0;
1073 }
1074 PrintVector (nodeList);
1075 SetRoute (nextHop, ipv4Address);
1076 // Cancel the route request timer for destination
1077 dsr->CancelRreqTimer (dst, true);
1081 dsr->SendPacketFromBuffer (sourceRoute, nextHop, protocol);
1082 }
1083 else
1084 {
1085 NS_LOG_DEBUG ("Failed to add the route");
1086 return 0;
1087 }
1088 }
1089 else
1090 {
1091 uint8_t length = rrep.GetLength () - 2; // The get length - 2 is to get aligned for the malformed header check
1092 NS_LOG_DEBUG ("The length of rrep option " << (uint32_t)length);
1093
1094 if (length % 2 != 0)
1095 {
1096 NS_LOG_LOGIC ("Malformed header. Drop!");
1097 m_dropTrace (packet);
1098 return 0;
1099 }
1100 PrintVector (nodeList);
1101 /*
1102 * This node is only an intermediate node, but it needs to save the possible route to the destination when cutting the route
1103 */
1104 std::vector<Ipv4Address> routeCopy = nodeList;
1105 std::vector<Ipv4Address> cutRoute = CutRoute (ipv4Address, nodeList);
1106 PrintVector (cutRoute);
1107 if (cutRoute.size () >= 2)
1108 {
1109 Ipv4Address dst = cutRoute.back ();
1110 NS_LOG_DEBUG ("The route destination after cut " << dst);
1111 DsrRouteCacheEntry toDestination (/*ip=*/ cutRoute,
1112 /*dst=*/ dst,
1113 /*exp=*/ ActiveRouteTimeout);
1114 NS_ASSERT (cutRoute.front () == ipv4Address);
1115 bool addRoute = false;
1116 if (dsr->IsLinkCache ())
1117 {
1118 addRoute = dsr->AddRoute_Link (nodeList, ipv4Address);
1119 }
1120 else
1121 {
1122 addRoute = dsr->AddRoute (toDestination);
1123 }
1124 if (addRoute)
1125 {
1126 dsr->CancelRreqTimer (dst, true);
1127 }
1128 else
1129 {
1130 NS_LOG_DEBUG ("The route not added");
1131 }
1132 }
1133 else
1134 {
1135 NS_LOG_DEBUG ("The route is corrupted");
1136 }
1137 /*
1138 * Reverse search the vector for next hop address
1139 */
1140 Ipv4Address nextHop = ReverseSearchNextHop (ipv4Address, routeCopy);
1141 NS_ASSERT (routeCopy.back () == source);
1142 PrintVector (routeCopy);
1143 NS_LOG_DEBUG ("The nextHop address " << nextHop << " and the source in the route reply " << source);
1144 /*
1145 * Set the route entry we will use to send reply
1146 */
1147 SetRoute (nextHop, ipv4Address);
1148 /*
1149 * This part add dsr routing header to the packet and send reply
1150 */
1151 DsrRoutingHeader dsrRoutingHeader;
1152 dsrRoutingHeader.SetNextHeader (protocol);
1153
1154 length = rrep.GetLength (); // Get the length of the rrep header excluding the type header
1155 NS_LOG_DEBUG ("The reply header length " << (uint32_t)length);
1156 dsrRoutingHeader.SetPayloadLength (length + 2);
1157 dsrRoutingHeader.SetMessageType (1);
1158 dsrRoutingHeader.SetSourceId (GetIDfromIP (source));
1159 dsrRoutingHeader.SetDestId (GetIDfromIP (targetAddress));
1160 dsrRoutingHeader.AddDsrOption (rrep);
1161 Ptr<Packet> newPacket = Create<Packet> ();
1162 newPacket->AddHeader (dsrRoutingHeader);
1163 dsr->SendReply (newPacket, ipv4Address, nextHop, m_ipv4Route);
1164 isPromisc = false;
1165 }
1166 return rrep.GetSerializedSize ();
1167}
1168
1170
1172{
1173 static TypeId tid = TypeId ("ns3::dsr::DsrOptionSR")
1175 .SetGroupName ("Dsr")
1176 .AddConstructor<DsrOptionSR> ()
1177 ;
1178 return tid;
1179}
1180
1182{
1184}
1185
1187{
1189}
1190
1192{
1193 return GetTypeId ();
1194}
1195
1197{
1199 return OPT_NUMBER;
1200}
1201
1202uint8_t DsrOptionSR::Process (Ptr<Packet> packet, Ptr<Packet> dsrP, Ipv4Address ipv4Address, Ipv4Address source, Ipv4Header const& ipv4Header, uint8_t protocol, bool& isPromisc, Ipv4Address promiscSource)
1203{
1204 NS_LOG_FUNCTION (this << packet << dsrP << ipv4Address << source << ipv4Address << ipv4Header << (uint32_t)protocol << isPromisc);
1205 Ptr<Packet> p = packet->Copy ();
1206 // Get the number of routers' address field
1207 uint8_t buf[2];
1208 p->CopyData (buf, sizeof(buf));
1209 uint8_t numberAddress = (buf[1] - 2) / 4;
1210 DsrOptionSRHeader sourceRoute;
1211 sourceRoute.SetNumberAddress (numberAddress);
1212 p->RemoveHeader (sourceRoute);
1213
1214 // The route size saved in the source route
1215 std::vector<Ipv4Address> nodeList = sourceRoute.GetNodesAddress ();
1216 uint8_t segsLeft = sourceRoute.GetSegmentsLeft ();
1217 uint8_t salvage = sourceRoute.GetSalvage ();
1218 /*
1219 * Get the node from IP address and get the DSR extension object
1220 */
1221 Ptr<Node> node = GetNodeWithAddress (ipv4Address);
1223 /*
1224 * Get the source and destination address from ipv4 header
1225 */
1226 Ipv4Address srcAddress = ipv4Header.GetSource ();
1227 Ipv4Address destAddress = ipv4Header.GetDestination ();
1228
1229 // Get the node list destination
1230 Ipv4Address destination = nodeList.back ();
1231 /*
1232 * If it's a promiscuous receive data packet,
1233 * 1. see if automatic route shortening possible or not
1234 * 2. see if it is a passive acknowledgment
1235 */
1236 if (isPromisc)
1237 {
1238 NS_LOG_LOGIC ("We process promiscuous receipt data packet");
1239 if (ContainAddressAfter (ipv4Address, destAddress, nodeList))
1240 {
1241 NS_LOG_LOGIC ("Send back the gratuitous reply");
1242 dsr->SendGratuitousReply (source, srcAddress, nodeList, protocol);
1243 }
1244
1245 uint16_t fragmentOffset = ipv4Header.GetFragmentOffset ();
1246 uint16_t identification = ipv4Header.GetIdentification ();
1247
1248 if (destAddress != destination)
1249 {
1250 NS_LOG_DEBUG ("Process the promiscuously received packet");
1251 bool findPassive = false;
1252 int32_t nNodes = NodeList::GetNNodes ();
1253 for (int32_t i = 0; i < nNodes; ++i)
1254 {
1255 NS_LOG_DEBUG ("Working with node " << i);
1256
1257 Ptr<Node> node = NodeList::GetNode (i);
1259 // The source and destination addresses here are the real source and destination for the packet
1260 findPassive = dsrNode->PassiveEntryCheck (packet, source, destination, segsLeft, fragmentOffset, identification, false);
1261 if (findPassive)
1262 {
1263 break;
1264 }
1265 }
1266
1267 if (findPassive)
1268 {
1269 NS_LOG_DEBUG ("We find one previously received passive entry");
1270 /*
1271 * Get the node from IP address and get the DSR extension object
1272 * the srcAddress would be the source address from ip header
1273 */
1274 PrintVector (nodeList);
1275
1276 NS_LOG_DEBUG ("promisc source " << promiscSource);
1277 Ptr<Node> node = GetNodeWithAddress (promiscSource);
1279 dsrSrc->CancelPassiveTimer (packet, source, destination, segsLeft);
1280 }
1281 else
1282 {
1283 NS_LOG_DEBUG ("Saved the entry for further use");
1284 dsr->PassiveEntryCheck (packet, source, destination, segsLeft, fragmentOffset, identification, true);
1285 }
1286 }
1288 return 0;
1289 }
1290 else
1291 {
1292 /*
1293 * Get the number of address from the source route header
1294 */
1295 uint8_t length = sourceRoute.GetLength ();
1296 uint8_t nextAddressIndex;
1297 Ipv4Address nextAddress;
1298
1299 // Get the option type value
1300 uint32_t size = p->GetSize ();
1301 uint8_t *data = new uint8_t[size];
1302 p->CopyData (data, size);
1303 uint8_t optionType = 0;
1304 optionType = *(data);
1307 if (optionType == 160)
1308 {
1309 NS_LOG_LOGIC ("Remove the ack request header and add ack header to the packet");
1310 // Here we remove the ack packet to the previous hop
1311 DsrOptionAckReqHeader ackReq;
1312 p->RemoveHeader (ackReq);
1313 uint16_t ackId = ackReq.GetAckId ();
1314 /*
1315 * Send back acknowledgment packet to the earlier hop
1316 * If the node list is not empty, find the previous hop from the node list,
1317 * otherwise, use srcAddress
1318 */
1319 Ipv4Address ackAddress = srcAddress;
1320 if (!nodeList.empty ())
1321 {
1322 if (segsLeft > numberAddress) // The segmentsLeft field should not be larger than the total number of ip addresses
1323 {
1324 NS_LOG_LOGIC ("Malformed header. Drop!");
1325 m_dropTrace (packet);
1326 return 0;
1327 }
1328 // -fstrict-overflow sensitive, see bug 1868
1329 if (numberAddress - segsLeft < 2) // The index is invalid
1330 {
1331 NS_LOG_LOGIC ("Malformed header. Drop!");
1332 m_dropTrace (packet);
1333 return 0;
1334 }
1335 ackAddress = nodeList[numberAddress - segsLeft - 2];
1336 }
1337 m_ipv4Route = SetRoute (ackAddress, ipv4Address);
1338 NS_LOG_DEBUG ("Send back ACK to the earlier hop " << ackAddress << " from us " << ipv4Address);
1339 dsr->SendAck (ackId, ackAddress, source, destination, protocol, m_ipv4Route);
1340 }
1341 /*
1342 * After send back ACK, check if the segments left value has turned to 0 or not, if yes, update the route entry
1343 * and return header length
1344 */
1345 if (segsLeft == 0)
1346 {
1347 NS_LOG_DEBUG ("This is the final destination");
1348 isPromisc = false;
1349 return sourceRoute.GetSerializedSize ();
1350 }
1351
1352 if (length % 2 != 0)
1353 {
1354 NS_LOG_LOGIC ("Malformed header. Drop!");
1355 m_dropTrace (packet);
1356 return 0;
1357 }
1358
1359 if (segsLeft > numberAddress) // The segmentsLeft field should not be larger than the total number of ip addresses
1360 {
1361 NS_LOG_LOGIC ("Malformed header. Drop!");
1362 m_dropTrace (packet);
1363 return 0;
1364 }
1365
1366 DsrOptionSRHeader newSourceRoute;
1367 newSourceRoute.SetSegmentsLeft (segsLeft - 1);
1368 newSourceRoute.SetSalvage (salvage);
1369 newSourceRoute.SetNodesAddress (nodeList);
1370 nextAddressIndex = numberAddress - segsLeft;
1371 nextAddress = newSourceRoute.GetNodeAddress (nextAddressIndex);
1372 NS_LOG_DEBUG ("The next address of source route option " << nextAddress << " and the nextAddressIndex: " << (uint32_t)nextAddressIndex << " and the segments left : " << (uint32_t)segsLeft);
1373 /*
1374 * Get the target Address in the node list
1375 */
1376 Ipv4Address targetAddress = nodeList.back ();
1377 Ipv4Address realSource = nodeList.front ();
1378 /*
1379 * Search the vector for next hop address
1380 */
1381 Ipv4Address nextHop = SearchNextHop (ipv4Address, nodeList);
1382 PrintVector (nodeList);
1383
1384 if (nextHop == "0.0.0.0")
1385 {
1386 NS_LOG_DEBUG ("Before new packet " << *dsrP);
1387 dsr->PacketNewRoute (dsrP, realSource, targetAddress, protocol);
1388 return 0;
1389 }
1390
1391 if (ipv4Address == nextHop)
1392 {
1393 NS_LOG_DEBUG ("We have reached the destination");
1394 newSourceRoute.SetSegmentsLeft (0);
1395 return newSourceRoute.GetSerializedSize ();
1396 }
1397 // Verify the multicast address, leave it here for now
1398 if (nextAddress.IsMulticast () || destAddress.IsMulticast ())
1399 {
1400 m_dropTrace (packet);
1401 return 0;
1402 }
1403 // Set the route and forward the data packet
1404 SetRoute (nextAddress, ipv4Address);
1405 NS_LOG_DEBUG ("dsr packet size " << dsrP->GetSize ());
1406 dsr->ForwardPacket (dsrP, newSourceRoute, ipv4Header, realSource, nextAddress, targetAddress, protocol, m_ipv4Route);
1407 }
1408 return sourceRoute.GetSerializedSize ();
1409}
1410
1412
1414{
1415 static TypeId tid = TypeId ("ns3::dsr::DsrOptionRerr")
1417 .SetGroupName ("Dsr")
1418 .AddConstructor<DsrOptionRerr> ()
1419 ;
1420 return tid;
1421}
1422
1424{
1426}
1427
1429{
1431}
1432
1434{
1435 return GetTypeId ();
1436}
1437
1439{
1441 return OPT_NUMBER;
1442}
1443
1444uint8_t DsrOptionRerr::Process (Ptr<Packet> packet, Ptr<Packet> dsrP, Ipv4Address ipv4Address, Ipv4Address source, Ipv4Header const& ipv4Header, uint8_t protocol, bool& isPromisc, Ipv4Address promiscSource)
1445{
1446 NS_LOG_FUNCTION (this << packet << dsrP << ipv4Address << source << ipv4Header << (uint32_t)protocol << isPromisc);
1447 Ptr<Packet> p = packet->Copy ();
1448 uint32_t size = p->GetSize ();
1449 uint8_t *data = new uint8_t[size];
1450 p->CopyData (data, size);
1451 uint8_t errorType = *(data + 2);
1452 /*
1453 * Get the node from Ip address and get the dsr extension object
1454 */
1455 Ptr<Node> node = GetNodeWithAddress (ipv4Address);
1457 /*
1458 * The error serialized size
1459 */
1460 [[maybe_unused]] uint32_t rerrSize;
1461 NS_LOG_DEBUG ("The error type value here " << (uint32_t)errorType);
1462 if (errorType == 1) // unreachable ip address
1463 {
1464 /*
1465 * Remove the route error header from the packet, and get the error type
1466 */
1467 DsrOptionRerrUnreachHeader rerrUnreach;
1468 p->RemoveHeader (rerrUnreach);
1469 /*
1470 * Get the error destination address
1471 */
1472 Ipv4Address unreachAddress = rerrUnreach.GetUnreachNode ();
1473 Ipv4Address errorSource = rerrUnreach.GetErrorSrc ();
1474
1475 NS_LOG_DEBUG ("The error source is " << rerrUnreach.GetErrorDst () << "and the unreachable node is " << unreachAddress);
1476 /*
1477 * Get the serialized size of the rerr header
1478 */
1479 rerrSize = rerrUnreach.GetSerializedSize ();
1480 /*
1481 * Delete all the routes including the unreachable node address from the route cache
1482 */
1483 Ptr<Node> node = GetNodeWithAddress (ipv4Address);
1484 dsr->DeleteAllRoutesIncludeLink (errorSource, unreachAddress, ipv4Address);
1485
1486 Ptr<Packet> newP = p->Copy ();
1487 uint32_t serialized = DoSendError (newP, rerrUnreach, rerrSize, ipv4Address, protocol);
1488 return serialized;
1489 }
1490 else
1491 {
1492 /*
1493 * Two other type of error headers:
1494 * 1. flow state not supported type-specific information
1495 * 2. unsupported option with option number
1496 */
1497 /*
1498 * Remove the route error header from the packet, and get the error type
1499 */
1500 DsrOptionRerrUnsupportHeader rerrUnsupport;
1501 p->RemoveHeader (rerrUnsupport);
1502 rerrSize = rerrUnsupport.GetSerializedSize ();
1503
1505 // uint32_t serialized = DoSendError (p, rerrUnsupport, rerrSize, ipv4Address, protocol);
1506 uint32_t serialized = 0;
1507 return serialized;
1508 }
1509}
1510
1511uint8_t DsrOptionRerr::DoSendError (Ptr<Packet> p, DsrOptionRerrUnreachHeader &rerr, uint32_t rerrSize, Ipv4Address ipv4Address, uint8_t protocol)
1512{
1513 // Get the number of routers' address field
1514 uint8_t buf[2];
1515 p->CopyData (buf, sizeof(buf));
1516 uint8_t numberAddress = (buf[1] - 2) / 4;
1517
1518 // Here remove the source route header and schedule next hop error transmission
1519 NS_LOG_DEBUG ("The number of addresses " << (uint32_t)numberAddress);
1520 DsrOptionSRHeader sourceRoute;
1521 sourceRoute.SetNumberAddress (numberAddress);
1522 p->RemoveHeader (sourceRoute);
1523 NS_ASSERT (p->GetSize () == 0);
1524 /*
1525 * Get the node from ip address and the dsr extension object
1526 */
1527 Ptr<Node> node = GetNodeWithAddress (ipv4Address);
1529 /*
1530 * Get the segments left field and the next address
1531 */
1532 uint8_t segmentsLeft = sourceRoute.GetSegmentsLeft ();
1533 uint8_t length = sourceRoute.GetLength ();
1534 uint8_t nextAddressIndex;
1535 Ipv4Address nextAddress;
1536 /*
1537 * Get the route size and the error target address
1538 */
1539 std::vector<Ipv4Address> nodeList = sourceRoute.GetNodesAddress ();
1540 Ipv4Address targetAddress = nodeList.back ();
1541 /*
1542 * The total serialized size for both the rerr and source route headers
1543 */
1544 uint32_t serializedSize = rerrSize + sourceRoute.GetSerializedSize ();
1545
1546 if (length % 2 != 0)
1547 {
1548 NS_LOG_LOGIC ("Malformed header. Drop!");
1549 m_dropTrace (p);
1550 return 0;
1551 }
1552
1553 if (segmentsLeft > numberAddress)
1554 {
1555 NS_LOG_LOGIC ("Malformed header. Drop!");
1556 m_dropTrace (p);
1557 return 0;
1558 }
1559 /*
1560 * When the error packet has reached to the destination
1561 */
1562 if (segmentsLeft == 0 && targetAddress == ipv4Address)
1563 {
1564 NS_LOG_INFO ("This is the destination of the error, send error request");
1565 dsr->SendErrorRequest (rerr, protocol);
1566 return serializedSize;
1567 }
1568
1569 // Get the next Router Address
1570 DsrOptionSRHeader newSourceRoute;
1571 newSourceRoute.SetSegmentsLeft (segmentsLeft - 1);
1572 nextAddressIndex = numberAddress - segmentsLeft;
1573 nextAddress = sourceRoute.GetNodeAddress (nextAddressIndex);
1574 newSourceRoute.SetSalvage (sourceRoute.GetSalvage ());
1575 newSourceRoute.SetNodesAddress (nodeList);
1576 nextAddress = newSourceRoute.GetNodeAddress (nextAddressIndex);
1577
1579 if (nextAddress.IsMulticast () || targetAddress.IsMulticast ())
1580 {
1581 m_dropTrace (p);
1582 return serializedSize;
1583 }
1584
1585 // Set the route entry
1586 SetRoute (nextAddress, ipv4Address);
1587 dsr->ForwardErrPacket (rerr, newSourceRoute, nextAddress, protocol, m_ipv4Route);
1588 return serializedSize;
1589}
1590
1592
1594{
1595 static TypeId tid = TypeId ("ns3::dsr::DsrOptionAckReq")
1597 .SetGroupName ("Dsr")
1598 .AddConstructor<DsrOptionAckReq> ()
1599 ;
1600 return tid;
1601}
1602
1604{
1606}
1607
1609{
1611}
1612
1614{
1615 return GetTypeId ();
1616}
1617
1619{
1621 return OPT_NUMBER;
1622}
1623
1624uint8_t DsrOptionAckReq::Process (Ptr<Packet> packet, Ptr<Packet> dsrP, Ipv4Address ipv4Address, Ipv4Address source, Ipv4Header const& ipv4Header, uint8_t protocol, bool& isPromisc, Ipv4Address promiscSource)
1625{
1626 NS_LOG_FUNCTION (this << packet << dsrP << ipv4Address << source << ipv4Header << (uint32_t)protocol << isPromisc);
1627 /*
1628 * Current implementation of the ack request header processing is coded in source route header processing
1629 */
1630 /*
1631 * Remove the ack request header
1632 */
1633 Ptr<Packet> p = packet->Copy ();
1634 DsrOptionAckReqHeader ackReq;
1635 p->RemoveHeader (ackReq);
1636 /*
1637 * Get the node with ip address and get the dsr extension and reoute cache objects
1638 */
1639 Ptr<Node> node = GetNodeWithAddress (ipv4Address);
1641
1642 NS_LOG_DEBUG ("The next header value " << (uint32_t)protocol);
1643
1644 return ackReq.GetSerializedSize ();
1645}
1646
1648
1650{
1651 static TypeId tid = TypeId ("ns3::dsr::DsrOptionAck")
1653 .SetGroupName ("Dsr")
1654 .AddConstructor<DsrOptionAck> ()
1655 ;
1656 return tid;
1657}
1658
1660{
1662}
1663
1665{
1667}
1668
1670{
1671 return GetTypeId ();
1672}
1673
1675{
1677 return OPT_NUMBER;
1678}
1679
1680uint8_t DsrOptionAck::Process (Ptr<Packet> packet, Ptr<Packet> dsrP, Ipv4Address ipv4Address, Ipv4Address source, Ipv4Header const& ipv4Header, uint8_t protocol, bool& isPromisc, Ipv4Address promiscSource)
1681{
1682 NS_LOG_FUNCTION (this << packet << dsrP << ipv4Address << source << ipv4Header << (uint32_t)protocol << isPromisc);
1683 /*
1684 * Remove the ACK header
1685 */
1686 Ptr<Packet> p = packet->Copy ();
1688 p->RemoveHeader (ack);
1689 /*
1690 * Get the ACK source and destination address
1691 */
1692 Ipv4Address realSrc = ack.GetRealSrc ();
1693 Ipv4Address realDst = ack.GetRealDst ();
1694 uint16_t ackId = ack.GetAckId ();
1695 /*
1696 * Get the node with ip address and get the dsr extension and route cache objects
1697 */
1698 Ptr<Node> node = GetNodeWithAddress (ipv4Address);
1700 dsr->UpdateRouteEntry (realDst);
1701 /*
1702 * Cancel the packet retransmit timer when receiving the ack packet
1703 */
1704 dsr->CallCancelPacketTimer (ackId, ipv4Header, realSrc, realDst);
1705 return ack.GetSerializedSize ();
1706}
1707
1708} // namespace dsr
1709} // namespace ns3
Ipv4 addresses are stored in host order in this class.
Definition: ipv4-address.h:41
bool IsMulticast(void) const
Packet header for IPv4.
Definition: ipv4-header.h:34
uint16_t GetIdentification(void) const
Definition: ipv4-header.cc:69
uint16_t GetFragmentOffset(void) const
Definition: ipv4-header.cc:246
Ipv4Address GetSource(void) const
Definition: ipv4-header.cc:291
Ipv4Address GetDestination(void) const
Definition: ipv4-header.cc:304
uint8_t GetTtl(void) const
Definition: ipv4-header.cc:265
Access to the IPv4 forwarding table, interfaces, and configuration.
Definition: ipv4.h:77
static uint32_t GetNNodes(void)
Definition: node-list.cc:247
static Ptr< Node > GetNode(uint32_t n)
Definition: node-list.cc:241
A base class which provides memory management and object aggregation.
Definition: object.h:88
Ptr< T > GetObject(void) const
Get a pointer to the requested aggregated Object.
Definition: object.h:470
uint32_t RemoveHeader(Header &header)
Deserialize and remove the header from the internal buffer.
Definition: packet.cc:280
void AddHeader(const Header &header)
Add header to this packet.
Definition: packet.cc:256
uint32_t CopyData(uint8_t *buffer, uint32_t size) const
Copy the packet contents to a byte buffer.
Definition: packet.cc:378
void AddPacketTag(const Tag &tag) const
Add a packet tag.
Definition: packet.cc:956
Ptr< Packet > Copy(void) const
performs a COW copy of the packet.
Definition: packet.cc:121
uint32_t GetSize(void) const
Returns the the size in bytes of the packet (including the zero-filled initial payload).
Definition: packet.h:856
This class implements a tag that carries the socket-specific TTL of a packet to the IP layer.
Definition: socket.h:1117
void SetTtl(uint8_t ttl)
Set the tag's TTL.
Definition: socket.cc:603
a unique identifier for an interface.
Definition: type-id.h:59
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:922
Hold an unsigned integer type.
Definition: uinteger.h:44
void SetSourceId(uint16_t sourceId)
brief Set the source ID of the header.
void SetNextHeader(uint8_t protocol)
Set the "Next header" field.
void SetDestId(uint16_t destId)
brief Set the dest ID of the header.
void SetMessageType(uint8_t messageType)
brief Set the message type of the header.
void SetPayloadLength(uint16_t length)
brief Set the payload length of the header.
Acknowledgement (ACK) Message Format.
uint16_t GetAckId() const
Set the Ack id number.
Ipv4Address GetRealDst() const
Get Error source ip address.
virtual uint32_t GetSerializedSize() const
Get the serialized size of the packet.
Ipv4Address GetRealSrc() const
Get Error source ip address.
Dsr Option Ack.
Definition: dsr-options.h:540
virtual uint8_t GetOptionNumber() const
Get the option number.
virtual TypeId GetInstanceTypeId() const
Get the instance type ID.
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.
static const uint8_t OPT_NUMBER
The Dsr Ack option number.
Definition: dsr-options.h:545
static TypeId GetTypeId()
Get the type ID.
Acknowledgement Request (ACK_RREQ) Message Format.
virtual uint32_t GetSerializedSize() const
Get the serialized size of the packet.
uint16_t GetAckId() const
Set the Ack request id number.
static TypeId GetTypeId()
Get the type ID.
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.
static const uint8_t OPT_NUMBER
Dsr ack request option number.
Definition: dsr-options.h:505
virtual TypeId GetInstanceTypeId() const
Get the instance type ID.
void AddDsrOption(DsrOptionHeader const &option)
Serialize the option, prepending pad1 or padn option as necessary.
uint8_t GetLength() const
Get the option length.
Header of Dsr Option Pad1.
virtual uint32_t GetSerializedSize() const
Get the serialized size of the packet.
Dsr Option Pad1.
Definition: dsr-options.h:278
static TypeId GetTypeId()
Get the type ID.
Definition: dsr-options.cc:381
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:408
virtual uint8_t GetOptionNumber() const
Get the option number.
Definition: dsr-options.cc:401
static const uint8_t OPT_NUMBER
Pad1 option number.
Definition: dsr-options.h:283
Header of Dsr Option Padn.
virtual uint32_t GetSerializedSize() const
Get the serialized size of the packet.
IPv4 Option Padn.
Definition: dsr-options.h:303
static const uint8_t OPT_NUMBER
PadN option number.
Definition: dsr-options.h:308
static TypeId GetTypeId()
Get the type ID.
Definition: dsr-options.cc:422
virtual uint8_t GetOptionNumber() const
Get the option number.
Definition: dsr-options.cc:442
virtual uint8_t Process(Ptr< Packet > packet, Ptr< Packet > dsrP, Ipv4Address ipv4Address, Ipv4Address source, Ipv4Header const &ipv4Header, uint8_t protocol, bool &isPromisc, Ipv4Address promiscSource)
Process method.
Definition: dsr-options.cc:448
void SetErrorType(uint8_t errorType)
Set the route error type.
Dsr Option Route Error.
Definition: dsr-options.h:449
uint8_t DoSendError(Ptr< Packet > p, DsrOptionRerrUnreachHeader &rerr, uint32_t rerrSize, Ipv4Address ipv4Address, uint8_t protocol)
Do Send error message.
static const uint8_t OPT_NUMBER
Dsr Route Error option number.
Definition: dsr-options.h:454
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.
static TypeId GetTypeId()
Get the type ID.
virtual TypeId GetInstanceTypeId() const
Get the instance type ID.
Route Error (RERR) Unreachable node address option Message Format.
virtual void SetErrorSrc(Ipv4Address errorSrcAddress)
Set the route error source address.
void SetUnreachNode(Ipv4Address unreachNode)
Set the unreachable node ip address.
virtual void SetErrorDst(Ipv4Address errorDstAddress)
Set the error destination ip address.
virtual Ipv4Address GetErrorSrc() const
Get the route error source address.
virtual uint8_t GetSalvage() const
Get the salvage value of the packet.
virtual uint32_t GetSerializedSize() const
Get the serialized size of the packet.
virtual void SetSalvage(uint8_t salvage)
Set the salvage value of the packet.
virtual Ipv4Address GetErrorDst() const
Get the error destination ip address.
Ipv4Address GetUnreachNode() const
Get the unreachable node ip address.
Route Error (RERR) Unsupported option Message Format.
virtual uint32_t GetSerializedSize() const
Get the serialized size of the packet.
Route Reply (RREP) Message Format.
void SetNumberAddress(uint8_t n)
Set the number of ipv4 address.
std::vector< Ipv4Address > GetNodesAddress() const
Get the vector of ipv4 address.
void SetNodesAddress(std::vector< Ipv4Address > ipv4Address)
Set the vector of ipv4 address.
virtual uint32_t GetSerializedSize() const
Get the serialized size of the packet.
Dsr Option Route Reply.
Definition: dsr-options.h:373
virtual TypeId GetInstanceTypeId() const
Get the instance type ID.
Definition: dsr-options.cc:986
virtual uint8_t GetOptionNumber() const
Get the option number.
Definition: dsr-options.cc:991
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
static const uint8_t OPT_NUMBER
Router alert option number.
Definition: dsr-options.h:378
static TypeId GetTypeId()
Get the type ID.
Definition: dsr-options.cc:966
Route Request (RREQ) Message Format.
void SetNodesAddress(std::vector< Ipv4Address > ipv4Address)
Set the vector of ipv4 address.
void SetNumberAddress(uint8_t n)
Set the number of ipv4 address.
virtual uint32_t GetSerializedSize() const
Get the serialized size of the packet.
Ipv4Address GetTarget()
Get the target ipv4 address.
std::vector< Ipv4Address > GetNodesAddresses() const
Get the vector of ipv4 address.
uint16_t GetId() const
Set the request id number.
Dsr Option Rreq.
Definition: dsr-options.h:328
virtual ~DsrOptionRreq()
Destructor.
Definition: dsr-options.cc:483
static TypeId GetTypeId()
Get the type ID.
Definition: dsr-options.cc:463
virtual TypeId GetInstanceTypeId() const
Get the instance type ID.
Definition: dsr-options.cc:473
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:495
static const uint8_t OPT_NUMBER
Rreq option number.
Definition: dsr-options.h:333
virtual uint8_t GetOptionNumber() const
Get the option number.
Definition: dsr-options.cc:488
DsrOptionRreq()
Constructor.
Definition: dsr-options.cc:478
Source Route (SR) Message Format.
Ipv4Address GetNodeAddress(uint8_t index) const
Get a Node IPv4 Address.
std::vector< Ipv4Address > GetNodesAddress() const
Get the vector of ipv4 address.
void SetNumberAddress(uint8_t n)
Set the number of ipv4 address.
virtual uint32_t GetSerializedSize() const
Get the serialized size of the packet.
void SetSalvage(uint8_t salvage)
Set the salvage value for a packet.
void SetSegmentsLeft(uint8_t segmentsLeft)
Set the number of segments left to send.
uint8_t GetSalvage() const
Get the salvage value for a packet.
void SetNodesAddress(std::vector< Ipv4Address > ipv4Address)
Set the vector of ipv4 address.
uint8_t GetSegmentsLeft() const
Get the number of segments left to send.
Dsr Option Source Route.
Definition: dsr-options.h:413
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 TypeId GetInstanceTypeId() const
Get the instance type ID.
virtual uint8_t GetOptionNumber() const
Get the option number.
static const uint8_t OPT_NUMBER
Source Route option number.
Definition: dsr-options.h:418
static TypeId GetTypeId()
Get the type ID.
Introspection did not find any typical Config paths.
Definition: dsr-options.h:75
Ipv4Address SearchNextHop(Ipv4Address ipv4Address, std::vector< Ipv4Address > &vec)
Search for the next hop in the route.
Definition: dsr-options.cc:167
TracedCallback< const DsrOptionSRHeader & > m_rxPacketTrace
The receive trace back, only triggered when final destination receive data packet.
Definition: dsr-options.h:267
Ipv4Address ReverseSearchNextTwoHop(Ipv4Address ipv4Address, std::vector< Ipv4Address > &vec)
Reverse search for the next two hop in the route.
Definition: dsr-options.cc:225
TracedCallback< Ptr< const Packet > > m_dropTrace
Drop trace callback.
Definition: dsr-options.h:231
Ptr< Node > GetNodeWithAddress(Ipv4Address ipv4Address)
Get the node object with Ipv4Address.
Definition: dsr-options.cc:362
DsrOptions()
Constructor.
Definition: dsr-options.cc:89
Ptr< Node > GetNode() const
Get the node.
Definition: dsr-options.cc:105
Time ActiveRouteTimeout
The active route timeout value.
Definition: dsr-options.h:263
bool CheckDuplicates(Ipv4Address ipv4Address, std::vector< Ipv4Address > &vec)
Check if the route already contains the node ip address.
Definition: dsr-options.cc:284
void SetNode(Ptr< Node > node)
Set the node.
Definition: dsr-options.cc:99
static TypeId GetTypeId(void)
Get the type identificator.
Definition: dsr-options.cc:68
virtual uint8_t GetOptionNumber() const =0
Get the option number.
std::vector< Ipv4Address > m_finalRoute
The vector of final Ipv4 address.
Definition: dsr-options.h:259
void PrintVector(std::vector< Ipv4Address > &vec)
Print out the elements in the route vector.
Definition: dsr-options.cc:244
bool IfDuplicates(std::vector< Ipv4Address > &vec, std::vector< Ipv4Address > &vec2)
Check if the two vectors contain duplicate or not.
Definition: dsr-options.cc:264
bool ReverseRoutes(std::vector< Ipv4Address > &vec)
Reverse the routes.
Definition: dsr-options.cc:149
void RemoveDuplicates(std::vector< Ipv4Address > &vec)
Remove the duplicates from the route.
Definition: dsr-options.cc:301
uint32_t GetIDfromIP(Ipv4Address address)
Get the node id with Ipv4Address.
Definition: dsr-options.cc:346
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:127
bool ContainAddressAfter(Ipv4Address ipv4Address, Ipv4Address destAddress, std::vector< Ipv4Address > &nodeList)
Search for the ipv4 address in the node list.
Definition: dsr-options.cc:111
Ipv4Address ReverseSearchNextHop(Ipv4Address ipv4Address, std::vector< Ipv4Address > &vec)
Reverse search for the next hop in the route.
Definition: dsr-options.cc:199
virtual ~DsrOptions()
Destructor.
Definition: dsr-options.cc:94
Ptr< Ipv4Route > m_ipv4Route
The ipv4 route.
Definition: dsr-options.h:247
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:139
Ptr< Node > m_node
the node
Definition: dsr-options.h:270
DsrRouteCacheEntry class for entries in the route cache.
Definition: dsr-rcache.h:221
IP_VECTOR GetVector() const
Get the IP vector.
Definition: dsr-rcache.h:293
std::vector< Ipv4Address > IP_VECTOR
Define the vector to hold Ip address.
Definition: dsr-rcache.h:223
Header of Dsr Routing.
Dsr Routing base.
Definition: dsr-routing.h:96
#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
Ptr< const AttributeAccessor > MakeUintegerAccessor(T1 a1)
Definition: uinteger.h:45
#define NS_FATAL_ERROR(msg)
Report a fatal error with a message and terminate.
Definition: fatal-error.h:165
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:206
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
Definition: log.h:274
#define NS_LOG_LOGIC(msg)
Use NS_LOG to output a message of level LOG_LOGIC.
Definition: log.h:290
#define NS_LOG_FUNCTION_NOARGS()
Output the name of the function.
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by ",...
#define NS_LOG_INFO(msg)
Use NS_LOG to output a message of level LOG_INFO.
Definition: log.h:282
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition: object-base.h:45
Ptr< const TraceSourceAccessor > MakeTraceSourceAccessor(T a)
Create a TraceSourceAccessor which will control access to the underlying trace source.
address
Definition: first.py:40
Every class exported by the ns3 library is enclosed in the ns3 namespace.
uint8_t data[writeSize]