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