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 (auto iter = m_ssRecords->begin(); iter != m_ssRecords->end(); ++iter)
52  {
53  delete *iter;
54  }
55  delete m_ssRecords;
56  m_ssRecords = nullptr;
57 }
58 
59 SSRecord*
61 {
62  auto ssRecord = new SSRecord(macAddress);
63  m_ssRecords->push_back(ssRecord);
64  return ssRecord;
65 }
66 
67 SSRecord*
68 SSManager::GetSSRecord(const Mac48Address& macAddress) const
69 {
70  for (auto iter = m_ssRecords->begin(); iter != m_ssRecords->end(); ++iter)
71  {
72  if ((*iter)->GetMacAddress() == macAddress)
73  {
74  return *iter;
75  }
76  }
77 
78  NS_LOG_DEBUG("GetSSRecord: SSRecord not found!");
79  return nullptr;
80 }
81 
82 SSRecord*
84 {
85  for (auto iter1 = m_ssRecords->begin(); iter1 != m_ssRecords->end(); ++iter1)
86  {
87  SSRecord* ssRecord = *iter1;
88  if (ssRecord->GetBasicCid() == cid || ssRecord->GetPrimaryCid() == cid)
89  {
90  return ssRecord;
91  }
92  else
93  {
94  std::vector<ServiceFlow*> sf = ssRecord->GetServiceFlows(ServiceFlow::SF_TYPE_ALL);
95  for (auto iter2 = sf.begin(); iter2 != sf.end(); ++iter2)
96  {
97  if ((*iter2)->GetConnection()->GetCid() == cid)
98  {
99  return ssRecord;
100  }
101  }
102  }
103  }
104 
105  NS_LOG_DEBUG("GetSSRecord: SSRecord not found!");
106  return nullptr;
107 }
108 
109 std::vector<SSRecord*>*
111 {
112  return m_ssRecords;
113 }
114 
115 bool
116 SSManager::IsInRecord(const Mac48Address& macAddress) const
117 {
118  for (auto iter = m_ssRecords->begin(); iter != m_ssRecords->end(); ++iter)
119  {
120  if ((*iter)->GetMacAddress() == macAddress)
121  {
122  return true;
123  }
124  }
125  return false;
126 }
127 
128 bool
129 SSManager::IsRegistered(const Mac48Address& macAddress) const
130 {
131  SSRecord* ssRecord = GetSSRecord(macAddress);
132  return ssRecord != nullptr &&
134 }
135 
136 void
138 {
139  for (auto iter1 = m_ssRecords->begin(); iter1 != m_ssRecords->end(); ++iter1)
140  {
141  SSRecord* ssRecord = *iter1;
142  if (ssRecord->GetBasicCid() == cid || ssRecord->GetPrimaryCid() == cid)
143  {
144  m_ssRecords->erase(iter1);
145  return;
146  }
147  else
148  {
149  std::vector<ServiceFlow*> sf = ssRecord->GetServiceFlows(ServiceFlow::SF_TYPE_ALL);
150  for (auto iter2 = sf.begin(); iter2 != sf.end(); ++iter2)
151  {
152  if ((*iter2)->GetConnection()->GetCid() == cid)
153  {
154  m_ssRecords->erase(iter1);
155  return;
156  }
157  }
158  }
159  }
160 }
161 
164 {
165  return GetSSRecord(cid)->GetMacAddress();
166 }
167 
168 uint32_t
170 {
171  return m_ssRecords->size();
172 }
173 
174 uint32_t
176 {
177  uint32_t nrSS = 0;
178  for (auto iter = m_ssRecords->begin(); iter != m_ssRecords->end(); ++iter)
179  {
180  if ((*iter)->GetRangingStatus() == WimaxNetDevice::RANGING_STATUS_SUCCESS)
181  {
182  nrSS++;
183  }
184  }
185  return nrSS;
186 }
187 
188 } // 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:175
bool IsInRecord(const Mac48Address &macAddress) const
Check if address is in record.
Definition: ss-manager.cc:116
SSRecord * GetSSRecord(const Mac48Address &macAddress) const
Get SS record.
Definition: ss-manager.cc:68
std::vector< SSRecord * > * GetSSRecords() const
Get SS records.
Definition: ss-manager.cc:110
SSRecord * CreateSSRecord(const Mac48Address &macAddress)
Create SS record.
Definition: ss-manager.cc:60
bool IsRegistered(const Mac48Address &macAddress) const
Check if address is registered.
Definition: ss-manager.cc:129
uint32_t GetNSSs() const
Get number of SSs.
Definition: ss-manager.cc:169
void DeleteSSRecord(Cid cid)
Delete SS record.
Definition: ss-manager.cc:137
Mac48Address GetMacAddress(Cid cid) const
Get MAC address by CID.
Definition: ss-manager.cc:163
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(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:59
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:931
#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.