f4791d29ed44998cb65daf0bb8a4fd460073065d
[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    SCreateSTsk(PRIOR0, &du_app_stsk);
258
259    /* system task for RLC_DL and MAC */
260    SCreateSTsk(PRIOR0, &rlc_mac_cl_stsk);
261    pthread_attr_init(&attr);
262    pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
263
264    /* system task for RLC UL */
265    SCreateSTsk(PRIOR1, &rlc_ul_stsk);
266
267    /* system task for SCTP receiver thread */
268    SCreateSTsk(PRIOR0, &sctp_stsk);
269
270    /* Create TAPA tasks */
271    if(duAppInit(du_app_stsk) != ROK)
272    {
273       DU_LOG("\nDU_APP : DU APP TAPA Task initialization failed");
274       return RFAILED;
275    }
276
277    if(egtpInit(du_app_stsk) != ROK)
278    {
279       DU_LOG("\nDU_APP : EGTP TAPA Task initialization failed");
280       return RFAILED;
281    }
282
283    if(sctpInit(sctp_stsk) != ROK)
284    {
285       DU_LOG("\nDU_APP : SCTP TAPA Task initialization failed");
286       return RFAILED;
287    }
288
289    if(rlcDlInit(rlc_mac_cl_stsk) != ROK)
290    {
291       DU_LOG("\nDU_APP : RLC DL Tapa Task initialization failed");
292       return RFAILED;
293    } 
294
295    if(rlcUlInit(rlc_ul_stsk) != ROK)
296    {
297      DU_LOG("\nDU_APP : RLC UL Tapa Task initialization failed");
298      return RFAILED;
299    } 
300    return ROK;
301 }
302
303 /*******************************************************************
304  *
305  * @brief Initializes the DU
306  *
307  * @details
308  *
309  *    Function : duInit
310  *
311  *    Functionality:
312  *       - Calls commonInit
313  *       - Registers DU Layers
314  *
315  * @params[in] void
316  * @return ROK     - success
317  *         RFAILED - failure
318  *
319  * ****************************************************************/
320 uint8_t duInit()
321 {
322    int ret = ROK;
323    if(commonInit() != ROK)
324    {
325       ret = RFAILED;
326    } 
327  
328    return ret;
329 }
330
331 void init_log()
332 {
333         openlog("ODU",LOG_CONS | LOG_PID | LOG_NDELAY, LOG_LOCAL1);
334 }
335 /*******************************************************************
336  *
337  * @brief Entry point for the DU APP 
338  *
339  * @details
340  *
341  *    Function : main
342  *
343  *    Functionality:
344  *      - Read config params into duCfgParams
345  *      - Initiate the init functions
346  *
347  * @params[in] void
348  * @return ROK     - success
349  *         RFAILED - failure
350  *
351  * ****************************************************************/
352 uint8_t tst(void)
353 {
354         init_log();
355
356         //Initialize TAPA layers
357         if(duInit() != ROK)
358         {
359       return RFAILED;
360    } 
361
362
363    //Read all the configs from du_utils.c into duCfgParams
364    duReadCfg();
365
366    return ROK;
367 }/* end of main()*/
368
369 /**********************************************************************
370          End of file
371 **********************************************************************/