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