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  << " remoteMask: " << f.remoteMask
70  << " localAddress: " << f.localAddress
71  << " localMask: " << f.localMask
72  << " remotePortStart: " << f.remotePortStart
73  << " remotePortEnd: " << f.remotePortEnd
74  << " localPortStart: " << f.localPortStart
75  << " localPortEnd: " << f.localPortEnd
76  << " typeOfService: 0x" << std::hex << (uint16_t) f.typeOfService << std::dec
77  << " typeOfServiceMask: 0x" << std::hex << (uint16_t) f.typeOfServiceMask << std::dec;
78  return os;
79 }
80 
82  : precedence (255),
83  direction (BIDIRECTIONAL),
84  remoteMask ("0.0.0.0"),
85  localMask ("0.0.0.0"),
86  remotePortStart (0),
87  remotePortEnd (65535),
88  localPortStart (0),
89  localPortEnd (65535),
90  typeOfService (0),
91  typeOfServiceMask (0)
92 {
93  NS_LOG_FUNCTION (this);
94 }
95 
96 bool
98  Ipv4Address ra,
99  Ipv4Address la,
100  uint16_t rp,
101  uint16_t lp,
102  uint8_t tos)
103 {
104  NS_LOG_FUNCTION (this << d << ra << la << rp << lp << (uint16_t) tos);
105  if (d & direction)
106  {
107  NS_LOG_LOGIC ("d matches");
108  if (remoteMask.IsMatch (remoteAddress, ra))
109  {
110  NS_LOG_LOGIC ("ra matches");
111  if (localMask.IsMatch (localAddress, la))
112  {
113  NS_LOG_LOGIC ("ls matches");
114  if (rp >= remotePortStart)
115  {
116  NS_LOG_LOGIC ("rps matches");
117  if (rp <= remotePortEnd)
118  {
119  NS_LOG_LOGIC ("rpe matches");
120  if (lp >= localPortStart)
121  {
122  NS_LOG_LOGIC ("lps matches");
123  if (lp <= localPortEnd)
124  {
125  NS_LOG_LOGIC ("lpe matches");
126  if ((tos & typeOfServiceMask) == (typeOfService & typeOfServiceMask))
127  {
128  NS_LOG_LOGIC ("tos matches --> have match!");
129  return true;
130  }
131  }
132  }
133  }
134  }
135  }
136  else
137  {
138  NS_LOG_LOGIC ("la doesn't match: la=" << la << " f.la=" << localAddress << " f.lmask=" << localMask);
139  }
140  }
141  else
142  {
143  NS_LOG_LOGIC ("ra doesn't match: ra=" << ra << " f.ra=" << remoteAddress << " f.rmask=" << remoteMask);
144  }
145  }
146  else
147  {
148  NS_LOG_LOGIC ("d doesn't match: d=0x" << std::hex << d << " f.d=0x" << std::hex << direction << std::dec);
149  }
150  return false;
151 }
152 
153 
156 {
157  Ptr<EpcTft> tft = Create<EpcTft> ();
158  EpcTft::PacketFilter defaultPacketFilter;
159  tft->Add (defaultPacketFilter);
160  return tft;
161 }
162 
163 
165  : m_numFilters (0)
166 {
167  NS_LOG_FUNCTION (this);
168 }
169 
170 uint8_t
172 {
173  NS_LOG_FUNCTION (this << f);
174  NS_ABORT_IF (m_numFilters >= 16);
175 
176  std::list<PacketFilter>::iterator it;
177  for (it = m_filters.begin ();
178  (it != m_filters.end ()) && (it->precedence <= f.precedence);
179  ++it)
180  {
181  }
182  m_filters.insert (it, f);
183  ++m_numFilters;
184  return (m_numFilters - 1);
185 }
186 
187 bool
189  Ipv4Address remoteAddress,
190  Ipv4Address localAddress,
191  uint16_t remotePort,
192  uint16_t localPort,
193  uint8_t typeOfService)
194 {
195  NS_LOG_FUNCTION (this << direction << remoteAddress << localAddress << std::dec << remotePort << localPort << (uint16_t) typeOfService);
196  for (std::list<PacketFilter>::iterator it = m_filters.begin ();
197  it != m_filters.end ();
198  ++it)
199  {
200  if (it->Matches (direction, remoteAddress, localAddress, remotePort, localPort, typeOfService))
201  {
202  return true;
203  }
204  }
205  return false;
206 }
207 
208 
209 } // namespace ns3
Direction
Indicates the direction of the traffic that is to be classified.
Definition: epc-tft.h:56
std::list< PacketFilter > m_filters
packet filter list
Definition: epc-tft.h:156
uint8_t Add(PacketFilter f)
add a PacketFilter to the Traffic Flow Template
Definition: epc-tft.cc:171
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 "...
Direction direction
whether the filter needs to be applied to uplink / downlink only, or in both cases ...
Definition: epc-tft.h:104
static Ptr< EpcTft > Default()
creates a TFT matching any traffic
Definition: epc-tft.cc:155
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:201
uint16_t localPortEnd
end of the port number range of the UE
Definition: epc-tft.h:115
bool Matches(Direction d, Ipv4Address ra, Ipv4Address la, uint16_t rp, uint16_t lp, uint8_t tos)
Definition: epc-tft.cc:97
Ipv4Mask localMask
IPv4 address mask of the UE.
Definition: epc-tft.h:110
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:107
double f(double x, void *params)
Definition: 80211b.c:72
uint16_t remotePortEnd
end of the port number range of the remote host
Definition: epc-tft.h:113
Every class exported by the ns3 library is enclosed in the ns3 namespace.
uint8_t typeOfService
type of service field
Definition: epc-tft.h:117
Ipv4Address localAddress
IPv4 address of the UE.
Definition: epc-tft.h:109
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
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:98
Ipv4Mask remoteMask
IPv4 address mask of the remote host.
Definition: epc-tft.h:108
uint8_t typeOfServiceMask
type of service field mask
Definition: epc-tft.h:118
bool Matches(Direction direction, Ipv4Address remoteAddress, Ipv4Address localAddress, uint16_t remotePort, uint16_t localPort, uint8_t typeOfService)
Definition: epc-tft.cc:188
uint16_t remotePortStart
start of the port number range of the remote host
Definition: epc-tft.h:112
uint8_t m_numFilters
number of packet filters applied to this TFT
Definition: epc-tft.h:157
Implement the data structure representing a TrafficFlowTemplate Packet Filter.
Definition: epc-tft.h:73
uint16_t localPortStart
start of the port number range of the UE
Definition: epc-tft.h:114