X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=blobdiff_plain;f=src%2Fcu_stub%2Fcu_stub_sctp.c;h=0a03f0d545779e68e63d3ed66d3f7ce827c7192d;hb=d6b8cf5c9afbba0fada62efd626d56cb59c1e839;hp=285414b8aa1bc3900a2e367ead24b52e8a16a652;hpb=6a921a2e24077727de299706bf23ceec317f1c5c;p=o-du%2Fl2.git diff --git a/src/cu_stub/cu_stub_sctp.c b/src/cu_stub/cu_stub_sctp.c index 285414b8a..0a03f0d54 100644 --- a/src/cu_stub/cu_stub_sctp.c +++ b/src/cu_stub/cu_stub_sctp.c @@ -107,12 +107,24 @@ uint8_t sctpCfgReq() fillAddrLst(&sctpCb.localAddrLst, &sctpCb.sctpCfg.localIpAddr); memset(&sctpCb.f1LstnSockFd, -1, sizeof(CmInetFd)); - for(destIdx=0; destIdx < sctpCb.sctpCfg.numDestNode; destIdx++) + for(destIdx=0; destIdx < sctpCb.sctpCfg.f1SctpInfo.numDestNode; destIdx++) { - sctpCb.assocCb[assocIdx].destPort = sctpCb.sctpCfg.destCb[destIdx].destPort; + sctpCb.assocCb[assocIdx].intf = F1_INTERFACE; + sctpCb.assocCb[assocIdx].destPort = sctpCb.sctpCfg.f1SctpInfo.destCb[destIdx].destPort; sctpCb.assocCb[assocIdx].bReadFdSet = ROK; memset(&sctpCb.assocCb[assocIdx].sockFd, -1, sizeof(CmInetFd)); - fillDestNetAddr(&sctpCb.assocCb[assocIdx].destIpNetAddr, &sctpCb.sctpCfg.destCb[destIdx].destIpAddr); + fillDestNetAddr(&sctpCb.assocCb[assocIdx].destIpNetAddr, &sctpCb.sctpCfg.f1SctpInfo.destCb[destIdx].destIpAddr); + assocIdx++; + } + + sctpCb.localXnNodeType = sctpCb.sctpCfg.xnSctpInfo.localNodeType; + for(destIdx=0; destIdx < sctpCb.sctpCfg.xnSctpInfo.numDestNode; destIdx++) + { + sctpCb.assocCb[assocIdx].intf = XN_INTERFACE; + sctpCb.assocCb[assocIdx].destPort = sctpCb.sctpCfg.xnSctpInfo.destCb[destIdx].destPort; + sctpCb.assocCb[assocIdx].bReadFdSet = ROK; + memset(&sctpCb.assocCb[assocIdx].sockFd, -1, sizeof(CmInetFd)); + fillDestNetAddr(&sctpCb.assocCb[assocIdx].destIpNetAddr, &sctpCb.sctpCfg.xnSctpInfo.destCb[destIdx].destIpAddr); assocIdx++; } sctpCb.numAssoc = assocIdx; @@ -192,16 +204,92 @@ uint8_t sctpStartReq() { uint8_t assocIdx; uint8_t ret = ROK; + CmInetFd sockFd; socket_type = CM_INET_STREAM; - if(sctpCb.numAssoc) + /* Establish SCTP association at XN interface */ + if(sctpCb.sctpCfg.xnSctpInfo.numDestNode) + { + if(sctpCb.localXnNodeType == SERVER) + { + if((ret = cmInetSocket(socket_type, &sctpCb.xnLstnSockFd, IPPROTO_SCTP) != ROK)) + { + DU_LOG("\nERROR --> SCTP : Socket[%d] coudnt open for listening", sctpCb.f1LstnSockFd.fd); + } + else if((ret = cmInetSctpBindx(&sctpCb.xnLstnSockFd, &sctpCb.localAddrLst, sctpCb.sctpCfg.xnSctpInfo.port)) != ROK) + { + DU_LOG("\nERROR --> SCTP: Binding failed at CU"); + } + else if(ret = cmInetListen(&sctpCb.xnLstnSockFd, 1) != ROK) + { + DU_LOG("\nERROR --> SCTP : Listening on socket failed"); + cmInetClose(&sctpCb.xnLstnSockFd); + return RFAILED; + } + else + { + for(assocIdx=0; assocIdx < sctpCb.numAssoc; assocIdx++) + { + if(sctpCb.assocCb[assocIdx].intf == XN_INTERFACE) + { + if((ret = sctpAccept(&sctpCb.xnLstnSockFd, &sctpCb.assocCb[assocIdx])) != ROK) + { + DU_LOG("\nERROR --> SCTP: Unable to accept the connection at CU"); + } + } + } + } + } + else if(sctpCb.localXnNodeType == CLIENT) + { + for(assocIdx=0; assocIdx < sctpCb.numAssoc; assocIdx++) + { + if(sctpCb.assocCb[assocIdx].intf == XN_INTERFACE) + { + if((ret = cmInetSocket(socket_type, &sctpCb.assocCb[assocIdx].sockFd, IPPROTO_SCTP)) != ROK) + { + DU_LOG("\nERROR --> SCTP : Failed while opening a socket in ODU"); + } + else if((ret = cmInetSctpBindx(&sctpCb.assocCb[assocIdx].sockFd, &sctpCb.localAddrLst, sctpCb.sctpCfg.xnSctpInfo.port)) != ROK) + { + DU_LOG("\nERROR --> SCTP: Failed during Binding in ODU"); + } + else if((ret = sctpSetSockOpts(&sctpCb.assocCb[assocIdx].sockFd)) != ROK) + { + DU_LOG("\nERROR --> SCTP : Failed to set Socket Opt in ODU"); + } + else + { + if(ret != ROK) + { + DU_LOG("\nERROR --> SCTP : Failed while establishing Req at DU"); + ret = RFAILED; + } + else + { + ret = cmInetSctpConnectx(&sctpCb.assocCb[assocIdx].sockFd, &sctpCb.assocCb[assocIdx].destIpNetAddr, \ + &sctpCb.assocCb[assocIdx].destAddrLst, sctpCb.assocCb[assocIdx].destPort); + /* 115 error_code indicates that Operation is in progress and hence ignored if SctpConnect failed due to this */ + if(ret == 18) + { + ret = ROK; + } + } + } + } + } + } + } + + /* Establish SCTP association at F1 interface */ + if(sctpCb.sctpCfg.f1SctpInfo.numDestNode) { if((ret = cmInetSocket(socket_type, &sctpCb.f1LstnSockFd, IPPROTO_SCTP) != ROK)) { DU_LOG("\nERROR --> SCTP : Socket[%d] coudnt open for listening", sctpCb.f1LstnSockFd.fd); } - else if((ret = cmInetSctpBindx(&sctpCb.f1LstnSockFd, &sctpCb.localAddrLst, sctpCb.sctpCfg.f1SctpPort)) != ROK) + else if((ret = cmInetSctpBindx(&sctpCb.f1LstnSockFd, &sctpCb.localAddrLst, sctpCb.sctpCfg.f1SctpInfo.port)) != ROK) { DU_LOG("\nERROR --> SCTP: Binding failed at CU"); } @@ -215,9 +303,12 @@ uint8_t sctpStartReq() { for(assocIdx=0; assocIdx < sctpCb.numAssoc; assocIdx++) { - if((ret = sctpAccept(&sctpCb.assocCb[assocIdx])) != ROK) + if(sctpCb.assocCb[assocIdx].intf == F1_INTERFACE) { - DU_LOG("\nERROR --> SCTP: Unable to accept the connection at CU"); + if((ret = sctpAccept(&sctpCb.f1LstnSockFd, &sctpCb.assocCb[assocIdx])) != ROK) + { + DU_LOG("\nERROR --> SCTP: Unable to accept the connection at CU"); + } } } } @@ -232,6 +323,7 @@ uint8_t sctpStartReq() } return (ret); } + /******************************************************************* * * @brief Sets socket options as per requirement @@ -287,7 +379,7 @@ uint8_t sctpSetSockOpts(CmInetFd *sock_Fd) * RFAILED - failure * * ****************************************************************/ -uint8_t sctpAccept(CuSctpAssocCb *assocCb) +uint8_t sctpAccept(CmInetFd *lstnSockFd, CuSctpAssocCb *assocCb) { uint8_t ret; @@ -295,7 +387,7 @@ uint8_t sctpAccept(CuSctpAssocCb *assocCb) while(!assocCb->connUp) { - ret = cmInetAccept(&sctpCb.f1LstnSockFd, &assocCb->peerAddr, &assocCb->sockFd); + ret = cmInetAccept(lstnSockFd, &assocCb->peerAddr, &assocCb->sockFd); if (ret == ROKDNA) { continue; @@ -421,12 +513,12 @@ uint8_t sctpSockPoll() uint32_t *timeoutPtr; Buffer *egtpBuf; MsgLen egtpBufLen; - CmInetAddr egtpFromAddr; CmInetMemInfo memInfo; - sctpSockPollParams f1PollParams; + sctpSockPollParams pollParams; uint64_t numMsgRcvd = 0; + CmInetAddr fromAddr; - memset(&f1PollParams, 0, sizeof(sctpSockPollParams)); + memset(&pollParams, 0, sizeof(sctpSockPollParams)); /* All sockets are non-blocking */ @@ -435,33 +527,34 @@ uint8_t sctpSockPoll() memInfo.region = CU_APP_MEM_REG; memInfo.pool = CU_POOL; - CM_INET_FD_ZERO(&f1PollParams.readFd); + CM_INET_FD_ZERO(&pollParams.readFd); while(1) { /* Receiving SCTP data */ for(assocIdx = 0; assocIdx < sctpCb.numAssoc; assocIdx++) { - if((ret = processPolling(&f1PollParams, &sctpCb.assocCb[assocIdx], timeoutPtr, &memInfo)) != ROK) + if((ret = processPolling(&pollParams, &sctpCb.assocCb[assocIdx], timeoutPtr, &memInfo)) != ROK) { DU_LOG("\nERROR --> SCTP : Failed to RecvMsg for F1 at CU\n"); } } /* Receiving EGTP data */ - for(destIdx = 0; destIdx < egtpCb.numDu; destIdx++) + egtpBufLen = -1; + ret = cmInetRecvMsg(&(egtpCb.sockFd), &fromAddr, &memInfo, &egtpBuf, &egtpBufLen, CM_INET_NO_FLAG); + if(ret == ROK && egtpBuf != NULLP) { - - 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) + for(destIdx = 0; destIdx < egtpCb.numDu; destIdx++) { - 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); + if((fromAddr.port == egtpCb.dstCb[destIdx].dstAddr.port) && (fromAddr.address == egtpCb.dstCb[destIdx].dstAddr.address)) + { + DU_LOG("\nINFO --> EGTP : Received UL Message [%ld] from DU Id [%d]\n", numMsgRcvd+1, egtpCb.dstCb[destIdx].duId); + numMsgRcvd++; + //ODU_PRINT_MSG(egtpBuf, 0 ,0); + cuEgtpHdlRecvMsg(egtpBuf); + break; + } } } @@ -516,9 +609,16 @@ uint8_t processPolling(sctpSockPollParams *pollParams, CuSctpAssocCb *assocCb, u DU_LOG("\nERROR --> SCTP : Failed to process sctp notify msg\n"); } } - else if(assocCb->connUp) + else if(assocCb->connUp && assocCb->intf == F1_INTERFACE) { - F1APMsgHdlr(&assocCb->duId, pollParams->mBuf); + F1APMsgHdlr(&assocCb->destId, pollParams->mBuf); + ODU_PUT_MSG_BUF(pollParams->mBuf); + } + else if(assocCb->connUp && assocCb->intf == XN_INTERFACE) + { + DU_LOG("\nDEBUG --> SCTP : Received message at XN interface"); + ODU_PRINT_MSG(pollParams->mBuf, 0,0); + XNAPMsgHdlr(&assocCb->destId, pollParams->mBuf); ODU_PUT_MSG_BUF(pollParams->mBuf); } else @@ -532,46 +632,72 @@ uint8_t processPolling(sctpSockPollParams *pollParams, CuSctpAssocCb *assocCb, u /******************************************************************* * - * @brief Send message on SCTP socket + * @brief Send message on an SCTP Association * * @details * - * Function : sctpSend + * Function : sendOnSctpAssoc * * Functionality: - * Send message on SCTP socket + * Send message on SCTP association * * @params[in] * @return ROK - success * RFAILED - failure * * ****************************************************************/ -uint8_t sctpSend(uint32_t duId, Buffer *mBuf) +uint8_t sendOnSctpAssoc(CuSctpAssocCb *assocCb, Buffer *mBuf) { - uint8_t ret = ROK, assocIdx = 0; + uint8_t ret = ROK; MsgLen len = 0; /* number of actually sent octets */ - CmInetMemInfo memInfo; - + CmInetMemInfo memInfo; + memset(&memInfo , 0, sizeof(CmInetMemInfo)); - memInfo.region = CU_APP_MEM_REG; + memInfo.region = CU_APP_MEM_REG; memInfo.pool = CU_POOL; + ret = cmInetSctpSendMsg(&assocCb->sockFd, &assocCb->destIpNetAddr, assocCb->destPort, &memInfo, mBuf, &len, 0, \ + FALSE, 0, 0/*SCT_PROTID_NONE*/, RWOULDBLOCK); + + if(ret != ROK && ret != RWOULDBLOCK) + { + DU_LOG("\nERROR --> SCTP : Send message failed"); + return RFAILED; + } + return ROK; +} + +/******************************************************************* + * + * @brief Send message on SCTP socket + * + * @details + * + * Function : sctpSend + * + * Functionality: + * Send message on SCTP socket + * + * @params[in] + * @return ROK - success + * RFAILED - failure + * + * ****************************************************************/ +uint8_t sctpSend(InterfaceType intf, uint32_t destId, Buffer *mBuf) +{ + uint8_t assocIdx = 0; + for(assocIdx=0; assocIdx < sctpCb.numAssoc; assocIdx++) { - if(sctpCb.assocCb[assocIdx].duId == duId) + if((sctpCb.assocCb[assocIdx].intf == intf) && (sctpCb.assocCb[assocIdx].destId == destId)) { - ret = cmInetSctpSendMsg(&sctpCb.assocCb[assocIdx].sockFd, &sctpCb.assocCb[assocIdx].destIpNetAddr, \ - sctpCb.assocCb[assocIdx].destPort, &memInfo, mBuf, &len, 0, FALSE, 0, 0/*SCT_PROTID_NONE*/, RWOULDBLOCK); - - if(ret != ROK && ret != RWOULDBLOCK) - { - DU_LOG("\nERROR --> SCTP : Send message failed"); - return RFAILED; - } - return ROK; + if(sendOnSctpAssoc(&sctpCb.assocCb[assocIdx], mBuf) == ROK) + return ROK; + else + break; } } - DU_LOG("\nERROR --> SCTP : DU ID [%d] not found in SCTP DestCb list. Failed to send message", duId); + DU_LOG("\nERROR --> SCTP : Dest ID [%d] at Interface [%d] not found in SCTP DestCb list. Failed to send message", destId, intf); return RFAILED; } /* End of sctpSend */