Adding new commiter to ODU-High repo
[o-du/l2.git] / src / o1 / O1Interface.cpp
1 /*******************************************************************************
2 ################################################################################
3 #   Copyright (c) [2020-2021] [HCL Technologies Ltd.]                          #
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 contains the C interface for ODU to start the O1 module */
20
21 #include "O1Interface.h"
22 #include "O1App.hpp"
23 #include "GlobalDefs.hpp"
24 #include "PnfRegistrationThread.hpp"
25 #include "ConfigLoader.hpp"
26
27 #include <signal.h>
28 #include <unistd.h>
29
30
31 /*******************************************************************
32  *
33  * @brief Wait for the O1 Module to start
34  *
35  * @details
36  *
37  *    Function : check_O1_module_status
38  *
39  *    Functionality:
40  *      - Checks if the O1App has started
41  *
42  *
43  * @params[in] void
44  * @return O1::SUCCESS - success
45  *         O1::FAILURE - failure
46  ******************************************************************/
47
48 int static check_O1_module_status(void){
49
50    const int N_RETRY = 5;
51    const int RETRY_DELAY = 1;
52
53    for( int i = 0; i < N_RETRY; i++)
54    {
55       if( O1App::instance().getStartupStatus() == true)
56       {
57          return O1::SUCCESS;
58       }
59       else
60       {
61          sleep(RETRY_DELAY);
62       }
63    }
64
65    return O1::FAILURE;
66 }
67
68 /*******************************************************************
69  *
70  * @brief Starts the O1 Module
71  *
72  * @details
73  *
74  *    Function : start_O1_module
75  *
76  *    Functionality:
77  *      - Starts the O1 module by instantiating the O1App instance
78  *        Invoked from the ODU-High main function
79  *
80  *
81  * @params[in] void
82  * @return O1::SUCCESS - success
83  *         O1::FAILURE - failure
84  ******************************************************************/
85
86 int start_O1_module(void)
87 {
88
89    if( !ConfigLoader::instance().loadConfigurations() )
90       return O1::FAILURE;
91
92    if(O1App::instance().start() == false){
93       O1_LOG("\nO1 O1Interface : Failed to start");
94       return O1::FAILURE;
95    }
96    
97    if(O1App::instance().setAffinity(O1::CPU_CORE))
98    {
99       O1_LOG("\nO1 O1Interface : CPU affinity set for O1App thread to" );
100       O1App::instance().printAffinity();
101    }
102    return check_O1_module_status();
103 }
104
105 /*******************************************************************
106  *
107  * @brief Send VES PNF Registration Request
108  *
109  * @details
110  *
111  *    Function : sendPnfRegistration
112  *
113  *    Functionality:
114  *      - Create a thread and send VES PNF Registration Request
115  *
116  *
117  * @params[in] void
118  * @return void
119  ******************************************************************/
120
121 void sendPnfRegistration(void)
122 {
123    PnfRegistrationThread::instance().start();
124    if(PnfRegistrationThread::instance().setAffinity(O1::CPU_CORE))
125    {
126       O1_LOG("\nO1 O1Interface : CPU affinity set for PnfRegistration thread to " );
127       PnfRegistrationThread::instance().printAffinity();
128    }
129 }
130
131
132 /**********************************************************************
133          End of file
134 **********************************************************************/