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 
29 namespace ns3 {
30 
31 NS_LOG_COMPONENT_DEFINE ("EpcTft");
32 
40 std::ostream& operator<< (std::ostream& os, EpcTft::Direction& d)
41 {
42  switch (d)
43  {
44  case EpcTft::DOWNLINK:
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 
65 std::ostream& operator<< (std::ostream& os, EpcTft::PacketFilter& f)
66 {
67  os << " direction: " << f.direction
68  << " remoteAddress: " << f.remoteAddress
69  << " remoteAddress6: " << f.remoteAddress6
70  << " remoteMask: " << f.remoteMask
71  << " localAddress: " << f.localAddress
72  << " localAddress6: " << f.localAddress6
73  << " localMask: " << f.localMask
74  << " remotePortStart: " << f.remotePortStart
75  << " remotePortEnd: " << f.remotePortEnd
76  << " localPortStart: " << f.localPortStart
77  << " localPortEnd: " << f.localPortEnd
78  << " typeOfService: 0x" << std::hex << (uint16_t) f.typeOfService << std::dec
79  << " typeOfServiceMask: 0x" << std::hex << (uint16_t) f.typeOfServiceMask << std::dec;
80  return os;
81 }
82 
84 : precedence (255),
85  direction (BIDIRECTIONAL),
86  remoteMask ("0.0.0.0"),
87  localMask ("0.0.0.0"),
88  remotePortStart (0),
89  remotePortEnd (65535),
90  localPortStart (0),
91  localPortEnd (65535),
92  typeOfService (0),
93  typeOfServiceMask (0)
94 {
95  NS_LOG_FUNCTION (this);
96 }
97 
98 bool
100  Ipv4Address ra,
101  Ipv4Address la,
102  uint16_t rp,
103  uint16_t lp,
104  uint8_t tos)
105 {
106  NS_LOG_FUNCTION (this << d << ra << la << rp << lp << (uint16_t) tos);
107  if (d & direction)
108  {
109  NS_LOG_LOGIC ("d matches");
110  if (remoteMask.IsMatch (remoteAddress, ra))
111  {
112  NS_LOG_LOGIC ("ra matches");
113  if (localMask.IsMatch (localAddress, la))
114  {
115  NS_LOG_LOGIC ("ls matches");
116  if (rp >= remotePortStart)
117  {
118  NS_LOG_LOGIC ("rps matches");
119  if (rp <= remotePortEnd)
120  {
121  NS_LOG_LOGIC ("rpe matches");
122  if (lp >= localPortStart)
123  {
124  NS_LOG_LOGIC ("lps matches");
125  if (lp <= localPortEnd)
126  {
127  NS_LOG_LOGIC ("lpe matches");
128  if ((tos & typeOfServiceMask) == (typeOfService & typeOfServiceMask))
129  {
130  NS_LOG_LOGIC ("tos matches --> have match!");
131  return true;
132  }
133  }
134  }
135  }
136  }
137  }
138  else
139  {
140  NS_LOG_LOGIC ("la doesn't match: la=" << la << " f.la=" << localAddress << " f.lmask=" << localMask);
141  }
142  }
143  else
144  {
145  NS_LOG_LOGIC ("ra doesn't match: ra=" << ra << " f.ra=" << remoteAddress << " f.rmask=" << remoteMask);
146  }
147  }
148  else
149  {
150  NS_LOG_LOGIC ("d doesn't match: d=0x" << std::hex << d << " f.d=0x" << std::hex << direction << std::dec);
151  }
152  return false;
153 }
154 
155 bool
157  Ipv6Address ra,
158  Ipv6Address la,
159  uint16_t rp,
160  uint16_t lp,
161  uint8_t tos)
162 {
163  NS_LOG_FUNCTION (this << d << ra << la << rp << lp << (uint16_t) tos);
164  if (d & direction)
165  {
166  NS_LOG_LOGIC ("d matches");
167  if (rp >= remotePortStart)
168  {
169  NS_LOG_LOGIC ("rps matches");
170  if (rp <= remotePortEnd)
171  {
172  NS_LOG_LOGIC ("rpe matches");
173  if (lp >= localPortStart)
174  {
175  NS_LOG_LOGIC ("lps matches");
176  if (lp <= localPortEnd)
177  {
178  NS_LOG_LOGIC ("lpe matches");
179  if ((tos & typeOfServiceMask) == (typeOfService & typeOfServiceMask))
180  {
181  NS_LOG_LOGIC ("tos matches --> have match!");
182  return true;
183  }
184  }
185  }
186  }
187 
188 
189  else
190  {
191  NS_LOG_LOGIC ("la doesn't match: la=" << la << " f.la=" << localAddress << " f.lmask=" << localMask);
192  }
193  }
194  else
195  {
196  NS_LOG_LOGIC ("ra doesn't match: ra=" << ra << " f.ra=" << remoteAddress << " f.rmask=" << remoteMask);
197  }
198  }
199  else
200  {
201  NS_LOG_LOGIC ("d doesn't match: d=0x" << std::hex << d << " f.d=0x" << std::hex << direction << std::dec);
202  }
203  return false;
204 }
205 
206 
209 {
210  Ptr<EpcTft> tft = Create<EpcTft> ();
211  EpcTft::PacketFilter defaultPacketFilter;
212  tft->Add (defaultPacketFilter);
213  return tft;
214 }
215 
216 
218 : m_numFilters (0)
219 {
220  NS_LOG_FUNCTION (this);
221 }
222 
223 uint8_t
225 {
226  NS_LOG_FUNCTION (this << f);
227  NS_ABORT_IF (m_numFilters >= 16);
228 
229  std::list<PacketFilter>::iterator it;
230  for (it = m_filters.begin ();
231  (it != m_filters.end ()) && (it->precedence <= f.precedence);
232  ++it)
233  {
234  }
235  m_filters.insert (it, f);
236  ++m_numFilters;
237  return (m_numFilters - 1);
238 }
239 
240 bool
242  Ipv4Address remoteAddress,
243  Ipv4Address localAddress,
244  uint16_t remotePort,
245  uint16_t localPort,
246  uint8_t typeOfService)
247 {
248  NS_LOG_FUNCTION (this << direction << remoteAddress << localAddress << std::dec << remotePort << localPort << (uint16_t) typeOfService);
249  for (std::list<PacketFilter>::iterator it = m_filters.begin ();
250  it != m_filters.end ();
251  ++it)
252  {
253  if (it->Matches (direction, remoteAddress, localAddress, remotePort, localPort, typeOfService))
254  {
255  return true;
256  }
257  }
258  return false;
259 }
260 
261 bool
263  Ipv6Address remoteAddress,
264  Ipv6Address localAddress,
265  uint16_t remotePort,
266  uint16_t localPort,
267  uint8_t typeOfService)
268 {
269  NS_LOG_FUNCTION (this << direction << remoteAddress << localAddress << std::dec << remotePort << localPort << (uint16_t) typeOfService);
270  for (std::list<PacketFilter>::iterator it = m_filters.begin ();
271  it != m_filters.end ();
272  ++it)
273  {
274  if (it->Matches (direction, remoteAddress, localAddress, remotePort, localPort, typeOfService))
275  {
276  return true;
277  }
278  }
279  return false;
280 }
281 
282 
283 } // namespace ns3
Direction
Indicates the direction of the traffic that is to be classified.
Definition: epc-tft.h:57
std::list< PacketFilter > m_filters
packet filter list
Definition: epc-tft.h:197
uint8_t Add(PacketFilter f)
add a PacketFilter to the Traffic Flow Template
Definition: epc-tft.cc:224
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:73
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by "...
bool IsMatch(Ipv4Address a, Ipv4Address b) const
Direction direction
whether the filter needs to be applied to uplink / downlink only, or in both cases ...
Definition: epc-tft.h:124
static Ptr< EpcTft > Default()
creates a TFT matching any traffic
Definition: epc-tft.cc:208
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:202
uint16_t localPortEnd
end of the port number range of the UE
Definition: epc-tft.h:137
Ipv6Address localAddress6
IPv6 address of the UE.
Definition: epc-tft.h:131
bool Matches(Direction d, Ipv4Address ra, Ipv4Address la, uint16_t rp, uint16_t lp, uint8_t tos)
Definition: epc-tft.cc:99
Ipv4Mask localMask
IPv4 address mask of the UE.
Definition: epc-tft.h:132
std::ostream & operator<<(std::ostream &os, const Angles &a)
print a struct Angles to output
Definition: angles.cc:42
Ipv4Address remoteAddress
IPv4 address of the remote host.
Definition: epc-tft.h:127
double f(double x, void *params)
Definition: 80211b.c:70
uint16_t remotePortEnd
end of the port number range of the remote host
Definition: epc-tft.h:135
Every class exported by the ns3 library is enclosed in the ns3 namespace.
uint8_t typeOfService
type of service field
Definition: epc-tft.h:139
Ipv4Address localAddress
IPv4 address of the UE.
Definition: epc-tft.h:130
NS_LOG_LOGIC("Net device "<< nd<< " is not bridged")
#define NS_ABORT_IF(cond)
Abnormal program termination if a condition is true.
Definition: abort.h:77
Describes an IPv6 address.
Definition: ipv6-address.h:49
Ipv4 addresses are stored in host order in this class.
Definition: ipv4-address.h:40
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:118
Ipv6Address remoteAddress6
IPv6 address of the remote host.
Definition: epc-tft.h:128
Ipv4Mask remoteMask
IPv4 address mask of the remote host.
Definition: epc-tft.h:129
uint8_t typeOfServiceMask
type of service field mask
Definition: epc-tft.h:140
bool Matches(Direction direction, Ipv4Address remoteAddress, Ipv4Address localAddress, uint16_t remotePort, uint16_t localPort, uint8_t typeOfService)
Definition: epc-tft.cc:241
uint16_t remotePortStart
start of the port number range of the remote host
Definition: epc-tft.h:134
uint8_t m_numFilters
number of packet filters applied to this TFT
Definition: epc-tft.h:198
Implement the data structure representing a TrafficFlowTemplate Packet Filter.
Definition: epc-tft.h:74
uint16_t localPortStart
start of the port number range of the UE
Definition: epc-tft.h:136