A Discrete-Event Network Simulator
Home
Tutorials ▼
English
Documentation ▼
Installation
Manual
Models
Contributing
Wiki
Development ▼
API Docs
Issue Tracker
Merge Requests
API
Loading...
Searching...
No Matches
flame-header.cc
Go to the documentation of this file.
1
/*
2
* Copyright (c) 2009 IITP RAS
3
*
4
* SPDX-License-Identifier: GPL-2.0-only
5
*
6
* Author: Kirill Andreev <andreev@iitp.ru>
7
*/
8
#include "
flame-header.h
"
9
10
#include "ns3/address-utils.h"
11
#include "ns3/assert.h"
12
#include "ns3/packet.h"
13
14
namespace
ns3
15
{
16
namespace
flame
17
{
18
19
NS_OBJECT_ENSURE_REGISTERED
(
FlameHeader
);
20
21
FlameHeader::FlameHeader
()
22
: m_cost(0),
23
m_seqno(0),
24
m_origDst(
Mac48Address
()),
25
m_origSrc(
Mac48Address
())
26
{
27
}
28
29
FlameHeader::~FlameHeader
()
30
{
31
}
32
33
TypeId
34
FlameHeader::GetTypeId
()
35
{
36
static
TypeId
tid =
TypeId
(
"ns3::flame::FlameHeader"
)
37
.
SetParent
<
Header
>()
38
.SetGroupName(
"Mesh"
)
39
.AddConstructor<
FlameHeader
>();
40
return
tid;
41
}
42
43
TypeId
44
FlameHeader::GetInstanceTypeId
()
const
45
{
46
return
GetTypeId
();
47
}
48
49
void
50
FlameHeader::Print
(std::ostream& os)
const
51
{
52
os <<
"Cost= "
<< (uint16_t)
m_cost
<<
", Sequence number= "
<<
m_seqno
53
<<
", Orig Destination= "
<<
m_origDst
<<
", Orig Source= "
<<
m_origSrc
;
54
}
55
56
uint32_t
57
FlameHeader::GetSerializedSize
()
const
58
{
59
return
1
// Reserved
60
+ 1
// Cost
61
+ 2
// Seqno
62
+ 6
// Orig Dst
63
+ 6
// Orig Src
64
+ 2
// Flame Port
65
;
66
}
67
68
void
69
FlameHeader::Serialize
(
Buffer::Iterator
start)
const
70
{
71
Buffer::Iterator
i = start;
72
i.
WriteU8
(0);
// Reserved
73
i.
WriteU8
(
m_cost
);
// Cost
74
i.
WriteHtonU16
(
m_seqno
);
// Seqno
75
WriteTo
(i,
m_origDst
);
76
WriteTo
(i,
m_origSrc
);
77
i.
WriteHtonU16
(
m_protocol
);
78
}
79
80
uint32_t
81
FlameHeader::Deserialize
(
Buffer::Iterator
start)
82
{
83
Buffer::Iterator
i = start;
84
i.
Next
(1);
85
m_cost
= i.
ReadU8
();
86
m_seqno
= i.
ReadNtohU16
();
87
ReadFrom
(i,
m_origDst
);
88
ReadFrom
(i,
m_origSrc
);
89
m_protocol
= i.
ReadNtohU16
();
90
return
i.
GetDistanceFrom
(start);
91
}
92
93
void
94
FlameHeader::AddCost
(uint8_t cost)
95
{
96
m_cost
= (((uint16_t)cost + (uint16_t)
m_cost
) > 255) ? 255 : cost +
m_cost
;
97
}
98
99
uint8_t
100
FlameHeader::GetCost
()
const
101
{
102
return
m_cost
;
103
}
104
105
void
106
FlameHeader::SetSeqno
(uint16_t seqno)
107
{
108
m_seqno
= seqno;
109
}
110
111
uint16_t
112
FlameHeader::GetSeqno
()
const
113
{
114
return
m_seqno
;
115
}
116
117
void
118
FlameHeader::SetOrigDst
(
Mac48Address
dst)
119
{
120
m_origDst
= dst;
121
}
122
123
Mac48Address
124
FlameHeader::GetOrigDst
()
const
125
{
126
return
m_origDst
;
127
}
128
129
void
130
FlameHeader::SetOrigSrc
(
Mac48Address
src)
131
{
132
m_origSrc
= src;
133
}
134
135
Mac48Address
136
FlameHeader::GetOrigSrc
()
const
137
{
138
return
m_origSrc
;
139
}
140
141
void
142
FlameHeader::SetProtocol
(uint16_t protocol)
143
{
144
m_protocol
= protocol;
145
}
146
147
uint16_t
148
FlameHeader::GetProtocol
()
const
149
{
150
return
m_protocol
;
151
}
152
153
bool
154
operator==
(
const
FlameHeader
& a,
const
FlameHeader
& b)
155
{
156
return
((a.
m_cost
== b.
m_cost
) && (a.
m_seqno
== b.
m_seqno
) && (a.
m_origDst
== b.
m_origDst
) &&
157
(a.
m_origSrc
== b.
m_origSrc
) && (a.
m_protocol
== b.
m_protocol
));
158
}
159
160
}
// namespace flame
161
}
// namespace ns3
ns3::Buffer::Iterator
iterator in a Buffer instance
Definition
buffer.h:89
ns3::Buffer::Iterator::ReadU8
uint8_t ReadU8()
Definition
buffer.h:1016
ns3::Buffer::Iterator::WriteU8
void WriteU8(uint8_t data)
Definition
buffer.h:870
ns3::Buffer::Iterator::WriteHtonU16
void WriteHtonU16(uint16_t data)
Definition
buffer.h:904
ns3::Buffer::Iterator::ReadNtohU16
uint16_t ReadNtohU16()
Definition
buffer.h:943
ns3::Buffer::Iterator::GetDistanceFrom
uint32_t GetDistanceFrom(const Iterator &o) const
Definition
buffer.cc:769
ns3::Buffer::Iterator::Next
void Next()
go forward by one byte
Definition
buffer.h:842
ns3::Header
Protocol header serialization and deserialization.
Definition
header.h:33
ns3::Mac48Address
an EUI-48 address
Definition
mac48-address.h:35
ns3::TypeId
a unique identifier for an interface.
Definition
type-id.h:48
ns3::TypeId::SetParent
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition
type-id.cc:1001
ns3::flame::FlameHeader
Flame header.
Definition
flame-header.h:29
ns3::flame::FlameHeader::m_cost
uint8_t m_cost
cost
Definition
flame-header.h:99
ns3::flame::FlameHeader::GetSerializedSize
uint32_t GetSerializedSize() const override
Definition
flame-header.cc:57
ns3::flame::FlameHeader::Deserialize
uint32_t Deserialize(Buffer::Iterator start) override
Definition
flame-header.cc:81
ns3::flame::FlameHeader::m_origDst
Mac48Address m_origDst
origin destination
Definition
flame-header.h:101
ns3::flame::FlameHeader::GetTypeId
static TypeId GetTypeId()
Get the type ID.
Definition
flame-header.cc:34
ns3::flame::FlameHeader::m_protocol
uint16_t m_protocol
protocol
Definition
flame-header.h:103
ns3::flame::FlameHeader::GetInstanceTypeId
TypeId GetInstanceTypeId() const override
Get the most derived TypeId for this Object.
Definition
flame-header.cc:44
ns3::flame::FlameHeader::GetCost
uint8_t GetCost() const
Get cost value.
Definition
flame-header.cc:100
ns3::flame::FlameHeader::m_seqno
uint16_t m_seqno
sequence number
Definition
flame-header.h:100
ns3::flame::FlameHeader::FlameHeader
FlameHeader()
Definition
flame-header.cc:21
ns3::flame::FlameHeader::GetOrigDst
Mac48Address GetOrigDst() const
Get origin destination address.
Definition
flame-header.cc:124
ns3::flame::FlameHeader::GetOrigSrc
Mac48Address GetOrigSrc() const
Get origin source address.
Definition
flame-header.cc:136
ns3::flame::FlameHeader::SetOrigSrc
void SetOrigSrc(Mac48Address OrigSrc)
Set origin source function.
Definition
flame-header.cc:130
ns3::flame::FlameHeader::AddCost
void AddCost(uint8_t cost)
Add cost value.
Definition
flame-header.cc:94
ns3::flame::FlameHeader::Print
void Print(std::ostream &os) const override
Definition
flame-header.cc:50
ns3::flame::FlameHeader::Serialize
void Serialize(Buffer::Iterator start) const override
Definition
flame-header.cc:69
ns3::flame::FlameHeader::GetSeqno
uint16_t GetSeqno() const
Get sequence number value.
Definition
flame-header.cc:112
ns3::flame::FlameHeader::SetOrigDst
void SetOrigDst(Mac48Address dst)
Set origin destination address.
Definition
flame-header.cc:118
ns3::flame::FlameHeader::SetProtocol
void SetProtocol(uint16_t protocol)
Set protocol value.
Definition
flame-header.cc:142
ns3::flame::FlameHeader::~FlameHeader
~FlameHeader() override
Definition
flame-header.cc:29
ns3::flame::FlameHeader::m_origSrc
Mac48Address m_origSrc
origin source
Definition
flame-header.h:102
ns3::flame::FlameHeader::GetProtocol
uint16_t GetProtocol() const
Get protocol value.
Definition
flame-header.cc:148
ns3::flame::FlameHeader::SetSeqno
void SetSeqno(uint16_t seqno)
Set sequence number value.
Definition
flame-header.cc:106
uint32_t
flame-header.h
NS_OBJECT_ENSURE_REGISTERED
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition
object-base.h:35
ns3::flame::operator==
bool operator==(const FlameHeader &a, const FlameHeader &b)
Definition
flame-header.cc:154
ns3
Every class exported by the ns3 library is enclosed in the ns3 namespace.
ns3::WriteTo
void WriteTo(Buffer::Iterator &i, Ipv4Address ad)
Write an Ipv4Address to a Buffer.
Definition
address-utils.cc:21
ns3::ReadFrom
void ReadFrom(Buffer::Iterator &i, Ipv4Address &ad)
Read an Ipv4Address from a Buffer.
Definition
address-utils.cc:74
src
mesh
model
flame
flame-header.cc
Generated on Fri Nov 1 2024 09:20:44 for ns-3 by
1.11.0