A Discrete-Event Network Simulator
QKDNetSim v2.0 (NS-3 v3.41) @ (+)
API
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
uan-tx-mode.cc
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2009 University of Washington
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License version 2 as
6  * published by the Free Software Foundation;
7  *
8  * This program is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  * GNU General Public License for more details.
12  *
13  * You should have received a copy of the GNU General Public License
14  * along with this program; if not, write to the Free Software
15  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16  *
17  * Author: Leonard Tracy <lentracy@gmail.com>
18  */
19 #include "uan-tx-mode.h"
20 
21 #include "ns3/log.h"
22 
23 #include <map>
24 #include <utility>
25 
26 namespace ns3
27 {
28 
29 NS_LOG_COMPONENT_DEFINE("UanTxMode");
30 
32 {
33 }
34 
36 {
37 }
38 
41 {
43 }
44 
45 uint32_t
47 {
49 }
50 
51 uint32_t
53 {
55 }
56 
57 uint32_t
59 {
61 }
62 
63 uint32_t
65 {
67 }
68 
69 uint32_t
71 {
73 }
74 
75 std::string
77 {
79 }
80 
81 uint32_t
83 {
84  return m_uid;
85 }
86 
87 std::ostream&
88 operator<<(std::ostream& os, const UanTxMode& mode)
89 {
90  os << mode.m_uid;
91  return os;
92 }
93 
94 std::istream&
95 operator>>(std::istream& is, UanTxMode& mode)
96 {
97  std::string name;
98  uint32_t duh;
99 
100  is >> duh;
101 
102  mode.m_uid = duh;
103  return is;
104 }
105 
107  : m_nextUid(0)
108 {
109 }
110 
112 {
113  m_modes.clear();
114 }
115 
116 bool
117 UanTxModeFactory::NameUsed(std::string name)
118 {
119  auto it = m_modes.begin();
120 
121  for (; it != m_modes.end(); it++)
122  {
123  if ((*it).second.m_name == name)
124  {
125  return true;
126  }
127  }
128  return false;
129 }
130 
131 UanTxMode
133  uint32_t dataRateBps,
134  uint32_t phyRateSps,
135  uint32_t cfHz,
136  uint32_t bwHz,
137  uint32_t constSize,
138  std::string name)
139 {
141 
142  UanTxModeItem* item;
143 
144  if (factory.NameUsed(name))
145  {
146  NS_LOG_WARN("Redefining UanTxMode with name \"" << name << "\"");
147  item = &factory.GetModeItem(name);
148  }
149  else
150  {
151  item = &factory.m_modes[factory.m_nextUid];
152  item->m_uid = factory.m_nextUid++;
153  }
154 
155  item->m_type = type;
156  item->m_dataRateBps = dataRateBps;
157  item->m_phyRateSps = phyRateSps;
158  item->m_cfHz = cfHz;
159  item->m_bwHz = bwHz;
160  item->m_constSize = constSize;
161  item->m_name = name;
162  return factory.MakeModeFromItem(*item);
163 }
164 
167 {
168  if (uid >= m_nextUid)
169  {
170  NS_FATAL_ERROR("Attempting to retrieve UanTxMode with uid, " << uid << ", >= m_nextUid");
171  }
172 
173  return m_modes[uid];
174 }
175 
178 {
179  auto it = m_modes.begin();
180  for (; it != m_modes.end(); it++)
181  {
182  if ((*it).second.m_name == name)
183  {
184  return (*it).second;
185  }
186  }
187  NS_FATAL_ERROR("Unknown mode, \"" << name << "\", requested from mode factory");
188  return (*it).second; // dummy to get rid of warning
189 }
190 
191 UanTxMode
192 UanTxModeFactory::GetMode(std::string name)
193 {
195  return factory.MakeModeFromItem(factory.GetModeItem(name));
196 }
197 
198 UanTxMode
200 {
202  return factory.MakeModeFromItem(factory.GetModeItem(uid));
203 }
204 
205 UanTxMode
207 {
208  UanTxMode mode;
209  mode.m_uid = item.m_uid;
210  return mode;
211 }
212 
215 {
216  static UanTxModeFactory factory;
217  return factory;
218 }
219 
221 {
222 }
223 
225 {
226  m_modes.clear();
227 }
228 
229 void
231 {
232  m_modes.push_back(newMode);
233 }
234 
235 void
236 UanModesList::DeleteMode(uint32_t modeNum)
237 {
238  NS_ASSERT(modeNum < m_modes.size());
239 
240  auto it = m_modes.begin();
241  for (uint32_t i = 0; i < modeNum; i++)
242  {
243  it++;
244  }
245  it = m_modes.erase(it);
246 }
247 
248 UanTxMode
249 UanModesList::operator[](uint32_t i) const
250 {
251  NS_ASSERT(i < m_modes.size());
252  return m_modes[i];
253 }
254 
255 uint32_t
257 {
258  return static_cast<uint32_t>(m_modes.size());
259 }
260 
261 std::ostream&
262 operator<<(std::ostream& os, const UanModesList& ml)
263 {
264  os << ml.GetNModes() << "|";
265 
266  for (uint32_t i = 0; i < ml.m_modes.size(); i++)
267  {
268  os << ml[i] << "|";
269  }
270  return os;
271 }
272 
273 std::istream&
274 operator>>(std::istream& is, UanModesList& ml)
275 {
276  char c;
277 
278  int numModes;
279 
280  is >> numModes >> c;
281  if (c != '|')
282  {
283  is.setstate(std::ios_base::failbit);
284  }
285  ml.m_modes.clear();
286  ml.m_modes.resize(numModes);
287 
288  for (int i = 0; i < numModes && !is.eof(); i++)
289  {
290  is >> ml.m_modes[i] >> c;
291  if (c != '|')
292  {
293  is.setstate(std::ios_base::failbit);
294  }
295  }
296 
297  return is;
298 }
299 
301 
302 } // namespace ns3
Container for UanTxModes.
Definition: uan-tx-mode.h:259
void DeleteMode(uint32_t num)
Delete the mode at given index.
Definition: uan-tx-mode.cc:236
UanModesList()
Constructor.
Definition: uan-tx-mode.cc:220
uint32_t GetNModes() const
Get the number of modes in this list.
Definition: uan-tx-mode.cc:256
void AppendMode(UanTxMode mode)
Add mode to this list.
Definition: uan-tx-mode.cc:230
UanTxMode operator[](uint32_t index) const
Retrieve a mode by index.
Definition: uan-tx-mode.cc:249
virtual ~UanModesList()
Destructor.
Definition: uan-tx-mode.cc:224
std::vector< UanTxMode > m_modes
The vector of modes in this list.
Definition: uan-tx-mode.h:290
Global database of UanTxMode objects, retrievable by id or name.
Definition: uan-tx-mode.h:140
static UanTxMode CreateMode(UanTxMode::ModulationType type, uint32_t dataRateBps, uint32_t phyRateSps, uint32_t cfHz, uint32_t bwHz, uint32_t constSize, std::string name)
Definition: uan-tx-mode.cc:132
UanTxMode MakeModeFromItem(const UanTxModeItem &item)
Create a public UanTxMode from an internal UanTxModeItem.
Definition: uan-tx-mode.cc:206
UanTxModeFactory()
Constructor.
Definition: uan-tx-mode.cc:106
static UanTxModeFactory & GetFactory()
Construct and get the static global factory instance.
Definition: uan-tx-mode.cc:214
static UanTxMode GetMode(std::string name)
Get a mode by name.
Definition: uan-tx-mode.cc:192
std::map< uint32_t, UanTxModeItem > m_modes
Container for modes.
Definition: uan-tx-mode.h:209
~UanTxModeFactory()
Destructor.
Definition: uan-tx-mode.cc:111
bool NameUsed(std::string name)
Check if the mode name already exists.
Definition: uan-tx-mode.cc:117
uint32_t m_nextUid
next id number
Definition: uan-tx-mode.h:182
UanTxModeItem & GetModeItem(uint32_t uid)
Get a mode by id.
Definition: uan-tx-mode.cc:166
Abstraction of packet modulation information.
Definition: uan-tx-mode.h:43
uint32_t GetUid() const
Get a unique id for the mode.
Definition: uan-tx-mode.cc:82
ModulationType
Modulation type.
Definition: uan-tx-mode.h:52
uint32_t GetConstellationSize() const
Get the number of constellation points in the modulation scheme.
Definition: uan-tx-mode.cc:70
uint32_t GetPhyRateSps() const
Get the physical signaling rate.
Definition: uan-tx-mode.cc:52
uint32_t GetDataRateBps() const
Get the data rate of the transmit mode.
Definition: uan-tx-mode.cc:46
~UanTxMode()
Destructor.
Definition: uan-tx-mode.cc:35
uint32_t GetBandwidthHz() const
Get the transmission signal bandwidth.
Definition: uan-tx-mode.cc:64
std::string GetName() const
Get the mode name.
Definition: uan-tx-mode.cc:76
UanTxMode()
Constructor.
Definition: uan-tx-mode.cc:31
uint32_t m_uid
Mode id.
Definition: uan-tx-mode.h:113
ModulationType GetModType() const
Get the modulation type of the mode.
Definition: uan-tx-mode.cc:40
uint32_t GetCenterFreqHz() const
Get the transmission center frequency.
Definition: uan-tx-mode.cc:58
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file,...
Definition: assert.h:66
#define NS_FATAL_ERROR(msg)
Report a fatal error with a message and terminate.
Definition: fatal-error.h:179
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:202
#define NS_LOG_WARN(msg)
Use NS_LOG to output a message of level LOG_WARN.
Definition: log.h:261
Every class exported by the ns3 library is enclosed in the ns3 namespace.
ATTRIBUTE_HELPER_CPP(ValueClassTest)
std::istream & operator>>(std::istream &is, Angles &a)
Definition: angles.cc:183
std::ostream & operator<<(std::ostream &os, const Angles &a)
Definition: angles.cc:159
Container for the UanTxMode properties.
Definition: uan-tx-mode.h:189
uint32_t m_constSize
Modulation constellation size (2 for BPSK, 4 for QPSK).
Definition: uan-tx-mode.h:195
uint32_t m_phyRateSps
Symbol rate in symbols per second.
Definition: uan-tx-mode.h:194
std::string m_name
Unique string name for this transmission mode.
Definition: uan-tx-mode.h:197
UanTxMode::ModulationType m_type
Modulation type.
Definition: uan-tx-mode.h:190
uint32_t m_bwHz
Bandwidth in Hz.
Definition: uan-tx-mode.h:192
uint32_t m_dataRateBps
Data rate in BPS.
Definition: uan-tx-mode.h:193
uint32_t m_cfHz
Center frequency in Hz.
Definition: uan-tx-mode.h:191