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 void
64 {
66 }
67 
68 void
70 {
71  m_maxDsaReqRetries = maxDsaReqRetries;
72 }
73 
74 uint8_t
76 {
77  return m_maxDsaReqRetries;
78 }
79 
80 EventId
82 {
83  return m_dsaRspTimeoutEvent;
84 }
85 
86 EventId
88 {
89  return m_dsaAckTimeoutEvent;
90 }
91 
92 void
94 {
95  ServiceFlow * sf = new ServiceFlow ();
96  sf->CopyParametersFrom (serviceFlow);
98 }
99 
100 void
102 {
104 }
105 
106 
107 void
109 {
110  ServiceFlow *serviceFlow = GetNextServiceFlowToAllocate ();
111  NS_ASSERT_MSG (serviceFlow != 0,"Error while initiating a new service flow: All service flows have been initiated");
112  m_pendingServiceFlow = serviceFlow;
114 }
115 
116 DsaReq
118 {
119  DsaReq dsaReq;
122 
123  /*as it is SS-initiated DSA therefore SFID and CID will
124  not be included, see 6.3.2.3.10.1 and 6.3.2.3.11.1*/
125  dsaReq.SetServiceFlow (*serviceFlow);
126  // dsaReq.SetParameterSet (*serviceFlow->GetParameterSet ());
127  return dsaReq;
128 }
129 
132 {
133  DsaAck dsaAck;
136  m_dsaAck = dsaAck;
137  Ptr<Packet> p = Create<Packet> ();
138  p->AddHeader (dsaAck);
140  return p;
141 }
142 
143 void
145 {
146  Ptr<Packet> p = Create<Packet> ();
147  DsaReq dsaReq;
149 
150  if (m_dsaReqRetries == 0)
151  {
152  dsaReq = CreateDsaReq (serviceFlow);
153  p->AddHeader (dsaReq);
154  m_dsaReq = dsaReq;
155  }
156  else
157  {
159  {
160  p->AddHeader (m_dsaReq);
161  }
162  else
163  {
164  NS_LOG_DEBUG ("Service flows could not be initialized!");
165  }
166  }
167 
168  m_dsaReqRetries++;
170 
172  {
174  }
175 
176  m_dsaRspTimeoutEvent = Simulator::Schedule (ss->GetIntervalT7 (),
178  this,
179  serviceFlow);
180 
181  m_device->Enqueue (p, MacHeaderType (), ss->GetPrimaryConnection ());
182 }
183 
184 
185 void
187 {
188 
190 
191  // already received DSA-RSP for that particular DSA-REQ
192  if (dsaRsp.GetTransactionId () != m_currentTransactionId)
193  {
194  return;
195  }
196 
197  Ptr<Packet> dsaAck = CreateDsaAck ();
198  m_device->Enqueue (dsaAck, MacHeaderType (), ss->GetPrimaryConnection ());
199 
200  m_dsaReqRetries = 0;
201  if (m_pendingServiceFlow == NULL)
202  {
203  // May be the DSA-ACK was not received by the SS
204  return;
205  }
206  ServiceFlow sf = dsaRsp.GetServiceFlow ();
207  (*m_pendingServiceFlow) = sf;
210  Ptr<WimaxConnection> transportConnection = CreateObject<WimaxConnection> (sf.GetCid (),
212 
213  m_pendingServiceFlow->SetConnection (transportConnection);
214  transportConnection->SetServiceFlow (m_pendingServiceFlow);
215  ss->GetConnectionManager ()->AddConnection (transportConnection,
219  // check if all service flow have been initiated
220  ServiceFlow * serviceFlow = GetNextServiceFlowToAllocate ();
221  if (serviceFlow == 0)
222  {
223  ss->SetAreServiceFlowsAllocated (true);
224  }
225  else
226  {
227  m_pendingServiceFlow = serviceFlow;
229  }
230 }
231 
232 } // 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
EventId GetDsaRspTimeoutEvent(void) const
void SetServiceFlow(ServiceFlow sf)
specify a service flow to be requested by this message
EventId GetDsaAckTimeoutEvent(void) const
void SetConnection(Ptr< WimaxConnection > connection)
Introspection did not find any typical Config paths.
Definition: mac-messages.h:41
ServiceFlow GetServiceFlow(void) const
Ptr< SubscriberStationNetDevice > m_device
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:201
ServiceFlow * GetNextServiceFlowToAllocate()
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 AddServiceFlow(ServiceFlow *serviceFlow)
add a service flow to the list
void SetMaxDsaReqRetries(uint8_t maxDsaReqRetries)
sets the maximum retries on DSA request message
void SetUnsolicitedPollingInterval(uint16_t)
void CopyParametersFrom(ServiceFlow sf)
void SetUnsolicitedGrantInterval(uint16_t)
SsServiceFlowManager(Ptr< SubscriberStationNetDevice > device)
creates a service flow manager and attaches it to a device
Represents the HT (Header Type) field of generic MAC and bandwidth request headers.
void DoDispose(void)
Destructor implementation.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
This class implements service flows as described by the IEEE-802.16 standard.
Definition: service-flow.h:39
uint8_t GetMaxDsaReqRetries(void) const
DsaReq CreateDsaReq(const ServiceFlow *serviceFlow)
void SetTransactionId(uint16_t transactionId)
#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 SetIsEnabled(bool isEnabled)
void SetTransactionId(uint16_t transactionId)
An identifier for simulation events.
Definition: event-id.h:53
void AddServiceFlow(ServiceFlow *serviceFlow)
uint16_t GetTransactionId(void) const
#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 DoDispose(void)
Destructor implementation.
void ProcessDsaRsp(const DsaRsp &dsaRsp)
Introspection did not find any typical Config paths.
Definition: mac-messages.h:262
void AddHeader(const Header &header)
Add header to this packet.
Definition: packet.cc:253
void SetConfirmationCode(uint16_t confirmationCode)
uint16_t GetCid(void) const
void ScheduleDsaReq(const ServiceFlow *serviceFlow)