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