6a550d27524c4105ff1891e34ecdfcd5815194c4
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 NWAL_ENABLE_SA
45 //define this for multi-thread
46 #define MULTI_THREAD
47 #include <stdio.h>
48 #include <stdlib.h>
49 #include <unistd.h>
50 #include <string.h>
51 #include <signal.h>
52 #include <pthread.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 #include "ti/drv/nwal/nwal_util.h"
66 #define TEST_SA
67 //#define TEST_MAC_IP
68 #define SA_CREATE_LOOP_COUNT 64
69 #define IP_CREATE_LOOP_COUNT 64
70 #define MAC_CREATE_LOOP_COUNT 59
72 #ifdef MULTI_THREAD
73 //__thread int our_core;
75 cpu_set_t cpu_set;
76 #endif
78 long htonl(long x)
79 {
80 long temp = (x&0xff000000)>>24 | (x&0xff0000)>>8 | (x&0xff00)<<8 | (x&0xff)<<24 ;
81 return temp;
82 }
84 /* net test default configuration */
85 netTestConfig_t config =
86 {
87 {0x00,0x01,0x02,0x03,0x05,0x05},
88 {0x00,0x01,0x02,0x03,0x05,0x06},
89 {10, 0, 0, 100, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
90 {10, 0, 1, 100, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
91 {10, 0, 2, 100, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
92 {192,168 , 1, 100, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
93 {192,168 , 1, 10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
94 IPSEC_MODE_RX_INFLOW,
95 IPSEC_MODE_TX_INFLOW,
96 0
97 };
99 #if 0
100 netTestConfigMax_t configMax =
101 {
102 {{0x00,0x00,0x02,0x03,0x05,0x07},
103 { 0x00,0x01,0x02,0x03,0x05,0x09}},
104 {{0x00,0x02,0x02,0x03,0x05,0x04},
105 { 0x00,0x03,0x02,0x03,0x05,0x03}},
106 {{0x00,0x04,0x02,0x03,0x05,0x07},
107 { 0x00,0x05,0x02,0x03,0x05,0x09}},
108 {{0x00,0x06,0x02,0x03,0x05,0x04},
109 { 0x00,0x07,0x02,0x03,0x05,0x03}},
110 {{0x00,0x08,0x02,0x03,0x05,0x07},
111 { 0x00,0x09,0x02,0x03,0x05,0x09}},
112 {{0x00,0x0a,0x02,0x03,0x05,0x04},
113 { 0x00,0x0b,0x02,0x03,0x05,0x03}},
114 {{0x00,0x0c,0x02,0x03,0x05,0x07},
115 { 0x00,0x0d,0x02,0x03,0x05,0x09}},
116 {{0x00,0x0e,0x02,0x03,0x05,0x04},
117 { 0x00,0x0f,0x02,0x03,0x05,0x03}},
120 {{0x00,0x10,0x02,0x03,0x05,0x07},
121 { 0x00,0x11,0x02,0x03,0x05,0x09}},
122 {{0x00,0x12,0x02,0x03,0x05,0x04},
123 { 0x00,0x13,0x02,0x03,0x05,0x03}},
124 {{0x00,0x14,0x02,0x03,0x05,0x07},
125 { 0x00,0x15,0x02,0x03,0x05,0x09}},
126 {{0x00,0x16,0x02,0x03,0x05,0x04},
127 { 0x00,0x17,0x02,0x03,0x05,0x03}},
128 {{0x00,0x18,0x02,0x03,0x05,0x07},
129 { 0x00,0x19,0x02,0x03,0x05,0x09}},
130 {{0x00,0x1a,0x02,0x03,0x05,0x04},
131 { 0x00,0x1b,0x02,0x03,0x05,0x03}},
132 {{0x00,0x1c,0x02,0x03,0x05,0x07},
133 { 0x00,0x1d,0x02,0x03,0x05,0x09}},
134 {{0x00,0x1e,0x02,0x03,0x05,0x04},
135 { 0x00,0x1f,0x02,0x03,0x05,0x03}},
137 {{0x00,0x10,0x02,0x03,0x05,0x07},
138 { 0x00,0x11,0x02,0x03,0x05,0x09}},
139 {{0x00,0x12,0x02,0x03,0x05,0x04},
140 { 0x00,0x13,0x02,0x03,0x05,0x03}},
141 {{0x00,0x14,0x02,0x03,0x05,0x07},
142 { 0x00,0x15,0x02,0x03,0x05,0x09}},
143 {{0x00,0x16,0x02,0x03,0x05,0x04},
144 { 0x00,0x17,0x02,0x03,0x05,0x03}},
145 {{0x00,0x18,0x02,0x03,0x05,0x07},
146 { 0x00,0x19,0x02,0x03,0x05,0x09}},
147 {{0x00,0x1a,0x02,0x03,0x05,0x04},
148 { 0x00,0x1b,0x02,0x03,0x05,0x03}},
149 {{0x00,0x1c,0x02,0x03,0x05,0x07},
150 { 0x00,0x1d,0x02,0x03,0x05,0x09}},
151 {{0x00,0x1e,0x02,0x03,0x05,0x04},
152 { 0x00,0x1f,0x02,0x03,0x05,0x03}},
155 {{10, 0, 0, 100, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
156 {10, 0, 1, 100, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}},
157 {{10, 0, 2, 100, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
158 {10, 0, 3, 100, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}},
159 {{10, 0, 4, 100, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
160 {10, 0, 5, 100, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}},
161 {192,168 , 1, 100, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
162 {192,168 , 1, 10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
163 IPSEC_MODE_RX_INFLOW,
164 IPSEC_MODE_TX_INFLOW,
165 0
166 };
167 #endif
172 Trie *p_trie_sa;
174 static int scnt=0;
175 static int QUIT=0;
176 void mysig(int x)
177 {
178 QUIT=1;
179 scnt+=1;
180 printf(">net_test: recv'd signal %d cnt=%d\n",x,scnt);
181 if (scnt > 10) {printf(">net_test: WARNING EXITING WITH PROPER SHUTDOWN, LUTS LEFT ACTIVE\n");exit(1);}
183 }
185 /*******************************************
186 *************NETAPI OBJECTS***************
187 *****************************************/
188 static NETAPI_CFG_T our_netapi_default_cfg=
189 {
190 TUNE_NETAPI_PERM_MEM_SZ,
191 128, //start of packet offset for hw to place data on rx for default flow
192 TUNE_NETAPI_QM_CONFIG_MAX_DESC_NUM, //max number of descriptors in system
193 TUNE_NETAPI_NUM_GLOBAL_DESC, //total we will use
194 TUNE_NETAPI_DEFAULT_NUM_BUFFERS, //#descriptors+buffers in default heap
195 64, //#descriptors w/o buffers in default heap
196 TUNE_NETAPI_DEFAULT_BUFFER_SIZE+128+128, //size of buffers in default heap
197 128 , //tail room
198 256 //extra room
199 };
201 Pktlib_HeapHandle ourHeap;
202 Pktlib_HeapHandle specialSmall;
203 Pktlib_HeapHandle specialLarge;
205 PKTIO_HANDLE_T *our_chan;
206 PKTIO_HANDLE_T *netcp_rx_chan;
207 PKTIO_HANDLE_T *netcp_rx_chan2;
208 PKTIO_HANDLE_T *netcp_tx_chan;
209 PKTIO_HANDLE_T *netcp_sb_tx_chan;
210 PKTIO_HANDLE_T *netcp_sb_rx_chan;
211 PKTIO_CFG_T our_chan_cfg={PKTIO_RW, PKTIO_LOCAL, PKTIO_Q_ANY, 8};
212 PKTIO_CFG_T netcp_rx_cfg={PKTIO_R, PKTIO_NA, PKTIO_NA, 8};
213 PKTIO_CFG_T netcp_rx_cfg2={PKTIO_R, (PKTIO_GLOBAL|PKTIO_PKT), PKTIO_Q_ANY, 8};
214 PKTIO_CFG_T netcp_tx_cfg={PKTIO_W, PKTIO_NA, PKTIO_NA, 8};
215 PKTIO_CFG_T netcp_sb_rx_cfg={PKTIO_R, PKTIO_NA, PKTIO_NA, 8};
216 PKTIO_CFG_T netcp_sb_tx_cfg={PKTIO_W, PKTIO_NA, PKTIO_NA, 8};
218 void house(NETAPI_SCHED_HANDLE_T *s);
219 NETAPI_T netapi_handle;
220 #ifdef MULTI_THREAD
221 NETAPI_SCHED_HANDLE_T * scheduler[TUNE_NETAPI_NUM_CORES];
222 #endif
223 NETAPI_SCHED_HANDLE_T * our_sched;
225 NETAPI_SCHED_CONFIG_T our_sched_cfg={
226 NETAPI_SCHED_DURATION|NETAPI_SCHED_CBV, 0, house, 5000000 //every 5000000 poll loops
227 };
230 NETCP_CFG_IP_T ip_rule0[IP_CREATE_LOOP_COUNT];
231 NETCP_CFG_IP_T ip_rule1[IP_CREATE_LOOP_COUNT];
232 //NETCP_CFG_IP_T ip_rule0;
233 //NETCP_CFG_IP_T ip_rule1;
235 NETCP_CFG_CLASS_T class_0;
236 NETCP_CFG_CLASS_T class_1;
237 NETCP_CFG_CLASS_T class_2;
238 NETCP_CFG_FLOW_HANDLE_T specialFlow;
241 NETCP_CFG_CLASSIFIER_T class_0_cfg=
242 {
243 NETCP_CFG_CLASS_TYPE_L4,
244 {
245 .c_l4={0,0, NWAL_APP_PLOAD_PROTO_UDP, {2500}}
246 }
247 };
249 NETCP_CFG_CLASSIFIER_T class_1_cfg=
250 {
251 NETCP_CFG_CLASS_TYPE_L4,
252 {
253 .c_l4= {0,0, NWAL_APP_PLOAD_PROTO_UDP, {2502}}
254 }
255 };
257 NETCP_CFG_ROUTE_T class2_route=
258 {
259 NULL, NULL //* to be filled in
260 };
261 NETCP_CFG_CLASSIFIER_T class_2_cfg=
262 {
263 NETCP_CFG_CLASS_TYPE_L3_L4,
264 {
265 .c_l3_l4={0, 4 ,0/*fill in below*/ , NULL, NULL, //L2/L3
266 NWAL_APP_PLOAD_PROTO_UDP, {2504}} //L4
267 }
268 };
270 PKTIO_CONTROL_T zap_channel_control={PKTIO_CLEAR, NULL};
272 /* security objects. (for loopback mode) */
273 netTestSA_t sa_info[SA_CREATE_LOOP_COUNT];
275 NETCP_CFG_IPSEC_POLICY_T rx_policy[SA_CREATE_LOOP_COUNT];
279 NETAPI_SEC_SA_INFO_T rx_sa [14] = {
280 {
281 NWAL_SA_DIR_INBOUND,
282 0x11111111, //spi
283 nwal_IpSecProtoESP, //ESP mode
284 nwal_SA_MODE_TUNNEL, //tunnel mode
285 nwal_IPV4, //v4
286 { 1, 2, 3, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, /* Src IP (them) -> set below */
287 { 1, 2, 3, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, /* dst IP (us)-> set below*/
288 64,/* replayWindow */
289 NWAL_SA_AALG_HMAC_SHA1,
290 NWAL_SA_EALG_AES_CBC,
291 0,0 //na
292 },
293 {
294 NWAL_SA_DIR_INBOUND,
295 0x22222222, //spi
296 nwal_IpSecProtoESP, //ESP mode
297 nwal_SA_MODE_TUNNEL, //tunnel mode
298 nwal_IPV4, //v4
299 { 1, 2, 3, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, /* Src IP (them) -> set below */
300 { 1, 2, 3, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, /* dst IP (us)-> set below*/
301 64,/* replayWindow */
302 NWAL_SA_AALG_HMAC_SHA2_256,
303 NWAL_SA_EALG_AES_CTR,
304 0,0 //na
305 },
306 {
307 NWAL_SA_DIR_INBOUND,
308 0x33333333, //spi
309 nwal_IpSecProtoESP, //ESP mode
310 nwal_SA_MODE_TUNNEL, //tunnel mode
311 nwal_IPV4, //v4
312 { 1, 2, 3, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, /* Src IP (them) -> set below */
313 { 1, 2, 3, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, /* dst IP (us)-> set below*/
314 64,/* replayWindow */
315 NWAL_SA_AALG_HMAC_SHA2_256,
316 NWAL_SA_EALG_3DES_CBC,
317 0,0 //na
318 },
319 {
320 NWAL_SA_DIR_INBOUND,
321 0x44444444, //spi
322 nwal_IpSecProtoESP, //ESP mode
323 nwal_SA_MODE_TUNNEL, //tunnel mode
324 nwal_IPV4, //v4
325 { 1, 2, 3, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, /* Src IP (them) -> set below */
326 { 1, 2, 3, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, /* dst IP (us)-> set below*/
327 64,/* replayWindow */
328 NWAL_SA_AALG_HMAC_MD5,
329 NWAL_SA_EALG_NULL,
330 0,0 //na
331 },
332 {
333 NWAL_SA_DIR_INBOUND,
334 0x55555555, //spi
335 nwal_IpSecProtoESP, //ESP mode
336 nwal_SA_MODE_TUNNEL, //tunnel mode
337 nwal_IPV4, //v4
338 { 1, 2, 3, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, /* Src IP (them) -> set below */
339 { 1, 2, 3, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, /* dst IP (us)-> set below*/
340 64,/* replayWindow */
341 NWAL_SA_AALG_NULL,
342 NWAL_SA_EALG_AES_GCM,
343 0,0 //na
344 },
345 {
346 NWAL_SA_DIR_INBOUND,
347 0x66666666, //spi
348 nwal_IpSecProtoESP, //ESP mode
349 nwal_SA_MODE_TUNNEL, //tunnel mode
350 nwal_IPV4, //v4
351 { 1, 2, 3, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, /* Src IP (them) -> set below */
352 { 1, 2, 3, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, /* dst IP (us)-> set below*/
353 64,/* replayWindow */
354 NWAL_SA_AALG_NULL,
355 NWAL_SA_EALG_AES_CCM,
356 0,0 //na
357 },
358 {
359 NWAL_SA_DIR_INBOUND,
360 0x77777777, //spi
361 nwal_IpSecProtoESP, //ESP mode
362 nwal_SA_MODE_TUNNEL, //tunnel mode
363 nwal_IPV4, //v4
364 { 1, 2, 3, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, /* Src IP (them) -> set below */
365 { 1, 2, 3, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, /* dst IP (us)-> set below*/
366 64,/* replayWindow */
367 NWAL_SA_AALG_AES_XCBC,
368 NWAL_SA_EALG_NULL,
369 0,0 //na
370 },
371 {
372 NWAL_SA_DIR_INBOUND,
373 0x91111111, //spi
374 nwal_IpSecProtoESP, //ESP mode
375 nwal_SA_MODE_TUNNEL, //tunnel mode
376 nwal_IPV4, //v4
377 { 1, 2, 3, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, /* Src IP (them) -> set below */
378 { 1, 2, 3, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, /* dst IP (us)-> set below*/
379 64,/* replayWindow */
380 NWAL_SA_AALG_HMAC_SHA1,
381 NWAL_SA_EALG_AES_CBC,
382 0,0 //na
383 },
384 {
385 NWAL_SA_DIR_INBOUND,
386 0x92222222, //spi
387 nwal_IpSecProtoESP, //ESP mode
388 nwal_SA_MODE_TUNNEL, //tunnel mode
389 nwal_IPV4, //v4
390 { 1, 2, 3, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, /* Src IP (them) -> set below */
391 { 1, 2, 3, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, /* dst IP (us)-> set below*/
392 64,/* replayWindow */
393 NWAL_SA_AALG_HMAC_SHA2_256,
394 NWAL_SA_EALG_AES_CTR,
395 0,0 //na
396 },
397 {
398 NWAL_SA_DIR_INBOUND,
399 0x93333333, //spi
400 nwal_IpSecProtoESP, //ESP mode
401 nwal_SA_MODE_TUNNEL, //tunnel mode
402 nwal_IPV4, //v4
403 { 1, 2, 3, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, /* Src IP (them) -> set below */
404 { 1, 2, 3, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, /* dst IP (us)-> set below*/
405 64,/* replayWindow */
406 NWAL_SA_AALG_HMAC_SHA2_256,
407 NWAL_SA_EALG_3DES_CBC,
408 0,0 //na
409 },
410 {
411 NWAL_SA_DIR_INBOUND,
412 0x94444444, //spi
413 nwal_IpSecProtoESP, //ESP mode
414 nwal_SA_MODE_TUNNEL, //tunnel mode
415 nwal_IPV4, //v4
416 { 1, 2, 3, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, /* Src IP (them) -> set below */
417 { 1, 2, 3, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, /* dst IP (us)-> set below*/
418 64,/* replayWindow */
419 NWAL_SA_AALG_HMAC_MD5,
420 NWAL_SA_EALG_NULL,
421 0,0 //na
422 },
423 {
424 NWAL_SA_DIR_INBOUND,
425 0x95555555, //spi
426 nwal_IpSecProtoESP, //ESP mode
427 nwal_SA_MODE_TUNNEL, //tunnel mode
428 nwal_IPV4, //v4
429 { 1, 2, 3, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, /* Src IP (them) -> set below */
430 { 1, 2, 3, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, /* dst IP (us)-> set below*/
431 64,/* replayWindow */
432 NWAL_SA_AALG_NULL,
433 NWAL_SA_EALG_AES_GCM,
434 0,0 //na
435 },
436 {
437 NWAL_SA_DIR_INBOUND,
438 0x96666666, //spi
439 nwal_IpSecProtoESP, //ESP mode
440 nwal_SA_MODE_TUNNEL, //tunnel mode
441 nwal_IPV4, //v4
442 { 1, 2, 3, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, /* Src IP (them) -> set below */
443 { 1, 2, 3, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, /* dst IP (us)-> set below*/
444 64,/* replayWindow */
445 NWAL_SA_AALG_NULL,
446 NWAL_SA_EALG_AES_CCM,
447 0,0 //na
448 },
449 {
450 NWAL_SA_DIR_INBOUND,
451 0x97777777, //spi
452 nwal_IpSecProtoESP, //ESP mode
453 nwal_SA_MODE_TUNNEL, //tunnel mode
454 nwal_IPV4, //v4
455 { 1, 2, 3, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, /* Src IP (them) -> set below */
456 { 1, 2, 3, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, /* dst IP (us)-> set below*/
457 64,/* replayWindow */
458 NWAL_SA_AALG_AES_XCBC,
459 NWAL_SA_EALG_NULL,
460 0,0 //na
461 }
465 };
467 /*tx */
468 NETAPI_SEC_SA_INFO_T tx_sa[14]= {
469 {
470 NWAL_SA_DIR_OUTBOUND,
471 0x11111111, //spi
472 nwal_IpSecProtoESP, //ESP mode
473 nwal_SA_MODE_TUNNEL, //tunnel mode
474 nwal_IPV4, //v4
475 { 1, 2, 3, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, /* Src IP (us) -> set below */
476 { 1, 2, 3, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, /* dst IP (them) -> set below*/
477 64, /* NA replayWindow */
478 NWAL_SA_AALG_HMAC_SHA1,
479 NWAL_SA_EALG_AES_CBC,
480 0,0 //seq no
481 },
482 {
483 NWAL_SA_DIR_OUTBOUND,
484 0x22222222, //spi
485 nwal_IpSecProtoESP, //ESP mode
486 nwal_SA_MODE_TUNNEL, //tunnel mode
487 nwal_IPV4, //v4
488 { 1, 2, 3, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, /* Src IP (us) -> set below */
489 { 1, 2, 3, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, /* dst IP (them) -> set below*/
490 64, /* NA replayWindow */
491 NWAL_SA_AALG_HMAC_SHA2_256,
492 NWAL_SA_EALG_AES_CTR,
493 0,0 //seq no
494 },
495 {
496 NWAL_SA_DIR_OUTBOUND,
497 0x33333333, //spi
498 nwal_IpSecProtoESP, //ESP mode
499 nwal_SA_MODE_TUNNEL, //tunnel mode
500 nwal_IPV4, //v4
501 { 1, 2, 3, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, /* Src IP (us) -> set below */
502 { 1, 2, 3, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, /* dst IP (them) -> set below*/
503 64, /* NA replayWindow */
504 NWAL_SA_AALG_HMAC_SHA2_256,
505 NWAL_SA_EALG_3DES_CBC,
506 0,0 //seq no
507 },
508 {
509 NWAL_SA_DIR_OUTBOUND,
510 0x44444444, //spi
511 nwal_IpSecProtoESP, //ESP mode
512 nwal_SA_MODE_TUNNEL, //tunnel mode
513 nwal_IPV4, //v4
514 { 1, 2, 3, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, /* Src IP (us) -> set below */
515 { 1, 2, 3, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, /* dst IP (them) -> set below*/
516 64, /* NA replayWindow */
517 NWAL_SA_AALG_HMAC_MD5,
518 NWAL_SA_EALG_NULL,
519 },
520 {
521 NWAL_SA_DIR_OUTBOUND,
522 0x55555555, //spi
523 nwal_IpSecProtoESP, //ESP mode
524 nwal_SA_MODE_TUNNEL, //tunnel mode
525 nwal_IPV4, //v4
526 { 1, 2, 3, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, /* Src IP (them) -> set below */
527 { 1, 2, 3, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, /* dst IP (us)-> set below*/
528 64,/* replayWindow */
529 NWAL_SA_AALG_NULL,
530 NWAL_SA_EALG_AES_GCM,
531 0,0 //na
532 },
533 {
534 NWAL_SA_DIR_OUTBOUND,
535 0x66666666, //spi
536 nwal_IpSecProtoESP, //ESP mode
537 nwal_SA_MODE_TUNNEL, //tunnel mode
538 nwal_IPV4, //v4
539 { 1, 2, 3, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, /* Src IP (them) -> set below */
540 { 1, 2, 3, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, /* dst IP (us)-> set below*/
541 64,/* replayWindow */
542 NWAL_SA_AALG_NULL,
543 NWAL_SA_EALG_AES_CCM,
544 0,0 //na
545 },
546 {
547 NWAL_SA_DIR_OUTBOUND,
548 0x77777777, //spi
549 nwal_IpSecProtoESP, //ESP mode
550 nwal_SA_MODE_TUNNEL, //tunnel mode
551 nwal_IPV4, //v4
552 { 1, 2, 3, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, /* Src IP (them) -> set below */
553 { 1, 2, 3, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, /* dst IP (us)-> set below*/
554 64,/* replayWindow */
555 NWAL_SA_AALG_AES_XCBC,
556 NWAL_SA_EALG_NULL,
557 0,0 //na
558 },
559 {
560 NWAL_SA_DIR_OUTBOUND,
561 0x91111111, //spi
562 nwal_IpSecProtoESP, //ESP mode
563 nwal_SA_MODE_TUNNEL, //tunnel mode
564 nwal_IPV4, //v4
565 { 1, 2, 3, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, /* Src IP (us) -> set below */
566 { 1, 2, 3, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, /* dst IP (them) -> set below*/
567 64, /* NA replayWindow */
568 NWAL_SA_AALG_HMAC_SHA1,
569 NWAL_SA_EALG_AES_CBC,
570 0,0 //seq no
571 },
572 {
573 NWAL_SA_DIR_OUTBOUND,
574 0x92222222, //spi
575 nwal_IpSecProtoESP, //ESP mode
576 nwal_SA_MODE_TUNNEL, //tunnel mode
577 nwal_IPV4, //v4
578 { 1, 2, 3, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, /* Src IP (us) -> set below */
579 { 1, 2, 3, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, /* dst IP (them) -> set below*/
580 64, /* NA replayWindow */
581 NWAL_SA_AALG_HMAC_SHA2_256,
582 NWAL_SA_EALG_AES_CTR,
583 0,0 //seq no
584 },
585 {
586 NWAL_SA_DIR_OUTBOUND,
587 0x93333333, //spi
588 nwal_IpSecProtoESP, //ESP mode
589 nwal_SA_MODE_TUNNEL, //tunnel mode
590 nwal_IPV4, //v4
591 { 1, 2, 3, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, /* Src IP (us) -> set below */
592 { 1, 2, 3, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, /* dst IP (them) -> set below*/
593 64, /* NA replayWindow */
594 NWAL_SA_AALG_HMAC_SHA2_256,
595 NWAL_SA_EALG_3DES_CBC,
596 0,0 //seq no
597 },
598 {
599 NWAL_SA_DIR_OUTBOUND,
600 0x94444444, //spi
601 nwal_IpSecProtoESP, //ESP mode
602 nwal_SA_MODE_TUNNEL, //tunnel mode
603 nwal_IPV4, //v4
604 { 1, 2, 3, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, /* Src IP (us) -> set below */
605 { 1, 2, 3, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, /* dst IP (them) -> set below*/
606 64, /* NA replayWindow */
607 NWAL_SA_AALG_HMAC_MD5,
608 NWAL_SA_EALG_NULL,
609 },
610 {
611 NWAL_SA_DIR_OUTBOUND,
612 0x95555555, //spi
613 nwal_IpSecProtoESP, //ESP mode
614 nwal_SA_MODE_TUNNEL, //tunnel mode
615 nwal_IPV4, //v4
616 { 1, 2, 3, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, /* Src IP (them) -> set below */
617 { 1, 2, 3, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, /* dst IP (us)-> set below*/
618 64,/* replayWindow */
619 NWAL_SA_AALG_NULL,
620 NWAL_SA_EALG_AES_GCM,
621 0,0 //na
622 },
623 {
624 NWAL_SA_DIR_OUTBOUND,
625 0x96666666, //spi
626 nwal_IpSecProtoESP, //ESP mode
627 nwal_SA_MODE_TUNNEL, //tunnel mode
628 nwal_IPV4, //v4
629 { 1, 2, 3, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, /* Src IP (them) -> set below */
630 { 1, 2, 3, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, /* dst IP (us)-> set below*/
631 64,/* replayWindow */
632 NWAL_SA_AALG_NULL,
633 NWAL_SA_EALG_AES_CCM,
634 0,0 //na
635 },
636 {
637 NWAL_SA_DIR_OUTBOUND,
638 0x97777777, //spi
639 nwal_IpSecProtoESP, //ESP mode
640 nwal_SA_MODE_TUNNEL, //tunnel mode
641 nwal_IPV4, //v4
642 { 1, 2, 3, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, /* Src IP (them) -> set below */
643 { 1, 2, 3, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, /* dst IP (us)-> set below*/
644 64,/* replayWindow */
645 NWAL_SA_AALG_AES_XCBC,
646 NWAL_SA_EALG_NULL,
647 0,0 //na
648 }
649 };
652 static nwalSecKeyParams_t ourTXKeyParams[14] ={
653 {
654 32, /* encKeySize: CTR 16 bytes Encryption Key and 4 bytes Salt : 24 bytes:NWAL_SA_EALG_3DES_CBC and 0 bytes Salt*/
655 20, /* macKeySize: 16 bytes NWAL_SA_AALG_HMAC_SHA1 */
656 NULL, //set below
657 NULL, //set below
658 },
659 {
660 20, /* encKeySize: CTR 16 bytes Encryption Key and 4 bytes Salt : 24 bytes:NWAL_SA_EALG_AES_CTR and 0 bytes Salt*/
661 32, /* macKeySize: 16 bytes NWAL_SA_AALG_HMAC_SHA2_256 */
662 NULL, //set below
663 NULL, //set below
664 },
665 {
666 24, /* encKeySize: DES-CBC: 24 bytes:NWAL_SA_EALG_3DES_CBC and 0 bytes Salt*/
667 32, /* macKeySize: 16 bytes NWAL_SA_AALG_HMAC_SHA2_256 */
668 NULL, //set below
669 NULL, //set below
670 },
671 {
672 0, /* NULL*/
673 16, /* MD5, 16 bytes */
674 NULL, //set below
675 NULL, //set below
676 },
677 {
678 20, /* encKeySize: GCM 16 bytes Encryption Key and 4 bytes Salt */
679 0, /* macKeySize: 0*/
680 NULL, //set below
681 NULL, //set below
682 },
683 {
684 19, /* encKeySize: CTR 16 bytes Encryption Key and 3 bytes Salt : 24 bytes:NWAL_SA_EALG_AES_CTR and 0 bytes Salt*/
685 0, /* macKeySize 0*/
686 NULL, //set below
687 NULL, //set below
688 },
689 {
690 0, /* encKeySize: CTR 16 bytes Encryption Key and 3 bytes Salt : 24 bytes:NWAL_SA_EALG_AES_CTR and 0 bytes Salt*/
691 16, /* macKeySize 0*/
692 NULL, //set below
693 NULL, //set below
694 },
695 {
696 32, /* encKeySize: CTR 16 bytes Encryption Key and 4 bytes Salt : 24 bytes:NWAL_SA_EALG_3DES_CBC and 0 bytes Salt*/
697 20, /* macKeySize: 16 bytes NWAL_SA_AALG_HMAC_SHA1 */
698 NULL, //set below
699 NULL, //set below
700 },
701 {
702 20, /* encKeySize: CTR 16 bytes Encryption Key and 4 bytes Salt : 24 bytes:NWAL_SA_EALG_AES_CTR and 0 bytes Salt*/
703 32, /* macKeySize: 16 bytes NWAL_SA_AALG_HMAC_SHA2_256 */
704 NULL, //set below
705 NULL, //set below
706 },
707 {
708 24, /* encKeySize: DES-CBC: 24 bytes:NWAL_SA_EALG_3DES_CBC and 0 bytes Salt*/
709 32, /* macKeySize: 16 bytes NWAL_SA_AALG_HMAC_SHA2_256 */
710 NULL, //set below
711 NULL, //set below
712 },
713 {
714 0, /* NULL*/
715 16, /* MD5, 16 bytes */
716 NULL, //set below
717 NULL, //set below
718 },
719 {
720 20, /* encKeySize: GCM 16 bytes Encryption Key and 4 bytes Salt */
721 0, /* macKeySize: 0*/
722 NULL, //set below
723 NULL, //set below
724 },
725 {
726 19, /* encKeySize: CTR 16 bytes Encryption Key and 3 bytes Salt : 24 bytes:NWAL_SA_EALG_AES_CTR and 0 bytes Salt*/
727 0, /* macKeySize 0*/
728 NULL, //set below
729 NULL, //set below
730 },
731 {
732 0, /* encKeySize: CTR 16 bytes Encryption Key and 3 bytes Salt : 24 bytes:NWAL_SA_EALG_AES_CTR and 0 bytes Salt*/
733 16, /* macKeySize 0*/
734 NULL, //set below
735 NULL, //set below
736 }
737 };
739 /* these keys are for aes-ctr and hmac sha2_256 */
740 static nwalSecKeyParams_t ourRXKeyParams[14] ={
741 {
742 32, /* encKeySize: CTR 16 bytes Encryption Key and 4 bytes Salt : 24 bytes:NWAL_SA_EALG_3DES_CBC and 0 bytes Salt*/
743 20, /* macKeySize: 16 bytes NWAL_SA_AALG_HMAC_SHA1 */
744 NULL, //set below
745 NULL, //set below
746 },
747 {
748 20, /* encKeySize: CTR 16 bytes Encryption Key and 4 bytes Salt */
749 32, /* macKeySize: 16 bytes NWAL_SA_AALG_HMAC_SHA2_256 */
750 NULL, //set below
751 NULL, //set below
752 },
753 {
754 24, /* encKeySize: DES-CBC: 24 bytes:NWAL_SA_EALG_3DES_CBC and 0 bytes Salt*/
755 32, /* macKeySize: 16 bytes NWAL_SA_AALG_HMAC_SHA2_256 */
756 NULL, //set below
757 NULL, //set below
758 },
759 {
760 0, /* NWAL_SA_EALG_NULL*/
761 16, /* NWAL_SA_AALG_HMAC_MD5, 16 bytes */
762 NULL, //set below
763 NULL, //set below
764 },
765 {
766 20, /* encKeySize: GCM 16 bytes Encryption Key and 4 bytes Salt */
767 0, /* macKeySize: 0*/
768 NULL, //set below
769 NULL, //set below
770 },
771 {
772 19, /* encKeySize: CTR 16 bytes Encryption Key and 3 bytes Salt t*/
773 0, /* macKeySize 0*/
774 NULL, //set below
775 NULL, //set below
776 },
777 {
778 0, /* encKeySize: CTR 16 bytes Encryption Key and 3 bytes Salt : 24 bytes:NWAL_SA_EALG_AES_CTR and 0 bytes Salt*/
779 16, /* macKeySize 0*/
780 NULL, //set below
781 NULL, //set below
782 },
783 {
784 32, /* encKeySize: CTR 16 bytes Encryption Key and 4 bytes Salt : 24 bytes:NWAL_SA_EALG_3DES_CBC and 0 bytes Salt*/
785 20, /* macKeySize: 16 bytes NWAL_SA_AALG_HMAC_SHA1 */
786 NULL, //set below
787 NULL, //set below
788 },
789 {
790 20, /* encKeySize: CTR 16 bytes Encryption Key and 4 bytes Salt */
791 32, /* macKeySize: 16 bytes NWAL_SA_AALG_HMAC_SHA2_256 */
792 NULL, //set below
793 NULL, //set below
794 },
795 {
796 24, /* encKeySize: DES-CBC: 24 bytes:NWAL_SA_EALG_3DES_CBC and 0 bytes Salt*/
797 32, /* macKeySize: 16 bytes NWAL_SA_AALG_HMAC_SHA2_256 */
798 NULL, //set below
799 NULL, //set below
800 },
801 {
802 0, /* NWAL_SA_EALG_NULL*/
803 16, /* NWAL_SA_AALG_HMAC_MD5, 16 bytes */
804 NULL, //set below
805 NULL, //set below
806 },
807 {
808 20, /* encKeySize: GCM 16 bytes Encryption Key and 4 bytes Salt */
809 0, /* macKeySize: 0*/
810 NULL, //set below
811 NULL, //set below
812 },
813 {
814 19, /* encKeySize: CTR 16 bytes Encryption Key and 3 bytes Salt t*/
815 0, /* macKeySize 0*/
816 NULL, //set below
817 NULL, //set below
818 },
819 {
820 0, /* encKeySize: CTR 16 bytes Encryption Key and 3 bytes Salt : 24 bytes:NWAL_SA_EALG_AES_CTR and 0 bytes Salt*/
821 16, /* macKeySize 0*/
822 NULL, //set below
823 NULL, //set below
824 }
825 };
828 static uint8_t ourAuthKey[36] =
829 {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F,
830 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F,
831 0x20, 0x21, 0x22, 0x23 };
832 ;
834 static uint8_t ourEncrKey[36] =
835 {0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0xFF,
836 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0xFF,
837 0x30, 0x31, 0x32, 0x33 };
840 hplib_atomic32_T spi = hplib_mAtomic32Init(0x11111111);
842 /*************************END NETAPI OBJECTS***********************/
844 #define START_SRC_IP 0x0a00000a
845 #define DST_IP 0xc0a80001
846 #define NEW_START_SRC_IP 0x9eda000a
847 #define DST_PORT 0x555
848 #define START_SRC_PORT 0x1234
849 #define NEW_START_SRC_PORT 100
850 void update_header(HEAD_T * p_head, int len)
851 {
852 unsigned char *p = (unsigned char *) &p_head->udp[1];
853 len -= (20+14);
854 /* update ip checksum */
855 /* update udp checksum */
856 /* update length */
857 *p= (len&0xff00)>>8;
858 *(p+1) = len&0xff;
859 }
861 //===========stub transmitter==================
862 void send_pkt(Ti_Pkt *pkt, int len)
863 {
864 //just free pkt. Don't send
865 Pktlib_freePacket((Ti_Pkt*)pkt);
866 return;
867 }
870 /* check header */
871 struct LastPktInfo
872 {
873 int iface;
874 int ipcsum;
875 int l4csum;
876 } ;
877 static struct LastPktInfo lpInfo;
880 void recv_cb_bench(struct PKTIO_HANDLE_Tag * channel, Ti_Pkt* p_recv[],
881 PKTIO_METADATA_T meta[], int n_pkts,
882 uint64_t ts )
883 {
884 }
886 /****************************************************************************************/
887 /******************SB Accelerator Callback PKT RECEIVE HANDLER *************************/
888 /****************** Handles Decrypt and Encrypt operation callbacks ******************/
889 /******************************************************************************************/
890 void recv_sb_cb(struct PKTIO_HANDLE_Tag * channel, Ti_Pkt* p_recv[],
891 PKTIO_METADATA_T meta[], int n_pkts,
892 uint64_t ts )
893 {
894 }
896 /******************************************************/
897 /******************PKT RECEIVE HANDLER *************************/
898 /******************************************************/
899 void recv_cb(struct PKTIO_HANDLE_Tag * channel, Ti_Pkt* p_recv[],
900 PKTIO_METADATA_T meta[], int n_pkts,
901 uint64_t ts )
902 {
903 }
905 //******************************************************
906 //use scheduling housekeeping callback to generate pkts
907 //******************************************************
908 static int done_burst=0;
909 void house(NETAPI_SCHED_HANDLE_T * s)
910 {
911 int err;
912 if (QUIT) {netapi_schedShutdown(s,NULL,&err); return;}
913 }
915 void build_sa_db(int i)
916 {
917 int coreid = Osal_nwalGetProcId();
918 long tmp_spi;
919 //static uint32_t spi = 11111111;
920 if ((tx_sa[0].authMode == NWAL_SA_AALG_HMAC_SHA1) && (tx_sa[0].cipherMode == NWAL_SA_EALG_AES_CBC))
921 {
923 tx_sa[0].spi = rx_sa[0].spi = hplib_mAtomic32AddReturn(&spi,1);
924 printf("coreid: %d, build_sa_db: spi %d\n", coreid, spi);
925 /* static configuration, will not change */
926 sa_info[i].tx_payload_info.aadSize = 0;
927 sa_info[i].tx_payload_info.pAad = NULL;
928 sa_info[i].tx_payload_info.pAuthIV = NULL;
929 sa_info[i].tx_payload_info.authOffset = netTest_MAC_HEADER_LEN + netTest_IP_HEADER_LEN; /*done: same for all cipher suites */
930 sa_info[i].tx_payload_info.encOffset = netTest_MAC_HEADER_LEN +
931 netTest_IP_HEADER_LEN +
932 netTest_ESP_HEADER_LEN +
933 netTest_AES_CBC_IV_LEN;
935 /* dynamic configuration, will be calculated on the fly */
936 sa_info[i].tx_payload_info.authSize = 0; /* pkt len - mac - ip -icv (12) */
937 sa_info[i].tx_payload_info.encSize = 0; /* authSize - esp header size (always 8 bytes) */
938 sa_info[i].tx_payload_info.pEncIV = 0;
939 sa_info[i].tx_payload_info.pPkt = 0; /* not being referenced in net_test */
941 sa_info[i].cipherMode = NWAL_SA_EALG_AES_CBC;
942 sa_info[i].inner_ip_offset = sa_info[i].tx_payload_info.encOffset;
943 sa_info[i].auth_tag_size = netTest_ICV_LEN; /* icv or mac size,. always 12 except for AES_CCM/AES_GCM */
945 sa_info[i].tx_pkt_info.enetPort = 0;
946 sa_info[i].tx_pkt_info.ipOffBytes = sa_info[i].tx_payload_info.encOffset;
947 sa_info[i].tx_pkt_info.l4HdrLen = netTest_UDP_HEADER_LEN; /*UDP header len */
948 sa_info[i].tx_pkt_info.l4OffBytes = sa_info[i].inner_ip_offset + netTest_IP_HEADER_LEN;
949 sa_info[i].tx_pkt_info.startOffset = 0;
950 sa_info[i].tx_pkt_info.lpbackPass = 0;
951 sa_info[i].tx_pkt_info.ploadLen = 0; /*sa_info[i].tx_pkt_info.l4OffBytes + 4 */
952 sa_info[i].tx_pkt_info.pPkt = NULL;
953 sa_info[i].tx_pkt_info.saOffBytes = netTest_MAC_HEADER_LEN + netTest_IP_HEADER_LEN;
954 sa_info[i].tx_pkt_info.saPayloadLen = 0;
955 sa_info[i].tx_pkt_info.pseudoHdrChecksum =0;
957 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 ;
959 tmp_spi = htonl((long)(tx_sa[0].spi));
960 trie_insert(p_trie_sa,(char *)&tmp_spi,4, (void *) &sa_info[i]); //asociate with tx sa SPI
963 }
964 else if ((tx_sa[i].authMode == NWAL_SA_AALG_HMAC_SHA2_256) && (tx_sa[i].cipherMode == NWAL_SA_EALG_AES_CTR))
965 {
966 tx_sa[i].spi = rx_sa[i].spi = hplib_mAtomic32AddReturn(&spi,1);
967 /* static configuration, will not change */
968 sa_info[i].tx_payload_info.aadSize = 0;
969 sa_info[i].tx_payload_info.pAad = NULL;
970 sa_info[i].tx_payload_info.pAuthIV = NULL;
971 sa_info[i].tx_payload_info.authOffset = netTest_MAC_HEADER_LEN + netTest_IP_HEADER_LEN; /*done: same for all cipher suites */
972 sa_info[i].tx_payload_info.encOffset = netTest_MAC_HEADER_LEN +
973 netTest_IP_HEADER_LEN +
974 netTest_ESP_HEADER_LEN +
975 netTest_AES_CTR_IV_LEN;
980 /* dynamic configuration, will be calculated on the fly */
981 sa_info[i].tx_payload_info.authSize = 0;
982 sa_info[i].tx_payload_info.encSize = 0;
983 sa_info[i].tx_payload_info.pEncIV = 0;
984 sa_info[i].tx_payload_info.pPkt = 0;
986 sa_info[i].cipherMode = NWAL_SA_EALG_AES_CTR;
987 sa_info[i].inner_ip_offset = sa_info[i].tx_payload_info.encOffset;
988 sa_info[i].auth_tag_size = netTest_ICV_LEN; /* icv or mac size,. always 12 except for AES_CCM/AES_GCM */
991 sa_info[i].tx_pkt_info.enetPort = 0;
992 sa_info[i].tx_pkt_info.ipOffBytes = sa_info[i].tx_payload_info.encOffset;
993 sa_info[i].tx_pkt_info.l4HdrLen = netTest_UDP_HEADER_LEN; /*UDP header len */
994 sa_info[i].tx_pkt_info.l4OffBytes = sa_info[i].inner_ip_offset + netTest_IP_HEADER_LEN;
995 sa_info[i].tx_pkt_info.startOffset = 0;
996 sa_info[i].tx_pkt_info.lpbackPass = 0;
997 sa_info[i].tx_pkt_info.ploadLen = 0; /*sa_info[i].tx_pkt_info.l4OffBytes + 4 */
998 sa_info[i].tx_pkt_info.pPkt = NULL;
999 sa_info[i].tx_pkt_info.saOffBytes = netTest_MAC_HEADER_LEN + netTest_IP_HEADER_LEN;
1000 sa_info[i].tx_pkt_info.saPayloadLen = 0;
1001 sa_info[i].tx_pkt_info.pseudoHdrChecksum =0;
1003 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 ;
1004 tmp_spi = htonl((long)(tx_sa[i].spi));
1005 trie_insert(p_trie_sa,(char *)&tmp_spi,4, (void *) &sa_info[i]); //asociate with tx sa SPI
1006 }
1007 else if ((tx_sa[i].authMode == NWAL_SA_AALG_HMAC_SHA2_256) && (tx_sa[i].cipherMode == NWAL_SA_EALG_3DES_CBC))
1008 {
1009 tx_sa[i].spi = rx_sa[i].spi = hplib_mAtomic32AddReturn(&spi,1);
1010 /* static configuration, will not change */
1011 sa_info[i].tx_payload_info.aadSize = 0;
1012 sa_info[i].tx_payload_info.pAad = NULL;
1013 sa_info[i].tx_payload_info.pAuthIV = NULL;
1014 sa_info[i].tx_payload_info.authOffset = netTest_MAC_HEADER_LEN + netTest_IP_HEADER_LEN; /*done: same for all cipher suites */
1015 sa_info[i].tx_payload_info.encOffset = netTest_MAC_HEADER_LEN +
1016 netTest_IP_HEADER_LEN +
1017 netTest_ESP_HEADER_LEN +
1018 netTest_3DES_CBC_IV_LEN;
1020 /* dynamic configuration, will be calculated on the fly */
1021 sa_info[i].tx_payload_info.authSize = 0;
1022 sa_info[i].tx_payload_info.encSize = 0;
1023 sa_info[i].tx_payload_info.pEncIV = 0;
1024 sa_info[i].tx_payload_info.pPkt = 0;
1026 sa_info[i].cipherMode = NWAL_SA_EALG_3DES_CBC;
1027 sa_info[i].inner_ip_offset = sa_info[i].tx_payload_info.encOffset;
1028 sa_info[i].auth_tag_size = netTest_ICV_LEN; /* icv or mac size,. always 12 except for AES_CCM/AES_GCM */
1031 sa_info[i].tx_pkt_info.enetPort = 0;
1032 sa_info[i].tx_pkt_info.ipOffBytes = sa_info[i].tx_payload_info.encOffset;
1033 sa_info[i].tx_pkt_info.l4HdrLen = netTest_UDP_HEADER_LEN; /*UDP header len */
1034 sa_info[i].tx_pkt_info.l4OffBytes = sa_info[i].inner_ip_offset + netTest_IP_HEADER_LEN;
1035 sa_info[i].tx_pkt_info.startOffset = 0;
1036 sa_info[i].tx_pkt_info.lpbackPass = 0;
1037 sa_info[i].tx_pkt_info.ploadLen = 0; /*sa_info[i].tx_pkt_info.l4OffBytes + 4 */
1038 sa_info[i].tx_pkt_info.pPkt = NULL;
1039 sa_info[i].tx_pkt_info.saOffBytes = netTest_MAC_HEADER_LEN + netTest_IP_HEADER_LEN;
1040 sa_info[i].tx_pkt_info.saPayloadLen = 0;
1041 sa_info[i].tx_pkt_info.pseudoHdrChecksum =0;
1043 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 ;
1045 tmp_spi = htonl((long)(tx_sa[i].spi));
1046 trie_insert(p_trie_sa,(char *)&tmp_spi,4, (void *) &sa_info[i]); //asociate with tx sa SPI
1047 }
1048 else if ((tx_sa[i].authMode == NWAL_SA_AALG_HMAC_MD5) && (rx_sa[i].cipherMode == NWAL_SA_EALG_NULL))
1049 {
1050 tx_sa[i].spi = rx_sa[i].spi = hplib_mAtomic32AddReturn(&spi,1);
1051 /* static configuration, will not change */
1052 sa_info[i].tx_payload_info.aadSize = 0;
1053 sa_info[i].tx_payload_info.pAad = NULL;
1054 sa_info[i].tx_payload_info.pAuthIV = NULL;
1055 sa_info[i].tx_payload_info.authOffset = netTest_MAC_HEADER_LEN + netTest_IP_HEADER_LEN; /*done: same for all cipher suites */
1057 sa_info[i].tx_payload_info.encOffset = netTest_MAC_HEADER_LEN +
1058 netTest_IP_HEADER_LEN +
1059 netTest_ESP_HEADER_LEN +
1060 netTest_NULL_IV_LEN;
1064 /* dynamic configuration, will be calculated on the fly */
1065 sa_info[i].tx_payload_info.authSize = 0;
1066 sa_info[i].tx_payload_info.encSize = 0;
1067 sa_info[i].tx_payload_info.pEncIV = 0;
1068 sa_info[i].tx_payload_info.pPkt = 0;
1070 sa_info[i].cipherMode = NWAL_SA_EALG_NULL;
1071 sa_info[i].inner_ip_offset = sa_info[i].tx_payload_info.encOffset;
1072 sa_info[i].auth_tag_size = netTest_ICV_LEN; /* icv or mac size,. always 12 except for AES_CCM/AES_GCM */
1074 sa_info[i].tx_pkt_info.enetPort = 0;
1075 sa_info[i].tx_pkt_info.ipOffBytes = sa_info[i].tx_payload_info.encOffset;
1076 sa_info[i].tx_pkt_info.l4HdrLen = netTest_UDP_HEADER_LEN; /*UDP header len */
1077 sa_info[i].tx_pkt_info.l4OffBytes = sa_info[i].inner_ip_offset + netTest_IP_HEADER_LEN;
1078 sa_info[i].tx_pkt_info.startOffset = 0;
1079 sa_info[i].tx_pkt_info.lpbackPass = 0;
1080 sa_info[i].tx_pkt_info.ploadLen = 0; /*sa_info[i].tx_pkt_info.l4OffBytes + 4 */
1081 sa_info[i].tx_pkt_info.pPkt = NULL;
1082 sa_info[i].tx_pkt_info.saOffBytes = netTest_MAC_HEADER_LEN + netTest_IP_HEADER_LEN;
1083 sa_info[i].tx_pkt_info.saPayloadLen = 0;
1084 sa_info[i].tx_pkt_info.pseudoHdrChecksum =0;
1086 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 ;
1087 tmp_spi = htonl((long)(tx_sa[i].spi));
1088 trie_insert(p_trie_sa,(char *)&tmp_spi,4, (void *) &sa_info[i]); //asociate with tx sa SPI
1089 }
1090 else if ((tx_sa[i].authMode == NWAL_SA_AALG_NULL) && (rx_sa[i].cipherMode == NWAL_SA_EALG_AES_GCM))
1091 {
1092 tx_sa[i].spi = rx_sa[i].spi = hplib_mAtomic32AddReturn(&spi,1);
1093 /* static configuration, will not change */
1094 sa_info[i].tx_payload_info.aadSize = 0;
1095 sa_info[i].tx_payload_info.pAad = NULL;
1096 sa_info[i].tx_payload_info.pAuthIV = NULL;
1097 sa_info[i].tx_payload_info.authOffset = netTest_MAC_HEADER_LEN + netTest_IP_HEADER_LEN; /*done: same for all cipher suites */
1098 //sa_info[i].tx_payload_info.encIvSize = netTest_AES_GCM_IV_LEN;
1100 sa_info[i].tx_payload_info.encOffset = netTest_MAC_HEADER_LEN +
1101 netTest_IP_HEADER_LEN +
1102 netTest_ESP_HEADER_LEN +
1103 netTest_AES_GCM_IV_LEN;
1107 /* dynamic configuration, will be calculated on the fly */
1108 sa_info[i].tx_payload_info.authSize = 0;
1109 sa_info[i].tx_payload_info.encSize = 0;
1110 //sa_info[i].tx_payload_info.ploadLen = 0;
1111 sa_info[i].tx_payload_info.pEncIV = 0;
1112 sa_info[i].tx_payload_info.pPkt = 0;
1114 sa_info[i].cipherMode = NWAL_SA_EALG_AES_GCM;
1115 sa_info[i].inner_ip_offset = sa_info[i].tx_payload_info.encOffset;
1116 sa_info[i].auth_tag_size = netTest_AES_GCM_CCM_ICV_LEN; /* icv or mac size,. always 12 except for AES_CCM/AES_GCM */
1118 sa_info[i].tx_pkt_info.enetPort = 0;
1119 sa_info[i].tx_pkt_info.ipOffBytes = sa_info[i].tx_payload_info.encOffset;
1120 sa_info[i].tx_pkt_info.l4HdrLen = netTest_UDP_HEADER_LEN; /*UDP header len */
1121 sa_info[i].tx_pkt_info.l4OffBytes = sa_info[i].inner_ip_offset + netTest_IP_HEADER_LEN;
1122 sa_info[i].tx_pkt_info.startOffset = 0;
1123 sa_info[i].tx_pkt_info.lpbackPass = 0;
1124 sa_info[i].tx_pkt_info.ploadLen = 0; /*sa_info[i].tx_pkt_info.l4OffBytes + 4 */
1125 sa_info[i].tx_pkt_info.pPkt = NULL;
1126 sa_info[i].tx_pkt_info.saOffBytes = netTest_MAC_HEADER_LEN + netTest_IP_HEADER_LEN;
1127 sa_info[i].tx_pkt_info.saPayloadLen = 0;
1128 sa_info[i].tx_pkt_info.pseudoHdrChecksum =0;
1130 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 ;
1132 tmp_spi = htonl((long)(tx_sa[i].spi));
1133 trie_insert(p_trie_sa,(char *)&tmp_spi,4, (void *) &sa_info[i]); //asociate with tx sa SPI
1134 }
1135 else if ((tx_sa[i].authMode == NWAL_SA_AALG_NULL) && (rx_sa[i].cipherMode == NWAL_SA_EALG_AES_CCM))
1136 {
1137 tx_sa[i].spi = rx_sa[i].spi = hplib_mAtomic32AddReturn(&spi,1);
1138 /* static configuration, will not change */
1139 sa_info[i].tx_payload_info.aadSize = 0;
1140 sa_info[i].tx_payload_info.pAad = NULL;
1141 //sa_info[i].tx_payload_info.authIvSize = 0;
1142 sa_info[i].tx_payload_info.pAuthIV = NULL;
1143 sa_info[i].tx_payload_info.authOffset = netTest_MAC_HEADER_LEN + netTest_IP_HEADER_LEN; /*done: same for all cipher suites */
1145 sa_info[i].tx_payload_info.encOffset = netTest_MAC_HEADER_LEN +
1146 netTest_IP_HEADER_LEN +
1147 netTest_ESP_HEADER_LEN +
1148 netTest_AES_CCM_IV_LEN;
1150 /* dynamic configuration, will be calculated on the fly */
1151 sa_info[i].tx_payload_info.authSize = 0;
1152 sa_info[i].tx_payload_info.encSize = 0;
1153 //sa_info[i].tx_payload_info.ploadLen = 0;
1154 sa_info[i].tx_payload_info.pEncIV = 0;
1155 sa_info[i].tx_payload_info.pPkt = 0;
1157 sa_info[i].cipherMode = NWAL_SA_EALG_AES_CCM;
1158 sa_info[i].inner_ip_offset = sa_info[i].tx_payload_info.encOffset;
1159 sa_info[i].auth_tag_size = netTest_AES_GCM_CCM_ICV_LEN; /* icv or mac size,. always 12 except for AES_CCM/AES_GCM */
1161 sa_info[i].tx_pkt_info.enetPort = 0;
1162 sa_info[i].tx_pkt_info.ipOffBytes = sa_info[i].tx_payload_info.encOffset;
1163 sa_info[i].tx_pkt_info.l4HdrLen = netTest_UDP_HEADER_LEN; /*UDP header len */
1164 sa_info[i].tx_pkt_info.l4OffBytes = sa_info[i].inner_ip_offset + netTest_IP_HEADER_LEN;
1165 sa_info[i].tx_pkt_info.startOffset = 0;
1166 sa_info[i].tx_pkt_info.lpbackPass = 0;
1167 sa_info[i].tx_pkt_info.ploadLen = 0; /*sa_info[i].tx_pkt_info.l4OffBytes + 4 */
1168 sa_info[i].tx_pkt_info.pPkt = NULL;
1169 sa_info[i].tx_pkt_info.saOffBytes = netTest_MAC_HEADER_LEN + netTest_IP_HEADER_LEN;
1170 sa_info[i].tx_pkt_info.saPayloadLen = 0;
1171 sa_info[i].tx_pkt_info.pseudoHdrChecksum =0;
1173 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 ;
1175 tmp_spi = htonl((long)(tx_sa[i].spi));
1176 trie_insert(p_trie_sa,(char *)&tmp_spi,4, (void *) &sa_info[i]); //asociate with tx sa SPI
1177 }
1178 else if ((tx_sa[i].authMode == NWAL_SA_AALG_AES_XCBC) && (rx_sa[i].cipherMode == NWAL_SA_EALG_NULL))
1179 {
1180 tx_sa[i].spi = rx_sa[i].spi = hplib_mAtomic32AddReturn(&spi,1);
1181 /* static configuration, will not change */
1182 sa_info[i].tx_payload_info.aadSize = 0;
1183 sa_info[i].tx_payload_info.pAad = NULL;
1184 sa_info[i].tx_payload_info.pAuthIV = NULL;
1185 sa_info[i].tx_payload_info.authOffset = netTest_MAC_HEADER_LEN + netTest_IP_HEADER_LEN;
1188 sa_info[i].tx_payload_info.encOffset = netTest_MAC_HEADER_LEN +
1189 netTest_IP_HEADER_LEN +
1190 netTest_ESP_HEADER_LEN +
1191 netTest_NULL_IV_LEN;
1193 /* dynamic configuration, will be calculated on the fly */
1194 sa_info[i].tx_payload_info.authSize = 0;
1195 sa_info[i].tx_payload_info.encSize = 0;
1196 //sa_info[i].tx_payload_info.ploadLen = 0;
1197 sa_info[i].tx_payload_info.pEncIV = 0;
1198 sa_info[i].tx_payload_info.pPkt = 0;
1200 sa_info[i].cipherMode = NWAL_SA_EALG_NULL;
1201 sa_info[i].authMode = NWAL_SA_AALG_AES_XCBC;
1202 sa_info[i].inner_ip_offset = sa_info[i].tx_payload_info.encOffset;
1203 sa_info[i].auth_tag_size = netTest_ICV_LEN; /* icv or mac size,. always 12 except for AES_CCM/AES_GCM , GMAC*/
1205 sa_info[i].tx_pkt_info.enetPort = 0;
1206 sa_info[i].tx_pkt_info.ipOffBytes = sa_info[i].tx_payload_info.encOffset;
1207 sa_info[i].tx_pkt_info.l4HdrLen = netTest_UDP_HEADER_LEN; /*UDP header len */
1208 sa_info[i].tx_pkt_info.l4OffBytes = sa_info[i].inner_ip_offset + netTest_IP_HEADER_LEN;
1209 sa_info[i].tx_pkt_info.startOffset = 0;
1210 sa_info[i].tx_pkt_info.lpbackPass = 0;
1211 sa_info[i].tx_pkt_info.ploadLen = 0; /*sa_info[i].tx_pkt_info.l4OffBytes + 4 */
1212 sa_info[i].tx_pkt_info.pPkt = NULL;
1213 sa_info[i].tx_pkt_info.saOffBytes = netTest_MAC_HEADER_LEN + netTest_IP_HEADER_LEN;
1214 sa_info[i].tx_pkt_info.saPayloadLen = 0;
1215 sa_info[i].tx_pkt_info.pseudoHdrChecksum =0;
1217 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 ;
1219 tmp_spi = htonl((long)(tx_sa[i].spi));
1220 trie_insert(p_trie_sa,(char *)&tmp_spi,4, (void *) &sa_info[i]); //asociate with tx sa SPI
1221 }
1222 else
1223 printf("build_sa_db(): invalid encryption/authentication combination selected\n");
1225 }
1229 #ifdef MULTI_THREAD
1230 NETAPI_T worker_nh[TUNE_NETAPI_NUM_CORES];
1231 void slow_path_thread(int coreid)
1232 {
1233 int err, i, count=0;
1235 PKTIO_HANDLE_T *our_chan;
1236 PKTIO_HANDLE_T *rx_chan;
1237 PKTIO_HANDLE_T *tx_chan;
1238 PKTIO_HANDLE_T *sb_tx_chan;
1239 PKTIO_HANDLE_T *sb_rx_chan;
1243 printf("slow_path_thread, mypid: %d, core_id %d\n", gettid(), coreid);
1245 CPU_ZERO( &cpu_set);
1246 #ifdef CORTEX_A15
1247 CPU_SET( coreid, &cpu_set);
1248 hplib_utilSetupCore(coreid, &cpu_set);
1249 #else
1250 CPU_SET( 0, &cpu_set);
1251 hplib_utilSetupCore(coreid+1, &cpu_set);
1252 #endif
1253 worker_nh[coreid]=netapi_init(NETAPI_CORE_MASTER,NULL);
1256 NETAPI_HANDLE_T * n = (NETAPI_HANDLE_T *) worker_nh[coreid];
1258 /* open netcp default tx, rx queues */
1259 tx_chan = pktio_open(worker_nh[coreid], NETCP_TX, NULL, &netcp_tx_cfg, &err);
1262 #ifdef EXPERIMENTAL
1263 rx_chan = pktio_open(worker_nh[coreid], NETCP_RX, (PKTIO_CB) recv_cb_router, &netcp_rx_cfg, &err);
1264 #else
1265 rx_chan = pktio_open(worker_nh[coreid], NETCP_RX, (PKTIO_CB) recv_cb, &netcp_rx_cfg, &err);
1266 #endif
1268 #ifndef EXPERIMENTAL
1269 /* create a pktio channel for specially classified pkts */
1270 /* open netcp default tx, rx queues for sideband crypto */
1271 sb_tx_chan = pktio_open(worker_nh[coreid], NETCP_SB_TX, NULL, &netcp_sb_tx_cfg, &err);
1273 sb_rx_chan = pktio_open(worker_nh[coreid], NETCP_SB_RX, (PKTIO_CB) recv_sb_cb, &netcp_sb_rx_cfg, &err);
1274 #endif
1280 netapi_setCookie(worker_nh[coreid],coreid);
1281 //our_core = coreid;
1283 scheduler[coreid] =netapi_schedOpen(worker_nh[coreid],&our_sched_cfg, &err);
1284 if (!scheduler[coreid])
1285 {
1286 printf("sched create failed for core%d\n",coreid);
1287 exit(1);
1288 }
1289 scheduler[coreid]->config.yield = FALSE;
1290 scheduler[coreid]->config.pollGarbageQ = TRUE;
1291 scheduler[coreid]->config.pollCtrlQ = TRUE;
1292 /*********************************************/
1293 /**************Entry point into scheduler ****/
1294 /*********************************************/
1296 #ifdef TEST_MAC_IP
1297 for (i = 0; i < 30 ;i++)
1298 {
1299 /* add mac intefaces */
1300 netcp_cfgCreateMacInterface(
1301 worker_nh[coreid],
1302 &config.mac0[0],
1303 i,0,
1304 (NETCP_CFG_ROUTE_HANDLE_T) NULL,
1305 (NETCP_CFG_VLAN_T ) NULL , //future
1306 1,
1307 &err);
1308 if (err) {printf("addmac0 failed %d\n",err); exit(1); }
1309 else
1310 {
1311 printf("addmac0 passed for index %d, mac before %d\n",i, config.mac0[5]);
1312 config.mac0[3]++;
1313 }
1314 }
1316 for (i = 0; i < 30 ;i++)
1317 {
1318 //attach an IP to this interface
1319 ip_rule0[i]=netcp_cfgAddIp(
1320 worker_nh[coreid],
1321 0,
1322 nwal_IPV4,
1323 &config.ip0,
1324 NULL, //all IP
1325 (NETCP_CFG_ROUTE_HANDLE_T) NULL,
1326 &err
1327 );
1328 if (err) {printf("addip0 failed %d\n",err); exit(1); }
1329 else
1330 {
1331 printf("addip0 passed for index%d ip[3] %d\n",i, config.ip0.ipv4[3]);
1332 config.ip0.ipv4[3]++;
1333 }
1335 }
1336 sleep(1);
1337 //delete IPs and MAC Interfacess
1338 for (i = 0; i < 30;i++)
1339 {
1340 printf("calling netcp_cfgDelIp and for index %d\n", i);
1341 netcp_cfgDelIp(worker_nh[coreid], i, 0, NULL, NULL, ip_rule0[i], &err);
1342 netcp_cfgDelMac(worker_nh[coreid],i,&err);
1343 }
1344 for (i = 0; i < 30;i++)
1345 {
1346 printf("calling and netcp_cfgDelMac for index %d\n", i);
1347 netcp_cfgDelMac(worker_nh[coreid],i,&err);
1348 }
1349 #endif
1351 #ifdef TEST_SA
1352 for (i = 0; i < 32;i++)
1353 {
1354 ourRXKeyParams[0].pEncKey = &ourEncrKey[0];
1355 ourRXKeyParams[0].pAuthKey = &ourAuthKey[0];
1356 memcpy(&(rx_sa[0].src), &config.remote_ipsec_ip,4);
1357 memcpy(&(rx_sa[0].dst), &config.local_ipsec_ip,4);
1359 build_sa_db(i);
1360 count++;
1361 //printf("thread: %d: calling netapi_secAddSA for rx, count = %d\n",coreid, count);
1362 sa_info[i].rx_tunnel = netapi_secAddSA(
1363 worker_nh[coreid],
1364 config.ipsec_if_no, //iface #0
1365 &rx_sa[0],
1366 &ourRXKeyParams[0],
1367 config.ipsec_mode_rx == IPSEC_MODE_RX_SIDEBAND ? NETAPI_SEC_SA_SIDEBAND: NETAPI_SEC_SA_INFLOW,
1368 NULL, //use default route
1369 &(sa_info[i].rx_data_mode_handle),
1370 &(sa_info[i].rx_inflow_mode_handle),
1371 &err);
1372 //if (err) {printf("addRxSa failed %d\n",err); exit(1);}
1373 if (err) {printf("addRxSa failed %d\n",err);}
1374 sched_yield();
1377 }
1378 //tx SA
1379 //security stuff
1380 count = 0;
1381 for (i = 0; i <32;i++)
1382 {
1383 ourTXKeyParams[0].pEncKey = &ourEncrKey[0];
1384 ourTXKeyParams[0].pAuthKey = &ourAuthKey[0];
1385 memcpy(&(tx_sa[0].src), &config.local_ipsec_ip,4);
1386 memcpy(&(tx_sa[0].dst), &config.remote_ipsec_ip,4);
1387 count++;
1388 //printf("thread: %d: calling netapi_secAddSA for tx, count = %d\n",coreid, count);
1389 sa_info[i].tx_tunnel = netapi_secAddSA( worker_nh[coreid],
1390 0, //iface #0
1391 &tx_sa[0],
1392 &ourTXKeyParams[0],
1393 config.ipsec_mode_tx == IPSEC_MODE_TX_SIDEBAND ? NETAPI_SEC_SA_SIDEBAND: NETAPI_SEC_SA_INFLOW,
1394 NULL, //use default route
1395 &(sa_info[i].tx_data_mode_handle),
1396 &(sa_info[i].tx_inflow_mode_handle),
1397 &err);
1398 if (err) {printf("addTxSa failed %d\n",err); exit(1);}
1399 sched_yield();
1400 }
1401 sleep(1);
1402 count = 0;
1403 #ifdef TEST_SA
1404 for (i = 0; i < 32;i++)
1405 {
1406 if (rx_policy[i])
1407 netapi_secDelRxPolicy(worker_nh[coreid], rx_policy[i], &err);
1408 count ++;
1409 //delete tunnels
1410 printf("main: calling netapi_secDelSA for rx, count = %d\n", count);
1411 netapi_secDelSA(worker_nh[coreid], 0, sa_info[i].rx_tunnel, &err);
1412 //sleep(1);
1413 //printf("main: calling netapi_secDelSA for tx, count = %d\n", count);
1414 netapi_secDelSA(worker_nh[coreid], 0, sa_info[i].tx_tunnel, &err);
1415 }
1416 #endif
1417 #endif
1420 netapi_schedWaitForEvents(scheduler[coreid], &err);
1422 printf(">net_test: core %d worker thread done\n",coreid);
1423 pktio_close(tx_chan, &err);
1424 pktio_close(rx_chan, &err);
1425 pktio_close(sb_tx_chan, &err);
1426 pktio_close(sb_tx_chan, &err);
1427 netapi_shutdown(worker_nh[coreid]);
1428 }
1430 void fast_path_thread(int coreid)
1431 {
1432 int err, i, count=0;
1433 PKTIO_HANDLE_T *our_chan;
1434 PKTIO_HANDLE_T *rx_chan;
1435 PKTIO_HANDLE_T *tx_chan;
1436 PKTIO_HANDLE_T *sb_tx_chan;
1437 PKTIO_HANDLE_T *sb_rx_chan;
1439 printf("fast_path_thread, mypid: %d, core_id %d\n", gettid(), coreid);
1440 #ifdef CORTEX_A15
1441 CPU_SET( coreid, &cpu_set);
1442 hplib_utilSetupCore(coreid, &cpu_set);
1443 #else
1444 CPU_SET( 0, &cpu_set);
1445 hplib_utilSetupCore(coreid + 1, &cpu_set);
1446 #endif
1447 worker_nh[coreid]=netapi_init(NETAPI_CORE_MASTER,NULL);
1450 NETAPI_HANDLE_T * n = (NETAPI_HANDLE_T *) worker_nh[coreid];
1452 /* open netcp default tx, rx queues */
1453 tx_chan = pktio_open(worker_nh[coreid], NETCP_TX, NULL, &netcp_tx_cfg, &err);
1456 #ifdef EXPERIMENTAL
1457 rx_chan = pktio_open(worker_nh[coreid], NETCP_RX, (PKTIO_CB) recv_cb_router, &netcp_rx_cfg, &err);
1458 #else
1459 rx_chan = pktio_open(worker_nh[coreid], NETCP_RX, (PKTIO_CB) recv_cb, &netcp_rx_cfg, &err);
1460 #endif
1462 #ifndef EXPERIMENTAL
1463 /* create a pktio channel for specially classified pkts */
1464 /* open netcp default tx, rx queues for sideband crypto */
1465 sb_tx_chan = pktio_open(worker_nh[coreid], NETCP_SB_TX, NULL, &netcp_sb_tx_cfg, &err);
1467 sb_rx_chan = pktio_open(worker_nh[coreid], NETCP_SB_RX, (PKTIO_CB) recv_sb_cb, &netcp_sb_rx_cfg, &err);
1468 #endif
1470 netapi_setCookie(worker_nh[coreid],coreid);
1471 //our_core = coreid;
1472 scheduler[coreid] =netapi_schedOpen(worker_nh[coreid],&our_sched_cfg, &err);
1473 if (!scheduler[coreid])
1474 {
1475 printf("sched create failed for core%d\n",coreid);
1476 exit(1);
1477 }
1479 /*********************************************/
1480 /**************Entry point into scheduler ****/
1481 /*********************************************/
1482 scheduler[coreid]->config.yield = FALSE;
1483 scheduler[coreid]->config.pollGarbageQ = FALSE;
1484 scheduler[coreid]->config.pollCtrlQ = FALSE;
1485 //sleep(100000);
1486 #ifdef TEST_MAC_IP
1487 for (i = 30; i < MAC_CREATE_LOOP_COUNT ;i++)
1488 {
1489 /* add mac intefaces */
1490 netcp_cfgCreateMacInterface(
1491 worker_nh[coreid],
1492 &config.mac0[0],
1493 i,0,
1494 (NETCP_CFG_ROUTE_HANDLE_T) NULL,
1495 (NETCP_CFG_VLAN_T ) NULL , //future
1496 1,
1497 &err);
1498 if (err) {printf("addmac0 failed %d\n",err); exit(1); }
1499 else
1500 {
1501 printf("addmac0 passed for index %d, mac before %d\n",i, config.mac0[5]);
1502 config.mac0[3]++;
1503 }
1504 }
1506 for (i = 30; i < IP_CREATE_LOOP_COUNT ;i++)
1507 {
1508 //attach an IP to this interface
1509 ip_rule0[i]=netcp_cfgAddIp(
1510 worker_nh[coreid],
1511 30,
1512 nwal_IPV4,
1513 &config.ip0,
1514 NULL, //all IP
1515 (NETCP_CFG_ROUTE_HANDLE_T) NULL,
1516 &err
1517 );
1518 if (err) {printf("addip0 failed %d\n",err); exit(1); }
1519 else
1520 {
1521 printf("addip0 passed for index%d ip[3] %d\n",i, config.ip0.ipv4[3]);
1522 config.ip0.ipv4[3]++;
1523 }
1525 }
1526 sleep(1);
1527 //delete IPs and MAC Interfacess
1528 for (i = 30; i < IP_CREATE_LOOP_COUNT;i++)
1529 {
1530 printf("calling netcp_cfgDelIp and for index %d\n", i);
1531 netcp_cfgDelIp(worker_nh[coreid], i, 0, NULL, NULL, ip_rule0[i], &err);
1532 netcp_cfgDelMac(worker_nh[coreid],i,&err);
1533 }
1534 for (i = 30; i < MAC_CREATE_LOOP_COUNT;i++)
1535 {
1536 printf("calling and netcp_cfgDelMac for index %d\n", i);
1537 netcp_cfgDelMac(worker_nh[coreid],i,&err);
1538 }
1539 #endif
1542 #ifdef TEST_SA
1543 for (i = 32; i < SA_CREATE_LOOP_COUNT-1;i++)
1544 {
1545 ourRXKeyParams[0].pEncKey = &ourEncrKey[0];
1546 ourRXKeyParams[0].pAuthKey = &ourAuthKey[0];
1547 memcpy(&(rx_sa[0].src), &config.remote_ipsec_ip,4);
1548 memcpy(&(rx_sa[0].dst), &config.local_ipsec_ip,4);
1550 build_sa_db(i);
1551 count++;
1552 //printf("thread: %d: calling netapi_secAddSA for rx, count = %d\n",coreid, count);
1553 sa_info[i].rx_tunnel = netapi_secAddSA(
1554 worker_nh[coreid],
1555 config.ipsec_if_no, //iface #0
1556 &rx_sa[0],
1557 &ourRXKeyParams[0],
1558 config.ipsec_mode_rx == IPSEC_MODE_RX_SIDEBAND ? NETAPI_SEC_SA_SIDEBAND: NETAPI_SEC_SA_INFLOW,
1559 NULL, //use default route
1560 &(sa_info[i].rx_data_mode_handle),
1561 &(sa_info[i].rx_inflow_mode_handle),
1562 &err);
1563 //if (err) {printf("addRxSa failed %d\n",err); exit(1);}
1564 if (err) {printf("addRxSa failed %d\n",err);}
1565 sched_yield();
1567 }
1568 count = 0;
1569 //tx SA
1570 //security stuff
1571 for (i = 32; i <SA_CREATE_LOOP_COUNT-1;i++)
1572 {
1573 ourTXKeyParams[0].pEncKey = &ourEncrKey[0];
1574 ourTXKeyParams[0].pAuthKey = &ourAuthKey[0];
1575 memcpy(&(tx_sa[0].src), &config.local_ipsec_ip,4);
1576 memcpy(&(tx_sa[0].dst), &config.remote_ipsec_ip,4);
1577 count++;
1578 //printf("thread: %d: calling netapi_secAddSA for tx, count = %d\n",coreid, count);
1579 sa_info[i].tx_tunnel = netapi_secAddSA( worker_nh[coreid],
1580 0, //iface #0
1581 &tx_sa[0],
1582 &ourTXKeyParams[0],
1583 config.ipsec_mode_tx == IPSEC_MODE_TX_SIDEBAND ? NETAPI_SEC_SA_SIDEBAND: NETAPI_SEC_SA_INFLOW,
1584 NULL, //use default route
1585 &(sa_info[i].tx_data_mode_handle),
1586 &(sa_info[i].tx_inflow_mode_handle),
1587 &err);
1588 if (err) {printf("addTxSa failed %d\n",err); exit(1);}
1589 sched_yield();
1590 }
1592 sleep(1);
1593 count = 0;
1595 for (i = 32; i < SA_CREATE_LOOP_COUNT-1;i++)
1596 {
1597 if (rx_policy[i])
1598 netapi_secDelRxPolicy(worker_nh[coreid], rx_policy[i], &err);
1599 count ++;
1600 //delete tunnels
1601 //printf("main: calling netapi_secDelSA for rx, count = %d\n", count);
1602 netapi_secDelSA(worker_nh[coreid], 0, sa_info[i].rx_tunnel, &err);
1603 //sleep(1);
1604 //printf("main: calling netapi_secDelSA for tx, count = %d\n", count);
1605 netapi_secDelSA(worker_nh[coreid], 0, sa_info[i].tx_tunnel, &err);
1606 }
1607 #endif
1609 netapi_schedWaitForEvents(scheduler[coreid], &err);
1610 printf(">net_test: core %d worker thread done\n",coreid);
1611 pktio_close(tx_chan, &err);
1612 pktio_close(rx_chan, &err);
1613 pktio_close(sb_tx_chan, &err);
1614 pktio_close(sb_tx_chan, &err);
1615 netapi_shutdown(worker_nh[coreid]);
1616 }
1618 #endif
1619 //#endif
1621 /***************************************
1622 ********** test driver*****************
1623 ***************************************/
1624 int main(int argc, char **argv)
1625 {
1626 int err,i, j, count;
1627 Pktlib_HeapCfg heapCfg;
1628 rlim_t oss,ss = 1024*1024;
1629 struct rlimit rl;
1630 int32_t errCode;
1631 Pktlib_HeapIfTable* pPktifTable;
1634 FILE * fpr = NULL;
1637 err= getrlimit(RLIMIT_STACK,&rl);
1638 if (!err) printf(" stack limit = %d\n",rl.rlim_cur); else printf("getrlimit failed\n");
1641 memset(&sa_info, 0, sizeof(sa_info));
1643 /* create netapi */
1644 netapi_handle = netapi_init(NETAPI_SYS_MASTER, &our_netapi_default_cfg);
1646 /* open the main heap */
1647 ourHeap = Pktlib_findHeapByName("netapi");
1648 if (!ourHeap)
1649 {
1650 printf("Pktlib_findHeapByName() fail\n");
1651 exit(1);
1652 }
1654 /* create two secondary heaps */
1655 /* Initialize the heap configuration. */
1656 memset ((void *)&heapCfg, 0, sizeof(Pktlib_HeapCfg));
1658 pPktifTable = netapi_getPktlibIfTable();
1659 /* Populate the heap configuration */
1660 heapCfg.name = "netapi-small";
1661 heapCfg.memRegion = NETAPI_GLOBAL_REGION;
1662 heapCfg.sharedHeap = 1;
1663 heapCfg.useStarvationQueue = 0;
1664 heapCfg.dataBufferSize = 512;
1665 heapCfg.numPkts = 64;
1666 heapCfg.numZeroBufferPackets= 0;
1667 heapCfg.heapInterfaceTable.data_malloc = pPktifTable->data_malloc;
1668 heapCfg.heapInterfaceTable.data_free = pPktifTable->data_free;
1669 heapCfg.dataBufferPktThreshold = 0;
1670 heapCfg.zeroBufferPktThreshold = 0;
1672 specialSmall = Pktlib_createHeap(&heapCfg, &errCode);
1673 heapCfg.name = "netapi-big";
1674 heapCfg.dataBufferSize = 1600;
1675 specialLarge = Pktlib_createHeap(&heapCfg, &errCode);
1676 //register these heaps so poll routine will include their garbage queues.
1677 netapi_registerHeap(netapi_handle, specialSmall);
1678 netapi_registerHeap(netapi_handle, specialLarge);
1680 /* create a pktio channel */
1681 our_chan=pktio_create(netapi_handle,"our1stq",(PKTIO_CB) recv_cb_bench, &our_chan_cfg,&err);
1682 if (!our_chan)
1683 {
1684 printf("pktio create failed err=%d\n",err);
1685 exit(1);
1686 }
1688 /* open netcp default tx, rx queues */
1689 netcp_tx_chan= pktio_open(netapi_handle, NETCP_TX, NULL, &netcp_tx_cfg, &err);
1690 if (!netcp_tx_chan)
1691 {
1692 printf("pktio open TX failed err=%d\n",err);
1693 exit(1);
1694 }
1695 netcp_rx_chan= pktio_open(netapi_handle, NETCP_RX, (PKTIO_CB) recv_cb, &netcp_rx_cfg, &err);
1697 if (!netcp_rx_chan)
1698 {
1699 printf("pktio open RX failed err=%d\n",err);
1700 exit(1);
1701 }
1703 /* create a pktio channel for specially classified pkts */
1704 netcp_rx_chan2= pktio_create(netapi_handle, "classq", (PKTIO_CB) recv_cb, &netcp_rx_cfg2, &err);
1705 if (!netcp_rx_chan2) {printf("pktio create RX2 failed err=%d\n",err); exit(1);}
1707 /* open netcp default tx, rx queues for sideband crypto */
1708 netcp_sb_tx_chan= pktio_open(netapi_handle, NETCP_SB_TX, NULL, &netcp_sb_tx_cfg, &err);
1709 if (!netcp_sb_tx_chan)
1710 {
1711 printf("pktio open SB TX failed err=%d\n",err);
1712 exit(1);
1713 }
1714 netcp_sb_rx_chan= pktio_open(netapi_handle, NETCP_SB_RX, (PKTIO_CB) recv_sb_cb, &netcp_sb_rx_cfg, &err);
1715 if (!netcp_sb_rx_chan)
1716 {
1717 printf("pktio open SB RX failed err=%d\n",err);
1718 exit(1);
1719 }
1721 printf("net_test> %d bytes left in our CMA area\n", netapi_getBufMemRemainder());
1722 /* create scheduler instance */
1723 our_sched =netapi_schedOpen(netapi_handle,&our_sched_cfg, &err);
1724 if (!our_sched) {printf("sched create failed\n"); exit(1);}
1726 //#define PROMISCUOUS
1727 #define ETH0 0
1728 #define ETH1 1
1730 //security stuff
1731 p_trie_sa = trie_new();
1732 if (!p_trie_sa) {printf("trie alloc for SA failed\n"); exit(1);}
1735 #ifdef MULTI_THREAD
1736 {
1737 CPU_ZERO( &cpu_set );
1738 pthread_t *thrs;
1739 int procs =2; //get this from config eventually
1740 char c;
1741 thrs = malloc( sizeof( pthread_t ) * procs );
1742 if (thrs == NULL)
1743 {
1744 perror( "malloc" );
1745 return -1;
1746 }
1747 printf( "Starting %d threads...\n", procs );
1749 if (pthread_create( &thrs[0], NULL, slow_path_thread,
1750 (void *)0 ))
1751 {
1752 perror( "pthread_create" );
1753 exit(1);
1754 }
1755 if (pthread_create( &thrs[1], NULL, fast_path_thread,
1756 (void *)1 ))
1757 {
1758 perror( "pthread_create" );
1759 exit(1);
1760 }
1762 //this thread of execution (main) now just waits on user input
1763 for(;;)
1764 {
1765 printf(">");
1766 c=getchar();
1767 if (c=='q')
1768 {
1769 QUIT=1;
1770 break;
1771 }
1772 //else if (c=='s') our_stats_cb(netapi_handle, &netcp_stats);
1773 else if (c=='h') printf("'q' to quit, 's' for stats, 'h' for help\n");
1774 }
1776 //wait for completion
1777 printf("main task now pending on slow/fast path completion\n");
1778 for (i = 0; i < procs; i++)
1779 pthread_join( thrs[i], NULL );
1781 free( thrs );
1782 }
1783 #else
1784 /*********************************************/
1785 /**************Entry point into scheduler ****/
1786 /*********************************************/
1787 netapi_schedWaitForEvents(our_sched, &err);
1789 #endif
1799 #if 0
1800 //create specialFlow for this classifier
1801 {
1802 Pktlib_HeapHandle heaps[2];
1803 //int sizes[2];
1804 heaps[0]= specialSmall;
1805 heaps[1]= specialLarge;
1806 #define SPECIAL_SOP_OFF 128
1807 // sizes[0]=512-SPECIAL_SOP_OFF;
1808 //sizes[1]=1600-SPECIAL_SOP_OFF;
1809 }
1810 #endif
1812 count = 0;
1813 //sleep(1);
1815 /*************************************************
1816 ************CLEAN UP****************************
1817 ************************************************/
1819 //delete Classifiers
1820 netcp_cfgDelClass(netapi_handle, class_0, &err);
1821 netcp_cfgDelClass(netapi_handle, class_1, &err);
1822 //netcp_cfgDelClass(netapi_handle, class_2, &err);
1824 count = 0;
1825 //close pktio channels we opened
1826 printf("main: calling pktio_close for netcp_tx_chan\n");
1827 pktio_close(netcp_tx_chan ,&err);
1828 printf("main: calling pktio_close for netcp_rx_chan\n");
1829 pktio_close(netcp_rx_chan ,&err);
1830 printf("main: calling pktio_close for netcp_sb_tx_chan\n");
1831 pktio_close(netcp_sb_tx_chan ,&err);
1832 printf("main: calling pktio_close for netcp_sb_rx_chan\n");
1833 pktio_close(netcp_sb_rx_chan ,&err);
1835 //clear pktio channel we created
1836 pktio_control(our_chan, (PKTIO_CB) NULL, (PKTIO_CFG_T *) NULL, &zap_channel_control, &err);
1837 pktio_control(netcp_rx_chan2, (PKTIO_CB) NULL, (PKTIO_CFG_T *) NULL, &zap_channel_control, &err);
1839 //delete pktio channels we created
1840 pktio_delete(our_chan, &err);
1841 pktio_delete(netcp_rx_chan2,&err);
1842 netapi_shutdown(netapi_handle);
1844 }