1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2010 Hemanth Narra
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: Hemanth Narra <hemanth@ittc.ku.com>
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 DSDV_PACKET_H
33 #define DSDV_PACKET_H
34 
35 #include <iostream>
36 #include "ns3/header.h"
37 #include "ns3/ipv4-address.h"
38 #include "ns3/nstime.h"
39 
40 namespace ns3 {
41 namespace dsdv {
42 /**
43  * \ingroup dsdv
44  * \brief DSDV Update Packet Format
45  * \verbatim
46  |      0        |      1        |      2        |       3       |
47   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
48  +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
49  |                      Destination Address                      |
50  +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
51  |                            HopCount                           |
52  +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
53  |                       Sequence Number                         |
54  +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
55  * \endverbatim
56  */
57 
58 class DsdvHeader : public Header
59 {
60 public:
61   /**
62    * Constructor
63    *
64    * \param dst destination IP address
65    * \param hopcount hop count
66    * \param dstSeqNo destination sequence number
67    */
68   DsdvHeader (Ipv4Address dst = Ipv4Address (), uint32_t hopcount = 0, uint32_t dstSeqNo = 0);
69   virtual ~DsdvHeader ();
70   /**
71    * \brief Get the type ID.
72    * \return the object TypeId
73    */
74   static TypeId GetTypeId (void);
75   virtual TypeId GetInstanceTypeId (void) const;
76   virtual uint32_t GetSerializedSize () const;
77   virtual void Serialize (Buffer::Iterator start) const;
78   virtual uint32_t Deserialize (Buffer::Iterator start);
79   virtual void Print (std::ostream &os) const;
80 
81   /**
82    * Set destination address
83    * \param destination the destination IPv4 address
84    */
85   void
SetDst(Ipv4Address destination)86   SetDst (Ipv4Address destination)
87   {
88     m_dst = destination;
89   }
90   /**
91    * Get destination address
92    * \returns the destination IPv4 address
93    */
94   Ipv4Address
GetDst()95   GetDst () const
96   {
97     return m_dst;
98   }
99   /**
100    * Set hop count
101    * \param hopCount the hop count
102    */
103   void
SetHopCount(uint32_t hopCount)104   SetHopCount (uint32_t hopCount)
105   {
106     m_hopCount = hopCount;
107   }
108   /**
109    * Get hop count
110    * \returns the hop count
111    */
112   uint32_t
GetHopCount()113   GetHopCount () const
114   {
115     return m_hopCount;
116   }
117   /**
118    * Set destination sequence number
119    * \param sequenceNumber The sequence number
120    */
121   void
SetDstSeqno(uint32_t sequenceNumber)122   SetDstSeqno (uint32_t sequenceNumber)
123   {
124     m_dstSeqNo = sequenceNumber;
125   }
126   /**
127    * Get destination sequence number
128    * \returns the destination sequence number
129    */
130   uint32_t
GetDstSeqno()131   GetDstSeqno () const
132   {
133     return m_dstSeqNo;
134   }
135 private:
136   Ipv4Address m_dst; ///< Destination IP Address
137   uint32_t m_hopCount; ///< Number of Hops
138   uint32_t m_dstSeqNo; ///< Destination Sequence Number
139 };
140 static inline std::ostream & operator<< (std::ostream& os, const DsdvHeader & packet)
141 {
142   packet.Print (os);
143   return os;
144 }
145 }
146 }
147 
148 #endif /* DSDV_PACKET_H */
149