Added failure check in system task creation
[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 extern uint8_t rlcUlActvTsk (Pst *, Buffer *);
34 extern uint8_t rlcUlActvInit (Ent, Inst, Region, Reason);
35 extern uint8_t rlcDlActvTsk (Pst *, Buffer *);
36 extern uint8_t rlcDlActvInit (Ent, Inst, Region, Reason);
37 extern uint8_t rgActvTsk (Pst *, Buffer *);
38 extern uint8_t rgActvInit (Ent, Inst, Region, Reason);
39
40 /* Global variable */
41 DuCfgParams duCfgParam;
42
43 /*******************************************************************
44  *
45  * @brief Initializes DU APP
46  *
47  * @details
48  *
49  *    Function : duAppInit
50  *
51  *    Functionality:
52  *       - Registers and attaches TAPA tasks belonging to 
53  *         DU_APP sys task
54  *
55  * @params[in] system task ID
56  * @return ROK     - success
57  *         RFAILED - failure
58  *
59  * ****************************************************************/
60 uint8_t duAppInit(SSTskId sysTskId)
61 {
62         /* Register DU APP TAPA Task for DU */
63         if(ODU_REG_TTSK((Ent)ENTDUAPP, (Inst)DU_INST, (Ttype)TTNORM, (Prior)PRIOR0,
64             duActvInit, (ActvTsk)duActvTsk) != ROK)
65    {
66       return RFAILED;
67    }
68    /* Attach DU APP TAPA Task for DU */
69    if (ODU_ATTACH_TTSK((Ent)ENTDUAPP, (Inst)0, sysTskId)!= ROK)
70    {
71       return RFAILED;
72    }
73
74    DU_LOG("\nDU_APP : DU APP created and registered \
75    to %d sys task", sysTskId);
76    return ROK;
77 }
78
79 /*******************************************************************
80  *
81  * @brief Initializes EGTP
82  *
83  * @details
84  *
85  *    Function : egtpInit
86  *
87  *    Functionality:
88  *       - Registers and attaches TAPA tasks belonging to 
89  *         DU_APP sys task
90  *
91  * @params[in] system task ID
92  * @return ROK     - success
93  *         RFAILED - failure
94  *
95  * ****************************************************************/
96 uint8_t egtpInit(SSTskId sysTskId)
97 {
98    /* Register DU APP TAPA Task for DU */
99    if(ODU_REG_TTSK((Ent)ENTEGTP, (Inst)EGTP_INST, (Ttype)TTNORM, (Prior)PRIOR0,
100              egtpActvInit, (ActvTsk)egtpActvTsk) != ROK)
101    {
102       return RFAILED;
103    }
104    /* Attach DU APP TAPA Task for DU */
105    if (ODU_ATTACH_TTSK((Ent)ENTEGTP, (Inst)0, sysTskId)!= ROK)
106    {
107       return RFAILED;
108    }
109  
110     DU_LOG("\nDU_APP : EGTP created and registered \
111     to %d sys task", sysTskId);
112     return ROK;
113 }
114  
115
116 /*******************************************************************
117  *
118  * @brief Initializes SCTP task
119  *
120  * @details
121  *
122  *    Function : sctpInit
123  *
124  *    Functionality:
125  *       - Registers and attaches TAPA tasks for SCTP receiver 
126  *
127  * @params[in] system task ID
128  * @return ROK     - success
129  *         RFAILED - failure
130  *
131  * ****************************************************************/
132 uint8_t sctpInit(SSTskId sysTskId)
133 {
134    /* Register SCTP TAPA Task */
135    if(ODU_REG_TTSK((Ent)ENTSCTP, (Inst)0, (Ttype)TTNORM, (Prior)PRIOR0,
136             sctpActvInit, (ActvTsk)sctpActvTsk) != ROK)
137    {
138       return RFAILED;
139    }
140    /* Attach SCTP TAPA Task */
141    if (ODU_ATTACH_TTSK((Ent)ENTSCTP, (Inst)SCTP_INST, sysTskId)!= ROK)
142    {
143       return RFAILED;
144    }
145
146    DU_LOG("\nDU_APP : SCTP TAPA task created and registered to %d sys task", 
147          sysTskId);
148    return ROK;
149 }
150 /*******************************************************************
151  *
152  * @brief Initializes RLC DL, MAC TAPA task
153  *
154  * @details
155  *
156  *    Function : rlcDlInit
157  *
158  *    Functionality:
159  *       - Registers and attaches TAPA tasks for MAC and RLC DL
160  *
161  * @params[in] system task ID
162  * @return ROK     - success
163  *         RFAILED - failure
164  *
165  * ****************************************************************/
166 uint8_t rlcDlInit(SSTskId sysTskId)
167 {
168    /* Register RLC DL TAPA Task */
169    if(ODU_REG_TTSK((Ent)ENTKW, (Inst)1, (Ttype)TTNORM, (Prior)PRIOR0,
170             rlcDlActvInit, (ActvTsk)rlcDlActvTsk) != ROK)
171    {
172       return RFAILED;
173    }
174    /* Attach RLC DL Task */
175    if (ODU_ATTACH_TTSK((Ent)ENTKW, (Inst)1, sysTskId)!= ROK)
176    {
177       return RFAILED;
178    }
179
180    /* Register MAC TAPA Task */
181    if(ODU_REG_TTSK((Ent)ENTRG, (Inst)0, (Ttype)TTNORM, (Prior)PRIOR0,
182             rgActvInit, (ActvTsk)rgActvTsk) != ROK)
183    {
184       return RFAILED;
185    }
186    /* Attach MAC Task */
187    if (ODU_ATTACH_TTSK((Ent)ENTRG, (Inst)0, sysTskId)!= ROK)
188    {
189       return RFAILED;
190    }
191
192    DU_LOG("\nDU_APP : RLC DL and MAC TAPA task created and registered to \
193    %d sys task", sysTskId);
194    return ROK;
195 }
196
197 /*******************************************************************
198  *
199  * @brief Initializes RLC UL TAPA task
200  *
201  * @details
202  *
203  *    Function : rlcUlInit
204  *
205  *    Functionality:
206  *       - Registers and attaches TAPA task for RLC UL
207  *
208  * @params[in] system task ID
209  * @return ROK     - success
210  *         RFAILED - failure
211  *
212  * ****************************************************************/
213 uint8_t rlcUlInit(SSTskId sysTskId)
214 {
215    /* Register RLC UL TAPA Task */
216    if(ODU_REG_TTSK((Ent)ENTKW, (Inst)0, (Ttype)TTNORM, (Prior)PRIOR0,
217             rlcUlActvInit, (ActvTsk)rlcUlActvTsk) != ROK)
218    {
219       return RFAILED;
220    }
221    /* Attach RLC DL Task */
222    if (ODU_ATTACH_TTSK((Ent)ENTKW, (Inst)0, sysTskId)!= ROK)
223    {
224       return RFAILED;
225    }
226    DU_LOG("\nDU_APP : RLC UL TAPA task created and registered to \
227    %d sys task", sysTskId);
228    return ROK;
229 }
230
231 /*******************************************************************
232  *
233  * @brief Initializes system and TAPA tasks
234  *
235  * @details
236  *
237  *    Function : commonInit
238  *
239  *    Functionality:
240  *       - Registers and attaches system and TAPA tasks
241  *
242  * @params[in] void
243  * @return ROK     - success
244  *         RFAILED - failure
245  *
246  * ****************************************************************/
247 uint8_t commonInit()
248 {
249    /* Declare system task Ids */
250    SSTskId du_app_stsk, sctp_stsk, rlc_ul_stsk, rlc_mac_cl_stsk;
251
252    pthread_attr_t attr;
253
254    ODU_SET_PROC_ID(DU_PROC);
255
256    /* system task for DU APP */
257    if(SCreateSTsk(PRIOR0, &du_app_stsk) != ROK)
258    {
259       DU_LOG("\nDU_APP : System Task creation for DU APP failed");
260       return RFAILED;
261    }
262
263    /* system task for RLC_DL and MAC */
264    if(SCreateSTsk(PRIOR0, &rlc_mac_cl_stsk) != ROK)
265    {
266       DU_LOG("\nDU_APP : System Task creation for RLC DL/MAC failed");
267       return RFAILED;
268    }
269    pthread_attr_init(&attr);
270    pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
271
272    /* system task for RLC UL */
273    if(SCreateSTsk(PRIOR1, &rlc_ul_stsk) != ROK)
274    {
275       DU_LOG("\nDU_APP : System Task creation for RLC UL failed");
276       return RFAILED;
277    }
278
279    /* system task for SCTP receiver thread */
280    if(SCreateSTsk(PRIOR0, &sctp_stsk) != ROK)
281    {
282       DU_LOG("\nDU_APP : System Task creation for SCTP failed");
283       return RFAILED;
284    }
285
286    /* Create TAPA tasks */
287    if(duAppInit(du_app_stsk) != ROK)
288    {
289       DU_LOG("\nDU_APP : DU APP TAPA Task initialization failed");
290       return RFAILED;
291    }
292
293    if(egtpInit(du_app_stsk) != ROK)
294    {
295       DU_LOG("\nDU_APP : EGTP TAPA Task initialization failed");
296       return RFAILED;
297    }
298
299    if(sctpInit(sctp_stsk) != ROK)
300    {
301       DU_LOG("\nDU_APP : SCTP TAPA Task initialization failed");
302       return RFAILED;
303    }
304
305    if(rlcDlInit(rlc_mac_cl_stsk) != ROK)
306    {
307       DU_LOG("\nDU_APP : RLC DL Tapa Task initialization failed");
308       return RFAILED;
309    } 
310
311    if(rlcUlInit(rlc_ul_stsk) != ROK)
312    {
313      DU_LOG("\nDU_APP : RLC UL Tapa Task initialization failed");
314      return RFAILED;
315    } 
316    return ROK;
317 }
318
319 /*******************************************************************
320  *
321  * @brief Initializes the DU
322  *
323  * @details
324  *
325  *    Function : duInit
326  *
327  *    Functionality:
328  *       - Calls commonInit
329  *       - Registers DU Layers
330  *
331  * @params[in] void
332  * @return ROK     - success
333  *         RFAILED - failure
334  *
335  * ****************************************************************/
336 uint8_t duInit()
337 {
338    int ret = ROK;
339    if(commonInit() != ROK)
340    {
341       ret = RFAILED;
342    } 
343  
344    return ret;
345 }
346
347 void init_log()
348 {
349         openlog("ODU",LOG_CONS | LOG_PID | LOG_NDELAY, LOG_LOCAL1);
350 }
351 /*******************************************************************
352  *
353  * @brief Entry point for the DU APP 
354  *
355  * @details
356  *
357  *    Function : main
358  *
359  *    Functionality:
360  *      - Read config params into duCfgParams
361  *      - Initiate the init functions
362  *
363  * @params[in] void
364  * @return ROK     - success
365  *         RFAILED - failure
366  *
367  * ****************************************************************/
368 uint8_t tst(void)
369 {
370         init_log();
371
372         //Initialize TAPA layers
373         if(duInit() != ROK)
374         {
375       return RFAILED;
376    } 
377
378
379    //Read all the configs from du_utils.c into duCfgParams
380    duReadCfg();
381
382    return ROK;
383 }/* end of main()*/
384
385 /**********************************************************************
386          End of file
387 **********************************************************************/