]> Gitweb @ Texas Instruments - Open Source Git Repositories - git.TI.com/gitweb - keystone-rtos/netapi.git/blob - ti/runtime/netapi/test/net_test_utils.c
fix for SDOCM00101400- sp config file parameter is used for both slow path and switc...
[keystone-rtos/netapi.git] / ti / runtime / netapi / test / net_test_utils.c
1 /******************************************
2  * File: net_test_utils.c
3  * Purpose: net_test application general utilities
4  **************************************************************
5  * FILE:  net_test_utils.c
6  * 
7  * DESCRIPTION:  net_test application general utilities
8  * 
9  * REVISION HISTORY:
10  *
11  *  Copyright (c) Texas Instruments Incorporated 2010-2011
12  * 
13  *  Redistribution and use in source and binary forms, with or without 
14  *  modification, are permitted provided that the following conditions 
15  *  are met:
16  *
17  *    Redistributions of source code must retain the above copyright 
18  *    notice, this list of conditions and the following disclaimer.
19  *
20  *    Redistributions in binary form must reproduce the above copyright
21  *    notice, this list of conditions and the following disclaimer in the 
22  *    documentation and/or other materials provided with the   
23  *    distribution.
24  *
25  *    Neither the name of Texas Instruments Incorporated nor the names of
26  *    its contributors may be used to endorse or promote products derived
27  *    from this software without specific prior written permission.
28  *
29  *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 
30  *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 
31  *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
32  *  A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 
33  *  OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 
34  *  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 
35  *  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
36  *  DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
37  *  THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 
38  *  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 
39  *  OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
41  *****************************************/
43 #include "net_test_utils.h"
44 #include <signal.h>
45 #include <pthread.h>
46 #include "router.h"
48 #include "ti/drv/nwal/test/fw_rm.h"
49 #include <ti/drv/sa/salld.h>
50 #include <ti/drv/pa/pa.h>
52 extern NETAPI_T netapi_handle;
53 extern netTestConfig_t netTestCfg;
54 extern netTestConfig_t config;
55 extern netTestSA_t sa_info[];
56 extern NETAPI_SCHED_HANDLE_T * scheduler[];
57 extern Pktlib_HeapHandle ourHeap;
58 extern NETCP_CFG_IP_T ip_rule[];
59 extern NETCP_CFG_MACIF_T mac[];
63 netTestStats_T stats[NET_TEST_MAX_SP_THREAD + NET_TEST_MAX_FP_THREAD +1];
64 paSysStats_t netcp_stats;
68 static LastPktInfo_t lpInfo;
69 int netTest_utilCheckHeader(netTestHead_T * p_head, PKTIO_METADATA_T * p_meta)
70 {
71 #ifdef netTest_MULTI_THREAD
72     int coreid=Osal_nwalGetProcId();  //who we are(thread local)
73 #else
74     int coreid=0;
75 #endif
76     if (NWAL_RX_FLAG1_META_DATA_VALID & p_meta->u.rx_meta->rxFlag1)
77     {
78         lpInfo.iface = ((unsigned int)p_meta->u.rx_meta->appId) &0xff; //last byte is interface num
79         lpInfo.ipcsum =(p_meta->u.rx_meta->rxFlag1 & NWAL_RX_FLAG1_IPV4_CHKSUM_VERIFY_MASK )== NWAL_RX_FLAG1_IPV4_CHKSUM_VERIFY_ACK ? 1 : 0;
80         lpInfo.l4csum = (p_meta->u.rx_meta->rxFlag1 & NWAL_RX_FLAG1_L4_CHKSUM_VERIFY_MASK )== ((NWAL_RX_FLAG1_L4_CHKSUM_VERIFY_ACK) << NWAL_RX_FLAG1_L4_CHKSUM_VERIFY_SHIFT) ? 1 : 0; 
81         if ((unsigned int)p_meta->u.rx_meta->appId & NETAPI_NETCP_MATCH_IPSEC)
82         {
83         stats[coreid].sec_rx++;
84         }
85         if ((unsigned int)p_meta->u.rx_meta->appId & NETAPI_NETCP_MATCH_IPSEC_POLICY)
86         {
87         stats[coreid].secp_rx++;
88         }
90         if ((unsigned int)p_meta->u.rx_meta->appId & NETAPI_NETCP_MATCH_CLASS)
91         {
92             int c= ((unsigned int)p_meta->u.rx_meta->appId >>8)&0xffff;
93         if (c==0)  stats[coreid].n_class0_rx +=1;
94         else if (c==1) stats[coreid].n_class1_rx +=1;
95         else if (c==2) stats[coreid].n_class2_rx +=1;
96         else netapi_Log("**NET_TEST RX -unknown class: %x\n",  p_meta->u.rx_meta->appId);
97     }
98 }
100  return 1;
104 static int scnt=0;
105 int QUIT;
106 void netTest_utilMySig(int x)
108     QUIT=1;
109     scnt+=1;
110     netapi_Log(">net_test: recv'd signal %d cnt=%d\n",x,scnt);
111     if (scnt > 10)
112     {
113         netapi_Log(">net_test: WARNING EXITING WITH PROPER SHUTDOWN, LUTS LEFT ACTIVE\n");
114         exit(1);
115     }
117 unsigned long netTest_utilPeek(unsigned long * p)
119     return *p;
121 void netTest_utilDumpDescr(unsigned long *p, int n)
123     netapi_Log("--------dump of descriptor %d %x\n", n, (int) p);
124     netapi_Log("> %x %x %x %x %x %x %x %x\n",p[0],p[1],p[2],p[3],p[4],p[5],p[6],p[7]);
125     netapi_Log("> %x %x %x %x %x %x %x %x\n",p[8],p[9],p[10],p[11],p[12],p[13],p[14],p[15]);
126     netapi_Log("-----------------------------\n");
128 void netTest_utilDumpHeader(unsigned long *p, int n, int a, int r)
130     netapi_Log("--------dump of header %d %x appID=%x flag1=%x\n", n, (int) p,a,r);
131     netapi_Log("> %x %x %x %x %x %x %x %x\n",p[0],p[1],p[2],p[3],p[4],p[5],p[6],p[7]);
132     netapi_Log("> %x %x %x %x %x %x %x %x\n",p[8],p[9],p[10],p[11],p[12],p[13],p[14],p[15]);
133     netapi_Log("> %x %x %x %x %x %x %x %x\n",p[16],p[17],p[18],p[19],p[20],p[21],p[22],p[23]);
134     netapi_Log("> %x %x %x %x %x %x %x %x\n",p[24],p[25],p[26],p[27],p[28],p[29],p[30],p[31]);
135     netapi_Log("-----------------------------\n");
138 void   netTest_utilDumpBuffer
140     unsigned long *                      buf,
141     uint32_t                      buf_length
144     uint8_t                       count = 0;
145     uint16_t                      dump_size;
146     uint8_t*                     tmp_buf;
147     uint8_t                       row_count;
148     static uint8_t                first = 0;
150     //if(first > 2) return;
152     //first++;
154     dump_size = buf_length ;
156     tmp_buf = (uint8_t *)(buf);
158     netapi_Log("netapi *:  - 8 bit word hex Length: %d Start \n",buf_length);
159     do
160     {
161     row_count = (dump_size - count);
163         if(row_count == 0)
164         {
165             break;
166         }
168         if(row_count > 4)
169         {
170             row_count = 4;
171         }
173         switch (row_count)
174         {
175             case 4:
176             {
177                 netapi_Log("netapi *:%02d : %02x    %02x    %02x    %02x \n",
178                       count,tmp_buf[0],tmp_buf[1],tmp_buf[2],tmp_buf[3]);
179                 break;
180             }
181             case 3:
182             {
183                 netapi_Log("netapi *: %02d : %02x    %02x    %02x \n",
184                       count,tmp_buf[0],tmp_buf[1],tmp_buf[2]);
185                 break;
186             }
188             case 2:
189             {
190                 netapi_Log("netapi *: %02d : %02x    %02x \n",
191                       count,tmp_buf[0],tmp_buf[1]);
192                 break;
193             }
195             case 1:
196             {
197                 netapi_Log("netapi *: %02d : %02x \n",
198                       count,tmp_buf[0]);
199                 break;
200             }
202             default:
203             {
204                 /* Should never reach here */
205                 netapi_Log("netapi *: Internal Error in  netTest_utilDumpBuffer().Row Count: %d \n", row_count);
206                 return;
207             }
208         }
210         tmp_buf = tmp_buf + row_count;
211         count = count +  row_count;
213     }while(count < dump_size);
215     netapi_Log("netapi *:  - Byte hex Dump End \n");
218 long netTest_utilHtonl(long x)
220     long temp = (x&0xff000000)>>24 | (x&0xff0000)>>8 | (x&0xff00)<<8 |  (x&0xff)<<24 ;
221     return temp;
224 unsigned char netTest_utilHex2Dec(char *p_s)
226     int val;
227     sscanf(p_s,"%x",&val); 
228     return val&0xff;
231 /********************************************************************
232  *  FUNCTION PURPOSE: Ones complement addition utility
233  ********************************************************************
234  ********************************************************************/
235 uint16_t netTest_utilOnesComplementAdd (uint16_t v1, uint16_t v2)
237   uint32_t result;
239   result = (uint32_t)v1 + (uint32_t)v2;
240   result = (result >> 16) + (result & 0xffff);
241   result = (result >> 16) + (result & 0xffff);
243   return ((uint16_t)result);
246 /********************************************************************
247  *  FUNCTION PURPOSE: Ones complement checksum utility
248  ********************************************************************
249  ********************************************************************/
250  uint16_t netTest_utilOnesCompChkSum  (uint8_t *p, uint32_t nwords)
252   uint16_t chksum = 0;
253   uint16_t v;
254   uint32_t i;
255   uint32_t j;
257   for (i = j = 0; i < nwords; i++, j+=2)  {
258     v = (p[j] << 8) | p[j+1];
259     chksum = netTest_utilOnesComplementAdd (chksum, v);
260   }
261   return (chksum);
262 } /* utilOnesCompChkSum */
264 /**************************************************************************************
265  * FUNCTION PURPOSE: Compute ipv4 psudo checksum
266  **************************************************************************************
267  * DESCRIPTION: Compute ipv4 psudo checksum
268  **************************************************************************************/
269 uint16_t netTest_utilGetIPv4PsudoChkSum (uint8_t *data, uint16_t payloadLen)
271   uint16_t psudo_chksum;
273   psudo_chksum = netTest_utilOnesCompChkSum (&data[12], 4);
274   psudo_chksum = netTest_utilOnesComplementAdd(psudo_chksum, (uint16_t) data[9]);
275   psudo_chksum = netTest_utilOnesComplementAdd(psudo_chksum, payloadLen);
277   return (psudo_chksum);
279 } /* utilGetIpv4PsudoChkSum */
281 #define CHECK_SET_PARAM(ARG1, ARG2)     \
282     do { \
283         if(strcmp(key, ARG1) == 0) { \
284         if(d1)strncpy(ARG2,d1,netTest_CONFIG_STRING_LEN); \
285         continue; \
286         } \
287     } while(0)
289 #define CHECK_SET_PARAM2(ARG1, ARG2,  ARG3)     \
290     do { \
291         if(strcmp(key, ARG1) == 0) { \
292         if(d1) strncpy(ARG2,d1,netTest_CONFIG_STRING_LEN); \
293         if(d2) strncpy(ARG3,d2,netTest_CONFIG_STRING_LEN); \
294         continue; \
295         } \
296     } while(0)
298 #define CHECK_SET_PARAM_SA(ARG1, ARG2, ARG3, ARG4, ARG5, \
299                                                    ARG6, ARG7, ARG8,  ARG9, ARG10, \
300                                                    ARG11, ARG12,ARG13, ARG14, ARG15, ARG16,ARG17, ARG18)     \
301     do { \
302         if(strcmp(key, ARG1) == 0) { \
303         if(d1) strncpy(ARG2,d1,netTest_CONFIG_STRING_LEN); \
304         if(d2) strncpy(ARG3,d2,netTest_CONFIG_STRING_LEN); \
305         if(d3) strncpy(ARG4,d3,netTest_CONFIG_STRING_LEN); \
306         if(d4) strncpy(ARG5,d4,netTest_CONFIG_STRING_LEN); \
307         if(d5) strncpy(ARG6, d5,netTest_CONFIG_STRING_LEN); \
308         if(d6) strncpy(ARG7,d6,netTest_CONFIG_STRING_LEN); \
309         if(d7) strncpy(ARG8,d7,netTest_CONFIG_STRING_LEN); \
310         if(d8) strncpy(ARG9,d8,netTest_CONFIG_STRING_LEN); \
311         if(d9) strncpy(ARG10,d9,netTest_CONFIG_STRING_LEN); \
312         if(d10) strncpy(ARG11,d10,netTest_CONFIG_STRING_LEN); \
313         if(d11) strncpy(ARG12,d11,netTest_CONFIG_STRING_LEN); \
314         if(d12) strncpy(ARG13,d12,netTest_CONFIG_STRING_LEN); \
315         if(d13) strncpy(ARG14,d13,netTest_CONFIG_STRING_LEN); \
316         if(d14) strncpy(ARG15,d14,netTest_CONFIG_STRING_LEN); \
317         if(d15) strncpy(ARG16,d15,netTest_CONFIG_STRING_LEN); \
318         if(d16) strncpy(ARG17,d16,netTest_CONFIG_STRING_LEN); \
319         if(d17) strncpy(ARG18,d17,netTest_CONFIG_STRING_LEN); \
320         continue; \
321         } \
322     } while(0)
324 void netTest_utilPrintIPSecStats(Sa_IpsecStats_t     *p_saIpsecStats, nwal_saAALG auth, nwal_saEALG cipher)
326 #if 0
327     if(retVal != nwal_OK)
328     {
329         System_System_netapi_Log("CORE: %d Error getting IP Sec Stats: Ret Status: %d \n",
330                        retVal);
331         return(nwal_FALSE);
332     }
333     if((p_saIpsecStats->pktEncHi) ||(p_saIpsecStats->pktEncLo))
334     {
335         Debug_netapi_Log("------------- IPSec TX (Encryption Channel) Stats BEGIN --\n");
336     }
337     else
338     {
339         netapi_Log("------------- IPSec RX (Decryption Channel) Stats BEGIN --\n");
340     }
341 #endif
342     printf("\nAutentication mode: %d, Encryption Mode: %d\n", auth, cipher);
343     printf("IPSec replayOld:0x%x,replayDup:0x%x,authFail:0x%x \n",
344                    p_saIpsecStats->replayOld,p_saIpsecStats->replayDup,p_saIpsecStats->authFail);
345     printf("IPSec txESN:0x%x,rxESN:0x%x,pktEncHi:0x%x,pktEncLo:0x%x,pktDecHi:0x%x,pktDecLo:0x%x \n",
346                    p_saIpsecStats->txESN,p_saIpsecStats->rxESN,p_saIpsecStats->pktEncHi,
347                    p_saIpsecStats->pktEncLo,p_saIpsecStats->pktDecHi,p_saIpsecStats->pktDecLo);
350 void netTest_utilPrintDataModeStats(Sa_DataModeStats_t     *p_saDataModeStats, nwal_saAALG auth, nwal_saEALG cipher)
353     printf("\nAutentication mode: %d, Encryption Mode: %d\n", auth, cipher);
354     printf(" Packets processedHi: 0x%x, Packets processed Lo:0x%x\n",
355             p_saDataModeStats->pktHi, p_saDataModeStats->pktLo);
358 /******************************************************
359  * stats callback
360  *******************************************************/
361 void netTest_utilStatsCbMt(NETAPI_T h, paSysStats_t* pPaStats)
364 #ifdef netTest_MULTI_THREAD
365     int coreid=Osal_nwalGetProcId();  //who we are(thread local)
366     //int coreid = our_core;
367 #else
368 int coreid=0;
369 #endif
371   stats[coreid].n_stats_cb +=1;
372   if(pPaStats) memcpy(&netcp_stats,pPaStats, sizeof(paSysStats_t));
374 void netTest_utilsStatsCb(NETAPI_T h, paSysStats_t* pPaStats)
376     uint32_t numFreeDataPackets;
377     uint32_t            numZeroBufferPackets;
378     uint32_t            numPacketsinGarbage;
379     Pktlib_HeapStats    pktLibHeapStats;
380     int i,j;
381     unsigned long long bcpp;
382     unsigned long long bcpp_noc;
383     unsigned long long bcpp_app;
384     unsigned long long bcpp_tx;
385     unsigned long long npL;
386     unsigned long long cyclesL;
387     unsigned long long ccyclesL; //cache cycles
388     unsigned long long tmp_npL[TUNE_NETAPI_NUM_CORES];
389     unsigned long long tmp_cyclesL[TUNE_NETAPI_NUM_CORES];
390     unsigned long long tmp_ccyclesL[TUNE_NETAPI_NUM_CORES]; //cache cycles
391     NETAPI_SA_STATS_T netapi_sa_stats;
393     uint8_t num_threads =  netTestCfg.num_fp_threads;
394     for (j= 0;j < num_threads;j++)
395     {
396         if (netTestCfg.fp_thread_num[j] == 0)
397             continue;
398         i = netTestCfg.fp_thread_num[j];
399         printf("Per THREAD Statistics for Thread %d\n", netTestCfg.fp_thread_num[j]);;
400         printf(">*****stats @ %lld (#cbs%d) \n", hplib_mUtilGetTimestamp(),stats[i].n_stats_cb);
401         printf(">itx=%d rx=%d tx=%d bad=%d slow=%d \n>rx_class0=%d rx_class1=%d rx_class2=%dsecRx=%d\t"
402             "secPRX=%d sb_rx=%d sb_tx=%d auth_ok=%d sec_tx=%d  min_rx=%d min_tx=%d  fragPkt=%d, exceptionPktOther=%d\n",
403          stats[i].itx, stats[i].rx, stats[i].tx, stats[i].n_bad, stats[i].n_new, 
404          stats[i].n_class0_rx, stats[i].n_class1_rx,  stats[i].n_class2_rx, stats[i].sec_rx,
405          stats[i].secp_rx, stats[i].sb_rx, stats[i].sb_tx, stats[i].n_auth_ok,
406          stats[i].sec_tx, stats[i].rx_min, stats[i].tx_min, stats[i].exceptionPktsFrag, stats[i].exceptionPktsOther);
407         printf(">if rx stats:  %d %d %d\n",stats[i].if_rx[0],stats[i].if_rx[1],stats[i].if_rx[2]);
408         printf(">thread rx stats:  %d \n",stats[i].core_rx);
410         if (stats[i].rx && stats[i].tx)
411             printf("decrypt time per packet(avg): %lu, encrypt  time per packet(avg): %lu\n", 
412             (unsigned long) stats[i].total_decrypt_time/stats[i].rx, (unsigned long) stats[i].total_encrypt_time/stats[i].tx);
415         if (npL && stats[i].rx)
416         {
417             bcpp = cyclesL/npL; 
418             bcpp_noc = (cyclesL-ccyclesL)/npL; 
419             bcpp_app = (stats[i].app_cycles-stats[i].tx_cache_cycles)/stats[i].rx;
420         }
421         else
422         {
423             bcpp = bcpp_noc=bcpp_app=0L;
424         }
425         if (stats[i].tx)
426         {
427             bcpp_tx = (stats[i].send_cycles-stats[i].tx_cache_cycles)/stats[i].tx;
428         }
429         else
430         {
431             bcpp_tx = 0L;
432         }
433         printf(">         ++ busy cycles pp=%lld (%lld wo cache ops) (app+tx= %lld) (tx= %lld) ++\n",
434          bcpp,bcpp_noc,bcpp_app, bcpp_tx);
435         printf("\n");
436     }
438 #ifdef netTest_MULTI_THREAD
439     for (i=0;i < TUNE_NETAPI_NUM_CORES;i++)
440     {
441         if(scheduler[i])
442         {
443             netapi_schedGetStats(scheduler[i],&tmp_npL[0],&tmp_cyclesL[0],&tmp_ccyclesL[0]);
444             npL = tmp_npL[0]+tmp_npL[1];
445             cyclesL = tmp_cyclesL[0]+tmp_cyclesL[1];
446             ccyclesL = tmp_ccyclesL[0]+tmp_ccyclesL[1];
447         }
448     }
449 #else
450 netapi_schedGetStats(our_sched, &npL,&cyclesL,&ccyclesL);
451 #endif
453 if(pPaStats)
455        printf("C1 number of packets:           %d\n", pPaStats->classify1.nPackets);
456        printf("C1 number IPv4 packets:         %d\n", pPaStats->classify1.nIpv4Packets);
457        printf("C1 number IPv6 packets:        %d\n", pPaStats->classify1.nIpv6Packets);
458        printf("C1 number Custom packets:        %d\n", pPaStats->classify1.nCustomPackets);
459        printf("C1 number SRIO packets:        %d\n", pPaStats->classify1.nSrioPackets);
460        printf("C1 number LLC/SNAP Fail packets:        %d\n", pPaStats->classify1.nLlcSnapFail);
461        printf("C1 number table matched:        %d\n", pPaStats->classify1.nTableMatch);
462        printf("C1 number failed table matched: %d\n", pPaStats->classify1.nNoTableMatch);
463        printf("C1 number IP Fragmented packets: %d\n", pPaStats->classify1.nIpFrag);
464        printf("C1 number IP Depth Overflow: %d\n", pPaStats->classify1.nIpDepthOverflow);
465        printf("C1 number VLAN Depth Overflow: %d\n", pPaStats->classify1.nVlanDepthOverflow);
466        printf("C1 number GRE Depth Overflow: %d\n", pPaStats->classify1.nGreDepthOverflow);
467        printf("C1 number MPLS Packets: %d\n", pPaStats->classify1.nMplsPackets);
468        printf ("C1 number of parse fail:        %d\n",pPaStats->classify1.nParseFail);
469        printf("C1 number of Invalid IPv6 Opt:  %d\n", pPaStats->classify1.nInvalidIPv6Opt);
470        printf("C1 number of TX IP Fragments:  %d\n", pPaStats->classify1.nTxIpFrag);
471        printf ("C1 number of silent discard:    %d\n",pPaStats->classify1.nSilentDiscard);
472        printf("C1 number of invalid control:   %d\n", pPaStats->classify1.nInvalidControl);
473        printf ("C1 number of invalid states:    %d\n",pPaStats->classify1.nInvalidState);
474        printf ("C1 number of system fails:      %d\n",pPaStats->classify1.nSystemFail);
475        printf ("C2 number Packets  :           %d\n",pPaStats->classify2.nPackets);
476        printf ("C2 number udp           :      %d\n",pPaStats->classify2.nUdp);
477        printf ("C2 number tcp           :      %d\n",pPaStats->classify2.nTcp);
478        printf ("C2 number Custom       :      %d\n",pPaStats->classify2.nCustom);
479        printf ("C2 number silent drop   :      %d\n",pPaStats->classify2.nSilentDiscard);
480        printf ("C2 number invalid cntrl :      %d\n\n",pPaStats->classify2.nInvalidControl);
481        printf ("C2 number Modify Stats Cmd Fail :      %d\n\n",pPaStats->modify.nCommandFail);
483 Pktlib_getHeapStats(ourHeap, &pktLibHeapStats);
484 printf("main heap stats>  #free=%d #zb=%d #garbage=%d\n", pktLibHeapStats.numFreeDataPackets,
485                                 pktLibHeapStats.numZeroBufferPackets, pktLibHeapStats.numPacketsinGarbage);
486 printf("               >  #dataBufThreshStatus=%d #dataBufStarvCounter=%d #zBufThreshStatus=%d #zBufStarvCounter=%d \n", 
487                         pktLibHeapStats.dataBufferThresholdStatus,pktLibHeapStats.dataBufferStarvationCounter,
488                         pktLibHeapStats.zeroDataBufferThresholdStatus, pktLibHeapStats.zeroDataBufferStarvationCounter);
490 #if 0
491 netapi_Log("pa2sa descriptor area dump\n");
492 for(i=0;i<TUNE_NETAPI_CONFIG_MAX_PA_TO_SA_DESC;i++)
494    extern long * pa2sa_descr_base;
495    long * tip= &pa2sa_descr_base[32*i]; 
496    netTest_utilDumpDescr(tip, i);
498 netapi_Log("sa2pa descriptor area dump\n");
499 for(i=0;i<TUNE_NETAPI_CONFIG_MAX_SA_TO_PA_DESC;i++)
501    extern long * sa2pa_descr_base;
502    long * tip= &sa2pa_descr_base[32*i]; 
503    netTest_utilDumpDescr(tip, i);
505 #endif
506     for (i = 0; i < netTestCfg.num_sa; i++)
507     {
508         /* Statistics for RX Tunnel */
509         memset(&netapi_sa_stats, 0, sizeof(netapi_sa_stats));
510         if (netTestCfg.sa[i].dir ==NWAL_SA_DIR_INBOUND )
511         {
512             netapi_getSaStats(netapi_handle, sa_info[i].rx_tunnel, &netapi_sa_stats);
513             if (netapi_sa_stats.validParams & NETAPI_IPSEC_STAT_VALID)
514             {
515                 netTest_utilPrintIPSecStats(&(netapi_sa_stats.saIpsecStats), 
516                                  netTestCfg.sa[i].authMode,
517                                  netTestCfg.sa[i].cipherMode);
518             }
519             if (netapi_sa_stats.validParams & NETAPI_SIDEBAND_DATA_MODE_STAT_VALID)
520             {
521                 netTest_utilPrintDataModeStats(&(netapi_sa_stats.dataModeStats),
522                                    netTestCfg.sa[i].authMode,
523                                    netTestCfg.sa[i].cipherMode);
524             }
525         }
526         else if (netTestCfg.sa[i].dir ==NWAL_SA_DIR_OUTBOUND)
527         {
528             netapi_getSaStats(netapi_handle, sa_info[i].tx_tunnel, &netapi_sa_stats);
529             if (netapi_sa_stats.validParams & NETAPI_IPSEC_STAT_VALID)
530             {
531                  netTest_utilPrintIPSecStats(&(netapi_sa_stats.saIpsecStats), 
532                                    netTestCfg.sa[i].authMode,
533                                    netTestCfg.sa[i].cipherMode);
534             }
535             if (netapi_sa_stats.validParams & NETAPI_SIDEBAND_DATA_MODE_STAT_VALID)
536             {
537                 netTest_utilPrintDataModeStats(&(netapi_sa_stats.dataModeStats),
538                                     netTestCfg.sa[i].authMode,
539                                     netTestCfg.sa[i].cipherMode);
540             }
541         }
542         else
543             netapi_Log("netTest_utilsStatsCb: invalid SA direction\n");
544     }
545     netapi_dump_internal_heap_stats();
551 void parse_dsp_mac(char * p_mac_str)
553     if (strlen(&p_mac_str[0]))
554     {
555         sscanf(p_mac_str,"mac%d",&netTestCfg.dsp_mac);
556     }
559 void parse_dsp_ip(char * p_ip_str)
561     if (strlen(&p_ip_str[0]))
562     {
563         sscanf(p_ip_str,"ip%d",&netTestCfg.dsp_ip);
564     }
567 void netTest_utilParseOneKey(char *p_key_str, unsigned char *p_key)
569     int index = 0;
570     int i;
571     if (strlen(&p_key_str[0]))
572     {
573         char * pch = strtok (&p_key_str[0],",");
575         while (pch != NULL)
576         {
577             p_key[index] = netTest_utilHex2Dec(pch);
578             index++;
579             pch = strtok (NULL,",");
580         }
581     }
584 void netTest_utilParseOneIP(char * p_ip_addr_str, unsigned char * p_ip)
586     int index = 0;
587     int i;
588     if (strlen(&p_ip_addr_str[0]))
589     {
590         char * pch = strtok (&p_ip_addr_str[0],".");
592         while (pch != NULL)
593         {
594             p_ip[index] = atoi(pch);
595             index++;
596             pch = strtok (NULL,".");
597         }
598     }
601 void netTest_utilParseOneMac(char * p_mac_str, unsigned char *p_mac)
603     int index = 0;
604     int i;
605     if (strlen(&p_mac_str[0]))
606     {
607         char *pch = strtok (&(p_mac_str[0]),"-");
609         while (pch != NULL)
610         {
611             p_mac[index] = netTest_utilHex2Dec(pch);
612             index++;
613             pch = strtok (NULL,"-");
614         }
615     }
618 void netTest_utilParseMac(netTestConfigFile_t *pConfig)
620     int i;
621     int port = 0;
622     for(i=0;i<NET_TEST_MAX_MAC;i++)
623     {
624         if (strlen(&pConfig->mac[i][0]))
625         {
626             netTestCfg.num_macs++;
627             netTest_utilParseOneMac(&pConfig->mac[i][0],&netTestCfg.mac[i][0]);
628             sscanf(&pConfig->switch_port[i][0],"swp%d",&netTestCfg.switch_port[i]);
629         }
630     }
631     netapi_Log("netTest_utilParseMac: number of mac address %d\n", netTestCfg.num_macs);
634 void netTest_utilParseIP(netTestConfigFile_t *pConfig)
636     int i;
638     for(i=0;i<NET_TEST_MAX_IP;i++)
639     {
640         if (strlen(&pConfig->ip[i][0]))
641         {
642             netTestCfg.num_ips++;
643             netTest_utilParseOneIP(&pConfig->ip[i][0],&netTestCfg.ip[i].ipv4[0]);
644             sscanf(&pConfig->attach_iface[i][0],"mac%d",&netTestCfg.attach_iface[i]);
645         }
646     }
647     netapi_Log("netTest_utilParseIP: number of ip address %d\n", netTestCfg.num_ips);
649 void netTest_utilParseIpsecMode(netTestConfigFile_t *pConfig)
652     if (strlen(&pConfig->ipsec_mode_rx[0]))
653     {
654         if (strcmp(pConfig->ipsec_mode_rx, "SIDEBAND") == 0)
655         {
656             netTestCfg.ipsec_mode_rx = IPSEC_MODE_RX_SIDEBAND;
657         }
658         else if (strcmp(pConfig->ipsec_mode_rx, "INFLOW") == 0)
659         {
660             netTestCfg.ipsec_mode_rx = IPSEC_MODE_RX_INFLOW;
661         }
662         else
663         {
664             netapi_Log("netTest_utilParseIpsecMode(), invalid RX ipsec mode in config file \n");
665         }
666     }
668     if (strlen(&pConfig->ipsec_mode_tx[0]))
669     {
670         if (strcmp(pConfig->ipsec_mode_tx, "SIDEBAND") == 0)
671         {
672             netTestCfg.ipsec_mode_tx = IPSEC_MODE_TX_SIDEBAND;
673         }
674         else if (strcmp(pConfig->ipsec_mode_tx, "INFLOW") == 0)
675         {
676             netTestCfg.ipsec_mode_tx = IPSEC_MODE_TX_INFLOW;
677         }
678         else
679         {
680             netapi_Log("netTest_utilParseIpsecMode(), invalid TX ipsec mode in config file \n");
681         }
682     }
686 void netTest_utilParseAuthMode(char *auth_mode_str, nwal_saAALG *auth_mode)
688     if (strlen(auth_mode_str))
689     {
690         netapi_Log("strlen of auth_mode_str is %d\n", strlen(auth_mode_str));
692         if (strcmp(auth_mode_str, "NULL") == 0)
693         {
694             *auth_mode= NWAL_SA_AALG_NULL;
695         }
696         else if (strcmp(auth_mode_str, "HMAC_MD5") == 0)
697         {
698             *auth_mode= NWAL_SA_AALG_HMAC_MD5;
699         }
700         else if (strcmp(auth_mode_str, "HMAC_SHA1") == 0)
701         {
702             *auth_mode= NWAL_SA_AALG_HMAC_SHA1;
703         }
704         else if (strcmp(auth_mode_str, "HMAC_SHA2_224") == 0)
705         {
706             *auth_mode= NWAL_SA_AALG_HMAC_SHA2_224;
707         }
708         else if (strcmp(auth_mode_str, "HMAC_SHA2_256") == 0)
709         {
710             *auth_mode= NWAL_SA_AALG_HMAC_SHA2_256;
711         }
712         else if (strcmp(auth_mode_str, "GMAC") == 0)
713         {
714             *auth_mode= NWAL_SA_AALG_GMAC;
715         }
716         else if (strcmp(auth_mode_str, "AES_XCBC") == 0)
717         {
718             *auth_mode= NWAL_SA_AALG_AES_XCBC;
719         }
720         else
721         {
722             netapi_Log("netTest_utilParseAuthMode: invalid auth mode specified\n");
723         }
724     }
727 void netTest_utilParseEncryptMode(char *ency_mode_str, nwal_saEALG*encr_mode)
729     if (strlen(ency_mode_str))
730     {
731         if (strcmp(ency_mode_str, "NULL") == 0)
732         {
733             *encr_mode= NWAL_SA_EALG_NULL;
734         }
735         else if (strcmp(ency_mode_str, "AES_CTR") == 0)
736         {
737             *encr_mode= NWAL_SA_EALG_AES_CTR;
738         }
739         else if (strcmp(ency_mode_str, "AES_CBC") == 0)
740         {
741             *encr_mode= NWAL_SA_EALG_AES_CBC;
742         }
743         else if (strcmp(ency_mode_str, "3DES_CBC") == 0)
744         {
745             *encr_mode= NWAL_SA_EALG_3DES_CBC;
746         }
747         else if (strcmp(ency_mode_str, "AES_CCM") == 0)
748         {
749             *encr_mode= NWAL_SA_EALG_AES_CCM;
750         }
751         else if (strcmp(ency_mode_str, "AES_GCM") == 0)
752         {
753             *encr_mode= NWAL_SA_EALG_AES_GCM;
754         }
755         else if (strcmp(ency_mode_str, "AES_XCBC") == 0)
756         {
757             *encr_mode= NWAL_SA_AALG_AES_XCBC;
758         }
759         else
760         {
761             netapi_Log("netTest_utilParseEncryptMode: invalid auth mode specified\n");
762         }
763     }
766 void netTest_utilParseProto(char *proto_str, nwal_IpSecProto *proto)
768     if (strlen(proto_str))
769     {
770         if (strcmp(proto_str, "ESP") == 0)
771         {
772             *proto= nwal_IpSecProtoESP;
773             netapi_Log("netTest_utilParseProto(): setting proto  to ESP\n");
774         }
775         else if (strcmp(proto_str, "AH") == 0)
776         {
777             *proto = nwal_IpSecProtoAH;
778             netapi_Log("netTest_utilParseProto(): setting proto to AH\n");
779         }
780         else
781         {
782             netapi_Log("netTest_utilParseProto(), invalid RX ipsec mode in config file \n");
783         }
784     }
789 void netTest_utilParseSaMode(char *mode_str, nwal_saMode *mode)
791     if (strlen(mode_str))
792     {
793         if (strcmp(mode_str, "TUNNEL") == 0)
794         {
795             *mode= nwal_SA_MODE_TUNNEL;
796         }
797         else if (strcmp(mode_str, "TRANSPORT") == 0)
798         {
799             *mode = nwal_SA_MODE_TRANSPORT;
800         }
801         else
802         {
803             netapi_Log("netTest_utilParseSaMode(), invalid RX ipsec mode in config file \n");
804         }
805     }
808 void netTest_utilParseIPType(char *ip_type_str, nwal_IpType *ipType)
810     if (strlen(ip_type_str))
811     {
812         if (strcmp(ip_type_str, "IPV4") == 0)
813         {
814             *ipType= nwal_IPV4;
815         }
816         else if (strcmp(ip_type_str, "IPV6") == 0)
817         {
818             *ipType = nwal_IPV6;
819         }
820         else
821         {
822             netapi_Log("netTest_utilParseIPType(), invalid RX ipsec mode in config file \n");
823         }
824     }
827 void parse_simple_param_u16(char* input_str, uint16_t *val)
829     if (strlen(input_str))
830     {
831         *val = (uint16_t)strtol(input_str, NULL, 0);
832     }
835 void parse_simple_param_u32(char* input_str, uint32_t *val)
837     if (strlen(input_str))
838     {
839         *val = (uint32_t)strtol(input_str, NULL, 0);
840     }
843 void netTest_utilParseSADir(char* dir_str, nwal_SaDir *dir)
845     if (strlen(dir_str))
846     {
847         if (strcmp(dir_str, "INBOUND") == 0)
848         {
849             *dir= NWAL_SA_DIR_INBOUND;
850         }
851         else if (strcmp(dir_str, "OUTBOUND") == 0)
852         {
853             *dir = NWAL_SA_DIR_OUTBOUND;
854         }
855         else
856             netapi_Log("netTest_utilParseSADir: invalid direction\n");
857     }
859 void netTest_utilParseThreadConfig(char * p_thread_str, uint8_t* start, uint8_t* end)
861     int index = 0;
862     int i;
864     if (strlen(p_thread_str))
865     {
866         char *pch = strtok (&(p_thread_str[0]),"-");
867         *start = atoi(pch);
868         pch = strtok (NULL,"-");
869         *end = atoi(pch);
870         netapi_Log("netTest_utilParseThreadConfig: start %d, end %d\n", *start, *end);
871     }
874 void netTest_utilParseThreadParams(netTestConfigFile_t *pConfig)
876     int i;
877     for(i=0;i<NET_TEST_MAX_FP_THREAD;i++)
878     {
879         if (strlen(&pConfig->fp[i][0]))
880         {
881             netTestCfg.num_fp_threads++;
882             netTest_utilParseThreadConfig(&pConfig->fp[i][0],
883                                          (uint8_t*)&netTestCfg.fp_proc_start[i],
884                                          (uint8_t*)&netTestCfg.fp_proc_end[i]);
885             netapi_Log("netTest_utilParseThreadParams: fp start[%d]: %d, fp end[%d]: %d\n",
886                     i,
887                     netTestCfg.fp_proc_start[i],
888                     i,
889                     netTestCfg.fp_proc_end[i]);
890         }
891         if (strlen(&pConfig->fp_thread_num[i][0]))
892         {
893             netTestCfg.fp_thread_num[i] = atoi((char*)(&pConfig->fp_thread_num[i]));
894             netapi_Log("parse_fp: thread_num[%d]: %d\n", i, netTestCfg.fp_thread_num[i]);
895         }
896     }
897     netapi_Log("parse_fp: number of fp threads  %d\n", netTestCfg.num_fp_threads);
899     for(i=0;i<NET_TEST_MAX_SP_THREAD;i++)
900     {
901         if (strlen(&pConfig->sp[i][0]))
902         {
903             netTestCfg.num_sp_threads++;
904             netTest_utilParseThreadConfig(&pConfig->sp[i][0],
905                                          (uint8_t*)&netTestCfg.sp_proc_start[i],
906                                          (uint8_t*)&netTestCfg.sp_proc_end[i]);
907         }
908         if (strlen(&pConfig->sp_thread_num[i][0]))
909         {
910             netTestCfg.sp_thread_num[i] = atoi((char*)(&pConfig->sp_thread_num[i]));
911             netapi_Log("parse_sp: thread_num[%d]: %d\n", i, netTestCfg.sp_thread_num[i]);
912         }
913     }
914     netapi_Log("parse_sp: number of sp threads  %d\n", netTestCfg.num_sp_threads);
916 void netTest_utilParseSA(netTestConfigFile_t *pConfig)
918     int i;
919     for(i=0;i<MAX_SEC_INDEX;i++)
920     {
921         if (strlen((char*)&pConfig->sa_config[i][0].dir))
922         {
923             netTest_utilParseSADir((char*) &pConfig->sa_config[i][0].dir, &netTestCfg.sa[i].dir);
924             parse_simple_param_u32((char*)&pConfig->sa_config[i][0].spi, &netTestCfg.sa[i].spi);
925             netTest_utilParseProto((char*)&pConfig->sa_config[i][0].proto, &netTestCfg.sa[i].proto);
926             netTest_utilParseSaMode((char*)&pConfig->sa_config[i][0].saMode, &netTestCfg.sa[i].saMode);
927             netTest_utilParseIPType((char*)&pConfig->sa_config[i][0].ipType, &netTestCfg.sa[i].ipType);
928             netTest_utilParseOneIP((char*)&pConfig->sa_config[i][0].src, (unsigned char *)&netTestCfg.sa[i].src);
929             netTest_utilParseOneIP((char*)&pConfig->sa_config[i][0].dst, (unsigned char *)&netTestCfg.sa[i].dst);
930             parse_simple_param_u32((char*)&pConfig->sa_config[i][0].replayWindow, &netTestCfg.sa[i].replayWindow);
931             netTest_utilParseAuthMode((char*)&pConfig->sa_config[i][0].authMode, &netTestCfg.sa[i].authMode);
932             netTest_utilParseEncryptMode((char*)&pConfig->sa_config[i][0].cipherMode, &netTestCfg.sa[i].cipherMode);
933             parse_simple_param_u32((char*)&pConfig->sa_config[i][0].esnLo, &netTestCfg.sa[i].esnLo);
934             parse_simple_param_u32((char*)&pConfig->sa_config[i][0].esnHi, &netTestCfg.sa[i].esnHi);
935             parse_simple_param_u16((char*)&pConfig->sa_config[i][0].encKeySize, &netTestCfg.key_params[i].encKeySize);
936             parse_simple_param_u16((char*)&pConfig->sa_config[i][0].macKeySize, &netTestCfg.key_params[i].macKeySize);
939             netTest_utilParseOneKey((char*) &pConfig->sa_config[i][0].encr_key, &netTestCfg.encr_key[i][0]);
940             netTestCfg.key_params[i].pEncKey = (uint8_t*)&netTestCfg.encr_key[i][0];
942             netTest_utilParseOneKey((char*)&pConfig->sa_config[i][0].auth_key, &netTestCfg.auth_key[i][0]);
943             netTestCfg.key_params[i].pAuthKey= (uint8_t*)&netTestCfg.auth_key[i][0];
946             parse_simple_param_u32((char*)&pConfig->sa_config[i][0].tunnel_id, &netTestCfg.tunnel_id[i]);
948             netTestCfg.num_sa++;
949         }
950     }
952 void netTest_utilParseRoutes(netTestConfigFile_t *pConfig, OUR_ROUTE_T *routes, Trie ** our_router)
954     int i;
955     int said=0;
956     for(i=0;i<MAX_ROUTES;i++)
957     {
958         int port;
959         if (pConfig->routes[i][0])
960         {
961             port=atoi(&pConfig->ports[i][0]);
962             if((port<1)||(port>2)) continue; //bad port #: only 1 or 2 valid
963             netapi_Log("netTest_utilParseRoutes [%d]: %s\n", i, &pConfig->routes[i][0]);
964             if(strncmp(&pConfig->routes[i][0],"MAC",3)==0)
965             {
966                routes[i].out_port = port;
967                netTest_utilParseOneMac(&pConfig->routes[i][3],&routes[i].out_mac[0]);
968                //memcpy(&routes[i].out_mac[6], ((port==1) ?&config.mac0[0]: &config.mac1[0] ),6); 
969                memcpy(&routes[i].out_mac[6], ((port==1) ?&netTestCfg.mac[0][0]: &netTestCfg.mac[1][0] ),6);
970                routes[i].out_mac[12]=0x08;
971                routes[i].out_mac[13]=0x00;
972                routes[i].sec_ptr=NULL;
973             }
974             else if (strncmp(&pConfig->routes[i][0],"SA",2)==0)
975             {      
976                said=atoi(&pConfig->routes[i][2]) ;
977                routes[i].sec_ptr=&sa_info[said];
978             }
979         }
980     }
981     *our_router = route_init();
982     for (i=0;i<MAX_ROUTES;i++)
983     {
984       unsigned long ip_be;
985       int route_index;
986       if (pConfig->dst_ips[i][0])
987       {
988          netTest_utilParseOneIP(&pConfig->dst_ips[i][0],(unsigned char *)&ip_be);
989          sscanf(&pConfig->paths[i][0],"route%d",&route_index);
990          route_add(*our_router,&ip_be,(void*)&routes[route_index]);
991       }
992     }
995 void netTest_utilProcessConfigFile(FILE * fpr, netTestConfigFile_t *pConfig)
997     char line[MAX_LINE_LENGTH + 1];
998     int i;
999     static int sa_count = 0;
1000  
1001     char *key, *ep;
1002     char * d1, *d2, *d3, *d4;
1003     char * d5, *d6, *d7, *d8;
1004     char * d9, *d10, *d11, *d12;
1005     char * d13, *d14, *d15, *d16, *d17;
1006     char tokens[] = " :=;\n";
1007     char temp_str[50];
1008     memset(line, 0, MAX_LINE_LENGTH + 1);
1009     memset(pConfig, 0, sizeof(netTestConfigFile_t));
1010     while (fgets(line, MAX_LINE_LENGTH + 1, fpr))
1011     {
1012         if(line[0]=='#')
1013             continue; //skip comment
1014         key  = (char *)strtok(line, tokens);
1016         d1 = (char *)strtok(NULL, tokens);
1017         if (!key)
1018             continue;
1019         if (!d1) 
1020             continue;
1022         if(strlen(d1) == 0) 
1023         {
1024             continue;
1025         }
1028         d2 = (char *)strtok(NULL, tokens);
1029         d3 = (char *)strtok(NULL, tokens);
1030         d4 = (char *)strtok(NULL, tokens);
1031         d5 = (char *)strtok(NULL, tokens);
1032         d6 = (char *)strtok(NULL, tokens);
1033         d7 = (char *)strtok(NULL, tokens);
1034         d8 = (char *)strtok(NULL, tokens);
1035         d9 = (char *)strtok(NULL, tokens);
1036         d10 = (char *)strtok(NULL, tokens);
1037         d11 = (char *)strtok(NULL, tokens);
1038         d12 = (char *)strtok(NULL, tokens);
1039         d13 = (char *)strtok(NULL, tokens);
1040         d14 = (char *)strtok(NULL, tokens);
1041         d15 = (char *)strtok(NULL, tokens);
1042         d16 = (char *)strtok(NULL, tokens);
1043         d17 = (char *)strtok(NULL, tokens);
1045         CHECK_SET_PARAM(netTest_INIT_CONFIG_IPSEC_MODE_RX,&(pConfig->ipsec_mode_rx[0]));
1046         CHECK_SET_PARAM(netTest_INIT_CONFIG_IPSEC_MODE_TX,&(pConfig->ipsec_mode_tx[0]));
1047         CHECK_SET_PARAM(netTest_INIT_CONFIG_IPSEC_IF_NO,&(pConfig->ipsec_if_no[0]));
1048         CHECK_SET_PARAM(netTest_INIT_CONFIG_DSP_MAC,&(pConfig->dsp_mac[0]));
1049         CHECK_SET_PARAM(netTest_INIT_CONFIG_DSP_IP,&(pConfig->dsp_ip[0]));
1050         CHECK_SET_PARAM(netTest_INIT_CONFIG_STATIC_LOOPBACK_PORT,&(pConfig->dest_udp_port_config[0]));
1053         for(i=0;i<MAX_SEC_INDEX;i++)
1054         {
1055             sprintf(temp_str,"sa%d",i);
1056             CHECK_SET_PARAM_SA(temp_str, 
1057                               (char*)&pConfig->sa_config[i][0].dir,
1058                               (char*)&pConfig->sa_config[i][0].spi,
1059                               (char*)&pConfig->sa_config[i][0].proto,
1060                               (char*)&pConfig->sa_config[i][0].saMode,
1061                               (char*)&pConfig->sa_config[i][0].ipType,
1062                               (char*)&pConfig->sa_config[i][0].src,
1063                               (char*)&pConfig->sa_config[i][0].dst,
1064                               (char*)&pConfig->sa_config[i][0].replayWindow,
1065                               (char*)&pConfig->sa_config[i][0].authMode,
1066                               (char*)&pConfig->sa_config[i][0].cipherMode,
1067                               (char*)&pConfig->sa_config[i][0].esnLo,
1068                               (char*)&pConfig->sa_config[i][0].esnHi,
1069                               (char*)&pConfig->sa_config[i][0].encKeySize,
1070                               (char*)&pConfig->sa_config[i][0].macKeySize,
1071                               (char*)&pConfig->sa_config[i][0].encr_key,
1072                               (char*)&pConfig->sa_config[i][0].auth_key,
1073                               (char*)&pConfig->sa_config[i][0].tunnel_id);
1074         }
1076         for(i=0;i<MAX_ROUTES;i++)
1077         {
1078             sprintf(temp_str,"route%d",i);
1079             CHECK_SET_PARAM2(temp_str,&pConfig->routes[i][0],&pConfig->ports[i][0] );
1080         }
1082         for(i=0;i<MAX_ROUTES;i++)
1083         {
1084             sprintf(temp_str,"dstip%d",i);
1085             CHECK_SET_PARAM2(temp_str,&pConfig->dst_ips[i][0],&pConfig->paths[i][0] );
1086         }
1087         for(i=0;i<NET_TEST_MAX_MAC;i++)
1088         {
1089             sprintf(temp_str,"mac%d",i);
1090             CHECK_SET_PARAM2(temp_str,&pConfig->mac[i][0],&pConfig->switch_port[i][0] );
1091         }
1092         for(i=0;i<NET_TEST_MAX_IP;i++)
1093         {
1094             sprintf(temp_str,"ip%d",i);
1095             CHECK_SET_PARAM2(temp_str,&pConfig->ip[i][0], &pConfig->attach_iface[i][0]);
1096         }
1097         for(i=0;i<NET_TEST_MAX_FP_THREAD;i++)
1098         {
1099             sprintf(temp_str,"fp%d",i);
1100             CHECK_SET_PARAM2(temp_str, &pConfig->fp_thread_num[i][0],&pConfig->fp[i][0]);
1101         }
1102         for(i=0;i<NET_TEST_MAX_SP_THREAD;i++)
1103         {
1104             sprintf(temp_str,"sp%d",i);
1105             CHECK_SET_PARAM2(temp_str, &pConfig->sp_thread_num[i][0],&pConfig->sp[i][0]);
1106         }
1107     }
1110 //******************************************************
1111 //use scheduling housekeeping callback to generate pkts
1112 //******************************************************
1113 static int done_burst=0;
1114 void house(NETAPI_SCHED_HANDLE_T * s)
1116     Ti_Pkt * tip;
1117     unsigned int len;
1118     nwalTxPktInfo_t meta_tx = {0};
1119     PKTIO_METADATA_T meta = {PKTIO_META_TX,{0},0};
1120     int err;
1121     static int house_pkts_gened=0;
1122     int p;
1123     unsigned char * pIpHdr,* pData;
1124     unsigned int vv1,vv2,vv3;
1125     unsigned int sum_vv1=0;
1126     unsigned int sum_vv2=0;
1127     unsigned int sum_vv3=0;
1128     unsigned int sum_vv4=0;
1129     unsigned int sum_vv5=0;
1131     unsigned int nwal_flow_vv1,nwal_flow_vv2;
1132     unsigned int nwal_sum_vv1=0;
1133     unsigned int nwal_sum_vv2=0;
1134     unsigned int nwal_sum_vv3=0;
1135     unsigned int nwal_sum_vv4=0;
1136     unsigned int nwal_sum_vv5=0;
1137     unsigned int nwal_sum_vv6=0;
1139     unsigned int nwal_sum_flow_vv1=0;
1140     unsigned int nwal_sum_flow_vv2=0;
1141     unsigned long long cache_op_b1;
1142     unsigned long long  cache_op_b2;
1143     unsigned long long  n_c_ops;
1144     static int first =0;
1145     Cppi_HostDesc*      pPktDesc;
1146     NETAPI_SCHED_SHUTDOWN_T sched_shutdown;
1148     uint32_t coreid = 0;  //who we are
1149 #ifdef netTest_MULTI_THREAD
1150     NETAPI_T nh= netapi_schedGetHandle(s);
1151     coreid=(uint32_t) netapi_getCookie(nh);
1153     if (QUIT) 
1154     {
1155         sched_shutdown.shutdown_type = NETAPI_SCHED_SHUTDOWN_NOW;
1156         netapi_schedClose(s,&sched_shutdown,&err); 
1157         return;
1158     }
1160     
1161     /* only slow path threads get netcp stats */
1162     if (coreid & NET_TEST_SP_THREAD_MASK)
1163     {
1164         netapi_netcpCfgReqStats(nh, netTest_utilStatsCbMt, 0,&err); 
1165     }
1167     coreid = NET_TEST_THREAD_NUM_MASK & coreid;
1168 #else
1169     coreid = NET_TEST_THREAD_NUM_MASK & coreid;
1170     if(done_burst)
1171     {
1172         house_pkts_gened+=TX_BURST;
1173         netapi_Log("net_test> request stats at n=%d \n",house_pkts_gened);
1174         netapi_netcpCfgReqStats(netapi_handle, netTest_utilsStatsCb, 0,&err);
1175         if (err!=0) {netapi_Log("stats req failed\n");}
1176         if (house_pkts_gened >= np2process+ 100)
1177         {
1178             sched_shutdown.shutdown_type = NETAPI_SCHED_SHUTDOWN_NOW;
1179             netapi_schedClose(s,&sched_shutdown,&err);
1180         }
1181         return;
1182     }
1183     done_burst=1;
1184     Osal_cache_op_measure_reset();
1185     memset(&meta_tx,0,sizeof(meta_tx));
1186     for(p=0;p<TX_BURST;p++) {  
1187     //reguest stats 
1188     if ((house_pkts_gened>0) && (! (house_pkts_gened%1000)) )
1189     {
1190        netapi_Log("net_test> request stats at n=%d \n",house_pkts_gened);
1191        netapi_netcpCfgReqStats(netapi_handle, netTest_utilsStatsCb, 0,&err); 
1192        if (err!=0) {netapi_Log("stats req failed\n");}
1193     }
1196     if (house_pkts_gened >= np2process+ 100)
1197     {
1198         //shutdown
1199         sched_shutdown.shutdown_type = NETAPI_SCHED_SHUTDOWN_NOW;
1200         netapi_schedClose(s,&sched_shutdown,&err);
1201         continue;
1202     }
1204     else if (house_pkts_gened >= np2process) { house_pkts_gened+=1;  continue;}
1206     /* manufacture a pkt to transmit */
1207     tip = get_pkt(house_pkts_gened, &len, ourHeap, netTest_PKT_LEN,&testPkt[0]  , TEST_netTest_PKT_LEN);
1208     if(!tip) { house_pkts_gened +=1; continue; }
1211     /* set the pkt length */
1212     vv1 = hplib_mUtilGetPmuCCNT();
1213     Pktlib_setPacketLen(tip, len);
1215     /* set up meta data */
1216     meta.sa_handle=nwal_HANDLE_INVALID;
1217     /* #define BENCH_UDP_SEND */
1218 #ifdef BEND_UDP_SEND
1219     meta_tx.txFlag1 = (NWAL_TX_FLAG1_DO_IPV4_CHKSUM | NWAL_TX_FLAG1_DO_UDP_CHKSUM| NWAL_TX_FLAG1_META_DATA_VALID);
1220     meta_tx.startOffset = 0;
1221     /* GONE in V2 meta_tx.pktLen = len; */
1222     meta_tx.ipOffBytes = TEST_PKT_IP_OFFSET_BYTES;
1223     meta_tx.l4OffBytes = TEST_PKT_UDP_OFFSET_BYTES;
1224     meta_tx.l4HdrLen = TEST_PKT_UDP_HDR_LEN;
1225     //GONE in V2 meta_tx.ploadOffBytes = TEST_PKT_PLOAD_OFFSET_BYTES;
1226     meta_tx.ploadLen = TEST_PAYLOAD_LEN;
1228     Pktlib_getDataBuffer(tip,&pData,&len);
1229     if(house_pkts_gened &0x1)
1230     {
1231         memcpy(&pData[6],&netTestCfg.mac[1][0] ,6);
1232     }
1233     pIpHdr = pData + meta_tx.ipOffBytes;
1234     meta_tx.pseudoHdrChecksum =
1235         netTest_utilGetIPv4PsudoChkSum(pIpHdr,(TEST_PAYLOAD_LEN+TEST_PKT_UDP_HDR_LEN));
1236 #else
1237     Pktlib_getDataBuffer(tip,&pData,&len);
1238     if(house_pkts_gened &0x1)
1239     {
1240         memcpy(&pData[6],&netTestCfg.mac[1][0] ,6);
1241     }
1242     meta_tx.txFlag1 = NWAL_TX_FLAG1_META_DATA_VALID;
1243     meta_tx.startOffset = 0;
1244     meta_tx.ploadLen = TEST_PAYLOAD_LEN;
1245 #endif
1246    /* post it to netcp tx channel*/
1247    meta.u.tx_meta=&meta_tx;
1248 #ifdef DEBUG_DESC
1249     if (house_pkts_gened<16) netTest_utilDumpDescr((long *) tip, house_pkts_gened);
1250     else if (house_pkts_gened>99) netTest_utilDumpDescr((long *) tip,house_pkts_gened);
1251 #endif
1253     if(!first)
1254     {
1255         first++;
1256         nwal_flow_vv1= hplib_mUtilGetPmuCCNT();
1257         if(nwal_initPSCmdInfo(pktio_mGetNwalInstance(netcp_tx_chan),
1258                              &meta_tx,
1259                              &flowPSCmdInfo) != nwal_OK)
1260         {
1261             netapi_Log("nwal_initPSCmdInfo() ERROR \n");
1262         }
1263         nwal_flow_vv2= hplib_mUtilGetPmuCCNT();
1264         nwal_sum_flow_vv1 += (nwal_flow_vv1-vv1); 
1265         nwal_sum_flow_vv2 += (nwal_flow_vv2-nwal_flow_vv1); 
1266     }
1267     cache_op_b1= Osal_cache_op_measure(&n_c_ops);
1268     vv2= hplib_mUtilGetPmuCCNT();
1269 #ifdef BEND_UDP_SEND
1270     nwal_mCmdSetL4CkSumPort(  tip,
1271                              &flowPSCmdInfo,
1272                              TEST_PKT_UDP_OFFSET_BYTES,
1273                              (TEST_PKT_UDP_HDR_LEN + TEST_PAYLOAD_LEN),
1274                              meta_tx.pseudoHdrChecksum,
1275                              meta_tx.enetPort);
1276 #else
1277     nwal_mCmdSetPort  (tip,
1278                       &flowPSCmdInfo,  //could be NULL
1279                       0);  //port 0 -> switch decides
1281 #endif
1283     pPktDesc = Pktlib_getDescFromPacket(tip);
1284     /* Send the packet out to transmit Q*/
1285     Qmss_queuePushDescSize (flowPSCmdInfo.txQueue, 
1286                         pPktDesc, 
1287                         NWAL_DESC_SIZE);
1288     vv3= hplib_mUtilGetPmuCCNT();
1289     cache_op_b2= Osal_cache_op_measure(&n_c_ops);
1291     sum_vv1 += (vv2-vv1);
1292     if(!house_pkts_gened)
1293     {
1294         /* first packet. Take out the PS command label creation cost */
1295         sum_vv1 = sum_vv1 - nwal_sum_flow_vv2;
1296     }
1298     sum_vv3 += (vv3-vv2)-(long) (cache_op_b2-cache_op_b1); //sub out cache op cost
1300     // netapi_Log("pktio send. full=%d metadata=%d netapi_pktioSend=%d\n", vv3-vv1,  vv2-vv1,  vv3-vv2);
1301     stats[coreid].itx +=1;
1302     house_pkts_gened +=1;
1303     }
1304     {
1305         unsigned long long  ccycles;
1306         ccycles =Osal_cache_op_measure(&n_c_ops);
1307         if (sum_vv1) 
1308         {
1309             netapi_Log("BURST NWAL Fast send %d pkts.  metadata=%d Cmd Label Creation Cost=%d  nwal Fast Send Cost (less cacheop)= %d n_c_ops=%lld cache_op_time=%lld (pp-> %d)\n", 
1310               stats[coreid].itx, sum_vv1/stats[coreid].itx,  nwal_sum_flow_vv2, sum_vv3/stats[coreid].itx, 
1311               n_c_ops, ccycles, n_c_ops? (ccycles/(n_c_ops/2L)) : 0);
1312 #if 0
1313             netapi_Log("NWAL Profile Cycles: Prof1= %d,Prof2=%d,Prof3=%d,Prof4=%d,Prof5=%d ,Prof6=%d \n",
1314               nwal_sum_vv1/stats[coreid].itx,nwal_sum_vv2/stats[coreid].itx,nwal_sum_vv3/stats[coreid].itx,
1315               nwal_sum_vv4/stats[coreid].itx,nwal_sum_vv5/stats[coreid].itx,nwal_sum_vv6/stats[coreid].itx);
1316   
1317 #endif  
1319             if(stats[core_id].itx2)
1320             {
1321                 netapi_Log("nwal_flowSend Profile Cycles: Prof1= %d,Prof2=%d \n",
1322                 nwal_sum_flow_vv1/stats[coreid].itx2,nwal_sum_flow_vv2/stats[coreid].itx2);
1323             }
1324         }
1325     }
1326 #endif
1329 void netTest_utilCreateInterfaces(uint8_t num_macs, uint8_t num_ips)
1331     int err, i;
1333     for (i = 0; i < num_macs; i++)
1334     {
1335         /* add mac intefaces */
1336         mac[i] = netapi_netcpCfgCreateMacInterface(
1337                           netapi_handle,
1338                           &netTestCfg.mac[i][0],
1339                           i,
1340                           netTestCfg.switch_port[i],
1341                           (NETCP_CFG_ROUTE_HANDLE_T)  NULL,
1342                           (NETCP_CFG_VLAN_T ) NULL ,  //future
1343                           1, 
1344                           &err);
1345        if (err)
1346        {
1347             netapi_Log("addmac %d  failed %d\n",i, err);
1348         //exit(1); 
1349        }
1350        else
1351         netapi_Log("netTest_utilCreateInterfaces, added mac sucess\n");
1352     }
1353     for (i = 0; i < num_ips; i++)
1354     {
1355         //attach an IP to this interface
1356         ip_rule[i]=netapi_netcpCfgAddIp(
1357                           netapi_handle,
1358                           netTestCfg.attach_iface[i],
1359                           nwal_IPV4,
1360                           (nwalIpAddr_t*)&netTestCfg.ip[i].ipv4[0],
1361                           NULL,  //all IP
1362                           (NETCP_CFG_ROUTE_HANDLE_T) NULL,
1363                           (void*)NULL,
1364                           &err
1365                           );
1366         if (err) {
1367             netapi_Log("netTest_utilCreateInterfaces: add ip %d failed %d\n", i, err);
1368         //exit(1); 
1369         }
1370         else
1371             netapi_Log("netTest_utilCreateInterfaces, added ip sucess\n");
1372     }
1375 void netTest_utilDeleteInterfaces(uint8_t num_macs, uint8_t num_ips)
1377     int err,i;
1378     //delete IPs and MAC Interfacess
1379     for (i = 0; i < num_ips; i++)
1380     {
1381         err = 0;
1382         netapi_netcpCfgDelIp(netapi_handle, netTestCfg.attach_iface[i], nwal_IPV4, 
1383                       NULL, NULL, ip_rule[i], &err);
1384     }
1385     for (i = 0; i < num_macs; i++)
1386     {
1387         err = 0;
1388         netapi_netcpCfgDelMac(netapi_handle,i,&err);
1389     }
1390     
1391     //netapi_netcpCfgDelMac(netapi_handle,0,&err);
1392     //netapi_netcpCfgDelMac(netapi_handle,1,&err);