A Discrete-Event Network Simulator
API
channel-scheduler.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 
19 #include "channel-scheduler.h"
20 #include "ns3/log.h"
21 
22 namespace ns3 {
23 
24 NS_LOG_COMPONENT_DEFINE ("ChannelScheduler");
25 
26 NS_OBJECT_ENSURE_REGISTERED (ChannelScheduler);
27 
28 TypeId
30 {
31  static TypeId tid = TypeId ("ns3::ChannelScheduler")
32  .SetParent<Object> ()
33  ;
34  return tid;
35 }
36 
38 {
39  NS_LOG_FUNCTION (this);
40 }
42 {
43  NS_LOG_FUNCTION (this);
44 }
45 
46 void
48 {
49  // assign default CCH access when the device is initialized
51 }
52 
53 void
55 {
56  NS_LOG_FUNCTION (this << device);
57  m_device = device;
58 }
59 
60 bool
61 ChannelScheduler::IsChannelAccessAssigned (uint32_t channelNumber) const
62 {
63  NS_LOG_FUNCTION (this << channelNumber);
64  return (GetAssignedAccessType (channelNumber) != NoAccess);
65 }
66 
67 bool
69 {
70  NS_LOG_FUNCTION (this);
71  return (GetAssignedAccessType (CCH) != NoAccess);
72 }
73 
74 bool
76 {
77  NS_LOG_FUNCTION (this);
81 }
82 
83 bool
84 ChannelScheduler::IsContinuousAccessAssigned (uint32_t channelNumber) const
85 {
86  NS_LOG_FUNCTION (this << channelNumber);
87  return (GetAssignedAccessType (channelNumber) == ContinuousAccess);
88 }
89 bool
90 ChannelScheduler::IsAlternatingAccessAssigned (uint32_t channelNumber) const
91 {
92  NS_LOG_FUNCTION (this << channelNumber);
93  return (GetAssignedAccessType (channelNumber) == AlternatingAccess);
94 }
95 bool
96 ChannelScheduler::IsExtendedAccessAssigned (uint32_t channelNumber) const
97 {
98  NS_LOG_FUNCTION (this << channelNumber);
99  return (GetAssignedAccessType (channelNumber) == ExtendedAccess);
100 }
101 bool
103 {
104  NS_LOG_FUNCTION (this);
106 }
107 bool
109 {
110  NS_LOG_FUNCTION (this << &schInfo);
111  uint32_t cn = schInfo.channelNumber;
112 
113  if (ChannelManager::IsCch (schInfo.channelNumber))
114  {
115  NS_LOG_DEBUG ("the channel access requirement for CCH is not allowed.");
116  return false;
117  }
118  uint32_t extends = schInfo.extendedAccess;
119  bool immediate = schInfo.immediateAccess;
120  Ptr<OcbWifiMac> mac = m_device->GetMac (cn);
121  for (EdcaParameterSetI i = schInfo.edcaParameterSet.begin (); i != schInfo.edcaParameterSet.end (); ++i)
122  {
123  EdcaParameter edca = i->second;
124  mac->ConfigureEdca (edca.cwmin, edca.cwmax, edca.aifsn, i->first);
125  }
126 
127  if (extends == EXTENDED_CONTINUOUS)
128  {
129  return AssignContinuousAccess (cn, immediate);
130  }
131  else if (extends == EXTENDED_ALTERNATING)
132  {
133  return AssignAlternatingAccess (cn, immediate);
134  }
135  else
136  {
137  return AssignExtendedAccess (cn, extends, immediate);
138  }
139 }
140 
141 bool
142 ChannelScheduler::StopSch (uint32_t channelNumber)
143 {
144  NS_LOG_FUNCTION (this << channelNumber);
145  if (ChannelManager::IsCch (channelNumber))
146  {
147  NS_LOG_DEBUG ("the channel access for CCH is not allowed to be released.");
148  return false;
149  }
150  if (!IsChannelAccessAssigned (channelNumber))
151  {
152  NS_LOG_DEBUG ("the channel access for channel " << channelNumber << " has already been released.");
153  return true;
154  }
155  return ReleaseAccess (channelNumber);
156 }
157 
158 } // namespace ns3
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by "...
void ConfigureEdca(uint32_t cwmin, uint32_t cwmax, uint32_t aifsn, enum AcIndex ac)
uint8_t extendedAccess
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition: object-base.h:44
virtual bool AssignExtendedAccess(uint32_t channelNumber, uint32_t extends, bool immediate)=0
bool StartSch(const SchInfo &schInfo)
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:201
EdcaParameterSet edcaParameterSet
virtual bool AssignDefaultCchAccess(void)=0
bool IsDefaultCchAccessAssigned(void) const
#define CCH
virtual void DoInitialize(void)
Initialize() implementation.
virtual void SetWaveNetDevice(Ptr< WaveNetDevice > device)
bool IsSchAccessAssigned(void) const
#define EXTENDED_ALTERNATING
bool IsAlternatingAccessAssigned(uint32_t channelNumber) const
#define EXTENDED_CONTINUOUS
virtual bool AssignAlternatingAccess(uint32_t channelNumber, bool immediate)=0
#define SCH2
virtual enum ChannelAccess GetAssignedAccessType(uint32_t channelNumber) const =0
static bool IsCch(uint32_t channelNumber)
Every class exported by the ns3 library is enclosed in the ns3 namespace.
Ptr< OcbWifiMac > GetMac(uint32_t channelNumber) const
uint32_t channelNumber
virtual bool AssignContinuousAccess(uint32_t channelNumber, bool immediate)=0
std::map< AcIndex, EdcaParameter >::const_iterator EdcaParameterSetI
bool IsContinuousAccessAssigned(uint32_t channelNumber) const
bool StopSch(uint32_t channelNumber)
static TypeId GetTypeId(void)
Ptr< WaveNetDevice > m_device
bool IsCchAccessAssigned(void) const
#define SCH5
#define SCH3
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
Definition: log.h:236
bool IsExtendedAccessAssigned(uint32_t channelNumber) const
bool IsChannelAccessAssigned(uint32_t channelNumber) const
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
#define SCH6
virtual bool ReleaseAccess(uint32_t channelNumber)=0