A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
ss-scheduler.cc
Go to the documentation of this file.
1/*
2 * Copyright (c) 2007,2008 INRIA
3 *
4 * SPDX-License-Identifier: GPL-2.0-only
5 *
6 * Author: Jahanzeb Farooq <jahanzeb.farooq@sophia.inria.fr>
7 */
8
9#include "ss-scheduler.h"
10
11#include "connection-manager.h"
13#include "service-flow-record.h"
14#include "service-flow.h"
15#include "ss-net-device.h"
16#include "wimax-connection.h"
17#include "wimax-mac-queue.h"
18#include "wimax-phy.h"
19
20#include "ns3/log.h"
21#include "ns3/node.h"
22#include "ns3/simulator.h"
23
24namespace ns3
25{
26
27NS_LOG_COMPONENT_DEFINE("SSScheduler");
28
30
31TypeId
33{
34 static TypeId tid = TypeId("ns3::SSScheduler").SetParent<Object>().SetGroupName("Wimax");
35 return tid;
36}
37
39 : m_ss(ss),
40 m_pollMe(false)
41{
42}
43
47
48void
50{
51 m_ss = nullptr;
52}
53
54void
56{
57 m_pollMe = pollMe;
58}
59
60bool
62{
63 return m_pollMe;
64}
65
67SSScheduler::Schedule(uint16_t availableSymbols,
68 WimaxPhy::ModulationType modulationType,
70 Ptr<WimaxConnection>& connection)
71{
72 Time timeStamp;
74 uint16_t nrSymbolsRequired = 0;
75
76 if (!connection)
77 {
78 connection = SelectConnection();
79 }
80 else
81 {
82 NS_ASSERT_MSG(connection->HasPackets(),
83 "SS: Error while scheduling packets: The selected connection has no packets");
84 }
85
86 Ptr<Packet> packet;
87
88 while (connection && connection->HasPackets(packetType))
89 {
90 NS_LOG_INFO("FRAG_DEBUG: SS Scheduler" << std::endl);
91
92 uint32_t availableByte = m_ss->GetPhy()->GetNrBytes(availableSymbols, modulationType);
93
94 uint32_t requiredByte = connection->GetQueue()->GetFirstPacketRequiredByte(packetType);
95
96 NS_LOG_INFO("\t availableByte = " << availableByte << ", requiredByte = " << requiredByte);
97
98 if (availableByte >= requiredByte)
99 {
100 // The SS could sent a packet without a other fragmentation
101 NS_LOG_INFO("\t availableByte >= requiredByte"
102 "\n\t Send packet without other fragmentation"
103 << std::endl);
104
105 packet = connection->Dequeue(packetType);
106 burst->AddPacket(packet);
107
108 nrSymbolsRequired = m_ss->GetPhy()->GetNrSymbols(packet->GetSize(), modulationType);
109 availableSymbols -= nrSymbolsRequired;
110 }
111 else
112 {
113 if (connection->GetType() == Cid::TRANSPORT)
114 {
115 NS_LOG_INFO("\t availableByte < requiredByte"
116 "\n\t Check if the fragmentation is possible");
117
118 uint32_t headerSize = connection->GetQueue()->GetFirstPacketHdrSize(packetType);
119 if (!connection->GetQueue()->CheckForFragmentation(packetType))
120 {
121 NS_LOG_INFO("\t Add fragmentSubhdrSize = 2");
122 headerSize += 2;
123 }
124 NS_LOG_INFO("\t availableByte = " << availableByte
125 << " headerSize = " << headerSize);
126
127 if (availableByte > headerSize)
128 {
129 NS_LOG_INFO("\t Fragmentation IS possible");
130 packet = connection->Dequeue(packetType, availableByte);
131 burst->AddPacket(packet);
132
133 nrSymbolsRequired =
134 m_ss->GetPhy()->GetNrSymbols(packet->GetSize(), modulationType);
135 availableSymbols -= nrSymbolsRequired;
136 }
137 else
138 {
139 NS_LOG_INFO("\t Fragmentation IS NOT possible" << std::endl);
140 break;
141 }
142 }
143 else
144 {
145 NS_LOG_INFO("\t no Transport Connection "
146 "\n\t Fragmentation IS NOT possible, "
147 << std::endl);
148 break;
149 }
150 }
151 }
152 return burst;
153}
154
157{
158 Time currentTime = Simulator::Now();
159
160 NS_LOG_INFO("SS Scheduler: Selecting connection...");
161 if (m_ss->GetInitialRangingConnection()->HasPackets())
162 {
163 NS_LOG_INFO("Return GetInitialRangingConnection");
164 return m_ss->GetInitialRangingConnection();
165 }
166 if (m_ss->GetBasicConnection()->HasPackets())
167 {
168 NS_LOG_INFO("Return GetBasicConnection");
169 return m_ss->GetBasicConnection();
170 }
171 if (m_ss->GetPrimaryConnection()->HasPackets())
172 {
173 NS_LOG_INFO("Return GetPrimaryConnection");
174 return m_ss->GetPrimaryConnection();
175 }
176
177 auto serviceFlows = m_ss->GetServiceFlowManager()->GetServiceFlows(ServiceFlow::SF_TYPE_UGS);
178 for (auto iter = serviceFlows.begin(); iter != serviceFlows.end(); ++iter)
179 {
180 // making sure that this grant was actually intended for this UGS
181
182 if ((*iter)->HasPackets() && (currentTime + m_ss->GetPhy()->GetFrameDuration() >
183 MilliSeconds((*iter)->GetUnsolicitedGrantInterval())))
184 {
185 NS_LOG_INFO("Return UGS SF: CID = " << (*iter)->GetCid()
186 << "SFID = " << (*iter)->GetSfid());
187 return (*iter)->GetConnection();
188 }
189 }
190
191 /* In the following cases (rtPS, nrtPS and BE flows) connection is seletected only for data
192 packets, for bandwidth request packets connection will itself be passed to Schedule () and
193 hence this function will never be called. */
194
195 serviceFlows = m_ss->GetServiceFlowManager()->GetServiceFlows(ServiceFlow::SF_TYPE_RTPS);
196 for (auto iter = serviceFlows.begin(); iter != serviceFlows.end(); ++iter)
197 {
198 if ((*iter)->HasPackets(MacHeaderType::HEADER_TYPE_GENERIC) &&
199 (currentTime + m_ss->GetPhy()->GetFrameDuration() >
200 MilliSeconds((*iter)->GetUnsolicitedPollingInterval())))
201 {
202 NS_LOG_INFO("Return RTPS SF: CID = " << (*iter)->GetCid()
203 << "SFID = " << (*iter)->GetSfid());
204 return (*iter)->GetConnection();
205 }
206 }
207
208 serviceFlows = m_ss->GetServiceFlowManager()->GetServiceFlows(ServiceFlow::SF_TYPE_NRTPS);
209 for (auto iter = serviceFlows.begin(); iter != serviceFlows.end(); ++iter)
210 {
211 if ((*iter)->HasPackets(MacHeaderType::HEADER_TYPE_GENERIC))
212 {
213 NS_LOG_INFO("Return NRTPS SF: CID = " << (*iter)->GetCid()
214 << "SFID = " << (*iter)->GetSfid());
215 return (*iter)->GetConnection();
216 }
217 }
218
219 serviceFlows = m_ss->GetServiceFlowManager()->GetServiceFlows(ServiceFlow::SF_TYPE_BE);
220 for (auto iter = serviceFlows.begin(); iter != serviceFlows.end(); ++iter)
221 {
222 if ((*iter)->HasPackets(MacHeaderType::HEADER_TYPE_GENERIC))
223 {
224 NS_LOG_INFO("Return BE SF: CID = " << (*iter)->GetCid()
225 << "SFID = " << (*iter)->GetSfid());
226 return (*iter)->GetConnection();
227 }
228 }
229
230 if (m_ss->GetBroadcastConnection()->HasPackets())
231 {
232 return m_ss->GetBroadcastConnection();
233 }
234 NS_LOG_INFO("NO connection is selected!");
235 return nullptr;
236}
237
238} // namespace ns3
@ TRANSPORT
Definition cid.h:35
HeaderType
Header type enumeration.
A base class which provides memory management and object aggregation.
Definition object.h:78
Smart pointer class similar to boost::intrusive_ptr.
SSScheduler(Ptr< SubscriberStationNetDevice > ss)
Constructor.
bool m_pollMe
poll me flag
void DoDispose() override
Destructor implementation.
Ptr< PacketBurst > Schedule(uint16_t availableSymbols, WimaxPhy::ModulationType modulationType, MacHeaderType::HeaderType packetType, Ptr< WimaxConnection > &connection)
static TypeId GetTypeId()
Get the type ID.
Ptr< SubscriberStationNetDevice > m_ss
the subscriber station
void SetPollMe(bool pollMe)
Set poll me value.
Ptr< WimaxConnection > SelectConnection()
Select connection.
bool GetPollMe() const
Get the poll me value.
~SSScheduler() override
static Time Now()
Return the current simulation virtual time.
Definition simulator.cc:197
Simulation virtual time values and global simulation resolution.
Definition nstime.h:94
a unique identifier for an interface.
Definition type-id.h:48
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition type-id.cc:1001
ModulationType
ModulationType enumeration.
Definition wimax-phy.h:43
#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:75
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition log.h:191
#define NS_LOG_INFO(msg)
Use NS_LOG to output a message of level LOG_INFO.
Definition log.h:264
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition object-base.h:35
Ptr< T > Create(Ts &&... args)
Create class instances by constructors with varying numbers of arguments and return them by Ptr.
Definition ptr.h:436
Time MilliSeconds(uint64_t value)
Construct a Time in the indicated unit.
Definition nstime.h:1320
Every class exported by the ns3 library is enclosed in the ns3 namespace.