A Discrete-Event Network Simulator
API
ss-scheduler.cc
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2007,2008 INRIA
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License version 2 as
6  * published by the Free Software Foundation;
7  *
8  * This program is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  * GNU General Public License for more details.
12  *
13  * You should have received a copy of the GNU General Public License
14  * along with this program; if not, write to the Free Software
15  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16  *
17  * Author: Jahanzeb Farooq <jahanzeb.farooq@sophia.inria.fr>
18  */
19 
20 #include "ss-scheduler.h"
21 
22 #include "connection-manager.h"
23 #include "service-flow-manager.h"
24 #include "service-flow-record.h"
25 #include "service-flow.h"
26 #include "ss-net-device.h"
27 #include "wimax-connection.h"
28 #include "wimax-mac-queue.h"
29 #include "wimax-phy.h"
30 
31 #include "ns3/log.h"
32 #include "ns3/node.h"
33 #include "ns3/simulator.h"
34 
35 namespace ns3
36 {
37 
38 NS_LOG_COMPONENT_DEFINE("SSScheduler");
39 
40 NS_OBJECT_ENSURE_REGISTERED(SSScheduler);
41 
42 TypeId
44 {
45  static TypeId tid = TypeId("ns3::SSScheduler").SetParent<Object>().SetGroupName("Wimax");
46  return tid;
47 }
48 
50  : m_ss(ss),
51  m_pollMe(false)
52 {
53 }
54 
56 {
57 }
58 
59 void
61 {
62  m_ss = nullptr;
63 }
64 
65 void
67 {
68  m_pollMe = pollMe;
69 }
70 
71 bool
73 {
74  return m_pollMe;
75 }
76 
78 SSScheduler::Schedule(uint16_t availableSymbols,
79  WimaxPhy::ModulationType modulationType,
80  MacHeaderType::HeaderType packetType,
81  Ptr<WimaxConnection>& connection)
82 {
83  Time timeStamp;
84  Ptr<PacketBurst> burst = Create<PacketBurst>();
85  uint16_t nrSymbolsRequired = 0;
86 
87  if (!connection)
88  {
89  connection = SelectConnection();
90  }
91  else
92  {
93  NS_ASSERT_MSG(connection->HasPackets(),
94  "SS: Error while scheduling packets: The selected connection has no packets");
95  }
96 
97  Ptr<Packet> packet;
98 
99  while (connection && connection->HasPackets(packetType))
100  {
101  NS_LOG_INFO("FRAG_DEBUG: SS Scheduler" << std::endl);
102 
103  uint32_t availableByte = m_ss->GetPhy()->GetNrBytes(availableSymbols, modulationType);
104 
105  uint32_t requiredByte = connection->GetQueue()->GetFirstPacketRequiredByte(packetType);
106 
107  NS_LOG_INFO("\t availableByte = " << availableByte << ", requiredByte = " << requiredByte);
108 
109  if (availableByte >= requiredByte)
110  {
111  // The SS could sent a packet without a other fragmentation
112  NS_LOG_INFO("\t availableByte >= requiredByte"
113  "\n\t Send packet without other fragmentation"
114  << std::endl);
115 
116  packet = connection->Dequeue(packetType);
117  burst->AddPacket(packet);
118 
119  nrSymbolsRequired = m_ss->GetPhy()->GetNrSymbols(packet->GetSize(), modulationType);
120  availableSymbols -= nrSymbolsRequired;
121  }
122  else
123  {
124  if (connection->GetType() == Cid::TRANSPORT)
125  {
126  NS_LOG_INFO("\t availableByte < requiredByte"
127  "\n\t Check if the fragmentation is possible");
128 
129  uint32_t headerSize = connection->GetQueue()->GetFirstPacketHdrSize(packetType);
130  if (!connection->GetQueue()->CheckForFragmentation(packetType))
131  {
132  NS_LOG_INFO("\t Add fragmentSubhdrSize = 2");
133  headerSize += 2;
134  }
135  NS_LOG_INFO("\t availableByte = " << availableByte
136  << " headerSize = " << headerSize);
137 
138  if (availableByte > headerSize)
139  {
140  NS_LOG_INFO("\t Fragmentation IS possible");
141  packet = connection->Dequeue(packetType, availableByte);
142  burst->AddPacket(packet);
143 
144  nrSymbolsRequired =
145  m_ss->GetPhy()->GetNrSymbols(packet->GetSize(), modulationType);
146  availableSymbols -= nrSymbolsRequired;
147  }
148  else
149  {
150  NS_LOG_INFO("\t Fragmentation IS NOT possible" << std::endl);
151  break;
152  }
153  }
154  else
155  {
156  NS_LOG_INFO("\t no Transport Connection "
157  "\n\t Fragmentation IS NOT possible, "
158  << std::endl);
159  break;
160  }
161  }
162  }
163  return burst;
164 }
165 
168 {
169  Time currentTime = Simulator::Now();
170 
171  NS_LOG_INFO("SS Scheduler: Selecting connection...");
172  if (m_ss->GetInitialRangingConnection()->HasPackets())
173  {
174  NS_LOG_INFO("Return GetInitialRangingConnection");
175  return m_ss->GetInitialRangingConnection();
176  }
177  if (m_ss->GetBasicConnection()->HasPackets())
178  {
179  NS_LOG_INFO("Return GetBasicConnection");
180  return m_ss->GetBasicConnection();
181  }
182  if (m_ss->GetPrimaryConnection()->HasPackets())
183  {
184  NS_LOG_INFO("Return GetPrimaryConnection");
185  return m_ss->GetPrimaryConnection();
186  }
187 
188  auto serviceFlows = m_ss->GetServiceFlowManager()->GetServiceFlows(ServiceFlow::SF_TYPE_UGS);
189  for (auto iter = serviceFlows.begin(); iter != serviceFlows.end(); ++iter)
190  {
191  // making sure that this grant was actually intended for this UGS
192 
193  if ((*iter)->HasPackets() && (currentTime + m_ss->GetPhy()->GetFrameDuration() >
194  MilliSeconds((*iter)->GetUnsolicitedGrantInterval())))
195  {
196  NS_LOG_INFO("Return UGS SF: CID = " << (*iter)->GetCid()
197  << "SFID = " << (*iter)->GetSfid());
198  return (*iter)->GetConnection();
199  }
200  }
201 
202  /* In the following cases (rtPS, nrtPS and BE flows) connection is seletected only for data
203  packets, for bandwidth request packets connection will itself be passed to Schedule () and
204  hence this function will never be called. */
205 
206  serviceFlows = m_ss->GetServiceFlowManager()->GetServiceFlows(ServiceFlow::SF_TYPE_RTPS);
207  for (auto iter = serviceFlows.begin(); iter != serviceFlows.end(); ++iter)
208  {
209  if ((*iter)->HasPackets(MacHeaderType::HEADER_TYPE_GENERIC) &&
210  (currentTime + m_ss->GetPhy()->GetFrameDuration() >
211  MilliSeconds((*iter)->GetUnsolicitedPollingInterval())))
212  {
213  NS_LOG_INFO("Return RTPS SF: CID = " << (*iter)->GetCid()
214  << "SFID = " << (*iter)->GetSfid());
215  return (*iter)->GetConnection();
216  }
217  }
218 
219  serviceFlows = m_ss->GetServiceFlowManager()->GetServiceFlows(ServiceFlow::SF_TYPE_NRTPS);
220  for (auto iter = serviceFlows.begin(); iter != serviceFlows.end(); ++iter)
221  {
222  if ((*iter)->HasPackets(MacHeaderType::HEADER_TYPE_GENERIC))
223  {
224  NS_LOG_INFO("Return NRTPS SF: CID = " << (*iter)->GetCid()
225  << "SFID = " << (*iter)->GetSfid());
226  return (*iter)->GetConnection();
227  }
228  }
229 
230  serviceFlows = m_ss->GetServiceFlowManager()->GetServiceFlows(ServiceFlow::SF_TYPE_BE);
231  for (auto iter = serviceFlows.begin(); iter != serviceFlows.end(); ++iter)
232  {
233  if ((*iter)->HasPackets(MacHeaderType::HEADER_TYPE_GENERIC))
234  {
235  NS_LOG_INFO("Return BE SF: CID = " << (*iter)->GetCid()
236  << "SFID = " << (*iter)->GetSfid());
237  return (*iter)->GetConnection();
238  }
239  }
240 
241  if (m_ss->GetBroadcastConnection()->HasPackets())
242  {
243  return m_ss->GetBroadcastConnection();
244  }
245  NS_LOG_INFO("NO connection is selected!");
246  return nullptr;
247 }
248 
249 } // namespace ns3
@ TRANSPORT
Definition: cid.h:46
HeaderType
Header type enumeration.
A base class which provides memory management and object aggregation.
Definition: object.h:89
uint32_t GetSize() const
Returns the the size in bytes of the packet (including the zero-filled initial payload).
Definition: packet.h:861
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:77
SSScheduler(Ptr< SubscriberStationNetDevice > ss)
Constructor.
Definition: ss-scheduler.cc:49
bool m_pollMe
poll me flag
Definition: ss-scheduler.h:94
void DoDispose() override
Destructor implementation.
Definition: ss-scheduler.cc:60
Ptr< PacketBurst > Schedule(uint16_t availableSymbols, WimaxPhy::ModulationType modulationType, MacHeaderType::HeaderType packetType, Ptr< WimaxConnection > &connection)
Definition: ss-scheduler.cc:78
static TypeId GetTypeId()
Get the type ID.
Definition: ss-scheduler.cc:43
Ptr< SubscriberStationNetDevice > m_ss
the subscriber station
Definition: ss-scheduler.h:93
void SetPollMe(bool pollMe)
Set poll me value.
Definition: ss-scheduler.cc:66
Ptr< WimaxConnection > SelectConnection()
Select connection.
bool GetPollMe() const
Get the poll me value.
Definition: ss-scheduler.cc:72
~SSScheduler() override
Definition: ss-scheduler.cc:55
static Time Now()
Return the current simulation virtual time.
Definition: simulator.cc:208
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:105
a unique identifier for an interface.
Definition: type-id.h:59
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:931
ModulationType
ModulationType enumeration.
Definition: wimax-phy.h:54
#define NS_ASSERT_MSG(condition, message)
At runtime, in debugging builds, if this condition is not true, the program prints the message to out...
Definition: assert.h:86
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:202
#define NS_LOG_INFO(msg)
Use NS_LOG to output a message of level LOG_INFO.
Definition: log.h:275
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition: object-base.h:46
Time MilliSeconds(uint64_t value)
Construct a Time in the indicated unit.
Definition: nstime.h:1338
Every class exported by the ns3 library is enclosed in the ns3 namespace.