A Discrete-Event Network Simulator
Home
Tutorials ▼
English
Portuguese
Docs ▼
Wiki
Manual
Models
Develop ▼
API
Bugs
API
Main Page
Related Pages
Modules
Namespaces
Classes
Files
File List
File Members
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Properties
Friends
Macros
Groups
Pages
flame-header.cc
Go to the documentation of this file.
1
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2
/*
3
* Copyright (c) 2009 IITP RAS
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: Kirill Andreev <andreev@iitp.ru>
19
*/
20
#include "ns3/assert.h"
21
#include "ns3/address-utils.h"
22
#include "ns3/packet.h"
23
24
#include "
flame-header.h
"
25
26
namespace
ns3 {
27
namespace
flame {
28
29
NS_OBJECT_ENSURE_REGISTERED
(
FlameHeader
);
30
31
FlameHeader::FlameHeader
() :
32
m_cost (0), m_seqno (0), m_origDst (
Mac48Address
()), m_origSrc (
Mac48Address
())
33
{
34
}
35
FlameHeader::~FlameHeader
()
36
{
37
}
38
TypeId
39
FlameHeader::GetTypeId
(
void
)
40
{
41
static
TypeId
tid =
TypeId
(
"ns3::flame::FlameHeader"
)
42
.
SetParent
<
Header
> ()
43
.AddConstructor<FlameHeader> ();
44
return
tid;
45
}
46
TypeId
47
FlameHeader::GetInstanceTypeId
(
void
)
const
48
{
49
return
GetTypeId
();
50
}
51
void
52
FlameHeader::Print
(std::ostream &os)
const
53
{
54
os <<
"Cost = "
<< (uint16_t)
m_cost
<< std::endl <<
"Sequence number = "
<<
m_seqno
55
<< std::endl <<
"Orig Destination = "
<<
m_origDst
<< std::endl <<
"Orig Source = "
<<
m_origSrc
<< std::endl;
56
}
57
uint32_t
58
FlameHeader::GetSerializedSize
(
void
)
const
59
{
60
return
1
// Reserved
61
+ 1
// Cost
62
+ 2
// Seqno
63
+ 6
// Orig Dst
64
+ 6
// Orig Src
65
+ 2
// Flame Port
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
uint32_t
80
FlameHeader::Deserialize
(
Buffer::Iterator
start
)
81
{
82
Buffer::Iterator
i =
start
;
83
i.
Next
(1);
84
m_cost
= i.
ReadU8
();
85
m_seqno
= i.
ReadNtohU16
();
86
ReadFrom
(i,
m_origDst
);
87
ReadFrom
(i,
m_origSrc
);
88
m_protocol
= i.
ReadNtohU16
();
89
return
i.
GetDistanceFrom
(start);
90
}
91
void
92
FlameHeader::AddCost
(uint8_t cost)
93
{
94
m_cost
= (((uint16_t) cost + (uint16_t)
m_cost
) > 255) ? 255 : cost +
m_cost
;
95
}
96
uint8_t
97
FlameHeader::GetCost
()
const
98
{
99
return
m_cost
;
100
}
101
void
102
FlameHeader::SetSeqno
(uint16_t seqno)
103
{
104
m_seqno
= seqno;
105
}
106
uint16_t
107
FlameHeader::GetSeqno
()
const
108
{
109
return
m_seqno
;
110
}
111
void
112
FlameHeader::SetOrigDst
(
Mac48Address
dst)
113
{
114
m_origDst
= dst;
115
}
116
Mac48Address
117
FlameHeader::GetOrigDst
()
const
118
{
119
return
m_origDst
;
120
}
121
void
122
FlameHeader::SetOrigSrc
(
Mac48Address
src)
123
{
124
m_origSrc
= src;
125
}
126
Mac48Address
127
FlameHeader::GetOrigSrc
()
const
128
{
129
return
m_origSrc
;
130
}
131
void
132
FlameHeader::SetProtocol
(uint16_t protocol)
133
{
134
m_protocol
= protocol;
135
}
136
uint16_t
137
FlameHeader::GetProtocol
()
const
138
{
139
return
m_protocol
;
140
}
141
bool
142
operator==
(
const
FlameHeader
& a,
const
FlameHeader
& b)
143
{
144
return
((a.
m_cost
== b.
m_cost
) && (a.
m_seqno
== b.
m_seqno
) && (a.
m_origDst
== b.
m_origDst
) && (a.
m_origSrc
145
== b.
m_origSrc
) && (a.
m_protocol
== b.
m_protocol
));
146
}
147
148
}
// namespace flame
149
}
// namespace ns3
src
mesh
model
flame
flame-header.cc
Generated on Tue Oct 9 2012 16:45:42 for ns-3 by
1.8.1.2