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