A Discrete-Event Network Simulator
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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 
33 std::ostream& operator<< (std::ostream& os, EpcTft::Direction& d)
34 {
35  switch (d)
36  {
37  case EpcTft::DOWNLINK:
38  os << "DOWNLINK";
39  break;
40  case EpcTft::UPLINK:
41  os << "UPLINK";
42  break;
43  default:
44  os << "BIDIRECTIONAL";
45  break;
46  }
47  return os;
48 }
49 
50 
51 std::ostream& operator<< (std::ostream& os, EpcTft::PacketFilter& f)
52 {
53  os << " direction: " << f.direction
54  << " remoteAddress: " << f.remoteAddress
55  << " remoteMask: " << f.remoteMask
56  << " localAddress: " << f.localAddress
57  << " localMask: " << f.localMask
58  << " remotePortStart: " << f.remotePortStart
59  << " remotePortEnd: " << f.remotePortEnd
60  << " localPortStart: " << f.localPortStart
61  << " localPortEnd: " << f.localPortEnd
62  << " typeOfService: 0x" << std::hex << (uint16_t) f.typeOfService << std::dec
63  << " typeOfServiceMask: 0x" << std::hex << (uint16_t) f.typeOfServiceMask << std::dec;
64  return os;
65 }
66 
68  : precedence (255),
69  direction (BIDIRECTIONAL),
70  remoteMask ("0.0.0.0"),
71  localMask ("0.0.0.0"),
72  remotePortStart (0),
73  remotePortEnd (65535),
74  localPortStart (0),
75  localPortEnd (65535),
76  typeOfService (0),
77  typeOfServiceMask (0)
78 {
79  NS_LOG_FUNCTION (this);
80 }
81 
82 bool
84  Ipv4Address ra,
85  Ipv4Address la,
86  uint16_t rp,
87  uint16_t lp,
88  uint8_t tos)
89 {
90  NS_LOG_FUNCTION (this << d << ra << la << rp << lp << (uint16_t) tos);
91  if (d & direction)
92  {
93  NS_LOG_LOGIC ("d matches");
94  if (remoteMask.IsMatch (remoteAddress, ra))
95  {
96  NS_LOG_LOGIC ("ra matches");
97  if (localMask.IsMatch (localAddress, la))
98  {
99  NS_LOG_LOGIC ("ls matches");
100  if (rp >= remotePortStart)
101  {
102  NS_LOG_LOGIC ("rps matches");
103  if (rp <= remotePortEnd)
104  {
105  NS_LOG_LOGIC ("rpe matches");
106  if (lp >= localPortStart)
107  {
108  NS_LOG_LOGIC ("lps matches");
109  if (lp <= localPortEnd)
110  {
111  NS_LOG_LOGIC ("lpe matches");
112  if ((tos & typeOfServiceMask) == (typeOfService & typeOfServiceMask))
113  {
114  NS_LOG_LOGIC ("tos matches --> have match!");
115  return true;
116  }
117  }
118  }
119  }
120  }
121  }
122  else
123  {
124  NS_LOG_LOGIC ("la doesn't match: la=" << la << " f.la=" << localAddress << " f.lmask=" << localMask);
125  }
126  }
127  else
128  {
129  NS_LOG_LOGIC ("ra doesn't match: ra=" << ra << " f.ra=" << remoteAddress << " f.rmask=" << remoteMask);
130  }
131  }
132  else
133  {
134  NS_LOG_LOGIC ("d doesn't match: d=0x" << std::hex << d << " f.d=0x" << std::hex << direction << std::dec);
135  }
136  return false;
137 }
138 
139 
142 {
143  Ptr<EpcTft> tft = Create<EpcTft> ();
144  EpcTft::PacketFilter defaultPacketFilter;
145  tft->Add (defaultPacketFilter);
146  return tft;
147 }
148 
149 
151  : m_numFilters (0)
152 {
153  NS_LOG_FUNCTION (this);
154 }
155 
156 uint8_t
158 {
159  NS_LOG_FUNCTION (this << f);
160  NS_ABORT_IF (m_numFilters >= 16);
161 
162  std::list<PacketFilter>::iterator it;
163  for (it = m_filters.begin ();
164  (it != m_filters.end ()) && (it->precedence <= f.precedence);
165  ++it)
166  {
167  }
168  m_filters.insert (it, f);
169  ++m_numFilters;
170  return (m_numFilters - 1);
171 }
172 
173 bool
175  Ipv4Address remoteAddress,
176  Ipv4Address localAddress,
177  uint16_t remotePort,
178  uint16_t localPort,
179  uint8_t typeOfService)
180 {
181  NS_LOG_FUNCTION (this << direction << remoteAddress << localAddress << std::dec << remotePort << localPort << (uint16_t) typeOfService);
182  for (std::list<PacketFilter>::iterator it = m_filters.begin ();
183  it != m_filters.end ();
184  ++it)
185  {
186  if (it->Matches (direction, remoteAddress, localAddress, remotePort, localPort, typeOfService))
187  {
188  return true;
189  }
190  }
191  return false;
192 }
193 
194 
195 } // namespace ns3
Direction
Indicates the direction of the traffic that is to be classified.
Definition: epc-tft.h:56
std::list< PacketFilter > m_filters
Definition: epc-tft.h:156
uint8_t Add(PacketFilter f)
add a PacketFilter to the Traffic Flow Template
Definition: epc-tft.cc:157
smart pointer class similar to boost::intrusive_ptr
Definition: ptr.h:60
#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:141
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:170
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:83
Ipv4Mask localMask
IPv4 address mask of the UE.
Definition: epc-tft.h:110
#define NS_LOG_LOGIC(msg)
Use NS_LOG to output a message of level LOG_LOGIC.
Definition: log.h:233
std::ostream & operator<<(std::ostream &os, const Angles &a)
print a struct Angles to output
Definition: angles.cc:43
Ipv4Address remoteAddress
IPv4 address of the remote host.
Definition: epc-tft.h:107
uint16_t remotePortEnd
end of the port number range of the remote host
Definition: epc-tft.h:113
uint8_t typeOfService
type of service field
Definition: epc-tft.h:117
Ipv4Address localAddress
IPv4 address of the UE.
Definition: epc-tft.h:109
#define NS_ABORT_IF(cond)
Abnormal program termination if cond is true.
Definition: abort.h:71
Ipv4 addresses are stored in host order in this class.
Definition: ipv4-address.h:38
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:174
uint16_t remotePortStart
start of the port number range of the remote host
Definition: epc-tft.h:112
uint8_t m_numFilters
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