[Epic-ID: ODUHIGH-463][Task-ID: ODUHIGH-508] UE context release at Source GNB after...
[o-du/l2.git] / src / cu_stub / cu_stub.h
1 /*******************************************************************************
2 ################################################################################
3 #   Copyright (c) [2017-2019] [Radisys]                                        #
4 #                                                                              #
5 #   Licensed under the Apache License, Version 2.0 (the "License");            #
6 #   you may not use this file except in compliance with the License.           #
7 #   You may obtain a copy of the License at                                    #
8 #                                                                              #
9 #       http://www.apache.org/licenses/LICENSE-2.0                             #
10 #                                                                              #
11 #   Unless required by applicable law or agreed to in writing, software        #
12 #   distributed under the License is distributed on an "AS IS" BASIS,          #
13 #   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.   #
14 #   See the License for the specific language governing permissions and        #
15 #   limitations under the License.                                             #
16 ################################################################################
17 *******************************************************************************/
18
19 #ifndef __CU_MGR_MAIN_H__
20 #define __CU_MGR_MAIN_H__
21
22 #define CU_ID 1
23 #define CU_NAME "ORAN OAM CU"
24
25 #define DU_IP_V6_ADDR "0000:0000:0000:0000:0000:0000:0000:0001"
26 #define CU_IP_V6_ADDR "0000:0000:0000:0000:0000:0000:0000:0011"
27
28 #ifndef O1_ENABLE
29 #define LOCAL_IP_CU "192.168.130.82"
30
31 #define F1_SCTP_PORT 38472  /* As per the spec 38.472, the registered port number for F1AP is 38472 */
32 #define NUM_F1_ASSOC 1  
33 #define REMOTE_IP_DU (char*[]){"192.168.130.81", "192.168.130.83"}
34
35 #define XN_SCTP_PORT 38422 /* As per 3GPP TS 38.422, The SCTP Destination Port number value assigned by IANA to be used for XnAP is 38422 */
36 #define NUM_XN_ASSOC 0
37 #define REMOTE_IP_CU (char*[]){"192.168.130.84"}
38 #define LOCAL_NODE_TYPE SERVER
39 #endif
40
41 #define F1_EGTP_PORT 2152 /* As per the spec 29.281, the registered port number for GTP-U is 2152 */
42 #define RRC_VER 0
43 #define EXT_RRC_VER 5
44
45 #define PLMN_MCC0 3
46 #define PLMN_MCC1 1
47 #define PLMN_MCC2 1
48 #define PLMN_MNC0 4
49 #define PLMN_MNC1 8
50 #define PLMN_MNC2 0
51
52 #define CU_DU_NAME_LEN_MAX 30      /* Max length of CU/DU name string */
53
54 #define CU_APP_MEM_REG 1
55 #define CU_POOL 1
56
57 #define MAX_NUM_OF_SLICE 1024 /* As per the spec 38.473, maxnoofSliceItems = 1024*/
58 #define MAX_QOS_FLOWS 64 /* As per the spec 38.331, maxNrofQFIs = 64 */
59
60 /* allocate and zero out a static buffer */
61
62 #define CU_ALLOC(_datPtr, _size)                             \
63 {                                                            \
64    S16 _ret;                                                 \
65    _ret = SGetSBuf(CU_APP_MEM_REG, CU_POOL,                  \
66                      (Data **)&_datPtr, _size);              \
67    if(_ret == ROK)                                           \
68       memset(_datPtr, 0, _size);                      \
69    else                                                      \
70       _datPtr = NULLP;                                       \
71 }
72  
73 /* free a static buffer */
74 #define CU_FREE(_datPtr, _size)                              \
75    if(_datPtr)                                               \
76    SPutSBuf(CU_APP_MEM_REG, CU_POOL,                         \
77          (Data *)_datPtr, _size);
78
79 #define SEARCH_DU_DB(_duIdx, _duId, _duDb){\
80    _duDb = NULLP; \
81    for(_duIdx=0; _duIdx < cuCb.numDu; _duIdx++)\
82    {\
83       if(cuCb.duInfo[_duIdx].duId == _duId)\
84       {\
85          _duDb =  (&cuCb.duInfo[_duIdx]);\
86          break; \
87      }\
88    }\
89 }
90
91 #define SEARCH_CELL_DB(_cellIdx, _duDb, _nrCellId, _cellCb){\
92    _cellCb = NULLP; \
93    for(_cellIdx=0; _cellIdx < _duDb->numCells; _cellIdx++)\
94    {\
95       if(_duDb->cellCb[_cellIdx].nrCellId == _nrCellId)\
96       {\
97          _cellCb = (&(_duDb->cellCb[_cellIdx]));\
98          break;\
99       }\
100    }\
101 }
102
103 #ifdef NR_DRX
104 /* Set this parameter true of false as per the need to enable or disable drx of
105  * a particular UE */
106 #define DRX_TO_BE_RELEASE true 
107 #endif
108
109 typedef enum
110 {
111   Xn_Based_Inter_CU_HO = 1,
112   Inter_DU_HO
113 }HandoverType;
114
115 typedef enum
116 {
117    XN_SETUP_REQ,
118    XN_SETUP_RSP,
119    HO_REQ,
120    HO_REQ_ACK,
121    UE_CTXT_REL
122 }XnEventType;
123
124 typedef enum
125 {
126    CELL_INACTIVE,
127    CELL_ACTIVE,
128    CELL_DELETION_IN_PROGRESS
129 }CellStatusInfo;
130
131 typedef enum
132 {
133    UE_IDLE,
134    UE_ATTACH_IN_PROGRESS,
135    UE_ACTIVE,
136    UE_HANDOVER_IN_PROGRESS
137 }UeState;
138
139 typedef struct RrcVersion
140 {
141   uint8_t    rrcVer;     /* Latest RRC Version */
142   uint32_t   extRrcVer;  /* Latest RRC version extended */
143 }RrcVersion;
144
145 typedef struct cuCfgParams
146 {
147    uint32_t         cuId;
148    char             cuName[CU_DU_NAME_LEN_MAX];
149    CuSctpParams     sctpParams;
150    Plmn             plmn;
151    CuEgtpParams     egtpParams;
152    RrcVersion       rrcVersion;
153 }CuCfgParams;
154
155 typedef struct handoverInfo
156 {
157    HandoverType HOType;
158    uint32_t srcNodeId;   /* If Inter_DU HO, this is Source DU ID. In case of Inter CU HO, this is Source CU ID */
159    uint32_t tgtNodeId;   /* If Inter_DU HO, this is Taregt DU ID. In case of Inter CU HO, this is Target CU ID */
160    uint32_t tgtCellId;   /* Cell Id in target node to which UE is to be handed over */
161    uint8_t  cuUeF1apIdSrc;  /* Used for Inter-CU HO. CU UE F1AP ID of UE in source CU */
162    uint8_t  cuUeF1apIdTgt;  /* Used for Inter-CU HO. CU UE F1AP ID of UE in target CU */
163 }HandoverInfo;
164
165 typedef struct dlAmCfg
166 {
167    uint8_t        snLenDl;              /* Sequence Number length in bits. Allowed values are 12 and 18 */
168    int8_t         reAssemTmr;           /* T_reassembling Timer in msec*/
169    int16_t        statProhTmr;          /* T_status_prohibit Timer in msec*/
170 }DlAmCfg;
171
172 typedef struct ulAmCfg
173 {
174    uint8_t      snLenUl;             /* Sequence Number length in bits. Allowed values are 12 and 18 */
175    uint16_t     pollRetxTmr;         /* T_poll_retransmit Timer in msec */
176    int16_t      pollPdu;             /* Used to trigger a poll for every pollPdu.*/
177    int32_t      pollByte;            /* Poll_Byte in bytes. */
178    uint8_t      maxRetxTh;           /* Max_Retx_Threshold */
179 }UlAmCfg;
180
181 typedef struct amBearerCfg
182 {
183    UlAmCfg  ulAmCfg;
184    DlAmCfg  dlAmCfg;
185 }AmBearerCfg;
186
187 typedef struct ulUmCfg
188 {
189    uint8_t        snLenUlUm;             /* Sequence Number length in bits. Allowed values are 6 and 12 */
190 }UlUmCfg;
191
192 typedef struct dlUmCfg
193 {
194    uint8_t        snLenDlUm;             /* Sequence Number length in bits. Allowed values are 6 and 12 */
195    int8_t         reAssemTmr;            /* T_reassembling Timer in msec*/
196 }DlUmCfg;
197
198 typedef struct umBiDirBearerCfg
199 {
200    UlUmCfg  ulUmCfg;
201    DlUmCfg  dlUmCfg;
202 }UmBiDirBearerCfg;
203
204 typedef struct umUniDirUlBearerCfg
205 {
206    UlUmCfg  ulUmCfg;
207 }UmUniDirUlBearerCfg;
208
209 typedef struct umUniDirDlBearerCfg
210 {
211    DlUmCfg  dlUmCfg;
212 }UmUniDirDlBearerCfg;
213
214 typedef struct rlcLcCfg
215 {
216    uint8_t rlcMode;
217    union
218    {   
219       AmBearerCfg         amCfg;
220       UmBiDirBearerCfg    umBiDirCfg;
221       UmUniDirUlBearerCfg umUniDirUlCfg;
222       UmUniDirDlBearerCfg umUniDirDlCfg;
223    }u; 
224 }RlcLcCfg;
225
226 typedef struct macLcCfg
227 {
228    uint8_t priority;
229    uint8_t lcGroup;
230    uint8_t schReqId;
231    uint8_t pbr;        // prioritisedBitRate
232    uint8_t bsd;        // bucketSizeDuration
233 }MacLcCfg;
234
235 typedef struct srbInfo
236 {
237    uint8_t   srbId;
238    uint8_t   lcId;
239    RlcLcCfg  rlcLcCfg;
240    MacLcCfg  macLcCfg;
241    bool      cfgSentToUe;
242 }SrbInfo;
243
244 typedef struct qosInfo
245 {
246    uint8_t nonDynFiveQI;
247    uint16_t avgWindow;
248    uint16_t maxBurstDataVol;
249    uint8_t priorityLevel;
250    uint8_t preemptionCapability;
251    uint8_t preemptionVulnerability;
252    uint8_t pduSessionId;
253 }QosInfo;
254
255 typedef struct flowsMapped
256 {
257    uint8_t qosFlowId;
258    QosInfo qos;
259 }FlowsMapped;
260
261 typedef struct TnlInfo
262 {
263    uint8_t address[4];
264    uint8_t teId[4];
265 }TnlInfo;
266
267 typedef struct drbInfo
268 {
269    uint8_t drbId;
270    uint8_t lcId;
271    QosInfo qos;
272    Snssai *snssai;
273    uint8_t numFlowMap;
274    FlowsMapped flowMapList[MAX_QOS_FLOWS];
275    TnlInfo ulUpTnlInfo;
276    TnlInfo dlUpTnlInfo;
277    uint8_t rlcMode;
278    RlcLcCfg  rlcLcCfg;
279    MacLcCfg  macLcCfg;
280    bool      cfgSentToUe;
281 }DrbInfo;
282
283 typedef struct cuCellCb CuCellCb;
284
285 #ifdef NR_DRX
286 /* The following list of structures is taken from the DRX-Config section of specification 33.331. */
287 typedef struct drxOnDurationTimer
288 {
289    bool  onDurationTimerValInMs;
290    union
291    {
292       uint8_t  subMilliSeconds;
293       uint16_t milliSeconds;
294    }onDurationtimerValue;
295 }DrxOnDurationTimer;
296
297 typedef struct drxLongCycleStartOffset
298 {
299    uint16_t drxLongCycleStartOffsetChoice;
300    uint16_t drxLongCycleStartOffsetVal;
301 }DrxLongCycleStartOffset;
302
303 typedef struct shortDrx
304 {
305    uint16_t   drxShortCycle;
306    uint8_t    drxShortCycleTimer;
307 }ShortDrx;
308
309 typedef struct drxCfg
310 {
311    DrxOnDurationTimer       drxOnDurationTimer;
312    uint16_t                 drxInactivityTimer;
313    uint8_t                  drxHarqRttTimerDl;
314    uint8_t                  drxHarqRttTimerUl;
315    uint16_t                 drxRetransmissionTimerDl;
316    uint16_t                 drxRetransmissionTimerUl;
317    DrxLongCycleStartOffset  drxLongCycleStartOffset;
318    bool                     shortDrxPres;
319    ShortDrx                 shortDrx;
320    uint8_t                  drxSlotOffset;
321 }DrxCfg;
322 #endif
323
324 typedef struct cuUeCb
325 {
326    CuCellCb  *cellCb;
327    uint32_t  crnti;
328    uint8_t   gnbDuUeF1apId;
329    uint8_t   gnbCuUeF1apId;
330    uint16_t  pdcpSn;
331    uint8_t   numSrb;
332    SrbInfo   srbList[MAX_NUM_SRB];
333    uint8_t   numDrb;
334    DrbInfo   drbList[MAX_NUM_DRB];
335    F1apMsgDb f1apMsgDb;
336    UeState   state;
337 #ifdef NR_DRX
338    bool      drxCfgPresent;
339    DrxCfg    drxCfg;
340 #endif
341    HandoverInfo hoInfo;
342 }CuUeCb;
343
344 struct cuCellCb
345 {
346    uint32_t nrCellId;
347    uint8_t  numUe;
348    CuUeCb   *ueCb[MAX_NUM_UE];
349    CellStatusInfo cellStatus;
350 };
351
352 typedef struct duDb
353 {
354    uint32_t duId;
355    char     duName[CU_DU_NAME_LEN_MAX];
356    uint8_t  numCells;
357    CuCellCb cellCb[MAX_NUM_CELL];  
358    uint8_t  numUe;
359    CuUeCb   ueCb[MAX_NUM_CELL * MAX_NUM_UE];
360    CuUeCb   *tempUeCtxtInHo;
361 }DuDb;
362
363 typedef struct cuGlobalCb
364 {
365    CuCfgParams cuCfgParams;
366    uint8_t     numSnssaiSupported;
367    Snssai      *snssaiList[MAX_NUM_OF_SLICE];
368    uint8_t     numDu;
369    DuDb        duInfo[MAX_DU_SUPPORTED];
370    uint32_t    gnbCuUeF1apIdGenerator;   /* Generating CU UE F1AP ID */
371 }CuGlobalCb;
372
373 CuGlobalCb cuCb;
374
375 void readCuCfg();
376 void cuAppInmsgHdlr(Buffer *mBuf);
377 void sctpNtfyInd(CmInetSctpNotification *ntfy);
378 uint8_t egtpInitReq();
379 void *cuConsoleHandler(void *);
380
381 #endif
382
383 /**********************************************************************
384          End of file
385 **********************************************************************/