A Discrete-Event Network Simulator
API
ss-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) 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  * Mohamed Amine Ismail <amine.ismail@sophia.inria.fr>
19  */
20 
21 #include <stdint.h>
22 #include "ns3/node.h"
23 #include "ns3/simulator.h"
24 #include "ns3/packet.h"
25 #include "service-flow.h"
26 #include "service-flow-manager.h"
27 #include "ns3/log.h"
28 #include "wimax-net-device.h"
29 #include "bs-net-device.h"
30 #include "ss-net-device.h"
31 #include "ss-record.h"
32 #include "ns3/pointer.h"
33 #include "ns3/enum.h"
34 #include "wimax-connection.h"
35 #include "ss-manager.h"
36 #include "connection-manager.h"
37 #include "bs-uplink-scheduler.h"
38 #include "ss-scheduler.h"
39 #include "ns3/buffer.h"
40 #include "service-flow-record.h"
41 
42 namespace ns3 {
43 
44 NS_LOG_COMPONENT_DEFINE ("SsServiceFlowManager");
45 
47  : m_device (device),
48  m_maxDsaReqRetries (100),
49  m_dsaReq (DsaReq ()),
50  m_dsaAck (DsaAck ()),
51  m_currentTransactionId (0),
52  m_transactionIdIndex (1),
53  m_dsaReqRetries (0),
54  m_pendingServiceFlow (0)
55 {
56 }
57 
59 {
60 }
61 
62 /* static */
63 TypeId
65 {
66  static TypeId tid = TypeId ("ns3::SsServiceFlowManager")
68  .SetGroupName ("Wimax")
69  // No AddConstructor because this is an abstract class.
70  ;
71  return tid;
72 }
73 
74 void
76 {
78 }
79 
80 void
82 {
83  m_maxDsaReqRetries = maxDsaReqRetries;
84 }
85 
86 uint8_t
88 {
89  return m_maxDsaReqRetries;
90 }
91 
92 EventId
94 {
95  return m_dsaRspTimeoutEvent;
96 }
97 
98 EventId
100 {
101  return m_dsaAckTimeoutEvent;
102 }
103 
104 void
106 {
107  ServiceFlow * sf = new ServiceFlow ();
108  sf->CopyParametersFrom (serviceFlow);
110 }
111 
112 void
114 {
116 }
117 
118 
119 void
121 {
122  ServiceFlow *serviceFlow = GetNextServiceFlowToAllocate ();
123  NS_ASSERT_MSG (serviceFlow != 0,"Error while initiating a new service flow: All service flows have been initiated");
124  m_pendingServiceFlow = serviceFlow;
126 }
127 
128 DsaReq
130 {
131  DsaReq dsaReq;
134 
135  /*as it is SS-initiated DSA therefore SFID and CID will
136  not be included, see 6.3.2.3.10.1 and 6.3.2.3.11.1*/
137  dsaReq.SetServiceFlow (*serviceFlow);
138  // dsaReq.SetParameterSet (*serviceFlow->GetParameterSet ());
139  return dsaReq;
140 }
141 
144 {
145  DsaAck dsaAck;
148  m_dsaAck = dsaAck;
149  Ptr<Packet> p = Create<Packet> ();
150  p->AddHeader (dsaAck);
152  return p;
153 }
154 
155 void
157 {
158  Ptr<Packet> p = Create<Packet> ();
159  DsaReq dsaReq;
161 
162  if (m_dsaReqRetries == 0)
163  {
164  dsaReq = CreateDsaReq (serviceFlow);
165  p->AddHeader (dsaReq);
166  m_dsaReq = dsaReq;
167  }
168  else
169  {
171  {
172  p->AddHeader (m_dsaReq);
173  }
174  else
175  {
176  NS_LOG_DEBUG ("Service flows could not be initialized!");
177  }
178  }
179 
180  m_dsaReqRetries++;
182 
184  {
186  }
187 
188  m_dsaRspTimeoutEvent = Simulator::Schedule (ss->GetIntervalT7 (),
190  this,
191  serviceFlow);
192 
193  m_device->Enqueue (p, MacHeaderType (), ss->GetPrimaryConnection ());
194 }
195 
196 
197 void
199 {
200 
202 
203  // already received DSA-RSP for that particular DSA-REQ
204  if (dsaRsp.GetTransactionId () != m_currentTransactionId)
205  {
206  return;
207  }
208 
209  Ptr<Packet> dsaAck = CreateDsaAck ();
210  m_device->Enqueue (dsaAck, MacHeaderType (), ss->GetPrimaryConnection ());
211 
212  m_dsaReqRetries = 0;
213  if (m_pendingServiceFlow == NULL)
214  {
215  // May be the DSA-ACK was not received by the SS
216  return;
217  }
218  ServiceFlow sf = dsaRsp.GetServiceFlow ();
219  (*m_pendingServiceFlow) = sf;
222  Ptr<WimaxConnection> transportConnection = CreateObject<WimaxConnection> (sf.GetCid (),
224 
225  m_pendingServiceFlow->SetConnection (transportConnection);
226  transportConnection->SetServiceFlow (m_pendingServiceFlow);
227  ss->GetConnectionManager ()->AddConnection (transportConnection,
231  // check if all service flow have been initiated
232  ServiceFlow * serviceFlow = GetNextServiceFlowToAllocate ();
233  if (serviceFlow == 0)
234  {
235  ss->SetAreServiceFlowsAllocated (true);
236  }
237  else
238  {
239  m_pendingServiceFlow = serviceFlow;
241  }
242 }
243 
244 } // namespace ns3
This class implements the DSA-RSP message described by "IEEE Standard for Local and metropolitan ...
Definition: mac-messages.h:474
static EventId Schedule(Time const &delay, FUNC f, Ts &&... args)
Schedule an event to expire after delay.
Definition: simulator.h:557
uint8_t m_maxDsaReqRetries
maximum DSA request retries
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:73
This class implements the DSA-ACK message described by "IEEE Standard for Local and metropolitan area...
Definition: mac-messages.h:572
void SetServiceFlow(ServiceFlow sf)
specify a service flow to be requested by this message
void SetConnection(Ptr< WimaxConnection > connection)
Set connection.
Mac Management messages Section 6.3.2.3 MAC Management messages page 42, Table 14 page 43...
Definition: mac-messages.h:43
uint16_t GetTransactionId(void) const
Ptr< SubscriberStationNetDevice > m_device
the device
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:205
ServiceFlow * GetNextServiceFlowToAllocate()
static void Cancel(const EventId &id)
Set the cancel bit on this event: the event&#39;s associated function will not be invoked when it expires...
Definition: simulator.cc:268
uint8_t GetMaxDsaReqRetries(void) const
EventId GetDsaAckTimeoutEvent(void) const
Get DSA ack timeout event.
void AddServiceFlow(ServiceFlow *serviceFlow)
add a service flow to the list
void SetMaxDsaReqRetries(uint8_t maxDsaReqRetries)
sets the maximum retries on DSA request message
uint16_t GetTransactionId(void) const
void CopyParametersFrom(ServiceFlow sf)
Copy parameters from another service flow.
EventId GetDsaRspTimeoutEvent(void) const
Get DSA response timeout event.
void SetUnsolicitedGrantInterval(uint16_t unsolicitedGrantInterval)
Set unsolicied grant interval.
uint16_t m_currentTransactionId
current transaction ID
SsServiceFlowManager(Ptr< SubscriberStationNetDevice > device)
Constructor.
This class Represents the HT (Header Type) field of generic MAC and bandwidth request headers...
void InitiateServiceFlows(void)
Initiate service flows.
uint16_t GetCid(void) const
Get CID.
void DoDispose(void)
Destructor implementation.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
ServiceFlow * m_pendingServiceFlow
pending service flow
This class implements service flows as described by the IEEE-802.16 standard.
Definition: service-flow.h:39
EventId m_dsaAckTimeoutEvent
DSA ack timeout event.
DsaReq CreateDsaReq(const ServiceFlow *serviceFlow)
Create DSA request.
void SetTransactionId(uint16_t transactionId)
set the transaction ID
#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
ServiceFlow GetServiceFlow(void) const
void SetIsEnabled(bool isEnabled)
Set is enabled flag.
void SetTransactionId(uint16_t transactionId)
Set transaction ID field.
An identifier for simulation events.
Definition: event-id.h:53
void AddServiceFlow(ServiceFlow *serviceFlow)
Add service flow function.
void SetUnsolicitedPollingInterval(uint16_t unsolicitedPollingInterval)
Set unsolicited polling interval.
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
Definition: log.h:273
Ptr< Packet > CreateDsaAck(void)
Create DSA ack.
bool IsRunning(void) const
This method is syntactic sugar for !IsExpired().
Definition: event-id.cc:71
uint16_t m_transactionIdIndex
transaction ID index
SubscriberStationNetDevice subclass of WimaxNetDevice.
Definition: ss-net-device.h:48
void DoDispose(void)
Destructor implementation.
void ProcessDsaRsp(const DsaRsp &dsaRsp)
Process DSA response.
EventId m_dsaRspTimeoutEvent
DSA response timeout event.
uint8_t m_dsaReqRetries
DSA request retries.
This class implements the DSA-REQ message described by "IEEE Standard for Local and metropolitan area...
Definition: mac-messages.h:373
The same service flow manager class serves both for BS and SS though some functions are exclusive to ...
a unique identifier for an interface.
Definition: type-id.h:58
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:923
static TypeId GetTypeId(void)
Register this type.
void AddHeader(const Header &header)
Add header to this packet.
Definition: packet.cc:256
void SetConfirmationCode(uint16_t confirmationCode)
Set confirmation code field.
void ScheduleDsaReq(const ServiceFlow *serviceFlow)
Schedule DSA response.