A Discrete-Event Network Simulator
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
14namespace ns3
15{
16namespace flame
17{
18
20
22 : m_cost(0),
23 m_seqno(0),
24 m_origDst(Mac48Address()),
25 m_origSrc(Mac48Address())
26{
27}
28
32
35{
36 static TypeId tid = TypeId("ns3::flame::FlameHeader")
38 .SetGroupName("Mesh")
39 .AddConstructor<FlameHeader>();
40 return tid;
41}
42
45{
46 return GetTypeId();
47}
48
49void
50FlameHeader::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
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
68void
70{
71 Buffer::Iterator i = start;
72 i.WriteU8(0); // Reserved
73 i.WriteU8(m_cost); // Cost
74 i.WriteHtonU16(m_seqno); // Seqno
78}
79
82{
83 Buffer::Iterator i = start;
84 i.Next(1);
85 m_cost = i.ReadU8();
86 m_seqno = i.ReadNtohU16();
90 return i.GetDistanceFrom(start);
91}
92
93void
95{
96 m_cost = (((uint16_t)cost + (uint16_t)m_cost) > 255) ? 255 : cost + m_cost;
97}
98
99uint8_t
101{
102 return m_cost;
103}
104
105void
107{
108 m_seqno = seqno;
109}
110
111uint16_t
113{
114 return m_seqno;
115}
116
117void
122
125{
126 return m_origDst;
127}
128
129void
134
137{
138 return m_origSrc;
139}
140
141void
142FlameHeader::SetProtocol(uint16_t protocol)
143{
144 m_protocol = protocol;
145}
146
147uint16_t
149{
150 return m_protocol;
151}
152
153bool
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
iterator in a Buffer instance
Definition buffer.h:89
void WriteU8(uint8_t data)
Definition buffer.h:870
void WriteHtonU16(uint16_t data)
Definition buffer.h:904
uint16_t ReadNtohU16()
Definition buffer.h:943
uint32_t GetDistanceFrom(const Iterator &o) const
Definition buffer.cc:769
void Next()
go forward by one byte
Definition buffer.h:842
Protocol header serialization and deserialization.
Definition header.h:33
an EUI-48 address
a unique identifier for an interface.
Definition type-id.h:48
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition type-id.cc:1001
uint32_t GetSerializedSize() const override
uint32_t Deserialize(Buffer::Iterator start) override
Mac48Address m_origDst
origin destination
static TypeId GetTypeId()
Get the type ID.
uint16_t m_protocol
protocol
TypeId GetInstanceTypeId() const override
Get the most derived TypeId for this Object.
uint8_t GetCost() const
Get cost value.
uint16_t m_seqno
sequence number
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
void Serialize(Buffer::Iterator start) const override
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
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:35
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.