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