32e8e7941a351f349355cdac586403c990272d3c
[o-du/l2.git] / src / du_app / du_cell_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
19 /* This file contains message handling functionality for DU cell management */
20 #include "common_def.h"
21 #include "lrg.h"
22 #include "legtp.h"
23 #include "lrg.x"
24 #include "lkw.x"
25 #include "rgr.h"
26 #include "rgr.x"
27 #include "du_app_mac_inf.h"
28 #include "du_app_rlc_inf.h"
29 #include "du_cfg.h"
30 #include "du_mgr.h"
31 #include "du_utils.h"
32 #include "du_cell_mgr.h"
33
34 #ifdef O1_ENABLE
35
36 #include "AlarmInterface.h"
37 #include "CmInterface.h"
38
39 #endif
40
41 DuMacCellDeleteReq packMacCellDeleteReqOpts[] =
42 {
43    packDuMacCellDeleteReq,       /* Loose coupling */
44    MacProcCellDeleteReq,         /* TIght coupling */
45    packDuMacCellDeleteReq        /* Light weight-loose coupling */
46 };
47
48 /*******************************************************************
49  *
50  * @brief Processes cells to be activated
51  *
52  * @details
53  *
54  *    Function : duProcCellsToBeActivated
55  *
56  *    Functionality:
57  *      - Processes cells to be activated list received in F1SetupRsp
58  *
59  * @params[in] void
60  * @return ROK     - success
61  *         RFAILED - failure
62  *
63  * ****************************************************************/
64 uint8_t duProcCellsToBeActivated(uint8_t *plmnStr, uint16_t nci, uint16_t nRPci)
65 {
66    uint8_t ret = ROK;
67    DuCellCb *cellCb = NULLP;
68    uint8_t cfgIdx, tmpPlmn[4];
69
70    for(cfgIdx=0; cfgIdx<duCb.numCfgCells; cfgIdx++)
71    {
72       memset(tmpPlmn, 0, 4);
73       buildPlmnId(duCb.cfgCellLst[cfgIdx]->cellInfo.nrEcgi.plmn, tmpPlmn);
74       if(duCb.cfgCellLst[cfgIdx]->cellInfo.nrEcgi.cellId == nci &&
75             (strcmp((const char*)tmpPlmn, (const char*)plmnStr) == 0))
76       {
77          cellCb = duCb.cfgCellLst[cfgIdx];
78          break;
79       }
80       else
81       {
82          DU_LOG("\nERROR  -->  DU APP : No Cell found for NCI %d", nci);
83          return RFAILED;
84       }
85    }
86
87    cellCb->cellStatus = ACTIVATION_IN_PROGRESS; 
88    cellCb->cellInfo.nrPci = nRPci;
89
90    duCb.actvCellLst[cellCb->cellId -1] = cellCb;
91    duCb.numActvCells++;
92
93    if(duBuildAndSendMacCellCfg(cellCb->cellId) != ROK)
94    {
95       DU_LOG("\nERROR  -->  DU APP : macCellCfg build and send failed");
96       /* Delete cell from actvCellList */
97       duCb.actvCellLst[cellCb->cellId -1] = NULLP;
98       --(duCb.numActvCells);
99       ret = RFAILED;
100    }
101    return ret;
102 }
103
104 /*******************************************************************
105  *
106  * @brief Handles DU F1Setup Rsp received in F1AP
107  *
108  * @details
109  *
110  *    Function : duProcF1SetupRsp
111  *
112  *    Functionality:
113  *      - Handles DU F1Setup Rsp received in F1AP
114  *
115  * @params[in] Pointer to F1SetupRsp 
116  * @return void
117  *
118  ******************************************************************/
119 void duProcF1SetupRsp()
120 {
121    DU_LOG("\nINFO   -->  DU_APP : F1 Setup Response received");
122    duCb.f1Status = TRUE; //Set F1 status as true
123 }
124
125 /*******************************************************************
126 *
127 * @brief Returns cellCb based on cell ID
128 *
129 * @details
130 *
131 *    Function : duGetCellCb
132 *
133 *    Functionality: Returns DU APP CellCb based on cell ID
134 *
135 * @params[in] F1AP_PDU_t ASN decoded F1AP message
136 * @return ROK     - success
137 *         RFAILED - failure
138 *
139 * ****************************************************************/
140 uint8_t duGetCellCb(uint16_t cellId, DuCellCb **cellCb)
141 {
142    uint8_t cellIdx = 0;
143    for(cellIdx=0; cellIdx < MAX_NUM_CELL; cellIdx++)
144    {
145       if(duCb.actvCellLst[cellIdx] && (duCb.actvCellLst[cellIdx]->cellId == cellId))
146       {
147          *cellCb = duCb.actvCellLst[cellIdx];
148               break;
149       }
150    }
151
152    if(!*cellCb)
153    {
154       DU_LOG("\nERROR  -->  DU APP : Cell Id %d not found in DU APP", cellId);
155       return RFAILED;
156    }
157
158    return ROK;
159 }
160
161 /*****************************************************************
162 * @brief Handles slot indication from MAC
163 *
164 * @details
165 *
166 *   Function : duHandleSlotInd
167 *
168 *   Functionality:
169 *       Handles  slot indication from MAC
170
171 *  @params[in] Post structure pointer
172 *              SlotTimingInfo *slotIndInfo
173 *  @return ROK     - success
174 *          RFAILED - failure
175
176
177 *****************************************************************/
178 uint8_t duHandleSlotInd(Pst *pst, SlotTimingInfo *slotIndInfo)
179 {
180    uint8_t cellIdx = 0, ret = ROK;
181    DuCellCb *duCellCb;
182
183    if(slotIndInfo)
184    {
185       GET_CELL_IDX(slotIndInfo->cellId, cellIdx);
186       duCellCb = duCb.actvCellLst[cellIdx];
187
188       if(duCellCb)
189       {
190          duCellCb->currSlotInfo.sfn = slotIndInfo->sfn;
191          duCellCb->currSlotInfo.slot = slotIndInfo->slot;
192       }
193       else
194       {
195          DU_LOG("\nERROR  -->  DU APP : CellId[%d] doesnot exist", slotIndInfo->cellId);
196          ret = RFAILED;
197       }
198       DU_FREE_SHRABL_BUF(pst->region, pst->pool, slotIndInfo, sizeof(SlotTimingInfo));
199    }
200    else
201    {
202       DU_LOG("\nERROR  -->  DU APP : Recevied null pointer from MAC");
203       ret = RFAILED;
204    }
205    return(ret);
206 }
207 /*******************************************************************
208  *
209  * @brief Handles cell up indication from MAC
210  *
211  * @details
212  *
213  *    Function : duHandleCellUpInd
214  *
215  *    Functionality:
216  *      Handles cell up indication from MAC
217  *
218  * @params[in] Post structure pointer
219  *             cell Up info
220  * @return ROK     - success
221  *         RFAILED - failure
222  *
223  * ****************************************************************/
224 uint8_t duHandleCellUpInd(Pst *pst, OduCellId *cellId)
225 {
226    DuCellCb *cellCb = NULLP; 
227
228 #ifndef O1_ENABLE
229
230    /*Note: Static Configuration, when O1 is not configuring the RRM policy*/
231    RrmPolicy *rrmPolicy;
232    DU_ALLOC(rrmPolicy, sizeof(RrmPolicy));
233    rrmPolicy->rsrcType = RSRC_PRB;
234    rrmPolicy->numMemberList = 1;
235    DU_ALLOC(rrmPolicy->memberList, sizeof(PolicyMemberList *));
236    DU_ALLOC(rrmPolicy->memberList[0], sizeof(PolicyMemberList));
237    
238    memset(&rrmPolicy->memberList[0]->plmn, 0, sizeof(Plmn)); 
239    rrmPolicy->memberList[0]->snssai.sst = 1;
240    rrmPolicy->memberList[0]->snssai.sd[0] = 2;
241    rrmPolicy->memberList[0]->snssai.sd[1] = 3;
242    rrmPolicy->memberList[0]->snssai.sd[2] = 4;
243    rrmPolicy->policyMinRatio = 30;
244    rrmPolicy->policyMaxRatio = 90;
245    rrmPolicy->policyDedicatedRatio = 10;
246 #endif
247
248    if(cellId->cellId <=0 || cellId->cellId > MAX_NUM_CELL)
249    {
250       DU_LOG("\nERROR  -->  DU APP : Invalid Cell Id %d in duHandleCellUpInd()", cellId->cellId);
251       return RFAILED;
252    }
253
254    if(duGetCellCb(cellId->cellId, &cellCb) != ROK)
255       return RFAILED;
256
257    if((cellCb != NULL) && (cellCb->cellStatus == ACTIVATION_IN_PROGRESS))
258    {
259       DU_LOG("\nINFO   -->  DU APP : 5G-NR Cell %d is UP", cellId->cellId);
260       cellCb->cellStatus = ACTIVATED;
261       gCellStatus = CELL_UP;
262
263 #ifdef O1_ENABLE
264       if(duCfgParam.tempSliceCfg.rrmPolicy)
265          BuildAndSendSliceConfigReq(duCfgParam.tempSliceCfg.rrmPolicy, duCfgParam.tempSliceCfg.totalRrmPolicy, duCfgParam.tempSliceCfg.totalSliceCount);
266       DU_LOG("\nINFO   -->  DU APP : Raise cell UP alarm for cell id=%d", cellId->cellId);
267       raiseCellAlrm(CELL_UP_ALARM_ID, cellId->cellId);
268       setCellOpState(cellId->cellId, ENABLED, ACTIVE);
269 #else
270       BuildAndSendSliceConfigReq(&rrmPolicy,1, rrmPolicy->numMemberList);
271 #endif
272
273    }
274
275    if((pst->selector == ODU_SELECTOR_LWLC) || (pst->selector == ODU_SELECTOR_TC))
276       DU_FREE_SHRABL_BUF(pst->region, pst->pool, cellId, sizeof(OduCellId));
277    return ROK;
278 }
279
280 /*******************************************************************
281  *
282  * @brief Handle Cell delete response from MAC
283  *
284  * @details
285  *
286  *    Function : DuProcMacCellDeleteRsp
287  *
288  *    Functionality: Handle Cell delete response from MAC
289  *
290  * @params[in] Pointer to MacCellDeleteRsp and Pst
291  * @return ROK     - success
292  *         RFAILED - failure
293  *
294  * ****************************************************************/
295
296 uint8_t DuProcMacCellDeleteRsp(Pst *pst, MacCellDeleteRsp *deleteRsp)
297 {
298    uint8_t ret = ROK;
299    uint16_t cellIdx=0;
300    
301    if(deleteRsp)
302    {
303       if(deleteRsp->result == SUCCESSFUL_RSP)
304       {
305          GET_CELL_IDX(deleteRsp->cellId, cellIdx);
306          DU_LOG("\nINFO   -->  DU APP : MAC CELL Delete Response : SUCCESS [CELL IDX : %d]", deleteRsp->cellId);
307          if(duCb.actvCellLst[cellIdx] && (duCb.actvCellLst[cellIdx]->cellId == deleteRsp->cellId))
308          {
309             memset(duCb.actvCellLst[cellIdx], 0, sizeof(DuCellCb));
310             gCellStatus = CELL_DOWN;
311
312 #ifdef O1_ENABLE
313             DU_LOG("\nINFO   -->  DU APP : Raise cell down alarm for cell id=%d", deleteRsp->cellId);
314             raiseCellAlrm(CELL_DOWN_ALARM_ID, deleteRsp->cellId);
315             setCellOpState(deleteRsp->cellId, DISABLED, INACTIVE);
316 #endif
317
318             duCb.numActvCells--;
319             duCb.numCfgCells--;
320             DU_FREE(duCb.actvCellLst[cellIdx], sizeof(DuCellCb));
321
322          }
323          else
324          {
325             DU_LOG("\nERROR  -->  DU APP : DuProcMacCellDeleteRsp(): CellId [%d] doesnot exist", deleteRsp->cellId);
326             ret = RFAILED;
327          }
328       }
329       else
330       {
331          DU_LOG("\nERROR  -->  DU APP : DuProcMacCellDeleteRsp(): MAC CELL Delete Response : FAILED\
332          [CELL IDX : %d]", deleteRsp->cellId);
333          ret = RFAILED;
334       }
335       DU_FREE_SHRABL_BUF(pst->region, pst->pool, deleteRsp, sizeof(MacCellDeleteRsp));
336    }
337    else
338    {
339       DU_LOG("\nERROR  -->  DU APP : DuProcMacCellDeleteRsp(): Received MAC cell delete response is NULL");
340       ret = RFAILED;
341    }
342    return ret;
343 }
344
345 /*******************************************************************
346  *
347  * @brief Sending Cell Delete Req To Mac
348  *
349  * @details
350  *
351  *    Function : sendCellDeleteReqToMac
352  *
353  *    Functionality:
354  *     sending Cell Delete Req To Mac
355  *
356  *  @params[in]    uint16_t cellId
357  *  @return ROK     - success
358  *          RFAILED - failure
359  *
360  *
361  *****************************************************************/
362
363 uint8_t sendCellDeleteReqToMac(uint16_t cellId)
364 {
365    Pst pst;
366    uint8_t ret=ROK;
367    MacCellDelete *cellDelete = NULLP;
368    
369    DU_ALLOC_SHRABL_BUF(cellDelete, sizeof(MacCellDelete));
370    if(cellDelete)
371    {
372       cellDelete->cellId = cellId;
373       FILL_PST_DUAPP_TO_MAC(pst, EVENT_MAC_CELL_DELETE_REQ);
374
375       DU_LOG("\nINFO   -->  DU APP : Sending Cell Delete Request to MAC");  
376       /* Processing one Cell at a time to MAC */
377       ret = (*packMacCellDeleteReqOpts[pst.selector])(&pst, cellDelete);
378       if(ret == RFAILED)
379       {
380          DU_LOG("\nERROR  -->  DU APP : sendCellDeleteReqToMac(): Failed to send Cell delete Req to MAC");
381          DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, cellDelete, sizeof(MacCellDelete));
382       }
383    }
384    else
385    {
386       DU_LOG("\nERROR  -->   DU APP : sendCellDeleteReqToMac(): Failed to allocate memory"); 
387       ret = RFAILED;
388    }
389    return ret;
390 }
391
392 /*******************************************************************
393  *
394  * @brief DU preocess Cell Delete Req to MAC 
395  *
396  * @details
397  *
398  *    Function : duSendCellDeletReq 
399  *
400  *    Functionality: DU process Cell Delete Req to MAC 
401  *
402  * @params[in] uint16_t cellId
403  * @return ROK     - success
404  *         RFAILED - failure
405  *
406  * ****************************************************************/
407
408 uint8_t duSendCellDeletReq(uint16_t cellId)
409 {
410    uint16_t cellIdx = 0;
411    DU_LOG("\nINFO   -->  DU APP : Processing Cell Delete Request ");
412    GET_CELL_IDX(cellId, cellIdx);
413
414    if(duCb.actvCellLst[cellIdx] == NULLP)
415    {
416       DU_LOG("\nERROR  -->  DU APP : duSendCellDeletReq(): CellId[%d] is not found", cellId);
417       return RFAILED;
418    }
419    
420    if(duCb.actvCellLst[cellIdx]->cellId != cellId)
421    {
422       DU_LOG("\nERROR  -->  DU APP : duSendCellDeletReq(): CellId[%d] is not found", cellId);
423       return RFAILED;
424
425    }  
426    
427    if(duCb.actvCellLst[cellIdx]->cellStatus != DELETION_IN_PROGRESS)
428    {
429       DU_LOG("\nERROR  -->  DU APP : duSendCellDeletReq(): CellStatus[%d] of cellId[%d] is not correct.\
430       Expected CellStatus is DELETION_IN_PROGRESS",duCb.actvCellLst[cellIdx]->cellStatus, cellId);
431       return RFAILED;  
432    }
433
434    if(duBuildAndSendMacCellStop(cellId) == RFAILED)
435    {
436       DU_LOG("\nERROR  -->  DU APP : duSendCellDeletReq(): Failed to build and send cell stop request to MAC for\
437             cellId[%d]",cellId);
438       return RFAILED;
439    }
440
441    return ROK;
442 }
443
444 /**********************************************************************
445   End of file
446  **********************************************************************/