A Discrete-Event Network Simulator
API
dsr-options.h
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 #ifndef DSR_OPTION_H
33 #define DSR_OPTION_H
34 
35 #include <map>
36 #include <list>
37 
38 #include "ns3/buffer.h"
39 #include "ns3/packet.h"
40 #include "ns3/callback.h"
41 #include "ns3/ptr.h"
42 #include "ns3/udp-l4-protocol.h"
43 #include "ns3/ipv4.h"
44 #include "ns3/ipv4-route.h"
45 #include "ns3/object.h"
46 #include "ns3/node.h"
47 #include "ns3/ipv4-interface.h"
48 #include "ns3/ipv4-header.h"
49 #include "ns3/ipv4-address.h"
50 #include "ns3/traced-callback.h"
51 #include "ns3/output-stream-wrapper.h"
52 #include "ns3/timer.h"
53 
54 #include "dsr-rsendbuff.h"
55 #include "dsr-maintain-buff.h"
56 #include "dsr-option-header.h"
57 #include "dsr-rcache.h"
58 #include "dsr-routing.h"
60 
61 namespace ns3 {
62 
63 class Packet;
64 class NetDevice;
65 class Node;
66 class Ipv4Address;
67 class Ipv4Interface;
68 class Ipv4Route;
69 class Ipv4;
70 class Time;
71 
72 namespace dsr {
73 
74 class DsrOptions : public Object
75 {
76 public:
81  static TypeId GetTypeId (void);
85  DsrOptions ();
89  virtual ~DsrOptions ();
94  virtual uint8_t GetOptionNumber () const = 0;
99  void SetNode (Ptr<Node> node);
104  Ptr<Node> GetNode () const;
113  bool ContainAddressAfter (Ipv4Address ipv4Address, Ipv4Address destAddress, std::vector<Ipv4Address> &nodeList);
121  std::vector<Ipv4Address> CutRoute (Ipv4Address ipv4Address, std::vector<Ipv4Address> &nodeList);
130  virtual Ptr<Ipv4Route> SetRoute (Ipv4Address nextHop, Ipv4Address srcAddress);
137  bool ReverseRoutes (std::vector<Ipv4Address>& vec);
145  Ipv4Address SearchNextHop (Ipv4Address ipv4Address, std::vector<Ipv4Address>& vec);
153  Ipv4Address ReverseSearchNextHop (Ipv4Address ipv4Address, std::vector<Ipv4Address>& vec);
161  Ipv4Address ReverseSearchNextTwoHop (Ipv4Address ipv4Address, std::vector<Ipv4Address>& vec);
166  void PrintVector (std::vector<Ipv4Address>& vec);
174  bool IfDuplicates (std::vector<Ipv4Address>& vec, std::vector<Ipv4Address>& vec2);
182  bool CheckDuplicates (Ipv4Address ipv4Address, std::vector<Ipv4Address>& vec);
188  void RemoveDuplicates (std::vector<Ipv4Address>& vec);
196  void ScheduleReply (Ptr<Packet> &packet, std::vector<Ipv4Address> &nodeList, Ipv4Address &source, Ipv4Address &destination);
203  uint32_t GetIDfromIP (Ipv4Address address);
225  virtual uint8_t Process (Ptr<Packet> packet, Ptr<Packet> dsrP, Ipv4Address ipv4Address, Ipv4Address source, Ipv4Header const& ipv4Header, uint8_t protocol, bool& isPromisc, Ipv4Address promiscSource) = 0;
226 
227 protected:
255  std::vector<Ipv4Address> m_ipv4Address;
259  std::vector<Ipv4Address> m_finalRoute;
268 
269 private:
271 };
272 
277 class DsrOptionPad1 : public DsrOptions
278 {
279 public:
283  static const uint8_t OPT_NUMBER = 224;
284 
289  static TypeId GetTypeId ();
290 
291  DsrOptionPad1 ();
292  virtual ~DsrOptionPad1 ();
293 
294  virtual uint8_t GetOptionNumber () const;
295  virtual uint8_t Process (Ptr<Packet> packet, Ptr<Packet> dsrP, Ipv4Address ipv4Address, Ipv4Address source, Ipv4Header const& ipv4Header, uint8_t protocol, bool& isPromisc, Ipv4Address promiscSource);
296 };
297 
302 class DsrOptionPadn : public DsrOptions
303 {
304 public:
308  static const uint8_t OPT_NUMBER = 0;
309 
314  static TypeId GetTypeId ();
315 
316  DsrOptionPadn ();
317  virtual ~DsrOptionPadn ();
318 
319  virtual uint8_t GetOptionNumber () const;
320  virtual uint8_t Process (Ptr<Packet> packet, Ptr<Packet> dsrP, Ipv4Address ipv4Address, Ipv4Address source, Ipv4Header const& ipv4Header, uint8_t protocol, bool& isPromisc, Ipv4Address promiscSource);
321 };
322 
327 class DsrOptionRreq : public DsrOptions
328 {
329 public:
333  static const uint8_t OPT_NUMBER = 1;
334 
339  static TypeId GetTypeId ();
344  virtual TypeId GetInstanceTypeId () const;
348  DsrOptionRreq ();
352  virtual ~DsrOptionRreq ();
353 
354  virtual uint8_t GetOptionNumber () const;
355  virtual uint8_t Process (Ptr<Packet> packet, Ptr<Packet> dsrP, Ipv4Address ipv4Address, Ipv4Address source, Ipv4Header const& ipv4Header, uint8_t protocol, bool& isPromisc, Ipv4Address promiscSource);
356 
357 private:
366 };
367 
372 class DsrOptionRrep : public DsrOptions
373 {
374 public:
378  static const uint8_t OPT_NUMBER = 2;
379 
384  static TypeId GetTypeId ();
389  virtual TypeId GetInstanceTypeId () const;
390 
391  DsrOptionRrep ();
392  virtual ~DsrOptionRrep ();
393 
394  virtual uint8_t GetOptionNumber () const;
395  virtual uint8_t Process (Ptr<Packet> packet, Ptr<Packet> dsrP, Ipv4Address ipv4Address, Ipv4Address source, Ipv4Header const& ipv4Header, uint8_t protocol, bool& isPromisc, Ipv4Address promiscSource);
396 
397 private:
406 };
407 
412 class DsrOptionSR : public DsrOptions
413 {
414 public:
418  static const uint8_t OPT_NUMBER = 96;
419 
424  static TypeId GetTypeId ();
429  virtual TypeId GetInstanceTypeId () const;
430 
431  DsrOptionSR ();
432  virtual ~DsrOptionSR ();
433 
434  virtual uint8_t GetOptionNumber () const;
435  virtual uint8_t Process (Ptr<Packet> packet, Ptr<Packet> dsrP, Ipv4Address ipv4Address, Ipv4Address source, Ipv4Header const& ipv4Header, uint8_t protocol, bool& isPromisc, Ipv4Address promiscSource);
436 
437 private:
442 };
443 
448 class DsrOptionRerr : public DsrOptions
449 {
450 public:
454  static const uint8_t OPT_NUMBER = 3;
455 
460  static TypeId GetTypeId ();
465  virtual TypeId GetInstanceTypeId () const;
466 
467  DsrOptionRerr ();
468  virtual ~DsrOptionRerr ();
469 
470  virtual uint8_t GetOptionNumber () const;
471  virtual uint8_t Process (Ptr<Packet> packet, Ptr<Packet> dsrP, Ipv4Address ipv4Address, Ipv4Address source, Ipv4Header const& ipv4Header, uint8_t protocol, bool& isPromisc, Ipv4Address promiscSource);
482  uint8_t DoSendError (Ptr<Packet> p, DsrOptionRerrUnreachHeader &rerr, uint32_t rerrSize, Ipv4Address ipv4Address, uint8_t protocol);
483 
484 private:
493 };
494 
500 {
501 public:
505  static const uint8_t OPT_NUMBER = 160;
506 
511  static TypeId GetTypeId ();
516  virtual TypeId GetInstanceTypeId () const;
517 
518  DsrOptionAckReq ();
519  virtual ~DsrOptionAckReq ();
520 
521  virtual uint8_t GetOptionNumber () const;
522  virtual uint8_t Process (Ptr<Packet> packet, Ptr<Packet> dsrP, Ipv4Address ipv4Address, Ipv4Address source, Ipv4Header const& ipv4Header, uint8_t protocol, bool& isPromisc, Ipv4Address promiscSource);
523 
524 private:
533 };
534 
539 class DsrOptionAck : public DsrOptions
540 {
541 public:
545  static const uint8_t OPT_NUMBER = 32;
546 
551  static TypeId GetTypeId ();
556  virtual TypeId GetInstanceTypeId () const;
557 
558  DsrOptionAck ();
559  virtual ~DsrOptionAck ();
560 
561  virtual uint8_t GetOptionNumber () const;
562  virtual uint8_t Process (Ptr<Packet> packet, Ptr<Packet> dsrP, Ipv4Address ipv4Address, Ipv4Address source, Ipv4Header const& ipv4Header, uint8_t protocol, bool& isPromisc, Ipv4Address promiscSource);
563 
564 private:
573 };
574 } // namespace dsr
575 } // Namespace ns3
576 
577 #endif
Ipv4 addresses are stored in host order in this class.
Definition: ipv4-address.h:41
Packet header for IPv4.
Definition: ipv4-header.h:34
A base class which provides memory management and object aggregation.
Definition: object.h:88
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:103
Forward calls to a chain of Callback.
a unique identifier for an interface.
Definition: type-id.h:59
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.
Ptr< Ipv4 > m_ipv4
The ipv4 layer 3.
Definition: dsr-options.h:572
static const uint8_t OPT_NUMBER
The Dsr Ack option number.
Definition: dsr-options.h:545
static TypeId GetTypeId()
Get the type ID.
Ptr< dsr::DsrRouteCache > m_routeCache
The route cache.
Definition: dsr-options.h:568
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.
Ptr< dsr::DsrRouteCache > m_routeCache
The route cache.
Definition: dsr-options.h:528
Ptr< Ipv4 > m_ipv4
The ipv4 layer 3.
Definition: dsr-options.h:532
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
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
Dsr Option Route Error.
Definition: dsr-options.h:449
Ptr< Ipv4 > m_ipv4
The ipv4 layer 3.
Definition: dsr-options.h:492
uint8_t DoSendError(Ptr< Packet > p, DsrOptionRerrUnreachHeader &rerr, uint32_t rerrSize, Ipv4Address ipv4Address, uint8_t protocol)
Do Send error message.
Ptr< dsr::DsrRouteCache > m_routeCache
The route cache.
Definition: dsr-options.h:488
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.
Dsr Option Route Reply.
Definition: dsr-options.h:373
virtual TypeId GetInstanceTypeId() const
Get the instance type ID.
Definition: dsr-options.cc:983
virtual uint8_t GetOptionNumber() const
Get the option number.
Definition: dsr-options.cc:988
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:995
Ptr< Ipv4 > m_ipv4
The ip layer 3.
Definition: dsr-options.h:405
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:963
Ptr< dsr::DsrRouteCache > m_routeCache
The route cache.
Definition: dsr-options.h:401
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
Ptr< Ipv4 > m_ipv4
The ipv4.
Definition: dsr-options.h:365
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
Ptr< dsr::DsrRouteCache > m_routeCache
The route cache.
Definition: dsr-options.h:361
DsrOptionRreq()
Constructor.
Definition: dsr-options.cc:478
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
Ptr< Ipv4 > m_ipv4
The ip layer 3.
Definition: dsr-options.h:441
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.
Ptr< dsr::DsrRreqTable > m_rreqTable
The route request table.
Definition: dsr-options.h:239
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
Ipv4Address Broadcast
The broadcast IP address.
Definition: dsr-options.h:235
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
Ptr< Ipv4 > m_ipv4
The ipv4.
Definition: dsr-options.h:251
void ScheduleReply(Ptr< Packet > &packet, std::vector< Ipv4Address > &nodeList, Ipv4Address &source, Ipv4Address &destination)
Schedule the intermediate node route request broadcast.
virtual uint8_t Process(Ptr< Packet > packet, Ptr< Packet > dsrP, Ipv4Address ipv4Address, Ipv4Address source, Ipv4Header const &ipv4Header, uint8_t protocol, bool &isPromisc, Ipv4Address promiscSource)=0
Process method.
virtual ~DsrOptions()
Destructor.
Definition: dsr-options.cc:94
Ptr< dsr::DsrRouteCache > m_routeCache
The route cache table.
Definition: dsr-options.h:243
Ptr< Ipv4Route > m_ipv4Route
The ipv4 route.
Definition: dsr-options.h:247
std::vector< Ipv4Address > m_ipv4Address
The vector of Ipv4 address.
Definition: dsr-options.h:255
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
address
Definition: first.py:44
void(* Time)(Time oldValue, Time newValue)
TracedValue callback signature for Time.
Definition: nstime.h:793
Every class exported by the ns3 library is enclosed in the ns3 namespace.