A Discrete-Event Network Simulator
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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 NS_LOG_COMPONENT_DEFINE ("SSScheduler");
35 
36 namespace ns3 {
37 NS_OBJECT_ENSURE_REGISTERED (SSScheduler)
38  ;
39 
41 {
42  static TypeId tid = TypeId ("ns3::SSScheduler")
43  .SetParent<Object> ();
44  return tid;
45 }
46 
48  : m_ss (ss),
49  m_pollMe (false)
50 {
51 }
52 
54 {
55 }
56 
57 void
59 {
60  m_ss = 0;
61 }
62 
63 void
65 {
66  m_pollMe = pollMe;
67 }
68 
69 bool
71 {
72  return m_pollMe;
73 }
74 
76 SSScheduler::Schedule (uint16_t availableSymbols,
77  WimaxPhy::ModulationType modulationType,
78  MacHeaderType::HeaderType packetType,
79  Ptr<WimaxConnection> &connection)
80 {
81  Time timeStamp;
82  Ptr<PacketBurst> burst = Create<PacketBurst> ();
83  uint16_t nrSymbolsRequired = 0;
84 
85  if (!connection)
86  {
87  connection = SelectConnection ();
88  }
89  else
90  {
91  NS_ASSERT_MSG (connection->HasPackets (),
92  "SS: Error while scheduling packets: The selected connection has no packets");
93  }
94 
95  Ptr<Packet> packet;
96 
97  while (connection && connection->HasPackets (packetType))
98  {
99  NS_LOG_INFO ("FRAG_DEBUG: SS Scheduler" << std::endl);
100 
101  uint32_t availableByte = m_ss->GetPhy ()->
102  GetNrBytes (availableSymbols, modulationType);
103 
104  uint32_t requiredByte = connection->GetQueue ()->GetFirstPacketRequiredByte (packetType);
105 
106  NS_LOG_INFO ("\t availableByte = " << availableByte <<
107  ", 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" << std::endl);
114 
115  packet = connection->Dequeue (packetType);
116  burst->AddPacket (packet);
117 
118  nrSymbolsRequired = m_ss->GetPhy ()->
119  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 = m_ss->GetPhy ()->
145  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, " << std::endl);
158  break;
159  }
160  }
161  }
162  return burst;
163 }
164 
167 {
168  Time currentTime = Simulator::Now ();
169  std::vector<ServiceFlow*>::const_iterator iter;
170  std::vector<ServiceFlow*> serviceFlows;
171 
172  NS_LOG_INFO ("SS Scheduler: Selecting connection...");
173  if (m_ss->GetInitialRangingConnection ()->HasPackets ())
174  {
175  NS_LOG_INFO ("Return GetInitialRangingConnection");
176  return m_ss->GetInitialRangingConnection ();
177  }
178  if (m_ss->GetBasicConnection ()->HasPackets ())
179  {
180  NS_LOG_INFO ("Return GetBasicConnection");
181  return m_ss->GetBasicConnection ();
182  }
183  if (m_ss->GetPrimaryConnection ()->HasPackets ())
184  {
185  NS_LOG_INFO ("Return GetPrimaryConnection");
186  return m_ss->GetPrimaryConnection ();
187  }
188 
189  serviceFlows = m_ss->GetServiceFlowManager ()->GetServiceFlows (ServiceFlow::SF_TYPE_UGS);
190  for (iter = serviceFlows.begin (); iter != serviceFlows.end (); ++iter)
191  {
192  // making sure that this grant was actually intended for this UGS
193 
194  if ((*iter)->HasPackets () && (currentTime
195  + m_ss->GetPhy ()->GetFrameDuration () > MilliSeconds (
196  (*iter)->GetUnsolicitedGrantInterval ())))
197  {
198  NS_LOG_INFO ("Return UGS SF: CID = " << (*iter)->GetCid () << "SFID = "
199  << (*iter)->GetSfid ());
200  return (*iter)->GetConnection ();
201  }
202  }
203 
204  /* In the following cases (rtPS, nrtPS and BE flows) connection is seletected only for data packets, for bandwidth
205  request packets connection will itself be passed to Schedule () and hence this function will never be called. */
206 
207  serviceFlows = m_ss->GetServiceFlowManager ()->GetServiceFlows (ServiceFlow::SF_TYPE_RTPS);
208  for (iter = serviceFlows.begin (); iter != serviceFlows.end (); ++iter)
209  {
210  if ((*iter)->HasPackets (MacHeaderType::HEADER_TYPE_GENERIC)
211  && (currentTime + m_ss->GetPhy ()->GetFrameDuration ()
212  > MilliSeconds (
213  (*iter)->GetUnsolicitedPollingInterval ())))
214  {
215  NS_LOG_INFO ("Return RTPS SF: CID = " << (*iter)->GetCid () << "SFID = "
216  << (*iter)->GetSfid ());
217  return (*iter)->GetConnection ();
218  }
219  }
220 
221  serviceFlows = m_ss->GetServiceFlowManager ()->GetServiceFlows (ServiceFlow::SF_TYPE_NRTPS);
222  for (iter = serviceFlows.begin (); iter != serviceFlows.end (); ++iter)
223  {
224  if ((*iter)->HasPackets (MacHeaderType::HEADER_TYPE_GENERIC))
225  {
226  NS_LOG_INFO ("Return NRTPS SF: CID = " << (*iter)->GetCid () << "SFID = "
227  << (*iter)->GetSfid ());
228  return (*iter)->GetConnection ();
229  }
230  }
231 
232  serviceFlows = m_ss->GetServiceFlowManager ()->GetServiceFlows (ServiceFlow::SF_TYPE_BE);
233  for (iter = serviceFlows.begin (); iter != serviceFlows.end (); ++iter)
234  {
235  if ((*iter)->HasPackets (MacHeaderType::HEADER_TYPE_GENERIC))
236  {
237  NS_LOG_INFO ("Return BE SF: CID = " << (*iter)->GetCid () << "SFID = "
238  << (*iter)->GetSfid ());
239  return (*iter)->GetConnection ();
240  }
241  }
242 
243  if (m_ss->GetBroadcastConnection ()->HasPackets ())
244  {
245  return m_ss->GetBroadcastConnection ();
246  }
247  NS_LOG_INFO ("NO connection is selected!");
248  return 0;
249 }
250 
251 } // namespace ns3
HeaderType
this class implements the mac header type field.
void DoDispose(void)
This method is called by Object::Dispose or by the object's destructor, whichever comes first...
Definition: ss-scheduler.cc:58
keep track of time values and allow control of global simulation resolution
Definition: nstime.h:81
smart pointer class similar to boost::intrusive_ptr
Definition: ptr.h:59
Ptr< PacketBurst > Schedule(uint16_t availableSymbols, WimaxPhy::ModulationType modulationType, MacHeaderType::HeaderType packetType, Ptr< WimaxConnection > &connection)
Definition: ss-scheduler.cc:76
void SetPollMe(bool pollMe)
Definition: ss-scheduler.cc:64
NS_OBJECT_ENSURE_REGISTERED(NullMessageSimulatorImpl)
uint32_t GetSize(void) const
Definition: packet.h:650
#define NS_LOG_INFO(msg)
Definition: log.h:298
NS_LOG_COMPONENT_DEFINE("SSScheduler")
bool GetPollMe(void) const
Definition: ss-scheduler.cc:70
Ptr< SubscriberStationNetDevice > m_ss
Definition: ss-scheduler.h:69
SSScheduler(Ptr< SubscriberStationNetDevice > ss)
Definition: ss-scheduler.cc:47
static TypeId GetTypeId(void)
Definition: ss-scheduler.cc:40
static Time Now(void)
Return the "current simulation time".
Definition: simulator.cc:180
#define NS_ASSERT_MSG(condition, message)
Definition: assert.h:86
a base class which provides memory management and object aggregation
Definition: object.h:63
Ptr< WimaxConnection > SelectConnection(void)
a unique identifier for an interface.
Definition: type-id.h:49
TypeId SetParent(TypeId tid)
Definition: type-id.cc:611