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 std::vector<Ptr<WimaxConnection>>::const_iterator iter;
132
133 for (iter = m_basicConnections.begin(); iter != m_basicConnections.end(); ++iter)
134 {
135 if ((*iter)->GetCid() == cid)
136 {
137 return *iter;
138 }
139 }
140
141 for (iter = m_primaryConnections.begin(); iter != m_primaryConnections.end(); ++iter)
142 {
143 if ((*iter)->GetCid() == cid)
144 {
145 return *iter;
146 }
147 }
148
149 for (iter = m_transportConnections.begin(); iter != m_transportConnections.end(); ++iter)
150 {
151 if ((*iter)->GetCid() == cid)
152 {
153 return *iter;
154 }
155 }
156
157 return nullptr;
158}
159
160std::vector<Ptr<WimaxConnection>>
162{
163 std::vector<Ptr<WimaxConnection>> connections;
164
165 switch (type)
166 {
167 case Cid::BASIC:
168 connections = m_basicConnections;
169 break;
170 case Cid::PRIMARY:
171 connections = m_primaryConnections;
172 break;
173 case Cid::TRANSPORT:
174 connections = m_transportConnections;
175 break;
176 default:
177 NS_FATAL_ERROR("Invalid connection type");
178 break;
179 }
180
181 return connections;
182}
183
186{
187 uint32_t nrPackets = 0;
188
189 switch (type)
190 {
191 case Cid::BASIC: {
192 for (std::vector<Ptr<WimaxConnection>>::const_iterator iter = m_basicConnections.begin();
193 iter != m_basicConnections.end();
194 ++iter)
195 {
196 nrPackets += (*iter)->GetQueue()->GetSize();
197 }
198 break;
199 }
200 case Cid::PRIMARY: {
201 for (std::vector<Ptr<WimaxConnection>>::const_iterator iter = m_primaryConnections.begin();
202 iter != m_primaryConnections.end();
203 ++iter)
204 {
205 nrPackets += (*iter)->GetQueue()->GetSize();
206 }
207 break;
208 }
209 case Cid::TRANSPORT: {
210 for (std::vector<Ptr<WimaxConnection>>::const_iterator iter =
212 iter != m_transportConnections.end();
213 ++iter)
214 {
215 if (schedulingType == ServiceFlow::SF_TYPE_ALL ||
216 (*iter)->GetSchedulingType() == schedulingType)
217 {
218 nrPackets += (*iter)->GetQueue()->GetSize();
219 }
220 }
221 break;
222 }
223 default:
224 NS_FATAL_ERROR("Invalid connection type");
225 break;
226 }
227
228 return nrPackets;
229}
230
231bool
233{
234 std::vector<Ptr<WimaxConnection>>::const_iterator iter;
235 for (iter = m_basicConnections.begin(); iter != m_basicConnections.end(); ++iter)
236 {
237 if ((*iter)->HasPackets())
238 {
239 return true;
240 }
241 }
242
243 for (iter = m_primaryConnections.begin(); iter != m_primaryConnections.end(); ++iter)
244 {
245 if ((*iter)->HasPackets())
246 {
247 return true;
248 }
249 }
250
251 for (iter = m_transportConnections.begin(); iter != m_transportConnections.end(); ++iter)
252 {
253 if ((*iter)->HasPackets())
254 {
255 return true;
256 }
257 }
258
259 return false;
260}
261} // 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:78
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:936
#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.