A Discrete-Event Network Simulator
API
ss-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 "ss-manager.h"
23 
24 #include "service-flow.h"
25 
26 #include "ns3/log.h"
27 
28 #include <stdint.h>
29 
30 namespace ns3
31 {
32 
33 NS_LOG_COMPONENT_DEFINE("SSManager");
34 
36 
37 TypeId
39 {
40  static TypeId tid = TypeId("ns3::SSManager").SetParent<Object>().SetGroupName("Wimax");
41  return tid;
42 }
43 
45 {
46  m_ssRecords = new std::vector<SSRecord*>();
47 }
48 
50 {
51  for (std::vector<SSRecord*>::iterator iter = m_ssRecords->begin(); iter != m_ssRecords->end();
52  ++iter)
53  {
54  delete *iter;
55  }
56  delete m_ssRecords;
57  m_ssRecords = nullptr;
58 }
59 
60 SSRecord*
62 {
63  SSRecord* ssRecord = new SSRecord(macAddress);
64  m_ssRecords->push_back(ssRecord);
65  return ssRecord;
66 }
67 
68 SSRecord*
69 SSManager::GetSSRecord(const Mac48Address& macAddress) const
70 {
71  for (std::vector<SSRecord*>::iterator iter = m_ssRecords->begin(); iter != m_ssRecords->end();
72  ++iter)
73  {
74  if ((*iter)->GetMacAddress() == macAddress)
75  {
76  return *iter;
77  }
78  }
79 
80  NS_LOG_DEBUG("GetSSRecord: SSRecord not found!");
81  return nullptr;
82 }
83 
84 SSRecord*
86 {
87  for (std::vector<SSRecord*>::iterator iter1 = m_ssRecords->begin(); iter1 != m_ssRecords->end();
88  ++iter1)
89  {
90  SSRecord* ssRecord = *iter1;
91  if (ssRecord->GetBasicCid() == cid || ssRecord->GetPrimaryCid() == cid)
92  {
93  return ssRecord;
94  }
95  else
96  {
97  std::vector<ServiceFlow*> sf = ssRecord->GetServiceFlows(ServiceFlow::SF_TYPE_ALL);
98  for (std::vector<ServiceFlow*>::iterator iter2 = sf.begin(); iter2 != sf.end(); ++iter2)
99  {
100  if ((*iter2)->GetConnection()->GetCid() == cid)
101  {
102  return ssRecord;
103  }
104  }
105  }
106  }
107 
108  NS_LOG_DEBUG("GetSSRecord: SSRecord not found!");
109  return nullptr;
110 }
111 
112 std::vector<SSRecord*>*
114 {
115  return m_ssRecords;
116 }
117 
118 bool
119 SSManager::IsInRecord(const Mac48Address& macAddress) const
120 {
121  for (std::vector<SSRecord*>::iterator iter = m_ssRecords->begin(); iter != m_ssRecords->end();
122  ++iter)
123  {
124  if ((*iter)->GetMacAddress() == macAddress)
125  {
126  return true;
127  }
128  }
129  return false;
130 }
131 
132 bool
133 SSManager::IsRegistered(const Mac48Address& macAddress) const
134 {
135  SSRecord* ssRecord = GetSSRecord(macAddress);
136  return ssRecord != nullptr &&
138 }
139 
140 void
142 {
143  for (std::vector<SSRecord*>::iterator iter1 = m_ssRecords->begin(); iter1 != m_ssRecords->end();
144  ++iter1)
145  {
146  SSRecord* ssRecord = *iter1;
147  if (ssRecord->GetBasicCid() == cid || ssRecord->GetPrimaryCid() == cid)
148  {
149  m_ssRecords->erase(iter1);
150  return;
151  }
152  else
153  {
154  std::vector<ServiceFlow*> sf = ssRecord->GetServiceFlows(ServiceFlow::SF_TYPE_ALL);
155  for (std::vector<ServiceFlow*>::const_iterator iter2 = sf.begin(); iter2 != sf.end();
156  ++iter2)
157  {
158  if ((*iter2)->GetConnection()->GetCid() == cid)
159  {
160  m_ssRecords->erase(iter1);
161  return;
162  }
163  }
164  }
165  }
166 }
167 
170 {
171  return GetSSRecord(cid)->GetMacAddress();
172 }
173 
174 uint32_t
176 {
177  return m_ssRecords->size();
178 }
179 
180 uint32_t
182 {
183  uint32_t nrSS = 0;
184  for (std::vector<SSRecord*>::iterator iter = m_ssRecords->begin(); iter != m_ssRecords->end();
185  ++iter)
186  {
187  if ((*iter)->GetRangingStatus() == WimaxNetDevice::RANGING_STATUS_SUCCESS)
188  {
189  nrSS++;
190  }
191  }
192  return nrSS;
193 }
194 
195 } // namespace ns3
Cid class.
Definition: cid.h:37
an EUI-48 address
Definition: mac48-address.h:46
A base class which provides memory management and object aggregation.
Definition: object.h:89
static TypeId GetTypeId()
Get the type ID.
Definition: ss-manager.cc:38
uint32_t GetNRegisteredSSs() const
Get number of registered SSs.
Definition: ss-manager.cc:181
bool IsInRecord(const Mac48Address &macAddress) const
Check if address is in record.
Definition: ss-manager.cc:119
SSRecord * GetSSRecord(const Mac48Address &macAddress) const
Get SS record.
Definition: ss-manager.cc:69
std::vector< SSRecord * > * GetSSRecords() const
Get SS records.
Definition: ss-manager.cc:113
SSRecord * CreateSSRecord(const Mac48Address &macAddress)
Create SS record.
Definition: ss-manager.cc:61
bool IsRegistered(const Mac48Address &macAddress) const
Check if address is registered.
Definition: ss-manager.cc:133
uint32_t GetNSSs() const
Get number of SSs.
Definition: ss-manager.cc:175
void DeleteSSRecord(Cid cid)
Delete SS record.
Definition: ss-manager.cc:141
Mac48Address GetMacAddress(Cid cid) const
Get MAC address by CID.
Definition: ss-manager.cc:169
std::vector< SSRecord * > * m_ssRecords
the SS records
Definition: ss-manager.h:109
~SSManager() override
Definition: ss-manager.cc:49
This class is used by the base station to store some information related to subscriber station in the...
Definition: ss-record.h:46
Cid GetBasicCid() const
Get basic CID.
Definition: ss-record.cc:95
WimaxNetDevice::RangingStatus GetRangingStatus() const
Get ranging status.
Definition: ss-record.cc:179
std::vector< ServiceFlow * > GetServiceFlows(enum ServiceFlow::SchedulingType schedulingType) const
Get service flows.
Definition: ss-record.cc:233
Mac48Address GetMacAddress() const
Get MAC address.
Definition: ss-record.cc:119
Cid GetPrimaryCid() const
Get primary CID.
Definition: ss-record.cc:107
a unique identifier for an interface.
Definition: type-id.h:60
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:935
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:202
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
Definition: log.h:268
#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.