GtpUserX2.h Source File

Simu5G: GtpUserX2.h Source File
Simu5G
GtpUserX2.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_X2_H_
14#define __GTP_USER_X2_H_
15
16#include <map>
17#include <tuple>
18
19#include <inet/common/ModuleRefByPar.h>
20#include <inet/transportlayer/contract/udp/UdpSocket.h>
21
22#include "simu5g/common/binder/Binder.h"
23#include "simu5g/corenetwork/gtp/GtpTunnel.h"
24#include "simu5g/corenetwork/gtp/GtpUserMsg_m.h"
25#include "simu5g/x2/packet/LteX2Message.h"
26
27namespace simu5g {
28
29using namespace omnetpp;
30
31
46class GtpUserX2 : public cSimpleModule
47{
48 inet::UdpSocket socket_;
49 int localPort_;
50
51 // reference to the LTE Binder module
52 inet::ModuleRefByPar<Binder> binder_;
53
54 // the GTP protocol Port
55 unsigned int tunnelPeerPort_;
56
57 // The tunnels ending here: the session of each TEID this base station allocated.
58 // A released session's tunnels stay known, like at ~GtpUser.
59 std::map<Teid, TunnelSession> rxTunnels_;
60
61 // The TEID of each session's downlink tunnel at the other base stations it has
62 // one at, by each of the UE's node ids, then by base station
63 std::map<MacNodeId, std::map<MacNodeId, Teid>> forwardingTeids_;
64
65 // The dual connectivity bearer of each X2-U tunnel ending here (rx), and the TEID of
66 // each bearer's tunnel at the peer node for the direction this node sends (tx),
67 // by each of the UE's node ids, the DRB and the direction
68 struct DcTunnel {
69 MacNodeId ueNodeId = NODEID_NONE; // the UE, by the id this node keys the bearer by
70 DrbId drbId;
71 Direction direction = DL;
72 };
73 std::map<Teid, DcTunnel> dcRxTunnels_;
74 std::map<std::tuple<MacNodeId, DrbId, Direction>, Teid> dcTxTeids_;
75
76 protected:
77
78 int numInitStages() const override { return inet::NUM_INIT_STAGES; }
79 void initialize(int stage) override;
80 void handleMessage(inet::cMessage *msg) override;
81
82 // receive an X2 Message from the X2 Manager, encapsulates it in a GTP-U packet then forwards it to the proper next hop
83 void handleFromStack(inet::Packet *x2Msg);
84
85 // receive a GTP-U packet from UDP, detunnel it and send it to the X2 Manager
86 void handleFromUdp(inet::Packet *gtpMsg);
87
88 // The TEID to forward a datagram of the given session to the given base station with
89 virtual Teid getForwardingTeid(const SessionTag *session, MacNodeId targetBs);
90
91 public:
92 // The tunnels of the sessions, as the base station's control plane
93 // (ConnectionControlEnb) sets them up here
94
95 // A tunnel ending at this base station: G-PDUs arriving with the TEID belong to the
96 // session, which is of the given type
97 virtual void addTunnel(Teid teid, const SessionRef& session, SessionType type);
98
99 // The TEID of the session's downlink tunnel at another base station
100 virtual void setForwardingTeid(const SessionRef& session, MacNodeId bsId, Teid teid);
101
102 // The session is released: forget the TEIDs to forward it with
103 virtual void removeSession(const SessionRef& session);
104
105 // A dual connectivity bearer's X2-U tunnel ending at this node, for the given
106 // direction: G-PDUs arriving with the TEID carry PDCP PDUs of the bearer the UE
107 // with the given id (this node's key for the bearer) has with the given DRB id
108 virtual void addDcTunnel(Teid teid, MacNodeId ueNodeId, DrbId drbId, Direction direction);
109
110 // The TEID of a dual connectivity bearer's X2-U tunnel at the peer node, for the
111 // direction this node sends; the UE is named by both of its node ids
112 virtual void setDcTunnelTeid(MacNodeId ueLteId, MacNodeId ueNrId, DrbId drbId, Direction direction, Teid teid);
113};
114
115} //namespace
116
117#endif
118
Definition GtpUserX2.h:47
Definition AlertReceiver.h:24
constexpr MacNodeId NODEID_NONE
MAC node ID.
Definition LteTypes.h:54
Definition GtpTunnel.h:51