]> Gitweb @ Texas Instruments - Open Source Git Repositories - git.TI.com/gitweb - keystone-rtos/netapi.git/blobdiff - ti/runtime/netapi/test/net_test_loopback.c
Update config file paths to point to new location on filesystem
[keystone-rtos/netapi.git] / ti / runtime / netapi / test / net_test_loopback.c
index ccc15f034189809da9f92737d56ee4185d9983b0..f8b901b292c140d2287365174d53d671dde35462 100755 (executable)
 
  *****************************************************************************/
 
-#include "net_test.h"
+#include "netapi.h"
+#include "net_test_sa_utils.h"
+#include "net_test_utils.h"
+#include "net_test_thread_utils.h"
 #include "ti/drv/nwal/test/fw_rm.h"
 #include <signal.h>
 #include <pthread.h>
 
 
 #if defined(DEVICE_K2H)
-#include <ti/runtime/hplib/device/k2h/src/hplib_device.c>
-#include <ti/runtime/netapi/device/k2h/src/netapi_device.c>
 #include <ti/drv/qmss/device/k2h/src/qmss_device.c>
 #include <ti/drv/cppi/device/k2h/src/cppi_device.c>
 #elif defined (DEVICE_K2K)
-#include <ti/runtime/hplib/device/k2k/src/hplib_device.c>
-#include <ti/runtime/netapi/device/k2k/src/netapi_device.c>
 #include <ti/drv/qmss/device/k2k/src/qmss_device.c>
 #include <ti/drv/cppi/device/k2k/src/cppi_device.c>
 #elif defined (DEVICE_K2L)
-#include <ti/runtime/hplib/device/k2l/src/hplib_device.c>
-#include <ti/runtime/netapi/device/k2l/src/netapi_device.c>
 #include <ti/drv/qmss/device/k2l/src/qmss_device.c>
 #include <ti/drv/cppi/device/k2l/src/cppi_device.c>
 #elif defined (DEVICE_K2E)
-#include <ti/runtime/hplib/device/k2e/src/hplib_device.c>
-#include <ti/runtime/netapi/device/k2e/src/netapi_device.c>
 #include <ti/drv/qmss/device/k2e/src/qmss_device.c>
 #include <ti/drv/cppi/device/k2e/src/cppi_device.c>
 #else /*Default */
-#include <ti/runtime/hplib/device/k2h/src/hplib_device.c>
-#include <ti/runtime/netapi/device/k2h/src/netapi_device.c>
 #include <ti/drv/qmss/device/k2h/src/qmss_device.c>
 #include <ti/drv/cppi/device/k2h/src/cppi_device.c>
 #endif /* Device */
@@ -79,10 +72,13 @@ extern int QUIT;
 extern netTestStats_T stats[TUNE_NETAPI_NUM_CORES];
 extern paSysStats_t netcp_stats;
 
+extern Rm_ServiceHandle   *rmClientServiceHandle;
+hplib_spinLock_T net_test_thread_lock;
+
 
 netTestConfig_t netTestCfg;
 static netTestConfigFile_t config_file;
-char    input_file_name[] = "/etc/netapi/net_test_config.txt";
+char    input_file_name[] = "/etc/transportnetlib/test/net_test_config.txt";
 nwal_RetValue       nwalRetVal;
 Pktlib_HeapHandle   ourHeap;
 
@@ -127,7 +123,8 @@ static NETAPI_CFG_T our_netapi_default_cfg=
     TUNE_NETAPI_DEFAULT_BUFFER_SIZE+128+128,  //size of buffers in default heap
     128, //tail room
     256, //extra room
-    0
+    0,
+    NULL
 };
 
 NETAPI_T netapi_handle;
