A Discrete-Event Network Simulator
API
channel-manager.cc
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * This program is free software; you can redistribute it and/or modify
4  * it under the terms of the GNU General Public License version 2 as
5  * published by the Free Software Foundation;
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * along with this program; if not, write to the Free Software
14  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
15  *
16  * Author: Junling Bu <linlinjavaer@gmail.com>
17  */
18 #include "channel-manager.h"
19 #include "ns3/log.h"
20 #include "ns3/assert.h"
21 
22 namespace ns3 {
23 
24 NS_LOG_COMPONENT_DEFINE ("ChannelManager");
25 
26 NS_OBJECT_ENSURE_REGISTERED (ChannelManager);
27 
28 TypeId
30 {
31  static TypeId tid = TypeId ("ns3::ChannelManager")
32  .SetParent<Object> ()
33  .SetGroupName ("Wave")
34  .AddConstructor<ChannelManager> ()
35  ;
36  return tid;
37 }
38 
40 {
41  NS_LOG_FUNCTION (this);
42  m_channels.insert (std::make_pair (CCH, new WaveChannel (CCH)));
43  m_channels.insert (std::make_pair (SCH1, new WaveChannel (SCH1)));
44  m_channels.insert (std::make_pair (SCH2, new WaveChannel (SCH2)));
45  m_channels.insert (std::make_pair (SCH3, new WaveChannel (SCH3)));
46  m_channels.insert (std::make_pair (SCH4, new WaveChannel (SCH4)));
47  m_channels.insert (std::make_pair (SCH5, new WaveChannel (SCH5)));
48  m_channels.insert (std::make_pair (SCH6, new WaveChannel (SCH6)));
49 }
50 
52 {
53  NS_LOG_FUNCTION (this);
54  std::map<uint32_t, WaveChannel *> ::iterator i;
55  for (i = m_channels.begin (); i != m_channels.end (); ++i)
56  {
57  delete (i->second);
58  }
59  m_channels.clear ();
60 }
61 
62 uint32_t
64 {
66  return CCH;
67 }
68 
69 std::vector<uint32_t>
71 {
73  std::vector<uint32_t> schs;
74  schs.push_back (SCH1);
75  schs.push_back (SCH2);
76  schs.push_back (SCH3);
77  schs.push_back (SCH4);
78  schs.push_back (SCH5);
79  schs.push_back (SCH6);
80  return schs;
81 }
82 
83 std::vector<uint32_t>
85 {
87  std::vector<uint32_t> channels;
88  channels.push_back (CCH);
89  channels.push_back (SCH1);
90  channels.push_back (SCH2);
91  channels.push_back (SCH3);
92  channels.push_back (SCH4);
93  channels.push_back (SCH5);
94  channels.push_back (SCH6);
95  return channels;
96 }
97 
98 uint32_t
100 {
102  static uint32_t NumberOfWaveChannels = GetWaveChannels ().size ();
103  return NumberOfWaveChannels;
104 }
105 
106 bool
107 ChannelManager::IsCch (uint32_t channelNumber)
108 {
110  return channelNumber == CCH;
111 }
112 
113 bool
114 ChannelManager::IsSch (uint32_t channelNumber)
115 {
117  if (channelNumber < SCH1 || channelNumber > SCH6)
118  {
119  return false;
120  }
121  if (channelNumber % 2 == 1)
122  {
123  return false;
124  }
125  return (channelNumber != CCH);
126 }
127 
128 bool
129 ChannelManager::IsWaveChannel (uint32_t channelNumber)
130 {
132  if (channelNumber < SCH1 || channelNumber > SCH6)
133  {
134  return false;
135  }
136  if (channelNumber % 2 == 1)
137  {
138  return false;
139  }
140  return true;
141 }
142 
143 uint32_t
144 ChannelManager::GetOperatingClass (uint32_t channelNumber)
145 {
146  NS_LOG_FUNCTION (this << channelNumber);
147  return m_channels[channelNumber]->operatingClass;
148 }
149 
150 bool
152 {
153  NS_LOG_FUNCTION (this << channelNumber);
154  return m_channels[channelNumber]->adaptable;
155 }
156 
157 WifiMode
159 {
160  NS_LOG_FUNCTION (this << channelNumber);
161  return m_channels[channelNumber]->dataRate;
162 }
163 
166 {
167  NS_LOG_FUNCTION (this << channelNumber);
168  return m_channels[channelNumber]->preamble;
169 }
170 
171 uint32_t
173 {
174  NS_LOG_FUNCTION (this << channelNumber);
175  return m_channels[channelNumber]->txPowerLevel;
176 }
177 
178 } // namespace ns3
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by "...
static std::vector< uint32_t > GetWaveChannels(void)
static std::vector< uint32_t > GetSchs(void)
bool GetManagementAdaptable(uint32_t channelNumber)
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition: object-base.h:45
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:204
static bool IsWaveChannel(uint32_t channelNumber)
#define NS_LOG_FUNCTION_NOARGS()
Output the name of the function.
WifiPreamble GetManagementPreamble(uint32_t channelNumber)
#define CCH
represent a single transmission modeA WifiMode is implemented by a single integer which is used to lo...
Definition: wifi-mode.h:97
WifiPreamble
The type of preamble to be used by an IEEE 802.11 transmission.
Definition: wifi-preamble.h:30
static uint32_t GetNumberOfWaveChannels(void)
#define SCH2
static uint32_t GetCch(void)
static bool IsCch(uint32_t channelNumber)
Every class exported by the ns3 library is enclosed in the ns3 namespace.
uint32_t GetOperatingClass(uint32_t channelNumber)
static bool IsSch(uint32_t channelNumber)
#define SCH5
#define SCH3
uint32_t GetManagementPowerLevel(uint32_t channelNumber)
WifiMode GetManagementDataRate(uint32_t channelNumber)
A base class which provides memory management and object aggregation.
Definition: object.h:87
a unique identifier for an interface.
Definition: type-id.h:58
#define SCH4
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:915
#define SCH1
static TypeId GetTypeId(void)
Get the type ID.
#define SCH6
std::map< uint32_t, WaveChannel * > m_channels
list of channels
manage 7 WaveChannels and the tx information such as data rate and txPowerLevel.