A Discrete-Event Network Simulator
Home
Tutorials ▼
English
Portuguese
Docs ▼
Wiki
Manual
Models
Develop ▼
API
Bugs
API
Main Page
Related Pages
Modules
Namespaces
Classes
Files
File List
File Members
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Properties
Friends
Macros
Groups
Pages
ss-scheduler.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 INRIA
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
* Author: Jahanzeb Farooq <jahanzeb.farooq@sophia.inria.fr>
19
*/
20
21
#include "ns3/simulator.h"
22
#include "ns3/node.h"
23
#include "ns3/log.h"
24
#include "
ss-scheduler.h
"
25
#include "
ss-net-device.h
"
26
#include "
wimax-phy.h
"
27
#include "
wimax-mac-queue.h
"
28
#include "
wimax-connection.h
"
29
#include "
connection-manager.h
"
30
#include "
service-flow.h
"
31
#include "
service-flow-record.h
"
32
#include "
service-flow-manager.h
"
33
34
NS_LOG_COMPONENT_DEFINE
(
"SSScheduler"
);
35
36
namespace
ns3 {
37
NS_OBJECT_ENSURE_REGISTERED
(SSScheduler);
38
39
TypeId
SSScheduler::GetTypeId
(
void
)
40
{
41
static
TypeId
tid =
TypeId
(
"ns3::SSScheduler"
)
42
.
SetParent
<
Object
> ();
43
return
tid;
44
}
45
46
SSScheduler::SSScheduler
(
Ptr<SubscriberStationNetDevice>
ss)
47
: m_ss (ss),
48
m_pollMe (false)
49
{
50
}
51
52
SSScheduler::~SSScheduler
(
void
)
53
{
54
}
55
56
void
57
SSScheduler::DoDispose
(
void
)
58
{
59
m_ss
= 0;
60
}
61
62
void
63
SSScheduler::SetPollMe
(
bool
pollMe)
64
{
65
m_pollMe
= pollMe;
66
}
67
68
bool
69
SSScheduler::GetPollMe
(
void
)
const
70
{
71
return
m_pollMe
;
72
}
73
74
Ptr<PacketBurst>
75
SSScheduler::Schedule
(uint16_t availableSymbols,
76
WimaxPhy::ModulationType
modulationType,
77
MacHeaderType::HeaderType
packetType,
78
Ptr<WimaxConnection>
&connection)
79
{
80
Time
timeStamp;
81
Ptr<PacketBurst>
burst = Create<PacketBurst> ();
82
uint16_t nrSymbolsRequired = 0;
83
84
if
(!connection)
85
{
86
connection =
SelectConnection
();
87
}
88
else
89
{
90
NS_ASSERT_MSG
(connection->
HasPackets
(),
91
"SS: Error while scheduling packets: The selected connection has no packets"
);
92
}
93
94
Ptr<Packet>
packet;
95
96
while
(connection && connection->
HasPackets
(packetType))
97
{
98
NS_LOG_INFO
(
"FRAG_DEBUG: SS Scheduler"
<< std::endl);
99
100
uint32_t availableByte =
m_ss
->
GetPhy
()->
101
GetNrBytes (availableSymbols, modulationType);
102
103
uint32_t requiredByte = connection->
GetQueue
()->
GetFirstPacketRequiredByte
(packetType);
104
105
NS_LOG_INFO
(
"\t availableByte = "
<< availableByte <<
106
", requiredByte = "
<< requiredByte);
107
108
if
(availableByte >= requiredByte)
109
{
110
// The SS could sent a packet without a other fragmentation
111
NS_LOG_INFO
(
"\t availableByte >= requiredByte"
112
"\n\t Send packet without other fragmentation"
<< std::endl);
113
114
packet = connection->
Dequeue
(packetType);
115
burst->
AddPacket
(packet);
116
117
nrSymbolsRequired =
m_ss
->
GetPhy
()->
118
GetNrSymbols (packet->
GetSize
(), modulationType);
119
availableSymbols -= nrSymbolsRequired;
120
}
121
else
122
{
123
if
(connection->
GetType
() ==
Cid::TRANSPORT
)
124
{
125
NS_LOG_INFO
(
"\t availableByte < requiredByte"
126
"\n\t Check if the fragmentation is possible"
);
127
128
uint32_t headerSize = connection->
GetQueue
()->
GetFirstPacketHdrSize
(packetType);
129
if
(!connection->
GetQueue
()->
CheckForFragmentation
(packetType))
130
{
131
NS_LOG_INFO
(
"\t Add fragmentSubhdrSize = 2"
);
132
headerSize += 2;
133
}
134
NS_LOG_INFO
(
"\t availableByte = "
<< availableByte <<
135
" headerSize = "
<< headerSize);
136
137
if
(availableByte > headerSize)
138
{
139
NS_LOG_INFO
(
"\t Fragmentation IS possible"
);
140
packet = connection->
Dequeue
(packetType, availableByte);
141
burst->
AddPacket
(packet);
142
143
nrSymbolsRequired =
m_ss
->
GetPhy
()->
144
GetNrSymbols (packet->
GetSize
(), modulationType);
145
availableSymbols -= nrSymbolsRequired;
146
}
147
else
148
{
149
NS_LOG_INFO
(
"\t Fragmentation IS NOT possible"
<< std::endl);
150
break
;
151
}
152
}
153
else
154
{
155
NS_LOG_INFO
(
"\t no Transport Connection "
156
"\n\t Fragmentation IS NOT possible, "
<< std::endl);
157
break
;
158
}
159
}
160
}
161
return
burst;
162
}
163
164
Ptr<WimaxConnection>
165
SSScheduler::SelectConnection
(
void
)
166
{
167
Time
currentTime =
Simulator::Now
();
168
std::vector<ServiceFlow*>::const_iterator iter;
169
std::vector<ServiceFlow*> serviceFlows;
170
171
NS_LOG_INFO
(
"SS Scheduler: Selecting connection..."
);
172
if
(
m_ss
->
GetInitialRangingConnection
()->
HasPackets
())
173
{
174
NS_LOG_INFO
(
"Return GetInitialRangingConnection"
);
175
return
m_ss
->
GetInitialRangingConnection
();
176
}
177
if
(
m_ss
->
GetBasicConnection
()->
HasPackets
())
178
{
179
NS_LOG_INFO
(
"Return GetBasicConnection"
);
180
return
m_ss
->
GetBasicConnection
();
181
}
182
if
(
m_ss
->
GetPrimaryConnection
()->
HasPackets
())
183
{
184
NS_LOG_INFO
(
"Return GetPrimaryConnection"
);
185
return
m_ss
->
GetPrimaryConnection
();
186
}
187
188
serviceFlows =
m_ss
->
GetServiceFlowManager
()->
GetServiceFlows
(
ServiceFlow::SF_TYPE_UGS
);
189
for
(iter = serviceFlows.begin (); iter != serviceFlows.end (); ++iter)
190
{
191
// making sure that this grant was actually intended for this UGS
192
193
if
((*iter)->HasPackets () && (currentTime
194
+
m_ss
->
GetPhy
()->
GetFrameDuration
() >
MilliSeconds
(
195
(*iter)->GetUnsolicitedGrantInterval ())))
196
{
197
NS_LOG_INFO
(
"Return UGS SF: CID = "
<< (*iter)->GetCid () <<
"SFID = "
198
<< (*iter)->GetSfid ());
199
return
(*iter)->GetConnection ();
200
}
201
}
202
203
/* In the following cases (rtPS, nrtPS and BE flows) connection is seletected only for data packets, for bandwidth
204
request packets connection will itself be passed to Schedule () and hence this function will never be called. */
205
206
serviceFlows =
m_ss
->
GetServiceFlowManager
()->
GetServiceFlows
(
ServiceFlow::SF_TYPE_RTPS
);
207
for
(iter = serviceFlows.begin (); iter != serviceFlows.end (); ++iter)
208
{
209
if
((*iter)->HasPackets (
MacHeaderType::HEADER_TYPE_GENERIC
)
210
&& (currentTime +
m_ss
->
GetPhy
()->
GetFrameDuration
()
211
>
MilliSeconds
(
212
(*iter)->GetUnsolicitedPollingInterval ())))
213
{
214
NS_LOG_INFO
(
"Return RTPS SF: CID = "
<< (*iter)->GetCid () <<
"SFID = "
215
<< (*iter)->GetSfid ());
216
return
(*iter)->GetConnection ();
217
}
218
}
219
220
serviceFlows =
m_ss
->
GetServiceFlowManager
()->
GetServiceFlows
(
ServiceFlow::SF_TYPE_NRTPS
);
221
for
(iter = serviceFlows.begin (); iter != serviceFlows.end (); ++iter)
222
{
223
if
((*iter)->HasPackets (
MacHeaderType::HEADER_TYPE_GENERIC
))
224
{
225
NS_LOG_INFO
(
"Return NRTPS SF: CID = "
<< (*iter)->GetCid () <<
"SFID = "
226
<< (*iter)->GetSfid ());
227
return
(*iter)->GetConnection ();
228
}
229
}
230
231
serviceFlows =
m_ss
->
GetServiceFlowManager
()->
GetServiceFlows
(
ServiceFlow::SF_TYPE_BE
);
232
for
(iter = serviceFlows.begin (); iter != serviceFlows.end (); ++iter)
233
{
234
if
((*iter)->HasPackets (
MacHeaderType::HEADER_TYPE_GENERIC
))
235
{
236
NS_LOG_INFO
(
"Return BE SF: CID = "
<< (*iter)->GetCid () <<
"SFID = "
237
<< (*iter)->GetSfid ());
238
return
(*iter)->GetConnection ();
239
}
240
}
241
242
if
(
m_ss
->
GetBroadcastConnection
()->
HasPackets
())
243
{
244
return
m_ss
->
GetBroadcastConnection
();
245
}
246
NS_LOG_INFO
(
"NO connection is selected!"
);
247
return
0;
248
}
249
250
}
// namespace ns3
src
wimax
model
ss-scheduler.cc
Generated on Tue May 14 2013 11:08:38 for ns-3 by
1.8.1.2