A Discrete-Event Network Simulator
API
connection-manager.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,2009 INRIA, UDcast
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 * Authors: Jahanzeb Farooq <jahanzeb.farooq@sophia.inria.fr>
19 * Mohamed Amine Ismail <amine.ismail@sophia.inria.fr>
20 * <amine.ismail@UDcast.com>
21 */
22
23#include "connection-manager.h"
24#include "ns3/log.h"
25#include "cid-factory.h"
26#include "ss-record.h"
27#include "mac-messages.h"
28#include "ns3/pointer.h"
29#include "ns3/enum.h"
30#include "service-flow.h"
31#include "ss-net-device.h"
32#include "bs-net-device.h"
33
34namespace ns3 {
35
36NS_LOG_COMPONENT_DEFINE ("ConnectionManager");
37
38NS_OBJECT_ENSURE_REGISTERED (ConnectionManager);
39
41{
42 static TypeId tid = TypeId ("ns3::ConnectionManager")
43 .SetParent<Object> ()
44 .SetGroupName("Wimax");
45 return tid;
46}
47
49 : m_cidFactory (0)
50{
51}
52
53void
55{
56}
57
59{
60}
61
62void
64{
65 m_cidFactory = cidFactory;
66}
67
68void
70{
72 ssRecord->SetBasicCid (basicConnection->GetCid ());
73
75 ssRecord->SetPrimaryCid (primaryConnection->GetCid ());
76
77 rngrsp->SetBasicCid (basicConnection->GetCid ());
78 rngrsp->SetPrimaryCid (primaryConnection->GetCid ());
79}
80
83{
84 Cid cid;
85 switch (type)
86 {
87 case Cid::BASIC:
88 case Cid::MULTICAST:
89 case Cid::PRIMARY:
90 cid = m_cidFactory->Allocate (type);
91 break;
92 case Cid::TRANSPORT:
94 break;
95 default:
96 NS_FATAL_ERROR ("Invalid connection type");
97 break;
98 }
99 Ptr<WimaxConnection> connection = CreateObject<WimaxConnection> (cid, type);
100 AddConnection (connection, type);
101 return connection;
102}
103
104void
106{
107 switch (type)
108 {
109 case Cid::BASIC:
110 m_basicConnections.push_back (connection);
111 break;
112 case Cid::PRIMARY:
113 m_primaryConnections.push_back (connection);
114 break;
115 case Cid::TRANSPORT:
116 m_transportConnections.push_back (connection);
117 break;
118 case Cid::MULTICAST:
119 m_multicastConnections.push_back (connection);
120 break;
121 default:
122 NS_FATAL_ERROR ("Invalid connection type");
123 break;
124 }
125}
126
129{
130 std::vector<Ptr<WimaxConnection> >::const_iterator iter;
131
132 for (iter = m_basicConnections.begin (); iter != m_basicConnections.end (); ++iter)
133 {
134 if ((*iter)->GetCid () == cid)
135 {
136 return *iter;
137 }
138 }
139
140 for (iter = m_primaryConnections.begin (); iter != m_primaryConnections.end (); ++iter)
141 {
142 if ((*iter)->GetCid () == cid)
143 {
144 return *iter;
145 }
146 }
147
148 for (iter = m_transportConnections.begin (); iter != m_transportConnections.end (); ++iter)
149 {
150 if ((*iter)->GetCid () == cid)
151 {
152 return *iter;
153 }
154 }
155
156 return 0;
157}
158
159std::vector<Ptr<WimaxConnection> >
161{
162 std::vector<Ptr<WimaxConnection> > connections;
163
164 switch (type)
165 {
166 case Cid::BASIC:
167 connections = m_basicConnections;
168 break;
169 case Cid::PRIMARY:
170 connections = m_primaryConnections;
171 break;
172 case Cid::TRANSPORT:
173 connections = m_transportConnections;
174 break;
175 default:
176 NS_FATAL_ERROR ("Invalid connection type");
177 break;
178 }
179
180 return connections;
181}
182
185{
186 uint32_t nrPackets = 0;
187
188 switch (type)
189 {
190 case Cid::BASIC:
191 {
192 for (std::vector<Ptr<WimaxConnection> >::const_iterator iter = m_basicConnections.begin (); iter
193 != m_basicConnections.end (); ++iter)
194 {
195 nrPackets += (*iter)->GetQueue ()->GetSize ();
196 }
197 break;
198 }
199 case Cid::PRIMARY:
200 {
201 for (std::vector<Ptr<WimaxConnection> >::const_iterator iter = m_primaryConnections.begin (); iter
202 != m_primaryConnections.end (); ++iter)
203 {
204 nrPackets += (*iter)->GetQueue ()->GetSize ();
205 }
206 break;
207 }
208 case Cid::TRANSPORT:
209 {
210 for (std::vector<Ptr<WimaxConnection> >::const_iterator iter = m_transportConnections.begin (); iter
211 != m_transportConnections.end (); ++iter)
212 {
213 if (schedulingType == ServiceFlow::SF_TYPE_ALL || (*iter)->GetSchedulingType () == schedulingType)
214 {
215 nrPackets += (*iter)->GetQueue ()->GetSize ();
216 }
217 }
218 break;
219 }
220 default:
221 NS_FATAL_ERROR ("Invalid connection type");
222 break;
223 }
224
225 return nrPackets;
226}
227
228bool
230{
231 std::vector<Ptr<WimaxConnection> >::const_iterator iter;
232 for (iter = m_basicConnections.begin (); iter != m_basicConnections.end (); ++iter)
233 {
234 if ((*iter)->HasPackets ())
235 {
236 return true;
237 }
238 }
239
240 for (iter = m_primaryConnections.begin (); iter != m_primaryConnections.end (); ++iter)
241 {
242 if ((*iter)->HasPackets ())
243 {
244 return true;
245 }
246 }
247
248 for (iter = m_transportConnections.begin (); iter != m_transportConnections.end (); ++iter)
249 {
250 if ((*iter)->HasPackets ())
251 {
252 return true;
253 }
254 }
255
256 return false;
257}
258} // namespace ns3
259
260
This class is used exclusively by the BS to allocate CIDs to new connections.
Definition: cid-factory.h:46
Cid Allocate(enum Cid::Type type)
This function returns the next CID for the specified type.
Definition: cid-factory.cc:74
Cid AllocateTransportOrSecondary(void)
This function returns the next Transport (or Secondary) CID.
Definition: cid-factory.cc:57
Cid class.
Definition: cid.h:38
Type
Type enumeration.
Definition: cid.h:42
@ PRIMARY
Definition: cid.h:46
@ TRANSPORT
Definition: cid.h:47
@ MULTICAST
Definition: cid.h:48
@ BASIC
Definition: cid.h:45
std::vector< Ptr< WimaxConnection > > m_primaryConnections
primary connections
std::vector< Ptr< WimaxConnection > > m_basicConnections
basic connections
void DoDispose(void)
Destructor implementation.
void AllocateManagementConnections(SSRecord *ssRecord, RngRsp *rngrsp)
allocates the management connection for an ss record.
static TypeId GetTypeId(void)
Get the type ID.
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.
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:88
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:74
This class implements the ranging response message described by "IEEE Standard for Local and metropol...
Definition: mac-messages.h:122
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:44
void SetPrimaryCid(Cid primaryCid)
Set primary CID.
Definition: ss-record.cc:98
void SetBasicCid(Cid basicCid)
Set basic CID.
Definition: ss-record.cc:86
SchedulingType
section 11.13.11 Service flow scheduling type, page 701
Definition: service-flow.h:59
a unique identifier for an interface.
Definition: type-id.h:59
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:922
#define NS_FATAL_ERROR(msg)
Report a fatal error with a message and terminate.
Definition: fatal-error.h:165
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:205
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition: object-base.h:45
Every class exported by the ns3 library is enclosed in the ns3 namespace.