X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=blobdiff_plain;f=src%2Fcu_stub%2Fcu_stub_sctp.c;h=e4c266909c52c6441f0568f3411a9151f0fced19;hb=def50dc175cebc67238db5f1acd5ff322a2279bd;hp=c7a3eeb1cb778180f0658633554de6d298b3fd8d;hpb=d349ae65e1495488772f87e5cfa1ae71d9eab075;p=o-du%2Fl2.git diff --git a/src/cu_stub/cu_stub_sctp.c b/src/cu_stub/cu_stub_sctp.c index c7a3eeb1c..e4c266909 100644 --- a/src/cu_stub/cu_stub_sctp.c +++ b/src/cu_stub/cu_stub_sctp.c @@ -18,23 +18,13 @@ /* This file contains all SCTP related functionality */ -#include -#include "f1ap_msg_hdl.h" +#include "common_def.h" +#include "cu_f1ap_msg_hdl.h" #include "cu_stub_sctp.h" +#include "cu_stub_egtp.h" +#include "du_log.h" -/* Global variable declaration */ -CmInetFd lstnSockFd; /* Listening Socket file descriptor */ -CmInetFd sockFd; /* Socket File descriptor */ -U8 socket_type; /* Socket type */ -Bool nonblocking; /* Blocking/Non-blocking socket */ -Bool connUp; /* Is connection up */ -int assocId; /* Assoc Id of connected assoc */ - -CmInetNetAddrLst localAddrLst; -CmInetNetAddrLst remoteAddrLst; - -SctpParams *sctpCfg; /* SCTP configurations at DU */ - +CuSctpDestCb f1Params; /************************************************************************** * @brief Task Initiation callback function. * @@ -55,12 +45,13 @@ SctpParams *sctpCfg; /* SCTP configurations at DU */ * @return ROK - success * RFAILED - failure ***************************************************************************/ -S16 sctpActvInit(Ent entity, Inst inst, Region region, Reason reason) +S16 sctpActvInit() { + DU_LOG("\n\nSCTP : Initializing"); connUp = FALSE; assocId = 0; nonblocking = FALSE; - sctpCfg = &(cuCfgParams.sctpParams); + sctpCfg = cuCfgParams.sctpParams; return ROK; } @@ -91,125 +82,129 @@ S16 sctpActvTsk(Pst *pst, Buffer *mBuf) return ROK; } +/************************************************************************** + * @brief Function to configure the Sctp Params during config Request + * + * @details + * + * Function : duSctpCfgReq + * + * Functionality: + * This function configures SCTP Params during the config Request + * + * @return ROK - success + * RFAILED - failure + * + ***************************************************************************/ + +S16 sctpCfgReq() +{ + +/* Fill F1 Params */ + f1Params.destPort = sctpCfg.duPort; + f1Params.srcPort = sctpCfg.cuPort; + f1Params.bReadFdSet = ROK; + memset(&f1Params.sockFd, -1, sizeof(CmInetFd)); + memset(&f1Params.lstnSockFd, -1, sizeof(CmInetFd)); + fillDestNetAddr(&f1Params.destIpNetAddr, &sctpCfg.duIpAddr); + + return ROK; +} + + /******************************************************************* * - * @brief Opens a non-blocking socket and binds to local address + * @brief Fills the address List of the source Ip Address * * @details * - * Function : openSctpEndp + * Function : fillAddrLst * * Functionality: - * Opens a non-blocking socket and binds to local address + * Fills the address List of source Ip Address * - * @params[in] + * @params[in] CmInetNetAddrLst *addrLstPtr, Address List pointer + * @params[in] F1IpAddr *srcIpAddr, src Ip Adrress to be filled in the Address List * @return ROK - success * RFAILED - failure * - * ****************************************************************/ -S16 openSctpEndp() -{ - U8 ret; - U8 numRetry = 0; - - /* Opening a non-blocking SCTP socket */ - socket_type = CM_INET_STREAM; - - do{ - ret = cmInetSocket(socket_type, &lstnSockFd, IPPROTO_SCTP,(sctpCfg->cuIpAddr.ipV4Pres ? AF_INET : AF_INET6)); - if (ret != ROK) - { - numRetry++; - if(numRetry >= MAX_RETRY) - { - printf("\nAll attempts to open socket failed."); - /* Send indication to du_app */ - RETVALUE(RFAILED); - } - else - { - printf("\nRetrying socket opening"); - } - } - else - { - printf("\nSocket[%d] opened successfully",lstnSockFd.fd); - break; - } - }while(numRetry < MAX_RETRY); + ******************************************************************/ - RETVALUE(ROK); -} /* End of openSctpEndp */ +S16 fillAddrLst(CmInetNetAddrLst *addrLstPtr, SctpIpAddr *ipAddr) +{ + addrLstPtr->count++; + addrLstPtr->addrs[(addrLstPtr->count - 1)].type = CM_INET_IPV4ADDR_TYPE; + addrLstPtr->addrs[(addrLstPtr->count - 1)].u.ipv4NetAddr = CM_INET_NTOH_UINT32(ipAddr->ipV4Addr); + return ROK; +} -/******************************************************************* +/****************************************************************************** * - * @brief Bind socket to local Ip address and port + * @brief Fills the address List of the source Ip Address * * @details * - * Function : bindSctpEndp + * Function : fillDestNetAddr * * Functionality: - * -Bind socket to local Ip address and port + * Fills the address List of destinatoion Ip Address * - * @params[in] + * @params[in] CmInetNetAddr *destAddrPtr, Address List pointer + * @params[in] F1IpAddr *dstIpAddr, destIp Address to be filled in the Address List * @return ROK - success * RFAILED - failure * - * ****************************************************************/ -S16 bindSctpEndp() + *******************************************************************************/ +S16 fillDestNetAddr(CmInetNetAddr *destAddrPtr, SctpIpAddr *dstIpPtr) { + /* Filling destination address */ + destAddrPtr->type = CM_INET_IPV4ADDR_TYPE; + destAddrPtr->u.ipv4NetAddr = CM_INET_NTOH_UINT32(dstIpPtr->ipV4Addr); + return ROK; +} - U8 ret; - U8 numRetry = 0; +/****************************************************************************** + * + * @brief Eastablishes the Assoc Req for the received interface type + * + * @details + * + * Function : sctpStartReq + * + * Functionality: + * Eastablishes the Assoc Req for the received interface type + * + * @params[in] DuSctpDestCb *paramPtr + * @return ROK - success + * RFAILED - failure + * + *******************************************************************************/ - /* Binding the socket with local address */ - localAddrLst.count = 1; - if(sctpCfg->cuIpAddr.ipV4Pres) +S16 sctpStartReq() +{ + S16 ret = ROK; + socket_type = CM_INET_STREAM; + fillAddrLst(&f1Params.localAddrLst, &sctpCfg.cuIpAddr); + + if((ret = cmInetSocket(socket_type, &f1Params.lstnSockFd, IPPROTO_SCTP) != ROK)) + { + DU_LOG("\nSCTP : Socket[%d] coudnt open for listening", f1Params.lstnSockFd.fd); + } + else if((ret = cmInetSctpBindx(&f1Params.lstnSockFd, &f1Params.localAddrLst, f1Params.srcPort)) != ROK) { - localAddrLst.addrs[0].type = CM_INET_IPV4ADDR_TYPE; - localAddrLst.addrs[0].u.ipv4NetAddr = CM_INET_NTOH_U32(sctpCfg->cuIpAddr.ipV4Addr); + DU_LOG("\nSCTP: Binding failed at CU"); } - else if(sctpCfg->cuIpAddr.ipV6Pres) + else if((ret = sctpAccept(&f1Params.lstnSockFd, &f1Params.peerAddr, &f1Params.sockFd)) != ROK) { - localAddrLst.addrs[0].type = CM_INET_IPV6ADDR_TYPE; - // CM_INET_COPY_IPV6ADDR(&(localAddrLst.addrs[0].u.ipv6NetAddr),&(sctpCfg->cuIpAddr.ipV6Addr); + DU_LOG("\nSCTP: Unable to accept the connection at CU"); } - else + else if(sctpSockPoll() != ROK) { - localAddrLst.addrs[0].type = CM_INET_IPV4ADDR_TYPE; - localAddrLst.addrs[0].u.ipv4NetAddr = 0; - } - - do{ - ret = cmInetSctpBindx(&lstnSockFd, &localAddrLst, sctpCfg->cuPort); - if (ret != ROK) - { - numRetry++; - if(numRetry >= MAX_RETRY) - { - printf("\nAll attempts to bind socket failed."); - cmInetClose(&lstnSockFd); - /* Send indication to du_app */ - RETVALUE(RFAILED); - } - else - { - printf("\nRetrying socket binding"); - } - } - else - { - printf("\nSocket bind successful"); - break; - } - }while(numRetry < MAX_RETRY); - - RETVALUE(ROK); - -} /* End of bindSctpEndp() */ - + DU_LOG("\nSCTP: Polling failed to start at CU"); + } + return (ret); +} /******************************************************************* * * @brief Sets socket options as per requirement @@ -226,8 +221,9 @@ S16 bindSctpEndp() * RFAILED - failure * * ****************************************************************/ -S16 sctpSetSockOpts() +S16 sctpSetSockOpts(CmInetFd *sock_Fd) { + S16 ret = ROK; CmSctpEvent sctpEvent; sctpEvent.dataIoEvent = TRUE; @@ -239,8 +235,12 @@ S16 sctpSetSockOpts() sctpEvent.partialDeliveryEvent = TRUE; sctpEvent.adaptationLayerEvent = TRUE; - cmInetSetOpt(&sockFd, CM_SOCKOPT_LEVEL_SCTP, CM_SOCKOPT_OPT_SCTP_EVENTS, &sctpEvent); - RETVALUE(ROK); + if((ret = cmInetSetOpt(sock_Fd, CM_SOCKOPT_LEVEL_SCTP, CM_SOCKOPT_OPT_SCTP_EVENTS, &sctpEvent)) != ROK) + { + ret = RFAILED; + } + + return (ret); } /******************************************************************* @@ -260,42 +260,43 @@ S16 sctpSetSockOpts() * RFAILED - failure * * ****************************************************************/ -S16 sctpAccept() +S16 sctpAccept(CmInetFd *lstnSock_Fd, CmInetAddr *peerAddr, CmInetFd *sock_Fd) { - U8 ret; - CmInetAddr peerAddr; + uint8_t ret; - ret = cmInetListen(&lstnSockFd, 1);; + ret = cmInetListen(lstnSock_Fd, 1); if (ret != ROK) { - printf("\nListening on socket failed"); - cmInetClose(&lstnSockFd); - RETVALUE(RFAILED); + DU_LOG("\nSCTP : Listening on socket failed"); + cmInetClose(lstnSock_Fd); + return RFAILED; } + + DU_LOG("\nSCTP : Connecting"); while(!connUp) { - ret = cmInetAccept(&lstnSockFd, &peerAddr, &sockFd); + ret = cmInetAccept(lstnSock_Fd, peerAddr, sock_Fd); if (ret == ROKDNA) { continue; } else if(ret != ROK) { - printf("\nFailed to accept connection"); - RETVALUE(RFAILED); + DU_LOG("\nSCTP : Failed to accept connection"); + return RFAILED; } else { connUp = TRUE; - sctpSetSockOpts(); - printf("\nAccepted incoming connection"); + sctpSetSockOpts(sock_Fd); break; } } + DU_LOG("\nSCTP : Connection established"); - RETVALUE(ROK); -}/* End of sctpAccept() */ + return ROK; +} /******************************************************************* * @@ -319,60 +320,62 @@ S16 sctpNtfyHdlr(CmInetSctpNotification *ntfy) switch(ntfy->header.nType) { case CM_INET_SCTP_ASSOC_CHANGE : + DU_LOG("\nSCTP : Assoc change notification received"); switch(ntfy->u.assocChange.state) { case CM_INET_SCTP_COMM_UP: - printf("\nSCTP notify assocchange(comm up) received"); + DU_LOG("Event : COMMUNICATION UP"); connUp = TRUE; break; case CM_INET_SCTP_COMM_LOST: - printf("\nSCTP notify assocchange(comm lost) received"); + DU_LOG("Event : COMMUNICATION LOST"); connUp = FALSE; break; case CM_INET_SCTP_RESTART: - printf("\nSCTP notify assocchange(sctp restart) received"); + DU_LOG("Event : SCTP RESTART"); connUp = FALSE; break; case CM_INET_SCTP_SHUTDOWN_COMP: /* association gracefully shutdown */ - printf("\nSCTP notify assocchange(shutdown complete) received\n"); + DU_LOG("Event : SHUTDOWN COMPLETE"); connUp = FALSE; break; case CM_INET_SCTP_CANT_STR_ASSOC: - printf("\nSCTP notify assocchange(cant str assoc) received\n"); + DU_LOG("Event : CANT START ASSOC"); connUp = FALSE; break; default: - printf("\nInvalid event"); + DU_LOG("\nInvalid event"); break; } break; case CM_INET_SCTP_PEER_ADDR_CHANGE : - printf("\nSCTP notify peer addr change received"); + DU_LOG("\nSCTP : Peer Address Change notificarion received"); /* Need to add handler */ break; case CM_INET_SCTP_REMOTE_ERROR : - printf("\nSCTP notify remote error received"); + DU_LOG("\nSCTP : Remote Error notification received"); break; case CM_INET_SCTP_SEND_FAILED : - printf("\nSCTP notify send failed received\n"); + DU_LOG("\nSCTP : Send Failed notification received\n"); break; case CM_INET_SCTP_SHUTDOWN_EVENT : /* peer socket gracefully closed */ - printf("\nSCTP notify shutdown event received\n"); + DU_LOG("\nSCTP : Shutdown Event notification received\n"); connUp = FALSE; + exit(0); break; case CM_INET_SCTP_ADAPTATION_INDICATION : - printf("\nSCTP notify adaptation indication received\n"); + DU_LOG("\nSCTP : Adaptation Indication received\n"); break; case CM_INET_SCTP_PARTIAL_DELIVERY_EVENT: - printf("\nSCTP notify partial delivery received\n"); + DU_LOG("\nSCTP : Partial Delivery Event received\n"); break; default: - printf("\nInvalid sctp notification type\n"); + DU_LOG("\nSCTP : Invalid notification type\n"); break; } sctpNtfyInd(ntfy); - RETVALUE(ROK); + return ROK; }/* End of sctpNtfyHdlr */ /******************************************************************* @@ -393,21 +396,21 @@ S16 sctpNtfyHdlr(CmInetSctpNotification *ntfy) * ****************************************************************/ S16 sctpSockPoll() { - U8 ret; - S16 numFds; - CmInetFdSet readFd; - U16 port; - U32 timeout; /* timeout for cmInetSelect() */ - U32 *timeoutPtr; /* pointer to timeout */ - U32 flag; - Buffer *mBuf; - MsgLen bufLen; - CmInetMemInfo memInfo; /* buffer allocation info */ - CmInetNetAddr addr; - CmInetSctpSndRcvInfo info; - CmInetSctpNotification ntfy; - - if (sockFd.blocking) + uint16_t ret = ROK; + uint32_t timeout; + uint32_t *timeoutPtr; + Buffer *egtpBuf; + MsgLen egtpBufLen; + CmInetAddr egtpFromAddr; + CmInetMemInfo memInfo; + sctpSockPollParams f1PollParams; + + memset(&f1PollParams, 0, sizeof(sctpSockPollParams)); + + egtpFromAddr.port = egtpCb.dstCb.dstPort; + egtpFromAddr.address = egtpCb.dstCb.dstIp; + + if(f1Params.sockFd.blocking) { /* blocking */ timeoutPtr = NULLP; @@ -420,136 +423,125 @@ S16 sctpSockPoll() } memInfo.region = CU_APP_MEM_REG; memInfo.pool = CU_POOL; - CM_INET_FD_ZERO(&readFd); + + CM_INET_FD_ZERO(&f1PollParams.readFd); while(1) { - CM_INET_FD_SET(&sockFd, &readFd); - ret = cmInetSelect(&readFd, NULLP, timeoutPtr, &numFds); - if (CM_INET_FD_ISSET(&sockFd, &readFd)) + if((ret = processPolling(&f1PollParams, &f1Params.sockFd, timeoutPtr, &memInfo)) != ROK) { - CM_INET_FD_CLR(&sockFd, &readFd); - ret = cmInetSctpRecvMsg(&sockFd, &addr, &port, &memInfo, &mBuf, &bufLen, &info, &flag, &ntfy); - if (ret != ROK) - { - printf("\nFailed to receive sctp msg\n"); - } - else - { - if ((flag & CM_INET_SCTP_MSG_NOTIFICATION) != 0) - { - ret = sctpNtfyHdlr(&ntfy); - if(ret != ROK) - { - printf("\nFailed to process sctp notify msg\n"); - } - } - else if(connUp) /* If data received */ - { - F1InmsgHdlr(mBuf); - SPutMsg(mBuf); - } - else - { - SPutMsg(mBuf); - } - } + DU_LOG("\nSCTP : Failed to RecvMsg for F1 at CU\n"); } - }; - RETVALUE(ROK); + /* Receiving EGTP data */ + egtpBufLen = -1; + ret = cmInetRecvMsg(&(egtpCb.recvTptSrvr.sockFd), &egtpFromAddr, &memInfo, &egtpBuf, &egtpBufLen, CM_INET_NO_FLAG); + if(ret == ROK && egtpBuf != NULLP) + { + DU_LOG("\nEGTP : Received message \n"); + ODU_PRINT_MSG(egtpBuf, 0 ,0); + cuEgtpHdlRecvMsg(egtpBuf); + + } + }; + return (ret); }/* End of sctpSockPoll() */ /******************************************************************* * - * @brief Send message on SCTP socket + * @brief checks for valid readFd and process the InetSctpRecvMsg + * during polling * * @details * - * Function : sctpOutMsgSend + * Function : processPolling * * Functionality: - * Send message on SCTP socket + * checks for valid readFd and process the InetSctpRecvMsg + * during polling + * + * @params[in] Params required for polling + * @params[in] SockFd for file descriptor + * @params[in] timeoutPtr indicates the timeout value + * @params[in] MemInfo indicates memory region * - * @params[in] * @return ROK - success * RFAILED - failure * * ****************************************************************/ -S16 sctpOutMsgSend(Buffer *mBuf) -{ - U8 ret; - MsgLen len; /* number of actually sent octets */ - CmInetNetAddr peerAddr; /* destination port address */ - CmInetNetAddr *dstAddr; - CmInetMemInfo memInfo; - - memInfo.region = CU_APP_MEM_REG; - memInfo.pool = CU_POOL; - - if(sctpCfg->duIpAddr.ipV4Pres) - { - peerAddr.type = CM_INET_IPV4ADDR_TYPE; - peerAddr.u.ipv4NetAddr = CM_INET_NTOH_U32(sctpCfg->duIpAddr.ipV4Addr); - dstAddr = &peerAddr; - } - else if(sctpCfg->duIpAddr.ipV6Pres) - { - peerAddr.type = CM_INET_IPV6ADDR_TYPE; - //CM_INET_COPY_IPV6ADDR(&(primDstAddr.u.ipv6NetAddr),&(sctpCfg->duIpAddr.ipV6Addr); - dstAddr = &peerAddr; - } - else - { - dstAddr = NULLP; - } - - ret = cmInetSctpSendMsg(&sockFd, dstAddr, sctpCfg->duPort, &memInfo, mBuf, &len, 0, FALSE, 0, 0/*SCT_PROTID_NONE*/, RWOULDBLOCK); - if(ret != ROK && ret != RWOULDBLOCK) +S16 processPolling(sctpSockPollParams *pollParams, CmInetFd *sockFd, uint32_t *timeoutPtr, CmInetMemInfo *memInfo) +{ + uint16_t ret = ROK; + CM_INET_FD_SET(sockFd, &pollParams->readFd); + ret = cmInetSelect(&pollParams->readFd, NULLP, timeoutPtr, &pollParams->numFd); + if(CM_INET_FD_ISSET(sockFd, &pollParams->readFd)) { - printf("\nFailed sending the message"); - RETVALUE(RFAILED); - } - - RETVALUE(ROK); -} /* End of sctpOutMsgSend */ + CM_INET_FD_CLR(sockFd, &pollParams->readFd); + ret = cmInetSctpRecvMsg(sockFd, &pollParams->addr, &pollParams->port, memInfo, &pollParams->mBuf, &pollParams->bufLen, &pollParams->info, &pollParams->flag, &pollParams->ntfy); + if(connUp & (ret != ROK)) + { + f1Params.bReadFdSet = RFAILED; + } + else + { + if(((pollParams->flag & CM_INET_SCTP_MSG_NOTIFICATION) != 0) && (ret == ROK)) + { + ret = sctpNtfyHdlr(&pollParams->ntfy); + if(ret != ROK) + { + DU_LOG("\nSCTP : Failed to process sctp notify msg\n"); + } + } + else if(connUp & (pollParams->port == f1Params.destPort)) + { + F1APMsgHdlr(pollParams->mBuf); + ODU_PUT_MSG_BUF(pollParams->mBuf); + } + else + { + ODU_PUT_MSG_BUF(pollParams->mBuf); + } + } + } + return ROK; +}/* End of sctpSockPoll() */ /******************************************************************* * - * @brief Start SCTP at CU + * @brief Send message on SCTP socket * * @details * - * Function : sctpStartReq + * Function : sctpSend * * Functionality: - * Start SCTP at CU + * Send message on SCTP socket * - * @params[in] + * @params[in] * @return ROK - success * RFAILED - failure * * ****************************************************************/ -void sctpStartReq() +S16 sctpSend(Buffer *mBuf) { - if(openSctpEndp() != ROK) - { - printf("\nFailed while opening socket"); - } - else if(bindSctpEndp() != ROK) - { - printf("\nFailed while binding socket"); - } - else if(sctpAccept() != ROK) - { - printf("\nFailed while accepting connection"); - } - else if(sctpSockPoll() != ROK) + uint8_t ret; + MsgLen len; /* number of actually sent octets */ + CmInetMemInfo memInfo; + + memInfo.region = CU_APP_MEM_REG; + memInfo.pool = CU_POOL; + + ret = cmInetSctpSendMsg(&f1Params.sockFd, &f1Params.destIpNetAddr, f1Params.destPort, &memInfo, mBuf, &len, 0, FALSE, 0, 0/*SCT_PROTID_NONE*/, RWOULDBLOCK); + + if(ret != ROK && ret != RWOULDBLOCK) { - printf("\nFailed while polling"); + DU_LOG("\nSCTP : Send message failed"); + return RFAILED; } -} /* End of sctpAssocReq */ + + return ROK; +} /* End of sctpSend */ /********************************************************************** End of file