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_5_6
:
143
item->
phyRate
= dataRate * 6 / 5;
144
break
;
145
case
WIFI_CODE_RATE_3_4
:
146
item->
phyRate
= dataRate * 4 / 3;
147
break
;
148
case
WIFI_CODE_RATE_2_3
:
149
item->
phyRate
= dataRate * 3 / 2;
150
break
;
151
case
WIFI_CODE_RATE_1_2
:
152
item->
phyRate
= dataRate * 2 / 1;
153
break
;
154
case
WIFI_CODE_RATE_UNDEFINED
:
155
default
:
156
item->
phyRate
= dataRate;
157
break
;
158
}
159
160
// Check for compatibility between modulation class and coding
161
// rate. If modulation class is DSSS then coding rate must be
162
// undefined, and vice versa. I could have done this with an
163
// assertion, but it seems better to always give the error (i.e.,
164
// not only in non-optimised builds) and the cycles that extra test
165
// here costs are only suffered at simulation setup.
166
if
((codingRate ==
WIFI_CODE_RATE_UNDEFINED
) != (modClass ==
WIFI_MOD_CLASS_DSSS
))
167
{
168
NS_FATAL_ERROR
(
"Error in creation of WifiMode named "
<< uniqueName << std::endl
169
<<
"Code rate must be WIFI_CODE_RATE_UNDEFINED iff Modulation Class is WIFI_MOD_CLASS_DSSS"
);
170
}
171
172
item->
constellationSize
= constellationSize;
173
item->
isMandatory
= isMandatory;
174
175
return
WifiMode
(uid);
176
}
177
178
WifiMode
179
WifiModeFactory::Search
(std::string name)
180
{
181
WifiModeItemList::const_iterator i;
182
uint32_t j = 0;
183
for
(i =
m_itemList
.begin (); i !=
m_itemList
.end (); i++)
184
{
185
if
(i->uniqueUid == name)
186
{
187
return
WifiMode
(j);
188
}
189
j++;
190
}
191
192
// If we get here then a matching WifiMode was not found above. This
193
// is a fatal problem, but we try to be helpful by displaying the
194
// list of WifiModes that are supported.
195
NS_LOG_UNCOND
(
"Could not find match for WifiMode named \""
196
<< name <<
"\". Valid options are:"
);
197
for
(i =
m_itemList
.begin (); i !=
m_itemList
.end (); i++)
198
{
199
NS_LOG_UNCOND
(
" "
<< i->uniqueUid);
200
}
201
// Empty fatal error to die. We've already unconditionally logged
202
// the helpful information.
203
NS_FATAL_ERROR
(
""
);
204
205
// This next line is unreachable because of the fatal error
206
// immediately above, and that is fortunate, because we have no idea
207
// what is in WifiMode (0), but we do know it is not what our caller
208
// has requested by name. It's here only because it's the safest
209
// thing that'll give valid code.
210
return
WifiMode
(0);
211
}
212
213
uint32_t
214
WifiModeFactory::AllocateUid
(std::string uniqueUid)
215
{
216
uint32_t j = 0;
217
for
(WifiModeItemList::const_iterator i =
m_itemList
.begin ();
218
i !=
m_itemList
.end (); i++)
219
{
220
if
(i->uniqueUid == uniqueUid)
221
{
222
return
j;
223
}
224
j++;
225
}
226
uint32_t uid =
m_itemList
.size ();
227
m_itemList
.push_back (
WifiModeItem
());
228
return
uid;
229
}
230
231
struct
WifiModeFactory::WifiModeItem
*
232
WifiModeFactory::Get
(uint32_t uid)
233
{
234
NS_ASSERT
(uid <
m_itemList
.size ());
235
return
&
m_itemList
[uid];
236
}
237
238
WifiModeFactory
*
239
WifiModeFactory::GetFactory
(
void
)
240
{
241
static
bool
isFirstTime =
true
;
242
static
WifiModeFactory
factory;
243
if
(isFirstTime)
244
{
245
uint32_t uid = factory.
AllocateUid
(
"Invalid-WifiMode"
);
246
WifiModeItem
*item = factory.
Get
(uid);
247
item->
uniqueUid
=
"Invalid-WifiMode"
;
248
item->
bandwidth
= 0;
249
item->
dataRate
= 0;
250
item->
phyRate
= 0;
251
item->
modClass
=
WIFI_MOD_CLASS_UNKNOWN
;
252
item->
constellationSize
= 0;
253
item->
codingRate
=
WIFI_CODE_RATE_UNDEFINED
;
254
item->
isMandatory
=
false
;
255
isFirstTime =
false
;
256
}
257
return
&factory;
258
}
259
260
}
// namespace ns3
ns3::operator>>
std::istream & operator>>(std::istream &is, Angles &a)
Definition:
angles.cc:49
ns3::WifiModeFactory::WifiModeFactory
WifiModeFactory()
Definition:
wifi-mode.cc:113
ns3::WifiMode::WifiMode
WifiMode()
Definition:
wifi-mode.cc:98
ns3::WifiModeFactory::WifiModeItem::dataRate
uint32_t dataRate
Definition:
wifi-mode.h:232
ns3::WifiCodeRate
WifiCodeRate
Definition:
wifi-mode.h:67
wifi-mode.h
ns3::WifiMode::GetModulationClass
enum WifiModulationClass GetModulationClass() const
Definition:
wifi-mode.cc:93
NS_ASSERT
#define NS_ASSERT(condition)
Definition:
assert.h:64
ns3::WIFI_CODE_RATE_3_4
Definition:
wifi-mode.h:72
ns3::WifiModeFactory::AllocateUid
uint32_t AllocateUid(std::string uniqueName)
Definition:
wifi-mode.cc:214
ns3::WifiMode
represent a single transmission modeA WifiMode is implemented by a single integer which is used to lo...
Definition:
wifi-mode.h:91
ns3::WifiMode::IsMandatory
bool IsMandatory(void) const
Definition:
wifi-mode.cc:82
NS_FATAL_ERROR
#define NS_FATAL_ERROR(msg)
fatal error handling
Definition:
fatal-error.h:72
ns3::WIFI_MOD_CLASS_UNKNOWN
Definition:
wifi-mode.h:40
ns3::WifiModeFactory::Get
WifiModeItem * Get(uint32_t uid)
Definition:
wifi-mode.cc:232
ns3::WIFI_CODE_RATE_1_2
Definition:
wifi-mode.h:76
ns3::WifiMode::m_uid
uint32_t m_uid
Definition:
wifi-mode.h:157
ns3::WifiMode::GetCodeRate
enum WifiCodeRate GetCodeRate(void) const
Definition:
wifi-mode.cc:63
ns3::WifiModeFactory::WifiModeItem::codingRate
enum WifiCodeRate codingRate
Definition:
wifi-mode.h:236
ns3::WifiMode::GetUniqueName
std::string GetUniqueName(void) const
Definition:
wifi-mode.cc:75
ns3::WifiModeFactory::m_itemList
WifiModeItemList m_itemList
Definition:
wifi-mode.h:245
ns3::WifiModeFactory::CreateWifiMode
static WifiMode CreateWifiMode(std::string uniqueName, enum WifiModulationClass modClass, bool isMandatory, uint32_t bandwidth, uint32_t dataRate, enum WifiCodeRate codingRate, uint8_t constellationSize)
Definition:
wifi-mode.cc:119
ns3::WifiMode::GetBandwidth
uint32_t GetBandwidth(void) const
Definition:
wifi-mode.cc:45
ns3::WIFI_CODE_RATE_2_3
Definition:
wifi-mode.h:74
ns3::operator<<
std::ostream & operator<<(std::ostream &os, const Angles &a)
Definition:
angles.cc:43
ns3::WifiModeFactory::WifiModeItem::phyRate
uint32_t phyRate
Definition:
wifi-mode.h:233
ns3::WifiMode::GetConstellationSize
uint8_t GetConstellationSize(void) const
Definition:
wifi-mode.cc:69
ns3::WIFI_CODE_RATE_5_6
Definition:
wifi-mode.h:78
ns3::WifiMode::GetPhyRate
uint64_t GetPhyRate(void) const
Definition:
wifi-mode.cc:51
NS_LOG_UNCOND
#define NS_LOG_UNCOND(msg)
Definition:
log.h:343
ns3::WifiModeFactory::WifiMode
friend class WifiMode
Definition:
wifi-mode.h:218
ns3::WIFI_CODE_RATE_UNDEFINED
Definition:
wifi-mode.h:70
ns3::WifiModeFactory
create WifiMode class instances and keep track of them.
Definition:
wifi-mode.h:189
ns3::WifiModulationClass
WifiModulationClass
Definition:
wifi-mode.h:36
ns3::operator==
bool operator==(const EventId &a, const EventId &b)
Definition:
event-id.cc:89
ns3::WifiModeFactory::WifiModeItem::constellationSize
uint8_t constellationSize
Definition:
wifi-mode.h:235
ns3::WifiModeFactory::GetFactory
static WifiModeFactory * GetFactory()
Definition:
wifi-mode.cc:239
ns3::WifiModeFactory::WifiModeItem::modClass
enum WifiModulationClass modClass
Definition:
wifi-mode.h:234
ns3::ATTRIBUTE_HELPER_CPP
ATTRIBUTE_HELPER_CPP(ObjectFactory)
ns3::WifiMode::GetUid
uint32_t GetUid(void) const
Definition:
wifi-mode.cc:88
ns3::WifiModeFactory::WifiModeItem::bandwidth
uint32_t bandwidth
Definition:
wifi-mode.h:231
ns3::WifiModeFactory::WifiModeItem::isMandatory
bool isMandatory
Definition:
wifi-mode.h:237
ns3::WifiModeFactory::Search
WifiMode Search(std::string name)
Definition:
wifi-mode.cc:179
ns3::WifiMode::GetDataRate
uint64_t GetDataRate(void) const
Definition:
wifi-mode.cc:57
ns3::WifiModeFactory::WifiModeItem
Definition:
wifi-mode.h:228
ns3::WIFI_MOD_CLASS_DSSS
Definition:
wifi-mode.h:46
ns3::WifiModeFactory::WifiModeItem::uniqueUid
std::string uniqueUid
Definition:
wifi-mode.h:230
src
wifi
model
wifi-mode.cc
Generated on Sun Apr 20 2014 11:15:05 for ns-3 by
1.8.6