[Epic-Id: ODUHIGH-576][Task-Id: ODUHIGH-594][SubTask-Id: ODUHIGH-609]|[NFAPI_BRANCH... 29/13029/3
authorsvaidhya <svaidhya@radisys.com>
Wed, 26 Jun 2024 12:02:50 +0000 (17:32 +0530)
committersvaidhya <svaidhya@radisys.com>
Tue, 2 Jul 2024 06:49:15 +0000 (12:19 +0530)
Change-Id: I036e6719e61245a49661e9f1f4bb8bd77120b77b
Signed-off-by: svaidhya <svaidhya@radisys.com>
src/5gnrmac/nfapi_common.h
src/5gnrmac/nfapi_p7_clk.c
src/5gnrmac/nfapi_p7_msg_hdl.c
src/5gnrmac/nfapi_p7_msg_hdl.h
src/5gnrmac/nfapi_udp_p7.c
src/5gnrmac/nfapi_vnf_fsm.h
src/pnf_stub/pnf_stub.h
src/pnf_stub/pnf_stub_p7_msg_hdl.c
src/pnf_stub/pnf_stub_sctp.c

index 6642fc5..c5c4bf2 100644 (file)
 
 #define CALC_TIME_USEC_FROM_SFNSLOT(_frameInfo) (_frameInfo.sfn * 10000) + (_frameInfo.slot * PER_TTI_TIME_USEC)
 
+#define EXTRACT_SFN_SLOT_FROM_TIME(_t, _frameInfo)  \
+{                                                   \
+   unsigned int time;                                      \
+   time = _t / PER_TTI_TIME_USEC;                   \
+   _frameInfo.sfn = time / NUM_SLOTS_PER_SUBFRAME;  \
+   _frameInfo.slot = time % NUM_SLOTS_PER_SUBFRAME; \
+}
+
+/*_cmpStatus: -1 when CurrTime is ahead and vice-versa */
+#define CMP_INFO(_t1, _currTime, _cmpStatus) \
+{                                                             \
+   uint32_t t1Val = (_t1.sfn * NUM_SLOTS_PER_SUBFRAME) + _t1.slot; \
+   uint32_t currTimeVal = (_currTime.sfn * NUM_SLOTS_PER_SUBFRAME) + _currTime.slot; \
+   uint32_t halfCycle = (1024 * NUM_SLOTS_PER_SUBFRAME) / 2;  \
+   if( t1Val == currTimeVal)                                  \
+   {                                                          \
+      _cmpStatus = 0;                                         \
+   }                                                          \
+   else                                                       \
+   {                                                          \
+       if(t1Val > currTimeVal)                                       \
+       {                                                             \
+         _cmpStatus = ((t1Val - currTimeVal) > halfCycle) ? 1 : -1;  \
+       }                                                             \
+       else                                                          \
+       {                                                             \
+         _cmpStatus = ((currTimeVal - t1Val) > halfCycle) ? -1 : 1;  \
+       }                                                             \
+   }                                                                 \
+}
+
+#define CALC_TIME_DIFF(_t1, _t2, _numSlots)                                                     \
+{                                                                                               \
+   if((_t1.sfn * NUM_SLOTS_PER_SUBFRAME + _t1.slot)                                             \
+           >= (_t2.sfn * NUM_SLOTS_PER_SUBFRAME + _t2.slot))                                    \
+   {                                                                                            \
+      _numSlots = (_t1.sfn * NUM_SLOTS_PER_SUBFRAME + _t1.slot) -                               \
+                          (_t2.sfn * NUM_SLOTS_PER_SUBFRAME + _t2.slot);                        \
+       printf("\n t1 > t2,(%d, %d) ",(_t1.sfn * NUM_SLOTS_PER_SUBFRAME + _t1.slot),(_t2.sfn * NUM_SLOTS_PER_SUBFRAME + _t2.slot));\
+   }                                                                                            \
+   else                                                                                         \
+   {                                                                                            \
+      _numSlots = (_t1.sfn * NUM_SLOTS_PER_SUBFRAME + _t1.slot) +                               \
+                 ((1024 * NUM_SLOTS_PER_SUBFRAME) - (_t2.sfn*NUM_SLOTS_PER_SUBFRAME+_t2.slot)); \
+       printf("\n t1 < t2,(%d, %d) ",(_t1.sfn * NUM_SLOTS_PER_SUBFRAME + _t1.slot),((1024 * NUM_SLOTS_PER_SUBFRAME) - (_t2.sfn * NUM_SLOTS_PER_SUBFRAME + _t2.slot)));\
+   }                                                                                            \
+   printf("\n numSLots:%d", _numSlots);\
+}
+
 /*Global Variable*/
 uint32_t PER_TTI_TIME_USEC;
 uint8_t  NUM_SLOTS_PER_SUBFRAME;
@@ -160,6 +209,7 @@ void nfapiFillP5Hdr(Buffer *mBuf);
 void nfapiFillMsgHdr(Buffer *mBuf, uint8_t phyId, uint16_t msgId, uint32_t msglen);
 void nfapiFillP7Hdr(Buffer *mBuf,uint32_t totSduLen, uint32_t byteOffset, uint32_t time);
 void nFapiExtractP5Hdr(nFapi_p5_hdr *p5Hdr, Buffer *mBuf);
+void nFapiExtractP7Hdr(nFapi_p7_hdr *p7Hdr, Buffer *mBuf);
 void nFapiExtractMsgHdr(nFapi_msg_header *msgHdr, Buffer *mBuf);
 
 uint8_t convertNfapiP5TagValToMsgId(uint16_t tagVal,  NfapiPnfEvent *nfapiPnfEvent, EventState *phyEvent);
index a9a4fa0..7b0f382 100644 (file)
@@ -179,7 +179,7 @@ void nfapiGenerateTicks()
       
          vnfDb.vnfP7Info.p7SyncInfo.frameInfo.sfn++;
          vnfDb.vnfP7Info.p7SyncInfo.frameInfo.slot++;
-         DU_LOG("\nVNF_NFAPI : Starting to generate slot indications t_ref:%llu, slotDur:%f, perTTi:%u, slotsPerFrame:%d, nanoSec:%d",\
+         DU_LOG("\nINFO  --> VNF_NFAPI : Starting to generate slot indications t_ref:%llu, slotDur:%f, perTTi:%u, slotsPerFrame:%d, nanoSec:%d",\
                vnfDb.vnfP7Info.t_ref_ns, slotDur_ms, PER_TTI_TIME_USEC, NUM_SLOTS_PER_SUBFRAME, tti_req.tv_nsec);
          nfapiBuildAndSendDlNodeSync(); 
       }
index a9855e8..b93de25 100644 (file)
@@ -48,7 +48,6 @@ extern NfapiVnfDb vnfDb;
 
 uint8_t nfapiBuildAndSendDlNodeSync()
 {
-   uint32_t t1 = 0; /*Offset from VNF SFN/Slot 0/0 to the DL Node Sync Tx*/
    uint8_t  scs = 0;
    Buffer   *mBuf = NULLP;
    
@@ -59,16 +58,166 @@ uint8_t nfapiBuildAndSendDlNodeSync()
    }
   
    
-   t1 = CALC_TIME_USEC_FROM_SFNSLOT(vnfDb.vnfP7Info.p7SyncInfo.frameInfo);
+   vnfDb.vnfP7Info.p7SyncInfo.prev_t1 = CALC_TIME_USEC_FROM_SFNSLOT(vnfDb.vnfP7Info.p7SyncInfo.frameInfo);
    scs = 15 * (pow(2, vnfDb.numerology));
   
    nfapiFillP7Hdr(mBuf,( sizeof(nFapi_dl_node_sync_info) + sizeof(nFapi_msg_header)), 0, 0);
    nfapiFillMsgHdr(mBuf, vnfDb.vnfP7Info.p7SyncInfo.phyId, TAG_NFAPI_DL_NODE_SYNC, sizeof(nFapi_dl_node_sync_info));
-   CMCHKPK(oduPackPostUInt32, t1, mBuf);
+   CMCHKPK(oduPackPostUInt32, vnfDb.vnfP7Info.p7SyncInfo.prev_t1, mBuf);
    CMCHKPK(SPkPostS32, vnfDb.vnfP7Info.p7SyncInfo.delta_sfn_slot, mBuf);
    CMCHKPK(oduPackPostUInt8, scs, mBuf);
 
+   memset(&vnfDb.vnfP7Info.p7SyncInfo.delta_sfn_slot, 0, sizeof(int32_t)); 
    return(nfapiP7UdpSendMsg(mBuf));
 }
 
