]> Gitweb @ Texas Instruments - Open Source Git Repositories - git.TI.com/gitweb - keystone-rtos/netapi.git/blobdiff - ti/runtime/netapi/test/net_test_router.c
some minor changes to test code:
[keystone-rtos/netapi.git] / ti / runtime / netapi / test / net_test_router.c
index a002618527a16cb2b6486b191bf220578cacffd7..670578e5c0eee3e8e80521c738e6f42210d2fc8b 100755 (executable)
 extern int QUIT;
 
 /* Global definitions */
-#ifdef netTest_MULTI_THREAD
-    cpu_set_t cpu_set;
-#endif
 
 netTestConfig_t netTestCfg;
 static  netTestConfigFile_t config_file;
 
-char    input_file_name[] = "net_test_config.txt";
+char    input_file_name[] = "/etc/netapi/net_test_config.txt";
 
 nwal_RetValue       nwalRetVal;
 Pktlib_HeapHandle ourHeap;
@@ -175,7 +172,7 @@ nwalTxPktInfo_t txPktInfoESP =
     0,                                                                                                 /* saAhMacSize */
     0,                                                                                                  /* etherLenOffBytes */
     netTest_MAC_HEADER_LEN,                                                        /* ipOffBytes */
-    0,                                                                                                  /* l4OffBytes */
+    0,                          /* l4OffBytes */
     0,                         /* l4HdrLen */
     0,                                                                                   /* pseudoHdrChecksum */
     0                                                                                                   /* pLoadLen */
@@ -196,7 +193,7 @@ nwalTxPktInfo_t txPktInfoAH =
     12,                                                                                                 /* saAhMacSize */
     0,                                                                                                  /* etherLenOffBytes */
     netTest_MAC_HEADER_LEN,   /* ipOffBytes */
-    0,                                                                                                  /* l4OffBytes */
+    0,                    /* l4OffBytes */
     netTest_UDP_HEADER_LEN,                                                                            /* l4HdrLen */
     0,                                                                                                  /* pseudoHdrChecksum */
     0                                                                                                   /* pLoadLen */
@@ -235,7 +232,7 @@ void close_pktio_channels(void)
 void open_pktio_tx_channels()
 {
     int err;
-    /* open netcp default  TX channels */
+    /* open netcp default TX channels for non-ipsec*/
     netcp_tx_chan_no_crypto= netapi_pktioOpen(netapi_handle, NETCP_TX, NULL, &netcp_tx_cfg,  &err);
     if (!netcp_tx_chan_no_crypto)
     {
@@ -244,17 +241,14 @@ void open_pktio_tx_channels()
     }
     else
     {
-        if(netTestCfg.ipsec_mode_tx == IPSEC_MODE_TX_INFLOW)
-        {
             PKTIO_CONTROL_T control;
             control.op = PKTIO_UPDATE_FAST_PATH;
             PKTIO_CFG_T cfg;
             cfg.fast_path_cfg.fp_send_option = PKTIO_FP_NO_CRYPTO_NO_CKSUM_PORT;
             cfg.fast_path_cfg.txPktInfo= &txPktInfoNoCrypto;
-            //netapi_pktioControl(netcp_tx_chan_no_crypto, NULL, &cfg, &control, &err);
-        }
+            netapi_pktioControl(netcp_tx_chan_no_crypto, NULL, &cfg, &control, &err);
     }
-    /* open netcp default  TX for ESP packets */
+    /* open netcp default TX for ESP packets */
     netcp_tx_chan_esp= netapi_pktioOpen(netapi_handle, NETCP_TX, NULL, &netcp_tx_cfg,  &err);
     if (!netcp_tx_chan_esp)
     {
@@ -268,9 +262,9 @@ void open_pktio_tx_channels()
             PKTIO_CONTROL_T control;
             control.op = PKTIO_UPDATE_FAST_PATH;
             PKTIO_CFG_T cfg;
-            cfg.fast_path_cfg.fp_send_option = PKTIO_FP_ESP_PORT;
+            cfg.fast_path_cfg.fp_send_option = PKTIO_FP_ESP_L3CKSUM_PORT;
             cfg.fast_path_cfg.txPktInfo= &txPktInfoESP;
-            //netapi_pktioControl(netcp_tx_chan_esp, NULL, &cfg, &control, &err);
+            netapi_pktioControl(netcp_tx_chan_esp, NULL, &cfg, &control, &err);
         }
     }
 
@@ -290,7 +284,7 @@ void open_pktio_tx_channels()
             PKTIO_CFG_T cfg;
             cfg.fast_path_cfg.fp_send_option = PKTIO_FP_AH_PORT;
             cfg.fast_path_cfg.txPktInfo= &txPktInfoAH;
-            //netapi_pktioControl(netcp_tx_chan_ah, NULL, &cfg, &control, &err);
+            netapi_pktioControl(netcp_tx_chan_ah, NULL, &cfg, &control, &err);
         }
     }
 }
