A Discrete-Event Network Simulator
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
ss-manager.cc
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 
33 TypeId SSManager::GetTypeId (void)
34 {
35  static TypeId tid = TypeId ("ns3::SSManager")
36  .SetParent<Object> ();
37  return tid;
38 }
39 
40 SSManager::SSManager (void)
41 {
42  m_ssRecords = new std::vector<SSRecord*> ();
43 }
44 
45 SSManager::~SSManager (void)
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*
56 SSManager::CreateSSRecord (const Mac48Address &macAddress)
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*
79 SSManager::GetSSRecord (Cid cid) const
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*>*
106 SSManager::GetSSRecords (void) const
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
132 SSManager::DeleteSSRecord (Cid cid)
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 
157 Mac48Address
158 SSManager::GetMacAddress (Cid cid) const
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
170 SSManager::GetNRegisteredSSs (void) const
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 
#define NS_LOG_COMPONENT_DEFINE(name)
Definition: log.h:122
Definition: cid.h:35
#define NS_LOG_DEBUG(msg)
Definition: log.h:255
This class is used by the base station to store some information related to subscriber station in the...
Definition: ss-record.h:43