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