@@ -299,36 +293,44 @@ void open_pktio_tx_channels()
 
 
 NETAPI_T worker_nh[TUNE_NETAPI_NUM_CORES];
-void slow_path_thread(uint32_t thread_num)
+void slow_path_thread(uint32_t index)
 {
     int err,i;
+    uint32_t thread_num;
     PKTIO_HANDLE_T *rx_chan;
     PKTIO_HANDLE_T *sb_tx_chan;
     PKTIO_HANDLE_T *sb_rx_chan;
+    cpu_set_t cpu_set;
 
+    thread_num = netTestCfg.sp_thread_num[index];
+    printf("slow_path_thread for index %d  called for thread %d\n", index, thread_num);
 
     CPU_ZERO( &cpu_set);
-#ifdef CORTEX_A15
-    for (i = netTestCfg.sp_proc_start[thread_num]; i <= netTestCfg.sp_proc_end[thread_num];i++)
+#ifdef CORTEX_A8
+   for (i = netTestCfg.sp_proc_start[index]; i <= netTestCfg.sp_proc_end[index];i++)
     {
-        printf("fast_path_thread: setting cpu %d to cpu_set\n", i);
+        printf("slow_path_thread: setting cpu %d to cpu_set\n", i);
         CPU_SET( i, &cpu_set);
     }
-    hplib_utilSetupCore(thread_num, &cpu_set);
+    hplib_utilSetupThread(0, &cpu_set, hplib_spinLock_Type_LOL);
 #else
-    for (i = netTestCfg.sp_proc_start[thread_num]; i <= netTestCfg.sp_proc_end[thread_num];i++)
+    for (i = netTestCfg.sp_proc_start[index]; i <= netTestCfg.sp_proc_end[index];i++)
     {
-        printf("fast_path_thread: setting cpu %d to cpu_set\n", i);
+        printf("slow_path_thread: setting cpu %d to cpu_set\n", i);
         CPU_SET( i, &cpu_set);
     }
-    hplib_utilSetupCore(thread_num, &cpu_set);
+    hplib_utilSetupThread(thread_num, &cpu_set, hplib_spinLock_Type_LOL);
 #endif
     worker_nh[thread_num]=netapi_init(NETAPI_CORE_MASTER,NULL);
-
+    if (worker_nh[thread_num] == NULL)
+    {
+        printf("slow_path_thread: netapi_init failure, exiting\n");
+        exit(1);
+    }
     NETAPI_HANDLE_T * n = (NETAPI_HANDLE_T *) worker_nh[thread_num];
 
    /* open netcp RX channel */
-    rx_chan = netapi_pktioOpen(worker_nh[thread_num], NETCP_RX, (PKTIO_CB) recv_cb_router, &netcp_rx_cfg,  &err);
+    //rx_chan = netapi_pktioOpen(worker_nh[thread_num], NETCP_RX, (PKTIO_CB) recv_cb_router, &netcp_rx_cfg,  &err);
 
 
 
@@ -347,37 +349,46 @@ void slow_path_thread(uint32_t thread_num)
     /**************Entry point into scheduler ****/
     /*********************************************/
     netapi_schedRun(scheduler[thread_num], &err);
-    netapi_Log(">net_test: core %d worker thread done\n",thread_num);
+    netapi_Log("slow_path_thread: core %d worker thread done\n",thread_num);
 
-    netapi_pktioClose(rx_chan, &err);
+    //netapi_pktioClose(rx_chan, &err);
     netapi_shutdown(worker_nh[thread_num]);
 }
 
 
