X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=blobdiff_plain;f=src%2Fcu_stub%2Fcu_stub_sctp.c;h=c74290a22b4a31fcfc98cc80f97ffb2255bf09ec;hb=0ba7b600f85b2975e1d60e5b8ad1523349b5f396;hp=452e318641da677e603b972b473fe33d2529294f;hpb=834004e09017b5b86cb738be98a7a1be79c0a9b0;p=o-du%2Fl2.git diff --git a/src/cu_stub/cu_stub_sctp.c b/src/cu_stub/cu_stub_sctp.c index 452e31864..c74290a22 100644 --- a/src/cu_stub/cu_stub_sctp.c +++ b/src/cu_stub/cu_stub_sctp.c @@ -19,12 +19,18 @@ /* This file contains all SCTP related functionality */ #include "common_def.h" +#include "OCTET_STRING.h" #include "cu_f1ap_msg_hdl.h" #include "cu_stub_sctp.h" #include "cu_stub_egtp.h" -#include "du_log.h" +#include "cu_stub.h" +#include "cm_inet.h" +#include "cm_tpt.h" + +#include "cm_inet.x" +#include "cm_tpt.x" + -CuSctpDestCb f1Params; /************************************************************************** * @brief Task Initiation callback function. * @@ -45,15 +51,12 @@ CuSctpDestCb f1Params; * @return ROK - success * RFAILED - failure ***************************************************************************/ -S16 sctpActvInit() +uint8_t sctpActvInit() { DU_LOG("\n\nDEBUG --> SCTP : Initializing"); - connUp = FALSE; - assocId = 0; - nonblocking = FALSE; - sctpCfg = cuCfgParams.sctpParams; + memset(&sctpCb, 0, sizeof(SctpGlobalCb)); + sctpCb.sctpCfg = cuCb.cuCfgParams.sctpParams; return ROK; - } /************************************************************************** @@ -75,7 +78,7 @@ S16 sctpActvInit() * RFAILED - failure * ***************************************************************************/ -S16 sctpActvTsk(Pst *pst, Buffer *mBuf) +uint8_t sctpActvTsk(Pst *pst, Buffer *mBuf) { //TODO: TBD @@ -97,17 +100,21 @@ S16 sctpActvTsk(Pst *pst, Buffer *mBuf) * ***************************************************************************/ -S16 sctpCfgReq() +uint8_t 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); - + int destIdx; + + for(destIdx=0; destIdx < sctpCb.sctpCfg.numDu; destIdx++) + { + sctpCb.destCb[destIdx].destPort = sctpCb.sctpCfg.sctpAssoc[destIdx].duPort; + sctpCb.destCb[destIdx].srcPort = sctpCb.sctpCfg.sctpAssoc[destIdx].cuPort; + sctpCb.destCb[destIdx].bReadFdSet = ROK; + memset(&sctpCb.destCb[destIdx].sockFd, -1, sizeof(CmInetFd)); + memset(&sctpCb.destCb[destIdx].lstnSockFd, -1, sizeof(CmInetFd)); + fillDestNetAddr(&sctpCb.destCb[destIdx].destIpNetAddr, &sctpCb.sctpCfg.sctpAssoc[destIdx].duIpAddr); + fillAddrLst(&sctpCb.destCb[destIdx].localAddrLst, &sctpCb.sctpCfg.sctpAssoc[destIdx].cuIpAddr); + } + sctpCb.numDu = sctpCb.sctpCfg.numDu; return ROK; } @@ -130,12 +137,11 @@ S16 sctpCfgReq() * ******************************************************************/ -S16 fillAddrLst(CmInetNetAddrLst *addrLstPtr, SctpIpAddr *ipAddr) +uint8_t fillAddrLst(CmInetNetAddrLst *addrLstPtr, SctpIpAddr *ipAddr) { + addrLstPtr->addrs[addrLstPtr->count].type = CM_INET_IPV4ADDR_TYPE; + addrLstPtr->addrs[addrLstPtr->count].u.ipv4NetAddr = CM_INET_NTOH_UINT32(ipAddr->ipV4Addr); 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; } @@ -156,7 +162,7 @@ S16 fillAddrLst(CmInetNetAddrLst *addrLstPtr, SctpIpAddr *ipAddr) * RFAILED - failure * *******************************************************************************/ -S16 fillDestNetAddr(CmInetNetAddr *destAddrPtr, SctpIpAddr *dstIpPtr) +uint8_t fillDestNetAddr(CmInetNetAddr *destAddrPtr, SctpIpAddr *dstIpPtr) { /* Filling destination address */ destAddrPtr->type = CM_INET_IPV4ADDR_TYPE; @@ -181,25 +187,30 @@ S16 fillDestNetAddr(CmInetNetAddr *destAddrPtr, SctpIpAddr *dstIpPtr) * *******************************************************************************/ -S16 sctpStartReq() +uint8_t sctpStartReq() { - S16 ret = ROK; - socket_type = CM_INET_STREAM; - fillAddrLst(&f1Params.localAddrLst, &sctpCfg.cuIpAddr); + uint8_t destIdx; + uint8_t ret = ROK; - if((ret = cmInetSocket(socket_type, &f1Params.lstnSockFd, IPPROTO_SCTP) != ROK)) - { - DU_LOG("\nERROR --> SCTP : Socket[%d] coudnt open for listening", f1Params.lstnSockFd.fd); - } - else if((ret = cmInetSctpBindx(&f1Params.lstnSockFd, &f1Params.localAddrLst, f1Params.srcPort)) != ROK) - { - DU_LOG("\nERROR --> SCTP: Binding failed at CU"); - } - else if((ret = sctpAccept(&f1Params.lstnSockFd, &f1Params.peerAddr, &f1Params.sockFd)) != ROK) + socket_type = CM_INET_STREAM; + for(destIdx=0; destIdx < sctpCb.numDu; destIdx++) { - DU_LOG("\nERROR --> SCTP: Unable to accept the connection at CU"); + if((ret = cmInetSocket(socket_type, &sctpCb.destCb[destIdx].lstnSockFd, IPPROTO_SCTP) != ROK)) + { + DU_LOG("\nERROR --> SCTP : Socket[%d] coudnt open for listening", sctpCb.destCb[destIdx].lstnSockFd.fd); + } + else if((ret = cmInetSctpBindx(&sctpCb.destCb[destIdx].lstnSockFd, &sctpCb.destCb[destIdx].localAddrLst, \ + sctpCb.destCb[destIdx].srcPort)) != ROK) + { + DU_LOG("\nERROR --> SCTP: Binding failed at CU"); + } + else if((ret = sctpAccept(&sctpCb.destCb[destIdx])) != ROK) + { + DU_LOG("\nERROR --> SCTP: Unable to accept the connection at CU"); + } } - else if(sctpSockPoll() != ROK) + + if(sctpSockPoll() != ROK) { DU_LOG("\nERROR --> SCTP: Polling failed to start at CU"); } @@ -221,7 +232,7 @@ S16 sctpStartReq() * RFAILED - failure * * ****************************************************************/ -S16 sctpSetSockOpts(CmInetFd *sock_Fd) +uint8_t sctpSetSockOpts(CmInetFd *sock_Fd) { S16 ret = ROK; CmSctpEvent sctpEvent; @@ -260,23 +271,23 @@ S16 sctpSetSockOpts(CmInetFd *sock_Fd) * RFAILED - failure * * ****************************************************************/ -S16 sctpAccept(CmInetFd *lstnSock_Fd, CmInetAddr *peerAddr, CmInetFd *sock_Fd) +uint8_t sctpAccept(CuSctpDestCb *destCb) { uint8_t ret; - ret = cmInetListen(lstnSock_Fd, 1); + ret = cmInetListen(&destCb->lstnSockFd, 1); if (ret != ROK) { DU_LOG("\nERROR --> SCTP : Listening on socket failed"); - cmInetClose(lstnSock_Fd); + cmInetClose(&destCb->lstnSockFd); return RFAILED; } DU_LOG("\nINFO --> SCTP : Connecting"); - while(!connUp) + while(!destCb->connUp) { - ret = cmInetAccept(lstnSock_Fd, peerAddr, sock_Fd); + ret = cmInetAccept(&destCb->lstnSockFd, &destCb->peerAddr, &destCb->sockFd); if (ret == ROKDNA) { continue; @@ -288,8 +299,8 @@ S16 sctpAccept(CmInetFd *lstnSock_Fd, CmInetAddr *peerAddr, CmInetFd *sock_Fd) } else { - connUp = TRUE; - sctpSetSockOpts(sock_Fd); + destCb->connUp = TRUE; + sctpSetSockOpts(&destCb->sockFd); break; } } @@ -315,7 +326,7 @@ S16 sctpAccept(CmInetFd *lstnSock_Fd, CmInetAddr *peerAddr, CmInetFd *sock_Fd) * RFAILED - failure * * ****************************************************************/ -S16 sctpNtfyHdlr(CmInetSctpNotification *ntfy) +uint8_t sctpNtfyHdlr(CuSctpDestCb *destCb, CmInetSctpNotification *ntfy) { switch(ntfy->header.nType) { @@ -325,23 +336,23 @@ S16 sctpNtfyHdlr(CmInetSctpNotification *ntfy) { case CM_INET_SCTP_COMM_UP: DU_LOG("DEBUG --> Event : COMMUNICATION UP"); - connUp = TRUE; + destCb->connUp = TRUE; break; case CM_INET_SCTP_COMM_LOST: DU_LOG("DEBUG --> Event : COMMUNICATION LOST"); - connUp = FALSE; + destCb->connUp = FALSE; break; case CM_INET_SCTP_RESTART: DU_LOG("DEBUG --> Event : SCTP RESTART"); - connUp = FALSE; + destCb->connUp = FALSE; break; case CM_INET_SCTP_SHUTDOWN_COMP: /* association gracefully shutdown */ DU_LOG("DEBUG --> Event : SHUTDOWN COMPLETE"); - connUp = FALSE; + destCb->connUp = FALSE; break; case CM_INET_SCTP_CANT_STR_ASSOC: DU_LOG("DEBUG --> Event : CANT START ASSOC"); - connUp = FALSE; + destCb->connUp = FALSE; break; default: DU_LOG("\nERROR --> Invalid event"); @@ -360,7 +371,7 @@ S16 sctpNtfyHdlr(CmInetSctpNotification *ntfy) break; case CM_INET_SCTP_SHUTDOWN_EVENT : /* peer socket gracefully closed */ DU_LOG("\nINFO --> SCTP : Shutdown Event notification received\n"); - connUp = FALSE; + destCb->connUp = FALSE; exit(0); break; case CM_INET_SCTP_ADAPTATION_INDICATION : @@ -394,8 +405,9 @@ S16 sctpNtfyHdlr(CmInetSctpNotification *ntfy) * RFAILED - failure * * ****************************************************************/ -S16 sctpSockPoll() +uint8_t sctpSockPoll() { + uint8_t destIdx; uint16_t ret = ROK; uint32_t timeout; uint32_t *timeoutPtr; @@ -404,23 +416,14 @@ S16 sctpSockPoll() CmInetAddr egtpFromAddr; CmInetMemInfo memInfo; sctpSockPollParams f1PollParams; + uint64_t numMsgRcvd = 0; memset(&f1PollParams, 0, sizeof(sctpSockPollParams)); - egtpFromAddr.port = egtpCb.dstCb.dstPort; - egtpFromAddr.address = egtpCb.dstCb.dstIp; - if(f1Params.sockFd.blocking) - { - /* blocking */ - timeoutPtr = NULLP; - } - else - { - /* non-blocking */ - timeout = 0; - timeoutPtr = &timeout; - } + /* All sockets are non-blocking */ + timeout = 0; + timeoutPtr = &timeout; memInfo.region = CU_APP_MEM_REG; memInfo.pool = CU_POOL; @@ -428,20 +431,31 @@ S16 sctpSockPoll() while(1) { - if((ret = processPolling(&f1PollParams, &f1Params.sockFd, timeoutPtr, &memInfo)) != ROK) + /* Receiving SCTP data */ + for(destIdx = 0; destIdx < sctpCb.numDu; destIdx++) { - DU_LOG("\nERROR --> SCTP : Failed to RecvMsg for F1 at CU\n"); + if((ret = processPolling(&f1PollParams, &sctpCb.destCb[destIdx], timeoutPtr, &memInfo)) != ROK) + { + DU_LOG("\nERROR --> SCTP : Failed to RecvMsg for F1 at CU\n"); + } } /* Receiving EGTP data */ - egtpBufLen = -1; - ret = cmInetRecvMsg(&(egtpCb.recvTptSrvr.sockFd), &egtpFromAddr, &memInfo, &egtpBuf, &egtpBufLen, CM_INET_NO_FLAG); - if(ret == ROK && egtpBuf != NULLP) + for(destIdx = 0; destIdx < egtpCb.numDu; destIdx++) { - DU_LOG("\nINFO --> EGTP : Received message \n"); - ODU_PRINT_MSG(egtpBuf, 0 ,0); - cuEgtpHdlRecvMsg(egtpBuf); + + egtpFromAddr.port = egtpCb.dstCb[destIdx].dstPort; + egtpFromAddr.address = egtpCb.dstCb[destIdx].dstIp; + egtpBufLen = -1; + ret = cmInetRecvMsg(&(egtpCb.recvTptSrvr.sockFd), &egtpFromAddr, &memInfo, &egtpBuf, &egtpBufLen, CM_INET_NO_FLAG); + if(ret == ROK && egtpBuf != NULLP) + { + DU_LOG("\nINFO --> EGTP : Received UL Message [%ld] from DUid %d\n", numMsgRcvd+1, egtpCb.dstCb[destIdx].duId); + numMsgRcvd++; + //ODU_PRINT_MSG(egtpBuf, 0 ,0); + cuEgtpHdlRecvMsg(egtpBuf); + } } }; return (ret); @@ -470,32 +484,33 @@ S16 sctpSockPoll() * * ****************************************************************/ -S16 processPolling(sctpSockPollParams *pollParams, CmInetFd *sockFd, uint32_t *timeoutPtr, CmInetMemInfo *memInfo) +uint8_t processPolling(sctpSockPollParams *pollParams, CuSctpDestCb *destCb, uint32_t *timeoutPtr, CmInetMemInfo *memInfo) { uint16_t ret = ROK; - CM_INET_FD_SET(sockFd, &pollParams->readFd); + CM_INET_FD_SET(&destCb->sockFd, &pollParams->readFd); ret = cmInetSelect(&pollParams->readFd, NULLP, timeoutPtr, &pollParams->numFd); - if(CM_INET_FD_ISSET(sockFd, &pollParams->readFd)) + if(CM_INET_FD_ISSET(&destCb->sockFd, &pollParams->readFd)) { - 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)) + CM_INET_FD_CLR(&destCb->sockFd, &pollParams->readFd); + ret = cmInetSctpRecvMsg(&destCb->sockFd, &pollParams->addr, &pollParams->port, memInfo, &pollParams->mBuf, \ + &pollParams->bufLen, &pollParams->info, &pollParams->flag, &pollParams->ntfy); + if(destCb->connUp & (ret != ROK)) { - f1Params.bReadFdSet = RFAILED; + destCb->bReadFdSet = RFAILED; } else { if(((pollParams->flag & CM_INET_SCTP_MSG_NOTIFICATION) != 0) && (ret == ROK)) { - ret = sctpNtfyHdlr(&pollParams->ntfy); + ret = sctpNtfyHdlr(destCb, &pollParams->ntfy); if(ret != ROK) { DU_LOG("\nERROR --> SCTP : Failed to process sctp notify msg\n"); } } - else if(connUp & (pollParams->port == f1Params.destPort)) + else if(destCb->connUp & (pollParams->port == destCb->destPort)) { - F1APMsgHdlr(pollParams->mBuf); + F1APMsgHdlr(&destCb->duId, pollParams->mBuf); ODU_PUT_MSG_BUF(pollParams->mBuf); } else @@ -523,24 +538,33 @@ S16 processPolling(sctpSockPollParams *pollParams, CmInetFd *sockFd, uint32_t *t * RFAILED - failure * * ****************************************************************/ -S16 sctpSend(Buffer *mBuf) +uint8_t sctpSend(uint32_t duId, Buffer *mBuf) { - uint8_t ret; - MsgLen len; /* number of actually sent octets */ + uint8_t ret = ROK, destIdx = 0; + MsgLen len = 0; /* number of actually sent octets */ CmInetMemInfo memInfo; - + + memset(&memInfo , 0, sizeof(CmInetMemInfo)); 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) + for(destIdx=0; destIdx < sctpCb.numDu; destIdx++) { - DU_LOG("\nERROR --> SCTP : Send message failed"); - return RFAILED; - } + if(sctpCb.destCb[destIdx].duId == duId) + { + ret = cmInetSctpSendMsg(&sctpCb.destCb[destIdx].sockFd, &sctpCb.destCb[destIdx].destIpNetAddr, \ + sctpCb.destCb[destIdx].destPort, &memInfo, mBuf, &len, 0, FALSE, 0, 0/*SCT_PROTID_NONE*/, RWOULDBLOCK); - return ROK; + if(ret != ROK && ret != RWOULDBLOCK) + { + DU_LOG("\nERROR --> SCTP : Send message failed"); + return RFAILED; + } + return ROK; + } + } + DU_LOG("\nERROR --> SCTP : DU ID [%d] not found in SCTP DestCb list. Failed to send message", duId); + return RFAILED; } /* End of sctpSend */ /**********************************************************************