A Discrete-Event Network Simulator
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
dsdv-packet.cc
Go to the documentation of this file.
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 #include "dsdv-packet.h"
32 #include "ns3/address-utils.h"
33 #include "ns3/packet.h"
34 
35 namespace ns3 {
36 namespace dsdv {
37 NS_OBJECT_ENSURE_REGISTERED (DsdvHeader)
38  ;
39 DsdvHeader::DsdvHeader (Ipv4Address dst, uint32_t hopCount, uint32_t dstSeqNo)
40  : m_dst (dst),
41  m_hopCount (hopCount),
42  m_dstSeqNo (dstSeqNo)
43 {
44 }
45 
47 {
48 }
49 
50 TypeId
52 {
53  static TypeId tid = TypeId ("ns3::dsdv::DsdvHeader")
54  .SetParent<Header> ()
55  .AddConstructor<DsdvHeader> ();
56  return tid;
57 }
58 
59 TypeId
61 {
62  return GetTypeId ();
63 }
64 
65 uint32_t
67 {
68  return 12;
69 }
70 
71 void
73 {
74  WriteTo (i, m_dst);
77 
78 }
79 
80 uint32_t
82 {
84 
85  ReadFrom (i, m_dst);
86  m_hopCount = i.ReadNtohU32 ();
87  m_dstSeqNo = i.ReadNtohU32 ();
88 
89  uint32_t dist = i.GetDistanceFrom (start);
90  NS_ASSERT (dist == GetSerializedSize ());
91  return dist;
92 }
93 
94 void
95 DsdvHeader::Print (std::ostream &os) const
96 {
97  os << "DestinationIpv4: " << m_dst
98  << " Hopcount: " << m_hopCount
99  << " SequenceNumber: " << m_dstSeqNo;
100 }
101 }
102 }
Protocol header serialization and deserialization.
Definition: header.h:42
virtual void Print(std::ostream &os) const
Definition: dsdv-packet.cc:95
virtual uint32_t GetSerializedSize() const
Definition: dsdv-packet.cc:66
void ReadFrom(Buffer::Iterator &i, Ipv4Address &ad)
Read an Ipv4Address from a Buffer.
#define NS_ASSERT(condition)
Definition: assert.h:64
NS_OBJECT_ENSURE_REGISTERED(NullMessageSimulatorImpl)
void WriteTo(Buffer::Iterator &i, Ipv4Address ad)
Write an Ipv4Address to a Buffer.
uint32_t m_hopCount
Number of Hops.
Definition: dsdv-packet.h:102
uint32_t m_dstSeqNo
Destination Sequence Number.
Definition: dsdv-packet.h:103
uint32_t ReadNtohU32(void)
Definition: buffer.h:791
uint32_t GetDistanceFrom(Iterator const &o) const
Definition: buffer.cc:807
iterator in a Buffer instance
Definition: buffer.h:98
static TypeId GetTypeId(void)
Definition: dsdv-packet.cc:51
virtual void Serialize(Buffer::Iterator start) const
Definition: dsdv-packet.cc:72
void WriteHtonU32(uint32_t data)
Definition: buffer.h:745
virtual TypeId GetInstanceTypeId(void) const
Definition: dsdv-packet.cc:60
Ipv4 addresses are stored in host order in this class.
Definition: ipv4-address.h:38
Ipv4Address m_dst
Destination IP Address.
Definition: dsdv-packet.h:101
a unique identifier for an interface.
Definition: type-id.h:49
TypeId SetParent(TypeId tid)
Definition: type-id.cc:611
DsdvHeader(Ipv4Address dst=Ipv4Address(), uint32_t hopcount=0, uint32_t dstSeqNo=0)
Definition: dsdv-packet.cc:39
virtual uint32_t Deserialize(Buffer::Iterator start)
Definition: dsdv-packet.cc:81