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
ns3::DsaRsp::GetServiceFlow
ServiceFlow GetServiceFlow(void) const
Definition: mac-messages.cc:668
ns3::TypeId
a unique identifier for an interface.
Definition: type-id.h:59
NS_LOG_COMPONENT_DEFINE
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:205
ns3::DsaRsp::GetTransactionId
uint16_t GetTransactionId(void) const
Definition: mac-messages.cc:662
ns3::ServiceFlow::SetUnsolicitedGrantInterval
void SetUnsolicitedGrantInterval(uint16_t unsolicitedGrantInterval)
Set unsolicied grant interval.
Definition: service-flow.cc:615
ns3::DsaReq::GetTransactionId
uint16_t GetTransactionId(void) const
Definition: mac-messages.cc:540
ss-net-device.h
ns3::EventId
An identifier for simulation events.
Definition: event-id.h:54
ns3::Packet::AddHeader
void AddHeader(const Header &header)
Add header to this packet.
Definition: packet.cc:256
ns3
Every class exported by the ns3 library is enclosed in the ns3 namespace.
ns3::ServiceFlow::GetCid
uint16_t GetCid(void) const
Get CID.
Definition: service-flow.cc:325
ns3::Cid::TRANSPORT
@ TRANSPORT
Definition: cid.h:47
ns3::ManagementMessageType
Mac Management messages Section 6.3.2.3 MAC Management messages page 42, Table 14 page 43.
Definition: mac-messages.h:44
ns3::ServiceFlowManager::GetNextServiceFlowToAllocate
ServiceFlow * GetNextServiceFlowToAllocate()
Definition: service-flow-manager.cc:173
ns3::SsServiceFlowManager::SetMaxDsaReqRetries
void SetMaxDsaReqRetries(uint8_t maxDsaReqRetries)
sets the maximum retries on DSA request message
Definition: ss-service-flow-manager.cc:81
ns3::ManagementMessageType::MESSAGE_TYPE_DSA_REQ
@ MESSAGE_TYPE_DSA_REQ
Definition: mac-messages.h:57
ns3::MacHeaderType
This class Represents the HT (Header Type) field of generic MAC and bandwidth request headers.
Definition: wimax-mac-header.h:37
ns3::SsServiceFlowManager::m_pendingServiceFlow
ServiceFlow * m_pendingServiceFlow
pending service flow
Definition: ss-service-flow-manager.h:145
ns3::ServiceFlowManager
The same service flow manager class serves both for BS and SS though some functions are exclusive to ...
Definition: service-flow-manager.h:43
ns3::Simulator::Schedule
static EventId Schedule(Time const &delay, FUNC f, Ts &&... args)
Schedule an event to expire after delay.
Definition: simulator.h:557
ns3::TypeId::SetParent
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:923
ns3::SsServiceFlowManager::m_maxDsaReqRetries
uint8_t m_maxDsaReqRetries
maximum DSA request retries
Definition: ss-service-flow-manager.h:132
ns3::DsaReq::SetServiceFlow
void SetServiceFlow(ServiceFlow sf)
specify a service flow to be requested by this message
Definition: mac-messages.cc:634
ns3::Ptr
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:74
ns3::DsaReq
This class implements the DSA-REQ message described by "IEEE Standard for Local and metropolitan area...
Definition: mac-messages.h:374
ns3::SsServiceFlowManager::ProcessDsaRsp
void ProcessDsaRsp(const DsaRsp &dsaRsp)
Process DSA response.
Definition: ss-service-flow-manager.cc:198
ns3::EventId::IsRunning
bool IsRunning(void) const
This method is syntactic sugar for !IsExpired().
Definition: event-id.cc:71
ns3::DsaAck
This class implements the DSA-ACK message described by "IEEE Standard for Local and metropolitan area...
Definition: mac-messages.h:573
ns3::ServiceFlow::SetUnsolicitedPollingInterval
void SetUnsolicitedPollingInterval(uint16_t unsolicitedPollingInterval)
Set unsolicited polling interval.
Definition: service-flow.cc:620
ns3::SsServiceFlowManager::GetDsaAckTimeoutEvent
EventId GetDsaAckTimeoutEvent(void) const
Get DSA ack timeout event.
Definition: ss-service-flow-manager.cc:99
ns3::ServiceFlow::SetConnection
void SetConnection(Ptr< WimaxConnection > connection)
Set connection.
Definition: service-flow.cc:215
ns3::Simulator::Cancel
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
ns3::DsaAck::SetConfirmationCode
void SetConfirmationCode(uint16_t confirmationCode)
Set confirmation code field.
Definition: mac-messages.cc:802
ns3::SsServiceFlowManager::m_dsaReq
DsaReq m_dsaReq
DSA request.
Definition: ss-service-flow-manager.h:137
connection-manager.h
ns3::ServiceFlow::CopyParametersFrom
void CopyParametersFrom(ServiceFlow sf)
Copy parameters from another service flow.
Definition: service-flow.cc:672
ns3::DsaRsp
This class implements the DSA-RSP message described by "IEEE Standard for Local and metropolitan ar...
Definition: mac-messages.h:475
ns3::SsServiceFlowManager::~SsServiceFlowManager
~SsServiceFlowManager(void)
Definition: ss-service-flow-manager.cc:58
ns3::SsServiceFlowManager::m_transactionIdIndex
uint16_t m_transactionIdIndex
transaction ID index
Definition: ss-service-flow-manager.h:141
ns3::ManagementMessageType::MESSAGE_TYPE_DSA_ACK
@ MESSAGE_TYPE_DSA_ACK
Definition: mac-messages.h:59
wimax-connection.h
ns3::SsServiceFlowManager::SsServiceFlowManager
SsServiceFlowManager(Ptr< SubscriberStationNetDevice > device)
Constructor.
Definition: ss-service-flow-manager.cc:46
ns3::SsServiceFlowManager::ScheduleDsaReq
void ScheduleDsaReq(const ServiceFlow *serviceFlow)
Schedule DSA response.
Definition: ss-service-flow-manager.cc:156
NS_ASSERT_MSG
#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
ns3::SsServiceFlowManager::GetDsaRspTimeoutEvent
EventId GetDsaRspTimeoutEvent(void) const
Get DSA response timeout event.
Definition: ss-service-flow-manager.cc:93
service-flow.h
ns3::SsServiceFlowManager::InitiateServiceFlows
void InitiateServiceFlows(void)
Initiate service flows.
Definition: ss-service-flow-manager.cc:120
ns3::SubscriberStationNetDevice
SubscriberStationNetDevice subclass of WimaxNetDevice.
Definition: ss-net-device.h:49
wimax-net-device.h
ns3::SsServiceFlowManager::m_dsaRspTimeoutEvent
EventId m_dsaRspTimeoutEvent
DSA response timeout event.
Definition: ss-service-flow-manager.h:134
ns3::ServiceFlowManager::DoDispose
void DoDispose(void)
Destructor implementation.
Definition: service-flow-manager.cc:67
ns3::DsaAck::SetTransactionId
void SetTransactionId(uint16_t transactionId)
Set transaction ID field.
Definition: mac-messages.cc:790
ns3::SsServiceFlowManager::AddServiceFlow
void AddServiceFlow(ServiceFlow *serviceFlow)
add a service flow to the list
Definition: ss-service-flow-manager.cc:113
ss-record.h
NS_LOG_DEBUG
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
Definition: log.h:273
ns3::SsServiceFlowManager::CreateDsaAck
Ptr< Packet > CreateDsaAck(void)
Create DSA ack.
Definition: ss-service-flow-manager.cc:143
ns3::SsServiceFlowManager::m_currentTransactionId
uint16_t m_currentTransactionId
current transaction ID
Definition: ss-service-flow-manager.h:140
ns3::SsServiceFlowManager::CreateDsaReq
DsaReq CreateDsaReq(const ServiceFlow *serviceFlow)
Create DSA request.
Definition: ss-service-flow-manager.cc:129
ns3::SsServiceFlowManager::m_dsaAckTimeoutEvent
EventId m_dsaAckTimeoutEvent
DSA ack timeout event.
Definition: ss-service-flow-manager.h:135
ns3::ServiceFlow::SetIsEnabled
void SetIsEnabled(bool isEnabled)
Set is enabled flag.
Definition: service-flow.cc:228
ns3::ServiceFlowManager::AddServiceFlow
void AddServiceFlow(ServiceFlow *serviceFlow)
Add service flow function.
Definition: service-flow-manager.cc:78
ss-scheduler.h
ns3::ServiceFlow
This class implements service flows as described by the IEEE-802.16 standard.
Definition: service-flow.h:40
ss-manager.h
service-flow-record.h
ns3::SsServiceFlowManager::CONFIRMATION_CODE_SUCCESS
@ CONFIRMATION_CODE_SUCCESS
Definition: ss-service-flow-manager.h:49
ns3::SsServiceFlowManager::DoDispose
void DoDispose(void)
Destructor implementation.
Definition: ss-service-flow-manager.cc:75
service-flow-manager.h
ns3::SsServiceFlowManager::m_device
Ptr< SubscriberStationNetDevice > m_device
the device
Definition: ss-service-flow-manager.h:130
ns3::SsServiceFlowManager::m_dsaReqRetries
uint8_t m_dsaReqRetries
DSA request retries.
Definition: ss-service-flow-manager.h:142
ns3::SsServiceFlowManager::m_dsaAck
DsaAck m_dsaAck
DSA ack.
Definition: ss-service-flow-manager.h:138
bs-net-device.h
ns3::DsaReq::SetTransactionId
void SetTransactionId(uint16_t transactionId)
set the transaction ID
Definition: mac-messages.cc:534
ns3::SsServiceFlowManager::GetTypeId
static TypeId GetTypeId(void)
Register this type.
Definition: ss-service-flow-manager.cc:64
ns3::SsServiceFlowManager::GetMaxDsaReqRetries
uint8_t GetMaxDsaReqRetries(void) const
Definition: ss-service-flow-manager.cc:87