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_INFLOW_LOW_LEVEL_API
44 #ifdef NET_TEST_ENABLE_INFLOW_LOW_LEVEL_API
45 #define NWAL_ENABLE_SA
46 #endif
47 #define NET_TEST_ENABLE_SIDE_BAND_LOW_LEVEL_API
48 #ifdef NET_TEST_ENABLE_SIDE_BAND_LOW_LEVEL_API
49 #define NWAL_ENABLE_SA
50 #endif
52 #include <stdio.h>
53 #include <stdlib.h>
54 #include <unistd.h>
55 #include <string.h>
58 #include "trie.h"
59 #include "string.h"
60 #include "netapi.h"
61 #include "pktio.h"
62 #include <sys/resource.h>
63 #include "net_test.h"
64 #include <ti/drv/sa/salld.h>
65 //#define EXPERIMENTAL
66 #ifdef EXPERIMENTAL
67 #include "router.c"
68 Trie * our_router;
73 OUR_ROUTE_T routes[MAX_ROUTES]=
74 {
75 {0,{0xD4,0xbe,0xd9,0x00,0xd3,0x7e, 0x00,0x01,0x02,0x03,0x14,0x02,0x08,0x00},0},
76 {0,{0x00,0x00,0x0,0x00,0x0,0x0, 0x00,0x00,0x00,0x00,0x00,0x00,0x08,0x00},0},
77 {0,{0xD4,0xbe,0xd9,0x00,0xd3,0x7e, 0x00,0x01,0x02,0x03,0x14,0x02,0x08,0x00},0},
78 {0,{0x00,0x15,0x60,0xa1,0xf7,0xbe, 0x00,0x01,0x02,0x03,0x04,0x05,0x08,0x00},0},
79 {0,{0xd4,0xbe,0xd9,0x00,0xd3,0x7e, 0x00,0x01,0x02,0x03,0x04,0x05,0x08,0x00},0}};
81 unsigned int ip[MAX_ROUTES]={BE(0x0a0100c8),BE(0x0a00000a),BE(0x0a02000a),BE(0xc0a8010a),BE(0x9eda6719)};
83 #endif
84 //#define TEST_TIMERS
86 /*************debug********************/
87 void dump_descr(unsigned long *p, int n)
88 {
89 printf("--------dump of descriptor %d %x\n", n, (int) p);
90 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]);
91 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]);
92 printf("-----------------------------\n");
93 }
94 void dump_header(unsigned long *p, int n, int a, int r)
95 {
96 printf("--------dump of header %d %x appID=%x flag1=%x\n", n, (int) p,a,r);
97 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]);
98 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]);
99 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]);
100 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]);
101 printf("-----------------------------\n");
102 }
104 /*****************************************/
107 //************for multi pkt burst xfer test in loopback mode
108 #define TX_BURST 700
109 int pktloopback=TUNE_NETAPI_NWAL_ENABLE_PASS_LOOPBACK;
110 nwalTxPSCmdInfo_t flowPSCmdInfo;
111 nwal_RetValue nwalRetVal;
113 /* Local Per Process default resourcese maintained at NWAL */
114 nwalLocCxtInfo_t nwalLocCxt;
116 //this device: 10.0.0.100, mac 0x,01,02,03,04,05 and .. 0x6
118 //test packet, setup for loopback (so dest is ourself)
119 static uint8_t testPkt[] = {
121 /* MAC header */
122 0x00, 0x01, 0x02, 0x03, 0x04, 0x05,
123 0x00, 0xe0, 0xa6, 0x66, 0x57, 0x04,
124 0x08, 0x00,
126 /* IP header */
127 0x45, 0x00,
128 0x00, 0x6c, /* Length (including this header) */
129 0x00, 0x00, 0x00, 0x00, 0x05, 0x11,
130 0x00, 0x00, /* Header checksum */
131 0x0a, 0x00, 0x00, 0x0a, 0x0a, 0x00, 0x00, 0x64,
133 /* UDP header */
134 0x12, 0x34, 0x05, 0x55,
135 0x00, 0x58, /* Length, including this header */
136 0x00, 0x00, /* Header checksum */
138 /* Payload */
139 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39,
140 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f, 0x40, 0x41,
141 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49,
142 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f, 0x50, 0x51,
143 0x52, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, 0x59,
144 0x5a, 0x5b, 0x5c, 0x5d, 0x5e, 0x5f, 0x60, 0x61,
145 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69,
146 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, 0x6f, 0x70, 0x71,
147 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79,
148 0x7a, 0x7b, 0x7c, 0x7d, 0x7e, 0x7f, 0x80, 0x81
150 };
152 char input_file_name[] = "net_test_config.txt";
153 #define MAX_LINE_LENGTH 40
155 #define TEST_PAYLOAD_LEN 80
157 #define TEST_PKT_IP_OFFSET_BYTES 14
158 #define TEST_PKT_UDP_OFFSET_BYTES 34
159 #define TEST_PKT_PLOAD_OFFSET_BYTES 42
160 #define TEST_PKT_UDP_HDR_LEN 8
161 /* Offsets to length fields */
162 #define TEST_PKT_OFFSET_IP_LEN 16
163 #define TEST_PKT_OFFSET_UDP_LEN 38
165 #define TEST_PKT_LEN 122
167 /* The pseudo header checksum of the packet except for the 16 bit length */
168 #define TEST_PKT_PSEUDO_HDR_CHKSUM_SANS_LEN 0x0FFC
170 void example_fast_poll( PKTIO_HANDLE_T * p_pktio, int max_pkts);
171 void example_fast_pushpop(Pktlib_HeapHandle p_heap, int ntrials);
173 void recv_cb_router(struct PKTIO_HANDLE_Tag * channel, Ti_Pkt* p_recv[],
174 PKTIO_METADATA_T meta[], int n_pkts,
175 uint64_t ts );
178 //#include "arpa/inet.h"
179 long htonl(long x)
180 {
181 long temp = (x&0xff000000)>>24 | (x&0xff0000)>>8 | (x&0xff00)<<8 | (x&0xff)<<24 ;
182 return temp;
183 }
185 /********************************************************************
186 * FUNCTION PURPOSE: Ones complement addition utility
187 ********************************************************************
188 ********************************************************************/
189 uint16_t test_utilOnesComplementAdd (uint16_t v1, uint16_t v2)
190 {
191 uint32_t result;
193 result = (uint32_t)v1 + (uint32_t)v2;
194 result = (result >> 16) + (result & 0xffff);
195 result = (result >> 16) + (result & 0xffff);
197 return ((uint16_t)result);
198 }
200 /********************************************************************
201 * FUNCTION PURPOSE: Ones complement checksum utility
202 ********************************************************************
203 ********************************************************************/
204 uint16_t test_utilOnesCompChkSum (uint8_t *p, uint32_t nwords)
205 {
206 uint16_t chksum = 0;
207 uint16_t v;
208 uint32_t i;
209 uint32_t j;
211 for (i = j = 0; i < nwords; i++, j+=2) {
212 v = (p[j] << 8) | p[j+1];
213 chksum = test_utilOnesComplementAdd (chksum, v);
214 }
215 return (chksum);
216 } /* utilOnesCompChkSum */
218 /**************************************************************************************
219 * FUNCTION PURPOSE: Compute ipv4 psudo checksum
220 **************************************************************************************
221 * DESCRIPTION: Compute ipv4 psudo checksum
222 **************************************************************************************/
223 uint16_t test_utilGetIpv4PsudoChkSum (uint8_t *data, uint16_t payloadLen)
224 {
225 uint16_t psudo_chksum;
227 psudo_chksum = test_utilOnesCompChkSum (&data[12], 4);
228 psudo_chksum = test_utilOnesComplementAdd(psudo_chksum, (uint16_t) data[9]);
229 psudo_chksum = test_utilOnesComplementAdd(psudo_chksum, payloadLen);
231 return (psudo_chksum);
233 } /* utilGetIpv4PsudoChkSum */
237 /* net test default configuration */
238 netTestConfig_t config =
239 {
240 {0x00,0x01,0x02,0x03,0x05,0x05},
241 {0x00,0x01,0x02,0x03,0x05,0x06},
242 {10, 0, 0, 100, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
243 {10, 0, 1, 100, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
244 {10, 0, 2, 100, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
245 {192,168 , 1, 100, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
246 {192,168 , 1, 10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
247 IPSEC_MODE_RX_SIDEBAND,
248 IPSEC_MODE_TX_SIDEBAND,
249 0
250 };
252 #if 1 //goes with real tx (to laptop)
253 unsigned char real_mac_header[]={0xd4,0xbe,0xd9,0x00,0xd3,0x7e,
254 0x00,0x01,0x02,0x03,0x04,0x05,
255 0x08,0x00};
256 unsigned char real_ip_addr[]={0xa,0x00,0x00,0x64,0xa,0x0,0x0,0xa};
257 #endif
259 #if 0 //goes with loopback
260 unsigned char mac_header[]={0x00,0x01,0x02,0x03,0x04,0x05,
261 0x00,0x11,0x22,0x33,0x44,0x55,
262 0x08,0x00};
263 #endif
264 #define NE 65536
265 HEAD_T *nat;
267 #define NP 5000
268 int n_pkt = NP;
269 STATS_T stats;
271 Trie * P_trie;
272 Trie *p_trie_sa;
273 HEAD_T pkts[NP];
274 #define PERSLOW 10 //% of pkts that will not be fastpath'd
275 int perslow= PERSLOW;
277 /*******************************************
278 *************NETAPI OBJECTS***************
279 *****************************************/
280 static NETAPI_CFG_T our_netapi_default_cfg=
281 {
282 TUNE_NETAPI_PERM_MEM_SZ,
283 128, //start of packet offset for hw to place data on rx for default flow
284 TUNE_NETAPI_QM_CONFIG_MAX_DESC_NUM, //max number of descriptors in system
285 TUNE_NETAPI_NUM_GLOBAL_DESC, //total we will use
286 TUNE_NETAPI_DEFAULT_NUM_BUFFERS, //#descriptors+buffers in default heap
287 64, //#descriptors w/o buffers in default heap
288 TUNE_NETAPI_DEFAULT_BUFFER_SIZE+128+128, //size of buffers in default heap
289 128 , //tail room
290 256 //extra room
291 };
293 Pktlib_HeapHandle OurHeap;
294 Pktlib_HeapHandle specialSmall;
295 Pktlib_HeapHandle specialLarge;
297 PKTIO_HANDLE_T *our_chan;
298 PKTIO_HANDLE_T *netcp_rx_chan;
299 PKTIO_HANDLE_T *netcp_rx_chan2;
300 PKTIO_HANDLE_T *netcp_tx_chan;
301 PKTIO_HANDLE_T *netcp_sb_tx_chan;
302 PKTIO_HANDLE_T *netcp_sb_rx_chan;
303 PKTIO_CFG_T our_chan_cfg={PKTIO_RW, PKTIO_LOCAL, PKTIO_Q_ANY, 8};
304 PKTIO_CFG_T netcp_rx_cfg={PKTIO_R, PKTIO_NA, PKTIO_NA, 8};
305 PKTIO_CFG_T netcp_rx_cfg2={PKTIO_R, (PKTIO_GLOBAL|PKTIO_PKT), PKTIO_Q_ANY, 8};
306 PKTIO_CFG_T netcp_tx_cfg={PKTIO_W, PKTIO_NA, PKTIO_NA, 8};
307 PKTIO_CFG_T netcp_sb_rx_cfg={PKTIO_R, PKTIO_NA, PKTIO_NA, 8};
308 PKTIO_CFG_T netcp_sb_tx_cfg={PKTIO_W, PKTIO_NA, PKTIO_NA, 8};
310 void house(NETAPI_SCHED_HANDLE_T *s);
311 NETAPI_T netapi_handle;
312 NETAPI_SCHED_HANDLE_T * our_sched;
313 NETAPI_SCHED_CONFIG_T our_sched_cfg={
314 NETAPI_SCHED_DURATION|NETAPI_SCHED_CBV, 0, house, 5000000 //every 5000000 poll loops
315 };
316 void our_stats_cb(NETAPI_T h, paSysStats_t* pPaStats);
317 NETAPI_TIMER_GROUP_HANDLE_T ourTimerBlock;
318 NETAPI_TIMER_T t1;
319 NETAPI_TIMER_T t2;
320 NETAPI_TIMER_T t3;
322 void our_timer_cb( NETAPI_TIMER_GROUP_HANDLE_T th,
323 int n_fired, //# timers fired
324 NETAPI_TIMER_LIST_T fired_list,
325 uint64_t currentTime);
327 NETCP_CFG_IP_T ip_rule0;
328 NETCP_CFG_IP_T ip_rule1;
329 NETCP_CFG_CLASS_T class_0;
330 NETCP_CFG_CLASS_T class_1;
331 NETCP_CFG_CLASS_T class_2;
332 NETCP_CFG_FLOW_HANDLE_T specialFlow;
334 NETCP_CFG_CLASSIFIER_T class_0_cfg=
335 {
336 NETCP_CFG_CLASS_TYPE_L4,
337 {
338 .c_l4={0,0, NWAL_APP_PLOAD_PROTO_UDP, {2500}}
339 }
340 };
342 NETCP_CFG_CLASSIFIER_T class_1_cfg=
343 {
344 NETCP_CFG_CLASS_TYPE_L4,
345 {
346 .c_l4= {0,0, NWAL_APP_PLOAD_PROTO_UDP, {2502}}
347 }
348 };
350 NETCP_CFG_ROUTE_T class2_route=
351 {
352 NULL, NULL //* to be filled in
353 };
354 NETCP_CFG_CLASSIFIER_T class_2_cfg=
355 {
356 NETCP_CFG_CLASS_TYPE_L3_L4,
357 {
358 .c_l3_l4={0, 4 ,0/*fill in below*/ , NULL, NULL, //L2/L3
359 NWAL_APP_PLOAD_PROTO_UDP, {2504}} //L4
360 }
361 };
363 PKTIO_CONTROL_T zap_channel_control={PKTIO_CLEAR, NULL};
365 /* security objects. (for loopback mode) */
366 netTestSA_t sa_info[7];
367 int netapi_algorithm_set = 0;
368 int netapi_sec_sa_mode = 2;
369 /* tmannan-end */
370 //NETCP_CFG_SA_T rx_tunnel;
371 //NETCP_CFG_SA_T tx_tunnel;
372 NETCP_CFG_IPSEC_POLICY_T rx_policy[4];
373 //void * rx_data_mode_handle;
374 //void * tx_data_mode_handle;
375 //void * rx_inflow_mode_handle;
376 //void * tx_inflow_mode_handle;
377 /* rx */
380 NETAPI_SEC_SA_INFO_T rx_sa [7] = {
381 {
382 NWAL_SA_DIR_INBOUND,
383 0x11111111, //spi
384 nwal_IpSecProtoESP, //ESP mode
385 nwal_SA_MODE_TUNNEL, //tunnel mode
386 nwal_IPV4, //v4
387 { 1, 2, 3, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, /* Src IP (them) -> set below */
388 { 1, 2, 3, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, /* dst IP (us)-> set below*/
389 64,/* replayWindow */
390 NWAL_SA_AALG_HMAC_SHA1,
391 NWAL_SA_EALG_AES_CBC,
392 0,0 //na
393 },
394 {
395 NWAL_SA_DIR_INBOUND,
396 0x22222222, //spi
397 nwal_IpSecProtoESP, //ESP mode
398 nwal_SA_MODE_TUNNEL, //tunnel mode
399 nwal_IPV4, //v4
400 { 1, 2, 3, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, /* Src IP (them) -> set below */
401 { 1, 2, 3, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, /* dst IP (us)-> set below*/
402 64,/* replayWindow */
403 NWAL_SA_AALG_HMAC_SHA2_256,
404 NWAL_SA_EALG_AES_CTR,
405 0,0 //na
406 },
407 {
408 NWAL_SA_DIR_INBOUND,
409 0x33333333, //spi
410 nwal_IpSecProtoESP, //ESP mode
411 nwal_SA_MODE_TUNNEL, //tunnel mode
412 nwal_IPV4, //v4
413 { 1, 2, 3, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, /* Src IP (them) -> set below */
414 { 1, 2, 3, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, /* dst IP (us)-> set below*/
415 64,/* replayWindow */
416 NWAL_SA_AALG_HMAC_SHA2_256,
417 NWAL_SA_EALG_3DES_CBC,
418 0,0 //na
419 },
420 {
421 NWAL_SA_DIR_INBOUND,
422 0x44444444, //spi
423 nwal_IpSecProtoESP, //ESP mode
424 nwal_SA_MODE_TUNNEL, //tunnel mode
425 nwal_IPV4, //v4
426 { 1, 2, 3, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, /* Src IP (them) -> set below */
427 { 1, 2, 3, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, /* dst IP (us)-> set below*/
428 64,/* replayWindow */
429 NWAL_SA_AALG_HMAC_MD5,
430 NWAL_SA_EALG_NULL,
431 0,0 //na
432 },
433 {
434 NWAL_SA_DIR_INBOUND,
435 0x55555555, //spi
436 nwal_IpSecProtoESP, //ESP mode
437 nwal_SA_MODE_TUNNEL, //tunnel mode
438 nwal_IPV4, //v4
439 { 1, 2, 3, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, /* Src IP (them) -> set below */
440 { 1, 2, 3, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, /* dst IP (us)-> set below*/
441 64,/* replayWindow */
442 NWAL_SA_AALG_NULL,
443 NWAL_SA_EALG_AES_GCM,
444 0,0 //na
445 },
446 {
447 NWAL_SA_DIR_INBOUND,
448 0x66666666, //spi
449 nwal_IpSecProtoESP, //ESP mode
450 nwal_SA_MODE_TUNNEL, //tunnel mode
451 nwal_IPV4, //v4
452 { 1, 2, 3, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, /* Src IP (them) -> set below */
453 { 1, 2, 3, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, /* dst IP (us)-> set below*/
454 64,/* replayWindow */
455 NWAL_SA_AALG_NULL,
456 NWAL_SA_EALG_AES_CCM,
457 0,0 //na
458 },
459 {
460 NWAL_SA_DIR_INBOUND,
461 0x77777777, //spi
462 nwal_IpSecProtoESP, //ESP mode
463 nwal_SA_MODE_TUNNEL, //tunnel mode
464 nwal_IPV4, //v4
465 { 1, 2, 3, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, /* Src IP (them) -> set below */
466 { 1, 2, 3, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, /* dst IP (us)-> set below*/
467 64,/* replayWindow */
468 NWAL_SA_AALG_AES_XCBC,
469 NWAL_SA_EALG_NULL,
470 0,0 //na
471 }
472 };
474 /*tx */
475 NETAPI_SEC_SA_INFO_T tx_sa[7]= {
476 {
477 NWAL_SA_DIR_OUTBOUND,
478 0x11111111, //spi
479 nwal_IpSecProtoESP, //ESP mode
480 nwal_SA_MODE_TUNNEL, //tunnel mode
481 nwal_IPV4, //v4
482 { 1, 2, 3, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, /* Src IP (us) -> set below */
483 { 1, 2, 3, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, /* dst IP (them) -> set below*/
484 64, /* NA replayWindow */
485 NWAL_SA_AALG_HMAC_SHA1,
486 NWAL_SA_EALG_AES_CBC,
487 0,0 //seq no
488 },
489 {
490 NWAL_SA_DIR_OUTBOUND,
491 0x22222222, //spi
492 nwal_IpSecProtoESP, //ESP mode
493 nwal_SA_MODE_TUNNEL, //tunnel mode
494 nwal_IPV4, //v4
495 { 1, 2, 3, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, /* Src IP (us) -> set below */
496 { 1, 2, 3, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, /* dst IP (them) -> set below*/
497 64, /* NA replayWindow */
498 NWAL_SA_AALG_HMAC_SHA2_256,
499 NWAL_SA_EALG_AES_CTR,
500 0,0 //seq no
501 },
502 {
503 NWAL_SA_DIR_OUTBOUND,
504 0x33333333, //spi
505 nwal_IpSecProtoESP, //ESP mode
506 nwal_SA_MODE_TUNNEL, //tunnel mode
507 nwal_IPV4, //v4
508 { 1, 2, 3, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, /* Src IP (us) -> set below */
509 { 1, 2, 3, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, /* dst IP (them) -> set below*/
510 64, /* NA replayWindow */
511 NWAL_SA_AALG_HMAC_SHA2_256,
512 NWAL_SA_EALG_3DES_CBC,
513 0,0 //seq no
514 },
515 {
516 NWAL_SA_DIR_OUTBOUND,
517 0x44444444, //spi
518 nwal_IpSecProtoESP, //ESP mode
519 nwal_SA_MODE_TUNNEL, //tunnel mode
520 nwal_IPV4, //v4
521 { 1, 2, 3, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, /* Src IP (us) -> set below */
522 { 1, 2, 3, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, /* dst IP (them) -> set below*/
523 64, /* NA replayWindow */
524 NWAL_SA_AALG_HMAC_MD5,
525 NWAL_SA_EALG_NULL,
526 },
527 {
528 NWAL_SA_DIR_OUTBOUND,
529 0x55555555, //spi
530 nwal_IpSecProtoESP, //ESP mode
531 nwal_SA_MODE_TUNNEL, //tunnel mode
532 nwal_IPV4, //v4
533 { 1, 2, 3, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, /* Src IP (them) -> set below */
534 { 1, 2, 3, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, /* dst IP (us)-> set below*/
535 64,/* replayWindow */
536 NWAL_SA_AALG_NULL,
537 NWAL_SA_EALG_AES_GCM,
538 0,0 //na
539 },
540 {
541 NWAL_SA_DIR_OUTBOUND,
542 0x66666666, //spi
543 nwal_IpSecProtoESP, //ESP mode
544 nwal_SA_MODE_TUNNEL, //tunnel mode
545 nwal_IPV4, //v4
546 { 1, 2, 3, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, /* Src IP (them) -> set below */
547 { 1, 2, 3, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, /* dst IP (us)-> set below*/
548 64,/* replayWindow */
549 NWAL_SA_AALG_NULL,
550 NWAL_SA_EALG_AES_CCM,
551 0,0 //na
552 },
553 {
554 NWAL_SA_DIR_OUTBOUND,
555 0x77777777, //spi
556 nwal_IpSecProtoESP, //ESP mode
557 nwal_SA_MODE_TUNNEL, //tunnel mode
558 nwal_IPV4, //v4
559 { 1, 2, 3, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, /* Src IP (them) -> set below */
560 { 1, 2, 3, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, /* dst IP (us)-> set below*/
561 64,/* replayWindow */
562 NWAL_SA_AALG_AES_XCBC,
563 NWAL_SA_EALG_NULL,
564 0,0 //na
565 }
566 };
568 static nwalSecKeyParams_t ourTXKeyParams[7] ={
569 {
570 32, /* encKeySize: CTR 16 bytes Encryption Key and 4 bytes Salt : 24 bytes:NWAL_SA_EALG_3DES_CBC and 0 bytes Salt*/
571 20, /* macKeySize: 16 bytes NWAL_SA_AALG_HMAC_SHA1 */
572 NULL, //set below
573 NULL, //set below
574 },
575 {
576 20, /* encKeySize: CTR 16 bytes Encryption Key and 4 bytes Salt : 24 bytes:NWAL_SA_EALG_AES_CTR and 0 bytes Salt*/
577 32, /* macKeySize: 16 bytes NWAL_SA_AALG_HMAC_SHA2_256 */
578 NULL, //set below
579 NULL, //set below
580 },
581 {
582 24, /* encKeySize: DES-CBC: 24 bytes:NWAL_SA_EALG_3DES_CBC and 0 bytes Salt*/
583 32, /* macKeySize: 16 bytes NWAL_SA_AALG_HMAC_SHA2_256 */
584 NULL, //set below
585 NULL, //set below
586 },
587 {
588 0, /* NULL*/
589 16, /* MD5, 16 bytes */
590 NULL, //set below
591 NULL, //set below
592 },
593 {
594 20, /* encKeySize: GCM 16 bytes Encryption Key and 4 bytes Salt */
595 0, /* macKeySize: 0*/
596 NULL, //set below
597 NULL, //set below
598 },
599 {
600 19, /* encKeySize: CTR 16 bytes Encryption Key and 3 bytes Salt : 24 bytes:NWAL_SA_EALG_AES_CTR and 0 bytes Salt*/
601 0, /* macKeySize 0*/
602 NULL, //set below
603 NULL, //set below
604 },
605 {
606 0, /* encKeySize: CTR 16 bytes Encryption Key and 3 bytes Salt : 24 bytes:NWAL_SA_EALG_AES_CTR and 0 bytes Salt*/
607 16, /* macKeySize 0*/
608 NULL, //set below
609 NULL, //set below
610 }
611 };
613 /* these keys are for aes-ctr and hmac sha2_256 */
614 static nwalSecKeyParams_t ourRXKeyParams[7] ={
615 {
616 32, /* encKeySize: CTR 16 bytes Encryption Key and 4 bytes Salt : 24 bytes:NWAL_SA_EALG_3DES_CBC and 0 bytes Salt*/
617 20, /* macKeySize: 16 bytes NWAL_SA_AALG_HMAC_SHA1 */
618 NULL, //set below
619 NULL, //set below
620 },
621 {
622 20, /* encKeySize: CTR 16 bytes Encryption Key and 4 bytes Salt : 24 bytes:NWAL_SA_EALG_AES_CTR and 0 bytes Salt*/
623 32, /* macKeySize: 16 bytes NWAL_SA_AALG_HMAC_SHA2_256 */
624 NULL, //set below
625 NULL, //set below
626 },
627 {
628 24, /* encKeySize: DES-CBC: 24 bytes:NWAL_SA_EALG_3DES_CBC and 0 bytes Salt*/
629 32, /* macKeySize: 16 bytes NWAL_SA_AALG_HMAC_SHA2_256 */
630 NULL, //set below
631 NULL, //set below
632 },
633 {
634 0, /* NWAL_SA_EALG_NULL*/
635 16, /* NWAL_SA_AALG_HMAC_MD5, 16 bytes */
636 NULL, //set below
637 NULL, //set below
638 },
639 {
640 20, /* encKeySize: GCM 16 bytes Encryption Key and 4 bytes Salt */
641 0, /* macKeySize: 0*/
642 NULL, //set below
643 NULL, //set below
644 },
645 {
646 19, /* encKeySize: CTR 16 bytes Encryption Key and 3 bytes Salt t*/
647 0, /* macKeySize 0*/
648 NULL, //set below
649 NULL, //set below
650 },
651 {
652 0, /* encKeySize: CTR 16 bytes Encryption Key and 3 bytes Salt : 24 bytes:NWAL_SA_EALG_AES_CTR and 0 bytes Salt*/
653 16, /* macKeySize 0*/
654 NULL, //set below
655 NULL, //set below
656 }
657 };
660 static uint8_t ourAuthKey[36] =
661 {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F,
662 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F,
663 0x20, 0x21, 0x22, 0x23 };
664 ;
666 static uint8_t ourEncrKey[36] =
667 {0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0xFF,
668 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0xFF,
669 0x30, 0x31, 0x32, 0x33 };
672 /*************************END NETAPI OBJECTS***********************/
674 #define START_SRC_IP 0x0a00000a
675 #define DST_IP 0xc0a80001
676 #define NEW_START_SRC_IP 0x9eda000a
677 #define DST_PORT 0x555
678 #define START_SRC_PORT 0x1234
679 #define NEW_START_SRC_PORT 100
680 void update_header(HEAD_T * p_head, int len)
681 {
682 unsigned char *p = (unsigned char *) &p_head->udp[1];
683 len -= (20+14);
684 /* update ip checksum */
685 /* update udp checksum */
686 /* update length */
687 *p= (len&0xff00)>>8;
688 *(p+1) = len&0xff;
689 }
691 #if 0
692 void gen_pkts(int np)
693 {
694 int i;
695 int ip = START_SRC_IP &0xff;
696 int port= START_SRC_PORT;
697 //HEAD_T temp={{0x25000200,0xdead0000,0x80110000,START_SRC_IP,DST_IP},
698 // {START_SRC_PORT<<16|DST_PORT,0x01ec<<16|0x0000}};
699 HEAD_T temp;
700 memcpy(&temp,&testPkt[0],sizeof(HEAD_T));
702 for(i=0;(i<np) && (i<NP);i++)
703 {
704 memcpy(&pkts[i],&temp,sizeof(temp));
705 update_header(&pkts[i],512); /* update checksums etc */
706 /* change template for new pkt */
707 ip+=1;
708 if(ip>254) {(ip=START_SRC_IP&0xff); port+=1; }
709 temp.ip[3] = htonl((START_SRC_IP&0xffffff00)| ip);
710 temp.udp[0] = htonl( (temp.udp[0]&0xffff0000)| port);
711 temp.udp[1] = htonl(temp.udp[1]);
713 }
714 n_pkt=np;
715 }
716 #endif
718 void build_table(Trie * p_trie)
719 {
720 int i;
721 int sport=NEW_START_SRC_PORT;
722 HEAD_T temp,temp2;
723 KEY_T key;
725 memcpy(&temp,&testPkt[14],sizeof(temp));
727 //insert entry into trie
728 key.src_ip = temp.ip[3];
729 key.dst_ip = temp.ip[4];
730 key.src_port= (temp.udp[0]&0xffff0000)>>16;
731 key.dst_port= (temp.udp[0]&0x0000ffff);
732 trie_insert(p_trie,(char *)&key,sizeof(key), (void *) &nat[0]); //asociate with nat entry 0
734 //build nat table
735 for(i=0;i<100;i++)
736 {
737 memcpy(&temp2,&testPkt[14],sizeof(temp));
738 temp2.udp[0] = (temp2.udp[0] & 0xffff0000) | sport;
739 memcpy(&nat[i], &temp2, sizeof(temp2));
740 sport+= 1;
741 }
742 }
744 //===========stub transmitter==================
745 void send_pkt(Ti_Pkt *pkt, int len)
746 {
747 //just free pkt. Don't send
748 Pktlib_freePacket((Ti_Pkt*)pkt);
749 return;
750 }
752 //==========stub slow path============
753 void slow_path(Ti_Pkt *pkt, int len)
754 {
755 // debug: check descriptor for validity by verifying that desciptor link field is null as expected\n");
756 {Ti_Pkt * k= Pktlib_getNextPacket(pkt); if(k != 0) {printf(" slowpath, nexpkt != NULL");}}
757 //just free pkt
758 Pktlib_freePacket((Ti_Pkt*)pkt);
759 return;
760 }
761 /* check header */
762 struct LastPktInfo
763 {
764 int iface;
765 int ipcsum;
766 int l4csum;
767 } ;
768 static struct LastPktInfo lpInfo;
770 int check_header(HEAD_T * p_head, PKTIO_METADATA_T * p_meta)
771 {
772 if (NWAL_RX_FLAG1_META_DATA_VALID & p_meta->u.rx_meta->rxFlag1)
773 {
774 lpInfo.iface = ((unsigned int)p_meta->u.rx_meta->appId) &0xff; //last byte is interface num
775 lpInfo.ipcsum =(p_meta->u.rx_meta->rxFlag1 & NWAL_RX_FLAG1_IPV4_CHKSUM_VERIFY_MASK )== NWAL_RX_FLAG1_IPV4_CHKSUM_VERIFY_ACK ? 1 : 0;
776 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;
777 if ((unsigned int)p_meta->u.rx_meta->appId & NETAPI_NETCP_MATCH_IPSEC)
778 {
779 stats.sec_rx++;
780 }
781 if ((unsigned int)p_meta->u.rx_meta->appId & NETAPI_NETCP_MATCH_IPSEC_POLICY)
782 {
783 stats.secp_rx++;
784 }
786 if ((unsigned int)p_meta->u.rx_meta->appId & NETAPI_NETCP_MATCH_CLASS)
787 {
788 int c= ((unsigned int)p_meta->u.rx_meta->appId >>8)&0xffff;
789 if (c==0) stats.n_class0_rx +=1;
790 else if (c==1) stats.n_class1_rx +=1;
791 else if (c==2) stats.n_class2_rx +=1;
792 else printf("**NET_TEST RX -unknown class: %x\n", p_meta->u.rx_meta->appId);
793 }
794 }
796 return 1;
797 }
799 #define PKT_LEN 1400
800 void test_alloc_free(int n)
801 {
802 int i;
803 Ti_Pkt * b;
805 for(i=0;i<n;i++)
806 {
807 b=Pktlib_allocPacket(OurHeap,PKT_LEN);
808 Pktlib_freePacket(b);
809 }
810 }
812 //measurement test points
813 unsigned int vv1;
814 unsigned int vv2;
815 unsigned int vv3;
816 unsigned int vv4;
817 unsigned int vv5;
818 unsigned int vv6;
819 //these are updated by pktio.
820 #ifdef PKTIO_GET_BENCHMARK
821 extern unsigned int vv7p;
822 extern unsigned int vv8p;
823 extern unsigned int vv9p;
824 extern unsigned int vv10p;
825 extern unsigned int vv11p;
826 extern unsigned int vv12p;
828 extern unsigned int vv13p; //rcv path
829 extern unsigned int vv14p;
830 extern unsigned int vv15p;
831 #endif
833 unsigned int vv11;
835 extern unsigned int nwal_prof1,nwal_prof2,nwal_prof3,nwal_prof4,nwal_prof5,nwal_prof6;
837 //#define REASSEMBLE_BENCH
838 #ifdef REASSEMBLE_BENCH
839 #include <ti/drv/pa/example/reassemLib/reassemLib.h>
840 /*--------------reassembly benchmark--------------------------------*/
841 void our_reassemble_bench(int nfrags)
842 {
843 paIPReassemblyConfig_t Config={5,128,10000 };
844 int i,j;
845 int len;
846 Ti_Pkt tip;
847 char *buffer;
848 unsigned long v1;
849 unsigned long v2;
850 unsigned long sum1=0;
851 unsigned long sum2=0;
852 paEx_reassemLibInit(&Config);
853 for(j=0;j<200/nfrags;j++)
854 {
855 for(i=0;i<nfrags;i++)
856 {
857 short temp;
858 tip=Pktlib_allocPacket(OurHeap,PKT_LEN);
859 Pktlib_getDataBuffer(tip,(uint8_t**)&buffer,&len);
860 memcpy(&buffer[0],&testPkt[14],20); //IP header
861 if (i < (nfrags-1)) buffer[6] = 0x20;
862 temp = i*40;
863 buffer[6]|= (temp&0x1f00)>>8;
864 buffer[7]= (temp&0xff);
865 temp = 20+40*8;
866 buffer[2]= (temp&0xff00)>>8;
867 buffer[3]= (temp&0xff);
868 Pktlib_setPacketLen(tip, temp);
869 v1= netapi_timing_stop();
870 paEx_reassemLibProc(tip, 0xffff);
871 v2= netapi_timing_stop();
872 sum1+= v2-v1;
873 }
874 sum2 += v2-v1;
875 }
876 printf("reasssembly test: %d trials, %d frags/pkt %d cycles/frag %d cycles/last frag\n",j,nfrags, sum1/(j*nfrags), sum2/(j));
877 }
878 #endif
880 /*--------------basic pktio send/recv benchmark----------------------*/
881 unsigned int timings[10];
882 void our_pktio_bench(int ntrials)
883 {
884 int i;
885 #define NBATCH 8
886 Ti_Pkt tip;
887 unsigned char * pData;
888 int len;
889 int n;
890 int err;
891 int sum =0;
893 Osal_cache_op_measure_reset();
894 for(i=0;i<10;i++) timings[i]=0;
895 printf("calibration loop .. ");
896 for(i=0;i<1000;i++)
897 {
898 vv1= netapi_timing_stop();
899 vv2= netapi_timing_stop();
900 sum+=(vv2-vv1);
901 }
902 printf(" accuracy = +- %d cycles\n", sum/1000);
903 sleep(1);
905 PKTIO_METADATA_T meta[10]={0};
906 //send single, recv single
907 for(i=0;i<ntrials;i++)
908 {
909 vv1= netapi_timing_stop();
910 tip=Pktlib_allocPacket(OurHeap,PKT_LEN);
911 vv2= netapi_timing_stop();
912 Pktlib_getDataBuffer(tip,&pData,&len);
913 vv3= netapi_timing_stop();
914 pktio_send(our_chan,tip,&meta[0],&err);
915 vv4= netapi_timing_stop();
916 n=pktio_poll(our_chan,NULL , &err);
917 vv5= netapi_timing_stop();
918 timings[0]+=(vv6-vv4);
919 timings[1]+=(vv5-vv4);
920 timings[3]+=(vv4-vv3);
921 timings[5]+=(vv3-vv1);
922 timings[8]+=(vv11-vv6);
924 #ifdef PKTIO_GET_BENCHMARK
925 timings[2]+=(vv7p-vv4);
926 timings[4]+=(vv8p-vv3);
927 timings[6]+=(vv9p-vv8p);
928 timings[7]+=(vv10p-vv7p);
929 #endif
930 }
932 #ifdef PKTIO_GET_BENCHMARK
933 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,
934 timings[1]/ntrials, timings[2]/ntrials,timings[3]/ntrials, timings[4]/ntrials,timings[5]/ntrials,
935 timings[6]/ntrials,timings[7]/ntrials, timings[8]/ntrials );
936 {
937 unsigned int ccycles;
938 int n_c_ops;
939 ccycles =Osal_cache_op_measure(&n_c_ops);
940 printf("n_c_ops=%d cache_op_time=%d (total) = %d (pp)\n", n_c_ops, ccycles, n_c_ops? (ccycles/(n_c_ops)) : 0);
941 }
942 #endif
944 }
945 /*-----------test driver: gen an input pkt------- */
946 //char buffer[sizeof(HEAD_T)+PKT_LEN];
947 Ti_Pkt * get_pkt(int n, unsigned int *p_len, Pktlib_HeapHandle heap2use, int size, unsigned char * buf2cpy, int copy_size)
948 {
949 int ind;
950 long long temp;
951 Ti_Pkt * b;
952 char * buffer;
953 unsigned int len;
955 if (pktloopback==0)
956 {
957 if (n>=TX_BURST) return NULL; //just gen pkts to warm swtich, so that it knows
958 //our mac is valid
959 }
960 b=Pktlib_allocPacket(heap2use,size);
961 if (!b)
962 {printf("net_test: get_pkt() heap empty!! %d pkts gen'd %d \n", n); return NULL;};
964 //debug - way to validate descriptor
965 {Ti_Pkt* k= Pktlib_getNextPacket(b);
966 if(k != 0) {printf(" genpkt, nexpkt != NULL");}}
969 //get pointer to buffer area of packet
970 Pktlib_getDataBuffer(b,(uint8_t**)&buffer,&len);
971 if (!buffer)
972 {printf("net_test: get_pkt() heap returned empty buffer %d \n", n); return NULL;};
974 #if 0
975 if (pktloopback==0)
976 {
977 temp = (long long) rand();
978 temp *= PKT_LEN;
979 temp /= RAND_MAX;
980 temp +=2;
981 *p_len = (int) temp;
982 *p_len = *p_len &0xfffffffe;
983 temp = (long long) rand();
984 temp *= n_pkt;
985 temp /= RAND_MAX;
986 ind = (int) temp;
987 update_header(&pkts[ind],*p_len);
988 //printf("get pkt:%d %d ind=%d len=%d\n",RAND_MAX, rand(),ind, *p_len);
989 memcpy(&buffer[0], &mac_header[0],14);
990 memcpy(&buffer[14],(char*)&pkts[ind],sizeof(HEAD_T));
991 }
992 else
993 #endif
995 //copy test packet into buffer
996 {
997 memcpy(&buffer[0], buf2cpy, copy_size);
998 *p_len = copy_size;
999 }
1000 return b;
1001 }
1003 static int eof=0;
1004 /*--------------------------------------------------------------
1005 *----------utility to flip a packet and send
1006 *--------------------back to source----------------------------
1007 * flag=1 => ipsec
1008 *--------------------------------------------------------------*/
1009 void flip_and_send_pkt(Ti_Pkt *tip, unsigned char * p_pkt, int len, int flag)
1010 {
1011 unsigned char mac_temp[6];
1012 unsigned char ip_temp[4];
1013 unsigned char new_dest_port[2]={0x75,0x30}; // 30000
1014 uint16_t blah;
1015 uint16_t i=1; /* for testing only */
1017 uint8_t *p_spi;
1018 netTestSA_t * p_sa_info;
1019 uint8_t p_iv[16];
1020 uint8_t p_add[8];
1021 Cppi_HostDesc* pPloadDesc;
1023 Pktlib_setPacketLen(tip,len);
1024 //mac
1025 memcpy(&mac_temp,&p_pkt[0],6);
1026 memcpy(&p_pkt[0],&p_pkt[6],6);
1027 memcpy(&p_pkt[6],&mac_temp,6);
1028 //memcpy(&p_pkt[0],real_mac_header,6); //for testing to wireshark pc
1030 //ip (outer in case of ipsec)
1031 memcpy(&ip_temp, &p_pkt[14+12],4);
1032 memcpy(&p_pkt[14+12],&p_pkt[14+12+4],4);
1033 memcpy(&p_pkt[14+12+4],&ip_temp,4);
1035 //outer checksum to 0
1036 if (!flag)
1037 {
1038 memset(&p_pkt[14+10],0,2);
1039 }
1041 //inner ip &udp for ipsec
1042 if (flag)
1043 {
1044 p_spi = &(p_pkt[netTest_MAC_HEADER_LEN+netTest_IP_HEADER_LEN]);
1045 p_sa_info = (netTestSA_t *) trie_lookup(p_trie_sa, (char *)p_spi ,4);
1046 if (p_sa_info == NULL)
1047 {
1048 printf("flip_and_send_pkt(): trie_lookup() failed\n");
1049 return;
1050 }
1051 //just drop non-udp packet
1052 if (p_pkt[p_sa_info->tx_payload_info.encOffset+9]!=0x11)
1054 {
1055 stats.n_new+=1;Pktlib_freePacket(tip); return;
1056 }
1058 /* flip inner IP */
1059 memcpy(&ip_temp, &p_pkt[p_sa_info->tx_payload_info.encOffset+12],4);
1060 memcpy(&p_pkt[p_sa_info->tx_payload_info.encOffset+12],&p_pkt[p_sa_info->tx_payload_info.encOffset+12+4],4);
1061 memcpy(&p_pkt[p_sa_info->tx_payload_info.encOffset+12+4],&ip_temp,4);
1063 /* setting udp ports */
1064 memcpy(&p_pkt[p_sa_info->tx_payload_info.encOffset+20+2],&new_dest_port[0],2);
1065 memset(&p_pkt[p_sa_info->tx_payload_info.encOffset+20+6],0,2); //checksum
1070 if (config.ipsec_mode_tx == IPSEC_MODE_TX_SIDEBAND)
1071 {
1072 //inner ip checksum : leave alone
1073 #if 0
1074 blah=test_utilOnesCompChkSum (&p_pkt[14+20+8+16], 10);
1075 p_pkt[14+20+8+16+10]= (blah&0xff00)>>8;
1076 p_pkt[14+20+8+16+11]= blah&0xff;
1077 #endif
1079 //tbd udp checksum (leave at 0)
1081 //outer ip, set to 0 (we will compute on way out
1082 memset(&p_pkt[14+10],0,2);
1083 }
1084 else
1085 {
1086 //#else //inflow, don't touch outer , clear inner
1087 //DALmemset(&p_pkt[14+20+8+16+10],0,2); //inner checksum, we will compute on way out
1088 //outer ip checksum : leave alone
1090 #if 0
1091 blah = test_utilOnesCompChkSum (&p_pkt[14], 10);
1092 p_pkt[14+10]= (blah&0xff00)>>8;
1093 p_pkt[14+11]= blah&0xff;
1094 #endif
1096 }
1097 }
1098 else
1099 {
1100 memset(&p_pkt[14+20+6],0,2);//0 udp checksum (we will compute on way out
1101 memcpy(&p_pkt[14+20+2],&new_dest_port[0],2);
1102 }
1104 /*IPSEC case */
1105 if (flag)
1106 {
1107 if (config.ipsec_mode_tx == IPSEC_MODE_TX_SIDEBAND)
1108 //send to crypto for encryption
1109 //12 byte auth tag
1110 {
1111 PKTIO_METADATA_T meta = {PKTIO_META_SB_TX,{0},0};
1112 int err;
1113 nwalDmTxPayloadInfo_t meta_tx={0};
1114 meta.sa_handle=p_sa_info->tx_data_mode_handle; //use TX SA context
1116 #if 0
1118 meta_tx.encOffset =p_sa_info->tx_payload_info.encOffset;
1120 meta_tx.authOffset =netTest_MAC_HEADER_LEN+netTest_IP_HEADER_LEN;
1122 //meta_tx.encSize=len - 14- 20-8-16-12;
1123 meta_tx.encSize = len - p_sa_info->tx_payload_info.encOffset -netTest_ICV_LEN;
1125 //meta_tx.authSize= len -14-20-12;
1126 meta_tx.authSize = len - meta_tx.authOffset - netTest_ICV_LEN;
1127 //meta_tx.pEncIV= &p_pkt[14+20+8]; //just use same IV..
1128 #endif
1129 memcpy(&meta_tx, &(p_sa_info->tx_payload_info), sizeof(nwalDmTxPayloadInfo_t));
1132 meta_tx.encSize = len - p_sa_info->tx_payload_info.encOffset -p_sa_info->auth_tag_size;
1133 meta_tx.authSize = len - meta_tx.authOffset - p_sa_info->auth_tag_size;
1135 #if 0
1136 printf("flip_and_send_pkt(): encOffset %d\n", meta_tx.encOffset);
1137 printf("flip_and_send_pkt():authOffset %d\n", meta_tx.authOffset);
1138 printf("flip_and_send_pkt(): encSize %d\n", meta_tx.encSize);
1139 printf("flip_and_send_pkt(): authSize %d\n", meta_tx.authSize);
1140 #endif
1142 meta_tx.pAuthIV=NULL;
1143 meta_tx.aadSize=0;
1144 meta_tx.pAad=NULL;
1145 if (p_sa_info->cipherMode == NWAL_SA_EALG_AES_CTR)
1146 {
1147 memcpy(&p_iv[0], &ourEncrKey[16], 4);
1148 memcpy(&p_iv[4], &p_pkt[netTest_MAC_HEADER_LEN +netTest_IP_HEADER_LEN + netTest_ESP_HEADER_LEN], 8);
1149 p_iv[12] = 0;
1150 p_iv[13] = 0;
1151 p_iv[14] = 0;
1152 p_iv[15] = 1;
1153 meta_tx.pEncIV = &p_iv[0];
1154 }
1155 else if ((p_sa_info->cipherMode == NWAL_SA_EALG_AES_GCM) ||
1156 (p_sa_info->cipherMode == NWAL_SA_EALG_AES_CCM))
1157 {
1158 memcpy(&p_iv[0], &p_pkt[netTest_MAC_HEADER_LEN +netTest_IP_HEADER_LEN + netTest_ESP_HEADER_LEN], 8);
1159 meta_tx.pEncIV = &p_iv[0];
1160 memcpy(&p_add[0], &p_pkt[netTest_MAC_HEADER_LEN +netTest_IP_HEADER_LEN], 8);
1161 meta_tx.pAad= &p_add[0];
1162 meta_tx.aadSize = 8;
1163 }
1164 else if (p_sa_info->cipherMode == NWAL_SA_EALG_NULL)
1165 {
1166 meta_tx.pEncIV = NULL;
1167 }
1168 else
1169 {
1170 meta_tx.pEncIV = &p_pkt[netTest_MAC_HEADER_LEN +netTest_IP_HEADER_LEN + netTest_ESP_HEADER_LEN ];
1171 }
1172 /* post it to netcp sb tx channel*/
1173 meta_tx.appCtxId = (nwal_AppId)netapi_timing_start();
1174 meta.u.tx_sb_meta=&meta_tx;
1176 #ifdef NET_TEST_ENABLE_SIDE_BAND_LOW_LEVEL_API
1177 /* Use the command label which was cached during create time
1178 * Update the Queue to receive output packet from SA to the local
1179 * core Queue. Below information can be saved by application in
1180 * per process context to avoid API overhead per packet
1181 * Application can use below rxSbSaQ for polling packets back from
1182 * SA
1183 */
1184 nwalRetVal =
1185 nwal_getLocCxtInfo(PKTIO_GET_NWAL_INSTANCE(netcp_sb_tx_chan),
1186 &nwalLocCxt);
1187 if(nwalRetVal == nwal_OK)
1188 {
1189 p_sa_info->tx_dmPSCmdInfo.rxSbSaQ = nwalLocCxt.rxSbSaQ;
1190 }
1191 nwal_mCmdDMUpdate(tip,
1192 &p_sa_info->tx_dmPSCmdInfo,
1193 meta_tx.appCtxId,
1194 meta_tx.encOffset,
1195 meta_tx.encSize,
1196 meta_tx.pEncIV,
1197 meta_tx.authOffset,
1198 meta_tx.authSize,
1199 meta_tx.pAuthIV,
1200 meta_tx.aadSize,
1201 meta_tx.pAad);
1202 pPloadDesc = Pktlib_getDescFromPacket(tip);
1203 pPloadDesc = Qmss_osalConvertDescVirtToPhy(pPloadDesc);
1204 Qmss_queuePushDescSizeRaw(p_sa_info->tx_dmPSCmdInfo.txQueue,
1205 pPloadDesc,
1206 NWAL_DESC_SIZE);
1208 #else
1209 pktio_send(netcp_sb_tx_chan,tip,&meta,&err);
1210 #endif
1211 }
1212 else
1213 {
1214 //inflow tx
1215 //send pkt directly, asking for IP and UDP checksum offloads AND IPSEC to be applied
1216 PKTIO_METADATA_T meta = {PKTIO_META_TX,{0},0};
1217 int err;
1218 nwalTxPktInfo_t meta_tx={0};
1219 #define USE_COPY
1220 #ifdef USE_COPY
1221 //debug: see if re-using RX descriptor for TX is causing our SA lockup
1222 {
1223 int new_len=0;
1224 Ti_Pkt new_tip = get_pkt(0, &new_len, specialLarge , len+10 , &p_pkt[0] , len);
1225 if (!new_tip)
1226 {
1227 printf("net_test> new_tip NULL\n");
1228 }
1229 else
1230 {
1231 Pktlib_setPacketLen(new_tip,new_len);
1232 Pktlib_freePacket(tip);
1233 tip=new_tip;
1234 Pktlib_getDataBuffer(tip,(uint8_t**)&p_pkt,&new_len); //reset p_pkt to point to new buffer as its used below
1235 Cppi_setTimeStamp (Cppi_DescType_HOST, (Cppi_Desc *) tip,stats.sec_tx);
1236 }
1237 }
1238 if (len <1500)
1239 {
1240 eof+=1;
1241 }
1242 #endif
1243 meta.sa_handle=p_sa_info->tx_inflow_mode_handle; //this tells netapi that inflow crypto needs to be applied
1244 //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 );
1245 meta_tx.txFlag1 = p_sa_info->tx_pkt_info.txFlag1;
1246 meta_tx.enetPort=0;
1247 //meta_tx.saOffBytes=14+20;
1248 meta_tx.saOffBytes= p_sa_info->tx_pkt_info.saOffBytes;
1249 meta_tx.saPayloadLen=len-14-20; //don't include tag, mac and outer header
1250 //meta_tx.startOffset = 0;
1251 meta_tx.startOffset = p_sa_info->tx_pkt_info.startOffset;
1252 //meta_tx.ipOffBytes = 14+20+8+16; //to inner header
1253 meta_tx.ipOffBytes =p_sa_info->tx_payload_info.encOffset;
1254 //meta_tx.l4OffBytes = 14+20+8+16+20; //to L4
1255 meta_tx.l4OffBytes = p_sa_info->tx_pkt_info.l4OffBytes;
1256 meta_tx.l4HdrLen = p_sa_info->tx_pkt_info.l4HdrLen;
1257 meta_tx.ploadLen = (unsigned) ((p_pkt[meta_tx.l4OffBytes+4]<<8)|p_pkt[meta_tx.l4OffBytes+4+1]) -8 ;
1258 meta_tx.pseudoHdrChecksum =
1259 test_utilGetIpv4PsudoChkSum(&p_pkt[meta_tx.ipOffBytes],8+ meta_tx.ploadLen);
1261 /* post it to netcp tx channel*/
1262 meta.u.tx_meta=&meta_tx;
1263 if (stats.sec_tx<20) dump_descr((long *) tip, stats.sec_tx);
1264 #ifdef NET_TEST_ENABLE_INFLOW_LOW_LEVEL_API
1265 #if 0
1266 nwal_mCmdSetCrypPort (tip,
1267 &p_sa_info->tx_psCmdInfo,
1268 p_sa_info->tx_pkt_info.saOffBytes,
1269 meta_tx.saPayloadLen,
1270 p_sa_info->swInfo0,
1271 p_sa_info->swInfo1,
1272 NWAL_ENET_PORT_UNKNOWN);
1273 #endif
1274 nwal_mCmdSetL4CkSumCrypPort(tip,
1275 &p_sa_info->tx_psCmdInfo,
1276 meta_tx.l4OffBytes,
1277 meta_tx.ploadLen + meta_tx.l4HdrLen,
1278 meta_tx.pseudoHdrChecksum,
1279 p_sa_info->tx_pkt_info.saOffBytes,
1280 meta_tx.saPayloadLen,
1281 p_sa_info->swInfo0,
1282 p_sa_info->swInfo1,
1283 NWAL_ENET_PORT_UNKNOWN);
1285 pPloadDesc = Pktlib_getDescFromPacket(tip);
1286 pPloadDesc = Qmss_osalConvertDescVirtToPhy(pPloadDesc);
1287 Qmss_queuePushDescSizeRaw(p_sa_info->tx_psCmdInfo.txQueue,
1288 pPloadDesc,
1289 NWAL_DESC_SIZE);
1290 #else
1291 pktio_send(netcp_tx_chan,tip,&meta,&err);
1292 #endif
1293 stats.tx +=1;
1294 stats.sec_tx +=1;
1295 }
1296 }
1297 else //non ipsec send pkt directly, asking for IP and UDP checksum ofload
1298 {
1299 PKTIO_METADATA_T meta2 = {PKTIO_META_TX,{0},0};
1300 int err;
1301 nwalTxPktInfo_t meta_tx2={0};
1302 meta2.sa_handle=nwal_HANDLE_INVALID;
1303 meta_tx2.txFlag1 = (NWAL_TX_FLAG1_DO_IPV4_CHKSUM|NWAL_TX_FLAG1_DO_UDP_CHKSUM| NWAL_TX_FLAG1_META_DATA_VALID );
1304 meta_tx2.startOffset = 0;
1305 meta_tx2.ipOffBytes = 14;
1306 meta_tx2.l4OffBytes = 14+20;
1307 meta_tx2.l4HdrLen = 8;
1308 meta_tx2.ploadLen = (unsigned) ((p_pkt[14+20+4]<<8)|p_pkt[14+20+4+1]) -8 ;
1309 meta_tx2.pseudoHdrChecksum =
1310 test_utilGetIpv4PsudoChkSum(&p_pkt[14],8+ meta_tx2.ploadLen);
1312 /* post it to netcp tx channel*/
1313 meta2.u.tx_meta=&meta_tx2;
1314 pktio_send(netcp_tx_chan,tip,&meta2,&err);
1315 stats.tx +=1;
1316 }
1317 }
1322 /***************************************
1323 benchmark receive handler
1324 ****************************************/
1325 void recv_cb_bench(struct PKTIO_HANDLE_Tag * channel, Ti_Pkt* p_recv[],
1326 PKTIO_METADATA_T meta[], int n_pkts,
1327 uint64_t ts )
1328 {
1329 int i;
1330 vv6= netapi_timing_stop();
1331 for (i=0;i<n_pkts; i++)
1332 {
1333 Pktlib_freePacket(p_recv[i]);
1334 }
1335 vv11 = netapi_timing_stop();
1336 }
1338 /****************************************************************************************/
1339 /******************SB Accelerator Callback PKT RECEIVE HANDLER *************************/
1340 /****************** Handles Decrypt and Encrypt operation callbacks ******************/
1341 /******************************************************************************************/
1342 void recv_sb_cb(struct PKTIO_HANDLE_Tag * channel, Ti_Pkt* p_recv[],
1343 PKTIO_METADATA_T meta[], int n_pkts,
1344 uint64_t ts )
1345 {
1346 int i;
1347 int len;
1348 int p;
1349 HEAD_T * p_res;
1350 Ti_Pkt * tip;
1351 unsigned int templen;
1352 int err;
1353 KEY_T key;
1354 char * p_pkt;
1355 HEAD_T * p_head;
1356 HEAD_T temp_head;
1357 int tag_cmp=0;
1358 unsigned int hash[4];
1359 uint8_t *p_spi;
1360 netTestSA_t *p_sa_info;
1362 //nwal_AppId time;
1363 unsigned long time, delta_time;
1364 /* loop over received pkts */
1365 for(i=0;i<n_pkts;i++)
1366 {
1367 tip = p_recv[i];
1368 Pktlib_getDataBuffer(tip,(uint8_t**)&p_pkt,&templen);//ignore templen
1369 len = Pktlib_getPacketLen(tip);//real length
1372 p_spi = &(p_pkt[netTest_MAC_HEADER_LEN+netTest_IP_HEADER_LEN]);
1373 p_sa_info = (netTestSA_t *) trie_lookup(p_trie_sa, (char *)p_spi ,4);
1374 if (p_sa_info == NULL)
1375 {
1376 printf("recv_sb_cb(): trie_lookup failed\n");
1377 continue;
1378 }
1381 //is this a decrypt (rx_tunnel) complete
1382 if ((int)meta[i].u.rx_sb_meta->appId == p_sa_info->rx_tunnel)
1383 {
1385 time = netapi_timing_start();
1386 delta_time = time -(unsigned long) meta[i].u.rx_sb_meta->appCtxId;
1387 stats.total_decrypt_time += delta_time;
1388 stats.sb_rx+=1;
1389 //copy hash out of meta data (for some reason it needs endian conversion)
1390 hash[0]= htonl( meta[i].u.rx_sb_meta->pAuthTag[0]);
1391 hash[1]= htonl( meta[i].u.rx_sb_meta->pAuthTag[1]);
1392 hash[2]= htonl( meta[i].u.rx_sb_meta->pAuthTag[2]);
1393 hash[3]= htonl( meta[i].u.rx_sb_meta->pAuthTag[3]);
1394 if(stats.sb_rx<=16)
1395 {
1396 char *tp = (char *) &hash[0];
1397 //dump_header((long*)p_pkt, stats.sb_rx, (int)meta[i].u.rx_sb_meta->appId,0);
1398 #if 0
1399 printf("decrypt complete: tag in pkt= %x %x %x %x %x %x %x %x %x %x %x %x %x %x %x %x \n",
1400 p_pkt[len-16],p_pkt[len-15],p_pkt[len-14],p_pkt[len-13],
1401 p_pkt[len-12],p_pkt[len-11],p_pkt[len-10],p_pkt[len-9], p_pkt[len-8],
1402 p_pkt[len-7],p_pkt[len-6],
1403 p_pkt[len-5],p_pkt[len-4],p_pkt[len-3],p_pkt[len-2],p_pkt[len-1]);
1404 printf("decrypt complete: tag from SA=%x %x %x %x %x %x %x %x %x %x %x %x %x %x %x %x \n",
1405 tp[0],tp[1],tp[2],tp[3],tp[4],tp[5],
1406 tp[6],tp[7],tp[8],tp[9],tp[10],tp[11],tp[12],tp[13],tp[14],tp[15]);
1407 #endif
1408 }
1409 //check tag
1410 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
1411 stats.n_auth_ok += !(tag_cmp);
1413 flip_and_send_pkt(tip, p_pkt, len,1); //flip packet to echo back and send
1414 }
1415 //this is an encrypt (tx tunnel) complete
1416 else if((int)meta[i].u.rx_sb_meta->appId== p_sa_info->tx_tunnel )
1417 {
1418 hash[0]= htonl( meta[i].u.rx_sb_meta->pAuthTag[0]);
1419 hash[1]= htonl( meta[i].u.rx_sb_meta->pAuthTag[1]);
1420 hash[2]= htonl( meta[i].u.rx_sb_meta->pAuthTag[2]);
1421 hash[3]= htonl( meta[i].u.rx_sb_meta->pAuthTag[3]);
1422 stats.sb_tx+=1;
1423 if(stats.sb_tx<=16)
1424 {
1425 char *tp1 = (char *) &hash[0];
1426 //dump_header((long*)p_pkt, stats.sb_tx, (int)meta[i].u.rx_sb_meta->appId,0);
1427 #if 0
1428 printf("encrypt complete: tag in pkt= %x %x %x %x %x %x %x %x %x %x %x %x %x %x %x %x \n",
1429 p_pkt[len-16],p_pkt[len-15],p_pkt[len-14],p_pkt[len-13],
1430 p_pkt[len-12],p_pkt[len-11],p_pkt[len-10],p_pkt[len-9], p_pkt[len-8],
1431 p_pkt[len-7],p_pkt[len-6],
1432 p_pkt[len-5],p_pkt[len-4],p_pkt[len-3],p_pkt[len-2],p_pkt[len-1]);
1433 printf("encrypt complete: tag from SA=%x %x %x %x %x %x %x %x %x %x %x %x %x %x %x %x \n",
1434 tp1[0],tp1[1],tp1[2],tp1[3],tp1[4],tp1[5],
1435 tp1[6],tp1[7],tp1[8],tp1[9],tp1[10],tp1[11],tp1[12],tp1[13],tp1[14],tp1[15]);
1436 #endif
1437 }
1438 //put the computed tag in the packet
1439 memcpy(&p_pkt[len-p_sa_info->auth_tag_size],(char*)&hash[0],p_sa_info->auth_tag_size); //todo, really use meta->authTagLen
1440 {
1441 PKTIO_METADATA_T meta2 = {PKTIO_META_TX,{0},0};
1442 nwalTxPktInfo_t meta_tx={0};
1443 // now send directly
1444 meta2.sa_handle=nwal_HANDLE_INVALID;
1445 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
1446 meta_tx.startOffset = 0;
1447 meta_tx.ipOffBytes = netTest_MAC_HEADER_LEN;
1448 //not used
1449 meta_tx.l4OffBytes = 0;
1450 meta_tx.l4HdrLen = 0;
1451 meta_tx.ploadLen = 0;
1452 time = netapi_timing_start();
1453 delta_time = time -(unsigned long) meta[i].u.rx_sb_meta->appCtxId;
1454 stats.total_encrypt_time += delta_time;
1457 /* post it to netcp tx channel*/
1458 meta2.u.tx_meta=&meta_tx;
1459 pktio_send(netcp_tx_chan,tip,&meta2,&err);
1460 netapi_utilCacheWbInv(p_pkt,len);
1461 stats.tx +=1;
1462 }
1463 }
1464 else printf("netapi recv_sb_cb: unknown appiD %x \n",meta[i].u.rx_sb_meta->appId );
1465 }
1466 }
1468 /******************************************************/
1469 /******************PKT RECEIVE HANDLER *************************/
1470 /******************************************************/
1471 void recv_cb(struct PKTIO_HANDLE_Tag * channel, Ti_Pkt* p_recv[],
1472 PKTIO_METADATA_T meta[], int n_pkts,
1473 uint64_t ts )
1474 {
1475 int i;
1476 int len;
1477 int p;
1478 HEAD_T * p_res;
1479 Ti_Pkt * tip;
1480 unsigned int templen;
1481 int err;
1482 KEY_T key;
1483 char * p_pkt;
1484 HEAD_T * p_head;
1485 HEAD_T temp_head;
1486 netTestSA_t *p_sa_info;
1487 uint8_t *p_spi;
1488 uint8_t p_iv[16];
1489 uint8_t p_add[8];
1490 int16_t retVal;
1491 nwalGlobCxtInfo_t nwalGlobCxt;
1492 nwalLocCxtInfo_t nwalLocCxt;
1493 Cppi_HostDesc* pPloadDesc;
1495 p_head=&temp_head;
1497 //debug
1498 #if 0
1499 if (n_pkts != TX_BURST) {
1500 printf("recv_cb, txsofar=%d rxsofar=%d np = %d, NOT %d\n",
1501 stats.itx, stats.rx, n_pkts,TX_BURST);
1502 our_stats_cb(netapi_handle,NULL);
1503 }
1504 #endif
1505 //test_alloc_free(7);
1506 //printf("recv start\n");
1508 /* loop over received pkts */
1509 for(i=0;i<n_pkts;i++)
1510 {
1511 tip = p_recv[i];
1512 Pktlib_getDataBuffer(tip,(uint8_t**)&p_pkt,&templen);//ignore templen
1513 len = Pktlib_getPacketLen(tip)-4;//real length, subtract mac trailer
1514 Cppi_setData (Cppi_DescType_HOST, (Cppi_Desc *) tip, p_pkt,len);
1515 Pktlib_setPacketLen(tip,len);
1517 //debug: validate descriptor */
1518 if(Pktlib_getNextPacket(tip) != 0)
1519 {
1520 printf(" rcv_cb, nexpkt != NULL");
1521 }
1522 //debug printf("recv pkt, len=%d %d\n", len, templen);
1523 stats.rx+=1;
1525 #ifdef DEBUG_DESC
1526 if (stats.rx<16)
1527 {
1528 printf(">rx dmp..");
1529 dump_descr((long *) tip, stats.rx);
1530 }
1531 else if (stats.rx>99)
1532 {
1533 printf(">rx dmp..");
1534 dump_descr((long *) tip,stats.rx);
1535 }
1536 #endif
1537 #if 0
1538 if(stats.rx<=16)
1539 {
1540 dump_header((long*)p_pkt, stats.rx, (int)meta[i].u.rx_meta->appId,meta[i].u.rx_meta->rxFlag1);
1541 }
1542 #endif
1543 /* check header */
1544 memcpy(p_head,&p_pkt[14],sizeof(HEAD_T));
1546 if ((p_head->ip[2]&0x0000ff00)==0x00003200)
1547 {
1548 if (!check_header(p_head,&meta[i]))
1549 {
1550 stats.n_bad+=1;Pktlib_freePacket(tip);
1551 continue;
1552 }
1557 //process IP SEC PACKET
1558 if (config.ipsec_mode_rx == IPSEC_MODE_RX_SIDEBAND)
1559 {
1560 p_spi = &(p_pkt[netTest_MAC_HEADER_LEN+netTest_IP_HEADER_LEN]);
1561 p_sa_info = (netTestSA_t *) trie_lookup(p_trie_sa, (char *)p_spi ,4);
1562 if (p_sa_info == NULL)
1563 {
1564 printf("recv_cb(): trie_lookup() failed\n");
1565 continue;
1566 }
1568 //ship to crypto for decrypt!!
1569 //12 byte auth tag
1570 PKTIO_METADATA_T meta2 = {PKTIO_META_SB_TX,{0},0};
1571 nwalDmTxPayloadInfo_t meta_tx={0};
1572 meta2.sa_handle=p_sa_info->rx_data_mode_handle;
1574 memcpy(&meta_tx, &(p_sa_info->tx_payload_info), sizeof(nwalDmTxPayloadInfo_t));
1576 meta_tx.encSize = len - p_sa_info->tx_payload_info.encOffset -p_sa_info->auth_tag_size;
1577 meta_tx.authSize = len - meta_tx.authOffset - p_sa_info->auth_tag_size;
1580 if (p_sa_info->cipherMode == NWAL_SA_EALG_AES_CTR)
1581 {
1582 memcpy(&p_iv[0], &ourEncrKey[16], 4);
1583 memcpy(&p_iv[4], &p_pkt[netTest_MAC_HEADER_LEN +netTest_IP_HEADER_LEN + netTest_ESP_HEADER_LEN], 8);
1584 p_iv[12] = 0;
1585 p_iv[13] = 0;
1586 p_iv[14] = 0;
1587 p_iv[15] = 1;
1588 meta_tx.pEncIV = &p_iv[0];
1589 }
1590 else if ((p_sa_info->cipherMode == NWAL_SA_EALG_AES_GCM) ||
1591 (p_sa_info->cipherMode == NWAL_SA_EALG_AES_CCM))
1592 {
1593 memcpy(&p_iv[0], &p_pkt[netTest_MAC_HEADER_LEN +netTest_IP_HEADER_LEN + netTest_ESP_HEADER_LEN], 8);
1594 meta_tx.pEncIV = &p_iv[0];
1595 /* aad is the ESP header which is 8 bytes */
1596 memcpy(&p_add[0], &p_pkt[netTest_MAC_HEADER_LEN +netTest_IP_HEADER_LEN], 8);
1597 meta_tx.pAad= &p_add[0];
1598 meta_tx.aadSize = 8;
1599 }
1600 else if (p_sa_info->cipherMode == NWAL_SA_EALG_NULL)
1601 {
1602 meta_tx.pEncIV = NULL;
1603 }
1604 else
1605 {
1606 meta_tx.pEncIV = &p_pkt[netTest_MAC_HEADER_LEN +netTest_IP_HEADER_LEN + netTest_ESP_HEADER_LEN ];
1607 }
1608 meta_tx.appCtxId = (nwal_AppId)netapi_timing_start();
1609 //printf("recv_cb appCtxId: %lu\n", meta_tx.appCtxId);
1611 /* post it to netcp sb tx channel*/
1612 meta2.u.tx_sb_meta=&meta_tx;
1613 #ifdef NET_TEST_ENABLE_SIDE_BAND_LOW_LEVEL_API
1614 /* Use the command label which was cached during create time
1615 * Update the Queue to receive output packet from SA to the local
1616 * core Queue. Below information can be saved by application in
1617 * per process context to avoid API overhead per packet
1618 * Application can use below rxSbSaQ for polling packets back from
1619 * SA
1620 */
1621 nwalRetVal =
1622 nwal_getLocCxtInfo(PKTIO_GET_NWAL_INSTANCE(netcp_sb_tx_chan),
1623 &nwalLocCxt);
1624 if(nwalRetVal == nwal_OK)
1625 {
1626 p_sa_info->rx_dmPSCmdInfo.rxSbSaQ = nwalLocCxt.rxSbSaQ;
1627 }
1628 nwal_mCmdDMUpdate(tip,
1629 &p_sa_info->rx_dmPSCmdInfo,
1630 meta_tx.appCtxId,
1631 meta_tx.encOffset,
1632 meta_tx.encSize,
1633 meta_tx.pEncIV,
1634 meta_tx.authOffset,
1635 meta_tx.authSize,
1636 meta_tx.pAuthIV,
1637 meta_tx.aadSize,
1638 meta_tx.pAad);
1639 pPloadDesc = Pktlib_getDescFromPacket(tip);
1640 pPloadDesc = Qmss_osalConvertDescVirtToPhy(pPloadDesc);
1641 Qmss_queuePushDescSizeRaw(p_sa_info->rx_dmPSCmdInfo.txQueue,
1642 pPloadDesc,
1643 NWAL_DESC_SIZE);
1645 #else
1646 pktio_send(netcp_sb_tx_chan,tip,&meta2,&err);
1647 #endif
1648 continue;
1649 }
1650 else
1651 //inflow mode. flip and send
1652 flip_and_send_pkt(tip,p_pkt,len,1);
1653 }
1654 else if ((p_head->ip[2]&0x0000ff00)!=0x00001100)
1655 {
1656 stats.n_new+=1;Pktlib_freePacket(tip); continue;
1657 }
1658 else //non ipsec
1659 {
1660 if (!check_header(p_head,&meta[i])) {
1661 stats.n_bad+=1;Pktlib_freePacket(tip);
1662 continue;
1663 }
1665 #if 0
1666 /* lookup flow */
1667 key.src_ip = p_head->ip[3];
1668 key.dst_ip = p_head->ip[4];
1669 key.src_port= (p_head->udp[0]&0xffff0000)>>16;
1670 key.dst_port= (p_head->udp[0]&0x0000ffff);
1671 p_res= (HEAD_T *) trie_lookup(P_trie, (char *) &key, sizeof(key));
1672 if (!p_res) { stats.n_new+=1; slow_path(tip, len); continue;}
1674 /* copy header */
1675 memcpy((char *) p_head, (char *) p_res, sizeof(HEAD_T));
1677 memcpy(&p_pkt[14],p_head,sizeof(HEAD_T));
1678 /* update_mac(&p_pkt[0]); */
1680 /* 'simulate' send pkt */
1681 send_pkt(tip,len);
1682 #endif
1683 //just flip and send
1684 flip_and_send_pkt(tip,p_pkt,len,0);
1685 }
1686 }
1687 //printf("recv done\n");
1688 }
1690 #ifdef TEST_TIMERS
1691 //timer callback
1692 void our_timer_cb( NETAPI_TIMER_GROUP_HANDLE_T th,
1693 int n_fired, //# timers fired
1694 NETAPI_TIMER_LIST_T fired_list,
1695 uint64_t currentTime)
1696 {
1697 int i;
1698 NETAPI_TIMER_T tx;
1699 int cookie;
1700 int err;
1701 unsigned long long et;
1702 //DEBUGprintf("TIMER CALLBACK @ %lld %d timers\n", currentTime, n_fired);
1703 tx = netapi_TimerGetFirst(fired_list);
1704 for(i=0;i<n_fired;i++)
1705 {
1706 cookie = (int) netapi_TimerGetCookie(tx);
1707 et = netapi_TimerGetTs(tx); //debug
1708 //DEBUGprintf(" timer %d - cookie = %d expected ts=%lld (delta=%lld)\n", i, cookie, et, currentTime-et);
1709 if (cookie ==1)
1710 {
1711 stats.n_t1+=1;
1712 t1 = netapi_TimerGroupStartTimer(
1713 th,
1714 (void *) 1,
1715 100LL, //timer group tics
1716 &err);
1717 }
1718 else if (cookie ==2)
1719 {
1720 stats.n_t2+=1;
1721 t2 = netapi_TimerGroupStartTimer(
1722 th,
1723 (void *) 2,
1724 200LL, //timer group ticks
1725 &err);
1726 }
1727 else
1728 {
1729 stats.n_t3+=1;
1730 t3 = netapi_TimerGroupStartTimer(
1731 th,
1732 (void *) 3,
1733 300LL, //timer group ticks
1734 &err);
1735 //cancel 1 and restart 1
1736 netapi_TimerGroupCancel(th,t1,&err);
1737 t1 = netapi_TimerGroupStartTimer(
1738 th,
1739 (void *) 1,
1740 100LL, //timer group ticks
1741 &err);
1742 }
1743 tx = netapi_TimerGetNext(fired_list,tx);
1744 }
1745 }
1746 #endif
1747 void print_ipsec_stats(Sa_IpsecStats_t *p_saIpsecStats, nwal_saAALG auth, nwal_saEALG cipher)
1748 {
1749 #if 0
1750 if(retVal != nwal_OK)
1751 {
1752 System_printf("CORE: %d Error getting IP Sec Stats: Ret Status: %d \n",
1753 retVal);
1754 return(nwal_FALSE);
1755 }
1756 if((p_saIpsecStats->pktEncHi) ||(p_saIpsecStats->pktEncLo))
1757 {
1758 printf("------------- IPSec TX (Encryption Channel) Stats BEGIN --\n");
1759 }
1760 else
1761 {
1762 printf("------------- IPSec RX (Decryption Channel) Stats BEGIN --\n");
1763 }
1764 #endif
1765 printf("\nAutentication mode: %d, Encryption Mode: %d\n", auth, cipher);
1766 printf("IPSec replayOld:0x%x,replayDup:0x%x,authFail:0x%x \n",
1767 p_saIpsecStats->replayOld,p_saIpsecStats->replayDup,p_saIpsecStats->authFail);
1768 printf("IPSec txESN:0x%x,rxESN:0x%x,pktEncHi:0x%x,pktEncLo:0x%x,pktDecHi:0x%x,pktDecLo:0x%x \n",
1769 p_saIpsecStats->txESN,p_saIpsecStats->rxESN,p_saIpsecStats->pktEncHi,
1770 p_saIpsecStats->pktEncLo,p_saIpsecStats->pktDecHi,p_saIpsecStats->pktDecLo);
1771 }
1773 void print_datamode_stats(Sa_DataModeStats_t *p_saDataModeStats, nwal_saAALG auth, nwal_saEALG cipher)
1774 {
1776 printf("\nAutentication mode: %d, Encryption Mode: %d\n", auth, cipher);
1777 printf(" Packets processedHi: 0x%x, Packets processed Lo:0x%x\n",
1778 p_saDataModeStats->pktHi, p_saDataModeStats->pktLo);
1779 }
1784 static int np2process = NP;
1785 /******************************************************
1786 * stats callback
1787 *******************************************************/
1788 void our_stats_cb(NETAPI_T h, paSysStats_t* pPaStats)
1789 {
1790 uint32_t numFreeDataPackets;
1791 uint32_t numZeroBufferPackets;
1792 uint32_t numPacketsinGarbage;
1793 Pktlib_HeapStats pktLibHeapStats;
1794 int i;
1795 unsigned long long bcpp;
1796 unsigned long long bcpp_noc;
1797 unsigned long long bcpp_app;
1798 unsigned long long bcpp_tx;
1799 unsigned long long npL;
1800 unsigned long long cyclesL;
1801 unsigned long long ccyclesL; //cache cycles
1802 NETAPI_SA_STATS_T netapi_sa_stats;
1804 printf(">*****stats @ %lld\n", netapi_getTimestamp());
1805 //printf("netcp_tx_handle check %x\n", netcp_tx_chan->back);
1806 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\n",
1807 stats.itx, stats.rx, stats.tx, stats.n_bad, stats.n_new,
1808 stats.n_class0_rx, stats.n_class1_rx,
1809 stats.n_class2_rx, stats.sec_rx, stats.secp_rx, stats.sb_rx, stats.sb_tx, stats.n_auth_ok,
1810 stats.sec_tx);
1812 if (stats.rx && stats.tx)
1813 printf("decrypt time per packet(avg): %lu, encrypt time per packet(avg): %lu\n",
1814 (unsigned long) stats.total_decrypt_time/stats.rx, (unsigned long) stats.total_encrypt_time/stats.tx);
1815 netapi_sched_get_stats(&npL,&cyclesL,&ccyclesL);
1816 if (npL && stats.rx) {
1817 bcpp = cyclesL/npL;
1818 bcpp_noc = (cyclesL-ccyclesL)/npL;
1819 bcpp_app = (stats.app_cycles-stats.tx_cache_cycles)/stats.rx;
1820 }
1821 else {bcpp = bcpp_noc=bcpp_app=0L;}
1822 if (stats.tx)
1823 {
1824 bcpp_tx = (stats.send_cycles-stats.tx_cache_cycles)/stats.tx;
1825 }else {bcpp_tx = 0L;}
1826 printf("> ++ busy cycles pp=%lld (%lld wo cache ops) (app+tx= %lld) (tx= %lld) ++\n",
1827 bcpp,bcpp_noc,bcpp_app, bcpp_tx);
1828 if(pPaStats)
1829 {
1830 printf("C1 number of packets: %d\n", pPaStats->classify1.nPackets);
1831 printf("C1 number IPv4 packets: %d\n", pPaStats->classify1.nIpv4Packets);
1832 printf("C1 number IPv6 packets: %d\n", pPaStats->classify1.nIpv6Packets);
1833 printf("C1 number Custom packets: %d\n", pPaStats->classify1.nCustomPackets);
1834 printf("C1 number SRIO packets: %d\n", pPaStats->classify1.nSrioPackets);
1835 printf("C1 number LLC/SNAP Fail packets: %d\n", pPaStats->classify1.nLlcSnapFail);
1836 printf("C1 number table matched: %d\n", pPaStats->classify1.nTableMatch);
1837 printf("C1 number failed table matched: %d\n", pPaStats->classify1.nNoTableMatch);
1838 printf("C1 number IP Fragmented packets: %d\n", pPaStats->classify1.nIpFrag);
1839 printf("C1 number IP Depth Overflow: %d\n", pPaStats->classify1.nIpDepthOverflow);
1840 printf("C1 number VLAN Depth Overflow: %d\n", pPaStats->classify1.nVlanDepthOverflow);
1841 printf("C1 number GRE Depth Overflow: %d\n", pPaStats->classify1.nGreDepthOverflow);
1842 printf("C1 number MPLS Packets: %d\n", pPaStats->classify1.nMplsPackets);
1843 printf ("C1 number of parse fail: %d\n",pPaStats->classify1.nParseFail);
1844 printf("C1 number of Invalid IPv6 Opt: %d\n", pPaStats->classify1.nInvalidIPv6Opt);
1845 printf("C1 number of TX IP Fragments: %d\n", pPaStats->classify1.nTxIpFrag);
1846 printf ("C1 number of silent discard: %d\n",pPaStats->classify1.nSilentDiscard);
1847 printf("C1 number of invalid control: %d\n", pPaStats->classify1.nInvalidControl);
1848 printf ("C1 number of invalid states: %d\n",pPaStats->classify1.nInvalidState);
1849 printf ("C1 number of system fails: %d\n",pPaStats->classify1.nSystemFail);
1850 printf ("C2 number Packets : %d\n",pPaStats->classify2.nPackets);
1851 printf ("C2 number udp : %d\n",pPaStats->classify2.nUdp);
1852 printf ("C2 number tcp : %d\n",pPaStats->classify2.nTcp);
1853 printf ("C2 number Custom : %d\n",pPaStats->classify2.nCustom);
1854 printf ("C2 number silent drop : %d\n",pPaStats->classify2.nSilentDiscard);
1855 printf ("C2 number invalid cntrl : %d\n\n",pPaStats->classify2.nInvalidControl);
1856 printf ("C2 number Modify Stats Cmd Fail : %d\n\n",pPaStats->modify.nCommandFail);
1857 }
1858 Pktlib_getHeapStats(OurHeap, &pktLibHeapStats);
1859 printf("main heap stats> #free=%d #zb=%d #garbage=%d\n", pktLibHeapStats.numFreeDataPackets,
1860 pktLibHeapStats.numZeroBufferPackets, pktLibHeapStats.numPacketsinGarbage);
1861 printf(" > #dataBufThreshStatus=%d #dataBufStarvCounter=%d #zBufThreshStatus=%d #zBufStarvCounter=%d \n",
1862 pktLibHeapStats.dataBufferThresholdStatus,pktLibHeapStats.dataBufferStarvationCounter,
1863 pktLibHeapStats.zeroDataBufferThresholdStatus, pktLibHeapStats.zeroDataBufferStarvationCounter);
1865 Pktlib_getHeapStats(specialSmall, &pktLibHeapStats);
1866 printf("specialSmall heap stats> #free=%d #zb=%d #garbage=%d\n", pktLibHeapStats.numFreeDataPackets,
1867 pktLibHeapStats.numZeroBufferPackets, pktLibHeapStats.numPacketsinGarbage);
1868 printf(" > #dataBufThreshStatus=%d #dataBufStarvCounter=%d #zBufThreshStatus=%d #zBufStarvCounter=%d \n",
1869 pktLibHeapStats.dataBufferThresholdStatus,pktLibHeapStats.dataBufferStarvationCounter,
1870 pktLibHeapStats.zeroDataBufferThresholdStatus, pktLibHeapStats.zeroDataBufferStarvationCounter);
1873 Pktlib_getHeapStats(specialLarge, &pktLibHeapStats);
1874 printf("specialLarge heap stats> #free=%d #zb=%d #garbage=%d\n", pktLibHeapStats.numFreeDataPackets,
1875 pktLibHeapStats.numZeroBufferPackets, pktLibHeapStats.numPacketsinGarbage);
1876 printf(" > #dataBufThreshStatus=%d #dataBufStarvCounter=%d #zBufThreshStatus=%d #zBufStarvCounter=%d \n",
1877 pktLibHeapStats.dataBufferThresholdStatus,pktLibHeapStats.dataBufferStarvationCounter,
1878 pktLibHeapStats.zeroDataBufferThresholdStatus, pktLibHeapStats.zeroDataBufferStarvationCounter);
1881 #if 0
1882 printf("pa2sa descriptor area dump\n");
1883 for(i=0;i<TUNE_NETAPI_CONFIG_MAX_PA_TO_SA_DESC;i++)
1884 {
1885 extern long * pa2sa_descr_base;
1886 long * tip= &pa2sa_descr_base[32*i];
1887 dump_descr(tip, i);
1888 }
1889 printf("sa2pa descriptor area dump\n");
1890 for(i=0;i<TUNE_NETAPI_CONFIG_MAX_SA_TO_PA_DESC;i++)
1891 {
1892 extern long * sa2pa_descr_base;
1893 long * tip= &sa2pa_descr_base[32*i];
1894 dump_descr(tip, i);
1895 }
1896 #endif
1897 #ifdef TEST_TIMERS
1898 //debug = dump timer polling stats
1899 dump_poll_stats();
1900 //debug = dump timer polling stats
1901 //dump_poll_stats();
1902 #endif
1903 #ifndef EXPERIMENTAL
1904 for (i = 0; i < MAX_SEC_INDEX; i++)
1905 #else
1906 for (i=0; i < 1;i++)
1907 #endif
1908 {
1909 /* Statistics for RX Tunnel */
1910 memset(&netapi_sa_stats, 0, sizeof(netapi_sa_stats));
1911 netapi_getSaStats(netapi_handle, sa_info[i].rx_tunnel, &netapi_sa_stats);
1912 if (netapi_sa_stats.validParams & NETAPI_IPSEC_STAT_VALID)
1913 {
1914 print_ipsec_stats(&(netapi_sa_stats.saIpsecStats),
1915 rx_sa[i].authMode,
1916 rx_sa[i].cipherMode);
1917 }
1918 if (netapi_sa_stats.validParams & NETAPI_SIDEBAND_DATA_MODE_STAT_VALID)
1919 {
1920 print_datamode_stats(&(netapi_sa_stats.dataModeStats),
1921 rx_sa[i].authMode,
1922 rx_sa[i].cipherMode);
1923 }
1925 /* Statistics for TX Tunnel */
1926 memset(&netapi_sa_stats, 0, sizeof(netapi_sa_stats));
1927 netapi_getSaStats(netapi_handle, sa_info[i].tx_tunnel, &netapi_sa_stats);
1928 if (netapi_sa_stats.validParams & NETAPI_IPSEC_STAT_VALID)
1929 {
1930 print_ipsec_stats(&(netapi_sa_stats.saIpsecStats),
1931 tx_sa[i].authMode,
1932 tx_sa[i].cipherMode);
1933 }
1934 if (netapi_sa_stats.validParams & NETAPI_SIDEBAND_DATA_MODE_STAT_VALID)
1935 {
1936 print_datamode_stats(&(netapi_sa_stats.dataModeStats),
1937 tx_sa[i].authMode,
1938 tx_sa[i].cipherMode);
1939 }
1940 }
1941 //netapi_dump_internal_heap_stats();
1942 }
1944 //******************************************************
1945 //use scheduling housekeeping callback to generate pkts
1946 //******************************************************
1947 static int done_burst=0;
1948 void house(NETAPI_SCHED_HANDLE_T * s)
1949 {
1950 Ti_Pkt * tip;
1951 unsigned int len;
1952 nwalTxPktInfo_t meta_tx = {0};
1953 PKTIO_METADATA_T meta = {PKTIO_META_TX,{0},0};
1954 int err;
1955 static int house_pkts_gened=0;
1956 int p;
1957 unsigned char * pIpHdr,* pData;
1958 unsigned int vv1,vv2,vv3;
1959 unsigned int sum_vv1=0;
1960 unsigned int sum_vv2=0;
1961 unsigned int sum_vv3=0;
1962 unsigned int sum_vv4=0;
1963 unsigned int sum_vv5=0;
1965 unsigned int nwal_flow_vv1,nwal_flow_vv2;
1966 unsigned int nwal_sum_vv1=0;
1967 unsigned int nwal_sum_vv2=0;
1968 unsigned int nwal_sum_vv3=0;
1969 unsigned int nwal_sum_vv4=0;
1970 unsigned int nwal_sum_vv5=0;
1971 unsigned int nwal_sum_vv6=0;
1973 unsigned int nwal_sum_flow_vv1=0;
1974 unsigned int nwal_sum_flow_vv2=0;
1975 unsigned int cache_op_b1;
1976 unsigned int cache_op_b2;
1977 int n_c_ops;
1978 static int first =0;
1979 Cppi_HostDesc* pPktDesc;
1981 if(done_burst)
1982 {
1983 house_pkts_gened+=TX_BURST;
1984 printf("net_test> request stats at n=%d \n",house_pkts_gened);
1985 netcp_cfgReqStats(netapi_handle, our_stats_cb, 0,&err);
1986 if (err!=0) {printf("stats req failed\n");}
1987 if (house_pkts_gened >= np2process+ 100)
1988 {
1989 netapi_schedShutdown(s,NULL,&err);
1990 }
1991 return;
1992 }
1993 done_burst=1;
1994 Osal_cache_op_measure_reset();
1995 memset(&meta_tx,0,sizeof(meta_tx));
1996 for(p=0;p<TX_BURST;p++) {
1997 //reguest stats
1998 if ((house_pkts_gened>0) && (! (house_pkts_gened%1000)) )
1999 {
2000 printf("net_test> request stats at n=%d \n",house_pkts_gened);
2001 netcp_cfgReqStats(netapi_handle, our_stats_cb, 0,&err);
2002 if (err!=0) {printf("stats req failed\n");}
2003 }
2006 if (house_pkts_gened >= np2process+ 100)
2007 {
2008 //shutdown
2009 netapi_schedShutdown(s,NULL,&err);
2010 continue;
2011 }
2013 else if (house_pkts_gened >= np2process) { house_pkts_gened+=1; continue;}
2016 /* manufacture a pkt to transmit */
2017 tip = get_pkt(house_pkts_gened, &len, OurHeap, PKT_LEN,&testPkt[0] , TEST_PKT_LEN);
2018 if(!tip) { house_pkts_gened +=1; continue; }
2021 /* set the pkt length */
2022 vv1 = netapi_timing_start();
2023 Pktlib_setPacketLen(tip, len);
2025 /* set up meta data */
2026 meta.sa_handle=nwal_HANDLE_INVALID;
2027 //#define BENCH_UDP_SEND
2028 #ifdef BEND_UDP_SEND
2029 meta_tx.txFlag1 = (NWAL_TX_FLAG1_DO_IPV4_CHKSUM | NWAL_TX_FLAG1_DO_UDP_CHKSUM| NWAL_TX_FLAG1_META_DATA_VALID);
2030 meta_tx.startOffset = 0;
2031 //GONE in V2 meta_tx.pktLen = len;
2032 meta_tx.ipOffBytes = TEST_PKT_IP_OFFSET_BYTES;
2033 meta_tx.l4OffBytes = TEST_PKT_UDP_OFFSET_BYTES;
2034 meta_tx.l4HdrLen = TEST_PKT_UDP_HDR_LEN;
2035 //GONE in V2 meta_tx.ploadOffBytes = TEST_PKT_PLOAD_OFFSET_BYTES;
2036 meta_tx.ploadLen = TEST_PAYLOAD_LEN;
2038 Pktlib_getDataBuffer(tip,&pData,&len);
2039 if(house_pkts_gened &0x1)
2040 {
2041 memcpy(&pData[6],&config.mac1[0] ,6);
2042 }
2043 pIpHdr = pData + meta_tx.ipOffBytes;
2044 meta_tx.pseudoHdrChecksum =
2045 test_utilGetIpv4PsudoChkSum(pIpHdr,(TEST_PAYLOAD_LEN+TEST_PKT_UDP_HDR_LEN));
2046 #else
2047 Pktlib_getDataBuffer(tip,&pData,&len);
2048 if(house_pkts_gened &0x1)
2049 {
2050 memcpy(&pData[6],&config.mac1[0] ,6);
2051 }
2052 meta_tx.txFlag1 = NWAL_TX_FLAG1_META_DATA_VALID;
2053 meta_tx.startOffset = 0;
2054 meta_tx.ploadLen = TEST_PAYLOAD_LEN;
2055 #endif
2056 /* post it to netcp tx channel*/
2057 meta.u.tx_meta=&meta_tx;
2058 #ifdef DEBUG_DESC
2059 if (house_pkts_gened<16) dump_descr((long *) tip, house_pkts_gened);
2060 else if (house_pkts_gened>99) dump_descr((long *) tip,house_pkts_gened);
2061 #endif
2063 if(!first)
2064 {
2065 first++;
2066 nwal_flow_vv1= netapi_timing_stop();
2067 if(nwal_initPSCmdInfo(PKTIO_GET_NWAL_INSTANCE(netcp_tx_chan),
2068 &meta_tx,
2069 &flowPSCmdInfo) != nwal_OK)
2070 {
2071 printf("nwal_initPSCmdInfo() ERROR \n");
2072 }
2073 nwal_flow_vv2= netapi_timing_stop();
2074 nwal_sum_flow_vv1 += (nwal_flow_vv1-vv1);
2075 nwal_sum_flow_vv2 += (nwal_flow_vv2-nwal_flow_vv1);
2076 }
2078 cache_op_b1= Osal_cache_op_measure(&n_c_ops);
2079 vv2= netapi_timing_stop();
2080 #ifdef BEND_UDP_SEND
2081 nwal_mCmdSetL4CkSumPort( tip,
2082 &flowPSCmdInfo,
2083 TEST_PKT_UDP_OFFSET_BYTES,
2084 (TEST_PKT_UDP_HDR_LEN + TEST_PAYLOAD_LEN),
2085 meta_tx.pseudoHdrChecksum,
2086 meta_tx.enetPort);
2087 #else
2088 nwal_mCmdSetPort (tip,
2089 &flowPSCmdInfo, //could be NULL
2090 0); //port 0 -> switch decides
2092 #endif
2094 pPktDesc = Pktlib_getDescFromPacket(tip);
2095 /* Send the packet out to transmit Q*/
2096 Qmss_queuePushDescSize (flowPSCmdInfo.txQueue,
2097 pPktDesc,
2098 NWAL_DESC_SIZE);
2099 vv3= netapi_timing_stop();
2100 cache_op_b2= Osal_cache_op_measure(&n_c_ops);
2102 sum_vv1 += (vv2-vv1);
2103 if(!house_pkts_gened)
2104 {
2105 /* first packet. Take out the PS command label creation cost */
2106 sum_vv1 = sum_vv1 - nwal_sum_flow_vv2;
2107 }
2109 sum_vv3 += (vv3-vv2)-(cache_op_b2-cache_op_b1); //sub out cache op cost
2111 // printf("pktio send. full=%d metadata=%d pktio_send=%d\n", vv3-vv1, vv2-vv1, vv3-vv2);
2114 stats.itx +=1;
2115 house_pkts_gened +=1;
2116 }
2117 {
2118 unsigned int ccycles;
2119 ccycles =Osal_cache_op_measure(&n_c_ops);
2120 if (sum_vv1)
2121 {
2122 printf("BURST NWAL Fast send %d pkts. metadata=%d Cmd Label Creation Cost=%d nwal Fast Send Cost (less cacheop)= %d n_c_ops=%d cache_op_time=%d (pp-> %d)\n",
2123 stats.itx, sum_vv1/stats.itx, nwal_sum_flow_vv2, sum_vv3/stats.itx,
2124 n_c_ops, ccycles, n_c_ops? (ccycles/(n_c_ops/2)) : 0);
2125 #if 0
2126 printf("NWAL Profile Cycles: Prof1= %d,Prof2=%d,Prof3=%d,Prof4=%d,Prof5=%d ,Prof6=%d \n",
2127 nwal_sum_vv1/stats.itx,nwal_sum_vv2/stats.itx,nwal_sum_vv3/stats.itx,
2128 nwal_sum_vv4/stats.itx,nwal_sum_vv5/stats.itx,nwal_sum_vv6/stats.itx);
2130 #endif
2132 if(stats.itx2)
2133 {
2134 printf("nwal_flowSend Profile Cycles: Prof1= %d,Prof2=%d \n",
2135 nwal_sum_flow_vv1/stats.itx2,nwal_sum_flow_vv2/stats.itx2);
2136 }
2138 }
2139 }
2140 }
2142 void build_sa_db(int i)
2143 {
2144 long tmp_spi;
2145 if ((tx_sa[i].authMode == NWAL_SA_AALG_HMAC_SHA1) && (tx_sa[i].cipherMode == NWAL_SA_EALG_AES_CBC))
2146 {
2147 /* static configuration, will not change */
2148 sa_info[i].tx_payload_info.aadSize = 0;
2149 sa_info[i].tx_payload_info.pAad = NULL;
2150 sa_info[i].tx_payload_info.pAuthIV = NULL;
2151 sa_info[i].tx_payload_info.authOffset = netTest_MAC_HEADER_LEN + netTest_IP_HEADER_LEN; /*done: same for all cipher suites */
2152 sa_info[i].tx_payload_info.encOffset = netTest_MAC_HEADER_LEN +
2153 netTest_IP_HEADER_LEN +
2154 netTest_ESP_HEADER_LEN +
2155 netTest_AES_CBC_IV_LEN;
2159 /* dynamic configuration, will be calculated on the fly */
2160 sa_info[i].tx_payload_info.authSize = 0; /* pkt len - mac - ip -icv (12) */
2161 sa_info[i].tx_payload_info.encSize = 0; /* authSize - esp header size (always 8 bytes) */
2162 sa_info[i].tx_payload_info.pEncIV = 0;
2163 sa_info[i].tx_payload_info.pPkt = 0; /* not being referenced in net_test */
2165 sa_info[i].cipherMode = NWAL_SA_EALG_AES_CBC;
2166 sa_info[i].inner_ip_offset = sa_info[i].tx_payload_info.encOffset;
2167 sa_info[i].auth_tag_size = netTest_ICV_LEN; /* icv or mac size,. always 12 except for AES_CCM/AES_GCM */
2168 #ifdef EXPERIMENTAL
2169 sa_info[i].iv_len=16;
2170 sa_info[i].bl=16;
2171 sa_info[i].spi = tx_sa[i].spi;
2172 sa_info[i].src =*((unsigned int *)(&config.local_ipsec_ip.ipv4[0]));
2173 sa_info[i].dst =*((unsigned int *)(&config.remote_ipsec_ip.ipv4[0]));
2174 #endif
2175 sa_info[i].tx_pkt_info.enetPort = 0;
2176 sa_info[i].tx_pkt_info.ipOffBytes = sa_info[i].tx_payload_info.encOffset;
2177 sa_info[i].tx_pkt_info.l4HdrLen = netTest_UDP_HEADER_LEN; /*UDP header len */
2178 sa_info[i].tx_pkt_info.l4OffBytes = sa_info[i].inner_ip_offset + netTest_IP_HEADER_LEN;
2179 sa_info[i].tx_pkt_info.startOffset = 0;
2180 sa_info[i].tx_pkt_info.lpbackPass = 0;
2181 sa_info[i].tx_pkt_info.ploadLen = 0; /*sa_info[i].tx_pkt_info.l4OffBytes + 4 */
2182 sa_info[i].tx_pkt_info.pPkt = NULL;
2183 sa_info[i].tx_pkt_info.saOffBytes = netTest_MAC_HEADER_LEN + netTest_IP_HEADER_LEN;
2184 sa_info[i].tx_pkt_info.saPayloadLen = 0;
2185 sa_info[i].tx_pkt_info.pseudoHdrChecksum =0;
2187 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 ;
2189 tmp_spi = htonl((long)(tx_sa[i].spi));
2190 trie_insert(p_trie_sa,(char *)&tmp_spi,4, (void *) &sa_info[i]); //asociate with tx sa SPI
2192 }
2193 else if ((tx_sa[i].authMode == NWAL_SA_AALG_HMAC_SHA2_256) && (tx_sa[i].cipherMode == NWAL_SA_EALG_AES_CTR))
2194 {
2195 printf("inside build_sa_db, index %d\n", i);
2196 /* static configuration, will not change */
2197 sa_info[i].tx_payload_info.aadSize = 0;
2198 sa_info[i].tx_payload_info.pAad = NULL;
2199 sa_info[i].tx_payload_info.pAuthIV = NULL;
2200 sa_info[i].tx_payload_info.authOffset = netTest_MAC_HEADER_LEN + netTest_IP_HEADER_LEN; /*done: same for all cipher suites */
2201 sa_info[i].tx_payload_info.encOffset = netTest_MAC_HEADER_LEN +
2202 netTest_IP_HEADER_LEN +
2203 netTest_ESP_HEADER_LEN +
2204 netTest_AES_CTR_IV_LEN;
2209 /* dynamic configuration, will be calculated on the fly */
2210 sa_info[i].tx_payload_info.authSize = 0;
2211 sa_info[i].tx_payload_info.encSize = 0;
2212 sa_info[i].tx_payload_info.pEncIV = 0;
2213 sa_info[i].tx_payload_info.pPkt = 0;
2215 sa_info[i].cipherMode = NWAL_SA_EALG_AES_CTR;
2216 sa_info[i].inner_ip_offset = sa_info[i].tx_payload_info.encOffset;
2217 sa_info[i].auth_tag_size = netTest_ICV_LEN; /* icv or mac size,. always 12 except for AES_CCM/AES_GCM */
2218 #ifdef EXPERIMENTAL
2219 sa_info[i].iv_len=8;
2220 sa_info[i].bl=8;
2221 sa_info[i].spi = tx_sa[i].spi;
2222 sa_info[i].src =*((unsigned int *)(&config.local_ipsec_ip.ipv4[0]));
2223 sa_info[i].dst =*((unsigned int *)(&config.remote_ipsec_ip.ipv4[0]));
2224 #endif
2226 sa_info[i].tx_pkt_info.enetPort = 0;
2227 sa_info[i].tx_pkt_info.ipOffBytes = sa_info[i].tx_payload_info.encOffset;
2228 sa_info[i].tx_pkt_info.l4HdrLen = netTest_UDP_HEADER_LEN; /*UDP header len */
2229 sa_info[i].tx_pkt_info.l4OffBytes = sa_info[i].inner_ip_offset + netTest_IP_HEADER_LEN;
2230 sa_info[i].tx_pkt_info.startOffset = 0;
2231 sa_info[i].tx_pkt_info.lpbackPass = 0;
2232 sa_info[i].tx_pkt_info.ploadLen = 0; /*sa_info[i].tx_pkt_info.l4OffBytes + 4 */
2233 sa_info[i].tx_pkt_info.pPkt = NULL;
2234 sa_info[i].tx_pkt_info.saOffBytes = netTest_MAC_HEADER_LEN + netTest_IP_HEADER_LEN;
2235 sa_info[i].tx_pkt_info.saPayloadLen = 0;
2236 sa_info[i].tx_pkt_info.pseudoHdrChecksum =0;
2238 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 ;
2240 tmp_spi = htonl((long)(tx_sa[i].spi));
2241 trie_insert(p_trie_sa,(char *)&tmp_spi,4, (void *) &sa_info[i]); //asociate with tx sa SPI
2242 }
2243 else if ((tx_sa[i].authMode == NWAL_SA_AALG_HMAC_SHA2_256) && (tx_sa[i].cipherMode == NWAL_SA_EALG_3DES_CBC))
2244 {
2245 /* static configuration, will not change */
2246 sa_info[i].tx_payload_info.aadSize = 0;
2247 sa_info[i].tx_payload_info.pAad = NULL;
2248 sa_info[i].tx_payload_info.pAuthIV = NULL;
2249 sa_info[i].tx_payload_info.authOffset = netTest_MAC_HEADER_LEN + netTest_IP_HEADER_LEN; /*done: same for all cipher suites */
2250 sa_info[i].tx_payload_info.encOffset = netTest_MAC_HEADER_LEN +
2251 netTest_IP_HEADER_LEN +
2252 netTest_ESP_HEADER_LEN +
2253 netTest_3DES_CBC_IV_LEN;
2255 /* dynamic configuration, will be calculated on the fly */
2256 sa_info[i].tx_payload_info.authSize = 0;
2257 sa_info[i].tx_payload_info.encSize = 0;
2258 sa_info[i].tx_payload_info.pEncIV = 0;
2259 sa_info[i].tx_payload_info.pPkt = 0;
2261 sa_info[i].cipherMode = NWAL_SA_EALG_3DES_CBC;
2262 sa_info[i].inner_ip_offset = sa_info[i].tx_payload_info.encOffset;
2263 sa_info[i].auth_tag_size = netTest_ICV_LEN; /* icv or mac size,. always 12 except for AES_CCM/AES_GCM */
2264 #ifdef EXPERIMENTAL
2265 sa_info[i].iv_len=8;
2266 sa_info[i].bl=8;
2267 sa_info[i].spi = tx_sa[i].spi;
2268 sa_info[i].src =*((unsigned int *)(&config.local_ipsec_ip.ipv4[0]));
2269 sa_info[i].dst =*((unsigned int *)(&config.remote_ipsec_ip.ipv4[0]));
2270 #endif
2272 sa_info[i].tx_pkt_info.enetPort = 0;
2273 sa_info[i].tx_pkt_info.ipOffBytes = sa_info[i].tx_payload_info.encOffset;
2274 sa_info[i].tx_pkt_info.l4HdrLen = netTest_UDP_HEADER_LEN; /*UDP header len */
2275 sa_info[i].tx_pkt_info.l4OffBytes = sa_info[i].inner_ip_offset + netTest_IP_HEADER_LEN;
2276 sa_info[i].tx_pkt_info.startOffset = 0;
2277 sa_info[i].tx_pkt_info.lpbackPass = 0;
2278 sa_info[i].tx_pkt_info.ploadLen = 0; /*sa_info[i].tx_pkt_info.l4OffBytes + 4 */
2279 sa_info[i].tx_pkt_info.pPkt = NULL;
2280 sa_info[i].tx_pkt_info.saOffBytes = netTest_MAC_HEADER_LEN + netTest_IP_HEADER_LEN;
2281 sa_info[i].tx_pkt_info.saPayloadLen = 0;
2282 sa_info[i].tx_pkt_info.pseudoHdrChecksum =0;
2284 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 ;
2286 tmp_spi = htonl((long)(tx_sa[i].spi));
2287 trie_insert(p_trie_sa,(char *)&tmp_spi,4, (void *) &sa_info[i]); //asociate with tx sa SPI
2288 }
2289 else if ((tx_sa[i].authMode == NWAL_SA_AALG_HMAC_MD5) && (rx_sa[i].cipherMode == NWAL_SA_EALG_NULL))
2290 {
2291 /* static configuration, will not change */
2292 sa_info[i].tx_payload_info.aadSize = 0;
2293 sa_info[i].tx_payload_info.pAad = NULL;
2294 sa_info[i].tx_payload_info.pAuthIV = NULL;
2295 sa_info[i].tx_payload_info.authOffset = netTest_MAC_HEADER_LEN + netTest_IP_HEADER_LEN; /*done: same for all cipher suites */
2297 sa_info[i].tx_payload_info.encOffset = netTest_MAC_HEADER_LEN +
2298 netTest_IP_HEADER_LEN +
2299 netTest_ESP_HEADER_LEN +
2300 netTest_NULL_IV_LEN;
2301 #ifdef EXPERIMENTAL
2302 sa_info[i].iv_len=0;
2303 sa_info[i].bl=4;
2304 sa_info[i].spi = tx_sa[i].spi;
2305 sa_info[i].src =*((unsigned int *)(&config.local_ipsec_ip.ipv4[0]));
2306 sa_info[i].dst =*((unsigned int *)(&config.remote_ipsec_ip.ipv4[0]));
2307 #endif
2310 /* dynamic configuration, will be calculated on the fly */
2311 sa_info[i].tx_payload_info.authSize = 0;
2312 sa_info[i].tx_payload_info.encSize = 0;
2313 sa_info[i].tx_payload_info.pEncIV = 0;
2314 sa_info[i].tx_payload_info.pPkt = 0;
2316 sa_info[i].cipherMode = NWAL_SA_EALG_NULL;
2317 sa_info[i].inner_ip_offset = sa_info[i].tx_payload_info.encOffset;
2318 sa_info[i].auth_tag_size = netTest_ICV_LEN; /* icv or mac size,. always 12 except for AES_CCM/AES_GCM */
2320 sa_info[i].tx_pkt_info.enetPort = 0;
2321 sa_info[i].tx_pkt_info.ipOffBytes = sa_info[i].tx_payload_info.encOffset;
2322 sa_info[i].tx_pkt_info.l4HdrLen = netTest_UDP_HEADER_LEN; /*UDP header len */
2323 sa_info[i].tx_pkt_info.l4OffBytes = sa_info[i].inner_ip_offset + netTest_IP_HEADER_LEN;
2324 sa_info[i].tx_pkt_info.startOffset = 0;
2325 sa_info[i].tx_pkt_info.lpbackPass = 0;
2326 sa_info[i].tx_pkt_info.ploadLen = 0; /*sa_info[i].tx_pkt_info.l4OffBytes + 4 */
2327 sa_info[i].tx_pkt_info.pPkt = NULL;
2328 sa_info[i].tx_pkt_info.saOffBytes = netTest_MAC_HEADER_LEN + netTest_IP_HEADER_LEN;
2329 sa_info[i].tx_pkt_info.saPayloadLen = 0;
2330 sa_info[i].tx_pkt_info.pseudoHdrChecksum =0;
2332 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 ;
2333 tmp_spi = htonl((long)(tx_sa[i].spi));
2334 trie_insert(p_trie_sa,(char *)&tmp_spi,4, (void *) &sa_info[i]); //asociate with tx sa SPI
2335 }
2336 else if ((tx_sa[i].authMode == NWAL_SA_AALG_NULL) && (rx_sa[i].cipherMode == NWAL_SA_EALG_AES_GCM))
2337 {
2338 /* static configuration, will not change */
2339 sa_info[i].tx_payload_info.aadSize = 0;
2340 sa_info[i].tx_payload_info.pAad = NULL;
2341 sa_info[i].tx_payload_info.pAuthIV = NULL;
2342 sa_info[i].tx_payload_info.authOffset = netTest_MAC_HEADER_LEN + netTest_IP_HEADER_LEN; /*done: same for all cipher suites */
2343 //sa_info[i].tx_payload_info.encIvSize = netTest_AES_GCM_IV_LEN;
2345 sa_info[i].tx_payload_info.encOffset = netTest_MAC_HEADER_LEN +
2346 netTest_IP_HEADER_LEN +
2347 netTest_ESP_HEADER_LEN +
2348 netTest_AES_GCM_IV_LEN;
2349 #ifdef EXPERIMENTAL
2350 sa_info[i].iv_len=0;
2351 sa_info[i].bl=4;
2352 sa_info[i].spi = tx_sa[i].spi;
2353 sa_info[i].src =*((unsigned int *)(&config.local_ipsec_ip.ipv4[0]));
2354 sa_info[i].dst =*((unsigned int *)(&config.remote_ipsec_ip.ipv4[0]));
2355 #endif
2358 /* dynamic configuration, will be calculated on the fly */
2359 sa_info[i].tx_payload_info.authSize = 0;
2360 sa_info[i].tx_payload_info.encSize = 0;
2361 //sa_info[i].tx_payload_info.ploadLen = 0;
2362 sa_info[i].tx_payload_info.pEncIV = 0;
2363 sa_info[i].tx_payload_info.pPkt = 0;
2365 sa_info[i].cipherMode = NWAL_SA_EALG_AES_GCM;
2366 sa_info[i].inner_ip_offset = sa_info[i].tx_payload_info.encOffset;
2367 sa_info[i].auth_tag_size = netTest_AES_GCM_CCM_ICV_LEN; /* icv or mac size,. always 12 except for AES_CCM/AES_GCM */
2369 sa_info[i].tx_pkt_info.enetPort = 0;
2370 sa_info[i].tx_pkt_info.ipOffBytes = sa_info[i].tx_payload_info.encOffset;
2371 sa_info[i].tx_pkt_info.l4HdrLen = netTest_UDP_HEADER_LEN; /*UDP header len */
2372 sa_info[i].tx_pkt_info.l4OffBytes = sa_info[i].inner_ip_offset + netTest_IP_HEADER_LEN;
2373 sa_info[i].tx_pkt_info.startOffset = 0;
2374 sa_info[i].tx_pkt_info.lpbackPass = 0;
2375 sa_info[i].tx_pkt_info.ploadLen = 0; /*sa_info[i].tx_pkt_info.l4OffBytes + 4 */
2376 sa_info[i].tx_pkt_info.pPkt = NULL;
2377 sa_info[i].tx_pkt_info.saOffBytes = netTest_MAC_HEADER_LEN + netTest_IP_HEADER_LEN;
2378 sa_info[i].tx_pkt_info.saPayloadLen = 0;
2379 sa_info[i].tx_pkt_info.pseudoHdrChecksum =0;
2381 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 ;
2383 tmp_spi = htonl((long)(tx_sa[i].spi));
2384 trie_insert(p_trie_sa,(char *)&tmp_spi,4, (void *) &sa_info[i]); //asociate with tx sa SPI
2385 }
2386 else if ((tx_sa[i].authMode == NWAL_SA_AALG_NULL) && (rx_sa[i].cipherMode == NWAL_SA_EALG_AES_CCM))
2387 {
2388 /* static configuration, will not change */
2389 sa_info[i].tx_payload_info.aadSize = 0;
2390 sa_info[i].tx_payload_info.pAad = NULL;
2391 //sa_info[i].tx_payload_info.authIvSize = 0;
2392 sa_info[i].tx_payload_info.pAuthIV = NULL;
2393 sa_info[i].tx_payload_info.authOffset = netTest_MAC_HEADER_LEN + netTest_IP_HEADER_LEN; /*done: same for all cipher suites */
2395 sa_info[i].tx_payload_info.encOffset = netTest_MAC_HEADER_LEN +
2396 netTest_IP_HEADER_LEN +
2397 netTest_ESP_HEADER_LEN +
2398 netTest_AES_CCM_IV_LEN;
2399 #ifdef EXPERIMENTAL
2400 sa_info[i].iv_len=0;
2401 sa_info[i].bl=4;
2402 sa_info[i].spi = tx_sa[i].spi;
2403 sa_info[i].src =*((unsigned int *)(&config.local_ipsec_ip.ipv4[0]));
2404 sa_info[i].dst =*((unsigned int *)(&config.remote_ipsec_ip.ipv4[0]));
2405 #endif
2408 /* dynamic configuration, will be calculated on the fly */
2409 sa_info[i].tx_payload_info.authSize = 0;
2410 sa_info[i].tx_payload_info.encSize = 0;
2411 //sa_info[i].tx_payload_info.ploadLen = 0;
2412 sa_info[i].tx_payload_info.pEncIV = 0;
2413 sa_info[i].tx_payload_info.pPkt = 0;
2415 sa_info[i].cipherMode = NWAL_SA_EALG_AES_CCM;
2416 sa_info[i].inner_ip_offset = sa_info[i].tx_payload_info.encOffset;
2417 sa_info[i].auth_tag_size = netTest_AES_GCM_CCM_ICV_LEN; /* icv or mac size,. always 12 except for AES_CCM/AES_GCM */
2419 sa_info[i].tx_pkt_info.enetPort = 0;
2420 sa_info[i].tx_pkt_info.ipOffBytes = sa_info[i].tx_payload_info.encOffset;
2421 sa_info[i].tx_pkt_info.l4HdrLen = netTest_UDP_HEADER_LEN; /*UDP header len */
2422 sa_info[i].tx_pkt_info.l4OffBytes = sa_info[i].inner_ip_offset + netTest_IP_HEADER_LEN;
2423 sa_info[i].tx_pkt_info.startOffset = 0;
2424 sa_info[i].tx_pkt_info.lpbackPass = 0;
2425 sa_info[i].tx_pkt_info.ploadLen = 0; /*sa_info[i].tx_pkt_info.l4OffBytes + 4 */
2426 sa_info[i].tx_pkt_info.pPkt = NULL;
2427 sa_info[i].tx_pkt_info.saOffBytes = netTest_MAC_HEADER_LEN + netTest_IP_HEADER_LEN;
2428 sa_info[i].tx_pkt_info.saPayloadLen = 0;
2429 sa_info[i].tx_pkt_info.pseudoHdrChecksum =0;
2431 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 ;
2433 tmp_spi = htonl((long)(tx_sa[i].spi));
2434 trie_insert(p_trie_sa,(char *)&tmp_spi,4, (void *) &sa_info[i]); //asociate with tx sa SPI
2435 }
2436 else if ((tx_sa[i].authMode == NWAL_SA_AALG_AES_XCBC) && (rx_sa[i].cipherMode == NWAL_SA_EALG_NULL))
2437 {
2438 /* static configuration, will not change */
2439 sa_info[i].tx_payload_info.aadSize = 0;
2440 sa_info[i].tx_payload_info.pAad = NULL;
2441 sa_info[i].tx_payload_info.pAuthIV = NULL;
2442 sa_info[i].tx_payload_info.authOffset = netTest_MAC_HEADER_LEN + netTest_IP_HEADER_LEN;
2445 sa_info[i].tx_payload_info.encOffset = netTest_MAC_HEADER_LEN +
2446 netTest_IP_HEADER_LEN +
2447 netTest_ESP_HEADER_LEN +
2448 netTest_NULL_IV_LEN;
2449 #ifdef EXPERIMENTAL
2450 sa_info[i].iv_len=0;
2451 sa_info[i].bl=4;
2452 sa_info[i].spi = tx_sa[i].spi;
2453 sa_info[i].src =*((unsigned int *)(&config.local_ipsec_ip.ipv4[0]));
2454 sa_info[i].dst =*((unsigned int *)(&config.remote_ipsec_ip.ipv4[0]));
2455 #endif
2458 /* dynamic configuration, will be calculated on the fly */
2459 sa_info[i].tx_payload_info.authSize = 0;
2460 sa_info[i].tx_payload_info.encSize = 0;
2461 //sa_info[i].tx_payload_info.ploadLen = 0;
2462 sa_info[i].tx_payload_info.pEncIV = 0;
2463 sa_info[i].tx_payload_info.pPkt = 0;
2465 sa_info[i].cipherMode = NWAL_SA_EALG_NULL;
2466 sa_info[i].authMode = NWAL_SA_AALG_AES_XCBC;
2467 sa_info[i].inner_ip_offset = sa_info[i].tx_payload_info.encOffset;
2468 sa_info[i].auth_tag_size = netTest_ICV_LEN; /* icv or mac size,. always 12 except for AES_CCM/AES_GCM , GMAC*/
2470 sa_info[i].tx_pkt_info.enetPort = 0;
2471 sa_info[i].tx_pkt_info.ipOffBytes = sa_info[i].tx_payload_info.encOffset;
2472 sa_info[i].tx_pkt_info.l4HdrLen = netTest_UDP_HEADER_LEN; /*UDP header len */
2473 sa_info[i].tx_pkt_info.l4OffBytes = sa_info[i].inner_ip_offset + netTest_IP_HEADER_LEN;
2474 sa_info[i].tx_pkt_info.startOffset = 0;
2475 sa_info[i].tx_pkt_info.lpbackPass = 0;
2476 sa_info[i].tx_pkt_info.ploadLen = 0; /*sa_info[i].tx_pkt_info.l4OffBytes + 4 */
2477 sa_info[i].tx_pkt_info.pPkt = NULL;
2478 sa_info[i].tx_pkt_info.saOffBytes = netTest_MAC_HEADER_LEN + netTest_IP_HEADER_LEN;
2479 sa_info[i].tx_pkt_info.saPayloadLen = 0;
2480 sa_info[i].tx_pkt_info.pseudoHdrChecksum =0;
2482 sa_info[i].tx_pkt_info.txFlag1 = NWAL_TX_FLAG1_DO_IPSEC_ESP_CRYPTO| NWAL_TX_FLAG1_DO_UDP_CHKSUM| NWAL_TX_FLAG1_META_DATA_VALID ;
2484 tmp_spi = htonl((long)(tx_sa[i].spi));
2485 trie_insert(p_trie_sa,(char *)&tmp_spi,4, (void *) &sa_info[i]); //asociate with tx sa SPI
2486 }
2487 else
2488 printf("build_sa_db(): invalid encryption/authentication combination selected\n");
2490 //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);
2493 }
2497 #define CHECK_SET_PARAM(ARG1, ARG2) \
2498 do { \
2499 if(strcmp(key, ARG1) == 0) { \
2500 if(data)strncpy(ARG2,data,CONFIG_STRING_LEN); \
2501 printf("CHECK_SET_PARM, match found, input cong string %s\n", ARG2); \
2502 continue; \
2503 } \
2504 } while(0)
2506 #define CHECK_SET_PARAM2(ARG1, ARG2, ARG3) \
2507 do { \
2508 if(strcmp(key, ARG1) == 0) { \
2509 if(data) strncpy(ARG2,data,CONFIG_STRING_LEN); \
2510 if(data2) strncpy(ARG3,data2,CONFIG_STRING_LEN); \
2511 printf("CHECK_SET_PARM2, match found, input cong string %s %s\n", ARG2, ARG3); \
2512 continue; \
2513 } \
2514 } while(0)
2516 unsigned char hex2dec(char *p_s)
2517 {
2518 int val;
2519 sscanf(p_s,"%x",&val);
2520 return val&0xff;
2521 }
2522 void parse_one_mac(char * p_mac_str, unsigned char *p_mac)
2523 {
2524 int index = 0;
2525 int i;
2526 char *pch = strtok (&(p_mac_str[0]),"-");
2528 while (pch != NULL)
2529 {
2530 printf ("%s\n",pch);
2531 p_mac[index] = hex2dec(pch);
2532 index++;
2533 pch = strtok (NULL,"-");
2534 }
2535 printf("index value : %d\n", index);
2536 for (i=0; i<6;i++)
2537 printf("************mac0[%d]: 0x%x\n",i, p_mac[i]);
2538 }
2540 void parse_one_ip(char * p_ip_addr_str, unsigned char * p_ip)
2541 {
2542 int index = 0;
2543 int i;
2544 char * pch = strtok (&p_ip_addr_str[0],".");
2546 while (pch != NULL)
2547 {
2548 printf ("xxxxx: %s\n",pch);
2549 p_ip[index] = atoi(pch);
2550 index++;
2551 pch = strtok (NULL,".");
2552 }
2553 printf("index value : %d\n", index);
2554 for (i=0; i<4;i++)
2555 printf("************ip[%d]: 0x%x\n",i, p_ip[i]);
2558 }
2560 void parse_mac_address(netTestConfigFile_t *pConfig)
2561 {
2562 if (strlen(&pConfig->mac0[0]))
2563 parse_one_mac(&pConfig->mac0[0],&config.mac0[0]);
2564 if (strlen(&pConfig->mac1[0]))
2565 parse_one_mac(&pConfig->mac1[0],&config.mac1[0]);
2566 }
2567 void parse_ip_address(netTestConfigFile_t *pConfig)
2568 {
2569 if (strlen(&pConfig->ip0[0]))
2570 parse_one_ip(&pConfig->ip0[0],&config.ip0.ipv4[0]);
2571 if (strlen(&pConfig->ip1[0]))
2572 parse_one_ip(&pConfig->ip1[0],&config.ip1.ipv4[0]);
2573 if (strlen(&pConfig->ip2[0]))
2574 parse_one_ip(&pConfig->ip2[0],&config.ip2.ipv4[0]);
2575 if (strlen(&pConfig->local_ipsec_ip[0]))
2576 parse_one_ip(&pConfig->local_ipsec_ip[0],&config.local_ipsec_ip.ipv4[0]);
2577 if (strlen(&pConfig->remote_ipsec_ip[0]))
2578 parse_one_ip(&pConfig->remote_ipsec_ip[0],&config.remote_ipsec_ip.ipv4[0]);
2579 }
2582 void parse_ipsec_mode(netTestConfigFile_t *pConfig)
2583 {
2585 printf("parse_ipsec_mode, string length %d\n", strlen(&pConfig->ipsec_mode_rx));
2586 if (strlen(&pConfig->ipsec_mode_rx[0]))
2587 {
2588 if (strcmp(pConfig->ipsec_mode_rx, "SIDEBAND") == 0)
2589 {
2590 config.ipsec_mode_rx = IPSEC_MODE_RX_SIDEBAND;
2591 }
2592 else if (strcmp(pConfig->ipsec_mode_rx, "INFLOW") == 0)
2593 {
2594 config.ipsec_mode_rx = IPSEC_MODE_RX_INFLOW;
2595 }
2596 else
2597 printf("parse_ipsec_mode(), invalid RX ipsec mode in config file \n");
2598 }
2600 if (strlen(&pConfig->ipsec_mode_tx[0]))
2601 {
2602 if (strcmp(pConfig->ipsec_mode_tx, "SIDEBAND") == 0)
2603 {
2604 config.ipsec_mode_tx = IPSEC_MODE_TX_SIDEBAND;
2605 }
2606 else if (strcmp(pConfig->ipsec_mode_tx, "INFLOW") == 0)
2607 {
2608 config.ipsec_mode_tx = IPSEC_MODE_TX_INFLOW;
2609 }
2610 else
2611 printf("parse_ipsec_mode(), invalid TX ipsec mode in config file \n");
2612 }
2614 printf("parse_ipsec_mode(): RX mode %d\n", config.ipsec_mode_rx);
2615 printf("parse_ipsec_mode(): TX mode %d\n", config.ipsec_mode_tx);
2618 }
2620 #ifdef EXPERIMENTAL
2621 int n_routes=0;
2622 int n_dst_ips=0;
2623 void parse_routes(netTestConfigFile_t *pConfig)
2624 {
2625 int i;
2626 int said=0;
2627 for(i=0;i<MAX_ROUTES;i++)
2628 {
2629 int port;
2630 if (pConfig->routes[i][0])
2631 {
2632 port=atoi(&pConfig->ports[i][0]);
2633 if((port<1)||(port>2)) continue; //bad port #: only 1 or 2 valid
2634 if(strncmp(&pConfig->routes[i][0],"MAC",3)==0)
2635 {
2636 routes[i].out_port = port;
2637 parse_one_mac(&pConfig->routes[i][3],&routes[i].out_mac[0]);
2638 memcpy(&routes[i].out_mac[6], ((port==1) ?&config.mac0[0]: &config.mac1[0] ),6);
2639 routes[i].out_mac[12]=0x08;
2640 routes[i].out_mac[13]=0x00;
2641 routes[i].sec_ptr=NULL;
2642 n_routes+=1;
2643 }
2644 else if (strncmp(&pConfig->routes[i][0],"SA",2)==0)
2645 {
2646 said=atoi(&pConfig->routes[i][2]) ;
2647 routes[i].sec_ptr=&sa_info[said];
2648 n_routes+=1;
2649 }
2650 }
2651 }
2652 our_router = route_init();
2653 for (i=0;i<MAX_ROUTES;i++)
2654 {
2655 unsigned long ip_be;
2656 int route_index;
2657 if (pConfig->dst_ips[i][0])
2658 {
2659 parse_one_ip(&pConfig->dst_ips[i][0],(unsigned char *)&ip_be);
2660 sscanf(&pConfig->paths[i][0],"route%d",&route_index);
2661 route_add(our_router,&ip_be,&routes[route_index]);
2662 n_dst_ips+=1;
2663 }
2664 }
2665 printf(">Route DB built. %d entries\n",n_dst_ips);
2666 }
2667 #endif
2668 static void parse_config_file(FILE * fpr, netTestConfigFile_t *pConfig)
2669 {
2670 char line[MAX_LINE_LENGTH + 1];
2671 int i;
2673 char *key, *data, *ep, *data2;
2674 char tokens[] = " :=;\n";
2675 char temp_str[50];
2676 memset(line, 0, MAX_LINE_LENGTH + 1);
2677 memset(pConfig, 0, sizeof(netTestConfigFile_t));
2678 while (fgets(line, MAX_LINE_LENGTH + 1, fpr))
2679 {
2680 if(line[0]=='#') continue; //skip comment
2681 key = (char *)strtok(line, tokens);
2682 data = (char *)strtok(NULL, tokens);
2683 data2 = (char *)strtok(NULL, tokens);
2684 if (!key) continue;
2685 if (!data) continue;
2687 if(strlen(data) == 0)
2688 {
2689 continue;
2690 }
2692 CHECK_SET_PARAM(INIT_CONFIG_MAC0,&(pConfig->mac0[0]));
2693 CHECK_SET_PARAM(INIT_CONFIG_MAC1,&(pConfig->mac1[0]));
2694 CHECK_SET_PARAM(INIT_CONFIG_IP0,&(pConfig->ip0[0]));
2695 CHECK_SET_PARAM(INIT_CONFIG_IP1,&(pConfig->ip1[0]));
2696 CHECK_SET_PARAM(INIT_CONFIG_IP2,&(pConfig->ip2[0]));
2697 CHECK_SET_PARAM(INIT_CONFIG_LOCAL_IPSEC_IP,&(pConfig->local_ipsec_ip[0]));
2698 CHECK_SET_PARAM(INIT_CONFIG_REMOTE_IPSEC_IP,&(pConfig->remote_ipsec_ip[0]));
2699 CHECK_SET_PARAM(INIT_CONFIG_IPSEC_MODE_RX,&(pConfig->ipsec_mode_rx[0]));
2700 CHECK_SET_PARAM(INIT_CONFIG_IPSEC_MODE_TX,&(pConfig->ipsec_mode_tx[0]));
2701 CHECK_SET_PARAM(INIT_CONFIG_IPSEC_IF_NO,&(pConfig->ipsec_if_no[0]));
2702 #ifdef EXPERIMENTAL
2703 for(i=0;i<MAX_ROUTES;i++)
2704 {
2705 sprintf(temp_str,"route%d",i);
2706 CHECK_SET_PARAM2(temp_str,&pConfig->routes[i][0],&pConfig->ports[i][0] );
2707 }
2708 for(i=0;i<MAX_ROUTES;i++)
2709 {
2710 sprintf(temp_str,"dstip%d",i);
2711 CHECK_SET_PARAM2(temp_str,&pConfig->dst_ips[i][0],&pConfig->paths[i][0] );
2712 }
2713 #endif
2715 }
2716 parse_mac_address(pConfig);
2718 parse_ip_address(pConfig);
2720 parse_ipsec_mode(pConfig);
2721 #ifdef EXPERIMENTAL
2722 if (strlen(&pConfig->ipsec_if_no[0]))
2723 config.ipsec_if_no = atoi(&pConfig->ipsec_if_no[0]);
2724 parse_routes(pConfig);
2725 #endif
2726 }
2728 static netTestConfigFile_t config_file;
2729 /***************************************
2730 ********** test driver*****************
2731 ***************************************/
2732 int main(int argc, char **argv)
2733 {
2734 int err,i;
2735 rlim_t oss,ss = 1024*1024;
2736 struct rlimit rl;
2738 Pktlib_HeapCfg heapCfg;
2739 int32_t errCode;
2740 Pktlib_HeapIfTable* pPktifTable;
2742 FILE * fpr = NULL;
2744 nwalSaIpSecId_t nwalSaIpSecId;
2746 err= getrlimit(RLIMIT_STACK,&rl);
2747 if (!err) printf(" stack limit = %d\n",rl.rlim_cur); else printf("getrlimit failed\n");
2748 #if 0
2749 rl.rlim_cur = ss;
2750 err=setrlimit(RLIMIT_STACK,&rl);
2751 i f (!err) printf("set stack to %d\n",rl.rlim_cur); else printf("setrlimit failed\n");
2752 #endif
2755 if (argc>=2) np2process = atoi(argv[1]);
2756 printf("*************** np2process %d\n", np2process);
2757 if (np2process<0) np2process = NP; /* default */
2758 if (argc==3) perslow = atoi(argv[2]);
2759 if ((perslow<0)||(perslow>100)) perslow=PERSLOW;//default
2760 if (argc>3) {printf("net_test <no of pkts to process> <percent slow path>\n"); exit(1);}
2761 #if 1
2763 #if 0
2764 if (argc >= 2)
2765 {
2766 fpr = fopen(argv[2], "r");
2767 if (fpr == NULL)
2768 {
2769 printf("Error in opening %s input file\n", argv[2]);
2770 }
2771 }
2772 else
2773 #endif
2774 {
2775 fpr = fopen(input_file_name, "r");
2776 if (fpr == NULL)
2777 {
2778 printf("Error in opening %s input file\n", input_file_name);
2779 }
2780 else
2781 {
2782 parse_config_file(fpr,&config_file);
2783 }
2784 }
2786 #endif
2788 memset(&sa_info, 0, sizeof(sa_info));
2791 //real mode, so update our test packet mac header and ip header
2792 if (pktloopback==0)
2793 {
2794 memcpy(&testPkt,&real_mac_header[0],14); //overwrite test pkt mac address
2795 memcpy(&testPkt[26],&real_ip_addr[0],8);//overrite test pkt ip addresses
2796 }
2797 #if 0
2798 our_router = route_init();
2799 for (i=0;i<n_dst_ips;i++)
2800 {
2801 route_add(our_router,&ip[i],&routes[i]);
2802 }
2803 #endif
2805 /*******************************************/
2806 /*************NETAPI STARTUP****************/
2807 /*******************************************/
2809 /* create netapi */
2810 netapi_handle = netapi_init(NETAPI_SYS_MASTER, &our_netapi_default_cfg);
2812 /* open the main heap */
2813 OurHeap = Pktlib_findHeapByName("netapi");
2814 if (!OurHeap) {printf("findheapbyname fail\n"); exit(1);}
2816 /* create two secondary heaps */
2817 /* Initialize the heap configuration. */
2818 memset ((void *)&heapCfg, 0, sizeof(Pktlib_HeapCfg));
2820 pPktifTable = netapi_getPktlibIfTable();
2821 /* Populate the heap configuration */
2822 heapCfg.name = "netapi-small";
2823 heapCfg.memRegion = NETAPI_GLOBAL_REGION;
2824 heapCfg.sharedHeap = 1;
2825 heapCfg.useStarvationQueue = 0;
2826 heapCfg.dataBufferSize = 512;
2827 heapCfg.numPkts = 64;
2828 heapCfg.numZeroBufferPackets= 0;
2829 heapCfg.heapInterfaceTable.data_malloc = pPktifTable->data_malloc;
2830 heapCfg.heapInterfaceTable.data_free = pPktifTable->data_free;
2831 heapCfg.dataBufferPktThreshold = 0;
2832 heapCfg.zeroBufferPktThreshold = 0;
2834 specialSmall = Pktlib_createHeap(&heapCfg, &errCode);
2835 heapCfg.name = "netapi-big";
2836 heapCfg.dataBufferSize = 1600;
2837 specialLarge = Pktlib_createHeap(&heapCfg, &errCode);
2838 //register these heaps so poll routine will include their garbage queues.
2839 netapi_registerHeap(netapi_handle, specialSmall);
2840 netapi_registerHeap(netapi_handle, specialLarge);
2842 #ifdef REASSEMBLE_BENCH
2843 our_reassemble_bench(2);
2844 exit(1);
2845 #endif
2847 #ifndef EXPERIMENTAL
2848 /* create a pktio channel */
2849 our_chan=pktio_create(netapi_handle,"our1stq",(PKTIO_CB) recv_cb_bench, &our_chan_cfg,&err);
2850 if (!our_chan) {printf("pktio create failed err=%d\n",err); exit(1);}
2851 #endif
2853 /* open netcp default tx, rx queues */
2854 netcp_tx_chan= pktio_open(netapi_handle, NETCP_TX, NULL, &netcp_tx_cfg, &err);
2855 if (!netcp_tx_chan) {printf("pktio open TX failed err=%d\n",err); exit(1);}
2856 #ifdef EXPERIMENTAL
2857 netcp_rx_chan= pktio_open(netapi_handle, NETCP_RX, (PKTIO_CB) recv_cb_router, &netcp_rx_cfg, &err);
2858 #else
2859 netcp_rx_chan= pktio_open(netapi_handle, NETCP_RX, (PKTIO_CB) recv_cb, &netcp_rx_cfg, &err);
2860 #endif
2861 if (!netcp_rx_chan) {printf("pktio open RX failed err=%d\n",err); exit(1);}
2863 #ifndef EXPERIMENTAL
2864 /* create a pktio channel for specially classified pkts */
2865 netcp_rx_chan2= pktio_create(netapi_handle, "classq", (PKTIO_CB) recv_cb, &netcp_rx_cfg2, &err);
2866 if (!netcp_rx_chan2) {printf("pktio create RX2 failed err=%d\n",err); exit(1);}
2868 /* open netcp default tx, rx queues for sideband crypto */
2869 netcp_sb_tx_chan= pktio_open(netapi_handle, NETCP_SB_TX, NULL, &netcp_sb_tx_cfg, &err);
2870 if (!netcp_sb_tx_chan) {printf("pktio open SB TX failed err=%d\n",err); exit(1);}
2871 netcp_sb_rx_chan= pktio_open(netapi_handle, NETCP_SB_RX, (PKTIO_CB) recv_sb_cb, &netcp_sb_rx_cfg, &err);
2872 if (!netcp_sb_rx_chan) {printf("pktio open SB RX failed err=%d\n",err); exit(1);}
2873 #endif
2875 printf("net_test> %d bytes left in our CMA area\n", netapi_getBufMemRemainder());
2876 /* create scheduler instance */
2877 our_sched =netapi_schedOpen(netapi_handle,&our_sched_cfg, &err);
2878 if (!our_sched) {printf("sched create failed\n"); exit(1);}
2880 #if 0
2881 /********************************************
2882 * Basic pkt loopback test
2883 *********************************************/
2884 printf("...running pure push/pop benchmark\n");
2885 our_pktio_bench(1000);
2886 our_pktio_bench(1000);
2887 our_pktio_bench(1000);
2888 our_pktio_bench(1000);
2889 our_pktio_bench(1000);
2890 /*********************************************/
2891 #endif
2896 /* add mac intefaces */
2897 netcp_cfgCreateMacInterface(
2898 netapi_handle,
2899 &config.mac0[0],
2900 0,0,
2901 (NETCP_CFG_ROUTE_HANDLE_T) NULL,
2902 (NETCP_CFG_VLAN_T ) NULL , //future
2903 1,
2904 &err);
2905 if (err) {printf("addmac0 failed %d\n",err); exit(1); }
2907 //attach an IP to this interface
2908 ip_rule0=netcp_cfgAddIp(
2909 netapi_handle,
2910 0,
2911 nwal_IPV4,
2912 &config.ip0,
2913 NULL, //all IP
2914 (NETCP_CFG_ROUTE_HANDLE_T) NULL,
2915 &err
2916 );
2917 if (err) {printf("addip0 failed %d\n",err); exit(1); }
2919 //create a 2nd mac instance
2920 netcp_cfgCreateMacInterface(
2921 netapi_handle,
2922 &config.mac1[0],
2923 1,1,
2924 (NETCP_CFG_ROUTE_HANDLE_T) NULL,
2925 (NETCP_CFG_VLAN_T ) NULL , //future
2926 1,
2927 &err);
2928 if (err) {printf("addmac1 failed %d\n",err); exit(1); }
2930 //attach an IP to this interface
2931 ip_rule1=netcp_cfgAddIp(
2932 netapi_handle,
2933 1,
2934 nwal_IPV4,
2935 &config.ip1,
2936 NULL, //all IP
2937 (NETCP_CFG_ROUTE_HANDLE_T) NULL,
2938 &err
2939 );
2940 if (err) {printf("addip1 failed %d\n",err); exit(1); }
2942 #ifndef EXPERIMENTAL
2943 //attach 2 classifiers to iface 0, ip0
2944 class_0_cfg.u.c_l4.ip = ip_rule0;
2945 class_0 = netcp_cfgAddClass(netapi_handle,
2946 &class_0_cfg,
2947 NULL,
2948 NETCP_CFG_ACTION_TO_SW,
2949 &err);
2950 if (err) {printf("addclass0 failed %d\n",err); exit(1);}
2952 class_1_cfg.u.c_l4.ip = ip_rule0;
2953 class_1 = netcp_cfgAddClass(netapi_handle,
2954 &class_1_cfg,
2955 NULL,
2956 NETCP_CFG_ACTION_TO_SW,
2957 &err);
2958 if (err) {printf("addclass1 failed %d\n",err); exit(1);}
2961 //3rd classifier has a different IP and route
2962 class_2_cfg.u.c_l3_l4.ip_addr = &config.ip2;
2964 //create specialFlow for this classifier
2965 {
2966 Pktlib_HeapHandle heaps[2];
2967 int sizes[2];
2968 heaps[0]= specialSmall;
2969 heaps[1]= specialLarge;
2970 #define SPECIAL_SOP_OFF 128
2971 sizes[0]=512-SPECIAL_SOP_OFF;
2972 sizes[1]=1600-SPECIAL_SOP_OFF;
2973 #if 0
2974 specialFlow = netcp_cfgAddFlow( netapi_handle,
2975 2,
2976 heaps,
2977 sizes,
2978 SPECIAL_SOP_OFF, //offset to start rx is 128
2979 &err);
2980 if (err) {printf("add flow failed\n", err); exit(1);}
2981 #endif
2982 }
2983 #if 0
2984 //special route for this classifier: different flow + destination q
2985 class2_route.p_dest_q = netcp_rx_chan2;
2986 class2_route.p_flow = specialFlow;
2987 class_2 = netcp_cfgAddClass(netapi_handle,
2988 &class_2_cfg,
2989 (void*) &class2_route,
2990 NETCP_CFG_ACTION_TO_SW,
2991 &err);
2992 if (err) {printf("addclass2 failed %d\n",err); exit(1);}
2993 #endif
2995 #endif
2996 //security stuff
2997 p_trie_sa = trie_new();
2998 if (!p_trie_sa) {printf("trie alloc for SA failed\n"); exit(1);}
3002 for (i=0; i < MAX_SEC_INDEX;i++)
3003 {
3004 ourRXKeyParams[i].pEncKey = &ourEncrKey[0];
3005 ourRXKeyParams[i].pAuthKey = &ourAuthKey[0];
3006 memcpy(&(rx_sa[i].src), &config.remote_ipsec_ip,4);
3007 memcpy(&(rx_sa[i].dst), &config.local_ipsec_ip,4);
3009 build_sa_db(i);
3010 sa_info[i].rx_tunnel = netapi_secAddSA(
3011 netapi_handle,
3012 config.ipsec_if_no, //iface #0
3013 &rx_sa[i],
3014 &ourRXKeyParams[i],
3015 config.ipsec_mode_rx == IPSEC_MODE_RX_SIDEBAND ? NETAPI_SEC_SA_SIDEBAND: NETAPI_SEC_SA_INFLOW,
3016 NULL, //use default route
3017 &(sa_info[i].rx_data_mode_handle),
3018 &(sa_info[i].rx_inflow_mode_handle),
3019 &err);
3020 if (err) {printf("addRxSa failed %d\n",err); exit(1);}
3022 if (config.ipsec_mode_rx == IPSEC_MODE_RX_INFLOW)
3023 {
3024 //assume inner and outer ip is the same
3025 rx_policy[i]= netapi_secAddRxPolicy( netapi_handle,
3026 sa_info[i].rx_tunnel, //link to tunnel above
3027 4, //ipv4
3028 &config.remote_ipsec_ip, //src -> them
3029 &config.local_ipsec_ip, //dst -> us
3030 NULL, // no qualifiers
3031 NULL, //default route
3032 &err);
3033 if (err) {printf("addSaPolicy failed %d, for index %d\n",err,i); exit(1);}
3034 }
3035 else
3036 {
3037 rx_policy[i] = 0;
3039 }
3040 #ifdef NET_TEST_ENABLE_SIDE_BAND_LOW_LEVEL_API
3041 /* Remember the NetCP Command Label so save cycles per Crypto
3042 * operation
3043 *
3044 */
3045 if(config.ipsec_mode_rx == IPSEC_MODE_RX_SIDEBAND)
3046 {
3047 nwalRetVal =
3048 nwal_initDMPSCmdInfo(PKTIO_GET_NWAL_INSTANCE(netcp_sb_rx_chan),
3049 sa_info[i].rx_data_mode_handle,
3050 &sa_info[i].rx_dmPSCmdInfo);
3051 }
3053 #endif
3054 }
3056 //tx SA
3057 //security stuff
3058 for (i=0; i < MAX_SEC_INDEX;i++)
3059 {
3060 ourTXKeyParams[i].pEncKey = &ourEncrKey[0];
3061 ourTXKeyParams[i].pAuthKey = &ourAuthKey[0];
3062 memcpy(&(tx_sa[i].src), &config.local_ipsec_ip,4);
3063 memcpy(&(tx_sa[i].dst), &config.remote_ipsec_ip,4);
3064 sa_info[i].tx_tunnel = netapi_secAddSA( netapi_handle,
3065 0, //iface #0
3066 &(tx_sa[i]),
3067 &ourTXKeyParams[i],
3068 config.ipsec_mode_tx == IPSEC_MODE_TX_SIDEBAND ? NETAPI_SEC_SA_SIDEBAND: NETAPI_SEC_SA_INFLOW,
3069 NULL, //use default route
3070 &(sa_info[i].tx_data_mode_handle),
3071 &(sa_info[i].tx_inflow_mode_handle),
3072 &err);
3073 if (err) {printf("addTxSa failed %d\n",err); exit(1);}
3075 #ifdef NET_TEST_ENABLE_SIDE_BAND_LOW_LEVEL_API
3076 /* Remember the NetCP Command Label so save cycles per Crypto
3077 * operation
3078 *
3079 */
3080 if(config.ipsec_mode_tx == IPSEC_MODE_TX_SIDEBAND)
3081 {
3082 nwalRetVal =
3083 nwal_initDMPSCmdInfo(PKTIO_GET_NWAL_INSTANCE(netcp_sb_tx_chan),
3084 sa_info[i].tx_data_mode_handle,
3085 &sa_info[i].tx_dmPSCmdInfo);
3086 }
3087 #endif
3089 #ifdef NET_TEST_ENABLE_INFLOW_LOW_LEVEL_API
3090 if(config.ipsec_mode_tx == IPSEC_MODE_TX_INFLOW)
3091 {
3092 memset(&nwalSaIpSecId, 0, sizeof(nwalSaIpSecId_t));
3093 nwalSaIpSecId.spi = tx_sa[i].spi;
3094 memcpy(&(nwalSaIpSecId.src), &config.local_ipsec_ip,sizeof( nwalIpAddr_t));
3095 memcpy(&(nwalSaIpSecId.dst), &config.remote_ipsec_ip,sizeof( nwalIpAddr_t));
3096 nwalSaIpSecId.proto= tx_sa[i].proto;
3098 nwalRetVal = nwal_initPSCmdInfo(PKTIO_GET_NWAL_INSTANCE(netcp_tx_chan),
3099 &sa_info[i].tx_pkt_info,
3100 &sa_info[i].tx_psCmdInfo);
3102 if (nwalRetVal == nwal_OK)
3103 {
3104 if (nwal_getSecAssoc(PKTIO_GET_NWAL_INSTANCE(netcp_tx_chan),
3105 &nwalSaIpSecId,
3106 NWAL_SA_DIR_OUTBOUND,
3107 &(sa_info[i].tx_inflow_mode_handle),
3108 &sa_info[i].swInfo0,
3109 &sa_info[i].swInfo1) != nwal_TRUE)
3110 {
3111 printf("main: nwal_getSecAssoc failed\n");
3112 exit (1);
3113 }
3114 }
3115 else
3116 {
3117 printf("main: nwal_initPSCmdInfo failed\n");
3118 exit (1);
3119 }
3120 }
3121 #endif
3122 }
3124 #ifdef TEST_TIMERS
3125 //timers
3126 ourTimerBlock = netapi_TimerGroupCreate(
3127 netapi_handle,
3128 "our1sttimer",
3129 our_timer_cb,
3130 0, //1 if timers local to thread
3131 0, //1 if expect to cancel
3132 netapi_getTicksPerSec()/1000, /* 1 msc resolution for these timers */
3133 netapi_getTicksPerSec()/5000, /* would like .5 msc tolerence */
3134 10, //small # of timers to test garbage collection
3135 &err);
3136 if (err) {printf("timergroupcreate failed %d\n",err); exit(1);}
3138 //start a couple of timers
3139 t1 = netapi_TimerGroupStartTimer(
3140 ourTimerBlock,
3141 (void *) 1,
3142 100LL, //timer group ticks
3143 &err);
3144 if (err) {printf("timerstart failed %d\n");}
3145 t2 = netapi_TimerGroupStartTimer(
3146 ourTimerBlock,
3147 (void *) 2,
3148 200LL, //timer group ticks
3149 &err);
3150 if (err) {printf("timerstart failed %d\n");}
3151 t3 = netapi_TimerGroupStartTimer(
3152 ourTimerBlock,
3153 (void *) 3,
3154 300LL, //timer group ticks
3155 &err);
3156 if (err) {printf("timerstart failed %d\n");}
3157 #endif
3158 netcp_cfgReqStats(netapi_handle, our_stats_cb, 1,&err);
3159 if (err!=0) {printf("stats req failed\n");}
3161 /*********************************************/
3162 /*****************end NETAPI STARTUP**********/
3163 /*********************************************/
3166 #if 0
3167 /********************************************
3168 * Basic pkt loopback test
3169 *********************************************/
3170 printf("...runnining pure push/pop benchmark\n");
3171 our_pktio_bench(100);
3172 #endif
3174 /**************unused stuff******************/
3175 #if 0
3176 /* create TRIE */
3177 P_trie = trie_new();
3178 if (!P_trie) {printf("trie alloc failed\n"); exit(1);}
3180 nat = (HEAD_T *) malloc(NE * sizeof(HEAD_T));
3181 if (!nat) {printf("malloc of nat table failed\n"); exit(1);}
3183 //gen_pkts(np2process<NP ? np2process:NP);
3184 n_pkt= np2process;
3186 /* build table */
3187 build_table(P_trie);
3190 /* processing loop: get pkt, check it, look up in table, copy new header,
3191 send packet */
3192 srand((unsigned) np2process);
3193 #endif
3195 /*********************************************/
3196 /**************Entry point into scheduler ****/
3197 /*********************************************/
3198 netapi_schedWaitForEvents(our_sched, &err);
3200 /* done */
3201 our_stats_cb(netapi_handle, NULL);
3204 #define DO_FAST_POLL
3205 #ifdef DO_FAST_POLL
3206 //example_fast_pushpop(OurHeap, 500);
3207 //example_fast_poll(netcp_rx_chan,20000);
3208 #endif
3210 /*************************************************
3211 ************CLEAN UP****************************
3212 ************************************************/
3214 #ifndef EXPERIMENTAL
3215 //delete Classifiers
3216 netcp_cfgDelClass(netapi_handle, class_0, &err);
3217 netcp_cfgDelClass(netapi_handle, class_1, &err);
3218 //netcp_cfgDelClass(netapi_handle, class_2, &err);
3220 #if 0
3221 //delete flow
3222 netcp_cfgDelFlow(netapi_handle, specialFlow, &err);
3223 #endif
3224 #endif
3225 #if 1
3226 //delete policy
3227 for (i=0; i < MAX_SEC_INDEX;i++)
3228 {
3229 if (rx_policy[i])
3230 netapi_secDelRxPolicy(netapi_handle, rx_policy[i], &err);
3232 //delete tunnels
3233 netapi_secDelSA(netapi_handle, 0, sa_info[i].rx_tunnel, &err);
3234 netapi_secDelSA(netapi_handle, 0, sa_info[i].tx_tunnel, &err);
3235 #endif
3236 }
3237 //delete IPs and MAC Interfacess
3238 netcp_cfgDelIp(netapi_handle, 0, 0, NULL, NULL, ip_rule0, &err);
3239 netcp_cfgDelIp(netapi_handle, 1, 0, NULL, NULL, ip_rule1, &err);
3240 netcp_cfgDelMac(netapi_handle,0,&err);
3241 netcp_cfgDelMac(netapi_handle,1,&err);
3244 //close pktio channels we opened
3245 pktio_close(netcp_tx_chan ,&err);
3246 pktio_close(netcp_rx_chan ,&err);
3247 #ifndef EXPERIMENTAL
3248 pktio_close(netcp_sb_tx_chan ,&err);
3249 pktio_close(netcp_sb_rx_chan ,&err);
3251 //clear pktio channel we created
3252 pktio_control(our_chan, (PKTIO_CB) NULL, (PKTIO_CFG_T *) NULL, &zap_channel_control, &err);
3253 pktio_control(netcp_rx_chan2, (PKTIO_CB) NULL, (PKTIO_CFG_T *) NULL, &zap_channel_control, &err);
3255 //delete pktio channels we created
3256 pktio_delete(our_chan, &err);
3257 pktio_delete(netcp_rx_chan2,&err);
3258 #endif
3259 netapi_shutdown(netapi_handle);
3261 }
3263 //EXAMPLE FAST POLL
3264 /* PLD */
3265 void netapi_pld(void * x)
3266 {
3267 asm volatile("pld [r0]");
3268 }
3269 #include "ti/drv/nwal/nwal_util.h"
3271 #define M 1008
3272 static int l3_off[M], l4_off[M], L3_chk_ok[M], L4_chk_ok[M], len[M] ;
3273 static nwal_AppId appid[M];
3274 static unsigned char * buf[M];
3275 #define N2POLL 8 //batch size
3276 #define NTOPOP 190
3277 Ti_Pkt * pHd[NTOPOP];
3278 void example_fast_pushpop(Pktlib_HeapHandle h , int n_trials)
3279 {
3280 int i,j;
3281 unsigned long t1;
3282 unsigned long t2;
3283 unsigned long sumf=0;
3284 unsigned long sumt=0;
3285 unsigned long sump=0;
3286 #define NTOPOP 190
3287 Ti_Pkt * tempVA;
3288 Qmss_QueueHnd freeQ=Pktlib_getInternalHeapQueue(h);
3290 //n_trials of NTOPOP actions
3291 for(i=0;i<n_trials;i++)
3292 {
3293 //raw pop
3294 t1= netapi_timing_start();
3295 pHd[0] = (Ti_Pkt *)QMSS_DESC_PTR(PKTIO_QMSS_QUEUE_POP_RAW (freeQ));
3296 for(j=1;j<NTOPOP;j++)
3297 {
3298 tempVA = _Osal_qmssPhyToVirt(pHd[j-1]);
3299 netapi_pld(tempVA);
3300 //__builtin_prefetch(tempVA);
3301 pHd[j] = (Ti_Pkt *)QMSS_DESC_PTR(PKTIO_QMSS_QUEUE_POP_RAW (freeQ));
3302 sumf+= (int) ( ((Cppi_HostDesc *) tempVA)->origBuffPtr -
3303 ((Cppi_HostDesc *) tempVA)->buffPtr);
3304 }
3305 tempVA = _Osal_qmssPhyToVirt(pHd[j-1]);
3306 sumf+= (int) ( ((Cppi_HostDesc *) tempVA)->origBuffPtr -
3307 ((Cppi_HostDesc *) tempVA)->buffPtr);
3308 t2=netapi_timing_stop();
3309 sumt+= (t2-t1);
3311 //invalidate/wb
3312 for(j=0;j<NTOPOP;j++)
3313 {
3314 tempVA = _Osal_qmssPhyToVirt(pHd[j]);
3315 netapi_utilCacheWbInv(tempVA,128);
3316 }