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  .AddConstructor<ChannelManager> ()
34  ;
35  return tid;
36 }
37 
39 {
40  NS_LOG_FUNCTION (this);
41  m_channels.insert (std::make_pair (CCH, new WaveChannel (CCH)));
42  m_channels.insert (std::make_pair (SCH1, new WaveChannel (SCH1)));
43  m_channels.insert (std::make_pair (SCH2, new WaveChannel (SCH2)));
44  m_channels.insert (std::make_pair (SCH3, new WaveChannel (SCH3)));
45  m_channels.insert (std::make_pair (SCH4, new WaveChannel (SCH4)));
46  m_channels.insert (std::make_pair (SCH5, new WaveChannel (SCH5)));
47  m_channels.insert (std::make_pair (SCH6, new WaveChannel (SCH6)));
48 }
49 
51 {
52  NS_LOG_FUNCTION (this);
53  std::map<uint32_t, WaveChannel *> ::iterator i;
54  for (i = m_channels.begin (); i != m_channels.end (); ++i)
55  {
56  delete (i->second);
57  }
58  m_channels.clear ();
59 }
60 
61 uint32_t
63 {
65  return CCH;
66 }
67 
68 std::vector<uint32_t>
70 {
72  std::vector<uint32_t> schs;
73  schs.push_back (SCH1);
74  schs.push_back (SCH2);
75  schs.push_back (SCH3);
76  schs.push_back (SCH4);
77  schs.push_back (SCH5);
78  schs.push_back (SCH6);
79  return schs;
80 }
81 
82 std::vector<uint32_t>
84 {
86  std::vector<uint32_t> channels;
87  channels.push_back (CCH);
88  channels.push_back (SCH1);
89  channels.push_back (SCH2);
90  channels.push_back (SCH3);
91  channels.push_back (SCH4);
92  channels.push_back (SCH5);
93  channels.push_back (SCH6);
94  return channels;
95 }
96 
97 uint32_t
99 {
101  static uint32_t NumberOfWaveChannels = GetWaveChannels ().size ();
102  return NumberOfWaveChannels;
103 }
104 
105 bool
106 ChannelManager::IsCch (uint32_t channelNumber)
107 {
109  return channelNumber == CCH;
110 }
111 
112 bool
113 ChannelManager::IsSch (uint32_t channelNumber)
114 {
116  if (channelNumber < SCH1 || channelNumber > SCH6)
117  {
118  return false;
119  }
120  if (channelNumber % 2 == 1)
121  {
122  return false;
123  }
124  return (channelNumber != CCH);
125 }
126 
127 bool
128 ChannelManager::IsWaveChannel (uint32_t channelNumber)
129 {
131  if (channelNumber < SCH1 || channelNumber > SCH6)
132  {
133  return false;
134  }
135  if (channelNumber % 2 == 1)
136  {
137  return false;
138  }
139  return true;
140 }
141 
142 uint32_t
143 ChannelManager::GetOperatingClass (uint32_t channelNumber)
144 {
145  NS_LOG_FUNCTION (this << channelNumber);
146  return m_channels[channelNumber]->operatingClass;
147 }
148 
149 bool
151 {
152  NS_LOG_FUNCTION (this << channelNumber);
153  return m_channels[channelNumber]->adaptable;
154 }
155 
156 WifiMode
158 {
159  NS_LOG_FUNCTION (this << channelNumber);
160  return m_channels[channelNumber]->dataRate;
161 }
162 
163 uint32_t
165 {
166  NS_LOG_FUNCTION (this << channelNumber);
167  return m_channels[channelNumber]->txPowerLevel;
168 }
169 
170 } // 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:44
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:201
static bool IsWaveChannel(uint32_t channelNumber)
#define NS_LOG_FUNCTION_NOARGS()
Output the name of the function.
#define CCH
represent a single transmission modeA WifiMode is implemented by a single integer which is used to lo...
Definition: wifi-mode.h:93
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:51
#define SCH4
TypeId SetParent(TypeId tid)
Definition: type-id.cc:631
#define SCH1
static TypeId GetTypeId(void)
#define SCH6
std::map< uint32_t, WaveChannel * > m_channels