[Epic-ID: ODUHIGH-405][Task-ID: ODUHIGH-434] EGTP connection towards multiple DUs...
[o-du/l2.git] / src / cu_stub / cu_stub_sctp.c
index 66ec535..c74290a 100644 (file)
@@ -55,7 +55,7 @@ uint8_t sctpActvInit()
 {
    DU_LOG("\n\nDEBUG  -->  SCTP : Initializing");
    memset(&sctpCb, 0, sizeof(SctpGlobalCb));
-   sctpCb.sctpCfg = cuCfgParams.sctpParams;
+   sctpCb.sctpCfg = cuCb.cuCfgParams.sctpParams;
    return ROK;
 }
 
@@ -420,8 +420,6 @@ uint8_t sctpSockPoll()
 
    memset(&f1PollParams, 0, sizeof(sctpSockPollParams));
     
-   egtpFromAddr.port = egtpCb.dstCb.dstPort;
-   egtpFromAddr.address = egtpCb.dstCb.dstIp;
 
    /* All sockets are non-blocking */
    timeout = 0;
@@ -443,15 +441,21 @@ uint8_t sctpSockPoll()
       }
 
       /* 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 UL Message [%ld]\n", numMsgRcvd+1);
-         numMsgRcvd++;
-         //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);
@@ -506,7 +510,7 @@ uint8_t processPolling(sctpSockPollParams *pollParams, CuSctpDestCb *destCb, uin
          }
          else if(destCb->connUp & (pollParams->port == destCb->destPort))
          {  
-            F1APMsgHdlr(pollParams->mBuf);
+            F1APMsgHdlr(&destCb->duId, pollParams->mBuf);
             ODU_PUT_MSG_BUF(pollParams->mBuf);
          }
          else
@@ -534,9 +538,9 @@ uint8_t processPolling(sctpSockPollParams *pollParams, CuSctpDestCb *destCb, uin
  *         RFAILED - failure
  *
  * ****************************************************************/
-uint8_t sctpSend(Buffer *mBuf)
+uint8_t sctpSend(uint32_t duId, Buffer *mBuf)
 {
-   uint8_t          ret = ROK;
+   uint8_t          ret = ROK, destIdx = 0;
    MsgLen           len = 0;          /* number of actually sent octets */
    CmInetMemInfo    memInfo;                        
   
@@ -544,16 +548,23 @@ uint8_t sctpSend(Buffer *mBuf)
    memInfo.region = CU_APP_MEM_REG;               
    memInfo.pool   = CU_POOL;
 
-   ret = cmInetSctpSendMsg(&sctpCb.destCb[0].sockFd, &sctpCb.destCb[0].destIpNetAddr, sctpCb.destCb[0].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 */
 
 /**********************************************************************