A Discrete-Event Network Simulator
QKDNetSim v2.0 (NS-3 v3.41) @ (+)
API
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
flame-header.cc
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2009 IITP RAS
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License version 2 as
6  * published by the Free Software Foundation;
7  *
8  * This program is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  * GNU General Public License for more details.
12  *
13  * You should have received a copy of the GNU General Public License
14  * along with this program; if not, write to the Free Software
15  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16  *
17  * Author: Kirill Andreev <andreev@iitp.ru>
18  */
19 #include "flame-header.h"
20 
21 #include "ns3/address-utils.h"
22 #include "ns3/assert.h"
23 #include "ns3/packet.h"
24 
25 namespace ns3
26 {
27 namespace flame
28 {
29 
31 
33  : m_cost(0),
34  m_seqno(0),
35  m_origDst(Mac48Address()),
36  m_origSrc(Mac48Address())
37 {
38 }
39 
41 {
42 }
43 
44 TypeId
46 {
47  static TypeId tid = TypeId("ns3::flame::FlameHeader")
48  .SetParent<Header>()
49  .SetGroupName("Mesh")
50  .AddConstructor<FlameHeader>();
51  return tid;
52 }
53 
54 TypeId
56 {
57  return GetTypeId();
58 }
59 
60 void
61 FlameHeader::Print(std::ostream& os) const
62 {
63  os << "Cost= " << (uint16_t)m_cost << ", Sequence number= " << m_seqno
64  << ", Orig Destination= " << m_origDst << ", Orig Source= " << m_origSrc;
65 }
66 
67 uint32_t
69 {
70  return 1 // Reserved
71  + 1 // Cost
72  + 2 // Seqno
73  + 6 // Orig Dst
74  + 6 // Orig Src
75  + 2 // Flame Port
76  ;
77 }
78 
79 void
81 {
83  i.WriteU8(0); // Reserved
84  i.WriteU8(m_cost); // Cost
85  i.WriteHtonU16(m_seqno); // Seqno
86  WriteTo(i, m_origDst);
87  WriteTo(i, m_origSrc);
89 }
90 
91 uint32_t
93 {
95  i.Next(1);
96  m_cost = i.ReadU8();
97  m_seqno = i.ReadNtohU16();
98  ReadFrom(i, m_origDst);
99  ReadFrom(i, m_origSrc);
100  m_protocol = i.ReadNtohU16();
101  return i.GetDistanceFrom(start);
102 }
103 
104 void
105 FlameHeader::AddCost(uint8_t cost)
106 {
107  m_cost = (((uint16_t)cost + (uint16_t)m_cost) > 255) ? 255 : cost + m_cost;
108 }
109 
110 uint8_t
112 {
113  return m_cost;
114 }
115 
116 void
117 FlameHeader::SetSeqno(uint16_t seqno)
118 {
119  m_seqno = seqno;
120 }
121 
122 uint16_t
124 {
125  return m_seqno;
126 }
127 
128 void
130 {
131  m_origDst = dst;
132 }
133 
136 {
137  return m_origDst;
138 }
139 
140 void
142 {
143  m_origSrc = src;
144 }
145 
148 {
149  return m_origSrc;
150 }
151 
152 void
153 FlameHeader::SetProtocol(uint16_t protocol)
154 {
155  m_protocol = protocol;
156 }
157 
158 uint16_t
160 {
161  return m_protocol;
162 }
163 
164 bool
165 operator==(const FlameHeader& a, const FlameHeader& b)
166 {
167  return ((a.m_cost == b.m_cost) && (a.m_seqno == b.m_seqno) && (a.m_origDst == b.m_origDst) &&
168  (a.m_origSrc == b.m_origSrc) && (a.m_protocol == b.m_protocol));
169 }
170 
171 } // namespace flame
172 } // namespace ns3
iterator in a Buffer instance
Definition: buffer.h:100
uint8_t ReadU8()
Definition: buffer.h:1027
void WriteU8(uint8_t data)
Definition: buffer.h:881
void WriteHtonU16(uint16_t data)
Definition: buffer.h:915
uint16_t ReadNtohU16()
Definition: buffer.h:954
uint32_t GetDistanceFrom(const Iterator &o) const
Definition: buffer.cc:780
void Next()
go forward by one byte
Definition: buffer.h:853
Protocol header serialization and deserialization.
Definition: header.h:44
virtual uint32_t Deserialize(Buffer::Iterator start)=0
Deserialize the object from a buffer iterator.
an EUI-48 address
Definition: mac48-address.h:46
a unique identifier for an interface.
Definition: type-id.h:59
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:931
uint32_t GetSerializedSize() const override
Definition: flame-header.cc:68
Mac48Address m_origDst
origin destination
Definition: flame-header.h:112
static TypeId GetTypeId()
Get the type ID.
Definition: flame-header.cc:45
uint16_t m_protocol
protocol
Definition: flame-header.h:114
TypeId GetInstanceTypeId() const override
Get the most derived TypeId for this Object.
Definition: flame-header.cc:55
uint8_t GetCost() const
Get cost value.
uint16_t m_seqno
sequence number
Definition: flame-header.h:111
Mac48Address GetOrigDst() const
Get origin destination address.
Mac48Address GetOrigSrc() const
Get origin source address.
void SetOrigSrc(Mac48Address OrigSrc)
Set origin source function.
void AddCost(uint8_t cost)
Add cost value.
void Print(std::ostream &os) const override
Definition: flame-header.cc:61
void Serialize(Buffer::Iterator start) const override
Definition: flame-header.cc:80
uint16_t GetSeqno() const
Get sequence number value.
void SetOrigDst(Mac48Address dst)
Set origin destination address.
void SetProtocol(uint16_t protocol)
Set protocol value.
Mac48Address m_origSrc
origin source
Definition: flame-header.h:113
uint16_t GetProtocol() const
Get protocol value.
void SetSeqno(uint16_t seqno)
Set sequence number value.
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition: object-base.h:46
bool operator==(const FlameHeader &a, const FlameHeader &b)
Every class exported by the ns3 library is enclosed in the ns3 namespace.
void WriteTo(Buffer::Iterator &i, Ipv4Address ad)
Write an Ipv4Address to a Buffer.
void ReadFrom(Buffer::Iterator &i, Ipv4Address &ad)
Read an Ipv4Address from a Buffer.