GtpUser.h Source File

Simu5G: GtpUser.h Source File
Simu5G
GtpUser.h
1//
2// Simu5G
3//
4// Copyright (C) 2012-2021 Giovanni Nardini, Giovanni Stea, Antonio Virdis et al. (University of Pisa)
5// Copyright (C) 2022-2026 Giovanni Nardini, Giovanni Stea et al. (University of Pisa)
6//
7// This file is part of a software released under the license included in file
8// "license.pdf". Please read LICENSE and README files before using it.
9// The above files and the present reference are part of the software itself,
10// and cannot be removed from it.
11//
12
13#ifndef __GTP_USER_H_
14#define __GTP_USER_H_
15
16#include <map>
17
18#include "simu5g/common/LteDefs.h"
19#include <inet/common/ModuleAccess.h>
20#include <inet/common/ModuleRefByPar.h>
21#include <inet/linklayer/common/InterfaceTag_m.h>
22#include <inet/networklayer/common/L3AddressResolver.h>
23#include <inet/networklayer/common/NetworkInterface.h>
24#include <inet/transportlayer/contract/udp/UdpSocket.h>
25
26#include "simu5g/common/binder/Binder.h"
27#include "simu5g/corenetwork/gtp/GtpTunnel.h"
28#include "simu5g/corenetwork/gtp/GtpUserMsg_m.h"
29
30namespace simu5g {
31
32using namespace omnetpp;
33
34
42class GtpUser : public cSimpleModule
43{
44 inet::UdpSocket socket_;
45 int localPort_;
46
47 // reference to the LTE Binder module
48 inet::ModuleRefByPar<Binder> binder_;
49
50 // the GTP protocol Port
51 unsigned int tunnelPeerPort_;
52
53 // the core network gateway (the "gateway" parameter) of a base station connected to
54 // the core network or of a MEC host's UPF, and its IP address; empty otherwise
55 std::string gateway_;
56 inet::L3Address gwAddress_;
57
58 // specifies the type of the node that contains this filter (it can be ENB or PGW)
59 CoreNodeType ownerType_;
60
61 // if this module is on BS, this variable includes the ID of the BS
62 MacNodeId myMacNodeID;
63
64 opp_component_ptr<cModule> networkNode_;
65
66 // The tunnels ending here: the session of each TEID allocated at this endpoint.
67 // A released session's tunnels stay known, so that a G-PDU still in flight can be
68 // attributed; TEIDs are not reused.
69 std::map<Teid, TunnelSession> rxTunnels_;
70
71 // At a base station: the uplink tunnels of the sessions of the UEs it serves or
72 // has served, with the session, by each of the UE's node ids
73 struct UplinkSession {
74 TunnelSession session;
75 UplinkTunnels tunnels;
76 };
77 std::map<MacNodeId, UplinkSession> ulTunnels_;
78
79 // At a UPF/PGW or a MEC host's UPF: the downlink tunnel of each session it serves,
80 // by each of the UE's node ids; none while the UE is attached nowhere
81 std::map<MacNodeId, FTeid> dlTunnels_;
82
83 // At an anchor UPF: the N6 tunnel of each Unstructured session it anchors, by each
84 // of the UE's node ids (see UserPlaneNodeControl)
85 std::map<MacNodeId, N6Tunnel> n6Tunnels_;
86
87 // At an anchor UPF: the Identification field of the IPv4 datagrams it originates
88 // on the N6 tunnels of Unstructured sessions
89 uint16_t n6DatagramId_ = 0;
90
91 CoreNodeType selectOwnerType(const char *type);
92
93 protected:
94
95 int numInitStages() const override { return inet::NUM_INIT_STAGES; }
96 void initialize(int stage) override;
97 void handleMessage(cMessage *msg) override;
98
99 // receive an IP Datagram from the traffic filter, encapsulates it in a GTP-U packet then forwards it to the proper next hop
100 void handleFromTrafficFlowFilter(inet::Packet *datagram);
101
102 // receive a GTP-U packet from Udp, reads the TEID and decides whether performing label switching or removal
103 void handleFromUdp(inet::Packet *gtpMsg);
104
105 // at a UPF/PGW: send a packet to the node's message dispatcher on the relay's user data side,
106 // which delivers it to the module that provides the given service
107 void sendToDispatcher(inet::Packet *packet, const inet::Protocol& service);
108
109 // encapsulate a datagram into GTP-U, and send it through the given downlink tunnel of
110 // a session
111 void tunnelDownlink(inet::Packet *datagram, const FTeid& tunnel, Qfi qfi);
112
113 // At an anchor UPF: send the uplink payload of an Unstructured session to the data
114 // network over the session's N6 tunnel, in a UDP/IP datagram this node originates
115 // (TS 29.561 9.2)
116 void tunnelUplinkOverN6(inet::Packet *payload, const SessionRef& session);
117
118 // At a base station: an End Marker arrived on the tunnel with the given TEID
119 void handleEndMarker(Teid teid);
120
121 // At a UPF/PGW or a MEC host's UPF: the downlink tunnel of the session of the UE
122 // with the given node id; nullptr if its session is not served here, or the UE is
123 // attached nowhere
124 const FTeid *findDownlinkTunnel(MacNodeId ueNodeId);
125
126 // At a base station: the uplink tunnels of the session of the UE with the given node id
127 const UplinkTunnels& getUplinkTunnels(MacNodeId ueNodeId);
128
129 // At a base station: the session of a UE whose uplink enters the core network
130 // here, by one of the UE's node ids; throws if it has none
131 const TunnelSession& getServedSession(MacNodeId ueNodeId);
132
133 // The session of a tunnel ending here; throws for an unknown TEID
134 const TunnelSession& findTunnel(Teid teid);
135
136
137 public:
138 // The tunnels of the sessions, as the bearer configurator (the SMF stand-in)
139 // sets them up and moves them.
140
141 // A tunnel ending at this endpoint: G-PDUs arriving with the TEID belong to the
142 // session, which is of the given type
143 virtual void addTunnel(Teid teid, const SessionRef& session, SessionType type);
144
145 // At a base station: the uplink tunnels of the session, which is of the given type
146 virtual void setUplinkTunnels(const SessionRef& session, SessionType type, const UplinkTunnels& tunnels);
147
148 // At a UPF/PGW or a MEC host's UPF: the session's downlink tunnel, which the path
149 // switch moves; an unset F-TEID while the UE is attached nowhere
150 virtual void setDownlinkTunnel(const SessionRef& session, const FTeid& tunnel);
151
152 // At an anchor UPF/PGW: end a downlink tunnel with an End Marker, as the path switch
153 // moves the session's downlink off it (the "send end marker" instruction of the SMF)
154 virtual void sendEndMarker(const FTeid& tunnel);
155
156 // At an anchor UPF: the N6 tunnel of an Unstructured session, which its uplink
157 // leaves the node on
158 virtual void setN6Tunnel(const SessionRef& session, const N6Tunnel& tunnel);
159
160 // The session is released: forget its uplink, downlink and N6 tunnels
161 virtual void removeSession(const SessionRef& session);
162};
163
164} //namespace
165
166#endif
Definition GtpUser.h:43
Definition AlertReceiver.h:24
Definition GtpTunnel.h:33
Definition GtpTunnel.h:126
Definition GtpTunnel.h:51
Definition GtpTunnel.h:100
Definition GtpTunnel.h:144