A Discrete-Event Network Simulator
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
service-flow-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  */
21 
22 #include <stdint.h>
23 #include "ns3/node.h"
24 #include "ns3/simulator.h"
25 #include "ns3/packet.h"
26 #include "service-flow.h"
27 #include "service-flow-manager.h"
28 #include "ns3/log.h"
29 #include "wimax-net-device.h"
30 #include "bs-net-device.h"
31 #include "ss-net-device.h"
32 #include "ss-record.h"
33 #include "ns3/pointer.h"
34 #include "ns3/enum.h"
35 #include "wimax-connection.h"
36 #include "ss-manager.h"
37 #include "connection-manager.h"
38 #include "bs-uplink-scheduler.h"
39 #include "ss-scheduler.h"
40 #include "ns3/buffer.h"
41 #include "service-flow-record.h"
42 NS_LOG_COMPONENT_DEFINE ("ServiceFlowManager");
43 
44 namespace ns3 {
45 
46 NS_OBJECT_ENSURE_REGISTERED (ServiceFlowManager)
47  ;
48 
50 {
51  static TypeId tid = TypeId ("ns3::ServiceFlowManager")
52  .SetParent<Object> ();
53  return tid;
54 }
55 
57 {
58  m_serviceFlows = new std::vector<ServiceFlow*>;
59 }
60 
62 {
63 }
64 
65 void
67 {
68  for (std::vector<ServiceFlow*>::iterator iter = m_serviceFlows->begin (); iter != m_serviceFlows->end (); ++iter)
69  {
70  delete (*iter);
71  }
72  m_serviceFlows->clear ();
73  delete m_serviceFlows;
74 }
75 
76 void
78 {
79  m_serviceFlows->push_back (serviceFlow);
80 }
81 
83  Ipv4Address dstAddress,
84  uint16_t srcPort,
85  uint16_t dstPort,
86  uint8_t proto,
87  ServiceFlow::Direction dir) const
88 {
89  for (std::vector<ServiceFlow*>::iterator iter = m_serviceFlows->begin (); iter != m_serviceFlows->end (); ++iter)
90  {
91  if ((*iter)->GetDirection () == dir)
92  {
93  if ((*iter)->CheckClassifierMatch (srcAddress, dstAddress, srcPort, dstPort, proto))
94  {
95  return (*iter);
96  }
97  }
98  }
99  return 0;
100 }
101 
104 {
105  for (std::vector<ServiceFlow*>::iterator iter = m_serviceFlows->begin (); iter != m_serviceFlows->end (); ++iter)
106  {
107  if ((*iter)->GetSfid () == sfid)
108  {
109  return (*iter);
110  }
111  }
112 
113  NS_LOG_DEBUG ("GetServiceFlow: service flow not found!");
114  return 0;
115 }
116 
119 {
120  for (std::vector<ServiceFlow*>::iterator iter = m_serviceFlows->begin (); iter != m_serviceFlows->end (); ++iter)
121  {
122  if ((*iter)->GetCid () == cid.GetIdentifier ())
123  {
124  return (*iter);
125  }
126  }
127 
128  NS_LOG_DEBUG ("GetServiceFlow: service flow not found!");
129  return 0;
130 }
131 
132 std::vector<ServiceFlow*>
134 {
135  std::vector<ServiceFlow*> tmpServiceFlows;
136  for (std::vector<ServiceFlow*>::iterator iter = m_serviceFlows->begin (); iter != m_serviceFlows->end (); ++iter)
137  {
138  if (((*iter)->GetSchedulingType () == schedulingType) || (schedulingType == ServiceFlow::SF_TYPE_ALL))
139  {
140  tmpServiceFlows.push_back ((*iter));
141  }
142  }
143  return tmpServiceFlows;
144 }
145 
146 bool
148 {
150 }
151 
152 bool
153 ServiceFlowManager::AreServiceFlowsAllocated (std::vector<ServiceFlow*>* serviceFlowVector)
154 {
155  return AreServiceFlowsAllocated (*serviceFlowVector);
156 }
157 
158 bool
159 ServiceFlowManager::AreServiceFlowsAllocated (std::vector<ServiceFlow*> serviceFlowVector)
160 {
161  for (std::vector<ServiceFlow*>::const_iterator iter = serviceFlowVector.begin (); iter != serviceFlowVector.end (); ++iter)
162  {
163  if (!(*iter)->GetIsEnabled ())
164  {
165  return false;
166  }
167  }
168  return true;
169 }
170 
173 {
174  std::vector<ServiceFlow*>::iterator iter;
175  for (iter = m_serviceFlows->begin (); iter != m_serviceFlows->end (); ++iter)
176  {
177  if (!(*iter)->GetIsEnabled ())
178  {
179  return (*iter);
180  }
181  }
182  return 0;
183 }
184 
185 uint32_t
187 {
188  return m_serviceFlows->size ();
189 }
190 
191 } // namespace ns3
static TypeId GetTypeId(void)
ServiceFlow * GetServiceFlow(uint32_t sfid) const
NS_OBJECT_ENSURE_REGISTERED(NullMessageSimulatorImpl)
ServiceFlow * GetNextServiceFlowToAllocate()
uint32_t GetNrServiceFlows(void) const
ServiceFlow * DoClassify(Ipv4Address SrcAddress, Ipv4Address DstAddress, uint16_t SrcPort, uint16_t DstPort, uint8_t Proto, ServiceFlow::Direction dir) const
void DoDispose(void)
This method is called by Object::Dispose or by the object's destructor, whichever comes first...
Definition: cid.h:35
std::vector< ServiceFlow * > GetServiceFlows(enum ServiceFlow::SchedulingType schedulingType) const
This class implements service flows as described by the IEEE-802.16 standard.
Definition: service-flow.h:39
Ipv4 addresses are stored in host order in this class.
Definition: ipv4-address.h:38
std::vector< ServiceFlow * > * m_serviceFlows
void AddServiceFlow(ServiceFlow *serviceFlow)
#define NS_LOG_DEBUG(msg)
Definition: log.h:289
uint16_t GetIdentifier(void) const
Definition: cid.cc:45
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
NS_LOG_COMPONENT_DEFINE("ServiceFlowManager")