From e916ff3559fb554e54a328da6e264fc5e4348cd1 Mon Sep 17 00:00:00 2001 From: svaidhya Date: Sat, 4 May 2024 17:04:54 +0530 Subject: [PATCH] [Epic-Id: ODUHIGH-576] [Task-Id: ODUHIGH-586] [SubTask-Id: ODUHIGH-592]| [NFAPI_BRANCH] | PNF State MAchine At VNF and Establishment of PNF_READY_IND & PNF_PARAM_REQ Change-Id: I08795bfab760e131223f04a5d41e1000f305e72b Signed-off-by: svaidhya --- src/5gnrmac/lwr_mac_ex_ms.c | 23 ++ src/5gnrmac/lwr_mac_utils.h | 18 ++ src/5gnrmac/nfapi_common.c | 193 ++++++++++++++++ src/5gnrmac/nfapi_common.h | 42 ++++ src/5gnrmac/nfapi_vnf_fsm.c | 276 +++++++++++++++++++++++ src/5gnrmac/{lwr_mac_nfapi.h => nfapi_vnf_fsm.h} | 70 +++++- src/5gnrmac/rg_lmm.c | 9 + src/du_app/du_mgr_msg_router.c | 44 ++++ src/du_app/du_sctp.c | 3 - src/intel_fapi/nfapi_interface.h | 6 - src/pnf_stub/pnf_stub.c | 184 +++++++++++++++ src/pnf_stub/pnf_stub.h | 2 + src/pnf_stub/pnf_stub_sctp.c | 10 +- 13 files changed, 859 insertions(+), 21 deletions(-) create mode 100644 src/5gnrmac/nfapi_common.c create mode 100644 src/5gnrmac/nfapi_common.h create mode 100644 src/5gnrmac/nfapi_vnf_fsm.c rename src/5gnrmac/{lwr_mac_nfapi.h => nfapi_vnf_fsm.h} (57%) diff --git a/src/5gnrmac/lwr_mac_ex_ms.c b/src/5gnrmac/lwr_mac_ex_ms.c index efa92eac9..eaca62ac6 100644 --- a/src/5gnrmac/lwr_mac_ex_ms.c +++ b/src/5gnrmac/lwr_mac_ex_ms.c @@ -31,6 +31,9 @@ #endif #ifdef NFAPI_ENABLED #include "lwr_mac_sctp_inf.h" +#include "nfapi_interface.h" +#include "nfapi_common.h" +#include "nfapi_vnf_fsm.h" #endif /************************************************************************** @@ -259,7 +262,27 @@ uint8_t lwrMacActvTsk(Pst *pst, Buffer *mBuf) #ifdef NFAPI_ENABLED case EVENT_PNF_DATA: { + nFapi_p5_hdr p5Hdr; + nFapi_msg_header msgHdr; + NfapiPnfEvent msgType = 0; + + nFapiExtractP5Hdr(&p5Hdr, mBuf); + nFapiExtractMsgHdr(&msgHdr, mBuf); + if(msgHdr.sRU_termination_type != NFAPI_P5_P7_SRU_TYPE) + { + DU_LOG("\nERROR --> NFAPI_VNF: Incorrect SRU Termination Type:%d",\ + msgHdr.sRU_termination_type); + return RFAILED; + } + msgType = convertNfapiP5TagValToMsgId(msgHdr.msg_id); + if(msgType == PNF_MAX_EVENT) + { + DU_LOG("\nERROR --> NFAPI_VNF: Incorrect NFAPI MsgID received:%d",\ + msgHdr.msg_id); + return RFAILED; + } + sendEventToNfapiVnfFsm(msgType, &p5Hdr, &msgHdr, mBuf); break; } #endif diff --git a/src/5gnrmac/lwr_mac_utils.h b/src/5gnrmac/lwr_mac_utils.h index 50f9a4538..ce9ba9179 100644 --- a/src/5gnrmac/lwr_mac_utils.h +++ b/src/5gnrmac/lwr_mac_utils.h @@ -60,6 +60,24 @@ _pst.intfVer = 0; \ } +/* Fill Pst structure for sending msg from Lower MAC to DUAPP */ +#define FILL_PST_LWR_MAC_TO_DUAPP(_pst, _event) \ +{ \ + _pst.selector = ODU_SELECTOR_LWLC; \ + _pst.srcEnt = ENTLWRMAC; \ + _pst.dstEnt = ENTDUAPP; \ + _pst.dstInst = 0; \ + _pst.srcInst = 0; \ + _pst.dstProcId = ODU_GET_PROCID(); \ + _pst.srcProcId = ODU_GET_PROCID(); \ + _pst.region = MAC_MEM_REGION; \ + _pst.pool = MAC_POOL; \ + _pst.event = _event; \ + _pst.route = 0; \ + _pst.prior = 0; \ + _pst.intfVer = 0; \ +} + void convertFreqDomRsrcMapToIAPIFormat(uint8_t *sourceBitMap, uint8_t *destBitMap); /********************************************************************** End of file diff --git a/src/5gnrmac/nfapi_common.c b/src/5gnrmac/nfapi_common.c new file mode 100644 index 000000000..b982f3987 --- /dev/null +++ b/src/5gnrmac/nfapi_common.c @@ -0,0 +1,193 @@ + /******************************************************************************* + ################################################################################ + # Copyright (c) [2017-2019] [Radisys] # + # # + # Licensed under the Apache License, Version 2.0 (the "License"); # + # you may not use this file except in compliance with the License. # + # You may obtain a copy of the License at # + # # + # http://www.apache.org/licenses/LICENSE-2.0 # + # # + # Unless required by applicable law or agreed to in writing, software # + # distributed under the License is distributed on an "AS IS" BASIS, # + # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # + # See the License for the specific language governing permissions and # + # limitations under the License. # + ################################################################################ + *******************************************************************************/ + +/*Reference: SCF225_5G_NFAPI_SPECIFICATION, v225.2.1, Issue Date: 23 Nov 2021*/ + +/* header include files -- defines (.h) */ +#include "common_def.h" +#include "mac_utils.h" +#include "lwr_mac.h" +#include "nfapi_vnf_fsm.h" +#include "nfapi_interface.h" +#include "nfapi_common.h" + +/********************************************************************************* + * + * @Function Name: nFapiFillP5Hdr + * + * + * @Functionality: + * It Fills NFAPI P5 Msg Header[as per Table 2-3 " nFapi Header"] + * + * + * @params + * [OUT]: Msg Buffer to send in SCTP P5 Interface + * + * *******************************************************************************/ + +void nfapiFillP5Hdr(Buffer *mBuf) +{ + uint8_t moreSeqNum = 0; + moreSeqNum = NFAPI_MORE_SEG_NUM(NFAPI_P5_MORE, NFAPI_P5_SEG_NUM); + + CMCHKPK(oduPackPostUInt16, NFAPI_P5_SEG_NUM, mBuf); + CMCHKPK(oduPackPostUInt8, moreSeqNum, mBuf); + CMCHKPK(oduPackPostUInt8, vnfDb.p5Info.seqNum, mBuf); + CMCHKPK(oduPackPostUInt32, NFAPI_P5_TIMESTAMP, mBuf); + +} + +/********************************************************************************* + * + * @Function Name: nFapiFillMsgHdr + * + * + * @Functionality: + * It Fills Message Header[as per Table 2-4 " nFapi Msg Header"] + * + * + * @params + * [IN]: Phy_id, msgId, msgLen + * [OUT]: Msg Buffer to send in SCTP P5 Interface + * + * *******************************************************************************/ + +void nfapiFillMsgHdr(Buffer *mBuf, uint8_t phyId, uint16_t msgId, uint32_t msgLen) +{ + CMCHKPK(oduPackPostUInt8, NFAPI_P5_P7_SRU_TYPE, mBuf); + CMCHKPK(oduPackPostUInt8, phyId, mBuf); + CMCHKPK(oduPackPostUInt16, msgId, mBuf); + CMCHKPK(oduPackPostUInt32, msgLen, mBuf); + +} + +/********************************************************************************* + * + * @Function Name: nFapiExtractP5Hdr + * + * + * @Functionality: + * It extracts NFAPI P5 Message Header[as per Table 2-5 "P5 nFapi Header"] + * + * + * @params + * [IN]: Msg Buffer received in SCTP P5 Interface + * [OUT]: nFapi_p5_hdr *p5Hdr + * + * *******************************************************************************/ + +void nFapiExtractP5Hdr(nFapi_p5_hdr *p5Hdr, Buffer *mBuf) +{ + CMCHKPK(oduPackUInt16, &(p5Hdr->seg_len), mBuf); + CMCHKPK(oduPackUInt8, &(p5Hdr->more_segNum), mBuf); + CMCHKPK(oduPackUInt8, &(p5Hdr->seq_num), mBuf); + CMCHKPK(oduPackUInt32, &(p5Hdr->timeStamp), mBuf); + DU_LOG("\nINFo --> NFAPI_VNF: seqLen:%d, moreSegNum:%d, seqNum:%d, timeStamp:%d", + p5Hdr->seg_len,p5Hdr->more_segNum,p5Hdr->seq_num,p5Hdr->timeStamp); +} + +/********************************************************************************* + * + * @Function Name: nFapiExtractMsgHdr + * + * + * @Functionality: + * It extracts Message Header[as per Table 2-4 "P5 nFapi Msg Header"] + * + * + * @params + * [IN]: Msg Buffer received in SCTP P5 Interface + * [OUT]: nFapi_msg_header *msgHdr + * + * *******************************************************************************/ + +void nFapiExtractMsgHdr(nFapi_msg_header *msgHdr, Buffer *mBuf) +{ + + CMCHKPK(oduPackUInt8, &(msgHdr->sRU_termination_type), mBuf); + CMCHKPK(oduPackUInt8, &(msgHdr->phy_id), mBuf); + CMCHKPK(oduPackUInt16, &(msgHdr->msg_id), mBuf); + CMCHKPK(oduPackUInt32, &(msgHdr->length), mBuf); + + DU_LOG("\nINFO --> NFAPI_VNF: RUType:%d, phy_id:%d, msgId:%d, len:%d",\ + msgHdr->sRU_termination_type,msgHdr->phy_id,msgHdr->msg_id,msgHdr->length ); +} + +/********************************************************************************* + * @Function Name: convertNfapiP5TagValToMsgId + * + * + * @Functionality: + * It converts NFAPI_P5 Tag VALUE [as per Table 2-7 "Dedicated nFAPI messages"] + * to MSG_EVENT (NfapiPnfEvent in nfapi_vnf_fsm.h) + * + * + * @params + * [IN]: tagVal from (SCF 225 Table 2-7 "Dedicated nFAPI messages") + * [OUT]: NfapiPnfEvent + * + * *******************************************************************************/ +NfapiPnfEvent convertNfapiP5TagValToMsgId(uint16_t tagVal) +{ + + switch(tagVal) + { + case TAG_NFAPI_PNF_READY_IND: + { + return PNF_READY_IND; + } + case TAG_NFAPI_PNF_PARAM_REQ: + { + return PNF_PARAM_REQ; + } + case TAG_NFAPI_PNF_PARAM_RESP: + { + return PNF_PARAM_RESP; + } + case TAG_NFAPI_PNF_CONFIG_REQ: + { + return PNF_CONFIG_REQ; + } + case TAG_NFAPI_PNF_CONFIG_RESP: + { + return PNF_CONFIG_RESP; + } + case TAG_NFAPI_PNF_START_REQ: + { + return PNF_START_REQ; + } + case TAG_NFAPI_PNF_START_RESP: + { + return PNF_START_RESP; + } + case TAG_NFAPI_PNF_STOP_REQ: + { + return PNF_STOP_REQ; + } + case TAG_NFAPI_PNF_STOP_RESP: + { + return PNF_STOP_RESP; + } + default: + { + DU_LOG("\n Incorrect TAG VALUE of NFAPI P5 Messages:%d",tagVal); + return PNF_MAX_EVENT; + } + } + return PNF_MAX_EVENT; +} diff --git a/src/5gnrmac/nfapi_common.h b/src/5gnrmac/nfapi_common.h new file mode 100644 index 000000000..0cb816c27 --- /dev/null +++ b/src/5gnrmac/nfapi_common.h @@ -0,0 +1,42 @@ + /******************************************************************************* + ################################################################################ + # Copyright (c) [2017-2019] [Radisys] # + # # + # Licensed under the Apache License, Version 2.0 (the "License"); # + # you may not use this file except in compliance with the License. # + # You may obtain a copy of the License at # + # # + # http://www.apache.org/licenses/LICENSE-2.0 # + # # + # Unless required by applicable law or agreed to in writing, software # + # distributed under the License is distributed on an "AS IS" BASIS, # + # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # + # See the License for the specific language governing permissions and # + # limitations under the License. # + ################################################################################ + *******************************************************************************/ + +/*Reference: SCF225_5G_NFAPI_SPECIFICATION, v225.2.1, Issue Date: 23 Nov 2021*/ + +#ifndef _NFAPI_COMMON_H +#define _NFAPI_COMMON_H + +#include "nfapi_vnf_fsm.h" + +#define NFAPI_P5_PHY_ID 0 +#define NFAPI_P5_TIMESTAMP 0 /*As per SCF225,Table 2-3:Set to zero on Tx and ignored on Rx */ +#define NFAPI_P5_MORE 0 +#define NFAPI_P5_SEG_NUM 0 +#define NFAPI_P5_P7_SRU_TYPE 0x01 /*SCF225,Table 2-4: 0x01 for P5/P7 messages.*/ + +#define NFAPI_MORE_SEG_NUM(_moreField, _segStart) ((_moreField << 7) | (_segStart & 0x07)) + +/*Common Functions*/ +void nfapiFillP5Hdr(Buffer *mBuf); +void nfapiFillMsgHdr(Buffer *mBuf, uint8_t phyId, uint16_t msgId, uint32_t msglen); + +void nFapiExtractP5Hdr(nFapi_p5_hdr *p5Hdr, Buffer *mBuf); +void nFapiExtractMsgHdr(nFapi_msg_header *msgHdr, Buffer *mBuf); + +NfapiPnfEvent convertNfapiP5TagValToMsgId(uint16_t tagVal); +#endif diff --git a/src/5gnrmac/nfapi_vnf_fsm.c b/src/5gnrmac/nfapi_vnf_fsm.c new file mode 100644 index 000000000..539d43ff6 --- /dev/null +++ b/src/5gnrmac/nfapi_vnf_fsm.c @@ -0,0 +1,276 @@ + /******************************************************************************* + ################################################################################ + # Copyright (c) [2017-2019] [Radisys] # + # # + # Licensed under the Apache License, Version 2.0 (the "License"); # + # you may not use this file except in compliance with the License. # + # You may obtain a copy of the License at # + # # + # http://www.apache.org/licenses/LICENSE-2.0 # + # # + # Unless required by applicable law or agreed to in writing, software # + # distributed under the License is distributed on an "AS IS" BASIS, # + # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # + # See the License for the specific language governing permissions and # + # limitations under the License. # + ################################################################################ + *******************************************************************************/ + +/*Reference: SCF225_5G_NFAPI_SPECIFICATION, v225.2.1, Issue Date: 23 Nov 2021*/ + +/* header include files -- defines (.h) */ +#include "common_def.h" +#include "lwr_mac.h" +#include "nfapi_vnf_fsm.h" +#include "nfapi_interface.h" +#include "nfapi_common.h" +#include "lwr_mac_utils.h" +#include "lwr_mac_sctp_inf.h" +#include "mac_utils.h" + +/******************************************************************* + * + * @brief Initalization of VNF Database + * + * @details + * + * Function : nFapiVnfInit + * + * @params[in] + * @return void + * + * ****************************************************************/ + +void nFapiVnfInit() +{ + memset(&vnfDb, 0, sizeof(NfapiVnfDb)); + vnfDb.pnfStateAtVnf = PNF_STATE_IDLE; + vnfDb.pnfEvent = 0; +} + +/******************************************************************* + * + * @brief Processes NFAPI PNF_READY_IND from PNF + * + * @details + * + * Function : nfapi_vnf_procPnfReadyIndEvt + * + * Functionality: + * - Processes PNF_READY_IND(Ref: SCF 225, Sec 3.1.0) + * - Starts the PNF Initalization(Ref: SCF 225, Sec 2.1.1.1) + * + * @params[in] + * @return ROK - success + * RFAILED - failure + * + * ****************************************************************/ + +uint8_t nfapi_vnf_procPnfReadyIndEvt(nFapi_p5_hdr *p5Hdr, nFapi_msg_header *msgHdr, void *msg) +{ + uint32_t version = 0; + + DU_LOG("\nINFO --> NFAPI_VNF: Received EVENT[%d] at STATE[%d]",\ + vnfDb.pnfEvent, vnfDb.pnfStateAtVnf); + + CMCHKPK(oduPackUInt32, &(version), msg); + + DU_LOG("\nINFO --> NFAPI_VNF: PNF_READY_IND version:%d",version); + + sendEventToNfapiVnfFsm(PNF_PARAM_REQ, NULLP, NULLP, NULLP); + return ROK; +} + +/******************************************************************* + * + * @brief Processes NFAPI PNF_PARAM_REQ from PNF + * + * @details + * + * Function : nfapi_vnf_procPnfParamReqEvt + * + * Functionality: + * - Builds and Sends PNF_PARAM_REQ(Ref: SCF 225, Sec 3.1.1) + * + * @params[in] + * @return ROK - success + * RFAILED - failure + * + * ****************************************************************/ + +uint8_t nfapi_vnf_procPnfParamReqEvt(nFapi_p5_hdr *p5Hdr, nFapi_msg_header *msgHdr, void *msg) +{ + Buffer *mBuf = NULLP; + Pst pst; + + if (ODU_GET_MSG_BUF(MAC_MEM_REGION, MAC_POOL, &mBuf) != ROK) + { + DU_LOG("\nERROR --> NFAPI_VNF : Memory allocation failed in packPnfParamReq"); + return RFAILED; + } + nfapiFillP5Hdr(mBuf); + nfapiFillMsgHdr(mBuf, NFAPI_P5_PHY_ID, TAG_NFAPI_PNF_PARAM_REQ, 0); + vnfDb.p5Info.seqNum++; + FILL_PST_LWR_MAC_TO_DUAPP(pst, EVENT_PNF_DATA); + return ODU_POST_TASK(&pst, mBuf); +} + +/******************************************************************* + * + * @brief Processes NFAPI PNF_PARAM_RESP from PNF + * + * @details + * + * Function : nfapi_vnf_procPnfParamRespEvt + * + * Functionality: + * - Processes PNF_PARAM_RESP(Ref: SCF 225, Sec 3.1.2) + * + * @params[in] + * @return ROK - success + * RFAILED - failure + * + * ****************************************************************/ + +uint8_t nfapi_vnf_procPnfParamRespEvt(nFapi_p5_hdr *p5Hdr, nFapi_msg_header *msgHdr, void *msg) +{ + uint8_t errorCode = 1; + + DU_LOG("\nINFO --> NFAPI_VNF: Received EVENT[%d] at STATE[%d]",\ + vnfDb.pnfEvent, vnfDb.pnfStateAtVnf); + + CMCHKPK(oduPackUInt8, &(errorCode), msg); + + DU_LOG("\nINFO --> NFAPI_VNF: PNF_PARAM_RESP errCode:%d",errorCode); + + return ROK; +} + +uint8_t nfapi_vnf_procPnfConfigReqEvt(nFapi_p5_hdr *p5Hdr, nFapi_msg_header *msgHdr, void *msg) +{ + return ROK; +} + +uint8_t nfapi_vnf_procPnfConfigRespEvt(nFapi_p5_hdr *p5Hdr, nFapi_msg_header *msgHdr, void *msg) +{ + return ROK; +} + +uint8_t nfapi_vnf_procPnfStartReqEvt(nFapi_p5_hdr *p5Hdr, nFapi_msg_header *msgHdr, void *msg) +{ + return ROK; +} + +uint8_t nfapi_vnf_procPnfStartRespEvt(nFapi_p5_hdr *p5Hdr, nFapi_msg_header *msgHdr, void *msg) +{ + return ROK; +} + +uint8_t nfapi_vnf_procPnfStopReqEvt(nFapi_p5_hdr *p5Hdr, nFapi_msg_header *msgHdr, void *msg) +{ + return ROK; +} + +uint8_t nfapi_vnf_procPnfStopRespEvt(nFapi_p5_hdr *p5Hdr, nFapi_msg_header *msgHdr, void *msg) +{ + return ROK; +} + +/******************************************************************* + * + * @brief Handles Invalid Request Event + * + * @details + * + * Function : nfapi_vnf_procInvalidEvt + * + * Functionality: + * - Displays the PNF state when the invalid event occurs + * + * @params[in] + * @return ROK - success + * RFAILED - failure + * + * ****************************************************************/ +uint8_t nfapi_vnf_procInvalidEvt(nFapi_p5_hdr *p5Hdr, nFapi_msg_header *msgHdr, void *msg) +{ + DU_LOG("\nINFO --> NFAPI_VNF: Invalid Msg received EVENT[%d] at STATE[%d]",\ + vnfDb.pnfEvent, vnfDb.pnfStateAtVnf); + return ROK; +} + +/* ******************************************************** + * NFAPI VNF FINITE STATE MACHINE HANDLER + * ********************************************************/ +nFapiVnfFsmHdlr nFapiEvtHdlr[PNF_MAX_STATE][PNF_MAX_EVENT] = +{ + { + /* PNF_STATE_IDLE */ + nfapi_vnf_procPnfReadyIndEvt, /*PNF_READY_IND*/ + nfapi_vnf_procPnfParamReqEvt, /*PNF_PARAM_REQ*/ + nfapi_vnf_procPnfParamRespEvt, /*PNF_PARAM_RESP*/ + nfapi_vnf_procPnfConfigReqEvt, /*PNF_CONFIG_REQ*/ + nfapi_vnf_procPnfConfigRespEvt, /*PNF_CONFIG_RESP*/ + nfapi_vnf_procInvalidEvt, /*PNF_START_REQ*/ + nfapi_vnf_procPnfStartRespEvt, /*PNF_START_RESP*/ + nfapi_vnf_procInvalidEvt, /*PNF_STOP_REQ*/ + nfapi_vnf_procPnfStopRespEvt, /*PNF_STOP_RESP*/ + }, + { + /* PNF_STATE_CONFIGURED */ + nfapi_vnf_procInvalidEvt, /*PNF_READY_IND*/ + nfapi_vnf_procPnfParamReqEvt, /*PNF_PARAM_REQ*/ + nfapi_vnf_procPnfParamRespEvt, /*PNF_PARAM_RESP*/ + nfapi_vnf_procPnfConfigReqEvt, /*PNF_CONFIG_REQ*/ + nfapi_vnf_procPnfConfigRespEvt, /*PNF_CONFIG_RESP*/ + nfapi_vnf_procPnfStartReqEvt, /*PNF_START_REQ*/ + nfapi_vnf_procPnfStartRespEvt, /*PNF_START_RESP*/ + nfapi_vnf_procInvalidEvt, /*PNF_STOP_REQ*/ + nfapi_vnf_procPnfStopRespEvt, /*PNF_STOP_RESP*/ + }, + { + /* PNF_STATE_RUNNING */ + nfapi_vnf_procInvalidEvt, /*PNF_READY_IND*/ + nfapi_vnf_procInvalidEvt, /*PNF_PARAM_REQ*/ + nfapi_vnf_procPnfParamRespEvt, /*PNF_PARAM_RESP*/ + nfapi_vnf_procPnfConfigReqEvt, /*PNF_CONFIG_REQ*/ + nfapi_vnf_procPnfConfigRespEvt, /*PNF_CONFIG_RESP*/ + nfapi_vnf_procInvalidEvt, /*PNF_START_REQ*/ + nfapi_vnf_procPnfStartRespEvt, /*PNF_START_RESP*/ + nfapi_vnf_procPnfStopReqEvt, /*PNF_STOP_REQ*/ + nfapi_vnf_procPnfStopRespEvt, /*PNF_STOP_RESP*/ + } +}; + +/******************************************************************* + * + * @brief Sends message to NFAPI_VNF Fsm Event Handler + * + * @details + * + * Function : sendEventToNfapiVnfFsm + * + * Functionality: + * -Sends message to NfapiVnf + * + * @params[in] Message Type + * Message Hdr and P5 Hdr + * Messaga Pointer + * + * @return void + * + ******************************************************************/ +void sendEventToNfapiVnfFsm(NfapiPnfEvent msgType, nFapi_p5_hdr *p5Hdr, nFapi_msg_header *msgHdr, void *msg) +{ + uint8_t ret = ROK; + vnfDb.pnfEvent = msgType; + ret = nFapiEvtHdlr[vnfDb.pnfStateAtVnf][vnfDb.pnfEvent](p5Hdr, msgHdr, msg); + if(ret == RFAILED) + { + DU_LOG("\nERROR --> NFAPI_VNF: NFAPI_VNF FSM failed"); + } +} + +/********************************************************************** + End of file + **********************************************************************/ diff --git a/src/5gnrmac/lwr_mac_nfapi.h b/src/5gnrmac/nfapi_vnf_fsm.h similarity index 57% rename from src/5gnrmac/lwr_mac_nfapi.h rename to src/5gnrmac/nfapi_vnf_fsm.h index e73a04def..f72716e0d 100644 --- a/src/5gnrmac/lwr_mac_nfapi.h +++ b/src/5gnrmac/nfapi_vnf_fsm.h @@ -16,11 +16,33 @@ ################################################################################ *******************************************************************************/ -#ifndef _LWR_MAC_NFAPI_H_ -#define _LWR_MAC_NFAPI_H_ +/*Reference: SCF225_5G_NFAPI_SPECIFICATION, v225.2.1, Issue Date: 23 Nov 2021*/ + +#ifndef _NFAPI_VNF_FSM_H_ +#define _NFAPI_VNF_FSM_H_ #include "nfapi_interface.h" +typedef enum { + PNF_STATE_IDLE = 0, + PNF_STATE_CONFIGURED, + PNF_STATE_RUNNING, + PNF_MAX_STATE +}NfapiPnfState; + +typedef enum { + PNF_READY_IND = 0, + PNF_PARAM_REQ, + PNF_PARAM_RESP, + PNF_CONFIG_REQ, + PNF_CONFIG_RESP, + PNF_START_REQ, + PNF_START_RESP, + PNF_STOP_REQ, + PNF_STOP_RESP, + PNF_MAX_EVENT +}NfapiPnfEvent; + typedef struct nfapiTransportInfo { uint32_t assocId; @@ -32,7 +54,7 @@ typedef struct nfapiTransportInfo CmInetNetAddrLst addrLst; /* Refers to the destinaiton Addr Lst in CmInetNetAddrLst format */ CmInetNetAddr ipNetAddr; /* Refers to the destination Addr in CmInetNet Addr format */ - /*TODO: later also add the IPV6 support*/ + /*TODO: Add the IPV6 support*/ }NfapiTransportInfo; @@ -49,21 +71,20 @@ typedef struct nfapiTimingInfo typedef struct nfapiPnfConfig { - nFapi_pnf_state pnfState; uint16_t max_phys; NfapiTimingInfo vnfTimingCfg; }NfapiPnfConfig; typedef struct nfapiSyncInfo { - uint8_t phyId; - uint8_t inSync; - uint32_t prev_t1; - uint32_t prev_t2; - uint32_t prev_t3; + uint8_t phyId; + uint8_t inSync; + uint32_t prev_t1; + uint32_t prev_t2; + uint32_t prev_t3; uint8_t sfn; uint8_t slot; - NfapiSyncInfo *next; + struct nfapiSyncInfo *next; }NfapiSyncInfo; typedef struct nfapiP7VnfInfo @@ -73,13 +94,40 @@ typedef struct nfapiP7VnfInfo NfapiSyncInfo *p7SyncInfo; }NfapiP7VnfInfo; +typedef struct nfapiP5Info +{ + uint8_t seqNum; +}NfapiP5Info; + typedef struct nfapiVnfDb { - NfapiTransportInfo p5TransInfo; + NfapiPnfState pnfStateAtVnf; + NfapiPnfEvent pnfEvent; + NfapiP5Info p5Info; NfapiTransportInfo p7TransInfo; NfapiPnfConfig pnfConfig; NfapiSyncInfo vnfSynchInfo; NfapiP7VnfInfo vnfP7Info; }NfapiVnfDb; +/* Global variables */ +NfapiVnfDb vnfDb; + +void nFapiVnfInit(); +typedef uint8_t (*nFapiVnfFsmHdlr)(nFapi_p5_hdr *, nFapi_msg_header *, void *); +void sendEventToNfapiVnfFsm(NfapiPnfEvent msgType, nFapi_p5_hdr *p5Hdr, nFapi_msg_header *msgHdr, void *msg); + +/*NFAPI Msg Handler Functions*/ +uint8_t nfapi_vnf_procPnfReadyIndEvt(nFapi_p5_hdr *p5Hdr, nFapi_msg_header *msgHdr, void *msg); +uint8_t nfapi_vnf_procPnfParamReqEvt(nFapi_p5_hdr *p5Hdr, nFapi_msg_header *msgHdr, void *msg); +uint8_t nfapi_vnf_procPnfParamRespEvt(nFapi_p5_hdr *p5Hdr, nFapi_msg_header *msgHdr, void *msg); +uint8_t nfapi_vnf_procPnfConfigReqEvt(nFapi_p5_hdr *p5Hdr, nFapi_msg_header *msgHdr, void *msg); +uint8_t nfapi_vnf_procPnfConfigRespEvt(nFapi_p5_hdr *p5Hdr, nFapi_msg_header *msgHdr, void *msg); +uint8_t nfapi_vnf_procPnfStartReqEvt(nFapi_p5_hdr *p5Hdr, nFapi_msg_header *msgHdr, void *msg); +uint8_t nfapi_vnf_procPnfStartRespEvt(nFapi_p5_hdr *p5Hdr, nFapi_msg_header *msgHdr, void *msg); +uint8_t nfapi_vnf_procPnfStopReqEvt(nFapi_p5_hdr *p5Hdr, nFapi_msg_header *msgHdr, void *msg); +uint8_t nfapi_vnf_procPnfStopRespEvt(nFapi_p5_hdr *p5Hdr, nFapi_msg_header *msgHdr, void *msg); +uint8_t nfapi_vnf_procInvalidEvt(nFapi_p5_hdr *p5Hdr, nFapi_msg_header *msgHdr, void *msg); + + #endif diff --git a/src/5gnrmac/rg_lmm.c b/src/5gnrmac/rg_lmm.c index 69fad5b4c..968d784cf 100755 --- a/src/5gnrmac/rg_lmm.c +++ b/src/5gnrmac/rg_lmm.c @@ -68,6 +68,10 @@ #include "lwr_mac_fsm.h" #include "lwr_mac_phy.h" +#ifdef NFAPI_ENABLED +#include "nfapi_vnf_fsm.h" +#endif + #ifdef __cplusplus extern "C" { #endif /* __cplusplus */ @@ -172,6 +176,11 @@ Reason reason /* reason */ /* Initialize lower mac */ lwrMacLayerInit(region, 0); +#ifdef NFAPI_ENABLED + /*Initialize VNF*/ + nFapiVnfInit(); +#endif + return ROK; } /* macActvInit */ diff --git a/src/du_app/du_mgr_msg_router.c b/src/du_app/du_mgr_msg_router.c index 0338f742b..d864b00fd 100644 --- a/src/du_app/du_mgr_msg_router.c +++ b/src/du_app/du_mgr_msg_router.c @@ -42,6 +42,10 @@ #include "du_ue_mgr.h" #include "du_utils.h" +#ifdef NFAPI_ENABLED +#include "lwr_mac_sctp_inf.h" +#endif + uint8_t unpackRlcConfigCfm(RlcConfigCfm func,Pst *pst, Buffer *mBuf); uint8_t cmUnpkLkwCntrlCfm(LkwCntrlCfm func,Pst *pst, Buffer *mBuf); uint8_t cmUnpkLrgCfgCfm(LrgCfgCfm func,Pst *pst, Buffer *mBuf); @@ -373,6 +377,26 @@ void callFlowduActvTsk(Pst *pst) } break; } + case ENTLWRMAC: + { + strcpy(sourceTask,"ENTLWRMAC"); + switch(pst->event) + { +#ifdef NFAPI_ENABLED + case EVENT_PNF_DATA: + { + strcpy(message,"EVENT_PNF_DATA"); + break; + } +#endif + default: + { + strcpy(message,"Invalid Event"); + break; + } + } + break; + } default: { strcpy(sourceTask,"Invalid Source Entity Id"); @@ -689,6 +713,26 @@ uint8_t duActvTsk(Pst *pst, Buffer *mBuf) ODU_PUT_MSG_BUF(mBuf); break; } + case ENTLWRMAC: + { + switch(pst->event) + { +#ifdef NFAPI_ENABLED + case EVENT_PNF_DATA: + { + sctpSend(mBuf, PNF_P5_INTERFACE); + break; + } +#endif + default: + { + DU_LOG("\nERROR --> DU_APP : Invalid event[%d] received at duActvTsk from ENTEGTP", pst->event); + ret = RFAILED; + } + } + ODU_PUT_MSG_BUF(mBuf); + break; + } default: { DU_LOG("\nERROR --> DU_APP : DU APP can not process message from Entity %d", pst->srcEnt); diff --git a/src/du_app/du_sctp.c b/src/du_app/du_sctp.c index 342b1fd31..b3464ea2d 100644 --- a/src/du_app/du_sctp.c +++ b/src/du_app/du_sctp.c @@ -615,9 +615,6 @@ void sendToLwrMac(Buffer *mBuf, Event event) { Pst pst; DU_LOG("\nDEBUG --> SCTP : Forwarding received message to Lwr MAC"); - ODU_PRINT_MSG(mBuf, 0, 0); - - ODU_GET_MSG_BUF(pst.region, pst.pool, &mBuf); memset(&(pst), 0, sizeof(Pst)); pst.srcEnt = (Ent)ENTSCTP; diff --git a/src/intel_fapi/nfapi_interface.h b/src/intel_fapi/nfapi_interface.h index 28592269c..71c478b43 100644 --- a/src/intel_fapi/nfapi_interface.h +++ b/src/intel_fapi/nfapi_interface.h @@ -83,12 +83,6 @@ /*As per Table 3-19*/ #define MAX_NUM_TLV_IN_CONFIG_REQ 9 -typedef enum { - PNF_STATE_IDLE = 0, - PNF_STATE_CONFIGURED, - PNF_STATE_RUNNING -}nFapi_pnf_state; - /*Table 3-4 and Table 3-7*/ typedef enum { NFAPI_MSG_OK = 0, diff --git a/src/pnf_stub/pnf_stub.c b/src/pnf_stub/pnf_stub.c index fc0021d1e..83570ef3a 100644 --- a/src/pnf_stub/pnf_stub.c +++ b/src/pnf_stub/pnf_stub.c @@ -34,6 +34,7 @@ #include #include "pnf_stub_sctp.h" #include "pnf_stub.h" +#include "nfapi_interface.h" PnfGlobalCb pnfCb; @@ -159,5 +160,188 @@ uint8_t tst() return ROK; } +/******************************************************************* + * + * @Function Name: nFapiFillP5Hdr + * + * + * @Functionality: + * It Fills NFAPI P5 Msg Header[as per Table 2-3 " nFapi Header"] + * + * + * @params + * [OUT]: Msg Buffer to send in SCTP P5 Interface + * + * ****************************************************************/ +void nfapiFillP5Hdr(Buffer *mBuf) +{ + CMCHKPK(oduPackPostUInt16, 0, mBuf); + CMCHKPK(oduPackPostUInt8, 0, mBuf); + CMCHKPK(oduPackPostUInt8, 0, mBuf); + CMCHKPK(oduPackPostUInt32, 0, mBuf); + return; +} + +/********************************************************************************* + * + * @Function Name: nFapiFillMsgHdr + * + * + * @Functionality: + * It Fills Message Header[as per Table 2-4 " nFapi Msg Header"] + * + * + * @params + * [IN]: Phy_id, msgId, msgLen + * [OUT]: Msg Buffer to send in SCTP P5 Interface + * + * *******************************************************************************/ + +void nfapiFillMsgHdr(Buffer *mBuf, uint8_t phyId, uint16_t msgId, uint32_t msgLen) +{ + CMCHKPK(oduPackPostUInt8, 1, mBuf); + CMCHKPK(oduPackPostUInt8, phyId, mBuf); + CMCHKPK(oduPackPostUInt16, msgId, mBuf); + CMCHKPK(oduPackPostUInt32, msgLen, mBuf); + return; +} + +/********************************************************************************* + * + * @Function Name: nFapiExtractP5Hdr + * + * + * @Functionality: + * It extracts NFAPI P5 Message Header[as per Table 2-5 "P5 nFapi Header"] + * + * + * @params + * [IN]: Msg Buffer received in SCTP P5 Interface + * [OUT]: nFapi_p5_hdr *p5Hdr + * + * *******************************************************************************/ +void nFapiExtractP5Hdr(nFapi_p5_hdr *p5Hdr, Buffer *mBuf) +{ + CMCHKPK(oduPackUInt16, &(p5Hdr->seg_len), mBuf); + CMCHKPK(oduPackUInt8, &(p5Hdr->more_segNum), mBuf); + CMCHKPK(oduPackUInt8, &(p5Hdr->seq_num), mBuf); + CMCHKPK(oduPackUInt32, &(p5Hdr->timeStamp), mBuf); + DU_LOG("\nINFo --> NFAPI_PNF: seqLen:%d, moreSegNum:%d, seqNum:%d, timeStamp:%d", + p5Hdr->seg_len,p5Hdr->more_segNum,p5Hdr->seq_num,p5Hdr->timeStamp); + return; +} + +/********************************************************************************* + * + * @Function Name: nFapiExtractMsgHdr + * + * + * @Functionality: + * It extracts Message Header[as per Table 2-4 "P5 nFapi Msg Header"] + * + * + * @params + * [IN]: Msg Buffer received in SCTP P5 Interface + * [OUT]: nFapi_msg_header *msgHdr + * + * *******************************************************************************/ +void nFapiExtractMsgHdr(nFapi_msg_header *msgHdr, Buffer *mBuf) +{ + + CMCHKPK(oduPackUInt8, &(msgHdr->sRU_termination_type), mBuf); + CMCHKPK(oduPackUInt8, &(msgHdr->phy_id), mBuf); + CMCHKPK(oduPackUInt16, &(msgHdr->msg_id), mBuf); + CMCHKPK(oduPackUInt32, &(msgHdr->length), mBuf); + + DU_LOG("\nINFO --> NFAPI_PNF: RUType:%d, phy_id:%d, msgId:%d, len:%d",\ + msgHdr->sRU_termination_type,msgHdr->phy_id,msgHdr->msg_id,msgHdr->length ); + return; +} + +/********************************************************************************* + * + * @Function Name: sendPnfReadyInd + * + * + * @Functionality: + * It Build And Sends the PNF_READY_IND + * + * + * *******************************************************************************/ +uint8_t sendReadyInd() +{ + uint8_t ret = ROK; + Buffer *mBuf = NULLP; + + if (ODU_GET_MSG_BUF(PNF_APP_MEM_REG, PNF_POOL, &mBuf) != ROK) + { + DU_LOG("\nERROR --> NFAPI_PNF : Memory allocation failed in pnf_readyInd"); + return RFAILED; + } + nfapiFillP5Hdr(mBuf); + nfapiFillMsgHdr(mBuf, 0, TAG_NFAPI_PNF_READY_IND, 0); + CMCHKPK(oduPackPostUInt32, 123, mBuf); //version + ret = pnfP5SctpSend(mBuf); + if(ret == RFAILED) + { + ODU_PUT_MSG_BUF(mBuf); + } + return ret; +} +uint8_t buildAndSendPnfParamResp() +{ + uint8_t ret = ROK; + Buffer *mBuf = NULLP; + + if (ODU_GET_MSG_BUF(PNF_APP_MEM_REG, PNF_POOL, &mBuf) != ROK) + { + DU_LOG("\nERROR --> NFAPI_PNF : Memory allocation failed in pnf_readyInd"); + return RFAILED; + } + nfapiFillP5Hdr(mBuf); + nfapiFillMsgHdr(mBuf, 0, TAG_NFAPI_PNF_PARAM_RESP, 0); + CMCHKPK(oduPackPostUInt8, 0, mBuf); //errorCode + ret = pnfP5SctpSend(mBuf); + if(ret == RFAILED) + { + ODU_PUT_MSG_BUF(mBuf); + } + return ret; +} +/********************************************************************************* + * + * @Function Name: p5MsgHandlerAtPnf + * + * + * @Functionality: + * Handles the P5 MEssages at PNF SIM + * + * @Params [IN]: Message Buffer received at SCTP NFAPI P5 Interface + * + * *******************************************************************************/ +uint8_t p5MsgHandlerAtPnf(Buffer *mBuf) +{ + nFapi_p5_hdr p5Hdr; + nFapi_msg_header msgHdr; + uint8_t ret = ROK; + + nFapiExtractP5Hdr(&p5Hdr, mBuf); + nFapiExtractMsgHdr(&msgHdr, mBuf); + + switch(msgHdr.msg_id) + { + case TAG_NFAPI_PNF_PARAM_REQ: + { + DU_LOG("\nINFO --> NFAPI_PNF: PNF_PARAM_REQ recevied."); + ret = buildAndSendPnfParamResp(); + break; + } + default: + { + DU_LOG("\nERROR --> NFAPI_PNF: Wrong MSGID of NFAPI P5 Message:%d",msgHdr.msg_id); + } + } + return ret; +} diff --git a/src/pnf_stub/pnf_stub.h b/src/pnf_stub/pnf_stub.h index 2b4acceb1..eedeb9351 100644 --- a/src/pnf_stub/pnf_stub.h +++ b/src/pnf_stub/pnf_stub.h @@ -47,5 +47,7 @@ typedef struct pnfGlobalCb }PnfGlobalCb; extern PnfGlobalCb pnfCb; +uint8_t sendReadyInd(); +uint8_t p5MsgHandlerAtPnf(Buffer *mBuf); #endif diff --git a/src/pnf_stub/pnf_stub_sctp.c b/src/pnf_stub/pnf_stub_sctp.c index e4b12e14e..ee3bf2962 100644 --- a/src/pnf_stub/pnf_stub_sctp.c +++ b/src/pnf_stub/pnf_stub_sctp.c @@ -192,6 +192,9 @@ uint8_t pnfP5SctpStartReq() } } + /*Since Socket is UP and Client(VNF) has responded with CONNECT thus + * initating PNF_READY_IND as part of PNF INITIALIZATION msg*/ + ret = sendReadyInd(); if(ret == ROK) { if(pnfP5SctpSockPoll() != ROK) @@ -390,7 +393,12 @@ uint8_t pnfP5ProcessPolling(PnfP5SctpSockPollParams *pollParams, PnfP5SctpAssocC else if(assocCb->connUp) { /*TODO: Add the Handler of PNF P5 msgs*/ - //E2APMsgHdlr(&assocCb->duId, pollParams->mBuf); + if(p5MsgHandlerAtPnf(pollParams->mBuf) != ROK) + { + DU_LOG("\nERROR --> NFAPI_PNF: Failed to process SCTP msg received from VNF"); + ODU_PUT_MSG_BUF(pollParams->mBuf); + return RFAILED; + } ODU_PUT_MSG_BUF(pollParams->mBuf); } else -- 2.16.6