A Discrete-Event Network Simulator
API
channel-scheduler.cc
Go to the documentation of this file.
1 /*
2  * This program is free software; you can redistribute it and/or modify
3  * it under the terms of the GNU General Public License version 2 as
4  * published by the Free Software Foundation;
5  *
6  * This program is distributed in the hope that it will be useful,
7  * but WITHOUT ANY WARRANTY; without even the implied warranty of
8  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9  * GNU General Public License for more details.
10  *
11  * You should have received a copy of the GNU General Public License
12  * along with this program; if not, write to the Free Software
13  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
14  *
15  * Author: Junling Bu <linlinjavaer@gmail.com>
16  */
17 
18 #include "channel-scheduler.h"
19 
20 #include "ns3/log.h"
21 
22 namespace ns3
23 {
24 
25 NS_LOG_COMPONENT_DEFINE("ChannelScheduler");
26 
27 NS_OBJECT_ENSURE_REGISTERED(ChannelScheduler);
28 
33 TypeId
35 {
36  static TypeId tid = TypeId("ns3::ChannelScheduler").SetParent<Object>().SetGroupName("Wave");
37  return tid;
38 }
39 
41 {
42  NS_LOG_FUNCTION(this);
43 }
44 
46 {
47  NS_LOG_FUNCTION(this);
48 }
49 
50 void
52 {
53  // assign default CCH access when the device is initialized
55 }
56 
57 void
59 {
60  NS_LOG_FUNCTION(this << device);
61  m_device = device;
62 }
63 
64 bool
65 ChannelScheduler::IsChannelAccessAssigned(uint32_t channelNumber) const
66 {
67  NS_LOG_FUNCTION(this << channelNumber);
68  return (GetAssignedAccessType(channelNumber) != NoAccess);
69 }
70 
71 bool
73 {
74  NS_LOG_FUNCTION(this);
75  return (GetAssignedAccessType(CCH) != NoAccess);
76 }
77 
78 bool
80 {
81  NS_LOG_FUNCTION(this);
85 }
86 
87 bool
88 ChannelScheduler::IsContinuousAccessAssigned(uint32_t channelNumber) const
89 {
90  NS_LOG_FUNCTION(this << channelNumber);
91  return (GetAssignedAccessType(channelNumber) == ContinuousAccess);
92 }
93 
94 bool
95 ChannelScheduler::IsAlternatingAccessAssigned(uint32_t channelNumber) const
96 {
97  NS_LOG_FUNCTION(this << channelNumber);
98  return (GetAssignedAccessType(channelNumber) == AlternatingAccess);
99 }
100 
101 bool
102 ChannelScheduler::IsExtendedAccessAssigned(uint32_t channelNumber) const
103 {
104  NS_LOG_FUNCTION(this << channelNumber);
105  return (GetAssignedAccessType(channelNumber) == ExtendedAccess);
106 }
107 
108 bool
110 {
111  NS_LOG_FUNCTION(this);
113 }
114 
115 bool
117 {
118  NS_LOG_FUNCTION(this << &schInfo);
119  uint32_t cn = schInfo.channelNumber;
120 
122  {
123  NS_LOG_DEBUG("the channel access requirement for CCH is not allowed.");
124  return false;
125  }
126  uint32_t extends = schInfo.extendedAccess;
127  bool immediate = schInfo.immediateAccess;
129  for (EdcaParametersI i = schInfo.edcaParameters.begin(); i != schInfo.edcaParameters.end(); ++i)
130  {
131  EdcaParameter edca = i->second;
132  mac->ConfigureEdca(edca.cwmin, edca.cwmax, edca.aifsn, i->first);
133  }
134 
135  if (extends == EXTENDED_CONTINUOUS)
136  {
137  return AssignContinuousAccess(cn, immediate);
138  }
139  else if (extends == EXTENDED_ALTERNATING)
140  {
141  return AssignAlternatingAccess(cn, immediate);
142  }
143  else
144  {
145  return AssignExtendedAccess(cn, extends, immediate);
146  }
147 }
148 
149 bool
150 ChannelScheduler::StopSch(uint32_t channelNumber)
151 {
152  NS_LOG_FUNCTION(this << channelNumber);
153  if (ChannelManager::IsCch(channelNumber))
154  {
155  NS_LOG_DEBUG("the channel access for CCH is not allowed to be released.");
156  return false;
157  }
158  if (!IsChannelAccessAssigned(channelNumber))
159  {
160  NS_LOG_DEBUG("the channel access for channel " << channelNumber
161  << " has already been released.");
162  return true;
163  }
164  return ReleaseAccess(channelNumber);
165 }
166 
167 void
169 {
170  NS_LOG_FUNCTION(this);
171  m_device = nullptr;
172 }
173 
174 } // namespace ns3
#define SCH2
#define SCH5
#define SCH1
#define CCH
#define SCH6
#define SCH4
#define SCH3
#define EXTENDED_ALTERNATING
#define EXTENDED_CONTINUOUS
static bool IsCch(uint32_t channelNumber)
bool StopSch(uint32_t channelNumber)
bool StartSch(const SchInfo &schInfo)
bool IsAlternatingAccessAssigned(uint32_t channelNumber) const
bool IsCchAccessAssigned() const
void DoDispose() override
Destructor implementation.
bool IsSchAccessAssigned() const
bool IsContinuousAccessAssigned(uint32_t channelNumber) const
virtual ChannelAccess GetAssignedAccessType(uint32_t channelNumber) const =0
virtual void SetWaveNetDevice(Ptr< WaveNetDevice > device)
bool IsChannelAccessAssigned(uint32_t channelNumber) const
static TypeId GetTypeId()
Get the type ID.
Ptr< WaveNetDevice > m_device
the device
bool IsDefaultCchAccessAssigned() const
virtual bool ReleaseAccess(uint32_t channelNumber)=0
void DoInitialize() override
Initialize() implementation.
virtual bool AssignContinuousAccess(uint32_t channelNumber, bool immediate)=0
virtual bool AssignDefaultCchAccess()=0
This method will assign default CCH access for CCH.
virtual bool AssignExtendedAccess(uint32_t channelNumber, uint32_t extends, bool immediate)=0
bool IsExtendedAccessAssigned(uint32_t channelNumber) const
virtual bool AssignAlternatingAccess(uint32_t channelNumber, bool immediate)=0
A base class which provides memory management and object aggregation.
Definition: object.h:89
a unique identifier for an interface.
Definition: type-id.h:60
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:935
Ptr< OcbWifiMac > GetMac(uint32_t channelNumber) const
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:202
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
Definition: log.h:268
#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:46
std::map< AcIndex, EdcaParameter >::const_iterator EdcaParametersI
EDCA parameters iterator typedef.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
@ AlternatingAccess
@ ContinuousAccess
@ ExtendedAccess
@ DefaultCchAccess
mac
Definition: third.py:85
EdcaParameter structure.
uint32_t cwmin
minimum
uint32_t aifsn
AIFSN.
uint32_t cwmax
maximum
uint8_t extendedAccess
extended access
EdcaParameters edcaParameters
EDCA parameters.
uint32_t channelNumber
channel number
bool immediateAccess
immediate access