CoreControl.h Source File

Simu5G: CoreControl.h Source File
Simu5G
CoreControl.h
1//
2// Simu5G
3//
4// Authors: Andras Varga (OpenSim Ltd)
5//
6// This file is part of a software released under the license included in file
7// "license.pdf". Please read LICENSE and README files before using it.
8// The above files and the present reference are part of the software itself,
9// and cannot be removed from it.
10//
11
12#ifndef _CORECONTROL_H_
13#define _CORECONTROL_H_
14
15#include <map>
16#include <set>
17#include <string>
18#include <vector>
19
20#include <inet/common/ModuleRefByPar.h>
21
22#include "simu5g/common/LteCommon.h"
23#include "simu5g/common/binder/Binder.h"
24#include "simu5g/corenetwork/gtp/GtpTunnel.h"
25
26namespace simu5g {
27
31
40class CoreControl : public omnetpp::cSimpleModule, public omnetpp::cListener
41{
42 public:
43 // A session the core network establishes for a UE (see sessionsToEstablish()): its
44 // id (1..15, unique among the UE's sessions), its type, and the UE addresses that
45 // belong to it (empty: every address of the UE)
46 struct SessionPlan {
47 SessionId id = SessionId(0);
48 SessionType type = IP_V4;
49 std::vector<AddressPrefix> addresses;
50 };
51
52 protected:
53 inet::ModuleRefByPar<Binder> binder_;
54 inet::ModuleRefByPar<BearerConfigurator> bearerConfigurator_;
55
56 // A node of the network that ends tunnels (see takeGtpEndpoints()), through its
57 // control-plane entry point: the UserPlaneNodeControl of a user plane node (a UPF/PGW or a
58 // MEC host's UPF), or the connection control of a base station. Each allocates
59 // its node's TEIDs itself, and is programmed through its calls.
60 struct GtpEndpoint {
61 omnetpp::cModule *node = nullptr; // the network node
62 UserPlaneNodeControl *userPlaneNode = nullptr; // user plane nodes only
63 ConnectionControlEnb *bs = nullptr; // base stations only
64 CoreNodeType type = ENB;
65 MacNodeId bsId = NODEID_NONE; // base stations only
66 std::string gateway; // the core network gateway of a base station connected to the core network, or of a MEC host's UPF; empty otherwise
67 };
68 std::vector<GtpEndpoint> gtpEndpoints_; // the user plane nodes, then the base stations
69 std::map<MacNodeId, int> bsGtpEndpoints_; // base station id -> index into gtpEndpoints_
70
71 // A UE's session (a PDN connection of an EPC, a PDU session of a 5G core, TS 23.501
72 // 5.6), as the core network keeps it: established when the UE first has a serving
73 // node, as sessionsToEstablish() says, released when the UE leaves (see
74 // establishSessions()). The
75 // anchor (the PGW, or the PDU session anchor UPF) is chosen at establishment and
76 // kept for the lifetime of the session (SSC mode 1): a handover only moves the
77 // downlink end of the tunnel (see updateDownlinkPath()). The tunnel ends are told
78 // about every change through their nodes' control-plane entry points.
79 struct CoreSession {
80 omnetpp::cModule *ueModule = nullptr;
81 SessionRef ref; // the UE's node ids and the session id
82 SessionType type = IP_V4; // the session's type
83 std::vector<AddressPrefix> addresses; // the UE addresses that belong to the session; empty: every address of the UE
84 inet::L3Address n6Address; // Unstructured sessions only: the session's address on the anchor's N6 tunnel, allocated from the anchor's prefix
85 uint32_t n6Suffix = 0; // the host part of n6Address within the prefix (0: none)
86 int anchor = -1; // the anchor UPF/PGW, index into gtpEndpoints_
87 FTeid ulAnchor; // uplink F-TEID at the anchor
88 std::map<int, FTeid> ulMecHosts; // uplink F-TEIDs at the MEC host UPFs of the anchor's core network, by index into gtpEndpoints_
89 MacNodeId dlBaseStation = NODEID_NONE; // where the downlink enters the RAN; NODEID_NONE while the UE is attached nowhere
90 MacNodeId lastDlBaseStation = NODEID_NONE; // where the downlink last entered the RAN, kept while the UE is attached nowhere
91 FTeid dl; // downlink F-TEID at dlBaseStation
92 std::map<MacNodeId, FTeid> dlTunnels; // the downlink F-TEID at each base station the UE has been attached through, kept until release
93 };
94 typedef std::pair<int, SessionId> CoreSessionKey; // the UE module's id, and the session id
95 std::map<CoreSessionKey, CoreSession> sessions_;
96 std::map<MacNodeId, std::vector<CoreSessionKey>> sessionsOfNode_; // UE node id (either stack) -> the UE's sessions, in establishment order
97 std::map<int, SessionType> requestedTypes_; // UE module id -> the session type the UE requests
98
99 // The host parts of the N6 addresses allocated from each anchor's prefix to the
100 // Unstructured sessions it anchors, by index into gtpEndpoints_
101 std::map<int, std::set<uint32_t>> n6AddressesInUse_;
102
103 protected:
104 void initialize(int stage) override;
105 int numInitStages() const override { return inet::NUM_INIT_STAGES; }
106 void handleMessage(omnetpp::cMessage *msg) override { throw omnetpp::cRuntimeError("This module does not process messages"); }
107
111 void receiveSignal(omnetpp::cComponent *source, omnetpp::simsignal_t signalID, long nodeId, omnetpp::cObject *details) override;
112
113 // Take the nodes that end tunnels from the Binder: the user plane nodes' control-
114 // plane entry points, registered there at INITSTAGE_LOCAL, in registration order, then the
115 // base stations' connection controls, through the node directory, in node id
116 // order. Before the first tunnel is set up.
117 virtual void takeGtpEndpoints();
118
119 // Deliver the QFI classification rules the BearerConfigurator holds to their
120 // evaluation sites: the downlink rules to each user plane node, the uplink rules
121 // to each SDAP UE's classifier through the
122 // UE's RRC (the QoS rules NAS signaling installs into a UE at PDU session
123 // establishment, TS 23.501 5.7.1.4). The sites never author rules of their own.
124 virtual void deliverQfiRules();
125
126 // The node a gateway parameter names, or nullptr
127 virtual omnetpp::cModule *findGatewayNode(const std::string& gateway);
128
129 // The UPF/PGW endpoint the gateway parameter of the given endpoint names; throws if
130 // there is none
131 virtual int findGatewayEndpoint(const std::string& gateway, const GtpEndpoint& from);
132
133 // The base station a downlink packet for the UE enters the RAN at: the master of the
134 // serving node of the stack the core network addresses the UE by, the LTE one while
135 // it is attached and else the NR one (as Binder::getMacNodeId() resolves a UE
136 // address); NODEID_NONE if the UE is attached nowhere
137 virtual MacNodeId findDlBaseStation(MacNodeId lteNodeId, MacNodeId nrNodeId);
138
139 // The policy: the sessions to establish for a UE that requests a session of the
140 // given type. One session per UE, of the requested type, with every address of
141 // the UE: a UE has one session in this model, a deliberate simplification of 3GPP
142 // (where a UE may have several, each with its own type and address). The protocol
143 // modules keep their state per session, so a subclass may return several.
144 virtual std::vector<SessionPlan> sessionsToEstablish(omnetpp::cModule *ueModule, SessionType requestedType);
145
146 // Establish the sessions of the UE with the given node id (see
147 // sessionsToEstablish()), each anchored at the gateway of the UE's downlink base
148 // station: its uplink tunnels at the anchor and the MEC host UPFs. Does nothing if
149 // the UE is attached nowhere yet, or its base station is not connected to a core
150 // network; throws if the anchor's core network cannot carry a session of the
151 // type (an EPC carries the IP types only). The RAN end of the sessions is set up
152 // separately (initialUeMessage(), pathSwitchRequest()).
153 virtual void establishSessions(MacNodeId ueNodeId, SessionType requestedType);
154
155 // If the base station the UE's downlink enters the RAN at has changed, the downlink
156 // end of the tunnel moves there (the path switch, TS 23.502 4.9.1.2.2), and that
157 // base station is told (ConnectionControlEnb::downlinkPathSwitched())
158 virtual void updateDownlinkPath(CoreSession& session);
159
160 // Set up the session's tunnels at a base station the UE is attached through, unless
161 // they are there already (see registerRanTunnel())
162 virtual void setUpRanTunnels(CoreSession& session, MacNodeId bsId);
163
164 // Record the session's downlink tunnel at a base station. The base stations of the
165 // session learn each other's downlink TEIDs, to forward the downlink over X2 with.
166 virtual void registerRanTunnel(CoreSession& session, MacNodeId bsId, const FTeid& dl);
167
168 // The session's uplink tunnels, as a base station uses them
169 virtual UplinkTunnels getUplinkTunnels(const CoreSession& session);
170
171 // Allocate the N6 address of an Unstructured session from its anchor's prefix (the
172 // SMF's allocation of TS 29.561 9.2, one address per session): the lowest free one
173 // after the prefix itself; and free it at the session's release
174 virtual void allocateN6Address(CoreSession& session);
175 virtual void freeN6Address(const CoreSession& session);
176
177 // Release the sessions of the UE with the given node id, if it has any
178 virtual void releaseSessions(MacNodeId ueNodeId);
179
180 // Release one session
181 virtual void releaseSession(const CoreSession& session);
182
183 public:
184 // INITIAL UE MESSAGE (S1AP/NGAP), and the registration and session establishment that
185 // follow: a leg of a UE has connected at the given base station, requesting a
186 // session of the given type (the NAS message the INITIAL UE MESSAGE carries). The
187 // UE's sessions are established once, at its first leg's registration; the other
188 // leg of a dual-stack UE requests the same type. Each session's RAN resources are
189 // set up at every base station the UE attaches through, once
190 // (ConnectionControlEnb::sessionResourceSetup()); and the downlink paths are
191 // settled.
192 virtual void initialUeMessage(MacNodeId legId, ConnectionControlEnb *bs, SessionType sessionType);
193
194 // PATH SWITCH REQUEST (S1AP/NGAP), from the base station a leg arrived at by handover: the
195 // UE's sessions now enter the RAN at that base station (the master of it, under
196 // dual connectivity), with the downlink F-TEIDs the handover preparation set up
197 // there (the session resources "to be switched in downlink"); a base station the
198 // preparation gave no tunnels (a secondary node's source has none to transfer)
199 // gets them now. The downlink path is switched if the base station the downlink
200 // enters at changed.
201 virtual void pathSwitchRequest(MacNodeId legId, ConnectionControlEnb *bs, const std::vector<SessionResource>& sessions);
202
203 // UE CONTEXT RELEASE REQUEST (S1AP/NGAP), from the base station a leg left without a
204 // handover: the leg is attached nowhere; the downlink paths follow the UE's
205 // remaining attachment, if any. The UE's sessions stay until the UE leaves the
206 // simulation (nodeUnregistered).
207 virtual void ueContextReleaseRequest(MacNodeId legId);
208};
209
210} //namespace
211
212#endif
Definition BearerConfigurator.h:40
Definition ConnectionControlEnb.h:78
Definition CoreControl.h:41
void receiveSignal(omnetpp::cComponent *source, omnetpp::simsignal_t signalID, long nodeId, omnetpp::cObject *details) override
Definition UserPlaneNodeControl.h:38
Definition AlertReceiver.h:24
constexpr MacNodeId NODEID_NONE
MAC node ID.
Definition LteTypes.h:54
Definition GtpTunnel.h:33
Definition GtpTunnel.h:51
Definition GtpTunnel.h:144