1 /******************************************
2 * File: net_test.c
3 * Purpose: test app for netapi
4 **************************************************************
5 * FILE: net_test.c
6 *
7 * DESCRIPTION: netapi user space transport
8 * library test application
9 *
10 * REVISION HISTORY: rev 0.0.1
11 *
12 * Copyright (c) Texas Instruments Incorporated 2010-2011
13 *
14 * Redistribution and use in source and binary forms, with or without
15 * modification, are permitted provided that the following conditions
16 * are met:
17 *
18 * Redistributions of source code must retain the above copyright
19 * notice, this list of conditions and the following disclaimer.
20 *
21 * Redistributions in binary form must reproduce the above copyright
22 * notice, this list of conditions and the following disclaimer in the
23 * documentation and/or other materials provided with the
24 * distribution.
25 *
26 * Neither the name of Texas Instruments Incorporated nor the names of
27 * its contributors may be used to endorse or promote products derived
28 * from this software without specific prior written permission.
29 *
30 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
31 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
32 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
33 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
34 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
35 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
36 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
37 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
38 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
39 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
40 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
42 *****************************************/
43 //#define NET_TEST_ENABLE_SIDE_BAND_LOW_LEVEL_API
44 #ifdef NET_TEST_ENABLE_SIDE_BAND_LOW_LEVEL_API
45 #define NWAL_ENABLE_SA
46 #endif
48 #include <stdio.h>
49 #include <stdlib.h>
50 #include <unistd.h>
51 #include <string.h>
54 #include "trie.h"
55 #include "string.h"
56 #include "netapi.h"
57 #include "pktio.h"
58 #include <sys/resource.h>
59 #include "net_test.h"
60 #include <ti/drv/sa/salld.h>
61 //#define EXPERIMENTAL
62 #ifdef EXPERIMENTAL
63 #include "router.c"
64 Trie * our_router;
69 OUR_ROUTE_T routes[MAX_ROUTES]=
70 {
71 {0,{0xD4,0xbe,0xd9,0x00,0xd3,0x7e, 0x00,0x01,0x02,0x03,0x14,0x02,0x08,0x00},0},
72 {0,{0x00,0x00,0x0,0x00,0x0,0x0, 0x00,0x00,0x00,0x00,0x00,0x00,0x08,0x00},0},
73 {0,{0xD4,0xbe,0xd9,0x00,0xd3,0x7e, 0x00,0x01,0x02,0x03,0x14,0x02,0x08,0x00},0},
74 {0,{0x00,0x15,0x60,0xa1,0xf7,0xbe, 0x00,0x01,0x02,0x03,0x04,0x05,0x08,0x00},0},
75 {0,{0xd4,0xbe,0xd9,0x00,0xd3,0x7e, 0x00,0x01,0x02,0x03,0x04,0x05,0x08,0x00},0}};
77 unsigned int ip[MAX_ROUTES]={BE(0x0a0100c8),BE(0x0a00000a),BE(0x0a02000a),BE(0xc0a8010a),BE(0x9eda6719)};
79 #endif
80 //#define TEST_TIMERS
82 /*************debug********************/
83 void dump_descr(unsigned long *p, int n)
84 {
85 printf("--------dump of descriptor %d %x\n", n, (int) p);
86 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]);
87 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]);
88 printf("-----------------------------\n");
89 }
90 void dump_header(unsigned long *p, int n, int a, int r)
91 {
92 printf("--------dump of header %d %x appID=%x flag1=%x\n", n, (int) p,a,r);
93 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]);
94 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]);
95 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]);
96 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]);
97 printf("-----------------------------\n");
98 }
100 /*****************************************/
103 //************for multi pkt burst xfer test in loopback mode
104 #define TX_BURST 700
105 int pktloopback=TUNE_NETAPI_NWAL_ENABLE_PASS_LOOPBACK;
106 nwalTxPSCmdInfo_t flowPSCmdInfo;
107 nwal_RetValue nwalRetVal;
109 /* Local Per Process default resourcese maintained at NWAL */
110 nwalLocCxtInfo_t nwalLocCxt;
112 //this device: 10.0.0.100, mac 0x,01,02,03,04,05 and .. 0x6
114 //test packet, setup for loopback (so dest is ourself)
115 static uint8_t testPkt[] = {
117 /* MAC header */
118 0x00, 0x01, 0x02, 0x03, 0x04, 0x05,
119 0x00, 0xe0, 0xa6, 0x66, 0x57, 0x04,
120 0x08, 0x00,
122 /* IP header */
123 0x45, 0x00,
124 0x00, 0x6c, /* Length (including this header) */
125 0x00, 0x00, 0x00, 0x00, 0x05, 0x11,
126 0x00, 0x00, /* Header checksum */
127 0x0a, 0x00, 0x00, 0x0a, 0x0a, 0x00, 0x00, 0x64,
129 /* UDP header */
130 0x12, 0x34, 0x05, 0x55,
131 0x00, 0x58, /* Length, including this header */
132 0x00, 0x00, /* Header checksum */
134 /* Payload */
135 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39,
136 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f, 0x40, 0x41,
137 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49,
138 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f, 0x50, 0x51,
139 0x52, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, 0x59,
140 0x5a, 0x5b, 0x5c, 0x5d, 0x5e, 0x5f, 0x60, 0x61,
141 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69,
142 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, 0x6f, 0x70, 0x71,
143 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79,
144 0x7a, 0x7b, 0x7c, 0x7d, 0x7e, 0x7f, 0x80, 0x81
146 };
148 char input_file_name[] = "net_test_config.txt";
149 #define MAX_LINE_LENGTH 40
151 #define TEST_PAYLOAD_LEN 80
153 #define TEST_PKT_IP_OFFSET_BYTES 14
154 #define TEST_PKT_UDP_OFFSET_BYTES 34
155 #define TEST_PKT_PLOAD_OFFSET_BYTES 42
156 #define TEST_PKT_UDP_HDR_LEN 8
157 /* Offsets to length fields */
158 #define TEST_PKT_OFFSET_IP_LEN 16
159 #define TEST_PKT_OFFSET_UDP_LEN 38
161 #define TEST_PKT_LEN 122
163 /* The pseudo header checksum of the packet except for the 16 bit length */
164 #define TEST_PKT_PSEUDO_HDR_CHKSUM_SANS_LEN 0x0FFC
166 void example_fast_poll( PKTIO_HANDLE_T * p_pktio, int max_pkts);
167 void example_fast_pushpop(Pktlib_HeapHandle p_heap, int ntrials);
169 void recv_cb_router(struct PKTIO_HANDLE_Tag * channel, Ti_Pkt* p_recv[],
170 PKTIO_METADATA_T meta[], int n_pkts,
171 uint64_t ts );
174 //#include "arpa/inet.h"
175 long htonl(long x)
176 {
177 long temp = (x&0xff000000)>>24 | (x&0xff0000)>>8 | (x&0xff00)<<8 | (x&0xff)<<24 ;
178 return temp;
179 }
181 /********************************************************************
182 * FUNCTION PURPOSE: Ones complement addition utility
183 ********************************************************************
184 ********************************************************************/
185 uint16_t test_utilOnesComplementAdd (uint16_t v1, uint16_t v2)
186 {
187 uint32_t result;
189 result = (uint32_t)v1 + (uint32_t)v2;
190 result = (result >> 16) + (result & 0xffff);
191 result = (result >> 16) + (result & 0xffff);
193 return ((uint16_t)result);
194 }
196 /********************************************************************
197 * FUNCTION PURPOSE: Ones complement checksum utility
198 ********************************************************************
199 ********************************************************************/
200 uint16_t test_utilOnesCompChkSum (uint8_t *p, uint32_t nwords)
201 {
202 uint16_t chksum = 0;
203 uint16_t v;
204 uint32_t i;
205 uint32_t j;
207 for (i = j = 0; i < nwords; i++, j+=2) {
208 v = (p[j] << 8) | p[j+1];
209 chksum = test_utilOnesComplementAdd (chksum, v);
210 }
211 return (chksum);
212 } /* utilOnesCompChkSum */
214 /**************************************************************************************
215 * FUNCTION PURPOSE: Compute ipv4 psudo checksum
216 **************************************************************************************
217 * DESCRIPTION: Compute ipv4 psudo checksum
218 **************************************************************************************/
219 uint16_t test_utilGetIpv4PsudoChkSum (uint8_t *data, uint16_t payloadLen)
220 {
221 uint16_t psudo_chksum;
223 psudo_chksum = test_utilOnesCompChkSum (&data[12], 4);
224 psudo_chksum = test_utilOnesComplementAdd(psudo_chksum, (uint16_t) data[9]);
225 psudo_chksum = test_utilOnesComplementAdd(psudo_chksum, payloadLen);
227 return (psudo_chksum);
229 } /* utilGetIpv4PsudoChkSum */
233 /* net test default configuration */
234 netTestConfig_t config =
235 {
236 {0x00,0x01,0x02,0x03,0x05,0x05},
237 {0x00,0x01,0x02,0x03,0x05,0x06},
238 {10, 0, 0, 100, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
239 {10, 0, 1, 100, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
240 {10, 0, 2, 100, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
241 {192,168 , 1, 100, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
242 {192,168 , 1, 10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
243 IPSEC_MODE_RX_SIDEBAND,
244 IPSEC_MODE_TX_SIDEBAND,
245 0
246 };
248 #if 1 //goes with real tx (to laptop)
249 unsigned char real_mac_header[]={0xd4,0xbe,0xd9,0x00,0xd3,0x7e,
250 0x00,0x01,0x02,0x03,0x04,0x05,
251 0x08,0x00};
252 unsigned char real_ip_addr[]={0xa,0x00,0x00,0x64,0xa,0x0,0x0,0xa};
253 #endif
255 #if 0 //goes with loopback
256 unsigned char mac_header[]={0x00,0x01,0x02,0x03,0x04,0x05,
257 0x00,0x11,0x22,0x33,0x44,0x55,
258 0x08,0x00};
259 #endif
260 #define NE 65536
261 HEAD_T *nat;
263 #define NP 5000
264 int n_pkt = NP;
265 STATS_T stats;
267 Trie * P_trie;
268 Trie *p_trie_sa;
269 HEAD_T pkts[NP];
270 #define PERSLOW 10 //% of pkts that will not be fastpath'd
271 int perslow= PERSLOW;
273 /*******************************************
274 *************NETAPI OBJECTS***************
275 *****************************************/
276 static NETAPI_CFG_T our_netapi_default_cfg=
277 {
278 TUNE_NETAPI_PERM_MEM_SZ,
279 128, //start of packet offset for hw to place data on rx for default flow
280 TUNE_NETAPI_QM_CONFIG_MAX_DESC_NUM, //max number of descriptors in system
281 TUNE_NETAPI_NUM_GLOBAL_DESC, //total we will use
282 TUNE_NETAPI_DEFAULT_NUM_BUFFERS, //#descriptors+buffers in default heap
283 64, //#descriptors w/o buffers in default heap
284 TUNE_NETAPI_DEFAULT_BUFFER_SIZE+128+128, //size of buffers in default heap
285 128 , //tail room
286 256 //extra room
287 };
289 Pktlib_HeapHandle OurHeap;
290 Pktlib_HeapHandle specialSmall;
291 Pktlib_HeapHandle specialLarge;
293 PKTIO_HANDLE_T *our_chan;
294 PKTIO_HANDLE_T *netcp_rx_chan;
295 PKTIO_HANDLE_T *netcp_rx_chan2;
296 PKTIO_HANDLE_T *netcp_tx_chan;
297 PKTIO_HANDLE_T *netcp_sb_tx_chan;
298 PKTIO_HANDLE_T *netcp_sb_rx_chan;
299 PKTIO_CFG_T our_chan_cfg={PKTIO_RW, PKTIO_LOCAL, PKTIO_Q_ANY, 8};
300 PKTIO_CFG_T netcp_rx_cfg={PKTIO_R, PKTIO_NA, PKTIO_NA, 8};
301 PKTIO_CFG_T netcp_rx_cfg2={PKTIO_R, (PKTIO_GLOBAL|PKTIO_PKT), PKTIO_Q_ANY, 8};
302 PKTIO_CFG_T netcp_tx_cfg={PKTIO_W, PKTIO_NA, PKTIO_NA, 8};
303 PKTIO_CFG_T netcp_sb_rx_cfg={PKTIO_R, PKTIO_NA, PKTIO_NA, 8};
304 PKTIO_CFG_T netcp_sb_tx_cfg={PKTIO_W, PKTIO_NA, PKTIO_NA, 8};
306 void house(NETAPI_SCHED_HANDLE_T *s);
307 NETAPI_T netapi_handle;
308 NETAPI_SCHED_HANDLE_T * our_sched;
309 NETAPI_SCHED_CONFIG_T our_sched_cfg={
310 NETAPI_SCHED_DURATION|NETAPI_SCHED_CBV, 0, house, 5000000 //every 5000000 poll loops
311 };
312 void our_stats_cb(NETAPI_T h, paSysStats_t* pPaStats);
313 NETAPI_TIMER_GROUP_HANDLE_T ourTimerBlock;
314 NETAPI_TIMER_T t1;
315 NETAPI_TIMER_T t2;
316 NETAPI_TIMER_T t3;
318 void our_timer_cb( NETAPI_TIMER_GROUP_HANDLE_T th,
319 int n_fired, //# timers fired
320 NETAPI_TIMER_LIST_T fired_list,
321 uint64_t currentTime);
323 NETCP_CFG_IP_T ip_rule0;
324 NETCP_CFG_IP_T ip_rule1;
325 NETCP_CFG_CLASS_T class_0;
326 NETCP_CFG_CLASS_T class_1;
327 NETCP_CFG_CLASS_T class_2;
328 NETCP_CFG_FLOW_HANDLE_T specialFlow;
330 NETCP_CFG_CLASSIFIER_T class_0_cfg=
331 {
332 NETCP_CFG_CLASS_TYPE_L4,
333 {
334 {0,0, NWAL_APP_PLOAD_PROTO_UDP, {2500}}
335 }
336 };
338 NETCP_CFG_CLASSIFIER_T class_1_cfg=
339 {
340 NETCP_CFG_CLASS_TYPE_L4,
341 {
342 {0,0, NWAL_APP_PLOAD_PROTO_UDP, {2502}}
343 }
344 };
346 NETCP_CFG_ROUTE_T class2_route=
347 {
348 NULL, NULL //* to be filled in
349 };
350 NETCP_CFG_CLASSIFIER_T class_2_cfg=
351 {
352 NETCP_CFG_CLASS_TYPE_L3_L4,
353 {
354 {0, 4 ,0/*fill in below*/ , NULL, NULL, //L2/L3
355 NWAL_APP_PLOAD_PROTO_UDP, {2504}} //L4
356 }
357 };
359 PKTIO_CONTROL_T zap_channel_control={PKTIO_CLEAR, NULL};
361 /* security objects. (for loopback mode) */
362 netTestSA_t sa_info[6];
363 int netapi_algorithm_set = 0;
364 int netapi_sec_sa_mode = 2;
365 /* tmannan-end */
366 //NETCP_CFG_SA_T rx_tunnel;
367 //NETCP_CFG_SA_T tx_tunnel;
368 NETCP_CFG_IPSEC_POLICY_T rx_policy[4];
369 //void * rx_data_mode_handle;
370 //void * tx_data_mode_handle;
371 //void * rx_inflow_mode_handle;
372 //void * tx_inflow_mode_handle;
373 /* rx */
376 NETAPI_SEC_SA_INFO_T rx_sa [7] = {
377 {
378 NWAL_SA_DIR_INBOUND,
379 0x11111111, //spi
380 nwal_IpSecProtoESP, //ESP mode
381 nwal_SA_MODE_TUNNEL, //tunnel mode
382 nwal_IPV4, //v4
383 { 1, 2, 3, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, /* Src IP (them) -> set below */
384 { 1, 2, 3, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, /* dst IP (us)-> set below*/
385 64,/* replayWindow */
386 NWAL_SA_AALG_HMAC_SHA1,
387 NWAL_SA_EALG_AES_CBC,
388 0,0 //na
389 },
390 {
391 NWAL_SA_DIR_INBOUND,
392 0x22222222, //spi
393 nwal_IpSecProtoESP, //ESP mode
394 nwal_SA_MODE_TUNNEL, //tunnel mode
395 nwal_IPV4, //v4
396 { 1, 2, 3, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, /* Src IP (them) -> set below */
397 { 1, 2, 3, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, /* dst IP (us)-> set below*/
398 64,/* replayWindow */
399 NWAL_SA_AALG_HMAC_SHA2_256,
400 NWAL_SA_EALG_AES_CTR,
401 0,0 //na
402 },
403 {
404 NWAL_SA_DIR_INBOUND,
405 0x33333333, //spi
406 nwal_IpSecProtoESP, //ESP mode
407 nwal_SA_MODE_TUNNEL, //tunnel mode
408 nwal_IPV4, //v4
409 { 1, 2, 3, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, /* Src IP (them) -> set below */
410 { 1, 2, 3, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, /* dst IP (us)-> set below*/
411 64,/* replayWindow */
412 NWAL_SA_AALG_HMAC_SHA2_256,
413 NWAL_SA_EALG_3DES_CBC,
414 0,0 //na
415 },
416 {
417 NWAL_SA_DIR_INBOUND,
418 0x44444444, //spi
419 nwal_IpSecProtoESP, //ESP mode
420 nwal_SA_MODE_TUNNEL, //tunnel mode
421 nwal_IPV4, //v4
422 { 1, 2, 3, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, /* Src IP (them) -> set below */
423 { 1, 2, 3, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, /* dst IP (us)-> set below*/
424 64,/* replayWindow */
425 NWAL_SA_AALG_HMAC_MD5,
426 NWAL_SA_EALG_NULL,
427 0,0 //na
428 },
429 {
430 NWAL_SA_DIR_INBOUND,
431 0x55555555, //spi
432 nwal_IpSecProtoESP, //ESP mode
433 nwal_SA_MODE_TUNNEL, //tunnel mode
434 nwal_IPV4, //v4
435 { 1, 2, 3, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, /* Src IP (them) -> set below */
436 { 1, 2, 3, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, /* dst IP (us)-> set below*/
437 64,/* replayWindow */
438 NWAL_SA_AALG_NULL,
439 NWAL_SA_EALG_AES_GCM,
440 0,0 //na
441 },
442 {
443 NWAL_SA_DIR_INBOUND,
444 0x66666666, //spi
445 nwal_IpSecProtoESP, //ESP mode
446 nwal_SA_MODE_TUNNEL, //tunnel mode
447 nwal_IPV4, //v4
448 { 1, 2, 3, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, /* Src IP (them) -> set below */
449 { 1, 2, 3, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, /* dst IP (us)-> set below*/
450 64,/* replayWindow */
451 NWAL_SA_AALG_NULL,
452 NWAL_SA_EALG_AES_CCM,
453 0,0 //na
454 },
455 {
456 NWAL_SA_DIR_INBOUND,
457 0x77777777, //spi
458 nwal_IpSecProtoESP, //ESP mode
459 nwal_SA_MODE_TUNNEL, //tunnel mode
460 nwal_IPV4, //v4
461 { 1, 2, 3, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, /* Src IP (them) -> set below */
462 { 1, 2, 3, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, /* dst IP (us)-> set below*/
463 64,/* replayWindow */
464 NWAL_SA_AALG_GMAC,
465 NWAL_SA_EALG_NULL,
466 0,0 //na
467 }
468 };
470 /*tx */
471 NETAPI_SEC_SA_INFO_T tx_sa[7]= {
472 {
473 NWAL_SA_DIR_OUTBOUND,
474 0x11111111, //spi
475 nwal_IpSecProtoESP, //ESP mode
476 nwal_SA_MODE_TUNNEL, //tunnel mode
477 nwal_IPV4, //v4
478 { 1, 2, 3, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, /* Src IP (us) -> set below */
479 { 1, 2, 3, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, /* dst IP (them) -> set below*/
480 64, /* NA replayWindow */
481 NWAL_SA_AALG_HMAC_SHA1,
482 NWAL_SA_EALG_AES_CBC,
483 0,0 //seq no
484 },
485 {
486 NWAL_SA_DIR_OUTBOUND,
487 0x22222222, //spi
488 nwal_IpSecProtoESP, //ESP mode
489 nwal_SA_MODE_TUNNEL, //tunnel mode
490 nwal_IPV4, //v4
491 { 1, 2, 3, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, /* Src IP (us) -> set below */
492 { 1, 2, 3, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, /* dst IP (them) -> set below*/
493 64, /* NA replayWindow */
494 NWAL_SA_AALG_HMAC_SHA2_256,
495 NWAL_SA_EALG_AES_CTR,
496 0,0 //seq no
497 },
498 {
499 NWAL_SA_DIR_OUTBOUND,
500 0x33333333, //spi
501 nwal_IpSecProtoESP, //ESP mode
502 nwal_SA_MODE_TUNNEL, //tunnel mode
503 nwal_IPV4, //v4
504 { 1, 2, 3, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, /* Src IP (us) -> set below */
505 { 1, 2, 3, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, /* dst IP (them) -> set below*/
506 64, /* NA replayWindow */
507 NWAL_SA_AALG_HMAC_SHA2_256,
508 NWAL_SA_EALG_3DES_CBC,
509 0,0 //seq no
510 },
511 {
512 NWAL_SA_DIR_OUTBOUND,
513 0x44444444, //spi
514 nwal_IpSecProtoESP, //ESP mode
515 nwal_SA_MODE_TUNNEL, //tunnel mode
516 nwal_IPV4, //v4
517 { 1, 2, 3, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, /* Src IP (us) -> set below */
518 { 1, 2, 3, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, /* dst IP (them) -> set below*/
519 64, /* NA replayWindow */
520 NWAL_SA_AALG_HMAC_MD5,
521 NWAL_SA_EALG_NULL,
522 },
523 {
524 NWAL_SA_DIR_OUTBOUND,
525 0x55555555, //spi
526 nwal_IpSecProtoESP, //ESP mode
527 nwal_SA_MODE_TUNNEL, //tunnel mode
528 nwal_IPV4, //v4
529 { 1, 2, 3, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, /* Src IP (them) -> set below */
530 { 1, 2, 3, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, /* dst IP (us)-> set below*/
531 64,/* replayWindow */
532 NWAL_SA_AALG_NULL,
533 NWAL_SA_EALG_AES_GCM,
534 0,0 //na
535 },
536 {
537 NWAL_SA_DIR_OUTBOUND,
538 0x66666666, //spi
539 nwal_IpSecProtoESP, //ESP mode
540 nwal_SA_MODE_TUNNEL, //tunnel mode
541 nwal_IPV4, //v4
542 { 1, 2, 3, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, /* Src IP (them) -> set below */
543 { 1, 2, 3, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, /* dst IP (us)-> set below*/
544 64,/* replayWindow */
545 NWAL_SA_AALG_NULL,
546 NWAL_SA_EALG_AES_CCM,
547 0,0 //na
548 },
549 {
550 NWAL_SA_DIR_OUTBOUND,
551 0x77777777, //spi
552 nwal_IpSecProtoESP, //ESP mode
553 nwal_SA_MODE_TUNNEL, //tunnel mode
554 nwal_IPV4, //v4
555 { 1, 2, 3, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, /* Src IP (them) -> set below */
556 { 1, 2, 3, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, /* dst IP (us)-> set below*/
557 64,/* replayWindow */
558 NWAL_SA_AALG_GMAC,
559 NWAL_SA_EALG_NULL,
560 0,0 //na
561 }
562 };
564 static nwalSecKeyParams_t ourTXKeyParams[7] ={
565 {
566 16, /* encKeySize: CTR 16 bytes Encryption Key and 4 bytes Salt : 24 bytes:NWAL_SA_EALG_3DES_CBC and 0 bytes Salt*/
567 20, /* macKeySize: 16 bytes NWAL_SA_AALG_HMAC_SHA1 */
568 NULL, //set below
569 NULL, //set below
570 },
571 {
572 20, /* encKeySize: CTR 16 bytes Encryption Key and 4 bytes Salt : 24 bytes:NWAL_SA_EALG_AES_CTR and 0 bytes Salt*/
573 32, /* macKeySize: 16 bytes NWAL_SA_AALG_HMAC_SHA2_256 */
574 NULL, //set below
575 NULL, //set below
576 },
577 {
578 24, /* encKeySize: DES-CBC: 24 bytes:NWAL_SA_EALG_3DES_CBC and 0 bytes Salt*/
579 32, /* macKeySize: 16 bytes NWAL_SA_AALG_HMAC_SHA2_256 */
580 NULL, //set below
581 NULL, //set below
582 },
583 {
584 0, /* NULL*/
585 16, /* MD5, 16 bytes */
586 NULL, //set below
587 NULL, //set below
588 },
589 {
590 20, /* encKeySize: GCM 16 bytes Encryption Key and 4 bytes Salt */
591 0, /* macKeySize: 0*/
592 NULL, //set below
593 NULL, //set below
594 },
595 {
596 19, /* encKeySize: CTR 16 bytes Encryption Key and 3 bytes Salt : 24 bytes:NWAL_SA_EALG_AES_CTR and 0 bytes Salt*/
597 0, /* macKeySize 0*/
598 NULL, //set below
599 NULL, //set below
600 },
601 {
602 0, /* encKeySize: CTR 16 bytes Encryption Key and 3 bytes Salt : 24 bytes:NWAL_SA_EALG_AES_CTR and 0 bytes Salt*/
603 24, /* macKeySize 0*/
604 NULL, //set below
605 NULL, //set below
606 }
607 };
609 /* these keys are for aes-ctr and hmac sha2_256 */
610 static nwalSecKeyParams_t ourRXKeyParams[7] ={
611 {
612 16, /* encKeySize: CTR 16 bytes Encryption Key and 4 bytes Salt : 24 bytes:NWAL_SA_EALG_3DES_CBC and 0 bytes Salt*/
613 20, /* macKeySize: 16 bytes NWAL_SA_AALG_HMAC_SHA1 */
614 NULL, //set below
615 NULL, //set below
616 },
617 {
618 20, /* encKeySize: CTR 16 bytes Encryption Key and 4 bytes Salt : 24 bytes:NWAL_SA_EALG_AES_CTR and 0 bytes Salt*/
619 32, /* macKeySize: 16 bytes NWAL_SA_AALG_HMAC_SHA2_256 */
620 NULL, //set below
621 NULL, //set below
622 },
623 {
624 24, /* encKeySize: DES-CBC: 24 bytes:NWAL_SA_EALG_3DES_CBC and 0 bytes Salt*/
625 32, /* macKeySize: 16 bytes NWAL_SA_AALG_HMAC_SHA2_256 */
626 NULL, //set below
627 NULL, //set below
628 },
629 {
630 0, /* NWAL_SA_EALG_NULL*/
631 16, /* NWAL_SA_AALG_HMAC_MD5, 16 bytes */
632 NULL, //set below
633 NULL, //set below
634 },
635 {
636 20, /* encKeySize: GCM 16 bytes Encryption Key and 4 bytes Salt */
637 0, /* macKeySize: 0*/
638 NULL, //set below
639 NULL, //set below
640 },
641 {
642 19, /* encKeySize: CTR 16 bytes Encryption Key and 3 bytes Salt t*/
643 0, /* macKeySize 0*/
644 NULL, //set below
645 NULL, //set below
646 },
647 {
648 0, /* encKeySize: CTR 16 bytes Encryption Key and 3 bytes Salt : 24 bytes:NWAL_SA_EALG_AES_CTR and 0 bytes Salt*/
649 24, /* macKeySize 0*/
650 NULL, //set below
651 NULL, //set below
652 }
653 };
656 static uint8_t ourAuthKey[36] =
657 {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F,
658 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F,
659 0x20, 0x21, 0x22, 0x23 };
660 ;
662 static uint8_t ourEncrKey[36] =
663 {0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0xFF,
664 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0xFF,
665 0x30, 0x31, 0x32, 0x33 };
668 /*************************END NETAPI OBJECTS***********************/
670 #define START_SRC_IP 0x0a00000a
671 #define DST_IP 0xc0a80001
672 #define NEW_START_SRC_IP 0x9eda000a
673 #define DST_PORT 0x555
674 #define START_SRC_PORT 0x1234
675 #define NEW_START_SRC_PORT 100
676 void update_header(HEAD_T * p_head, int len)
677 {
678 unsigned char *p = (unsigned char *) &p_head->udp[1];
679 len -= (20+14);
680 /* update ip checksum */
681 /* update udp checksum */
682 /* update length */
683 *p= (len&0xff00)>>8;
684 *(p+1) = len&0xff;
685 }
687 #if 0
688 void gen_pkts(int np)
689 {
690 int i;
691 int ip = START_SRC_IP &0xff;
692 int port= START_SRC_PORT;
693 //HEAD_T temp={{0x25000200,0xdead0000,0x80110000,START_SRC_IP,DST_IP},
694 // {START_SRC_PORT<<16|DST_PORT,0x01ec<<16|0x0000}};
695 HEAD_T temp;
696 memcpy(&temp,&testPkt[0],sizeof(HEAD_T));
698 for(i=0;(i<np) && (i<NP);i++)
699 {
700 memcpy(&pkts[i],&temp,sizeof(temp));
701 update_header(&pkts[i],512); /* update checksums etc */
702 /* change template for new pkt */
703 ip+=1;
704 if(ip>254) {(ip=START_SRC_IP&0xff); port+=1; }
705 temp.ip[3] = htonl((START_SRC_IP&0xffffff00)| ip);
706 temp.udp[0] = htonl( (temp.udp[0]&0xffff0000)| port);
707 temp.udp[1] = htonl(temp.udp[1]);
709 }
710 n_pkt=np;
711 }
712 #endif
714 void build_table(Trie * p_trie)
715 {
716 int i;
717 int sport=NEW_START_SRC_PORT;
718 HEAD_T temp,temp2;
719 KEY_T key;
721 memcpy(&temp,&testPkt[14],sizeof(temp));
723 //insert entry into trie
724 key.src_ip = temp.ip[3];
725 key.dst_ip = temp.ip[4];
726 key.src_port= (temp.udp[0]&0xffff0000)>>16;
727 key.dst_port= (temp.udp[0]&0x0000ffff);
728 trie_insert(p_trie,(char *)&key,sizeof(key), (void *) &nat[0]); //asociate with nat entry 0
730 //build nat table
731 for(i=0;i<100;i++)
732 {
733 memcpy(&temp2,&testPkt[14],sizeof(temp));
734 temp2.udp[0] = (temp2.udp[0] & 0xffff0000) | sport;
735 memcpy(&nat[i], &temp2, sizeof(temp2));
736 sport+= 1;
737 }
738 }
740 //===========stub transmitter==================
741 void send_pkt(Ti_Pkt *pkt, int len)
742 {
743 //just free pkt. Don't send
744 Pktlib_freePacket((Ti_Pkt*)pkt);
745 return;
746 }
748 //==========stub slow path============
749 void slow_path(Ti_Pkt *pkt, int len)
750 {
751 // debug: check descriptor for validity by verifying that desciptor link field is null as expected\n");
752 {Ti_Pkt * k= Pktlib_getNextPacket(pkt); if(k != 0) {printf(" slowpath, nexpkt != NULL");}}
753 //just free pkt
754 Pktlib_freePacket((Ti_Pkt*)pkt);
755 return;
756 }
757 /* check header */
758 struct LastPktInfo
759 {
760 int iface;
761 int ipcsum;
762 int l4csum;
763 } ;
764 static struct LastPktInfo lpInfo;
766 int check_header(HEAD_T * p_head, PKTIO_METADATA_T * p_meta)
767 {
768 if (NWAL_RX_FLAG1_META_DATA_VALID & p_meta->u.rx_meta->rxFlag1)
769 {
770 lpInfo.iface = ((unsigned int)p_meta->u.rx_meta->appId) &0xff; //last byte is interface num
771 lpInfo.ipcsum =(p_meta->u.rx_meta->rxFlag1 & NWAL_RX_FLAG1_IPV4_CHKSUM_VERIFY_MASK )== NWAL_RX_FLAG1_IPV4_CHKSUM_VERIFY_ACK ? 1 : 0;
772 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;
773 if ((unsigned int)p_meta->u.rx_meta->appId & NETAPI_NETCP_MATCH_IPSEC)
774 {
775 stats.sec_rx++;
776 }
777 if ((unsigned int)p_meta->u.rx_meta->appId & NETAPI_NETCP_MATCH_IPSEC_POLICY)
778 {
779 stats.secp_rx++;
780 }
782 if ((unsigned int)p_meta->u.rx_meta->appId & NETAPI_NETCP_MATCH_CLASS)
783 {
784 int c= ((unsigned int)p_meta->u.rx_meta->appId >>8)&0xffff;
785 if (c==0) stats.n_class0_rx +=1;
786 else if (c==1) stats.n_class1_rx +=1;
787 else if (c==2) stats.n_class2_rx +=1;
788 else printf("**NET_TEST RX -unknown class: %x\n", p_meta->u.rx_meta->appId);
789 }
790 }
792 return 1;
793 }
795 #define PKT_LEN 1400
796 void test_alloc_free(int n)
797 {
798 int i;
799 Ti_Pkt * b;
801 for(i=0;i<n;i++)
802 {
803 b=Pktlib_allocPacket(OurHeap,PKT_LEN);
804 Pktlib_freePacket(b);
805 }
806 }
808 //measurement test points
809 unsigned int vv1;
810 unsigned int vv2;
811 unsigned int vv3;
812 unsigned int vv4;
813 unsigned int vv5;
814 unsigned int vv6;
815 //these are updated by pktio.
816 #ifdef PKTIO_GET_BENCHMARK
817 extern unsigned int vv7p;
818 extern unsigned int vv8p;
819 extern unsigned int vv9p;
820 extern unsigned int vv10p;
821 extern unsigned int vv11p;
822 extern unsigned int vv12p;
824 extern unsigned int vv13p; //rcv path
825 extern unsigned int vv14p;
826 extern unsigned int vv15p;
827 #endif
829 unsigned int vv11;
831 extern unsigned int nwal_prof1,nwal_prof2,nwal_prof3,nwal_prof4,nwal_prof5,nwal_prof6;
833 //#define REASSEMBLE_BENCH
834 #ifdef REASSEMBLE_BENCH
835 #include <ti/drv/pa/example/reassemLib/reassemLib.h>
836 /*--------------reassembly benchmark--------------------------------*/
837 void our_reassemble_bench(int nfrags)
838 {
839 paIPReassemblyConfig_t Config={5,128,10000 };
840 int i,j;
841 int len;
842 Ti_Pkt tip;
843 char *buffer;
844 unsigned long v1;
845 unsigned long v2;
846 unsigned long sum1=0;
847 unsigned long sum2=0;
848 paEx_reassemLibInit(&Config);
849 for(j=0;j<200/nfrags;j++)
850 {
851 for(i=0;i<nfrags;i++)
852 {
853 short temp;
854 tip=Pktlib_allocPacket(OurHeap,PKT_LEN);
855 Pktlib_getDataBuffer(tip,(uint8_t**)&buffer,&len);
856 memcpy(&buffer[0],&testPkt[14],20); //IP header
857 if (i < (nfrags-1)) buffer[6] = 0x20;
858 temp = i*40;
859 buffer[6]|= (temp&0x1f00)>>8;
860 buffer[7]= (temp&0xff);
861 temp = 20+40*8;
862 buffer[2]= (temp&0xff00)>>8;
863 buffer[3]= (temp&0xff);
864 Pktlib_setPacketLen(tip, temp);
865 v1= netapi_timing_stop();
866 paEx_reassemLibProc(tip, 0xffff);
867 v2= netapi_timing_stop();
868 sum1+= v2-v1;
869 }
870 sum2 += v2-v1;
871 }
872 printf("reasssembly test: %d trials, %d frags/pkt %d cycles/frag %d cycles/last frag\n",j,nfrags, sum1/(j*nfrags), sum2/(j));
873 }
874 #endif
876 /*--------------basic pktio send/recv benchmark----------------------*/
877 unsigned int timings[10];
878 void our_pktio_bench(int ntrials)
879 {
880 int i;
881 #define NBATCH 8
882 Ti_Pkt tip;
883 unsigned char * pData;
884 int len;
885 int n;
886 int err;
887 int sum =0;
889 Osal_cache_op_measure_reset();
890 for(i=0;i<10;i++) timings[i]=0;
891 printf("calibration loop .. ");
892 for(i=0;i<1000;i++)
893 {
894 vv1= netapi_timing_stop();
895 vv2= netapi_timing_stop();
896 sum+=(vv2-vv1);
897 }
898 printf(" accuracy = +- %d cycles\n", sum/1000);
899 sleep(1);
901 PKTIO_METADATA_T meta[10]={0};
902 //send single, recv single
903 for(i=0;i<ntrials;i++)
904 {
905 vv1= netapi_timing_stop();
906 tip=Pktlib_allocPacket(OurHeap,PKT_LEN);
907 vv2= netapi_timing_stop();
908 Pktlib_getDataBuffer(tip,&pData,&len);
909 vv3= netapi_timing_stop();
910 pktio_send(our_chan,tip,&meta[0],&err);
911 vv4= netapi_timing_stop();
912 n=pktio_poll(our_chan,NULL , &err);
913 vv5= netapi_timing_stop();
914 timings[0]+=(vv6-vv4);
915 timings[1]+=(vv5-vv4);
916 timings[3]+=(vv4-vv3);
917 timings[5]+=(vv3-vv1);
918 timings[8]+=(vv11-vv6);
920 #ifdef PKTIO_GET_BENCHMARK
921 timings[2]+=(vv7p-vv4);
922 timings[4]+=(vv8p-vv3);
923 timings[6]+=(vv9p-vv8p);
924 timings[7]+=(vv10p-vv7p);
925 #endif
926 }
928 #ifdef PKTIO_GET_BENCHMARK
929 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,
930 timings[1]/ntrials, timings[2]/ntrials,timings[3]/ntrials, timings[4]/ntrials,timings[5]/ntrials,
931 timings[6]/ntrials,timings[7]/ntrials, timings[8]/ntrials );
932 {
933 unsigned int ccycles;
934 int n_c_ops;
935 ccycles =Osal_cache_op_measure(&n_c_ops);
936 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);
937 }
938 #endif
940 }
941 /*-----------test driver: gen an input pkt------- */
942 //char buffer[sizeof(HEAD_T)+PKT_LEN];
943 Ti_Pkt * get_pkt(int n, unsigned int *p_len, Pktlib_HeapHandle heap2use, int size, unsigned char * buf2cpy, int copy_size)
944 {
945 int ind;
946 long long temp;
947 Ti_Pkt * b;
948 char * buffer;
949 unsigned int len;
951 if (pktloopback==0)
952 {
953 if (n>=TX_BURST) return NULL; //just gen pkts to warm swtich, so that it knows
954 //our mac is valid
955 }
956 b=Pktlib_allocPacket(heap2use,size);
957 if (!b)
958 {printf("net_test: get_pkt() heap empty!! %d pkts gen'd %d \n", n); return NULL;};
960 //debug - way to validate descriptor
961 {Ti_Pkt* k= Pktlib_getNextPacket(b);
962 if(k != 0) {printf(" genpkt, nexpkt != NULL");}}
965 //get pointer to buffer area of packet
966 Pktlib_getDataBuffer(b,(uint8_t**)&buffer,&len);
967 if (!buffer)
968 {printf("net_test: get_pkt() heap returned empty buffer %d \n", n); return NULL;};
970 #if 0
971 if (pktloopback==0)
972 {
973 temp = (long long) rand();
974 temp *= PKT_LEN;
975 temp /= RAND_MAX;
976 temp +=2;
977 *p_len = (int) temp;
978 *p_len = *p_len &0xfffffffe;
979 temp = (long long) rand();
980 temp *= n_pkt;
981 temp /= RAND_MAX;
982 ind = (int) temp;
983 update_header(&pkts[ind],*p_len);
984 //printf("get pkt:%d %d ind=%d len=%d\n",RAND_MAX, rand(),ind, *p_len);
985 memcpy(&buffer[0], &mac_header[0],14);
986 memcpy(&buffer[14],(char*)&pkts[ind],sizeof(HEAD_T));
987 }
988 else
989 #endif
991 //copy test packet into buffer
992 {
993 memcpy(&buffer[0], buf2cpy, copy_size);
994 *p_len = copy_size;
995 }
996 return b;
997 }
999 static int eof=0;
1000 /*--------------------------------------------------------------
1001 *----------utility to flip a packet and send
1002 *--------------------back to source----------------------------
1003 * flag=1 => ipsec
1004 *--------------------------------------------------------------*/
1005 void flip_and_send_pkt(Ti_Pkt *tip, unsigned char * p_pkt, int len, int flag)
1006 {
1007 unsigned char mac_temp[6];
1008 unsigned char ip_temp[4];
1009 unsigned char new_dest_port[2]={0x75,0x30}; // 30000
1010 uint16_t blah;
1011 uint16_t i=1; /* for testing only */
1013 uint8_t *p_spi;
1014 netTestSA_t * p_sa_info;
1015 uint8_t p_iv[16];
1016 uint8_t p_add[8];
1017 Cppi_HostDesc* pPloadDesc;
1019 Pktlib_setPacketLen(tip,len);
1020 //mac
1021 memcpy(&mac_temp,&p_pkt[0],6);
1022 memcpy(&p_pkt[0],&p_pkt[6],6);
1023 memcpy(&p_pkt[6],&mac_temp,6);
1024 //memcpy(&p_pkt[0],real_mac_header,6); //for testing to wireshark pc
1026 //ip (outer in case of ipsec)
1027 memcpy(&ip_temp, &p_pkt[14+12],4);
1028 memcpy(&p_pkt[14+12],&p_pkt[14+12+4],4);
1029 memcpy(&p_pkt[14+12+4],&ip_temp,4);
1031 //outer checksum to 0
1032 if (!flag)
1033 {
1034 memset(&p_pkt[14+10],0,2);
1035 }
1037 //inner ip &udp for ipsec
1038 if (flag)
1039 {
1040 p_spi = &(p_pkt[netTest_MAC_HEADER_LEN+netTest_IP_HEADER_LEN]);
1041 p_sa_info = (netTestSA_t *) trie_lookup(p_trie_sa, (char *)p_spi ,4);
1042 if (p_sa_info == NULL)
1043 {
1044 printf("flip_and_send_pkt(): trie_lookup() failed\n");
1045 return;
1046 }
1047 //just drop non-udp packet
1048 if (p_pkt[p_sa_info->tx_payload_info.encOffset+9]!=0x11)
1050 {
1051 stats.n_new+=1;Pktlib_freePacket(tip); return;
1052 }
1054 /* flip inner IP */
1055 memcpy(&ip_temp, &p_pkt[p_sa_info->tx_payload_info.encOffset+12],4);
1056 memcpy(&p_pkt[p_sa_info->tx_payload_info.encOffset+12],&p_pkt[p_sa_info->tx_payload_info.encOffset+12+4],4);
1057 memcpy(&p_pkt[p_sa_info->tx_payload_info.encOffset+12+4],&ip_temp,4);
1059 /* setting udp ports */
1060 memcpy(&p_pkt[p_sa_info->tx_payload_info.encOffset+20+2],&new_dest_port[0],2);
1061 memset(&p_pkt[p_sa_info->tx_payload_info.encOffset+20+6],0,2); //checksum
1066 if (config.ipsec_mode_tx == IPSEC_MODE_TX_SIDEBAND)
1067 {
1068 //inner ip checksum : leave alone
1069 #if 0
1070 blah=test_utilOnesCompChkSum (&p_pkt[14+20+8+16], 10);
1071 p_pkt[14+20+8+16+10]= (blah&0xff00)>>8;
1072 p_pkt[14+20+8+16+11]= blah&0xff;
1073 #endif
1075 //tbd udp checksum (leave at 0)
1077 //outer ip, set to 0 (we will compute on way out
1078 memset(&p_pkt[14+10],0,2);
1079 }
1080 else
1081 {
1082 //#else //inflow, don't touch outer , clear inner
1083 //DALmemset(&p_pkt[14+20+8+16+10],0,2); //inner checksum, we will compute on way out
1084 //outer ip checksum : leave alone
1086 #if 0
1087 blah = test_utilOnesCompChkSum (&p_pkt[14], 10);
1088 p_pkt[14+10]= (blah&0xff00)>>8;
1089 p_pkt[14+11]= blah&0xff;
1090 #endif
1092 }
1093 }
1094 else
1095 {
1096 memset(&p_pkt[14+20+6],0,2);//0 udp checksum (we will compute on way out
1097 memcpy(&p_pkt[14+20+2],&new_dest_port[0],2);
1098 }
1100 /*IPSEC case */
1101 if (flag)
1102 {
1103 if (config.ipsec_mode_tx == IPSEC_MODE_TX_SIDEBAND)
1104 //send to crypto for encryption
1105 //12 byte auth tag
1106 {
1107 PKTIO_METADATA_T meta = {PKTIO_META_SB_TX,{0},0};
1108 int err;
1109 nwalDmTxPayloadInfo_t meta_tx={0};
1110 meta.sa_handle=p_sa_info->tx_data_mode_handle; //use TX SA context
1112 #if 0
1114 meta_tx.encOffset =p_sa_info->tx_payload_info.encOffset;
1116 meta_tx.authOffset =netTest_MAC_HEADER_LEN+netTest_IP_HEADER_LEN;
1118 //meta_tx.encSize=len - 14- 20-8-16-12;
1119 meta_tx.encSize = len - p_sa_info->tx_payload_info.encOffset -netTest_ICV_LEN;
1121 //meta_tx.authSize= len -14-20-12;
1122 meta_tx.authSize = len - meta_tx.authOffset - netTest_ICV_LEN;
1123 //meta_tx.pEncIV= &p_pkt[14+20+8]; //just use same IV..
1124 #endif
1125 memcpy(&meta_tx, &(p_sa_info->tx_payload_info), sizeof(nwalDmTxPayloadInfo_t));
1128 meta_tx.encSize = len - p_sa_info->tx_payload_info.encOffset -p_sa_info->auth_tag_size;
1129 meta_tx.authSize = len - meta_tx.authOffset - p_sa_info->auth_tag_size;
1131 #if 0
1132 printf("flip_and_send_pkt(): encOffset %d\n", meta_tx.encOffset);
1133 printf("flip_and_send_pkt():authOffset %d\n", meta_tx.authOffset);
1134 printf("flip_and_send_pkt(): encSize %d\n", meta_tx.encSize);
1135 printf("flip_and_send_pkt(): authSize %d\n", meta_tx.authSize);
1136 #endif
1138 meta_tx.pAuthIV=NULL;
1139 meta_tx.aadSize=0;
1140 meta_tx.pAad=NULL;
1141 if (p_sa_info->cipherMode == NWAL_SA_EALG_AES_CTR)
1142 {
1143 memcpy(&p_iv[0], &ourEncrKey[16], 4);
1144 memcpy(&p_iv[4], &p_pkt[netTest_MAC_HEADER_LEN +netTest_IP_HEADER_LEN + netTest_ESP_HEADER_LEN], 8);
1145 p_iv[12] = 0;
1146 p_iv[13] = 0;
1147 p_iv[14] = 0;
1148 p_iv[15] = 1;
1149 meta_tx.pEncIV = &p_iv[0];
1150 }
1151 else if ((p_sa_info->cipherMode == NWAL_SA_EALG_AES_GCM) ||
1152 (p_sa_info->cipherMode == NWAL_SA_EALG_AES_CCM))
1153 {
1154 memcpy(&p_iv[0], &p_pkt[netTest_MAC_HEADER_LEN +netTest_IP_HEADER_LEN + netTest_ESP_HEADER_LEN], 8);
1155 meta_tx.pEncIV = &p_iv[0];
1156 memcpy(&p_add[0], &p_pkt[netTest_MAC_HEADER_LEN +netTest_IP_HEADER_LEN], 8);
1157 meta_tx.pAad= &p_add[0];
1158 meta_tx.aadSize = 8;
1159 }
1160 else if (p_sa_info->cipherMode == NWAL_SA_EALG_NULL)
1161 {
1162 meta_tx.pEncIV = NULL;
1163 }
1164 else
1165 {
1166 meta_tx.pEncIV = &p_pkt[netTest_MAC_HEADER_LEN +netTest_IP_HEADER_LEN + netTest_ESP_HEADER_LEN ];
1167 }
1168 /* post it to netcp sb tx channel*/
1169 meta_tx.appCtxId = (nwal_AppId)netapi_timing_start();
1170 meta.u.tx_sb_meta=&meta_tx;
1172 #ifdef NET_TEST_ENABLE_SIDE_BAND_LOW_LEVEL_API
1173 /* Use the command label which was cached during create time
1174 * Update the Queue to receive output packet from SA to the local
1175 * core Queue. Below information can be saved by application in
1176 * per process context to avoid API overhead per packet
1177 * Application can use below rxSbSaQ for polling packets back from
1178 * SA
1179 */
1180 nwalRetVal =
1181 nwal_getLocCxtInfo(PKTIO_GET_NWAL_INSTANCE(netcp_sb_tx_chan),
1182 &nwalLocCxt);
1183 if(nwalRetVal == nwal_OK)
1184 {
1185 p_sa_info->tx_dmPSCmdInfo.rxSbSaQ = nwalLocCxt.rxSbSaQ;
1186 }
1187 nwal_mCmdDMUpdate(tip,
1188 &p_sa_info->tx_dmPSCmdInfo,
1189 meta_tx.appCtxId,
1190 meta_tx.encOffset,
1191 meta_tx.encSize,
1192 meta_tx.pEncIV,
1193 meta_tx.authOffset,
1194 meta_tx.authSize,
1195 meta_tx.pAuthIV,
1196 meta_tx.aadSize,
1197 meta_tx.pAad);
1198 pPloadDesc = Pktlib_getDescFromPacket(tip);
1199 pPloadDesc = Qmss_osalConvertDescVirtToPhy(pPloadDesc);
1200 Qmss_queuePushDescSizeRaw(p_sa_info->tx_dmPSCmdInfo.txQueue,
1201 pPloadDesc,
1202 NWAL_DESC_SIZE);
1204 #else
1205 pktio_send(netcp_sb_tx_chan,tip,&meta,&err);
1206 #endif
1207 }
1208 else
1209 {
1210 //inflow tx
1211 //send pkt directly, asking for IP and UDP checksum offloads AND IPSEC to be applied
1212 PKTIO_METADATA_T meta = {PKTIO_META_TX,{0},0};
1213 int err;
1214 nwalTxPktInfo_t meta_tx={0};
1215 #define USE_COPY
1216 #ifdef USE_COPY
1217 //debug: see if re-using RX descriptor for TX is causing our SA lockup
1218 {
1219 int new_len=0;
1220 Ti_Pkt new_tip = get_pkt(0, &new_len, specialLarge , len+10 , &p_pkt[0] , len);
1221 if (!new_tip)
1222 {
1223 printf("net_test> new_tip NULL\n");
1224 }
1225 else
1226 {
1227 Pktlib_setPacketLen(new_tip,new_len);
1228 Pktlib_freePacket(tip);
1229 tip=new_tip;
1230 Pktlib_getDataBuffer(tip,(uint8_t**)&p_pkt,&new_len); //reset p_pkt to point to new buffer as its used below
1231 Cppi_setTimeStamp (Cppi_DescType_HOST, (Cppi_Desc *) tip,stats.sec_tx);
1232 }
1233 }
1234 if (len <1500)
1235 {
1236 eof+=1;
1237 }
1238 #endif
1239 meta.sa_handle=p_sa_info->tx_inflow_mode_handle; //this tells netapi that inflow crypto needs to be applied
1240 //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 );
1241 meta_tx.txFlag1 = p_sa_info->tx_pkt_info.txFlag1;
1242 meta_tx.enetPort=0;
1243 //meta_tx.saOffBytes=14+20;
1244 meta_tx.saOffBytes= p_sa_info->tx_pkt_info.saOffBytes;
1245 meta_tx.saPayloadLen=len-14-20; //don't include tag, mac and outer header
1246 //meta_tx.startOffset = 0;
1247 meta_tx.startOffset = p_sa_info->tx_pkt_info.startOffset;
1248 //meta_tx.ipOffBytes = 14+20+8+16; //to inner header
1249 meta_tx.ipOffBytes =p_sa_info->tx_payload_info.encOffset;
1250 //meta_tx.l4OffBytes = 14+20+8+16+20; //to L4
1251 meta_tx.l4OffBytes = p_sa_info->tx_pkt_info.l4OffBytes;
1252 meta_tx.l4HdrLen = p_sa_info->tx_pkt_info.l4HdrLen;
1253 meta_tx.ploadLen = (unsigned) ((p_pkt[meta_tx.l4OffBytes+4]<<8)|p_pkt[meta_tx.l4OffBytes+4+1]) -8 ;
1254 meta_tx.pseudoHdrChecksum =
1255 test_utilGetIpv4PsudoChkSum(&p_pkt[meta_tx.ipOffBytes],8+ meta_tx.ploadLen);
1257 /* post it to netcp tx channel*/
1258 meta.u.tx_meta=&meta_tx;
1259 if (stats.sec_tx<20) dump_descr((long *) tip, stats.sec_tx);
1260 pktio_send(netcp_tx_chan,tip,&meta,&err);
1261 stats.tx +=1;
1262 stats.sec_tx +=1;
1263 }
1264 }
1265 else //non ipsec send pkt directly, asking for IP and UDP checksum ofload
1266 {
1267 PKTIO_METADATA_T meta2 = {PKTIO_META_TX,{0},0};
1268 int err;
1269 nwalTxPktInfo_t meta_tx2={0};
1270 meta2.sa_handle=nwal_HANDLE_INVALID;
1271 meta_tx2.txFlag1 = (NWAL_TX_FLAG1_DO_IPV4_CHKSUM|NWAL_TX_FLAG1_DO_UDP_CHKSUM| NWAL_TX_FLAG1_META_DATA_VALID );
1272 meta_tx2.startOffset = 0;
1273 meta_tx2.ipOffBytes = 14;
1274 meta_tx2.l4OffBytes = 14+20;
1275 meta_tx2.l4HdrLen = 8;
1276 meta_tx2.ploadLen = (unsigned) ((p_pkt[14+20+4]<<8)|p_pkt[14+20+4+1]) -8 ;
1277 meta_tx2.pseudoHdrChecksum =
1278 test_utilGetIpv4PsudoChkSum(&p_pkt[14],8+ meta_tx2.ploadLen);
1280 /* post it to netcp tx channel*/
1281 meta2.u.tx_meta=&meta_tx2;
1282 pktio_send(netcp_tx_chan,tip,&meta2,&err);
1283 stats.tx +=1;
1284 }
1285 }
1290 /***************************************
1291 benchmark receive handler
1292 ****************************************/
1293 void recv_cb_bench(struct PKTIO_HANDLE_Tag * channel, Ti_Pkt* p_recv[],
1294 PKTIO_METADATA_T meta[], int n_pkts,
1295 uint64_t ts )
1296 {
1297 int i;
1298 vv6= netapi_timing_stop();
1299 for (i=0;i<n_pkts; i++)
1300 {
1301 Pktlib_freePacket(p_recv[i]);
1302 }
1303 vv11 = netapi_timing_stop();
1304 }
1306 /****************************************************************************************/
1307 /******************SB Accelerator Callback PKT RECEIVE HANDLER *************************/
1308 /****************** Handles Decrypt and Encrypt operation callbacks ******************/
1309 /******************************************************************************************/
1310 void recv_sb_cb(struct PKTIO_HANDLE_Tag * channel, Ti_Pkt* p_recv[],
1311 PKTIO_METADATA_T meta[], int n_pkts,
1312 uint64_t ts )
1313 {
1314 int i;
1315 int len;
1316 int p;
1317 HEAD_T * p_res;
1318 Ti_Pkt * tip;
1319 unsigned int templen;
1320 int err;
1321 KEY_T key;
1322 char * p_pkt;
1323 HEAD_T * p_head;
1324 HEAD_T temp_head;
1325 int tag_cmp=0;
1326 unsigned int hash[4];
1327 uint8_t *p_spi;
1328 netTestSA_t *p_sa_info;
1330 //nwal_AppId time;
1331 unsigned long time, delta_time;
1332 /* loop over received pkts */
1333 for(i=0;i<n_pkts;i++)
1334 {
1335 tip = p_recv[i];
1336 Pktlib_getDataBuffer(tip,(uint8_t**)&p_pkt,&templen);//ignore templen
1337 len = Pktlib_getPacketLen(tip);//real length
1340 p_spi = &(p_pkt[netTest_MAC_HEADER_LEN+netTest_IP_HEADER_LEN]);
1341 p_sa_info = (netTestSA_t *) trie_lookup(p_trie_sa, (char *)p_spi ,4);
1342 if (p_sa_info == NULL)
1343 {
1344 printf("recv_sb_cb(): trie_lookup failed\n");
1345 continue;
1346 }
1349 //is this a decrypt (rx_tunnel) complete
1350 if ((int)meta[i].u.rx_sb_meta->appId == p_sa_info->rx_tunnel)
1351 {
1353 time = netapi_timing_start();
1354 delta_time = time -(unsigned long) meta[i].u.rx_sb_meta->appCtxId;
1355 stats.total_decrypt_time += delta_time;
1356 stats.sb_rx+=1;
1357 //copy hash out of meta data (for some reason it needs endian conversion)
1358 hash[0]= htonl( meta[i].u.rx_sb_meta->pAuthTag[0]);
1359 hash[1]= htonl( meta[i].u.rx_sb_meta->pAuthTag[1]);
1360 hash[2]= htonl( meta[i].u.rx_sb_meta->pAuthTag[2]);
1361 hash[3]= htonl( meta[i].u.rx_sb_meta->pAuthTag[3]);
1362 if(stats.sb_rx<=16)
1363 {
1364 char *tp = (char *) &hash[0];
1365 //dump_header((long*)p_pkt, stats.sb_rx, (int)meta[i].u.rx_sb_meta->appId,0);
1366 #if 0
1367 printf("decrypt complete: tag in pkt= %x %x %x %x %x %x %x %x %x %x %x %x %x %x %x %x \n",
1368 p_pkt[len-16],p_pkt[len-15],p_pkt[len-14],p_pkt[len-13],
1369 p_pkt[len-12],p_pkt[len-11],p_pkt[len-10],p_pkt[len-9], p_pkt[len-8],
1370 p_pkt[len-7],p_pkt[len-6],
1371 p_pkt[len-5],p_pkt[len-4],p_pkt[len-3],p_pkt[len-2],p_pkt[len-1]);
1372 printf("decrypt complete: tag from SA=%x %x %x %x %x %x %x %x %x %x %x %x %x %x %x %x \n",
1373 tp[0],tp[1],tp[2],tp[3],tp[4],tp[5],
1374 tp[6],tp[7],tp[8],tp[9],tp[10],tp[11],tp[12],tp[13],tp[14],tp[15]);
1375 #endif
1376 }
1377 //check tag
1378 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
1379 stats.n_auth_ok += !(tag_cmp);
1381 flip_and_send_pkt(tip, p_pkt, len,1); //flip packet to echo back and send
1382 }
1383 //this is an encrypt (tx tunnel) complete
1384 else if((int)meta[i].u.rx_sb_meta->appId== p_sa_info->tx_tunnel )
1385 {
1386 hash[0]= htonl( meta[i].u.rx_sb_meta->pAuthTag[0]);
1387 hash[1]= htonl( meta[i].u.rx_sb_meta->pAuthTag[1]);
1388 hash[2]= htonl( meta[i].u.rx_sb_meta->pAuthTag[2]);
1389 hash[3]= htonl( meta[i].u.rx_sb_meta->pAuthTag[3]);
1390 stats.sb_tx+=1;
1391 if(stats.sb_tx<=16)
1392 {
1393 char *tp1 = (char *) &hash[0];
1394 //dump_header((long*)p_pkt, stats.sb_tx, (int)meta[i].u.rx_sb_meta->appId,0);
1395 #if 0
1396 printf("encrypt complete: tag in pkt= %x %x %x %x %x %x %x %x %x %x %x %x %x %x %x %x \n",
1397 p_pkt[len-16],p_pkt[len-15],p_pkt[len-14],p_pkt[len-13],
1398 p_pkt[len-12],p_pkt[len-11],p_pkt[len-10],p_pkt[len-9], p_pkt[len-8],
1399 p_pkt[len-7],p_pkt[len-6],
1400 p_pkt[len-5],p_pkt[len-4],p_pkt[len-3],p_pkt[len-2],p_pkt[len-1]);
1401 printf("encrypt complete: tag from SA=%x %x %x %x %x %x %x %x %x %x %x %x %x %x %x %x \n",
1402 tp1[0],tp1[1],tp1[2],tp1[3],tp1[4],tp1[5],
1403 tp1[6],tp1[7],tp1[8],tp1[9],tp1[10],tp1[11],tp1[12],tp1[13],tp1[14],tp1[15]);
1404 #endif
1405 }
1406 //put the computed tag in the packet
1407 memcpy(&p_pkt[len-p_sa_info->auth_tag_size],(char*)&hash[0],p_sa_info->auth_tag_size); //todo, really use meta->authTagLen
1408 {
1409 PKTIO_METADATA_T meta2 = {PKTIO_META_TX,{0},0};
1410 nwalTxPktInfo_t meta_tx={0};
1411 // now send directly
1412 meta2.sa_handle=nwal_HANDLE_INVALID;
1413 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
1414 meta_tx.startOffset = 0;
1415 meta_tx.ipOffBytes = netTest_MAC_HEADER_LEN;
1416 //not used
1417 meta_tx.l4OffBytes = 0;
1418 meta_tx.l4HdrLen = 0;
1419 meta_tx.ploadLen = 0;
1420 time = netapi_timing_start();
1421 delta_time = time -(unsigned long) meta[i].u.rx_sb_meta->appCtxId;
1422 stats.total_encrypt_time += delta_time;
1425 /* post it to netcp tx channel*/
1426 meta2.u.tx_meta=&meta_tx;
1427 pktio_send(netcp_tx_chan,tip,&meta2,&err);
1428 netapi_utilCacheWbInv(p_pkt,len);
1429 stats.tx +=1;
1430 }
1431 }
1432 else printf("netapi recv_sb_cb: unknown appiD %x \n",meta[i].u.rx_sb_meta->appId );
1433 }
1434 }
1436 /******************************************************/
1437 /******************PKT RECEIVE HANDLER *************************/
1438 /******************************************************/
1439 void recv_cb(struct PKTIO_HANDLE_Tag * channel, Ti_Pkt* p_recv[],
1440 PKTIO_METADATA_T meta[], int n_pkts,
1441 uint64_t ts )
1442 {
1443 int i;
1444 int len;
1445 int p;
1446 HEAD_T * p_res;
1447 Ti_Pkt * tip;
1448 unsigned int templen;
1449 int err;
1450 KEY_T key;
1451 char * p_pkt;
1452 HEAD_T * p_head;
1453 HEAD_T temp_head;
1454 netTestSA_t *p_sa_info;
1455 uint8_t *p_spi;
1456 uint8_t p_iv[16];
1457 uint8_t p_add[8];
1458 int16_t retVal;
1459 nwalGlobCxtInfo_t nwalGlobCxt;
1460 nwalLocCxtInfo_t nwalLocCxt;
1461 Cppi_HostDesc* pPloadDesc;
1463 p_head=&temp_head;
1465 //debug
1466 #if 0
1467 if (n_pkts != TX_BURST) {
1468 printf("recv_cb, txsofar=%d rxsofar=%d np = %d, NOT %d\n",
1469 stats.itx, stats.rx, n_pkts,TX_BURST);
1470 our_stats_cb(netapi_handle,NULL);
1471 }
1472 #endif
1473 //test_alloc_free(7);
1474 //printf("recv start\n");
1476 /* loop over received pkts */
1477 for(i=0;i<n_pkts;i++)
1478 {
1479 tip = p_recv[i];
1480 Pktlib_getDataBuffer(tip,(uint8_t**)&p_pkt,&templen);//ignore templen
1481 len = Pktlib_getPacketLen(tip)-4;//real length, subtract mac trailer
1482 Cppi_setData (Cppi_DescType_HOST, (Cppi_Desc *) tip, p_pkt,len);
1483 Pktlib_setPacketLen(tip,len);
1485 //debug: validate descriptor */
1486 if(Pktlib_getNextPacket(tip) != 0)
1487 {
1488 printf(" rcv_cb, nexpkt != NULL");
1489 }
1490 //debug printf("recv pkt, len=%d %d\n", len, templen);
1491 stats.rx+=1;
1493 #ifdef DEBUG_DESC
1494 if (stats.rx<16)
1495 {
1496 printf(">rx dmp..");
1497 dump_descr((long *) tip, stats.rx);
1498 }
1499 else if (stats.rx>99)
1500 {
1501 printf(">rx dmp..");
1502 dump_descr((long *) tip,stats.rx);
1503 }
1504 #endif
1505 #if 0
1506 if(stats.rx<=16)
1507 {
1508 dump_header((long*)p_pkt, stats.rx, (int)meta[i].u.rx_meta->appId,meta[i].u.rx_meta->rxFlag1);
1509 }
1510 #endif
1511 /* check header */
1512 memcpy(p_head,&p_pkt[14],sizeof(HEAD_T));
1514 if ((p_head->ip[2]&0x0000ff00)==0x00003200)
1515 {
1516 if (!check_header(p_head,&meta[i]))
1517 {
1518 stats.n_bad+=1;Pktlib_freePacket(tip);
1519 continue;
1520 }
1525 //process IP SEC PACKET
1526 if (config.ipsec_mode_rx == IPSEC_MODE_RX_SIDEBAND)
1527 {
1528 p_spi = &(p_pkt[netTest_MAC_HEADER_LEN+netTest_IP_HEADER_LEN]);
1529 p_sa_info = (netTestSA_t *) trie_lookup(p_trie_sa, (char *)p_spi ,4);
1530 if (p_sa_info == NULL)
1531 {
1532 printf("recv_cb(): trie_lookup() failed\n");
1533 continue;
1534 }
1536 //ship to crypto for decrypt!!
1537 //12 byte auth tag
1538 PKTIO_METADATA_T meta2 = {PKTIO_META_SB_TX,{0},0};
1539 nwalDmTxPayloadInfo_t meta_tx={0};
1540 meta2.sa_handle=p_sa_info->rx_data_mode_handle;
1542 memcpy(&meta_tx, &(p_sa_info->tx_payload_info), sizeof(nwalDmTxPayloadInfo_t));
1544 meta_tx.encSize = len - p_sa_info->tx_payload_info.encOffset -p_sa_info->auth_tag_size;
1545 meta_tx.authSize = len - meta_tx.authOffset - p_sa_info->auth_tag_size;
1547 #if 0
1548 printf("recv_cb(): encOffset %d\n", meta_tx.encOffset);
1549 printf("recv_cb():authOffset %d\n", meta_tx.authOffset);
1550 printf("recv_cb(): encSize %d\n", meta_tx.encSize);
1551 printf("recv_cb(): authSize %d\n", meta_tx.authSize);
1552 #endif
1554 if (p_sa_info->cipherMode == NWAL_SA_EALG_AES_CTR)
1555 {
1556 memcpy(&p_iv[0], &ourEncrKey[16], 4);
1557 memcpy(&p_iv[4], &p_pkt[netTest_MAC_HEADER_LEN +netTest_IP_HEADER_LEN + netTest_ESP_HEADER_LEN], 8);
1558 p_iv[12] = 0;
1559 p_iv[13] = 0;
1560 p_iv[14] = 0;
1561 p_iv[15] = 1;
1562 meta_tx.pEncIV = &p_iv[0];
1563 }
1564 else if ((p_sa_info->cipherMode == NWAL_SA_EALG_AES_GCM) ||
1565 (p_sa_info->cipherMode == NWAL_SA_EALG_AES_CCM))
1566 {
1567 memcpy(&p_iv[0], &p_pkt[netTest_MAC_HEADER_LEN +netTest_IP_HEADER_LEN + netTest_ESP_HEADER_LEN], 8);
1568 meta_tx.pEncIV = &p_iv[0];
1569 /* aad is the ESP header which is 8 bytes */
1570 memcpy(&p_add[0], &p_pkt[netTest_MAC_HEADER_LEN +netTest_IP_HEADER_LEN], 8);
1571 meta_tx.pAad= &p_add[0];
1572 meta_tx.aadSize = 8;
1573 }
1574 else if (p_sa_info->cipherMode == NWAL_SA_EALG_NULL)
1575 {
1576 meta_tx.pEncIV = NULL;
1577 }
1578 else
1579 {
1580 meta_tx.pEncIV = &p_pkt[netTest_MAC_HEADER_LEN +netTest_IP_HEADER_LEN + netTest_ESP_HEADER_LEN ];
1581 }
1582 meta_tx.appCtxId = (nwal_AppId)netapi_timing_start();
1583 //printf("recv_cb appCtxId: %lu\n", meta_tx.appCtxId);
1585 /* post it to netcp sb tx channel*/
1586 meta2.u.tx_sb_meta=&meta_tx;
1587 #ifdef NET_TEST_ENABLE_SIDE_BAND_LOW_LEVEL_API
1588 /* Use the command label which was cached during create time
1589 * Update the Queue to receive output packet from SA to the local
1590 * core Queue. Below information can be saved by application in
1591 * per process context to avoid API overhead per packet
1592 * Application can use below rxSbSaQ for polling packets back from
1593 * SA
1594 */
1595 nwalRetVal =
1596 nwal_getLocCxtInfo(PKTIO_GET_NWAL_INSTANCE(netcp_sb_tx_chan),
1597 &nwalLocCxt);
1598 if(nwalRetVal == nwal_OK)
1599 {
1600 p_sa_info->rx_dmPSCmdInfo.rxSbSaQ = nwalLocCxt.rxSbSaQ;
1601 }
1602 nwal_mCmdDMUpdate(tip,
1603 &p_sa_info->rx_dmPSCmdInfo,
1604 meta_tx.appCtxId,
1605 meta_tx.encOffset,
1606 meta_tx.encSize,
1607 meta_tx.pEncIV,
1608 meta_tx.authOffset,
1609 meta_tx.authSize,
1610 meta_tx.pAuthIV,
1611 meta_tx.aadSize,
1612 meta_tx.pAad);
1613 pPloadDesc = Pktlib_getDescFromPacket(tip);
1614 pPloadDesc = Qmss_osalConvertDescVirtToPhy(pPloadDesc);
1615 Qmss_queuePushDescSizeRaw(p_sa_info->rx_dmPSCmdInfo.txQueue,
1616 pPloadDesc,
1617 NWAL_DESC_SIZE);
1619 #else
1620 pktio_send(netcp_sb_tx_chan,tip,&meta2,&err);
1621 #endif
1622 continue;
1623 }
1624 else
1625 //inflow mode. flip and send
1626 flip_and_send_pkt(tip,p_pkt,len,1);
1627 }
1628 else if ((p_head->ip[2]&0x0000ff00)!=0x00001100)
1629 {
1630 stats.n_new+=1;Pktlib_freePacket(tip); continue;
1631 }
1632 else //non ipsec
1633 {
1634 if (!check_header(p_head,&meta[i])) {
1635 stats.n_bad+=1;Pktlib_freePacket(tip);
1636 continue;
1637 }
1639 #if 0
1640 /* lookup flow */
1641 key.src_ip = p_head->ip[3];
1642 key.dst_ip = p_head->ip[4];
1643 key.src_port= (p_head->udp[0]&0xffff0000)>>16;
1644 key.dst_port= (p_head->udp[0]&0x0000ffff);
1645 p_res= (HEAD_T *) trie_lookup(P_trie, (char *) &key, sizeof(key));
1646 if (!p_res) { stats.n_new+=1; slow_path(tip, len); continue;}
1648 /* copy header */
1649 memcpy((char *) p_head, (char *) p_res, sizeof(HEAD_T));
1651 memcpy(&p_pkt[14],p_head,sizeof(HEAD_T));
1652 /* update_mac(&p_pkt[0]); */
1654 /* 'simulate' send pkt */
1655 send_pkt(tip,len);
1656 #endif
1657 //just flip and send
1658 flip_and_send_pkt(tip,p_pkt,len,0);
1659 }
1660 }
1661 //printf("recv done\n");
1662 }
1664 #ifdef TEST_TIMERS
1665 //timer callback
1666 void our_timer_cb( NETAPI_TIMER_GROUP_HANDLE_T th,
1667 int n_fired, //# timers fired
1668 NETAPI_TIMER_LIST_T fired_list,
1669 uint64_t currentTime)
1670 {
1671 int i;
1672 NETAPI_TIMER_T tx;
1673 int cookie;
1674 int err;
1675 unsigned long long et;
1676 //DEBUGprintf("TIMER CALLBACK @ %lld %d timers\n", currentTime, n_fired);
1677 tx = netapi_TimerGetFirst(fired_list);
1678 for(i=0;i<n_fired;i++)
1679 {
1680 cookie = (int) netapi_TimerGetCookie(tx);
1681 et = netapi_TimerGetTs(tx); //debug
1682 //DEBUGprintf(" timer %d - cookie = %d expected ts=%lld (delta=%lld)\n", i, cookie, et, currentTime-et);
1683 if (cookie ==1)
1684 {
1685 stats.n_t1+=1;
1686 t1 = netapi_TimerGroupStartTimer(
1687 th,
1688 (void *) 1,
1689 100LL, //timer group tics
1690 &err);
1691 }
1692 else if (cookie ==2)
1693 {
1694 stats.n_t2+=1;
1695 t2 = netapi_TimerGroupStartTimer(
1696 th,
1697 (void *) 2,
1698 200LL, //timer group ticks
1699 &err);
1700 }
1701 else
1702 {
1703 stats.n_t3+=1;
1704 t3 = netapi_TimerGroupStartTimer(
1705 th,
1706 (void *) 3,
1707 300LL, //timer group ticks
1708 &err);
1709 //cancel 1 and restart 1
1710 netapi_TimerGroupCancel(th,t1,&err);
1711 t1 = netapi_TimerGroupStartTimer(
1712 th,
1713 (void *) 1,
1714 100LL, //timer group ticks
1715 &err);
1716 }
1717 tx = netapi_TimerGetNext(fired_list,tx);
1718 }
1719 }
1720 #endif
1721 void print_ipsec_stats(Sa_IpsecStats_t *p_saIpsecStats, nwal_saAALG auth, nwal_saEALG cipher)
1722 {
1723 #if 0
1724 if(retVal != nwal_OK)
1725 {
1726 System_printf("CORE: %d Error getting IP Sec Stats: Ret Status: %d \n",
1727 retVal);
1728 return(nwal_FALSE);
1729 }
1730 if((p_saIpsecStats->pktEncHi) ||(p_saIpsecStats->pktEncLo))
1731 {
1732 printf("------------- IPSec TX (Encryption Channel) Stats BEGIN --\n");
1733 }
1734 else
1735 {
1736 printf("------------- IPSec RX (Decryption Channel) Stats BEGIN --\n");
1737 }
1738 #endif
1739 printf("\nAutentication mode: %d, Encryption Mode: %d\n", auth, cipher);
1740 printf("IPSec replayOld:0x%x,replayDup:0x%x,authFail:0x%x \n",
1741 p_saIpsecStats->replayOld,p_saIpsecStats->replayDup,p_saIpsecStats->authFail);
1742 printf("IPSec txESN:0x%x,rxESN:0x%x,pktEncHi:0x%x,pktEncLo:0x%x,pktDecHi:0x%x,pktDecLo:0x%x \n",
1743 p_saIpsecStats->txESN,p_saIpsecStats->rxESN,p_saIpsecStats->pktEncHi,
1744 p_saIpsecStats->pktEncLo,p_saIpsecStats->pktDecHi,p_saIpsecStats->pktDecLo);
1745 }
1747 void print_datamode_stats(Sa_DataModeStats_t *p_saDataModeStats, nwal_saAALG auth, nwal_saEALG cipher)
1748 {
1750 printf("\nAutentication mode: %d, Encryption Mode: %d\n", auth, cipher);
1751 printf(" Packets processedHi: 0x%x, Packets processed Lo:0x%x\n",
1752 p_saDataModeStats->pktHi, p_saDataModeStats->pktLo);
1753 }
1758 static int np2process = NP;
1759 /******************************************************
1760 * stats callback
1761 *******************************************************/
1762 void our_stats_cb(NETAPI_T h, paSysStats_t* pPaStats)
1763 {
1764 uint32_t numFreeDataPackets;
1765 uint32_t numZeroBufferPackets;
1766 uint32_t numPacketsinGarbage;
1767 Pktlib_HeapStats pktLibHeapStats;
1768 int i;
1769 unsigned long long bcpp;
1770 unsigned long long bcpp_noc;
1771 unsigned long long bcpp_app;
1772 unsigned long long bcpp_tx;
1773 unsigned long long npL;
1774 unsigned long long cyclesL;
1775 unsigned long long ccyclesL; //cache cycles
1776 NETAPI_SA_STATS_T netapi_sa_stats;
1778 printf(">*****stats @ %lld\n", netapi_getTimestamp());
1779 //printf("netcp_tx_handle check %x\n", netcp_tx_chan->back);
1780 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",
1781 stats.itx, stats.rx, stats.tx, stats.n_bad, stats.n_new,
1782 stats.n_class0_rx, stats.n_class1_rx,
1783 stats.n_class2_rx, stats.sec_rx, stats.secp_rx, stats.sb_rx, stats.sb_tx, stats.n_auth_ok,
1784 stats.sec_tx);
1786 if (stats.rx && stats.tx)
1787 printf("decrypt time per packet(avg): %lu, encrypt time per packet(avg): %lu\n",
1788 (unsigned long) stats.total_decrypt_time/stats.rx, (unsigned long) stats.total_encrypt_time/stats.tx);
1789 netapi_sched_get_stats(&npL,&cyclesL,&ccyclesL);
1790 if (npL && stats.rx) {
1791 bcpp = cyclesL/npL;
1792 bcpp_noc = (cyclesL-ccyclesL)/npL;
1793 bcpp_app = (stats.app_cycles-stats.tx_cache_cycles)/stats.rx;
1794 }
1795 else {bcpp = bcpp_noc=bcpp_app=0L;}
1796 if (stats.tx)
1797 {
1798 bcpp_tx = (stats.send_cycles-stats.tx_cache_cycles)/stats.tx;
1799 }else {bcpp_tx = 0L;}
1800 printf("> ++ busy cycles pp=%lld (%lld wo cache ops) (app+tx= %lld) (tx= %lld) ++\n",
1801 bcpp,bcpp_noc,bcpp_app, bcpp_tx);
1802 if(pPaStats)
1803 {
1804 printf("C1 number of packets: %d\n", pPaStats->classify1.nPackets);
1805 printf("C1 number IPv4 packets: %d\n", pPaStats->classify1.nIpv4Packets);
1806 printf("C1 number IPv6 packets: %d\n", pPaStats->classify1.nIpv6Packets);
1807 printf("C1 number Custom packets: %d\n", pPaStats->classify1.nCustomPackets);
1808 printf("C1 number SRIO packets: %d\n", pPaStats->classify1.nSrioPackets);
1809 printf("C1 number LLC/SNAP Fail packets: %d\n", pPaStats->classify1.nLlcSnapFail);
1810 printf("C1 number table matched: %d\n", pPaStats->classify1.nTableMatch);
1811 printf("C1 number failed table matched: %d\n", pPaStats->classify1.nNoTableMatch);
1812 printf("C1 number IP Fragmented packets: %d\n", pPaStats->classify1.nIpFrag);
1813 printf("C1 number IP Depth Overflow: %d\n", pPaStats->classify1.nIpDepthOverflow);
1814 printf("C1 number VLAN Depth Overflow: %d\n", pPaStats->classify1.nVlanDepthOverflow);
1815 printf("C1 number GRE Depth Overflow: %d\n", pPaStats->classify1.nGreDepthOverflow);
1816 printf("C1 number MPLS Packets: %d\n", pPaStats->classify1.nMplsPackets);
1817 printf ("C1 number of parse fail: %d\n",pPaStats->classify1.nParseFail);
1818 printf("C1 number of Invalid IPv6 Opt: %d\n", pPaStats->classify1.nInvalidIPv6Opt);
1819 printf("C1 number of TX IP Fragments: %d\n", pPaStats->classify1.nTxIpFrag);
1820 printf ("C1 number of silent discard: %d\n",pPaStats->classify1.nSilentDiscard);
1821 printf("C1 number of invalid control: %d\n", pPaStats->classify1.nInvalidControl);
1822 printf ("C1 number of invalid states: %d\n",pPaStats->classify1.nInvalidState);
1823 printf ("C1 number of system fails: %d\n",pPaStats->classify1.nSystemFail);
1824 printf ("C2 number Packets : %d\n",pPaStats->classify2.nPackets);
1825 printf ("C2 number udp : %d\n",pPaStats->classify2.nUdp);
1826 printf ("C2 number tcp : %d\n",pPaStats->classify2.nTcp);
1827 printf ("C2 number Custom : %d\n",pPaStats->classify2.nCustom);
1828 printf ("C2 number silent drop : %d\n",pPaStats->classify2.nSilentDiscard);
1829 printf ("C2 number invalid cntrl : %d\n\n",pPaStats->classify2.nInvalidControl);
1830 printf ("C2 number Modify Stats Cmd Fail : %d\n\n",pPaStats->modify.nCommandFail);
1831 }
1832 Pktlib_getHeapStats(OurHeap, &pktLibHeapStats);
1833 printf("main heap stats> #free=%d #zb=%d #garbage=%d\n", pktLibHeapStats.numFreeDataPackets,
1834 pktLibHeapStats.numZeroBufferPackets, pktLibHeapStats.numPacketsinGarbage);
1835 printf(" > #dataBufThreshStatus=%d #dataBufStarvCounter=%d #zBufThreshStatus=%d #zBufStarvCounter=%d \n",
1836 pktLibHeapStats.dataBufferThresholdStatus,pktLibHeapStats.dataBufferStarvationCounter,
1837 pktLibHeapStats.zeroDataBufferThresholdStatus, pktLibHeapStats.zeroDataBufferStarvationCounter);
1839 Pktlib_getHeapStats(specialSmall, &pktLibHeapStats);
1840 printf("specialSmall heap stats> #free=%d #zb=%d #garbage=%d\n", pktLibHeapStats.numFreeDataPackets,
1841 pktLibHeapStats.numZeroBufferPackets, pktLibHeapStats.numPacketsinGarbage);
1842 printf(" > #dataBufThreshStatus=%d #dataBufStarvCounter=%d #zBufThreshStatus=%d #zBufStarvCounter=%d \n",
1843 pktLibHeapStats.dataBufferThresholdStatus,pktLibHeapStats.dataBufferStarvationCounter,
1844 pktLibHeapStats.zeroDataBufferThresholdStatus, pktLibHeapStats.zeroDataBufferStarvationCounter);
1847 Pktlib_getHeapStats(specialLarge, &pktLibHeapStats);
1848 printf("specialLarge heap stats> #free=%d #zb=%d #garbage=%d\n", pktLibHeapStats.numFreeDataPackets,
1849 pktLibHeapStats.numZeroBufferPackets, pktLibHeapStats.numPacketsinGarbage);
1850 printf(" > #dataBufThreshStatus=%d #dataBufStarvCounter=%d #zBufThreshStatus=%d #zBufStarvCounter=%d \n",
1851 pktLibHeapStats.dataBufferThresholdStatus,pktLibHeapStats.dataBufferStarvationCounter,
1852 pktLibHeapStats.zeroDataBufferThresholdStatus, pktLibHeapStats.zeroDataBufferStarvationCounter);
1855 #if 0
1856 printf("pa2sa descriptor area dump\n");
1857 for(i=0;i<TUNE_NETAPI_CONFIG_MAX_PA_TO_SA_DESC;i++)
1858 {
1859 extern long * pa2sa_descr_base;
1860 long * tip= &pa2sa_descr_base[32*i];
1861 dump_descr(tip, i);
1862 }
1863 printf("sa2pa descriptor area dump\n");
1864 for(i=0;i<TUNE_NETAPI_CONFIG_MAX_SA_TO_PA_DESC;i++)
1865 {
1866 extern long * sa2pa_descr_base;
1867 long * tip= &sa2pa_descr_base[32*i];
1868 dump_descr(tip, i);
1869 }
1870 #endif
1871 #ifdef TEST_TIMERS
1872 //debug = dump timer polling stats
1873 dump_poll_stats();
1874 //debug = dump timer polling stats
1875 //dump_poll_stats();
1876 #endif
1877 #ifndef EXPERIMENTAL
1878 for (i = 0; i < MAX_SEC_INDEX; i++)
1879 #else
1880 for (i=0; i < 1;i++)
1881 #endif
1882 {
1883 /* Statistics for RX Tunnel */
1884 memset(&netapi_sa_stats, 0, sizeof(netapi_sa_stats));
1885 netapi_getSaStats(netapi_handle, sa_info[i].rx_tunnel, &netapi_sa_stats);
1886 if (netapi_sa_stats.validParams & NETAPI_IPSEC_STAT_VALID)
1887 {
1888 print_ipsec_stats(&(netapi_sa_stats.saIpsecStats),
1889 rx_sa[i].authMode,
1890 rx_sa[i].cipherMode);
1891 }
1892 if (netapi_sa_stats.validParams & NETAPI_SIDEBAND_DATA_MODE_STAT_VALID)
1893 {
1894 print_datamode_stats(&(netapi_sa_stats.dataModeStats),
1895 rx_sa[i].authMode,
1896 rx_sa[i].cipherMode);
1897 }
1899 /* Statistics for TX Tunnel */
1900 memset(&netapi_sa_stats, 0, sizeof(netapi_sa_stats));
1901 netapi_getSaStats(netapi_handle, sa_info[i].tx_tunnel, &netapi_sa_stats);
1902 if (netapi_sa_stats.validParams & NETAPI_IPSEC_STAT_VALID)
1903 {
1904 print_ipsec_stats(&(netapi_sa_stats.saIpsecStats),
1905 tx_sa[i].authMode,
1906 tx_sa[i].cipherMode);
1907 }
1908 if (netapi_sa_stats.validParams & NETAPI_SIDEBAND_DATA_MODE_STAT_VALID)
1909 {
1910 print_datamode_stats(&(netapi_sa_stats.dataModeStats),
1911 tx_sa[i].authMode,
1912 tx_sa[i].cipherMode);
1913 }
1914 }
1915 netapi_dump_internal_heap_stats();
1916 }
1918 //******************************************************
1919 //use scheduling housekeeping callback to generate pkts
1920 //******************************************************
1921 static int done_burst=0;
1922 void house(NETAPI_SCHED_HANDLE_T * s)
1923 {
1924 Ti_Pkt * tip;
1925 unsigned int len;
1926 nwalTxPktInfo_t meta_tx = {0};
1927 PKTIO_METADATA_T meta = {PKTIO_META_TX,{0},0};
1928 int err;
1929 static int house_pkts_gened=0;
1930 int p;
1931 unsigned char * pIpHdr,* pData;
1932 unsigned int vv1,vv2,vv3;
1933 unsigned int sum_vv1=0;
1934 unsigned int sum_vv2=0;
1935 unsigned int sum_vv3=0;
1936 unsigned int sum_vv4=0;
1937 unsigned int sum_vv5=0;
1939 unsigned int nwal_flow_vv1,nwal_flow_vv2;
1940 unsigned int nwal_sum_vv1=0;
1941 unsigned int nwal_sum_vv2=0;
1942 unsigned int nwal_sum_vv3=0;
1943 unsigned int nwal_sum_vv4=0;
1944 unsigned int nwal_sum_vv5=0;
1945 unsigned int nwal_sum_vv6=0;
1947 unsigned int nwal_sum_flow_vv1=0;
1948 unsigned int nwal_sum_flow_vv2=0;
1949 unsigned int cache_op_b1;
1950 unsigned int cache_op_b2;
1951 int n_c_ops;
1952 static int first =0;
1953 Cppi_HostDesc* pPktDesc;
1955 if(done_burst)
1956 {
1957 house_pkts_gened+=TX_BURST;
1958 printf("net_test> request stats at n=%d \n",house_pkts_gened);
1959 netcp_cfgReqStats(netapi_handle, our_stats_cb, 0,&err);
1960 if (err!=0) {printf("stats req failed\n");}
1961 if (house_pkts_gened >= np2process+ 100)
1962 {
1963 netapi_schedShutdown(s,NULL,&err);
1964 }
1965 return;
1966 }
1967 done_burst=1;
1968 Osal_cache_op_measure_reset();
1969 memset(&meta_tx,0,sizeof(meta_tx));
1970 for(p=0;p<TX_BURST;p++) {
1971 //reguest stats
1972 if ((house_pkts_gened>0) && (! (house_pkts_gened%1000)) )
1973 {
1974 printf("net_test> request stats at n=%d \n",house_pkts_gened);
1975 netcp_cfgReqStats(netapi_handle, our_stats_cb, 0,&err);
1976 if (err!=0) {printf("stats req failed\n");}
1977 }
1980 if (house_pkts_gened >= np2process+ 100)
1981 {
1982 //shutdown
1983 netapi_schedShutdown(s,NULL,&err);
1984 continue;
1985 }
1987 else if (house_pkts_gened >= np2process) { house_pkts_gened+=1; continue;}
1990 /* manufacture a pkt to transmit */
1991 tip = get_pkt(house_pkts_gened, &len, OurHeap, PKT_LEN,&testPkt[0] , TEST_PKT_LEN);
1992 if(!tip) { house_pkts_gened +=1; continue; }
1995 /* set the pkt length */
1996 vv1 = netapi_timing_start();
1997 Pktlib_setPacketLen(tip, len);
1999 /* set up meta data */
2000 meta.sa_handle=nwal_HANDLE_INVALID;
2001 //#define BENCH_UDP_SEND
2002 #ifdef BEND_UDP_SEND
2003 meta_tx.txFlag1 = (NWAL_TX_FLAG1_DO_IPV4_CHKSUM | NWAL_TX_FLAG1_DO_UDP_CHKSUM| NWAL_TX_FLAG1_META_DATA_VALID);
2004 meta_tx.startOffset = 0;
2005 //GONE in V2 meta_tx.pktLen = len;
2006 meta_tx.ipOffBytes = TEST_PKT_IP_OFFSET_BYTES;
2007 meta_tx.l4OffBytes = TEST_PKT_UDP_OFFSET_BYTES;
2008 meta_tx.l4HdrLen = TEST_PKT_UDP_HDR_LEN;
2009 //GONE in V2 meta_tx.ploadOffBytes = TEST_PKT_PLOAD_OFFSET_BYTES;
2010 meta_tx.ploadLen = TEST_PAYLOAD_LEN;
2012 Pktlib_getDataBuffer(tip,&pData,&len);
2013 if(house_pkts_gened &0x1)
2014 {
2015 memcpy(&pData[6],&config.mac1[0] ,6);
2016 }
2017 pIpHdr = pData + meta_tx.ipOffBytes;
2018 meta_tx.pseudoHdrChecksum =
2019 test_utilGetIpv4PsudoChkSum(pIpHdr,(TEST_PAYLOAD_LEN+TEST_PKT_UDP_HDR_LEN));
2020 #else
2021 Pktlib_getDataBuffer(tip,&pData,&len);
2022 if(house_pkts_gened &0x1)
2023 {
2024 memcpy(&pData[6],&config.mac1[0] ,6);
2025 }
2026 meta_tx.txFlag1 = NWAL_TX_FLAG1_META_DATA_VALID;
2027 meta_tx.startOffset = 0;
2028 meta_tx.ploadLen = TEST_PAYLOAD_LEN;
2029 #endif
2030 /* post it to netcp tx channel*/
2031 meta.u.tx_meta=&meta_tx;
2032 #ifdef DEBUG_DESC
2033 if (house_pkts_gened<16) dump_descr((long *) tip, house_pkts_gened);
2034 else if (house_pkts_gened>99) dump_descr((long *) tip,house_pkts_gened);
2035 #endif
2037 if(!first)
2038 {
2039 first++;
2040 nwal_flow_vv1= netapi_timing_stop();
2041 if(nwal_initPSCmdInfo(PKTIO_GET_NWAL_INSTANCE(netcp_tx_chan),
2042 &meta_tx,
2043 &flowPSCmdInfo) != nwal_OK)
2044 {
2045 printf("nwal_initPSCmdInfo() ERROR \n");
2046 }
2047 nwal_flow_vv2= netapi_timing_stop();
2048 nwal_sum_flow_vv1 += (nwal_flow_vv1-vv1);
2049 nwal_sum_flow_vv2 += (nwal_flow_vv2-nwal_flow_vv1);
2050 }
2052 cache_op_b1= Osal_cache_op_measure(&n_c_ops);
2053 vv2= netapi_timing_stop();
2054 #ifdef BEND_UDP_SEND
2055 nwal_mCmdSetL4CkSumPort( tip,
2056 &flowPSCmdInfo,
2057 TEST_PKT_UDP_OFFSET_BYTES,
2058 (TEST_PKT_UDP_HDR_LEN + TEST_PAYLOAD_LEN),
2059 meta_tx.pseudoHdrChecksum,
2060 meta_tx.enetPort);
2061 #else
2062 nwal_mCmdSetPort (tip,
2063 &flowPSCmdInfo, //could be NULL
2064 0); //port 0 -> switch decides
2066 #endif
2068 pPktDesc = Pktlib_getDescFromPacket(tip);
2069 /* Send the packet out to transmit Q*/
2070 Qmss_queuePushDescSize (flowPSCmdInfo.txQueue,
2071 pPktDesc,
2072 NWAL_DESC_SIZE);
2073 vv3= netapi_timing_stop();
2074 cache_op_b2= Osal_cache_op_measure(&n_c_ops);
2076 sum_vv1 += (vv2-vv1);
2077 if(!house_pkts_gened)
2078 {
2079 /* first packet. Take out the PS command label creation cost */
2080 sum_vv1 = sum_vv1 - nwal_sum_flow_vv2;
2081 }
2083 sum_vv3 += (vv3-vv2)-(cache_op_b2-cache_op_b1); //sub out cache op cost
2085 // printf("pktio send. full=%d metadata=%d pktio_send=%d\n", vv3-vv1, vv2-vv1, vv3-vv2);
2088 stats.itx +=1;
2089 house_pkts_gened +=1;
2090 }
2091 {
2092 unsigned int ccycles;
2093 ccycles =Osal_cache_op_measure(&n_c_ops);
2094 if (sum_vv1)
2095 {
2096 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",
2097 stats.itx, sum_vv1/stats.itx, nwal_sum_flow_vv2, sum_vv3/stats.itx,
2098 n_c_ops, ccycles, n_c_ops? (ccycles/(n_c_ops/2)) : 0);
2099 #if 0
2100 printf("NWAL Profile Cycles: Prof1= %d,Prof2=%d,Prof3=%d,Prof4=%d,Prof5=%d ,Prof6=%d \n",
2101 nwal_sum_vv1/stats.itx,nwal_sum_vv2/stats.itx,nwal_sum_vv3/stats.itx,
2102 nwal_sum_vv4/stats.itx,nwal_sum_vv5/stats.itx,nwal_sum_vv6/stats.itx);
2104 #endif
2106 if(stats.itx2)
2107 {
2108 printf("nwal_flowSend Profile Cycles: Prof1= %d,Prof2=%d \n",
2109 nwal_sum_flow_vv1/stats.itx2,nwal_sum_flow_vv2/stats.itx2);
2110 }
2112 }
2113 }
2114 }
2116 void build_sa_db(int i)
2117 {
2118 long tmp_spi;
2119 if ((tx_sa[i].authMode == NWAL_SA_AALG_HMAC_SHA1) && (tx_sa[i].cipherMode == NWAL_SA_EALG_AES_CBC))
2120 {
2121 /* static configuration, will not change */
2122 sa_info[i].tx_payload_info.aadSize = 0;
2123 sa_info[i].tx_payload_info.pAad = NULL;
2124 sa_info[i].tx_payload_info.pAuthIV = NULL;
2125 sa_info[i].tx_payload_info.authOffset = netTest_MAC_HEADER_LEN + netTest_IP_HEADER_LEN; /*done: same for all cipher suites */
2126 sa_info[i].tx_payload_info.encOffset = netTest_MAC_HEADER_LEN +
2127 netTest_IP_HEADER_LEN +
2128 netTest_ESP_HEADER_LEN +
2129 netTest_AES_CBC_IV_LEN;
2133 /* dynamic configuration, will be calculated on the fly */
2134 sa_info[i].tx_payload_info.authSize = 0; /* pkt len - mac - ip -icv (12) */
2135 sa_info[i].tx_payload_info.encSize = 0; /* authSize - esp header size (always 8 bytes) */
2136 sa_info[i].tx_payload_info.pEncIV = 0;
2137 sa_info[i].tx_payload_info.pPkt = 0; /* not being referenced in net_test */
2139 sa_info[i].cipherMode = NWAL_SA_EALG_AES_CBC;
2140 sa_info[i].inner_ip_offset = sa_info[i].tx_payload_info.encOffset;
2141 sa_info[i].auth_tag_size = netTest_ICV_LEN; /* icv or mac size,. always 12 except for AES_CCM/AES_GCM */
2142 #ifdef EXPERIMENTAL
2143 sa_info[i].iv_len=16;
2144 sa_info[i].bl=16;
2145 sa_info[i].spi = tx_sa[i].spi;
2146 sa_info[i].src =*((unsigned int *)(&config.local_ipsec_ip.ipv4[0]));
2147 sa_info[i].dst =*((unsigned int *)(&config.remote_ipsec_ip.ipv4[0]));
2148 #endif
2149 sa_info[i].tx_pkt_info.enetPort = 0;
2150 sa_info[i].tx_pkt_info.ipOffBytes = sa_info[i].tx_payload_info.encOffset;
2151 sa_info[i].tx_pkt_info.l4HdrLen = netTest_UDP_HEADER_LEN; /*UDP header len */
2152 sa_info[i].tx_pkt_info.l4OffBytes = sa_info[i].inner_ip_offset + netTest_IP_HEADER_LEN;
2153 sa_info[i].tx_pkt_info.startOffset = 0;
2154 sa_info[i].tx_pkt_info.lpbackPass = 0;
2155 sa_info[i].tx_pkt_info.ploadLen = 0; /*sa_info[i].tx_pkt_info.l4OffBytes + 4 */
2156 sa_info[i].tx_pkt_info.pPkt = NULL;
2157 sa_info[i].tx_pkt_info.saOffBytes = netTest_MAC_HEADER_LEN + netTest_IP_HEADER_LEN;
2158 sa_info[i].tx_pkt_info.saPayloadLen = 0;
2159 sa_info[i].tx_pkt_info.pseudoHdrChecksum =0;
2161 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 ;
2163 tmp_spi = htonl((long)(tx_sa[i].spi));
2164 trie_insert(p_trie_sa,(char *)&tmp_spi,4, (void *) &sa_info[i]); //asociate with tx sa SPI
2166 }
2167 else if ((tx_sa[i].authMode == NWAL_SA_AALG_HMAC_SHA2_256) && (tx_sa[i].cipherMode == NWAL_SA_EALG_AES_CTR))
2168 {
2169 printf("inside build_sa_db, index %d\n", i);
2170 /* static configuration, will not change */
2171 sa_info[i].tx_payload_info.aadSize = 0;
2172 sa_info[i].tx_payload_info.pAad = NULL;
2173 sa_info[i].tx_payload_info.pAuthIV = NULL;
2174 sa_info[i].tx_payload_info.authOffset = netTest_MAC_HEADER_LEN + netTest_IP_HEADER_LEN; /*done: same for all cipher suites */
2175 sa_info[i].tx_payload_info.encOffset = netTest_MAC_HEADER_LEN +
2176 netTest_IP_HEADER_LEN +
2177 netTest_ESP_HEADER_LEN +
2178 netTest_AES_CTR_IV_LEN;
2183 /* dynamic configuration, will be calculated on the fly */
2184 sa_info[i].tx_payload_info.authSize = 0;
2185 sa_info[i].tx_payload_info.encSize = 0;
2186 sa_info[i].tx_payload_info.pEncIV = 0;
2187 sa_info[i].tx_payload_info.pPkt = 0;
2189 sa_info[i].cipherMode = NWAL_SA_EALG_AES_CTR;
2190 sa_info[i].inner_ip_offset = sa_info[i].tx_payload_info.encOffset;
2191 sa_info[i].auth_tag_size = netTest_ICV_LEN; /* icv or mac size,. always 12 except for AES_CCM/AES_GCM */
2192 #ifdef EXPERIMENTAL
2193 sa_info[i].iv_len=8;
2194 sa_info[i].bl=8;
2195 sa_info[i].spi = tx_sa[i].spi;
2196 sa_info[i].src =*((unsigned int *)(&config.local_ipsec_ip.ipv4[0]));
2197 sa_info[i].dst =*((unsigned int *)(&config.remote_ipsec_ip.ipv4[0]));
2198 #endif
2200 sa_info[i].tx_pkt_info.enetPort = 0;
2201 sa_info[i].tx_pkt_info.ipOffBytes = sa_info[i].tx_payload_info.encOffset;
2202 sa_info[i].tx_pkt_info.l4HdrLen = netTest_UDP_HEADER_LEN; /*UDP header len */
2203 sa_info[i].tx_pkt_info.l4OffBytes = sa_info[i].inner_ip_offset + netTest_IP_HEADER_LEN;
2204 sa_info[i].tx_pkt_info.startOffset = 0;
2205 sa_info[i].tx_pkt_info.lpbackPass = 0;
2206 sa_info[i].tx_pkt_info.ploadLen = 0; /*sa_info[i].tx_pkt_info.l4OffBytes + 4 */
2207 sa_info[i].tx_pkt_info.pPkt = NULL;
2208 sa_info[i].tx_pkt_info.saOffBytes = netTest_MAC_HEADER_LEN + netTest_IP_HEADER_LEN;
2209 sa_info[i].tx_pkt_info.saPayloadLen = 0;
2210 sa_info[i].tx_pkt_info.pseudoHdrChecksum =0;
2212 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 ;
2214 tmp_spi = htonl((long)(tx_sa[i].spi));
2215 trie_insert(p_trie_sa,(char *)&tmp_spi,4, (void *) &sa_info[i]); //asociate with tx sa SPI
2216 }
2217 else if ((tx_sa[i].authMode == NWAL_SA_AALG_HMAC_SHA2_256) && (tx_sa[i].cipherMode == NWAL_SA_EALG_3DES_CBC))
2218 {
2219 /* static configuration, will not change */
2220 sa_info[i].tx_payload_info.aadSize = 0;
2221 sa_info[i].tx_payload_info.pAad = NULL;
2222 sa_info[i].tx_payload_info.pAuthIV = NULL;
2223 sa_info[i].tx_payload_info.authOffset = netTest_MAC_HEADER_LEN + netTest_IP_HEADER_LEN; /*done: same for all cipher suites */
2224 sa_info[i].tx_payload_info.encOffset = netTest_MAC_HEADER_LEN +
2225 netTest_IP_HEADER_LEN +
2226 netTest_ESP_HEADER_LEN +
2227 netTest_3DES_CBC_IV_LEN;
2229 /* dynamic configuration, will be calculated on the fly */
2230 sa_info[i].tx_payload_info.authSize = 0;
2231 sa_info[i].tx_payload_info.encSize = 0;
2232 sa_info[i].tx_payload_info.pEncIV = 0;
2233 sa_info[i].tx_payload_info.pPkt = 0;
2235 sa_info[i].cipherMode = NWAL_SA_EALG_3DES_CBC;
2236 sa_info[i].inner_ip_offset = sa_info[i].tx_payload_info.encOffset;
2237 sa_info[i].auth_tag_size = netTest_ICV_LEN; /* icv or mac size,. always 12 except for AES_CCM/AES_GCM */
2238 #ifdef EXPERIMENTAL
2239 sa_info[i].iv_len=8;
2240 sa_info[i].bl=8;
2241 sa_info[i].spi = tx_sa[i].spi;
2242 sa_info[i].src =*((unsigned int *)(&config.local_ipsec_ip.ipv4[0]));
2243 sa_info[i].dst =*((unsigned int *)(&config.remote_ipsec_ip.ipv4[0]));
2244 #endif
2246 sa_info[i].tx_pkt_info.enetPort = 0;
2247 sa_info[i].tx_pkt_info.ipOffBytes = sa_info[i].tx_payload_info.encOffset;
2248 sa_info[i].tx_pkt_info.l4HdrLen = netTest_UDP_HEADER_LEN; /*UDP header len */
2249 sa_info[i].tx_pkt_info.l4OffBytes = sa_info[i].inner_ip_offset + netTest_IP_HEADER_LEN;
2250 sa_info[i].tx_pkt_info.startOffset = 0;
2251 sa_info[i].tx_pkt_info.lpbackPass = 0;
2252 sa_info[i].tx_pkt_info.ploadLen = 0; /*sa_info[i].tx_pkt_info.l4OffBytes + 4 */
2253 sa_info[i].tx_pkt_info.pPkt = NULL;
2254 sa_info[i].tx_pkt_info.saOffBytes = netTest_MAC_HEADER_LEN + netTest_IP_HEADER_LEN;
2255 sa_info[i].tx_pkt_info.saPayloadLen = 0;
2256 sa_info[i].tx_pkt_info.pseudoHdrChecksum =0;
2258 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 ;
2260 tmp_spi = htonl((long)(tx_sa[i].spi));
2261 trie_insert(p_trie_sa,(char *)&tmp_spi,4, (void *) &sa_info[i]); //asociate with tx sa SPI
2262 }
2263 else if ((tx_sa[i].authMode == NWAL_SA_AALG_HMAC_MD5) && (rx_sa[i].cipherMode == NWAL_SA_EALG_NULL))
2264 {
2265 /* static configuration, will not change */
2266 sa_info[i].tx_payload_info.aadSize = 0;
2267 sa_info[i].tx_payload_info.pAad = NULL;
2268 sa_info[i].tx_payload_info.pAuthIV = NULL;
2269 sa_info[i].tx_payload_info.authOffset = netTest_MAC_HEADER_LEN + netTest_IP_HEADER_LEN; /*done: same for all cipher suites */
2271 sa_info[i].tx_payload_info.encOffset = netTest_MAC_HEADER_LEN +
2272 netTest_IP_HEADER_LEN +
2273 netTest_ESP_HEADER_LEN +
2274 netTest_NULL_IV_LEN;
2275 #ifdef EXPERIMENTAL
2276 sa_info[i].iv_len=0;
2277 sa_info[i].bl=4;
2278 sa_info[i].spi = tx_sa[i].spi;
2279 sa_info[i].src =*((unsigned int *)(&config.local_ipsec_ip.ipv4[0]));
2280 sa_info[i].dst =*((unsigned int *)(&config.remote_ipsec_ip.ipv4[0]));
2281 #endif
2284 /* dynamic configuration, will be calculated on the fly */
2285 sa_info[i].tx_payload_info.authSize = 0;
2286 sa_info[i].tx_payload_info.encSize = 0;
2287 sa_info[i].tx_payload_info.pEncIV = 0;
2288 sa_info[i].tx_payload_info.pPkt = 0;
2290 sa_info[i].cipherMode = NWAL_SA_EALG_NULL;
2291 sa_info[i].inner_ip_offset = sa_info[i].tx_payload_info.encOffset;
2292 sa_info[i].auth_tag_size = netTest_ICV_LEN; /* icv or mac size,. always 12 except for AES_CCM/AES_GCM */
2294 sa_info[i].tx_pkt_info.enetPort = 0;
2295 sa_info[i].tx_pkt_info.ipOffBytes = sa_info[i].tx_payload_info.encOffset;
2296 sa_info[i].tx_pkt_info.l4HdrLen = netTest_UDP_HEADER_LEN; /*UDP header len */
2297 sa_info[i].tx_pkt_info.l4OffBytes = sa_info[i].inner_ip_offset + netTest_IP_HEADER_LEN;
2298 sa_info[i].tx_pkt_info.startOffset = 0;
2299 sa_info[i].tx_pkt_info.lpbackPass = 0;
2300 sa_info[i].tx_pkt_info.ploadLen = 0; /*sa_info[i].tx_pkt_info.l4OffBytes + 4 */
2301 sa_info[i].tx_pkt_info.pPkt = NULL;
2302 sa_info[i].tx_pkt_info.saOffBytes = netTest_MAC_HEADER_LEN + netTest_IP_HEADER_LEN;
2303 sa_info[i].tx_pkt_info.saPayloadLen = 0;
2304 sa_info[i].tx_pkt_info.pseudoHdrChecksum =0;
2306 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 ;
2307 tmp_spi = htonl((long)(tx_sa[i].spi));
2308 trie_insert(p_trie_sa,(char *)&tmp_spi,4, (void *) &sa_info[i]); //asociate with tx sa SPI
2309 }
2310 else if ((tx_sa[i].authMode == NWAL_SA_AALG_NULL) && (rx_sa[i].cipherMode == NWAL_SA_EALG_AES_GCM))
2311 {
2312 /* static configuration, will not change */
2313 sa_info[i].tx_payload_info.aadSize = 0;
2314 sa_info[i].tx_payload_info.pAad = NULL;
2315 sa_info[i].tx_payload_info.pAuthIV = NULL;
2316 sa_info[i].tx_payload_info.authOffset = netTest_MAC_HEADER_LEN + netTest_IP_HEADER_LEN; /*done: same for all cipher suites */
2317 //sa_info[i].tx_payload_info.encIvSize = netTest_AES_GCM_IV_LEN;
2319 sa_info[i].tx_payload_info.encOffset = netTest_MAC_HEADER_LEN +
2320 netTest_IP_HEADER_LEN +
2321 netTest_ESP_HEADER_LEN +
2322 netTest_AES_GCM_IV_LEN;
2323 #ifdef EXPERIMENTAL
2324 sa_info[i].iv_len=0;
2325 sa_info[i].bl=4;
2326 sa_info[i].spi = tx_sa[i].spi;
2327 sa_info[i].src =*((unsigned int *)(&config.local_ipsec_ip.ipv4[0]));
2328 sa_info[i].dst =*((unsigned int *)(&config.remote_ipsec_ip.ipv4[0]));
2329 #endif
2332 /* dynamic configuration, will be calculated on the fly */
2333 sa_info[i].tx_payload_info.authSize = 0;
2334 sa_info[i].tx_payload_info.encSize = 0;
2335 //sa_info[i].tx_payload_info.ploadLen = 0;
2336 sa_info[i].tx_payload_info.pEncIV = 0;
2337 sa_info[i].tx_payload_info.pPkt = 0;
2339 sa_info[i].cipherMode = NWAL_SA_EALG_AES_GCM;
2340 sa_info[i].inner_ip_offset = sa_info[i].tx_payload_info.encOffset;
2341 sa_info[i].auth_tag_size = netTest_AES_GCM_CCM_ICV_LEN; /* icv or mac size,. always 12 except for AES_CCM/AES_GCM */
2343 sa_info[i].tx_pkt_info.enetPort = 0;
2344 sa_info[i].tx_pkt_info.ipOffBytes = sa_info[i].tx_payload_info.encOffset;
2345 sa_info[i].tx_pkt_info.l4HdrLen = netTest_UDP_HEADER_LEN; /*UDP header len */
2346 sa_info[i].tx_pkt_info.l4OffBytes = sa_info[i].inner_ip_offset + netTest_IP_HEADER_LEN;
2347 sa_info[i].tx_pkt_info.startOffset = 0;
2348 sa_info[i].tx_pkt_info.lpbackPass = 0;
2349 sa_info[i].tx_pkt_info.ploadLen = 0; /*sa_info[i].tx_pkt_info.l4OffBytes + 4 */
2350 sa_info[i].tx_pkt_info.pPkt = NULL;
2351 sa_info[i].tx_pkt_info.saOffBytes = netTest_MAC_HEADER_LEN + netTest_IP_HEADER_LEN;
2352 sa_info[i].tx_pkt_info.saPayloadLen = 0;
2353 sa_info[i].tx_pkt_info.pseudoHdrChecksum =0;
2355 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 ;
2357 tmp_spi = htonl((long)(tx_sa[i].spi));
2358 trie_insert(p_trie_sa,(char *)&tmp_spi,4, (void *) &sa_info[i]); //asociate with tx sa SPI
2359 }
2360 else if ((tx_sa[i].authMode == NWAL_SA_AALG_NULL) && (rx_sa[i].cipherMode == NWAL_SA_EALG_AES_CCM))
2361 {
2362 /* static configuration, will not change */
2363 sa_info[i].tx_payload_info.aadSize = 0;
2364 sa_info[i].tx_payload_info.pAad = NULL;
2365 //sa_info[i].tx_payload_info.authIvSize = 0;
2366 sa_info[i].tx_payload_info.pAuthIV = NULL;
2367 sa_info[i].tx_payload_info.authOffset = netTest_MAC_HEADER_LEN + netTest_IP_HEADER_LEN; /*done: same for all cipher suites */
2369 sa_info[i].tx_payload_info.encOffset = netTest_MAC_HEADER_LEN +
2370 netTest_IP_HEADER_LEN +
2371 netTest_ESP_HEADER_LEN +
2372 netTest_AES_CCM_IV_LEN;
2373 #ifdef EXPERIMENTAL
2374 sa_info[i].iv_len=0;
2375 sa_info[i].bl=4;
2376 sa_info[i].spi = tx_sa[i].spi;
2377 sa_info[i].src =*((unsigned int *)(&config.local_ipsec_ip.ipv4[0]));
2378 sa_info[i].dst =*((unsigned int *)(&config.remote_ipsec_ip.ipv4[0]));
2379 #endif
2382 /* dynamic configuration, will be calculated on the fly */
2383 sa_info[i].tx_payload_info.authSize = 0;
2384 sa_info[i].tx_payload_info.encSize = 0;
2385 //sa_info[i].tx_payload_info.ploadLen = 0;
2386 sa_info[i].tx_payload_info.pEncIV = 0;
2387 sa_info[i].tx_payload_info.pPkt = 0;
2389 sa_info[i].cipherMode = NWAL_SA_EALG_AES_CCM;
2390 sa_info[i].inner_ip_offset = sa_info[i].tx_payload_info.encOffset;
2391 sa_info[i].auth_tag_size = netTest_AES_GCM_CCM_ICV_LEN; /* icv or mac size,. always 12 except for AES_CCM/AES_GCM */
2393 sa_info[i].tx_pkt_info.enetPort = 0;
2394 sa_info[i].tx_pkt_info.ipOffBytes = sa_info[i].tx_payload_info.encOffset;
2395 sa_info[i].tx_pkt_info.l4HdrLen = netTest_UDP_HEADER_LEN; /*UDP header len */
2396 sa_info[i].tx_pkt_info.l4OffBytes = sa_info[i].inner_ip_offset + netTest_IP_HEADER_LEN;
2397 sa_info[i].tx_pkt_info.startOffset = 0;
2398 sa_info[i].tx_pkt_info.lpbackPass = 0;
2399 sa_info[i].tx_pkt_info.ploadLen = 0; /*sa_info[i].tx_pkt_info.l4OffBytes + 4 */
2400 sa_info[i].tx_pkt_info.pPkt = NULL;
2401 sa_info[i].tx_pkt_info.saOffBytes = netTest_MAC_HEADER_LEN + netTest_IP_HEADER_LEN;
2402 sa_info[i].tx_pkt_info.saPayloadLen = 0;
2403 sa_info[i].tx_pkt_info.pseudoHdrChecksum =0;
2405 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 ;
2407 tmp_spi = htonl((long)(tx_sa[i].spi));
2408 trie_insert(p_trie_sa,(char *)&tmp_spi,4, (void *) &sa_info[i]); //asociate with tx sa SPI
2409 }
2410 else if ((tx_sa[i].authMode == NWAL_SA_AALG_GMAC) && (rx_sa[i].cipherMode == NWAL_SA_EALG_NULL))
2411 {
2412 /* static configuration, will not change */
2413 sa_info[i].tx_payload_info.aadSize = 0;
2414 sa_info[i].tx_payload_info.pAad = NULL;
2415 sa_info[i].tx_payload_info.pAuthIV = NULL;
2416 sa_info[i].tx_payload_info.authOffset = netTest_MAC_HEADER_LEN + netTest_IP_HEADER_LEN;
2419 sa_info[i].tx_payload_info.encOffset = netTest_MAC_HEADER_LEN +
2420 netTest_IP_HEADER_LEN +
2421 netTest_ESP_HEADER_LEN +
2422 netTest_AES_GMAC_IV_LEN;
2423 #ifdef EXPERIMENTAL
2424 sa_info[i].iv_len=0;
2425 sa_info[i].bl=4;
2426 sa_info[i].spi = tx_sa[i].spi;
2427 sa_info[i].src =*((unsigned int *)(&config.local_ipsec_ip.ipv4[0]));
2428 sa_info[i].dst =*((unsigned int *)(&config.remote_ipsec_ip.ipv4[0]));
2429 #endif
2432 /* dynamic configuration, will be calculated on the fly */
2433 sa_info[i].tx_payload_info.authSize = 0;
2434 sa_info[i].tx_payload_info.encSize = 0;
2435 //sa_info[i].tx_payload_info.ploadLen = 0;
2436 sa_info[i].tx_payload_info.pEncIV = 0;
2437 sa_info[i].tx_payload_info.pPkt = 0;
2439 sa_info[i].cipherMode = NWAL_SA_EALG_NULL;
2440 sa_info[i].authMode = NWAL_SA_AALG_GMAC;
2441 sa_info[i].inner_ip_offset = sa_info[i].tx_payload_info.encOffset;
2442 sa_info[i].auth_tag_size = netTest_AES_GMAC_ICV_LEN; /* icv or mac size,. always 12 except for AES_CCM/AES_GCM , GMAC*/
2444 sa_info[i].tx_pkt_info.enetPort = 0;
2445 sa_info[i].tx_pkt_info.ipOffBytes = sa_info[i].tx_payload_info.encOffset;
2446 sa_info[i].tx_pkt_info.l4HdrLen = netTest_UDP_HEADER_LEN; /*UDP header len */
2447 sa_info[i].tx_pkt_info.l4OffBytes = sa_info[i].inner_ip_offset + netTest_IP_HEADER_LEN;
2448 sa_info[i].tx_pkt_info.startOffset = 0;
2449 sa_info[i].tx_pkt_info.lpbackPass = 0;
2450 sa_info[i].tx_pkt_info.ploadLen = 0; /*sa_info[i].tx_pkt_info.l4OffBytes + 4 */
2451 sa_info[i].tx_pkt_info.pPkt = NULL;
2452 sa_info[i].tx_pkt_info.saOffBytes = netTest_MAC_HEADER_LEN + netTest_IP_HEADER_LEN;
2453 sa_info[i].tx_pkt_info.saPayloadLen = 0;
2454 sa_info[i].tx_pkt_info.pseudoHdrChecksum =0;
2456 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 ;
2458 tmp_spi = htonl((long)(tx_sa[i].spi));
2459 trie_insert(p_trie_sa,(char *)&tmp_spi,4, (void *) &sa_info[i]); //asociate with tx sa SPI
2460 }
2461 else
2462 printf("build_sa_db(): invalid encryption/authentication combination selected\n");
2464 //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);
2467 }
2471 #define CHECK_SET_PARAM(ARG1, ARG2) \
2472 do { \
2473 if(strcmp(key, ARG1) == 0) { \
2474 if(data)strncpy(ARG2,data,CONFIG_STRING_LEN); \
2475 printf("CHECK_SET_PARM, match found, input cong string %s\n", ARG2); \
2476 continue; \
2477 } \
2478 } while(0)
2480 #define CHECK_SET_PARAM2(ARG1, ARG2, ARG3) \
2481 do { \
2482 if(strcmp(key, ARG1) == 0) { \
2483 if(data) strncpy(ARG2,data,CONFIG_STRING_LEN); \
2484 if(data2) strncpy(ARG3,data2,CONFIG_STRING_LEN); \
2485 printf("CHECK_SET_PARM2, match found, input cong string %s %s\n", ARG2, ARG3); \
2486 continue; \
2487 } \
2488 } while(0)
2490 unsigned char hex2dec(char *p_s)
2491 {
2492 int val;
2493 sscanf(p_s,"%x",&val);
2494 return val&0xff;
2495 }
2496 void parse_one_mac(char * p_mac_str, unsigned char *p_mac)
2497 {
2498 int index = 0;
2499 int i;
2500 char *pch = strtok (&(p_mac_str[0]),"-");
2502 while (pch != NULL)
2503 {
2504 printf ("%s\n",pch);
2505 p_mac[index] = hex2dec(pch);
2506 index++;
2507 pch = strtok (NULL,"-");
2508 }
2509 printf("index value : %d\n", index);
2510 for (i=0; i<6;i++)
2511 printf("************mac0[%d]: 0x%x\n",i, p_mac[i]);
2512 }
2514 void parse_one_ip(char * p_ip_addr_str, unsigned char * p_ip)
2515 {
2516 int index = 0;
2517 int i;
2518 char * pch = strtok (&p_ip_addr_str[0],".");
2520 while (pch != NULL)
2521 {
2522 printf ("xxxxx: %s\n",pch);
2523 p_ip[index] = atoi(pch);
2524 index++;
2525 pch = strtok (NULL,".");
2526 }
2527 printf("index value : %d\n", index);
2528 for (i=0; i<4;i++)
2529 printf("************ip[%d]: 0x%x\n",i, p_ip[i]);
2532 }
2534 void parse_mac_address(netTestConfigFile_t *pConfig)
2535 {
2536 if (strlen(&pConfig->mac0[0]))
2537 parse_one_mac(&pConfig->mac0[0],&config.mac0[0]);
2538 if (strlen(&pConfig->mac1[0]))
2539 parse_one_mac(&pConfig->mac1[0],&config.mac1[0]);
2540 }
2541 void parse_ip_address(netTestConfigFile_t *pConfig)
2542 {
2543 if (strlen(&pConfig->ip0[0]))
2544 parse_one_ip(&pConfig->ip0[0],&config.ip0.ipv4[0]);
2545 if (strlen(&pConfig->ip1[0]))
2546 parse_one_ip(&pConfig->ip1[0],&config.ip1.ipv4[0]);
2547 if (strlen(&pConfig->ip2[0]))
2548 parse_one_ip(&pConfig->ip2[0],&config.ip2.ipv4[0]);
2549 if (strlen(&pConfig->local_ipsec_ip[0]))
2550 parse_one_ip(&pConfig->local_ipsec_ip[0],&config.local_ipsec_ip.ipv4[0]);
2551 if (strlen(&pConfig->remote_ipsec_ip[0]))
2552 parse_one_ip(&pConfig->remote_ipsec_ip[0],&config.remote_ipsec_ip.ipv4[0]);
2553 }
2556 void parse_ipsec_mode(netTestConfigFile_t *pConfig)
2557 {
2559 printf("parse_ipsec_mode, string length %d\n", strlen(&pConfig->ipsec_mode_rx));
2560 if (strlen(&pConfig->ipsec_mode_rx[0]))
2561 {
2562 if (strcmp(pConfig->ipsec_mode_rx, "SIDEBAND") == 0)
2563 {
2564 config.ipsec_mode_rx = IPSEC_MODE_RX_SIDEBAND;
2565 }
2566 else if (strcmp(pConfig->ipsec_mode_rx, "INFLOW") == 0)
2567 {
2568 config.ipsec_mode_rx = IPSEC_MODE_RX_INFLOW;
2569 }
2570 else
2571 printf("parse_ipsec_mode(), invalid RX ipsec mode in config file \n");
2572 }
2574 if (strlen(&pConfig->ipsec_mode_tx[0]))
2575 {
2576 if (strcmp(pConfig->ipsec_mode_tx, "SIDEBAND") == 0)
2577 {
2578 config.ipsec_mode_tx = IPSEC_MODE_TX_SIDEBAND;
2579 }
2580 else if (strcmp(pConfig->ipsec_mode_tx, "INFLOW") == 0)
2581 {
2582 config.ipsec_mode_tx = IPSEC_MODE_TX_INFLOW;
2583 }
2584 else
2585 printf("parse_ipsec_mode(), invalid TX ipsec mode in config file \n");
2586 }
2588 printf("parse_ipsec_mode(): RX mode %d\n", config.ipsec_mode_rx);
2589 printf("parse_ipsec_mode(): TX mode %d\n", config.ipsec_mode_tx);
2592 }
2594 #ifdef EXPERIMENTAL
2595 int n_routes=0;
2596 int n_dst_ips=0;
2597 void parse_routes(netTestConfigFile_t *pConfig)
2598 {
2599 int i;
2600 int said=0;
2601 for(i=0;i<MAX_ROUTES;i++)
2602 {
2603 int port;
2604 if (pConfig->routes[i][0])
2605 {
2606 port=atoi(&pConfig->ports[i][0]);
2607 if((port<1)||(port>2)) continue; //bad port #: only 1 or 2 valid
2608 if(strncmp(&pConfig->routes[i][0],"MAC",3)==0)
2609 {
2610 routes[i].out_port = port;
2611 parse_one_mac(&pConfig->routes[i][3],&routes[i].out_mac[0]);
2612 memcpy(&routes[i].out_mac[6], ((port==1) ?&config.mac0[0]: &config.mac1[0] ),6);
2613 routes[i].out_mac[12]=0x08;
2614 routes[i].out_mac[13]=0x00;
2615 routes[i].sec_ptr=NULL;
2616 n_routes+=1;
2617 }
2618 else if (strncmp(&pConfig->routes[i][0],"SA",2)==0)
2619 {
2620 said=atoi(&pConfig->routes[i][2]) ;
2621 routes[i].sec_ptr=&sa_info[said];
2622 n_routes+=1;
2623 }
2624 }
2625 }
2626 our_router = route_init();
2627 for (i=0;i<MAX_ROUTES;i++)
2628 {
2629 unsigned long ip_be;
2630 int route_index;
2631 if (pConfig->dst_ips[i][0])
2632 {
2633 parse_one_ip(&pConfig->dst_ips[i][0],(unsigned char *)&ip_be);
2634 sscanf(&pConfig->paths[i][0],"route%d",&route_index);
2635 route_add(our_router,&ip_be,&routes[route_index]);
2636 n_dst_ips+=1;
2637 }
2638 }
2639 printf(">Route DB built. %d entries\n",n_dst_ips);
2640 }
2641 #endif
2642 static void parse_config_file(FILE * fpr, netTestConfigFile_t *pConfig)
2643 {
2644 char line[MAX_LINE_LENGTH + 1];
2645 int i;
2647 char *key, *data, *ep, *data2;
2648 char tokens[] = " :=;\n";
2649 char temp_str[50];
2650 memset(line, 0, MAX_LINE_LENGTH + 1);
2651 memset(pConfig, 0, sizeof(netTestConfigFile_t));
2652 while (fgets(line, MAX_LINE_LENGTH + 1, fpr))
2653 {
2654 if(line[0]=='#') continue; //skip comment
2655 key = (char *)strtok(line, tokens);
2656 data = (char *)strtok(NULL, tokens);
2657 data2 = (char *)strtok(NULL, tokens);
2658 if (!key) continue;
2659 if (!data) continue;
2661 if(strlen(data) == 0)
2662 {
2663 continue;
2664 }
2666 CHECK_SET_PARAM(INIT_CONFIG_MAC0,&(pConfig->mac0[0]));
2667 CHECK_SET_PARAM(INIT_CONFIG_MAC1,&(pConfig->mac1[0]));
2668 CHECK_SET_PARAM(INIT_CONFIG_IP0,&(pConfig->ip0[0]));
2669 CHECK_SET_PARAM(INIT_CONFIG_IP1,&(pConfig->ip1[0]));
2670 CHECK_SET_PARAM(INIT_CONFIG_IP2,&(pConfig->ip2[0]));
2671 CHECK_SET_PARAM(INIT_CONFIG_LOCAL_IPSEC_IP,&(pConfig->local_ipsec_ip[0]));
2672 CHECK_SET_PARAM(INIT_CONFIG_REMOTE_IPSEC_IP,&(pConfig->remote_ipsec_ip[0]));
2673 CHECK_SET_PARAM(INIT_CONFIG_IPSEC_MODE_RX,&(pConfig->ipsec_mode_rx[0]));
2674 CHECK_SET_PARAM(INIT_CONFIG_IPSEC_MODE_TX,&(pConfig->ipsec_mode_tx[0]));
2675 CHECK_SET_PARAM(INIT_CONFIG_IPSEC_IF_NO,&(pConfig->ipsec_if_no[0]));
2676 #ifdef EXPERIMENTAL
2677 for(i=0;i<MAX_ROUTES;i++)
2678 {
2679 sprintf(temp_str,"route%d",i);
2680 CHECK_SET_PARAM2(temp_str,&pConfig->routes[i][0],&pConfig->ports[i][0] );
2681 }
2682 for(i=0;i<MAX_ROUTES;i++)
2683 {
2684 sprintf(temp_str,"dstip%d",i);
2685 CHECK_SET_PARAM2(temp_str,&pConfig->dst_ips[i][0],&pConfig->paths[i][0] );
2686 }
2687 #endif
2689 }
2690 parse_mac_address(pConfig);
2692 parse_ip_address(pConfig);
2694 parse_ipsec_mode(pConfig);
2695 #ifdef EXPERIMENTAL
2696 if (strlen(&pConfig->ipsec_if_no[0]))
2697 config.ipsec_if_no = atoi(&pConfig->ipsec_if_no[0]);
2698 parse_routes(pConfig);
2699 #endif
2700 }
2702 static netTestConfigFile_t config_file;
2703 /***************************************
2704 ********** test driver*****************
2705 ***************************************/
2706 int main(int argc, char **argv)
2707 {
2708 int err,i;
2709 rlim_t oss,ss = 1024*1024;
2710 struct rlimit rl;
2712 Pktlib_HeapCfg heapCfg;
2713 int32_t errCode;
2714 Pktlib_HeapIfTable* pPktifTable;
2716 FILE * fpr = NULL;
2720 err= getrlimit(RLIMIT_STACK,&rl);
2721 if (!err) printf(" stack limit = %d\n",rl.rlim_cur); else printf("getrlimit failed\n");
2722 #if 0
2723 rl.rlim_cur = ss;
2724 err=setrlimit(RLIMIT_STACK,&rl);
2725 i f (!err) printf("set stack to %d\n",rl.rlim_cur); else printf("setrlimit failed\n");
2726 #endif
2729 if (argc>=2) np2process = atoi(argv[1]);
2730 printf("*************** np2process %d\n", np2process);
2731 if (np2process<0) np2process = NP; /* default */
2732 if (argc==3) perslow = atoi(argv[2]);
2733 if ((perslow<0)||(perslow>100)) perslow=PERSLOW;//default
2734 if (argc>3) {printf("net_test <no of pkts to process> <percent slow path>\n"); exit(1);}
2735 #if 1
2737 #if 0
2738 if (argc >= 2)
2739 {
2740 fpr = fopen(argv[2], "r");
2741 if (fpr == NULL)
2742 {
2743 printf("Error in opening %s input file\n", argv[2]);
2744 }
2745 }
2746 else
2747 #endif
2748 {
2749 fpr = fopen(input_file_name, "r");
2750 if (fpr == NULL)
2751 {
2752 printf("Error in opening %s input file\n", input_file_name);
2753 }
2754 else
2755 {
2756 parse_config_file(fpr,&config_file);
2757 }
2758 }
2760 #endif
2762 memset(&sa_info, 0, sizeof(sa_info));
2765 //real mode, so update our test packet mac header and ip header
2766 if (pktloopback==0)
2767 {
2768 memcpy(&testPkt,&real_mac_header[0],14); //overwrite test pkt mac address
2769 memcpy(&testPkt[26],&real_ip_addr[0],8);//overrite test pkt ip addresses
2770 }
2771 #if 0
2772 our_router = route_init();
2773 for (i=0;i<n_dst_ips;i++)
2774 {
2775 route_add(our_router,&ip[i],&routes[i]);
2776 }
2777 #endif
2779 /*******************************************/
2780 /*************NETAPI STARTUP****************/
2781 /*******************************************/
2783 /* create netapi */
2784 netapi_handle = netapi_init(NETAPI_SYS_MASTER, &our_netapi_default_cfg);
2786 /* open the main heap */
2787 OurHeap = Pktlib_findHeapByName("netapi");
2788 if (!OurHeap) {printf("findheapbyname fail\n"); exit(1);}
2790 /* create two secondary heaps */
2791 /* Initialize the heap configuration. */
2792 memset ((void *)&heapCfg, 0, sizeof(Pktlib_HeapCfg));
2794 pPktifTable = netapi_getPktlibIfTable();
2795 /* Populate the heap configuration */
2796 heapCfg.name = "netapi-small";
2797 heapCfg.memRegion = NETAPI_GLOBAL_REGION;
2798 heapCfg.sharedHeap = 1;
2799 heapCfg.useStarvationQueue = 0;
2800 heapCfg.dataBufferSize = 512;
2801 heapCfg.numPkts = 64;
2802 heapCfg.numZeroBufferPackets= 0;
2803 heapCfg.heapInterfaceTable.data_malloc = pPktifTable->data_malloc;
2804 heapCfg.heapInterfaceTable.data_free = pPktifTable->data_free;
2805 heapCfg.dataBufferPktThreshold = 0;
2806 heapCfg.zeroBufferPktThreshold = 0;
2808 specialSmall = Pktlib_createHeap(&heapCfg, &errCode);
2809 heapCfg.name = "netapi-big";
2810 heapCfg.dataBufferSize = 1600;
2811 specialLarge = Pktlib_createHeap(&heapCfg, &errCode);
2812 //register these heaps so poll routine will include their garbage queues.
2813 netapi_registerHeap(netapi_handle, specialSmall);
2814 netapi_registerHeap(netapi_handle, specialLarge);
2816 #ifdef REASSEMBLE_BENCH
2817 our_reassemble_bench(2);
2818 exit(1);
2819 #endif
2821 #ifndef EXPERIMENTAL
2822 /* create a pktio channel */
2823 our_chan=pktio_create(netapi_handle,"our1stq",(PKTIO_CB) recv_cb_bench, &our_chan_cfg,&err);
2824 if (!our_chan) {printf("pktio create failed err=%d\n",err); exit(1);}
2825 #endif
2827 /* open netcp default tx, rx queues */
2828 netcp_tx_chan= pktio_open(netapi_handle, NETCP_TX, NULL, &netcp_tx_cfg, &err);
2829 if (!netcp_tx_chan) {printf("pktio open TX failed err=%d\n",err); exit(1);}
2830 #ifdef EXPERIMENTAL
2831 netcp_rx_chan= pktio_open(netapi_handle, NETCP_RX, (PKTIO_CB) recv_cb_router, &netcp_rx_cfg, &err);
2832 #else
2833 netcp_rx_chan= pktio_open(netapi_handle, NETCP_RX, (PKTIO_CB) recv_cb, &netcp_rx_cfg, &err);
2834 #endif
2835 if (!netcp_rx_chan) {printf("pktio open RX failed err=%d\n",err); exit(1);}
2837 #ifndef EXPERIMENTAL
2838 /* create a pktio channel for specially classified pkts */
2839 netcp_rx_chan2= pktio_create(netapi_handle, "classq", (PKTIO_CB) recv_cb, &netcp_rx_cfg2, &err);
2840 if (!netcp_rx_chan2) {printf("pktio create RX2 failed err=%d\n",err); exit(1);}
2842 /* open netcp default tx, rx queues for sideband crypto */
2843 netcp_sb_tx_chan= pktio_open(netapi_handle, NETCP_SB_TX, NULL, &netcp_sb_tx_cfg, &err);
2844 if (!netcp_sb_tx_chan) {printf("pktio open SB TX failed err=%d\n",err); exit(1);}
2845 netcp_sb_rx_chan= pktio_open(netapi_handle, NETCP_SB_RX, (PKTIO_CB) recv_sb_cb, &netcp_sb_rx_cfg, &err);
2846 if (!netcp_sb_rx_chan) {printf("pktio open SB RX failed err=%d\n",err); exit(1);}
2847 #endif
2849 printf("net_test> %d bytes left in our CMA area\n", netapi_getBufMemRemainder());
2850 /* create scheduler instance */
2851 our_sched =netapi_schedOpen(netapi_handle,&our_sched_cfg, &err);
2852 if (!our_sched) {printf("sched create failed\n"); exit(1);}
2854 #if 0
2855 /********************************************
2856 * Basic pkt loopback test
2857 *********************************************/
2858 printf("...running pure push/pop benchmark\n");
2859 our_pktio_bench(1000);
2860 our_pktio_bench(1000);
2861 our_pktio_bench(1000);
2862 our_pktio_bench(1000);
2863 our_pktio_bench(1000);
2864 /*********************************************/
2865 #endif
2870 /* add mac intefaces */
2871 netcp_cfgCreateMacInterface(
2872 netapi_handle,
2873 &config.mac0[0],
2874 0,0,
2875 (NETCP_CFG_ROUTE_HANDLE_T) NULL,
2876 (NETCP_CFG_VLAN_T ) NULL , //future
2877 1,
2878 &err);
2879 if (err) {printf("addmac0 failed %d\n",err); exit(1); }
2881 //attach an IP to this interface
2882 ip_rule0=netcp_cfgAddIp(
2883 netapi_handle,
2884 0,
2885 nwal_IPV4,
2886 &config.ip0,
2887 NULL, //all IP
2888 (NETCP_CFG_ROUTE_HANDLE_T) NULL,
2889 &err
2890 );
2891 if (err) {printf("addip0 failed %d\n",err); exit(1); }
2893 //create a 2nd mac instance
2894 netcp_cfgCreateMacInterface(
2895 netapi_handle,
2896 &config.mac1[0],
2897 1,1,
2898 (NETCP_CFG_ROUTE_HANDLE_T) NULL,
2899 (NETCP_CFG_VLAN_T ) NULL , //future
2900 1,
2901 &err);
2902 if (err) {printf("addmac1 failed %d\n",err); exit(1); }
2904 //attach an IP to this interface
2905 ip_rule1=netcp_cfgAddIp(
2906 netapi_handle,
2907 1,
2908 nwal_IPV4,
2909 &config.ip1,
2910 NULL, //all IP
2911 (NETCP_CFG_ROUTE_HANDLE_T) NULL,
2912 &err
2913 );
2914 if (err) {printf("addip1 failed %d\n",err); exit(1); }
2916 #ifndef EXPERIMENTAL
2917 //attach 2 classifiers to iface 0, ip0
2918 class_0_cfg.u.c_l4.ip = ip_rule0;
2919 class_0 = netcp_cfgAddClass(netapi_handle,
2920 &class_0_cfg,
2921 NULL,
2922 NETCP_CFG_ACTION_TO_SW,
2923 &err);
2924 if (err) {printf("addclass0 failed %d\n",err); exit(1);}
2926 class_1_cfg.u.c_l4.ip = ip_rule0;
2927 class_1 = netcp_cfgAddClass(netapi_handle,
2928 &class_1_cfg,
2929 NULL,
2930 NETCP_CFG_ACTION_TO_SW,
2931 &err);
2932 if (err) {printf("addclass1 failed %d\n",err); exit(1);}
2935 //3rd classifier has a different IP and route
2936 class_2_cfg.u.c_l3_l4.ip_addr = &config.ip2;
2938 //create specialFlow for this classifier
2939 {
2940 Pktlib_HeapHandle heaps[2];
2941 int sizes[2];
2942 heaps[0]= specialSmall;
2943 heaps[1]= specialLarge;
2944 #define SPECIAL_SOP_OFF 128
2945 sizes[0]=512-SPECIAL_SOP_OFF;
2946 sizes[1]=1600-SPECIAL_SOP_OFF;
2947 #if 0
2948 specialFlow = netcp_cfgAddFlow( netapi_handle,
2949 2,
2950 heaps,
2951 sizes,
2952 SPECIAL_SOP_OFF, //offset to start rx is 128
2953 &err);
2954 if (err) {printf("add flow failed\n", err); exit(1);}
2955 #endif
2956 }
2957 #if 0
2958 //special route for this classifier: different flow + destination q
2959 class2_route.p_dest_q = netcp_rx_chan2;
2960 class2_route.p_flow = specialFlow;
2961 class_2 = netcp_cfgAddClass(netapi_handle,
2962 &class_2_cfg,
2963 (void*) &class2_route,
2964 NETCP_CFG_ACTION_TO_SW,
2965 &err);
2966 if (err) {printf("addclass2 failed %d\n",err); exit(1);}
2967 #endif
2969 #endif
2970 //security stuff
2971 p_trie_sa = trie_new();
2972 if (!p_trie_sa) {printf("trie alloc for SA failed\n"); exit(1);}
2976 for (i=0; i < MAX_SEC_INDEX;i++)
2977 {
2978 ourRXKeyParams[i].pEncKey = &ourEncrKey[0];
2979 ourRXKeyParams[i].pAuthKey = &ourAuthKey[0];
2980 memcpy(&(rx_sa[i].src), &config.remote_ipsec_ip,4);
2981 memcpy(&(rx_sa[i].dst), &config.local_ipsec_ip,4);
2983 build_sa_db(i);
2984 sa_info[i].rx_tunnel = netapi_secAddSA(
2985 netapi_handle,
2986 config.ipsec_if_no, //iface #0
2987 &rx_sa[i],
2988 &ourRXKeyParams[i],
2989 config.ipsec_mode_rx == IPSEC_MODE_RX_SIDEBAND ? NETAPI_SEC_SA_SIDEBAND: NETAPI_SEC_SA_INFLOW,
2990 NULL, //use default route
2991 &(sa_info[i].rx_data_mode_handle),
2992 &(sa_info[i].rx_inflow_mode_handle),
2993 &err);
2994 if (err) {printf("addRxSa failed %d\n",err); exit(1);}
2996 if (config.ipsec_mode_rx == IPSEC_MODE_RX_INFLOW)
2997 {
2998 //assume inner and outer ip is the same
2999 rx_policy[i]= netapi_secAddRxPolicy( netapi_handle,
3000 sa_info[i].rx_tunnel, //link to tunnel above
3001 4, //ipv4
3002 &config.remote_ipsec_ip, //src -> them
3003 &config.local_ipsec_ip, //dst -> us
3004 NULL, // no qualifiers
3005 NULL, //default route
3006 &err);
3007 if (err) {printf("addSaPolicy failed %d, for index %d\n",err,i); exit(1);}
3008 }
3009 else
3010 {
3011 rx_policy[i] = 0;
3013 }
3014 #ifdef NET_TEST_ENABLE_SIDE_BAND_LOW_LEVEL_API
3015 /* Remember the NetCP Command Label so save cycles per Crypto
3016 * operation
3017 *
3018 */
3019 if(config.ipsec_mode_rx == IPSEC_MODE_RX_SIDEBAND)
3020 {
3021 nwalRetVal =
3022 nwal_initDMPSCmdInfo(PKTIO_GET_NWAL_INSTANCE(netcp_sb_rx_chan),
3023 sa_info[i].rx_data_mode_handle,
3024 &sa_info[i].rx_dmPSCmdInfo);
3025 }
3027 #endif
3028 }
3030 //tx SA
3031 //security stuff
3032 for (i=0; i < MAX_SEC_INDEX;i++)
3033 {
3034 ourTXKeyParams[i].pEncKey = &ourEncrKey[0];
3035 ourTXKeyParams[i].pAuthKey = &ourAuthKey[0];
3036 memcpy(&(tx_sa[i].src), &config.local_ipsec_ip,4);
3037 memcpy(&(tx_sa[i].dst), &config.remote_ipsec_ip,4);
3038 sa_info[i].tx_tunnel = netapi_secAddSA( netapi_handle,
3039 0, //iface #0
3040 &(tx_sa[i]),
3041 &ourTXKeyParams[i],
3042 config.ipsec_mode_tx == IPSEC_MODE_TX_SIDEBAND ? NETAPI_SEC_SA_SIDEBAND: NETAPI_SEC_SA_INFLOW,
3043 NULL, //use default route
3044 &(sa_info[i].tx_data_mode_handle),
3045 &(sa_info[i].tx_inflow_mode_handle),
3046 &err);
3047 if (err) {printf("addTxSa failed %d\n",err); exit(1);}
3049 #ifdef NET_TEST_ENABLE_SIDE_BAND_LOW_LEVEL_API
3050 /* Remember the NetCP Command Label so save cycles per Crypto
3051 * operation
3052 *
3053 */
3054 if(config.ipsec_mode_tx == IPSEC_MODE_TX_SIDEBAND)
3055 {
3056 nwalRetVal =
3057 nwal_initDMPSCmdInfo(PKTIO_GET_NWAL_INSTANCE(netcp_sb_tx_chan),
3058 sa_info[i].tx_data_mode_handle,
3059 &sa_info[i].tx_dmPSCmdInfo);
3060 }
3062 #endif
3063 }
3065 #ifdef TEST_TIMERS
3066 //timers
3067 ourTimerBlock = netapi_TimerGroupCreate(
3068 netapi_handle,
3069 "our1sttimer",
3070 our_timer_cb,
3071 0, //1 if timers local to thread
3072 0, //1 if expect to cancel
3073 netapi_getTicksPerSec()/1000, /* 1 msc resolution for these timers */
3074 netapi_getTicksPerSec()/5000, /* would like .5 msc tolerence */
3075 10, //small # of timers to test garbage collection
3076 &err);
3077 if (err) {printf("timergroupcreate failed %d\n",err); exit(1);}
3079 //start a couple of timers
3080 t1 = netapi_TimerGroupStartTimer(
3081 ourTimerBlock,
3082 (void *) 1,
3083 100LL, //timer group ticks
3084 &err);
3085 if (err) {printf("timerstart failed %d\n");}
3086 t2 = netapi_TimerGroupStartTimer(
3087 ourTimerBlock,
3088 (void *) 2,
3089 200LL, //timer group ticks
3090 &err);
3091 if (err) {printf("timerstart failed %d\n");}
3092 t3 = netapi_TimerGroupStartTimer(
3093 ourTimerBlock,
3094 (void *) 3,
3095 300LL, //timer group ticks
3096 &err);
3097 if (err) {printf("timerstart failed %d\n");}
3098 #endif
3099 netcp_cfgReqStats(netapi_handle, our_stats_cb, 1,&err);
3100 if (err!=0) {printf("stats req failed\n");}
3102 /*********************************************/
3103 /*****************end NETAPI STARTUP**********/
3104 /*********************************************/
3107 #if 0
3108 /********************************************
3109 * Basic pkt loopback test
3110 *********************************************/
3111 printf("...runnining pure push/pop benchmark\n");
3112 our_pktio_bench(100);
3113 #endif
3115 /**************unused stuff******************/
3116 #if 0
3117 /* create TRIE */
3118 P_trie = trie_new();
3119 if (!P_trie) {printf("trie alloc failed\n"); exit(1);}
3121 nat = (HEAD_T *) malloc(NE * sizeof(HEAD_T));
3122 if (!nat) {printf("malloc of nat table failed\n"); exit(1);}
3124 //gen_pkts(np2process<NP ? np2process:NP);
3125 n_pkt= np2process;
3127 /* build table */
3128 build_table(P_trie);
3131 /* processing loop: get pkt, check it, look up in table, copy new header,
3132 send packet */
3133 srand((unsigned) np2process);
3134 #endif
3136 /*********************************************/
3137 /**************Entry point into scheduler ****/
3138 /*********************************************/
3139 netapi_schedWaitForEvents(our_sched, &err);
3141 /* done */
3142 our_stats_cb(netapi_handle, NULL);
3145 #define DO_FAST_POLL
3146 #ifdef DO_FAST_POLL
3147 //example_fast_pushpop(OurHeap, 500);
3148 //example_fast_poll(netcp_rx_chan,20000);
3149 #endif
3151 /*************************************************
3152 ************CLEAN UP****************************
3153 ************************************************/
3155 #ifndef EXPERIMENTAL
3156 //delete Classifiers
3157 netcp_cfgDelClass(netapi_handle, class_0, &err);
3158 netcp_cfgDelClass(netapi_handle, class_1, &err);
3159 //netcp_cfgDelClass(netapi_handle, class_2, &err);
3161 #if 0
3162 //delete flow
3163 netcp_cfgDelFlow(netapi_handle, specialFlow, &err);
3164 #endif
3165 #endif
3166 #if 1
3167 //delete policy
3168 for (i=0; i < MAX_SEC_INDEX;i++)
3169 {
3170 if (rx_policy[i])
3171 netapi_secDelRxPolicy(netapi_handle, rx_policy[i], &err);
3173 //delete tunnels
3174 netapi_secDelSA(netapi_handle, 0, sa_info[i].rx_tunnel, &err);
3175 netapi_secDelSA(netapi_handle, 0, sa_info[i].tx_tunnel, &err);
3176 #endif
3177 }
3178 //delete IPs and MAC Interfacess
3179 netcp_cfgDelIp(netapi_handle, 0, 0, NULL, NULL, ip_rule0, &err);
3180 netcp_cfgDelIp(netapi_handle, 1, 0, NULL, NULL, ip_rule1, &err);
3181 netcp_cfgDelMac(netapi_handle,0,&err);
3182 netcp_cfgDelMac(netapi_handle,1,&err);
3185 //close pktio channels we opened
3186 pktio_close(netcp_tx_chan ,&err);
3187 pktio_close(netcp_rx_chan ,&err);
3188 #ifndef EXPERIMENTAL
3189 pktio_close(netcp_sb_tx_chan ,&err);
3190 pktio_close(netcp_sb_rx_chan ,&err);
3192 //clear pktio channel we created
3193 pktio_control(our_chan, (PKTIO_CB) NULL, (PKTIO_CFG_T *) NULL, &zap_channel_control, &err);
3194 pktio_control(netcp_rx_chan2, (PKTIO_CB) NULL, (PKTIO_CFG_T *) NULL, &zap_channel_control, &err);
3196 //delete pktio channels we created
3197 pktio_delete(our_chan, &err);
3198 pktio_delete(netcp_rx_chan2,&err);
3199 #endif
3200 netapi_shutdown(netapi_handle);
3202 }
3204 //EXAMPLE FAST POLL
3205 /* PLD */
3206 void netapi_pld(void * x)
3207 {
3208 asm volatile("pld [r0]");
3209 }
3210 #include "ti/drv/nwal/nwal_util.h"
3212 #define M 1008
3213 static int l3_off[M], l4_off[M], L3_chk_ok[M], L4_chk_ok[M], len[M] ;
3214 static nwal_AppId appid[M];
3215 static unsigned char * buf[M];
3216 #define N2POLL 8 //batch size
3217 #define NTOPOP 190
3218 Ti_Pkt * pHd[NTOPOP];
3219 void example_fast_pushpop(Pktlib_HeapHandle h , int n_trials)
3220 {
3221 int i,j;
3222 unsigned long t1;
3223 unsigned long t2;
3224 unsigned long sumf=0;
3225 unsigned long sumt=0;
3226 unsigned long sump=0;
3227 #define NTOPOP 190
3228 Ti_Pkt * tempVA;
3229 Qmss_QueueHnd freeQ=Pktlib_getInternalHeapQueue(h);
3231 //n_trials of NTOPOP actions
3232 for(i=0;i<n_trials;i++)
3233 {
3234 //raw pop
3235 t1= netapi_timing_start();
3236 pHd[0] = (Ti_Pkt *)QMSS_DESC_PTR(PKTIO_QMSS_QUEUE_POP_RAW (freeQ));
3237 for(j=1;j<NTOPOP;j++)
3238 {
3239 tempVA = _Osal_qmssPhyToVirt(pHd[j-1]);
3240 netapi_pld(tempVA);
3241 //__builtin_prefetch(tempVA);
3242 pHd[j] = (Ti_Pkt *)QMSS_DESC_PTR(PKTIO_QMSS_QUEUE_POP_RAW (freeQ));
3243 sumf+= (int) ( ((Cppi_HostDesc *) tempVA)->origBuffPtr -
3244 ((Cppi_HostDesc *) tempVA)->buffPtr);
3245 }
3246 tempVA = _Osal_qmssPhyToVirt(pHd[j-1]);
3247 sumf+= (int) ( ((Cppi_HostDesc *) tempVA)->origBuffPtr -
3248 ((Cppi_HostDesc *) tempVA)->buffPtr);
3249 t2=netapi_timing_stop();
3250 sumt+= (t2-t1);
3252 //invalidate/wb
3253 for(j=0;j<NTOPOP;j++)
3254 {
3255 tempVA = _Osal_qmssPhyToVirt(pHd[j]);
3256 netapi_utilCacheWbInv(tempVA,128);
3257 }
3259 //raw push
3260 t1=netapi_timing_start();
3261 for(j=0;j<NTOPOP;j++)
3262 {
3263 PKTIO_QMSS_QUEUE_PUSH_DESC_SIZE_RAW (freeQ,
3264 (void *) pHd[j],
3265 128);
3266 }
3267 t2=netapi_timing_stop();
3268 sump += (t2-t1);
3269 }
3270 printf("\nfast poppush: np=%d pop=%d push=%d sumf=%d\n", (n_trials*NTOPOP),
3271 sumt/(n_trials*NTOPOP), sump/(n_trials*NTOPOP), sumf);
3272 sleep(1);
3273 return;
3274 }
3278 void example_fast_poll( PKTIO_HANDLE_T * p_pktio, int max_pkts)
3279 {
3280 int j=0;
3281 int jj=0;
3282 int i,k,l=0,ltot=0;
3283 int n= N2POLL; //max # of pkts to poll
3284 Ti_Pkt * tempVA;
3285 pasahoLongInfo_t* pinfo;
3286 unsigned long t1;
3287 unsigned long t2;
3288 unsigned long t11;
3289 unsigned long t12;
3290 unsigned long np;
3291 unsigned long sumt=0;
3292 unsigned long sumf=0;
3293 unsigned long sump=0;
3294 unsigned long totlen=0;
3295 int max_batch=0;
3297 //this should be done once and saved
3298 Qmss_QueueHnd rxQ= PKTIO_GET_DEFAULT_NETCP_Q(p_pktio);
3299 Qmss_QueueHnd freeQ;
3300 //loop forever
3301 for(;max_pkts>0;)
3302 {
3303 t1= netapi_timing_stop();
3304 pHd[0] = (Ti_Pkt *)QMSS_DESC_PTR(PKTIO_QMSS_QUEUE_POP_RAW (rxQ));
3305 if (!pHd[0]) continue;
3306 //got pkt
3307 for(i=1;(i<n) && (pHd[i-1]);i++)
3308 {
3309 //convert previous descriptor PA -> VA
3310 tempVA = Osal_qmssPhyToVirt(pHd[i-1]);
3312 //try and preload desriptor
3313 __builtin_prefetch(tempVA);
3314 //netapi_pld(tempVA);
3316 //read next descriptor from queue
3317 pHd[i] = (Ti_Pkt *)QMSS_DESC_PTR(PKTIO_QMSS_QUEUE_POP_RAW (rxQ));
3318 #if 1
3319 /* extract some meta data */
3320 Cppi_getData (Cppi_DescType_HOST, (Cppi_Desc*)tempVA, &buf[jj], &len[jj]);
3321 pinfo = nwal_mGetProtoInfo(tempVA);
3322 l3_off[jj]= nwal_mGetL3OffBytes(pinfo);
3323 l4_off[jj]= nwal_mGetL4Offset(pinfo);
3324 if(nwal_mGetAppidFmPkt(tempVA,&appid[jj]) != nwal_TRUE)
3325 {
3326 printf("ERROR!!!! AppID not available in incoming packet \n");
3327 }
3328 //#define VERIFY_SOP
3329 #ifdef VERIFY_SOP
3330 if (sump < 200) printf("..sop off=%d\n", (int) buf[jj]-
3331 (int) ((Cppi_HostDesc *) tempVA)->origBuffPtr) ;
3332 #endif
3333 #endif
3334 jj+=1;
3335 }
3336 //finish last pkt in burst
3337 if(pHd[i-1])
3338 {
3339 //convert previous descriptor PA -> VA
3340 tempVA = Osal_qmssPhyToVirt(pHd[i-1]);
3342 /* extract some meta data */
3343 #if 1
3344 pinfo = nwal_mGetProtoInfo(tempVA);
3345 l3_off[jj]= nwal_mGetL3OffBytes(pinfo);
3346 l4_off[jj]= nwal_mGetL4Offset(pinfo);
3347 if(nwal_mGetAppidFmPkt(tempVA,&appid[jj]) != nwal_TRUE)
3348 {
3349 printf("ERROR!!!! AppID not available in incoming packet \n");
3350 }
3351 #endif
3352 //get ptr (Physical address) and length of associate buffer
3353 Cppi_getData (Cppi_DescType_HOST, (Cppi_Desc*)tempVA, &buf[jj], &len[jj]);
3354 jj+=1;
3355 }
3356 t2= netapi_timing_stop();
3357 j+=(pHd[i-1]? i: (i-1)) ;
3358 if (jj>(M-n)) jj=0;
3359 l+=1; //n batches
3360 ltot+=1;
3361 if(pHd[i-1])
3362 {
3363 if (i>max_batch) max_batch= i;
3364 }
3365 else
3366 {
3367 if( (i-1) >max_batch) max_batch = i-1;
3368 }
3370 //cleanup
3371 //printf("cleanup %d\n",i);
3372 for(k=0;k<i;k++)
3373 {
3374 //cleanup. need to covert all of desriptor to VA so that i can use freePacket()
3375 //alternative would be to just do cache ops plus descriptor raw push to pktlib
3376 // heap free queue
3377 if(pHd[k])
3378 {
3380 //tempVA=Qmss_osalConvertDescPhyToVirt(pHd[k]);
3381 tempVA = Osal_qmssPhyToVirt(pHd[k]);
3382 freeQ=Qmss_getQueueHandle(Cppi_getReturnQueue (Cppi_DescType_HOST, (Cppi_Desc *)tempVA));
3383 netapi_utilCacheWbInv(tempVA,128);
3384 //would need to wbInv buffer also in practice. Also need to walk
3385 // descriptor chain
3386 t11= netapi_timing_stop();
3387 // Pktlib_freePacket(tempVA);
3388 PKTIO_QMSS_QUEUE_PUSH_DESC_SIZE_RAW (freeQ,
3389 (void *) pHd[k],
3390 128);
3392 t12= netapi_timing_stop();
3393 sumf += (t12-t11);
3394 }
3395 }
3396 sumt += (t2-t1);
3397 sump +=(pHd[i-1]? i: (i-1));
3398 max_pkts -= (pHd[i-1]? i: (i-1));
3400 //printf("end cleanup %d %d %d\n",sumt,sumf,sump );
3401 if (sump > 10000) {
3402 printf("pkts rx %d batches=%d appid=%x l3_off=%d l4_off=%d len=%d buf=0x%x rxcycle= %d pkts/batchx1000=%d maxbatch=%d cycles per rawpush = %d\n",
3403 j,ltot, appid[j%M],
3404 l3_off[j%M],l4_off[j%M],
3405 len[j%M],buf[j%M],
3406 sumt/sump, (sump*1000)/l, max_batch,
3407 sumf/sump);
3408 sumt=sump=sumf=0;
3409 l=0;
3410 }
3411 }
3413 //cleanup any remaining buffers
3414 for(;;)
3415 {
3416 pHd[0] = (Ti_Pkt *)QMSS_DESC_PTR(PKTIO_QMSS_QUEUE_POP_RAW (rxQ));
3417 if(!pHd[0]) break;
3418 tempVA = Osal_qmssPhyToVirt(pHd[0]);
3419 freeQ=Qmss_getQueueHandle(Cppi_getReturnQueue (Cppi_DescType_HOST, (Cppi_Desc *)tempVA));
3420 netapi_utilCacheWbInv(tempVA,128);
3421 PKTIO_QMSS_QUEUE_PUSH_DESC_SIZE_RAW (freeQ,
3422 (void *) pHd[0],
3423 128);
3424 }
3425 }
3427 #ifdef EXPERIMENTAL
3429 static inline void send_it(Ti_Pkt *tip, int len, ROUTE_SEC_T * p_sec)
3430 {
3431 unsigned long st1;
3432 unsigned long st2;
3433 int err=0;
3434 PKTIO_METADATA_T meta2 = {PKTIO_META_TX,{0},0};
3435 nwalTxPktInfo_t meta_tx2={0};
3436 st1=netapi_timing_start();
3437 if (len<60)
3438 {
3439 unsigned int templen;
3440 char * p_pkt;
3441 len=60;
3442 Pktlib_getDataBuffer(tip,(uint8_t**)&p_pkt,&templen);//ignore templen
3443 Cppi_setData (Cppi_DescType_HOST, (Cppi_Desc *) tip, p_pkt,len);
3444 stats.tx_min+=1;
3445 }
3446 Pktlib_setPacketLen(tip,len);
3447 meta_tx2.txFlag1 = (NWAL_TX_FLAG1_DO_IPV4_CHKSUM| NWAL_TX_FLAG1_META_DATA_VALID );
3448 meta_tx2.startOffset = 0;
3449 meta_tx2.ipOffBytes = 14;
3450 meta_tx2.ploadLen = len ;
3451 if(p_sec)
3452 {
3453 meta_tx2.txFlag1 |= NWAL_TX_FLAG1_DO_IPSEC_ESP_CRYPTO ;
3454 meta2.sa_handle=p_sec->tx_inflow_mode_handle; //this tells netapi that inflow crypto needs to be applied
3455 meta_tx2.enetPort=0;
3456 meta_tx2.saOffBytes=14+20;
3457 meta_tx2.saPayloadLen=len-14-20; //don't include tag, mac and outer header
3458 stats.sec_tx+=1;
3459 }
3460 meta2.u.tx_meta=&meta_tx2;
3461 pktio_send(netcp_tx_chan,tip,&meta2,&err);
3462 stats.tx +=1;
3463 st2=netapi_timing_start();
3464 stats.send_cycles += (unsigned long long) (st2-st1);
3465 }
3466 void recv_cb_router(struct PKTIO_HANDLE_Tag * channel, Ti_Pkt* p_recv[],
3467 PKTIO_METADATA_T meta[], int n_pkts,
3468 uint64_t ts )
3469 {
3470 int i;
3471 int len;
3472 int p;
3473 Ti_Pkt * tip;
3474 unsigned int templen;
3475 char * p_pkt;
3476 HEAD_T temp_head;
3477 unsigned int appid;
3478 IP_HEAD_T th;
3479 ROUTE_SEC_T *sec_data=NULL;
3480 unsigned long t1;
3481 unsigned long t2;
3482 unsigned long ct1;
3483 unsigned long ct2;
3484 unsigned short ip_pl;
3485 int n_c_ops;
3486 t1=netapi_timing_start();
3487 ct1 =Osal_cache_op_measure(&n_c_ops);
3488 for(i=0;i<n_pkts;i++)
3489 {
3490 tip = p_recv[i];
3491 Pktlib_getDataBuffer(tip,(uint8_t**)&p_pkt,&templen);//ignore templen
3492 len = Pktlib_getPacketLen(tip)-4;//real length, subtract mac trailer
3493 stats.rx+=1;
3494 appid = ((unsigned int)meta[i].u.rx_meta->appId)&0xff000000;
3495 switch(appid)
3496 {
3497 case(NETAPI_NETCP_MATCH_IPSEC):
3498 case(NETAPI_NETCP_MATCH_IPSEC_POLICY):
3499 {
3500 int tailen=12+2;
3501 memcpy(&temp_head,&p_pkt[14],sizeof(HEAD_T));
3502 if (!check_header(&temp_head,&meta[i])) {
3503 stats.n_bad+=1;
3504 Pktlib_freePacket(tip);
3505 continue;
3506 }
3507 tailen+=p_pkt[len-12-2]; //padding length (12)should come from sec_ptr
3508 p_pkt = &p_pkt[8+16+20]; //16= iv len, should come from sec_ptr
3509 len -= (8+16+20+tailen); //16= iv len should come from sec ptr
3511 //now check inner headder.
3512 memcpy(&th,&p_pkt[14],20);
3513 if (!check_header(&temp_head,&meta[i])) {
3514 stats.n_bad+=1;
3515 Pktlib_freePacket(tip);
3516 continue;
3517 }
3518 Cppi_setData (Cppi_DescType_HOST, (Cppi_Desc *) tip, p_pkt,len);
3519 Pktlib_setPacketLen(tip,len);
3521 if (route_pkt(our_router, tip, &th, p_pkt, &len,&sec_data)<0)
3522 {
3523 stats.n_bad+=1;
3524 Pktlib_freePacket(tip);
3525 }
3526 else
3527 {
3528 send_it(tip,len,sec_data);
3529 }
3530 break;
3531 }
3532 case(NETAPI_NETCP_MATCH_GENERIC_MAC):
3533 if((p_pkt[12]!=0x8)||(p_pkt[13]!=0x00))
3534 {
3535 stats.n_new+=1;
3536 Pktlib_freePacket(tip);
3537 continue;
3538 }
3539 if (!check_header(&temp_head,&meta[i]))
3540 {
3541 stats.n_bad+=1;
3542 Pktlib_freePacket(tip);
3543 continue;
3544 }
3545 memcpy(&th,&p_pkt[14],20);
3546 ip_pl= (((unsigned char *)&th.w1)[2]<<8) | ((unsigned char *)&th.w1)[3];
3547 if ((ip_pl+14)<60)
3548 {
3549 len-= (60-(ip_pl+14));
3550 stats.rx_min+=1;
3551 }
3552 Pktlib_setPacketLen(tip,len);
3553 if (route_pkt(our_router, tip, &th, p_pkt, &len,&sec_data)<0)
3554 {
3555 stats.n_bad+=1;
3556 Pktlib_freePacket(tip);
3557 }
3558 else
3559 {
3560 send_it(tip,len,sec_data);
3561 }
3562 break;
3563 case(NETAPI_NETCP_MATCH_GENERIC_IP):
3564 Pktlib_freePacket(tip);
3565 stats.n_new=1;
3566 break;
3567 default:
3568 stats.n_new+=1;
3569 Pktlib_freePacket(tip);
3570 break;
3571 }
3572 }
3573 t2=netapi_timing_start();
3574 ct2 =Osal_cache_op_measure(&n_c_ops);
3575 stats.app_cycles += (unsigned long long) (t2-t1);
3576 stats.tx_cache_cycles += (unsigned long long) (ct2-ct1);
3577 return;
3578 }
3579 #endif