]> Gitweb @ Texas Instruments - Open Source Git Repositories - git.TI.com/gitweb - keystone-rtos/netapi.git/blob - ti/runtime/netapi/test/net_test_utils.c
SDOCM00113322: kernel RX UDP/TCP checksum offload to NETCP breaks user space tranport...
[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     printf(">net_test: recv'd signal %d cnt=%d\n",x,scnt);
111     if (scnt > 10)
112     {
113         printf(">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     printf("--------dump of descriptor %d %x\n", n, (int) p);
124     printf("> %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     printf("> %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     printf("-----------------------------\n");
128 void netTest_utilDumpHeader(unsigned long *p, int n, int a, int r)
130     printf("--------dump of header %d %x appID=%x flag1=%x\n", n, (int) p,a,r);
131     printf("> %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     printf("> %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     printf("> %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     printf("> %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     printf("-----------------------------\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     printf("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                 printf("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                 printf("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                 printf("netapi *: %02d : %02x    %02x \n",
191                       count,tmp_buf[0],tmp_buf[1]);
192                 break;
193             }
195             case 1:
196             {
197                 printf("netapi *: %02d : %02x \n",
198                       count,tmp_buf[0]);
199                 break;
200             }
202         }
204         tmp_buf = tmp_buf + row_count;
205         count = count +  row_count;
207     }while(count < dump_size);
209     printf("netapi *:  - Byte hex Dump End \n");
212 long netTest_utilHtonl(long x)
214     long temp = (x&0xff000000)>>24 | (x&0xff0000)>>8 | (x&0xff00)<<8 |  (x&0xff)<<24 ;
215     return temp;
218 unsigned char netTest_utilHex2Dec(char *p_s)
220     int val;
221     sscanf(p_s,"%x",&val); 
222     return val&0xff;
225 /********************************************************************
226  *  FUNCTION PURPOSE: Ones complement addition utility
227  ********************************************************************
228  ********************************************************************/
229 uint16_t netTest_utilOnesComplementAdd (uint16_t v1, uint16_t v2)
231   uint32_t result;
233   result = (uint32_t)v1 + (uint32_t)v2;
234   result = (result >> 16) + (result & 0xffff);
235   result = (result >> 16) + (result & 0xffff);
237   return ((uint16_t)result);
240 /********************************************************************
241  *  FUNCTION PURPOSE: Ones complement checksum utility
242  ********************************************************************
243  ********************************************************************/
244  uint16_t netTest_utilOnesCompChkSum  (uint8_t *p, uint32_t nwords)
246   uint16_t chksum = 0;
247   uint16_t v;
248   uint32_t i;
249   uint32_t j;
251   for (i = j = 0; i < nwords; i++, j+=2)  {
252     v = (p[j] << 8) | p[j+1];
253     chksum = netTest_utilOnesComplementAdd (chksum, v);
254   }
255   return (chksum);
256 } /* utilOnesCompChkSum */
258 /**************************************************************************************
259  * FUNCTION PURPOSE: Compute ipv4 psudo checksum
260  **************************************************************************************
261  * DESCRIPTION: Compute ipv4 psudo checksum
262  **************************************************************************************/
263 uint16_t netTest_utilGetIPv4PsudoChkSum (uint8_t *data, uint16_t payloadLen)
265   uint16_t psudo_chksum;
267   psudo_chksum = netTest_utilOnesCompChkSum (&data[12], 4);
268   psudo_chksum = netTest_utilOnesComplementAdd(psudo_chksum, (uint16_t) data[9]);
269   psudo_chksum = netTest_utilOnesComplementAdd(psudo_chksum, payloadLen);
271   return (psudo_chksum);
273 } /* utilGetIpv4PsudoChkSum */
275 #define CHECK_SET_PARAM(ARG1, ARG2)     \
276     do { \
277         if(strcmp(key, ARG1) == 0) { \
278         if(d1)strncpy(ARG2,d1,netTest_CONFIG_STRING_LEN); \
279         continue; \
280         } \
281     } while(0)
283 #define CHECK_SET_PARAM2(ARG1, ARG2,  ARG3)     \
284     do { \
285         if(strcmp(key, ARG1) == 0) { \
286         if(d1) strncpy(ARG2,d1,netTest_CONFIG_STRING_LEN); \
287         if(d2) strncpy(ARG3,d2,netTest_CONFIG_STRING_LEN); \
288         continue; \
289         } \
290     } while(0)
292 #define CHECK_SET_PARAM_SA(ARG1, ARG2, ARG3, ARG4, ARG5, \
293                                                    ARG6, ARG7, ARG8,  ARG9, ARG10, \
294                                                    ARG11, ARG12,ARG13, ARG14, ARG15, ARG16,ARG17, ARG18)     \
295     do { \
296         if(strcmp(key, ARG1) == 0) { \
297         if(d1) strncpy(ARG2,d1,netTest_CONFIG_STRING_LEN); \
298         if(d2) strncpy(ARG3,d2,netTest_CONFIG_STRING_LEN); \
299         if(d3) strncpy(ARG4,d3,netTest_CONFIG_STRING_LEN); \
300         if(d4) strncpy(ARG5,d4,netTest_CONFIG_STRING_LEN); \
301         if(d5) strncpy(ARG6, d5,netTest_CONFIG_STRING_LEN); \
302         if(d6) strncpy(ARG7,d6,netTest_CONFIG_STRING_LEN); \
303         if(d7) strncpy(ARG8,d7,netTest_CONFIG_STRING_LEN); \
304         if(d8) strncpy(ARG9,d8,netTest_CONFIG_STRING_LEN); \
305         if(d9) strncpy(ARG10,d9,netTest_CONFIG_STRING_LEN); \
306         if(d10) strncpy(ARG11,d10,netTest_CONFIG_STRING_LEN); \
307         if(d11) strncpy(ARG12,d11,netTest_CONFIG_STRING_LEN); \
308         if(d12) strncpy(ARG13,d12,netTest_CONFIG_STRING_LEN); \
309         if(d13) strncpy(ARG14,d13,netTest_CONFIG_STRING_LEN); \
310         if(d14) strncpy(ARG15,d14,netTest_CONFIG_STRING_LEN); \
311         if(d15) strncpy(ARG16,d15,netTest_CONFIG_STRING_LEN); \
312         if(d16) strncpy(ARG17,d16,netTest_CONFIG_STRING_LEN); \
313         if(d17) strncpy(ARG18,d17,netTest_CONFIG_STRING_LEN); \
314         continue; \
315         } \
316     } while(0)
318 void netTest_utilPrintIPSecStats(Sa_IpsecStats_t     *p_saIpsecStats, nwal_saAALG auth, nwal_saEALG cipher)
320 #if 0
321     if(retVal != nwal_OK)
322     {
323         System_System_netapi_Log("CORE: %d Error getting IP Sec Stats: Ret Status: %d \n",
324                        retVal);
325         return(nwal_FALSE);
326     }
327     if((p_saIpsecStats->pktEncHi) ||(p_saIpsecStats->pktEncLo))
328     {
329         Debug_netapi_Log("------------- IPSec TX (Encryption Channel) Stats BEGIN --\n");
330     }
331     else
332     {
333         netapi_Log("------------- IPSec RX (Decryption Channel) Stats BEGIN --\n");
334     }
335 #endif
336     printf("\nAutentication mode: %d, Encryption Mode: %d\n", auth, cipher);
337     printf("IPSec replayOld:0x%x,replayDup:0x%x,authFail:0x%x \n",
338                    p_saIpsecStats->replayOld,p_saIpsecStats->replayDup,p_saIpsecStats->authFail);
339     printf("IPSec txESN:0x%x,rxESN:0x%x,pktEncHi:0x%x,pktEncLo:0x%x,pktDecHi:0x%x,pktDecLo:0x%x \n",
340                    p_saIpsecStats->txESN,p_saIpsecStats->rxESN,p_saIpsecStats->pktEncHi,
341                    p_saIpsecStats->pktEncLo,p_saIpsecStats->pktDecHi,p_saIpsecStats->pktDecLo);
344 void netTest_utilPrintDataModeStats(Sa_DataModeStats_t     *p_saDataModeStats, nwal_saAALG auth, nwal_saEALG cipher)
347     printf("\nAutentication mode: %d, Encryption Mode: %d\n", auth, cipher);
348     printf(" Packets processedHi: 0x%x, Packets processed Lo:0x%x\n",
349             p_saDataModeStats->pktHi, p_saDataModeStats->pktLo);
352 /******************************************************
353  * stats callback
354  *******************************************************/
355 void netTest_utilStatsCbMt(NETAPI_T h, paSysStats_t* pPaStats)
358 #ifdef netTest_MULTI_THREAD
359     int coreid=Osal_nwalGetProcId();  //who we are(thread local)
360     //int coreid = our_core;
361 #else
362 int coreid=0;
363 #endif
365   stats[coreid].n_stats_cb +=1;
366   if(pPaStats) memcpy(&netcp_stats,pPaStats, sizeof(paSysStats_t));
368 void netTest_utilsStatsCb(NETAPI_T h, paSysStats_t* pPaStats)
370     uint32_t numFreeDataPackets;
371     uint32_t            numZeroBufferPackets;
372     uint32_t            numPacketsinGarbage;
373     Pktlib_HeapStats    pktLibHeapStats;
374     int i,j;
375     unsigned long long bcpp = 0;
376     unsigned long long bcpp_noc = 0;
377     unsigned long long bcpp_app = 0;
378     unsigned long long bcpp_tx = 0;
379     unsigned long long npL = 0;
380     unsigned long long cyclesL = 0;
381     unsigned long long ccyclesL = 0; //cache cycles
382     unsigned long long tmp_npL[TUNE_NETAPI_NUM_CORES];
383     unsigned long long tmp_cyclesL[TUNE_NETAPI_NUM_CORES];
384     unsigned long long tmp_ccyclesL[TUNE_NETAPI_NUM_CORES]; //cache cycles
385     NETAPI_SA_STATS_T netapi_sa_stats;
387     uint8_t num_threads =  netTestCfg.num_fp_threads;
388     for (j= 0;j < num_threads;j++)
389     {
390         if (netTestCfg.fp_thread_num[j] == 0)
391             continue;
392         i = netTestCfg.fp_thread_num[j];
393         printf("Per THREAD Statistics for Thread %d\n", netTestCfg.fp_thread_num[j]);;
394         printf(">*****stats @ %lld (#cbs%d) \n", hplib_mUtilGetTimestamp(),stats[i].n_stats_cb);
395         printf(">itx=%d rx=%d tx=%d bad=%d slow=%d \n>rx_class0=%d rx_class1=%d rx_class2=%dsecRx=%d\t"
396             "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",
397          stats[i].itx, stats[i].rx, stats[i].tx, stats[i].n_bad, stats[i].n_new, 
398          stats[i].n_class0_rx, stats[i].n_class1_rx,  stats[i].n_class2_rx, stats[i].sec_rx,
399          stats[i].secp_rx, stats[i].sb_rx, stats[i].sb_tx, stats[i].n_auth_ok,
400          stats[i].sec_tx, stats[i].rx_min, stats[i].tx_min, stats[i].exceptionPktsFrag, stats[i].exceptionPktsOther);
401         printf(">if rx stats:  %d %d %d\n",stats[i].if_rx[0],stats[i].if_rx[1],stats[i].if_rx[2]);
402         printf(">thread rx stats:  %d \n",stats[i].core_rx);
404         if (stats[i].rx && stats[i].tx)
405             printf("decrypt time per packet(avg): %lu, encrypt  time per packet(avg): %lu\n", 
406             (unsigned long) stats[i].total_decrypt_time/stats[i].rx, (unsigned long) stats[i].total_encrypt_time/stats[i].tx);
409          netapi_schedGetStats(scheduler[i],&tmp_npL[i],&tmp_cyclesL[i],&tmp_ccyclesL[i]);
410         if (tmp_npL[i] && stats[i].rx)
411         {
412             bcpp = tmp_cyclesL[i]/tmp_npL[i];
413             bcpp_noc = bcpp;
414             bcpp_app = (stats[i].app_cycles)/stats[i].rx;
415         }
416         if (stats[i].tx)
417         {
418             bcpp_tx = (stats[i].send_cycles)/stats[i].tx;
419         }
420         else
421         {
422             bcpp_tx = 0L;
423         }
424         printf(">         ++ busy cycles pp=%lld (%lld wo cache ops) (app+tx= %lld) (tx= %lld) ++\n",
425          bcpp,bcpp_noc,bcpp_app, bcpp_tx);
426         printf("\n");
427     }
431 if(pPaStats)
433        printf("C1 number of packets:           %d\n", pPaStats->classify1.nPackets);
434        printf("C1 number IPv4 packets:         %d\n", pPaStats->classify1.nIpv4Packets);
435        printf("C1 number IPv6 packets:        %d\n", pPaStats->classify1.nIpv6Packets);
436        printf("C1 number Custom packets:        %d\n", pPaStats->classify1.nCustomPackets);
437        printf("C1 number SRIO packets:        %d\n", pPaStats->classify1.nSrioPackets);
438        printf("C1 number LLC/SNAP Fail packets:        %d\n", pPaStats->classify1.nLlcSnapFail);
439        printf("C1 number table matched:        %d\n", pPaStats->classify1.nTableMatch);
440        printf("C1 number failed table matched: %d\n", pPaStats->classify1.nNoTableMatch);
441        printf("C1 number IP Fragmented packets: %d\n", pPaStats->classify1.nIpFrag);
442        printf("C1 number IP Depth Overflow: %d\n", pPaStats->classify1.nIpDepthOverflow);
443        printf("C1 number VLAN Depth Overflow: %d\n", pPaStats->classify1.nVlanDepthOverflow);
444        printf("C1 number GRE Depth Overflow: %d\n", pPaStats->classify1.nGreDepthOverflow);
445        printf("C1 number MPLS Packets: %d\n", pPaStats->classify1.nMplsPackets);
446        printf ("C1 number of parse fail:        %d\n",pPaStats->classify1.nParseFail);
447        printf("C1 number of Invalid IPv6 Opt:  %d\n", pPaStats->classify1.nInvalidIPv6Opt);
448        printf("C1 number of TX IP Fragments:  %d\n", pPaStats->classify1.nTxIpFrag);
449        printf ("C1 number of silent discard:    %d\n",pPaStats->classify1.nSilentDiscard);
450        printf("C1 number of invalid control:   %d\n", pPaStats->classify1.nInvalidControl);
451        printf ("C1 number of invalid states:    %d\n",pPaStats->classify1.nInvalidState);
452        printf ("C1 number of system fails:      %d\n",pPaStats->classify1.nSystemFail);
453        printf ("C2 number Packets  :           %d\n",pPaStats->classify2.nPackets);
454        printf ("C2 number udp           :      %d\n",pPaStats->classify2.nUdp);
455        printf ("C2 number tcp           :      %d\n",pPaStats->classify2.nTcp);
456        printf ("C2 number Custom       :      %d\n",pPaStats->classify2.nCustom);
457        printf ("C2 number silent drop   :      %d\n",pPaStats->classify2.nSilentDiscard);
458        printf ("C2 number invalid cntrl :      %d\n\n",pPaStats->classify2.nInvalidControl);
459        printf ("C2 number Modify Stats Cmd Fail :      %d\n\n",pPaStats->modify.nCommandFail);
461 Pktlib_getHeapStats(ourHeap, &pktLibHeapStats);
462 printf("main heap stats>  #free=%d #zb=%d #garbage=%d\n", pktLibHeapStats.numFreeDataPackets,
463                                 pktLibHeapStats.numZeroBufferPackets, pktLibHeapStats.numPacketsinGarbage);
464 printf("               >  #dataBufThreshStatus=%d #dataBufStarvCounter=%d #zBufThreshStatus=%d #zBufStarvCounter=%d \n", 
465                         pktLibHeapStats.dataBufferThresholdStatus,pktLibHeapStats.dataBufferStarvationCounter,
466                         pktLibHeapStats.zeroDataBufferThresholdStatus, pktLibHeapStats.zeroDataBufferStarvationCounter);
468 #if 0
469 netapi_Log("pa2sa descriptor area dump\n");
470 for(i=0;i<TUNE_NETAPI_CONFIG_MAX_PA_TO_SA_DESC;i++)
472    extern long * pa2sa_descr_base;
473    long * tip= &pa2sa_descr_base[32*i]; 
474    netTest_utilDumpDescr(tip, i);
476 netapi_Log("sa2pa descriptor area dump\n");
477 for(i=0;i<TUNE_NETAPI_CONFIG_MAX_SA_TO_PA_DESC;i++)
479    extern long * sa2pa_descr_base;
480    long * tip= &sa2pa_descr_base[32*i]; 
481    netTest_utilDumpDescr(tip, i);
483 #endif
484     for (i = 0; i < netTestCfg.num_sa; i++)
485     {
486         /* Statistics for RX Tunnel */
487         memset(&netapi_sa_stats, 0, sizeof(netapi_sa_stats));
488         if (netTestCfg.sa[i].dir ==NWAL_SA_DIR_INBOUND )
489         {
490             netapi_getSaStats(netapi_handle, sa_info[i].rx_tunnel, &netapi_sa_stats);
491             if (netapi_sa_stats.validParams & NETAPI_IPSEC_STAT_VALID)
492             {
493                 netTest_utilPrintIPSecStats(&(netapi_sa_stats.saIpsecStats), 
494                                  netTestCfg.sa[i].authMode,
495                                  netTestCfg.sa[i].cipherMode);
496             }
497             if (netapi_sa_stats.validParams & NETAPI_SIDEBAND_DATA_MODE_STAT_VALID)
498             {
499                 netTest_utilPrintDataModeStats(&(netapi_sa_stats.dataModeStats),
500                                    netTestCfg.sa[i].authMode,
501                                    netTestCfg.sa[i].cipherMode);
502             }
503         }
504         else if (netTestCfg.sa[i].dir ==NWAL_SA_DIR_OUTBOUND)
505         {
506             netapi_getSaStats(netapi_handle, sa_info[i].tx_tunnel, &netapi_sa_stats);
507             if (netapi_sa_stats.validParams & NETAPI_IPSEC_STAT_VALID)
508             {
509                  netTest_utilPrintIPSecStats(&(netapi_sa_stats.saIpsecStats), 
510                                    netTestCfg.sa[i].authMode,
511                                    netTestCfg.sa[i].cipherMode);
512             }
513             if (netapi_sa_stats.validParams & NETAPI_SIDEBAND_DATA_MODE_STAT_VALID)
514             {
515                 netTest_utilPrintDataModeStats(&(netapi_sa_stats.dataModeStats),
516                                     netTestCfg.sa[i].authMode,
517                                     netTestCfg.sa[i].cipherMode);
518             }
519         }
520         else
521             netapi_Log("netTest_utilsStatsCb: invalid SA direction\n");
522     }
523     netapi_dump_internal_heap_stats();
529 void parse_dsp_mac(char * p_mac_str)
531     if (strlen(&p_mac_str[0]))
532     {
533         sscanf(p_mac_str,"mac%d",&netTestCfg.dsp_mac);
534     }
537 void parse_dsp_ip(char * p_ip_str)
539     if (strlen(&p_ip_str[0]))
540     {
541         sscanf(p_ip_str,"ip%d",&netTestCfg.dsp_ip);
542     }
545 void netTest_utilParseOneKey(char *p_key_str, unsigned char *p_key)
547     int index = 0;
548     int i;
549     if (strlen(&p_key_str[0]))
550     {
551         char * pch = strtok (&p_key_str[0],",");
553         while (pch != NULL)
554         {
555             p_key[index] = netTest_utilHex2Dec(pch);
556             index++;
557             pch = strtok (NULL,",");
558         }
559     }
562 void netTest_utilParseOneIP(char * p_ip_addr_str, unsigned char * p_ip)
564     int index = 0;
565     int i;
566     if (strlen(&p_ip_addr_str[0]))
567     {
568         char * pch = strtok (&p_ip_addr_str[0],".");
570         while (pch != NULL)
571         {
572             p_ip[index] = atoi(pch);
573             index++;
574             pch = strtok (NULL,".");
575         }
576     }
579 void netTest_utilParseOneMac(char * p_mac_str, unsigned char *p_mac)
581     int index = 0;
582     int i;
583     if (strlen(&p_mac_str[0]))
584     {
585         char *pch = strtok (&(p_mac_str[0]),"-");
587         while (pch != NULL)
588         {
589             p_mac[index] = netTest_utilHex2Dec(pch);
590             index++;
591             pch = strtok (NULL,"-");
592         }
593     }
596 void netTest_utilParseMac(netTestConfigFile_t *pConfig)
598     int i;
599     int port = 0;
600     for(i=0;i<NET_TEST_MAX_MAC;i++)
601     {
602         if (strlen(&pConfig->mac[i][0]))
603         {
604             netTestCfg.num_macs++;
605             netTest_utilParseOneMac(&pConfig->mac[i][0],&netTestCfg.mac[i][0]);
606             sscanf(&pConfig->switch_port[i][0],"swp%d",&netTestCfg.switch_port[i]);
607         }
608     }
609     netapi_Log("netTest_utilParseMac: number of mac address %d\n", netTestCfg.num_macs);
612 void netTest_utilParseIP(netTestConfigFile_t *pConfig)
614     int i;
616     for(i=0;i<NET_TEST_MAX_IP;i++)
617     {
618         if (strlen(&pConfig->ip[i][0]))
619         {
620             netTestCfg.num_ips++;
621             netTest_utilParseOneIP(&pConfig->ip[i][0],&netTestCfg.ip[i].ipv4[0]);
622             sscanf(&pConfig->attach_iface[i][0],"mac%d",&netTestCfg.attach_iface[i]);
623         }
624     }
625     netapi_Log("netTest_utilParseIP: number of ip address %d\n", netTestCfg.num_ips);
627 void netTest_utilParseIpsecMode(netTestConfigFile_t *pConfig)
630     if (strlen(&pConfig->ipsec_mode_rx[0]))
631     {
632         if (strcmp(pConfig->ipsec_mode_rx, "SIDEBAND") == 0)
633         {
634             netTestCfg.ipsec_mode_rx = IPSEC_MODE_RX_SIDEBAND;
635         }
636         else if (strcmp(pConfig->ipsec_mode_rx, "INFLOW") == 0)
637         {
638             netTestCfg.ipsec_mode_rx = IPSEC_MODE_RX_INFLOW;
639         }
640         else
641         {
642             netapi_Log("netTest_utilParseIpsecMode(), invalid RX ipsec mode in config file \n");
643         }
644     }
646     if (strlen(&pConfig->ipsec_mode_tx[0]))
647     {
648         if (strcmp(pConfig->ipsec_mode_tx, "SIDEBAND") == 0)
649         {
650             netTestCfg.ipsec_mode_tx = IPSEC_MODE_TX_SIDEBAND;
651         }
652         else if (strcmp(pConfig->ipsec_mode_tx, "INFLOW") == 0)
653         {
654             netTestCfg.ipsec_mode_tx = IPSEC_MODE_TX_INFLOW;
655         }
656         else
657         {
658             netapi_Log("netTest_utilParseIpsecMode(), invalid TX ipsec mode in config file \n");
659         }
660     }
664 void netTest_utilParseAuthMode(char *auth_mode_str, nwal_saAALG *auth_mode)
666     if (strlen(auth_mode_str))
667     {
668         netapi_Log("strlen of auth_mode_str is %d\n", strlen(auth_mode_str));
670         if (strcmp(auth_mode_str, "NULL") == 0)
671         {
672             *auth_mode= NWAL_SA_AALG_NULL;
673         }
674         else if (strcmp(auth_mode_str, "HMAC_MD5") == 0)
675         {
676             *auth_mode= NWAL_SA_AALG_HMAC_MD5;
677         }
678         else if (strcmp(auth_mode_str, "HMAC_SHA1") == 0)
679         {
680             *auth_mode= NWAL_SA_AALG_HMAC_SHA1;
681         }
682         else if (strcmp(auth_mode_str, "HMAC_SHA2_224") == 0)
683         {
684             *auth_mode= NWAL_SA_AALG_HMAC_SHA2_224;
685         }
686         else if (strcmp(auth_mode_str, "HMAC_SHA2_256") == 0)
687         {
688             *auth_mode= NWAL_SA_AALG_HMAC_SHA2_256;
689         }
690         else if (strcmp(auth_mode_str, "GMAC") == 0)
691         {
692             *auth_mode= NWAL_SA_AALG_GMAC;
693         }
694         else if (strcmp(auth_mode_str, "AES_XCBC") == 0)
695         {
696             *auth_mode= NWAL_SA_AALG_AES_XCBC;
697         }
698         else
699         {
700             netapi_Log("netTest_utilParseAuthMode: invalid auth mode specified\n");
701         }
702     }
705 void netTest_utilParseEncryptMode(char *ency_mode_str, nwal_saEALG*encr_mode)
707     if (strlen(ency_mode_str))
708     {
709         if (strcmp(ency_mode_str, "NULL") == 0)
710         {
711             *encr_mode= NWAL_SA_EALG_NULL;
712         }
713         else if (strcmp(ency_mode_str, "AES_CTR") == 0)
714         {
715             *encr_mode= NWAL_SA_EALG_AES_CTR;
716         }
717         else if (strcmp(ency_mode_str, "AES_CBC") == 0)
718         {
719             *encr_mode= NWAL_SA_EALG_AES_CBC;
720         }
721         else if (strcmp(ency_mode_str, "3DES_CBC") == 0)
722         {
723             *encr_mode= NWAL_SA_EALG_3DES_CBC;
724         }
725         else if (strcmp(ency_mode_str, "AES_CCM") == 0)
726         {
727             *encr_mode= NWAL_SA_EALG_AES_CCM;
728         }
729         else if (strcmp(ency_mode_str, "AES_GCM") == 0)
730         {
731             *encr_mode= NWAL_SA_EALG_AES_GCM;
732         }
733         else if (strcmp(ency_mode_str, "AES_XCBC") == 0)
734         {
735             *encr_mode= NWAL_SA_AALG_AES_XCBC;
736         }
737         else
738         {
739             netapi_Log("netTest_utilParseEncryptMode: invalid auth mode specified\n");
740         }
741     }
744 void netTest_utilParseProto(char *proto_str, nwal_IpSecProto *proto)
746     if (strlen(proto_str))
747     {
748         if (strcmp(proto_str, "ESP") == 0)
749         {
750             *proto= nwal_IpSecProtoESP;
751             netapi_Log("netTest_utilParseProto(): setting proto  to ESP\n");
752         }
753         else if (strcmp(proto_str, "AH") == 0)
754         {
755             *proto = nwal_IpSecProtoAH;
756             netapi_Log("netTest_utilParseProto(): setting proto to AH\n");
757         }
758         else
759         {
760             netapi_Log("netTest_utilParseProto(), invalid RX ipsec mode in config file \n");
761         }
762     }
767 void netTest_utilParseSaMode(char *mode_str, nwal_saMode *mode)
769     if (strlen(mode_str))
770     {
771         if (strcmp(mode_str, "TUNNEL") == 0)
772         {
773             *mode= nwal_SA_MODE_TUNNEL;
774         }
775         else if (strcmp(mode_str, "TRANSPORT") == 0)
776         {
777             *mode = nwal_SA_MODE_TRANSPORT;
778         }
779         else
780         {
781             netapi_Log("netTest_utilParseSaMode(), invalid RX ipsec mode in config file \n");
782         }
783     }
786 void netTest_utilParseIPType(char *ip_type_str, nwal_IpType *ipType)
788     if (strlen(ip_type_str))
789     {
790         if (strcmp(ip_type_str, "IPV4") == 0)
791         {
792             *ipType= nwal_IPV4;
793         }
794         else if (strcmp(ip_type_str, "IPV6") == 0)
795         {
796             *ipType = nwal_IPV6;
797         }
798         else
799         {
800             netapi_Log("netTest_utilParseIPType(), invalid RX ipsec mode in config file \n");
801         }
802     }
806 void parse_simple_param_u8(char* input_str, uint8_t *val)
808     if (strlen(input_str))
809     {
810         *val = (uint8_t)strtol(input_str, NULL, 0);
811     }
814 void parse_simple_param_u16(char* input_str, uint16_t *val)
816     if (strlen(input_str))
817     {
818         *val = (uint16_t)strtol(input_str, NULL, 0);
819     }
822 void parse_simple_param_u32(char* input_str, uint32_t *val)
824     if (strlen(input_str))
825     {
826         *val = (uint32_t)strtol(input_str, NULL, 0);
827     }
830 void netTest_utilParseSADir(char* dir_str, nwal_SaDir *dir)
832     if (strlen(dir_str))
833     {
834         if (strcmp(dir_str, "INBOUND") == 0)
835         {
836             *dir= NWAL_SA_DIR_INBOUND;
837         }
838         else if (strcmp(dir_str, "OUTBOUND") == 0)
839         {
840             *dir = NWAL_SA_DIR_OUTBOUND;
841         }
842         else
843             netapi_Log("netTest_utilParseSADir: invalid direction\n");
844     }
846 void netTest_utilParseThreadConfig(char * p_thread_str, uint8_t* start, uint8_t* end)
848     int index = 0;
849     int i;
851     if (strlen(p_thread_str))
852     {
853         char *pch = strtok (&(p_thread_str[0]),"-");
854         *start = atoi(pch);
855         pch = strtok (NULL,"-");
856         *end = atoi(pch);
857     }
860 void netTest_utilParseThreadParams(netTestConfigFile_t *pConfig)
862     int i;
863     for(i=0;i<NET_TEST_MAX_FP_THREAD;i++)
864     {
865         if (strlen(&pConfig->fp[i][0]))
866         {
867             netTestCfg.num_fp_threads++;
868             netTest_utilParseThreadConfig(&pConfig->fp[i][0],
869                                          (uint8_t*)&netTestCfg.fp_proc_start[i],
870                                          (uint8_t*)&netTestCfg.fp_proc_end[i]);
871         }
872         if (strlen(&pConfig->fp_thread_num[i][0]))
873         {
874             netTestCfg.fp_thread_num[i] = atoi((char*)(&pConfig->fp_thread_num[i]));
875         }
876     }
878     for(i=0;i<NET_TEST_MAX_SP_THREAD;i++)
879     {
880         if (strlen(&pConfig->sp[i][0]))
881         {
882             netTestCfg.num_sp_threads++;
883             netTest_utilParseThreadConfig(&pConfig->sp[i][0],
884                                          (uint8_t*)&netTestCfg.sp_proc_start[i],
885                                          (uint8_t*)&netTestCfg.sp_proc_end[i]);
886         }
887         if (strlen(&pConfig->sp_thread_num[i][0]))
888         {
889             netTestCfg.sp_thread_num[i] = atoi((char*)(&pConfig->sp_thread_num[i]));
890         }
891     }
893 void netTest_utilParseSA(netTestConfigFile_t *pConfig)
895     int i;
896     for(i=0;i<MAX_SEC_INDEX;i++)
897     {
898         if (strlen((char*)&pConfig->sa_config[i][0].dir))
899         {
900             netTest_utilParseSADir((char*) &pConfig->sa_config[i][0].dir, &netTestCfg.sa[i].dir);
901             parse_simple_param_u32((char*)&pConfig->sa_config[i][0].spi, &netTestCfg.sa[i].spi);
902             netTest_utilParseProto((char*)&pConfig->sa_config[i][0].proto, &netTestCfg.sa[i].proto);
903             netTest_utilParseSaMode((char*)&pConfig->sa_config[i][0].saMode, &netTestCfg.sa[i].saMode);
904             netTest_utilParseIPType((char*)&pConfig->sa_config[i][0].ipType, &netTestCfg.sa[i].ipType);
905             netTest_utilParseOneIP((char*)&pConfig->sa_config[i][0].src, (unsigned char *)&netTestCfg.sa[i].src);
906             netTest_utilParseOneIP((char*)&pConfig->sa_config[i][0].dst, (unsigned char *)&netTestCfg.sa[i].dst);
907             parse_simple_param_u32((char*)&pConfig->sa_config[i][0].replayWindow, &netTestCfg.sa[i].replayWindow);
908             netTest_utilParseAuthMode((char*)&pConfig->sa_config[i][0].authMode, &netTestCfg.sa[i].authMode);
909             netTest_utilParseEncryptMode((char*)&pConfig->sa_config[i][0].cipherMode, &netTestCfg.sa[i].cipherMode);
910             parse_simple_param_u32((char*)&pConfig->sa_config[i][0].esnLo, &netTestCfg.sa[i].esnLo);
911             parse_simple_param_u32((char*)&pConfig->sa_config[i][0].esnHi, &netTestCfg.sa[i].esnHi);
912             parse_simple_param_u16((char*)&pConfig->sa_config[i][0].encKeySize, &netTestCfg.key_params[i].encKeySize);
913             parse_simple_param_u16((char*)&pConfig->sa_config[i][0].macKeySize, &netTestCfg.key_params[i].macKeySize);
916             netTest_utilParseOneKey((char*) &pConfig->sa_config[i][0].encr_key, &netTestCfg.encr_key[i][0]);
917             netTestCfg.key_params[i].pEncKey = (uint8_t*)&netTestCfg.encr_key[i][0];
919             netTest_utilParseOneKey((char*)&pConfig->sa_config[i][0].auth_key, &netTestCfg.auth_key[i][0]);
920             netTestCfg.key_params[i].pAuthKey= (uint8_t*)&netTestCfg.auth_key[i][0];
923             parse_simple_param_u32((char*)&pConfig->sa_config[i][0].tunnel_id, &netTestCfg.tunnel_id[i]);
925             netTestCfg.num_sa++;
926         }
927     }
929 void netTest_utilParseRoutes(netTestConfigFile_t *pConfig, OUR_ROUTE_T *routes, Trie ** our_router)
931     int i;
932     int said=0;
933     for(i=0;i<MAX_ROUTES;i++)
934     {
935         int port;
936         if (pConfig->routes[i][0])
937         {
938             port=atoi(&pConfig->ports[i][0]);
939             if((port<1)||(port>2)) continue; //bad port #: only 1 or 2 valid
941             if(strncmp(&pConfig->routes[i][0],"MAC",3)==0)
942             {
943                routes[i].out_port = port;
944                netTest_utilParseOneMac(&pConfig->routes[i][3],&routes[i].out_mac[0]);
945                //memcpy(&routes[i].out_mac[6], ((port==1) ?&config.mac0[0]: &config.mac1[0] ),6); 
946                memcpy(&routes[i].out_mac[6], ((port==1) ?&netTestCfg.mac[0][0]: &netTestCfg.mac[1][0] ),6);
947                routes[i].out_mac[12]=0x08;
948                routes[i].out_mac[13]=0x00;
949                routes[i].sec_ptr=NULL;
950             }
951             else if (strncmp(&pConfig->routes[i][0],"SA",2)==0)
952             {      
953                said=atoi(&pConfig->routes[i][2]) ;
954                routes[i].sec_ptr=&sa_info[said];
955             }
956         }
957     }
958     *our_router = route_init();
959     for (i=0;i<MAX_ROUTES;i++)
960     {
961       unsigned long ip_be;
962       int route_index;
963       if (pConfig->dst_ips[i][0])
964       {
965          netTest_utilParseOneIP(&pConfig->dst_ips[i][0],(unsigned char *)&ip_be);
966          sscanf(&pConfig->paths[i][0],"route%d",&route_index);
967          route_add(*our_router,&ip_be,(void*)&routes[route_index]);
968       }
969     }
972 void netTest_utilProcessConfigFile(FILE * fpr, netTestConfigFile_t *pConfig)
974     char line[MAX_LINE_LENGTH + 1];
975     int i;
976     static int sa_count = 0;
977  
978     char *key, *ep;
979     char * d1, *d2, *d3, *d4;
980     char * d5, *d6, *d7, *d8;
981     char * d9, *d10, *d11, *d12;
982     char * d13, *d14, *d15, *d16, *d17;
983     char tokens[] = " :=;\n";
984     char temp_str[TEMP_STR_LEN];
985     memset(line, 0, MAX_LINE_LENGTH + 1);
986     memset(pConfig, 0, sizeof(netTestConfigFile_t));
987     while (fgets(line, MAX_LINE_LENGTH + 1, fpr))
988     {
989         if(line[0]=='#')
990             continue; //skip comment
991         key  = (char *)strtok(line, tokens);
993         d1 = (char *)strtok(NULL, tokens);
994         if (!key)
995             continue;
996         if (!d1) 
997             continue;
999         if(strlen(d1) == 0) 
1000         {
1001             continue;
1002         }
1005         d2 = (char *)strtok(NULL, tokens);
1006         d3 = (char *)strtok(NULL, tokens);
1007         d4 = (char *)strtok(NULL, tokens);
1008         d5 = (char *)strtok(NULL, tokens);
1009         d6 = (char *)strtok(NULL, tokens);
1010         d7 = (char *)strtok(NULL, tokens);
1011         d8 = (char *)strtok(NULL, tokens);
1012         d9 = (char *)strtok(NULL, tokens);
1013         d10 = (char *)strtok(NULL, tokens);
1014         d11 = (char *)strtok(NULL, tokens);
1015         d12 = (char *)strtok(NULL, tokens);
1016         d13 = (char *)strtok(NULL, tokens);
1017         d14 = (char *)strtok(NULL, tokens);
1018         d15 = (char *)strtok(NULL, tokens);
1019         d16 = (char *)strtok(NULL, tokens);
1020         d17 = (char *)strtok(NULL, tokens);
1022         CHECK_SET_PARAM(netTest_INIT_CONFIG_IPSEC_MODE_RX,&(pConfig->ipsec_mode_rx[0]));
1023         CHECK_SET_PARAM(netTest_INIT_CONFIG_IPSEC_MODE_TX,&(pConfig->ipsec_mode_tx[0]));
1024         CHECK_SET_PARAM(netTest_INIT_CONFIG_IPSEC_IF_NO,&(pConfig->ipsec_if_no[0]));
1025         CHECK_SET_PARAM(netTest_INIT_CONFIG_DSP_MAC,&(pConfig->dsp_mac[0]));
1026         CHECK_SET_PARAM(netTest_INIT_CONFIG_DSP_IP,&(pConfig->dsp_ip[0]));
1027         CHECK_SET_PARAM(netTest_INIT_CONFIG_STATIC_LOOPBACK_PORT,&(pConfig->dest_udp_port_config[0]));
1030         for(i=0;i<MAX_SEC_INDEX;i++)
1031         {
1032             snprintf(temp_str, TEMP_STR_LEN-1, "sa%d",i);
1033             CHECK_SET_PARAM_SA(temp_str, 
1034                               (char*)&pConfig->sa_config[i][0].dir,
1035                               (char*)&pConfig->sa_config[i][0].spi,
1036                               (char*)&pConfig->sa_config[i][0].proto,
1037                               (char*)&pConfig->sa_config[i][0].saMode,
1038                               (char*)&pConfig->sa_config[i][0].ipType,
1039                               (char*)&pConfig->sa_config[i][0].src,
1040                               (char*)&pConfig->sa_config[i][0].dst,
1041                               (char*)&pConfig->sa_config[i][0].replayWindow,
1042                               (char*)&pConfig->sa_config[i][0].authMode,
1043                               (char*)&pConfig->sa_config[i][0].cipherMode,
1044                               (char*)&pConfig->sa_config[i][0].esnLo,
1045                               (char*)&pConfig->sa_config[i][0].esnHi,
1046                               (char*)&pConfig->sa_config[i][0].encKeySize,
1047                               (char*)&pConfig->sa_config[i][0].macKeySize,
1048                               (char*)&pConfig->sa_config[i][0].encr_key,
1049                               (char*)&pConfig->sa_config[i][0].auth_key,
1050                               (char*)&pConfig->sa_config[i][0].tunnel_id);
1051         }
1053         for(i=0;i<MAX_ROUTES;i++)
1054         {
1055             snprintf(temp_str, TEMP_STR_LEN-1, "route%d",i);
1056             CHECK_SET_PARAM2(temp_str,&pConfig->routes[i][0],&pConfig->ports[i][0] );
1057         }
1059         for(i=0;i<MAX_ROUTES;i++)
1060         {
1061             snprintf(temp_str, TEMP_STR_LEN-1, "dstip%d",i);
1062             CHECK_SET_PARAM2(temp_str,&pConfig->dst_ips[i][0],&pConfig->paths[i][0] );
1063         }
1064         for(i=0;i<NET_TEST_MAX_MAC;i++)
1065         {
1066             snprintf(temp_str, TEMP_STR_LEN-1, "mac%d",i);
1067             CHECK_SET_PARAM2(temp_str,&pConfig->mac[i][0],&pConfig->switch_port[i][0] );
1068         }
1069         for(i=0;i<NET_TEST_MAX_IP;i++)
1070         {
1071             snprintf(temp_str, TEMP_STR_LEN-1, "ip%d",i);
1072             CHECK_SET_PARAM2(temp_str,&pConfig->ip[i][0], &pConfig->attach_iface[i][0]);
1073         }
1074         for(i=0;i<NET_TEST_MAX_FP_THREAD;i++)
1075         {
1076             snprintf(temp_str, TEMP_STR_LEN-1, "fp%d",i);
1077             CHECK_SET_PARAM2(temp_str, &pConfig->fp_thread_num[i][0],&pConfig->fp[i][0]);
1078         }
1079         for(i=0;i<NET_TEST_MAX_SP_THREAD;i++)
1080         {
1081             snprintf(temp_str, TEMP_STR_LEN-1, "sp%d",i);
1082             CHECK_SET_PARAM2(temp_str, &pConfig->sp_thread_num[i][0],&pConfig->sp[i][0]);
1083         }
1084     }
1087 //******************************************************
1088 //use scheduling housekeeping callback to generate pkts
1089 //******************************************************
1090 static int done_burst=0;
1091 void house(NETAPI_SCHED_HANDLE_T * s)
1093     Ti_Pkt * tip;
1094     unsigned int len;
1095     nwalTxPktInfo_t meta_tx = {0};
1096     PKTIO_METADATA_T meta = {PKTIO_META_TX,{0},0};
1097     int err;
1098     static int house_pkts_gened=0;
1099     int p;
1100     unsigned char * pIpHdr,* pData;
1101     unsigned int vv1,vv2,vv3;
1102     unsigned int sum_vv1=0;
1103     unsigned int sum_vv2=0;
1104     unsigned int sum_vv3=0;
1105     unsigned int sum_vv4=0;
1106     unsigned int sum_vv5=0;
1108     unsigned int nwal_flow_vv1,nwal_flow_vv2;
1109     unsigned int nwal_sum_vv1=0;
1110     unsigned int nwal_sum_vv2=0;
1111     unsigned int nwal_sum_vv3=0;
1112     unsigned int nwal_sum_vv4=0;
1113     unsigned int nwal_sum_vv5=0;
1114     unsigned int nwal_sum_vv6=0;
1116     unsigned int nwal_sum_flow_vv1=0;
1117     unsigned int nwal_sum_flow_vv2=0;
1118     unsigned long long cache_op_b1;
1119     unsigned long long  cache_op_b2;
1120     unsigned long long  n_c_ops;
1121     static int first =0;
1122     Cppi_HostDesc*      pPktDesc;
1123     NETAPI_SCHED_SHUTDOWN_T sched_shutdown;
1125     uint32_t coreid = 0;  //who we are
1126 #ifdef netTest_MULTI_THREAD
1127     NETAPI_T nh= netapi_schedGetHandle(s);
1128     coreid=(uint32_t) netapi_getCookie(nh);
1130     if (QUIT) 
1131     {
1132         sched_shutdown.shutdown_type = NETAPI_SCHED_SHUTDOWN_NOW;
1133         netapi_schedClose(s,&sched_shutdown,&err); 
1134         return;
1135     }
1137     
1138     /* only slow path threads get netcp stats */
1139     if (coreid & NET_TEST_SP_THREAD_MASK)
1140     {
1141         netapi_netcpCfgReqStats(nh, netTest_utilStatsCbMt, 0,&err); 
1142     }
1144     coreid = NET_TEST_THREAD_NUM_MASK & coreid;
1145 #else
1146     coreid = NET_TEST_THREAD_NUM_MASK & coreid;
1147     if(done_burst)
1148     {
1149         house_pkts_gened+=TX_BURST;
1150         netapi_Log("net_test> request stats at n=%d \n",house_pkts_gened);
1151         netapi_netcpCfgReqStats(netapi_handle, netTest_utilsStatsCb, 0,&err);
1152         if (err!=0) {netapi_Log("stats req failed\n");}
1153         if (house_pkts_gened >= np2process+ 100)
1154         {
1155             sched_shutdown.shutdown_type = NETAPI_SCHED_SHUTDOWN_NOW;
1156             netapi_schedClose(s,&sched_shutdown,&err);
1157         }
1158         return;
1159     }
1160     done_burst=1;
1161     Osal_cache_op_measure_reset();
1162     memset(&meta_tx,0,sizeof(meta_tx));
1163     for(p=0;p<TX_BURST;p++) {  
1164     //reguest stats 
1165     if ((house_pkts_gened>0) && (! (house_pkts_gened%1000)) )
1166     {
1167        netapi_Log("net_test> request stats at n=%d \n",house_pkts_gened);
1168        netapi_netcpCfgReqStats(netapi_handle, netTest_utilsStatsCb, 0,&err); 
1169        if (err!=0) {netapi_Log("stats req failed\n");}
1170     }
1173     if (house_pkts_gened >= np2process+ 100)
1174     {
1175         //shutdown
1176         sched_shutdown.shutdown_type = NETAPI_SCHED_SHUTDOWN_NOW;
1177         netapi_schedClose(s,&sched_shutdown,&err);
1178         continue;
1179     }
1181     else if (house_pkts_gened >= np2process) { house_pkts_gened+=1;  continue;}
1183     /* manufacture a pkt to transmit */
1184     tip = get_pkt(house_pkts_gened, &len, ourHeap, netTest_PKT_LEN,&testPkt[0]  , TEST_netTest_PKT_LEN);
1185     if(!tip) { house_pkts_gened +=1; continue; }
1188     /* set the pkt length */
1189     vv1 = hplib_mUtilGetPmuCCNT();
1190     Pktlib_setPacketLen(tip, len);
1192     /* set up meta data */
1193     meta.sa_handle=nwal_HANDLE_INVALID;
1194     /* #define BENCH_UDP_SEND */
1195 #ifdef BEND_UDP_SEND
1196     meta_tx.txFlag1 = (NWAL_TX_FLAG1_DO_IPV4_CHKSUM | NWAL_TX_FLAG1_DO_UDP_CHKSUM| NWAL_TX_FLAG1_META_DATA_VALID);
1197     meta_tx.startOffset = 0;
1198     /* GONE in V2 meta_tx.pktLen = len; */
1199     meta_tx.ipOffBytes = TEST_PKT_IP_OFFSET_BYTES;
1200     meta_tx.l4OffBytes = TEST_PKT_UDP_OFFSET_BYTES;
1201     meta_tx.l4HdrLen = TEST_PKT_UDP_HDR_LEN;
1202     //GONE in V2 meta_tx.ploadOffBytes = TEST_PKT_PLOAD_OFFSET_BYTES;
1203     meta_tx.ploadLen = TEST_PAYLOAD_LEN;
1205     Pktlib_getDataBuffer(tip,&pData,&len);
1206     if(house_pkts_gened &0x1)
1207     {
1208         memcpy(&pData[6],&netTestCfg.mac[1][0] ,6);
1209     }
1210     pIpHdr = pData + meta_tx.ipOffBytes;
1211     meta_tx.pseudoHdrChecksum =
1212         netTest_utilGetIPv4PsudoChkSum(pIpHdr,(TEST_PAYLOAD_LEN+TEST_PKT_UDP_HDR_LEN));
1213 #else
1214     Pktlib_getDataBuffer(tip,&pData,&len);
1215     if(house_pkts_gened &0x1)
1216     {
1217         memcpy(&pData[6],&netTestCfg.mac[1][0] ,6);
1218     }
1219     meta_tx.txFlag1 = NWAL_TX_FLAG1_META_DATA_VALID;
1220     meta_tx.startOffset = 0;
1221     meta_tx.ploadLen = TEST_PAYLOAD_LEN;
1222 #endif
1223    /* post it to netcp tx channel*/
1224    meta.u.tx_meta=&meta_tx;
1225 #ifdef DEBUG_DESC
1226     if (house_pkts_gened<16) netTest_utilDumpDescr((long *) tip, house_pkts_gened);
1227     else if (house_pkts_gened>99) netTest_utilDumpDescr((long *) tip,house_pkts_gened);
1228 #endif
1230     if(!first)
1231     {
1232         first++;
1233         nwal_flow_vv1= hplib_mUtilGetPmuCCNT();
1234         if(nwal_initPSCmdInfo(pktio_mGetNwalInstance(netcp_tx_chan),
1235                              &meta_tx,
1236                              &flowPSCmdInfo) != nwal_OK)
1237         {
1238             netapi_Log("nwal_initPSCmdInfo() ERROR \n");
1239         }
1240         nwal_flow_vv2= hplib_mUtilGetPmuCCNT();
1241         nwal_sum_flow_vv1 += (nwal_flow_vv1-vv1); 
1242         nwal_sum_flow_vv2 += (nwal_flow_vv2-nwal_flow_vv1); 
1243     }
1244     cache_op_b1= Osal_cache_op_measure(&n_c_ops);
1245     vv2= hplib_mUtilGetPmuCCNT();
1246 #ifdef BEND_UDP_SEND
1247     nwal_mCmdSetL4CkSumPort(  tip,
1248                              &flowPSCmdInfo,
1249                              TEST_PKT_UDP_OFFSET_BYTES,
1250                              (TEST_PKT_UDP_HDR_LEN + TEST_PAYLOAD_LEN),
1251                              meta_tx.pseudoHdrChecksum,
1252                              meta_tx.enetPort);
1253 #else
1254     nwal_mCmdSetPort  (tip,
1255                       &flowPSCmdInfo,  //could be NULL
1256                       0);  //port 0 -> switch decides
1258 #endif
1260     pPktDesc = Pktlib_getDescFromPacket(tip);
1261     /* Send the packet out to transmit Q*/
1262     Qmss_queuePushDescSize (flowPSCmdInfo.txQueue, 
1263                         pPktDesc, 
1264                         NWAL_DESC_SIZE);
1265     vv3= hplib_mUtilGetPmuCCNT();
1266     cache_op_b2= Osal_cache_op_measure(&n_c_ops);
1268     sum_vv1 += (vv2-vv1);
1269     if(!house_pkts_gened)
1270     {
1271         /* first packet. Take out the PS command label creation cost */
1272         sum_vv1 = sum_vv1 - nwal_sum_flow_vv2;
1273     }
1275     sum_vv3 += (vv3-vv2)-(long) (cache_op_b2-cache_op_b1); //sub out cache op cost
1277     // netapi_Log("pktio send. full=%d metadata=%d netapi_pktioSend=%d\n", vv3-vv1,  vv2-vv1,  vv3-vv2);
1278     stats[coreid].itx +=1;
1279     house_pkts_gened +=1;
1280     }
1281     {
1282         unsigned long long  ccycles;
1283         ccycles =Osal_cache_op_measure(&n_c_ops);
1284         if (sum_vv1) 
1285         {
1286             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", 
1287               stats[coreid].itx, sum_vv1/stats[coreid].itx,  nwal_sum_flow_vv2, sum_vv3/stats[coreid].itx, 
1288               n_c_ops, ccycles, n_c_ops? (ccycles/(n_c_ops/2L)) : 0);
1289 #if 0
1290             netapi_Log("NWAL Profile Cycles: Prof1= %d,Prof2=%d,Prof3=%d,Prof4=%d,Prof5=%d ,Prof6=%d \n",
1291               nwal_sum_vv1/stats[coreid].itx,nwal_sum_vv2/stats[coreid].itx,nwal_sum_vv3/stats[coreid].itx,
1292               nwal_sum_vv4/stats[coreid].itx,nwal_sum_vv5/stats[coreid].itx,nwal_sum_vv6/stats[coreid].itx);
1293   
1294 #endif  
1296             if(stats[core_id].itx2)
1297             {
1298                 netapi_Log("nwal_flowSend Profile Cycles: Prof1= %d,Prof2=%d \n",
1299                 nwal_sum_flow_vv1/stats[coreid].itx2,nwal_sum_flow_vv2/stats[coreid].itx2);
1300             }
1301         }
1302     }
1303 #endif
1305 NETCP_CFG_ROUTE_T test_route;
1307 void netTest_utilCreateInterfaces(uint8_t num_macs, uint8_t num_ips, Bool match_action_host)
1309     int err, i;
1311     if (match_action_host)
1312     {
1313         memset(&test_route, 0, sizeof(NETCP_CFG_ROUTE_T));
1314         test_route.valid_params = NETCP_CFG_VALID_PARAM_MATCH_ACTION_DEST;
1315         test_route.match_destination = NETCP_CFG_ACTION_TO_SW;
1316         test_route.routeType = 0;
1317         test_route.p_flow = NULL;
1318         test_route.p_dest_q = NULL;
1319     
1320         for (i = 0; i < num_macs; i++)
1321         {
1322             /* add mac intefaces */
1323             mac[i] = netapi_netcpCfgCreateMacInterface(
1324                               netapi_handle,
1325                               &netTestCfg.mac[i][0],
1326                               NULL,
1327                               i,
1328                               netTestCfg.switch_port[i],
1329                               (NETCP_CFG_ROUTE_HANDLE_T)  &test_route,
1330                               (NETCP_CFG_VLAN_T ) NULL ,  //future
1331                               0,
1332                               1, 
1333                               &err);
1334            if (err)
1335                netapi_Log("netapi_netcpCfgCreateMacInterface failed with error: %d\n",err);
1336     
1337         }
1338     }
1339     else
1340     {
1341         for (i = 0; i < num_macs; i++)
1342         {
1343             /* add mac intefaces */
1344             mac[i] = netapi_netcpCfgCreateMacInterface(
1345                               netapi_handle,
1346                               &netTestCfg.mac[i][0],
1347                               NULL,
1348                               i,
1349                               netTestCfg.switch_port[i],
1350                               (NETCP_CFG_ROUTE_HANDLE_T)  NULL,
1351                               (NETCP_CFG_VLAN_T ) NULL ,  //future
1352                               0,
1353                               1, 
1354                               &err);
1355            if (err)
1356                netapi_Log("netapi_netcpCfgCreateMacInterface failed with error: %d\n",err);
1357     
1358         }
1360     }
1361     for (i = 0; i < num_ips; i++)
1362     {
1363         //attach an IP to this interface
1364         ip_rule[i]=netapi_netcpCfgAddIp(
1365                           netapi_handle,
1366                           netTestCfg.attach_iface[i],
1367                           nwal_IPV4,
1368                           (nwalIpAddr_t*)&netTestCfg.ip[i].ipv4[0],
1369                           NULL,
1370                           NULL,  //all IP
1371                           (NETCP_CFG_ROUTE_HANDLE_T) NULL,
1372                           (void*)NULL,
1373                           &err
1374                           );
1375         if (err)
1376             netapi_Log("netapi_netcpCfgAddIp: add ip failed with error %d\n", err);
1377     }
1380 void netTest_utilDeleteInterfaces(uint8_t num_macs, uint8_t num_ips)
1382     int err,i;
1383     //delete IPs and MAC Interfacess
1384     for (i = 0; i < num_ips; i++)
1385     {
1386         err = 0;
1387         netapi_netcpCfgDelIp(netapi_handle, netTestCfg.attach_iface[i], nwal_IPV4, 
1388                       NULL, NULL, ip_rule[i], &err);
1389     }
1390     for (i = 0; i < num_macs; i++)
1391     {
1392         err = 0;
1393         netapi_netcpCfgDelMac(netapi_handle,i,&err);
1394     }
1395     
1396     //netapi_netcpCfgDelMac(netapi_handle,0,&err);
1397     //netapi_netcpCfgDelMac(netapi_handle,1,&err);