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
wifi-mode.cc
Go to the documentation of this file.
1
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2
/*
3
* Copyright (c) 2005,2006,2007 INRIA
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: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
19
*/
20
#include "
wifi-mode.h
"
21
#include "ns3/simulator.h"
22
#include "ns3/assert.h"
23
#include "ns3/log.h"
24
25
namespace
ns3 {
26
27
bool
operator ==
(
const
WifiMode
&a,
const
WifiMode
&b)
28
{
29
return
a.
GetUid
() == b.
GetUid
();
30
}
31
std::ostream &
operator <<
(std::ostream & os,
const
WifiMode
&mode)
32
{
33
os << mode.
GetUniqueName
();
34
return
os;
35
}
36
std::istream &
operator >>
(std::istream &is,
WifiMode
&mode)
37
{
38
std::string str;
39
is >> str;
40
mode =
WifiModeFactory::GetFactory
()->
Search
(str);
41
return
is;
42
}
43
44
uint32_t
45
WifiMode::GetBandwidth
(
void
)
const
46
{
47
struct
WifiModeFactory::WifiModeItem
*item =
WifiModeFactory::GetFactory
()->
Get
(
m_uid
);
48
return
item->
bandwidth
;
49
}
50
uint64_t
51
WifiMode::GetPhyRate
(
void
)
const
52
{
53
struct
WifiModeFactory::WifiModeItem
*item =
WifiModeFactory::GetFactory
()->
Get
(
m_uid
);
54
return
item->
phyRate
;
55
}
56
uint64_t
57
WifiMode::GetDataRate
(
void
)
const
58
{
59
struct
WifiModeFactory::WifiModeItem
*item =
WifiModeFactory::GetFactory
()->
Get
(
m_uid
);
60
return
item->
dataRate
;
61
}
62
enum
WifiCodeRate
63
WifiMode::GetCodeRate
(
void
)
const
64
{
65
struct
WifiModeFactory::WifiModeItem
*item =
WifiModeFactory::GetFactory
()->
Get
(
m_uid
);
66
return
item->
codingRate
;
67
}
68
uint8_t
69
WifiMode::GetConstellationSize
(
void
)
const
70
{
71
struct
WifiModeFactory::WifiModeItem
*item =
WifiModeFactory::GetFactory
()->
Get
(
m_uid
);
72
return
item->
constellationSize
;
73
}
74
std::string
75
WifiMode::GetUniqueName
(
void
)
const
76
{
77
// needed for ostream printing of the invalid mode
78
struct
WifiModeFactory::WifiModeItem
*item =
WifiModeFactory::GetFactory
()->
Get
(
m_uid
);
79
return
item->
uniqueUid
;
80
}
81
bool
82
WifiMode::IsMandatory
(
void
)
const
83
{
84
struct
WifiModeFactory::WifiModeItem
*item =
WifiModeFactory::GetFactory
()->
Get
(
m_uid
);
85
return
item->
isMandatory
;
86
}
87
uint32_t
88
WifiMode::GetUid
(
void
)
const
89
{
90
return
m_uid
;
91
}
92
enum
WifiModulationClass
93
WifiMode::GetModulationClass
()
const
94
{
95
struct
WifiModeFactory::WifiModeItem
*item =
WifiModeFactory::GetFactory
()->
Get
(
m_uid
);
96
return
item->
modClass
;
97
}
98
WifiMode::WifiMode
()
99
: m_uid (0)
100
{
101
}
102
WifiMode::WifiMode
(uint32_t uid)
103
: m_uid (uid)
104
{
105
}
106
WifiMode::WifiMode
(std::string name)
107
{
108
*
this
=
WifiModeFactory::GetFactory
()->
Search
(name);
109
}
110
111
ATTRIBUTE_HELPER_CPP
(
WifiMode
);
112
113
WifiModeFactory::WifiModeFactory
()
114
{
115
}
116
117
118
WifiMode
119
WifiModeFactory::CreateWifiMode
(std::string uniqueName,
120
enum
WifiModulationClass
modClass,
121
bool
isMandatory,
122
uint32_t bandwidth,
123
uint32_t dataRate,
124
enum
WifiCodeRate
codingRate,
125
uint8_t constellationSize)
126
{
127
WifiModeFactory
*factory =
GetFactory
();
128
uint32_t uid = factory->
AllocateUid
(uniqueName);
129
WifiModeItem
*item = factory->
Get
(uid);
130
item->
uniqueUid
= uniqueName;
131
item->
modClass
= modClass;
132
// The modulation class for this WifiMode must be valid.
133
NS_ASSERT
(modClass !=
WIFI_MOD_CLASS_UNKNOWN
);
134
135
item->
bandwidth
= bandwidth;
136
item->
dataRate
= dataRate;
137
138
item->
codingRate
= codingRate;
139
140
switch
(codingRate)
141
{
142
case
WIFI_CODE_RATE_3_4
:
143
item->
phyRate
= dataRate * 4 / 3;
144
break
;
145
case
WIFI_CODE_RATE_2_3
:
146
item->
phyRate
= dataRate * 3 / 2;
147
break
;
148
case
WIFI_CODE_RATE_1_2
:
149
item->
phyRate
= dataRate * 2 / 1;
150
break
;
151
case
WIFI_CODE_RATE_UNDEFINED
:
152
default
:
153
item->
phyRate
= dataRate;
154
break
;
155
}
156
157
// Check for compatibility between modulation class and coding
158
// rate. If modulation class is DSSS then coding rate must be
159
// undefined, and vice versa. I could have done this with an
160
// assertion, but it seems better to always give the error (i.e.,
161
// not only in non-optimised builds) and the cycles that extra test
162
// here costs are only suffered at simulation setup.
163
if
((codingRate ==
WIFI_CODE_RATE_UNDEFINED
) != (modClass ==
WIFI_MOD_CLASS_DSSS
))
164
{
165
NS_FATAL_ERROR
(
"Error in creation of WifiMode named "
<< uniqueName << std::endl
166
<<
"Code rate must be WIFI_CODE_RATE_UNDEFINED iff Modulation Class is WIFI_MOD_CLASS_DSSS"
);
167
}
168
169
item->
constellationSize
= constellationSize;
170
item->
isMandatory
= isMandatory;
171
172
return
WifiMode
(uid);
173
}
174
175
WifiMode
176
WifiModeFactory::Search
(std::string name)
177
{
178
WifiModeItemList::const_iterator i;
179
uint32_t j = 0;
180
for
(i =
m_itemList
.begin (); i !=
m_itemList
.end (); i++)
181
{
182
if
(i->uniqueUid == name)
183
{
184
return
WifiMode
(j);
185
}
186
j++;
187
}
188
189
// If we get here then a matching WifiMode was not found above. This
190
// is a fatal problem, but we try to be helpful by displaying the
191
// list of WifiModes that are supported.
192
NS_LOG_UNCOND
(
"Could not find match for WifiMode named \""
193
<< name <<
"\". Valid options are:"
);
194
for
(i =
m_itemList
.begin (); i !=
m_itemList
.end (); i++)
195
{
196
NS_LOG_UNCOND
(
" "
<< i->uniqueUid);
197
}
198
// Empty fatal error to die. We've already unconditionally logged
199
// the helpful information.
200
NS_FATAL_ERROR
(
""
);
201
202
// This next line is unreachable because of the fatal error
203
// immediately above, and that is fortunate, because we have no idea
204
// what is in WifiMode (0), but we do know it is not what our caller
205
// has requested by name. It's here only because it's the safest
206
// thing that'll give valid code.
207
return
WifiMode
(0);
208
}
209
210
uint32_t
211
WifiModeFactory::AllocateUid
(std::string uniqueUid)
212
{
213
uint32_t j = 0;
214
for
(WifiModeItemList::const_iterator i =
m_itemList
.begin ();
215
i !=
m_itemList
.end (); i++)
216
{
217
if
(i->uniqueUid == uniqueUid)
218
{
219
return
j;
220
}
221
j++;
222
}
223
uint32_t uid =
m_itemList
.size ();
224
m_itemList
.push_back (
WifiModeItem
());
225
return
uid;
226
}
227
228
struct
WifiModeFactory::WifiModeItem
*
229
WifiModeFactory::Get
(uint32_t uid)
230
{
231
NS_ASSERT
(uid <
m_itemList
.size ());
232
return
&
m_itemList
[uid];
233
}
234
235
WifiModeFactory
*
236
WifiModeFactory::GetFactory
(
void
)
237
{
238
static
bool
isFirstTime =
true
;
239
static
WifiModeFactory
factory;
240
if
(isFirstTime)
241
{
242
uint32_t uid = factory.
AllocateUid
(
"Invalid-WifiMode"
);
243
WifiModeItem
*item = factory.
Get
(uid);
244
item->
uniqueUid
=
"Invalid-WifiMode"
;
245
item->
bandwidth
= 0;
246
item->
dataRate
= 0;
247
item->
phyRate
= 0;
248
item->
modClass
=
WIFI_MOD_CLASS_UNKNOWN
;
249
item->
constellationSize
= 0;
250
item->
codingRate
=
WIFI_CODE_RATE_UNDEFINED
;
251
item->
isMandatory
=
false
;
252
isFirstTime =
false
;
253
}
254
return
&factory;
255
}
256
257
}
// namespace ns3
src
wifi
model
wifi-mode.cc
Generated on Fri Dec 21 2012 19:00:49 for ns-3 by
1.8.1.2