+/*******************************************************************
+ *
+ * @brief Validating T1 received from PNF@ UL_NODE_SYNC
+ *
+ * @details
+ *
+ *    Function : nfapiValidatingT1
+ *
+ *    Functionality:
+ *           Matching the T1 received from UL Node Sync to validate that
+ *           correct UL Node Sync or not
+ *
+ * @params[in] T1 received from UL_NODE_SYNC
+ * @return ROK     - success
+ *         RFAILED - failure
+ *
+ * ****************************************************************/
+uint8_t nfapiValidatingT1(uint32_t ulNodeSyncT1)
+{
+   DU_LOG("\nDEBUG  --> NFAPI_VNF: t1@VNF:%u, t1_from_pnf:%u",\
+            vnfDb.vnfP7Info.p7SyncInfo.prev_t1, ulNodeSyncT1);
+   
+   if(vnfDb.vnfP7Info.p7SyncInfo.prev_t1 == ulNodeSyncT1)
+   {
+      DU_LOG("\nINFO   --> NFAPI_VNF: T1 matching so this UL Node Sync can be processed");
+      return ROK;
+   }
+   else
+   {
+      DU_LOG("\nERROR  --> NFAPI_VNF: Mismatch T1");
+      return RFAILED;
+   }
+}
+
+
+/*******************************************************************
+ *
+ * @brief Processes and handles UL_NODE_SYNC
+ *
+ * @details
+ *
+ *    Function : nfapiP7ProcUlNodeSync
+ *
+ *    Functionality:
+ *           Processes UL Node Sync and determine if VNF and PNF are in Sync
+ *           If in un-sync, calculate the slot difference.
+ *
+ * @params[in] Buffer *mBuf 
+ * @return ROK     - success
+ *         RFAILED - failure
+ *
+ * ****************************************************************/
+/*Following parameters can be referred to Table 4-2 Ul Node Sync Parameters*/
+uint8_t nfapiP7ProcUlNodeSync(Buffer *mBuf)
+{
+   int8_t                  cmpStatus = 0;
+   uint8_t                 ret = ROK;
+   uint16_t                numSlotDiff = 0;
+   NfapiFrameInfo          t3_sfnSlot;
+   nFapi_ul_node_sync_info ulNodeSyncInfo; 
+
+   CMCHKPK(oduUnpackUInt32, &(ulNodeSyncInfo.t1), mBuf);
+   CMCHKPK(oduUnpackUInt32, &(ulNodeSyncInfo.t2), mBuf);
+   CMCHKPK(oduUnpackUInt32, &(ulNodeSyncInfo.t3), mBuf);
+
+   if(nfapiValidatingT1(ulNodeSyncInfo.t1) == ROK)
+   {
+      memset(&vnfDb.vnfP7Info.p7SyncInfo.delta_sfn_slot, 0, sizeof(int32_t)); 
+      vnfDb.vnfP7Info.p7SyncInfo.prev_t2 = ulNodeSyncInfo.t2;
+      vnfDb.vnfP7Info.p7SyncInfo.prev_t3 = ulNodeSyncInfo.t3;
+   
+      EXTRACT_SFN_SLOT_FROM_TIME(vnfDb.vnfP7Info.p7SyncInfo.prev_t3, t3_sfnSlot);
+      CMP_INFO(t3_sfnSlot, vnfDb.vnfP7Info.p7SyncInfo.frameInfo, cmpStatus);
+      if(cmpStatus == 0)
+      {
+         vnfDb.vnfP7Info.p7SyncInfo.inSync = TRUE;
+      }
+      else
+      {
+         vnfDb.vnfP7Info.p7SyncInfo.inSync = FALSE;
+         if(cmpStatus == -1)
+         { /*PNF is ahead.*/
+            DU_LOG("\nINFO   --> NFAPI_VNF: PNF is ahead.");
+            CALC_TIME_DIFF(t3_sfnSlot, vnfDb.vnfP7Info.p7SyncInfo.frameInfo, numSlotDiff);
+         }
+         else if(cmpStatus == 1)
+         {
+            DU_LOG("\nINFO   --> NFAPI_VNF: VNF is ahead.");
+            CALC_TIME_DIFF(vnfDb.vnfP7Info.p7SyncInfo.frameInfo, t3_sfnSlot, numSlotDiff);
+         }
+         vnfDb.vnfP7Info.p7SyncInfo.delta_sfn_slot = cmpStatus * numSlotDiff;
+         ret = nfapiBuildAndSendDlNodeSync();
+      }
+      DU_LOG("\nDEBUG  --> NFAPI_VNF: delta:%d insyn:%d", vnfDb.vnfP7Info.p7SyncInfo.delta_sfn_slot, vnfDb.vnfP7Info.p7SyncInfo.inSync);
+      return ret;
+   }
+   else
+   {
+      DU_LOG("\nERROR  --> NFAPI_VNF: T1 Validation failed");
+      return RFAILED;
+   }
+   return ret;
+}
+
+/*******************************************************************
+ *
+ * @brief Processed the NFAPI P7 message from UDP socket 
+ *
+ * @details
+ *
+ *    Function : nfapiP7MsgHandler
+ *
+ *    Functionality:
+ *      Extracts the Hdr of P7 msgs and re-direct msgs to its particular
+ *      handling.
+ *      
+ *
+ * @params[in] Buffer received in UDP
+ * @return ROK     - success
+ *         RFAILED - failure
+ *
+ * ****************************************************************/
+uint8_t  nfapiP7MsgHandler(Buffer *mBuf)
+{
+   nFapi_p7_hdr p7Hdr;
+   nFapi_msg_header msgHdr;
+
+   nFapiExtractP7Hdr(&p7Hdr, mBuf);
+   nFapiExtractMsgHdr(&msgHdr, mBuf);
+
+   switch(msgHdr.msg_id)
+   {
+      case TAG_NFAPI_UL_NODE_SYNC:
+      {
+         DU_LOG("\nINFO  --> NFAPI_VNF: Received UL Node Synch");
+         nfapiP7ProcUlNodeSync(mBuf);
+         break;
+      }
+
+      default:
+      {
+         DU_LOG("\nERROR --> NFAPI_VNF: Wrong MsgId:%d", msgHdr.msg_id);
+         return RFAILED;
+      }
+   }
+
+   return ROK;
+}
+
 #endif
