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 {
32  ;
33 
35 {
36  static TypeId tid = TypeId ("ns3::SSManager")
37  .SetParent<Object> ();
38  return tid;
39 }
40 
42 {
43  m_ssRecords = new std::vector<SSRecord*> ();
44 }
45 
47 {
48  for (std::vector<SSRecord*>::iterator iter = m_ssRecords->begin (); iter != m_ssRecords->end (); ++iter)
49  {
50  delete *iter;
51  }
52  delete m_ssRecords;
53  m_ssRecords = 0;
54 }
55 
56 SSRecord*
58 {
59  SSRecord *ssRecord = new SSRecord (macAddress);
60  m_ssRecords->push_back (ssRecord);
61  return ssRecord;
62 }
63 
64 SSRecord*
65 SSManager::GetSSRecord (const Mac48Address &macAddress) const
66 {
67  for (std::vector<SSRecord*>::iterator iter = m_ssRecords->begin (); iter != m_ssRecords->end (); ++iter)
68  {
69  if ((*iter)->GetMacAddress () == macAddress)
70  {
71  return *iter;
72  }
73  }
74 
75  NS_LOG_DEBUG ("GetSSRecord: SSRecord not found!");
76  return 0;
77 }
78 
79 SSRecord*
81 {
82  for (std::vector<SSRecord*>::iterator iter1 = m_ssRecords->begin (); iter1 != m_ssRecords->end (); ++iter1)
83  {
84  SSRecord *ssRecord = *iter1;
85  if (ssRecord->GetBasicCid () == cid || ssRecord->GetPrimaryCid () == cid)
86  {
87  return ssRecord;
88  }
89  else
90  {
91  std::vector<ServiceFlow*> sf = ssRecord->GetServiceFlows (ServiceFlow::SF_TYPE_ALL);
92  for (std::vector<ServiceFlow*>::iterator iter2 = sf.begin (); iter2 != sf.end (); ++iter2)
93  {
94  if ((*iter2)->GetConnection ()->GetCid () == cid)
95  {
96  return ssRecord;
97  }
98  }
99  }
100  }
101 
102  NS_LOG_DEBUG ("GetSSRecord: SSRecord not found!");
103  return 0;
104 }
105 
106 std::vector<SSRecord*>*
108 {
109  return m_ssRecords;
110 }
111 
112 bool
113 SSManager::IsInRecord (const Mac48Address &macAddress) const
114 {
115  for (std::vector<SSRecord*>::iterator iter = m_ssRecords->begin (); iter != m_ssRecords->end (); ++iter)
116  {
117  if ((*iter)->GetMacAddress () == macAddress)
118  {
119  return true;
120  }
121  }
122  return false;
123 }
124 
125 bool
126 SSManager::IsRegistered (const Mac48Address &macAddress) const
127 {
128  SSRecord *ssRecord = GetSSRecord (macAddress);
129  return ssRecord != 0 && ssRecord->GetRangingStatus () == WimaxNetDevice::RANGING_STATUS_SUCCESS;
130 }
131 
132 void
134 {
135  for (std::vector<SSRecord*>::iterator iter1 = m_ssRecords->begin (); iter1 != m_ssRecords->end (); ++iter1)
136  {
137  SSRecord *ssRecord = *iter1;
138  if (ssRecord->GetBasicCid () == cid || ssRecord->GetPrimaryCid () == cid)
139  {
140  m_ssRecords->erase (iter1);
141  return;
142  }
143  else
144  {
145  std::vector<ServiceFlow*> sf = ssRecord->GetServiceFlows (ServiceFlow::SF_TYPE_ALL);
146  for (std::vector<ServiceFlow*>::const_iterator iter2 = sf.begin (); iter2 != sf.end (); ++iter2)
147  {
148  if ((*iter2)->GetConnection ()->GetCid () == cid)
149  {
150  m_ssRecords->erase (iter1);
151  return;
152  }
153  }
154  }
155  }
156 }
157 
160 {
161  return GetSSRecord (cid)->GetMacAddress ();
162 }
163 
164 uint32_t
165 SSManager::GetNSSs (void) const
166 {
167  return m_ssRecords->size ();
168 }
169 
170 uint32_t
172 {
173  uint32_t nrSS = 0;
174  for (std::vector<SSRecord*>::iterator iter = m_ssRecords->begin (); iter != m_ssRecords->end (); ++iter)
175  {
176  if ((*iter)->GetRangingStatus () == WimaxNetDevice::RANGING_STATUS_SUCCESS)
177  {
178  nrSS++;
179  }
180  }
181  return nrSS;
182 }
183 
184 } // namespace ns3
185 
186 
Mac48Address GetMacAddress(void) const
Definition: ss-record.cc:116
Cid GetBasicCid(void) const
Definition: ss-record.cc:92
NS_LOG_COMPONENT_DEFINE("SSManager")
std::vector< SSRecord * > * m_ssRecords
Definition: ss-manager.h:62
NS_OBJECT_ENSURE_REGISTERED(NullMessageSimulatorImpl)
WimaxNetDevice::RangingStatus GetRangingStatus(void) const
Definition: ss-record.cc:176
std::vector< SSRecord * > * GetSSRecords(void) const
Definition: ss-manager.cc:107
uint32_t GetNRegisteredSSs(void) const
Definition: ss-manager.cc:171
std::vector< ServiceFlow * > GetServiceFlows(enum ServiceFlow::SchedulingType schedulingType) const
Definition: ss-record.cc:229
uint32_t GetNSSs(void) const
Definition: ss-manager.cc:165
SSRecord * GetSSRecord(const Mac48Address &macAddress) const
Definition: ss-manager.cc:65
Definition: cid.h:35
an EUI-48 address
Definition: mac48-address.h:41
static TypeId GetTypeId(void)
Definition: ss-manager.cc:34
Cid GetPrimaryCid(void) const
Definition: ss-record.cc:104
void DeleteSSRecord(Cid cid)
Definition: ss-manager.cc:133
#define NS_LOG_DEBUG(msg)
Definition: log.h:289
SSRecord * CreateSSRecord(const Mac48Address &macAddress)
Definition: ss-manager.cc:57
~SSManager(void)
Definition: ss-manager.cc:46
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:63
a unique identifier for an interface.
Definition: type-id.h:49
TypeId SetParent(TypeId tid)
Definition: type-id.cc:611
Mac48Address GetMacAddress(Cid cid) const
Definition: ss-manager.cc:159
bool IsInRecord(const Mac48Address &macAddress) const
Definition: ss-manager.cc:113
bool IsRegistered(const Mac48Address &macAddress) const
Definition: ss-manager.cc:126