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 void
59 {
61 }
62 
63 void
65 {
66  m_maxDsaRspRetries = maxDsaRspRetries;
67 }
68 
69 uint8_t
71 {
72  return m_maxDsaRspRetries;
73 }
74 
75 EventId
77 {
78  return m_dsaAckTimeoutEvent;
79 }
80 
81 void
83 {
85 }
86 
89 {
91 }
92 
95 {
97 }
98 
99 std::vector<ServiceFlow*>
101 {
102  return ServiceFlowManager::GetServiceFlows (schedulingType);
103 }
104 
105 DsaRsp
106 BsServiceFlowManager::CreateDsaRsp (const ServiceFlow *serviceFlow, uint16_t transactionId)
107 {
108  DsaRsp dsaRsp;
109  dsaRsp.SetTransactionId (transactionId);
110  dsaRsp.SetServiceFlow (*serviceFlow);
111  // assuming SS can supports all of the service flow parameters
113 
114  return dsaRsp;
115 }
116 
117 void
119 {
121 
122  SSRecord *ssRecord = bs->GetSSManager ()->GetSSRecord (cid);
123  if (ssRecord == 0)
124  {
125  NS_LOG_INFO ("SS not registered with the BS CID:" << cid);
126  return;
127  }
128 
129  serviceFlow->SetIsEnabled (true);
130  serviceFlow->SetType (ServiceFlow::SF_TYPE_ACTIVE);
131  ssRecord->AddServiceFlow (serviceFlow);
132 
133 
134  bs->GetUplinkScheduler ()->SetupServiceFlow (ssRecord, serviceFlow);
135 
136  Ptr<Packet> p = Create<Packet> ();
137  DsaRsp dsaRsp;
138 
139  if (ssRecord->GetDsaRspRetries () == 0)
140  {
141  dsaRsp = CreateDsaRsp (serviceFlow, ssRecord->GetSfTransactionId ());
142  p->AddHeader (dsaRsp);
143  ssRecord->SetDsaRsp (dsaRsp);
144  }
145  else
146  {
147  if (ssRecord->GetDsaRspRetries () < m_maxDsaRspRetries)
148  {
149  p->AddHeader (ssRecord->GetDsaRsp ());
150  }
151  else
152  {
153  NS_LOG_DEBUG ("Service flows could not be initialized!");
154  }
155  }
156 
157  ssRecord->IncrementDsaRspRetries ();
159 
161  {
163  }
164 
166 
167  m_dsaAckTimeoutEvent = Simulator::Schedule (bs->GetIntervalT8 (),
169  this,
170  serviceFlow,
171  cid);
172  m_device->Enqueue (p, MacHeaderType (), bs->GetConnection (ssRecord->GetPrimaryCid ()));
173 }
174 
177 {
178  ServiceFlow * serviceFlow;
180  SSRecord *ssRecord = bs->GetSSManager ()->GetSSRecord (cid);
181 
182  NS_LOG_INFO ("BsServiceFlowManager: Processing DSA-REQ...");
183  if (ssRecord->GetSfTransactionId () != 0)
184  {
185  // had already received DSA-REQ. DSA-RSP was lost
186  NS_ASSERT_MSG (dsaReq.GetTransactionId () == ssRecord->GetSfTransactionId (),
187  "Error while processing DSA request:the received transaction ID is not expected");
188  serviceFlow = GetServiceFlow (ssRecord->GetDsaRsp ().GetSfid ());
189  }
190  else
191  {
192  ServiceFlow sf = dsaReq.GetServiceFlow ();
193  Ptr<WimaxConnection> transportConnection;
194  Ptr<ConnectionManager> BsConManager = bs->GetConnectionManager ();
195  transportConnection = BsConManager->CreateConnection (Cid::TRANSPORT);
196  serviceFlow = new ServiceFlow (m_sfidIndex++, sf.GetDirection (), transportConnection);
197  transportConnection->SetServiceFlow (serviceFlow);
198  serviceFlow->CopyParametersFrom (sf);
199  serviceFlow->SetUnsolicitedGrantInterval (1);
200  serviceFlow->SetUnsolicitedPollingInterval (1);
202  AddServiceFlow (serviceFlow);
203  ssRecord->SetSfTransactionId (dsaReq.GetTransactionId ());
204  NS_LOG_INFO ("BsServiceFlowManager: Creating a new Service flow: SFID = " << serviceFlow->GetSfid () << " CID = "
205  << serviceFlow->GetCid ());
206  }
207  return serviceFlow;
208 }
209 
210 void
212 {
213  ServiceFlow * serviceFlow = new ServiceFlow ();
214  serviceFlow->CopyParametersFrom (sf);
216  Ptr<WimaxConnection> multicastConnection = bs->GetConnectionManager ()->CreateConnection (Cid::MULTICAST);
217  serviceFlow->SetConnection (multicastConnection);
218  AddServiceFlow (serviceFlow);
219  serviceFlow->SetIsEnabled (true);
220  serviceFlow->SetType (ServiceFlow::SF_TYPE_ACTIVE);
221  serviceFlow->SetIsMulticast (true);
222  serviceFlow->SetModulation (modulation);
223  bs->GetUplinkScheduler ()->SetupServiceFlow (0, serviceFlow);
224 }
225 
226 void
228 {
229  ServiceFlow *serviceFlow = ProcessDsaReq (dsaReq, cid);
230  if (serviceFlow) {
231  ScheduleDsaRsp (serviceFlow, cid);
232  } else {
233  NS_LOG_INFO ("No service Flow. Could not connect.");
234  }
235 }
236 
237 void
239 {
241  SSRecord *ssRecord = bs->GetSSManager ()->GetSSRecord (cid);
242 
243  if (dsaAck.GetTransactionId () != ssRecord->GetSfTransactionId ())
244  {
245  return;
246  }
247 
248  ssRecord->SetDsaRspRetries (0);
249  ssRecord->SetSfTransactionId (0);
250 
251  // check if all service flow have been initiated
252  if (AreServiceFlowsAllocated (ssRecord->GetServiceFlows (ServiceFlow::SF_TYPE_ALL)))
253  {
254  ssRecord->SetAreServiceFlowsAllocated (true);
255  }
256 }
257 } // namespace ns3
Introspection did not find any typical Config paths.
Definition: mac-messages.h:344
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:73
Introspection did not find any typical Config paths.
Definition: mac-messages.h:430
ServiceFlow * GetServiceFlow(uint32_t sfid) const
void SetConnection(Ptr< WimaxConnection > connection)
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
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:201
BsServiceFlowManager(Ptr< BaseStationNetDevice > device)
uint8_t GetMaxDsaRspRetries(void) const
uint32_t GetSfid(void) const
#define NS_LOG_INFO(msg)
Use NS_LOG to output a message of level LOG_INFO.
Definition: log.h:244
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:311
bool IsRunning(void) const
This method is syntactic sugar for !IsExpired().
Definition: event-id.cc:65
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:819
void DoDispose(void)
Destructor implementation.
void ScheduleDsaRsp(ServiceFlow *serviceFlow, Cid cid)
void SetTransactionId(uint16_t transactionId)
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)
Destructor implementation.
void SetConvergenceSublayerParam(CsParameters)
Every class exported by the ns3 library is enclosed in the ns3 namespace.
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)
At runtime, in debugging builds, if this condition is not true, the program prints the message to out...
Definition: assert.h:90
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:53
void AddServiceFlow(ServiceFlow *serviceFlow)
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
Definition: log.h:236
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
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