A Discrete-Event Network Simulator
API
epc-tft.cc
Go to the documentation of this file.
1/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
2/*
3 * Copyright (c) 2011 CTTC
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 * Author: Nicola Baldo <nbaldo@cttc.es>
19 */
20
21
22
23
24#include "epc-tft.h"
25#include "ns3/abort.h"
26#include "ns3/log.h"
27
28
29namespace ns3 {
30
32
40std::ostream& operator<< (std::ostream& os, EpcTft::Direction& d)
41{
42 switch (d)
43 {
45 os << "DOWNLINK";
46 break;
47 case EpcTft::UPLINK:
48 os << "UPLINK";
49 break;
50 default:
51 os << "BIDIRECTIONAL";
52 break;
53 }
54 return os;
55}
56
57
65std::ostream& operator<< (std::ostream& os, EpcTft::PacketFilter& f)
66{
67 os << " direction: " << f.direction
68 << " remoteAddress: " << f.remoteAddress
69 << " remoteMask: " << f.remoteMask
70 << " remoteIpv6Address: " << f.remoteIpv6Address
71 << " remoteIpv6Prefix: " << f.remoteIpv6Prefix
72 << " localAddress: " << f.localAddress
73 << " localMask: " << f.localMask
74 << " localIpv6Address: " << f.localIpv6Address
75 << " localIpv6Prefix: " << f.localIpv6Prefix
76 << " remotePortStart: " << f.remotePortStart
77 << " remotePortEnd: " << f.remotePortEnd
78 << " localPortStart: " << f.localPortStart
79 << " localPortEnd: " << f.localPortEnd
80 << " typeOfService: 0x" << std::hex << (uint16_t) f.typeOfService << std::dec
81 << " typeOfServiceMask: 0x" << std::hex << (uint16_t) f.typeOfServiceMask << std::dec;
82 return os;
83}
84
86: precedence (255),
87 direction (BIDIRECTIONAL),
88 remoteMask ("0.0.0.0"),
89 localMask ("0.0.0.0"),
90 remotePortStart (0),
91 remotePortEnd (65535),
92 localPortStart (0),
93 localPortEnd (65535),
94 typeOfService (0),
95 typeOfServiceMask (0)
96{
97 NS_LOG_FUNCTION (this);
98}
99
100bool
102 Ipv4Address ra,
103 Ipv4Address la,
104 uint16_t rp,
105 uint16_t lp,
106 uint8_t tos)
107{
108 NS_LOG_FUNCTION (this << d << ra << la << rp << lp << (uint16_t) tos);
109 if (d & direction)
110 {
111 NS_LOG_LOGIC ("d matches");
112 if (remoteMask.IsMatch (remoteAddress, ra))
113 {
114 NS_LOG_LOGIC ("ra matches");
115 if (localMask.IsMatch (localAddress, la))
116 {
117 NS_LOG_LOGIC ("la matches");
118 if (remotePortStart <= rp && rp <= remotePortEnd)
119 {
120 NS_LOG_LOGIC ("rp matches");
121 if (localPortStart <= lp && lp <= localPortEnd)
122 {
123 NS_LOG_LOGIC ("lp matches");
124 if ((tos & typeOfServiceMask) == (typeOfService & typeOfServiceMask))
125 {
126 NS_LOG_LOGIC ("tos matches --> have match!");
127 return true;
128 }
129 else
130 {
131 NS_LOG_LOGIC ("tos doesn't match: tos=" << tos << " f.tos=" << typeOfService << " f.tosmask=" << typeOfServiceMask);
132 }
133 }
134 else
135 {
136 NS_LOG_LOGIC ("lp doesn't match: lp=" << lp << " f.lps=" << localPortStart << " f.lpe=" << localPortEnd);
137 }
138 }
139 else
140 {
141 NS_LOG_LOGIC ("rp doesn't match: rp=" << rp << " f.rps=" << remotePortStart << " f.lpe=" << remotePortEnd);
142 }
143 }
144 else
145 {
146 NS_LOG_LOGIC ("la doesn't match: la=" << la << " f.la=" << localAddress << " f.lmask=" << localMask);
147 }
148 }
149 else
150 {
151 NS_LOG_LOGIC ("ra doesn't match: ra=" << ra << " f.ra=" << remoteAddress << " f.rmask=" << remoteMask);
152 }
153 }
154 else
155 {
156 NS_LOG_LOGIC ("d doesn't match: d=0x" << std::hex << d << " f.d=0x" << std::hex << direction << std::dec);
157 }
158 return false;
159}
160
161bool
163 Ipv6Address ra,
164 Ipv6Address la,
165 uint16_t rp,
166 uint16_t lp,
167 uint8_t tos)
168{
169 NS_LOG_FUNCTION (this << d << ra << la << rp << lp << (uint16_t) tos);
170 if (d & direction)
171 {
172 NS_LOG_LOGIC ("d matches");
173 if (remoteIpv6Prefix.IsMatch (remoteIpv6Address, ra))
174 {
175 NS_LOG_LOGIC ("ra matches");
176 if (localIpv6Prefix.IsMatch (localIpv6Address, la))
177 {
178 NS_LOG_LOGIC ("la matches");
179 if (remotePortStart <= rp && rp <= remotePortEnd)
180 {
181 NS_LOG_LOGIC ("rp matches");
182 if (localPortStart <= lp && lp <= localPortEnd)
183 {
184 NS_LOG_LOGIC ("lp matches");
185 if ((tos & typeOfServiceMask) == (typeOfService & typeOfServiceMask))
186 {
187 NS_LOG_LOGIC ("tos matches --> have match!");
188 return true;
189 }
190 else
191 {
192 NS_LOG_LOGIC ("tos doesn't match: tos=" << tos << " f.tos=" << typeOfService << " f.tosmask=" << typeOfServiceMask);
193 }
194 }
195 else
196 {
197 NS_LOG_LOGIC ("lp doesn't match: lp=" << lp << " f.lps=" << localPortStart << " f.lpe=" << localPortEnd);
198 }
199 }
200 else
201 {
202 NS_LOG_LOGIC ("rp doesn't match: rp=" << rp << " f.rps=" << remotePortStart << " f.lpe=" << remotePortEnd);
203 }
204 }
205 else
206 {
207 NS_LOG_LOGIC ("la doesn't match: la=" << la << " f.la=" << localIpv6Address << " f.lprefix=" << localIpv6Prefix);
208 }
209 }
210 else
211 {
212 NS_LOG_LOGIC ("ra doesn't match: ra=" << ra << " f.ra=" << remoteIpv6Address << " f.rprefix=" << remoteIpv6Prefix);
213 }
214 }
215 else
216 {
217 NS_LOG_LOGIC ("d doesn't match: d=0x" << std::hex << d << " f.d=0x" << std::hex << direction << std::dec);
218 }
219 return false;
220}
221
222
225{
226 Ptr<EpcTft> tft = Create<EpcTft> ();
227 EpcTft::PacketFilter defaultPacketFilter;
228 tft->Add (defaultPacketFilter);
229 return tft;
230}
231
232
234: m_numFilters (0)
235{
236 NS_LOG_FUNCTION (this);
237}
238
239uint8_t
241{
242 NS_LOG_FUNCTION (this << f);
244
245 std::list<PacketFilter>::iterator it;
246 for (it = m_filters.begin ();
247 (it != m_filters.end ()) && (it->precedence <= f.precedence);
248 ++it)
249 {
250 }
251 m_filters.insert (it, f);
252 ++m_numFilters;
253 return (m_numFilters - 1);
254}
255
256bool
258 Ipv4Address remoteAddress,
259 Ipv4Address localAddress,
260 uint16_t remotePort,
261 uint16_t localPort,
262 uint8_t typeOfService)
263{
264 NS_LOG_FUNCTION (this << direction << remoteAddress << localAddress << std::dec << remotePort << localPort << (uint16_t) typeOfService);
265 for (std::list<PacketFilter>::iterator it = m_filters.begin ();
266 it != m_filters.end ();
267 ++it)
268 {
269 if (it->Matches (direction, remoteAddress, localAddress, remotePort, localPort, typeOfService))
270 {
271 return true;
272 }
273 }
274 return false;
275}
276
277bool
279 Ipv6Address remoteAddress,
280 Ipv6Address localAddress,
281 uint16_t remotePort,
282 uint16_t localPort,
283 uint8_t typeOfService)
284{
285 NS_LOG_FUNCTION (this << direction << remoteAddress << localAddress << std::dec << remotePort << localPort << (uint16_t) typeOfService);
286 for (std::list<PacketFilter>::iterator it = m_filters.begin ();
287 it != m_filters.end ();
288 ++it)
289 {
290 if (it->Matches (direction, remoteAddress, localAddress, remotePort, localPort, typeOfService))
291 {
292 return true;
293 }
294 }
295 return false;
296}
297
298std::list<EpcTft::PacketFilter>
300{
301 NS_LOG_FUNCTION (this);
302 return m_filters;
303};
304
305} // namespace ns3
double f(double x, void *params)
Definition: 80211b.c:70
uint8_t Add(PacketFilter f)
add a PacketFilter to the Traffic Flow Template
Definition: epc-tft.cc:240
bool Matches(Direction direction, Ipv4Address remoteAddress, Ipv4Address localAddress, uint16_t remotePort, uint16_t localPort, uint8_t typeOfService)
Definition: epc-tft.cc:257
static Ptr< EpcTft > Default()
creates a TFT matching any traffic
Definition: epc-tft.cc:224
std::list< PacketFilter > GetPacketFilters() const
Get the packet filters.
Definition: epc-tft.cc:299
Direction
Indicates the direction of the traffic that is to be classified.
Definition: epc-tft.h:57
@ DOWNLINK
Definition: epc-tft.h:57
std::list< PacketFilter > m_filters
packet filter list
Definition: epc-tft.h:205
uint8_t m_numFilters
number of packet filters applied to this TFT
Definition: epc-tft.h:206
Ipv4 addresses are stored in host order in this class.
Definition: ipv4-address.h:41
Describes an IPv6 address.
Definition: ipv6-address.h:50
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:74
#define NS_ABORT_IF(cond)
Abnormal program termination if a condition is true.
Definition: abort.h:77
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:205
#define NS_LOG_LOGIC(msg)
Use NS_LOG to output a message of level LOG_LOGIC.
Definition: log.h:289
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by ",...
Every class exported by the ns3 library is enclosed in the ns3 namespace.
std::ostream & operator<<(std::ostream &os, const Angles &a)
Definition: angles.cc:139
Implement the data structure representing a TrafficFlowTemplate Packet Filter.
Definition: epc-tft.h:75
bool Matches(Direction d, Ipv4Address ra, Ipv4Address la, uint16_t rp, uint16_t lp, uint8_t tos)
Definition: epc-tft.cc:101