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"
45 #include <stdio.h>
46 #include <stdlib.h>
47 #include <unistd.h>
48 #include <string.h>
49 #include <signal.h>
50 #include <pthread.h>
51 #include "trie.h"
52 #include "router.h"
54 #include <ti/drv/sa/salld.h>
55 #include <ti/drv/pa/pa.h>
57 extern NETAPI_T netapi_handle;
58 extern netTestConfig_t netTestCfg;
59 extern netTestConfig_t config;
60 extern netTestSA_t sa_info[];
61 extern NETAPI_SCHED_HANDLE_T * scheduler[];
62 extern Pktlib_HeapHandle ourHeap;
63 extern NETCP_CFG_IP_T ip_rule[];
64 extern NETCP_CFG_MACIF_T mac[];
65 Trie * our_router;
66 STATS_T stats[TUNE_NETAPI_NUM_CORES];
67 paSysStats_t netcp_stats;
69 //#include "router.c"
74 OUR_ROUTE_T routes[MAX_ROUTES]=
75 {
76 {0,{0xD4,0xbe,0xd9,0x00,0xd3,0x7e, 0x00,0x01,0x02,0x03,0x14,0x02,0x08,0x00},0},
77 {0,{0x00,0x00,0x0,0x00,0x0,0x0, 0x00,0x00,0x00,0x00,0x00,0x00,0x08,0x00},0},
78 {0,{0xD4,0xbe,0xd9,0x00,0xd3,0x7e, 0x00,0x01,0x02,0x03,0x14,0x02,0x08,0x00},0},
79 {0,{0x00,0x15,0x60,0xa1,0xf7,0xbe, 0x00,0x01,0x02,0x03,0x04,0x05,0x08,0x00},0},
80 {0,{0xd4,0xbe,0xd9,0x00,0xd3,0x7e, 0x00,0x01,0x02,0x03,0x04,0x05,0x08,0x00},0}};
82 static struct LastPktInfo lpInfo;
83 int check_header(HEAD_T * p_head, PKTIO_METADATA_T * p_meta)
84 {
85 #ifdef MULTI_THREAD
86 int coreid=Osal_nwalGetProcId(); //who we are(thread local)
87 //int coreid = our_core;
88 #else
89 int coreid=0;
90 #endif
91 if (NWAL_RX_FLAG1_META_DATA_VALID & p_meta->u.rx_meta->rxFlag1)
92 {
93 lpInfo.iface = ((unsigned int)p_meta->u.rx_meta->appId) &0xff; //last byte is interface num
94 lpInfo.ipcsum =(p_meta->u.rx_meta->rxFlag1 & NWAL_RX_FLAG1_IPV4_CHKSUM_VERIFY_MASK )== NWAL_RX_FLAG1_IPV4_CHKSUM_VERIFY_ACK ? 1 : 0;
95 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;
96 if ((unsigned int)p_meta->u.rx_meta->appId & NETAPI_NETCP_MATCH_IPSEC)
97 {
98 stats[coreid].sec_rx++;
99 }
100 if ((unsigned int)p_meta->u.rx_meta->appId & NETAPI_NETCP_MATCH_IPSEC_POLICY)
101 {
102 stats[coreid].secp_rx++;
103 }
105 if ((unsigned int)p_meta->u.rx_meta->appId & NETAPI_NETCP_MATCH_CLASS)
106 {
107 int c= ((unsigned int)p_meta->u.rx_meta->appId >>8)&0xffff;
108 if (c==0) stats[coreid].n_class0_rx +=1;
109 else if (c==1) stats[coreid].n_class1_rx +=1;
110 else if (c==2) stats[coreid].n_class2_rx +=1;
111 else netapi_Log("**NET_TEST RX -unknown class: %x\n", p_meta->u.rx_meta->appId);
112 }
113 }
115 return 1;
116 }
119 static int scnt=0;
120 int QUIT;
121 void mysig(int x)
122 {
123 QUIT=1;
124 scnt+=1;
125 netapi_Log(">net_test: recv'd signal %d cnt=%d\n",x,scnt);
126 if (scnt > 10)
127 {
128 netapi_Log(">net_test: WARNING EXITING WITH PROPER SHUTDOWN, LUTS LEFT ACTIVE\n");
129 exit(1);
130 }
131 }
132 unsigned long peek(unsigned long * p)
133 {
134 return *p;
135 }
136 void dump_descr(unsigned long *p, int n)
137 {
138 netapi_Log("--------dump of descriptor %d %x\n", n, (int) p);
139 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]);
140 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]);
141 netapi_Log("-----------------------------\n");
142 }
143 void dump_header(unsigned long *p, int n, int a, int r)
144 {
145 netapi_Log("--------dump of header %d %x appID=%x flag1=%x\n", n, (int) p,a,r);
146 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]);
147 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]);
148 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]);
149 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]);
150 netapi_Log("-----------------------------\n");
151 }
153 void netapi_dump_buf
154 (
155 unsigned long * buf,
156 uint32_t buf_length
157 )
158 {
159 uint8_t count = 0;
160 uint16_t dump_size;
161 uint8_t* tmp_buf;
162 uint8_t row_count;
163 static uint8_t first = 0;
165 //if(first > 2) return;
167 //first++;
169 dump_size = buf_length ;
171 tmp_buf = (uint8_t *)(buf);
173 netapi_Log("netapi *: - 8 bit word hex Length: %d Start \n",buf_length);
174 do
175 {
176 row_count = (dump_size - count);
178 if(row_count == 0)
179 {
180 break;
181 }
183 if(row_count > 4)
184 {
185 row_count = 4;
186 }
188 switch (row_count)
189 {
190 case 4:
191 {
192 netapi_Log("netapi *:%02d : %02x %02x %02x %02x \n",
193 count,tmp_buf[0],tmp_buf[1],tmp_buf[2],tmp_buf[3]);
194 break;
195 }
196 case 3:
197 {
198 netapi_Log("netapi *: %02d : %02x %02x %02x \n",
199 count,tmp_buf[0],tmp_buf[1],tmp_buf[2]);
200 break;
201 }
203 case 2:
204 {
205 netapi_Log("netapi *: %02d : %02x %02x \n",
206 count,tmp_buf[0],tmp_buf[1]);
207 break;
208 }
210 case 1:
211 {
212 netapi_Log("netapi *: %02d : %02x \n",
213 count,tmp_buf[0]);
214 break;
215 }
217 default:
218 {
219 /* Should never reach here */
220 netapi_Log("netapi *: Internal Error in netapi_dump_buf().Row Count: %d \n", row_count);
221 return;
222 }
223 }
225 tmp_buf = tmp_buf + row_count;
226 count = count + row_count;
228 }while(count < dump_size);
230 netapi_Log("netapi *: - Byte hex Dump End \n");
232 }
233 long htonl(long x)
234 {
235 long temp = (x&0xff000000)>>24 | (x&0xff0000)>>8 | (x&0xff00)<<8 | (x&0xff)<<24 ;
236 return temp;
237 }
239 unsigned char hex2dec(char *p_s)
240 {
241 int val;
242 sscanf(p_s,"%x",&val);
243 return val&0xff;
244 }
246 /********************************************************************
247 * FUNCTION PURPOSE: Ones complement addition utility
248 ********************************************************************
249 ********************************************************************/
250 uint16_t test_utilOnesComplementAdd (uint16_t v1, uint16_t v2)
251 {
252 uint32_t result;
254 result = (uint32_t)v1 + (uint32_t)v2;
255 result = (result >> 16) + (result & 0xffff);
256 result = (result >> 16) + (result & 0xffff);
258 return ((uint16_t)result);
259 }
261 /********************************************************************
262 * FUNCTION PURPOSE: Ones complement checksum utility
263 ********************************************************************
264 ********************************************************************/
265 uint16_t test_utilOnesCompChkSum (uint8_t *p, uint32_t nwords)
266 {
267 uint16_t chksum = 0;
268 uint16_t v;
269 uint32_t i;
270 uint32_t j;
272 for (i = j = 0; i < nwords; i++, j+=2) {
273 v = (p[j] << 8) | p[j+1];
274 chksum = test_utilOnesComplementAdd (chksum, v);
275 }
276 return (chksum);
277 } /* utilOnesCompChkSum */
279 /**************************************************************************************
280 * FUNCTION PURPOSE: Compute ipv4 psudo checksum
281 **************************************************************************************
282 * DESCRIPTION: Compute ipv4 psudo checksum
283 **************************************************************************************/
284 uint16_t test_utilGetIpv4PsudoChkSum (uint8_t *data, uint16_t payloadLen)
285 {
286 uint16_t psudo_chksum;
288 psudo_chksum = test_utilOnesCompChkSum (&data[12], 4);
289 psudo_chksum = test_utilOnesComplementAdd(psudo_chksum, (uint16_t) data[9]);
290 psudo_chksum = test_utilOnesComplementAdd(psudo_chksum, payloadLen);
292 return (psudo_chksum);
294 } /* utilGetIpv4PsudoChkSum */
296 #define CHECK_SET_PARAM(ARG1, ARG2) \
297 do { \
298 if(strcmp(key, ARG1) == 0) { \
299 if(d1)strncpy(ARG2,d1,CONFIG_STRING_LEN); \
300 continue; \
301 } \
302 } while(0)
304 #define CHECK_SET_PARAM2(ARG1, ARG2, ARG3) \
305 do { \
306 if(strcmp(key, ARG1) == 0) { \
307 if(d1) strncpy(ARG2,d1,CONFIG_STRING_LEN); \
308 if(d2) strncpy(ARG3,d2,CONFIG_STRING_LEN); \
309 continue; \
310 } \
311 } while(0)
313 #define CHECK_SET_PARAM_SA(ARG1, ARG2, ARG3, ARG4, ARG5, \
314 ARG6, ARG7, ARG8, ARG9, ARG10, \
315 ARG11, ARG12,ARG13, ARG14, ARG15, ARG16,ARG17, ARG18) \
316 do { \
317 if(d1) strncpy(ARG2,d1,CONFIG_STRING_LEN); \
318 if(d2) strncpy(ARG3,d2,CONFIG_STRING_LEN); \
319 if(d3) strncpy(ARG4,d3,CONFIG_STRING_LEN); \
320 if(d4) strncpy(ARG5,d4,CONFIG_STRING_LEN); \
321 if(d5) strncpy(ARG6, d5,CONFIG_STRING_LEN); \
322 if(d6) strncpy(ARG7,d6,CONFIG_STRING_LEN); \
323 if(d7) strncpy(ARG8,d7,CONFIG_STRING_LEN); \
324 if(d8) strncpy(ARG9,d8,CONFIG_STRING_LEN); \
325 if(d9) strncpy(ARG10,d9,CONFIG_STRING_LEN); \
326 if(d10) strncpy(ARG11,d10,CONFIG_STRING_LEN); \
327 if(d11) strncpy(ARG12,d11,CONFIG_STRING_LEN); \
328 if(d12) strncpy(ARG13,d12,CONFIG_STRING_LEN); \
329 if(d13) strncpy(ARG14,d13,CONFIG_STRING_LEN); \
330 if(d14) strncpy(ARG15,d14,CONFIG_STRING_LEN); \
331 if(d15) strncpy(ARG16,d15,CONFIG_STRING_LEN); \
332 if(d16) strncpy(ARG17,d16,CONFIG_STRING_LEN); \
333 if(d17) strncpy(ARG18,d17,CONFIG_STRING_LEN); \
334 continue; \
335 } while(0)
337 void print_ipsec_stats(Sa_IpsecStats_t *p_saIpsecStats, nwal_saAALG auth, nwal_saEALG cipher)
338 {
339 #if 0
340 if(retVal != nwal_OK)
341 {
342 System_System_netapi_Log("CORE: %d Error getting IP Sec Stats: Ret Status: %d \n",
343 retVal);
344 return(nwal_FALSE);
345 }
346 if((p_saIpsecStats->pktEncHi) ||(p_saIpsecStats->pktEncLo))
347 {
348 Debug_netapi_Log("------------- IPSec TX (Encryption Channel) Stats BEGIN --\n");
349 }
350 else
351 {
352 netapi_Log("------------- IPSec RX (Decryption Channel) Stats BEGIN --\n");
353 }
354 #endif
355 netapi_Log("\nAutentication mode: %d, Encryption Mode: %d\n", auth, cipher);
356 netapi_Log("IPSec replayOld:0x%x,replayDup:0x%x,authFail:0x%x \n",
357 p_saIpsecStats->replayOld,p_saIpsecStats->replayDup,p_saIpsecStats->authFail);
358 netapi_Log("IPSec txESN:0x%x,rxESN:0x%x,pktEncHi:0x%x,pktEncLo:0x%x,pktDecHi:0x%x,pktDecLo:0x%x \n",
359 p_saIpsecStats->txESN,p_saIpsecStats->rxESN,p_saIpsecStats->pktEncHi,
360 p_saIpsecStats->pktEncLo,p_saIpsecStats->pktDecHi,p_saIpsecStats->pktDecLo);
361 }
363 void print_datamode_stats(Sa_DataModeStats_t *p_saDataModeStats, nwal_saAALG auth, nwal_saEALG cipher)
364 {
366 netapi_Log("\nAutentication mode: %d, Encryption Mode: %d\n", auth, cipher);
367 netapi_Log(" Packets processedHi: 0x%x, Packets processed Lo:0x%x\n",
368 p_saDataModeStats->pktHi, p_saDataModeStats->pktLo);
369 }
371 /******************************************************
372 * stats callback
373 *******************************************************/
374 void our_stats_cb_mt(NETAPI_T h, paSysStats_t* pPaStats)
375 {
377 #ifdef MULTI_THREAD
378 int coreid=Osal_nwalGetProcId(); //who we are(thread local)
379 //int coreid = our_core;
380 #else
381 int coreid=0;
382 #endif
384 stats[coreid].n_stats_cb +=1;
385 if(pPaStats) memcpy(&netcp_stats,pPaStats, sizeof(paSysStats_t));
386 }
387 void our_stats_cb(NETAPI_T h, paSysStats_t* pPaStats)
388 {
389 uint32_t numFreeDataPackets;
390 uint32_t numZeroBufferPackets;
391 uint32_t numPacketsinGarbage;
392 Pktlib_HeapStats pktLibHeapStats;
393 int i;
394 unsigned long long bcpp;
395 unsigned long long bcpp_noc;
396 unsigned long long bcpp_app;
397 unsigned long long bcpp_tx;
398 unsigned long long npL;
399 unsigned long long cyclesL;
400 unsigned long long ccyclesL; //cache cycles
401 unsigned long long tmp_npL[TUNE_NETAPI_NUM_CORES];
402 unsigned long long tmp_cyclesL[TUNE_NETAPI_NUM_CORES];
403 unsigned long long tmp_ccyclesL[TUNE_NETAPI_NUM_CORES]; //cache cycles
404 NETAPI_SA_STATS_T netapi_sa_stats;
406 for (i=0;i < TUNE_NETAPI_NUM_CORES;i++)
407 {
408 printf("Per Core Statistics for CORE %d\n", i);
409 printf(">*****stats @ %lld (#cbs%d) \n", hplib_mUtilGetTimestamp(),stats[i].n_stats_cb);
410 printf(">itx=%d rx=%d tx=%d bad=%d slow=%d \n>rx_class0=%d rx_class1=%d rx_class2=%dsecRx=%d\t"
411 "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",
412 stats[i].itx, stats[i].rx, stats[i].tx, stats[i].n_bad, stats[i].n_new,
413 stats[i].n_class0_rx, stats[i].n_class1_rx, stats[i].n_class2_rx, stats[i].sec_rx,
414 stats[i].secp_rx, stats[i].sb_rx, stats[i].sb_tx, stats[i].n_auth_ok,
415 stats[i].sec_tx, stats[i].rx_min, stats[i].tx_min, stats[i].exceptionPktsFrag, stats[i].exceptionPktsOther);
416 printf(">if rx stats: %d %d %d\n",stats[i].if_rx[0],stats[i].if_rx[1],stats[i].if_rx[2]);
417 printf(">core rx stats: %d \n",stats[i].core_rx);
419 if (stats[i].rx && stats[i].tx)
420 printf("decrypt time per packet(avg): %lu, encrypt time per packet(avg): %lu\n",
421 (unsigned long) stats[i].total_decrypt_time/stats[i].rx, (unsigned long) stats[i].total_encrypt_time/stats[i].tx);
424 if (npL && stats[i].rx)
425 {
426 bcpp = cyclesL/npL;
427 bcpp_noc = (cyclesL-ccyclesL)/npL;
428 bcpp_app = (stats[i].app_cycles-stats[i].tx_cache_cycles)/stats[i].rx;
429 }
430 else
431 {
432 bcpp = bcpp_noc=bcpp_app=0L;
433 }
434 if (stats[i].tx)
435 {
436 bcpp_tx = (stats[i].send_cycles-stats[i].tx_cache_cycles)/stats[i].tx;
437 }
438 else
439 {
440 bcpp_tx = 0L;
441 }
442 printf("> ++ busy cycles pp=%lld (%lld wo cache ops) (app+tx= %lld) (tx= %lld) ++\n",
443 bcpp,bcpp_noc,bcpp_app, bcpp_tx);
444 printf("\n");
445 }
447 #ifdef MULTI_THREAD
448 for (i=0;i < TUNE_NETAPI_NUM_CORES;i++)
449 {
450 if(scheduler[i])
451 {
452 netapi_schedGetStats(scheduler[i],&tmp_npL[0],&tmp_cyclesL[0],&tmp_ccyclesL[0]);
453 npL = tmp_npL[0]+tmp_npL[1];
454 cyclesL = tmp_cyclesL[0]+tmp_cyclesL[1];
455 ccyclesL = tmp_ccyclesL[0]+tmp_ccyclesL[1];
456 }
457 }
458 #else
459 netapi_schedGetStats(our_sched, &npL,&cyclesL,&ccyclesL);
460 #endif
462 if(pPaStats)
463 {
464 printf("C1 number of packets: %d\n", pPaStats->classify1.nPackets);
465 printf("C1 number IPv4 packets: %d\n", pPaStats->classify1.nIpv4Packets);
466 printf("C1 number IPv6 packets: %d\n", pPaStats->classify1.nIpv6Packets);
467 printf("C1 number Custom packets: %d\n", pPaStats->classify1.nCustomPackets);
468 printf("C1 number SRIO packets: %d\n", pPaStats->classify1.nSrioPackets);
469 printf("C1 number LLC/SNAP Fail packets: %d\n", pPaStats->classify1.nLlcSnapFail);
470 printf("C1 number table matched: %d\n", pPaStats->classify1.nTableMatch);
471 printf("C1 number failed table matched: %d\n", pPaStats->classify1.nNoTableMatch);
472 printf("C1 number IP Fragmented packets: %d\n", pPaStats->classify1.nIpFrag);
473 printf("C1 number IP Depth Overflow: %d\n", pPaStats->classify1.nIpDepthOverflow);
474 printf("C1 number VLAN Depth Overflow: %d\n", pPaStats->classify1.nVlanDepthOverflow);
475 printf("C1 number GRE Depth Overflow: %d\n", pPaStats->classify1.nGreDepthOverflow);
476 printf("C1 number MPLS Packets: %d\n", pPaStats->classify1.nMplsPackets);
477 printf ("C1 number of parse fail: %d\n",pPaStats->classify1.nParseFail);
478 printf("C1 number of Invalid IPv6 Opt: %d\n", pPaStats->classify1.nInvalidIPv6Opt);
479 printf("C1 number of TX IP Fragments: %d\n", pPaStats->classify1.nTxIpFrag);
480 printf ("C1 number of silent discard: %d\n",pPaStats->classify1.nSilentDiscard);
481 printf("C1 number of invalid control: %d\n", pPaStats->classify1.nInvalidControl);
482 printf ("C1 number of invalid states: %d\n",pPaStats->classify1.nInvalidState);
483 printf ("C1 number of system fails: %d\n",pPaStats->classify1.nSystemFail);
484 printf ("C2 number Packets : %d\n",pPaStats->classify2.nPackets);
485 printf ("C2 number udp : %d\n",pPaStats->classify2.nUdp);
486 printf ("C2 number tcp : %d\n",pPaStats->classify2.nTcp);
487 printf ("C2 number Custom : %d\n",pPaStats->classify2.nCustom);
488 printf ("C2 number silent drop : %d\n",pPaStats->classify2.nSilentDiscard);
489 printf ("C2 number invalid cntrl : %d\n\n",pPaStats->classify2.nInvalidControl);
490 printf ("C2 number Modify Stats Cmd Fail : %d\n\n",pPaStats->modify.nCommandFail);
491 }
492 Pktlib_getHeapStats(ourHeap, &pktLibHeapStats);
493 printf("main heap stats> #free=%d #zb=%d #garbage=%d\n", pktLibHeapStats.numFreeDataPackets,
494 pktLibHeapStats.numZeroBufferPackets, pktLibHeapStats.numPacketsinGarbage);
495 printf(" > #dataBufThreshStatus=%d #dataBufStarvCounter=%d #zBufThreshStatus=%d #zBufStarvCounter=%d \n",
496 pktLibHeapStats.dataBufferThresholdStatus,pktLibHeapStats.dataBufferStarvationCounter,
497 pktLibHeapStats.zeroDataBufferThresholdStatus, pktLibHeapStats.zeroDataBufferStarvationCounter);
499 #if 0
500 netapi_Log("pa2sa descriptor area dump\n");
501 for(i=0;i<TUNE_NETAPI_CONFIG_MAX_PA_TO_SA_DESC;i++)
502 {
503 extern long * pa2sa_descr_base;
504 long * tip= &pa2sa_descr_base[32*i];
505 dump_descr(tip, i);
506 }
507 netapi_Log("sa2pa descriptor area dump\n");
508 for(i=0;i<TUNE_NETAPI_CONFIG_MAX_SA_TO_PA_DESC;i++)
509 {
510 extern long * sa2pa_descr_base;
511 long * tip= &sa2pa_descr_base[32*i];
512 dump_descr(tip, i);
513 }
514 #endif
515 for (i = 0; i < MAX_SEC_INDEX; i++)
516 {
517 /* Statistics for RX Tunnel */
518 memset(&netapi_sa_stats, 0, sizeof(netapi_sa_stats));
519 if (sa_info[i].dir ==NWAL_SA_DIR_INBOUND )
520 {
521 netapi_getSaStats(netapi_handle, sa_info[i].rx_tunnel, &netapi_sa_stats);
522 if (netapi_sa_stats.validParams & NETAPI_IPSEC_STAT_VALID)
523 {
524 print_ipsec_stats(&(netapi_sa_stats.saIpsecStats),
525 sa_info[i].authMode,
526 sa_info[i].cipherMode);
527 }
528 if (netapi_sa_stats.validParams & NETAPI_SIDEBAND_DATA_MODE_STAT_VALID)
529 {
530 print_datamode_stats(&(netapi_sa_stats.dataModeStats),
531 sa_info[i].authMode,
532 sa_info[i].cipherMode);
533 }
534 }
535 else if (sa_info[i].dir ==NWAL_SA_DIR_OUTBOUND)
536 {
537 netapi_getSaStats(netapi_handle, sa_info[i].tx_tunnel, &netapi_sa_stats);
538 if (netapi_sa_stats.validParams & NETAPI_IPSEC_STAT_VALID)
539 {
540 print_ipsec_stats(&(netapi_sa_stats.saIpsecStats),
541 sa_info[i].authMode,
542 sa_info[i].cipherMode);
543 }
544 if (netapi_sa_stats.validParams & NETAPI_SIDEBAND_DATA_MODE_STAT_VALID)
545 {
546 print_datamode_stats(&(netapi_sa_stats.dataModeStats),
547 sa_info[i].authMode,
548 sa_info[i].cipherMode);
549 }
550 }
551 else
552 netapi_Log("our_stats_cb: invalid SA direction\n");
553 }
554 netapi_dump_internal_heap_stats();
555 }
558 void parse_one_mac(char * p_mac_str, unsigned char *p_mac)
559 {
560 int index = 0;
561 int i;
562 char *pch = strtok (&(p_mac_str[0]),"-");
564 while (pch != NULL)
565 {
566 p_mac[index] = hex2dec(pch);
567 index++;
568 pch = strtok (NULL,"-");
569 }
570 }
573 void parse_one_key(char *p_key_str, unsigned char *p_key)
574 {
575 int index = 0;
576 int i;
577 char * pch = strtok (&p_key_str[0],",");
579 while (pch != NULL)
580 {
581 p_key[index] = hex2dec(pch);
582 index++;
583 pch = strtok (NULL,",");
584 }
585 }
587 void parse_one_ip(char * p_ip_addr_str, unsigned char * p_ip)
588 {
589 int index = 0;
590 int i;
591 char * pch = strtok (&p_ip_addr_str[0],".");
593 while (pch != NULL)
594 {
595 p_ip[index] = atoi(pch);
596 index++;
597 pch = strtok (NULL,".");
598 }
599 }
601 void parse_mac_address(netTestConfigFile_t *pConfig)
602 {
603 int i;
604 int port = 0;
605 for(i=0;i<NET_TEST_MAX_MAC;i++)
606 {
607 if (strlen(&pConfig->mac[i][0]))
608 {
609 netTestCfg.num_macs++;
610 parse_one_mac(&pConfig->mac[i][0],&netTestCfg.mac[i][0]);
611 sscanf(&pConfig->switch_port[i][0],"sp%d",&netTestCfg.switch_port[i]);
612 }
613 }
614 netapi_Log("parse_mac_address: number of mac address %d\n", netTestCfg.num_macs);
616 }
617 void parse_ip_address(netTestConfigFile_t *pConfig)
618 {
619 int i;
621 for(i=0;i<NET_TEST_MAX_IP;i++)
622 {
623 if (strlen(&pConfig->ip[i][0]))
624 {
625 netTestCfg.num_ips++;
626 parse_one_ip(&pConfig->ip[i][0],&netTestCfg.ip[i].ipv4[0]);
627 sscanf(&pConfig->attach_iface[i][0],"mac%d",&netTestCfg.attach_iface[i]);
628 }
629 }
630 netapi_Log("parse_ip_address: number of ip address %d\n", netTestCfg.num_ips);
631 }
632 void parse_ipsec_mode(netTestConfigFile_t *pConfig)
633 {
635 if (strlen(&pConfig->ipsec_mode_rx[0]))
636 {
637 if (strcmp(pConfig->ipsec_mode_rx, "SIDEBAND") == 0)
638 {
639 netTestCfg.ipsec_mode_rx = IPSEC_MODE_RX_SIDEBAND;
640 }
641 else if (strcmp(pConfig->ipsec_mode_rx, "INFLOW") == 0)
642 {
643 netTestCfg.ipsec_mode_rx = IPSEC_MODE_RX_INFLOW;
644 }
645 else
646 {
647 netapi_Log("parse_ipsec_mode(), invalid RX ipsec mode in config file \n");
648 }
649 }
651 if (strlen(&pConfig->ipsec_mode_tx[0]))
652 {
653 if (strcmp(pConfig->ipsec_mode_tx, "SIDEBAND") == 0)
654 {
655 netTestCfg.ipsec_mode_tx = IPSEC_MODE_TX_SIDEBAND;
656 }
657 else if (strcmp(pConfig->ipsec_mode_tx, "INFLOW") == 0)
658 {
659 netTestCfg.ipsec_mode_tx = IPSEC_MODE_TX_INFLOW;
660 }
661 else
662 {
663 netapi_Log("parse_ipsec_mode(), invalid TX ipsec mode in config file \n");
664 }
665 }
667 }
669 void parse_auth_mode(char *auth_mode_str, nwal_saAALG *auth_mode)
670 {
671 if (strlen(auth_mode_str))
672 {
673 netapi_Log("strlen of auth_mode_str is %d\n", strlen(auth_mode_str));
675 if (strcmp(auth_mode_str, "NULL") == 0)
676 {
677 *auth_mode= NWAL_SA_AALG_NULL;
678 }
679 else if (strcmp(auth_mode_str, "HMAC_MD5") == 0)
680 {
681 *auth_mode= NWAL_SA_AALG_HMAC_MD5;
682 }
683 else if (strcmp(auth_mode_str, "HMAC_SHA1") == 0)
684 {
685 *auth_mode= NWAL_SA_AALG_HMAC_SHA1;
686 }
687 else if (strcmp(auth_mode_str, "HMAC_SHA2_224") == 0)
688 {
689 *auth_mode= NWAL_SA_AALG_HMAC_SHA2_224;
690 }
691 else if (strcmp(auth_mode_str, "HMAC_SHA2_256") == 0)
692 {
693 *auth_mode= NWAL_SA_AALG_HMAC_SHA2_256;
694 }
695 else if (strcmp(auth_mode_str, "GMAC") == 0)
696 {
697 *auth_mode= NWAL_SA_AALG_GMAC;
698 }
699 else if (strcmp(auth_mode_str, "AES_XCBC") == 0)
700 {
701 *auth_mode= NWAL_SA_AALG_AES_XCBC;
702 }
703 else
704 {
705 netapi_Log("parse_auth_mode: invalid auth mode specified\n");
706 }
707 }
708 }
710 void parse_encr_mode(char *ency_mode_str, nwal_saEALG*encr_mode)
711 {
712 if (strlen(ency_mode_str))
713 {
714 if (strcmp(ency_mode_str, "NULL") == 0)
715 {
716 *encr_mode= NWAL_SA_EALG_NULL;
717 }
718 else if (strcmp(ency_mode_str, "AES_CTR") == 0)
719 {
720 *encr_mode= NWAL_SA_EALG_AES_CTR;
721 }
722 else if (strcmp(ency_mode_str, "AES_CBC") == 0)
723 {
724 *encr_mode= NWAL_SA_EALG_AES_CBC;
725 }
726 else if (strcmp(ency_mode_str, "3DES_CBC") == 0)
727 {
728 *encr_mode= NWAL_SA_EALG_3DES_CBC;
729 }
730 else if (strcmp(ency_mode_str, "AES_CCM") == 0)
731 {
732 *encr_mode= NWAL_SA_EALG_AES_CCM;
733 }
734 else if (strcmp(ency_mode_str, "AES_GCM") == 0)
735 {
736 *encr_mode= NWAL_SA_EALG_AES_GCM;
737 }
738 else if (strcmp(ency_mode_str, "AES_XCBC") == 0)
739 {
740 *encr_mode= NWAL_SA_AALG_AES_XCBC;
741 }
742 else
743 {
744 netapi_Log("parse_encr_mode: invalid auth mode specified\n");
745 }
746 }
747 }
749 void parse_proto(char *proto_str, nwal_IpSecProto *proto)
750 {
751 if (strlen(proto_str))
752 {
753 if (strcmp(proto_str, "ESP") == 0)
754 {
755 *proto= nwal_IpSecProtoESP;
756 netapi_Log("parse_proto(): setting proto to ESP\n");
757 }
758 else if (strcmp(proto_str, "AH") == 0)
759 {
760 *proto = nwal_IpSecProtoAH;
761 netapi_Log("parse_proto(): setting proto to AH\n");
762 }
763 else
764 {
765 netapi_Log("parse_proto(), invalid RX ipsec mode in config file \n");
766 }
767 }
768 }
772 void parse_mode(char *mode_str, nwal_saMode *mode)
773 {
774 if (strlen(mode_str))
775 {
776 if (strcmp(mode_str, "TUNNEL") == 0)
777 {
778 *mode= nwal_SA_MODE_TUNNEL;
779 }
780 else if (strcmp(mode_str, "TRANSPORT") == 0)
781 {
782 *mode = nwal_SA_MODE_TRANSPORT;
783 }
784 else
785 {
786 netapi_Log("parse_mode(), invalid RX ipsec mode in config file \n");
787 }
788 }
789 }
791 void parse_ipType(char *ip_type_str, nwal_IpType *ipType)
792 {
793 if (strlen(ip_type_str))
794 {
795 if (strcmp(ip_type_str, "IPV4") == 0)
796 {
797 *ipType= nwal_IPV4;
798 }
799 else if (strcmp(ip_type_str, "IPV6") == 0)
800 {
801 *ipType = nwal_IPV6;
802 }
803 else
804 {
805 netapi_Log("parse_ipType(), invalid RX ipsec mode in config file \n");
806 }
807 }
808 }
810 void parse_spi(char *spi_str, uint32_t *spi)
811 {
812 if (strlen(spi_str))
813 {
814 *spi = (int)strtol(spi_str, NULL, 0);
815 }
816 }
818 void parse_replayWindow(char *replay_window_str, uint32_t *replay_window)
819 {
820 *replay_window = atoi(replay_window_str);
821 }
823 void parse_esn(char *esn_str, uint32_t *esn)
824 {
825 *esn = atoi(esn_str);
826 }
828 void parse_key_size(char *key_size_str, uint16_t *key_size)
829 {
830 *key_size = atoi(key_size_str);
831 }
833 void parse_tunnel_id(char * tunnel_id_str, uint32_t *tunnel_id)
834 {
835 if (strlen(tunnel_id_str))
836 {
837 *tunnel_id = (int)strtol(tunnel_id_str, NULL, 0);
838 }
839 }
841 void parse_dir(char* dir_str, nwal_SaDir *dir)
842 {
843 if (strlen(dir_str))
844 {
845 if (strcmp(dir_str, "INBOUND") == 0)
846 {
847 *dir= NWAL_SA_DIR_INBOUND;
848 }
849 else if (strcmp(dir_str, "OUTBOUND") == 0)
850 {
851 *dir = NWAL_SA_DIR_OUTBOUND;
852 }
853 else
854 netapi_Log("parse_dir: invalid direction\n");
855 }
856 }
857 void parse_one_fp(char * p_fp_str, uint8_t* start, uint8_t* end)
858 {
859 int index = 0;
860 int i;
862 char *pch = strtok (&(p_fp_str[0]),"-");
863 *start = atoi(pch);
864 pch = strtok (NULL,"-");
865 *end = atoi(pch);
866 netapi_Log("parse_one_fp: start %d, end %d\n", *start, *end);
867 }
870 void parse_sp(netTestConfigFile_t *pConfig)
871 {
872 int i;
873 int port = 0;
874 for(i=0;i<NET_TEST_MAX_FP_THREAD;i++)
875 {
876 if (strlen(&pConfig->sp[i][0]))
877 {
878 netTestCfg.num_sp_threads++;
879 parse_one_fp(&pConfig->sp[i][0],(uint8_t*)&netTestCfg.sp_proc_start[i], (uint8_t*)&netTestCfg.sp_proc_end);
880 }
881 if (strlen(&pConfig->sp_thread_num[i][0]))
882 {
883 netTestCfg.sp_thread_num[i] = atoi((char*)(&pConfig->sp_thread_num[i]));
884 netapi_Log("parse_sp: thread_num[%d]: %d\n", i, netTestCfg.sp_thread_num[i]);
885 }
886 }
887 netapi_Log("parse_sp: number of sp threads %d\n", netTestCfg.num_sp_threads);
889 }
892 void parse_fp(netTestConfigFile_t *pConfig)
893 {
894 int i;
895 int port = 0;
896 for(i=0;i<NET_TEST_MAX_FP_THREAD;i++)
897 {
898 if (strlen(&pConfig->fp[i][0]))
899 {
900 netTestCfg.num_fp_threads++;
901 parse_one_fp(&pConfig->fp[i][0],(uint8_t*)&netTestCfg.fp_proc_start[i], (uint8_t*)&netTestCfg.fp_proc_end);
902 }
903 if (strlen(&pConfig->fp_thread_num[i][0]))
904 {
905 netTestCfg.fp_thread_num[i] = atoi((char*)(&pConfig->fp_thread_num[i]));
906 netapi_Log("parse_fp: thread_num[%d]: %d\n", i, netTestCfg.fp_thread_num[i]);
907 }
908 }
909 netapi_Log("parse_fp: number of fp threads %d\n", netTestCfg.num_fp_threads);
911 }
914 void parse_ipsec_if_no(netTestConfigFile_t *pConfig)
915 {
916 if (strlen(&pConfig->ipsec_if_no[0]))
917 {
918 netTestCfg.ipsec_if_no= atoi(&pConfig->ipsec_if_no[0]);
919 netapi_Log("parse_ipsec_if_no %d\n",netTestCfg.ipsec_if_no);
920 }
921 }
923 void parse_sa(netTestConfigFile_t *pConfig, int i)
924 {
925 parse_dir((char*) &pConfig->sa_config[i].dir, &netTestCfg.sa_info[i].dir);
926 parse_spi((char*)&pConfig->sa_config[i].spi, &netTestCfg.sa_info[i].spi);
927 parse_proto((char*)&pConfig->sa_config[i].proto, &netTestCfg.sa_info[i].proto);
928 parse_mode((char*)&pConfig->sa_config[i].saMode, &netTestCfg.sa_info[i].saMode);
929 parse_ipType((char*)&pConfig->sa_config[i].ipType, &netTestCfg.sa_info[i].ipType);
930 parse_one_ip((char*)&pConfig->sa_config[i].src, (unsigned char *)&netTestCfg.sa_info[i].src);
931 parse_one_ip((char*)&pConfig->sa_config[i].dst, (unsigned char *)&netTestCfg.sa_info[i].dst);
932 parse_replayWindow((char*)&pConfig->sa_config[i].replayWindow, &netTestCfg.sa_info[i].replayWindow);
933 parse_auth_mode((char*)&pConfig->sa_config[i].authMode, &netTestCfg.sa_info[i].authMode);
934 parse_encr_mode((char*)&pConfig->sa_config[i].cipherMode, &netTestCfg.sa_info[i].cipherMode);
935 parse_esn((char*)&pConfig->sa_config[i].esnLo, &netTestCfg.sa_info[i].esnLo);
936 parse_esn((char*)&pConfig->sa_config[i].esnHi, &netTestCfg.sa_info[i].esnHi);
937 parse_key_size((char*)&pConfig->sa_config[i].encKeySize, &netTestCfg.key_params[i].encKeySize);
938 parse_key_size((char*)&pConfig->sa_config[i].macKeySize, &netTestCfg.key_params[i].macKeySize);
941 parse_one_key((char*) &pConfig->sa_config[i].encr_key, &netTestCfg.encr_key[i][0]);
942 netTestCfg.key_params[i].pEncKey = (uint8_t*)&netTestCfg.encr_key[i][0];
944 parse_one_key((char*)&pConfig->sa_config[i].auth_key, &netTestCfg.auth_key[i][0]);
945 netTestCfg.key_params[i].pAuthKey= (uint8_t*)&netTestCfg.auth_key[i][0];
948 parse_tunnel_id((char*)&pConfig->sa_config[i].tunnel_id, &netTestCfg.tunnel_id[i]);
951 }
954 int n_routes=0;
955 int n_dst_ips=0;
956 void parse_routes(netTestConfigFile_t *pConfig)
957 {
958 int i;
959 int said=0;
960 for(i=0;i<MAX_ROUTES;i++)
961 {
962 int port;
963 if (pConfig->routes[i][0])
964 {
965 port=atoi(&pConfig->ports[i][0]);
966 if((port<1)||(port>2)) continue; //bad port #: only 1 or 2 valid
967 netapi_Log("parse_routes [%d]: %s\n", i, &pConfig->routes[i][0]);
968 if(strncmp(&pConfig->routes[i][0],"MAC",3)==0)
969 {
970 routes[i].out_port = port;
971 parse_one_mac(&pConfig->routes[i][3],&routes[i].out_mac[0]);
972 //memcpy(&routes[i].out_mac[6], ((port==1) ?&config.mac0[0]: &config.mac1[0] ),6);
973 memcpy(&routes[i].out_mac[6], ((port==1) ?&netTestCfg.mac[0][0]: &netTestCfg.mac[1][0] ),6);
974 routes[i].out_mac[12]=0x08;
975 routes[i].out_mac[13]=0x00;
976 routes[i].sec_ptr=NULL;
977 n_routes+=1;
978 }
979 else if (strncmp(&pConfig->routes[i][0],"SA",2)==0)
980 {
981 said=atoi(&pConfig->routes[i][2]) ;
982 routes[i].sec_ptr=&sa_info[said];
983 n_routes+=1;
984 }
985 }
986 }
987 our_router = route_init();
988 for (i=0;i<MAX_ROUTES;i++)
989 {
990 unsigned long ip_be;
991 int route_index;
992 if (pConfig->dst_ips[i][0])
993 {
994 parse_one_ip(&pConfig->dst_ips[i][0],(unsigned char *)&ip_be);
995 sscanf(&pConfig->paths[i][0],"route%d",&route_index);
996 route_add(our_router,&ip_be,(void*)&routes[route_index]);
997 n_dst_ips+=1;
998 }
999 }
1000 //netapi_Log(">Route DB built. %d entries\n",n_dst_ips);
1001 }
1003 void parse_config_file(FILE * fpr, netTestConfigFile_t *pConfig)
1004 {
1005 char line[MAX_LINE_LENGTH + 1];
1006 int i;
1007 static int sa_count = 0;
1009 char *key, *ep;
1010 char * d1, *d2, *d3, *d4;
1011 char * d5, *d6, *d7, *d8;
1012 char * d9, *d10, *d11, *d12;
1013 char * d13, *d14, *d15, *d16, *d17;
1014 char tokens[] = " :=;\n";
1015 char temp_str[50];
1016 memset(line, 0, MAX_LINE_LENGTH + 1);
1017 memset(pConfig, 0, sizeof(netTestConfigFile_t));
1018 while (fgets(line, MAX_LINE_LENGTH + 1, fpr))
1019 {
1020 if(line[0]=='#')
1021 continue; //skip comment
1022 key = (char *)strtok(line, tokens);
1024 d1 = (char *)strtok(NULL, tokens);
1025 if (!key)
1026 continue;
1027 if (!d1)
1028 continue;
1030 if(strlen(d1) == 0)
1031 {
1032 continue;
1033 }
1036 d2 = (char *)strtok(NULL, tokens);
1037 d3 = (char *)strtok(NULL, tokens);
1038 d4 = (char *)strtok(NULL, tokens);
1039 d5 = (char *)strtok(NULL, tokens);
1040 d6 = (char *)strtok(NULL, tokens);
1041 d7 = (char *)strtok(NULL, tokens);
1042 d8 = (char *)strtok(NULL, tokens);
1043 d9 = (char *)strtok(NULL, tokens);
1044 d10 = (char *)strtok(NULL, tokens);
1045 d11 = (char *)strtok(NULL, tokens);
1046 d12 = (char *)strtok(NULL, tokens);
1047 d13 = (char *)strtok(NULL, tokens);
1048 d14 = (char *)strtok(NULL, tokens);
1049 d15 = (char *)strtok(NULL, tokens);
1050 d16 = (char *)strtok(NULL, tokens);
1051 d17 = (char *)strtok(NULL, tokens);
1053 CHECK_SET_PARAM(INIT_CONFIG_IPSEC_MODE_RX,&(pConfig->ipsec_mode_rx[0]));
1054 CHECK_SET_PARAM(INIT_CONFIG_IPSEC_MODE_TX,&(pConfig->ipsec_mode_tx[0]));
1055 CHECK_SET_PARAM(INIT_CONFIG_IPSEC_IF_NO,&(pConfig->ipsec_if_no[0]));
1056 //CHECK_SET_PARAM(INIT_CONFIG_NUM_FP_CORES,&(pConfig->num_fp_cores[0]));
1057 //CHECK_SET_PARAM(INIT_CONFIG_NUM_FP_THREADS,&(pConfig->num_fp_threads[0]));
1059 sprintf(temp_str,"sa%d",sa_count);
1060 if(strcmp(key, temp_str) == 0)
1061 {
1062 netapi_Log("parse_config_file, temp_str %s, sa_count: %d\n", temp_str, sa_count);
1063 CHECK_SET_PARAM_SA(temp_str,
1064 (char*)&pConfig->sa_config[sa_count].dir,
1065 (char*)&pConfig->sa_config[sa_count].spi,
1066 (char*)&pConfig->sa_config[sa_count].proto,
1067 (char*)&pConfig->sa_config[sa_count].saMode,
1068 (char*)&pConfig->sa_config[sa_count].ipType,
1069 (char*)&pConfig->sa_config[sa_count].src,
1070 (char*)&pConfig->sa_config[sa_count].dst,
1071 (char*)&pConfig->sa_config[sa_count].replayWindow,
1072 (char*)&pConfig->sa_config[sa_count].authMode,
1073 (char*)&pConfig->sa_config[sa_count].cipherMode,
1074 (char*)&pConfig->sa_config[sa_count].esnLo,
1075 (char*)&pConfig->sa_config[sa_count].esnHi,
1076 (char*)&pConfig->sa_config[sa_count].encKeySize,
1077 (char*)&pConfig->sa_config[sa_count].macKeySize,
1078 (char*)&pConfig->sa_config[sa_count].encr_key,
1079 (char*)&pConfig->sa_config[sa_count].auth_key,
1080 (char*)&pConfig->sa_config[sa_count].tunnel_id);
1081 parse_sa(pConfig,sa_count);
1082 sa_count++;
1083 continue;
1084 }
1086 #ifdef EXPERIMENTAL
1087 for(i=0;i<MAX_ROUTES;i++)
1088 {
1089 sprintf(temp_str,"route%d",i);
1090 CHECK_SET_PARAM2(temp_str,&pConfig->routes[i][0],&pConfig->ports[i][0] );
1091 }
1093 for(i=0;i<MAX_ROUTES;i++)
1094 {
1095 sprintf(temp_str,"dstip%d",i);
1096 CHECK_SET_PARAM2(temp_str,&pConfig->dst_ips[i][0],&pConfig->paths[i][0] );
1097 }
1098 #endif
1099 for(i=0;i<NET_TEST_MAX_MAC;i++)
1100 {
1101 sprintf(temp_str,"mac%d",i);
1102 CHECK_SET_PARAM2(temp_str,&pConfig->mac[i][0],&pConfig->switch_port[i][0] );
1103 }
1104 for(i=0;i<NET_TEST_MAX_IP;i++)
1105 {
1106 sprintf(temp_str,"ip%d",i);
1107 CHECK_SET_PARAM2(temp_str,&pConfig->ip[i][0], &pConfig->attach_iface[i][0]);
1108 }
1109 for(i=0;i<2;i++)
1110 {
1111 sprintf(temp_str,"fp%d",i);
1112 CHECK_SET_PARAM2(temp_str, &pConfig->fp_thread_num[i][0],&pConfig->fp[i][0]);
1113 }
1114 for(i=0;i<2;i++)
1115 {
1116 sprintf(temp_str,"sp%d",i);
1117 CHECK_SET_PARAM2(temp_str, &pConfig->sp_thread_num[i][0],&pConfig->sp[i][0]);
1118 }
1119 }
1120 parse_mac_address(pConfig);
1122 parse_fp(pConfig);
1123 parse_sp(pConfig);
1125 parse_ip_address(pConfig);
1127 parse_ipsec_mode(pConfig);
1130 #ifdef EXPERIMENTAL
1131 parse_routes(pConfig);
1132 #endif
1134 parse_ipsec_if_no(pConfig);
1135 //parse_num_fp_cores(pConfig);
1136 //parse_num_fp_threads(pConfig);
1138 }
1140 //******************************************************
1141 //use scheduling housekeeping callback to generate pkts
1142 //******************************************************
1143 static int done_burst=0;
1144 void house(NETAPI_SCHED_HANDLE_T * s)
1145 {
1146 Ti_Pkt * tip;
1147 unsigned int len;
1148 nwalTxPktInfo_t meta_tx = {0};
1149 PKTIO_METADATA_T meta = {PKTIO_META_TX,{0},0};
1150 int err;
1151 static int house_pkts_gened=0;
1152 int p;
1153 unsigned char * pIpHdr,* pData;
1154 unsigned int vv1,vv2,vv3;
1155 unsigned int sum_vv1=0;
1156 unsigned int sum_vv2=0;
1157 unsigned int sum_vv3=0;
1158 unsigned int sum_vv4=0;
1159 unsigned int sum_vv5=0;
1161 unsigned int nwal_flow_vv1,nwal_flow_vv2;
1162 unsigned int nwal_sum_vv1=0;
1163 unsigned int nwal_sum_vv2=0;
1164 unsigned int nwal_sum_vv3=0;
1165 unsigned int nwal_sum_vv4=0;
1166 unsigned int nwal_sum_vv5=0;
1167 unsigned int nwal_sum_vv6=0;
1169 unsigned int nwal_sum_flow_vv1=0;
1170 unsigned int nwal_sum_flow_vv2=0;
1171 unsigned long long cache_op_b1;
1172 unsigned long long cache_op_b2;
1173 unsigned long long n_c_ops;
1174 static int first =0;
1175 Cppi_HostDesc* pPktDesc;
1176 NETAPI_SCHED_SHUTDOWN_T sched_shutdown;
1178 uint32_t coreid = 0; //who we are
1179 #ifdef MULTI_THREAD
1180 NETAPI_T nh= netapi_schedGetHandle(s);
1181 coreid=(uint32_t) netapi_getCookie(nh);
1183 if (QUIT)
1184 {
1185 sched_shutdown.shutdown_type = NETAPI_SCHED_SHUTDOWN_NOW;
1186 netapi_schedClose(s,&sched_shutdown,&err);
1187 return;
1188 }
1191 /* only slow path threads get netcp stats */
1192 if (coreid & NET_TEST_SP_THREAD_MASK)
1193 {
1194 netapi_netcpCfgReqStats(nh, our_stats_cb_mt, 0,&err);
1195 }
1197 coreid = NET_TEST_THREAD_NUM_MASK & coreid;
1198 #else
1199 coreid = NET_TEST_THREAD_NUM_MASK & coreid;
1200 if(done_burst)
1201 {
1202 house_pkts_gened+=TX_BURST;
1203 netapi_Log("net_test> request stats at n=%d \n",house_pkts_gened);
1204 netapi_netcpCfgReqStats(netapi_handle, our_stats_cb, 0,&err);
1205 if (err!=0) {netapi_Log("stats req failed\n");}
1206 if (house_pkts_gened >= np2process+ 100)
1207 {
1208 sched_shutdown.shutdown_type = NETAPI_SCHED_SHUTDOWN_NOW;
1209 netapi_schedClose(s,&sched_shutdown,&err);
1210 }
1211 return;
1212 }
1213 done_burst=1;
1214 Osal_cache_op_measure_reset();
1215 memset(&meta_tx,0,sizeof(meta_tx));
1216 for(p=0;p<TX_BURST;p++) {
1217 //reguest stats
1218 if ((house_pkts_gened>0) && (! (house_pkts_gened%1000)) )
1219 {
1220 netapi_Log("net_test> request stats at n=%d \n",house_pkts_gened);
1221 netapi_netcpCfgReqStats(netapi_handle, our_stats_cb, 0,&err);
1222 if (err!=0) {netapi_Log("stats req failed\n");}
1223 }
1226 if (house_pkts_gened >= np2process+ 100)
1227 {
1228 //shutdown
1229 sched_shutdown.shutdown_type = NETAPI_SCHED_SHUTDOWN_NOW;
1230 netapi_schedClose(s,&sched_shutdown,&err);
1231 continue;
1232 }
1234 else if (house_pkts_gened >= np2process) { house_pkts_gened+=1; continue;}
1236 /* manufacture a pkt to transmit */
1237 tip = get_pkt(house_pkts_gened, &len, ourHeap, PKT_LEN,&testPkt[0] , TEST_PKT_LEN);
1238 if(!tip) { house_pkts_gened +=1; continue; }
1241 /* set the pkt length */
1242 vv1 = hplib_mUtilGetPmuCCNT();
1243 Pktlib_setPacketLen(tip, len);
1245 /* set up meta data */
1246 meta.sa_handle=nwal_HANDLE_INVALID;
1247 /* #define BENCH_UDP_SEND */
1248 #ifdef BEND_UDP_SEND
1249 meta_tx.txFlag1 = (NWAL_TX_FLAG1_DO_IPV4_CHKSUM | NWAL_TX_FLAG1_DO_UDP_CHKSUM| NWAL_TX_FLAG1_META_DATA_VALID);
1250 meta_tx.startOffset = 0;
1251 /* GONE in V2 meta_tx.pktLen = len; */
1252 meta_tx.ipOffBytes = TEST_PKT_IP_OFFSET_BYTES;
1253 meta_tx.l4OffBytes = TEST_PKT_UDP_OFFSET_BYTES;
1254 meta_tx.l4HdrLen = TEST_PKT_UDP_HDR_LEN;
1255 //GONE in V2 meta_tx.ploadOffBytes = TEST_PKT_PLOAD_OFFSET_BYTES;
1256 meta_tx.ploadLen = TEST_PAYLOAD_LEN;
1258 Pktlib_getDataBuffer(tip,&pData,&len);
1259 if(house_pkts_gened &0x1)
1260 {
1261 memcpy(&pData[6],&netTestCfg.mac[1][0] ,6);
1262 }
1263 pIpHdr = pData + meta_tx.ipOffBytes;
1264 meta_tx.pseudoHdrChecksum =
1265 test_utilGetIpv4PsudoChkSum(pIpHdr,(TEST_PAYLOAD_LEN+TEST_PKT_UDP_HDR_LEN));
1266 #else
1267 Pktlib_getDataBuffer(tip,&pData,&len);
1268 if(house_pkts_gened &0x1)
1269 {
1270 memcpy(&pData[6],&netTestCfg.mac[1][0] ,6);
1271 }
1272 meta_tx.txFlag1 = NWAL_TX_FLAG1_META_DATA_VALID;
1273 meta_tx.startOffset = 0;
1274 meta_tx.ploadLen = TEST_PAYLOAD_LEN;
1275 #endif
1276 /* post it to netcp tx channel*/
1277 meta.u.tx_meta=&meta_tx;
1278 #ifdef DEBUG_DESC
1279 if (house_pkts_gened<16) dump_descr((long *) tip, house_pkts_gened);
1280 else if (house_pkts_gened>99) dump_descr((long *) tip,house_pkts_gened);
1281 #endif
1283 if(!first)
1284 {
1285 first++;
1286 nwal_flow_vv1= hplib_mUtilGetPmuCCNT();
1287 if(nwal_initPSCmdInfo(pktio_mGetNwalInstance(netcp_tx_chan),
1288 &meta_tx,
1289 &flowPSCmdInfo) != nwal_OK)
1290 {
1291 netapi_Log("nwal_initPSCmdInfo() ERROR \n");
1292 }
1293 nwal_flow_vv2= hplib_mUtilGetPmuCCNT();
1294 nwal_sum_flow_vv1 += (nwal_flow_vv1-vv1);
1295 nwal_sum_flow_vv2 += (nwal_flow_vv2-nwal_flow_vv1);
1296 }
1297 cache_op_b1= Osal_cache_op_measure(&n_c_ops);
1298 vv2= hplib_mUtilGetPmuCCNT();
1299 #ifdef BEND_UDP_SEND
1300 nwal_mCmdSetL4CkSumPort( tip,
1301 &flowPSCmdInfo,
1302 TEST_PKT_UDP_OFFSET_BYTES,
1303 (TEST_PKT_UDP_HDR_LEN + TEST_PAYLOAD_LEN),
1304 meta_tx.pseudoHdrChecksum,
1305 meta_tx.enetPort);
1306 #else
1307 nwal_mCmdSetPort (tip,
1308 &flowPSCmdInfo, //could be NULL
1309 0); //port 0 -> switch decides
1311 #endif
1313 pPktDesc = Pktlib_getDescFromPacket(tip);
1314 /* Send the packet out to transmit Q*/
1315 Qmss_queuePushDescSize (flowPSCmdInfo.txQueue,
1316 pPktDesc,
1317 NWAL_DESC_SIZE);
1318 vv3= hplib_mUtilGetPmuCCNT();
1319 cache_op_b2= Osal_cache_op_measure(&n_c_ops);
1321 sum_vv1 += (vv2-vv1);
1322 if(!house_pkts_gened)
1323 {
1324 /* first packet. Take out the PS command label creation cost */
1325 sum_vv1 = sum_vv1 - nwal_sum_flow_vv2;
1326 }
1328 sum_vv3 += (vv3-vv2)-(long) (cache_op_b2-cache_op_b1); //sub out cache op cost
1330 // netapi_Log("pktio send. full=%d metadata=%d pktio_send=%d\n", vv3-vv1, vv2-vv1, vv3-vv2);
1331 stats[coreid].itx +=1;
1332 house_pkts_gened +=1;
1333 }
1334 {
1335 unsigned long long ccycles;
1336 ccycles =Osal_cache_op_measure(&n_c_ops);
1337 if (sum_vv1)
1338 {
1339 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",
1340 stats[coreid].itx, sum_vv1/stats[coreid].itx, nwal_sum_flow_vv2, sum_vv3/stats[coreid].itx,
1341 n_c_ops, ccycles, n_c_ops? (ccycles/(n_c_ops/2L)) : 0);
1342 #if 0
1343 netapi_Log("NWAL Profile Cycles: Prof1= %d,Prof2=%d,Prof3=%d,Prof4=%d,Prof5=%d ,Prof6=%d \n",
1344 nwal_sum_vv1/stats[coreid].itx,nwal_sum_vv2/stats[coreid].itx,nwal_sum_vv3/stats[coreid].itx,
1345 nwal_sum_vv4/stats[coreid].itx,nwal_sum_vv5/stats[coreid].itx,nwal_sum_vv6/stats[coreid].itx);
1347 #endif
1349 if(stats[core_id].itx2)
1350 {
1351 netapi_Log("nwal_flowSend Profile Cycles: Prof1= %d,Prof2=%d \n",
1352 nwal_sum_flow_vv1/stats[coreid].itx2,nwal_sum_flow_vv2/stats[coreid].itx2);
1353 }
1354 }
1355 }
1356 #endif
1357 }
1359 void create_interfaces(void)
1360 {
1361 int err, i;
1363 for (i = 0; i < netTestCfg.num_macs; i++)
1364 {
1365 /* add mac intefaces */
1366 mac[i] = netapi_netcpCfgCreateMacInterface(
1367 netapi_handle,
1368 &netTestCfg.mac[i][0],
1369 i,
1370 netTestCfg.switch_port[i],
1371 (NETCP_CFG_ROUTE_HANDLE_T) NULL,
1372 (NETCP_CFG_VLAN_T ) NULL , //future
1373 1,
1374 &err);
1375 if (err)
1376 {
1377 netapi_Log("addmac %d failed %d\n",i, err);
1378 //exit(1);
1379 }
1380 else
1381 netapi_Log("create_interfaces, added mac sucess\n");
1382 }
1383 for (i = 0; i < netTestCfg.num_ips; i++)
1384 {
1385 //attach an IP to this interface
1386 ip_rule[i]=netapi_netcpCfgAddIp(
1387 netapi_handle,
1388 netTestCfg.attach_iface[i],
1389 nwal_IPV4,
1390 (nwalIpAddr_t *)&netTestCfg.ip[i].ipv4[0],
1391 NULL, //all IP
1392 (NETCP_CFG_ROUTE_HANDLE_T) NULL,
1393 (void*)NULL,
1394 &err
1395 );
1396 if (err) {
1397 netapi_Log("addip %d failed %d\n", i, err);
1398 //exit(1);
1399 }
1400 else
1401 netapi_Log("create_interfaces, added ip sucess\n");
1402 }
1403 }
1405 void delete_interfaces(void)
1406 {
1408 int err,i;
1409 //delete IPs and MAC Interfacess
1410 for (i = 0; i < netTestCfg.num_ips; i++)
1411 {
1412 err = 0;
1413 netapi_netcpCfgDelIp(netapi_handle, netTestCfg.attach_iface[i], nwal_IPV4,
1414 NULL, NULL, ip_rule[i], &err);
1415 }
1416 for (i = 0; i < netTestCfg.num_macs; i++)
1417 {
1418 err = 0;
1419 netapi_netcpCfgDelMac(netapi_handle,i,&err);
1420 }
1422 //netapi_netcpCfgDelMac(netapi_handle,0,&err);
1423 //netapi_netcpCfgDelMac(netapi_handle,1,&err);
1425 }