index 4ddd170..93a2c83 100644 (file)
@@ -22,5 +22,6 @@
 #define _NFAPI_P7_MSG_HDL_H
 
 uint8_t nfapiBuildAndSendDlNodeSync();
+uint8_t nfapiP7MsgHandler(Buffer *mBuf);
 
 #endif
index 0b5f8cd..d801dd3 100644 (file)
@@ -24,6 +24,7 @@
 #include "du_app_p7udp_inf.h"
 #include "nfapi_interface.h"
 #include "nfapi_common.h"
+#include "nfapi_p7_msg_hdl.h"
 
 /**************************************************************************
  * @brief Task Initiation callback function. 
@@ -331,6 +332,8 @@ uint8_t nfapiP7UdpRecvMsg()
       if(ret == ROK && recvBuf != NULLP)
       {
          DU_LOG("\nDEBUG  -->  NFAPI_VNF : Received P7 Message\n");
+  
+         nfapiP7MsgHandler(recvBuf);
          ODU_PUT_MSG_BUF(recvBuf);
       }
    }
index 17a0d72..8c5cea3 100644 (file)
@@ -85,7 +85,7 @@ typedef struct nfapiSyncInfo
 {
    uint8_t        phyId;
    NfapiFrameInfo frameInfo; 
-   uint8_t        inSync;
+   bool           inSync;
    uint32_t       prev_t1;
    uint32_t       prev_t2;
    uint32_t       prev_t3;
index d6fc85c..d892140 100644 (file)
    _frameInfo.slot = time % NUM_SLOTS_PER_SUBFRAME; \
 }
 
+#define EXTRACT_SFN_SLOT_FROM_DELTA(_delta, _sfnSlot) \
+{                                                    \
+   _sfnSlot.slot = _delta % NUM_SLOTS_PER_SUBFRAME;  \
+   _sfnSlot.sfn = _delta / NUM_SLOTS_PER_SUBFRAME;   \
+}
+
 /*P7 UDP Teansport Cfg Details*/
 #define PNF_P7_UDP_PORT 9876
 #define VNF_P7_UDP_PORT 6789
