1 /* -*-  Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2011 Centre Tecnologic de Telecomunicacions de Catalunya (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 #ifndef EPC_TFT_H
23 #define EPC_TFT_H
24 
25 
26 #include <ns3/simple-ref-count.h>
27 #include <ns3/ipv4-address.h>
28 #include <ns3/ipv6-address.h>
29 
30 #include <list>
31 
32 namespace ns3 {
33 
34 
35 
36 /**
37  * This class implements the EPS bearer Traffic Flow Template (TFT),
38  * which is the set of all packet filters associated with an EPS bearer.
39  *
40  */
41 class EpcTft : public SimpleRefCount<EpcTft>
42 {
43 
44 public:
45 
46 
47   /**
48    * creates a TFT matching any traffic
49    *
50    * \return a newly created TFT that will match any traffic
51    */
52   static Ptr<EpcTft> Default ();
53 
54   /**
55    * Indicates the direction of the traffic that is to be classified.
56    */
57   enum Direction {DOWNLINK = 1,
58 		  UPLINK = 2,
59 		  BIDIRECTIONAL = 3};
60 
61   /**
62    * Implement the data structure representing a TrafficFlowTemplate
63    * Packet Filter.
64    * See 3GPP TS 24.008 version 8.7.0 Release 8, Table 10.5.162/3GPP TS
65    * 24.008: Traffic flow template information element
66    *
67    * With respect to the Packet Filter specification in the above doc,
68    * the following features are NOT supported:
69    *  - IPv6 filtering (including flow labels)
70    *  - IPSec filtering
71    *  - filter precedence field is not evaluated, hence it is recommended to setup
72    *    the TFTs within a PDP context such that TFTs are mutually exclusive
73    */
74   struct PacketFilter
75   {
76     PacketFilter ();
77 
78     /**
79      *
80      * \param d the direction
81      * \param ra the remote address
82      * \param la the local address
83      * \param rp the remote port
84      * \param lp the local port
85      * \param tos the type of service
86      *
87      * \return true if the parameters match with the PacketFilter,
88      * false otherwise.
89      */
90     bool Matches (Direction d,
91 		  Ipv4Address ra,
92 		  Ipv4Address la,
93 		  uint16_t rp,
94 		  uint16_t lp,
95 		  uint8_t tos);
96 
97     /**
98      *
99      * \param d the direction
100      * \param ra the remote address
101      * \param la the local address
102      * \param rp the remote port
103      * \param lp the local port
104      * \param tos the type of service
105      *
106      * \return true if the parameters match with the PacketFilter,
107      * false otherwise.
108      */
109     bool Matches (Direction d,
110 		  Ipv6Address ra,
111 		  Ipv6Address la,
112 		  uint16_t rp,
113 		  uint16_t lp,
114 		  uint8_t tos);
115 
116 
117 
118     uint8_t precedence;  /**< used to specify the precedence for the
119 			  * packet filter among all packet filters in
120 			  * the TFT; higher values will be evaluated
121 			  * last.
122 			  */
123 
124     Direction direction; /**< whether the filter needs to be applied
125 			    to uplink / downlink only, or in both cases*/
126 
127     Ipv4Address remoteAddress;     /**< IPv4 address of the remote host  */
128     Ipv4Mask remoteMask;           /**< IPv4 address mask of the remote host */
129     Ipv4Address localAddress;      /**< IPv4 address of the UE */
130     Ipv4Mask localMask;            /**< IPv4 address mask of the UE */
131 
132     Ipv6Address remoteIpv6Address; /**< IPv6 address of the remote host  */
133     Ipv6Prefix remoteIpv6Prefix;   /**< IPv6 address prefix of the remote host  */
134     Ipv6Address localIpv6Address;  /**< IPv6 address of the UE */
135     Ipv6Prefix localIpv6Prefix;    /**< IPv6 address prefix of the UE */
136 
137     uint16_t remotePortStart;  /**< start of the port number range of the remote host */
138     uint16_t remotePortEnd;    /**< end of the port number range of the remote host */
139     uint16_t localPortStart;   /**< start of the port number range of the UE */
140     uint16_t localPortEnd;     /**< end of the port number range of the UE */
141 
142     uint8_t typeOfService;     /**< type of service field */
143     uint8_t typeOfServiceMask; /**< type of service field mask */
144   };
145 
146   EpcTft ();
147 
148 
149   /**
150    * add a PacketFilter to the Traffic Flow Template
151    *
152    * \param f the PacketFilter to be added
153    *
154    * \return the id( 0 <= id < 16) of the newly added filter, if the addition was successful. Will fail if you try to add more than 15 filters. This is to be compliant with TS 24.008.
155    */
156   uint8_t Add (PacketFilter f);
157 
158 
159     /**
160      *
161      * \param direction
162      * \param remoteAddress
163      * \param localAddress
164      * \param remotePort
165      * \param localPort
166      * \param typeOfService
167      *
168      * \return true if any PacketFilter in the TFT matches with the
169      * parameters, false otherwise.
170      */
171     bool Matches (Direction direction,
172 		  Ipv4Address remoteAddress,
173 		  Ipv4Address localAddress,
174 		  uint16_t remotePort,
175 		  uint16_t localPort,
176 		  uint8_t typeOfService);
177 
178     /**
179      *
180      * \param direction
181      * \param remoteAddress
182      * \param localAddress
183      * \param remotePort
184      * \param localPort
185      * \param typeOfService
186      *
187      * \return true if any PacketFilter in the TFT matches with the
188      * parameters, false otherwise.
189      */
190     bool Matches (Direction direction,
191 		  Ipv6Address remoteAddress,
192 		  Ipv6Address localAddress,
193 		  uint16_t remotePort,
194 		  uint16_t localPort,
195 		  uint8_t typeOfService);
196 
197 
198   std::list<PacketFilter> GetPacketFilters () const;
199 
200 private:
201 
202   std::list<PacketFilter> m_filters; ///< packet filter list
203   uint8_t m_numFilters; ///< number of packet filters applied to this TFT
204 
205 };
206 
207 
208 std::ostream& operator<< (std::ostream& os, EpcTft::Direction& d);
209 
210 
211 } // namespace ns3
212 
213 #endif /* EPC_TFT_H */
214 
215 
216