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
ie-dot11s-peer-management.cc
Go to the documentation of this file.
1
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2
/*
3
* Copyright (c) 2008,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
* Authors: Kirill Andreev <andreev@iitp.ru>
19
* Aleksey Kovalenko <kovalenko@iitp.ru>
20
*/
21
22
#include "
ie-dot11s-peer-management.h
"
23
#include "ns3/assert.h"
24
#include "ns3/packet.h"
25
26
namespace
ns3 {
27
namespace
dot11s {
28
29
IePeerManagement::IePeerManagement
() :
30
m_length (3), m_subtype (PEER_OPEN), m_localLinkId (0), m_peerLinkId (0), m_reasonCode (
REASON11S_RESERVED
)
31
{
32
}
33
WifiInformationElementId
34
IePeerManagement::ElementId
()
const
35
{
36
return
IE11S_PEERING_MANAGEMENT
;
37
}
38
void
39
IePeerManagement::SetPeerOpen
(uint16_t localLinkId)
40
{
41
m_length
= 3;
42
m_subtype
=
PEER_OPEN
;
43
m_localLinkId
= localLinkId;
44
}
45
void
46
IePeerManagement::SetPeerClose
(uint16_t localLinkId, uint16_t peerLinkId,
PmpReasonCode
reasonCode)
47
{
48
m_length
= 7;
49
m_subtype
=
PEER_CLOSE
;
50
m_localLinkId
= localLinkId;
51
m_peerLinkId
= peerLinkId;
52
m_reasonCode
= reasonCode;
53
}
54
55
void
56
IePeerManagement::SetPeerConfirm
(uint16_t localLinkId, uint16_t peerLinkId)
57
{
58
m_length
= 5;
59
m_subtype
=
PEER_CONFIRM
;
60
m_localLinkId
= localLinkId;
61
m_peerLinkId
= peerLinkId;
62
}
63
64
PmpReasonCode
65
IePeerManagement::GetReasonCode
()
const
66
{
67
return
m_reasonCode
;
68
}
69
70
uint16_t
71
IePeerManagement::GetLocalLinkId
()
const
72
{
73
return
m_localLinkId
;
74
}
75
76
uint16_t
77
IePeerManagement::GetPeerLinkId
()
const
78
{
79
return
m_peerLinkId
;
80
}
81
82
uint8_t
83
IePeerManagement::GetInformationFieldSize
(
void
)
const
84
{
85
return
m_length
;
86
}
87
uint8_t
88
IePeerManagement::GetSubtype
()
const
89
{
90
return
m_subtype
;
91
}
92
bool
93
IePeerManagement::SubtypeIsOpen
()
const
94
{
95
return
(
m_subtype
==
PEER_OPEN
);
96
}
97
bool
98
IePeerManagement::SubtypeIsClose
()
const
99
{
100
return
(
m_subtype
==
PEER_CLOSE
);
101
}
102
bool
103
IePeerManagement::SubtypeIsConfirm
()
const
104
{
105
return
(
m_subtype
==
PEER_CONFIRM
);
106
}
107
108
void
109
IePeerManagement::SerializeInformationField
(
Buffer::Iterator
i)
const
110
{
111
i.
WriteU8
(
m_subtype
);
112
i.
WriteHtolsbU16
(
m_localLinkId
);
113
if
(
m_length
> 3)
114
{
115
i.
WriteHtolsbU16
(
m_peerLinkId
);
116
}
117
if
(
m_length
> 5)
118
{
119
i.
WriteHtolsbU16
(
m_reasonCode
);
120
}
121
}
122
uint8_t
123
IePeerManagement::DeserializeInformationField
(
Buffer::Iterator
start
, uint8_t length)
124
{
125
Buffer::Iterator
i =
start
;
126
m_subtype
= i.
ReadU8
();
127
m_length
= length;
128
if
(
m_subtype
==
PEER_OPEN
)
129
{
130
NS_ASSERT
(length == 3);
131
}
132
if
(
m_subtype
==
PEER_CONFIRM
)
133
{
134
NS_ASSERT
(length == 5);
135
}
136
if
(
m_subtype
==
PEER_CLOSE
)
137
{
138
NS_ASSERT
(length == 7);
139
}
140
m_localLinkId
= i.
ReadLsbtohU16
();
141
if
(
m_length
> 3)
142
{
143
m_peerLinkId
= i.
ReadLsbtohU16
();
144
}
145
if
(
m_length
> 5)
146
{
147
m_reasonCode
= (
PmpReasonCode
) i.
ReadLsbtohU16
();
148
}
149
return
i.
GetDistanceFrom
(start);
150
}
151
void
152
IePeerManagement::Print
(std::ostream& os)
const
153
{
154
os << std::endl <<
"<information_element id="
<<
ElementId
() <<
">"
<< std::endl;
155
os <<
" Subtype: = "
<< (uint16_t)
m_subtype
<< std::endl;
156
os <<
" Length: = "
<< (uint16_t)
m_length
<< std::endl;
157
os <<
" LocalLinkId: = "
<<
m_localLinkId
<< std::endl;
158
os <<
" PeerLinkId: = "
<<
m_peerLinkId
<< std::endl;
159
os <<
" ReasonCode: = "
<<
m_reasonCode
<< std::endl;
160
os <<
"</information_element>"
<< std::endl;
161
}
162
bool
163
operator==
(
const
IePeerManagement
& a,
const
IePeerManagement
& b)
164
{
165
return
((a.
m_length
== b.
m_length
) && (a.
m_subtype
== b.
m_subtype
) && (a.
m_localLinkId
== b.
m_localLinkId
)
166
&& (a.
m_peerLinkId
== b.
m_peerLinkId
) && (a.
m_reasonCode
== b.
m_reasonCode
));
167
}
168
std::ostream &
169
operator <<
(std::ostream &os,
const
IePeerManagement
&a)
170
{
171
a.
Print
(os);
172
return
os;
173
}
174
}
// namespace dot11s
175
}
// namespace ns3
176
src
mesh
model
dot11s
ie-dot11s-peer-management.cc
Generated on Tue May 14 2013 11:08:28 for ns-3 by
1.8.1.2