A Discrete-Event Network Simulator
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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;
109  bool ContainAddressAfter (Ipv4Address ipv4Address, Ipv4Address destAddress, std::vector<Ipv4Address> &nodeList);
114  std::vector<Ipv4Address> CutRoute (Ipv4Address ipv4Address, std::vector<Ipv4Address> &nodeList);
120  virtual Ptr<Ipv4Route> SetRoute (Ipv4Address nextHop, Ipv4Address srcAddress);
125  bool ReverseRoutes (std::vector<Ipv4Address>& vec);
130  Ipv4Address SearchNextHop (Ipv4Address ipv4Address, std::vector<Ipv4Address>& vec);
135  Ipv4Address ReverseSearchNextHop (Ipv4Address ipv4Address, std::vector<Ipv4Address>& vec);
140  Ipv4Address ReverseSearchNextTwoHop (Ipv4Address ipv4Address, std::vector<Ipv4Address>& vec);
144  void PrintVector (std::vector<Ipv4Address>& vec);
149  bool IfDuplicates (std::vector<Ipv4Address>& vec, std::vector<Ipv4Address>& vec2);
154  bool CheckDuplicates (Ipv4Address ipv4Address, std::vector<Ipv4Address>& vec);
155  /*
156  * \brief Remove the duplicates from the route
157  * \return the route after route shorten
158  */
159  void RemoveDuplicates (std::vector<Ipv4Address>& vec);
167  void ScheduleReply (Ptr<Packet> &packet, std::vector<Ipv4Address> &nodeList, Ipv4Address &source, Ipv4Address &destination);
172  uint32_t GetIDfromIP (Ipv4Address address);
189  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;
190 
191 protected:
219  std::vector<Ipv4Address> m_ipv4Address;
223  std::vector<Ipv4Address> m_finalRoute;
232 
233 private:
235 };
236 
241 class DsrOptionPad1 : public DsrOptions
242 {
243 public:
247  static const uint8_t OPT_NUMBER = 224;
252  static TypeId GetTypeId ();
256  DsrOptionPad1 ();
260  virtual ~DsrOptionPad1 ();
265  virtual uint8_t GetOptionNumber () const;
277  virtual uint8_t Process (Ptr<Packet> packet, Ptr<Packet> dsrP, Ipv4Address ipv4Address, Ipv4Address source, Ipv4Header const& ipv4Header, uint8_t protocol, bool& isPromisc, Ipv4Address promiscSource);
278 };
279 
284 class DsrOptionPadn : public DsrOptions
285 {
286 public:
290  static const uint8_t OPT_NUMBER = 0;
295  static TypeId GetTypeId ();
299  DsrOptionPadn ();
303  virtual ~DsrOptionPadn ();
308  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;
338  static TypeId GetTypeId ();
343  virtual TypeId GetInstanceTypeId () const;
347  DsrOptionRreq ();
351  virtual ~DsrOptionRreq ();
356  virtual uint8_t GetOptionNumber () const;
368  virtual uint8_t Process (Ptr<Packet> packet, Ptr<Packet> dsrP, Ipv4Address ipv4Address, Ipv4Address source, Ipv4Header const& ipv4Header, uint8_t protocol, bool& isPromisc, Ipv4Address promiscSource);
369 
370 private:
379 };
380 
385 class DsrOptionRrep : public DsrOptions
386 {
387 public:
391  static const uint8_t OPT_NUMBER = 2;
396  static TypeId GetTypeId ();
401  virtual TypeId GetInstanceTypeId () const;
405  DsrOptionRrep ();
409  virtual ~DsrOptionRrep ();
414  virtual uint8_t GetOptionNumber () const;
426  virtual uint8_t Process (Ptr<Packet> packet, Ptr<Packet> dsrP, Ipv4Address ipv4Address, Ipv4Address source, Ipv4Header const& ipv4Header, uint8_t protocol, bool& isPromisc, Ipv4Address promiscSource);
427 
428 private:
437 };
438 
443 class DsrOptionSR : public DsrOptions
444 {
445 public:
449  static const uint8_t OPT_NUMBER = 96;
454  static TypeId GetTypeId ();
459  virtual TypeId GetInstanceTypeId () const;
463  DsrOptionSR ();
467  virtual ~DsrOptionSR ();
472  virtual uint8_t GetOptionNumber () const;
484  virtual uint8_t Process (Ptr<Packet> packet, Ptr<Packet> dsrP, Ipv4Address ipv4Address, Ipv4Address source, Ipv4Header const& ipv4Header, uint8_t protocol, bool& isPromisc, Ipv4Address promiscSource);
485 
486 private:
491 };
492 
497 class DsrOptionRerr : public DsrOptions
498 {
499 public:
503  static const uint8_t OPT_NUMBER = 3;
508  static TypeId GetTypeId ();
513  virtual TypeId GetInstanceTypeId () const;
517  DsrOptionRerr ();
521  virtual ~DsrOptionRerr ();
526  virtual uint8_t GetOptionNumber () const;
538  virtual uint8_t Process (Ptr<Packet> packet, Ptr<Packet> dsrP, Ipv4Address ipv4Address, Ipv4Address source, Ipv4Header const& ipv4Header, uint8_t protocol, bool& isPromisc, Ipv4Address promiscSource);
549  uint8_t DoSendError (Ptr<Packet> p, DsrOptionRerrUnreachHeader &rerr, uint32_t rerrSize, Ipv4Address ipv4Address, uint8_t protocol);
550 
551 private:
560 };
561 
567 {
568 public:
572  static const uint8_t OPT_NUMBER = 160;
577  static TypeId GetTypeId ();
582  virtual TypeId GetInstanceTypeId () const;
586  DsrOptionAckReq ();
590  virtual ~DsrOptionAckReq ();
595  virtual uint8_t GetOptionNumber () const;
607  virtual uint8_t Process (Ptr<Packet> packet, Ptr<Packet> dsrP, Ipv4Address ipv4Address, Ipv4Address source, Ipv4Header const& ipv4Header, uint8_t protocol, bool& isPromisc, Ipv4Address promiscSource);
608 
609 private:
618 };
619 
624 class DsrOptionAck : public DsrOptions
625 {
626 public:
630  static const uint8_t OPT_NUMBER = 32;
635  static TypeId GetTypeId ();
640  virtual TypeId GetInstanceTypeId () const;
644  DsrOptionAck ();
648  virtual ~DsrOptionAck ();
653  virtual uint8_t GetOptionNumber () const;
665  virtual uint8_t Process (Ptr<Packet> packet, Ptr<Packet> dsrP, Ipv4Address ipv4Address, Ipv4Address source, Ipv4Header const& ipv4Header, uint8_t protocol, bool& isPromisc, Ipv4Address promiscSource);
666 
667 private:
676 };
677 } // namespace dsr
678 } // Namespace ns3
679 
680 #endif
virtual ~DsrOptionAck()
Destructor.
static const uint8_t OPT_NUMBER
Dsr Route Error option number.
Definition: dsr-options.h:503
Ptr< Ipv4 > m_ipv4
The ip layer 3.
Definition: dsr-options.h:436
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
Rreq option number.
Definition: dsr-options.h:333
DsrOptionAck()
Constructor.
keep track of time values and allow control of global simulation resolution
Definition: nstime.h:81
static const uint8_t OPT_NUMBER
Dsr ack request option number.
Definition: dsr-options.h:572
Ptr< Ipv4 > m_ipv4
The ipv4 layer 3.
Definition: dsr-options.h:559
virtual TypeId GetInstanceTypeId() const
Get the instance type ID.
static TypeId GetTypeId()
Get the type identificator.
DsrOptionRerr()
Constructor.
virtual ~DsrOptionSR()
Destructor.
static TypeId GetTypeId()
Get the type identificator.
Definition: dsr-options.cc:416
forward calls to a chain of CallbackAn ns3::TracedCallback has almost exactly the same API as a norma...
virtual uint8_t GetOptionNumber() const =0
Get the option number.
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.
DsrOptionRrep()
Constructor.
Definition: dsr-options.cc:963
DsrOptionSR()
Constructor.
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.
Dsr Option Route Error.
Definition: dsr-options.h:497
virtual TypeId GetInstanceTypeId() const
Get the instance type ID.
Definition: dsr-options.cc:465
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.
void SetNode(Ptr< Node > node)
Set the node.
Definition: dsr-options.cc:94
static const uint8_t OPT_NUMBER
Pad1 option number.
Definition: dsr-options.h:247
uint8_t DoSendError(Ptr< Packet > p, DsrOptionRerrUnreachHeader &rerr, uint32_t rerrSize, Ipv4Address ipv4Address, uint8_t protocol)
Do Send error message.
Ptr< dsr::RreqTable > m_rreqTable
The route request table.
Definition: dsr-options.h:203
uint32_t GetIDfromIP(Ipv4Address address)
Get the node id with Ipv4Address.
Definition: dsr-options.cc:341
Ptr< Ipv4 > m_ipv4
The ipv4 layer 3.
Definition: dsr-options.h:617
Packet header for IPv4.
Definition: ipv4-header.h:31
void ScheduleReply(Ptr< Packet > &packet, std::vector< Ipv4Address > &nodeList, Ipv4Address &source, Ipv4Address &destination)
Schedule the intermediate node route request broadcast.
virtual uint8_t GetOptionNumber() const
Get the option number.
Dsr Option Route Reply.
Definition: dsr-options.h:385
static TypeId GetTypeId()
Get the type identificator.
Definition: dsr-options.cc:954
DsrOptionRreq()
Constructor.
Definition: dsr-options.cc:470
Ipv4Address ReverseSearchNextTwoHop(Ipv4Address ipv4Address, std::vector< Ipv4Address > &vec)
Reverse search for the next two hop in the route.
Definition: dsr-options.cc:220
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:985
Ptr< dsr::RouteCache > m_routeCache
The route cache.
Definition: dsr-options.h:432
TracedCallback< Ptr< const Packet > > m_dropTrace
Drop trace callback.
Definition: dsr-options.h:195
static const uint8_t OPT_NUMBER
Router alert option number.
Definition: dsr-options.h:391
virtual ~DsrOptionPad1()
Destructor.
Definition: dsr-options.cc:390
static TypeId GetTypeId()
Get the type identificator.
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:441
static const uint8_t OPT_NUMBER
PadN option number.
Definition: dsr-options.h:290
Ipv4Address Broadcast
The broadcast IP address.
Definition: dsr-options.h:199
virtual ~DsrOptionRreq()
Destructor.
Definition: dsr-options.cc:475
std::vector< Ipv4Address > m_finalRoute
The vector of final Ipv4 address.
Definition: dsr-options.h:223
virtual TypeId GetInstanceTypeId() const
Get the instance type ID.
void RemoveDuplicates(std::vector< Ipv4Address > &vec)
Definition: dsr-options.cc:296
Time ActiveRouteTimeout
The active route timeout value.
Definition: dsr-options.h:227
void PrintVector(std::vector< Ipv4Address > &vec)
Print out the elements in the route vector.
Definition: dsr-options.cc:239
DsrOptionPad1()
Constructor.
Definition: dsr-options.cc:385
DsrOptionPadn()
Constructor.
Definition: dsr-options.cc:425
DsrOptions()
Constructor.
Definition: dsr-options.cc:84
virtual ~DsrOptionRrep()
Destructor.
Definition: dsr-options.cc:968
Ptr< dsr::RouteCache > m_routeCache
The route cache.
Definition: dsr-options.h:671
static const uint8_t OPT_NUMBER
The Dsr Ack option number.
Definition: dsr-options.h:630
Ipv4Address SearchNextHop(Ipv4Address ipv4Address, std::vector< Ipv4Address > &vec)
Search for the next hop in the route.
Definition: dsr-options.cc:162
Dsr Option Source Route.
Definition: dsr-options.h:443
virtual ~DsrOptionRerr()
Destructor.
TracedCallback< const DsrOptionSRHeader & > m_rxPacketTrace
Definition: dsr-options.h:231
static TypeId GetTypeId()
Get the type identificator.
Ptr< Ipv4 > m_ipv4
The ip layer 3.
Definition: dsr-options.h:490
virtual ~DsrOptions()
Destructor.
Definition: dsr-options.cc:89
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:402
Ptr< Ipv4 > m_ipv4
The ipv4 layer 3.
Definition: dsr-options.h:675
virtual ~DsrOptionPadn()
Destructor.
Definition: dsr-options.cc:430
Ptr< Node > m_node
Definition: dsr-options.h:234
static TypeId GetTypeId()
Get the type identificator.
Definition: dsr-options.cc:376
Dsr Option Rreq.
Definition: dsr-options.h:327
IPv4 Option Padn.
Definition: dsr-options.h:284
bool CheckDuplicates(Ipv4Address ipv4Address, std::vector< Ipv4Address > &vec)
Check if the route already contains the node ip address.
Definition: dsr-options.cc:279
bool ReverseRoutes(std::vector< Ipv4Address > &vec)
Reverse the routes.
Definition: dsr-options.cc:144
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:487
Route Error (RERR) Unreachable node address option Message Format.
Ptr< Ipv4Route > m_ipv4Route
The ipv4 route.
Definition: dsr-options.h:211
Ptr< Ipv4 > m_ipv4
The ipv4.
Definition: dsr-options.h:215
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:194
virtual ~DsrOptionAckReq()
Destructor.
virtual TypeId GetInstanceTypeId() const
Get the instance type ID.
static TypeId GetTypeId(void)
Get the type identificator.
Definition: dsr-options.cc:70
bool ContainAddressAfter(Ipv4Address ipv4Address, Ipv4Address destAddress, std::vector< Ipv4Address > &nodeList)
Search for the ipv4 address in the node list.
Definition: dsr-options.cc:106
virtual uint8_t GetOptionNumber() const
Get the option number.
virtual uint8_t GetOptionNumber() const
Get the option number.
Definition: dsr-options.cc:395
virtual uint8_t GetOptionNumber() const
Get the option number.
Definition: dsr-options.cc:435
Dsr Option Ack.
Definition: dsr-options.h:624
Ptr< Ipv4 > m_ipv4
The ipv4.
Definition: dsr-options.h:378
virtual TypeId GetInstanceTypeId() const
Get the instance type ID.
Definition: dsr-options.cc:973
static const uint8_t OPT_NUMBER
Source Route option number.
Definition: dsr-options.h:449
std::vector< Ipv4Address > m_ipv4Address
The vector of Ipv4 address.
Definition: dsr-options.h:219
Ptr< dsr::RouteCache > m_routeCache
The route cache.
Definition: dsr-options.h:613
virtual uint8_t GetOptionNumber() const
Get the option number.
Definition: dsr-options.cc:978
a base class which provides memory management and object aggregation
Definition: object.h:63
tuple address
Definition: first.py:37
Dsr Option Pad1.
Definition: dsr-options.h:241
Ptr< Node > GetNode() const
Get the node.
Definition: dsr-options.cc:100
virtual Ptr< Ipv4Route > SetRoute(Ipv4Address nextHop, Ipv4Address srcAddress)
Set the route to use for data packets.
Definition: dsr-options.cc:134
DsrOptionAckReq()
Constructor.
bool IfDuplicates(std::vector< Ipv4Address > &vec, std::vector< Ipv4Address > &vec2)
Check if the two vectors contain duplicate or not.
Definition: dsr-options.cc:259
Ptr< dsr::RouteCache > m_routeCache
The route cache table.
Definition: dsr-options.h:207
Ptr< Node > GetNodeWithAddress(Ipv4Address ipv4Address)
Get the node object with Ipv4Address.
Definition: dsr-options.cc:357
static TypeId GetTypeId()
Get the type identificator.
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< dsr::RouteCache > m_routeCache
The route cache.
Definition: dsr-options.h:374
a unique identifier for an interface.
Definition: type-id.h:49
Ptr< dsr::RouteCache > m_routeCache
The route cache.
Definition: dsr-options.h:555
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:122
virtual uint8_t GetOptionNumber() const
Get the option number.
Definition: dsr-options.cc:480
static TypeId GetTypeId()
Get the type identificator.
Definition: dsr-options.cc:456
virtual uint8_t GetOptionNumber() const
Get the option number.