1 /******************************************
2 * File: net_test.c
3 * Purpose: test app for netapi
4 **************************************************************
5 * FILE: net_test.c
6 *
7 * DESCRIPTION: netapi user space transport
8 * library test application
9 *
10 * REVISION HISTORY: rev 0.0.1
11 *
12 * Copyright (c) Texas Instruments Incorporated 2010-2011
13 *
14 * Redistribution and use in source and binary forms, with or without
15 * modification, are permitted provided that the following conditions
16 * are met:
17 *
18 * Redistributions of source code must retain the above copyright
19 * notice, this list of conditions and the following disclaimer.
20 *
21 * Redistributions in binary form must reproduce the above copyright
22 * notice, this list of conditions and the following disclaimer in the
23 * documentation and/or other materials provided with the
24 * distribution.
25 *
26 * Neither the name of Texas Instruments Incorporated nor the names of
27 * its contributors may be used to endorse or promote products derived
28 * from this software without specific prior written permission.
29 *
30 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
31 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
32 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
33 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
34 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
35 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
36 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
37 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
38 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
39 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
40 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
42 *****************************************/
43 #define DAL_REVIEW
44 #define NET_TEST_ENABLE_SIDE_BAND_LOW_LEVEL_API
45 #ifdef NET_TEST_ENABLE_SIDE_BAND_LOW_LEVEL_API
46 #define NWAL_ENABLE_SA
47 #endif
48 #define AH_SUPPORT
50 //define this for multi-thread
51 #define MULTI_THREAD
52 #include <stdio.h>
53 #include <stdlib.h>
54 #include <unistd.h>
55 #include <string.h>
56 #include <signal.h>
57 #include <pthread.h>
59 #include "trie.h"
60 #include "string.h"
61 #include "netapi.h"
62 #include "pktio.h"
63 #include <sys/resource.h>
64 #include "net_test.h"
65 #include <ti/drv/sa/salld.h>
66 //#define EXPERIMENTAL
67 #ifdef EXPERIMENTAL
68 #include "router.c"
69 Trie * our_router;
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 unsigned int ip[MAX_ROUTES]={BE(0x0a0100c8),BE(0x0a00000a),BE(0x0a02000a),BE(0xc0a8010a),BE(0x9eda6719)};
84 #endif
86 #ifdef MULTI_THREAD
87 //__thread int our_core;
89 cpu_set_t cpu_set;
90 #endif
93 hplib_spinLock_T stats_lock;
95 //#define TEST_TIMERS
96 static int scnt=0;
97 static int QUIT=0;
98 void mysig(int x)
99 {
100 QUIT=1;
101 scnt+=1;
102 printf(">net_test: recv'd signal %d cnt=%d\n",x,scnt);
103 if (scnt > 10) {printf(">net_test: WARNING EXITING WITH PROPER SHUTDOWN, LUTS LEFT ACTIVE\n");exit(1);}
105 }
107 static unsigned char all_mac[]={0,0,0,0,0,0};
109 /*************debug********************/
110 void dump_descr(unsigned long *p, int n)
111 {
112 printf("--------dump of descriptor %d %x\n", n, (int) p);
113 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]);
114 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]);
115 printf("-----------------------------\n");
116 }
117 void dump_header(unsigned long *p, int n, int a, int r)
118 {
119 printf("--------dump of header %d %x appID=%x flag1=%x\n", n, (int) p,a,r);
120 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]);
121 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]);
122 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]);
123 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]);
124 printf("-----------------------------\n");
125 }
127 static void netapi_dump_buf
128 (
129 unsigned long * buf,
130 uint32_t buf_length
131 )
132 {
133 uint8_t count = 0;
134 uint16_t dump_size;
135 uint8_t* tmp_buf;
136 uint8_t row_count;
137 static uint8_t first = 0;
139 //if(first > 2) return;
141 //first++;
143 dump_size = buf_length ;
145 tmp_buf = (uint8_t *)(buf);
147 printf("netapi *: - 8 bit word hex Length: %d Start \n",buf_length);
148 do
149 {
150 row_count = (dump_size - count);
152 if(row_count == 0)
153 {
154 break;
155 }
157 if(row_count > 4)
158 {
159 row_count = 4;
160 }
162 switch (row_count)
163 {
164 case 4:
165 {
166 printf("netapi *:%02d : %02x %02x %02x %02x \n",
167 count,tmp_buf[0],tmp_buf[1],tmp_buf[2],tmp_buf[3]);
168 break;
169 }
170 case 3:
171 {
172 printf("netapi *: %02d : %02x %02x %02x \n",
173 count,tmp_buf[0],tmp_buf[1],tmp_buf[2]);
174 break;
175 }
177 case 2:
178 {
179 printf("netapi *: %02d : %02x %02x \n",
180 count,tmp_buf[0],tmp_buf[1]);
181 break;
182 }
184 case 1:
185 {
186 printf("netapi *: %02d : %02x \n",
187 count,tmp_buf[0]);
188 break;
189 }
191 default:
192 {
193 /* Should never reach here */
194 printf("netapi *: Internal Error in netapi_dump_buf().Row Count: %d \n",
195 row_count);
196 return;
197 }
198 }
200 tmp_buf = tmp_buf + row_count;
201 count = count + row_count;
203 }while(count < dump_size);
205 printf("netapi *: - Byte hex Dump End \n");
207 }
210 /*****************************************/
213 //************for multi pkt burst xfer test in loopback mode
214 #define TX_BURST 700
215 int pktloopback=TUNE_NETAPI_NWAL_ENABLE_PASS_LOOPBACK;
216 nwalTxPSCmdInfo_t flowPSCmdInfo;
217 nwal_RetValue nwalRetVal;
219 /* Local Per Process default resourcese maintained at NWAL */
220 nwalLocCxtInfo_t nwalLocCxt;
222 //this device: 10.0.0.100, mac 0x,01,02,03,04,05 and .. 0x6
224 //test packet, setup for loopback (so dest is ourself)
225 static uint8_t testPkt[] = {
227 /* MAC header */
228 0x00, 0x01, 0x02, 0x03, 0x04, 0x05,
229 0x00, 0xe0, 0xa6, 0x66, 0x57, 0x04,
230 0x08, 0x00,
232 /* IP header */
233 0x45, 0x00,
234 0x00, 0x6c, /* Length (including this header) */
235 0x00, 0x00, 0x00, 0x00, 0x05, 0x11,
236 0x00, 0x00, /* Header checksum */
237 0x0a, 0x00, 0x00, 0x0a, 0x0a, 0x00, 0x00, 0x64,
239 /* UDP header */
240 0x12, 0x34, 0x05, 0x55,
241 0x00, 0x58, /* Length, including this header */
242 0x00, 0x00, /* Header checksum */
244 /* Payload */
245 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39,
246 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f, 0x40, 0x41,
247 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49,
248 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f, 0x50, 0x51,
249 0x52, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, 0x59,
250 0x5a, 0x5b, 0x5c, 0x5d, 0x5e, 0x5f, 0x60, 0x61,
251 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69,
252 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, 0x6f, 0x70, 0x71,
253 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79,
254 0x7a, 0x7b, 0x7c, 0x7d, 0x7e, 0x7f, 0x80, 0x81
256 };
258 char input_file_name[] = "net_test_config.txt";
259 #define MAX_LINE_LENGTH 40
261 #define TEST_PAYLOAD_LEN 80
263 #define TEST_PKT_IP_OFFSET_BYTES 14
264 #define TEST_PKT_UDP_OFFSET_BYTES 34
265 #define TEST_PKT_PLOAD_OFFSET_BYTES 42
266 #define TEST_PKT_UDP_HDR_LEN 8
267 /* Offsets to length fields */
268 #define TEST_PKT_OFFSET_IP_LEN 16
269 #define TEST_PKT_OFFSET_UDP_LEN 38
271 #define TEST_PKT_LEN 122
273 /* The pseudo header checksum of the packet except for the 16 bit length */
274 #define TEST_PKT_PSEUDO_HDR_CHKSUM_SANS_LEN 0x0FFC
276 void example_fast_poll( PKTIO_HANDLE_T * p_pktio, int max_pkts);
277 void example_fast_pushpop(Pktlib_HeapHandle p_heap, int ntrials);
279 void recv_cb_router(struct PKTIO_HANDLE_Tag * channel, Ti_Pkt* p_recv[],
280 PKTIO_METADATA_T meta[], int n_pkts,
281 uint64_t ts );
284 //#include "arpa/inet.h"
285 long htonl(long x)
286 {
287 long temp = (x&0xff000000)>>24 | (x&0xff0000)>>8 | (x&0xff00)<<8 | (x&0xff)<<24 ;
288 return temp;
289 }
292 unsigned long peek(unsigned long * p)
293 {
294 return *p;
295 }
298 /********************************************************************
299 * FUNCTION PURPOSE: Ones complement addition utility
300 ********************************************************************
301 ********************************************************************/
302 uint16_t test_utilOnesComplementAdd (uint16_t v1, uint16_t v2)
303 {
304 uint32_t result;
306 result = (uint32_t)v1 + (uint32_t)v2;
307 result = (result >> 16) + (result & 0xffff);
308 result = (result >> 16) + (result & 0xffff);
310 return ((uint16_t)result);
311 }
313 /********************************************************************
314 * FUNCTION PURPOSE: Ones complement checksum utility
315 ********************************************************************
316 ********************************************************************/
317 uint16_t test_utilOnesCompChkSum (uint8_t *p, uint32_t nwords)
318 {
319 uint16_t chksum = 0;
320 uint16_t v;
321 uint32_t i;
322 uint32_t j;
324 for (i = j = 0; i < nwords; i++, j+=2) {
325 v = (p[j] << 8) | p[j+1];
326 chksum = test_utilOnesComplementAdd (chksum, v);
327 }
328 return (chksum);
329 } /* utilOnesCompChkSum */
331 /**************************************************************************************
332 * FUNCTION PURPOSE: Compute ipv4 psudo checksum
333 **************************************************************************************
334 * DESCRIPTION: Compute ipv4 psudo checksum
335 **************************************************************************************/
336 uint16_t test_utilGetIpv4PsudoChkSum (uint8_t *data, uint16_t payloadLen)
337 {
338 uint16_t psudo_chksum;
340 psudo_chksum = test_utilOnesCompChkSum (&data[12], 4);
341 psudo_chksum = test_utilOnesComplementAdd(psudo_chksum, (uint16_t) data[9]);
342 psudo_chksum = test_utilOnesComplementAdd(psudo_chksum, payloadLen);
344 return (psudo_chksum);
346 } /* utilGetIpv4PsudoChkSum */
350 /* net test default configuration */
351 netTestConfig_t config =
352 {
353 {0x00,0x01,0x02,0x03,0x05,0x05},
354 {0x00,0x01,0x02,0x03,0x05,0x06},
355 {10, 0, 0, 100, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
356 {10, 0, 1, 100, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
357 {10, 0, 2, 100, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
358 {192,168 , 1, 100, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
359 {192,168 , 1, 10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
360 IPSEC_MODE_RX_SIDEBAND,
361 IPSEC_MODE_TX_SIDEBAND,
362 0
363 };
365 #if 1 //goes with real tx (to laptop)
366 unsigned char real_mac_header[]={0xd4,0xbe,0xd9,0x00,0xd3,0x7e,
367 0x00,0x01,0x02,0x03,0x04,0x05,
368 0x08,0x00};
369 unsigned char real_ip_addr[]={0xa,0x00,0x00,0x64,0xa,0x0,0x0,0xa};
370 #endif
372 #if 0 //goes with loopback
373 unsigned char mac_header[]={0x00,0x01,0x02,0x03,0x04,0x05,
374 0x00,0x11,0x22,0x33,0x44,0x55,
375 0x08,0x00};
376 #endif
377 #define NE 65536
378 HEAD_T *nat;
380 #define NP 5000
381 int n_pkt = NP;
382 STATS_T stats[TUNE_NETAPI_NUM_CORES];
383 paSysStats_t netcp_stats;
385 Trie * P_trie;
386 Trie *p_trie_sa;
387 HEAD_T pkts[NP];
388 #define PERSLOW 10 //% of pkts that will not be fastpath'd
389 int perslow= PERSLOW;
391 /*******************************************
392 *************NETAPI OBJECTS***************
393 *****************************************/
394 static NETAPI_CFG_T our_netapi_default_cfg=
395 {
396 TUNE_NETAPI_PERM_MEM_SZ,
397 128, //start of packet offset for hw to place data on rx for default flow
398 TUNE_NETAPI_QM_CONFIG_MAX_DESC_NUM, //max number of descriptors in system
399 TUNE_NETAPI_NUM_GLOBAL_DESC, //total we will use
400 TUNE_NETAPI_DEFAULT_NUM_BUFFERS, //#descriptors+buffers in default heap
401 64, //#descriptors w/o buffers in default heap
402 TUNE_NETAPI_DEFAULT_BUFFER_SIZE+128+128, //size of buffers in default heap
403 128 , //tail room
404 256 //extra room
405 };
407 Pktlib_HeapHandle ourHeap;
408 Pktlib_HeapHandle specialSmall;
409 Pktlib_HeapHandle specialLarge;
411 PKTIO_HANDLE_T *our_chan;
412 PKTIO_HANDLE_T *netcp_rx_chan;
413 PKTIO_HANDLE_T *netcp_rx_chan2;
414 PKTIO_HANDLE_T *netcp_tx_chan;
415 PKTIO_HANDLE_T *netcp_sb_tx_chan;
416 PKTIO_HANDLE_T *netcp_sb_rx_chan;
417 PKTIO_CFG_T our_chan_cfg={PKTIO_RW, PKTIO_LOCAL, PKTIO_Q_ANY, 8};
418 PKTIO_CFG_T netcp_rx_cfg={PKTIO_R, PKTIO_NA, PKTIO_NA, 8};
419 PKTIO_CFG_T netcp_rx_cfg2={PKTIO_R, (PKTIO_GLOBAL|PKTIO_PKT), PKTIO_Q_ANY, 8};
420 PKTIO_CFG_T netcp_tx_cfg={PKTIO_W, PKTIO_NA, PKTIO_NA, 8};
421 PKTIO_CFG_T netcp_sb_rx_cfg={PKTIO_R, PKTIO_NA, PKTIO_NA, 8};
422 PKTIO_CFG_T netcp_sb_tx_cfg={PKTIO_W, PKTIO_NA, PKTIO_NA, 8};
424 void house(NETAPI_SCHED_HANDLE_T *s);
425 NETAPI_T netapi_handle;
426 NETAPI_SCHED_HANDLE_T * our_sched;
427 #ifdef MULTI_THREAD
428 NETAPI_SCHED_HANDLE_T * scheduler[TUNE_NETAPI_NUM_CORES];
429 #endif
430 NETAPI_SCHED_CONFIG_T our_sched_cfg={
431 NETAPI_SCHED_DURATION|NETAPI_SCHED_CBV, 0, house, 5000000 //every 5000000 poll loops
432 };
433 void our_stats_cb(NETAPI_T h, paSysStats_t* pPaStats);
434 void our_stats_cb_mt(NETAPI_T h, paSysStats_t* pPaStats);
437 #ifdef TEST_TIMERS
438 HPLIB_TIMER_GROUP_HANDLE_T ourTimerBlock;
439 HPLIB_TIMER_T t1;
440 HPLIB_TIMER_T t2;
441 HPLIB_TIMER_T t3;
443 void our_timer_cb( HPLIB_TIMER_GROUP_HANDLE_T th,
444 int n_fired, //# timers fired
445 HPLIB_TIMER_LIST_T fired_list,
446 uint64_t currentTime);
447 #endif
448 NETCP_CFG_IP_T ip_rule0;
449 NETCP_CFG_IP_T ip_rule1;
450 NETCP_CFG_CLASS_T class_0;
451 NETCP_CFG_CLASS_T class_1;
452 NETCP_CFG_CLASS_T class_2;
453 NETCP_CFG_FLOW_HANDLE_T specialFlow;
456 NETCP_CFG_CLASSIFIER_T class_0_cfg=
457 {
458 NETCP_CFG_CLASS_TYPE_L4,
459 {
460 .c_l4={0,0, NWAL_APP_PLOAD_PROTO_UDP, {2500}}
461 }
462 };
464 NETCP_CFG_CLASSIFIER_T class_1_cfg=
465 {
466 NETCP_CFG_CLASS_TYPE_L4,
467 {
468 .c_l4= {0,0, NWAL_APP_PLOAD_PROTO_UDP, {2502}}
469 }
470 };
472 NETCP_CFG_ROUTE_T class2_route=
473 {
474 NULL, NULL //* to be filled in
475 };
476 NETCP_CFG_CLASSIFIER_T class_2_cfg=
477 {
478 NETCP_CFG_CLASS_TYPE_L3_L4,
479 {
480 .c_l3_l4={0, 4 ,0/*fill in below*/ , NULL, NULL, //L2/L3
481 NWAL_APP_PLOAD_PROTO_UDP, {2504}} //L4
482 }
483 };
485 PKTIO_CONTROL_T zap_channel_control={PKTIO_CLEAR, NULL};
487 /* security objects. (for loopback mode) */
488 netTestSA_t sa_info[6];
489 int netapi_algorithm_set = 0;
490 int netapi_sec_sa_mode = 2;
492 NETCP_CFG_IPSEC_POLICY_T rx_policy[7];
496 NETAPI_SEC_SA_INFO_T rx_sa [7] = {
497 {
498 NWAL_SA_DIR_INBOUND,
499 0x11111111, //spi
500 nwal_IpSecProtoAH, //ESP mode
501 nwal_SA_MODE_TUNNEL, //tunnel mode
502 nwal_IPV4, //v4
503 { 1, 2, 3, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, /* Src IP (them) -> set below */
504 { 1, 2, 3, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, /* dst IP (us)-> set below*/
505 64,/* replayWindow */
506 NWAL_SA_AALG_HMAC_SHA1,
507 NWAL_SA_EALG_AES_CBC,
508 0,0 //na
509 },
510 {
511 NWAL_SA_DIR_INBOUND,
512 0x22222222, //spi
513 nwal_IpSecProtoESP, //ESP mode
514 nwal_SA_MODE_TUNNEL, //tunnel mode
515 nwal_IPV4, //v4
516 { 1, 2, 3, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, /* Src IP (them) -> set below */
517 { 1, 2, 3, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, /* dst IP (us)-> set below*/
518 64,/* replayWindow */
519 NWAL_SA_AALG_HMAC_SHA2_256,
520 NWAL_SA_EALG_AES_CTR,
521 0,0 //na
522 },
523 {
524 NWAL_SA_DIR_INBOUND,
525 0x33333333, //spi
526 nwal_IpSecProtoESP, //ESP mode
527 nwal_SA_MODE_TUNNEL, //tunnel mode
528 nwal_IPV4, //v4
529 { 1, 2, 3, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, /* Src IP (them) -> set below */
530 { 1, 2, 3, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, /* dst IP (us)-> set below*/
531 64,/* replayWindow */
532 NWAL_SA_AALG_HMAC_SHA2_256,
533 NWAL_SA_EALG_3DES_CBC,
534 0,0 //na
535 },
536 {
537 NWAL_SA_DIR_INBOUND,
538 0x44444444, //spi
539 nwal_IpSecProtoAH, //ESP mode
540 nwal_SA_MODE_TUNNEL, //tunnel mode
541 nwal_IPV4, //v4
542 { 1, 2, 3, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, /* Src IP (them) -> set below */
543 { 1, 2, 3, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, /* dst IP (us)-> set below*/
544 64,/* replayWindow */
545 NWAL_SA_AALG_HMAC_MD5,
546 NWAL_SA_EALG_NULL,
547 0,0 //na
548 },
549 {
550 NWAL_SA_DIR_INBOUND,
551 0x55555555, //spi
552 nwal_IpSecProtoESP, //ESP mode
553 nwal_SA_MODE_TUNNEL, //tunnel mode
554 nwal_IPV4, //v4
555 { 1, 2, 3, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, /* Src IP (them) -> set below */
556 { 1, 2, 3, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, /* dst IP (us)-> set below*/
557 64,/* replayWindow */
558 NWAL_SA_AALG_NULL,
559 NWAL_SA_EALG_AES_GCM,
560 0,0 //na
561 },
562 {
563 NWAL_SA_DIR_INBOUND,
564 0x66666666, //spi
565 nwal_IpSecProtoESP, //ESP mode
566 nwal_SA_MODE_TUNNEL, //tunnel mode
567 nwal_IPV4, //v4
568 { 1, 2, 3, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, /* Src IP (them) -> set below */
569 { 1, 2, 3, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, /* dst IP (us)-> set below*/
570 64,/* replayWindow */
571 NWAL_SA_AALG_NULL,
572 NWAL_SA_EALG_AES_CCM,
573 0,0 //na
574 },
575 {
576 NWAL_SA_DIR_INBOUND,
577 0x77777777, //spi
578 nwal_IpSecProtoESP, //ESP mode
579 nwal_SA_MODE_TUNNEL, //tunnel mode
580 nwal_IPV4, //v4
581 { 1, 2, 3, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, /* Src IP (them) -> set below */
582 { 1, 2, 3, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, /* dst IP (us)-> set below*/
583 64,/* replayWindow */
584 NWAL_SA_AALG_AES_XCBC,
585 NWAL_SA_EALG_NULL,
586 0,0 //na
587 }
588 };
590 /*tx */
591 NETAPI_SEC_SA_INFO_T tx_sa[7]= {
592 {
593 NWAL_SA_DIR_OUTBOUND,
594 0x11111111, //spi
595 nwal_IpSecProtoAH, //ESP mode
596 nwal_SA_MODE_TUNNEL, //tunnel mode
597 nwal_IPV4, //v4
598 { 1, 2, 3, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, /* Src IP (us) -> set below */
599 { 1, 2, 3, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, /* dst IP (them) -> set below*/
600 64, /* NA replayWindow */
601 NWAL_SA_AALG_HMAC_SHA1,
602 NWAL_SA_EALG_AES_CBC,
603 0,0 //seq no
604 },
605 {
606 NWAL_SA_DIR_OUTBOUND,
607 0x22222222, //spi
608 nwal_IpSecProtoESP, //ESP mode
609 nwal_SA_MODE_TUNNEL, //tunnel mode
610 nwal_IPV4, //v4
611 { 1, 2, 3, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, /* Src IP (us) -> set below */
612 { 1, 2, 3, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, /* dst IP (them) -> set below*/
613 64, /* NA replayWindow */
614 NWAL_SA_AALG_HMAC_SHA2_256,
615 NWAL_SA_EALG_AES_CTR,
616 0,0 //seq no
617 },
618 {
619 NWAL_SA_DIR_OUTBOUND,
620 0x33333333, //spi
621 nwal_IpSecProtoESP, //ESP mode
622 nwal_SA_MODE_TUNNEL, //tunnel mode
623 nwal_IPV4, //v4
624 { 1, 2, 3, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, /* Src IP (us) -> set below */
625 { 1, 2, 3, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, /* dst IP (them) -> set below*/
626 64, /* NA replayWindow */
627 NWAL_SA_AALG_HMAC_SHA2_256,
628 NWAL_SA_EALG_3DES_CBC,
629 0,0 //seq no
630 },
631 {
632 NWAL_SA_DIR_OUTBOUND,
633 0x44444444, //spi
634 nwal_IpSecProtoAH, //ESP mode
635 nwal_SA_MODE_TUNNEL, //tunnel mode
636 nwal_IPV4, //v4
637 { 1, 2, 3, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, /* Src IP (us) -> set below */
638 { 1, 2, 3, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, /* dst IP (them) -> set below*/
639 64, /* NA replayWindow */
640 NWAL_SA_AALG_HMAC_MD5,
641 NWAL_SA_EALG_NULL,
642 },
643 {
644 NWAL_SA_DIR_OUTBOUND,
645 0x55555555, //spi
646 nwal_IpSecProtoESP, //ESP mode
647 nwal_SA_MODE_TUNNEL, //tunnel mode
648 nwal_IPV4, //v4
649 { 1, 2, 3, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, /* Src IP (them) -> set below */
650 { 1, 2, 3, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, /* dst IP (us)-> set below*/
651 64,/* replayWindow */
652 NWAL_SA_AALG_NULL,
653 NWAL_SA_EALG_AES_GCM,
654 0,0 //na
655 },
656 {
657 NWAL_SA_DIR_OUTBOUND,
658 0x66666666, //spi
659 nwal_IpSecProtoESP, //ESP mode
660 nwal_SA_MODE_TUNNEL, //tunnel mode
661 nwal_IPV4, //v4
662 { 1, 2, 3, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, /* Src IP (them) -> set below */
663 { 1, 2, 3, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, /* dst IP (us)-> set below*/
664 64,/* replayWindow */
665 NWAL_SA_AALG_NULL,
666 NWAL_SA_EALG_AES_CCM,
667 0,0 //na
668 },
669 {
670 NWAL_SA_DIR_OUTBOUND,
671 0x77777777, //spi
672 nwal_IpSecProtoESP, //ESP mode
673 nwal_SA_MODE_TUNNEL, //tunnel mode
674 nwal_IPV4, //v4
675 { 1, 2, 3, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, /* Src IP (them) -> set below */
676 { 1, 2, 3, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, /* dst IP (us)-> set below*/
677 64,/* replayWindow */
678 NWAL_SA_AALG_AES_XCBC,
679 NWAL_SA_EALG_NULL,
680 0,0 //na
681 }
682 };
685 static nwalSecKeyParams_t ourTXKeyParams[7] ={
686 {
687 32, /* encKeySize: CTR 16 bytes Encryption Key and 4 bytes Salt : 24 bytes:NWAL_SA_EALG_3DES_CBC and 0 bytes Salt*/
688 20, /* macKeySize: 16 bytes NWAL_SA_AALG_HMAC_SHA1 */
689 NULL, //set below
690 NULL, //set below
691 },
692 {
693 20, /* encKeySize: CTR 16 bytes Encryption Key and 4 bytes Salt : 24 bytes:NWAL_SA_EALG_AES_CTR and 0 bytes Salt*/
694 32, /* macKeySize: 16 bytes NWAL_SA_AALG_HMAC_SHA2_256 */
695 NULL, //set below
696 NULL, //set below
697 },
698 {
699 24, /* encKeySize: DES-CBC: 24 bytes:NWAL_SA_EALG_3DES_CBC and 0 bytes Salt*/
700 32, /* macKeySize: 16 bytes NWAL_SA_AALG_HMAC_SHA2_256 */
701 NULL, //set below
702 NULL, //set below
703 },
704 {
705 0, /* NULL*/
706 16, /* MD5, 16 bytes */
707 NULL, //set below
708 NULL, //set below
709 },
710 {
711 20, /* encKeySize: GCM 16 bytes Encryption Key and 4 bytes Salt */
712 0, /* macKeySize: 0*/
713 NULL, //set below
714 NULL, //set below
715 },
716 {
717 19, /* encKeySize: CTR 16 bytes Encryption Key and 3 bytes Salt : 24 bytes:NWAL_SA_EALG_AES_CTR and 0 bytes Salt*/
718 0, /* macKeySize 0*/
719 NULL, //set below
720 NULL, //set below
721 },
722 {
723 0, /* encKeySize: CTR 16 bytes Encryption Key and 3 bytes Salt : 24 bytes:NWAL_SA_EALG_AES_CTR and 0 bytes Salt*/
724 16, /* macKeySize 0*/
725 NULL, //set below
726 NULL, //set below
727 }
728 };
730 /* these keys are for aes-ctr and hmac sha2_256 */
731 static nwalSecKeyParams_t ourRXKeyParams[7] ={
732 {
733 32, /* encKeySize: CTR 16 bytes Encryption Key and 4 bytes Salt : 24 bytes:NWAL_SA_EALG_3DES_CBC and 0 bytes Salt*/
734 20, /* macKeySize: 16 bytes NWAL_SA_AALG_HMAC_SHA1 */
735 NULL, //set below
736 NULL, //set below
737 },
738 {
739 20, /* encKeySize: CTR 16 bytes Encryption Key and 4 bytes Salt */
740 32, /* macKeySize: 16 bytes NWAL_SA_AALG_HMAC_SHA2_256 */
741 NULL, //set below
742 NULL, //set below
743 },
744 {
745 24, /* encKeySize: DES-CBC: 24 bytes:NWAL_SA_EALG_3DES_CBC and 0 bytes Salt*/
746 32, /* macKeySize: 16 bytes NWAL_SA_AALG_HMAC_SHA2_256 */
747 NULL, //set below
748 NULL, //set below
749 },
750 {
751 0, /* NWAL_SA_EALG_NULL*/
752 16, /* NWAL_SA_AALG_HMAC_MD5, 16 bytes */
753 NULL, //set below
754 NULL, //set below
755 },
756 {
757 20, /* encKeySize: GCM 16 bytes Encryption Key and 4 bytes Salt */
758 0, /* macKeySize: 0*/
759 NULL, //set below
760 NULL, //set below
761 },
762 {
763 19, /* encKeySize: CTR 16 bytes Encryption Key and 3 bytes Salt t*/
764 0, /* macKeySize 0*/
765 NULL, //set below
766 NULL, //set below
767 },
768 {
769 0, /* encKeySize: CTR 16 bytes Encryption Key and 3 bytes Salt : 24 bytes:NWAL_SA_EALG_AES_CTR and 0 bytes Salt*/
770 16, /* macKeySize 0*/
771 NULL, //set below
772 NULL, //set below
773 }
774 };
777 static uint8_t ourAuthKey[36] =
778 {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F,
779 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F,
780 0x20, 0x21, 0x22, 0x23 };
781 ;
783 static uint8_t ourEncrKey[36] =
784 {0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0xFF,
785 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0xFF,
786 0x30, 0x31, 0x32, 0x33 };
789 /*************************END NETAPI OBJECTS***********************/
791 #define START_SRC_IP 0x0a00000a
792 #define DST_IP 0xc0a80001
793 #define NEW_START_SRC_IP 0x9eda000a
794 #define DST_PORT 0x555
795 #define START_SRC_PORT 0x1234
796 #define NEW_START_SRC_PORT 100
797 void update_header(HEAD_T * p_head, int len)
798 {
799 unsigned char *p = (unsigned char *) &p_head->udp[1];
800 len -= (20+14);
801 /* update ip checksum */
802 /* update udp checksum */
803 /* update length */
804 *p= (len&0xff00)>>8;
805 *(p+1) = len&0xff;
806 }
808 #if 0
809 void gen_pkts(int np)
810 {
811 int i;
812 int ip = START_SRC_IP &0xff;
813 int port= START_SRC_PORT;
814 //HEAD_T temp={{0x25000200,0xdead0000,0x80110000,START_SRC_IP,DST_IP},
815 // {START_SRC_PORT<<16|DST_PORT,0x01ec<<16|0x0000}};
816 HEAD_T temp;
817 memcpy(&temp,&testPkt[0],sizeof(HEAD_T));
819 for(i=0;(i<np) && (i<NP);i++)
820 {
821 memcpy(&pkts[i],&temp,sizeof(temp));
822 update_header(&pkts[i],512); /* update checksums etc */
823 /* change template for new pkt */
824 ip+=1;
825 if(ip>254) {(ip=START_SRC_IP&0xff); port+=1; }
826 temp.ip[3] = htonl((START_SRC_IP&0xffffff00)| ip);
827 temp.udp[0] = htonl( (temp.udp[0]&0xffff0000)| port);
828 temp.udp[1] = htonl(temp.udp[1]);
830 }
831 n_pkt=np;
832 }
833 #endif
835 void build_table(Trie * p_trie)
836 {
837 int i;
838 int sport=NEW_START_SRC_PORT;
839 HEAD_T temp,temp2;
840 KEY_T key;
842 memcpy(&temp,&testPkt[14],sizeof(temp));
844 //insert entry into trie
845 key.src_ip = temp.ip[3];
846 key.dst_ip = temp.ip[4];
847 key.src_port= (temp.udp[0]&0xffff0000)>>16;
848 key.dst_port= (temp.udp[0]&0x0000ffff);
849 trie_insert(p_trie,(char *)&key,sizeof(key), (void *) &nat[0]); //asociate with nat entry 0
851 //build nat table
852 for(i=0;i<100;i++)
853 {
854 memcpy(&temp2,&testPkt[14],sizeof(temp));
855 temp2.udp[0] = (temp2.udp[0] & 0xffff0000) | sport;
856 memcpy(&nat[i], &temp2, sizeof(temp2));
857 sport+= 1;
858 }
859 }
861 //===========stub transmitter==================
862 void send_pkt(Ti_Pkt *pkt, int len)
863 {
864 //just free pkt. Don't send
865 Pktlib_freePacket((Ti_Pkt*)pkt);
866 return;
867 }
869 //==========stub slow path============
870 void slow_path(Ti_Pkt *pkt, int len)
871 {
872 // debug: check descriptor for validity by verifying that desciptor link field is null as expected\n");
873 {Ti_Pkt * k= Pktlib_getNextPacket(pkt); if(k != 0) {printf(" slowpath, nexpkt != NULL");}}
874 //just free pkt
875 Pktlib_freePacket((Ti_Pkt*)pkt);
876 return;
877 }
878 /* check header */
879 struct LastPktInfo
880 {
881 int iface;
882 int ipcsum;
883 int l4csum;
884 } ;
885 static struct LastPktInfo lpInfo;
887 int check_header(HEAD_T * p_head, PKTIO_METADATA_T * p_meta)
888 {
889 #ifdef MULTI_THREAD
890 int coreid=Osal_nwalGetProcId(); //who we are(thread local)
891 //int coreid = our_core;
892 #else
893 int coreid=0;
894 #endif
895 if (NWAL_RX_FLAG1_META_DATA_VALID & p_meta->u.rx_meta->rxFlag1)
896 {
897 lpInfo.iface = ((unsigned int)p_meta->u.rx_meta->appId) &0xff; //last byte is interface num
898 lpInfo.ipcsum =(p_meta->u.rx_meta->rxFlag1 & NWAL_RX_FLAG1_IPV4_CHKSUM_VERIFY_MASK )== NWAL_RX_FLAG1_IPV4_CHKSUM_VERIFY_ACK ? 1 : 0;
899 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;
900 if ((unsigned int)p_meta->u.rx_meta->appId & NETAPI_NETCP_MATCH_IPSEC)
901 {
902 stats[coreid].sec_rx++;
903 }
904 if ((unsigned int)p_meta->u.rx_meta->appId & NETAPI_NETCP_MATCH_IPSEC_POLICY)
905 {
906 stats[coreid].secp_rx++;
907 }
909 if ((unsigned int)p_meta->u.rx_meta->appId & NETAPI_NETCP_MATCH_CLASS)
910 {
911 int c= ((unsigned int)p_meta->u.rx_meta->appId >>8)&0xffff;
912 if (c==0) stats[coreid].n_class0_rx +=1;
913 else if (c==1) stats[coreid].n_class1_rx +=1;
914 else if (c==2) stats[coreid].n_class2_rx +=1;
915 else printf("**NET_TEST RX -unknown class: %x\n", p_meta->u.rx_meta->appId);
916 }
917 }
919 return 1;
920 }
922 #define PKT_LEN 1400
923 void test_alloc_free(int n)
924 {
925 int i;
926 Ti_Pkt * b;
928 for(i=0;i<n;i++)
929 {
930 b=Pktlib_allocPacket(ourHeap,PKT_LEN);
931 Pktlib_freePacket(b);
932 }
933 }
935 //measurement test points
936 unsigned int vv1;
937 unsigned int vv2;
938 unsigned int vv3;
939 unsigned int vv4;
940 unsigned int vv5;
941 unsigned int vv6;
944 unsigned int vv11;
946 extern unsigned int nwal_prof1,nwal_prof2,nwal_prof3,nwal_prof4,nwal_prof5,nwal_prof6;
948 //#define REASSEMBLE_BENCH
949 #ifdef REASSEMBLE_BENCH
950 #include <ti/drv/pa/example/reassemLib/reassemLib.h>
951 /*--------------reassembly benchmark--------------------------------*/
952 void our_reassemble_bench(int nfrags)
953 {
954 paIPReassemblyConfig_t Config={5,128,10000 };
955 int i,j;
956 int len;
957 Ti_Pkt tip;
958 char *buffer;
959 unsigned long v1;
960 unsigned long v2;
961 unsigned long sum1=0;
962 unsigned long sum2=0;
963 paEx_reassemLibInit(&Config);
964 for(j=0;j<200/nfrags;j++)
965 {
966 for(i=0;i<nfrags;i++)
967 {
968 short temp;
969 tip=Pktlib_allocPacket(ourHeap,PKT_LEN);
970 Pktlib_getDataBuffer(tip,(uint8_t**)&buffer,&len);
971 memcpy(&buffer[0],&testPkt[14],20); //IP header
972 if (i < (nfrags-1)) buffer[6] = 0x20;
973 temp = i*40;
974 buffer[6]|= (temp&0x1f00)>>8;
975 buffer[7]= (temp&0xff);
976 temp = 20+40*8;
977 buffer[2]= (temp&0xff00)>>8;
978 buffer[3]= (temp&0xff);
979 Pktlib_setPacketLen(tip, temp);
980 v1= hplib_mUtilGetPmuCCNT();
981 paEx_reassemLibProc(tip, 0xffff);
982 v2= hplib_mUtilGetPmuCCNT();
983 sum1+= v2-v1;
984 }
985 sum2 += v2-v1;
986 }
987 printf("reasssembly test: %d trials, %d frags/pkt %d cycles/frag %d cycles/last frag\n",j,nfrags, sum1/(j*nfrags), sum2/(j));
988 }
989 #endif
991 /*--------------basic pktio send/recv benchmark----------------------*/
992 unsigned int timings[10];
993 void our_pktio_bench(int ntrials)
994 {
995 int i;
996 #define NBATCH 8
997 Ti_Pkt tip;
998 unsigned char * pData;
999 int len;
1000 int n;
1001 int err;
1002 int sum =0;
1004 Osal_cache_op_measure_reset();
1005 for(i=0;i<10;i++) timings[i]=0;
1006 printf("calibration loop .. ");
1007 for(i=0;i<1000;i++)
1008 {
1009 vv1= hplib_mUtilGetPmuCCNT();
1010 vv2= hplib_mUtilGetPmuCCNT();
1011 sum+=(vv2-vv1);
1012 }
1013 printf(" accuracy = +- %d cycles\n", sum/1000);
1014 sleep(1);
1016 PKTIO_METADATA_T meta[10]={0};
1017 //send single, recv single
1018 for(i=0;i<ntrials;i++)
1019 {
1020 vv1= hplib_mUtilGetPmuCCNT();
1021 tip=Pktlib_allocPacket(ourHeap,PKT_LEN);
1022 vv2= hplib_mUtilGetPmuCCNT();
1023 Pktlib_getDataBuffer(tip,&pData,&len);
1024 vv3= hplib_mUtilGetPmuCCNT();
1025 pktio_send(our_chan,tip,&meta[0],&err);
1026 vv4= hplib_mUtilGetPmuCCNT();
1027 n=pktio_poll(our_chan,NULL , &err);
1028 vv5= hplib_mUtilGetPmuCCNT();
1029 timings[0]+=(vv6-vv4);
1030 timings[1]+=(vv5-vv4);
1031 timings[3]+=(vv4-vv3);
1032 timings[5]+=(vv3-vv1);
1033 timings[8]+=(vv11-vv6);
1035 #ifdef PKTIO_GET_BENCHMARK
1036 timings[2]+=(our_chan->vv7p-vv4);
1037 timings[4]+=(our_chan->vv8p-vv3);
1038 timings[6]+=(our_chan->vv9p-our_chan->vv8p);
1039 timings[7]+=(our_chan->vv10p-our_chan->vv7p);
1040 #endif
1041 }
1043 #ifdef PKTIO_GET_BENCHMARK
1044 printf("pktio bench. rx=%d (wcb%d) (toqm%d) tx=%d (toqm%d) alloc=%d qpush=%d qpop=%d free=%d\n", timings[0]/ntrials,
1045 timings[1]/ntrials, timings[2]/ntrials,timings[3]/ntrials, timings[4]/ntrials,timings[5]/ntrials,
1046 timings[6]/ntrials,timings[7]/ntrials, timings[8]/ntrials );
1047 {
1048 unsigned long long ccycles;
1049 unsigned long long n_c_ops;
1050 ccycles =Osal_cache_op_measure(&n_c_ops);
1051 printf("n_c_ops=%lld cache_op_time=%lld (total) = %lld (pp)\n", n_c_ops, ccycles, n_c_ops? (ccycles/(n_c_ops)) : 0);
1052 }
1053 #endif
1055 }
1056 /*-----------test driver: gen an input pkt------- */
1057 //char buffer[sizeof(HEAD_T)+PKT_LEN];
1058 Ti_Pkt * get_pkt(int n, unsigned int *p_len, Pktlib_HeapHandle heap2use, int size, unsigned char * buf2cpy, int copy_size)
1059 {
1060 int ind;
1061 long long temp;
1062 Ti_Pkt * b;
1063 char * buffer;
1064 unsigned int len;
1066 if (pktloopback==0)
1067 {
1068 if (n>=TX_BURST) return NULL; //just gen pkts to warm swtich, so that it knows
1069 //our mac is valid
1070 }
1071 b=Pktlib_allocPacket(heap2use,size);
1072 if (!b)
1073 {printf("net_test: get_pkt() heap empty!! %d pkts gen'd %d \n", n); return NULL;};
1075 //debug - way to validate descriptor
1076 {Ti_Pkt* k= Pktlib_getNextPacket(b);
1077 if(k != 0) {printf(" genpkt, nexpkt != NULL");}}
1080 //get pointer to buffer area of packet
1081 Pktlib_getDataBuffer(b,(uint8_t**)&buffer,&len);
1082 if (!buffer)
1083 {printf("net_test: get_pkt() heap returned empty buffer %d \n", n); return NULL;};
1085 #if 0
1086 if (pktloopback==0)
1087 {
1088 temp = (long long) rand();
1089 temp *= PKT_LEN;
1090 temp /= RAND_MAX;
1091 temp +=2;
1092 *p_len = (int) temp;
1093 *p_len = *p_len &0xfffffffe;
1094 temp = (long long) rand();
1095 temp *= n_pkt;
1096 temp /= RAND_MAX;
1097 ind = (int) temp;
1098 update_header(&pkts[ind],*p_len);
1099 //printf("get pkt:%d %d ind=%d len=%d\n",RAND_MAX, rand(),ind, *p_len);
1100 memcpy(&buffer[0], &mac_header[0],14);
1101 memcpy(&buffer[14],(char*)&pkts[ind],sizeof(HEAD_T));
1102 }
1103 else
1104 #endif
1106 //copy test packet into buffer
1107 {
1108 memcpy(&buffer[0], buf2cpy, copy_size);
1109 *p_len = copy_size;
1110 }
1111 return b;
1112 }
1114 static int eof=0;
1115 /*--------------------------------------------------------------
1116 *----------utility to flip a packet and send
1117 *--------------------back to source----------------------------
1118 * flag=1 => ipsec
1119 *--------------------------------------------------------------*/
1120 void flip_and_send_pkt(Ti_Pkt *tip, unsigned char * p_pkt, int len, int flag, uint16_t enet_port)
1121 {
1122 unsigned char mac_temp[6];
1123 unsigned char ip_temp[4];
1124 unsigned char new_dest_port[2]={0x75,0x30}; // 30000
1125 uint16_t blah;
1126 uint16_t i=1; /* for testing only */
1128 uint8_t *p_spi;
1129 netTestSA_t * p_sa_info;
1130 uint8_t p_iv[16];
1131 uint8_t p_add[8];
1132 Cppi_HostDesc* pPloadDesc;
1133 uint8_t ah_len;
1134 #ifdef AH_SUPPORT
1135 HEAD_T * p_head;
1136 HEAD_T temp_head;
1137 int pkt_type;
1138 #endif
1140 #ifdef MULTI_THREAD
1141 int coreid=Osal_nwalGetProcId(); //who we are(thread local)
1142 //int coreid = our_core;
1143 #else
1144 int coreid=0;
1145 #endif
1146 //netapi_dump_buf((long*)p_pkt,len);
1147 Pktlib_setPacketLen(tip,len);
1148 //flip the mac address
1149 memcpy(&mac_temp,&p_pkt[0],6);
1150 memcpy(&p_pkt[0],&p_pkt[6],6);
1151 memcpy(&p_pkt[6],&mac_temp,6);
1152 //memcpy(&p_pkt[0],real_mac_header,6); //for testing to wireshark pc
1154 //flip the ip (outer in case of ipsec)
1155 memcpy(&ip_temp, &p_pkt[14+12],4);
1156 memcpy(&p_pkt[14+12],&p_pkt[14+12+4],4);
1157 memcpy(&p_pkt[14+12+4],&ip_temp,4);
1159 #ifdef AH_SUPPORT
1160 p_head=&temp_head;
1161 #endif
1162 //outer checksum to 0
1163 if (!flag)
1164 {
1165 memset(&p_pkt[14+10],0,2);
1166 }
1168 //inner ip &udp for ipsec
1169 if (flag)
1170 {
1171 #ifdef AH_SUPPORT
1172 memcpy(p_head,&p_pkt[14],sizeof(HEAD_T));
1174 if ((p_head->ip[2]&0x0000ff00)==0x00003300)
1175 {
1176 p_spi = &(p_pkt[netTest_MAC_HEADER_LEN+netTest_IP_HEADER_LEN + 4]);
1177 pkt_type = IPSEC_AH_PKT;
1178 printf("flip_and_send_pkt: IPSEC AH packet received\n");
1179 }
1180 else if ((p_head->ip[2]&0x0000ff00)==0x00003200)
1181 {
1182 p_spi = &(p_pkt[netTest_MAC_HEADER_LEN+netTest_IP_HEADER_LEN]);
1183 pkt_type = IPSEC_ESP_PKT;
1185 printf("flip_and_send_pkt: IPSEC ESP packet received\n");
1187 }
1188 #endif
1190 //p_spi = &(p_pkt[netTest_MAC_HEADER_LEN+netTest_IP_HEADER_LEN + 4]);
1191 p_sa_info = (netTestSA_t *) trie_lookup(p_trie_sa, (char *)p_spi ,4);
1192 if (p_sa_info == NULL)
1193 {
1194 printf("flip_and_send_pkt(): trie_lookup() failed\n");
1195 return;
1196 }
1197 //just drop non-udp packet
1198 if (p_pkt[p_sa_info->tx_payload_info.encOffset+9]!=0x11)
1199 {
1200 stats[coreid].n_new+=1;Pktlib_freePacket(tip); return;
1201 }
1203 /* flip inner IP */
1204 printf("flip_and_send_pkt: encOffSet %d\n", p_sa_info->tx_payload_info.encOffset);
1205 memcpy(&ip_temp, &p_pkt[p_sa_info->tx_payload_info.encOffset+12],4);
1206 memcpy(&p_pkt[p_sa_info->tx_payload_info.encOffset+12],&p_pkt[p_sa_info->tx_payload_info.encOffset+12+4],4);
1207 memcpy(&p_pkt[p_sa_info->tx_payload_info.encOffset+12+4],&ip_temp,4);
1208 /* setting udp ports */
1209 memcpy(&p_pkt[p_sa_info->tx_payload_info.encOffset+20+2],&new_dest_port[0],2);
1210 memset(&p_pkt[p_sa_info->tx_payload_info.encOffset+20+6],0,2); //checksum
1212 if (config.ipsec_mode_tx == IPSEC_MODE_TX_SIDEBAND)
1213 {
1214 /* inner ip checksum : leave alone */
1215 /* outer ip, set to 0 (we will compute on way out */
1216 memset(&p_pkt[14+10],0,2);
1217 }
1218 else
1219 {
1220 //#else //inflow, don't touch outer , clear inner
1221 //DALmemset(&p_pkt[14+20+8+16+10],0,2); //inner checksum, we will compute on way out
1222 //outer ip checksum : leave alone
1223 }
1224 }
1225 else
1226 {
1227 memset(&p_pkt[14+20+6],0,2);//0 udp checksum (we will compute on way out
1228 memcpy(&p_pkt[14+20+2],&new_dest_port[0],2);
1229 }
1231 /*IPSEC case */
1232 if (flag)
1233 {
1234 if (config.ipsec_mode_tx == IPSEC_MODE_TX_SIDEBAND)
1235 //send to crypto for encryption
1236 //12 byte auth tag
1237 {
1238 PKTIO_METADATA_T meta = {PKTIO_META_SB_TX,{0},0};
1239 int err;
1240 nwalDmTxPayloadInfo_t meta_tx={0};
1241 meta.sa_handle=p_sa_info->tx_data_mode_handle; //use TX SA context
1243 memcpy(&meta_tx, &(p_sa_info->tx_payload_info), sizeof(nwalDmTxPayloadInfo_t));
1246 meta_tx.encSize = len - p_sa_info->tx_payload_info.encOffset -p_sa_info->auth_tag_size;
1247 meta_tx.authSize = len - meta_tx.authOffset - p_sa_info->auth_tag_size;
1249 #if 0
1250 printf("flip_and_send_pkt(): encOffset %d\n", meta_tx.encOffset);
1251 printf("flip_and_send_pkt():authOffset %d\n", meta_tx.authOffset);
1252 printf("flip_and_send_pkt(): encSize %d\n", meta_tx.encSize);
1253 printf("flip_and_send_pkt(): authSize %d\n", meta_tx.authSize);
1254 #endif
1256 meta_tx.pAuthIV=NULL;
1257 meta_tx.aadSize=0;
1258 meta_tx.pAad=NULL;
1259 if (p_sa_info->cipherMode == NWAL_SA_EALG_AES_CTR)
1260 {
1261 memcpy(&p_iv[0], &ourEncrKey[16], 4);
1262 memcpy(&p_iv[4], &p_pkt[netTest_MAC_HEADER_LEN +netTest_IP_HEADER_LEN + netTest_ESP_HEADER_LEN], 8);
1263 p_iv[12] = 0;
1264 p_iv[13] = 0;
1265 p_iv[14] = 0;
1266 p_iv[15] = 1;
1267 meta_tx.pEncIV = &p_iv[0];
1268 }
1269 else if ((p_sa_info->cipherMode == NWAL_SA_EALG_AES_GCM) ||
1270 (p_sa_info->cipherMode == NWAL_SA_EALG_AES_CCM))
1271 {
1272 memcpy(&p_iv[0], &p_pkt[netTest_MAC_HEADER_LEN +netTest_IP_HEADER_LEN + netTest_ESP_HEADER_LEN], 8);
1273 meta_tx.pEncIV = &p_iv[0];
1274 memcpy(&p_add[0], &p_pkt[netTest_MAC_HEADER_LEN +netTest_IP_HEADER_LEN], 8);
1275 meta_tx.pAad= &p_add[0];
1276 meta_tx.aadSize = 8;
1277 }
1278 else if (p_sa_info->cipherMode == NWAL_SA_EALG_NULL)
1279 {
1280 meta_tx.pEncIV = NULL;
1281 }
1282 else
1283 {
1284 meta_tx.pEncIV = &p_pkt[netTest_MAC_HEADER_LEN +netTest_IP_HEADER_LEN + netTest_ESP_HEADER_LEN ];
1285 }
1286 //meta_tx.authIvSize=0;
1288 /* post it to netcp sb tx channel*/
1289 meta_tx.appCtxId = (nwal_AppId)hplib_mUtilGetPmuCCNT();
1290 meta.u.tx_sb_meta=&meta_tx;
1292 /* Use the command label which was cached during create time
1293 * Update the Queue to receive output packet from SA to the local
1294 * core Queue. Below information can be saved by application in
1295 * per process context to avoid API overhead per packet
1296 * Application can use below rxSbSaQ for polling packets back from
1297 * SA
1298 */
1299 nwalRetVal =
1300 nwal_getLocCxtInfo(PKTIO_GET_NWAL_INSTANCE(netcp_sb_tx_chan),
1301 &nwalLocCxt);
1302 if(nwalRetVal == nwal_OK)
1303 {
1304 p_sa_info->tx_dmPSCmdInfo.rxSbSaQ = nwalLocCxt.rxSbSaQ;
1305 }
1306 nwal_mCmdDMUpdate(tip,
1307 &p_sa_info->tx_dmPSCmdInfo,
1308 meta_tx.appCtxId,
1309 meta_tx.encOffset,
1310 meta_tx.encSize,
1311 meta_tx.pEncIV,
1312 meta_tx.authOffset,
1313 meta_tx.authSize,
1314 meta_tx.pAuthIV,
1315 meta_tx.aadSize,
1316 meta_tx.pAad);
1317 pPloadDesc = Pktlib_getDescFromPacket(tip);
1318 pPloadDesc = Qmss_osalConvertDescVirtToPhy(pPloadDesc);
1319 Qmss_queuePushDescSizeRaw(p_sa_info->tx_dmPSCmdInfo.txQueue,
1320 pPloadDesc,
1321 NWAL_DESC_SIZE);
1323 }
1324 else
1325 {
1326 //INFLOW TX *******************
1327 //send pkt directly, asking for IP and UDP checksum offloads AND IPSEC to be applied
1328 PKTIO_METADATA_T meta = {PKTIO_META_TX,{0},0};
1329 int err;
1330 nwalTxPktInfo_t meta_tx={0};
1331 #define USE_COPY
1332 #ifdef USE_COPY
1333 //debug: see if re-using RX descriptor for TX is causing our SA lockup
1334 {
1335 int new_len=0;
1336 Ti_Pkt new_tip = get_pkt(0, &new_len, specialLarge , len+10 , &p_pkt[0] , len);
1337 if (!new_tip)
1338 {
1339 printf("net_test> new_tip NULL\n");
1340 }
1341 else
1342 {
1343 Pktlib_setPacketLen(new_tip,new_len);
1344 Pktlib_freePacket(tip);
1345 tip=new_tip;
1346 Pktlib_getDataBuffer(tip,(uint8_t**)&p_pkt,&new_len); //reset p_pkt to point to new buffer as its used below
1347 // Cppi_setTimeStamp (Cppi_DescType_HOST, (Cppi_Desc *) tip,stats[coreid].sec_tx);
1348 }
1349 }
1350 if (len <1500)
1351 {
1352 eof+=1;
1353 }
1354 #endif
1356 meta.sa_handle=p_sa_info->tx_inflow_mode_handle; //this tells netapi that inflow crypto needs to be applied
1357 meta_tx.startOffset = p_sa_info->tx_pkt_info.startOffset;
1358 meta_tx.ipOffBytes =p_sa_info->tx_payload_info.encOffset;
1359 meta_tx.l4OffBytes = p_sa_info->tx_pkt_info.l4OffBytes;
1360 meta_tx.l4HdrLen = p_sa_info->tx_pkt_info.l4HdrLen;
1361 meta_tx.ploadLen = (unsigned) ((p_pkt[meta_tx.l4OffBytes+4]<<8)|p_pkt[meta_tx.l4OffBytes+4+1]) -8 ;
1362 meta_tx.saOffBytes= p_sa_info->tx_pkt_info.saOffBytes;
1363 if (pkt_type == IPSEC_AH_PKT)
1364 {
1365 memset(&p_pkt[netTest_MAC_HEADER_LEN+netTest_IP_HEADER_LEN+netTest_IPSEC_AH_FIXED_HDR_SIZE],0,netTest_IPSEC_AH_FIXED_HDR_SIZE);
1366 meta_tx.txFlag1 = p_sa_info->tx_pkt_info.txFlag1;
1367 meta_tx.saPayloadLen=len-netTest_MAC_HEADER_LEN; //don't inlcude mac
1368 meta_tx.saAhMacSize = 12;
1369 meta_tx.saAhIcvOffBytes = netTest_MAC_HEADER_LEN + netTest_IP_HEADER_LEN + netTest_IPSEC_AH_FIXED_HDR_SIZE;
1370 meta_tx.enetPort = enet_port;
1371 }
1372 else if (pkt_type == IPSEC_ESP_PKT)
1373 {
1374 meta_tx.txFlag1 = p_sa_info->tx_pkt_info.txFlag1;
1375 meta_tx.saPayloadLen=len-netTest_MAC_HEADER_LEN-netTest_IP_HEADER_LEN; //don't include mac and ip outer header
1376 meta_tx.enetPort = 0;
1377 }
1378 else
1379 {
1380 printf("flip_and_send_pkt: invalid ESP protocol\n");
1381 return;
1382 }
1384 meta_tx.pseudoHdrChecksum =
1385 test_utilGetIpv4PsudoChkSum(&p_pkt[meta_tx.ipOffBytes],8+ meta_tx.ploadLen);
1388 /* post it to netcp tx channel*/
1389 meta.u.tx_meta=&meta_tx;
1390 if (stats[coreid].sec_tx<20) dump_descr((long *) tip, stats[coreid].sec_tx);
1391 pktio_send(netcp_tx_chan,tip,&meta,&err);
1392 stats[coreid].tx +=1;
1393 stats[coreid].sec_tx +=1;
1394 }
1395 }
1396 else //non ipsec send pkt directly, asking for IP and UDP checksum ofload
1397 {
1398 PKTIO_METADATA_T meta2 = {PKTIO_META_TX,{0},0};
1399 int err;
1400 nwalTxPktInfo_t meta_tx2={0};
1401 meta2.sa_handle=nwal_HANDLE_INVALID;
1402 meta_tx2.txFlag1 = (NWAL_TX_FLAG1_DO_IPV4_CHKSUM|NWAL_TX_FLAG1_DO_UDP_CHKSUM| NWAL_TX_FLAG1_META_DATA_VALID );
1403 meta_tx2.startOffset = 0;
1404 meta_tx2.ipOffBytes = 14;
1405 meta_tx2.l4OffBytes = 14+20;
1406 meta_tx2.l4HdrLen = 8;
1407 meta_tx2.ploadLen = (unsigned) ((p_pkt[14+20+4]<<8)|p_pkt[14+20+4+1]) -8 ;
1408 meta_tx2.pseudoHdrChecksum =
1409 test_utilGetIpv4PsudoChkSum(&p_pkt[14],8+ meta_tx2.ploadLen);
1411 /* post it to netcp tx channel*/
1412 meta2.u.tx_meta=&meta_tx2;
1413 pktio_send(netcp_tx_chan,tip,&meta2,&err);
1414 stats[coreid].tx +=1;
1415 }
1416 }
1421 /***************************************
1422 benchmark receive handler
1423 ****************************************/
1424 void recv_cb_bench(struct PKTIO_HANDLE_Tag * channel, Ti_Pkt* p_recv[],
1425 PKTIO_METADATA_T meta[], int n_pkts,
1426 uint64_t ts )
1427 {
1428 int i;
1429 vv6= hplib_mUtilGetPmuCCNT();
1430 for (i=0;i<n_pkts; i++)
1431 {
1432 Pktlib_freePacket(p_recv[i]);
1433 }
1434 vv11 = hplib_mUtilGetPmuCCNT();
1435 }
1437 /****************************************************************************************/
1438 /******************SB Accelerator Callback PKT RECEIVE HANDLER *************************/
1439 /****************** Handles Decrypt and Encrypt operation callbacks ******************/
1440 /******************************************************************************************/
1441 void recv_sb_cb(struct PKTIO_HANDLE_Tag * channel, Ti_Pkt* p_recv[],
1442 PKTIO_METADATA_T meta[], int n_pkts,
1443 uint64_t ts )
1444 {
1445 int i;
1446 int len;
1447 int p;
1448 HEAD_T * p_res;
1449 Ti_Pkt * tip;
1450 unsigned int templen;
1451 int err;
1452 KEY_T key;
1453 char * p_pkt;
1454 HEAD_T * p_head;
1455 HEAD_T temp_head;
1456 int tag_cmp=0;
1457 unsigned int hash[4];
1458 uint8_t *p_spi;
1459 netTestSA_t *p_sa_info;
1461 #ifdef MULTI_THREAD
1462 int coreid=Osal_nwalGetProcId(); //who we are(thread local)
1463 //int coreid = our_core;
1464 #else
1465 int coreid=0;
1466 #endif
1467 //nwal_AppId time;
1468 unsigned long time, delta_time;
1469 /* loop over received pkts */
1470 for(i=0;i<n_pkts;i++)
1471 {
1472 tip = p_recv[i];
1473 Pktlib_getDataBuffer(tip,(uint8_t**)&p_pkt,&templen);//ignore templen
1474 len = Pktlib_getPacketLen(tip);//real length
1477 p_spi = &(p_pkt[netTest_MAC_HEADER_LEN+netTest_IP_HEADER_LEN]);
1479 p_sa_info = (netTestSA_t *) trie_lookup(p_trie_sa, (char *)p_spi ,4);
1480 if (p_sa_info == NULL)
1481 {
1482 printf("recv_sb_cb(): trie_lookup failed\n");
1483 continue;
1484 }
1487 //is this a decrypt (rx_tunnel) complete
1488 if ((int)meta[i].u.rx_sb_meta->appId == p_sa_info->rx_tunnel)
1489 {
1491 time = hplib_mUtilGetPmuCCNT();
1492 delta_time = time -(unsigned long) meta[i].u.rx_sb_meta->appCtxId;
1493 stats[coreid].total_decrypt_time += delta_time;
1494 stats[coreid].sb_rx+=1;
1495 //copy hash out of meta data (for some reason it needs endian conversion)
1496 hash[0]= htonl( meta[i].u.rx_sb_meta->pAuthTag[0]);
1497 hash[1]= htonl( meta[i].u.rx_sb_meta->pAuthTag[1]);
1498 hash[2]= htonl( meta[i].u.rx_sb_meta->pAuthTag[2]);
1499 hash[3]= htonl( meta[i].u.rx_sb_meta->pAuthTag[3]);
1500 if(stats[coreid].sb_rx<=16)
1501 {
1502 char *tp = (char *) &hash[0];
1503 //dump_header((long*)p_pkt, stats[coreid].sb_rx, (int)meta[i].u.rx_sb_meta->appId,0);
1504 #if 0
1505 printf("decrypt complete: tag in pkt= %x %x %x %x %x %x %x %x %x %x %x %x %x %x %x %x \n",
1506 p_pkt[len-16],p_pkt[len-15],p_pkt[len-14],p_pkt[len-13],
1507 p_pkt[len-12],p_pkt[len-11],p_pkt[len-10],p_pkt[len-9], p_pkt[len-8],
1508 p_pkt[len-7],p_pkt[len-6],
1509 p_pkt[len-5],p_pkt[len-4],p_pkt[len-3],p_pkt[len-2],p_pkt[len-1]);
1510 printf("decrypt complete: tag from SA=%x %x %x %x %x %x %x %x %x %x %x %x %x %x %x %x \n",
1511 tp[0],tp[1],tp[2],tp[3],tp[4],tp[5],
1512 tp[6],tp[7],tp[8],tp[9],tp[10],tp[11],tp[12],tp[13],tp[14],tp[15]);
1514 // netapi_dump_buf((long*)p_pkt,len);
1515 #endif
1516 }
1517 //check tag
1518 //printf("recv_sb_cb(); auth tag size %d\n", p_sa_info->auth_tag_size);
1519 tag_cmp = memcmp(&p_pkt[len-p_sa_info->auth_tag_size],(char*) &hash[0],p_sa_info->auth_tag_size); //todo, really use meta->authTagLen
1520 stats[coreid].n_auth_ok += !(tag_cmp);
1522 flip_and_send_pkt(tip, p_pkt, len,1, 0); //flip packet to echo back and send
1523 }
1524 //this is an encrypt (tx tunnel) complete
1525 else if((int)meta[i].u.rx_sb_meta->appId== p_sa_info->tx_tunnel )
1526 {
1527 hash[0]= htonl( meta[i].u.rx_sb_meta->pAuthTag[0]);
1528 hash[1]= htonl( meta[i].u.rx_sb_meta->pAuthTag[1]);
1529 hash[2]= htonl( meta[i].u.rx_sb_meta->pAuthTag[2]);
1530 hash[3]= htonl( meta[i].u.rx_sb_meta->pAuthTag[3]);
1531 stats[coreid].sb_tx+=1;
1532 if(stats[coreid].sb_tx<=16)
1533 {
1534 char *tp1 = (char *) &hash[0];
1535 //dump_header((long*)p_pkt, stats[coreid].sb_tx, (int)meta[i].u.rx_sb_meta->appId,0);
1536 #if 0
1537 printf("encrypt complete: tag in pkt= %x %x %x %x %x %x %x %x %x %x %x %x %x %x %x %x \n",
1538 p_pkt[len-16],p_pkt[len-15],p_pkt[len-14],p_pkt[len-13],
1539 p_pkt[len-12],p_pkt[len-11],p_pkt[len-10],p_pkt[len-9], p_pkt[len-8],
1540 p_pkt[len-7],p_pkt[len-6],
1541 p_pkt[len-5],p_pkt[len-4],p_pkt[len-3],p_pkt[len-2],p_pkt[len-1]);
1542 printf("encrypt complete: tag from SA=%x %x %x %x %x %x %x %x %x %x %x %x %x %x %x %x \n",
1543 tp1[0],tp1[1],tp1[2],tp1[3],tp1[4],tp1[5],
1544 tp1[6],tp1[7],tp1[8],tp1[9],tp1[10],tp1[11],tp1[12],tp1[13],tp1[14],tp1[15]);
1545 //netapi_dump_buf((long*)p_pkt,len);
1546 #endif
1547 }
1548 //put the computed tag in the packet
1549 memcpy(&p_pkt[len-p_sa_info->auth_tag_size],(char*)&hash[0],p_sa_info->auth_tag_size); //todo, really use meta->authTagLen
1550 // printf("recv_sb_cb(): dumping pkt after updating computed tag, len %d, auth tag size %d\n", len, p_sa_info->auth_tag_size);
1551 //netapi_dump_buf(p_pkt, len);
1552 {
1553 PKTIO_METADATA_T meta2 = {PKTIO_META_TX,{0},0};
1554 nwalTxPktInfo_t meta_tx={0};
1555 // now send directly
1556 meta2.sa_handle=nwal_HANDLE_INVALID;
1557 meta_tx.txFlag1 = (NWAL_TX_FLAG1_DO_IPV4_CHKSUM| NWAL_TX_FLAG1_META_DATA_VALID);//only outer IP header checksum. no udp checksum possible since pkt is already encrypted
1558 meta_tx.startOffset = 0;
1559 meta_tx.ipOffBytes = netTest_MAC_HEADER_LEN;
1560 //not used
1561 meta_tx.l4OffBytes = 0;
1562 meta_tx.l4HdrLen = 0;
1563 meta_tx.ploadLen = 0;
1564 time = hplib_mUtilGetPmuCCNT();
1565 delta_time = time -(unsigned long) meta[i].u.rx_sb_meta->appCtxId;
1566 stats[coreid].total_encrypt_time += delta_time;
1569 /* post it to netcp tx channel*/
1570 meta2.u.tx_meta=&meta_tx;
1571 // printf("recv_sb_cb(): calling pktio send to send it to network\n");
1572 pktio_send(netcp_tx_chan,tip,&meta2,&err);
1573 hplib_cacheWbInv(p_pkt,len);
1574 stats[coreid].tx +=1;
1575 }
1576 }
1577 else printf("netapi recv_sb_cb: unknown appiD %x \n",meta[i].u.rx_sb_meta->appId );
1578 }
1579 }
1581 /******************************************************/
1582 /******************PKT RECEIVE HANDLER *************************/
1583 /******************************************************/
1584 void recv_cb(struct PKTIO_HANDLE_Tag * channel, Ti_Pkt* p_recv[],
1585 PKTIO_METADATA_T meta[], int n_pkts,
1586 uint64_t ts )
1587 {
1588 int i;
1589 int len;
1590 int p;
1591 HEAD_T * p_res;
1592 Ti_Pkt * tip;
1593 unsigned int templen;
1594 int err = 0;
1595 KEY_T key;
1596 char * p_pkt;
1597 HEAD_T * p_head;
1598 HEAD_T temp_head;
1599 netTestSA_t *p_sa_info;
1600 uint8_t *p_spi;
1601 uint8_t p_iv[16];
1602 uint8_t p_add[8];
1603 uint8_t p_add1[1500];
1604 int16_t retVal;
1605 nwalGlobCxtInfo_t nwalGlobCxt;
1606 nwalLocCxtInfo_t nwalLocCxt;
1608 Cppi_HostDesc* pPloadDesc;
1609 int ifno;
1610 uint16_t enet_port = 0;
1612 #ifdef MULTI_THREAD
1613 int coreid=Osal_nwalGetProcId(); //who we are(thread local)
1614 //int coreid = our_core;
1615 #else
1616 int coreid=0;
1617 #endif
1618 p_head=&temp_head;
1620 /* loop over received pkts */
1621 for(i=0;i<n_pkts;i++)
1622 {
1623 ifno = ((unsigned int)meta[i].u.rx_meta->appId)&0xff;
1624 enet_port = meta[i].u.rx_meta->enetPort;
1625 tip = p_recv[i];
1627 Pktlib_getDataBuffer(tip,(uint8_t**)&p_pkt,&templen);/*ignore templen */
1628 len = Pktlib_getPacketLen(tip)-4; /*real length, subtract mac trailer */
1629 Cppi_setData (Cppi_DescType_HOST, (Cppi_Desc *) tip, p_pkt,len);
1630 Pktlib_setPacketLen(tip,len);
1631 //printf("recv_cb() packet len %d\n", len);
1633 //debug: validate descriptor */
1634 if(Pktlib_getNextPacket(tip) != 0)
1635 {
1636 printf(" rcv_cb, nexpkt != NULL");
1637 }
1639 if(coreid<TUNE_NETAPI_NUM_CORES)
1640 stats[coreid].rx+=1;
1641 if (ifno < TUNE_NETAPI_MAX_NUM_MAC)
1642 stats[coreid].if_rx[ifno]+=1;
1645 #ifdef DEBUG_DESC
1646 if (stats[coreid].rx<16)
1647 {
1648 printf(">rx dmp..");
1649 dump_descr((long *) tip, stats[coreid].rx);
1650 }
1651 else if (stats[coreid].rx>99)
1652 {
1653 printf(">rx dmp..");
1654 dump_descr((long *) tip,stats[coreid].rx);
1655 }
1656 #endif
1657 #if 0
1658 if(stats[coreid].rx<=16)
1659 {
1660 dump_header((long*)p_pkt,stats[coreid].rx, (int)meta[i].u.rx_meta->appId,meta[i].u.rx_meta->rxFlag1);
1661 netapi_dump_buf((long*)p_pkt,len);
1662 }
1663 #endif
1664 /* check header */
1665 memcpy(p_head,&p_pkt[14],sizeof(HEAD_T));
1667 /* check for IPSEC ESP or AH packet, 0x32 is ESP tunnel mode, 0x33 is AH tunnel mode*/
1668 if (((p_head->ip[2]&0x0000ff00)==0x00003200) || ((p_head->ip[2]&0x0000ff00)==0x00003300))
1669 {
1670 if (!check_header(p_head,&meta[i]))
1671 {
1672 stats[coreid].n_bad+=1;Pktlib_freePacket(tip);
1673 continue;
1674 }
1676 //process IP SEC PACKET
1677 if (config.ipsec_mode_rx == IPSEC_MODE_RX_SIDEBAND)
1678 {
1680 p_spi = &(p_pkt[netTest_MAC_HEADER_LEN+netTest_IP_HEADER_LEN]);
1681 p_sa_info = (netTestSA_t *) trie_lookup(p_trie_sa, (char *)p_spi ,4);
1682 if (p_sa_info == NULL)
1683 {
1684 printf("recv_cb(): trie_lookup() failed\n");
1685 continue;
1686 }
1688 //ship to crypto for decrypt!!
1689 //12 byte auth tag
1690 PKTIO_METADATA_T meta2 = {PKTIO_META_SB_TX,{0},0};
1691 nwalDmTxPayloadInfo_t meta_tx={0};
1692 meta2.sa_handle=p_sa_info->rx_data_mode_handle;
1694 memcpy(&meta_tx, &(p_sa_info->tx_payload_info), sizeof(nwalDmTxPayloadInfo_t));
1696 //meta_tx.ploadLen = len;
1700 meta_tx.encSize = len - p_sa_info->tx_payload_info.encOffset -p_sa_info->auth_tag_size;
1701 meta_tx.authSize = len - meta_tx.authOffset - p_sa_info->auth_tag_size;
1705 #if 0
1706 printf("recv_cb(): packet length %d\n", len);
1707 printf("recv_cb(): encOffset %d\n", meta_tx.encOffset);
1708 printf("recv_cb():authOffset %d\n", meta_tx.authOffset);
1709 printf("recv_cb(): encSize %d\n", meta_tx.encSize);
1710 printf("recv_cb(): authSize %d\n", meta_tx.authSize);
1711 #endif
1713 if (p_sa_info->cipherMode == NWAL_SA_EALG_AES_CTR)
1714 {
1715 memcpy(&p_iv[0], &ourEncrKey[16], 4);
1716 memcpy(&p_iv[4], &p_pkt[netTest_MAC_HEADER_LEN +netTest_IP_HEADER_LEN + netTest_ESP_HEADER_LEN], 8);
1717 p_iv[12] = 0;
1718 p_iv[13] = 0;
1719 p_iv[14] = 0;
1720 p_iv[15] = 1;
1721 meta_tx.pEncIV = &p_iv[0];
1723 }
1724 else if ((p_sa_info->cipherMode == NWAL_SA_EALG_AES_GCM) ||
1725 (p_sa_info->cipherMode == NWAL_SA_EALG_AES_CCM))
1726 {
1727 memcpy(&p_iv[0], &p_pkt[netTest_MAC_HEADER_LEN +netTest_IP_HEADER_LEN + netTest_ESP_HEADER_LEN], 8);
1728 meta_tx.pEncIV = &p_iv[0];
1729 /* aad is the ESP header which is 8 bytes */
1730 memcpy(&p_add[0], &p_pkt[netTest_MAC_HEADER_LEN +netTest_IP_HEADER_LEN], 8);
1731 meta_tx.pAad= &p_add[0];
1732 meta_tx.aadSize = 8;
1733 }
1734 else if (p_sa_info->cipherMode == NWAL_SA_EALG_NULL)
1735 {
1736 meta_tx.pEncIV = NULL;
1737 }
1738 else
1739 {
1740 meta_tx.pEncIV = &p_pkt[netTest_MAC_HEADER_LEN +netTest_IP_HEADER_LEN + netTest_ESP_HEADER_LEN ];
1741 }
1743 meta_tx.appCtxId = (nwal_AppId)hplib_mUtilGetPmuCCNT();
1744 //printf("recv_cb appCtxId: %lu\n", meta_tx.appCtxId);
1746 /* post it to netcp sb tx channel*/
1747 meta2.u.tx_sb_meta=&meta_tx;
1749 /* TODO: Move the following ifdef code into ptkio_sendDM */
1750 #ifdef NET_TEST_ENABLE_SIDE_BAND_LOW_LEVEL_API
1751 /* Use the command label which was cached during create time
1752 * Update the Queue to receive output packet from SA to the local
1753 * core Queue. Below information can be saved by application in
1754 * per process context to avoid API overhead per packet
1755 * Application can use below rxSbSaQ for polling packets back from
1756 * SA
1757 */
1758 nwalRetVal =
1759 nwal_getLocCxtInfo(PKTIO_GET_NWAL_INSTANCE(netcp_sb_tx_chan),
1760 &nwalLocCxt);
1761 if(nwalRetVal == nwal_OK)
1762 {
1763 p_sa_info->rx_dmPSCmdInfo.rxSbSaQ = nwalLocCxt.rxSbSaQ;
1764 }
1765 nwal_mCmdDMUpdate(tip,
1766 &p_sa_info->rx_dmPSCmdInfo,
1767 meta_tx.appCtxId,
1768 meta_tx.encOffset,
1769 meta_tx.encSize,
1770 meta_tx.pEncIV,
1771 meta_tx.authOffset,
1772 meta_tx.authSize,
1773 meta_tx.pAuthIV,
1774 meta_tx.aadSize,
1775 meta_tx.pAad);
1776 pPloadDesc = Pktlib_getDescFromPacket(tip);
1777 pPloadDesc = Qmss_osalConvertDescVirtToPhy(pPloadDesc);
1778 Qmss_queuePushDescSizeRaw(p_sa_info->rx_dmPSCmdInfo.txQueue,
1779 pPloadDesc,
1780 NWAL_DESC_SIZE);
1782 #else
1783 pktio_send(netcp_sb_tx_chan,tip,&meta2,&err);
1784 #endif
1785 continue;
1786 }
1787 else
1788 {
1789 //inflow mode. flip and send
1790 flip_and_send_pkt(tip,p_pkt,len,1, enet_port);
1791 }
1792 }
1793 else if ((p_head->ip[2]&0x0000ff00)!=0x00001100)
1794 {
1795 stats[coreid].n_new+=1;Pktlib_freePacket(tip); continue;
1796 }
1797 else //non ipsec
1798 {
1799 if (!check_header(p_head,&meta[i]))
1800 {
1801 stats[coreid].n_bad+=1;Pktlib_freePacket(tip);
1802 continue;
1803 }
1805 #if 0
1806 /* lookup flow */
1807 key.src_ip = p_head->ip[3];
1808 key.dst_ip = p_head->ip[4];
1809 key.src_port= (p_head->udp[0]&0xffff0000)>>16;
1810 key.dst_port= (p_head->udp[0]&0x0000ffff);
1811 p_res= (HEAD_T *) trie_lookup(P_trie, (char *) &key, sizeof(key));
1812 if (!p_res) { stats[coreid].n_new+=1; slow_path(tip, len); continue;}
1814 /* copy header */
1815 memcpy((char *) p_head, (char *) p_res, sizeof(HEAD_T));
1817 memcpy(&p_pkt[14],p_head,sizeof(HEAD_T));
1818 /* update_mac(&p_pkt[0]); */
1820 /* 'simulate' send pkt */
1821 send_pkt(tip,len);
1822 #endif
1823 //just flip and send
1824 flip_and_send_pkt(tip,p_pkt,len,0, enet_port);
1825 }
1826 }
1827 //printf("recv done\n");
1828 }
1830 #ifdef TEST_TIMERS
1831 //timer callback
1832 void our_timer_cb( HPLIB_TIMER_GROUP_HANDLE_T th,
1833 int n_fired, //# timers fired
1834 HPLIB_TIMER_LIST_T fired_list,
1835 uint64_t currentTime)
1836 {
1837 int i;
1838 HPLIB_TIMER_T tx;
1839 int cookie;
1840 int err;
1841 unsigned long long et;
1842 #ifdef MULTI_THREAD
1843 int coreid=Osal_nwalGetProcId(); //who we are(thread local)
1844 //int coreid = our_core;
1845 #else
1846 int coreid=0;
1847 #endif
1848 //DEBUGprintf("TIMER CALLBACK @ %lld %d timers\n", currentTime, n_fired);
1849 tx = hplib_Timer_GetFirst(fired_list);
1850 for(i=0;i<n_fired;i++)
1851 {
1852 cookie = (int) hplib_Time_rGetCookie(tx);
1853 et = hplib_Timer_GetTs(tx); //debug
1854 //DEBUGprintf(" timer %d - cookie = %d expected ts=%lld (delta=%lld)\n", i, cookie, et, currentTime-et);
1855 if (cookie ==1)
1856 {
1857 stats[coreid].n_t1+=1;
1858 t1 = hplib_Timer_Start(
1859 th,
1860 (void *) 1,
1861 100LL, //timer group tics
1862 &err);
1863 }
1864 else if (cookie ==2)
1865 {
1866 stats[coreid].n_t2+=1;
1867 t2 = hplib_Timer_Start(
1868 th,
1869 (void *) 2,
1870 200LL, //timer group ticks
1871 &err);
1872 }
1873 else
1874 {
1875 stats[coreid].n_t3+=1;
1876 t3 = hplib_Timer_Start(
1877 th,
1878 (void *) 3,
1879 300LL, //timer group ticks
1880 &err);
1881 //cancel 1 and restart 1
1882 hplib_Timer_Cancel(th,t1,&err);
1883 t1 = hplib_Timer_Start(
1884 th,
1885 (void *) 1,
1886 100LL, //timer group ticks
1887 &err);
1888 }
1889 tx = hplib_Timer_GetNext(fired_list,tx);
1890 }
1891 }
1892 #endif
1893 void print_ipsec_stats(Sa_IpsecStats_t *p_saIpsecStats, nwal_saAALG auth, nwal_saEALG cipher)
1894 {
1895 #if 0
1896 if(retVal != nwal_OK)
1897 {
1898 System_printf("CORE: %d Error getting IP Sec Stats: Ret Status: %d \n",
1899 retVal);
1900 return(nwal_FALSE);
1901 }
1902 if((p_saIpsecStats->pktEncHi) ||(p_saIpsecStats->pktEncLo))
1903 {
1904 printf("------------- IPSec TX (Encryption Channel) Stats BEGIN --\n");
1905 }
1906 else
1907 {
1908 printf("------------- IPSec RX (Decryption Channel) Stats BEGIN --\n");
1909 }
1910 #endif
1911 printf("\nAutentication mode: %d, Encryption Mode: %d\n", auth, cipher);
1912 printf("IPSec replayOld:0x%x,replayDup:0x%x,authFail:0x%x \n",
1913 p_saIpsecStats->replayOld,p_saIpsecStats->replayDup,p_saIpsecStats->authFail);
1914 printf("IPSec txESN:0x%x,rxESN:0x%x,pktEncHi:0x%x,pktEncLo:0x%x,pktDecHi:0x%x,pktDecLo:0x%x \n",
1915 p_saIpsecStats->txESN,p_saIpsecStats->rxESN,p_saIpsecStats->pktEncHi,
1916 p_saIpsecStats->pktEncLo,p_saIpsecStats->pktDecHi,p_saIpsecStats->pktDecLo);
1917 }
1919 void print_datamode_stats(Sa_DataModeStats_t *p_saDataModeStats, nwal_saAALG auth, nwal_saEALG cipher)
1920 {
1922 printf("\nAutentication mode: %d, Encryption Mode: %d\n", auth, cipher);
1923 printf(" Packets processedHi: 0x%x, Packets processed Lo:0x%x\n",
1924 p_saDataModeStats->pktHi, p_saDataModeStats->pktLo);
1925 }
1930 static int np2process = NP;
1931 /******************************************************
1932 * stats callback
1933 *******************************************************/
1934 void our_stats_cb_mt(NETAPI_T h, paSysStats_t* pPaStats)
1935 {
1937 #ifdef MULTI_THREAD
1938 int coreid=Osal_nwalGetProcId(); //who we are(thread local)
1939 //int coreid = our_core;
1940 #else
1941 int coreid=0;
1942 #endif
1944 stats[coreid].n_stats_cb +=1;
1945 if(pPaStats) memcpy(&netcp_stats,pPaStats, sizeof(paSysStats_t));
1946 }
1947 void our_stats_cb(NETAPI_T h, paSysStats_t* pPaStats)
1948 {
1949 uint32_t numFreeDataPackets;
1950 uint32_t numZeroBufferPackets;
1951 uint32_t numPacketsinGarbage;
1952 Pktlib_HeapStats pktLibHeapStats;
1953 int i;
1954 unsigned long long bcpp;
1955 unsigned long long bcpp_noc;
1956 unsigned long long bcpp_app;
1957 unsigned long long bcpp_tx;
1958 unsigned long long npL;
1959 unsigned long long cyclesL;
1960 unsigned long long ccyclesL; //cache cycles
1961 unsigned long long tmp_npL[TUNE_NETAPI_NUM_CORES];
1962 unsigned long long tmp_cyclesL[TUNE_NETAPI_NUM_CORES];
1963 unsigned long long tmp_ccyclesL[TUNE_NETAPI_NUM_CORES]; //cache cycles
1964 NETAPI_SA_STATS_T netapi_sa_stats;
1966 for (i=0;i < TUNE_NETAPI_NUM_CORES;i++)
1967 {
1968 printf("Per Core Statistics for CORE %d\n", i);
1969 printf(">*****stats @ %lld (#cbs%d) \n", hplib_mUtilGetTimestamp(),stats[i].n_stats_cb);
1970 printf(">itx=%d rx=%d tx=%d bad=%d slow=%d \n>rx_class0=%d rx_class1=%d rx_class2=%d secRx=%d secPRX=%d sb_rx=%d sb_tx=%d auth_ok=%d sec_tx=%d min_rx=%d min_tx=%d\n",
1971 stats[i].itx, stats[i].rx, stats[i].tx, stats[i].n_bad, stats[i].n_new,
1972 stats[i].n_class0_rx, stats[i].n_class1_rx,
1973 stats[i].n_class2_rx, stats[i].sec_rx, stats[i].secp_rx, stats[i].sb_rx, stats[i].sb_tx, stats[i].n_auth_ok,
1974 stats[i].sec_tx, stats[i].rx_min, stats[i].tx_min);
1975 printf(">if rx stats: %d %d %d\n",stats[i].if_rx[0],stats[i].if_rx[1],stats[i].if_rx[2]);
1976 printf(">core rx stats: %d \n",stats[i].core_rx);
1978 if (stats[i].rx && stats[i].tx)
1979 printf("decrypt time per packet(avg): %lu, encrypt time per packet(avg): %lu\n",
1980 (unsigned long) stats[i].total_decrypt_time/stats[i].rx, (unsigned long) stats[i].total_encrypt_time/stats[i].tx);
1983 if (npL && stats[i].rx)
1984 {
1985 bcpp = cyclesL/npL;
1986 bcpp_noc = (cyclesL-ccyclesL)/npL;
1987 bcpp_app = (stats[i].app_cycles-stats[i].tx_cache_cycles)/stats[i].rx;
1988 }
1989 else
1990 {
1991 bcpp = bcpp_noc=bcpp_app=0L;
1992 }
1993 if (stats[i].tx)
1994 {
1995 bcpp_tx = (stats[i].send_cycles-stats[i].tx_cache_cycles)/stats[i].tx;
1996 }
1997 else
1998 {
1999 bcpp_tx = 0L;
2000 }
2001 printf("> ++ busy cycles pp=%lld (%lld wo cache ops) (app+tx= %lld) (tx= %lld) ++\n",
2002 bcpp,bcpp_noc,bcpp_app, bcpp_tx);
2003 printf("\n");
2004 }
2006 #ifdef MULTI_THREAD
2007 netapi_sched_get_stats(scheduler[0],&tmp_npL[0],&tmp_cyclesL[0],&tmp_ccyclesL[0]);
2008 netapi_sched_get_stats(scheduler[1],&tmp_npL[1],&tmp_cyclesL[1],&tmp_ccyclesL[1]);
2009 npL = tmp_npL[0]+tmp_npL[1];
2010 cyclesL = tmp_cyclesL[0]+tmp_cyclesL[1];
2011 ccyclesL = tmp_ccyclesL[0]+tmp_ccyclesL[1];
2012 #else
2013 netapi_sched_get_stats(our_sched, &npL,&cyclesL,&ccyclesL);
2014 #endif
2016 if(pPaStats)
2017 {
2018 printf("C1 number of packets: %d\n", pPaStats->classify1.nPackets);
2019 printf("C1 number IPv4 packets: %d\n", pPaStats->classify1.nIpv4Packets);
2020 printf("C1 number IPv6 packets: %d\n", pPaStats->classify1.nIpv6Packets);
2021 printf("C1 number Custom packets: %d\n", pPaStats->classify1.nCustomPackets);
2022 printf("C1 number SRIO packets: %d\n", pPaStats->classify1.nSrioPackets);
2023 printf("C1 number LLC/SNAP Fail packets: %d\n", pPaStats->classify1.nLlcSnapFail);
2024 printf("C1 number table matched: %d\n", pPaStats->classify1.nTableMatch);
2025 printf("C1 number failed table matched: %d\n", pPaStats->classify1.nNoTableMatch);
2026 printf("C1 number IP Fragmented packets: %d\n", pPaStats->classify1.nIpFrag);
2027 printf("C1 number IP Depth Overflow: %d\n", pPaStats->classify1.nIpDepthOverflow);
2028 printf("C1 number VLAN Depth Overflow: %d\n", pPaStats->classify1.nVlanDepthOverflow);
2029 printf("C1 number GRE Depth Overflow: %d\n", pPaStats->classify1.nGreDepthOverflow);
2030 printf("C1 number MPLS Packets: %d\n", pPaStats->classify1.nMplsPackets);
2031 printf ("C1 number of parse fail: %d\n",pPaStats->classify1.nParseFail);
2032 printf("C1 number of Invalid IPv6 Opt: %d\n", pPaStats->classify1.nInvalidIPv6Opt);
2033 printf("C1 number of TX IP Fragments: %d\n", pPaStats->classify1.nTxIpFrag);
2034 printf ("C1 number of silent discard: %d\n",pPaStats->classify1.nSilentDiscard);
2035 printf("C1 number of invalid control: %d\n", pPaStats->classify1.nInvalidControl);
2036 printf ("C1 number of invalid states: %d\n",pPaStats->classify1.nInvalidState);
2037 printf ("C1 number of system fails: %d\n",pPaStats->classify1.nSystemFail);
2038 printf ("C2 number Packets : %d\n",pPaStats->classify2.nPackets);
2039 printf ("C2 number udp : %d\n",pPaStats->classify2.nUdp);
2040 printf ("C2 number tcp : %d\n",pPaStats->classify2.nTcp);
2041 printf ("C2 number Custom : %d\n",pPaStats->classify2.nCustom);
2042 printf ("C2 number silent drop : %d\n",pPaStats->classify2.nSilentDiscard);
2043 printf ("C2 number invalid cntrl : %d\n\n",pPaStats->classify2.nInvalidControl);
2044 printf ("C2 number Modify Stats Cmd Fail : %d\n\n",pPaStats->modify.nCommandFail);
2045 }
2046 Pktlib_getHeapStats(ourHeap, &pktLibHeapStats);
2047 printf("main heap stats> #free=%d #zb=%d #garbage=%d\n", pktLibHeapStats.numFreeDataPackets,
2048 pktLibHeapStats.numZeroBufferPackets, pktLibHeapStats.numPacketsinGarbage);
2049 printf(" > #dataBufThreshStatus=%d #dataBufStarvCounter=%d #zBufThreshStatus=%d #zBufStarvCounter=%d \n",
2050 pktLibHeapStats.dataBufferThresholdStatus,pktLibHeapStats.dataBufferStarvationCounter,
2051 pktLibHeapStats.zeroDataBufferThresholdStatus, pktLibHeapStats.zeroDataBufferStarvationCounter);
2053 Pktlib_getHeapStats(specialSmall, &pktLibHeapStats);
2054 printf("specialSmall heap stats> #free=%d #zb=%d #garbage=%d\n", pktLibHeapStats.numFreeDataPackets,
2055 pktLibHeapStats.numZeroBufferPackets, pktLibHeapStats.numPacketsinGarbage);
2056 printf(" > #dataBufThreshStatus=%d #dataBufStarvCounter=%d #zBufThreshStatus=%d #zBufStarvCounter=%d \n",
2057 pktLibHeapStats.dataBufferThresholdStatus,pktLibHeapStats.dataBufferStarvationCounter,
2058 pktLibHeapStats.zeroDataBufferThresholdStatus, pktLibHeapStats.zeroDataBufferStarvationCounter);
2061 Pktlib_getHeapStats(specialLarge, &pktLibHeapStats);
2062 printf("specialLarge heap stats> #free=%d #zb=%d #garbage=%d\n", pktLibHeapStats.numFreeDataPackets,
2063 pktLibHeapStats.numZeroBufferPackets, pktLibHeapStats.numPacketsinGarbage);
2064 printf(" > #dataBufThreshStatus=%d #dataBufStarvCounter=%d #zBufThreshStatus=%d #zBufStarvCounter=%d \n",
2065 pktLibHeapStats.dataBufferThresholdStatus,pktLibHeapStats.dataBufferStarvationCounter,
2066 pktLibHeapStats.zeroDataBufferThresholdStatus, pktLibHeapStats.zeroDataBufferStarvationCounter);
2069 #if 0
2070 printf("pa2sa descriptor area dump\n");
2071 for(i=0;i<TUNE_NETAPI_CONFIG_MAX_PA_TO_SA_DESC;i++)
2072 {
2073 extern long * pa2sa_descr_base;
2074 long * tip= &pa2sa_descr_base[32*i];
2075 dump_descr(tip, i);
2076 }
2077 printf("sa2pa descriptor area dump\n");
2078 for(i=0;i<TUNE_NETAPI_CONFIG_MAX_SA_TO_PA_DESC;i++)
2079 {
2080 extern long * sa2pa_descr_base;
2081 long * tip= &sa2pa_descr_base[32*i];
2082 dump_descr(tip, i);
2083 }
2084 #endif
2085 #ifdef TEST_TIMERS
2086 //debug = dump timer polling stats
2087 dump_poll_stats();
2088 //debug = dump timer polling stats
2089 //dump_poll_stats();
2090 #endif
2091 #ifndef EXPERIMENTAL
2092 for (i = 0; i < MAX_SEC_INDEX; i++)
2093 #else
2094 for (i=0; i < 1;i++)
2095 #endif
2096 {
2097 /* Statistics for RX Tunnel */
2098 memset(&netapi_sa_stats, 0, sizeof(netapi_sa_stats));
2099 netapi_getSaStats(netapi_handle, sa_info[i].rx_tunnel, &netapi_sa_stats);
2100 if (netapi_sa_stats.validParams & NETAPI_IPSEC_STAT_VALID)
2101 {
2102 print_ipsec_stats(&(netapi_sa_stats.saIpsecStats),
2103 rx_sa[i].authMode,
2104 rx_sa[i].cipherMode);
2105 }
2106 if (netapi_sa_stats.validParams & NETAPI_SIDEBAND_DATA_MODE_STAT_VALID)
2107 {
2108 print_datamode_stats(&(netapi_sa_stats.dataModeStats),
2109 rx_sa[i].authMode,
2110 rx_sa[i].cipherMode);
2111 }
2113 /* Statistics for TX Tunnel */
2114 memset(&netapi_sa_stats, 0, sizeof(netapi_sa_stats));
2115 netapi_getSaStats(netapi_handle, sa_info[i].tx_tunnel, &netapi_sa_stats);
2116 if (netapi_sa_stats.validParams & NETAPI_IPSEC_STAT_VALID)
2117 {
2118 print_ipsec_stats(&(netapi_sa_stats.saIpsecStats),
2119 tx_sa[i].authMode,
2120 tx_sa[i].cipherMode);
2121 }
2122 if (netapi_sa_stats.validParams & NETAPI_SIDEBAND_DATA_MODE_STAT_VALID)
2123 {
2124 print_datamode_stats(&(netapi_sa_stats.dataModeStats),
2125 tx_sa[i].authMode,
2126 tx_sa[i].cipherMode);
2127 }
2128 }
2129 netapi_dump_internal_heap_stats();
2130 }
2132 //******************************************************
2133 //use scheduling housekeeping callback to generate pkts
2134 //******************************************************
2135 static int done_burst=0;
2136 void house(NETAPI_SCHED_HANDLE_T * s)
2137 {
2138 Ti_Pkt * tip;
2139 unsigned int len;
2140 nwalTxPktInfo_t meta_tx = {0};
2141 PKTIO_METADATA_T meta = {PKTIO_META_TX,{0},0};
2142 int err;
2143 static int house_pkts_gened=0;
2144 int p;
2145 unsigned char * pIpHdr,* pData;
2146 unsigned int vv1,vv2,vv3;
2147 unsigned int sum_vv1=0;
2148 unsigned int sum_vv2=0;
2149 unsigned int sum_vv3=0;
2150 unsigned int sum_vv4=0;
2151 unsigned int sum_vv5=0;
2153 unsigned int nwal_flow_vv1,nwal_flow_vv2;
2154 unsigned int nwal_sum_vv1=0;
2155 unsigned int nwal_sum_vv2=0;
2156 unsigned int nwal_sum_vv3=0;
2157 unsigned int nwal_sum_vv4=0;
2158 unsigned int nwal_sum_vv5=0;
2159 unsigned int nwal_sum_vv6=0;
2161 unsigned int nwal_sum_flow_vv1=0;
2162 unsigned int nwal_sum_flow_vv2=0;
2163 unsigned long long cache_op_b1;
2164 unsigned long long cache_op_b2;
2165 unsigned long long n_c_ops;
2166 static int first =0;
2167 Cppi_HostDesc* pPktDesc;
2169 int coreid = 0; //who we are
2170 #ifdef MULTI_THREAD
2171 NETAPI_T nh= netapi_schedGetNetapiHandle(s);
2172 coreid=(int) netapi_getCookie(nh);
2174 if (QUIT) {netapi_schedShutdown(s,NULL,&err); return;}
2176 if (coreid==0) //slave
2177 {
2178 netcp_cfgReqStats(nh, our_stats_cb_mt, 0,&err);
2179 }
2180 #else
2181 if(done_burst)
2182 {
2183 house_pkts_gened+=TX_BURST;
2184 printf("net_test> request stats at n=%d \n",house_pkts_gened);
2185 netcp_cfgReqStats(netapi_handle, our_stats_cb, 0,&err);
2186 if (err!=0) {printf("stats req failed\n");}
2187 if (house_pkts_gened >= np2process+ 100)
2188 {
2189 netapi_schedShutdown(s,NULL,&err);
2190 }
2191 return;
2192 }
2193 done_burst=1;
2194 Osal_cache_op_measure_reset();
2195 memset(&meta_tx,0,sizeof(meta_tx));
2196 for(p=0;p<TX_BURST;p++) {
2197 //reguest stats
2198 if ((house_pkts_gened>0) && (! (house_pkts_gened%1000)) )
2199 {
2200 printf("net_test> request stats at n=%d \n",house_pkts_gened);
2201 netcp_cfgReqStats(netapi_handle, our_stats_cb, 0,&err);
2202 if (err!=0) {printf("stats req failed\n");}
2203 }
2206 if (house_pkts_gened >= np2process+ 100)
2207 {
2208 //shutdown
2209 netapi_schedShutdown(s,NULL,&err);
2210 continue;
2211 }
2213 else if (house_pkts_gened >= np2process) { house_pkts_gened+=1; continue;}
2216 /* manufacture a pkt to transmit */
2217 tip = get_pkt(house_pkts_gened, &len, ourHeap, PKT_LEN,&testPkt[0] , TEST_PKT_LEN);
2218 if(!tip) { house_pkts_gened +=1; continue; }
2221 /* set the pkt length */
2222 vv1 = hplib_mUtilGetPmuCCNT();
2223 Pktlib_setPacketLen(tip, len);
2225 /* set up meta data */
2226 meta.sa_handle=nwal_HANDLE_INVALID;
2227 /* #define BENCH_UDP_SEND */
2228 #ifdef BEND_UDP_SEND
2229 meta_tx.txFlag1 = (NWAL_TX_FLAG1_DO_IPV4_CHKSUM | NWAL_TX_FLAG1_DO_UDP_CHKSUM| NWAL_TX_FLAG1_META_DATA_VALID);
2230 meta_tx.startOffset = 0;
2231 /* GONE in V2 meta_tx.pktLen = len; */
2232 meta_tx.ipOffBytes = TEST_PKT_IP_OFFSET_BYTES;
2233 meta_tx.l4OffBytes = TEST_PKT_UDP_OFFSET_BYTES;
2234 meta_tx.l4HdrLen = TEST_PKT_UDP_HDR_LEN;
2235 //GONE in V2 meta_tx.ploadOffBytes = TEST_PKT_PLOAD_OFFSET_BYTES;
2236 meta_tx.ploadLen = TEST_PAYLOAD_LEN;
2238 Pktlib_getDataBuffer(tip,&pData,&len);
2239 if(house_pkts_gened &0x1)
2240 {
2241 memcpy(&pData[6],&config.mac1[0] ,6);
2242 }
2243 pIpHdr = pData + meta_tx.ipOffBytes;
2244 meta_tx.pseudoHdrChecksum =
2245 test_utilGetIpv4PsudoChkSum(pIpHdr,(TEST_PAYLOAD_LEN+TEST_PKT_UDP_HDR_LEN));
2246 #else
2247 Pktlib_getDataBuffer(tip,&pData,&len);
2248 if(house_pkts_gened &0x1)
2249 {
2250 memcpy(&pData[6],&config.mac1[0] ,6);
2251 }
2252 meta_tx.txFlag1 = NWAL_TX_FLAG1_META_DATA_VALID;
2253 meta_tx.startOffset = 0;
2254 meta_tx.ploadLen = TEST_PAYLOAD_LEN;
2255 #endif
2256 /* post it to netcp tx channel*/
2257 meta.u.tx_meta=&meta_tx;
2258 #ifdef DEBUG_DESC
2259 if (house_pkts_gened<16) dump_descr((long *) tip, house_pkts_gened);
2260 else if (house_pkts_gened>99) dump_descr((long *) tip,house_pkts_gened);
2261 #endif
2263 if(!first)
2264 {
2265 first++;
2266 nwal_flow_vv1= hplib_mUtilGetPmuCCNT();
2267 if(nwal_initPSCmdInfo(PKTIO_GET_NWAL_INSTANCE(netcp_tx_chan),
2268 &meta_tx,
2269 &flowPSCmdInfo) != nwal_OK)
2270 {
2271 printf("nwal_initPSCmdInfo() ERROR \n");
2272 }
2273 nwal_flow_vv2= hplib_mUtilGetPmuCCNT();
2274 nwal_sum_flow_vv1 += (nwal_flow_vv1-vv1);
2275 nwal_sum_flow_vv2 += (nwal_flow_vv2-nwal_flow_vv1);
2276 }
2278 cache_op_b1= Osal_cache_op_measure(&n_c_ops);
2279 vv2= hplib_mUtilGetPmuCCNT();
2280 #ifdef BEND_UDP_SEND
2281 nwal_mCmdSetL4CkSumPort( tip,
2282 &flowPSCmdInfo,
2283 TEST_PKT_UDP_OFFSET_BYTES,
2284 (TEST_PKT_UDP_HDR_LEN + TEST_PAYLOAD_LEN),
2285 meta_tx.pseudoHdrChecksum,
2286 meta_tx.enetPort);
2287 #else
2288 nwal_mCmdSetPort (tip,
2289 &flowPSCmdInfo, //could be NULL
2290 0); //port 0 -> switch decides
2292 #endif
2294 pPktDesc = Pktlib_getDescFromPacket(tip);
2295 /* Send the packet out to transmit Q*/
2296 Qmss_queuePushDescSize (flowPSCmdInfo.txQueue,
2297 pPktDesc,
2298 NWAL_DESC_SIZE);
2299 vv3= hplib_mUtilGetPmuCCNT();
2300 cache_op_b2= Osal_cache_op_measure(&n_c_ops);
2302 sum_vv1 += (vv2-vv1);
2303 if(!house_pkts_gened)
2304 {
2305 /* first packet. Take out the PS command label creation cost */
2306 sum_vv1 = sum_vv1 - nwal_sum_flow_vv2;
2307 }
2309 sum_vv3 += (vv3-vv2)-(long) (cache_op_b2-cache_op_b1); //sub out cache op cost
2311 // printf("pktio send. full=%d metadata=%d pktio_send=%d\n", vv3-vv1, vv2-vv1, vv3-vv2);
2314 stats[coreid].itx +=1;
2315 house_pkts_gened +=1;
2316 }
2317 {
2318 unsigned long long ccycles;
2319 ccycles =Osal_cache_op_measure(&n_c_ops);
2320 if (sum_vv1)
2321 {
2322 printf("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",
2323 stats[coreid].itx, sum_vv1/stats[coreid].itx, nwal_sum_flow_vv2, sum_vv3/stats[coreid].itx,
2324 n_c_ops, ccycles, n_c_ops? (ccycles/(n_c_ops/2L)) : 0);
2325 #if 0
2326 printf("NWAL Profile Cycles: Prof1= %d,Prof2=%d,Prof3=%d,Prof4=%d,Prof5=%d ,Prof6=%d \n",
2327 nwal_sum_vv1/stats[coreid].itx,nwal_sum_vv2/stats[coreid].itx,nwal_sum_vv3/stats[coreid].itx,
2328 nwal_sum_vv4/stats[coreid].itx,nwal_sum_vv5/stats[coreid].itx,nwal_sum_vv6/stats[coreid].itx);
2330 #endif
2332 if(stats[core_id].itx2)
2333 {
2334 printf("nwal_flowSend Profile Cycles: Prof1= %d,Prof2=%d \n",
2335 nwal_sum_flow_vv1/stats[coreid].itx2,nwal_sum_flow_vv2/stats[coreid].itx2);
2336 }
2338 }
2339 }
2340 #endif
2341 }
2343 void build_sa_db(int i)
2344 {
2345 long tmp_spi;
2346 if ((tx_sa[i].authMode == NWAL_SA_AALG_HMAC_SHA1) && (tx_sa[i].cipherMode == NWAL_SA_EALG_AES_CBC))
2347 {
2348 /* static configuration, will not change */
2349 sa_info[i].tx_payload_info.aadSize = 0;
2350 sa_info[i].tx_payload_info.pAad = NULL;
2351 sa_info[i].tx_payload_info.pAuthIV = NULL;
2352 sa_info[i].tx_payload_info.authOffset = netTest_MAC_HEADER_LEN + netTest_IP_HEADER_LEN; /*done: same for all cipher suites */
2353 sa_info[i].tx_payload_info.encOffset = netTest_MAC_HEADER_LEN +
2354 netTest_IP_HEADER_LEN +
2355 netTest_ESP_HEADER_LEN +
2356 netTest_AES_CBC_IV_LEN;
2358 /* dynamic configuration, will be calculated on the fly */
2359 sa_info[i].tx_payload_info.authSize = 0; /* pkt len - mac - ip -icv (12) */
2360 sa_info[i].tx_payload_info.encSize = 0; /* authSize - esp header size (always 8 bytes) */
2361 sa_info[i].tx_payload_info.pEncIV = 0;
2362 sa_info[i].tx_payload_info.pPkt = 0; /* not being referenced in net_test */
2364 sa_info[i].cipherMode = NWAL_SA_EALG_AES_CBC;
2365 sa_info[i].inner_ip_offset = sa_info[i].tx_payload_info.encOffset;
2366 sa_info[i].auth_tag_size = netTest_ICV_LEN; /* icv or mac size,. always 12 except for AES_CCM/AES_GCM */
2367 #ifdef EXPERIMENTAL
2368 sa_info[i].iv_len=16;
2369 sa_info[i].bl=16;
2370 sa_info[i].spi = tx_sa[i].spi;
2371 sa_info[i].src =*((unsigned int *)(&config.local_ipsec_ip.ipv4[0]));
2372 sa_info[i].dst =*((unsigned int *)(&config.remote_ipsec_ip.ipv4[0]));
2373 #endif
2374 sa_info[i].tx_pkt_info.enetPort = 0;
2375 sa_info[i].tx_pkt_info.ipOffBytes = sa_info[i].tx_payload_info.encOffset;
2376 sa_info[i].tx_pkt_info.l4HdrLen = netTest_UDP_HEADER_LEN; /*UDP header len */
2377 sa_info[i].tx_pkt_info.l4OffBytes = sa_info[i].inner_ip_offset + netTest_IP_HEADER_LEN;
2378 sa_info[i].tx_pkt_info.startOffset = 0;
2379 sa_info[i].tx_pkt_info.lpbackPass = 0;
2380 sa_info[i].tx_pkt_info.ploadLen = 0; /*sa_info[i].tx_pkt_info.l4OffBytes + 4 */
2381 sa_info[i].tx_pkt_info.pPkt = NULL;
2382 sa_info[i].tx_pkt_info.saOffBytes = netTest_MAC_HEADER_LEN + netTest_IP_HEADER_LEN;
2383 sa_info[i].tx_pkt_info.saPayloadLen = 0;
2384 sa_info[i].tx_pkt_info.pseudoHdrChecksum =0;
2386 sa_info[i].tx_pkt_info.txFlag1 = NWAL_TX_FLAG1_DO_IPSEC_ESP_CRYPTO| NWAL_TX_FLAG1_DO_UDP_CHKSUM| NWAL_TX_FLAG1_META_DATA_VALID ;
2388 tmp_spi = htonl((long)(tx_sa[i].spi));
2389 trie_insert(p_trie_sa,(char *)&tmp_spi,4, (void *) &sa_info[i]); //asociate with tx sa SPI
2392 }
2393 else if ((tx_sa[i].authMode == NWAL_SA_AALG_HMAC_SHA2_256) && (tx_sa[i].cipherMode == NWAL_SA_EALG_AES_CTR))
2394 {
2395 /* static configuration, will not change */
2396 sa_info[i].tx_payload_info.aadSize = 0;
2397 sa_info[i].tx_payload_info.pAad = NULL;
2398 sa_info[i].tx_payload_info.pAuthIV = NULL;
2399 sa_info[i].tx_payload_info.authOffset = netTest_MAC_HEADER_LEN + netTest_IP_HEADER_LEN; /*done: same for all cipher suites */
2400 sa_info[i].tx_payload_info.encOffset = netTest_MAC_HEADER_LEN +
2401 netTest_IP_HEADER_LEN +
2402 netTest_ESP_HEADER_LEN +
2403 netTest_AES_CTR_IV_LEN;
2408 /* dynamic configuration, will be calculated on the fly */
2409 sa_info[i].tx_payload_info.authSize = 0;
2410 sa_info[i].tx_payload_info.encSize = 0;
2411 sa_info[i].tx_payload_info.pEncIV = 0;
2412 sa_info[i].tx_payload_info.pPkt = 0;
2414 sa_info[i].cipherMode = NWAL_SA_EALG_AES_CTR;
2415 sa_info[i].inner_ip_offset = sa_info[i].tx_payload_info.encOffset;
2416 sa_info[i].auth_tag_size = netTest_ICV_LEN; /* icv or mac size,. always 12 except for AES_CCM/AES_GCM */
2417 #ifdef EXPERIMENTAL
2418 sa_info[i].iv_len=8;
2419 sa_info[i].bl=8;
2420 sa_info[i].spi = tx_sa[i].spi;
2421 sa_info[i].src =*((unsigned int *)(&config.local_ipsec_ip.ipv4[0]));
2422 sa_info[i].dst =*((unsigned int *)(&config.remote_ipsec_ip.ipv4[0]));
2423 #endif
2425 sa_info[i].tx_pkt_info.enetPort = 0;
2426 sa_info[i].tx_pkt_info.ipOffBytes = sa_info[i].tx_payload_info.encOffset;
2427 sa_info[i].tx_pkt_info.l4HdrLen = netTest_UDP_HEADER_LEN; /*UDP header len */
2428 sa_info[i].tx_pkt_info.l4OffBytes = sa_info[i].inner_ip_offset + netTest_IP_HEADER_LEN;
2429 sa_info[i].tx_pkt_info.startOffset = 0;
2430 sa_info[i].tx_pkt_info.lpbackPass = 0;
2431 sa_info[i].tx_pkt_info.ploadLen = 0; /*sa_info[i].tx_pkt_info.l4OffBytes + 4 */
2432 sa_info[i].tx_pkt_info.pPkt = NULL;
2433 sa_info[i].tx_pkt_info.saOffBytes = netTest_MAC_HEADER_LEN + netTest_IP_HEADER_LEN;
2434 sa_info[i].tx_pkt_info.saPayloadLen = 0;
2435 sa_info[i].tx_pkt_info.pseudoHdrChecksum =0;
2437 sa_info[i].tx_pkt_info.txFlag1 = NWAL_TX_FLAG1_DO_IPSEC_ESP_CRYPTO| NWAL_TX_FLAG1_DO_UDP_CHKSUM| NWAL_TX_FLAG1_META_DATA_VALID ;
2438 tmp_spi = htonl((long)(tx_sa[i].spi));
2439 trie_insert(p_trie_sa,(char *)&tmp_spi,4, (void *) &sa_info[i]); //asociate with tx sa SPI
2440 }
2441 else if ((tx_sa[i].authMode == NWAL_SA_AALG_HMAC_SHA2_256) && (tx_sa[i].cipherMode == NWAL_SA_EALG_3DES_CBC))
2442 {
2443 /* static configuration, will not change */
2444 sa_info[i].tx_payload_info.aadSize = 0;
2445 sa_info[i].tx_payload_info.pAad = NULL;
2446 sa_info[i].tx_payload_info.pAuthIV = NULL;
2447 sa_info[i].tx_payload_info.authOffset = netTest_MAC_HEADER_LEN + netTest_IP_HEADER_LEN; /*done: same for all cipher suites */
2448 sa_info[i].tx_payload_info.encOffset = netTest_MAC_HEADER_LEN +
2449 netTest_IP_HEADER_LEN +
2450 netTest_ESP_HEADER_LEN +
2451 netTest_3DES_CBC_IV_LEN;
2453 /* dynamic configuration, will be calculated on the fly */
2454 sa_info[i].tx_payload_info.authSize = 0;
2455 sa_info[i].tx_payload_info.encSize = 0;
2456 sa_info[i].tx_payload_info.pEncIV = 0;
2457 sa_info[i].tx_payload_info.pPkt = 0;
2459 sa_info[i].cipherMode = NWAL_SA_EALG_3DES_CBC;
2460 sa_info[i].inner_ip_offset = sa_info[i].tx_payload_info.encOffset;
2461 sa_info[i].auth_tag_size = netTest_ICV_LEN; /* icv or mac size,. always 12 except for AES_CCM/AES_GCM */
2462 #ifdef EXPERIMENTAL
2463 sa_info[i].iv_len=8;
2464 sa_info[i].bl=8;
2465 sa_info[i].spi = tx_sa[i].spi;
2466 sa_info[i].src =*((unsigned int *)(&config.local_ipsec_ip.ipv4[0]));
2467 sa_info[i].dst =*((unsigned int *)(&config.remote_ipsec_ip.ipv4[0]));
2468 #endif
2470 sa_info[i].tx_pkt_info.enetPort = 0;
2471 sa_info[i].tx_pkt_info.ipOffBytes = sa_info[i].tx_payload_info.encOffset;
2472 sa_info[i].tx_pkt_info.l4HdrLen = netTest_UDP_HEADER_LEN; /*UDP header len */
2473 sa_info[i].tx_pkt_info.l4OffBytes = sa_info[i].inner_ip_offset + netTest_IP_HEADER_LEN;
2474 sa_info[i].tx_pkt_info.startOffset = 0;
2475 sa_info[i].tx_pkt_info.lpbackPass = 0;
2476 sa_info[i].tx_pkt_info.ploadLen = 0; /*sa_info[i].tx_pkt_info.l4OffBytes + 4 */
2477 sa_info[i].tx_pkt_info.pPkt = NULL;
2478 sa_info[i].tx_pkt_info.saOffBytes = netTest_MAC_HEADER_LEN + netTest_IP_HEADER_LEN;
2479 sa_info[i].tx_pkt_info.saPayloadLen = 0;
2480 sa_info[i].tx_pkt_info.pseudoHdrChecksum =0;
2482 sa_info[i].tx_pkt_info.txFlag1 = NWAL_TX_FLAG1_DO_IPSEC_ESP_CRYPTO| NWAL_TX_FLAG1_DO_UDP_CHKSUM| NWAL_TX_FLAG1_META_DATA_VALID ;
2484 tmp_spi = htonl((long)(tx_sa[i].spi));
2485 trie_insert(p_trie_sa,(char *)&tmp_spi,4, (void *) &sa_info[i]); //asociate with tx sa SPI
2486 }
2487 else if ((tx_sa[i].authMode == NWAL_SA_AALG_HMAC_MD5) && (rx_sa[i].cipherMode == NWAL_SA_EALG_NULL))
2488 {
2489 /* static configuration, will not change */
2490 sa_info[i].tx_payload_info.aadSize = 0;
2491 sa_info[i].tx_payload_info.pAad = NULL;
2492 sa_info[i].tx_payload_info.pAuthIV = NULL;
2493 //sa_info[i].tx_payload_info.authOffset = netTest_MAC_HEADER_LEN + netTest_IP_HEADER_LEN + 24; /*done: same for all cipher suites */
2494 sa_info[i].tx_payload_info.authOffset = netTest_MAC_HEADER_LEN;
2496 sa_info[i].tx_payload_info.encOffset = netTest_MAC_HEADER_LEN +
2497 netTest_IP_HEADER_LEN +
2498 netTest_NULL_ESP_HEADER_LEN +
2499 netTest_NULL_IV_LEN +
2500 24;
2503 #ifdef EXPERIMENTAL
2504 sa_info[i].iv_len=0;
2505 sa_info[i].bl=4;
2506 sa_info[i].spi = tx_sa[i].spi;
2507 sa_info[i].src =*((unsigned int *)(&config.local_ipsec_ip.ipv4[0]));
2508 sa_info[i].dst =*((unsigned int *)(&config.remote_ipsec_ip.ipv4[0]));
2509 #endif
2512 /* dynamic configuration, will be calculated on the fly */
2513 sa_info[i].tx_payload_info.authSize = 0;
2514 sa_info[i].tx_payload_info.encSize = 0;
2515 sa_info[i].tx_payload_info.pEncIV = 0;
2516 sa_info[i].tx_payload_info.pPkt = 0;
2518 sa_info[i].cipherMode = NWAL_SA_EALG_NULL;
2519 sa_info[i].inner_ip_offset = sa_info[i].tx_payload_info.encOffset;
2520 sa_info[i].auth_tag_size = netTest_ICV_LEN; /* icv or mac size,. always 12 except for AES_CCM/AES_GCM */
2522 sa_info[i].tx_pkt_info.enetPort = 0;
2523 sa_info[i].tx_pkt_info.ipOffBytes = sa_info[i].tx_payload_info.encOffset;
2524 sa_info[i].tx_pkt_info.l4HdrLen = netTest_UDP_HEADER_LEN; /*UDP header len */
2525 sa_info[i].tx_pkt_info.l4OffBytes = sa_info[i].inner_ip_offset + netTest_IP_HEADER_LEN;
2526 sa_info[i].tx_pkt_info.startOffset = 0;
2527 sa_info[i].tx_pkt_info.lpbackPass = 0;
2528 sa_info[i].tx_pkt_info.ploadLen = 0; /*sa_info[i].tx_pkt_info.l4OffBytes + 4 */
2529 sa_info[i].tx_pkt_info.pPkt = NULL;
2530 sa_info[i].tx_pkt_info.saOffBytes = netTest_MAC_HEADER_LEN;
2531 sa_info[i].tx_pkt_info.saPayloadLen = 0;
2532 sa_info[i].tx_pkt_info.pseudoHdrChecksum =0;
2533 sa_info[i].tx_pkt_info.txFlag1 = NWAL_TX_FLAG1_DO_IPSEC_AH_CRYPTO| NWAL_TX_FLAG1_DO_UDP_CHKSUM | NWAL_TX_FLAG1_META_DATA_VALID ;
2534 tmp_spi = htonl((long)(tx_sa[i].spi));
2535 trie_insert(p_trie_sa,(char *)&tmp_spi,4, (void *) &sa_info[i]); //asociate with tx sa SPI
2536 }
2537 else if ((tx_sa[i].authMode == NWAL_SA_AALG_NULL) && (rx_sa[i].cipherMode == NWAL_SA_EALG_AES_GCM))
2538 {
2539 /* static configuration, will not change */
2540 sa_info[i].tx_payload_info.aadSize = 0;
2541 sa_info[i].tx_payload_info.pAad = NULL;
2542 sa_info[i].tx_payload_info.pAuthIV = NULL;
2543 sa_info[i].tx_payload_info.authOffset = netTest_MAC_HEADER_LEN + netTest_IP_HEADER_LEN; /*done: same for all cipher suites */
2544 //sa_info[i].tx_payload_info.encIvSize = netTest_AES_GCM_IV_LEN;
2546 sa_info[i].tx_payload_info.encOffset = netTest_MAC_HEADER_LEN +
2547 netTest_IP_HEADER_LEN +
2548 netTest_ESP_HEADER_LEN +
2549 netTest_AES_GCM_IV_LEN;
2550 #ifdef EXPERIMENTAL
2551 sa_info[i].iv_len=0;
2552 sa_info[i].bl=4;
2553 sa_info[i].spi = tx_sa[i].spi;
2554 sa_info[i].src =*((unsigned int *)(&config.local_ipsec_ip.ipv4[0]));
2555 sa_info[i].dst =*((unsigned int *)(&config.remote_ipsec_ip.ipv4[0]));
2556 #endif
2559 /* dynamic configuration, will be calculated on the fly */
2560 sa_info[i].tx_payload_info.authSize = 0;
2561 sa_info[i].tx_payload_info.encSize = 0;
2562 //sa_info[i].tx_payload_info.ploadLen = 0;
2563 sa_info[i].tx_payload_info.pEncIV = 0;
2564 sa_info[i].tx_payload_info.pPkt = 0;
2566 sa_info[i].cipherMode = NWAL_SA_EALG_AES_GCM;
2567 sa_info[i].inner_ip_offset = sa_info[i].tx_payload_info.encOffset;
2568 sa_info[i].auth_tag_size = netTest_AES_GCM_CCM_ICV_LEN; /* icv or mac size,. always 12 except for AES_CCM/AES_GCM */
2570 sa_info[i].tx_pkt_info.enetPort = 0;
2571 sa_info[i].tx_pkt_info.ipOffBytes = sa_info[i].tx_payload_info.encOffset;
2572 sa_info[i].tx_pkt_info.l4HdrLen = netTest_UDP_HEADER_LEN; /*UDP header len */
2573 sa_info[i].tx_pkt_info.l4OffBytes = sa_info[i].inner_ip_offset + netTest_IP_HEADER_LEN;
2574 sa_info[i].tx_pkt_info.startOffset = 0;
2575 sa_info[i].tx_pkt_info.lpbackPass = 0;
2576 sa_info[i].tx_pkt_info.ploadLen = 0; /*sa_info[i].tx_pkt_info.l4OffBytes + 4 */
2577 sa_info[i].tx_pkt_info.pPkt = NULL;
2578 sa_info[i].tx_pkt_info.saOffBytes = netTest_MAC_HEADER_LEN + netTest_IP_HEADER_LEN;
2579 sa_info[i].tx_pkt_info.saPayloadLen = 0;
2580 sa_info[i].tx_pkt_info.pseudoHdrChecksum =0;
2582 sa_info[i].tx_pkt_info.txFlag1 = NWAL_TX_FLAG1_DO_IPSEC_ESP_CRYPTO| NWAL_TX_FLAG1_DO_UDP_CHKSUM| NWAL_TX_FLAG1_META_DATA_VALID ;
2584 tmp_spi = htonl((long)(tx_sa[i].spi));
2585 trie_insert(p_trie_sa,(char *)&tmp_spi,4, (void *) &sa_info[i]); //asociate with tx sa SPI
2586 }
2587 else if ((tx_sa[i].authMode == NWAL_SA_AALG_NULL) && (rx_sa[i].cipherMode == NWAL_SA_EALG_AES_CCM))
2588 {
2589 /* static configuration, will not change */
2590 sa_info[i].tx_payload_info.aadSize = 0;
2591 sa_info[i].tx_payload_info.pAad = NULL;
2592 //sa_info[i].tx_payload_info.authIvSize = 0;
2593 sa_info[i].tx_payload_info.pAuthIV = NULL;
2594 sa_info[i].tx_payload_info.authOffset = netTest_MAC_HEADER_LEN + netTest_IP_HEADER_LEN; /*done: same for all cipher suites */
2596 sa_info[i].tx_payload_info.encOffset = netTest_MAC_HEADER_LEN +
2597 netTest_IP_HEADER_LEN +
2598 netTest_ESP_HEADER_LEN +
2599 netTest_AES_CCM_IV_LEN;
2600 #ifdef EXPERIMENTAL
2601 sa_info[i].iv_len=0;
2602 sa_info[i].bl=4;
2603 sa_info[i].spi = tx_sa[i].spi;
2604 sa_info[i].src =*((unsigned int *)(&config.local_ipsec_ip.ipv4[0]));
2605 sa_info[i].dst =*((unsigned int *)(&config.remote_ipsec_ip.ipv4[0]));
2606 #endif
2609 /* dynamic configuration, will be calculated on the fly */
2610 sa_info[i].tx_payload_info.authSize = 0;
2611 sa_info[i].tx_payload_info.encSize = 0;
2612 //sa_info[i].tx_payload_info.ploadLen = 0;
2613 sa_info[i].tx_payload_info.pEncIV = 0;
2614 sa_info[i].tx_payload_info.pPkt = 0;
2616 sa_info[i].cipherMode = NWAL_SA_EALG_AES_CCM;
2617 sa_info[i].inner_ip_offset = sa_info[i].tx_payload_info.encOffset;
2618 sa_info[i].auth_tag_size = netTest_AES_GCM_CCM_ICV_LEN; /* icv or mac size,. always 12 except for AES_CCM/AES_GCM */
2620 sa_info[i].tx_pkt_info.enetPort = 0;
2621 sa_info[i].tx_pkt_info.ipOffBytes = sa_info[i].tx_payload_info.encOffset;
2622 sa_info[i].tx_pkt_info.l4HdrLen = netTest_UDP_HEADER_LEN; /*UDP header len */
2623 sa_info[i].tx_pkt_info.l4OffBytes = sa_info[i].inner_ip_offset + netTest_IP_HEADER_LEN;
2624 sa_info[i].tx_pkt_info.startOffset = 0;
2625 sa_info[i].tx_pkt_info.lpbackPass = 0;
2626 sa_info[i].tx_pkt_info.ploadLen = 0; /*sa_info[i].tx_pkt_info.l4OffBytes + 4 */
2627 sa_info[i].tx_pkt_info.pPkt = NULL;
2628 sa_info[i].tx_pkt_info.saOffBytes = netTest_MAC_HEADER_LEN + netTest_IP_HEADER_LEN;
2629 sa_info[i].tx_pkt_info.saPayloadLen = 0;
2630 sa_info[i].tx_pkt_info.pseudoHdrChecksum =0;
2632 sa_info[i].tx_pkt_info.txFlag1 = NWAL_TX_FLAG1_DO_IPSEC_ESP_CRYPTO| NWAL_TX_FLAG1_DO_UDP_CHKSUM| NWAL_TX_FLAG1_META_DATA_VALID ;
2634 tmp_spi = htonl((long)(tx_sa[i].spi));
2635 trie_insert(p_trie_sa,(char *)&tmp_spi,4, (void *) &sa_info[i]); //asociate with tx sa SPI
2636 }
2637 else if ((tx_sa[i].authMode == NWAL_SA_AALG_AES_XCBC) && (rx_sa[i].cipherMode == NWAL_SA_EALG_NULL))
2638 {
2639 /* static configuration, will not change */
2640 sa_info[i].tx_payload_info.aadSize = 0;
2641 sa_info[i].tx_payload_info.pAad = NULL;
2642 sa_info[i].tx_payload_info.pAuthIV = NULL;
2643 sa_info[i].tx_payload_info.authOffset = netTest_MAC_HEADER_LEN + netTest_IP_HEADER_LEN;
2646 sa_info[i].tx_payload_info.encOffset = netTest_MAC_HEADER_LEN +
2647 netTest_IP_HEADER_LEN +
2648 netTest_ESP_HEADER_LEN +
2649 netTest_NULL_IV_LEN;
2650 #ifdef EXPERIMENTAL
2651 sa_info[i].iv_len=0;
2652 sa_info[i].bl=4;
2653 sa_info[i].spi = tx_sa[i].spi;
2654 sa_info[i].src =*((unsigned int *)(&config.local_ipsec_ip.ipv4[0]));
2655 sa_info[i].dst =*((unsigned int *)(&config.remote_ipsec_ip.ipv4[0]));
2656 #endif
2659 /* dynamic configuration, will be calculated on the fly */
2660 sa_info[i].tx_payload_info.authSize = 0;
2661 sa_info[i].tx_payload_info.encSize = 0;
2662 //sa_info[i].tx_payload_info.ploadLen = 0;
2663 sa_info[i].tx_payload_info.pEncIV = 0;
2664 sa_info[i].tx_payload_info.pPkt = 0;
2666 sa_info[i].cipherMode = NWAL_SA_EALG_NULL;
2667 sa_info[i].authMode = NWAL_SA_AALG_AES_XCBC;
2668 sa_info[i].inner_ip_offset = sa_info[i].tx_payload_info.encOffset;
2669 sa_info[i].auth_tag_size = netTest_ICV_LEN; /* icv or mac size,. always 12 except for AES_CCM/AES_GCM , GMAC*/
2671 sa_info[i].tx_pkt_info.enetPort = 0;
2672 sa_info[i].tx_pkt_info.ipOffBytes = sa_info[i].tx_payload_info.encOffset;
2673 sa_info[i].tx_pkt_info.l4HdrLen = netTest_UDP_HEADER_LEN; /*UDP header len */
2674 sa_info[i].tx_pkt_info.l4OffBytes = sa_info[i].inner_ip_offset + netTest_IP_HEADER_LEN;
2675 sa_info[i].tx_pkt_info.startOffset = 0;
2676 sa_info[i].tx_pkt_info.lpbackPass = 0;
2677 sa_info[i].tx_pkt_info.ploadLen = 0; /*sa_info[i].tx_pkt_info.l4OffBytes + 4 */
2678 sa_info[i].tx_pkt_info.pPkt = NULL;
2679 sa_info[i].tx_pkt_info.saOffBytes = netTest_MAC_HEADER_LEN + netTest_IP_HEADER_LEN;
2680 sa_info[i].tx_pkt_info.saPayloadLen = 0;
2681 sa_info[i].tx_pkt_info.pseudoHdrChecksum =0;
2683 sa_info[i].tx_pkt_info.txFlag1 = NWAL_TX_FLAG1_DO_IPSEC_ESP_CRYPTO| NWAL_TX_FLAG1_DO_UDP_CHKSUM| NWAL_TX_FLAG1_META_DATA_VALID ;
2685 tmp_spi = htonl((long)(tx_sa[i].spi));
2686 trie_insert(p_trie_sa,(char *)&tmp_spi,4, (void *) &sa_info[i]); //asociate with tx sa SPI
2687 }
2688 else
2689 printf("build_sa_db(): invalid encryption/authentication combination selected\n");
2691 //printf("sa_build_db(): authOffset %d, innerIpOffset %d, encOffset %d\n", sa_info[i].tx_payload_info.authOffset, sa_info[i].inner_ip_offset, sa_info[i].tx_payload_info.encOffset);
2694 }
2698 #define CHECK_SET_PARAM(ARG1, ARG2) \
2699 do { \
2700 if(strcmp(key, ARG1) == 0) { \
2701 if(data)strncpy(ARG2,data,CONFIG_STRING_LEN); \
2702 printf("CHECK_SET_PARM, match found, input cong string %s\n", ARG2); \
2703 continue; \
2704 } \
2705 } while(0)
2707 #define CHECK_SET_PARAM2(ARG1, ARG2, ARG3) \
2708 do { \
2709 if(strcmp(key, ARG1) == 0) { \
2710 if(data) strncpy(ARG2,data,CONFIG_STRING_LEN); \
2711 if(data2) strncpy(ARG3,data2,CONFIG_STRING_LEN); \
2712 printf("CHECK_SET_PARM2, match found, input cong string %s %s\n", ARG2, ARG3); \
2713 continue; \
2714 } \
2715 } while(0)
2717 unsigned char hex2dec(char *p_s)
2718 {
2719 int val;
2720 sscanf(p_s,"%x",&val);
2721 return val&0xff;
2722 }
2723 void parse_one_mac(char * p_mac_str, unsigned char *p_mac)
2724 {
2725 int index = 0;
2726 int i;
2727 char *pch = strtok (&(p_mac_str[0]),"-");
2729 while (pch != NULL)
2730 {
2731 printf ("%s\n",pch);
2732 p_mac[index] = hex2dec(pch);
2733 index++;
2734 pch = strtok (NULL,"-");
2735 }
2736 printf("index value : %d\n", index);
2737 for (i=0; i<6;i++)
2738 printf("************mac0[%d]: 0x%x\n",i, p_mac[i]);
2739 }
2741 void parse_one_ip(char * p_ip_addr_str, unsigned char * p_ip)
2742 {
2743 int index = 0;
2744 int i;
2745 char * pch = strtok (&p_ip_addr_str[0],".");
2747 while (pch != NULL)
2748 {
2749 printf ("xxxxx: %s\n",pch);
2750 p_ip[index] = atoi(pch);
2751 index++;
2752 pch = strtok (NULL,".");
2753 }
2754 printf("index value : %d\n", index);
2755 for (i=0; i<4;i++)
2756 printf("************ip[%d]: 0x%x\n",i, p_ip[i]);
2759 }
2761 void parse_mac_address(netTestConfigFile_t *pConfig)
2762 {
2763 if (strlen(&pConfig->mac0[0]))
2764 parse_one_mac(&pConfig->mac0[0],&config.mac0[0]);
2765 if (strlen(&pConfig->mac1[0]))
2766 parse_one_mac(&pConfig->mac1[0],&config.mac1[0]);
2767 }
2768 void parse_ip_address(netTestConfigFile_t *pConfig)
2769 {
2770 if (strlen(&pConfig->ip0[0]))
2771 parse_one_ip(&pConfig->ip0[0],&config.ip0.ipv4[0]);
2772 if (strlen(&pConfig->ip1[0]))
2773 parse_one_ip(&pConfig->ip1[0],&config.ip1.ipv4[0]);
2774 if (strlen(&pConfig->ip2[0]))
2775 parse_one_ip(&pConfig->ip2[0],&config.ip2.ipv4[0]);
2776 if (strlen(&pConfig->local_ipsec_ip[0]))
2777 parse_one_ip(&pConfig->local_ipsec_ip[0],&config.local_ipsec_ip.ipv4[0]);
2778 if (strlen(&pConfig->remote_ipsec_ip[0]))
2779 parse_one_ip(&pConfig->remote_ipsec_ip[0],&config.remote_ipsec_ip.ipv4[0]);
2780 }
2783 void parse_ipsec_mode(netTestConfigFile_t *pConfig)
2784 {
2786 if (strlen(&pConfig->ipsec_mode_rx[0]))
2787 {
2788 if (strcmp(pConfig->ipsec_mode_rx, "SIDEBAND") == 0)
2789 {
2790 config.ipsec_mode_rx = IPSEC_MODE_RX_SIDEBAND;
2791 }
2792 else if (strcmp(pConfig->ipsec_mode_rx, "INFLOW") == 0)
2793 {
2794 config.ipsec_mode_rx = IPSEC_MODE_RX_INFLOW;
2795 }
2796 else
2797 printf("parse_ipsec_mode(), invalid RX ipsec mode in config file \n");
2798 }
2800 if (strlen(&pConfig->ipsec_mode_tx[0]))
2801 {
2802 if (strcmp(pConfig->ipsec_mode_tx, "SIDEBAND") == 0)
2803 {
2804 config.ipsec_mode_tx = IPSEC_MODE_TX_SIDEBAND;
2805 }
2806 else if (strcmp(pConfig->ipsec_mode_tx, "INFLOW") == 0)
2807 {
2808 config.ipsec_mode_tx = IPSEC_MODE_TX_INFLOW;
2809 }
2810 else
2811 printf("parse_ipsec_mode(), invalid TX ipsec mode in config file \n");
2812 }
2814 printf("parse_ipsec_mode(): RX mode %d\n", config.ipsec_mode_rx);
2815 printf("parse_ipsec_mode(): TX mode %d\n", config.ipsec_mode_tx);
2818 }
2820 #ifdef EXPERIMENTAL
2821 int n_routes=0;
2822 int n_dst_ips=0;
2823 void parse_routes(netTestConfigFile_t *pConfig)
2824 {
2825 int i;
2826 int said=0;
2827 for(i=0;i<MAX_ROUTES;i++)
2828 {
2829 int port;
2830 if (pConfig->routes[i][0])
2831 {
2832 port=atoi(&pConfig->ports[i][0]);
2833 if((port<1)||(port>2)) continue; //bad port #: only 1 or 2 valid
2834 if(strncmp(&pConfig->routes[i][0],"MAC",3)==0)
2835 {
2836 routes[i].out_port = port;
2837 parse_one_mac(&pConfig->routes[i][3],&routes[i].out_mac[0]);
2838 memcpy(&routes[i].out_mac[6], ((port==1) ?&config.mac0[0]: &config.mac1[0] ),6);
2839 routes[i].out_mac[12]=0x08;
2840 routes[i].out_mac[13]=0x00;
2841 routes[i].sec_ptr=NULL;
2842 n_routes+=1;
2843 }
2844 else if (strncmp(&pConfig->routes[i][0],"SA",2)==0)
2845 {
2846 said=atoi(&pConfig->routes[i][2]) ;
2847 routes[i].sec_ptr=&sa_info[said];
2848 n_routes+=1;
2849 }
2850 }
2851 }
2852 our_router = route_init();
2853 for (i=0;i<MAX_ROUTES;i++)
2854 {
2855 unsigned long ip_be;
2856 int route_index;
2857 if (pConfig->dst_ips[i][0])
2858 {
2859 parse_one_ip(&pConfig->dst_ips[i][0],(unsigned char *)&ip_be);
2860 sscanf(&pConfig->paths[i][0],"route%d",&route_index);
2861 route_add(our_router,&ip_be,&routes[route_index]);
2862 n_dst_ips+=1;
2863 }
2864 }
2865 printf(">Route DB built. %d entries\n",n_dst_ips);
2866 }
2867 #endif
2868 static void parse_config_file(FILE * fpr, netTestConfigFile_t *pConfig)
2869 {
2870 char line[MAX_LINE_LENGTH + 1];
2871 int i;
2873 char *key, *data, *ep, *data2;
2874 char tokens[] = " :=;\n";
2875 char temp_str[50];
2876 memset(line, 0, MAX_LINE_LENGTH + 1);
2877 memset(pConfig, 0, sizeof(netTestConfigFile_t));
2878 while (fgets(line, MAX_LINE_LENGTH + 1, fpr))
2879 {
2880 if(line[0]=='#') continue; //skip comment
2881 key = (char *)strtok(line, tokens);
2882 data = (char *)strtok(NULL, tokens);
2883 data2 = (char *)strtok(NULL, tokens);
2884 if (!key) continue;
2885 if (!data) continue;
2887 if(strlen(data) == 0)
2888 {
2889 continue;
2890 }
2892 CHECK_SET_PARAM(INIT_CONFIG_MAC0,&(pConfig->mac0[0]));
2893 CHECK_SET_PARAM(INIT_CONFIG_MAC1,&(pConfig->mac1[0]));
2894 CHECK_SET_PARAM(INIT_CONFIG_IP0,&(pConfig->ip0[0]));
2895 CHECK_SET_PARAM(INIT_CONFIG_IP1,&(pConfig->ip1[0]));
2896 CHECK_SET_PARAM(INIT_CONFIG_IP2,&(pConfig->ip2[0]));
2897 CHECK_SET_PARAM(INIT_CONFIG_LOCAL_IPSEC_IP,&(pConfig->local_ipsec_ip[0]));
2898 CHECK_SET_PARAM(INIT_CONFIG_REMOTE_IPSEC_IP,&(pConfig->remote_ipsec_ip[0]));
2899 CHECK_SET_PARAM(INIT_CONFIG_IPSEC_MODE_RX,&(pConfig->ipsec_mode_rx[0]));
2900 CHECK_SET_PARAM(INIT_CONFIG_IPSEC_MODE_TX,&(pConfig->ipsec_mode_tx[0]));
2901 CHECK_SET_PARAM(INIT_CONFIG_IPSEC_IF_NO,&(pConfig->ipsec_if_no[0]));
2902 #ifdef EXPERIMENTAL
2903 for(i=0;i<MAX_ROUTES;i++)
2904 {
2905 sprintf(temp_str,"route%d",i);
2906 CHECK_SET_PARAM2(temp_str,&pConfig->routes[i][0],&pConfig->ports[i][0] );
2907 }
2908 for(i=0;i<MAX_ROUTES;i++)
2909 {
2910 sprintf(temp_str,"dstip%d",i);
2911 CHECK_SET_PARAM2(temp_str,&pConfig->dst_ips[i][0],&pConfig->paths[i][0] );
2912 }
2913 #endif
2915 }
2916 parse_mac_address(pConfig);
2918 parse_ip_address(pConfig);
2920 parse_ipsec_mode(pConfig);
2921 #ifdef EXPERIMENTAL
2922 if (strlen(&pConfig->ipsec_if_no[0]))
2923 config.ipsec_if_no = atoi(&pConfig->ipsec_if_no[0]);
2924 parse_routes(pConfig);
2925 #endif
2926 }
2929 #ifdef MULTI_THREAD
2930 NETAPI_T worker_nh[TUNE_NETAPI_NUM_CORES];
2931 void slow_path_thread(int coreid)
2932 {
2933 int err;
2935 PKTIO_HANDLE_T *our_chan;
2936 PKTIO_HANDLE_T *rx_chan;
2937 PKTIO_HANDLE_T *tx_chan;
2938 PKTIO_HANDLE_T *sb_tx_chan;
2939 PKTIO_HANDLE_T *sb_rx_chan;
2943 printf("slow_path_thread, mypid: %d, core_id %d\n", gettid(), coreid);
2945 CPU_ZERO( &cpu_set);
2946 #ifdef CORTEX_A15
2947 CPU_SET( coreid, &cpu_set);
2948 hplib_utilSetupCore(coreid, &cpu_set);
2949 #else
2950 CPU_SET( 0, &cpu_set);
2951 hplib_utilSetupCore(coreid+1, &cpu_set);
2952 #endif
2953 worker_nh[coreid]=netapi_init(NETAPI_CORE_MASTER,NULL);
2955 #ifdef DAL_REVIEW
2956 NETAPI_HANDLE_T * n = (NETAPI_HANDLE_T *) worker_nh[coreid];
2958 /* open netcp default tx, rx queues */
2959 tx_chan = pktio_open(worker_nh[coreid], NETCP_TX, NULL, &netcp_tx_cfg, &err);
2962 #ifdef EXPERIMENTAL
2963 rx_chan = pktio_open(worker_nh[coreid], NETCP_RX, (PKTIO_CB) recv_cb_router, &netcp_rx_cfg, &err);
2964 #else
2965 rx_chan = pktio_open(worker_nh[coreid], NETCP_RX, (PKTIO_CB) recv_cb, &netcp_rx_cfg, &err);
2966 #endif
2968 #ifndef EXPERIMENTAL
2969 /* create a pktio channel for specially classified pkts */
2970 /* open netcp default tx, rx queues for sideband crypto */
2971 sb_tx_chan = pktio_open(worker_nh[coreid], NETCP_SB_TX, NULL, &netcp_sb_tx_cfg, &err);
2973 sb_rx_chan = pktio_open(worker_nh[coreid], NETCP_SB_RX, (PKTIO_CB) recv_sb_cb, &netcp_sb_rx_cfg, &err);
2974 #endif
2976 #endif
2980 netapi_setCookie(worker_nh[coreid],coreid);
2981 //our_core = coreid;
2983 scheduler[coreid] =netapi_schedOpen(worker_nh[coreid],&our_sched_cfg, &err);
2984 if (!scheduler[coreid])
2985 {
2986 printf("sched create failed for core%d\n",coreid);
2987 exit(1);
2988 }
2989 scheduler[coreid]->config.yield = FALSE;
2990 scheduler[coreid]->config.pollGarbageQ = TRUE;
2991 scheduler[coreid]->config.pollCtrlQ = TRUE;
2992 /*********************************************/
2993 /**************Entry point into scheduler ****/
2994 /*********************************************/
2995 netapi_schedWaitForEvents(scheduler[coreid], &err);
2996 printf(">net_test: core %d worker thread done\n",coreid);
2997 pktio_close(tx_chan, &err);
2998 pktio_close(rx_chan, &err);
2999 pktio_close(sb_tx_chan, &err);
3000 pktio_close(sb_tx_chan, &err);
3001 netapi_shutdown(worker_nh[coreid]);
3002 }
3004 void fast_path_thread(int coreid)
3005 {
3006 int err;
3007 PKTIO_HANDLE_T *our_chan;
3008 PKTIO_HANDLE_T *rx_chan;
3009 PKTIO_HANDLE_T *tx_chan;
3010 PKTIO_HANDLE_T *sb_tx_chan;
3011 PKTIO_HANDLE_T *sb_rx_chan;
3013 #ifdef CORTEX_A15
3014 CPU_SET( coreid, &cpu_set);
3015 hplib_utilSetupCore(coreid, &cpu_set);
3016 #else
3017 CPU_SET( 0, &cpu_set);
3018 hplib_utilSetupCore(coreid + 1, &cpu_set);
3019 #endif
3020 worker_nh[coreid]=netapi_init(NETAPI_CORE_MASTER,NULL);
3022 #ifdef DAL_REVIEW
3023 NETAPI_HANDLE_T * n = (NETAPI_HANDLE_T *) worker_nh[coreid];
3025 /* open netcp default tx, rx queues */
3026 tx_chan = pktio_open(worker_nh[coreid], NETCP_TX, NULL, &netcp_tx_cfg, &err);
3029 #ifdef EXPERIMENTAL
3030 rx_chan = pktio_open(worker_nh[coreid], NETCP_RX, (PKTIO_CB) recv_cb_router, &netcp_rx_cfg, &err);
3031 #else
3032 rx_chan = pktio_open(worker_nh[coreid], NETCP_RX, (PKTIO_CB) recv_cb, &netcp_rx_cfg, &err);
3033 #endif
3035 #ifndef EXPERIMENTAL
3036 /* create a pktio channel for specially classified pkts */
3037 /* open netcp default tx, rx queues for sideband crypto */
3038 sb_tx_chan = pktio_open(worker_nh[coreid], NETCP_SB_TX, NULL, &netcp_sb_tx_cfg, &err);
3040 sb_rx_chan = pktio_open(worker_nh[coreid], NETCP_SB_RX, (PKTIO_CB) recv_sb_cb, &netcp_sb_rx_cfg, &err);
3041 #endif
3043 #endif
3046 netapi_setCookie(worker_nh[coreid],coreid);
3047 //our_core = coreid;
3048 scheduler[coreid] =netapi_schedOpen(worker_nh[coreid],&our_sched_cfg, &err);
3049 if (!scheduler[coreid])
3050 {
3051 printf("sched create failed for core%d\n",coreid);
3052 exit(1);
3053 }
3055 /*********************************************/
3056 /**************Entry point into scheduler ****/
3057 /*********************************************/
3058 scheduler[coreid]->config.yield = FALSE;
3059 scheduler[coreid]->config.pollGarbageQ = FALSE;
3060 scheduler[coreid]->config.pollCtrlQ = FALSE;
3061 //sleep(100000);
3062 netapi_schedWaitForEvents(scheduler[coreid], &err);
3063 printf(">net_test: core %d worker thread done\n",coreid);
3064 pktio_close(tx_chan, &err);
3065 pktio_close(rx_chan, &err);
3066 pktio_close(sb_tx_chan, &err);
3067 pktio_close(sb_tx_chan, &err);
3068 netapi_shutdown(worker_nh[coreid]);
3069 }
3071 #endif
3072 static netTestConfigFile_t config_file;
3073 /***************************************
3074 ********** test driver*****************
3075 ***************************************/
3076 int main(int argc, char **argv)
3077 {
3078 int err,i;
3079 Pktlib_HeapCfg heapCfg;
3080 rlim_t oss,ss = 1024*1024;
3081 struct rlimit rl;
3082 int32_t errCode;
3083 Pktlib_HeapIfTable* pPktifTable;
3085 FILE * fpr = NULL;
3088 err= getrlimit(RLIMIT_STACK,&rl);
3089 if (!err) printf(" stack limit = %d\n",rl.rlim_cur); else printf("getrlimit failed\n");
3091 if (argc>=2) np2process = atoi(argv[1]);
3092 printf("*************** np2process %d\n", np2process);
3093 if (np2process<0) np2process = NP; /* default */
3094 if (argc==3) perslow = atoi(argv[2]);
3095 if ((perslow<0)||(perslow>100)) perslow=PERSLOW;//default
3096 if (argc>3) {printf("net_test <no of pkts to process> <percent slow path>\n"); exit(1);}
3098 /* install signal handler for ^c */
3099 signal(SIGINT,mysig);
3101 fpr = fopen(input_file_name, "r");
3102 if (fpr == NULL)
3103 {
3104 printf("Error in opening %s input file\n", input_file_name);
3105 exit(1);
3106 }
3107 else
3108 {
3109 parse_config_file(fpr,&config_file);
3110 }
3112 memset(&sa_info, 0, sizeof(sa_info));
3115 //real mode, so update our test packet mac header and ip header
3116 if (pktloopback==0)
3117 {
3118 memcpy(&testPkt,&real_mac_header[0],14); //overwrite test pkt mac address
3119 memcpy(&testPkt[26],&real_ip_addr[0],8);//overrite test pkt ip addresses
3120 }
3122 #ifdef MULTI_THREAD
3123 /* assign main net_test thread to run on core 0 */
3124 CPU_ZERO( &cpu_set);
3125 CPU_SET( 0, &cpu_set);
3126 hplib_utilSetupCore(0, &cpu_set);
3127 #endif
3128 /* create netapi */
3129 netapi_handle = netapi_init(NETAPI_SYS_MASTER, &our_netapi_default_cfg);
3131 /* open the main heap */
3132 ourHeap = Pktlib_findHeapByName("netapi");
3133 if (!ourHeap)
3134 {
3135 printf("Pktlib_findHeapByName() fail\n");
3136 exit(1);
3137 }
3139 /* create two secondary heaps */
3140 /* Initialize the heap configuration. */
3141 memset ((void *)&heapCfg, 0, sizeof(Pktlib_HeapCfg));
3143 pPktifTable = netapi_getPktlibIfTable();
3144 /* Populate the heap configuration */
3145 heapCfg.name = "netapi-small";
3146 heapCfg.memRegion = NETAPI_GLOBAL_REGION;
3147 heapCfg.sharedHeap = 1;
3148 heapCfg.useStarvationQueue = 0;
3149 heapCfg.dataBufferSize = 512;
3150 heapCfg.numPkts = 64;
3151 heapCfg.numZeroBufferPackets= 0;
3152 heapCfg.heapInterfaceTable.data_malloc = pPktifTable->data_malloc;
3153 heapCfg.heapInterfaceTable.data_free = pPktifTable->data_free;
3154 heapCfg.dataBufferPktThreshold = 0;
3155 heapCfg.zeroBufferPktThreshold = 0;
3157 specialSmall = Pktlib_createHeap(&heapCfg, &errCode);
3158 heapCfg.name = "netapi-big";
3159 heapCfg.dataBufferSize = 1600;
3160 specialLarge = Pktlib_createHeap(&heapCfg, &errCode);
3161 //register these heaps so poll routine will include their garbage queues.
3162 netapi_registerHeap(netapi_handle, specialSmall);
3163 netapi_registerHeap(netapi_handle, specialLarge);
3165 #ifdef REASSEMBLE_BENCH
3166 our_reassemble_bench(2);
3167 exit(1);
3168 #endif
3170 #ifndef EXPERIMENTAL
3171 /* create a pktio channel */
3172 our_chan=pktio_create(netapi_handle,"our1stq",(PKTIO_CB) recv_cb_bench, &our_chan_cfg,&err);
3173 if (!our_chan)
3174 {
3175 printf("pktio create failed err=%d\n",err);
3176 exit(1);
3177 }
3178 #endif
3180 /* open netcp default tx, rx queues */
3181 netcp_tx_chan= pktio_open(netapi_handle, NETCP_TX, NULL, &netcp_tx_cfg, &err);
3182 if (!netcp_tx_chan)
3183 {
3184 printf("pktio open TX failed err=%d\n",err);
3185 exit(1);
3186 }
3187 #ifdef EXPERIMENTAL
3188 netcp_rx_chan= pktio_open(netapi_handle, NETCP_RX, (PKTIO_CB) recv_cb_router, &netcp_rx_cfg, &err);
3189 #else
3190 netcp_rx_chan= pktio_open(netapi_handle, NETCP_RX, (PKTIO_CB) recv_cb, &netcp_rx_cfg, &err);
3191 #endif
3192 if (!netcp_rx_chan)
3193 {
3194 printf("pktio open RX failed err=%d\n",err);
3195 exit(1);
3196 }
3198 #ifndef EXPERIMENTAL
3199 /* create a pktio channel for specially classified pkts */
3200 netcp_rx_chan2= pktio_create(netapi_handle, "classq", (PKTIO_CB) recv_cb, &netcp_rx_cfg2, &err);
3201 if (!netcp_rx_chan2) {printf("pktio create RX2 failed err=%d\n",err); exit(1);}
3203 /* open netcp default tx, rx queues for sideband crypto */
3204 netcp_sb_tx_chan= pktio_open(netapi_handle, NETCP_SB_TX, NULL, &netcp_sb_tx_cfg, &err);
3205 if (!netcp_sb_tx_chan)
3206 {
3207 printf("pktio open SB TX failed err=%d\n",err);
3208 exit(1);
3209 }
3210 netcp_sb_rx_chan= pktio_open(netapi_handle, NETCP_SB_RX, (PKTIO_CB) recv_sb_cb, &netcp_sb_rx_cfg, &err);
3211 if (!netcp_sb_rx_chan)
3212 {
3213 printf("pktio open SB RX failed err=%d\n",err);
3214 exit(1);
3215 }
3216 #endif
3218 printf("net_test> %d bytes left in our CMA area\n", netapi_getBufMemRemainder());
3219 /* create scheduler instance */
3220 our_sched =netapi_schedOpen(netapi_handle,&our_sched_cfg, &err);
3221 if (!our_sched) {printf("sched create failed\n"); exit(1);}
3223 #if 0
3224 /********************************************
3225 * Basic pkt loopback test
3226 *********************************************/
3227 printf("...running pure push/pop benchmark\n");
3228 our_pktio_bench(1000);
3229 our_pktio_bench(1000);
3230 our_pktio_bench(1000);
3231 our_pktio_bench(1000);
3232 our_pktio_bench(1000);
3233 /*********************************************/
3234 #endif
3235 //#define PROMISCUOUS
3236 #ifdef PROMISCUOUS
3237 #define ETH0 1
3238 #define ETH1 2
3239 printf(">net_test: WARNING, ADDING RULE FOR PROMISCUOUS THAT WILL BREAK LINUX STACK\n");
3240 netcp_cfgCreateMacInterface(
3241 netapi_handle,
3242 &all_mac[0],
3243 0,0,
3244 (NETCP_CFG_ROUTE_HANDLE_T) NULL,
3245 (NETCP_CFG_VLAN_T ) NULL , //future
3246 1,
3247 &err);
3248 if (err) {printf("addmac0 failed %d\n",err); exit(1); }
3250 #else
3251 #define ETH0 0
3252 #define ETH1 1
3253 #endif
3255 /* add mac intefaces */
3256 netcp_cfgCreateMacInterface(
3257 netapi_handle,
3258 &config.mac0[0],
3259 ETH0,0,
3260 (NETCP_CFG_ROUTE_HANDLE_T) NULL,
3261 (NETCP_CFG_VLAN_T ) NULL , //future
3262 1,
3263 &err);
3264 if (err) {printf("addmac0 failed %d\n",err); exit(1); }
3266 //attach an IP to this interface
3267 ip_rule0=netcp_cfgAddIp(
3268 netapi_handle,
3269 ETH0,
3270 nwal_IPV4,
3271 &config.ip0,
3272 NULL, //all IP
3273 (NETCP_CFG_ROUTE_HANDLE_T) NULL,
3274 &err
3275 );
3276 if (err) {printf("addip0 failed %d\n",err); exit(1); }
3278 //create a 2nd mac instance
3279 netcp_cfgCreateMacInterface(
3280 netapi_handle,
3281 &config.mac1[0],
3282 ETH1,1,
3283 (NETCP_CFG_ROUTE_HANDLE_T) NULL,
3284 (NETCP_CFG_VLAN_T ) NULL , //future
3285 1,
3286 &err);
3287 if (err) {printf("addmac1 failed %d\n",err); exit(1); }
3289 //attach an IP to this interface
3290 ip_rule1=netcp_cfgAddIp(
3291 netapi_handle,
3292 ETH1,
3293 nwal_IPV4,
3294 &config.ip1,
3295 NULL, //all IP
3296 (NETCP_CFG_ROUTE_HANDLE_T) NULL,
3297 &err
3298 &nbs