A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
connection-manager.cc
Go to the documentation of this file.
1/*
2 * Copyright (c) 2007,2008,2009 INRIA, UDcast
3 *
4 * SPDX-License-Identifier: GPL-2.0-only
5 *
6 * Authors: Jahanzeb Farooq <jahanzeb.farooq@sophia.inria.fr>
7 * Mohamed Amine Ismail <amine.ismail@sophia.inria.fr>
8 * <amine.ismail@UDcast.com>
9 */
10
11#include "connection-manager.h"
12
13#include "bs-net-device.h"
14#include "cid-factory.h"
15#include "mac-messages.h"
16#include "service-flow.h"
17#include "ss-net-device.h"
18#include "ss-record.h"
19
20#include "ns3/enum.h"
21#include "ns3/log.h"
22#include "ns3/pointer.h"
23
24namespace ns3
25{
26
27NS_LOG_COMPONENT_DEFINE("ConnectionManager");
28
29NS_OBJECT_ENSURE_REGISTERED(ConnectionManager);
30
31TypeId
33{
34 static TypeId tid = TypeId("ns3::ConnectionManager").SetParent<Object>().SetGroupName("Wimax");
35 return tid;
36}
37
39 : m_cidFactory(nullptr)
40{
41}
42
43void
47
51
52void
54{
55 m_cidFactory = cidFactory;
56}
57
58void
60{
62 ssRecord->SetBasicCid(basicConnection->GetCid());
63
65 ssRecord->SetPrimaryCid(primaryConnection->GetCid());
66
67 rngrsp->SetBasicCid(basicConnection->GetCid());
68 rngrsp->SetPrimaryCid(primaryConnection->GetCid());
69}
70
73{
74 Cid cid;
75 switch (type)
76 {
77 case Cid::BASIC:
78 case Cid::MULTICAST:
79 case Cid::PRIMARY:
80 cid = m_cidFactory->Allocate(type);
81 break;
82 case Cid::TRANSPORT:
84 break;
85 default:
86 NS_FATAL_ERROR("Invalid connection type");
87 break;
88 }
90 AddConnection(connection, type);
91 return connection;
92}
93
94void
96{
97 switch (type)
98 {
99 case Cid::BASIC:
100 m_basicConnections.push_back(connection);
101 break;
102 case Cid::PRIMARY:
103 m_primaryConnections.push_back(connection);
104 break;
105 case Cid::TRANSPORT:
106 m_transportConnections.push_back(connection);
107 break;
108 case Cid::MULTICAST:
109 m_multicastConnections.push_back(connection);
110 break;
111 default:
112 NS_FATAL_ERROR("Invalid connection type");
113 break;
114 }
115}
116
119{
120 for (auto iter = m_basicConnections.begin(); iter != m_basicConnections.end(); ++iter)
121 {
122 if ((*iter)->GetCid() == cid)
123 {
124 return *iter;
125 }
126 }
127
128 for (auto iter = m_primaryConnections.begin(); iter != m_primaryConnections.end(); ++iter)
129 {
130 if ((*iter)->GetCid() == cid)
131 {
132 return *iter;
133 }
134 }
135
136 for (auto iter = m_transportConnections.begin(); iter != m_transportConnections.end(); ++iter)
137 {
138 if ((*iter)->GetCid() == cid)
139 {
140 return *iter;
141 }
142 }
143
144 return nullptr;
145}
146
147std::vector<Ptr<WimaxConnection>>
149{
150 std::vector<Ptr<WimaxConnection>> connections;
151
152 switch (type)
153 {
154 case Cid::BASIC:
155 connections = m_basicConnections;
156 break;
157 case Cid::PRIMARY:
158 connections = m_primaryConnections;
159 break;
160 case Cid::TRANSPORT:
161 connections = m_transportConnections;
162 break;
163 default:
164 NS_FATAL_ERROR("Invalid connection type");
165 break;
166 }
167
168 return connections;
169}
170
173{
174 uint32_t nrPackets = 0;
175
176 switch (type)
177 {
178 case Cid::BASIC: {
179 for (auto iter = m_basicConnections.begin(); iter != m_basicConnections.end(); ++iter)
180 {
181 nrPackets += (*iter)->GetQueue()->GetSize();
182 }
183 break;
184 }
185 case Cid::PRIMARY: {
186 for (auto iter = m_primaryConnections.begin(); iter != m_primaryConnections.end(); ++iter)
187 {
188 nrPackets += (*iter)->GetQueue()->GetSize();
189 }
190 break;
191 }
192 case Cid::TRANSPORT: {
193 for (auto iter = m_transportConnections.begin(); iter != m_transportConnections.end();
194 ++iter)
195 {
196 if (schedulingType == ServiceFlow::SF_TYPE_ALL ||
197 (*iter)->GetSchedulingType() == schedulingType)
198 {
199 nrPackets += (*iter)->GetQueue()->GetSize();
200 }
201 }
202 break;
203 }
204 default:
205 NS_FATAL_ERROR("Invalid connection type");
206 break;
207 }
208
209 return nrPackets;
210}
211
212bool
214{
215 for (auto iter = m_basicConnections.begin(); iter != m_basicConnections.end(); ++iter)
216 {
217 if ((*iter)->HasPackets())
218 {
219 return true;
220 }
221 }
222
223 for (auto iter = m_primaryConnections.begin(); iter != m_primaryConnections.end(); ++iter)
224 {
225 if ((*iter)->HasPackets())
226 {
227 return true;
228 }
229 }
230
231 for (auto iter = m_transportConnections.begin(); iter != m_transportConnections.end(); ++iter)
232 {
233 if ((*iter)->HasPackets())
234 {
235 return true;
236 }
237 }
238
239 return false;
240}
241} // namespace ns3
This class is used exclusively by the BS to allocate CIDs to new connections.
Definition cid-factory.h:35
Cid Allocate(Cid::Type type)
This function returns the next CID for the specified type.
Cid AllocateTransportOrSecondary()
This function returns the next Transport (or Secondary) CID.
Cid class.
Definition cid.h:26
Type
Type enumeration.
Definition cid.h:30
@ PRIMARY
Definition cid.h:34
@ TRANSPORT
Definition cid.h:35
@ MULTICAST
Definition cid.h:36
@ BASIC
Definition cid.h:33
std::vector< Ptr< WimaxConnection > > m_primaryConnections
primary connections
std::vector< Ptr< WimaxConnection > > m_basicConnections
basic connections
void DoDispose() override
Destructor implementation.
void AllocateManagementConnections(SSRecord *ssRecord, RngRsp *rngrsp)
allocates the management connection for an ss record.
std::vector< Ptr< WimaxConnection > > m_transportConnections
transport connections
Ptr< WimaxConnection > GetConnection(Cid cid)
Ptr< WimaxConnection > CreateConnection(Cid::Type type)
create a connection of type type
std::vector< Ptr< WimaxConnection > > GetConnections(Cid::Type type) const
uint32_t GetNPackets(Cid::Type type, ServiceFlow::SchedulingType schedulingType) const
get number of packets
void SetCidFactory(CidFactory *cidFactory)
Set CID factory.
static TypeId GetTypeId()
Get the type ID.
void AddConnection(Ptr< WimaxConnection > connection, Cid::Type type)
add a connection to the list of managed connections
CidFactory * m_cidFactory
the factory
std::vector< Ptr< WimaxConnection > > m_multicastConnections
multicast connections
A base class which provides memory management and object aggregation.
Definition object.h:78
Smart pointer class similar to boost::intrusive_ptr.
This class implements the ranging response message described by "IEEE Standard forLocal and metropoli...
void SetBasicCid(Cid basicCid)
set basic CID.
void SetPrimaryCid(Cid primaryCid)
set primary CID.
This class is used by the base station to store some information related to subscriber station in the...
Definition ss-record.h:35
void SetPrimaryCid(Cid primaryCid)
Set primary CID.
Definition ss-record.cc:90
void SetBasicCid(Cid basicCid)
Set basic CID.
Definition ss-record.cc:78
SchedulingType
section 11.13.11 Service flow scheduling type, page 701
a unique identifier for an interface.
Definition type-id.h:48
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition type-id.cc:1001
#define NS_FATAL_ERROR(msg)
Report a fatal error with a message and terminate.
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition log.h:191
Ptr< T > CreateObject(Args &&... args)
Create an object by type, with varying number of constructor parameters.
Definition object.h:619
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition object-base.h:35
Every class exported by the ns3 library is enclosed in the ns3 namespace.