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