A Discrete-Event Network Simulator
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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 NS_LOG_COMPONENT_DEFINE ("BsServiceFlowManager");
41 
42 namespace ns3 {
43 
45  : m_device (device),
46  m_sfidIndex (100),
47  m_maxDsaRspRetries (100) // default value
48 {
50 }
51 
53 {
54 }
55 
56 void
58 {
60 }
61 
62 void
64 {
65  m_maxDsaRspRetries = maxDsaRspRetries;
66 }
67 
68 uint8_t
70 {
71  return m_maxDsaRspRetries;
72 }
73 
74 EventId
76 {
77  return m_dsaAckTimeoutEvent;
78 }
79 
80 void
82 {
84 }
85 
88 {
90 }
91 
94 {
96 }
97 
98 std::vector<ServiceFlow*>
100 {
101  return ServiceFlowManager::GetServiceFlows (schedulingType);
102 }
103 
104 DsaRsp
105 BsServiceFlowManager::CreateDsaRsp (const ServiceFlow *serviceFlow, uint16_t transactionId)
106 {
107  DsaRsp dsaRsp;
108  dsaRsp.SetTransactionId (transactionId);
109  dsaRsp.SetServiceFlow (*serviceFlow);
110  // assuming SS can supports all of the service flow parameters
112 
113  return dsaRsp;
114 }
115 
116 void
118 {
120 
121  SSRecord *ssRecord = bs->GetSSManager ()->GetSSRecord (cid);
122  if (ssRecord == 0)
123  {
124  NS_LOG_INFO ("SS not registered with the BS CID:" << cid);
125  return;
126  }
127 
128  serviceFlow->SetIsEnabled (true);
129  serviceFlow->SetType (ServiceFlow::SF_TYPE_ACTIVE);
130  ssRecord->AddServiceFlow (serviceFlow);
131 
132 
133  bs->GetUplinkScheduler ()->SetupServiceFlow (ssRecord, serviceFlow);
134 
135  Ptr<Packet> p = Create<Packet> ();
136  DsaRsp dsaRsp;
137 
138  if (ssRecord->GetDsaRspRetries () == 0)
139  {
140  dsaRsp = CreateDsaRsp (serviceFlow, ssRecord->GetSfTransactionId ());
141  p->AddHeader (dsaRsp);
142  ssRecord->SetDsaRsp (dsaRsp);
143  }
144  else
145  {
146  if (ssRecord->GetDsaRspRetries () < m_maxDsaRspRetries)
147  {
148  p->AddHeader (ssRecord->GetDsaRsp ());
149  }
150  else
151  {
152  NS_LOG_DEBUG ("Service flows could not be initialized!");
153  }
154  }
155 
156  ssRecord->IncrementDsaRspRetries ();
158 
160  {
162  }
163 
165 
166  m_dsaAckTimeoutEvent = Simulator::Schedule (bs->GetIntervalT8 (),
168  this,
169  serviceFlow,
170  cid);
171  m_device->Enqueue (p, MacHeaderType (), bs->GetConnection (ssRecord->GetPrimaryCid ()));
172 }
173 
176 {
177  ServiceFlow * serviceFlow;
179  SSRecord *ssRecord = bs->GetSSManager ()->GetSSRecord (cid);
180 
181  NS_LOG_INFO ("BsServiceFlowManager: Processing DSA-REQ...");
182  if (ssRecord->GetSfTransactionId () != 0)
183  {
184  // had already received DSA-REQ. DSA-RSP was lost
185  NS_ASSERT_MSG (dsaReq.GetTransactionId () == ssRecord->GetSfTransactionId (),
186  "Error while processing DSA request:the received transaction ID is not expected");
187  serviceFlow = GetServiceFlow (ssRecord->GetDsaRsp ().GetSfid ());
188  }
189  else
190  {
191  ServiceFlow sf = dsaReq.GetServiceFlow ();
192  Ptr<WimaxConnection> transportConnection;
193  Ptr<ConnectionManager> BsConManager = bs->GetConnectionManager ();
194  transportConnection = BsConManager->CreateConnection (Cid::TRANSPORT);
195  serviceFlow = new ServiceFlow (m_sfidIndex++, sf.GetDirection (), transportConnection);
196  transportConnection->SetServiceFlow (serviceFlow);
197  serviceFlow->CopyParametersFrom (sf);
198  serviceFlow->SetUnsolicitedGrantInterval (1);
199  serviceFlow->SetUnsolicitedPollingInterval (1);
201  AddServiceFlow (serviceFlow);
202  ssRecord->SetSfTransactionId (dsaReq.GetTransactionId ());
203  NS_LOG_INFO ("BsServiceFlowManager: Creating a new Service flow: SFID = " << serviceFlow->GetSfid () << " CID = "
204  << serviceFlow->GetCid ());
205  }
206  return serviceFlow;
207 }
208 
209 void
211 {
212  ServiceFlow * serviceFlow = new ServiceFlow ();
213  serviceFlow->CopyParametersFrom (sf);
215  Ptr<WimaxConnection> multicastConnection = bs->GetConnectionManager ()->CreateConnection (Cid::MULTICAST);
216  serviceFlow->SetConnection (multicastConnection);
217  AddServiceFlow (serviceFlow);
218  serviceFlow->SetIsEnabled (true);
219  serviceFlow->SetType (ServiceFlow::SF_TYPE_ACTIVE);
220  serviceFlow->SetIsMulticast (true);
221  serviceFlow->SetModulation (modulation);
222  bs->GetUplinkScheduler ()->SetupServiceFlow (0, serviceFlow);
223 }
224 
225 void
227 {
228  ServiceFlow *serviceFlow = ProcessDsaReq (dsaReq, cid);
229  if (serviceFlow) {
230  ScheduleDsaRsp (serviceFlow, cid);
231  } else {
232  NS_LOG_INFO ("No service Flow. Could not connect.");
233  }
234 }
235 
236 void
238 {
240  SSRecord *ssRecord = bs->GetSSManager ()->GetSSRecord (cid);
241 
242  if (dsaAck.GetTransactionId () != ssRecord->GetSfTransactionId ())
243  {
244  return;
245  }
246 
247  ssRecord->SetDsaRspRetries (0);
248  ssRecord->SetSfTransactionId (0);
249 
250  // check if all service flow have been initiated
251  if (AreServiceFlowsAllocated (ssRecord->GetServiceFlows (ServiceFlow::SF_TYPE_ALL)))
252  {
253  ssRecord->SetAreServiceFlowsAllocated (true);
254  }
255 }
256 } // namespace ns3
Doxygen introspection did not find any typical Config paths.
Definition: mac-messages.h:335
smart pointer class similar to boost::intrusive_ptr
Definition: ptr.h:59
Doxygen introspection did not find any typical Config paths.
Definition: mac-messages.h:412
ServiceFlow * GetServiceFlow(uint32_t sfid) const
void SetConnection(Ptr< WimaxConnection > connection)
Doxygen introspection did not find any typical Config paths.
Definition: mac-messages.h:41
void SetServiceFlow(ServiceFlow sf)
specify a service flow to be requested by this message
void AllocateServiceFlows(const DsaReq &dsaReq, Cid cid)
ServiceFlow GetServiceFlow(void) const
BsServiceFlowManager(Ptr< BaseStationNetDevice > device)
uint8_t GetMaxDsaRspRetries(void) const
uint32_t GetSfid(void) const
#define NS_LOG_INFO(msg)
Definition: log.h:298
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
bool IsRunning(void) const
This method is syntactic sugar for the ns3::Simulator::isExpired method.
Definition: event-id.cc:59
static EventId Schedule(Time const &time, MEM mem_ptr, OBJ obj)
Schedule an event to expire at the relative time "time" is reached.
Definition: simulator.h:824
void DoDispose(void)
This method is called by Object::Dispose or by the object's destructor, whichever comes first...
void ScheduleDsaRsp(ServiceFlow *serviceFlow, Cid cid)
void SetTransactionId(uint16_t transactionId)
NS_LOG_COMPONENT_DEFINE("BsServiceFlowManager")
static Cid InitialRanging(void)
Definition: cid.cc:82
void SetUnsolicitedPollingInterval(uint16_t)
void CopyParametersFrom(ServiceFlow sf)
ServiceFlow * GetServiceFlow(uint32_t sfid) const
void SetUnsolicitedGrantInterval(uint16_t)
EventId GetDsaAckTimeoutEvent(void) const
Represents the HT (Header Type) field of generic MAC and bandwidth request headers.
void DoDispose(void)
This method is called by Object::Dispose or by the object's destructor, whichever comes first...
void SetConvergenceSublayerParam(CsParameters)
Definition: cid.h:35
std::vector< ServiceFlow * > GetServiceFlows(enum ServiceFlow::SchedulingType schedulingType) const
ServiceFlow * ProcessDsaReq(const DsaReq &dsaReq, Cid cid)
process a DSA-Req message
This class implements service flows as described by the IEEE-802.16 standard.
Definition: service-flow.h:39
void SetConfirmationCode(uint16_t confirmationCode)
#define NS_ASSERT_MSG(condition, message)
Definition: assert.h:86
void SetModulation(enum WimaxPhy::ModulationType modulationType)
void SetMaxDsaRspRetries(uint8_t maxDsaRspRetries)
set the maximum Dynamic ServiceFlow Add (DSA) retries
void ProcessDsaAck(const DsaAck &dsaAck, Cid cid)
process a DSA-ACK message
enum Direction GetDirection(void) const
void SetIsEnabled(bool isEnabled)
void SetType(enum Type type)
an identifier for simulation events.
Definition: event-id.h:46
void AddServiceFlow(ServiceFlow *serviceFlow)
#define NS_LOG_DEBUG(msg)
Definition: log.h:289
uint16_t GetTransactionId(void) const
void AddServiceFlow(ServiceFlow *serviceFlow)
Add a new service flow.
void AddMulticastServiceFlow(ServiceFlow sf, enum WimaxPhy::ModulationType modulation)
add a multicast service flow
This class is used by the base station to store some information related to subscriber station in the...
Definition: ss-record.h:43
void SetIsMulticast(bool isMulticast)
CsParameters GetConvergenceSublayerParam(void) const
Doxygen introspection did not find any typical Config paths.
Definition: mac-messages.h:262
DsaRsp CreateDsaRsp(const ServiceFlow *serviceFlow, uint16_t transactionId)
void AddHeader(const Header &header)
Add header to this packet.
Definition: packet.cc:253
uint16_t GetTransactionId(void) const
uint16_t GetCid(void) const
std::vector< ServiceFlow * > GetServiceFlows(ServiceFlow::SchedulingType schedulingType) const