bd31af417d3450d2f57adb302fcb30a1fb30d580
[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  * @brief Bring the cell Up
96  *
97  * @details
98  *
99  *    Function : bringCellUp
100  *
101  *    Functionality:
102  *       - Bring the cell Up when requested from OAM
103  *
104  * @params[in] Cell Id
105  * @return true     - success
106  *         false    - failure
107  *
108  * ****************************************************************/
109
110 bool bringCellUp(uint16_t cellId)
111 {
112    duProcCfgComplete();
113    BuildAndSendF1SetupReq();
114    return true;
115 }
116
117 /*******************************************************************
118  *
119  * @brief Bring the cell Down
120  *
121  * @details
122  *
123  *    Function : bringCellDown
124  *
125  *    Functionality:
126  *       - Bring the cell Down when requested from OAM
127  *
128  * @params[in] Cell Id
129  * @return true     - success
130  *         false    - failure
131  *
132  * ****************************************************************/
133
134 bool bringCellDown(uint16_t cellId)
135 {
136    BuildAndSendDUConfigUpdate(SERV_CELL_TO_DELETE);
137    return true;
138 }
139 #endif
140
141 /*******************************************************************
142  *
143  * @brief Initializes EGTP
144  *
145  * @details
146  *
147  *    Function : egtpInit
148  *
149  *    Functionality:
150  *       - Registers and attaches TAPA tasks belonging to 
151  *         DU_APP sys task
152  *
153  * @params[in] system task ID
154  * @return ROK     - success
155  *         RFAILED - failure
156  *
157  * ****************************************************************/
158 uint8_t egtpInit(SSTskId sysTskId)
159 {
160    /* Register DU APP TAPA Task for DU */
161    if(ODU_REG_TTSK((Ent)ENTEGTP, (Inst)EGTP_INST, (Ttype)TTNORM, (Prior)PRIOR0,
162              egtpActvInit, (ActvTsk)egtpActvTsk) != ROK)
163    {
164       return RFAILED;
165    }
166    /* Attach DU APP TAPA Task for DU */
167    if (ODU_ATTACH_TTSK((Ent)ENTEGTP, (Inst)0, sysTskId)!= ROK)
168    {
169       return RFAILED;
170    }
171  
172     DU_LOG("\nINFO   -->  DU_APP : EGTP created and registered \
173     to %d sys task", sysTskId);
174     return ROK;
175 }
176  
177
178 /*******************************************************************
179  *
180  * @brief Initializes SCTP task
181  *
182  * @details
183  *
184  *    Function : sctpInit
185  *
186  *    Functionality:
187  *       - Registers and attaches TAPA tasks for SCTP receiver 
188  *
189  * @params[in] system task ID
190  * @return ROK     - success
191  *         RFAILED - failure
192  *
193  * ****************************************************************/
194 uint8_t sctpInit(SSTskId sysTskId)
195 {
196    /* Register SCTP TAPA Task */
197    if(ODU_REG_TTSK((Ent)ENTSCTP, (Inst)0, (Ttype)TTNORM, (Prior)PRIOR0,
198             sctpActvInit, (ActvTsk)sctpActvTsk) != ROK)
199    {
200       return RFAILED;
201    }
202    /* Attach SCTP TAPA Task */
203    if (ODU_ATTACH_TTSK((Ent)ENTSCTP, (Inst)SCTP_INST, sysTskId)!= ROK)
204    {
205       return RFAILED;
206    }
207
208    DU_LOG("\nINFO   -->  DU_APP : SCTP TAPA task created and registered to %d sys task", 
209          sysTskId);
210    return ROK;
211 }
212 /*******************************************************************
213  *
214  * @brief Initializes RLC DL, MAC TAPA task
215  *
216  * @details
217  *
218  *    Function : rlcDlInit
219  *
220  *    Functionality:
221  *       - Registers and attaches TAPA tasks for MAC and RLC DL
222  *
223  * @params[in] system task ID
224  * @return ROK     - success
225  *         RFAILED - failure
226  *
227  * ****************************************************************/
228 uint8_t rlcDlInit(SSTskId sysTskId)
229 {
230    /* Register RLC DL TAPA Task */
231    if(ODU_REG_TTSK((Ent)ENTRLC, (Inst)1, (Ttype)TTNORM, (Prior)PRIOR0,
232             rlcDlActvInit, (ActvTsk)rlcDlActvTsk) != ROK)
233    {
234       return RFAILED;
235    }
236    /* Attach RLC DL Task */
237    if (ODU_ATTACH_TTSK((Ent)ENTRLC, (Inst)1, sysTskId)!= ROK)
238    {
239       return RFAILED;
240    }
241
242    /* Register MAC TAPA Task */
243    if(ODU_REG_TTSK((Ent)ENTMAC, (Inst)0, (Ttype)TTNORM, (Prior)PRIOR0,
244             rgActvInit, (ActvTsk)rgActvTsk) != ROK)
245    {
246       return RFAILED;
247    }
248    /* Attach MAC Task */
249    if (ODU_ATTACH_TTSK((Ent)ENTMAC, (Inst)0, sysTskId)!= ROK)
250    {
251       return RFAILED;
252    }
253
254    DU_LOG("\nINFO   -->  DU_APP : RLC DL and MAC TAPA task created and registered to \
255    %d sys task", sysTskId);
256    return ROK;
257 }
258
259 /*******************************************************************
260  *
261  * @brief Initializes RLC UL TAPA task
262  *
263  * @details
264  *
265  *    Function : rlcUlInit
266  *
267  *    Functionality:
268  *       - Registers and attaches TAPA task for RLC UL
269  *
270  * @params[in] system task ID
271  * @return ROK     - success
272  *         RFAILED - failure
273  *
274  * ****************************************************************/
275 uint8_t rlcUlInit(SSTskId sysTskId)
276 {
277    /* Register RLC UL TAPA Task */
278    if(ODU_REG_TTSK((Ent)ENTRLC, (Inst)0, (Ttype)TTNORM, (Prior)PRIOR0,
279             rlcUlActvInit, (ActvTsk)rlcUlActvTsk) != ROK)
280    {
281       return RFAILED;
282    }
283    /* Attach RLC DL Task */
284    if (ODU_ATTACH_TTSK((Ent)ENTRLC, (Inst)0, sysTskId)!= ROK)
285    {
286       return RFAILED;
287    }
288    DU_LOG("\nINFO   -->  DU_APP : RLC UL TAPA task created and registered to \
289    %d sys task", sysTskId);
290    return ROK;
291 }
292
293 /*******************************************************************
294  *
295  * @brief Initializes Lower MAC receiver task
296  *
297  * @details
298  *
299  *    Function : lwrMacInit
300  *
301  *    Functionality:
302  *       - Registers and attaches TAPA tasks for Lower MAC receiver
303  *
304  * @params[in] system task ID
305  * @return ROK     - success
306  *         RFAILED - failure
307  *
308  * ****************************************************************/
309 uint8_t lwrMacInit(SSTskId sysTskId)
310 {
311    /* Register SCTP TAPA Task */
312    if(ODU_REG_TTSK((Ent)ENTLWRMAC, (Inst)0, (Ttype)TTNORM, (Prior)PRIOR0,
313             lwrMacActvInit, (ActvTsk)lwrMacActvTsk) != ROK)
314    {
315       return RFAILED;
316    }
317    /* Attach SCTP TAPA Task */
318    if (ODU_ATTACH_TTSK((Ent)ENTLWRMAC, (Inst)0, sysTskId)!= ROK)
319    {
320       return RFAILED;
321    }
322
323    DU_LOG("\nINFO   -->  DU_APP : LWR MAC TAPA task created and registered to %d sys task",
324          sysTskId);
325    return ROK;
326 }
327
328 #ifndef INTEL_WLS_MEM
329 /*******************************************************************
330  *
331  * @brief Initializes Phy stub slot indication generator task
332  *
333  * @details
334  *
335  *    Function : phyStubInit
336  *
337  *    Functionality:
338  *       - Registers and attaches TAPA tasks for Phy stub's slot
339  *       indication generator
340  *
341  * @params[in] system task ID
342  * @return ROK     - success
343  *         RFAILED - failure
344  *
345  * ****************************************************************/
346 uint8_t phyStubInit(SSTskId sysTskId)
347 {
348    /* Register PHY stub slot indication TAPA Task */
349    if(ODU_REG_TTSK((Ent)ENTPHYSTUB, (Inst)0, (Ttype)TTNORM, (Prior)PRIOR0,
350             phyStubActvInit, (ActvTsk)phyStubActvTsk) != ROK)
351    {
352       return RFAILED;
353    }
354    /* Attach Phy stub slot indication TAPA Task */
355    if (ODU_ATTACH_TTSK((Ent)ENTPHYSTUB, (Inst)0, sysTskId)!= ROK)
356    {
357       return RFAILED;
358    }
359
360    DU_LOG("\nINFO   -->  DU_APP : PHY stub slot indication TAPA task created and registered to %d sys task",
361          sysTskId);
362    return ROK;
363 }
364 #endif
365
366 /*******************************************************************
367  *
368  * @brief Initializes system and TAPA tasks
369  *
370  * @details
371  *
372  *    Function : commonInit
373  *
374  *    Functionality:
375  *       - Registers and attaches system and TAPA tasks
376  *
377  * @params[in] void
378  * @return ROK     - success
379  *         RFAILED - failure
380  *
381  * ****************************************************************/
382 uint8_t commonInit()
383 {
384    /* Declare system task Ids */
385    SSTskId du_app_stsk, egtp_stsk, sctp_stsk, rlc_ul_stsk, rlc_mac_cl_stsk, lwr_mac_stsk, phy_stub_slot_ind_stsk;
386
387    pthread_attr_t attr;
388
389    ODU_SET_PROC_ID(DU_PROC);
390
391    /* Intel L1 using core 0-15. ODU-High using 16-21 */
392    /* system task for DU APP */
393    if(ODU_CREATE_TASK(PRIOR0, &du_app_stsk) != ROK)
394    {
395       DU_LOG("\nERROR  -->  DU_APP : System Task creation for DU APP failed");
396       return RFAILED;
397    }
398    //ODU_SET_THREAD_AFFINITY(&du_app_stsk, SS_AFFINITY_MODE_EXCL, 16, 0);
399
400    /* system task for EGTP */
401    if(ODU_CREATE_TASK(PRIOR0, &egtp_stsk) != ROK)
402    {
403       DU_LOG("\nERROR  -->  DU_APP : System Task creation for EGTP failed");
404       return RFAILED;
405    }
406    //ODU_SET_THREAD_AFFINITY(&egtp_stsk, SS_AFFINITY_MODE_EXCL, 17, 0);
407
408    /* system task for RLC_DL and MAC */
409    if(ODU_CREATE_TASK(PRIOR0, &rlc_mac_cl_stsk) != ROK)
410    {
411       DU_LOG("\nERROR  -->  DU_APP : System Task creation for RLC DL/MAC failed");
412       return RFAILED;
413    }
414    pthread_attr_init(&attr);
415    pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
416    //ODU_SET_THREAD_AFFINITY(&rlc_mac_cl_stsk, SS_AFFINITY_MODE_EXCL, 18, 0);
417
418    /* system task for RLC UL */
419    if(ODU_CREATE_TASK(PRIOR1, &rlc_ul_stsk) != ROK)
420    {
421       DU_LOG("\nERROR  -->  DU_APP : System Task creation for RLC UL failed");
422       return RFAILED;
423    }
424    //ODU_SET_THREAD_AFFINITY(&rlc_ul_stsk, SS_AFFINITY_MODE_EXCL, 19, 0);
425
426    /* system task for SCTP receiver thread */
427    if(ODU_CREATE_TASK(PRIOR0, &sctp_stsk) != ROK)
428    {
429       DU_LOG("\nERROR  -->  DU_APP : System Task creation for SCTP failed");
430       return RFAILED;
431    }
432    //ODU_SET_THREAD_AFFINITY(&sctp_stsk, SS_AFFINITY_MODE_EXCL, 20, 0);
433
434    /* system task for lower-mac receiver thread */
435    if(ODU_CREATE_TASK(PRIOR0, &lwr_mac_stsk) != ROK)
436    {
437       DU_LOG("\nERROR  -->  DU_APP : System Task creation for Lower MAC failed");
438       return RFAILED;
439    }
440    //ODU_SET_THREAD_AFFINITY(&lwr_mac_stsk, SS_AFFINITY_MODE_EXCL, 21, 0);
441
442 #ifndef INTEL_WLS_MEM
443    /* system task for phy stub's slot indication generator thread */
444    if(ODU_CREATE_TASK(PRIOR0, &phy_stub_slot_ind_stsk) != ROK)
445    {
446       DU_LOG("\nERROR  -->  DU_APP : System Task creation for Phy stub slot indication generator failed. MAX STSK [%d]", SS_MAX_STSKS);
447       return RFAILED;
448    }
449
450 #endif
451
452    /* Create TAPA tasks */
453    if(duAppInit(du_app_stsk) != ROK)
454    {
455       DU_LOG("\nERROR  -->  DU_APP : DU APP TAPA Task initialization failed");
456       return RFAILED;
457    }
458
459    if(egtpInit(egtp_stsk) != ROK)
460    {
461       DU_LOG("\nERROR  -->  DU_APP : EGTP TAPA Task initialization failed");
462       return RFAILED;
463    }
464
465    if(sctpInit(sctp_stsk) != ROK)
466    {
467       DU_LOG("\nERROR  -->  DU_APP : SCTP TAPA Task initialization failed");
468       return RFAILED;
469    }
470
471    if(rlcDlInit(rlc_mac_cl_stsk) != ROK)
472    {
473       DU_LOG("\nERROR  -->  DU_APP : RLC DL Tapa Task initialization failed");
474       return RFAILED;
475    } 
476
477    if(rlcUlInit(rlc_ul_stsk) != ROK)
478    {
479      DU_LOG("\nERROR  -->  DU_APP : RLC UL Tapa Task initialization failed");
480      return RFAILED;
481    } 
482
483    if(lwrMacInit(lwr_mac_stsk) != ROK)
484    {
485       DU_LOG("\nERROR  -->  DU_APP : Lower MAC Tapa Task initialization failed");
486       return RFAILED;
487    }
488
489 #ifndef INTEL_WLS_MEM
490    if(phyStubInit(phy_stub_slot_ind_stsk) != ROK)
491    {
492       DU_LOG("\nERROR  -->  DU_APP : PHY stub slot indication Tapa Task initialization failed");
493       return RFAILED;
494    }
495 #endif
496
497    return ROK;
498 }
499
500 /*******************************************************************
501  *
502  * @brief Initializes the DU
503  *
504  * @details
505  *
506  *    Function : duInit
507  *
508  *    Functionality:
509  *       - Calls commonInit
510  *       - Registers DU Layers
511  *
512  * @params[in] void
513  * @return ROK     - success
514  *         RFAILED - failure
515  *
516  * ****************************************************************/
517 uint8_t duInit()
518 {
519    int ret = ROK;
520    if(commonInit() != ROK)
521    {
522       ret = RFAILED;
523    } 
524    return ret;
525 }
526
527 void init_log()
528 {
529         openlog("ODU",LOG_CONS | LOG_PID | LOG_NDELAY, LOG_LOCAL1);
530 }
531
532 /*******************************************************************
533  *
534  * @brief Entry point for the DU APP 
535  *
536  * @details
537  *
538  *    Function : main
539  *
540  *    Functionality:
541  *      - Read config params into duCfgParams
542  *      - Initiate the init functions
543  *
544  * @params[in] void
545  * @return ROK     - success
546  *         RFAILED - failure
547  *
548  * ****************************************************************/
549 uint8_t tst(void)
550 {
551    init_log();
552
553 #ifdef O1_ENABLE
554    if(start_O1_module() != ROK)
555       return RFAILED;
556 #endif
557    //Initialize TAPA layers
558    if(duInit() != ROK)
559    {
560       return RFAILED;
561    } 
562
563    //Read all the configs from du_utils.c into duCfgParams
564    duReadCfg();
565
566 #ifdef O1_ENABLE
567    //Send VES PNF registration message to SMO
568    sendPnfRegistration();
569 #endif
570
571    return ROK;
572
573 }/* end of main()*/
574
575 /**********************************************************************
576          End of file
577 **********************************************************************/