A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
epc-pgw-application.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2018 Centre Tecnologic de Telecomunicacions de Catalunya (CTTC)
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation;
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, write to the Free Software
15 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 *
17 * Author: Manuel Requena <manuel.requena@cttc.es>
18 * (based on epc-sgw-pgw-application.h)
19 */
20
21#ifndef EPC_PGW_APPLICATION_H
22#define EPC_PGW_APPLICATION_H
23
24#include "epc-gtpc-header.h"
25#include "epc-tft-classifier.h"
26
27#include "ns3/application.h"
28#include "ns3/socket.h"
29#include "ns3/virtual-net-device.h"
30
31namespace ns3
32{
33
34/**
35 * \ingroup lte
36 *
37 * This application implements the Packet Data Network (PDN) Gateway Entity (PGW)
38 * according to the 3GPP TS 23.401 document.
39 *
40 * This Application implements the PGW side of the S5 interface between
41 * the PGW node and the SGW nodes and the PGW side of the SGi interface between
42 * the PGW node and the internet hosts. It supports the following functions and messages:
43 *
44 * - S5 connectivity (i.e. GTPv2-C signalling and GTP-U data plane)
45 * - Bearer management functions including dedicated bearer establishment
46 * - Per-user based packet filtering
47 * - UL and DL bearer binding
48 * - Tunnel Management messages
49 *
50 * Others functions enumerated in section 4.4.3.3 of 3GPP TS 23.401 are not supported.
51 */
53{
54 public:
55 /**
56 * \brief Get the type ID.
57 * \return the object TypeId
58 */
59 static TypeId GetTypeId();
60 void DoDispose() override;
61
62 /**
63 * Constructor that binds the tap device to the callback methods.
64 *
65 * \param tunDevice TUN VirtualNetDevice used to tunnel IP packets from
66 * the SGi interface of the PGW in the internet
67 * over GTP-U/UDP/IP on the S5 interface
68 * \param s5Addr IP address of the PGW S5 interface
69 * \param s5uSocket socket used to send GTP-U packets to the peer SGW
70 * \param s5cSocket socket used to send GTP-C packets to the peer SGW
71 */
73 Ipv4Address s5Addr,
74 const Ptr<Socket> s5uSocket,
75 const Ptr<Socket> s5cSocket);
76
77 /** Destructor */
78 ~EpcPgwApplication() override;
79
80 /**
81 * Method to be assigned to the callback of the SGi TUN VirtualNetDevice.
82 * It is called when the PGW receives a data packet from the
83 * internet (including IP headers) that is to be sent to the UE via
84 * its associated SGW and eNB, tunneling IP over GTP-U/UDP/IP.
85 *
86 * \param packet
87 * \param source
88 * \param dest
89 * \param protocolNumber
90 * \return true always
91 */
93 const Address& source,
94 const Address& dest,
95 uint16_t protocolNumber);
96
97 /**
98 * Method to be assigned to the receiver callback of the S5-U socket.
99 * It is called when the PGW receives a data packet from the SGW
100 * that is to be forwarded to the internet.
101 *
102 * \param socket pointer to the S5-U socket
103 */
104 void RecvFromS5uSocket(Ptr<Socket> socket);
105
106 /**
107 * Method to be assigned to the receiver callback of the S5-C socket.
108 * It is called when the PGW receives a control packet from the SGW.
109 *
110 * \param socket pointer to the S5-C socket
111 */
112 void RecvFromS5cSocket(Ptr<Socket> socket);
113
114 /**
115 * Send a data packet to the internet via the SGi interface of the PGW
116 *
117 * \param packet packet to be sent
118 * \param teid the Tunnel Endpoint Identifier
119 */
120 void SendToTunDevice(Ptr<Packet> packet, uint32_t teid);
121
122 /**
123 * Send a data packet to the SGW via the S5-U interface
124 *
125 * \param packet packet to be sent
126 * \param sgwS5uAddress the address of the SGW
127 * \param teid the Tunnel Endpoint Identifier
128 */
129 void SendToS5uSocket(Ptr<Packet> packet, Ipv4Address sgwS5uAddress, uint32_t teid);
130
131 /**
132 * Let the PGW be aware of a new SGW
133 *
134 * \param sgwS5Addr the address of the SGW S5 interface
135 */
136 void AddSgw(Ipv4Address sgwS5Addr);
137
138 /**
139 * Let the PGW be aware of a new UE
140 *
141 * \param imsi the unique identifier of the UE
142 */
143 void AddUe(uint64_t imsi);
144
145 /**
146 * Set the address of a previously added UE
147 *
148 * \param imsi the unique identifier of the UE
149 * \param ueAddr the IPv4 address of the UE
150 */
151 void SetUeAddress(uint64_t imsi, Ipv4Address ueAddr);
152
153 /**
154 * set the address of a previously added UE
155 *
156 * \param imsi the unique identifier of the UE
157 * \param ueAddr the IPv6 address of the UE
158 */
159 void SetUeAddress6(uint64_t imsi, Ipv6Address ueAddr);
160
161 /**
162 * TracedCallback signature for data Packet reception event.
163 *
164 * \param [in] packet The data packet sent from the internet.
165 */
166 typedef void (*RxTracedCallback)(Ptr<Packet> packet);
167
168 private:
169 /**
170 * Process Create Session Request message
171 * \param packet GTPv2-C Create Session Request message
172 */
174
175 /**
176 * Process Modify Bearer Request message
177 * \param packet GTPv2-C Modify Bearer Request message
178 */
180
181 /**
182 * Process Delete Bearer Command message
183 * \param packet GTPv2-C Delete Bearer Command message
184 */
186
187 /**
188 * Process Delete Bearer Response message
189 * \param packet GTPv2-C Delete Bearer Response message
190 */
192
193 /**
194 * store info for each UE connected to this PGW
195 */
196 class UeInfo : public SimpleRefCount<UeInfo>
197 {
198 public:
199 UeInfo();
200
201 /**
202 * Add a bearer for this UE on PGW side
203 *
204 * \param bearerId the ID of the EPS Bearer to be activated
205 * \param teid the TEID of the new bearer
206 * \param tft the Traffic Flow Template of the new bearer to be added
207 */
208 void AddBearer(uint8_t bearerId, uint32_t teid, Ptr<EpcTft> tft);
209
210 /**
211 * Delete context of bearer for this UE on PGW side
212 *
213 * \param bearerId the ID of the EPS Bearer whose contexts is to be removed
214 */
215 void RemoveBearer(uint8_t bearerId);
216
217 /**
218 * Classify the packet according to TFTs of this UE
219 *
220 * \param p the IPv4 or IPv6 packet from the internet to be classified
221 * \param protocolNumber identifies the type of packet.
222 * Only IPv4 and IPv6 packets are allowed.
223 *
224 * \return the corresponding bearer ID > 0 identifying the bearer
225 * among all the bearers of this UE; returns 0 if no bearers
226 * matches with the previously declared TFTs
227 */
228 uint32_t Classify(Ptr<Packet> p, uint16_t protocolNumber);
229
230 /**
231 * Get the address of the SGW to which the UE is connected
232 *
233 * \return the address of the SGW
234 */
236
237 /**
238 * Set the address of the eNB to which the UE is connected
239 *
240 * \param addr the address of the SGW
241 */
242 void SetSgwAddr(Ipv4Address addr);
243
244 /**
245 * Get the IPv4 address of the UE
246 *
247 * \return the IPv4 address of the UE
248 */
250
251 /**
252 * Set the IPv4 address of the UE
253 *
254 * \param addr the IPv4 address of the UE
255 */
256 void SetUeAddr(Ipv4Address addr);
257
258 /**
259 * Get the IPv6 address of the UE
260 *
261 * \return the IPv6 address of the UE
262 */
264
265 /**
266 * Set the IPv6 address of the UE
267 *
268 * \param addr the IPv6 address of the UE
269 */
270 void SetUeAddr6(Ipv6Address addr);
271
272 private:
273 Ipv4Address m_ueAddr; ///< UE IPv4 address
274 Ipv6Address m_ueAddr6; ///< UE IPv6 address
275 Ipv4Address m_sgwAddr; ///< SGW IPv4 address
277 std::map<uint8_t, uint32_t> m_teidByBearerIdMap; ///< TEID By bearer ID Map
278 };
279
280 /**
281 * PGW address of the S5 interface
282 */
284
285 /**
286 * UDP socket to send/receive GTP-U packets to/from the S5 interface
287 */
289
290 /**
291 * UDP socket to send/receive GTPv2-C packets to/from the S5 interface
292 */
294
295 /**
296 * TUN VirtualNetDevice used for tunneling/detunneling IP packets
297 * from/to the internet over GTP-U/UDP/IP on the S5 interface
298 */
300
301 /**
302 * UeInfo stored by UE IPv4 address
303 */
304 std::map<Ipv4Address, Ptr<UeInfo>> m_ueInfoByAddrMap;
305
306 /**
307 * UeInfo stored by UE IPv6 address
308 */
309 std::map<Ipv6Address, Ptr<UeInfo>> m_ueInfoByAddrMap6;
310
311 /**
312 * UeInfo stored by IMSI
313 */
314 std::map<uint64_t, Ptr<UeInfo>> m_ueInfoByImsiMap;
315
316 /**
317 * UDP port to be used for GTP-U
318 */
320
321 /**
322 * UDP port to be used for GTPv2-C
323 */
325
326 /**
327 * SGW address of the S5 interface
328 */
330
331 /**
332 * \brief Callback to trace received data packets at Tun NetDevice from internet.
333 */
335
336 /**
337 * \brief Callback to trace received data packets from S5 socket.
338 */
340};
341
342} // namespace ns3
343
344#endif // EPC_PGW_APPLICATION_H
a polymophic address class
Definition: address.h:101
The base class for all ns3 applications.
Definition: application.h:62
store info for each UE connected to this PGW
Ipv6Address GetUeAddr6()
Get the IPv6 address of the UE.
uint32_t Classify(Ptr< Packet > p, uint16_t protocolNumber)
Classify the packet according to TFTs of this UE.
void SetUeAddr(Ipv4Address addr)
Set the IPv4 address of the UE.
Ipv4Address GetSgwAddr()
Get the address of the SGW to which the UE is connected.
EpcTftClassifier m_tftClassifier
TFT classifier.
void RemoveBearer(uint8_t bearerId)
Delete context of bearer for this UE on PGW side.
Ipv4Address m_sgwAddr
SGW IPv4 address.
Ipv4Address m_ueAddr
UE IPv4 address.
std::map< uint8_t, uint32_t > m_teidByBearerIdMap
TEID By bearer ID Map.
Ipv6Address m_ueAddr6
UE IPv6 address.
Ipv4Address GetUeAddr()
Get the IPv4 address of the UE.
void SetUeAddr6(Ipv6Address addr)
Set the IPv6 address of the UE.
void SetSgwAddr(Ipv4Address addr)
Set the address of the eNB to which the UE is connected.
void AddBearer(uint8_t bearerId, uint32_t teid, Ptr< EpcTft > tft)
Add a bearer for this UE on PGW side.
This application implements the Packet Data Network (PDN) Gateway Entity (PGW) according to the 3GPP ...
void SendToS5uSocket(Ptr< Packet > packet, Ipv4Address sgwS5uAddress, uint32_t teid)
Send a data packet to the SGW via the S5-U interface.
void SetUeAddress6(uint64_t imsi, Ipv6Address ueAddr)
set the address of a previously added UE
void SendToTunDevice(Ptr< Packet > packet, uint32_t teid)
Send a data packet to the internet via the SGi interface of the PGW.
void AddSgw(Ipv4Address sgwS5Addr)
Let the PGW be aware of a new SGW.
TracedCallback< Ptr< Packet > > m_rxTunPktTrace
Callback to trace received data packets at Tun NetDevice from internet.
TracedCallback< Ptr< Packet > > m_rxS5PktTrace
Callback to trace received data packets from S5 socket.
std::map< Ipv6Address, Ptr< UeInfo > > m_ueInfoByAddrMap6
UeInfo stored by UE IPv6 address.
void RecvFromS5uSocket(Ptr< Socket > socket)
Method to be assigned to the receiver callback of the S5-U socket.
void DoRecvDeleteBearerResponse(Ptr< Packet > packet)
Process Delete Bearer Response message.
void RecvFromS5cSocket(Ptr< Socket > socket)
Method to be assigned to the receiver callback of the S5-C socket.
void DoRecvDeleteBearerCommand(Ptr< Packet > packet)
Process Delete Bearer Command message.
void AddUe(uint64_t imsi)
Let the PGW be aware of a new UE.
Ptr< Socket > m_s5uSocket
UDP socket to send/receive GTP-U packets to/from the S5 interface.
void DoDispose() override
Destructor implementation.
uint16_t m_gtpuUdpPort
UDP port to be used for GTP-U.
bool RecvFromTunDevice(Ptr< Packet > packet, const Address &source, const Address &dest, uint16_t protocolNumber)
Method to be assigned to the callback of the SGi TUN VirtualNetDevice.
std::map< uint64_t, Ptr< UeInfo > > m_ueInfoByImsiMap
UeInfo stored by IMSI.
Ipv4Address m_pgwS5Addr
PGW address of the S5 interface.
Ipv4Address m_sgwS5Addr
SGW address of the S5 interface.
~EpcPgwApplication() override
Destructor.
Ptr< VirtualNetDevice > m_tunDevice
TUN VirtualNetDevice used for tunneling/detunneling IP packets from/to the internet over GTP-U/UDP/IP...
void DoRecvModifyBearerRequest(Ptr< Packet > packet)
Process Modify Bearer Request message.
void DoRecvCreateSessionRequest(Ptr< Packet > packet)
Process Create Session Request message.
uint16_t m_gtpcUdpPort
UDP port to be used for GTPv2-C.
static TypeId GetTypeId()
Get the type ID.
Ptr< Socket > m_s5cSocket
UDP socket to send/receive GTPv2-C packets to/from the S5 interface.
std::map< Ipv4Address, Ptr< UeInfo > > m_ueInfoByAddrMap
UeInfo stored by UE IPv4 address.
void SetUeAddress(uint64_t imsi, Ipv4Address ueAddr)
Set the address of a previously added UE.
void(* RxTracedCallback)(Ptr< Packet > packet)
TracedCallback signature for data Packet reception event.
classifies IP packets according to Traffic Flow Templates (TFTs)
Ipv4 addresses are stored in host order in this class.
Definition: ipv4-address.h:42
Describes an IPv6 address.
Definition: ipv6-address.h:49
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:77
A template-based reference counting class.
Forward calls to a chain of Callback.
a unique identifier for an interface.
Definition: type-id.h:59
Every class exported by the ns3 library is enclosed in the ns3 namespace.