A Discrete-Event Network Simulator
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
service-flow-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  */
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 TypeId ServiceFlowManager::GetTypeId (void)
49 {
50  static TypeId tid = TypeId ("ns3::ServiceFlowManager")
51  .SetParent<Object> ();
52  return tid;
53 }
54 
55 ServiceFlowManager::ServiceFlowManager ()
56 {
57  m_serviceFlows = new std::vector<ServiceFlow*>;
58 }
59 
60 ServiceFlowManager::~ServiceFlowManager (void)
61 {
62 }
63 
64 void
66 {
67  for (std::vector<ServiceFlow*>::iterator iter = m_serviceFlows->begin (); iter != m_serviceFlows->end (); ++iter)
68  {
69  delete (*iter);
70  }
71  m_serviceFlows->clear ();
72  delete m_serviceFlows;
73 }
74 
75 void
76 ServiceFlowManager::AddServiceFlow (ServiceFlow *serviceFlow)
77 {
78  m_serviceFlows->push_back (serviceFlow);
79 }
80 
82  Ipv4Address dstAddress,
83  uint16_t srcPort,
84  uint16_t dstPort,
85  uint8_t proto,
86  ServiceFlow::Direction dir) const
87 {
88  for (std::vector<ServiceFlow*>::iterator iter = m_serviceFlows->begin (); iter != m_serviceFlows->end (); ++iter)
89  {
90  if ((*iter)->GetDirection () == dir)
91  {
92  if ((*iter)->CheckClassifierMatch (srcAddress, dstAddress, srcPort, dstPort, proto))
93  {
94  return (*iter);
95  }
96  }
97  }
98  return 0;
99 }
100 
102 ServiceFlowManager::GetServiceFlow (uint32_t sfid) const
103 {
104  for (std::vector<ServiceFlow*>::iterator iter = m_serviceFlows->begin (); iter != m_serviceFlows->end (); ++iter)
105  {
106  if ((*iter)->GetSfid () == sfid)
107  {
108  return (*iter);
109  }
110  }
111 
112  NS_LOG_DEBUG ("GetServiceFlow: service flow not found!");
113  return 0;
114 }
115 
116 ServiceFlow*
117 ServiceFlowManager::GetServiceFlow (Cid cid) const
118 {
119  for (std::vector<ServiceFlow*>::iterator iter = m_serviceFlows->begin (); iter != m_serviceFlows->end (); ++iter)
120  {
121  if ((*iter)->GetCid () == cid.GetIdentifier ())
122  {
123  return (*iter);
124  }
125  }
126 
127  NS_LOG_DEBUG ("GetServiceFlow: service flow not found!");
128  return 0;
129 }
130 
131 std::vector<ServiceFlow*>
132 ServiceFlowManager::GetServiceFlows (enum ServiceFlow::SchedulingType schedulingType) const
133 {
134  std::vector<ServiceFlow*> tmpServiceFlows;
135  for (std::vector<ServiceFlow*>::iterator iter = m_serviceFlows->begin (); iter != m_serviceFlows->end (); ++iter)
136  {
137  if (((*iter)->GetSchedulingType () == schedulingType) || (schedulingType == ServiceFlow::SF_TYPE_ALL))
138  {
139  tmpServiceFlows.push_back ((*iter));
140  }
141  }
142  return tmpServiceFlows;
143 }
144 
145 bool
147 {
148  return AreServiceFlowsAllocated (m_serviceFlows);
149 }
150 
151 bool
152 ServiceFlowManager::AreServiceFlowsAllocated (std::vector<ServiceFlow*>* serviceFlowVector)
153 {
154  return AreServiceFlowsAllocated (*serviceFlowVector);
155 }
156 
157 bool
158 ServiceFlowManager::AreServiceFlowsAllocated (std::vector<ServiceFlow*> serviceFlowVector)
159 {
160  for (std::vector<ServiceFlow*>::const_iterator iter = serviceFlowVector.begin (); iter != serviceFlowVector.end (); ++iter)
161  {
162  if (!(*iter)->GetIsEnabled ())
163  {
164  return false;
165  }
166  }
167  return true;
168 }
169 
172 {
173  std::vector<ServiceFlow*>::iterator iter;
174  for (iter = m_serviceFlows->begin (); iter != m_serviceFlows->end (); ++iter)
175  {
176  if (!(*iter)->GetIsEnabled ())
177  {
178  return (*iter);
179  }
180  }
181  return 0;
182 }
183 
184 uint32_t
186 {
187  return m_serviceFlows->size ();
188 }
189 
190 } // namespace ns3
#define NS_LOG_COMPONENT_DEFINE(name)
Definition: log.h:122
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
Ipv4 addresses are stored in host order in this class.
Definition: ipv4-address.h:38
#define NS_LOG_DEBUG(msg)
Definition: log.h:255