[Epic-ID: ODUHIGH-510][Task-ID: ODUHIGH-512] Implementation of E2 setup failure
[o-du/l2.git] / src / du_app / du_e2ap_mgr.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 #include "common_def.h"
19 #include "du_tmr.h"
20 #include "lrg.h"
21 #include "lkw.x"
22 #include "lrg.x"
23 #include "legtp.h"
24 #include "du_e2ap_mgr.h"
25 #include "du_app_mac_inf.h"
26 #include "du_app_rlc_inf.h"
27 #include "du_e2ap_msg_hdl.h"
28 #include "du_cfg.h"
29 #include "du_sctp.h"
30 #include "du_mgr.h"
31 #include "du_mgr_main.h"
32 #include "du_utils.h"
33
34 /*******************************************************************
35  *
36  * @brief Assigns new transaction id to DU initiated procedure
37  *
38  * @details
39  *
40  *    Function : assignTransactionId
41  *
42  *    Functionality: Assigns new transaction id to a DU initiated
43  *       procedure
44  *
45  * @params[in] Region region
46  *             Pool pool
47  * @return ROK     - success
48  *         RFAILED - failure
49  *
50  * ****************************************************************/
51 uint8_t assignTransactionId()
52 {
53    uint8_t currTransId = duCb.e2apDb.e2TransInfo.transIdCounter;
54
55    /* Update to next valid value */
56    duCb.e2apDb.e2TransInfo.transIdCounter++;
57    if(duCb.e2apDb.e2TransInfo.transIdCounter == MAX_NUM_TRANSACTION)
58       duCb.e2apDb.e2TransInfo.transIdCounter = 0;
59
60    return currTransId;
61 }
62
63 /*******************************************************************
64  *
65  * @brief Sends E2 msg over SCTP
66  *
67  * @details
68  *
69  *    Function : SendE2APMsg
70  *
71  *    Functionality: Sends E2 msg over SCTP
72  *
73  * @params[in] Region region
74  *             Pool pool
75  * @return ROK     - success
76  *         RFAILED - failure
77  *
78  * ****************************************************************/
79
80 uint8_t SendE2APMsg(Region region, Pool pool, char *encBuf, int encBufSize)
81 {
82    Buffer *mBuf=NULLP;
83
84    if(ODU_GET_MSG_BUF(region, pool, &mBuf) == ROK)
85    {
86       if(ODU_ADD_POST_MSG_MULT((Data *)encBuf, encBufSize, mBuf) == ROK)
87       {
88          ODU_PRINT_MSG(mBuf, 0,0);
89
90          if(sctpSend(mBuf, E2_INTERFACE) != ROK)
91          {
92             DU_LOG("\nERROR  -->  E2AP : SCTP Send for E2  failed");
93             ODU_PUT_MSG_BUF(mBuf);
94             return RFAILED;
95          }
96       }
97       else
98       {
99          DU_LOG("\nERROR  -->  E2AP : ODU_ADD_POST_MSG_MULT failed");
100          ODU_PUT_MSG_BUF(mBuf);
101          return RFAILED;
102       }
103       ODU_PUT_MSG_BUF(mBuf);
104    }
105    else
106    {
107       DU_LOG("\nERROR  -->  E2AP : Failed to allocate memory");
108       return RFAILED;
109    }
110
111    return ROK;
112 } /* SendE2APMsg */
113
114 /*******************************************************************
115  *
116  * @brief Resets E2 
117  *
118  * @details
119  *
120  *    Function : ResetE2Request
121  *
122  *    Functionality: This function resets E2.
123  *       As per ORAN WG3 E2GAP v3.0 Spec, section 5.5.3
124  *       If E2 node initates reset procedure then:
125  *        a. Send reset request to RIC
126  *        b. Delete any pre-established RIC subscriptions
127  *        c. Gracefully terminates any ongoing RIC services
128  *       If RIC initiates reset procedure then :
129  *        a. Delete any pre-established RIC subscriptions
130  *        b. Gracefully terminates any ongoing RIC services
131  *        c. Send reset response to RIC
132  *
133  * @params[in]
134  * @return ROK     - success
135  *         RFAILED - failure
136  *
137  * ****************************************************************/
138 uint8_t ResetE2Request(E2ProcedureDirection dir, E2CauseType type, E2Cause cause)
139 {
140    /* Send Reset Request to RIC if DU detects any abnormal failure */
141    if(dir == E2_NODE_INITIATED)
142    {
143       if(BuildAndSendE2ResetRequest(type, cause) != ROK)
144       {
145          DU_LOG("\nERROR  -->  E2AP : BuildAndSendE2ResetRequest failed");
146          return RFAILED;
147       }
148    }
149
150    /* TODO when RIC subscription service model is implemented
151       Process following steps of resetting E2
152       1. Deletes any pre-established RIC subscriptions
153       2. Gracefully terminates any ongoing RIC services
154     */
155
156    /* Send Reset Response if RIC initiated Reset request is received at DU */
157    if(dir == RIC_INITIATED)
158    {
159       //BuildAndSendE2ResetResponse();
160    }   
161    return ROK;
162 }
163
164 /**********************************************************************
165   End of file
166  **********************************************************************/
167