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 }
55 
56 uint32_t
58 {
60  return CCH;
61 }
62 
63 std::vector<uint32_t>
65 {
67  std::vector<uint32_t> schs;
68  schs.push_back (SCH1);
69  schs.push_back (SCH2);
70  schs.push_back (SCH3);
71  schs.push_back (SCH4);
72  schs.push_back (SCH5);
73  schs.push_back (SCH6);
74  return schs;
75 }
76 
77 std::vector<uint32_t>
79 {
81  std::vector<uint32_t> channels;
82  channels.push_back (CCH);
83  channels.push_back (SCH1);
84  channels.push_back (SCH2);
85  channels.push_back (SCH3);
86  channels.push_back (SCH4);
87  channels.push_back (SCH5);
88  channels.push_back (SCH6);
89  return channels;
90 }
91 
92 uint32_t
94 {
96  static uint32_t NumberOfWaveChannels = GetWaveChannels ().size ();
97  return NumberOfWaveChannels;
98 }
99 
100 bool
101 ChannelManager::IsCch (uint32_t channelNumber)
102 {
104  return channelNumber == CCH;
105 }
106 
107 bool
108 ChannelManager::IsSch (uint32_t channelNumber)
109 {
111  if (channelNumber < SCH1 || channelNumber > SCH6)
112  {
113  return false;
114  }
115  if (channelNumber % 2 == 1)
116  {
117  return false;
118  }
119  return (channelNumber != CCH);
120 }
121 
122 bool
123 ChannelManager::IsWaveChannel (uint32_t channelNumber)
124 {
126  if (channelNumber < SCH1 || channelNumber > SCH6)
127  {
128  return false;
129  }
130  if (channelNumber % 2 == 1)
131  {
132  return false;
133  }
134  return true;
135 }
136 
137 uint32_t
138 ChannelManager::GetOperatingClass (uint32_t channelNumber)
139 {
140  NS_LOG_FUNCTION (this << channelNumber);
141  return m_channels[channelNumber]->operatingClass;
142 }
143 
144 bool
146 {
147  NS_LOG_FUNCTION (this << channelNumber);
148  return m_channels[channelNumber]->adaptable;
149 }
150 
151 WifiMode
153 {
154  NS_LOG_FUNCTION (this << channelNumber);
155  return m_channels[channelNumber]->dataRate;
156 }
157 
160 {
161  NS_LOG_FUNCTION (this << channelNumber);
162  return m_channels[channelNumber]->preamble;
163 }
164 
165 uint32_t
167 {
168  NS_LOG_FUNCTION (this << channelNumber);
169  return m_channels[channelNumber]->txPowerLevel;
170 }
171 
172 void
174 {
175  NS_LOG_FUNCTION (this);
176  std::map<uint32_t, WaveChannel *> ::iterator i;
177  for (i = m_channels.begin (); i != m_channels.end (); ++i)
178  {
179  delete (i->second);
180  }
181  m_channels.clear ();
182 }
183 
184 } // namespace ns3
#define SCH2
#define SCH5
#define SCH1
#define CCH
#define SCH6
#define SCH4
#define SCH3
manage 7 WaveChannels and the tx information such as data rate and txPowerLevel.
static bool IsCch(uint32_t channelNumber)
static uint32_t GetNumberOfWaveChannels(void)
bool GetManagementAdaptable(uint32_t channelNumber)
static std::vector< uint32_t > GetWaveChannels(void)
virtual void DoDispose(void)
Destructor implementation.
static TypeId GetTypeId(void)
Get the type ID.
WifiPreamble GetManagementPreamble(uint32_t channelNumber)
uint32_t GetManagementPowerLevel(uint32_t channelNumber)
WifiMode GetManagementDataRate(uint32_t channelNumber)
static bool IsSch(uint32_t channelNumber)
uint32_t GetOperatingClass(uint32_t channelNumber)
std::map< uint32_t, WaveChannel * > m_channels
list of channels
static std::vector< uint32_t > GetSchs(void)
static uint32_t GetCch(void)
static bool IsWaveChannel(uint32_t channelNumber)
A base class which provides memory management and object aggregation.
Definition: object.h:88
a unique identifier for an interface.
Definition: type-id.h:59
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:922
represent a single transmission mode
Definition: wifi-mode.h:48
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:205
#define NS_LOG_FUNCTION_NOARGS()
Output the name of the function.
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by ",...
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition: object-base.h:45
WifiPreamble
The type of preamble to be used by an IEEE 802.11 transmission.
Every class exported by the ns3 library is enclosed in the ns3 namespace.