A Discrete-Event Network Simulator
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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 NS_LOG_COMPONENT_DEFINE ("SsServiceFlowManager");
42 
43 namespace ns3 {
44 
46  : m_device (device),
47  m_maxDsaReqRetries (100),
48  m_dsaReq (DsaReq ()),
49  m_dsaAck (DsaAck ()),
50  m_currentTransactionId (0),
51  m_transactionIdIndex (1),
52  m_dsaReqRetries (0),
53  m_pendingServiceFlow (0)
54 {
55 }
56 
58 {
59 }
60 
61 void
63 {
65 }
66 
67 void
69 {
70  m_maxDsaReqRetries = maxDsaReqRetries;
71 }
72 
73 uint8_t
75 {
76  return m_maxDsaReqRetries;
77 }
78 
79 EventId
81 {
82  return m_dsaRspTimeoutEvent;
83 }
84 
85 EventId
87 {
88  return m_dsaAckTimeoutEvent;
89 }
90 
91 void
93 {
94  ServiceFlow * sf = new ServiceFlow ();
95  sf->CopyParametersFrom (serviceFlow);
97 }
98 
99 void
101 {
103 }
104 
105 
106 void
108 {
109  ServiceFlow *serviceFlow = GetNextServiceFlowToAllocate ();
110  NS_ASSERT_MSG (serviceFlow != 0,"Error while initiating a new service flow: All service flows have been initiated");
111  m_pendingServiceFlow = serviceFlow;
113 }
114 
115 DsaReq
117 {
118  DsaReq dsaReq;
121 
122  /*as it is SS-initiated DSA therefore SFID and CID will
123  not be included, see 6.3.2.3.10.1 and 6.3.2.3.11.1*/
124  dsaReq.SetServiceFlow (*serviceFlow);
125  // dsaReq.SetParameterSet (*serviceFlow->GetParameterSet ());
126  return dsaReq;
127 }
128 
131 {
132  DsaAck dsaAck;
135  m_dsaAck = dsaAck;
136  Ptr<Packet> p = Create<Packet> ();
137  p->AddHeader (dsaAck);
139  return p;
140 }
141 
142 void
144 {
145  Ptr<Packet> p = Create<Packet> ();
146  DsaReq dsaReq;
148 
149  if (m_dsaReqRetries == 0)
150  {
151  dsaReq = CreateDsaReq (serviceFlow);
152  p->AddHeader (dsaReq);
153  m_dsaReq = dsaReq;
154  }
155  else
156  {
158  {
159  p->AddHeader (m_dsaReq);
160  }
161  else
162  {
163  NS_LOG_DEBUG ("Service flows could not be initialized!");
164  }
165  }
166 
167  m_dsaReqRetries++;
169 
171  {
173  }
174 
175  m_dsaRspTimeoutEvent = Simulator::Schedule (ss->GetIntervalT7 (),
177  this,
178  serviceFlow);
179 
180  m_device->Enqueue (p, MacHeaderType (), ss->GetPrimaryConnection ());
181 }
182 
183 
184 void
186 {
187 
189 
190  // already received DSA-RSP for that particular DSA-REQ
191  if (dsaRsp.GetTransactionId () != m_currentTransactionId)
192  {
193  return;
194  }
195 
196  Ptr<Packet> dsaAck = CreateDsaAck ();
197  m_device->Enqueue (dsaAck, MacHeaderType (), ss->GetPrimaryConnection ());
198 
199  m_dsaReqRetries = 0;
200  if (m_pendingServiceFlow == NULL)
201  {
202  // May be the DSA-ACK was not received by the SS
203  return;
204  }
205  ServiceFlow sf = dsaRsp.GetServiceFlow ();
206  (*m_pendingServiceFlow) = sf;
209  Ptr<WimaxConnection> transportConnection = CreateObject<WimaxConnection> (sf.GetCid (),
211 
212  m_pendingServiceFlow->SetConnection (transportConnection);
213  transportConnection->SetServiceFlow (m_pendingServiceFlow);
214  ss->GetConnectionManager ()->AddConnection (transportConnection,
218  // check if all service flow have been initiated
219  ServiceFlow * serviceFlow = GetNextServiceFlowToAllocate ();
220  if (serviceFlow == 0)
221  {
222  ss->SetAreServiceFlowsAllocated (true);
223  }
224  else
225  {
226  m_pendingServiceFlow = serviceFlow;
228  }
229 }
230 
231 } // namespace ns3
NS_LOG_COMPONENT_DEFINE("SsServiceFlowManager")
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
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)
Doxygen introspection did not find any typical Config paths.
Definition: mac-messages.h:41
ServiceFlow GetServiceFlow(void) const
Ptr< SubscriberStationNetDevice > m_device
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: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 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)
This method is called by Object::Dispose or by the object's destructor, whichever comes first...
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)
Definition: assert.h:86
void SetIsEnabled(bool isEnabled)
void SetTransactionId(uint16_t transactionId)
an identifier for simulation events.
Definition: event-id.h:46
void AddServiceFlow(ServiceFlow *serviceFlow)
uint16_t GetTransactionId(void) const
#define NS_LOG_DEBUG(msg)
Definition: log.h:289
uint16_t GetTransactionId(void) const
void DoDispose(void)
This method is called by Object::Dispose or by the object's destructor, whichever comes first...
void ProcessDsaRsp(const DsaRsp &dsaRsp)
Doxygen 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)