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 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation;
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, write to the Free Software
15 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 *
17 * Authors: Jahanzeb Farooq <jahanzeb.farooq@sophia.inria.fr>
18 * Mohamed Amine Ismail <amine.ismail@sophia.inria.fr>
19 * <amine.ismail@UDcast.com>
20 */
21
22#include "connection-manager.h"
23
24#include "bs-net-device.h"
25#include "cid-factory.h"
26#include "mac-messages.h"
27#include "service-flow.h"
28#include "ss-net-device.h"
29#include "ss-record.h"
30
31#include "ns3/enum.h"
32#include "ns3/log.h"
33#include "ns3/pointer.h"
34
35namespace ns3
36{
37
38NS_LOG_COMPONENT_DEFINE("ConnectionManager");
39
40NS_OBJECT_ENSURE_REGISTERED(ConnectionManager);
41
42TypeId
44{
45 static TypeId tid = TypeId("ns3::ConnectionManager").SetParent<Object>().SetGroupName("Wimax");
46 return tid;
47}
48
50 : m_cidFactory(nullptr)
51{
52}
53
54void
56{
57}
58
60{
61}
62
63void
65{
66 m_cidFactory = cidFactory;
67}
68
69void
71{
73 ssRecord->SetBasicCid(basicConnection->GetCid());
74
76 ssRecord->SetPrimaryCid(primaryConnection->GetCid());
77
78 rngrsp->SetBasicCid(basicConnection->GetCid());
79 rngrsp->SetPrimaryCid(primaryConnection->GetCid());
80}
81
84{
85 Cid cid;
86 switch (type)
87 {
88 case Cid::BASIC:
89 case Cid::MULTICAST:
90 case Cid::PRIMARY:
91 cid = m_cidFactory->Allocate(type);
92 break;
93 case Cid::TRANSPORT:
95 break;
96 default:
97 NS_FATAL_ERROR("Invalid connection type");
98 break;
99 }
100 Ptr<WimaxConnection> connection = CreateObject<WimaxConnection>(cid, type);
101 AddConnection(connection, type);
102 return connection;
103}
104
105void
107{
108 switch (type)
109 {
110 case Cid::BASIC:
111 m_basicConnections.push_back(connection);
112 break;
113 case Cid::PRIMARY:
114 m_primaryConnections.push_back(connection);
115 break;
116 case Cid::TRANSPORT:
117 m_transportConnections.push_back(connection);
118 break;
119 case Cid::MULTICAST:
120 m_multicastConnections.push_back(connection);
121 break;
122 default:
123 NS_FATAL_ERROR("Invalid connection type");
124 break;
125 }
126}
127
130{
131 for (auto iter = m_basicConnections.begin(); iter != m_basicConnections.end(); ++iter)
132 {
133 if ((*iter)->GetCid() == cid)
134 {
135 return *iter;
136 }
137 }
138
139 for (auto iter = m_primaryConnections.begin(); iter != m_primaryConnections.end(); ++iter)
140 {
141 if ((*iter)->GetCid() == cid)
142 {
143 return *iter;
144 }
145 }
146
147 for (auto iter = m_transportConnections.begin(); iter != m_transportConnections.end(); ++iter)
148 {
149 if ((*iter)->GetCid() == cid)
150 {
151 return *iter;
152 }
153 }
154
155 return nullptr;
156}
157
158std::vector<Ptr<WimaxConnection>>
160{
161 std::vector<Ptr<WimaxConnection>> connections;
162
163 switch (type)
164 {
165 case Cid::BASIC:
166 connections = m_basicConnections;
167 break;
168 case Cid::PRIMARY:
169 connections = m_primaryConnections;
170 break;
171 case Cid::TRANSPORT:
172 connections = m_transportConnections;
173 break;
174 default:
175 NS_FATAL_ERROR("Invalid connection type");
176 break;
177 }
178
179 return connections;
180}
181
184{
185 uint32_t nrPackets = 0;
186
187 switch (type)
188 {
189 case Cid::BASIC: {
190 for (auto iter = m_basicConnections.begin(); iter != m_basicConnections.end(); ++iter)
191 {
192 nrPackets += (*iter)->GetQueue()->GetSize();
193 }
194 break;
195 }
196 case Cid::PRIMARY: {
197 for (auto iter = m_primaryConnections.begin(); iter != m_primaryConnections.end(); ++iter)
198 {
199 nrPackets += (*iter)->GetQueue()->GetSize();
200 }
201 break;
202 }
203 case Cid::TRANSPORT: {
204 for (auto iter = m_transportConnections.begin(); iter != m_transportConnections.end();
205 ++iter)
206 {
207 if (schedulingType == ServiceFlow::SF_TYPE_ALL ||
208 (*iter)->GetSchedulingType() == schedulingType)
209 {
210 nrPackets += (*iter)->GetQueue()->GetSize();
211 }
212 }
213 break;
214 }
215 default:
216 NS_FATAL_ERROR("Invalid connection type");
217 break;
218 }
219
220 return nrPackets;
221}
222
223bool
225{
226 for (auto iter = m_basicConnections.begin(); iter != m_basicConnections.end(); ++iter)
227 {
228 if ((*iter)->HasPackets())
229 {
230 return true;
231 }
232 }
233
234 for (auto iter = m_primaryConnections.begin(); iter != m_primaryConnections.end(); ++iter)
235 {
236 if ((*iter)->HasPackets())
237 {
238 return true;
239 }
240 }
241
242 for (auto iter = m_transportConnections.begin(); iter != m_transportConnections.end(); ++iter)
243 {
244 if ((*iter)->HasPackets())
245 {
246 return true;
247 }
248 }
249
250 return false;
251}
252} // namespace ns3
This class is used exclusively by the BS to allocate CIDs to new connections.
Definition: cid-factory.h:46
Cid Allocate(Cid::Type type)
This function returns the next CID for the specified type.
Definition: cid-factory.cc:74
Cid AllocateTransportOrSecondary()
This function returns the next Transport (or Secondary) CID.
Definition: cid-factory.cc:58
Cid class.
Definition: cid.h:37
Type
Type enumeration.
Definition: cid.h:41
@ PRIMARY
Definition: cid.h:45
@ TRANSPORT
Definition: cid.h:46
@ MULTICAST
Definition: cid.h:47
@ BASIC
Definition: cid.h:44
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:89
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:77
This class implements the ranging response message described by "IEEE Standard for Local and metropol...
Definition: mac-messages.h:125
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:46
void SetPrimaryCid(Cid primaryCid)
Set primary CID.
Definition: ss-record.cc:101
void SetBasicCid(Cid basicCid)
Set basic CID.
Definition: ss-record.cc:89
SchedulingType
section 11.13.11 Service flow scheduling type, page 701
Definition: service-flow.h:62
a unique identifier for an interface.
Definition: type-id.h:59
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:932
#define NS_FATAL_ERROR(msg)
Report a fatal error with a message and terminate.
Definition: fatal-error.h:179
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:202
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition: object-base.h:46
Every class exported by the ns3 library is enclosed in the ns3 namespace.