-void fast_path_thread(uint32_t thread_num)
+void fast_path_thread(uint32_t index)
 {
     int err,i;
+    uint32_t thread_num;
     PKTIO_HANDLE_T *rx_chan;
     PKTIO_HANDLE_T *sb_tx_chan;
-    //PKTIO_HANDLE_T *sb_rx_chan;
 
-#ifdef CORTEX_A15
-    for (i = netTestCfg.fp_proc_start[thread_num]; i <= netTestCfg.fp_proc_end[thread_num];i++)
+    cpu_set_t cpu_set;
+
+    thread_num = netTestCfg.fp_thread_num[index];
+    printf("fast_path_thread for index %d  called for thread %d\n", index, thread_num);
+    CPU_ZERO( &cpu_set);
+#ifdef CORTEX_A8
+    for (i = netTestCfg.fp_proc_start[index]; i <= netTestCfg.fp_proc_end[index];i++)
     {
         printf("fast_path_thread: setting cpu %d to cpu_set\n", i);
         CPU_SET( i, &cpu_set);
     }
-    hplib_utilSetupCore(thread_num, &cpu_set);
+    hplib_utilSetupThread(thread_num, &cpu_set, hplib_spinLock_Type_LOL);
 #else
-    for (i = netTestCfg.fp_proc_start[thread_num]; i <= netTestCfg.fp_proc_end[thread_num];i++)
+    for (i = netTestCfg.fp_proc_start[index]; i <= netTestCfg.fp_proc_end[index];i++)
     {
         printf("fast_path_thread: setting cpu %d to cpu_set\n", i);
         CPU_SET( i, &cpu_set);
     }
-    hplib_utilSetupCore(thread_num, &cpu_set);
+    hplib_utilSetupThread(thread_num, &cpu_set, hplib_spinLock_Type_LOL);
 #endif
     worker_nh[thread_num]=netapi_init(NETAPI_CORE_MASTER,NULL);
-
+    if (worker_nh[thread_num] == NULL)
+    {
+        printf("fast_path_thread: netapi_init failure, exiting\n");
+        exit(1);
+    }
     NETAPI_HANDLE_T * n = (NETAPI_HANDLE_T *) worker_nh[thread_num];
 
    /* open netcp RX channel */
@@ -399,12 +410,11 @@ void fast_path_thread(uint32_t thread_num)
      scheduler[thread_num]->config.pollCtrlQ = FALSE;
      //sleep(100000);
     netapi_schedRun(scheduler[thread_num], &err);
-    netapi_Log(">net_test: core %d worker thread done\n",thread_num);
+    netapi_Log("fast_path_thread: core %d worker thread done\n",thread_num);
 
     netapi_pktioClose(rx_chan, &err);
     netapi_shutdown(worker_nh[thread_num]);
-\r}
-
+}
 #endif
 
 /***************************************
@@ -418,6 +428,7 @@ int main(int argc, char **argv)
     Pktlib_HeapIfTable*  pPktifTable;
     FILE * fpr = NULL;
 
+    cpu_set_t cpu_set;
     /* install signal handler for ^c */
     signal(SIGINT,netTest_utilMySig);
 
@@ -467,11 +478,15 @@ int main(int argc, char **argv)
     /* assign main net_test thread to run on core 0 */
     CPU_ZERO( &cpu_set);
     CPU_SET( 0, &cpu_set);
-    hplib_utilSetupCore(0, &cpu_set);
+    hplib_utilSetupThread(0, &cpu_set, hplib_spinLock_Type_LOL);
 #endif
     /* create netapi */
     netapi_handle = netapi_init(NETAPI_SYS_MASTER, &our_netapi_default_cfg);
-
+    if (netapi_handle == NULL)
+    {
+        printf("main: netapi_init failure, exiting\n");
+        exit(1);
+    }
     /* configure expection packet handling with netapi */
     netapi_netcpCfgExceptions(netapi_handle, NETCP_CFG_ALL_EXCEPTIONS, NETCP_CFG_ACTION_DISCARD, (NETCP_CFG_ROUTE_HANDLE_T) NULL);
     expPkt_appid = netapi_netcpCfgExceptions(netapi_handle, 7, NETCP_CFG_ACTION_TO_SW, (NETCP_CFG_ROUTE_HANDLE_T) NULL);
@@ -545,6 +560,7 @@ netTest_utilsStatsCb(netapi_handle, NULL);
 
     /* close pktio channels we opened via open_pktio_tx_channels() */
     close_pktio_channels();
+    netapi_shutdown(netapi_handle);
 }
 
 static inline void send_it(Ti_Pkt *tip, int len, netTestSA_t * p_sec, int out_port)
@@ -579,8 +595,7 @@ static inline void send_it(Ti_Pkt *tip, int len, netTestSA_t * p_sec, int out_po
   if(p_sec)
   {   
        meta_tx2.txFlag1 |= NWAL_TX_FLAG1_DO_IPSEC_ESP_CRYPTO ;
-       //meta2.sa_handle = (void*)p_sec->tx_tunnel;
-       meta2.sa_handle=p_sec->tx_inflow_mode_handle;
+       meta2.sa_handle = (void*)p_sec->tx_tunnel;
        meta_tx2.saOffBytes=netTest_MAC_HEADER_LEN + netTest_IP_HEADER_LEN;
        meta_tx2.saPayloadLen=len-netTest_MAC_HEADER_LEN - netTest_IP_HEADER_LEN;   //don't include tag, mac and outer header
        meta2.u.tx_meta=&meta_tx2;
@@ -635,7 +650,6 @@ void recv_cb_router(struct PKTIO_HANDLE_Tag * channel, Ti_Pkt* p_recv[],
         tip = p_recv[i];
         Pktlib_getDataBuffer(tip,(uint8_t**)&p_pkt,&templen);//ignore templen
         len = Pktlib_getPacketLen(tip)-4;//real length, subtract mac trailer
-        stats[coreid].rx+=1;
         appid = ((unsigned int)meta[i].u.rx_meta->appId)&0xff000000;
         switch(appid)
         {