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 
34 std::ostream& operator<< (std::ostream& os, EpcTft::Direction& d)
35 {
36  switch (d)
37  {
38  case EpcTft::DOWNLINK:
39  os << "DOWNLINK";
40  break;
41  case EpcTft::UPLINK:
42  os << "UPLINK";
43  break;
44  default:
45  os << "BIDIRECTIONAL";
46  break;
47  }
48  return os;
49 }
50 
51 
52 std::ostream& operator<< (std::ostream& os, EpcTft::PacketFilter& f)
53 {
54  os << " direction: " << f.direction
55  << " remoteAddress: " << f.remoteAddress
56  << " remoteMask: " << f.remoteMask
57  << " localAddress: " << f.localAddress
58  << " localMask: " << f.localMask
59  << " remotePortStart: " << f.remotePortStart
60  << " remotePortEnd: " << f.remotePortEnd
61  << " localPortStart: " << f.localPortStart
62  << " localPortEnd: " << f.localPortEnd
63  << " typeOfService: 0x" << std::hex << (uint16_t) f.typeOfService << std::dec
64  << " typeOfServiceMask: 0x" << std::hex << (uint16_t) f.typeOfServiceMask << std::dec;
65  return os;
66 }
67 
69  : precedence (255),
70  direction (BIDIRECTIONAL),
71  remoteMask ("0.0.0.0"),
72  localMask ("0.0.0.0"),
73  remotePortStart (0),
74  remotePortEnd (65535),
75  localPortStart (0),
76  localPortEnd (65535),
77  typeOfService (0),
78  typeOfServiceMask (0)
79 {
80  NS_LOG_FUNCTION (this);
81 }
82 
83 bool
85  Ipv4Address ra,
86  Ipv4Address la,
87  uint16_t rp,
88  uint16_t lp,
89  uint8_t tos)
90 {
91  NS_LOG_FUNCTION (this << d << ra << la << rp << lp << (uint16_t) tos);
92  if (d & direction)
93  {
94  NS_LOG_LOGIC ("d matches");
95  if (remoteMask.IsMatch (remoteAddress, ra))
96  {
97  NS_LOG_LOGIC ("ra matches");
98  if (localMask.IsMatch (localAddress, la))
99  {
100  NS_LOG_LOGIC ("ls matches");
101  if (rp >= remotePortStart)
102  {
103  NS_LOG_LOGIC ("rps matches");
104  if (rp <= remotePortEnd)
105  {
106  NS_LOG_LOGIC ("rpe matches");
107  if (lp >= localPortStart)
108  {
109  NS_LOG_LOGIC ("lps matches");
110  if (lp <= localPortEnd)
111  {
112  NS_LOG_LOGIC ("lpe matches");
113  if ((tos & typeOfServiceMask) == (typeOfService & typeOfServiceMask))
114  {
115  NS_LOG_LOGIC ("tos matches --> have match!");
116  return true;
117  }
118  }
119  }
120  }
121  }
122  }
123  else
124  {
125  NS_LOG_LOGIC ("la doesn't match: la=" << la << " f.la=" << localAddress << " f.lmask=" << localMask);
126  }
127  }
128  else
129  {
130  NS_LOG_LOGIC ("ra doesn't match: ra=" << ra << " f.ra=" << remoteAddress << " f.rmask=" << remoteMask);
131  }
132  }
133  else
134  {
135  NS_LOG_LOGIC ("d doesn't match: d=0x" << std::hex << d << " f.d=0x" << std::hex << direction << std::dec);
136  }
137  return false;
138 }
139 
140 
143 {
144  Ptr<EpcTft> tft = Create<EpcTft> ();
145  EpcTft::PacketFilter defaultPacketFilter;
146  tft->Add (defaultPacketFilter);
147  return tft;
148 }
149 
150 
152  : m_numFilters (0)
153 {
154  NS_LOG_FUNCTION (this);
155 }
156 
157 uint8_t
159 {
160  NS_LOG_FUNCTION (this << f);
161  NS_ABORT_IF (m_numFilters >= 16);
162 
163  std::list<PacketFilter>::iterator it;
164  for (it = m_filters.begin ();
165  (it != m_filters.end ()) && (it->precedence <= f.precedence);
166  ++it)
167  {
168  }
169  m_filters.insert (it, f);
170  ++m_numFilters;
171  return (m_numFilters - 1);
172 }
173 
174 bool
176  Ipv4Address remoteAddress,
177  Ipv4Address localAddress,
178  uint16_t remotePort,
179  uint16_t localPort,
180  uint8_t typeOfService)
181 {
182  NS_LOG_FUNCTION (this << direction << remoteAddress << localAddress << std::dec << remotePort << localPort << (uint16_t) typeOfService);
183  for (std::list<PacketFilter>::iterator it = m_filters.begin ();
184  it != m_filters.end ();
185  ++it)
186  {
187  if (it->Matches (direction, remoteAddress, localAddress, remotePort, localPort, typeOfService))
188  {
189  return true;
190  }
191  }
192  return false;
193 }
194 
195 
196 } // 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:158
smart pointer class similar to boost::intrusive_ptr
Definition: ptr.h:59
#define NS_LOG_FUNCTION(parameters)
Definition: log.h:345
NS_LOG_COMPONENT_DEFINE("GrantedTimeWindowMpiInterface")
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:142
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:84
Ipv4Mask localMask
IPv4 address mask of the UE.
Definition: epc-tft.h:110
#define NS_LOG_LOGIC(msg)
Definition: log.h:368
#define NS_ABORT_IF(cond)
Abnormal program termination if cond is true.
Definition: abort.h:69
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
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:175
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