A Discrete-Event Network Simulator
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
dsr-option-header.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_HEADER_H
33 #define DSR_OPTION_HEADER_H
34 
35 #include <ostream>
36 #include <algorithm>
37 
38 #include "ns3/header.h"
39 #include "ns3/ipv4-address.h"
40 #include "ns3/simulator.h"
41 
42 namespace ns3 {
43 
44 class Time;
45 namespace dsr {
50 class DsrOptionHeader : public Header
51 {
52 public:
57  struct Alignment
58  {
59  uint8_t factor;
60  uint8_t offset;
61  };
66  static TypeId GetTypeId ();
71  virtual TypeId GetInstanceTypeId () const;
75  DsrOptionHeader ();
79  virtual ~DsrOptionHeader ();
84  void SetType (uint8_t type);
89  uint8_t GetType () const;
94  void SetLength (uint8_t length);
99  uint8_t GetLength () const;
105  virtual void Print (std::ostream &os) const;
110  virtual uint32_t GetSerializedSize () const;
115  virtual void Serialize (Buffer::Iterator start) const;
121  virtual uint32_t Deserialize (Buffer::Iterator start);
129  virtual Alignment GetAlignment () const;
130 
131 private:
135  uint8_t m_type;
139  uint8_t m_length;
144 };
145 
151 {
152 public:
157  static TypeId GetTypeId ();
162  virtual TypeId GetInstanceTypeId () const;
170  virtual ~DsrOptionPad1Header ();
176  virtual void Print (std::ostream &os) const;
181  virtual uint32_t GetSerializedSize () const;
186  virtual void Serialize (Buffer::Iterator start) const;
192  virtual uint32_t Deserialize (Buffer::Iterator start);
193 };
194 
200 {
201 public:
206  static TypeId GetTypeId ();
211  virtual TypeId GetInstanceTypeId () const;
216  DsrOptionPadnHeader (uint32_t pad = 2);
220  virtual ~DsrOptionPadnHeader ();
226  virtual void Print (std::ostream &os) const;
231  virtual uint32_t GetSerializedSize () const;
236  virtual void Serialize (Buffer::Iterator start) const;
242  virtual uint32_t Deserialize (Buffer::Iterator start);
243 };
244 
273 {
274 public:
279  static TypeId GetTypeId ();
284  virtual TypeId GetInstanceTypeId () const;
292  virtual ~DsrOptionRreqHeader ();
297  void SetNumberAddress (uint8_t n);
307  void SetTarget (Ipv4Address target);
312  void SetNodesAddress (std::vector<Ipv4Address> ipv4Address);
317  std::vector<Ipv4Address> GetNodesAddresses () const;
322  uint32_t GetNodesNumber () const;
327  void AddNodeAddress (Ipv4Address ipv4);
333  void SetNodeAddress (uint8_t index, Ipv4Address addr);
339  Ipv4Address GetNodeAddress (uint8_t index) const;
344  void SetId (uint16_t identification);
349  uint16_t GetId () const;
355  virtual void Print (std::ostream &os) const;
360  virtual uint32_t GetSerializedSize () const;
365  virtual void Serialize (Buffer::Iterator start) const;
371  virtual uint32_t Deserialize (Buffer::Iterator start);
376  virtual Alignment GetAlignment () const;
377 
378 private:
382  uint32_t m_dataLength;
387  /*
388  * Ipv4 address of target node
389  */
391  /*
392  * Ipv4 address to write when desearizing the packet
393  */
398  typedef std::vector<Ipv4Address> VectorIpv4Address_t;
403 };
404 
430 // The Route Reply header modified for ns-3 implementation
453 {
454 public:
459  static TypeId GetTypeId ();
464  virtual TypeId GetInstanceTypeId () const;
472  virtual ~DsrOptionRrepHeader ();
477  void SetNumberAddress (uint8_t n);
482  void SetNodesAddress (std::vector<Ipv4Address> ipv4Address);
487  std::vector<Ipv4Address> GetNodesAddress () const;
488  /*
489  * \brief Get the target node Ip address
490  * \return the target address
491  */
492  Ipv4Address GetTargetAddress (std::vector<Ipv4Address> ipv4Address) const;
498  void SetNodeAddress (uint8_t index, Ipv4Address addr);
504  Ipv4Address GetNodeAddress (uint8_t index) const;
510  virtual void Print (std::ostream &os) const;
515  virtual uint32_t GetSerializedSize () const;
520  virtual void Serialize (Buffer::Iterator start) const;
526  virtual uint32_t Deserialize (Buffer::Iterator start);
531  virtual Alignment GetAlignment () const;
532 
533 private:
534  /*
535  * The Ip address to write to when deserialize the packet
536  */
541  typedef std::vector<Ipv4Address> VectorIpv4Address_t;
546 };
547 
574 {
575 public:
580  static TypeId GetTypeId ();
585  virtual TypeId GetInstanceTypeId () const;
593  virtual ~DsrOptionSRHeader ();
594  /*
595  * \brief Set the number of segments left to send
596  * \param The segments left
597  */
598  void SetSegmentsLeft (uint8_t segmentsLeft);
599  /*
600  * \brief Get the number of segments left to send
601  * \return The segments left
602  */
603  uint8_t GetSegmentsLeft () const;
608  void SetNumberAddress (uint8_t n);
613  void SetNodesAddress (std::vector<Ipv4Address> ipv4Address);
618  std::vector<Ipv4Address> GetNodesAddress () const;
619  /*
620  * \brief Get the node list size which is the number of ip address of the route
621  * \return the node list size
622  */
623  uint8_t GetNodeListSize () const;
629  void SetNodeAddress (uint8_t index, Ipv4Address addr);
635  Ipv4Address GetNodeAddress (uint8_t index) const;
636  /*
637  * \brief Set the salvage value for a packet
638  * \param The salvage value of the packet
639  */
640  void SetSalvage (uint8_t salvage);
641  /*
642  * \brief Get the salvage value for a packet
643  * \return The salvage value of the packet
644  */
645  uint8_t GetSalvage () const;
651  virtual void Print (std::ostream &os) const;
656  virtual uint32_t GetSerializedSize () const;
661  virtual void Serialize (Buffer::Iterator start) const;
667  virtual uint32_t Deserialize (Buffer::Iterator start);
672  virtual Alignment GetAlignment () const;
673 
674 private:
682  uint8_t m_segmentsLeft;
686  uint8_t m_salvage;
690  typedef std::vector<Ipv4Address> VectorIpv4Address_t;
695 };
696 
722 // / Error type
724 {
725  NODE_UNREACHABLE = 1, // !< NODE_UNREACHABLE
726  FLOW_STATE_NOT_SUPPORTED = 2, // !< FLOW_STATE_NOT_SUPPORTED
727  OPTION_NOT_SUPPORTED = 3, // !< OPTION_NOT_SUPPORTED
728 };
729 
731 {
732 public:
737  static TypeId GetTypeId ();
742  virtual TypeId GetInstanceTypeId () const;
750  virtual ~DsrOptionRerrHeader ();
755  void SetErrorType (uint8_t errorType);
760  uint8_t GetErrorType () const;
765  virtual void SetErrorSrc (Ipv4Address errorSrcAddress);
770  virtual Ipv4Address GetErrorSrc () const;
774  virtual void SetSalvage (uint8_t salvage);
779  virtual uint8_t GetSalvage () const;
784  virtual void SetErrorDst (Ipv4Address errorDstAddress);
789  virtual Ipv4Address GetErrorDst () const;
795  virtual void Print (std::ostream &os) const;
800  virtual uint32_t GetSerializedSize () const;
805  virtual void Serialize (Buffer::Iterator start) const;
811  virtual uint32_t Deserialize (Buffer::Iterator start);
816  virtual Alignment GetAlignment () const;
817 
818 private:
822  uint8_t m_optDataLen;
826  uint8_t m_errorType;
830  uint8_t m_reserved;
834  uint8_t m_salvage;
838  uint16_t m_errorLength;
851 };
852 
872 /*
873  * \brief The type-specific info field
874  * \verbatim
875  | 0 | 1 | 2 | 3 |
876  0 1 2 3 4 5 6 7 0 1 2 3 4 5 6 7 0 1 2 3 4 5 6 7 0 1 2 3 4 5 6 7
877  +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
878  | Unreachable Node Address |
879  +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
880  \endverbatim
881  */
882 
884 {
885 public:
890  static TypeId GetTypeId ();
895  virtual TypeId GetInstanceTypeId () const;
903  virtual ~DsrOptionRerrUnreachHeader ();
908  virtual void SetErrorSrc (Ipv4Address errorSrcAddress);
913  virtual Ipv4Address GetErrorSrc () const;
917  virtual void SetSalvage (uint8_t salvage);
922  virtual uint8_t GetSalvage () const;
927  virtual void SetErrorDst (Ipv4Address errorDstAddress);
932  virtual Ipv4Address GetErrorDst () const;
937  void SetUnreachNode (Ipv4Address unreachNode);
942  Ipv4Address GetUnreachNode () const;
947  void SetOriginalDst (Ipv4Address originalDst);
952  Ipv4Address GetOriginalDst () const;
958  virtual void Print (std::ostream &os) const;
963  virtual uint32_t GetSerializedSize () const;
968  virtual void Serialize (Buffer::Iterator start) const;
974  virtual uint32_t Deserialize (Buffer::Iterator start);
979  virtual Alignment GetAlignment () const;
980 
981 private:
985  uint8_t m_optDataLen;
989  uint8_t m_errorType;
993  uint8_t m_reserved;
997  uint8_t m_salvage;
1017  uint16_t m_typeSpecific;
1018 };
1019 
1039 /*
1040  * \brief The type-specific info field
1041  * \unsupported option
1042  * \verbatim
1043  | 0 |
1044  0 1 2 3 4 5 6 7
1045  +-+-+-+-+-+-+-+-+
1046  |Unsupported Opt|
1047  +-+-+-+-+-+-+-+-+
1048  \endverbatim
1049  */
1050 
1052 {
1053 public:
1058  static TypeId GetTypeId ();
1063  virtual TypeId GetInstanceTypeId () const;
1071  virtual ~DsrOptionRerrUnsupportHeader ();
1076  virtual void SetErrorSrc (Ipv4Address errorSrcAddress);
1081  virtual Ipv4Address GetErrorSrc () const;
1085  virtual void SetSalvage (uint8_t salvage);
1090  virtual uint8_t GetSalvage () const;
1095  virtual void SetErrorDst (Ipv4Address errorDstAddress);
1100  virtual Ipv4Address GetErrorDst () const;
1105  void SetUnsupported (uint16_t optionType);
1110  uint16_t GetUnsupported () const;
1116  virtual void Print (std::ostream &os) const;
1121  virtual uint32_t GetSerializedSize () const;
1126  virtual void Serialize (Buffer::Iterator start) const;
1132  virtual uint32_t Deserialize (Buffer::Iterator start);
1137  virtual Alignment GetAlignment () const;
1138 
1139 private:
1143  uint8_t m_optDataLen;
1147  uint8_t m_errorType;
1151  uint8_t m_reserved;
1155  uint8_t m_salvage;
1167  uint16_t m_unsupport;
1168 };
1169 
1188 {
1189 public:
1194  static TypeId GetTypeId ();
1199  virtual TypeId GetInstanceTypeId () const;
1207  virtual ~DsrOptionAckReqHeader ();
1212  void SetAckId (uint16_t identification);
1217  uint16_t GetAckId () const;
1223  virtual void Print (std::ostream &os) const;
1228  virtual uint32_t GetSerializedSize () const;
1233  virtual void Serialize (Buffer::Iterator start) const;
1239  virtual uint32_t Deserialize (Buffer::Iterator start);
1244  virtual Alignment GetAlignment () const;
1245 
1246 private:
1247  /*
1248  * The option data length
1249  */
1250  uint8_t m_optDataLen;
1251  /*
1252  * The identification field
1253  */
1255 };
1256 
1279 {
1280 public:
1285  static TypeId GetTypeId ();
1290  virtual TypeId GetInstanceTypeId () const;
1294  DsrOptionAckHeader ();
1298  virtual ~DsrOptionAckHeader ();
1303  void SetAckId (uint16_t identification);
1308  uint16_t GetAckId () const;
1313  void SetRealSrc (Ipv4Address realSrcAddress);
1318  Ipv4Address GetRealSrc () const;
1323  void SetRealDst (Ipv4Address realDstAddress);
1328  Ipv4Address GetRealDst () const;
1334  virtual void Print (std::ostream &os) const;
1339  virtual uint32_t GetSerializedSize () const;
1344  virtual void Serialize (Buffer::Iterator start) const;
1350  virtual uint32_t Deserialize (Buffer::Iterator start);
1355  virtual Alignment GetAlignment () const;
1356 
1357 private:
1361  uint8_t m_optDataLen;
1374 };
1375 
1376 static inline std::ostream & operator<< (std::ostream& os, const DsrOptionSRHeader & sr)
1377 {
1378  sr.Print (os);
1379  return os;
1380 }
1381 
1382 } // namespace dsr
1383 } // namespace ns3
1384 
1385 #endif /* DSR_OPTION_HEADER_H */