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 
34 namespace ns3 {
35 
36 NS_LOG_COMPONENT_DEFINE ("ConnectionManager");
37 
38 NS_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 
53 void
55 {
56 }
57 
59 {
60 }
61 
62 void
64 {
65  m_cidFactory = cidFactory;
66 }
67 
68 void
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 
104 void
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 
159 std::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 
183 uint32_t
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 
228 bool
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 
ns3::ConnectionManager::m_cidFactory
CidFactory * m_cidFactory
the factory
Definition: connection-manager.h:105
ns3::ConnectionManager::GetTypeId
static TypeId GetTypeId(void)
Get the type ID.
Definition: connection-manager.cc:40
ns3::TypeId
a unique identifier for an interface.
Definition: type-id.h:59
NS_LOG_COMPONENT_DEFINE
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:205
NS_OBJECT_ENSURE_REGISTERED
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition: object-base.h:45
ns3::Cid
Cid class.
Definition: cid.h:38
ns3::ConnectionManager::~ConnectionManager
~ConnectionManager(void)
Definition: connection-manager.cc:58
ns3::ConnectionManager::SetCidFactory
void SetCidFactory(CidFactory *cidFactory)
Set CID factory.
Definition: connection-manager.cc:63
ss-net-device.h
ns3::CidFactory::Allocate
Cid Allocate(enum Cid::Type type)
This function returns the next CID for the specified type.
Definition: cid-factory.cc:74
ns3
Every class exported by the ns3 library is enclosed in the ns3 namespace.
ns3::ConnectionManager::GetConnections
std::vector< Ptr< WimaxConnection > > GetConnections(Cid::Type type) const
Definition: connection-manager.cc:160
ns3::Cid::PRIMARY
@ PRIMARY
Definition: cid.h:46
ns3::Cid::TRANSPORT
@ TRANSPORT
Definition: cid.h:47
ns3::RngRsp::SetPrimaryCid
void SetPrimaryCid(Cid primaryCid)
set primary CID.
Definition: mac-messages.cc:312
cid-factory.h
ns3::ConnectionManager::AllocateManagementConnections
void AllocateManagementConnections(SSRecord *ssRecord, RngRsp *rngrsp)
allocates the management connection for an ss record.
Definition: connection-manager.cc:69
ns3::RngRsp::SetBasicCid
void SetBasicCid(Cid basicCid)
set basic CID.
Definition: mac-messages.cc:306
ns3::ConnectionManager::AddConnection
void AddConnection(Ptr< WimaxConnection > connection, Cid::Type type)
add a connection to the list of managed connections
Definition: connection-manager.cc:105
ns3::ConnectionManager::ConnectionManager
ConnectionManager(void)
Definition: connection-manager.cc:48
ns3::TypeId::SetParent
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:923
ns3::Cid::Type
Type
Type enumeration.
Definition: cid.h:42
ns3::ConnectionManager::CreateConnection
Ptr< WimaxConnection > CreateConnection(Cid::Type type)
create a connection of type type
Definition: connection-manager.cc:82
ns3::Ptr
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:74
NS_FATAL_ERROR
#define NS_FATAL_ERROR(msg)
Report a fatal error with a message and terminate.
Definition: fatal-error.h:165
ns3::ConnectionManager::DoDispose
void DoDispose(void)
Destructor implementation.
Definition: connection-manager.cc:54
ns3::Object
A base class which provides memory management and object aggregation.
Definition: object.h:88
mac-messages.h
ns3::SSRecord
This class is used by the base station to store some information related to subscriber station in the...
Definition: ss-record.h:44
ns3::ConnectionManager::m_basicConnections
std::vector< Ptr< WimaxConnection > > m_basicConnections
basic connections
Definition: connection-manager.h:100
ns3::ConnectionManager::HasPackets
bool HasPackets(void) const
Definition: connection-manager.cc:229
connection-manager.h
ns3::Cid::BASIC
@ BASIC
Definition: cid.h:45
ns3::Cid::MULTICAST
@ MULTICAST
Definition: cid.h:48
ns3::ConnectionManager::m_multicastConnections
std::vector< Ptr< WimaxConnection > > m_multicastConnections
multicast connections
Definition: connection-manager.h:103
service-flow.h
ns3::CidFactory::AllocateTransportOrSecondary
Cid AllocateTransportOrSecondary(void)
This function returns the next Transport (or Secondary) CID.
Definition: cid-factory.cc:57
ns3::ConnectionManager::GetConnection
Ptr< WimaxConnection > GetConnection(Cid cid)
Definition: connection-manager.cc:128
ns3::ConnectionManager::m_primaryConnections
std::vector< Ptr< WimaxConnection > > m_primaryConnections
primary connections
Definition: connection-manager.h:101
ss-record.h
ns3::SSRecord::SetBasicCid
void SetBasicCid(Cid basicCid)
Set basic CID.
Definition: ss-record.cc:86
ns3::CidFactory
This class is used exclusively by the BS to allocate CIDs to new connections.
Definition: cid-factory.h:46
ns3::ServiceFlow::SchedulingType
SchedulingType
section 11.13.11 Service flow scheduling type, page 701
Definition: service-flow.h:59
ns3::ServiceFlow::SF_TYPE_ALL
@ SF_TYPE_ALL
Definition: service-flow.h:66
ns3::SSRecord::SetPrimaryCid
void SetPrimaryCid(Cid primaryCid)
Set primary CID.
Definition: ss-record.cc:98
ns3::RngRsp
This class implements the ranging response message described by "IEEE Standard for Local and metropol...
Definition: mac-messages.h:122
ns3::ConnectionManager::GetNPackets
uint32_t GetNPackets(Cid::Type type, ServiceFlow::SchedulingType schedulingType) const
get number of packets
Definition: connection-manager.cc:184
bs-net-device.h
ns3::ConnectionManager::m_transportConnections
std::vector< Ptr< WimaxConnection > > m_transportConnections
transport connections
Definition: connection-manager.h:102