A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
epc-tft.cc
Go to the documentation of this file.
1/*
2 * Copyright (c) 2011 CTTC
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation;
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, write to the Free Software
15 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 *
17 * Author: Nicola Baldo <nbaldo@cttc.es>
18 */
19
20#include "epc-tft.h"
21
22#include "ns3/abort.h"
23#include "ns3/log.h"
24
25namespace ns3
26{
27
29
30/**
31 * Output stream operator for EPC TFT direction
32 *
33 * \param os output stream
34 * \param d EPC TFT direction
35 * \return ostream
36 */
37std::ostream&
38operator<<(std::ostream& os, const EpcTft::Direction& d)
39{
40 switch (d)
41 {
43 os << "DOWNLINK";
44 break;
45 case EpcTft::UPLINK:
46 os << "UPLINK";
47 break;
48 default:
49 os << "BIDIRECTIONAL";
50 break;
51 }
52 return os;
53}
54
55/**
56 * Output stream for EPC TFT packet filter
57 *
58 * \param os output stream
59 * \param f EPC TFT packet filter
60 * \return ostream
61 */
62std::ostream&
63operator<<(std::ostream& os, const EpcTft::PacketFilter& f)
64{
65 os << " direction: " << f.direction << " remoteAddress: " << f.remoteAddress
66 << " remoteMask: " << f.remoteMask << " remoteIpv6Address: " << f.remoteIpv6Address
67 << " remoteIpv6Prefix: " << f.remoteIpv6Prefix << " localAddress: " << f.localAddress
68 << " localMask: " << f.localMask << " localIpv6Address: " << f.localIpv6Address
69 << " localIpv6Prefix: " << f.localIpv6Prefix << " remotePortStart: " << f.remotePortStart
70 << " remotePortEnd: " << f.remotePortEnd << " localPortStart: " << f.localPortStart
71 << " localPortEnd: " << f.localPortEnd << " typeOfService: 0x" << std::hex
72 << (uint16_t)f.typeOfService << std::dec << " typeOfServiceMask: 0x" << std::hex
73 << (uint16_t)f.typeOfServiceMask << std::dec;
74 return os;
75}
76
78 : precedence(255),
79 direction(BIDIRECTIONAL),
80 remoteMask("0.0.0.0"),
81 localMask("0.0.0.0"),
82 remotePortStart(0),
83 remotePortEnd(65535),
84 localPortStart(0),
85 localPortEnd(65535),
86 typeOfService(0),
87 typeOfServiceMask(0)
88{
89 NS_LOG_FUNCTION(this);
90}
91
92bool
94 Ipv4Address ra,
95 Ipv4Address la,
96 uint16_t rp,
97 uint16_t lp,
98 uint8_t tos)
99{
100 NS_LOG_FUNCTION(this << d << ra << la << rp << lp << (uint16_t)tos);
101 if (d & direction)
102 {
103 NS_LOG_LOGIC("d matches");
104 if (remoteMask.IsMatch(remoteAddress, ra))
105 {
106 NS_LOG_LOGIC("ra matches");
107 if (localMask.IsMatch(localAddress, la))
108 {
109 NS_LOG_LOGIC("la matches");
110 if (remotePortStart <= rp && rp <= remotePortEnd)
111 {
112 NS_LOG_LOGIC("rp matches");
113 if (localPortStart <= lp && lp <= localPortEnd)
114 {
115 NS_LOG_LOGIC("lp matches");
116 if ((tos & typeOfServiceMask) == (typeOfService & typeOfServiceMask))
117 {
118 NS_LOG_LOGIC("tos matches --> have match!");
119 return true;
120 }
121 else
122 {
123 NS_LOG_LOGIC("tos doesn't match: tos="
124 << tos << " f.tos=" << typeOfService
125 << " f.tosmask=" << typeOfServiceMask);
126 }
127 }
128 else
129 {
130 NS_LOG_LOGIC("lp doesn't match: lp=" << lp << " f.lps=" << localPortStart
131 << " f.lpe=" << localPortEnd);
132 }
133 }
134 else
135 {
136 NS_LOG_LOGIC("rp doesn't match: rp=" << rp << " f.rps=" << remotePortStart
137 << " f.lpe=" << remotePortEnd);
138 }
139 }
140 else
141 {
142 NS_LOG_LOGIC("la doesn't match: la=" << la << " f.la=" << localAddress
143 << " f.lmask=" << localMask);
144 }
145 }
146 else
147 {
148 NS_LOG_LOGIC("ra doesn't match: ra=" << ra << " f.ra=" << remoteAddress
149 << " f.rmask=" << remoteMask);
150 }
151 }
152 else
153 {
154 NS_LOG_LOGIC("d doesn't match: d=0x" << std::hex << d << " f.d=0x" << std::hex << direction
155 << std::dec);
156 }
157 return false;
158}
159
160bool
162 Ipv6Address ra,
163 Ipv6Address la,
164 uint16_t rp,
165 uint16_t lp,
166 uint8_t tos)
167{
168 NS_LOG_FUNCTION(this << d << ra << la << rp << lp << (uint16_t)tos);
169 if (d & direction)
170 {
171 NS_LOG_LOGIC("d matches");
172 if (remoteIpv6Prefix.IsMatch(remoteIpv6Address, ra))
173 {
174 NS_LOG_LOGIC("ra matches");
175 if (localIpv6Prefix.IsMatch(localIpv6Address, la))
176 {
177 NS_LOG_LOGIC("la matches");
178 if (remotePortStart <= rp && rp <= remotePortEnd)
179 {
180 NS_LOG_LOGIC("rp matches");
181 if (localPortStart <= lp && lp <= localPortEnd)
182 {
183 NS_LOG_LOGIC("lp matches");
184 if ((tos & typeOfServiceMask) == (typeOfService & typeOfServiceMask))
185 {
186 NS_LOG_LOGIC("tos matches --> have match!");
187 return true;
188 }
189 else
190 {
191 NS_LOG_LOGIC("tos doesn't match: tos="
192 << tos << " f.tos=" << typeOfService
193 << " f.tosmask=" << typeOfServiceMask);
194 }
195 }
196 else
197 {
198 NS_LOG_LOGIC("lp doesn't match: lp=" << lp << " f.lps=" << localPortStart
199 << " f.lpe=" << localPortEnd);
200 }
201 }
202 else
203 {
204 NS_LOG_LOGIC("rp doesn't match: rp=" << rp << " f.rps=" << remotePortStart
205 << " f.lpe=" << remotePortEnd);
206 }
207 }
208 else
209 {
210 NS_LOG_LOGIC("la doesn't match: la=" << la << " f.la=" << localIpv6Address
211 << " f.lprefix=" << localIpv6Prefix);
212 }
213 }
214 else
215 {
216 NS_LOG_LOGIC("ra doesn't match: ra=" << ra << " f.ra=" << remoteIpv6Address
217 << " f.rprefix=" << remoteIpv6Prefix);
218 }
219 }
220 else
221 {
222 NS_LOG_LOGIC("d doesn't match: d=0x" << std::hex << d << " f.d=0x" << std::hex << direction
223 << std::dec);
224 }
225 return false;
226}
227
230{
231 Ptr<EpcTft> tft = Create<EpcTft>();
232 EpcTft::PacketFilter defaultPacketFilter;
233 tft->Add(defaultPacketFilter);
234 return tft;
235}
236
238 : m_numFilters(0)
239{
240 NS_LOG_FUNCTION(this);
241}
242
243uint8_t
245{
246 NS_LOG_FUNCTION(this << f);
248
249 std::list<PacketFilter>::iterator it;
250 for (it = m_filters.begin(); (it != m_filters.end()) && (it->precedence <= f.precedence); ++it)
251 {
252 }
253 m_filters.insert(it, f);
254 ++m_numFilters;
255 return (m_numFilters - 1);
256}
257
258bool
260 Ipv4Address remoteAddress,
261 Ipv4Address localAddress,
262 uint16_t remotePort,
263 uint16_t localPort,
264 uint8_t typeOfService)
265{
266 NS_LOG_FUNCTION(this << direction << remoteAddress << localAddress << std::dec << remotePort
267 << localPort << (uint16_t)typeOfService);
268 for (auto it = m_filters.begin(); it != m_filters.end(); ++it)
269 {
270 if (it->Matches(direction,
271 remoteAddress,
272 localAddress,
273 remotePort,
274 localPort,
275 typeOfService))
276 {
277 return true;
278 }
279 }
280 return false;
281}
282
283bool
285 Ipv6Address remoteAddress,
286 Ipv6Address localAddress,
287 uint16_t remotePort,
288 uint16_t localPort,
289 uint8_t typeOfService)
290{
291 NS_LOG_FUNCTION(this << direction << remoteAddress << localAddress << std::dec << remotePort
292 << localPort << (uint16_t)typeOfService);
293 for (auto it = m_filters.begin(); it != m_filters.end(); ++it)
294 {
295 if (it->Matches(direction,
296 remoteAddress,
297 localAddress,
298 remotePort,
299 localPort,
300 typeOfService))
301 {
302 return true;
303 }
304 }
305 return false;
306}
307
308std::list<EpcTft::PacketFilter>
310{
311 NS_LOG_FUNCTION(this);
312 return m_filters;
313}
314
315} // namespace ns3
uint8_t Add(PacketFilter f)
add a PacketFilter to the Traffic Flow Template
Definition: epc-tft.cc:244
bool Matches(Direction direction, Ipv4Address remoteAddress, Ipv4Address localAddress, uint16_t remotePort, uint16_t localPort, uint8_t typeOfService)
Definition: epc-tft.cc:259
static Ptr< EpcTft > Default()
creates a TFT matching any traffic
Definition: epc-tft.cc:229
std::list< PacketFilter > GetPacketFilters() const
Get the packet filters.
Definition: epc-tft.cc:309
Direction
Indicates the direction of the traffic that is to be classified.
Definition: epc-tft.h:51
@ DOWNLINK
Definition: epc-tft.h:52
std::list< PacketFilter > m_filters
packet filter list
Definition: epc-tft.h:195
uint8_t m_numFilters
number of packet filters applied to this TFT
Definition: epc-tft.h:196
Ipv4 addresses are stored in host order in this class.
Definition: ipv4-address.h:42
Describes an IPv6 address.
Definition: ipv6-address.h:49
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:77
#define NS_ABORT_IF(cond)
Abnormal program termination if a condition is true.
Definition: abort.h:76
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:202
#define NS_LOG_LOGIC(msg)
Use NS_LOG to output a message of level LOG_LOGIC.
Definition: log.h:282
#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:159
Implement the data structure representing a TrafficFlowTemplate Packet Filter.
Definition: epc-tft.h:71
Ipv4Address localAddress
IPv4 address of the UE.
Definition: epc-tft.h:121
Ipv6Prefix localIpv6Prefix
IPv6 address prefix of the UE.
Definition: epc-tft.h:127
uint16_t localPortEnd
end of the port number range of the UE
Definition: epc-tft.h:132
bool Matches(Direction d, Ipv4Address ra, Ipv4Address la, uint16_t rp, uint16_t lp, uint8_t tos)
Definition: epc-tft.cc:93
Ipv4Mask localMask
IPv4 address mask of the UE.
Definition: epc-tft.h:122
uint16_t remotePortEnd
end of the port number range of the remote host
Definition: epc-tft.h:130
Ipv6Address remoteIpv6Address
IPv6 address of the remote host.
Definition: epc-tft.h:124
uint8_t precedence
Used to specify the precedence for the packet filter among all packet filters in the TFT; higher valu...
Definition: epc-tft.h:114
Direction direction
Whether the filter needs to be applied to uplink / downlink only, or in both cases.
Definition: epc-tft.h:117
Ipv4Mask remoteMask
IPv4 address mask of the remote host.
Definition: epc-tft.h:120
uint16_t remotePortStart
start of the port number range of the remote host
Definition: epc-tft.h:129
Ipv6Address localIpv6Address
IPv6 address of the UE.
Definition: epc-tft.h:126
uint8_t typeOfService
type of service field
Definition: epc-tft.h:134
Ipv4Address remoteAddress
IPv4 address of the remote host.
Definition: epc-tft.h:119
uint8_t typeOfServiceMask
type of service field mask
Definition: epc-tft.h:135
Ipv6Prefix remoteIpv6Prefix
IPv6 address prefix of the remote host.
Definition: epc-tft.h:125
uint16_t localPortStart
start of the port number range of the UE
Definition: epc-tft.h:131