Edit-conf changes for CLA use case.
[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
49 /* Global variable */
50 DuCfgParams duCfgParam;
51
52 /*******************************************************************
53  *
54  * @brief Initializes DU APP
55  *
56  * @details
57  *
58  *    Function : duAppInit
59  *
60  *    Functionality:
61  *       - Registers and attaches TAPA tasks belonging to 
62  *         DU_APP sys task
63  *
64  * @params[in] system task ID
65  * @return ROK     - success
66  *         RFAILED - failure
67  *
68  * ****************************************************************/
69 uint8_t duAppInit(SSTskId sysTskId)
70 {
71    /* Register DU APP TAPA Task for DU */
72    if(ODU_REG_TTSK((Ent)ENTDUAPP, (Inst)DU_INST, (Ttype)TTNORM, (Prior)PRIOR0,
73       duActvInit, (ActvTsk)duActvTsk) != ROK)
74    {
75       return RFAILED;
76    }
77    /* Attach DU APP TAPA Task for DU */
78    if (ODU_ATTACH_TTSK((Ent)ENTDUAPP, (Inst)0, sysTskId)!= ROK)
79    {
80       return RFAILED;
81    }
82
83    DU_LOG("\nINFO   -->  DU_APP : DU APP created and registered \
84    to %d sys task", sysTskId);
85    return ROK;
86 }
87
88 #ifdef O1_ENABLE
89 /*******************************************************************
90  *
91  * @brief Bring the cell Up
92  *
93  * @details
94  *
95  *    Function : bringCellUp
96  *
97  *    Functionality:
98  *       - Bring the cell Up when requested from OAM
99  *
100  * @params[in] Cell Id
101  * @return true     - success
102  *         false    - failure
103  *
104  * ****************************************************************/
105
106 bool bringCellUp(uint16_t cellId)
107 {
108    return true;
109 }
110
111 /*******************************************************************
112  *
113  * @brief Bring the cell Down
114  *
115  * @details
116  *
117  *    Function : bringCellDown
118  *
119  *    Functionality:
120  *       - Bring the cell Down when requested from OAM
121  *
122  * @params[in] Cell Id
123  * @return true     - success
124  *         false    - failure
125  *
126  * ****************************************************************/
127
128 bool bringCellDown(uint16_t cellId)
129 {
130    return true;
131 }
132 #endif
133
134 /*******************************************************************
135  *
136  * @brief Initializes EGTP
137  *
138  * @details
139  *
140  *    Function : egtpInit
141  *
142  *    Functionality:
143  *       - Registers and attaches TAPA tasks belonging to 
144  *         DU_APP sys task
145  *
146  * @params[in] system task ID
147  * @return ROK     - success
148  *         RFAILED - failure
149  *
150  * ****************************************************************/
151 uint8_t egtpInit(SSTskId sysTskId)
152 {
153    /* Register DU APP TAPA Task for DU */
154    if(ODU_REG_TTSK((Ent)ENTEGTP, (Inst)EGTP_INST, (Ttype)TTNORM, (Prior)PRIOR0,
155              egtpActvInit, (ActvTsk)egtpActvTsk) != ROK)
156    {
157       return RFAILED;
158    }
159    /* Attach DU APP TAPA Task for DU */
160    if (ODU_ATTACH_TTSK((Ent)ENTEGTP, (Inst)0, sysTskId)!= ROK)
161    {
162       return RFAILED;
163    }
164  
165     DU_LOG("\nINFO   -->  DU_APP : EGTP created and registered \
166     to %d sys task", sysTskId);
167     return ROK;
168 }
169  
170
171 /*******************************************************************
172  *
173  * @brief Initializes SCTP task
174  *
175  * @details
176  *
177  *    Function : sctpInit
178  *
179  *    Functionality:
180  *       - Registers and attaches TAPA tasks for SCTP receiver 
181  *
182  * @params[in] system task ID
183  * @return ROK     - success
184  *         RFAILED - failure
185  *
186  * ****************************************************************/
187 uint8_t sctpInit(SSTskId sysTskId)
188 {
189    /* Register SCTP TAPA Task */
190    if(ODU_REG_TTSK((Ent)ENTSCTP, (Inst)0, (Ttype)TTNORM, (Prior)PRIOR0,
191             sctpActvInit, (ActvTsk)sctpActvTsk) != ROK)
192    {
193       return RFAILED;
194    }
195    /* Attach SCTP TAPA Task */
196    if (ODU_ATTACH_TTSK((Ent)ENTSCTP, (Inst)SCTP_INST, sysTskId)!= ROK)
197    {
198       return RFAILED;
199    }
200
201    DU_LOG("\nINFO   -->  DU_APP : SCTP TAPA task created and registered to %d sys task", 
202          sysTskId);
203    return ROK;
204 }
205 /*******************************************************************
206  *
207  * @brief Initializes RLC DL, MAC TAPA task
208  *
209  * @details
210  *
211  *    Function : rlcDlInit
212  *
213  *    Functionality:
214  *       - Registers and attaches TAPA tasks for MAC and RLC DL
215  *
216  * @params[in] system task ID
217  * @return ROK     - success
218  *         RFAILED - failure
219  *
220  * ****************************************************************/
221 uint8_t rlcDlInit(SSTskId sysTskId)
222 {
223    /* Register RLC DL TAPA Task */
224    if(ODU_REG_TTSK((Ent)ENTRLC, (Inst)1, (Ttype)TTNORM, (Prior)PRIOR0,
225             rlcDlActvInit, (ActvTsk)rlcDlActvTsk) != ROK)
226    {
227       return RFAILED;
228    }
229    /* Attach RLC DL Task */
230    if (ODU_ATTACH_TTSK((Ent)ENTRLC, (Inst)1, sysTskId)!= ROK)
231    {
232       return RFAILED;
233    }
234
235    /* Register MAC TAPA Task */
236    if(ODU_REG_TTSK((Ent)ENTMAC, (Inst)0, (Ttype)TTNORM, (Prior)PRIOR0,
237             rgActvInit, (ActvTsk)rgActvTsk) != ROK)
238    {
239       return RFAILED;
240    }
241    /* Attach MAC Task */
242    if (ODU_ATTACH_TTSK((Ent)ENTMAC, (Inst)0, sysTskId)!= ROK)
243    {
244       return RFAILED;
245    }
246
247    DU_LOG("\nINFO   -->  DU_APP : RLC DL and MAC TAPA task created and registered to \
248    %d sys task", sysTskId);
249    return ROK;
250 }
251
252 /*******************************************************************
253  *
254  * @brief Initializes RLC UL TAPA task
255  *
256  * @details
257  *
258  *    Function : rlcUlInit
259  *
260  *    Functionality:
261  *       - Registers and attaches TAPA task for RLC UL
262  *
263  * @params[in] system task ID
264  * @return ROK     - success
265  *         RFAILED - failure
266  *
267  * ****************************************************************/
268 uint8_t rlcUlInit(SSTskId sysTskId)
269 {
270    /* Register RLC UL TAPA Task */
271    if(ODU_REG_TTSK((Ent)ENTRLC, (Inst)0, (Ttype)TTNORM, (Prior)PRIOR0,
272             rlcUlActvInit, (ActvTsk)rlcUlActvTsk) != ROK)
273    {
274       return RFAILED;
275    }
276    /* Attach RLC DL Task */
277    if (ODU_ATTACH_TTSK((Ent)ENTRLC, (Inst)0, sysTskId)!= ROK)
278    {
279       return RFAILED;
280    }
281    DU_LOG("\nINFO   -->  DU_APP : RLC UL TAPA task created and registered to \
282    %d sys task", sysTskId);
283    return ROK;
284 }
285
286 /*******************************************************************
287  *
288  * @brief Initializes Lower MAC receiver task
289  *
290  * @details
291  *
292  *    Function : lwrMacInit
293  *
294  *    Functionality:
295  *       - Registers and attaches TAPA tasks for Lower MAC receiver
296  *
297  * @params[in] system task ID
298  * @return ROK     - success
299  *         RFAILED - failure
300  *
301  * ****************************************************************/
302 uint8_t lwrMacInit(SSTskId sysTskId)
303 {
304    /* Register SCTP TAPA Task */
305    if(ODU_REG_TTSK((Ent)ENTLWRMAC, (Inst)0, (Ttype)TTNORM, (Prior)PRIOR0,
306             lwrMacActvInit, (ActvTsk)lwrMacActvTsk) != ROK)
307    {
308       return RFAILED;
309    }
310    /* Attach SCTP TAPA Task */
311    if (ODU_ATTACH_TTSK((Ent)ENTLWRMAC, (Inst)0, sysTskId)!= ROK)
312    {
313       return RFAILED;
314    }
315
316    DU_LOG("\nINFO   -->  DU_APP : LWR MAC TAPA task created and registered to %d sys task",
317          sysTskId);
318    return ROK;
319 }
320
321 /*******************************************************************
322  *
323  * @brief Initializes system and TAPA tasks
324  *
325  * @details
326  *
327  *    Function : commonInit
328  *
329  *    Functionality:
330  *       - Registers and attaches system and TAPA tasks
331  *
332  * @params[in] void
333  * @return ROK     - success
334  *         RFAILED - failure
335  *
336  * ****************************************************************/
337 uint8_t commonInit()
338 {
339    /* Declare system task Ids */
340    SSTskId du_app_stsk, egtp_stsk, sctp_stsk, rlc_ul_stsk, rlc_mac_cl_stsk, lwr_mac_stsk;
341
342    pthread_attr_t attr;
343
344    ODU_SET_PROC_ID(DU_PROC);
345
346    /* Intel L1 using core 0-15. ODU-High using 16-21 */
347    /* system task for DU APP */
348    if(ODU_CREATE_TASK(PRIOR0, &du_app_stsk) != ROK)
349    {
350       DU_LOG("\nERROR  -->  DU_APP : System Task creation for DU APP failed");
351       return RFAILED;
352    }
353    ODU_SET_THREAD_AFFINITY(&du_app_stsk, SS_AFFINITY_MODE_EXCL, 16, 0);
354
355    /* system task for EGTP */
356    if(ODU_CREATE_TASK(PRIOR0, &egtp_stsk) != ROK)
357    {
358       DU_LOG("\nERROR  -->  DU_APP : System Task creation for EGTP failed");
359       return RFAILED;
360    }
361    ODU_SET_THREAD_AFFINITY(&egtp_stsk, SS_AFFINITY_MODE_EXCL, 17, 0);
362
363    /* system task for RLC_DL and MAC */
364    if(ODU_CREATE_TASK(PRIOR0, &rlc_mac_cl_stsk) != ROK)
365    {
366       DU_LOG("\nERROR  -->  DU_APP : System Task creation for RLC DL/MAC failed");
367       return RFAILED;
368    }
369    pthread_attr_init(&attr);
370    pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
371    ODU_SET_THREAD_AFFINITY(&rlc_mac_cl_stsk, SS_AFFINITY_MODE_EXCL, 18, 0);
372
373    /* system task for RLC UL */
374    if(ODU_CREATE_TASK(PRIOR1, &rlc_ul_stsk) != ROK)
375    {
376       DU_LOG("\nERROR  -->  DU_APP : System Task creation for RLC UL failed");
377       return RFAILED;
378    }
379    ODU_SET_THREAD_AFFINITY(&rlc_ul_stsk, SS_AFFINITY_MODE_EXCL, 19, 0);
380
381    /* system task for SCTP receiver thread */
382    if(ODU_CREATE_TASK(PRIOR0, &sctp_stsk) != ROK)
383    {
384       DU_LOG("\nERROR  -->  DU_APP : System Task creation for SCTP failed");
385       return RFAILED;
386    }
387    ODU_SET_THREAD_AFFINITY(&sctp_stsk, SS_AFFINITY_MODE_EXCL, 20, 0);
388
389    /* system task for lower-mac receiver thread */
390    if(ODU_CREATE_TASK(PRIOR0, &lwr_mac_stsk) != ROK)
391    {
392       DU_LOG("\nERROR  -->  DU_APP : System Task creation for Lower MAC failed");
393       return RFAILED;
394    }
395    ODU_SET_THREAD_AFFINITY(&lwr_mac_stsk, SS_AFFINITY_MODE_EXCL, 21, 0);
396
397    /* Create TAPA tasks */
398    if(duAppInit(du_app_stsk) != ROK)
399    {
400       DU_LOG("\nERROR  -->  DU_APP : DU APP TAPA Task initialization failed");
401       return RFAILED;
402    }
403
404    if(egtpInit(egtp_stsk) != ROK)
405    {
406       DU_LOG("\nERROR  -->  DU_APP : EGTP TAPA Task initialization failed");
407       return RFAILED;
408    }
409
410    if(sctpInit(sctp_stsk) != ROK)
411    {
412       DU_LOG("\nERROR  -->  DU_APP : SCTP TAPA Task initialization failed");
413       return RFAILED;
414    }
415
416    if(rlcDlInit(rlc_mac_cl_stsk) != ROK)
417    {
418       DU_LOG("\nERROR  -->  DU_APP : RLC DL Tapa Task initialization failed");
419       return RFAILED;
420    } 
421
422    if(rlcUlInit(rlc_ul_stsk) != ROK)
423    {
424      DU_LOG("\nERROR  -->  DU_APP : RLC UL Tapa Task initialization failed");
425      return RFAILED;
426    } 
427
428    if(lwrMacInit(lwr_mac_stsk) != ROK)
429    {
430       DU_LOG("\nERROR  -->  DU_APP : Lower MAC Tapa Task initialization failed");
431       return RFAILED;
432    }
433
434    return ROK;
435 }
436
437 /*******************************************************************
438  *
439  * @brief Initializes the DU
440  *
441  * @details
442  *
443  *    Function : duInit
444  *
445  *    Functionality:
446  *       - Calls commonInit
447  *       - Registers DU Layers
448  *
449  * @params[in] void
450  * @return ROK     - success
451  *         RFAILED - failure
452  *
453  * ****************************************************************/
454 uint8_t duInit()
455 {
456    int ret = ROK;
457    if(commonInit() != ROK)
458    {
459       ret = RFAILED;
460    } 
461    return ret;
462 }
463
464 void init_log()
465 {
466         openlog("ODU",LOG_CONS | LOG_PID | LOG_NDELAY, LOG_LOCAL1);
467 }
468
469 /*******************************************************************
470  *
471  * @brief Entry point for the DU APP 
472  *
473  * @details
474  *
475  *    Function : main
476  *
477  *    Functionality:
478  *      - Read config params into duCfgParams
479  *      - Initiate the init functions
480  *
481  * @params[in] void
482  * @return ROK     - success
483  *         RFAILED - failure
484  *
485  * ****************************************************************/
486 uint8_t tst(void)
487 {
488    init_log();
489
490 #ifdef O1_ENABLE
491    if(start_O1_module() != ROK)
492       return RFAILED;
493 #endif
494    //Initialize TAPA layers
495    if(duInit() != ROK)
496    {
497       return RFAILED;
498    } 
499
500    //Read all the configs from du_utils.c into duCfgParams
501    duReadCfg();
502
503    return ROK;
504 }/* end of main()*/
505
506 /**********************************************************************
507          End of file
508 **********************************************************************/