A Discrete-Event Network Simulator
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
connection-manager.cc
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 NS_LOG_COMPONENT_DEFINE ("ConnectionManager");
35 
36 namespace ns3 {
37 
38 NS_OBJECT_ENSURE_REGISTERED (ConnectionManager);
39 
40 TypeId ConnectionManager::GetTypeId (void)
41 {
42  static TypeId tid = TypeId ("ns3::ConnectionManager")
43  .SetParent<Object> ();
44  return tid;
45 }
46 
47 ConnectionManager::ConnectionManager (void)
48  : m_cidFactory (0)
49 {
50 }
51 
52 void
54 {
55 }
56 
57 ConnectionManager::~ConnectionManager (void)
58 {
59 }
60 
61 void
62 ConnectionManager::SetCidFactory (CidFactory *cidFactory)
63 {
64  m_cidFactory = cidFactory;
65 }
66 
67 void
69 {
70  Ptr<WimaxConnection> basicConnection = CreateConnection (Cid::BASIC);
71  ssRecord->SetBasicCid (basicConnection->GetCid ());
72 
73  Ptr<WimaxConnection> primaryConnection = CreateConnection (Cid::PRIMARY);
74  ssRecord->SetPrimaryCid (primaryConnection->GetCid ());
75 
76  rngrsp->SetBasicCid (basicConnection->GetCid ());
77  rngrsp->SetPrimaryCid (primaryConnection->GetCid ());
78 }
79 
82 {
83  Cid cid;
84  switch (type)
85  {
86  case Cid::BASIC:
87  case Cid::MULTICAST:
88  case Cid::PRIMARY:
89  cid = m_cidFactory->Allocate (type);
90  break;
91  case Cid::TRANSPORT:
92  cid = m_cidFactory->AllocateTransportOrSecondary ();
93  break;
94  default:
95  NS_FATAL_ERROR ("Invalid connection type");
96  break;
97  }
98  Ptr<WimaxConnection> connection = CreateObject<WimaxConnection> (cid, type);
99  AddConnection (connection, type);
100  return connection;
101 }
102 
103 void
105 {
106  switch (type)
107  {
108  case Cid::BASIC:
109  m_basicConnections.push_back (connection);
110  break;
111  case Cid::PRIMARY:
112  m_primaryConnections.push_back (connection);
113  break;
114  case Cid::TRANSPORT:
115  m_transportConnections.push_back (connection);
116  break;
117  case Cid::MULTICAST:
118  m_multicastConnections.push_back (connection);
119  break;
120  default:
121  NS_FATAL_ERROR ("Invalid connection type");
122  break;
123  }
124 }
125 
128 {
129  std::vector<Ptr<WimaxConnection> >::const_iterator iter;
130 
131  for (iter = m_basicConnections.begin (); iter != m_basicConnections.end (); ++iter)
132  {
133  if ((*iter)->GetCid () == cid)
134  {
135  return *iter;
136  }
137  }
138 
139  for (iter = m_primaryConnections.begin (); iter != m_primaryConnections.end (); ++iter)
140  {
141  if ((*iter)->GetCid () == cid)
142  {
143  return *iter;
144  }
145  }
146 
147  for (iter = m_transportConnections.begin (); iter != m_transportConnections.end (); ++iter)
148  {
149  if ((*iter)->GetCid () == cid)
150  {
151  return *iter;
152  }
153  }
154 
155  return 0;
156 }
157 
158 std::vector<Ptr<WimaxConnection> >
159 ConnectionManager::GetConnections (Cid::Type type) const
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 
182 uint32_t
183 ConnectionManager::GetNPackets (Cid::Type type, ServiceFlow::SchedulingType schedulingType) const
184 {
185  uint32_t nrPackets = 0;
186 
187  switch (type)
188  {
189  case Cid::BASIC:
190  {
191  for (std::vector<Ptr<WimaxConnection> >::const_iterator iter = m_basicConnections.begin (); iter
192  != m_basicConnections.end (); ++iter)
193  {
194  nrPackets += (*iter)->GetQueue ()->GetSize ();
195  }
196  break;
197  }
198  case Cid::PRIMARY:
199  {
200  for (std::vector<Ptr<WimaxConnection> >::const_iterator iter = m_primaryConnections.begin (); iter
201  != m_primaryConnections.end (); ++iter)
202  {
203  nrPackets += (*iter)->GetQueue ()->GetSize ();
204  }
205  break;
206  }
207  case Cid::TRANSPORT:
208  {
209  for (std::vector<Ptr<WimaxConnection> >::const_iterator iter = m_transportConnections.begin (); iter
210  != m_transportConnections.end (); ++iter)
211  {
212  if (schedulingType == ServiceFlow::SF_TYPE_ALL || (*iter)->GetSchedulingType () == schedulingType)
213  {
214  nrPackets += (*iter)->GetQueue ()->GetSize ();
215  }
216  }
217  break;
218  }
219  default:
220  NS_FATAL_ERROR ("Invalid connection type");
221  break;
222  }
223 
224  return nrPackets;
225 }
226 
227 bool
229 {
230  std::vector<Ptr<WimaxConnection> >::const_iterator iter;
231  for (iter = m_basicConnections.begin (); iter != m_basicConnections.end (); ++iter)
232  {
233  if ((*iter)->HasPackets ())
234  {
235  return true;
236  }
237  }
238 
239  for (iter = m_primaryConnections.begin (); iter != m_primaryConnections.end (); ++iter)
240  {
241  if ((*iter)->HasPackets ())
242  {
243  return true;
244  }
245  }
246 
247  for (iter = m_transportConnections.begin (); iter != m_transportConnections.end (); ++iter)
248  {
249  if ((*iter)->HasPackets ())
250  {
251  return true;
252  }
253  }
254 
255  return false;
256 }
257 } // namespace ns3
258 
259 
Ptr< WimaxConnection > GetConnection(Cid cid)
smart pointer class similar to boost::intrusive_ptr
Definition: ptr.h:59
#define NS_LOG_COMPONENT_DEFINE(name)
Definition: log.h:122
#define NS_FATAL_ERROR(msg)
fatal error handling
Definition: fatal-error.h:72
void AddConnection(Ptr< WimaxConnection > connection, Cid::Type type)
add a connection to the list of managed connections
Definition: cid.h:35
bool HasPackets(void) const
void AllocateManagementConnections(SSRecord *ssRecord, RngRsp *rngrsp)
allocates the management connection for an ss record. This method is only used by BS ...
Ptr< WimaxConnection > CreateConnection(Cid::Type type)
create a connection of type type
std::vector< Ptr< WimaxConnection > > GetConnections(Cid::Type type) const
This class is used by the base station to store some information related to subscriber station in the...
Definition: ss-record.h:43
Cid AllocateTransportOrSecondary(void)
This function returns the next Transport (or Secondary) CID.
Definition: cid-factory.cc:57