85447f225839c6c0dbd799351658234ad5166346
[o-du/l2.git] / src / du_app / du_e2ap_mgr.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 /* This file contains all E2AP message handler related functionality */
20 #define MAX_E2_SETUP_TMR 1
21 #define MAX_E2_NODE_CONFIG_UPDATE_TMR 1
22 #define MAX_RIC_SERVICE_UPDATE_TMR 1
23 #define MAX_RIC_SUBSCRIPTION_REPORTING_TMR 1
24
25 #define EVENT_E2_SETUP_TMR 1
26 #define EVENT_RIC_SERVICE_UPDATE_TMR 2
27 #define EVENT_E2_NODE_CONFIG_UPDATE_TMR 3
28 #define EVENT_RIC_SUBSCRIPTION_REPORTING_TMR 4
29
30 #define MAX_NUM_TRANSACTION 256 /* As per, O-RAN WG3 E2AP v3.0, section 9.2.33 */
31 #define MAX_RAN_FUNCTION 256        /* O-RAN.WG3.E2AP-R003-v03.00 : Section 9.1.2.2 : maxofRANfunctionID */
32 #define MAX_E2_NODE_COMPONENT 1024     /* O-RAN.WG3.E2AP-R003-v03.00 : Section 9.1.2.2 : maxofE2nodeComponents */
33 #define MAX_TNL_ASSOCIATION 32         /* O-RAN.WG3.E2AP-R003-v03.00 : Section 9.1.2.11 : maxofTNLA */
34 #define MAX_RIC_STYLES 64           /* O-RAN.WG3.E2SM-KPM-R003-v03.00 : Section 8.2.2.1 : maxnoofRICstyle */
35 #define MAX_MEASUREMENT_INFO 65535     /* O-RAN.WG3.E2SM-KPM-R003-v03.00 : Section 8.2.2.1 : maxnoofMeasurementInfo */
36 #define MAX_LABEL_INFO  2147483648     /* O-RAN.WG3.E2SM-KPM-R003-v03.00 : Section 8.2.1.2.1 : maxnoofLabelInfo */
37 #define MAX_RIC_ACTION  16          /* O-RAN.WG3.E2AP-R003-v03.00 : Section 9.1.1.1 : maxofRICActionID */
38 #define MAX_RIC_REQUEST 65535       /* O-RAN.WG3.E2AP-R003-v03.00 : Section 9.2.7 */
39 #define MAX_PENDING_SUBSCRIPTION_RSP 5  /* Number of statistics request in processing */
40
41 #define STRING_SIZE_150_BYTES 150
42 #define STRING_SIZE_1000_BYTES 1000
43
44 #define SHORT_NAME "ORAN-E2SM-KPM"
45 #define SERVICE_MODEL_OID  "1.3.6.1.4.1.53148.1.2.2.2"
46 #define DESCRIPTION "KPM Monitor"
47 #define NUM_OF_EVENT_TRIGGER_STYLE_SUPPORTED 1
48 #define EVENT_TRIGGER_STYLE_NAME "Periodic Report"
49 #define EVENT_TRIGGER_STYLE_TYPE 1
50 #define EVENT_TRIGGER_STYLE_FORMAT_TYPE 1
51 #define NUM_OF_RIC_REPORT_STYLE_SUPPORTED 1
52 #define REPORT_STYLE_NAME "E2 Node Measurement"
53 #define REPORT_STYLE_TYPE 1
54 #define REPORT_ACTION_FORMAT_TYPE 1
55 #define MEASUREMENT_TYPE_NAME (char*[]) {"RRU.PrbTotDl", "RRU.PrbTotUl"}
56 #define RIC_INDICATION_HEADER_FORMAT 1
57 #define RIC_INDICATION_MESSAGE_FORMAT 1
58
59 /* O-RAN.WG3.E2AP-R003-v03.00 : Section 9.2.26 */
60 typedef enum
61 {
62    NG,
63    XN,
64    E1,
65    F1,
66    W1,
67    S1,
68    X2
69 }InterfaceType;
70
71 typedef enum
72 {
73    E2_NODE_COMPONENT_ADD,
74    E2_NODE_COMPONENT_UPDATE,
75    E2_NODE_COMPONENT_DEL
76 }ComponentActionType;
77
78
79 /* O-RAN.WG3.E2AP-R003-v03.00 : Section 9.2.30 */
80 typedef enum
81 {
82    RIC_SERVICE,
83    SUPPORT_FUNCTIONS,
84    BOTH_FUNCTIONALITY
85 }AssocUsage;
86
87 /* O-RAN.WG3.E2AP-R003-v03.00 : Section 9.2.11 */
88 typedef enum
89 {
90    REPORT,
91    INSERT,
92    POLICY
93 }ActionType;
94
95 typedef enum
96 {
97    RIC_INITIATED,
98    E2_NODE_INITIATED
99 }E2ProcedureDirection;
100
101 typedef enum
102 {
103    E2_RAN_FUNCTION_ID_INVALID,
104    E2_ACTION_NOT_SUPPORTED,
105    E2_EXECESSIVE_ACTIONS,
106    E2_DUPLICATE_ACTION,
107    E2_DUPLICATE_EVENT_TRIGGER,
108    E2_FUNCTION_RESOURCE_LIMIT,
109    E2_REQUEST_ID_UNKNOWN,
110    E2_INCONSISTENT_ACTION_SUBSEQUENT_ACTION_SEQUENCE,
111    E2_CONTROL_MESSAGE_INVALID,
112    E2_RIC_CALL_PROCESS_ID_INVALID,
113    E2_CONTROL_TIMER_EXPIRED,
114    E2_CONTROL_FAILED_TO_EXECUTE,
115    E2_SYSTEM_NOT_READY,
116    E2_RIC_REQUEST_CAUSE_UNSPECIFIED,
117    E2_RIC_SUBSCRIPTION_END_TIME_EXPIRED,
118    E2_RIC_SUBSCRIPTION_END_TIME_INVALID,
119    E2_DUPLICATE_RIC_REQUEST_ID,
120    E2_EVENT_TRIGGER_NOT_SUPPORTED,
121    E2_REQUEST_INFORMATION_UNAVAILABLE,
122    E2_INVALID_INFORMATION_REQUEST
123 }E2CauseRicRequest;
124
125 typedef enum
126 {
127    E2_RAN_FUNCTION_NOT_SUPPORTED,
128    E2_EXCESSIVE_FUNCTIONS,
129    E2_RIC_RESOURCE_LIMIT,
130 }E2CauseRicService;
131
132 typedef enum
133 {
134    E2_NODE_COMPONENT_UNKNOWN
135 }E2CauseE2Node;
136
137 typedef enum
138 {
139    E2_TRANSPORT_CAUSE_UNSPECIFIED,
140    E2_TRANSPORT_RESOURCE_UNAVAILABLE
141 }E2CauseTransport;
142
143 typedef enum
144 {
145    E2_TRANSFER_SYNTAX_ERROR,
146    E2_ABSTRACT_SYNTAX_ERROR_REJECT,
147    E2_ABSTRACT_SYNTAX_ERROR_IGNORE_AND_NOTIFY,
148    E2_MESSAGE_NOT_COMPATIBLE_WITH_RECEIVER_STATE,
149    E2_SEMANTIC_ERROR,
150    E2_ABSTRACT_SYNTAX_ERROR_FALSELY_CONSTRUCTED_MESSAGE,
151    E2_PROTOCOL_CAUSE_UNSPECIFIED
152 }E2CauseProtocol;
153
154 typedef enum
155 {
156    E2_CONTROL_PROCESSING_OVERLOAD,
157    E2_HARDWARE_FAILURE,
158    E2_OM_INTERVENTION,
159    E2_MISCELLANEOUS_CAUSE_UNSPECIFIED
160 }E2CauseMisc;
161
162 typedef enum 
163 {
164    E2_NOTHING,
165    E2_RIC_REQUEST,
166    E2_RIC_SERVICE,
167    E2_NODE,
168    E2_TRANSPORT,
169    E2_PROTOCOL,
170    E2_MISCELLANEOUS
171 }E2CauseType;
172
173 typedef uint8_t E2Cause;
174
175 typedef struct e2FailureCause
176 {
177    E2CauseType causeType;
178    uint8_t     cause;
179 }E2FailureCause;
180
181 typedef struct
182 {
183    uint8_t transactionId;
184    uint8_t procedureCode;
185 }E2TransInfo;
186
187 typedef struct e2Transcation
188 {
189    uint8_t     transIdCounter; /* counting the total number of DU initiated transaction */
190    E2TransInfo e2InitTransaction[MAX_NUM_TRANSACTION]; /* Storing DU-initiated transactions information */
191    E2TransInfo ricInitTransaction[MAX_NUM_TRANSACTION]; /* Storing RIC-initiated transactions information */
192 }E2Transaction;
193
194 typedef struct
195 {
196    uint16_t   id;
197    uint16_t   revisionCounter;
198 }RanFuncInfo;
199
200 typedef struct
201 {
202    uint8_t     numOfRanFunToBeAdded;
203    RanFuncInfo ranFunToBeAdded[MAX_RAN_FUNCTION];
204    uint8_t     numOfRanFunToBeModified;
205    RanFuncInfo ranFunToBeModified[MAX_RAN_FUNCTION];
206    uint8_t     numOfRanFunToBeDeleted;
207    RanFuncInfo ranFunToBeDeleted[MAX_RAN_FUNCTION];
208 }E2TmpRanFunList;
209
210 typedef struct ricServiceUpdate
211 {
212    E2ProcedureDirection dir;
213    uint8_t              transId;
214    E2TmpRanFunList      recvRanFuncList;
215 }RicServiceUpdate;
216
217 typedef struct 
218 {
219    RicServiceUpdate ricService;
220    CmTimer          timer;
221 }RicServiceUpdateTimer;
222
223 typedef struct e2NodeCfgItem
224 {
225    InterfaceType interface;
226    uint64_t      componentId; 
227 }E2NodeConfigItem;
228
229 typedef struct e2NodeCfgList
230 {
231    uint16_t addE2NodeCount;
232    E2NodeConfigItem addE2Node[MAX_E2_NODE_COMPONENT];
233    uint16_t updateE2NodeCount;
234    E2NodeConfigItem updateE2Node[MAX_E2_NODE_COMPONENT];
235    uint16_t removeE2NodeCount;
236    E2NodeConfigItem removeE2Node[MAX_E2_NODE_COMPONENT];
237 }E2NodeConfigList;
238
239 typedef struct
240 {
241    E2NodeConfigList configList;
242    CmTimer    timer;
243 }E2NodeConfigUpdateTimer;
244
245 typedef struct e2Timer
246 {
247    CmTimer e2SetupTimer;
248    RicServiceUpdateTimer   ricServiceUpdateTimer;
249    E2NodeConfigUpdateTimer e2NodeConfigUpdate;
250    /* More timers can be added to this structure in future */
251 }E2Timer;
252
253
254 /* O-RAN.WG3.E2AP-R003-v03.00 : Section 9.2.4 */
255 typedef struct
256 {
257    Plmn     plmnId; 
258    uint32_t nearRtRicId;
259 }GlobalRicId;
260
261 /* O-RAN.WG3.E2SM-R003-v03.00 : Section 6.2.2.1 */
262 typedef struct
263 {
264    char  shortName[STRING_SIZE_150_BYTES];
265    char  serviceModelOID[STRING_SIZE_1000_BYTES];
266    char  description[STRING_SIZE_150_BYTES];
267 }RanFunctionName;
268
269 /* O-RAN.WG3.E2SM-R003-v03.00 : Section 6.2.2.2-6.2.2.4 */
270 typedef struct
271 {
272    uint8_t styleType;
273    char    name[STRING_SIZE_150_BYTES];
274    uint8_t formatType;
275 }RicStyle;
276
277 /* O-RAN.WG3.E2SM-KPM-R003-v03.00 : Section 8.2.2.1 */
278 typedef struct
279 {
280    char     measurementTypeName[STRING_SIZE_150_BYTES];
281    uint16_t measurementTypeId;
282 }MeasurementInfoForAction;
283
284 typedef struct
285 {
286    RicStyle       reportStyle;
287    CmLListCp      measurementInfoList;
288 }RicReportStyle;
289
290 /* O-RAN.WG3.E2AP-R003-v03.00 : Section 9.2.7 */
291 typedef struct
292 {
293    uint16_t requestorId;
294    uint16_t instanceId;
295 }RicRequestId;
296
297 typedef struct reportStartTime
298 {
299    uint32_t timeInSec;
300    uint32_t timeInMilliSec;
301 }ReportStartTime;
302
303 /* O-RAN.WG3.E2SM-KPM-R003-v03.00 : Section 8.2.1.1.1 */
304 typedef struct
305 {
306    uint32_t reportingPeriod; /* In milliseconds */
307    ReportStartTime startTime;
308 }EventTriggerFormat1;
309
310 /* O-RAN.WG3.E2SM-KPM-R003-v03.00 : Section 8.2.1.1 */
311 typedef struct
312 {
313    uint8_t  formatType;
314    union
315    {
316       EventTriggerFormat1 format1;
317       /* More formats can be added in future */
318    }choice;
319 }EventTriggerDefinition;
320
321 /* O-RAN.WG3.E2SM-KPM-R003-v03.00 : Section 8.3.11 */
322 typedef struct
323 {
324    /* TODO : To be added in future when subcounters for any
325     * measurment type is required */
326 }LabelInfo;
327
328 /* O-RAN.WG3.E2SM-KPM-R003-v03.00 : Section 8.2.1.2.1 */
329 typedef struct
330 {
331    char     measurementTypeName[STRING_SIZE_150_BYTES];
332    uint16_t measurementTypeId;
333
334    /* As of now Labels are not used, hence it is not implemented completely */
335    //uint32_t    numOfLabels;
336    //LabelInfo   LabelInfoList[MAX_LABEL_INFO];
337
338    CmLListCp   measuredValue;  /* To be filled when numOfLabels is 0, else values are calculated per Label */
339 }MeasurementInfo;
340
341 /* O-RAN.WG3.E2SM-KPM-R003-v03.00 : Section 8.2.1.2.1 */
342 typedef struct
343 {
344    CmLListCp               measurementInfoList;    /* Each node corresponds to MeasurementInfo */
345    uint32_t                granularityPeriod;      /* In millisecond */
346 }ActionDefFormat1;
347
348 /* O-RAN.WG3.E2SM-KPM-R003-v03.00 : Section 8.2.1.2.2 */
349 typedef struct
350 {
351    /* TODO : This format will be defined in future if required */
352 }ActionDefFormat2;
353
354 /* O-RAN.WG3.E2SM-KPM-R003-v03.00 : Section 8.2.1.2.3 */
355 typedef struct
356 {
357    /* TODO : This format will be defined in future if required */
358 }ActionDefFormat3;
359
360 /* O-RAN.WG3.E2SM-KPM-R003-v03.00 : Section 8.2.1.2.4 */
361 typedef struct
362 {
363    /* TODO : This format will be defined in future if required */
364 }ActionDefFormat4;
365
366 /* O-RAN.WG3.E2SM-KPM-R003-v03.00 : Section 8.2.1.2.5 */
367 typedef struct
368 {
369    /* TODO : This format will be defined in future if required */
370 }ActionDefFormat5;
371
372 /* O-RAN.WG3.E2SM-KPM-R003-v03.00 : Section 8.2.1.2 */
373 typedef struct
374 {
375    uint8_t     styleType;
376    uint8_t     formatType;
377    union
378    {
379       ActionDefFormat1  format1;
380       ActionDefFormat2  format2;
381       ActionDefFormat3  format3;
382       ActionDefFormat4  format4;
383       ActionDefFormat5  format5;
384    }choice;
385 }ActionDefinition;
386
387 /* O-RAN.WG3.E2AP-R003-v03.00 : Section 9.1.1.1 : maxofRICActionID */
388 typedef struct
389 {
390    int16_t           actionId;     /* O-RAN.WG3.E2AP-R003-v03.00 Section 9.2.10. Valid action id range = 0..255 */
391    ActionType        type;
392    ActionDefinition  definition;
393    ConfigType        action;
394    E2FailureCause    failureCause; /* Used only when an action is required to be deleted */
395 }ActionInfo;
396
397 /* O-RAN.WG3.E2AP-R003-v03.00 : Section 9.1.1.1 : maxofRICActionID */
398 typedef struct
399 {
400    RicRequestId           requestId;
401    uint16_t               ranFuncId;
402    EventTriggerDefinition eventTriggerDefinition;
403    CmLListCp              actionSequence; 
404    CmTimer                ricSubsReportTimer;
405    ConfigType             action;
406    E2FailureCause         failureCause; /* Used only when a subscription is required to be deleted */
407 }RicSubscription;
408
409 typedef struct rejectedAction
410 {
411    uint8_t id;
412    E2FailureCause failureCause;
413 }RejectedAction;
414
415 typedef struct pendingSubsRspInfo
416 {
417    RicRequestId    requestId;
418    uint16_t        ranFuncId;
419    uint8_t         numOfAcceptedActions;
420    uint8_t         acceptedActionList[MAX_RIC_ACTION];
421    uint8_t         numOfRejectedActions;
422    RejectedAction  rejectedActionList[MAX_RIC_ACTION];
423 }PendingSubsRspInfo;
424
425 typedef struct
426 {
427    /* O-RAN.WG3.E2SM-KPM-R003-v03.00 : Section 8.2.2.1 */
428    uint16_t         id;
429    RanFunctionName  name;
430    uint16_t         revisionCounter;
431    uint8_t          numOfEventTriggerStyleSupported;
432    RicStyle         eventTriggerStyleList[MAX_RIC_STYLES];
433    uint8_t          numOfReportStyleSupported;
434    RicReportStyle   reportStyleList[MAX_RIC_STYLES];
435    uint8_t          ricIndicationHeaderFormat;
436    uint8_t          ricIndicationMessageFormat;
437    /* O-RAN.WG3.E2AP-R003-v03.00 : Section 9.1.1.1 */
438    CmLListCp        subscriptionList;
439    uint8_t          numPendingSubsRsp;
440    PendingSubsRspInfo pendingSubsRspInfo[MAX_PENDING_SUBSCRIPTION_RSP];
441 }RanFunction;
442
443 /* O-RAN.WG3.E2AP-R003-v03.00 : Section 9.2.26-9.2.27 */
444 typedef struct
445 {
446    uint8_t    reqBufSize;
447    uint8_t    *componentRequestPart;
448    uint8_t    rspBufSize;
449    uint8_t    *componentResponsePart;
450 }E2NodeConfig;
451
452 typedef struct
453 {
454    InterfaceType interfaceType;
455    uint64_t      componentId; 
456    E2NodeConfig  *addConfiguration;
457    E2NodeConfig  *updateConfiguration;
458    bool          deleteConfiguration;
459 }E2NodeComponent;
460
461 /* O-RAN.WG3.E2AP-R003-v03.00 : Section 9.2.29 */
462
463 typedef struct e2Ipaddr
464 {
465    bool     ipV4Pres;
466    uint32_t ipV4Addr;
467 }E2IpAddr;
468
469 typedef struct
470 {
471    E2IpAddr    localIpAddress;
472    uint16_t    localPort;
473    E2IpAddr    destIpAddress;
474    uint16_t    destPort;
475    AssocUsage  usage;
476 }TNLAssociation;
477
478 typedef struct e2TimersInfo
479 {
480    E2Timer  e2Timers;
481    uint8_t  e2SetupTimerInterval;
482 }E2TimersInfo;
483
484 typedef struct
485 {
486    uint64_t         e2NodeId; 
487    GlobalRicId      ricId;
488    E2Transaction    e2TransInfo;
489    uint16_t         numOfRanFunction;
490    RanFunction      ranFunction[MAX_RAN_FUNCTION];  
491    CmLListCp        e2NodeComponentList; 
492    uint8_t          numOfTNLAssoc;
493    TNLAssociation   tnlAssoc[MAX_TNL_ASSOCIATION];
494    E2TimersInfo     e2TimersInfo;
495 }E2apDb;
496
497 typedef struct e2ConnectionItem
498 {
499    uint32_t    ipV4Addr;
500    AssocUsage  usage;
501 }E2ConnectionItem;
502
503 typedef struct e2ConnectionList
504 {
505    uint8_t numOfE2ConnectionSetup;
506    E2ConnectionItem setupE2Connection[MAX_TNL_ASSOCIATION];
507    uint8_t numOfE2ConnectionFailedToSetup;
508    E2ConnectionItem failedToSetupE2Connection[MAX_TNL_ASSOCIATION];
509 }E2ConnectionList;
510
511 uint8_t assignTransactionId();
512 ActionInfo *fetchActionInfoFromActionId(uint8_t actionId, RicSubscription *ricSubscriptionInfo, CmLList ** actionNode);
513 RicSubscription *fetchSubsInfoFromRicReqId(RicRequestId ricReqId, RanFunction *ranFuncDb, CmLList **ricSubscriptionNode);
514 RanFunction *fetchRanFuncFromRanFuncId(uint16_t ranFuncId);
515 uint8_t fetchSubsInfoFromSubsId(uint64_t subscriptionId, RanFunction **ranFuncDb, CmLList **ricSubscriptionNode, \
516    RicSubscription **ricSubscriptionInfo);
517 void fetchRicSubsToBeDeleted(CmLListCp *ricSubsToBeDelList);
518
519 uint8_t fillRicSubsInMacStatsReq(MacStatsReq *macStatsReq, RicSubscription* ricSubscriptionInfo);
520 uint8_t e2ProcStatsRsp(MacStatsRsp *statsRsp);
521 uint8_t e2ProcStatsInd(MacStatsInd *statsInd);
522 void E2apHdlRicSubsReportTmrExp(RicSubscription *ricSubscription);
523
524 uint8_t ResetE2Request(E2ProcedureDirection dir, E2FailureCause resetCause);
525 uint8_t SendE2APMsg(Region region, Pool pool, char *encBuf, int encBufSize);
526 E2NodeComponent *fetchE2NodeComponentInfo(InterfaceType interfaceType, uint64_t componentId, CmLList **e2ComponentNode);
527 uint8_t fillE2NodeComponentReqInfo(InterfaceType interfaceType, uint64_t componentId, uint8_t action, uint8_t bufSize, char *bufString);
528 uint8_t fillE2NodeComponentRspInfo(InterfaceType interfaceType, uint64_t componentId, uint8_t action, uint8_t bufSize, char *bufString);
529 void deleteRicSubscriptionList(CmLListCp *subscriptionList);
530 void deleteRicSubscriptionNode(CmLList *ricSubscriptionInfo);
531 void deleteMeasurementInfoList(CmLListCp *measInfoList);
532 void deleteActionSequence(CmLList *action);
533 void deleteMeasuredValueList(CmLListCp *measuredValueList);
534 void removeE2NodeInformation();
535 void encodeSubscriptionId(uint64_t *subscriptionId, uint16_t ranFuncId, RicRequestId ricReqId);
536 uint8_t e2ProcStatsDeleteRsp(MacStatsDeleteRsp *statsDeleteRsp);
537 uint8_t fillRicSubsInMacStatsModificationReq(MacStatsModificationReq *macStatsModReq, RicSubscription* ricSubscriptionInfo);
538
539 /**********************************************************************
540   End of file
541  **********************************************************************/