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 NET_TEST_ENABLE_SIDE_BAND_LOW_LEVEL_API
44 #ifdef NET_TEST_ENABLE_SIDE_BAND_LOW_LEVEL_API
45 #define NWAL_ENABLE_SA
46 #endif
48 //define this for multi-thread
49 #define MULTI_THREAD
50 #include <stdio.h>
51 #include <stdlib.h>
52 #include <unistd.h>
53 #include <string.h>
54 #include <signal.h>
55 #include <pthread.h>
57 #include "trie.h"
58 #include "string.h"
59 #include "netapi.h"
60 #include "pktio.h"
61 #include <sys/resource.h>
62 #include "net_test.h"
63 #include <ti/drv/sa/salld.h>
64 //#define EXPERIMENTAL
65 #ifdef EXPERIMENTAL
66 #include "router.c"
67 Trie * our_router;
71 OUR_ROUTE_T routes[MAX_ROUTES]=
72 {
73 {0,{0xD4,0xbe,0xd9,0x00,0xd3,0x7e, 0x00,0x01,0x02,0x03,0x14,0x02,0x08,0x00},0},
74 {0,{0x00,0x00,0x0,0x00,0x0,0x0, 0x00,0x00,0x00,0x00,0x00,0x00,0x08,0x00},0},
75 {0,{0xD4,0xbe,0xd9,0x00,0xd3,0x7e, 0x00,0x01,0x02,0x03,0x14,0x02,0x08,0x00},0},
76 {0,{0x00,0x15,0x60,0xa1,0xf7,0xbe, 0x00,0x01,0x02,0x03,0x04,0x05,0x08,0x00},0},
77 {0,{0xd4,0xbe,0xd9,0x00,0xd3,0x7e, 0x00,0x01,0x02,0x03,0x04,0x05,0x08,0x00},0}};
79 unsigned int ip[MAX_ROUTES]={BE(0x0a0100c8),BE(0x0a00000a),BE(0x0a02000a),BE(0xc0a8010a),BE(0x9eda6719)};
81 #endif
83 #ifdef MULTI_THREAD
84 __thread int our_core;
85 cpu_set_t cpu_set;
86 #endif
88 //#define TEST_TIMERS
89 static int scnt=0;
90 static int QUIT=0;
91 void mysig(int x)
92 {
93 QUIT=1;
94 scnt+=1;
95 printf(">net_test: recv'd signal %d cnt=%d\n",x,scnt);
96 if (scnt > 10) {printf(">net_test: WARNING EXITING WITH PROPER SHUTDOWN, LUTS LEFT ACTIVE\n");exit(1);}
98 }
100 static unsigned char all_mac[]={0,0,0,0,0,0};
102 /*************debug********************/
103 void dump_descr(unsigned long *p, int n)
104 {
105 printf("--------dump of descriptor %d %x\n", n, (int) p);
106 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]);
107 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]);
108 printf("-----------------------------\n");
109 }
110 void dump_header(unsigned long *p, int n, int a, int r)
111 {
112 printf("--------dump of header %d %x appID=%x flag1=%x\n", n, (int) p,a,r);
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("> %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]);
116 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]);
117 printf("-----------------------------\n");
118 }
121 static void netapi_dump_buf
122 (
123 unsigned long * buf,
124 uint32_t buf_length
125 )
126 {
127 uint8_t count = 0;
128 uint16_t dump_size;
129 uint8_t* tmp_buf;
130 uint8_t row_count;
131 static uint8_t first = 0;
133 //if(first > 2) return;
135 //first++;
137 dump_size = buf_length ;
139 tmp_buf = (uint8_t *)(buf);
141 printf("netapi *: - 8 bit word hex Length: %d Start \n",buf_length);
142 do
143 {
144 row_count = (dump_size - count);
146 if(row_count == 0)
147 {
148 break;
149 }
151 if(row_count > 4)
152 {
153 row_count = 4;
154 }
156 switch (row_count)
157 {
158 case 4:
159 {
160 printf("netapi *:%02d : %02x %02x %02x %02x \n",
161 count,tmp_buf[0],tmp_buf[1],tmp_buf[2],tmp_buf[3]);
162 break;
163 }
164 case 3:
165 {
166 printf("netapi *: %02d : %02x %02x %02x \n",
167 count,tmp_buf[0],tmp_buf[1],tmp_buf[2]);
168 break;
169 }
171 case 2:
172 {
173 printf("netapi *: %02d : %02x %02x \n",
174 count,tmp_buf[0],tmp_buf[1]);
175 break;
176 }
178 case 1:
179 {
180 printf("netapi *: %02d : %02x \n",
181 count,tmp_buf[0]);
182 break;
183 }
185 default:
186 {
187 /* Should never reach here */
188 printf("netapi *: Internal Error in netapi_dump_buf().Row Count: %d \n",
189 row_count);
190 return;
191 }
192 }
194 tmp_buf = tmp_buf + row_count;
195 count = count + row_count;
197 }while(count < dump_size);
199 printf("netapi *: - Byte hex Dump End \n");
201 }
204 /*****************************************/
207 //************for multi pkt burst xfer test in loopback mode
208 #define TX_BURST 700
209 int pktloopback=TUNE_NETAPI_NWAL_ENABLE_PASS_LOOPBACK;
210 nwalTxPSCmdInfo_t flowPSCmdInfo;
211 nwal_RetValue nwalRetVal;
213 /* Local Per Process default resourcese maintained at NWAL */
214 nwalLocCxtInfo_t nwalLocCxt;
216 //this device: 10.0.0.100, mac 0x,01,02,03,04,05 and .. 0x6
218 //test packet, setup for loopback (so dest is ourself)
219 static uint8_t testPkt[] = {
221 /* MAC header */
222 0x00, 0x01, 0x02, 0x03, 0x04, 0x05,
223 0x00, 0xe0, 0xa6, 0x66, 0x57, 0x04,
224 0x08, 0x00,
226 /* IP header */
227 0x45, 0x00,
228 0x00, 0x6c, /* Length (including this header) */
229 0x00, 0x00, 0x00, 0x00, 0x05, 0x11,
230 0x00, 0x00, /* Header checksum */
231 0x0a, 0x00, 0x00, 0x0a, 0x0a, 0x00, 0x00, 0x64,
233 /* UDP header */
234 0x12, 0x34, 0x05, 0x55,
235 0x00, 0x58, /* Length, including this header */
236 0x00, 0x00, /* Header checksum */
238 /* Payload */
239 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39,
240 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f, 0x40, 0x41,
241 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49,
242 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f, 0x50, 0x51,
243 0x52, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, 0x59,
244 0x5a, 0x5b, 0x5c, 0x5d, 0x5e, 0x5f, 0x60, 0x61,
245 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69,
246 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, 0x6f, 0x70, 0x71,
247 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79,
248 0x7a, 0x7b, 0x7c, 0x7d, 0x7e, 0x7f, 0x80, 0x81
250 };
252 char input_file_name[] = "net_test_config.txt";
253 #define MAX_LINE_LENGTH 40
255 #define TEST_PAYLOAD_LEN 80
257 #define TEST_PKT_IP_OFFSET_BYTES 14
258 #define TEST_PKT_UDP_OFFSET_BYTES 34
259 #define TEST_PKT_PLOAD_OFFSET_BYTES 42
260 #define TEST_PKT_UDP_HDR_LEN 8
261 /* Offsets to length fields */
262 #define TEST_PKT_OFFSET_IP_LEN 16
263 #define TEST_PKT_OFFSET_UDP_LEN 38
265 #define TEST_PKT_LEN 122
267 /* The pseudo header checksum of the packet except for the 16 bit length */
268 #define TEST_PKT_PSEUDO_HDR_CHKSUM_SANS_LEN 0x0FFC
270 void example_fast_poll( PKTIO_HANDLE_T * p_pktio, int max_pkts);
271 void example_fast_pushpop(Pktlib_HeapHandle p_heap, int ntrials);
273 void recv_cb_router(struct PKTIO_HANDLE_Tag * channel, Ti_Pkt* p_recv[],
274 PKTIO_METADATA_T meta[], int n_pkts,
275 uint64_t ts );
278 //#include "arpa/inet.h"
279 long htonl(long x)
280 {
281 long temp = (x&0xff000000)>>24 | (x&0xff0000)>>8 | (x&0xff00)<<8 | (x&0xff)<<24 ;
282 return temp;
283 }
285 /********************************************************************
286 * FUNCTION PURPOSE: Ones complement addition utility
287 ********************************************************************
288 ********************************************************************/
289 uint16_t test_utilOnesComplementAdd (uint16_t v1, uint16_t v2)
290 {
291 uint32_t result;
293 result = (uint32_t)v1 + (uint32_t)v2;
294 result = (result >> 16) + (result & 0xffff);
295 result = (result >> 16) + (result & 0xffff);
297 return ((uint16_t)result);
298 }
300 /********************************************************************
301 * FUNCTION PURPOSE: Ones complement checksum utility
302 ********************************************************************
303 ********************************************************************/
304 uint16_t test_utilOnesCompChkSum (uint8_t *p, uint32_t nwords)
305 {
306 uint16_t chksum = 0;
307 uint16_t v;
308 uint32_t i;
309 uint32_t j;
311 for (i = j = 0; i < nwords; i++, j+=2) {
312 v = (p[j] << 8) | p[j+1];
313 chksum = test_utilOnesComplementAdd (chksum, v);
314 }
315 return (chksum);
316 } /* utilOnesCompChkSum */
318 /**************************************************************************************
319 * FUNCTION PURPOSE: Compute ipv4 psudo checksum
320 **************************************************************************************
321 * DESCRIPTION: Compute ipv4 psudo checksum
322 **************************************************************************************/
323 uint16_t test_utilGetIpv4PsudoChkSum (uint8_t *data, uint16_t payloadLen)
324 {
325 uint16_t psudo_chksum;
327 psudo_chksum = test_utilOnesCompChkSum (&data[12], 4);
328 psudo_chksum = test_utilOnesComplementAdd(psudo_chksum, (uint16_t) data[9]);
329 psudo_chksum = test_utilOnesComplementAdd(psudo_chksum, payloadLen);
331 return (psudo_chksum);
333 } /* utilGetIpv4PsudoChkSum */
337 /* net test default configuration */
338 netTestConfig_t config =
339 {
340 {0x00,0x01,0x02,0x03,0x05,0x05},
341 {0x00,0x01,0x02,0x03,0x05,0x06},
342 {10, 0, 0, 100, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
343 {10, 0, 1, 100, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
344 {10, 0, 2, 100, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
345 {192,168 , 1, 100, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
346 {192,168 , 1, 10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
347 IPSEC_MODE_RX_SIDEBAND,
348 IPSEC_MODE_TX_SIDEBAND,
349 0
350 };
352 #if 1 //goes with real tx (to laptop)
353 unsigned char real_mac_header[]={0xd4,0xbe,0xd9,0x00,0xd3,0x7e,
354 0x00,0x01,0x02,0x03,0x04,0x05,
355 0x08,0x00};
356 unsigned char real_ip_addr[]={0xa,0x00,0x00,0x64,0xa,0x0,0x0,0xa};
357 #endif
359 #if 0 //goes with loopback
360 unsigned char mac_header[]={0x00,0x01,0x02,0x03,0x04,0x05,
361 0x00,0x11,0x22,0x33,0x44,0x55,
362 0x08,0x00};
363 #endif
364 #define NE 65536
365 HEAD_T *nat;
367 #define NP 5000
368 int n_pkt = NP;
369 STATS_T stats;
370 paSysStats_t netcp_stats;
372 Trie * P_trie;
373 Trie *p_trie_sa;
374 HEAD_T pkts[NP];
375 #define PERSLOW 10 //% of pkts that will not be fastpath'd
376 int perslow= PERSLOW;
378 /*******************************************
379 *************NETAPI OBJECTS***************
380 *****************************************/
381 static NETAPI_CFG_T our_netapi_default_cfg=
382 {
383 TUNE_NETAPI_PERM_MEM_SZ,
384 128, //start of packet offset for hw to place data on rx for default flow
385 TUNE_NETAPI_QM_CONFIG_MAX_DESC_NUM, //max number of descriptors in system
386 TUNE_NETAPI_NUM_GLOBAL_DESC, //total we will use
387 TUNE_NETAPI_DEFAULT_NUM_BUFFERS, //#descriptors+buffers in default heap
388 64, //#descriptors w/o buffers in default heap
389 TUNE_NETAPI_DEFAULT_BUFFER_SIZE+128+128, //size of buffers in default heap
390 128 , //tail room
391 256 //extra room
392 };
394 Pktlib_HeapHandle OurHeap;
395 Pktlib_HeapHandle specialSmall;
396 Pktlib_HeapHandle specialLarge;
398 PKTIO_HANDLE_T *our_chan;
399 PKTIO_HANDLE_T *netcp_rx_chan;
400 PKTIO_HANDLE_T *netcp_rx_chan2;
401 PKTIO_HANDLE_T *netcp_tx_chan;
402 PKTIO_HANDLE_T *netcp_sb_tx_chan;
403 PKTIO_HANDLE_T *netcp_sb_rx_chan;
404 PKTIO_CFG_T our_chan_cfg={PKTIO_RW, PKTIO_LOCAL, PKTIO_Q_ANY, 8};
405 PKTIO_CFG_T netcp_rx_cfg={PKTIO_R, PKTIO_NA, PKTIO_NA, 8};
406 PKTIO_CFG_T netcp_rx_cfg2={PKTIO_R, (PKTIO_GLOBAL|PKTIO_PKT), PKTIO_Q_ANY, 8};
407 PKTIO_CFG_T netcp_tx_cfg={PKTIO_W, PKTIO_NA, PKTIO_NA, 8};
408 PKTIO_CFG_T netcp_sb_rx_cfg={PKTIO_R, PKTIO_NA, PKTIO_NA, 8};
409 PKTIO_CFG_T netcp_sb_tx_cfg={PKTIO_W, PKTIO_NA, PKTIO_NA, 8};
411 void house(NETAPI_SCHED_HANDLE_T *s);
412 NETAPI_T netapi_handle;
413 NETAPI_SCHED_HANDLE_T * our_sched;
414 #ifdef MULTI_THREAD
415 NETAPI_SCHED_HANDLE_T * scheduler[TUNE_NETAPI_NUM_CORES];
416 #endif
417 NETAPI_SCHED_CONFIG_T our_sched_cfg={
418 NETAPI_SCHED_DURATION|NETAPI_SCHED_CBV, 0, house, 5000000 //every 5000000 poll loops
419 };
420 void our_stats_cb(NETAPI_T h, paSysStats_t* pPaStats);
421 void our_stats_cb_mt(NETAPI_T h, paSysStats_t* pPaStats);
422 HPLIB_TIMER_GROUP_HANDLE_T ourTimerBlock;
423 HPLIB_TIMER_T t1;
424 HPLIB_TIMER_T t2;
425 HPLIB_TIMER_T t3;
427 void our_timer_cb( HPLIB_TIMER_GROUP_HANDLE_T th,
428 int n_fired, //# timers fired
429 HPLIB_TIMER_LIST_T fired_list,
430 uint64_t currentTime);
432 NETCP_CFG_IP_T ip_rule0;
433 NETCP_CFG_IP_T ip_rule1;
434 NETCP_CFG_CLASS_T class_0;
435 NETCP_CFG_CLASS_T class_1;
436 NETCP_CFG_CLASS_T class_2;
437 NETCP_CFG_FLOW_HANDLE_T specialFlow;
440 NETCP_CFG_CLASSIFIER_T class_0_cfg=
441 {
442 NETCP_CFG_CLASS_TYPE_L4,
443 {
444 .c_l4={0,0, NWAL_APP_PLOAD_PROTO_UDP, {2500}}
445 }
446 };
448 NETCP_CFG_CLASSIFIER_T class_1_cfg=
449 {
450 NETCP_CFG_CLASS_TYPE_L4,
451 {
452 .c_l4= {0,0, NWAL_APP_PLOAD_PROTO_UDP, {2502}}
453 }
454 };
456 NETCP_CFG_ROUTE_T class2_route=
457 {
458 NULL, NULL //* to be filled in
459 };
460 NETCP_CFG_CLASSIFIER_T class_2_cfg=
461 {
462 NETCP_CFG_CLASS_TYPE_L3_L4,
463 {
464 .c_l3_l4={0, 4 ,0/*fill in below*/ , NULL, NULL, //L2/L3
465 NWAL_APP_PLOAD_PROTO_UDP, {2504}} //L4
466 }
467 };
469 PKTIO_CONTROL_T zap_channel_control={PKTIO_CLEAR, NULL};
471 /* security objects. (for loopback mode) */
472 netTestSA_t sa_info[6];
473 int netapi_algorithm_set = 0;
474 int netapi_sec_sa_mode = 2;
476 NETCP_CFG_IPSEC_POLICY_T rx_policy[4];
480 NETAPI_SEC_SA_INFO_T rx_sa [7] = {
481 {
482 NWAL_SA_DIR_INBOUND,
483 0x11111111, //spi
484 nwal_IpSecProtoESP, //ESP mode
485 nwal_SA_MODE_TUNNEL, //tunnel mode
486 nwal_IPV4, //v4
487 { 1, 2, 3, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, /* Src IP (them) -> set below */
488 { 1, 2, 3, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, /* dst IP (us)-> set below*/
489 64,/* replayWindow */
490 NWAL_SA_AALG_HMAC_SHA1,
491 NWAL_SA_EALG_AES_CBC,
492 0,0 //na
493 },
494 {
495 NWAL_SA_DIR_INBOUND,
496 0x22222222, //spi
497 nwal_IpSecProtoESP, //ESP mode
498 nwal_SA_MODE_TUNNEL, //tunnel mode
499 nwal_IPV4, //v4
500 { 1, 2, 3, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, /* Src IP (them) -> set below */
501 { 1, 2, 3, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, /* dst IP (us)-> set below*/
502 64,/* replayWindow */
503 NWAL_SA_AALG_HMAC_SHA2_256,
504 NWAL_SA_EALG_AES_CTR,
505 0,0 //na
506 },
507 {
508 NWAL_SA_DIR_INBOUND,
509 0x33333333, //spi
510 nwal_IpSecProtoESP, //ESP mode
511 nwal_SA_MODE_TUNNEL, //tunnel mode
512 nwal_IPV4, //v4
513 { 1, 2, 3, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, /* Src IP (them) -> set below */
514 { 1, 2, 3, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, /* dst IP (us)-> set below*/
515 0,/* replayWindow */
516 NWAL_SA_AALG_NULL,
517 NWAL_SA_EALG_3DES_CBC,
518 0,0 //na
519 },
520 {
521 NWAL_SA_DIR_INBOUND,
522 0x44444444, //spi
523 nwal_IpSecProtoESP, //ESP mode
524 nwal_SA_MODE_TUNNEL, //tunnel mode
525 nwal_IPV4, //v4
526 { 1, 2, 3, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, /* Src IP (them) -> set below */
527 { 1, 2, 3, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, /* dst IP (us)-> set below*/
528 64,/* replayWindow */
529 NWAL_SA_AALG_HMAC_MD5,
530 NWAL_SA_EALG_NULL,
531 0,0 //na
532 },
533 {
534 NWAL_SA_DIR_INBOUND,
535 0x55555555, //spi
536 nwal_IpSecProtoESP, //ESP mode
537 nwal_SA_MODE_TUNNEL, //tunnel mode
538 nwal_IPV4, //v4
539 { 1, 2, 3, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, /* Src IP (them) -> set below */
540 { 1, 2, 3, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, /* dst IP (us)-> set below*/
541 64,/* replayWindow */
542 NWAL_SA_AALG_NULL,
543 NWAL_SA_EALG_AES_GCM,
544 0,0 //na
545 },
546 {
547 NWAL_SA_DIR_INBOUND,
548 0x66666666, //spi
549 nwal_IpSecProtoESP, //ESP mode
550 nwal_SA_MODE_TUNNEL, //tunnel mode
551 nwal_IPV4, //v4
552 { 1, 2, 3, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, /* Src IP (them) -> set below */
553 { 1, 2, 3, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, /* dst IP (us)-> set below*/
554 64,/* replayWindow */
555 NWAL_SA_AALG_NULL,
556 NWAL_SA_EALG_AES_CCM,
557 0,0 //na
558 },
559 {
560 NWAL_SA_DIR_INBOUND,
561 0x77777777, //spi
562 nwal_IpSecProtoESP, //ESP mode
563 nwal_SA_MODE_TUNNEL, //tunnel mode
564 nwal_IPV4, //v4
565 { 1, 2, 3, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, /* Src IP (them) -> set below */
566 { 1, 2, 3, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, /* dst IP (us)-> set below*/
567 64,/* replayWindow */
568 NWAL_SA_AALG_GMAC,
569 NWAL_SA_EALG_NULL,
570 0,0 //na
571 }
572 };
574 /*tx */
575 NETAPI_SEC_SA_INFO_T tx_sa[7]= {
576 {
577 NWAL_SA_DIR_OUTBOUND,
578 0x11111111, //spi
579 nwal_IpSecProtoESP, //ESP mode
580 nwal_SA_MODE_TUNNEL, //tunnel mode
581 nwal_IPV4, //v4
582 { 1, 2, 3, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, /* Src IP (us) -> set below */
583 { 1, 2, 3, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, /* dst IP (them) -> set below*/
584 64, /* NA replayWindow */
585 NWAL_SA_AALG_HMAC_SHA1,
586 NWAL_SA_EALG_AES_CBC,
587 0,0 //seq no
588 },
589 {
590 NWAL_SA_DIR_OUTBOUND,
591 0x22222222, //spi
592 nwal_IpSecProtoESP, //ESP mode
593 nwal_SA_MODE_TUNNEL, //tunnel mode
594 nwal_IPV4, //v4
595 { 1, 2, 3, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, /* Src IP (us) -> set below */
596 { 1, 2, 3, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, /* dst IP (them) -> set below*/
597 64, /* NA replayWindow */
598 NWAL_SA_AALG_HMAC_SHA2_256,
599 NWAL_SA_EALG_AES_CTR,
600 0,0 //seq no
601 },
602 {
603 NWAL_SA_DIR_OUTBOUND,
604 0x33333333, //spi
605 nwal_IpSecProtoESP, //ESP mode
606 nwal_SA_MODE_TUNNEL, //tunnel mode
607 nwal_IPV4, //v4
608 { 1, 2, 3, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, /* Src IP (us) -> set below */
609 { 1, 2, 3, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, /* dst IP (them) -> set below*/
610 0, /* NA replayWindow */
611 NWAL_SA_AALG_NULL,
612 NWAL_SA_EALG_3DES_CBC,
613 0,0 //seq no
614 },
615 {
616 NWAL_SA_DIR_OUTBOUND,
617 0x44444444, //spi
618 nwal_IpSecProtoESP, //ESP mode
619 nwal_SA_MODE_TUNNEL, //tunnel mode
620 nwal_IPV4, //v4
621 { 1, 2, 3, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, /* Src IP (us) -> set below */
622 { 1, 2, 3, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, /* dst IP (them) -> set below*/
623 64, /* NA replayWindow */
624 NWAL_SA_AALG_HMAC_MD5,
625 NWAL_SA_EALG_NULL,
626 },
627 {
628 NWAL_SA_DIR_OUTBOUND,
629 0x55555555, //spi
630 nwal_IpSecProtoESP, //ESP mode
631 nwal_SA_MODE_TUNNEL, //tunnel mode
632 nwal_IPV4, //v4
633 { 1, 2, 3, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, /* Src IP (them) -> set below */
634 { 1, 2, 3, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, /* dst IP (us)-> set below*/
635 64,/* replayWindow */
636 NWAL_SA_AALG_NULL,
637 NWAL_SA_EALG_AES_GCM,
638 0,0 //na
639 },
640 {
641 NWAL_SA_DIR_OUTBOUND,
642 0x66666666, //spi
643 nwal_IpSecProtoESP, //ESP mode
644 nwal_SA_MODE_TUNNEL, //tunnel mode
645 nwal_IPV4, //v4
646 { 1, 2, 3, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, /* Src IP (them) -> set below */
647 { 1, 2, 3, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, /* dst IP (us)-> set below*/
648 64,/* replayWindow */
649 NWAL_SA_AALG_NULL,
650 NWAL_SA_EALG_AES_CCM,
651 0,0 //na
652 },
653 {
654 NWAL_SA_DIR_OUTBOUND,
655 0x77777777, //spi
656 nwal_IpSecProtoESP, //ESP mode
657 nwal_SA_MODE_TUNNEL, //tunnel mode
658 nwal_IPV4, //v4
659 { 1, 2, 3, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, /* Src IP (them) -> set below */
660 { 1, 2, 3, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, /* dst IP (us)-> set below*/
661 64,/* replayWindow */
662 NWAL_SA_AALG_GMAC,
663 NWAL_SA_EALG_NULL,
664 0,0 //na
665 }
666 };
668 static nwalSecKeyParams_t ourTXKeyParams[7] ={
669 {
670 16, /* encKeySize: CTR 16 bytes Encryption Key and 4 bytes Salt : 24 bytes:NWAL_SA_EALG_3DES_CBC and 0 bytes Salt*/
671 20, /* macKeySize: 16 bytes NWAL_SA_AALG_HMAC_SHA1 */
672 NULL, //set below
673 NULL, //set below
674 },
675 {
676 20, /* encKeySize: CTR 16 bytes Encryption Key and 4 bytes Salt : 24 bytes:NWAL_SA_EALG_AES_CTR and 0 bytes Salt*/
677 32, /* macKeySize: 16 bytes NWAL_SA_AALG_HMAC_SHA2_256 */
678 NULL, //set below
679 NULL, //set below
680 },
681 {
682 24, /* encKeySize: DES-CBC: 24 bytes:NWAL_SA_EALG_3DES_CBC and 0 bytes Salt*/
683 0, /* macKeySize: 16 bytes NWAL_SA_AALG_HMAC_SHA2_256 */
684 NULL, //set below
685 NULL, //set below
686 },
687 {
688 0, /* NULL*/
689 16, /* MD5, 16 bytes */
690 NULL, //set below
691 NULL, //set below
692 },
693 {
694 20, /* encKeySize: GCM 16 bytes Encryption Key and 4 bytes Salt */
695 0, /* macKeySize: 0*/
696 NULL, //set below
697 NULL, //set below
698 },
699 {
700 19, /* encKeySize: CTR 16 bytes Encryption Key and 3 bytes Salt : 24 bytes:NWAL_SA_EALG_AES_CTR and 0 bytes Salt*/
701 0, /* macKeySize 0*/
702 NULL, //set below
703 NULL, //set below
704 },
705 {
706 0, /* encKeySize: CTR 16 bytes Encryption Key and 3 bytes Salt : 24 bytes:NWAL_SA_EALG_AES_CTR and 0 bytes Salt*/
707 24, /* macKeySize 0*/
708 NULL, //set below
709 NULL, //set below
710 }
711 };
713 /* these keys are for aes-ctr and hmac sha2_256 */
714 static nwalSecKeyParams_t ourRXKeyParams[7] ={
715 {
716 16, /* encKeySize: CTR 16 bytes Encryption Key and 4 bytes Salt : 24 bytes:NWAL_SA_EALG_3DES_CBC and 0 bytes Salt*/
717 20, /* macKeySize: 16 bytes NWAL_SA_AALG_HMAC_SHA1 */
718 NULL, //set below
719 NULL, //set below
720 },
721 {
722 20, /* encKeySize: CTR 16 bytes Encryption Key and 4 bytes Salt */
723 32, /* macKeySize: 16 bytes NWAL_SA_AALG_HMAC_SHA2_256 */
724 NULL, //set below
725 NULL, //set below
726 },
727 {
728 24, /* encKeySize: DES-CBC: 24 bytes:NWAL_SA_EALG_3DES_CBC and 0 bytes Salt*/
729 0, /* macKeySize: 16 bytes NWAL_SA_AALG_HMAC_SHA2_256 */
730 NULL, //set below
731 NULL, //set below
732 },
733 {
734 0, /* NWAL_SA_EALG_NULL*/
735 16, /* NWAL_SA_AALG_HMAC_MD5, 16 bytes */
736 NULL, //set below
737 NULL, //set below
738 },
739 {
740 20, /* encKeySize: GCM 16 bytes Encryption Key and 4 bytes Salt */
741 0, /* macKeySize: 0*/
742 NULL, //set below
743 NULL, //set below
744 },
745 {
746 19, /* encKeySize: CTR 16 bytes Encryption Key and 3 bytes Salt t*/
747 0, /* macKeySize 0*/
748 NULL, //set below
749 NULL, //set below
750 },
751 {
752 0, /* encKeySize: CTR 16 bytes Encryption Key and 3 bytes Salt : 24 bytes:NWAL_SA_EALG_AES_CTR and 0 bytes Salt*/
753 24, /* macKeySize 0*/
754 NULL, //set below
755 NULL, //set below
756 }
757 };
760 static uint8_t ourAuthKey[36] =
761 {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F,
762 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F,
763 0x20, 0x21, 0x22, 0x23 };
764 ;
766 static uint8_t ourEncrKey[36] =
767 {0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0xFF,
768 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0xFF,
769 0x30, 0x31, 0x32, 0x33 };
772 /*************************END NETAPI OBJECTS***********************/
774 #define START_SRC_IP 0x0a00000a
775 #define DST_IP 0xc0a80001
776 #define NEW_START_SRC_IP 0x9eda000a
777 #define DST_PORT 0x555
778 #define START_SRC_PORT 0x1234
779 #define NEW_START_SRC_PORT 100
780 void update_header(HEAD_T * p_head, int len)
781 {
782 unsigned char *p = (unsigned char *) &p_head->udp[1];
783 len -= (20+14);
784 /* update ip checksum */
785 /* update udp checksum */
786 /* update length */
787 *p= (len&0xff00)>>8;
788 *(p+1) = len&0xff;
789 }
791 #if 0
792 void gen_pkts(int np)
793 {
794 int i;
795 int ip = START_SRC_IP &0xff;
796 int port= START_SRC_PORT;
797 //HEAD_T temp={{0x25000200,0xdead0000,0x80110000,START_SRC_IP,DST_IP},
798 // {START_SRC_PORT<<16|DST_PORT,0x01ec<<16|0x0000}};
799 HEAD_T temp;
800 memcpy(&temp,&testPkt[0],sizeof(HEAD_T));
802 for(i=0;(i<np) && (i<NP);i++)
803 {
804 memcpy(&pkts[i],&temp,sizeof(temp));
805 update_header(&pkts[i],512); /* update checksums etc */
806 /* change template for new pkt */
807 ip+=1;
808 if(ip>254) {(ip=START_SRC_IP&0xff); port+=1; }
809 temp.ip[3] = htonl((START_SRC_IP&0xffffff00)| ip);
810 temp.udp[0] = htonl( (temp.udp[0]&0xffff0000)| port);
811 temp.udp[1] = htonl(temp.udp[1]);
813 }
814 n_pkt=np;
815 }
816 #endif
818 void build_table(Trie * p_trie)
819 {
820 int i;
821 int sport=NEW_START_SRC_PORT;
822 HEAD_T temp,temp2;
823 KEY_T key;
825 memcpy(&temp,&testPkt[14],sizeof(temp));
827 //insert entry into trie
828 key.src_ip = temp.ip[3];
829 key.dst_ip = temp.ip[4];
830 key.src_port= (temp.udp[0]&0xffff0000)>>16;
831 key.dst_port= (temp.udp[0]&0x0000ffff);
832 trie_insert(p_trie,(char *)&key,sizeof(key), (void *) &nat[0]); //asociate with nat entry 0
834 //build nat table
835 for(i=0;i<100;i++)
836 {
837 memcpy(&temp2,&testPkt[14],sizeof(temp));
838 temp2.udp[0] = (temp2.udp[0] & 0xffff0000) | sport;
839 memcpy(&nat[i], &temp2, sizeof(temp2));
840 sport+= 1;
841 }
842 }
844 //===========stub transmitter==================
845 void send_pkt(Ti_Pkt *pkt, int len)
846 {
847 //just free pkt. Don't send
848 Pktlib_freePacket((Ti_Pkt*)pkt);
849 return;
850 }
852 //==========stub slow path============
853 void slow_path(Ti_Pkt *pkt, int len)
854 {
855 // debug: check descriptor for validity by verifying that desciptor link field is null as expected\n");
856 {Ti_Pkt * k= Pktlib_getNextPacket(pkt); if(k != 0) {printf(" slowpath, nexpkt != NULL");}}
857 //just free pkt
858 Pktlib_freePacket((Ti_Pkt*)pkt);
859 return;
860 }
861 /* check header */
862 struct LastPktInfo
863 {
864 int iface;
865 int ipcsum;
866 int l4csum;
867 } ;
868 static struct LastPktInfo lpInfo;
870 int check_header(HEAD_T * p_head, PKTIO_METADATA_T * p_meta)
871 {
872 if (NWAL_RX_FLAG1_META_DATA_VALID & p_meta->u.rx_meta->rxFlag1)
873 {
874 lpInfo.iface = ((unsigned int)p_meta->u.rx_meta->appId) &0xff; //last byte is interface num
875 lpInfo.ipcsum =(p_meta->u.rx_meta->rxFlag1 & NWAL_RX_FLAG1_IPV4_CHKSUM_VERIFY_MASK )== NWAL_RX_FLAG1_IPV4_CHKSUM_VERIFY_ACK ? 1 : 0;
876 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;
877 if ((unsigned int)p_meta->u.rx_meta->appId & NETAPI_NETCP_MATCH_IPSEC)
878 {
879 stats.sec_rx++;
880 }
881 if ((unsigned int)p_meta->u.rx_meta->appId & NETAPI_NETCP_MATCH_IPSEC_POLICY)
882 {
883 stats.secp_rx++;
884 }
886 if ((unsigned int)p_meta->u.rx_meta->appId & NETAPI_NETCP_MATCH_CLASS)
887 {
888 int c= ((unsigned int)p_meta->u.rx_meta->appId >>8)&0xffff;
889 if (c==0) stats.n_class0_rx +=1;
890 else if (c==1) stats.n_class1_rx +=1;
891 else if (c==2) stats.n_class2_rx +=1;
892 else printf("**NET_TEST RX -unknown class: %x\n", p_meta->u.rx_meta->appId);
893 }
894 }
896 return 1;
897 }
899 #define PKT_LEN 1400
900 void test_alloc_free(int n)
901 {
902 int i;
903 Ti_Pkt * b;
905 for(i=0;i<n;i++)
906 {
907 b=Pktlib_allocPacket(OurHeap,PKT_LEN);
908 Pktlib_freePacket(b);
909 }
910 }
912 //measurement test points
913 unsigned int vv1;
914 unsigned int vv2;
915 unsigned int vv3;
916 unsigned int vv4;
917 unsigned int vv5;
918 unsigned int vv6;
919 //these are updated by pktio.
920 #ifdef PKTIO_GET_BENCHMARK
921 extern unsigned int vv7p;
922 extern unsigned int vv8p;
923 extern unsigned int vv9p;
924 extern unsigned int vv10p;
925 extern unsigned int vv11p;
926 extern unsigned int vv12p;
928 extern unsigned int vv13p; //rcv path
929 extern unsigned int vv14p;
930 extern unsigned int vv15p;
931 #endif
933 unsigned int vv11;
935 extern unsigned int nwal_prof1,nwal_prof2,nwal_prof3,nwal_prof4,nwal_prof5,nwal_prof6;
937 //#define REASSEMBLE_BENCH
938 #ifdef REASSEMBLE_BENCH
939 #include <ti/drv/pa/example/reassemLib/reassemLib.h>
940 /*--------------reassembly benchmark--------------------------------*/
941 void our_reassemble_bench(int nfrags)
942 {
943 paIPReassemblyConfig_t Config={5,128,10000 };
944 int i,j;
945 int len;
946 Ti_Pkt tip;
947 char *buffer;
948 unsigned long v1;
949 unsigned long v2;
950 unsigned long sum1=0;
951 unsigned long sum2=0;
952 paEx_reassemLibInit(&Config);
953 for(j=0;j<200/nfrags;j++)
954 {
955 for(i=0;i<nfrags;i++)
956 {
957 short temp;
958 tip=Pktlib_allocPacket(OurHeap,PKT_LEN);
959 Pktlib_getDataBuffer(tip,(uint8_t**)&buffer,&len);
960 memcpy(&buffer[0],&testPkt[14],20); //IP header
961 if (i < (nfrags-1)) buffer[6] = 0x20;
962 temp = i*40;
963 buffer[6]|= (temp&0x1f00)>>8;
964 buffer[7]= (temp&0xff);
965 temp = 20+40*8;
966 buffer[2]= (temp&0xff00)>>8;
967 buffer[3]= (temp&0xff);
968 Pktlib_setPacketLen(tip, temp);
969 v1= hplib_mUtilGetTickCount();
970 paEx_reassemLibProc(tip, 0xffff);
971 v2= hplib_mUtilGetTickCount();
972 sum1+= v2-v1;
973 }
974 sum2 += v2-v1;
975 }
976 printf("reasssembly test: %d trials, %d frags/pkt %d cycles/frag %d cycles/last frag\n",j,nfrags, sum1/(j*nfrags), sum2/(j));
977 }
978 #endif
980 /*--------------basic pktio send/recv benchmark----------------------*/
981 unsigned int timings[10];
982 void our_pktio_bench(int ntrials)
983 {
984 int i;
985 #define NBATCH 8
986 Ti_Pkt tip;
987 unsigned char * pData;
988 int len;
989 int n;
990 int err;
991 int sum =0;
993 Osal_cache_op_measure_reset();
994 for(i=0;i<10;i++) timings[i]=0;
995 printf("calibration loop .. ");
996 for(i=0;i<1000;i++)
997 {
998 vv1= hplib_mUtilGetTickCount();
999 vv2= hplib_mUtilGetTickCount();
1000 sum+=(vv2-vv1);
1001 }
1002 printf(" accuracy = +- %d cycles\n", sum/1000);
1003 sleep(1);
1005 PKTIO_METADATA_T meta[10]={0};
1006 //send single, recv single
1007 for(i=0;i<ntrials;i++)
1008 {
1009 vv1= hplib_mUtilGetTickCount();
1010 tip=Pktlib_allocPacket(OurHeap,PKT_LEN);
1011 vv2= hplib_mUtilGetTickCount();
1012 Pktlib_getDataBuffer(tip,&pData,&len);
1013 vv3= hplib_mUtilGetTickCount();
1014 pktio_send(our_chan,tip,&meta[0],&err);
1015 vv4= hplib_mUtilGetTickCount();
1016 n=pktio_poll(our_chan,NULL , &err);
1017 vv5= hplib_mUtilGetTickCount();
1018 timings[0]+=(vv6-vv4);
1019 timings[1]+=(vv5-vv4);
1020 timings[3]+=(vv4-vv3);
1021 timings[5]+=(vv3-vv1);
1022 timings[8]+=(vv11-vv6);
1024 #ifdef PKTIO_GET_BENCHMARK
1025 timings[2]+=(vv7p-vv4);
1026 timings[4]+=(vv8p-vv3);
1027 timings[6]+=(vv9p-vv8p);
1028 timings[7]+=(vv10p-vv7p);
1029 #endif
1030 }
1032 #ifdef PKTIO_GET_BENCHMARK
1033 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,
1034 timings[1]/ntrials, timings[2]/ntrials,timings[3]/ntrials, timings[4]/ntrials,timings[5]/ntrials,
1035 timings[6]/ntrials,timings[7]/ntrials, timings[8]/ntrials );
1036 {
1037 unsigned long long ccycles;
1038 unsigned long long n_c_ops;
1039 ccycles =Osal_cache_op_measure(&n_c_ops);
1040 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);
1041 }
1042 #endif
1044 }
1045 /*-----------test driver: gen an input pkt------- */
1046 //char buffer[sizeof(HEAD_T)+PKT_LEN];
1047 Ti_Pkt * get_pkt(int n, unsigned int *p_len, Pktlib_HeapHandle heap2use, int size, unsigned char * buf2cpy, int copy_size)
1048 {
1049 int ind;
1050 long long temp;
1051 Ti_Pkt * b;
1052 char * buffer;
1053 unsigned int len;
1055 if (pktloopback==0)
1056 {
1057 if (n>=TX_BURST) return NULL; //just gen pkts to warm swtich, so that it knows
1058 //our mac is valid
1059 }
1060 b=Pktlib_allocPacket(heap2use,size);
1061 if (!b)
1062 {printf("net_test: get_pkt() heap empty!! %d pkts gen'd %d \n", n); return NULL;};
1064 //debug - way to validate descriptor
1065 {Ti_Pkt* k= Pktlib_getNextPacket(b);
1066 if(k != 0) {printf(" genpkt, nexpkt != NULL");}}
1069 //get pointer to buffer area of packet
1070 Pktlib_getDataBuffer(b,(uint8_t**)&buffer,&len);
1071 if (!buffer)
1072 {printf("net_test: get_pkt() heap returned empty buffer %d \n", n); return NULL;};
1074 #if 0
1075 if (pktloopback==0)
1076 {
1077 temp = (long long) rand();
1078 temp *= PKT_LEN;
1079 temp /= RAND_MAX;
1080 temp +=2;
1081 *p_len = (int) temp;
1082 *p_len = *p_len &0xfffffffe;
1083 temp = (long long) rand();
1084 temp *= n_pkt;
1085 temp /= RAND_MAX;
1086 ind = (int) temp;
1087 update_header(&pkts[ind],*p_len);
1088 //printf("get pkt:%d %d ind=%d len=%d\n",RAND_MAX, rand(),ind, *p_len);
1089 memcpy(&buffer[0], &mac_header[0],14);
1090 memcpy(&buffer[14],(char*)&pkts[ind],sizeof(HEAD_T));
1091 }
1092 else
1093 #endif
1095 //copy test packet into buffer
1096 {
1097 memcpy(&buffer[0], buf2cpy, copy_size);
1098 *p_len = copy_size;
1099 }
1100 return b;
1101 }
1103 static int eof=0;
1104 /*--------------------------------------------------------------
1105 *----------utility to flip a packet and send
1106 *--------------------back to source----------------------------
1107 * flag=1 => ipsec
1108 *--------------------------------------------------------------*/
1109 void flip_and_send_pkt(Ti_Pkt *tip, unsigned char * p_pkt, int len, int flag)
1110 {
1111 unsigned char mac_temp[6];
1112 unsigned char ip_temp[4];
1113 unsigned char new_dest_port[2]={0x75,0x30}; // 30000
1114 uint16_t blah;
1115 uint16_t i=1; /* for testing only */
1117 uint8_t *p_spi;
1118 netTestSA_t * p_sa_info;
1119 uint8_t p_iv[16];
1120 uint8_t p_add[8];
1121 Cppi_HostDesc* pPloadDesc;
1123 //netapi_dump_buf((long*)p_pkt,len);
1124 Pktlib_setPacketLen(tip,len);
1125 //flip the mac address
1126 memcpy(&mac_temp,&p_pkt[0],6);
1127 memcpy(&p_pkt[0],&p_pkt[6],6);
1128 memcpy(&p_pkt[6],&mac_temp,6);
1129 //memcpy(&p_pkt[0],real_mac_header,6); //for testing to wireshark pc
1131 //flip the ip (outer in case of ipsec)
1132 memcpy(&ip_temp, &p_pkt[14+12],4);
1133 memcpy(&p_pkt[14+12],&p_pkt[14+12+4],4);
1134 memcpy(&p_pkt[14+12+4],&ip_temp,4);
1137 //outer checksum to 0
1138 if (!flag)
1139 {
1140 memset(&p_pkt[14+10],0,2);
1141 }
1143 //inner ip &udp for ipsec
1144 if (flag)
1145 {
1146 p_spi = &(p_pkt[netTest_MAC_HEADER_LEN+netTest_IP_HEADER_LEN]);
1147 p_sa_info = (netTestSA_t *) trie_lookup(p_trie_sa, (char *)p_spi ,4);
1148 if (p_sa_info == NULL)
1149 {
1150 printf("flip_and_send_pkt(): trie_lookup() failed\n");
1151 return;
1152 }
1153 //just drop non-udp packet
1154 if (p_pkt[p_sa_info->tx_payload_info.encOffset+9]!=0x11)
1155 {
1156 stats.n_new+=1;Pktlib_freePacket(tip); return;
1157 }
1159 /* flip inner IP */
1160 memcpy(&ip_temp, &p_pkt[p_sa_info->tx_payload_info.encOffset+12],4);
1161 memcpy(&p_pkt[p_sa_info->tx_payload_info.encOffset+12],&p_pkt[p_sa_info->tx_payload_info.encOffset+12+4],4);
1162 memcpy(&p_pkt[p_sa_info->tx_payload_info.encOffset+12+4],&ip_temp,4);
1164 /* setting udp ports */
1165 memcpy(&p_pkt[p_sa_info->tx_payload_info.encOffset+20+2],&new_dest_port[0],2);
1166 memset(&p_pkt[p_sa_info->tx_payload_info.encOffset+20+6],0,2); //checksum
1168 if (config.ipsec_mode_tx == IPSEC_MODE_TX_SIDEBAND)
1169 {
1170 /* inner ip checksum : leave alone */
1171 /* outer ip, set to 0 (we will compute on way out */
1172 memset(&p_pkt[14+10],0,2);
1173 }
1174 else
1175 {
1176 //#else //inflow, don't touch outer , clear inner
1177 //DALmemset(&p_pkt[14+20+8+16+10],0,2); //inner checksum, we will compute on way out
1178 //outer ip checksum : leave alone
1179 }
1180 }
1181 else
1182 {
1183 memset(&p_pkt[14+20+6],0,2);//0 udp checksum (we will compute on way out
1184 memcpy(&p_pkt[14+20+2],&new_dest_port[0],2);
1185 }
1187 /*IPSEC case */
1188 if (flag)
1189 {
1190 if (config.ipsec_mode_tx == IPSEC_MODE_TX_SIDEBAND)
1191 //send to crypto for encryption
1192 //12 byte auth tag
1193 {
1194 PKTIO_METADATA_T meta = {PKTIO_META_SB_TX,{0},0};
1195 int err;
1196 nwalDmTxPayloadInfo_t meta_tx={0};
1197 meta.sa_handle=p_sa_info->tx_data_mode_handle; //use TX SA context
1199 memcpy(&meta_tx, &(p_sa_info->tx_payload_info), sizeof(nwalDmTxPayloadInfo_t));
1202 meta_tx.encSize = len - p_sa_info->tx_payload_info.encOffset -p_sa_info->auth_tag_size;
1203 meta_tx.authSize = len - meta_tx.authOffset - p_sa_info->auth_tag_size;
1205 #if 0
1206 printf("flip_and_send_pkt(): encOffset %d\n", meta_tx.encOffset);
1207 printf("flip_and_send_pkt():authOffset %d\n", meta_tx.authOffset);
1208 printf("flip_and_send_pkt(): encSize %d\n", meta_tx.encSize);
1209 printf("flip_and_send_pkt(): authSize %d\n", meta_tx.authSize);
1210 #endif
1212 meta_tx.pAuthIV=NULL;
1213 meta_tx.aadSize=0;
1214 meta_tx.pAad=NULL;
1215 if (p_sa_info->cipherMode == NWAL_SA_EALG_AES_CTR)
1216 {
1217 memcpy(&p_iv[0], &ourEncrKey[16], 4);
1218 memcpy(&p_iv[4], &p_pkt[netTest_MAC_HEADER_LEN +netTest_IP_HEADER_LEN + netTest_ESP_HEADER_LEN], 8);
1219 p_iv[12] = 0;
1220 p_iv[13] = 0;
1221 p_iv[14] = 0;
1222 p_iv[15] = 1;
1223 meta_tx.pEncIV = &p_iv[0];
1224 }
1225 else if ((p_sa_info->cipherMode == NWAL_SA_EALG_AES_GCM) ||
1226 (p_sa_info->cipherMode == NWAL_SA_EALG_AES_CCM))
1227 {
1228 memcpy(&p_iv[0], &p_pkt[netTest_MAC_HEADER_LEN +netTest_IP_HEADER_LEN + netTest_ESP_HEADER_LEN], 8);
1229 meta_tx.pEncIV = &p_iv[0];
1230 memcpy(&p_add[0], &p_pkt[netTest_MAC_HEADER_LEN +netTest_IP_HEADER_LEN], 8);
1231 meta_tx.pAad= &p_add[0];
1232 meta_tx.aadSize = 8;
1233 }
1234 else if (p_sa_info->cipherMode == NWAL_SA_EALG_NULL)
1235 {
1236 meta_tx.pEncIV = NULL;
1237 }
1238 else
1239 {
1240 meta_tx.pEncIV = &p_pkt[netTest_MAC_HEADER_LEN +netTest_IP_HEADER_LEN + netTest_ESP_HEADER_LEN ];
1241 }
1242 //meta_tx.authIvSize=0;
1244 /* post it to netcp sb tx channel*/
1245 meta_tx.appCtxId = (nwal_AppId)hplib_mUtilGetTickCount();
1246 meta.u.tx_sb_meta=&meta_tx;
1248 #ifdef NET_TEST_ENABLE_SIDE_BAND_LOW_LEVEL_API
1249 /* Use the command label which was cached during create time
1250 * Update the Queue to receive output packet from SA to the local
1251 * core Queue. Below information can be saved by application in
1252 * per process context to avoid API overhead per packet
1253 * Application can use below rxSbSaQ for polling packets back from
1254 * SA
1255 */
1256 nwalRetVal =
1257 nwal_getLocCxtInfo(PKTIO_GET_NWAL_INSTANCE(netcp_sb_tx_chan),
1258 &nwalLocCxt);
1259 if(nwalRetVal == nwal_OK)
1260 {
1261 p_sa_info->tx_dmPSCmdInfo.rxSbSaQ = nwalLocCxt.rxSbSaQ;
1262 }
1263 nwal_mCmdDMUpdate(tip,
1264 &p_sa_info->tx_dmPSCmdInfo,
1265 meta_tx.appCtxId,
1266 meta_tx.encOffset,
1267 meta_tx.encSize,
1268 meta_tx.pEncIV,
1269 meta_tx.authOffset,
1270 meta_tx.authSize,
1271 meta_tx.pAuthIV,
1272 meta_tx.aadSize,
1273 meta_tx.pAad);
1274 pPloadDesc = Pktlib_getDescFromPacket(tip);
1275 pPloadDesc = Qmss_osalConvertDescVirtToPhy(pPloadDesc);
1276 Qmss_queuePushDescSizeRaw(p_sa_info->tx_dmPSCmdInfo.txQueue,
1277 pPloadDesc,
1278 NWAL_DESC_SIZE);
1280 #else
1281 //printf("flip_and_send_pkt(): sending for encryption\n");
1282 pktio_send(netcp_sb_tx_chan,tip,&meta,&err);
1283 #endif
1284 }
1285 else
1286 {
1287 //inflow tx
1288 //send pkt directly, asking for IP and UDP checksum offloads AND IPSEC to be applied
1289 PKTIO_METADATA_T meta = {PKTIO_META_TX,{0},0};
1290 int err;
1291 nwalTxPktInfo_t meta_tx={0};
1292 #define USE_COPY
1293 #ifdef USE_COPY
1294 //debug: see if re-using RX descriptor for TX is causing our SA lockup
1295 {
1296 int new_len=0;
1297 Ti_Pkt new_tip = get_pkt(0, &new_len, specialLarge , len+10 , &p_pkt[0] , len);
1298 if (!new_tip)
1299 {
1300 printf("net_test> new_tip NULL\n");
1301 }
1302 else
1303 {
1304 Pktlib_setPacketLen(new_tip,new_len);
1305 Pktlib_freePacket(tip);
1306 tip=new_tip;
1307 Pktlib_getDataBuffer(tip,(uint8_t**)&p_pkt,&new_len); //reset p_pkt to point to new buffer as its used below
1308 Cppi_setTimeStamp (Cppi_DescType_HOST, (Cppi_Desc *) tip,stats.sec_tx);
1309 }
1310 }
1311 if (len <1500)
1312 {
1313 eof+=1;
1314 }
1315 #endif
1316 meta.sa_handle=p_sa_info->tx_inflow_mode_handle; //this tells netapi that inflow crypto needs to be applied
1317 //meta_tx.txFlag1 = (NWAL_TX_FLAG1_DO_IPV4_CHKSUM|NWAL_TX_FLAG1_DO_UDP_CHKSUM| NWAL_TX_FLAG1_DO_IPSEC_ESP_CRYPTO| NWAL_TX_FLAG1_META_DATA_VALID );
1318 meta_tx.txFlag1 = p_sa_info->tx_pkt_info.txFlag1;
1319 meta_tx.enetPort=0;
1320 //meta_tx.saOffBytes=14+20;
1321 meta_tx.saOffBytes= p_sa_info->tx_pkt_info.saOffBytes;
1322 meta_tx.saPayloadLen=len-14-20; //don't include tag, mac and outer header
1323 //meta_tx.startOffset = 0;
1324 meta_tx.startOffset = p_sa_info->tx_pkt_info.startOffset;
1325 //meta_tx.ipOffBytes = 14+20+8+16; //to inner header
1326 meta_tx.ipOffBytes =p_sa_info->tx_payload_info.encOffset;
1327 //meta_tx.l4OffBytes = 14+20+8+16+20; //to L4
1328 meta_tx.l4OffBytes = p_sa_info->tx_pkt_info.l4OffBytes;
1329 meta_tx.l4HdrLen = p_sa_info->tx_pkt_info.l4HdrLen;
1330 meta_tx.ploadLen = (unsigned) ((p_pkt[meta_tx.l4OffBytes+4]<<8)|p_pkt[meta_tx.l4OffBytes+4+1]) -8 ;
1331 meta_tx.pseudoHdrChecksum =
1332 test_utilGetIpv4PsudoChkSum(&p_pkt[meta_tx.ipOffBytes],8+ meta_tx.ploadLen);
1334 /* post it to netcp tx channel*/
1335 meta.u.tx_meta=&meta_tx;
1336 if (stats.sec_tx<20) dump_descr((long *) tip, stats.sec_tx);
1337 pktio_send(netcp_tx_chan,tip,&meta,&err);
1338 stats.tx +=1;
1339 stats.sec_tx +=1;
1340 }
1341 }
1342 else //non ipsec send pkt directly, asking for IP and UDP checksum ofload
1343 {
1344 PKTIO_METADATA_T meta2 = {PKTIO_META_TX,{0},0};
1345 int err;
1346 nwalTxPktInfo_t meta_tx2={0};
1347 meta2.sa_handle=nwal_HANDLE_INVALID;
1348 meta_tx2.txFlag1 = (NWAL_TX_FLAG1_DO_IPV4_CHKSUM|NWAL_TX_FLAG1_DO_UDP_CHKSUM| NWAL_TX_FLAG1_META_DATA_VALID );
1349 meta_tx2.startOffset = 0;
1350 meta_tx2.ipOffBytes = 14;
1351 meta_tx2.l4OffBytes = 14+20;
1352 meta_tx2.l4HdrLen = 8;
1353 meta_tx2.ploadLen = (unsigned) ((p_pkt[14+20+4]<<8)|p_pkt[14+20+4+1]) -8 ;
1354 meta_tx2.pseudoHdrChecksum =
1355 test_utilGetIpv4PsudoChkSum(&p_pkt[14],8+ meta_tx2.ploadLen);
1357 /* post it to netcp tx channel*/
1358 meta2.u.tx_meta=&meta_tx2;
1359 pktio_send(netcp_tx_chan,tip,&meta2,&err);
1360 stats.tx +=1;
1361 }
1362 }
1367 /***************************************
1368 benchmark receive handler
1369 ****************************************/
1370 void recv_cb_bench(struct PKTIO_HANDLE_Tag * channel, Ti_Pkt* p_recv[],
1371 PKTIO_METADATA_T meta[], int n_pkts,
1372 uint64_t ts )
1373 {
1374 int i;
1375 vv6= hplib_mUtilGetTickCount();
1376 for (i=0;i<n_pkts; i++)
1377 {
1378 Pktlib_freePacket(p_recv[i]);
1379 }
1380 vv11 = hplib_mUtilGetTickCount();
1381 }
1383 /****************************************************************************************/
1384 /******************SB Accelerator Callback PKT RECEIVE HANDLER *************************/
1385 /****************** Handles Decrypt and Encrypt operation callbacks ******************/
1386 /******************************************************************************************/
1387 void recv_sb_cb(struct PKTIO_HANDLE_Tag * channel, Ti_Pkt* p_recv[],
1388 PKTIO_METADATA_T meta[], int n_pkts,
1389 uint64_t ts )
1390 {
1391 int i;
1392 int len;
1393 int p;
1394 HEAD_T * p_res;
1395 Ti_Pkt * tip;
1396 unsigned int templen;
1397 int err;
1398 KEY_T key;
1399 char * p_pkt;
1400 HEAD_T * p_head;
1401 HEAD_T temp_head;
1402 int tag_cmp=0;
1403 unsigned int hash[4];
1404 uint8_t *p_spi;
1405 netTestSA_t *p_sa_info;
1407 //nwal_AppId time;
1408 unsigned long time, delta_time;
1409 /* loop over received pkts */
1410 for(i=0;i<n_pkts;i++)
1411 {
1412 tip = p_recv[i];
1413 Pktlib_getDataBuffer(tip,(uint8_t**)&p_pkt,&templen);//ignore templen
1414 len = Pktlib_getPacketLen(tip);//real length
1417 p_spi = &(p_pkt[netTest_MAC_HEADER_LEN+netTest_IP_HEADER_LEN]);
1419 p_sa_info = (netTestSA_t *) trie_lookup(p_trie_sa, (char *)p_spi ,4);
1420 if (p_sa_info == NULL)
1421 {
1422 printf("recv_sb_cb(): trie_lookup failed\n");
1423 continue;
1424 }
1427 //is this a decrypt (rx_tunnel) complete
1428 if ((int)meta[i].u.rx_sb_meta->appId == p_sa_info->rx_tunnel)
1429 {
1431 time = hplib_mUtilGetTickCount();
1432 delta_time = time -(unsigned long) meta[i].u.rx_sb_meta->appCtxId;
1433 stats.total_decrypt_time += delta_time;
1434 stats.sb_rx+=1;
1435 //copy hash out of meta data (for some reason it needs endian conversion)
1436 hash[0]= htonl( meta[i].u.rx_sb_meta->pAuthTag[0]);
1437 hash[1]= htonl( meta[i].u.rx_sb_meta->pAuthTag[1]);
1438 hash[2]= htonl( meta[i].u.rx_sb_meta->pAuthTag[2]);
1439 hash[3]= htonl( meta[i].u.rx_sb_meta->pAuthTag[3]);
1440 if(stats.sb_rx<=16)
1441 {
1442 char *tp = (char *) &hash[0];
1443 //dump_header((long*)p_pkt, stats.sb_rx, (int)meta[i].u.rx_sb_meta->appId,0);
1444 #if 0
1445 printf("decrypt complete: tag in pkt= %x %x %x %x %x %x %x %x %x %x %x %x %x %x %x %x \n",
1446 p_pkt[len-16],p_pkt[len-15],p_pkt[len-14],p_pkt[len-13],
1447 p_pkt[len-12],p_pkt[len-11],p_pkt[len-10],p_pkt[len-9], p_pkt[len-8],
1448 p_pkt[len-7],p_pkt[len-6],
1449 p_pkt[len-5],p_pkt[len-4],p_pkt[len-3],p_pkt[len-2],p_pkt[len-1]);
1450 printf("decrypt complete: tag from SA=%x %x %x %x %x %x %x %x %x %x %x %x %x %x %x %x \n",
1451 tp[0],tp[1],tp[2],tp[3],tp[4],tp[5],
1452 tp[6],tp[7],tp[8],tp[9],tp[10],tp[11],tp[12],tp[13],tp[14],tp[15]);
1454 // netapi_dump_buf((long*)p_pkt,len);
1455 #endif
1456 }
1457 //check tag
1458 //printf("recv_sb_cb(); auth tag size %d\n", p_sa_info->auth_tag_size);
1459 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
1460 stats.n_auth_ok += !(tag_cmp);
1462 flip_and_send_pkt(tip, p_pkt, len,1); //flip packet to echo back and send
1463 }
1464 //this is an encrypt (tx tunnel) complete
1465 else if((int)meta[i].u.rx_sb_meta->appId== p_sa_info->tx_tunnel )
1466 {
1467 hash[0]= htonl( meta[i].u.rx_sb_meta->pAuthTag[0]);
1468 hash[1]= htonl( meta[i].u.rx_sb_meta->pAuthTag[1]);
1469 hash[2]= htonl( meta[i].u.rx_sb_meta->pAuthTag[2]);
1470 hash[3]= htonl( meta[i].u.rx_sb_meta->pAuthTag[3]);
1471 stats.sb_tx+=1;
1472 if(stats.sb_tx<=16)
1473 {
1474 char *tp1 = (char *) &hash[0];
1475 //dump_header((long*)p_pkt, stats.sb_tx, (int)meta[i].u.rx_sb_meta->appId,0);
1476 #if 0
1477 printf("encrypt complete: tag in pkt= %x %x %x %x %x %x %x %x %x %x %x %x %x %x %x %x \n",
1478 p_pkt[len-16],p_pkt[len-15],p_pkt[len-14],p_pkt[len-13],
1479 p_pkt[len-12],p_pkt[len-11],p_pkt[len-10],p_pkt[len-9], p_pkt[len-8],
1480 p_pkt[len-7],p_pkt[len-6],
1481 p_pkt[len-5],p_pkt[len-4],p_pkt[len-3],p_pkt[len-2],p_pkt[len-1]);
1482 printf("encrypt complete: tag from SA=%x %x %x %x %x %x %x %x %x %x %x %x %x %x %x %x \n",
1483 tp1[0],tp1[1],tp1[2],tp1[3],tp1[4],tp1[5],
1484 tp1[6],tp1[7],tp1[8],tp1[9],tp1[10],tp1[11],tp1[12],tp1[13],tp1[14],tp1[15]);
1485 //netapi_dump_buf((long*)p_pkt,len);
1486 #endif
1487 }
1488 //put the computed tag in the packet
1489 memcpy(&p_pkt[len-p_sa_info->auth_tag_size],(char*)&hash[0],p_sa_info->auth_tag_size); //todo, really use meta->authTagLen
1490 // printf("recv_sb_cb(): dumping pkt after updating computed tag, len %d, auth tag size %d\n", len, p_sa_info->auth_tag_size);
1491 //netapi_dump_buf(p_pkt, len);
1492 {
1493 PKTIO_METADATA_T meta2 = {PKTIO_META_TX,{0},0};
1494 nwalTxPktInfo_t meta_tx={0};
1495 // now send directly
1496 meta2.sa_handle=nwal_HANDLE_INVALID;
1497 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
1498 meta_tx.startOffset = 0;
1499 meta_tx.ipOffBytes = netTest_MAC_HEADER_LEN;
1500 //not used
1501 meta_tx.l4OffBytes = 0;
1502 meta_tx.l4HdrLen = 0;
1503 meta_tx.ploadLen = 0;
1504 time = hplib_mUtilGetTickCount();
1505 delta_time = time -(unsigned long) meta[i].u.rx_sb_meta->appCtxId;
1506 stats.total_encrypt_time += delta_time;
1509 /* post it to netcp tx channel*/
1510 meta2.u.tx_meta=&meta_tx;
1511 // printf("recv_sb_cb(): calling pktio send to send it to network\n");
1512 pktio_send(netcp_tx_chan,tip,&meta2,&err);
1513 hplib_CacheWbInv(p_pkt,len);
1514 stats.tx +=1;
1515 }
1516 }
1517 else printf("netapi recv_sb_cb: unknown appiD %x \n",meta[i].u.rx_sb_meta->appId );
1518 }
1519 }
1521 /******************************************************/
1522 /******************PKT RECEIVE HANDLER *************************/
1523 /******************************************************/
1524 void recv_cb(struct PKTIO_HANDLE_Tag * channel, Ti_Pkt* p_recv[],
1525 PKTIO_METADATA_T meta[], int n_pkts,
1526 uint64_t ts )
1527 {
1528 int i;
1529 int len;
1530 int p;
1531 HEAD_T * p_res;
1532 Ti_Pkt * tip;
1533 unsigned int templen;
1534 int err = 0;
1535 KEY_T key;
1536 char * p_pkt;
1537 HEAD_T * p_head;
1538 HEAD_T temp_head;
1539 netTestSA_t *p_sa_info;
1540 uint8_t *p_spi;
1541 uint8_t p_iv[16];
1542 uint8_t p_add[8];
1543 uint8_t p_add1[1500];
1544 int16_t retVal;
1545 nwalGlobCxtInfo_t nwalGlobCxt;
1546 nwalLocCxtInfo_t nwalLocCxt;
1548 Cppi_HostDesc* pPloadDesc;
1549 int ifno;
1550 #ifdef MULTI_THREAD
1551 int coreid=our_core; //who we are(thread local)
1552 #else
1553 int coreid=0;
1554 #endif
1555 p_head=&temp_head;
1557 /* loop over received pkts */
1558 for(i=0;i<n_pkts;i++)
1559 {
1560 ifno = ((unsigned int)meta[i].u.rx_meta->appId)&0xff;
1561 if(coreid<TUNE_NETAPI_NUM_CORES) stats.core_rx[coreid]+=1;
1562 if (ifno < TUNE_NETAPI_MAX_INTERFACES) stats.if_rx[ifno]+=1;
1564 tip = p_recv[i];
1566 Pktlib_getDataBuffer(tip,(uint8_t**)&p_pkt,&templen);/*ignore templen */
1567 len = Pktlib_getPacketLen(tip)-4; /*real length, subtract mac trailer */
1568 Cppi_setData (Cppi_DescType_HOST, (Cppi_Desc *) tip, p_pkt,len);
1569 Pktlib_setPacketLen(tip,len);
1570 //printf("recv_cb() packet len %d\n", len);
1572 //debug: validate descriptor */
1573 if(Pktlib_getNextPacket(tip) != 0)
1574 {
1575 printf(" rcv_cb, nexpkt != NULL");
1576 }
1578 stats.rx+=1;
1580 #ifdef DEBUG_DESC
1581 if (stats.rx<16)
1582 {
1583 printf(">rx dmp..");
1584 dump_descr((long *) tip, stats.rx);
1585 }
1586 else if (stats.rx>99)
1587 {
1588 printf(">rx dmp..");
1589 dump_descr((long *) tip,stats.rx);
1590 }
1591 #endif
1592 #if 0
1593 if(stats.rx<=16)
1594 {
1595 dump_header((long*)p_pkt, stats.rx, (int)meta[i].u.rx_meta->appId,meta[i].u.rx_meta->rxFlag1);
1596 netapi_dump_buf((long*)p_pkt,len);
1597 }
1598 #endif
1599 /* check header */
1600 memcpy(p_head,&p_pkt[14],sizeof(HEAD_T));
1602 /* check for IPSEC packet, 0x32 is ESP tunnel mode */
1603 if ((p_head->ip[2]&0x0000ff00)==0x00003200)
1604 {
1605 if (!check_header(p_head,&meta[i]))
1606 {
1607 stats.n_bad+=1;Pktlib_freePacket(tip);
1608 continue;
1609 }
1611 //process IP SEC PACKET
1612 if (config.ipsec_mode_rx == IPSEC_MODE_RX_SIDEBAND)
1613 {
1615 p_spi = &(p_pkt[netTest_MAC_HEADER_LEN+netTest_IP_HEADER_LEN]);
1616 p_sa_info = (netTestSA_t *) trie_lookup(p_trie_sa, (char *)p_spi ,4);
1617 if (p_sa_info == NULL)
1618 {
1619 printf("recv_cb(): trie_lookup() failed\n");
1620 continue;
1621 }
1623 //ship to crypto for decrypt!!
1624 //12 byte auth tag
1625 PKTIO_METADATA_T meta2 = {PKTIO_META_SB_TX,{0},0};
1626 nwalDmTxPayloadInfo_t meta_tx={0};
1627 meta2.sa_handle=p_sa_info->rx_data_mode_handle;
1629 memcpy(&meta_tx, &(p_sa_info->tx_payload_info), sizeof(nwalDmTxPayloadInfo_t));
1631 //meta_tx.ploadLen = len;
1635 meta_tx.encSize = len - p_sa_info->tx_payload_info.encOffset -p_sa_info->auth_tag_size;
1636 meta_tx.authSize = len - meta_tx.authOffset - p_sa_info->auth_tag_size;
1640 #if 0
1641 printf("recv_cb(): packet length %d\n", len);
1642 printf("recv_cb(): encOffset %d\n", meta_tx.encOffset);
1643 printf("recv_cb():authOffset %d\n", meta_tx.authOffset);
1644 printf("recv_cb(): encSize %d\n", meta_tx.encSize);
1645 printf("recv_cb(): authSize %d\n", meta_tx.authSize);
1646 #endif
1648 if (p_sa_info->cipherMode == NWAL_SA_EALG_AES_CTR)
1649 {
1650 memcpy(&p_iv[0], &ourEncrKey[16], 4);
1651 memcpy(&p_iv[4], &p_pkt[netTest_MAC_HEADER_LEN +netTest_IP_HEADER_LEN + netTest_ESP_HEADER_LEN], 8);
1652 p_iv[12] = 0;
1653 p_iv[13] = 0;
1654 p_iv[14] = 0;
1655 p_iv[15] = 1;
1656 meta_tx.pEncIV = &p_iv[0];
1658 }
1659 else if ((p_sa_info->cipherMode == NWAL_SA_EALG_AES_GCM) ||
1660 (p_sa_info->cipherMode == NWAL_SA_EALG_AES_CCM))
1661 {
1662 memcpy(&p_iv[0], &p_pkt[netTest_MAC_HEADER_LEN +netTest_IP_HEADER_LEN + netTest_ESP_HEADER_LEN], 8);
1663 meta_tx.pEncIV = &p_iv[0];
1664 /* aad is the ESP header which is 8 bytes */
1665 memcpy(&p_add[0], &p_pkt[netTest_MAC_HEADER_LEN +netTest_IP_HEADER_LEN], 8);
1666 meta_tx.pAad= &p_add[0];
1667 meta_tx.aadSize = 8;
1668 }
1669 else if (p_sa_info->cipherMode == NWAL_SA_EALG_NULL)
1670 {
1671 meta_tx.pEncIV = NULL;
1672 }
1673 else
1674 {
1675 meta_tx.pEncIV = &p_pkt[netTest_MAC_HEADER_LEN +netTest_IP_HEADER_LEN + netTest_ESP_HEADER_LEN ];
1676 }
1678 meta_tx.appCtxId = (nwal_AppId)hplib_mUtilGetTickCount();
1679 //printf("recv_cb appCtxId: %lu\n", meta_tx.appCtxId);
1681 /* post it to netcp sb tx channel*/
1682 meta2.u.tx_sb_meta=&meta_tx;
1684 /* TODO: Move the following ifdef code into ptkio_sendDM */
1685 #ifdef NET_TEST_ENABLE_SIDE_BAND_LOW_LEVEL_API
1686 /* Use the command label which was cached during create time
1687 * Update the Queue to receive output packet from SA to the local
1688 * core Queue. Below information can be saved by application in
1689 * per process context to avoid API overhead per packet
1690 * Application can use below rxSbSaQ for polling packets back from
1691 * SA
1692 */
1693 nwalRetVal =
1694 nwal_getLocCxtInfo(PKTIO_GET_NWAL_INSTANCE(netcp_sb_tx_chan),
1695 &nwalLocCxt);
1696 if(nwalRetVal == nwal_OK)
1697 {
1698 p_sa_info->rx_dmPSCmdInfo.rxSbSaQ = nwalLocCxt.rxSbSaQ;
1699 }
1700 nwal_mCmdDMUpdate(tip,
1701 &p_sa_info->rx_dmPSCmdInfo,
1702 meta_tx.appCtxId,
1703 meta_tx.encOffset,
1704 meta_tx.encSize,
1705 meta_tx.pEncIV,
1706 meta_tx.authOffset,
1707 meta_tx.authSize,
1708 meta_tx.pAuthIV,
1709 meta_tx.aadSize,
1710 meta_tx.pAad);
1711 pPloadDesc = Pktlib_getDescFromPacket(tip);
1712 pPloadDesc = Qmss_osalConvertDescVirtToPhy(pPloadDesc);
1713 Qmss_queuePushDescSizeRaw(p_sa_info->rx_dmPSCmdInfo.txQueue,
1714 pPloadDesc,
1715 NWAL_DESC_SIZE);
1717 #else
1718 pktio_send(netcp_sb_tx_chan,tip,&meta2,&err);
1719 #endif
1720 continue;
1721 }
1722 else
1723 //inflow mode. flip and send
1724 flip_and_send_pkt(tip,p_pkt,len,1);
1725 }
1726 else if ((p_head->ip[2]&0x0000ff00)!=0x00001100)
1727 {
1728 stats.n_new+=1;Pktlib_freePacket(tip); continue;
1729 }
1730 else //non ipsec
1731 {
1732 if (!check_header(p_head,&meta[i]))
1733 {
1734 stats.n_bad+=1;Pktlib_freePacket(tip);
1735 continue;
1736 }
1738 #if 0
1739 /* lookup flow */
1740 key.src_ip = p_head->ip[3];
1741 key.dst_ip = p_head->ip[4];
1742 key.src_port= (p_head->udp[0]&0xffff0000)>>16;
1743 key.dst_port= (p_head->udp[0]&0x0000ffff);
1744 p_res= (HEAD_T *) trie_lookup(P_trie, (char *) &key, sizeof(key));
1745 if (!p_res) { stats.n_new+=1; slow_path(tip, len); continue;}
1747 /* copy header */
1748 memcpy((char *) p_head, (char *) p_res, sizeof(HEAD_T));
1750 memcpy(&p_pkt[14],p_head,sizeof(HEAD_T));
1751 /* update_mac(&p_pkt[0]); */
1753 /* 'simulate' send pkt */
1754 send_pkt(tip,len);
1755 #endif
1756 //just flip and send
1757 flip_and_send_pkt(tip,p_pkt,len,0);
1758 }
1759 }
1760 //printf("recv done\n");
1761 }
1763 #ifdef TEST_TIMERS
1764 //timer callback
1765 void our_timer_cb( HPLIB_TIMER_GROUP_HANDLE_T th,
1766 int n_fired, //# timers fired
1767 HPLIB_TIMER_LIST_T fired_list,
1768 uint64_t currentTime)
1769 {
1770 int i;
1771 HPLIB_TIMER_T tx;
1772 int cookie;
1773 int err;
1774 unsigned long long et;
1775 //DEBUGprintf("TIMER CALLBACK @ %lld %d timers\n", currentTime, n_fired);
1776 tx = hplib_Timer_GetFirst(fired_list);
1777 for(i=0;i<n_fired;i++)
1778 {
1779 cookie = (int) hplib_Time_rGetCookie(tx);
1780 et = hplib_Timer_GetTs(tx); //debug
1781 //DEBUGprintf(" timer %d - cookie = %d expected ts=%lld (delta=%lld)\n", i, cookie, et, currentTime-et);
1782 if (cookie ==1)
1783 {
1784 stats.n_t1+=1;
1785 t1 = hplib_Timer_Start(
1786 th,
1787 (void *) 1,
1788 100LL, //timer group tics
1789 &err);
1790 }
1791 else if (cookie ==2)
1792 {
1793 stats.n_t2+=1;
1794 t2 = hplib_Timer_Start(
1795 th,
1796 (void *) 2,
1797 200LL, //timer group ticks
1798 &err);
1799 }
1800 else
1801 {
1802 stats.n_t3+=1;
1803 t3 = hplib_Timer_Start(
1804 th,
1805 (void *) 3,
1806 300LL, //timer group ticks
1807 &err);
1808 //cancel 1 and restart 1
1809 hplib_Timer_Cancel(th,t1,&err);
1810 t1 = hplib_Timer_Start(
1811 th,
1812 (void *) 1,
1813 100LL, //timer group ticks
1814 &err);
1815 }
1816 tx = hplib_Timer_GetNext(fired_list,tx);
1817 }
1818 }
1819 #endif
1820 void print_ipsec_stats(Sa_IpsecStats_t *p_saIpsecStats, nwal_saAALG auth, nwal_saEALG cipher)
1821 {
1822 #if 0
1823 if(retVal != nwal_OK)
1824 {
1825 System_printf("CORE: %d Error getting IP Sec Stats: Ret Status: %d \n",
1826 retVal);
1827 return(nwal_FALSE);
1828 }
1829 if((p_saIpsecStats->pktEncHi) ||(p_saIpsecStats->pktEncLo))
1830 {
1831 printf("------------- IPSec TX (Encryption Channel) Stats BEGIN --\n");
1832 }
1833 else
1834 {
1835 printf("------------- IPSec RX (Decryption Channel) Stats BEGIN --\n");
1836 }
1837 #endif
1838 printf("\nAutentication mode: %d, Encryption Mode: %d\n", auth, cipher);
1839 printf("IPSec replayOld:0x%x,replayDup:0x%x,authFail:0x%x \n",
1840 p_saIpsecStats->replayOld,p_saIpsecStats->replayDup,p_saIpsecStats->authFail);
1841 printf("IPSec txESN:0x%x,rxESN:0x%x,pktEncHi:0x%x,pktEncLo:0x%x,pktDecHi:0x%x,pktDecLo:0x%x \n",
1842 p_saIpsecStats->txESN,p_saIpsecStats->rxESN,p_saIpsecStats->pktEncHi,
1843 p_saIpsecStats->pktEncLo,p_saIpsecStats->pktDecHi,p_saIpsecStats->pktDecLo);
1844 }
1846 void print_datamode_stats(Sa_DataModeStats_t *p_saDataModeStats, nwal_saAALG auth, nwal_saEALG cipher)
1847 {
1849 printf("\nAutentication mode: %d, Encryption Mode: %d\n", auth, cipher);
1850 printf(" Packets processedHi: 0x%x, Packets processed Lo:0x%x\n",
1851 p_saDataModeStats->pktHi, p_saDataModeStats->pktLo);
1852 }
1857 static int np2process = NP;
1858 /******************************************************
1859 * stats callback
1860 *******************************************************/
1861 void our_stats_cb_mt(NETAPI_T h, paSysStats_t* pPaStats)
1862 {
1863 stats.n_stats_cb +=1;
1864 if(pPaStats) memcpy(&netcp_stats,pPaStats, sizeof(paSysStats_t));
1865 }
1866 void our_stats_cb(NETAPI_T h, paSysStats_t* pPaStats)
1867 {
1868 uint32_t numFreeDataPackets;
1869 uint32_t numZeroBufferPackets;
1870 uint32_t numPacketsinGarbage;
1871 Pktlib_HeapStats pktLibHeapStats;
1872 int i;
1873 unsigned long long bcpp;
1874 unsigned long long bcpp_noc;
1875 unsigned long long bcpp_app;
1876 unsigned long long bcpp_tx;
1877 unsigned long long npL;
1878 unsigned long long cyclesL;
1879 unsigned long long ccyclesL; //cache cycles
1880 unsigned long long tmp_npL[TUNE_NETAPI_NUM_CORES];
1881 unsigned long long tmp_cyclesL[TUNE_NETAPI_NUM_CORES];
1882 unsigned long long tmp_ccyclesL[TUNE_NETAPI_NUM_CORES]; //cache cycles
1883 NETAPI_SA_STATS_T netapi_sa_stats;
1885 printf(">*****stats @ %lld (#cbs%d) \n", hplib_mUtilGetTimestamp(),stats.n_stats_cb);
1886 //printf("netcp_tx_handle check %x\n", netcp_tx_chan->back);
1887 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",
1888 stats.itx, stats.rx, stats.tx, stats.n_bad, stats.n_new,
1889 stats.n_class0_rx, stats.n_class1_rx,
1890 stats.n_class2_rx, stats.sec_rx, stats.secp_rx, stats.sb_rx, stats.sb_tx, stats.n_auth_ok,
1891 stats.sec_tx, stats.rx_min, stats.tx_min);
1892 printf(">if rx stats: %d %d %d\n",stats.if_rx[0],stats.if_rx[1],stats.if_rx[2]);
1893 printf(">core rx stats: %d %d %d\n",stats.core_rx[0],stats.core_rx[1],stats.core_rx[2]);
1896 if (stats.rx && stats.tx)
1897 printf("decrypt time per packet(avg): %lu, encrypt time per packet(avg): %lu\n",
1898 (unsigned long) stats.total_decrypt_time/stats.rx, (unsigned long) stats.total_encrypt_time/stats.tx);
1899 #ifdef MULTI_THREAD
1900 netapi_sched_get_stats(scheduler[0],&tmp_npL[0],&tmp_cyclesL[0],&tmp_ccyclesL[0]);
1901 netapi_sched_get_stats(scheduler[1],&tmp_npL[1],&tmp_cyclesL[1],&tmp_ccyclesL[1]);
1902 npL = tmp_npL[0]+tmp_npL[1];
1903 cyclesL = tmp_cyclesL[0]+tmp_cyclesL[1];
1904 ccyclesL = tmp_ccyclesL[0]+tmp_ccyclesL[1];
1905 #else
1906 netapi_sched_get_stats(our_sched, &npL,&cyclesL,&ccyclesL);
1907 #endif
1908 if (npL && stats.rx) {
1909 bcpp = cyclesL/npL;
1910 bcpp_noc = (cyclesL-ccyclesL)/npL;
1911 bcpp_app = (stats.app_cycles-stats.tx_cache_cycles)/stats.rx;
1912 }
1913 else {bcpp = bcpp_noc=bcpp_app=0L;}
1914 if (stats.tx)
1915 {
1916 bcpp_tx = (stats.send_cycles-stats.tx_cache_cycles)/stats.tx;
1917 }else {bcpp_tx = 0L;}
1918 printf("> ++ busy cycles pp=%lld (%lld wo cache ops) (app+tx= %lld) (tx= %lld) ++\n",
1919 bcpp,bcpp_noc,bcpp_app, bcpp_tx);
1920 if(pPaStats)
1921 {
1922 printf("C1 number of packets: %d\n", pPaStats->classify1.nPackets);
1923 printf("C1 number IPv4 packets: %d\n", pPaStats->classify1.nIpv4Packets);
1924 printf("C1 number IPv6 packets: %d\n", pPaStats->classify1.nIpv6Packets);
1925 printf("C1 number Custom packets: %d\n", pPaStats->classify1.nCustomPackets);
1926 printf("C1 number SRIO packets: %d\n", pPaStats->classify1.nSrioPackets);
1927 printf("C1 number LLC/SNAP Fail packets: %d\n", pPaStats->classify1.nLlcSnapFail);
1928 printf("C1 number table matched: %d\n", pPaStats->classify1.nTableMatch);
1929 printf("C1 number failed table matched: %d\n", pPaStats->classify1.nNoTableMatch);
1930 printf("C1 number IP Fragmented packets: %d\n", pPaStats->classify1.nIpFrag);
1931 printf("C1 number IP Depth Overflow: %d\n", pPaStats->classify1.nIpDepthOverflow);
1932 printf("C1 number VLAN Depth Overflow: %d\n", pPaStats->classify1.nVlanDepthOverflow);
1933 printf("C1 number GRE Depth Overflow: %d\n", pPaStats->classify1.nGreDepthOverflow);
1934 printf("C1 number MPLS Packets: %d\n", pPaStats->classify1.nMplsPackets);
1935 printf ("C1 number of parse fail: %d\n",pPaStats->classify1.nParseFail);
1936 printf("C1 number of Invalid IPv6 Opt: %d\n", pPaStats->classify1.nInvalidIPv6Opt);
1937 printf("C1 number of TX IP Fragments: %d\n", pPaStats->classify1.nTxIpFrag);
1938 printf ("C1 number of silent discard: %d\n",pPaStats->classify1.nSilentDiscard);
1939 printf("C1 number of invalid control: %d\n", pPaStats->classify1.nInvalidControl);
1940 printf ("C1 number of invalid states: %d\n",pPaStats->classify1.nInvalidState);
1941 printf ("C1 number of system fails: %d\n",pPaStats->classify1.nSystemFail);
1942 printf ("C2 number Packets : %d\n",pPaStats->classify2.nPackets);
1943 printf ("C2 number udp : %d\n",pPaStats->classify2.nUdp);
1944 printf ("C2 number tcp : %d\n",pPaStats->classify2.nTcp);
1945 printf ("C2 number Custom : %d\n",pPaStats->classify2.nCustom);
1946 printf ("C2 number silent drop : %d\n",pPaStats->classify2.nSilentDiscard);
1947 printf ("C2 number invalid cntrl : %d\n\n",pPaStats->classify2.nInvalidControl);
1948 printf ("C2 number Modify Stats Cmd Fail : %d\n\n",pPaStats->modify.nCommandFail);
1949 }
1950 Pktlib_getHeapStats(OurHeap, &pktLibHeapStats);
1951 printf("main heap stats> #free=%d #zb=%d #garbage=%d\n", pktLibHeapStats.numFreeDataPackets,
1952 pktLibHeapStats.numZeroBufferPackets, pktLibHeapStats.numPacketsinGarbage);
1953 printf(" > #dataBufThreshStatus=%d #dataBufStarvCounter=%d #zBufThreshStatus=%d #zBufStarvCounter=%d \n",
1954 pktLibHeapStats.dataBufferThresholdStatus,pktLibHeapStats.dataBufferStarvationCounter,
1955 pktLibHeapStats.zeroDataBufferThresholdStatus, pktLibHeapStats.zeroDataBufferStarvationCounter);
1957 Pktlib_getHeapStats(specialSmall, &pktLibHeapStats);
1958 printf("specialSmall heap stats> #free=%d #zb=%d #garbage=%d\n", pktLibHeapStats.numFreeDataPackets,
1959 pktLibHeapStats.numZeroBufferPackets, pktLibHeapStats.numPacketsinGarbage);
1960 printf(" > #dataBufThreshStatus=%d #dataBufStarvCounter=%d #zBufThreshStatus=%d #zBufStarvCounter=%d \n",
1961 pktLibHeapStats.dataBufferThresholdStatus,pktLibHeapStats.dataBufferStarvationCounter,
1962 pktLibHeapStats.zeroDataBufferThresholdStatus, pktLibHeapStats.zeroDataBufferStarvationCounter);
1965 Pktlib_getHeapStats(specialLarge, &pktLibHeapStats);
1966 printf("specialLarge heap stats> #free=%d #zb=%d #garbage=%d\n", pktLibHeapStats.numFreeDataPackets,
1967 pktLibHeapStats.numZeroBufferPackets, pktLibHeapStats.numPacketsinGarbage);
1968 printf(" > #dataBufThreshStatus=%d #dataBufStarvCounter=%d #zBufThreshStatus=%d #zBufStarvCounter=%d \n",
1969 pktLibHeapStats.dataBufferThresholdStatus,pktLibHeapStats.dataBufferStarvationCounter,
1970 pktLibHeapStats.zeroDataBufferThresholdStatus, pktLibHeapStats.zeroDataBufferStarvationCounter);
1973 #if 0
1974 printf("pa2sa descriptor area dump\n");
1975 for(i=0;i<TUNE_NETAPI_CONFIG_MAX_PA_TO_SA_DESC;i++)
1976 {
1977 extern long * pa2sa_descr_base;
1978 long * tip= &pa2sa_descr_base[32*i];
1979 dump_descr(tip, i);
1980 }
1981 printf("sa2pa descriptor area dump\n");
1982 for(i=0;i<TUNE_NETAPI_CONFIG_MAX_SA_TO_PA_DESC;i++)
1983 {
1984 extern long * sa2pa_descr_base;
1985 long * tip= &sa2pa_descr_base[32*i];
1986 dump_descr(tip, i);
1987 }
1988 #endif
1989 #ifdef TEST_TIMERS
1990 //debug = dump timer polling stats
1991 dump_poll_stats();
1992 //debug = dump timer polling stats
1993 //dump_poll_stats();
1994 #endif
1995 #ifndef EXPERIMENTAL
1996 for (i = 0; i < MAX_SEC_INDEX; i++)
1997 #else
1998 for (i=0; i < 1;i++)
1999 #endif
2000 {
2001 /* Statistics for RX Tunnel */
2002 memset(&netapi_sa_stats, 0, sizeof(netapi_sa_stats));
2003 netapi_getSaStats(netapi_handle, sa_info[i].rx_tunnel, &netapi_sa_stats);
2004 if (netapi_sa_stats.validParams & NETAPI_IPSEC_STAT_VALID)
2005 {
2006 print_ipsec_stats(&(netapi_sa_stats.saIpsecStats),
2007 rx_sa[i].authMode,
2008 rx_sa[i].cipherMode);
2009 }
2010 if (netapi_sa_stats.validParams & NETAPI_SIDEBAND_DATA_MODE_STAT_VALID)
2011 {
2012 print_datamode_stats(&(netapi_sa_stats.dataModeStats),
2013 rx_sa[i].authMode,
2014 rx_sa[i].cipherMode);
2015 }
2017 /* Statistics for TX Tunnel */
2018 memset(&netapi_sa_stats, 0, sizeof(netapi_sa_stats));
2019 netapi_getSaStats(netapi_handle, sa_info[i].tx_tunnel, &netapi_sa_stats);
2020 if (netapi_sa_stats.validParams & NETAPI_IPSEC_STAT_VALID)
2021 {
2022 print_ipsec_stats(&(netapi_sa_stats.saIpsecStats),
2023 tx_sa[i].authMode,
2024 tx_sa[i].cipherMode);
2025 }
2026 if (netapi_sa_stats.validParams & NETAPI_SIDEBAND_DATA_MODE_STAT_VALID)
2027 {
2028 print_datamode_stats(&(netapi_sa_stats.dataModeStats),
2029 tx_sa[i].authMode,
2030 tx_sa[i].cipherMode);
2031 }
2032 }
2033 netapi_dump_internal_heap_stats();
2034 }
2036 //******************************************************
2037 //use scheduling housekeeping callback to generate pkts
2038 //******************************************************
2039 static int done_burst=0;
2040 void house(NETAPI_SCHED_HANDLE_T * s)
2041 {
2042 Ti_Pkt * tip;
2043 unsigned int len;
2044 nwalTxPktInfo_t meta_tx = {0};
2045 PKTIO_METADATA_T meta = {PKTIO_META_TX,{0},0};
2046 int err;
2047 static int house_pkts_gened=0;
2048 int p;
2049 unsigned char * pIpHdr,* pData;
2050 unsigned int vv1,vv2,vv3;
2051 unsigned int sum_vv1=0;
2052 unsigned int sum_vv2=0;
2053 unsigned int sum_vv3=0;
2054 unsigned int sum_vv4=0;
2055 unsigned int sum_vv5=0;
2057 unsigned int nwal_flow_vv1,nwal_flow_vv2;
2058 unsigned int nwal_sum_vv1=0;
2059 unsigned int nwal_sum_vv2=0;
2060 unsigned int nwal_sum_vv3=0;
2061 unsigned int nwal_sum_vv4=0;
2062 unsigned int nwal_sum_vv5=0;
2063 unsigned int nwal_sum_vv6=0;
2065 unsigned int nwal_sum_flow_vv1=0;
2066 unsigned int nwal_sum_flow_vv2=0;
2067 unsigned long long cache_op_b1;
2068 unsigned long long cache_op_b2;
2069 unsigned long long n_c_ops;
2070 static int first =0;
2071 Cppi_HostDesc* pPktDesc;
2073 #ifdef MULTI_THREAD
2074 int coreid; //who we are
2075 NETAPI_T nh= netapi_schedGetNetapiHandle(s);
2076 coreid=(int) netapi_getCookie(nh);
2078 if (QUIT) {netapi_schedShutdown(s,NULL,&err); return;}
2080 if (coreid==0) //slave
2081 {
2082 netcp_cfgReqStats(nh, our_stats_cb_mt, 0,&err);
2083 }
2084 #else
2085 if(done_burst)
2086 {
2087 house_pkts_gened+=TX_BURST;
2088 printf("net_test> request stats at n=%d \n",house_pkts_gened);
2089 netcp_cfgReqStats(netapi_handle, our_stats_cb, 0,&err);
2090 if (err!=0) {printf("stats req failed\n");}
2091 if (house_pkts_gened >= np2process+ 100)
2092 {
2093 netapi_schedShutdown(s,NULL,&err);
2094 }
2095 return;
2096 }
2097 done_burst=1;
2098 Osal_cache_op_measure_reset();
2099 memset(&meta_tx,0,sizeof(meta_tx));
2100 for(p=0;p<TX_BURST;p++) {
2101 //reguest stats
2102 if ((house_pkts_gened>0) && (! (house_pkts_gened%1000)) )
2103 {
2104 printf("net_test> request stats at n=%d \n",house_pkts_gened);
2105 netcp_cfgReqStats(netapi_handle, our_stats_cb, 0,&err);
2106 if (err!=0) {printf("stats req failed\n");}
2107 }
2110 if (house_pkts_gened >= np2process+ 100)
2111 {
2112 //shutdown
2113 netapi_schedShutdown(s,NULL,&err);
2114 continue;
2115 }
2117 else if (house_pkts_gened >= np2process) { house_pkts_gened+=1; continue;}
2120 /* manufacture a pkt to transmit */
2121 tip = get_pkt(house_pkts_gened, &len, OurHeap, PKT_LEN,&testPkt[0] , TEST_PKT_LEN);
2122 if(!tip) { house_pkts_gened +=1; continue; }
2125 /* set the pkt length */
2126 vv1 = hplib_mUtilGetTickCount();
2127 Pktlib_setPacketLen(tip, len);
2129 /* set up meta data */
2130 meta.sa_handle=nwal_HANDLE_INVALID;
2131 //#define BENCH_UDP_SEND
2132 #ifdef BEND_UDP_SEND
2133 meta_tx.txFlag1 = (NWAL_TX_FLAG1_DO_IPV4_CHKSUM | NWAL_TX_FLAG1_DO_UDP_CHKSUM| NWAL_TX_FLAG1_META_DATA_VALID);
2134 meta_tx.startOffset = 0;
2135 //GONE in V2 meta_tx.pktLen = len;
2136 meta_tx.ipOffBytes = TEST_PKT_IP_OFFSET_BYTES;
2137 meta_tx.l4OffBytes = TEST_PKT_UDP_OFFSET_BYTES;
2138 meta_tx.l4HdrLen = TEST_PKT_UDP_HDR_LEN;
2139 //GONE in V2 meta_tx.ploadOffBytes = TEST_PKT_PLOAD_OFFSET_BYTES;
2140 meta_tx.ploadLen = TEST_PAYLOAD_LEN;
2142 Pktlib_getDataBuffer(tip,&pData,&len);
2143 if(house_pkts_gened &0x1)
2144 {
2145 memcpy(&pData[6],&config.mac1[0] ,6);
2146 }
2147 pIpHdr = pData + meta_tx.ipOffBytes;
2148 meta_tx.pseudoHdrChecksum =
2149 test_utilGetIpv4PsudoChkSum(pIpHdr,(TEST_PAYLOAD_LEN+TEST_PKT_UDP_HDR_LEN));
2150 #else
2151 Pktlib_getDataBuffer(tip,&pData,&len);
2152 if(house_pkts_gened &0x1)
2153 {
2154 memcpy(&pData[6],&config.mac1[0] ,6);
2155 }
2156 meta_tx.txFlag1 = NWAL_TX_FLAG1_META_DATA_VALID;
2157 meta_tx.startOffset = 0;
2158 meta_tx.ploadLen = TEST_PAYLOAD_LEN;
2159 #endif
2160 /* post it to netcp tx channel*/
2161 meta.u.tx_meta=&meta_tx;
2162 #ifdef DEBUG_DESC
2163 if (house_pkts_gened<16) dump_descr((long *) tip, house_pkts_gened);
2164 else if (house_pkts_gened>99) dump_descr((long *) tip,house_pkts_gened);
2165 #endif
2167 if(!first)
2168 {
2169 first++;
2170 nwal_flow_vv1= hplib_mUtilGetTickCount();
2171 if(nwal_initPSCmdInfo(PKTIO_GET_NWAL_INSTANCE(netcp_tx_chan),
2172 &meta_tx,
2173 &flowPSCmdInfo) != nwal_OK)
2174 {
2175 printf("nwal_initPSCmdInfo() ERROR \n");
2176 }
2177 nwal_flow_vv2= hplib_mUtilGetTickCount();
2178 nwal_sum_flow_vv1 += (nwal_flow_vv1-vv1);
2179 nwal_sum_flow_vv2 += (nwal_flow_vv2-nwal_flow_vv1);
2180 }
2182 cache_op_b1= Osal_cache_op_measure(&n_c_ops);
2183 vv2= hplib_mUtilGetTickCount();
2184 #ifdef BEND_UDP_SEND
2185 nwal_mCmdSetL4CkSumPort( tip,
2186 &flowPSCmdInfo,
2187 TEST_PKT_UDP_OFFSET_BYTES,
2188 (TEST_PKT_UDP_HDR_LEN + TEST_PAYLOAD_LEN),
2189 meta_tx.pseudoHdrChecksum,
2190 meta_tx.enetPort);
2191 #else
2192 nwal_mCmdSetPort (tip,
2193 &flowPSCmdInfo, //could be NULL
2194 0); //port 0 -> switch decides
2196 #endif
2198 pPktDesc = Pktlib_getDescFromPacket(tip);
2199 /* Send the packet out to transmit Q*/
2200 Qmss_queuePushDescSize (flowPSCmdInfo.txQueue,
2201 pPktDesc,
2202 NWAL_DESC_SIZE);
2203 vv3= hplib_mUtilGetTickCount();
2204 cache_op_b2= Osal_cache_op_measure(&n_c_ops);
2206 sum_vv1 += (vv2-vv1);
2207 if(!house_pkts_gened)
2208 {
2209 /* first packet. Take out the PS command label creation cost */
2210 sum_vv1 = sum_vv1 - nwal_sum_flow_vv2;
2211 }
2213 sum_vv3 += (vv3-vv2)-(long) (cache_op_b2-cache_op_b1); //sub out cache op cost
2215 // printf("pktio send. full=%d metadata=%d pktio_send=%d\n", vv3-vv1, vv2-vv1, vv3-vv2);
2218 stats.itx +=1;
2219 house_pkts_gened +=1;
2220 }
2221 {
2222 unsigned long long ccycles;
2223 ccycles =Osal_cache_op_measure(&n_c_ops);
2224 if (sum_vv1)
2225 {
2226 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",
2227 stats.itx, sum_vv1/stats.itx, nwal_sum_flow_vv2, sum_vv3/stats.itx,
2228 n_c_ops, ccycles, n_c_ops? (ccycles/(n_c_ops/2L)) : 0);
2229 #if 0
2230 printf("NWAL Profile Cycles: Prof1= %d,Prof2=%d,Prof3=%d,Prof4=%d,Prof5=%d ,Prof6=%d \n",
2231 nwal_sum_vv1/stats.itx,nwal_sum_vv2/stats.itx,nwal_sum_vv3/stats.itx,
2232 nwal_sum_vv4/stats.itx,nwal_sum_vv5/stats.itx,nwal_sum_vv6/stats.itx);
2234 #endif
2236 if(stats.itx2)
2237 {
2238 printf("nwal_flowSend Profile Cycles: Prof1= %d,Prof2=%d \n",
2239 nwal_sum_flow_vv1/stats.itx2,nwal_sum_flow_vv2/stats.itx2);
2240 }
2242 }
2243 }
2244 #endif
2245 }
2247 void build_sa_db(int i)
2248 {
2249 long tmp_spi;
2250 if ((tx_sa[i].authMode == NWAL_SA_AALG_HMAC_SHA1) && (tx_sa[i].cipherMode == NWAL_SA_EALG_AES_CBC))
2251 {
2252 /* static configuration, will not change */
2253 sa_info[i].tx_payload_info.aadSize = 0;
2254 sa_info[i].tx_payload_info.pAad = NULL;
2255 sa_info[i].tx_payload_info.pAuthIV = NULL;
2256 sa_info[i].tx_payload_info.authOffset = netTest_MAC_HEADER_LEN + netTest_IP_HEADER_LEN; /*done: same for all cipher suites */
2257 sa_info[i].tx_payload_info.encOffset = netTest_MAC_HEADER_LEN +
2258 netTest_IP_HEADER_LEN +
2259 netTest_ESP_HEADER_LEN +
2260 netTest_AES_CBC_IV_LEN;
2262 /* dynamic configuration, will be calculated on the fly */
2263 sa_info[i].tx_payload_info.authSize = 0; /* pkt len - mac - ip -icv (12) */
2264 sa_info[i].tx_payload_info.encSize = 0; /* authSize - esp header size (always 8 bytes) */
2265 sa_info[i].tx_payload_info.pEncIV = 0;
2266 sa_info[i].tx_payload_info.pPkt = 0; /* not being referenced in net_test */
2268 sa_info[i].cipherMode = NWAL_SA_EALG_AES_CBC;
2269 sa_info[i].inner_ip_offset = sa_info[i].tx_payload_info.encOffset;
2270 sa_info[i].auth_tag_size = netTest_ICV_LEN; /* icv or mac size,. always 12 except for AES_CCM/AES_GCM */
2271 #ifdef EXPERIMENTAL
2272 sa_info[i].iv_len=16;
2273 sa_info[i].bl=16;
2274 sa_info[i].spi = tx_sa[i].spi;
2275 sa_info[i].src =*((unsigned int *)(&config.local_ipsec_ip.ipv4[0]));
2276 sa_info[i].dst =*((unsigned int *)(&config.remote_ipsec_ip.ipv4[0]));
2277 #endif
2278 sa_info[i].tx_pkt_info.enetPort = 0;
2279 sa_info[i].tx_pkt_info.ipOffBytes = sa_info[i].tx_payload_info.encOffset;
2280 sa_info[i].tx_pkt_info.l4HdrLen = netTest_UDP_HEADER_LEN; /*UDP header len */
2281 sa_info[i].tx_pkt_info.l4OffBytes = sa_info[i].inner_ip_offset + netTest_IP_HEADER_LEN;
2282 sa_info[i].tx_pkt_info.startOffset = 0;
2283 sa_info[i].tx_pkt_info.lpbackPass = 0;
2284 sa_info[i].tx_pkt_info.ploadLen = 0; /*sa_info[i].tx_pkt_info.l4OffBytes + 4 */
2285 sa_info[i].tx_pkt_info.pPkt = NULL;
2286 sa_info[i].tx_pkt_info.saOffBytes = netTest_MAC_HEADER_LEN + netTest_IP_HEADER_LEN;
2287 sa_info[i].tx_pkt_info.saPayloadLen = 0;
2288 sa_info[i].tx_pkt_info.pseudoHdrChecksum =0;
2290 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 ;
2292 tmp_spi = htonl((long)(tx_sa[i].spi));
2293 trie_insert(p_trie_sa,(char *)&tmp_spi,4, (void *) &sa_info[i]); //asociate with tx sa SPI
2294 printf("*********** build_sa_db(): spi %d,0x%x\n", tx_sa[i].spi,tx_sa[i].spi);;
2297 }
2298 else if ((tx_sa[i].authMode == NWAL_SA_AALG_HMAC_SHA2_256) && (tx_sa[i].cipherMode == NWAL_SA_EALG_AES_CTR))
2299 {
2300 printf("inside build_sa_db, index %d\n", i);
2301 /* static configuration, will not change */
2302 sa_info[i].tx_payload_info.aadSize = 0;
2303 sa_info[i].tx_payload_info.pAad = NULL;
2304 sa_info[i].tx_payload_info.pAuthIV = NULL;
2305 sa_info[i].tx_payload_info.authOffset = netTest_MAC_HEADER_LEN + netTest_IP_HEADER_LEN; /*done: same for all cipher suites */
2306 sa_info[i].tx_payload_info.encOffset = netTest_MAC_HEADER_LEN +
2307 netTest_IP_HEADER_LEN +
2308 netTest_ESP_HEADER_LEN +
2309 netTest_AES_CTR_IV_LEN;
2314 /* dynamic configuration, will be calculated on the fly */
2315 sa_info[i].tx_payload_info.authSize = 0;
2316 sa_info[i].tx_payload_info.encSize = 0;
2317 sa_info[i].tx_payload_info.pEncIV = 0;
2318 sa_info[i].tx_payload_info.pPkt = 0;
2320 sa_info[i].cipherMode = NWAL_SA_EALG_AES_CTR;
2321 sa_info[i].inner_ip_offset = sa_info[i].tx_payload_info.encOffset;
2322 sa_info[i].auth_tag_size = netTest_ICV_LEN; /* icv or mac size,. always 12 except for AES_CCM/AES_GCM */
2323 #ifdef EXPERIMENTAL
2324 sa_info[i].iv_len=8;
2325 sa_info[i].bl=8;
2326 sa_info[i].spi = tx_sa[i].spi;
2327 sa_info[i].src =*((unsigned int *)(&config.local_ipsec_ip.ipv4[0]));
2328 sa_info[i].dst =*((unsigned int *)(&config.remote_ipsec_ip.ipv4[0]));
2329 #endif
2331 sa_info[i].tx_pkt_info.enetPort = 0;
2332 sa_info[i].tx_pkt_info.ipOffBytes = sa_info[i].tx_payload_info.encOffset;
2333 sa_info[i].tx_pkt_info.l4HdrLen = netTest_UDP_HEADER_LEN; /*UDP header len */
2334 sa_info[i].tx_pkt_info.l4OffBytes = sa_info[i].inner_ip_offset + netTest_IP_HEADER_LEN;
2335 sa_info[i].tx_pkt_info.startOffset = 0;
2336 sa_info[i].tx_pkt_info.lpbackPass = 0;
2337 sa_info[i].tx_pkt_info.ploadLen = 0; /*sa_info[i].tx_pkt_info.l4OffBytes + 4 */
2338 sa_info[i].tx_pkt_info.pPkt = NULL;
2339 sa_info[i].tx_pkt_info.saOffBytes = netTest_MAC_HEADER_LEN + netTest_IP_HEADER_LEN;
2340 sa_info[i].tx_pkt_info.saPayloadLen = 0;
2341 sa_info[i].tx_pkt_info.pseudoHdrChecksum =0;
2343 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 ;
2345 tmp_spi = htonl((long)(tx_sa[i].spi));
2346 trie_insert(p_trie_sa,(char *)&tmp_spi,4, (void *) &sa_info[i]); //asociate with tx sa SPI
2347 }
2348 else if ((tx_sa[i].authMode == NWAL_SA_AALG_NULL) && (tx_sa[i].cipherMode == NWAL_SA_EALG_3DES_CBC))
2349 {
2350 /* static configuration, will not change */
2351 sa_info[i].tx_payload_info.aadSize = 0;
2352 sa_info[i].tx_payload_info.pAad = NULL;
2353 sa_info[i].tx_payload_info.pAuthIV = NULL;
2354 sa_info[i].tx_payload_info.authOffset = netTest_MAC_HEADER_LEN + netTest_IP_HEADER_LEN; /*done: same for all cipher suites */
2355 sa_info[i].tx_payload_info.encOffset = netTest_MAC_HEADER_LEN +
2356 netTest_IP_HEADER_LEN +
2357 netTest_ESP_HEADER_LEN +
2358 netTest_3DES_CBC_IV_LEN;
2360 /* dynamic configuration, will be calculated on the fly */
2361 sa_info[i].tx_payload_info.authSize = 0;
2362 sa_info[i].tx_payload_info.encSize = 0;
2363 sa_info[i].tx_payload_info.pEncIV = 0;
2364 sa_info[i].tx_payload_info.pPkt = 0;
2366 sa_info[i].cipherMode = NWAL_SA_EALG_3DES_CBC;
2367 sa_info[i].inner_ip_offset = sa_info[i].tx_payload_info.encOffset;
2368 sa_info[i].auth_tag_size = 0; /* icv or mac size,. always 12 except for AES_CCM/AES_GCM */
2369 #ifdef EXPERIMENTAL
2370 sa_info[i].iv_len=8;
2371 sa_info[i].bl=8;
2372 sa_info[i].spi = tx_sa[i].spi;
2373 sa_info[i].src =*((unsigned int *)(&config.local_ipsec_ip.ipv4[0]));
2374 sa_info[i].dst =*((unsigned int *)(&config.remote_ipsec_ip.ipv4[0]));
2375 #endif
2377 sa_info[i].tx_pkt_info.enetPort = 0;
2378 sa_info[i].tx_pkt_info.ipOffBytes = sa_info[i].tx_payload_info.encOffset;
2379 sa_info[i].tx_pkt_info.l4HdrLen = netTest_UDP_HEADER_LEN; /*UDP header len */
2380 sa_info[i].tx_pkt_info.l4OffBytes = sa_info[i].inner_ip_offset + netTest_IP_HEADER_LEN;
2381 sa_info[i].tx_pkt_info.startOffset = 0;
2382 sa_info[i].tx_pkt_info.lpbackPass = 0;
2383 sa_info[i].tx_pkt_info.ploadLen = 0; /*sa_info[i].tx_pkt_info.l4OffBytes + 4 */
2384 sa_info[i].tx_pkt_info.pPkt = NULL;
2385 sa_info[i].tx_pkt_info.saOffBytes = netTest_MAC_HEADER_LEN + netTest_IP_HEADER_LEN;
2386 sa_info[i].tx_pkt_info.saPayloadLen = 0;
2387 sa_info[i].tx_pkt_info.pseudoHdrChecksum =0;
2389 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 ;
2391 tmp_spi = htonl((long)(tx_sa[i].spi));
2392 trie_insert(p_trie_sa,(char *)&tmp_spi,4, (void *) &sa_info[i]); //asociate with tx sa SPI
2393 }
2394 else if ((tx_sa[i].authMode == NWAL_SA_AALG_HMAC_MD5) && (rx_sa[i].cipherMode == NWAL_SA_EALG_NULL))
2395 {
2396 /* static configuration, will not change */
2397 sa_info[i].tx_payload_info.aadSize = 0;
2398 sa_info[i].tx_payload_info.pAad = NULL;
2399 sa_info[i].tx_payload_info.pAuthIV = NULL;
2400 sa_info[i].tx_payload_info.authOffset = netTest_MAC_HEADER_LEN + netTest_IP_HEADER_LEN; /*done: same for all cipher suites */
2402 sa_info[i].tx_payload_info.encOffset = netTest_MAC_HEADER_LEN +
2403 netTest_IP_HEADER_LEN +
2404 netTest_ESP_HEADER_LEN +
2405 netTest_NULL_IV_LEN;
2408 #ifdef EXPERIMENTAL
2409 sa_info[i].iv_len=0;
2410 sa_info[i].bl=4;
2411 sa_info[i].spi = tx_sa[i].spi;
2412 sa_info[i].src =*((unsigned int *)(&config.local_ipsec_ip.ipv4[0]));
2413 sa_info[i].dst =*((unsigned int *)(&config.remote_ipsec_ip.ipv4[0]));
2414 #endif
2417 /* dynamic configuration, will be calculated on the fly */
2418 sa_info[i].tx_payload_info.authSize = 0;
2419 sa_info[i].tx_payload_info.encSize = 0;
2420 sa_info[i].tx_payload_info.pEncIV = 0;
2421 sa_info[i].tx_payload_info.pPkt = 0;
2423 sa_info[i].cipherMode = NWAL_SA_EALG_NULL;
2424 sa_info[i].inner_ip_offset = sa_info[i].tx_payload_info.encOffset;
2425 sa_info[i].auth_tag_size = netTest_ICV_LEN; /* icv or mac size,. always 12 except for AES_CCM/AES_GCM */
2427 sa_info[i].tx_pkt_info.enetPort = 0;
2428 sa_info[i].tx_pkt_info.ipOffBytes = sa_info[i].tx_payload_info.encOffset;
2429 sa_info[i].tx_pkt_info.l4HdrLen = netTest_UDP_HEADER_LEN; /*UDP header len */
2430 sa_info[i].tx_pkt_info.l4OffBytes = sa_info[i].inner_ip_offset + netTest_IP_HEADER_LEN;
2431 sa_info[i].tx_pkt_info.startOffset = 0;
2432 sa_info[i].tx_pkt_info.lpbackPass = 0;
2433 sa_info[i].tx_pkt_info.ploadLen = 0; /*sa_info[i].tx_pkt_info.l4OffBytes + 4 */
2434 sa_info[i].tx_pkt_info.pPkt = NULL;
2435 sa_info[i].tx_pkt_info.saOffBytes = netTest_MAC_HEADER_LEN + netTest_IP_HEADER_LEN;
2436 sa_info[i].tx_pkt_info.saPayloadLen = 0;
2437 sa_info[i].tx_pkt_info.pseudoHdrChecksum =0;
2439 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 ;
2440 tmp_spi = htonl((long)(tx_sa[i].spi));
2441 trie_insert(p_trie_sa,(char *)&tmp_spi,4, (void *) &sa_info[i]); //asociate with tx sa SPI
2442 }
2443 else if ((tx_sa[i].authMode == NWAL_SA_AALG_NULL) && (rx_sa[i].cipherMode == NWAL_SA_EALG_AES_GCM))
2444 {
2445 /* static configuration, will not change */
2446 sa_info[i].tx_payload_info.aadSize = 0;
2447 sa_info[i].tx_payload_info.pAad = NULL;
2448 sa_info[i].tx_payload_info.pAuthIV = NULL;
2449 sa_info[i].tx_payload_info.authOffset = netTest_MAC_HEADER_LEN + netTest_IP_HEADER_LEN; /*done: same for all cipher suites */
2450 //sa_info[i].tx_payload_info.encIvSize = netTest_AES_GCM_IV_LEN;
2452 sa_info[i].tx_payload_info.encOffset = netTest_MAC_HEADER_LEN +
2453 netTest_IP_HEADER_LEN +
2454 netTest_ESP_HEADER_LEN +
2455 netTest_AES_GCM_IV_LEN;
2456 #ifdef EXPERIMENTAL
2457 sa_info[i].iv_len=0;
2458 sa_info[i].bl=4;
2459 sa_info[i].spi = tx_sa[i].spi;
2460 sa_info[i].src =*((unsigned int *)(&config.local_ipsec_ip.ipv4[0]));
2461 sa_info[i].dst =*((unsigned int *)(&config.remote_ipsec_ip.ipv4[0]));
2462 #endif
2465 /* dynamic configuration, will be calculated on the fly */
2466 sa_info[i].tx_payload_info.authSize = 0;
2467 sa_info[i].tx_payload_info.encSize = 0;
2468 //sa_info[i].tx_payload_info.ploadLen = 0;
2469 sa_info[i].tx_payload_info.pEncIV = 0;
2470 sa_info[i].tx_payload_info.pPkt = 0;
2472 sa_info[i].cipherMode = NWAL_SA_EALG_AES_GCM;
2473 sa_info[i].inner_ip_offset = sa_info[i].tx_payload_info.encOffset;
2474 sa_info[i].auth_tag_size = netTest_AES_GCM_CCM_ICV_LEN; /* icv or mac size,. always 12 except for AES_CCM/AES_GCM */
2476 sa_info[i].tx_pkt_info.enetPort = 0;
2477 sa_info[i].tx_pkt_info.ipOffBytes = sa_info[i].tx_payload_info.encOffset;
2478 sa_info[i].tx_pkt_info.l4HdrLen = netTest_UDP_HEADER_LEN; /*UDP header len */
2479 sa_info[i].tx_pkt_info.l4OffBytes = sa_info[i].inner_ip_offset + netTest_IP_HEADER_LEN;
2480 sa_info[i].tx_pkt_info.startOffset = 0;
2481 sa_info[i].tx_pkt_info.lpbackPass = 0;
2482 sa_info[i].tx_pkt_info.ploadLen = 0; /*sa_info[i].tx_pkt_info.l4OffBytes + 4 */
2483 sa_info[i].tx_pkt_info.pPkt = NULL;
2484 sa_info[i].tx_pkt_info.saOffBytes = netTest_MAC_HEADER_LEN + netTest_IP_HEADER_LEN;
2485 sa_info[i].tx_pkt_info.saPayloadLen = 0;
2486 sa_info[i].tx_pkt_info.pseudoHdrChecksum =0;
2488 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 ;
2490 tmp_spi = htonl((long)(tx_sa[i].spi));
2491 trie_insert(p_trie_sa,(char *)&tmp_spi,4, (void *) &sa_info[i]); //asociate with tx sa SPI
2492 }
2493 else if ((tx_sa[i].authMode == NWAL_SA_AALG_NULL) && (rx_sa[i].cipherMode == NWAL_SA_EALG_AES_CCM))
2494 {
2495 /* static configuration, will not change */
2496 sa_info[i].tx_payload_info.aadSize = 0;
2497 sa_info[i].tx_payload_info.pAad = NULL;
2498 //sa_info[i].tx_payload_info.authIvSize = 0;
2499 sa_info[i].tx_payload_info.pAuthIV = NULL;
2500 sa_info[i].tx_payload_info.authOffset = netTest_MAC_HEADER_LEN + netTest_IP_HEADER_LEN; /*done: same for all cipher suites */
2502 sa_info[i].tx_payload_info.encOffset = netTest_MAC_HEADER_LEN +
2503 netTest_IP_HEADER_LEN +
2504 netTest_ESP_HEADER_LEN +
2505 netTest_AES_CCM_IV_LEN;
2506 #ifdef EXPERIMENTAL
2507 sa_info[i].iv_len=0;
2508 sa_info[i].bl=4;
2509 sa_info[i].spi = tx_sa[i].spi;
2510 sa_info[i].src =*((unsigned int *)(&config.local_ipsec_ip.ipv4[0]));
2511 sa_info[i].dst =*((unsigned int *)(&config.remote_ipsec_ip.ipv4[0]));
2512 #endif
2515 /* dynamic configuration, will be calculated on the fly */
2516 sa_info[i].tx_payload_info.authSize = 0;
2517 sa_info[i].tx_payload_info.encSize = 0;
2518 //sa_info[i].tx_payload_info.ploadLen = 0;
2519 sa_info[i].tx_payload_info.pEncIV = 0;
2520 sa_info[i].tx_payload_info.pPkt = 0;
2522 sa_info[i].cipherMode = NWAL_SA_EALG_AES_CCM;
2523 sa_info[i].inner_ip_offset = sa_info[i].tx_payload_info.encOffset;
2524 sa_info[i].auth_tag_size = netTest_AES_GCM_CCM_ICV_LEN; /* icv or mac size,. always 12 except for AES_CCM/AES_GCM */
2526 sa_info[i].tx_pkt_info.enetPort = 0;
2527 sa_info[i].tx_pkt_info.ipOffBytes = sa_info[i].tx_payload_info.encOffset;
2528 sa_info[i].tx_pkt_info.l4HdrLen = netTest_UDP_HEADER_LEN; /*UDP header len */
2529 sa_info[i].tx_pkt_info.l4OffBytes = sa_info[i].inner_ip_offset + netTest_IP_HEADER_LEN;
2530 sa_info[i].tx_pkt_info.startOffset = 0;
2531 sa_info[i].tx_pkt_info.lpbackPass = 0;
2532 sa_info[i].tx_pkt_info.ploadLen = 0; /*sa_info[i].tx_pkt_info.l4OffBytes + 4 */
2533 sa_info[i].tx_pkt_info.pPkt = NULL;
2534 sa_info[i].tx_pkt_info.saOffBytes = netTest_MAC_HEADER_LEN + netTest_IP_HEADER_LEN;
2535 sa_info[i].tx_pkt_info.saPayloadLen = 0;
2536 sa_info[i].tx_pkt_info.pseudoHdrChecksum =0;
2538 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 ;
2540 tmp_spi = htonl((long)(tx_sa[i].spi));
2541 trie_insert(p_trie_sa,(char *)&tmp_spi,4, (void *) &sa_info[i]); //asociate with tx sa SPI
2542 }
2543 else if ((tx_sa[i].authMode == NWAL_SA_AALG_GMAC) && (rx_sa[i].cipherMode == NWAL_SA_EALG_NULL))
2544 {
2545 /* static configuration, will not change */
2546 sa_info[i].tx_payload_info.aadSize = 0;
2547 sa_info[i].tx_payload_info.pAad = NULL;
2548 sa_info[i].tx_payload_info.pAuthIV = NULL;
2549 sa_info[i].tx_payload_info.authOffset = netTest_MAC_HEADER_LEN + netTest_IP_HEADER_LEN;
2552 sa_info[i].tx_payload_info.encOffset = netTest_MAC_HEADER_LEN +
2553 netTest_IP_HEADER_LEN +
2554 netTest_ESP_HEADER_LEN +
2555 netTest_AES_GMAC_IV_LEN;
2556 #ifdef EXPERIMENTAL
2557 sa_info[i].iv_len=0;
2558 sa_info[i].bl=4;
2559 sa_info[i].spi = tx_sa[i].spi;
2560 sa_info[i].src =*((unsigned int *)(&config.local_ipsec_ip.ipv4[0]));
2561 sa_info[i].dst =*((unsigned int *)(&config.remote_ipsec_ip.ipv4[0]));
2562 #endif
2565 /* dynamic configuration, will be calculated on the fly */
2566 sa_info[i].tx_payload_info.authSize = 0;
2567 sa_info[i].tx_payload_info.encSize = 0;
2568 //sa_info[i].tx_payload_info.ploadLen = 0;
2569 sa_info[i].tx_payload_info.pEncIV = 0;
2570 sa_info[i].tx_payload_info.pPkt = 0;
2572 sa_info[i].cipherMode = NWAL_SA_EALG_NULL;
2573 sa_info[i].authMode = NWAL_SA_AALG_GMAC;
2574 sa_info[i].inner_ip_offset = sa_info[i].tx_payload_info.encOffset;
2575 sa_info[i].auth_tag_size = netTest_AES_GMAC_ICV_LEN; /* icv or mac size,. always 12 except for AES_CCM/AES_GCM , GMAC*/
2577 sa_info[i].tx_pkt_info.enetPort = 0;
2578 sa_info[i].tx_pkt_info.ipOffBytes = sa_info[i].tx_payload_info.encOffset;
2579 sa_info[i].tx_pkt_info.l4HdrLen = netTest_UDP_HEADER_LEN; /*UDP header len */
2580 sa_info[i].tx_pkt_info.l4OffBytes = sa_info[i].inner_ip_offset + netTest_IP_HEADER_LEN;
2581 sa_info[i].tx_pkt_info.startOffset = 0;
2582 sa_info[i].tx_pkt_info.lpbackPass = 0;
2583 sa_info[i].tx_pkt_info.ploadLen = 0; /*sa_info[i].tx_pkt_info.l4OffBytes + 4 */
2584 sa_info[i].tx_pkt_info.pPkt = NULL;
2585 sa_info[i].tx_pkt_info.saOffBytes = netTest_MAC_HEADER_LEN + netTest_IP_HEADER_LEN;
2586 sa_info[i].tx_pkt_info.saPayloadLen = 0;
2587 sa_info[i].tx_pkt_info.pseudoHdrChecksum =0;
2589 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 ;
2591 tmp_spi = htonl((long)(tx_sa[i].spi));
2592 trie_insert(p_trie_sa,(char *)&tmp_spi,4, (void *) &sa_info[i]); //asociate with tx sa SPI
2593 }
2594 else
2595 printf("build_sa_db(): invalid encryption/authentication combination selected\n");
2597 //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);
2600 }
2604 #define CHECK_SET_PARAM(ARG1, ARG2) \
2605 do { \
2606 if(strcmp(key, ARG1) == 0) { \
2607 if(data)strncpy(ARG2,data,CONFIG_STRING_LEN); \
2608 printf("CHECK_SET_PARM, match found, input cong string %s\n", ARG2); \
2609 continue; \
2610 } \
2611 } while(0)
2613 #define CHECK_SET_PARAM2(ARG1, ARG2, ARG3) \
2614 do { \
2615 if(strcmp(key, ARG1) == 0) { \
2616 if(data) strncpy(ARG2,data,CONFIG_STRING_LEN); \
2617 if(data2) strncpy(ARG3,data2,CONFIG_STRING_LEN); \
2618 printf("CHECK_SET_PARM2, match found, input cong string %s %s\n", ARG2, ARG3); \
2619 continue; \
2620 } \
2621 } while(0)
2623 unsigned char hex2dec(char *p_s)
2624 {
2625 int val;
2626 sscanf(p_s,"%x",&val);
2627 return val&0xff;
2628 }
2629 void parse_one_mac(char * p_mac_str, unsigned char *p_mac)
2630 {
2631 int index = 0;
2632 int i;
2633 char *pch = strtok (&(p_mac_str[0]),"-");
2635 while (pch != NULL)
2636 {
2637 printf ("%s\n",pch);
2638 p_mac[index] = hex2dec(pch);
2639 index++;
2640 pch = strtok (NULL,"-");
2641 }
2642 printf("index value : %d\n", index);
2643 for (i=0; i<6;i++)
2644 printf("************mac0[%d]: 0x%x\n",i, p_mac[i]);
2645 }
2647 void parse_one_ip(char * p_ip_addr_str, unsigned char * p_ip)
2648 {
2649 int index = 0;
2650 int i;
2651 char * pch = strtok (&p_ip_addr_str[0],".");
2653 while (pch != NULL)
2654 {
2655 printf ("xxxxx: %s\n",pch);
2656 p_ip[index] = atoi(pch);
2657 index++;
2658 pch = strtok (NULL,".");
2659 }
2660 printf("index value : %d\n", index);
2661 for (i=0; i<4;i++)
2662 printf("************ip[%d]: 0x%x\n",i, p_ip[i]);
2665 }
2667 void parse_mac_address(netTestConfigFile_t *pConfig)
2668 {
2669 if (strlen(&pConfig->mac0[0]))
2670 parse_one_mac(&pConfig->mac0[0],&config.mac0[0]);
2671 if (strlen(&pConfig->mac1[0]))
2672 parse_one_mac(&pConfig->mac1[0],&config.mac1[0]);
2673 }
2674 void parse_ip_address(netTestConfigFile_t *pConfig)
2675 {
2676 if (strlen(&pConfig->ip0[0]))
2677 parse_one_ip(&pConfig->ip0[0],&config.ip0.ipv4[0]);
2678 if (strlen(&pConfig->ip1[0]))
2679 parse_one_ip(&pConfig->ip1[0],&config.ip1.ipv4[0]);
2680 if (strlen(&pConfig->ip2[0]))
2681 parse_one_ip(&pConfig->ip2[0],&config.ip2.ipv4[0]);
2682 if (strlen(&pConfig->local_ipsec_ip[0]))
2683 parse_one_ip(&pConfig->local_ipsec_ip[0],&config.local_ipsec_ip.ipv4[0]);
2684 if (strlen(&pConfig->remote_ipsec_ip[0]))
2685 parse_one_ip(&pConfig->remote_ipsec_ip[0],&config.remote_ipsec_ip.ipv4[0]);
2686 }
2689 void parse_ipsec_mode(netTestConfigFile_t *pConfig)
2690 {
2692 if (strlen(&pConfig->ipsec_mode_rx[0]))
2693 {
2694 if (strcmp(pConfig->ipsec_mode_rx, "SIDEBAND") == 0)
2695 {
2696 config.ipsec_mode_rx = IPSEC_MODE_RX_SIDEBAND;
2697 }
2698 else if (strcmp(pConfig->ipsec_mode_rx, "INFLOW") == 0)
2699 {
2700 config.ipsec_mode_rx = IPSEC_MODE_RX_INFLOW;
2701 }
2702 else
2703 printf("parse_ipsec_mode(), invalid RX ipsec mode in config file \n");
2704 }
2706 if (strlen(&pConfig->ipsec_mode_tx[0]))
2707 {
2708 if (strcmp(pConfig->ipsec_mode_tx, "SIDEBAND") == 0)
2709 {
2710 config.ipsec_mode_tx = IPSEC_MODE_TX_SIDEBAND;
2711 }
2712 else if (strcmp(pConfig->ipsec_mode_tx, "INFLOW") == 0)
2713 {
2714 config.ipsec_mode_tx = IPSEC_MODE_TX_INFLOW;
2715 }
2716 else
2717 printf("parse_ipsec_mode(), invalid TX ipsec mode in config file \n");
2718 }
2720 printf("parse_ipsec_mode(): RX mode %d\n", config.ipsec_mode_rx);
2721 printf("parse_ipsec_mode(): TX mode %d\n", config.ipsec_mode_tx);
2724 }
2726 #ifdef EXPERIMENTAL
2727 int n_routes=0;
2728 int n_dst_ips=0;
2729 void parse_routes(netTestConfigFile_t *pConfig)
2730 {
2731 int i;
2732 int said=0;
2733 for(i=0;i<MAX_ROUTES;i++)
2734 {
2735 int port;
2736 if (pConfig->routes[i][0])
2737 {
2738 port=atoi(&pConfig->ports[i][0]);
2739 if((port<1)||(port>2)) continue; //bad port #: only 1 or 2 valid
2740 if(strncmp(&pConfig->routes[i][0],"MAC",3)==0)
2741 {
2742 routes[i].out_port = port;
2743 parse_one_mac(&pConfig->routes[i][3],&routes[i].out_mac[0]);
2744 memcpy(&routes[i].out_mac[6], ((port==1) ?&config.mac0[0]: &config.mac1[0] ),6);
2745 routes[i].out_mac[12]=0x08;
2746 routes[i].out_mac[13]=0x00;
2747 routes[i].sec_ptr=NULL;
2748 n_routes+=1;
2749 }
2750 else if (strncmp(&pConfig->routes[i][0],"SA",2)==0)
2751 {
2752 said=atoi(&pConfig->routes[i][2]) ;
2753 routes[i].sec_ptr=&sa_info[said];
2754 n_routes+=1;
2755 }
2756 }
2757 }
2758 our_router = route_init();
2759 for (i=0;i<MAX_ROUTES;i++)
2760 {
2761 unsigned long ip_be;
2762 int route_index;
2763 if (pConfig->dst_ips[i][0])
2764 {
2765 parse_one_ip(&pConfig->dst_ips[i][0],(unsigned char *)&ip_be);
2766 sscanf(&pConfig->paths[i][0],"route%d",&route_index);
2767 route_add(our_router,&ip_be,&routes[route_index]);
2768 n_dst_ips+=1;
2769 }
2770 }
2771 printf(">Route DB built. %d entries\n",n_dst_ips);
2772 }
2773 #endif
2774 static void parse_config_file(FILE * fpr, netTestConfigFile_t *pConfig)
2775 {
2776 char line[MAX_LINE_LENGTH + 1];
2777 int i;
2779 char *key, *data, *ep, *data2;
2780 char tokens[] = " :=;\n";
2781 char temp_str[50];
2782 memset(line, 0, MAX_LINE_LENGTH + 1);
2783 memset(pConfig, 0, sizeof(netTestConfigFile_t));
2784 while (fgets(line, MAX_LINE_LENGTH + 1, fpr))
2785 {
2786 if(line[0]=='#') continue; //skip comment
2787 key = (char *)strtok(line, tokens);
2788 data = (char *)strtok(NULL, tokens);
2789 data2 = (char *)strtok(NULL, tokens);
2790 if (!key) continue;
2791 if (!data) continue;
2793 if(strlen(data) == 0)
2794 {
2795 continue;
2796 }
2798 CHECK_SET_PARAM(INIT_CONFIG_MAC0,&(pConfig->mac0[0]));
2799 CHECK_SET_PARAM(INIT_CONFIG_MAC1,&(pConfig->mac1[0]));
2800 CHECK_SET_PARAM(INIT_CONFIG_IP0,&(pConfig->ip0[0]));
2801 CHECK_SET_PARAM(INIT_CONFIG_IP1,&(pConfig->ip1[0]));
2802 CHECK_SET_PARAM(INIT_CONFIG_IP2,&(pConfig->ip2[0]));
2803 CHECK_SET_PARAM(INIT_CONFIG_LOCAL_IPSEC_IP,&(pConfig->local_ipsec_ip[0]));
2804 CHECK_SET_PARAM(INIT_CONFIG_REMOTE_IPSEC_IP,&(pConfig->remote_ipsec_ip[0]));
2805 CHECK_SET_PARAM(INIT_CONFIG_IPSEC_MODE_RX,&(pConfig->ipsec_mode_rx[0]));
2806 CHECK_SET_PARAM(INIT_CONFIG_IPSEC_MODE_TX,&(pConfig->ipsec_mode_tx[0]));
2807 CHECK_SET_PARAM(INIT_CONFIG_IPSEC_IF_NO,&(pConfig->ipsec_if_no[0]));
2808 #ifdef EXPERIMENTAL
2809 for(i=0;i<MAX_ROUTES;i++)
2810 {
2811 sprintf(temp_str,"route%d",i);
2812 CHECK_SET_PARAM2(temp_str,&pConfig->routes[i][0],&pConfig->ports[i][0] );
2813 }
2814 for(i=0;i<MAX_ROUTES;i++)
2815 {
2816 sprintf(temp_str,"dstip%d",i);
2817 CHECK_SET_PARAM2(temp_str,&pConfig->dst_ips[i][0],&pConfig->paths[i][0] );
2818 }
2819 #endif
2821 }
2822 parse_mac_address(pConfig);
2824 parse_ip_address(pConfig);
2826 parse_ipsec_mode(pConfig);
2827 #ifdef EXPERIMENTAL
2828 if (strlen(&pConfig->ipsec_if_no[0]))
2829 config.ipsec_if_no = atoi(&pConfig->ipsec_if_no[0]);
2830 parse_routes(pConfig);
2831 #endif
2832 }
2835 #ifdef MULTI_THREAD
2836 NETAPI_T worker_nh[TUNE_NETAPI_NUM_CORES];
2837 void slow_path_thread(int coreid)
2838 {
2839 int err;
2840 printf("slow_path_thread, mypid: %d\n", gettid());
2841 hplib_Util_SetupCore(coreid, &cpu_set);
2842 worker_nh[coreid]=netapi_init(NETAPI_NO_MASTER,NULL);
2843 netapi_setCookie(worker_nh[coreid],coreid);
2844 our_core=coreid;
2845 scheduler[coreid] =netapi_schedOpen(worker_nh[coreid],&our_sched_cfg, &err);
2846 if (!scheduler[coreid]) {printf("sched create failed for core%d\n",coreid); exit(1);}
2850 /*********************************************/
2851 /**************Entry point into scheduler ****/
2852 /*********************************************/
2853 netapi_schedWaitForEvents(scheduler[coreid], &err);
2854 printf(">net_test: core %d worker thread done\n",coreid);
2855 netapi_shutdown(worker_nh[coreid]);
2857 }
2858 void fast_path_thread(int coreid)
2859 {
2860 int err;
2861 printf("fast_path_thread, mypid: %d\n", gettid());
2862 hplib_Util_SetupCore(coreid, &cpu_set);
2863 worker_nh[coreid]=netapi_init(NETAPI_NO_MASTER,NULL);
2864 netapi_setCookie(worker_nh[coreid],coreid);
2865 our_core=coreid;
2866 scheduler[coreid] =netapi_schedOpen(worker_nh[coreid],&our_sched_cfg, &err);
2867 if (!scheduler[coreid]) {printf("sched create failed for core%d\n",coreid); exit(1);}
2869 ;
2871 /*********************************************/
2872 /**************Entry point into scheduler ****/
2873 /*********************************************/
2874 netapi_schedWaitForEvents(scheduler[coreid], &err);
2875 printf(">net_test: core %d worker thread done\n",coreid);
2876 netapi_shutdown(worker_nh[coreid]);
2877 }
2878 #endif
2879 static netTestConfigFile_t config_file;
2880 /***************************************
2881 ********** test driver*****************
2882 ***************************************/
2883 int main(int argc, char **argv)
2884 {
2885 int err,i;
2886 rlim_t oss,ss = 1024*1024;
2887 struct rlimit rl;
2889 Pktlib_HeapCfg heapCfg;
2890 int32_t errCode;
2891 Pktlib_HeapIfTable* pPktifTable;
2893 FILE * fpr = NULL;
2896 err= getrlimit(RLIMIT_STACK,&rl);
2897 if (!err) printf(" stack limit = %d\n",rl.rlim_cur); else printf("getrlimit failed\n");
2898 #if 0
2899 rl.rlim_cur = ss;
2900 err=setrlimit(RLIMIT_STACK,&rl);
2901 i f (!err) printf("set stack to %d\n",rl.rlim_cur); else printf("setrlimit failed\n");
2902 #endif
2905 if (argc>=2) np2process = atoi(argv[1]);
2906 printf("*************** np2process %d\n", np2process);
2907 if (np2process<0) np2process = NP; /* default */
2908 if (argc==3) perslow = atoi(argv[2]);
2909 if ((perslow<0)||(perslow>100)) perslow=PERSLOW;//default
2910 if (argc>3) {printf("net_test <no of pkts to process> <percent slow path>\n"); exit(1);}
2911 //install signal handler for ^c
2912 signal(SIGINT,mysig);
2913 #if 1
2915 #if 0
2916 if (argc >= 2)
2917 {
2918 fpr = fopen(argv[2], "r");
2919 if (fpr == NULL)
2920 {
2921 printf("Error in opening %s input file\n", argv[2]);
2922 }
2923 }
2924 else
2925 #endif
2926 {
2927 fpr = fopen(input_file_name, "r");
2928 if (fpr == NULL)
2929 {
2930 printf("Error in opening %s input file\n", input_file_name);
2931 }
2932 else
2933 {
2934 parse_config_file(fpr,&config_file);
2935 }
2936 }
2938 #endif
2940 memset(&sa_info, 0, sizeof(sa_info));
2943 //real mode, so update our test packet mac header and ip header
2944 if (pktloopback==0)
2945 {
2946 memcpy(&testPkt,&real_mac_header[0],14); //overwrite test pkt mac address
2947 memcpy(&testPkt[26],&real_ip_addr[0],8);//overrite test pkt ip addresses
2948 }
2949 #if 0
2950 our_router = route_init();
2951 for (i=0;i<n_dst_ips;i++)
2952 {
2953 route_add(our_router,&ip[i],&routes[i]);
2954 }
2955 #endif
2958 /************** tmannan: core setup begin ************************/
2959 CPU_SET( 0, &cpu_set);
2961 if (sched_setaffinity( gettid(), sizeof( cpu_set_t ), &cpu_set ))
2962 {
2963 perror( "sched_setaffinity" );
2964 printf("main() , sched_setaffinity error\n");
2965 return hplib_FAILURE;
2966 }
2967 else
2968 printf("main() , ************* sched_setaffinity sucess ******************\n");
2971 hplib_Util_Init_NetapiProc();
2973 /**************** tmannan: core setup end ***********************/
2975 /*******************************************/
2976 /*************NETAPI STARTUP****************/
2977 /*******************************************/
2978 /* create netapi */
2979 netapi_handle = netapi_init(NETAPI_SYS_MASTER, &our_netapi_default_cfg);
2981 /* open the main heap */
2982 OurHeap = Pktlib_findHeapByName("netapi");
2983 if (!OurHeap) {printf("findheapbyname fail\n"); exit(1);}
2985 /* create two secondary heaps */
2986 /* Initialize the heap configuration. */
2987 memset ((void *)&heapCfg, 0, sizeof(Pktlib_HeapCfg));
2989 pPktifTable = netapi_getPktlibIfTable();
2990 /* Populate the heap configuration */
2991 heapCfg.name = "netapi-small";
2992 heapCfg.memRegion = NETAPI_GLOBAL_REGION;
2993 heapCfg.sharedHeap = 1;
2994 heapCfg.useStarvationQueue = 0;
2995 heapCfg.dataBufferSize = 512;
2996 heapCfg.numPkts = 64;
2997 heapCfg.numZeroBufferPackets= 0;
2998 heapCfg.heapInterfaceTable.data_malloc = pPktifTable->data_malloc;
2999 heapCfg.heapInterfaceTable.data_free = pPktifTable->data_free;
3000 heapCfg.dataBufferPktThreshold = 0;
3001 heapCfg.zeroBufferPktThreshold = 0;
3003 specialSmall = Pktlib_createHeap(&heapCfg, &errCode);
3004 heapCfg.name = "netapi-big";
3005 heapCfg.dataBufferSize = 1600;
3006 specialLarge = Pktlib_createHeap(&heapCfg, &errCode);
3007 //register these heaps so poll routine will include their garbage queues.
3008 netapi_registerHeap(netapi_handle, specialSmall);
3009 netapi_registerHeap(netapi_handle, specialLarge);
3011 #ifdef REASSEMBLE_BENCH
3012 our_reassemble_bench(2);
3013 exit(1);
3014 #endif
3016 #ifndef EXPERIMENTAL
3017 /* create a pktio channel */
3018 our_chan=pktio_create(netapi_handle,"our1stq",(PKTIO_CB) recv_cb_bench, &our_chan_cfg,&err);
3019 if (!our_chan) {printf("pktio create failed err=%d\n",err); exit(1);}
3020 #endif
3022 /* open netcp default tx, rx queues */
3023 netcp_tx_chan= pktio_open(netapi_handle, NETCP_TX, NULL, &netcp_tx_cfg, &err);
3024 if (!netcp_tx_chan) {printf("pktio open TX failed err=%d\n",err); exit(1);}
3025 #ifdef EXPERIMENTAL
3026 netcp_rx_chan= pktio_open(netapi_handle, NETCP_RX, (PKTIO_CB) recv_cb_router, &netcp_rx_cfg, &err);
3027 #else
3028 netcp_rx_chan= pktio_open(netapi_handle, NETCP_RX, (PKTIO_CB) recv_cb, &netcp_rx_cfg, &err);
3029 #endif
3030 if (!netcp_rx_chan) {printf("pktio open RX failed err=%d\n",err); exit(1);}
3032 #ifndef EXPERIMENTAL
3033 /* create a pktio channel for specially classified pkts */
3034 netcp_rx_chan2= pktio_create(netapi_handle, "classq", (PKTIO_CB) recv_cb, &netcp_rx_cfg2, &err);
3035 if (!netcp_rx_chan2) {printf("pktio create RX2 failed err=%d\n",err); exit(1);}
3037 /* open netcp default tx, rx queues for sideband crypto */
3038 netcp_sb_tx_chan= pktio_open(netapi_handle, NETCP_SB_TX, NULL, &netcp_sb_tx_cfg, &err);
3039 if (!netcp_sb_tx_chan) {printf("pktio open SB TX failed err=%d\n",err); exit(1);}
3040 netcp_sb_rx_chan= pktio_open(netapi_handle, NETCP_SB_RX, (PKTIO_CB) recv_sb_cb, &netcp_sb_rx_cfg, &err);
3041 if (!netcp_sb_rx_chan) {printf("pktio open SB RX failed err=%d\n",err); exit(1);}
3042 #endif
3044 printf("net_test> %d bytes left in our CMA area\n", netapi_getBufMemRemainder());
3045 /* create scheduler instance */
3046 our_sched =netapi_schedOpen(netapi_handle,&our_sched_cfg, &err);
3047 if (!our_sched) {printf("sched create failed\n"); exit(1);}
3049 #if 0
3050 /********************************************
3051 * Basic pkt loopback test
3052 *********************************************/
3053 printf("...running pure push/pop benchmark\n");
3054 our_pktio_bench(1000);
3055 our_pktio_bench(1000);
3056 our_pktio_bench(1000);
3057 our_pktio_bench(1000);
3058 our_pktio_bench(1000);
3059 /*********************************************/
3060 #endif
3061 //#define PROMISCUOUS
3062 #ifdef PROMISCUOUS
3063 #define ETH0 1
3064 #define ETH1 2
3065 printf(">net_test: WARNING, ADDING RULE FOR PROMISCUOUS THAT WILL BREAK LINUX STACK\n");
3066 netcp_cfgCreateMacInterface(
3067 netapi_handle,
3068 &all_mac[0],
3069 0,0,
3070 (NETCP_CFG_ROUTE_HANDLE_T) NULL,
3071 (NETCP_CFG_VLAN_T ) NULL , //future
3072 1,
3073 &err);
3074 if (err) {printf("addmac0 failed %d\n",err); exit(1); }
3076 #else
3077 #define ETH0 0
3078 #define ETH1 1
3079 #endif
3083 /* add mac intefaces */
3084 netcp_cfgCreateMacInterface(
3085 netapi_handle,
3086 &config.mac0[0],
3087 ETH0,0,
3088 (NETCP_CFG_ROUTE_HANDLE_T) NULL,
3089 (NETCP_CFG_VLAN_T ) NULL , //future
3090 1,
3091 &err);
3092 if (err) {printf("addmac0 failed %d\n",err); exit(1); }
3094 //attach an IP to this interface
3095 ip_rule0=netcp_cfgAddIp(
3096 netapi_handle,
3097 ETH0,
3098 nwal_IPV4,
3099 &config.ip0,
3100 NULL, //all IP
3101 (NETCP_CFG_ROUTE_HANDLE_T) NULL,
3102 &err
3103 );
3104 if (err) {printf("addip0 failed %d\n",err); exit(1); }
3106 //create a 2nd mac instance
3107 netcp_cfgCreateMacInterface(
3108 netapi_handle,
3109 &config.mac1[0],
3110 ETH1,1,
3111 (NETCP_CFG_ROUTE_HANDLE_T) NULL,
3112 (NETCP_CFG_VLAN_T ) NULL , //future
3113 1,
3114 &err);
3115 if (err) {printf("addmac1 failed %d\n",err); exit(1); }
3117 //attach an IP to this interface
3118 ip_rule1=netcp_cfgAddIp(
3119 netapi_handle,
3120 ETH1,
3121 nwal_IPV4,
3122 &config.ip1,
3123 NULL, //all IP
3124 (NETCP_CFG_ROUTE_HANDLE_T) NULL,
3125 &err
3126 );
3127 if (err) {printf("addip1 failed %d\n",err); exit(1); }
3129 #ifndef EXPERIMENTAL
3130 //attach 2 classifiers to iface 0, ip0
3131 class_0_cfg.u.c_l4.ip = ip_rule0;
3132 class_0 = netcp_cfgAddClass(netapi_handle,
3133 &class_0_cfg,
3134 NULL,
3135 NETCP_CFG_ACTION_TO_SW,
3136 &err);
3137 if (err) {printf("addclass0 failed %d\n",err); exit(1);}
3139 class_1_cfg.u.c_l4.ip = ip_rule0;
3140 class_1 = netcp_cfgAddClass(netapi_handle,
3141 &class_1_cfg,
3142 NULL,
3143 NETCP_CFG_ACTION_TO_SW,
3144 &err);
3145 if (err) {printf("addclass1 failed %d\n",err); exit(1);}
3148 //3rd classifier has a different IP and route
3149 class_2_cfg.u.c_l3_l4.ip_addr = &config.ip2;
3151 //create specialFlow for this classifier
3152 {
3153 Pktlib_HeapHandle heaps[2];
3154 int sizes[2];
3155 heaps[0]= specialSmall;
3156 heaps[1]= specialLarge;
3157 #define SPECIAL_SOP_OFF 128
3158 sizes[0]=512-SPECIAL_SOP_OFF;
3159 sizes[1]=1600-SPECIAL_SOP_OFF;
3160 #if 0
3161 specialFlow = netcp_cfgAddFlow( netapi_handle,
3162 2,
3163 heaps,
3164 sizes,
3165 SPECIAL_SOP_OFF, //offset to start rx is 128
3166 &err);
3167 if (err) {printf("add flow failed\n", err); exit(1);}
3168 #endif
3169 }
3170 #if 0
3171 //special route for this classifier: different flow + destination q
3172 class2_route.p_dest_q = netcp_rx_chan2;
3173 class2_route.p_flow = specialFlow;
3174 class_2 = netcp_cfgAddClass(netapi_handle,
3175 &class_2_cfg,
3176 (void*) &class2_route,
3177 NETCP_CFG_ACTION_TO_SW,
3178 &err);
3179 if (err) {printf("addclass2 failed %d\n",err); exit(1);}
3180 #endif
3182 #endif
3183 //security stuff
3184 p_trie_sa = trie_new();
3185 if (!p_trie_sa) {printf("trie alloc for SA failed\n"); exit(1);}
3189 for (i=0; i < MAX_SEC_INDEX;i++)
3190 {
3191 ourRXKeyParams[i].pEncKey = &ourEncrKey[0];
3192 ourRXKeyParams[i].pAuthKey = &ourAuthKey[0];
3193 memcpy(&(rx_sa[i].src), &config.remote_ipsec_ip,4);
3194 memcpy(&(rx_sa[i].dst), &config.local_ipsec_ip,4);
3196 build_sa_db(i);
3197 sa_info[i].rx_tunnel = netapi_secAddSA(
3198 netapi_handle,
3199 config.ipsec_if_no, //iface #0
3200 &rx_sa[i],
3201 &ourRXKeyParams[i],
3202 config.ipsec_mode_rx == IPSEC_MODE_RX_SIDEBAND ? NETAPI_SEC_SA_SIDEBAND: NETAPI_SEC_SA_INFLOW,
3203 NULL, //use default route
3204 &(sa_info[i].rx_data_mode_handle),
3205 &(sa_info[i].rx_inflow_mode_handle),
3206 &err);
3207 if (err) {printf("addRxSa failed %d\n",err); exit(1);}
3209 if (config.ipsec_mode_rx == IPSEC_MODE_RX_INFLOW)
3210 {
3211 //assume inner and outer ip is the same
3212 rx_policy[i]= netapi_secAddRxPolicy( netapi_handle,
3213 sa_info[i].rx_tunnel, //link to tunnel above
3214 4, //ipv4
3215 &config.remote_ipsec_ip, //src -> them
3216 &config.local_ipsec_ip, //dst -> us
3217 NULL, // no qualifiers
3218 NULL, //default route
3219 &err);
3220 if (err) {printf("addSaPolicy failed %d, for index %d\n",err,i); exit(1);}
3221 }
3222 else
3223 {
3224 rx_policy[i] = 0;
3226 }
3227 #ifdef NET_TEST_ENABLE_SIDE_BAND_LOW_LEVEL_API
3228 /* Remember the NetCP Command Label so save cycles per Crypto
3229 * operation
3230 *
3231 */
3232 if(config.ipsec_mode_rx == IPSEC_MODE_RX_SIDEBAND)
3233 {
3234 nwalRetVal =
3235 nwal_initDMPSCmdInfo(PKTIO_GET_NWAL_INSTANCE(netcp_sb_rx_chan),
3236 sa_info[i].rx_data_mode_handle,
3237 &sa_info[i].rx_dmPSCmdInfo);
3238 }
3240 #endif
3241 }
3243 //tx SA
3244 //security stuff
3245 for (i=0; i < MAX_SEC_INDEX;i++)
3246 {
3247 ourTXKeyParams[i].pEncKey = &ourEncrKey[0];
3248 ourTXKeyParams[i].pAuthKey = &ourAuthKey[0];
3249 memcpy(&(tx_sa[i].src), &config.local_ipsec_ip,4);
3250 memcpy(&(tx_sa[i].dst), &config.remote_ipsec_ip,4);
3251 sa_info[i].tx_tunnel = netapi_secAddSA( netapi_handle,
3252 0, //iface #0
3253 &(tx_sa[i]),
3254 &ourTXKeyParams[i],
3255 config.ipsec_mode_tx == IPSEC_MODE_TX_SIDEBAND ? NETAPI_SEC_SA_SIDEBAND: NETAPI_SEC_SA_INFLOW,
3256 NULL, //use default route
3257 &(sa_info[i].tx_data_mode_handle),
3258 &(sa_info[i].tx_inflow_mode_handle),
3259 &err);
3260 if (err) {printf("addTxSa failed %d\n",err); exit(1);}
3262 #ifdef NET_TEST_ENABLE_SIDE_BAND_LOW_LEVEL_API
3263 /* Remember the NetCP Command Label so save cycles per Crypto
3264 * operation
3265 *
3266 */
3267 if(config.ipsec_mode_tx == IPSEC_MODE_TX_SIDEBAND)
3268 {
3269 nwalRetVal =
3270 nwal_initDMPSCmdInfo(PKTIO_GET_NWAL_INSTANCE(netcp_sb_tx_chan),
3271 sa_info[i].tx_data_mode_handle,
3272 &sa_info[i].tx_dmPSCmdInfo);
3273 }
3275 #endif
3276 }
3278 #ifdef TEST_TIMERS
3279 //timers
3280 ourTimerBlock = hplib_Timer_CreateGroup(
3281 netapi_handle,
3282 "our1sttimer",
3283 our_timer_cb,
3284 0, //1 if timers local to thread
3285 0, //1 if expect to cancel
3286 hplib_getTicksPerSec()/1000, /* 1 msc resolution for these timers */
3287 hplib_getTicksPerSec()/5000, /* would like .5 msc tolerence */
3288 10); //small # of timers to test garbage collection
3289 if (err) {printf("hplib_Timer_CreateGroup() failed %d\n",err); exit(1);}
3291 //start a couple of timers
3292 t1 = hplib_Timer_Start(
3293 ourTimerBlock,
3294 (void *) 1,
3295 100LL, //timer group ticks
3296 &err);
3297 if (err) {printf("timerstart failed %d\n");}
3298 t2 = hplib_Timer_Start(
3299 ourTimerBlock,
3300 (void *) 2,
3301 200LL, //timer group ticks
3302 &err);
3303 if (err) {printf("timerstart failed %d\n");}
3304 t3 = hplib_Timer_Start(
3305 ourTimerBlock,
3306 (void *) 3,
3307 300LL, //timer group ticks
3308 &err);
3309 if (err) {printf("timerstart failed %d\n");}
3310 #endif
3311 #if 0
3312 netcp_cfgReqStats(netapi_handle, our_stats_cb, 1,&err);
3313 if (err!=0) {printf("stats req failed\n");}
3314 #endif
3315 /*********************************************/
3316 /*****************end NETAPI STARTUP**********/
3317 /*********************************************/
3320 #if 0
3321 /********************************************
3322 * Basic pkt loopback test
3323 *********************************************/
3324 printf("...runnining pure push/pop benchmark\n");
3325 our_pktio_bench(100);
3326 #endif
3328 /**************unused stuff******************/
3329 #if 0
3330 /* create TRIE */
3331 P_trie = trie_new();
3332 if (!P_trie) {printf("trie alloc failed\n"); exit(1);}
3334 nat = (HEAD_T *) malloc(NE * sizeof(HEAD_T));
3335 if (!nat) {printf("malloc of nat table failed\n"); exit(1);}
3337 //gen_pkts(np2process<NP ? np2process:NP);
3338 n_pkt= np2process;
3340 /* build table */
3341 build_table(P_trie);
3344 /* processing loop: get pkt, check it, look up in table, copy new header,
3345 send packet */
3346 srand((unsigned) np2process);
3347 #endif
3349 #ifdef MULTI_THREAD
3350 {
3351 CPU_ZERO( &cpu_set );
3352 pthread_t *thrs;
3353 int procs =2; //get this from config eventually
3354 char c;
3355 thrs = malloc( sizeof( pthread_t ) * procs );
3356 if (thrs == NULL)
3357 {
3358 perror( "malloc" );
3359 return -1;
3360 }
3361 printf( "Starting %d threads...\n", procs );
3363 if (pthread_create( &thrs[0], NULL, slow_path_thread,
3364 (void *)0 ))
3365 {
3366 perror( "pthread_create" );
3367 exit(1);
3368 }
3369 if (pthread_create( &thrs[1], NULL, fast_path_thread,
3370 (void *)1 ))
3371 {
3372 perror( "pthread_create" );
3373 exit(1);
3374 }
3376 //this thread of execution (main) now just waits on user input
3377 for(;;)
3378 {
3379 printf(">");
3380 c=getchar();
3381 if (c=='q') {QUIT=1;break;}
3382 else if (c=='s') our_stats_cb(netapi_handle, &netcp_stats);
3383 else if (c=='h') printf("'q' to quit, 's' for stats, 'h' for help\n");
3384 }
3386 //wait for completion
3387 printf("main task now pending on slow/fast path completion\n");
3388 for (i = 0; i < procs; i++)
3389 pthread_join( thrs[i], NULL );
3391 free( thrs );
3392 }
3393 #else
3396 /*********************************************/
3397 /**************Entry point into scheduler ****/
3398 /*********************************************/
3399 netapi_schedWaitForEvents(our_sched, &err);
3401 #endif
3403 /* done */
3404 our_stats_cb(netapi_handle, NULL);
3407 #define DO_FAST_POLL
3408 #ifdef DO_FAST_POLL
3409 //example_fast_pushpop(OurHeap, 500);
3410 //example_fast_poll(netcp_rx_chan,20000);
3411 #endif
3413 /*************************************************
3414 ************CLEAN UP****************************
3415 ************************************************/
3417 #ifndef EXPERIMENTAL
3418 //delete Classifiers
3419 netcp_cfgDelClass(netapi_handle, class_0, &err);
3420 netcp_cfgDelClass(netapi_handle, class_1, &err);
3421 //netcp_cfgDelClass(netapi_handle, class_2, &err);
3423 #if 0
3424 //delete flow
3425 netcp_cfgDelFlow(netapi_handle, specialFlow, &err);
3426 #endif
3427 #endif
3428 #if 1
3429 //delete policy
3430 for (i=0; i < MAX_SEC_INDEX;i++)
3431 {
3432 if (rx_policy[i])
3433 netapi_secDelRxPolicy(netapi_handle, rx_policy[i], &err);
3435 //delete tunnels
3436 netapi_secDelSA(netapi_handle, 0, sa_info[i].rx_tunnel, &err);
3437 netapi_secDelSA(netapi_handle, 0, sa_info[i].tx_tunnel, &err);
3438 #endif
3439 }
3440 //delete IPs and MAC Interfacess
3441 netcp_cfgDelIp(netapi_handle, 0, 0, NULL, NULL, ip_rule0, &err);
3442 netcp_cfgDelIp(netapi_handle, 1, 0, NULL, NULL, ip_rule1, &err);
3443 netcp_cfgDelMac(netapi_handle,0,&err);
3444 netcp_cfgDelMac(netapi_handle,1,&err);
3445 #ifdef PROMISCUOUS
3446 netcp_cfgDelMac(netapi_handle,2,&err);
3447 #endif
3449 //close pktio channels we opened
3450 pktio_close(netcp_tx_chan ,&err);
3451 pktio_close(netcp_rx_chan ,&err);
3452 #ifndef EXPERIMENTAL
3453 pktio_close(netcp_sb_tx_chan ,&err);
3454 pktio_close(netcp_sb_rx_chan ,&err);
3456 //clear pktio channel we created
3457 pktio_control(our_chan, (PKTIO_CB) NULL, (PKTIO_CFG_T *) NULL, &zap_channel_control, &err);
3458 pktio_control(netcp_rx_chan2, (PKTIO_CB) NULL, (PKTIO_CFG_T *) NULL, &zap_channel_control, &err);
3460 //delete pktio channels we created
3461 pktio_delete(our_chan, &err);
3462 pktio_delete(netcp_rx_chan2,&err);
3463 #endif
3464 netapi_shutdown(netapi_handle);
3466 }
3468 //EXAMPLE FAST POLL
3469 /* PLD */
3470 void netapi_pld(void * x)
3471 {
3472 asm volatile("pld [r0]");
3473 }
3474 #include "ti/drv/nwal/nwal_util.h"
3476 #define M 1008
3477 static int l3_off[M], l4_off[M], L3_chk_ok[M], L4_chk_ok[M], len[M] ;
3478 static nwal_AppId appid[M];
3479 static unsigned char * buf[M];
3480 #define N2POLL 8 //batch size
3481 #define NTOPOP 190
3482 Ti_Pkt * pHd[NTOPOP];
3483 void example_fast_pushpop(Pktlib_HeapHandle h , int n_trials)
3484 {
3485 int i,j;
3486 unsigned long t1;
3487 unsigned long t2;
3488 unsigned long sumf=0;
3489 unsigned long sumt=0;
3490 unsigned long sump=0;
3491 #define NTOPOP 190
3492 Ti_Pkt * tempVA;
3493 Qmss_QueueHnd freeQ=Pktlib_getInternalHeapQueue(h);
3495 //n_trials of NTOPOP actions
3496 for(i=0;i<n_trials;i++)
3497 {
3498 //raw pop
3499 t1= hplib_mUtilGetTickCount();
3500 pHd[0] = (Ti_Pkt *)QMSS_DESC_PTR(PKTIO_QMSS_QUEUE_POP_RAW (freeQ));
3501 for(j=1;j<NTOPOP;j++)
3502 {
3503 tempVA = hplib_mVMPhyToVirt(pHd[j-1]);
3504 netapi_pld(tempVA);
3505 //__builtin_prefetch(tempVA);
3506 pHd[j] = (Ti_Pkt *)QMSS_DESC_PTR(PKTIO_QMSS_QUEUE_POP_RAW (freeQ));
3507 sumf+= (int) ( ((Cppi_HostDesc *) tempVA)->origBuffPtr -
3508 ((Cppi_HostDesc *) tempVA)->buffPtr);
3509 }
3510 tempVA = hplib_mVMPhyToVirt(pHd[j-1]);
3511 sumf+= (int) ( ((Cppi_HostDesc *) tempVA)->origBuffPtr -
3512 ((Cppi_HostDesc *) tempVA)->buffPtr);
3513 t2=hplib_mUtilGetTickCount();
3514 sumt+= (t2-t1);
3516 //invalidate/wb
3517 for(j=0;j<NTOPOP;j++)
3518 {
3519 tempVA = hplib_mVMPhyToVirt(pHd[j]);
3520 hplib_CacheWbInv(tempVA,128);
3521 }
3523 //raw push
3524 t1=hplib_mUtilGetTickCount();
3525 for(j=0;j<NTOPOP;j++)
3526 {
3527 PKTIO_QMSS_QUEUE_PUSH_DESC_SIZE_RAW (freeQ,
3528 (void *) pHd[j],
3529 128);
3530 }
3531 t2=hplib_mUtilGetTickCount();
3532 sump += (t2-t1);
3533 }
3534 printf("\nfast poppush: np=%d pop=%d push=%d sumf=%d\n", (n_trials*NTOPOP),
3535 sumt/(n_trials*NTOPOP), sump/(n_trials*NTOPOP), sumf);
3536 sleep(1);
3537 return;
3538 }
3542 void example_fast_poll( PKTIO_HANDLE_T * p_pktio, int max_pkts)
3543 {
3544 int j=0;
3545 int jj=0;
3546 int i,k,l=0,ltot=0;
3547 int n= N2POLL; //max # of pkts to poll
3548 Ti_Pkt * tempVA;
3549 pasahoLongInfo_t* pinfo;
3550 unsigned long t1;
3551 unsigned long t2;
3552 unsigned long t11;
3553 unsigned long t12;
3554 unsigned long np;
3555 unsigned long sumt=0;
3556 unsigned long sumf=0;
3557 unsigned long sump=0;
3558 unsigned long totlen=0;
3559 int max_batch=0;
3561 //this should be done once and saved
3562 Qmss_QueueHnd rxQ= PKTIO_GET_DEFAULT_NETCP_Q(p_pktio);
3563 Qmss_QueueHnd freeQ;
3564 //loop forever
3565 for(;max_pkts>0;)
3566 {
3567 t1= hplib_mUtilGetTickCount();
3568 pHd[0] = (Ti_Pkt *)QMSS_DESC_PTR(PKTIO_QMSS_QUEUE_POP_RAW (rxQ));
3569 if (!pHd[0]) continue;
3570 //got pkt
3571 for(i=1;(i<n) && (pHd[i-1]);i++)
3572 {
3573 //convert previous descriptor PA -> VA
3574 tempVA = hplib_mVMPhyToVirt(pHd[i-1]);
3576 //try and preload desriptor
3577 __builtin_prefetch(tempVA);
3578 //netapi_pld(tempVA);
3580 //read next descriptor from queue
3581 pHd[i] = (Ti_Pkt *)QMSS_DESC_PTR(PKTIO_QMSS_QUEUE_POP_RAW (rxQ));
3582 #if 1
3583 /* extract some meta data */
3584 Cppi_getData (Cppi_DescType_HOST, (Cppi_Desc*)tempVA, &buf[jj], &len[jj]);
3585 pinfo = nwal_mGetProtoInfo(tempVA);
3586 l3_off[jj]= nwal_mGetL3OffBytes(pinfo);
3587 l4_off[jj]= nwal_mGetL4Offset(pinfo);
3588 if(nwal_mGetAppidFmPkt(tempVA,&appid[jj]) != nwal_TRUE)
3589 {
3590 printf("ERROR!!!! AppID not available in incoming packet \n");
3591 }
3592 //#define VERIFY_SOP
3593 #ifdef VERIFY_SOP
3594 if (sump < 200) printf("..sop off=%d\n", (int) buf[jj]-
3595 (int) ((Cppi_HostDesc *) tempVA)->origBuffPtr) ;
3596 #endif
3597 #endif
3598 jj+=1;
3599 }
3600 //finish last pkt in burst
3601 if(pHd[i-1])
3602 {
3603 //convert previous descriptor PA -> VA
3604 tempVA = hplib_mVMPhyToVirt(pHd[i-1]);
3606 /* extract some meta data */
3607 #if 1
3608 pinfo = nwal_mGetProtoInfo(tempVA);
3609 l3_off[jj]= nwal_mGetL3OffBytes(pinfo);
3610 l4_off[jj]= nwal_mGetL4Offset(pinfo);
3611 if(nwal_mGetAppidFmPkt(tempVA,&appid[jj]) != nwal_TRUE)
3612 {
3613 printf("ERROR!!!! AppID not available in incoming packet \n");
3614 }
3615 #endif
3616 //get ptr (Physical address) and length of associate buffer
3617 Cppi_getData (Cppi_DescType_HOST, (Cppi_Desc*)tempVA, &buf[jj], &len[jj]);
3618 jj+=1;
3619 }
3620 t2= hplib_mUtilGetTickCount();
3621 j+=(pHd[i-1]? i: (i-1)) ;
3622 if (jj>(M-n)) jj=0;
3623 l+=1; //n batches
3624 ltot+=1;
3625 if(pHd[i-1])
3626 {
3627 if (i>max_batch) max_batch= i;
3628 }
3629 else
3630 {
3631 if( (i-1) >max_batch) max_batch = i-1;
3632 }
3634 //cleanup
3635 //printf("cleanup %d\n",i);
3636 for(k=0;k<i;k++)
3637 {
3638 //cleanup. need to covert all of desriptor to VA so that i can use freePacket()
3639 //alternative would be to just do cache ops plus descriptor raw push to pktlib
3640 // heap free queue
3641 if(pHd[k])
3642 {
3644 //tempVA=Qmss_osalConvertDescPhyToVirt(pHd[k]);
3645 tempVA = hplib_mVMPhyToVirt(pHd[k]);
3646 freeQ=Qmss_getQueueHandle(Cppi_getReturnQueue (Cppi_DescType_HOST, (Cppi_Desc *)tempVA));
3647 hplib_CacheWbInv(tempVA,128);
3648 //would need to wbInv buffer also in practice. Also need to walk
3649 // descriptor chain
3650 t11= hplib_mUtilGetTickCount();
3651 // Pktlib_freePacket(tempVA);
3652 PKTIO_QMSS_QUEUE_PUSH_DESC_SIZE_RAW (freeQ,
3653 (void *) pHd[k],
3654 128);
3656 t12= hplib_mUtilGetTickCount();
3657 sumf += (t12-t11);
3658 }
3659 }
3660 sumt += (t2-t1);
3661 sump +=(pHd[i-1]? i: (i-1));
3662 max_pkts -= (pHd[i-1]? i: (i-1));
3664 //printf("end cleanup %d %d %d\n",sumt,sumf,sump );
3665 if (sump > 10000) {
3666 printf("pkts rx %d batches=%d appid=%x l3_off=%d l4_off=%d len=%d buf=0x%x rxcycle= %d pkts/batchx1000=%d maxbatch=%d cycles per rawpush = %d\n",
3667 j,ltot, appid[j%M],
3668 l3_off[j%M],l4_off[j%M],
3669 len[j%M],buf[j%M],
3670 sumt/sump, (sump*1000)/l, max_batch,
3671 sumf/sump);
3672 sumt=sump=sumf=0;
3673 l=0;
3674 }
3675 }
3677 //cleanup any remaining buffers
3678 for(;;)
3679 {
3680 pHd[0] = (Ti_Pkt *)QMSS_DESC_PTR(PKTIO_QMSS_QUEUE_POP_RAW (rxQ));
3681 if(!pHd[0]) break;
3682 tempVA = Osal_qmssPhyToVirt(pHd[0]);
3683 freeQ=Qmss_getQueueHandle(Cppi_getReturnQueue (Cppi_DescType_HOST, (Cppi_Desc *)tempVA));
3684 hplib_CacheWbInv(tempVA,128);
3685 PKTIO_QMSS_QUEUE_PUSH_DESC_SIZE_RAW (freeQ,
3686 (void *) pHd[0],
3687 128);
3688 }
3689 }
3691 #ifdef EXPERIMENTAL
3693 static inline void send_it(Ti_Pkt *tip, int len, ROUTE_SEC_T * p_sec, int out_port)
3694 {
3695 unsigned long st1;
3696 unsigned long st2;
3697 int err=0;
3698 PKTIO_METADATA_T meta2 = {PKTIO_META_TX,{0},0};
3699 nwalTxPktInfo_t meta_tx2={0};
3700 st1=hplib_mUtilGetTickCount();
3701 if (len<60)
3702 {
3703 unsigned int templen;
3704 char * p_pkt;
3705 len=60;
3706 Pktlib_getDataBuffer(tip,(uint8_t**)&p_pkt,&templen);//ignore templen
3707 Cppi_setData (Cppi_DescType_HOST, (Cppi_Desc *) tip, p_pkt,len);
3708 stats.tx_min+=1;
3709 }
3710 Pktlib_setPacketLen(tip,len);
3711 meta_tx2.txFlag1 = (NWAL_TX_FLAG1_DO_IPV4_CHKSUM| NWAL_TX_FLAG1_META_DATA_VALID );
3712 meta_tx2.startOffset = 0;
3713 meta_tx2.ipOffBytes = 14;
3714 meta_tx2.ploadLen = len ;
3715 meta_tx2.enetPort=out_port;
3716 if(p_sec)
3717 {
3718 meta_tx2.txFlag1 |= NWAL_TX_FLAG1_DO_IPSEC_ESP_CRYPTO ;
3719 meta2.sa_handle=p_sec->tx_inflow_mode_handle; //this tells netapi that inflow crypto needs to be applied
3720 meta_tx2.saOffBytes=14+20;
3721 meta_tx2.saPayloadLen=len-14-20; //don't include tag, mac and outer header
3722 stats.sec_tx+=1;
3723 }
3724 meta2.u.tx_meta=&meta_tx2;
3725 pktio_send(netcp_tx_chan,tip,&meta2,&err);
3726 stats.tx +=1;
3727 st2=hplib_mUtilGetTickCount();
3728 stats.send_cycles += (unsigned long long) (st2-st1);
3729 }
3730 void recv_cb_router(struct PKTIO_HANDLE_Tag * channel, Ti_Pkt* p_recv[],
3731 PKTIO_METADATA_T meta[], int n_pkts,
3732 uint64_t ts )
3733 {
3734 int i;
3735 int len;
3736 int p;
3737 Ti_Pkt * tip;
3738 unsigned int templen;
3739 char * p_pkt;
3740 HEAD_T temp_head;
3741 unsigned int appid;
3742 IP_HEAD_T th;
3743 ROUTE_SEC_T *sec_data=NULL;
3744 unsigned long t1;
3745 unsigned long t2;
3746 unsigned long long ct1;
3747 unsigned long long ct2;
3748 unsigned short ip_pl;
3749 unsigned long long n_c_ops;
3750 int ifno;
3751 int out_port;
3752 #ifdef MULTI_THREAD
3753 int coreid=our_core; //who we are(thread local)
3754 #else
3755 int coreid=0;
3756 #endif
3757 t1=hplib_mUtilGetTickCount();
3758 ct1 =Osal_cache_op_measure(&n_c_ops);
3759 for(i=0;i<n_pkts;i++)
3760 {
3761 ifno = ((unsigned int)meta[i].u.rx_meta->appId)&0xff;
3762 if(coreid<TUNE_NETAPI_NUM_CORES) stats.core_rx[coreid]+=1;
3763 if (ifno < TUNE_NETAPI_MAX_INTERFACES) stats.if_rx[ifno]+=1;
3764 tip = p_recv[i];
3765 Pktlib_getDataBuffer(tip,(uint8_t**)&p_pkt,&templen);//ignore templen
3766 len = Pktlib_getPacketLen(tip)-4;//real length, subtract mac trailer
3767 stats.rx+=1;
3768 appid = ((unsigned int)meta[i].u.rx_meta->appId)&0xff000000;
3769 switch(appid)
3770 {
3771 case(NETAPI_NETCP_MATCH_IPSEC):
3772 case(NETAPI_NETCP_MATCH_IPSEC_POLICY):
3773 {
3774 int tailen=12+2;
3775 memcpy(&temp_head,&p_pkt[14],sizeof(HEAD_T));
3776 if (!check_header(&temp_head,&meta[i])) {
3777 stats.n_bad+=1;
3778 Pktlib_freePacket(tip);
3779 continue;
3780 }
3781 tailen+=p_pkt[len-12-2]; //padding length (12)should come from sec_ptr
3782 p_pkt = &p_pkt[8+16+20]; //16= iv len, should come from sec_ptr
3783 len -= (8+16+20+tailen); //16= iv len should come from sec ptr
3785 //now check inner headder.
3786 memcpy(&th,&p_pkt[14],20);
3787 if (!check_header(&temp_head,&meta[i])) {
3788 stats.n_bad+=1;
3789 Pktlib_freePacket(tip);
3790 continue;
3791 }
3792 Cppi_setData (Cppi_DescType_HOST, (Cppi_Desc *) tip, p_pkt,len);
3793 Pktlib_setPacketLen(tip,len);
3795 if (route_pkt(our_router, tip, &th, p_pkt, &len,&sec_data,&out_port)<0)
3796 {
3797 stats.n_bad+=1;
3798 Pktlib_freePacket(tip);
3799 }
3800 else
3801 {
3802 send_it(tip,len,sec_data,out_port);
3803 }
3804 break;
3805 }
3806 case(NETAPI_NETCP_MATCH_GENERIC_MAC):
3807 if((p_pkt[12]!=0x8)||(p_pkt[13]!=0x00))
3808 {
3809 stats.n_new+=1;
3810 Pktlib_freePacket(tip);
3811 continue;
3812 }
3813 if (!check_header(&temp_head,&meta[i]))
3814 {
3815 stats.n_bad+=1;
3816 Pktlib_freePacket(tip);
3817 continue;
3818 }
3819 memcpy(&th,&p_pkt[14],20);
3820 ip_pl= (((unsigned char *)&th.w1)[2]<<8) | ((unsigned char *)&th.w1)[3];
3821 if ((ip_pl+14)<60)
3822 {
3823 len-= (60-(ip_pl+14));
3824 stats.rx_min+=1;
3825 }
3826 Pktlib_setPacketLen(tip,len);
3827 if (route_pkt(our_router, tip, &th, p_pkt, &len,&sec_data,&out_port)<0)
3828 {
3829 stats.n_bad+=1;
3830 Pktlib_freePacket(tip);
3831 }
3832 else
3833 {
3834 send_it(tip,len,sec_data,out_port);
3835 }
3836 break;
3837 case(NETAPI_NETCP_MATCH_GENERIC_IP):
3838 Pktlib_freePacket(tip);
3839 stats.n_new=1;
3840 break;
3841 default:
3842 stats.n_new+=1;
3843 Pktlib_freePacket(tip);
3844 break;
3845 }
3846 }
3847 t2=hplib_mUtilGetTickCount();
3848 ct2 =Osal_cache_op_measure(&n_c_ops);
3849 stats.app_cycles += (unsigned long long) (t2-t1);
3850 stats.tx_cache_cycles += (unsigned long long) (ct2-ct1);
3851 return;
3852 }
3853 #endif