A Discrete-Event Network Simulator
API
bs-service-flow-manager.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, 2009 INRIA, UDcast
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  * Authors: Jahanzeb Farooq <jahanzeb.farooq@sophia.inria.fr>
19  * Mohamed Amine Ismail <amine.ismail@sophia.inria.fr>
20  */
21 
22 #include <stdint.h>
23 #include "ns3/node.h"
24 #include "ns3/simulator.h"
25 #include "ns3/packet.h"
26 #include "service-flow.h"
27 #include "service-flow-manager.h"
28 #include "ns3/log.h"
29 #include "bs-net-device.h"
30 #include "ss-record.h"
31 #include "ns3/pointer.h"
32 #include "ns3/enum.h"
33 #include "wimax-connection.h"
34 #include "ss-manager.h"
35 #include "connection-manager.h"
36 #include "bs-uplink-scheduler.h"
37 #include "ss-scheduler.h"
38 #include "ns3/buffer.h"
39 #include "service-flow-record.h"
40 
41 namespace ns3 {
42 
43 NS_LOG_COMPONENT_DEFINE ("BsServiceFlowManager");
44 
46  : m_device (device),
47  m_sfidIndex (100),
48  m_maxDsaRspRetries (100) // default value
49 {
51 }
52 
54 {
55 }
56 
57 /* static */
58 TypeId
60 {
61  static TypeId tid = TypeId ("ns3::BsServiceFlowManager")
63  .SetGroupName ("Wifi")
64  // No AddConstructor because this class has no default constructor.
65  ;
66  return tid;
67 }
68 
69 void
71 {
73 }
74 
75 void
77 {
78  m_maxDsaRspRetries = maxDsaRspRetries;
79 }
80 
81 uint8_t
83 {
84  return m_maxDsaRspRetries;
85 }
86 
87 EventId
89 {
90  return m_dsaAckTimeoutEvent;
91 }
92 
93 void
95 {
97 }
98 
101 {
103 }
104 
107 {
109 }
110 
111 std::vector<ServiceFlow*>
113 {
114  return ServiceFlowManager::GetServiceFlows (schedulingType);
115 }
116 
117 DsaRsp
118 BsServiceFlowManager::CreateDsaRsp (const ServiceFlow *serviceFlow, uint16_t transactionId)
119 {
120  DsaRsp dsaRsp;
121  dsaRsp.SetTransactionId (transactionId);
122  dsaRsp.SetServiceFlow (*serviceFlow);
123  // assuming SS can supports all of the service flow parameters
125 
126  return dsaRsp;
127 }
128 
129 void
131 {
133 
134  SSRecord *ssRecord = bs->GetSSManager ()->GetSSRecord (cid);
135  if (ssRecord == 0)
136  {
137  NS_LOG_INFO ("SS not registered with the BS CID:" << cid);
138  return;
139  }
140 
141  serviceFlow->SetIsEnabled (true);
142  serviceFlow->SetType (ServiceFlow::SF_TYPE_ACTIVE);
143  ssRecord->AddServiceFlow (serviceFlow);
144 
145 
146  bs->GetUplinkScheduler ()->SetupServiceFlow (ssRecord, serviceFlow);
147 
148  Ptr<Packet> p = Create<Packet> ();
149  DsaRsp dsaRsp;
150 
151  if (ssRecord->GetDsaRspRetries () == 0)
152  {
153  dsaRsp = CreateDsaRsp (serviceFlow, ssRecord->GetSfTransactionId ());
154  p->AddHeader (dsaRsp);
155  ssRecord->SetDsaRsp (dsaRsp);
156  }
157  else
158  {
159  if (ssRecord->GetDsaRspRetries () < m_maxDsaRspRetries)
160  {
161  p->AddHeader (ssRecord->GetDsaRsp ());
162  }
163  else
164  {
165  NS_LOG_DEBUG ("Service flows could not be initialized!");
166  }
167  }
168 
169  ssRecord->IncrementDsaRspRetries ();
171 
173  {
175  }
176 
178 
179  m_dsaAckTimeoutEvent = Simulator::Schedule (bs->GetIntervalT8 (),
181  this,
182  serviceFlow,
183  cid);
184  m_device->Enqueue (p, MacHeaderType (), bs->GetConnection (ssRecord->GetPrimaryCid ()));
185 }
186 
189 {
190  ServiceFlow * serviceFlow;
192  SSRecord *ssRecord = bs->GetSSManager ()->GetSSRecord (cid);
193 
194  NS_LOG_INFO ("BsServiceFlowManager: Processing DSA-REQ...");
195  if (ssRecord->GetSfTransactionId () != 0)
196  {
197  // had already received DSA-REQ. DSA-RSP was lost
198  NS_ASSERT_MSG (dsaReq.GetTransactionId () == ssRecord->GetSfTransactionId (),
199  "Error while processing DSA request:the received transaction ID is not expected");
200  serviceFlow = GetServiceFlow (ssRecord->GetDsaRsp ().GetSfid ());
201  }
202  else
203  {
204  ServiceFlow sf = dsaReq.GetServiceFlow ();
205  Ptr<WimaxConnection> transportConnection;
206  Ptr<ConnectionManager> BsConManager = bs->GetConnectionManager ();
207  transportConnection = BsConManager->CreateConnection (Cid::TRANSPORT);
208  serviceFlow = new ServiceFlow (m_sfidIndex++, sf.GetDirection (), transportConnection);
209  transportConnection->SetServiceFlow (serviceFlow);
210  serviceFlow->CopyParametersFrom (sf);
211  serviceFlow->SetUnsolicitedGrantInterval (1);
212  serviceFlow->SetUnsolicitedPollingInterval (1);
214  AddServiceFlow (serviceFlow);
215  ssRecord->SetSfTransactionId (dsaReq.GetTransactionId ());
216  NS_LOG_INFO ("BsServiceFlowManager: Creating a new Service flow: SFID = " << serviceFlow->GetSfid () << " CID = "
217  << serviceFlow->GetCid ());
218  }
219  return serviceFlow;
220 }
221 
222 void
224 {
225  ServiceFlow * serviceFlow = new ServiceFlow ();
226  serviceFlow->CopyParametersFrom (sf);
228  Ptr<WimaxConnection> multicastConnection = bs->GetConnectionManager ()->CreateConnection (Cid::MULTICAST);
229  serviceFlow->SetConnection (multicastConnection);
230  AddServiceFlow (serviceFlow);
231  serviceFlow->SetIsEnabled (true);
232  serviceFlow->SetType (ServiceFlow::SF_TYPE_ACTIVE);
233  serviceFlow->SetIsMulticast (true);
234  serviceFlow->SetModulation (modulation);
235  bs->GetUplinkScheduler ()->SetupServiceFlow (0, serviceFlow);
236 }
237 
238 void
240 {
241  ServiceFlow *serviceFlow = ProcessDsaReq (dsaReq, cid);
242  if (serviceFlow) {
243  ScheduleDsaRsp (serviceFlow, cid);
244  } else {
245  NS_LOG_INFO ("No service Flow. Could not connect.");
246  }
247 }
248 
249 void
251 {
253  SSRecord *ssRecord = bs->GetSSManager ()->GetSSRecord (cid);
254 
255  if (dsaAck.GetTransactionId () != ssRecord->GetSfTransactionId ())
256  {
257  return;
258  }
259 
260  ssRecord->SetDsaRspRetries (0);
261  ssRecord->SetSfTransactionId (0);
262 
263  // check if all service flow have been initiated
264  if (AreServiceFlowsAllocated (ssRecord->GetServiceFlows (ServiceFlow::SF_TYPE_ALL)))
265  {
266  ssRecord->SetAreServiceFlowsAllocated (true);
267  }
268 }
269 } // namespace ns3
BaseStation NetDevice.
Definition: bs-net-device.h:53
ServiceFlow * GetServiceFlow(uint32_t sfid) const
uint8_t m_maxDsaRspRetries
maximum number of DSA response retries
void DoDispose(void)
Destructor implementation.
uint8_t GetMaxDsaRspRetries(void) const
void AllocateServiceFlows(const DsaReq &dsaReq, Cid cid)
allocate service flows
Cid m_inuseScheduleDsaRspCid
in use schedule DSA response CID
void AddMulticastServiceFlow(ServiceFlow sf, enum WimaxPhy::ModulationType modulation)
add a multicast service flow
Ptr< WimaxNetDevice > m_device
the device
void ScheduleDsaRsp(ServiceFlow *serviceFlow, Cid cid)
Create DSA response function.
void ProcessDsaAck(const DsaAck &dsaAck, Cid cid)
process a DSA-ACK message
std::vector< ServiceFlow * > GetServiceFlows(ServiceFlow::SchedulingType schedulingType) const
void AddServiceFlow(ServiceFlow *serviceFlow)
Add a new service flow.
void SetMaxDsaRspRetries(uint8_t maxDsaRspRetries)
set the maximum Dynamic ServiceFlow Add (DSA) retries
EventId GetDsaAckTimeoutEvent(void) const
DsaRsp CreateDsaRsp(const ServiceFlow *serviceFlow, uint16_t transactionId)
Create DSA response function.
EventId m_dsaAckTimeoutEvent
DSA ack timeout event.
static TypeId GetTypeId(void)
Register this type.
BsServiceFlowManager(Ptr< BaseStationNetDevice > device)
Constructor.
ServiceFlow * ProcessDsaReq(const DsaReq &dsaReq, Cid cid)
process a DSA-Req message
Cid class.
Definition: cid.h:38
@ TRANSPORT
Definition: cid.h:47
@ MULTICAST
Definition: cid.h:48
static Cid InitialRanging(void)
Definition: cid.cc:82
This class implements the DSA-ACK message described by "IEEE Standard for Local and metropolitan area...
Definition: mac-messages.h:573
uint16_t GetTransactionId(void) const
Get transaction ID field.
This class implements the DSA-REQ message described by "IEEE Standard for Local and metropolitan area...
Definition: mac-messages.h:374
uint16_t GetTransactionId(void) const
ServiceFlow GetServiceFlow(void) const
This class implements the DSA-RSP message described by "IEEE Standard for Local and metropolitan ar...
Definition: mac-messages.h:475
void SetConfirmationCode(uint16_t confirmationCode)
set the confirmation code
void SetServiceFlow(ServiceFlow sf)
specify a service flow to be requested by this message
void SetTransactionId(uint16_t transactionId)
set the transaction ID
An identifier for simulation events.
Definition: event-id.h:54
bool IsRunning(void) const
This method is syntactic sugar for !IsExpired().
Definition: event-id.cc:71
This class Represents the HT (Header Type) field of generic MAC and bandwidth request headers.
Mac Management messages Section 6.3.2.3 MAC Management messages page 42, Table 14 page 43.
Definition: mac-messages.h:44
void AddHeader(const Header &header)
Add header to this packet.
Definition: packet.cc:256
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:74
This class is used by the base station to store some information related to subscriber station in the...
Definition: ss-record.h:44
This class implements service flows as described by the IEEE-802.16 standard.
Definition: service-flow.h:40
void SetType(enum Type type)
Set type of service flow.
void SetModulation(enum WimaxPhy::ModulationType modulationType)
Set modulation.
enum Direction GetDirection(void) const
Get direction.
SchedulingType
section 11.13.11 Service flow scheduling type, page 701
Definition: service-flow.h:59
void SetConvergenceSublayerParam(CsParameters csparam)
Set convergence sublayer parameters.
uint16_t GetCid(void) const
Get CID.
void CopyParametersFrom(ServiceFlow sf)
Copy parameters from another service flow.
void SetIsMulticast(bool isMulticast)
Set is multicast.
CsParameters GetConvergenceSublayerParam(void) const
Get convergence sublayer.
void SetUnsolicitedGrantInterval(uint16_t unsolicitedGrantInterval)
Set unsolicied grant interval.
void SetUnsolicitedPollingInterval(uint16_t unsolicitedPollingInterval)
Set unsolicited polling interval.
uint32_t GetSfid(void) const
Get SFID.
void SetConnection(Ptr< WimaxConnection > connection)
Set connection.
void SetIsEnabled(bool isEnabled)
Set is enabled flag.
The same service flow manager class serves both for BS and SS though some functions are exclusive to ...
std::vector< ServiceFlow * > GetServiceFlows(enum ServiceFlow::SchedulingType schedulingType) const
Get service flows function.
void AddServiceFlow(ServiceFlow *serviceFlow)
Add service flow function.
ServiceFlow * GetServiceFlow(uint32_t sfid) const
Get service flow by flow id.
void DoDispose(void)
Destructor implementation.
static void Cancel(const EventId &id)
Set the cancel bit on this event: the event's associated function will not be invoked when it expires...
Definition: simulator.cc:268
static EventId Schedule(Time const &delay, FUNC f, Ts &&... args)
Schedule an event to expire after delay.
Definition: simulator.h:556
a unique identifier for an interface.
Definition: type-id.h:59
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:922
ModulationType
ModulationType enumeration.
Definition: wimax-phy.h:52
#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:88
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:205
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
Definition: log.h:273
#define NS_LOG_INFO(msg)
Use NS_LOG to output a message of level LOG_INFO.
Definition: log.h:281
Every class exported by the ns3 library is enclosed in the ns3 namespace.