@@ -142,6 +139,7 @@ NETAPI_SCHED_CONFIG_T our_sched_cfg={
 netTestSA_t sa_info[MAX_SEC_INDEX];
 NETCP_CFG_IPSEC_POLICY_T rx_policy[MAX_SEC_INDEX];
 
+int masterType = NETAPI_SYS_MASTER;
 
 
 
@@ -451,7 +449,8 @@ void recv_sb_cb(struct PKTIO_HANDLE_Tag * channel, Ti_Pkt* p_recv[],
     int coreid=0;
 #endif
     //nwal_AppId time;
-    unsigned long time, delta_time;
+    unsigned long time = 0;
+    unsigned long delta_time = 0;
     /* loop over received pkts */
     for(i=0;i<n_pkts;i++)
    {
@@ -612,21 +611,25 @@ void recv_cb(struct PKTIO_HANDLE_Tag * channel, Ti_Pkt* p_recv[],
         }
 
         if(coreid<TUNE_NETAPI_NUM_CORES)
+        {
             stats[coreid].rx+=1;
-        if (ifno < TUNE_NETAPI_MAX_NUM_MAC)
-            stats[coreid].if_rx[ifno]+=1;
-
+            if (ifno < TUNE_NETAPI_MAX_NUM_MAC)
+                stats[coreid].if_rx[ifno]+=1;
+        }
 
 #ifdef DEBUG_DESC
-        if (stats[coreid].rx<16)
-        {
-            netapi_Log(">rx dmp.."); 
-            netTest_utilDumpDescr((long *) tip, stats[coreid].rx);
-        }
-        else if (stats[coreid].rx>99) 
+        if(coreid<TUNE_NETAPI_NUM_CORES)
         {
-            netapi_Log(">rx dmp.."); 
-            netTest_utilDumpDescr((long *) tip,stats[coreid].rx);
+            if (stats[coreid].rx<16)
+            {
+                netapi_Log(">rx dmp.."); 
+                netTest_utilDumpDescr((long *) tip, stats[coreid].rx);
+            }
+            else if (stats[coreid].rx>99) 
+            {
+                netapi_Log(">rx dmp.."); 
+                netTest_utilDumpDescr((long *) tip,stats[coreid].rx);
+            }
         }
 #endif
 #if 0
@@ -906,12 +909,12 @@ void setup_netTestDSPFastPath(NETAPI_T handle)
     memset(&dsp_pktio_cfg, 0, sizeof (PKTIO_CFG_T));
     memset(&dsp_classi, 0, sizeof (NETCP_CFG_CLASSIFIER_T));
     memset(&dsp_route, 0, sizeof (NETCP_CFG_ROUTE_T));
-    char dsp_name[32];
+    char dsp_name[PKTIO_MAX_NAME];
     for (i = 0; i < CPU_NUM_REM_FAST_PATH_CORES; i++)
     {
-        sprintf(&dsp_name[0],"%s%d","dsp_chan", i);
+        snprintf(&dsp_name[0],32, "%s%d","dsp_chan", i);
         dsp_pktio_cfg.flags1 = PKTIO_RX;
-        dsp_pktio_cfg.flags2 = PKTIO_GLOBAL | PKTIO_PKT;
+        dsp_pktio_cfg.flags2 = PKTIO_PKT;
         dsp_pktio_cfg.qnum = TEST_NWAL_BASE_REM_FP_RX_PKT_QUEUE + i;
         dsp_pktio_cfg.max_n = 8;
 
@@ -1006,15 +1009,11 @@ void slow_path_thread(uint32_t index)
 #else
     for (i = netTestCfg.sp_proc_start[index]; i <= netTestCfg.sp_proc_end[index];i++)
     {
-        printf("slow_path_thread: setting cpu %d to cpu_set\n", i);
         CPU_SET( i, &cpu_set);
     }
     hplib_utilSetupThread(thread_num, &cpu_set, hplib_spinLock_Type_LOL);
 #endif
-    worker_nh[thread_num] = netapi_init(NETAPI_CORE_MASTER,
-                                        NULL,
-                                        &hplibDeviceGblCfgParam,
-                                        &netapiDeviceGblCfgParam);
+    worker_nh[thread_num] = netapi_init(NETAPI_CORE_MASTER,NULL);
 
     if (worker_nh[thread_num] == NULL)
     {
@@ -1029,14 +1028,15 @@ void slow_path_thread(uint32_t index)
         printf("sched create failed for core%d\n",thread_num);
         goto ERR_slow_path_thread;
     }
-    scheduler[thread_num]->config.yield = TRUE;
-    scheduler[thread_num]->config.pollGarbageQ = TRUE;
-    scheduler[thread_num]->config.pollCtrlQ = TRUE;
+    scheduler[thread_num]->config.yield = NETAPI_TRUE;
+    scheduler[thread_num]->config.pollGarbageQ = NETAPI_TRUE;
+    scheduler[thread_num]->config.pollCtrlQ = NETAPI_TRUE;
     printf("Slow Path thread: %d setup complete, running on ARM CORE: %d\n", i,i);
     /* Entry point to scheduler */
     netapi_schedRun(scheduler[thread_num], &err);
 
 ERR_slow_path_thread:
+    printf("slow_path_thread: calling netapi_shutdown\n");
     netapi_shutdown(worker_nh[thread_num]);
 }
 
@@ -1061,7 +1061,7 @@ void fast_path_thread(uint32_t index)
 #else
     for (i = netTestCfg.fp_proc_start[index]; i <= netTestCfg.fp_proc_end[index];i++)
     {
-        netapi_Log("fast_path_thread: start core %d, end core %d\n",
+        netapi_Log("fast_path_thread: start core %d end core %d\n",
                 netTestCfg.fp_proc_start[index],
                 netTestCfg.fp_proc_end[index]);
         netapi_Log("fast_path_thread: setting cpu %d to cpu_set\n", i);
@@ -1069,25 +1069,36 @@ void fast_path_thread(uint32_t index)
     }
     hplib_utilSetupThread(thread_num, &cpu_set, hplib_spinLock_Type_LOL);
 #endif
-    worker_nh[thread_num]=netapi_init(NETAPI_CORE_MASTER,
-                                      NULL,
-                                      &hplibDeviceGblCfgParam,
-                                      &netapiDeviceGblCfgParam);
+    hplib_mSpinLockLock(&net_test_thread_lock);
+    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");
+        hplib_mSpinLockUnlock(&net_test_thread_lock);
         exit(1);
     }
+    hplib_mSpinLockUnlock(&net_test_thread_lock);
     /* open netcp default RX channels*/
     rx_chan = netapi_pktioOpen(worker_nh[thread_num], NETCP_RX, (PKTIO_CB) recv_cb, &netcp_rx_cfg,  &err);
 
+    netcp_rx_cfg.flags2 = PKTIO_PKT;
+
+    if(masterType == NETAPI_SYS_MASTER)
+        netapi_pktioOpen(worker_nh[thread_num], "sysMaster", (PKTIO_CB) recv_cb, &netcp_rx_cfg,  &err);
+
+    else if(masterType == NETAPI_PROC_MASTER)
+        netapi_pktioOpen(worker_nh[thread_num], "procMaster", (PKTIO_CB) recv_cb, &netcp_rx_cfg,  &err);
+
     /* create a pktio channel for specially classified pkts */
     /* open netcp default tx, rx queues for sideband crypto */
     sb_rx_chan = netapi_pktioOpen(worker_nh[thread_num], NETCP_SB_RX, (PKTIO_CB) recv_sb_cb, &netcp_sb_rx_cfg,  &err);
 
     netapi_setCookie(worker_nh[thread_num],(void*)thread_num);
     
-    scheduler[thread_num] =netapi_schedOpen(worker_nh[thread_num],&our_sched_cfg, &err);
+    scheduler[thread_num] =netapi_schedOpen(worker_nh[thread_num],
+                                            &our_sched_cfg,
+                                            &err);
     if (!scheduler[thread_num]) 
         {
         printf("sched create failed for core%d\n",thread_num);
@@ -1096,9 +1107,9 @@ void fast_path_thread(uint32_t index)
     }
 
  
-    scheduler[thread_num]->config.yield = FALSE;
-    scheduler[thread_num]->config.pollGarbageQ = FALSE;
-    scheduler[thread_num]->config.pollCtrlQ = FALSE;
+    scheduler[thread_num]->config.yield = NETAPI_FALSE;
+    scheduler[thread_num]->config.pollGarbageQ = NETAPI_FALSE;
+    scheduler[thread_num]->config.pollCtrlQ = NETAPI_FALSE;
      //sleep(100000);
    /* Entry point to scheduler */
     printf("Fast Path thread: %d setup complete, running on ARM CORE: %d\n", i,i);
@@ -1107,7 +1118,8 @@ void fast_path_thread(uint32_t index)
 ERR_fast_path_thread:
     netapi_pktioClose(rx_chan, &err);
     netapi_pktioClose(sb_rx_chan, &err);
-
+    
+    printf("fast_path_thread: calling netapi_shutdown\n");
     netapi_shutdown(worker_nh[thread_num]);
 }
 
@@ -1122,56 +1134,84 @@ int main(int argc, char **argv)
     int32_t             errCode;
     Pktlib_HeapIfTable*  pPktifTable;
     FILE * fpr = NULL;
+    int c;
 
+    static char usage[] = "usage: %s -f < config File Name> -t <masterType: procMaster or sysMater> >\n";
 #ifdef netTest_MULTI_THREAD
     cpu_set_t cpu_set;
 #endif
      /* install signal handler for ^c */
     signal(SIGINT,netTest_utilMySig);
 
-    if (argc == 2)
+
+    while ((c = getopt (argc, argv, "f:t:?")) != -1)
     {
-        printf("main: filename1 %s\n", argv[1]);
-        fpr = fopen(argv[1], "r");
+       switch (c)
+       {
+            case 'f':
+                fpr = fopen(optarg, "r");
+                printf("main: filename1 %s\n", optarg);
+                break;
+            case 't':
+                if(strcmp("sysMaster", optarg) == 0)
+                {
+                    masterType = NETAPI_SYS_MASTER;
+                }
+                else if (strcmp("procMaster", optarg) == 0)
+                {
+                    masterType = NETAPI_PROC_MASTER;
+                }
+                else
+                {
+                    printf("%s\n", usage);
+                }
+                printf("optionValue %s: %d\n", optarg, masterType);
+                break;
+
+            case '?':
+                printf("optionValue %s: %d\n", optarg, masterType);
+                exit(EXIT_FAILURE);
+                break;
+            default:
+                break;
+        }
     }
-    else
-    {
+
+    if (fpr ==NULL)
         fpr = fopen(input_file_name, "r");
-    }
-    if (fpr == NULL)
+    if (initRm())
     {
-        printf("Cant open config file: filepath %s, %s\n", input_file_name, strerror(errno));
+        printf("main: initRm() returned error\n");
         exit(1);
     }
-    else
-    {
-        memset(&config_file, 0, sizeof(netTestConfigFile_t));
-        memset(&netTestCfg, 0, sizeof(netTestConfig_t));
-        
-        netTest_utilProcessConfigFile(fpr,&config_file);
+    hplib_mSpinLockInit(&net_test_thread_lock );
+    our_netapi_default_cfg.rmHandle = rmClientServiceHandle;
+    memset(&config_file, 0, sizeof(netTestConfigFile_t));
+    memset(&netTestCfg, 0, sizeof(netTestConfig_t));
 
-        netTest_utilParseMac(&config_file);
+    netTest_utilProcessConfigFile(fpr,&config_file);
 
-        /* parse slow path/fast path thread configuration parameters */
-        netTest_utilParseThreadParams(&config_file);
+    netTest_utilParseMac(&config_file);
 
-        netTest_utilParseIP(&config_file);
+    /* parse slow path/fast path thread configuration parameters */
+    netTest_utilParseThreadParams(&config_file);
 
-        netTest_utilParseIpsecMode(&config_file);
+    netTest_utilParseIP(&config_file);
 
-        /* DSP mac processing */
-        parse_dsp_mac(&config_file.dsp_mac[0]);
+    netTest_utilParseIpsecMode(&config_file);
 
-       /* DSP IP processing */
-        parse_dsp_ip(&config_file.dsp_ip[0]);
+    /* DSP mac processing */
+    parse_dsp_mac(&config_file.dsp_mac[0]);
 
-        /* IPSEC interface number processing */
-        parse_simple_param_u32((char*)&config_file.ipsec_if_no[0], &netTestCfg.ipsec_if_no);
+    /* DSP IP processing */
+    parse_dsp_ip(&config_file.dsp_ip[0]);
 
-        netTest_utilParseSA(&config_file);
+    /* IPSEC interface number processing */
+    parse_simple_param_u32((char*)&config_file.ipsec_if_no[0], &netTestCfg.ipsec_if_no);
 
-        parse_simple_param_u32(&config_file.dest_udp_port_config, &netTestCfg.dest_udp_port_config);
-    }
+    netTest_utilParseSA(&config_file);
+
+    parse_simple_param_u32(&config_file.dest_udp_port_config, &netTestCfg.dest_udp_port_config);
 
     memset(&sa_info, 0, sizeof(sa_info));
 
@@ -1183,21 +1223,18 @@ int main(int argc, char **argv)
     hplib_utilSetupThread(0, &cpu_set, hplib_spinLock_Type_LOL);
 #endif
 
-    /* hplib_globalDeviceConfigParams_t hplibDeviceGblCfgParam/
     /* create netapi */
-    netapi_handle = netapi_init(NETAPI_SYS_MASTER,
-                                &our_netapi_default_cfg,
-                                &hplibDeviceGblCfgParam,
-                                &netapiDeviceGblCfgParam);
+
+    netapi_handle = netapi_init(masterType,
+                                &our_netapi_default_cfg);
 
     if (netapi_handle == NULL)
     {
         printf("main: netapi_init failure, exiting\n");
+        closeRm();
         exit(1);
     }
 
-
-
     /* configure expection packet handling with netapi */
     netapi_netcpCfgExceptions(netapi_handle,
                               NETCP_CFG_ALL_EXCEPTIONS,
@@ -1213,6 +1250,7 @@ int main(int argc, char **argv)
     if (!ourHeap)
     {
         printf("Pktlib_findHeapByName()  fail\n");
+        closeRm();
         exit(1);
     }
 
@@ -1220,7 +1258,12 @@ int main(int argc, char **argv)
 
     /* create scheduler instance */
     our_sched =netapi_schedOpen(netapi_handle,&our_sched_cfg, &err);
-    if (!our_sched) {printf("sched create failed\n"); exit(1);}
+    if (!our_sched)
+    {
+        printf("sched create failed\n");
+        closeRm();
+        exit(1);
+    }
 
 
     /*create net_test MAC interfaces, attach IP to created MAC interfaces */
@@ -1232,13 +1275,18 @@ int main(int argc, char **argv)
     if (!p_trie_sa_rx || !p_trie_sa_tx)
     {
         printf("trie alloc for SA  failed\n");
+        closeRm();
         exit(1);
     }
 
 #ifdef netTest_DSP_FASTPATH
-    setup_netTestDSPFastPath(netapi_handle);
+    if (masterType == NETAPI_SYS_MASTER)
+    {
+        setup_netTestDSPFastPath(netapi_handle);
+    }
 #endif
 
+    netTest_utilCreateDefaultFlow(netapi_handle, masterType);
     /* Create RX SA's, RX Policy and TX SA's, all SA configuration parameters are read from net_test_config.txt file */
     netTest_utilCreateSecAssoc();
 
@@ -1255,24 +1303,25 @@ int main(int argc, char **argv)
     printf("\n Enter 's' for stats or 'q'to quit net_test_loopback app, or 'h' for help\n");
 
 
-    char c;
-        //this thread of execution (main) now just waits on user input
-        for(;;)
-        {
-           printf(">");
-           c=getchar();
-           if (c=='q')
-            {
-                QUIT=1;
-                printf("net_test_loopback: please wait for application shutdown and resource cleanup\n");
-                break;
-           }
-           else if (c=='s') netTest_utilsStatsCb(netapi_handle, &netcp_stats);
-           else if (c=='h') printf("'q' to quit,  's' for stats, 'h' for help\n");
-        }
 
-        netTest_utilRemoveSpFpThreads(netTestCfg.num_sp_threads, netTestCfg.num_fp_threads);
 
+    int c;
+    //this thread of execution (main) now just waits on user input
+    for(;;)
+    {
+       printf(">");
+       c=getchar();
+       if (c=='q')
+       {
+            QUIT=1;
+            printf("net_test_loopback: please wait for application shutdown and resource cleanup\n");
+            break;
+       }
+       else if (c=='s') netTest_utilsStatsCb(netapi_handle, &netcp_stats);
+       else if (c=='h') printf("'q' to quit,  's' for stats, 'h' for help\n");
+    }
+
+        netTest_utilRemoveSpFpThreads(netTestCfg.num_sp_threads, netTestCfg.num_fp_threads);
 }
 #else
     /*********************************************/
@@ -1294,10 +1343,14 @@ int main(int argc, char **argv)
     /* close pktio channels we opened via open_pktio_tx_channels() */
     close_pktio_channels();
 #ifdef netTest_DSP_FASTPATH
-    teardown_netTestDSPFastPath();
+    if (masterType == NETAPI_SYS_MASTER)
+    {
+        teardown_netTestDSPFastPath();
+    }
 #endif
 
     netapi_shutdown(netapi_handle);
+    closeRm();
     printf("net_test shutdown complete\n");
 
 }
@@ -1306,6 +1359,7 @@ int main(int argc, char **argv)
 /* Stub functions */
 Trie * route_init(void)
 {
+    return NULL;
 }
 void route_add(Trie * Pt, unsigned long * Pdest_ipBE, void * Pour_route)
 {