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