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 * SPDX-License-Identifier: GPL-2.0-only
5 *
6 * Author: Manuel Requena <manuel.requena@cttc.es>
7 * (based on epc-sgw-pgw-application.h)
8 */
9
10#ifndef EPC_PGW_APPLICATION_H
11#define EPC_PGW_APPLICATION_H
12
13#include "epc-gtpc-header.h"
14#include "epc-tft-classifier.h"
15
16#include "ns3/application.h"
17#include "ns3/socket.h"
18#include "ns3/virtual-net-device.h"
19
20namespace ns3
21{
22
23/**
24 * \ingroup lte
25 *
26 * This application implements the Packet Data Network (PDN) Gateway Entity (PGW)
27 * according to the 3GPP TS 23.401 document.
28 *
29 * This Application implements the PGW side of the S5 interface between
30 * the PGW node and the SGW nodes and the PGW side of the SGi interface between
31 * the PGW node and the internet hosts. It supports the following functions and messages:
32 *
33 * - S5 connectivity (i.e. GTPv2-C signalling and GTP-U data plane)
34 * - Bearer management functions including dedicated bearer establishment
35 * - Per-user based packet filtering
36 * - UL and DL bearer binding
37 * - Tunnel Management messages
38 *
39 * Others functions enumerated in section 4.4.3.3 of 3GPP TS 23.401 are not supported.
40 */
42{
43 public:
44 /**
45 * \brief Get the type ID.
46 * \return the object TypeId
47 */
48 static TypeId GetTypeId();
49 void DoDispose() override;
50
51 /**
52 * Constructor that binds the tap device to the callback methods.
53 *
54 * \param tunDevice TUN VirtualNetDevice used to tunnel IP packets from
55 * the SGi interface of the PGW in the internet
56 * over GTP-U/UDP/IP on the S5 interface
57 * \param s5Addr IP address of the PGW S5 interface
58 * \param s5uSocket socket used to send GTP-U packets to the peer SGW
59 * \param s5cSocket socket used to send GTP-C packets to the peer SGW
60 */
62 Ipv4Address s5Addr,
63 const Ptr<Socket> s5uSocket,
64 const Ptr<Socket> s5cSocket);
65
66 /** Destructor */
67 ~EpcPgwApplication() override;
68
69 /**
70 * Method to be assigned to the callback of the SGi TUN VirtualNetDevice.
71 * It is called when the PGW receives a data packet from the
72 * internet (including IP headers) that is to be sent to the UE via
73 * its associated SGW and eNB, tunneling IP over GTP-U/UDP/IP.
74 *
75 * \param packet
76 * \param source
77 * \param dest
78 * \param protocolNumber
79 * \return true always
80 */
82 const Address& source,
83 const Address& dest,
84 uint16_t protocolNumber);
85
86 /**
87 * Method to be assigned to the receiver callback of the S5-U socket.
88 * It is called when the PGW receives a data packet from the SGW
89 * that is to be forwarded to the internet.
90 *
91 * \param socket pointer to the S5-U socket
92 */
93 void RecvFromS5uSocket(Ptr<Socket> socket);
94
95 /**
96 * Method to be assigned to the receiver callback of the S5-C socket.
97 * It is called when the PGW receives a control packet from the SGW.
98 *
99 * \param socket pointer to the S5-C socket
100 */
101 void RecvFromS5cSocket(Ptr<Socket> socket);
102
103 /**
104 * Send a data packet to the internet via the SGi interface of the PGW
105 *
106 * \param packet packet to be sent
107 * \param teid the Tunnel Endpoint Identifier
108 */
109 void SendToTunDevice(Ptr<Packet> packet, uint32_t teid);
110
111 /**
112 * Send a data packet to the SGW via the S5-U interface
113 *
114 * \param packet packet to be sent
115 * \param sgwS5uAddress the address of the SGW
116 * \param teid the Tunnel Endpoint Identifier
117 */
118 void SendToS5uSocket(Ptr<Packet> packet, Ipv4Address sgwS5uAddress, uint32_t teid);
119
120 /**
121 * Let the PGW be aware of a new SGW
122 *
123 * \param sgwS5Addr the address of the SGW S5 interface
124 */
125 void AddSgw(Ipv4Address sgwS5Addr);
126
127 /**
128 * Let the PGW be aware of a new UE
129 *
130 * \param imsi the unique identifier of the UE
131 */
132 void AddUe(uint64_t imsi);
133
134 /**
135 * Set the address of a previously added UE
136 *
137 * \param imsi the unique identifier of the UE
138 * \param ueAddr the IPv4 address of the UE
139 */
140 void SetUeAddress(uint64_t imsi, Ipv4Address ueAddr);
141
142 /**
143 * set the address of a previously added UE
144 *
145 * \param imsi the unique identifier of the UE
146 * \param ueAddr the IPv6 address of the UE
147 */
148 void SetUeAddress6(uint64_t imsi, Ipv6Address ueAddr);
149
150 /**
151 * TracedCallback signature for data Packet reception event.
152 *
153 * \param [in] packet The data packet sent from the internet.
154 */
155 typedef void (*RxTracedCallback)(Ptr<Packet> packet);
156
157 private:
158 /**
159 * Process Create Session Request message
160 * \param packet GTPv2-C Create Session Request message
161 */
163
164 /**
165 * Process Modify Bearer Request message
166 * \param packet GTPv2-C Modify Bearer Request message
167 */
169
170 /**
171 * Process Delete Bearer Command message
172 * \param packet GTPv2-C Delete Bearer Command message
173 */
175
176 /**
177 * Process Delete Bearer Response message
178 * \param packet GTPv2-C Delete Bearer Response message
179 */
181
182 /**
183 * store info for each UE connected to this PGW
184 */
185 class UeInfo : public SimpleRefCount<UeInfo>
186 {
187 public:
188 UeInfo();
189
190 /**
191 * Add a bearer for this UE on PGW side
192 *
193 * \param bearerId the ID of the EPS Bearer to be activated
194 * \param teid the TEID of the new bearer
195 * \param tft the Traffic Flow Template of the new bearer to be added
196 */
197 void AddBearer(uint8_t bearerId, uint32_t teid, Ptr<EpcTft> tft);
198
199 /**
200 * Delete context of bearer for this UE on PGW side
201 *
202 * \param bearerId the ID of the EPS Bearer whose contexts is to be removed
203 */
204 void RemoveBearer(uint8_t bearerId);
205
206 /**
207 * Classify the packet according to TFTs of this UE
208 *
209 * \param p the IPv4 or IPv6 packet from the internet to be classified
210 * \param protocolNumber identifies the type of packet.
211 * Only IPv4 and IPv6 packets are allowed.
212 *
213 * \return the corresponding bearer ID > 0 identifying the bearer
214 * among all the bearers of this UE; returns 0 if no bearers
215 * matches with the previously declared TFTs
216 */
217 uint32_t Classify(Ptr<Packet> p, uint16_t protocolNumber);
218
219 /**
220 * Get the address of the SGW to which the UE is connected
221 *
222 * \return the address of the SGW
223 */
225
226 /**
227 * Set the address of the eNB to which the UE is connected
228 *
229 * \param addr the address of the SGW
230 */
231 void SetSgwAddr(Ipv4Address addr);
232
233 /**
234 * Get the IPv4 address of the UE
235 *
236 * \return the IPv4 address of the UE
237 */
239
240 /**
241 * Set the IPv4 address of the UE
242 *
243 * \param addr the IPv4 address of the UE
244 */
245 void SetUeAddr(Ipv4Address addr);
246
247 /**
248 * Get the IPv6 address of the UE
249 *
250 * \return the IPv6 address of the UE
251 */
253
254 /**
255 * Set the IPv6 address of the UE
256 *
257 * \param addr the IPv6 address of the UE
258 */
259 void SetUeAddr6(Ipv6Address addr);
260
261 private:
262 Ipv4Address m_ueAddr; ///< UE IPv4 address
263 Ipv6Address m_ueAddr6; ///< UE IPv6 address
264 Ipv4Address m_sgwAddr; ///< SGW IPv4 address
266 std::map<uint8_t, uint32_t> m_teidByBearerIdMap; ///< TEID By bearer ID Map
267 };
268
269 /**
270 * PGW address of the S5 interface
271 */
273
274 /**
275 * UDP socket to send/receive GTP-U packets to/from the S5 interface
276 */
278
279 /**
280 * UDP socket to send/receive GTPv2-C packets to/from the S5 interface
281 */
283
284 /**
285 * TUN VirtualNetDevice used for tunneling/detunneling IP packets
286 * from/to the internet over GTP-U/UDP/IP on the S5 interface
287 */
289
290 /**
291 * UeInfo stored by UE IPv4 address
292 */
293 std::map<Ipv4Address, Ptr<UeInfo>> m_ueInfoByAddrMap;
294
295 /**
296 * UeInfo stored by UE IPv6 address
297 */
298 std::map<Ipv6Address, Ptr<UeInfo>> m_ueInfoByAddrMap6;
299
300 /**
301 * UeInfo stored by IMSI
302 */
303 std::map<uint64_t, Ptr<UeInfo>> m_ueInfoByImsiMap;
304
305 /**
306 * UDP port to be used for GTP-U
307 */
309
310 /**
311 * UDP port to be used for GTPv2-C
312 */
314
315 /**
316 * SGW address of the S5 interface
317 */
319
320 /**
321 * \brief Callback to trace received data packets at Tun NetDevice from internet.
322 */
324
325 /**
326 * \brief Callback to trace received data packets from S5 socket.
327 */
329};
330
331} // namespace ns3
332
333#endif // EPC_PGW_APPLICATION_H
a polymophic address class
Definition address.h:90
The base class for all ns3 applications.
Definition application.h:51
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 ...
EpcPgwApplication(const Ptr< VirtualNetDevice > tunDevice, Ipv4Address s5Addr, const Ptr< Socket > s5uSocket, const Ptr< Socket > s5cSocket)
Constructor that binds the tap device to the callback methods.
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.
Describes an IPv6 address.
Smart pointer class similar to boost::intrusive_ptr.
A template-based reference counting class.
Forward calls to a chain of Callback.
a unique identifier for an interface.
Definition type-id.h:48
Every class exported by the ns3 library is enclosed in the ns3 namespace.