Jira Id - ODUHIGH-391, Implementation of Slice Cfg and ReCfg request and response
[o-du/l2.git] / src / du_app / du_mgr_main.c
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 is the entry point for DU APP */
20 #include "common_def.h"
21 #include "lrg.h"
22 #include "legtp.h"
23 #include "lrg.x"
24 #include "lkw.x"
25 #include "du_app_mac_inf.h"
26 #include "du_app_rlc_inf.h"
27 #include "du_cfg.h"
28 #include "du_mgr.h"
29 #include "du_mgr_main.h"
30 #include "du_sctp.h"
31 #include "du_egtp.h"
32
33 #ifdef O1_ENABLE
34
35 #include "O1Interface.h"
36 #include "ConfigInterface.h"
37
38 #endif
39
40 uint8_t rlcUlActvTsk (Pst *, Buffer *);
41 uint8_t rlcUlActvInit (Ent, Inst, Region, Reason);
42 uint8_t rlcDlActvTsk (Pst *, Buffer *);
43 uint8_t rlcDlActvInit (Ent, Inst, Region, Reason);
44 uint8_t rgActvTsk (Pst *, Buffer *);
45 uint8_t rgActvInit (Ent, Inst, Region, Reason);
46 uint8_t lwrMacActvTsk(Pst *, Buffer *);
47 uint8_t lwrMacActvInit(Ent, Inst, Region, Reason);
48 #ifndef INTEL_WLS_MEM
49 uint8_t phyStubActvTsk(Pst *, Buffer *);
50 uint8_t phyStubActvInit(Ent, Inst, Region, Reason);
51 #endif
52
53 /* Global variable */
54 DuCfgParams duCfgParam;
55
56 /*******************************************************************
57  *
58  * @brief Initializes DU APP
59  *
60  * @details
61  *
62  *    Function : duAppInit
63  *
64  *    Functionality:
65  *       - Registers and attaches TAPA tasks belonging to 
66  *         DU_APP sys task
67  *
68  * @params[in] system task ID
69  * @return ROK     - success
70  *         RFAILED - failure
71  *
72  * ****************************************************************/
73 uint8_t duAppInit(SSTskId sysTskId)
74 {
75    /* Register DU APP TAPA Task for DU */
76    if(ODU_REG_TTSK((Ent)ENTDUAPP, (Inst)DU_INST, (Ttype)TTNORM, (Prior)PRIOR0,
77       duActvInit, (ActvTsk)duActvTsk) != ROK)
78    {
79       return RFAILED;
80    }
81    /* Attach DU APP TAPA Task for DU */
82    if (ODU_ATTACH_TTSK((Ent)ENTDUAPP, (Inst)0, sysTskId)!= ROK)
83    {
84       return RFAILED;
85    }
86
87    DU_LOG("\nINFO   -->  DU_APP : DU APP created and registered \
88    to %d sys task", sysTskId);
89    return ROK;
90 }
91
92 #ifdef O1_ENABLE
93
94 /*******************************************************************
95  *
96  * @brief update Rrm Policy at DU and process the slice cfg request
97  *
98  * @details
99  *
100  *    Function : updateRrmPolicy 
101  *
102  *    Functionality:
103  *       - update Rrm Policy at DU and process the slice cfg request
104  *
105  * @params[in] RrmPolicy rrmPolicy[], uint8_t policyNum, uint8_t memberList
106  * @return true     - success
107  *         false    - failure
108  *
109  * ****************************************************************/
110 uint8_t updateRrmPolicy(RrmPolicy rrmPolicy[], uint8_t policyNum, \
111            uint8_t memberList)
112 {
113     DuCellCb *cellCb = NULLP;
114
115     cpyRrmPolicyInDuCfgParams(rrmPolicy, policyNum, memberList, &duCfgParam.tempSliceCfg);
116     cellCb = duCb.actvCellLst[0];
117
118     if(cellCb)
119     {
120        if(cellCb->cellStatus == ACTIVATED)
121        {
122            if(duCb.sliceState == SLICE_INFO_NOT_AVAILABLE)
123            {
124               BuildAndSendSliceConfigReq(duCfgParam.tempSliceCfg.rrmPolicy, duCfgParam.tempSliceCfg.totalRrmPolicy,\
125               duCfgParam.tempSliceCfg.totalSliceCount);
126            }
127            else 
128            {
129               BuildAndSendSliceReCfgReq(duCfgParam.tempSliceCfg.rrmPolicy, duCfgParam.tempSliceCfg.totalRrmPolicy,\
130               duCfgParam.tempSliceCfg.totalSliceCount);
131            }
132        }
133     }
134 }
135
136 /*******************************************************************
137  *
138  * @brief Bring the cell Up
139  *
140  * @details
141  *
142  *    Function : bringCellUp
143  *
144  *    Functionality:
145  *       - Bring the cell Up when requested from OAM
146  *
147  * @params[in] Cell Id
148  * @return true     - success
149  *         false    - failure
150  *
151  * ****************************************************************/
152
153 bool bringCellUp(uint16_t cellId)
154 {
155    duProcCfgComplete();
156    BuildAndSendF1SetupReq();
157    return true;
158 }
159
160 /*******************************************************************
161  *
162  * @brief Bring the cell Down
163  *
164  * @details
165  *
166  *    Function : bringCellDown
167  *
168  *    Functionality:
169  *       - Bring the cell Down when requested from OAM
170  *
171  * @params[in] Cell Id
172  * @return true     - success
173  *         false    - failure
174  *
175  * ****************************************************************/
176
177 bool bringCellDown(uint16_t cellId)
178 {
179    BuildAndSendDUConfigUpdate(SERV_CELL_TO_DELETE);
180    return true;
181 }
182 #endif
183
184 /*******************************************************************
185  *
186  * @brief Initializes EGTP
187  *
188  * @details
189  *
190  *    Function : egtpInit
191  *
192  *    Functionality:
193  *       - Registers and attaches TAPA tasks belonging to 
194  *         DU_APP sys task
195  *
196  * @params[in] system task ID
197  * @return ROK     - success
198  *         RFAILED - failure
199  *
200  * ****************************************************************/
201 uint8_t egtpInit(SSTskId sysTskId)
202 {
203    /* Register DU APP TAPA Task for DU */
204    if(ODU_REG_TTSK((Ent)ENTEGTP, (Inst)EGTP_INST, (Ttype)TTNORM, (Prior)PRIOR0,
205              egtpActvInit, (ActvTsk)egtpActvTsk) != ROK)
206    {
207       return RFAILED;
208    }
209    /* Attach DU APP TAPA Task for DU */
210    if (ODU_ATTACH_TTSK((Ent)ENTEGTP, (Inst)0, sysTskId)!= ROK)
211    {
212       return RFAILED;
213    }
214  
215     DU_LOG("\nINFO   -->  DU_APP : EGTP created and registered \
216     to %d sys task", sysTskId);
217     return ROK;
218 }
219  
220
221 /*******************************************************************
222  *
223  * @brief Initializes SCTP task
224  *
225  * @details
226  *
227  *    Function : sctpInit
228  *
229  *    Functionality:
230  *       - Registers and attaches TAPA tasks for SCTP receiver 
231  *
232  * @params[in] system task ID
233  * @return ROK     - success
234  *         RFAILED - failure
235  *
236  * ****************************************************************/
237 uint8_t sctpInit(SSTskId sysTskId)
238 {
239    /* Register SCTP TAPA Task */
240    if(ODU_REG_TTSK((Ent)ENTSCTP, (Inst)0, (Ttype)TTNORM, (Prior)PRIOR0,
241             sctpActvInit, (ActvTsk)sctpActvTsk) != ROK)
242    {
243       return RFAILED;
244    }
245    /* Attach SCTP TAPA Task */
246    if (ODU_ATTACH_TTSK((Ent)ENTSCTP, (Inst)SCTP_INST, sysTskId)!= ROK)
247    {
248       return RFAILED;
249    }
250
251    DU_LOG("\nINFO   -->  DU_APP : SCTP TAPA task created and registered to %d sys task", 
252          sysTskId);
253    return ROK;
254 }
255 /*******************************************************************
256  *
257  * @brief Initializes RLC DL, MAC TAPA task
258  *
259  * @details
260  *
261  *    Function : rlcDlInit
262  *
263  *    Functionality:
264  *       - Registers and attaches TAPA tasks for MAC and RLC DL
265  *
266  * @params[in] system task ID
267  * @return ROK     - success
268  *         RFAILED - failure
269  *
270  * ****************************************************************/
271 uint8_t rlcDlInit(SSTskId sysTskId)
272 {
273    /* Register RLC DL TAPA Task */
274    if(ODU_REG_TTSK((Ent)ENTRLC, (Inst)1, (Ttype)TTNORM, (Prior)PRIOR0,
275             rlcDlActvInit, (ActvTsk)rlcDlActvTsk) != ROK)
276    {
277       return RFAILED;
278    }
279    /* Attach RLC DL Task */
280    if (ODU_ATTACH_TTSK((Ent)ENTRLC, (Inst)1, sysTskId)!= ROK)
281    {
282       return RFAILED;
283    }
284
285    /* Register MAC TAPA Task */
286    if(ODU_REG_TTSK((Ent)ENTMAC, (Inst)0, (Ttype)TTNORM, (Prior)PRIOR0,
287             rgActvInit, (ActvTsk)rgActvTsk) != ROK)
288    {
289       return RFAILED;
290    }
291    /* Attach MAC Task */
292    if (ODU_ATTACH_TTSK((Ent)ENTMAC, (Inst)0, sysTskId)!= ROK)
293    {
294       return RFAILED;
295    }
296
297    DU_LOG("\nINFO   -->  DU_APP : RLC DL and MAC TAPA task created and registered to \
298    %d sys task", sysTskId);
299    return ROK;
300 }
301
302 /*******************************************************************
303  *
304  * @brief Initializes RLC UL TAPA task
305  *
306  * @details
307  *
308  *    Function : rlcUlInit
309  *
310  *    Functionality:
311  *       - Registers and attaches TAPA task for RLC UL
312  *
313  * @params[in] system task ID
314  * @return ROK     - success
315  *         RFAILED - failure
316  *
317  * ****************************************************************/
318 uint8_t rlcUlInit(SSTskId sysTskId)
319 {
320    /* Register RLC UL TAPA Task */
321    if(ODU_REG_TTSK((Ent)ENTRLC, (Inst)0, (Ttype)TTNORM, (Prior)PRIOR0,
322             rlcUlActvInit, (ActvTsk)rlcUlActvTsk) != ROK)
323    {
324       return RFAILED;
325    }
326    /* Attach RLC DL Task */
327    if (ODU_ATTACH_TTSK((Ent)ENTRLC, (Inst)0, sysTskId)!= ROK)
328    {
329       return RFAILED;
330    }
331    DU_LOG("\nINFO   -->  DU_APP : RLC UL TAPA task created and registered to \
332    %d sys task", sysTskId);
333    return ROK;
334 }
335
336 /*******************************************************************
337  *
338  * @brief Initializes Lower MAC receiver task
339  *
340  * @details
341  *
342  *    Function : lwrMacInit
343  *
344  *    Functionality:
345  *       - Registers and attaches TAPA tasks for Lower MAC receiver
346  *
347  * @params[in] system task ID
348  * @return ROK     - success
349  *         RFAILED - failure
350  *
351  * ****************************************************************/
352 uint8_t lwrMacInit(SSTskId sysTskId)
353 {
354    /* Register SCTP TAPA Task */
355    if(ODU_REG_TTSK((Ent)ENTLWRMAC, (Inst)0, (Ttype)TTNORM, (Prior)PRIOR0,
356             lwrMacActvInit, (ActvTsk)lwrMacActvTsk) != ROK)
357    {
358       return RFAILED;
359    }
360    /* Attach SCTP TAPA Task */
361    if (ODU_ATTACH_TTSK((Ent)ENTLWRMAC, (Inst)0, sysTskId)!= ROK)
362    {
363       return RFAILED;
364    }
365
366    DU_LOG("\nINFO   -->  DU_APP : LWR MAC TAPA task created and registered to %d sys task",
367          sysTskId);
368    return ROK;
369 }
370
371 #ifndef INTEL_WLS_MEM
372 /*******************************************************************
373  *
374  * @brief Initializes Phy stub slot indication generator task
375  *
376  * @details
377  *
378  *    Function : phyStubInit
379  *
380  *    Functionality:
381  *       - Registers and attaches TAPA tasks for Phy stub's slot
382  *       indication generator
383  *
384  * @params[in] system task ID
385  * @return ROK     - success
386  *         RFAILED - failure
387  *
388  * ****************************************************************/
389 uint8_t phyStubInit(SSTskId sysTskId)
390 {
391    /* Register PHY stub slot indication TAPA Task */
392    if(ODU_REG_TTSK((Ent)ENTPHYSTUB, (Inst)0, (Ttype)TTNORM, (Prior)PRIOR0,
393             phyStubActvInit, (ActvTsk)phyStubActvTsk) != ROK)
394    {
395       return RFAILED;
396    }
397    /* Attach Phy stub slot indication TAPA Task */
398    if (ODU_ATTACH_TTSK((Ent)ENTPHYSTUB, (Inst)0, sysTskId)!= ROK)
399    {
400       return RFAILED;
401    }
402
403    DU_LOG("\nINFO   -->  DU_APP : PHY stub slot indication TAPA task created and registered to %d sys task",
404          sysTskId);
405    return ROK;
406 }
407 #endif
408
409 /*******************************************************************
410  *
411  * @brief Initializes system and TAPA tasks
412  *
413  * @details
414  *
415  *    Function : commonInit
416  *
417  *    Functionality:
418  *       - Registers and attaches system and TAPA tasks
419  *
420  * @params[in] void
421  * @return ROK     - success
422  *         RFAILED - failure
423  *
424  * ****************************************************************/
425 uint8_t commonInit()
426 {
427    /* Declare system task Ids */
428    SSTskId du_app_stsk, egtp_stsk, sctp_stsk, rlc_ul_stsk, rlc_mac_cl_stsk, lwr_mac_stsk, phy_stub_slot_ind_stsk;
429
430    pthread_attr_t attr;
431
432    ODU_SET_PROC_ID(DU_PROC);
433
434    /* Intel L1 using core 0-15. ODU-High using 16-21 */
435    /* system task for DU APP */
436    if(ODU_CREATE_TASK(PRIOR0, &du_app_stsk) != ROK)
437    {
438       DU_LOG("\nERROR  -->  DU_APP : System Task creation for DU APP failed");
439       return RFAILED;
440    }
441    //ODU_SET_THREAD_AFFINITY(&du_app_stsk, SS_AFFINITY_MODE_EXCL, 16, 0);
442
443    /* system task for EGTP */
444    if(ODU_CREATE_TASK(PRIOR0, &egtp_stsk) != ROK)
445    {
446       DU_LOG("\nERROR  -->  DU_APP : System Task creation for EGTP failed");
447       return RFAILED;
448    }
449    //ODU_SET_THREAD_AFFINITY(&egtp_stsk, SS_AFFINITY_MODE_EXCL, 17, 0);
450
451    /* system task for RLC_DL and MAC */
452    if(ODU_CREATE_TASK(PRIOR0, &rlc_mac_cl_stsk) != ROK)
453    {
454       DU_LOG("\nERROR  -->  DU_APP : System Task creation for RLC DL/MAC failed");
455       return RFAILED;
456    }
457    pthread_attr_init(&attr);
458    pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
459    //ODU_SET_THREAD_AFFINITY(&rlc_mac_cl_stsk, SS_AFFINITY_MODE_EXCL, 18, 0);
460
461    /* system task for RLC UL */
462    if(ODU_CREATE_TASK(PRIOR1, &rlc_ul_stsk) != ROK)
463    {
464       DU_LOG("\nERROR  -->  DU_APP : System Task creation for RLC UL failed");
465       return RFAILED;
466    }
467    //ODU_SET_THREAD_AFFINITY(&rlc_ul_stsk, SS_AFFINITY_MODE_EXCL, 19, 0);
468
469    /* system task for SCTP receiver thread */
470    if(ODU_CREATE_TASK(PRIOR0, &sctp_stsk) != ROK)
471    {
472       DU_LOG("\nERROR  -->  DU_APP : System Task creation for SCTP failed");
473       return RFAILED;
474    }
475    //ODU_SET_THREAD_AFFINITY(&sctp_stsk, SS_AFFINITY_MODE_EXCL, 20, 0);
476
477    /* system task for lower-mac receiver thread */
478    if(ODU_CREATE_TASK(PRIOR0, &lwr_mac_stsk) != ROK)
479    {
480       DU_LOG("\nERROR  -->  DU_APP : System Task creation for Lower MAC failed");
481       return RFAILED;
482    }
483    //ODU_SET_THREAD_AFFINITY(&lwr_mac_stsk, SS_AFFINITY_MODE_EXCL, 21, 0);
484
485 #ifndef INTEL_WLS_MEM
486    /* system task for phy stub's slot indication generator thread */
487    if(ODU_CREATE_TASK(PRIOR0, &phy_stub_slot_ind_stsk) != ROK)
488    {
489       DU_LOG("\nERROR  -->  DU_APP : System Task creation for Phy stub slot indication generator failed. MAX STSK [%d]", SS_MAX_STSKS);
490       return RFAILED;
491    }
492
493 #endif
494
495    /* Create TAPA tasks */
496    if(duAppInit(du_app_stsk) != ROK)
497    {
498       DU_LOG("\nERROR  -->  DU_APP : DU APP TAPA Task initialization failed");
499       return RFAILED;
500    }
501
502    if(egtpInit(egtp_stsk) != ROK)
503    {
504       DU_LOG("\nERROR  -->  DU_APP : EGTP TAPA Task initialization failed");
505       return RFAILED;
506    }
507
508    if(sctpInit(sctp_stsk) != ROK)
509    {
510       DU_LOG("\nERROR  -->  DU_APP : SCTP TAPA Task initialization failed");
511       return RFAILED;
512    }
513
514    if(rlcDlInit(rlc_mac_cl_stsk) != ROK)
515    {
516       DU_LOG("\nERROR  -->  DU_APP : RLC DL Tapa Task initialization failed");
517       return RFAILED;
518    } 
519
520    if(rlcUlInit(rlc_ul_stsk) != ROK)
521    {
522      DU_LOG("\nERROR  -->  DU_APP : RLC UL Tapa Task initialization failed");
523      return RFAILED;
524    } 
525
526    if(lwrMacInit(lwr_mac_stsk) != ROK)
527    {
528       DU_LOG("\nERROR  -->  DU_APP : Lower MAC Tapa Task initialization failed");
529       return RFAILED;
530    }
531
532 #ifndef INTEL_WLS_MEM
533    if(phyStubInit(phy_stub_slot_ind_stsk) != ROK)
534    {
535       DU_LOG("\nERROR  -->  DU_APP : PHY stub slot indication Tapa Task initialization failed");
536       return RFAILED;
537    }
538 #endif
539
540    return ROK;
541 }
542
543 /*******************************************************************
544  *
545  * @brief Initializes the DU
546  *
547  * @details
548  *
549  *    Function : duInit
550  *
551  *    Functionality:
552  *       - Calls commonInit
553  *       - Registers DU Layers
554  *
555  * @params[in] void
556  * @return ROK     - success
557  *         RFAILED - failure
558  *
559  * ****************************************************************/
560 uint8_t duInit()
561 {
562    int ret = ROK;
563    if(commonInit() != ROK)
564    {
565       ret = RFAILED;
566    } 
567    return ret;
568 }
569
570 void init_log()
571 {
572         openlog("ODU",LOG_CONS | LOG_PID | LOG_NDELAY, LOG_LOCAL1);
573 }
574
575 /*******************************************************************
576  *
577  * @brief Entry point for the DU APP 
578  *
579  * @details
580  *
581  *    Function : main
582  *
583  *    Functionality:
584  *      - Read config params into duCfgParams
585  *      - Initiate the init functions
586  *
587  * @params[in] void
588  * @return ROK     - success
589  *         RFAILED - failure
590  *
591  * ****************************************************************/
592 uint8_t tst(void)
593 {
594    init_log();
595
596 #ifdef O1_ENABLE
597    if(start_O1_module() != ROK)
598       return RFAILED;
599 #endif
600    //Initialize TAPA layers
601    if(duInit() != ROK)
602    {
603       return RFAILED;
604    } 
605
606    //Read all the configs from du_utils.c into duCfgParams
607    duReadCfg();
608
609 #ifdef O1_ENABLE
610    //Send VES PNF registration message to SMO
611    sendPnfRegistration();
612 #endif
613
614    return ROK;
615
616 }/* end of main()*/
617
618 /**********************************************************************
619          End of file
620 **********************************************************************/