index 9c26588..9972745 100644 (file)
 extern PnfGlobalCb pnfCb;
 
 /*********************************************************************************
+ * @Brief: Filling of Ul Node Sync
+ *
+ * @Function: fillUlNodeSync
+ *
+ * @Description: At PNF, realize delta SFN/SLOT from VNF and adjust PNF's
+ *               SFN/Slot and calculate t3.
+ *
+ * @Params [IN]: delta_sfnSlot, ulSyncInfo
+ * [OUT]: void
+ *
+ * ******************************************************************************/
+
+void fillUlNodeSync(int32_t delta_sfnSlot, nFapi_ul_node_sync_info *ulSyncInfo)
+{
+    PnfSlotInfo  deltaSfnSlot;
+
+    if(delta_sfnSlot != 0)
+    {
+       EXTRACT_SFN_SLOT_FROM_DELTA(abs(delta_sfnSlot), deltaSfnSlot);
+       if(delta_sfnSlot < 0)
+       {
+          pnfCb.pnfSlotInfo.sfn -= deltaSfnSlot.sfn;
+          pnfCb.pnfSlotInfo.slot -= deltaSfnSlot.slot;
+       }
+       else
+       {
+          pnfCb.pnfSlotInfo.sfn += deltaSfnSlot.sfn;
+          pnfCb.pnfSlotInfo.slot += deltaSfnSlot.slot;
+       }
+    }
+    else
+    {
+       DU_LOG("\nINFO   --> NFAPI_PNF: No Delta between PNF and VNF");
+    }
+
+    ulSyncInfo->t3 = CALC_TIME_USEC_FROM_SFNSLOT(pnfCb.pnfSlotInfo);
+    return;
+}
+
+/*********************************************************************************
+ * @Brief: Building and Sending Ul Node Sync
+ *
+ * @Function: buildAndSendUlNodeSync
+ *
+ * @Description: At PNF , encode all the parameters of UL Node sync and Send to
+ *                 VNF via UDP
+ *
+ * @Params [IN]: Ptr to ulSyncInfo
+ * [OUT]: ROK/RFAILED
+ *
+ * ******************************************************************************/
+
+uint8_t buildAndSendUlNodeSync(nFapi_ul_node_sync_info *ulSyncInfo)
+{
+   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 start response");
+      return RFAILED;
+   }
+   nfapiFillP7Hdr(mBuf, (sizeof(nFapi_ul_node_sync_info) + sizeof(nFapi_msg_header)), 0, 0);
+   nfapiFillMsgHdr(mBuf, 1, TAG_NFAPI_UL_NODE_SYNC, sizeof(nFapi_ul_node_sync_info));
+
+   CMCHKPK(oduPackPostUInt32, ulSyncInfo->t1, mBuf);
+   CMCHKPK(oduPackPostUInt32, ulSyncInfo->t2, mBuf);
+   CMCHKPK(oduPackPostUInt32, ulSyncInfo->t3, mBuf);
+
+   if(pnfP7UdpSendMsg(mBuf) != ROK)
+   { 
+      return RFAILED;
+   }
+   return ROK;
+}
+
+/*********************************************************************************
+ * @Brief: Process and Handling of Dl Node Sync
  *
  * @Function Name: pnfDlNodeSyncHandler
  *
  *
  * @Functionality: 
- *    Processes DL Node Sync i.e. Extracts the DL_NODE_SYNC and will generate 
- *     UL_NODE_SYNC
+ * At PNF , extract all the parameters of DL Node sync and uses t1, 
+ * delta_sfnSlot  while processing and builing UL Node Sync
  *
  * @Params [IN]: Message Buffer received at UDP NFAPI P7 Interface
+ * [OUT]: ROK/RFAILED
  *
  * *******************************************************************************/
 uint8_t pnfDlNodeSyncHandler(Buffer *mBuf)
 {
+    uint8_t                 ret = ROK;
     nFapi_dl_node_sync_info dlNodeSync;
+    nFapi_ul_node_sync_info ulSyncInfo;
     PnfSlotInfo             vnfFrameInfo;
 
     CMCHKPK(oduUnpackUInt32, &(dlNodeSync.t1), mBuf);
@@ -64,9 +144,14 @@ uint8_t pnfDlNodeSyncHandler(Buffer *mBuf)
     DU_LOG("\n PNF_NFAPI: t1:%u, delta:%d, scs:%d",dlNodeSync.t1, dlNodeSync.delta_sfnSlot, dlNodeSync.scs);
 
     EXTRACT_SFN_SLOT_FROM_TIME(dlNodeSync.t1, vnfFrameInfo);
-    DU_LOG("\n dl node sync at VNF SFN:SLOT:%d/%d",vnfFrameInfo.sfn, vnfFrameInfo.slot);
-    //buildAndSendUlNodeSync(dlNodeSync.t1, dlNodeSync.delta_sfnSlot);
-    return ROK;
+
+    ulSyncInfo.t1 = dlNodeSync.t1;
+    ulSyncInfo.t2 = CALC_TIME_USEC_FROM_SFNSLOT(pnfCb.pnfSlotInfo);
+    
+    fillUlNodeSync(dlNodeSync.delta_sfnSlot, &ulSyncInfo);
+    
+    ret = buildAndSendUlNodeSync(&ulSyncInfo);
+    return ret;
 }
 
 /*********************************************************************************
index f790774..a779f98 100644 (file)
@@ -355,7 +355,7 @@ uint8_t pnfP5SctpSockPoll()
                DU_LOG("\nINFO  -->  P7_UDP : Received P7 Message [%ld] \n", numMsgRcvd+1);
                numMsgRcvd++;
                pnfP7MsgHandler(pnfP7UdpBuf);
-               break;
+               ODU_PUT_MSG_BUF(pnfP7UdpBuf);
           }
       }
    };