ca5834c0214766e9d031bcbb27df8982d8fe4cd1
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>
65 #define TEST_SA
66 //#define TEST_MAC_IP
67 #define SA_CREATE_LOOP_COUNT 64
68 #define IP_CREATE_LOOP_COUNT 64
69 #define MAC_CREATE_LOOP_COUNT 59
72 long htonl(long x)
73 {
74 long temp = (x&0xff000000)>>24 | (x&0xff0000)>>8 | (x&0xff00)<<8 | (x&0xff)<<24 ;
75 return temp;
76 }
78 /* net test default configuration */
79 netTestConfig_t config =
80 {
81 {0x00,0x01,0x02,0x03,0x05,0x05},
82 {0x00,0x01,0x02,0x03,0x05,0x06},
83 {10, 0, 0, 100, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
84 {10, 0, 1, 100, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
85 {10, 0, 2, 100, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
86 {192,168 , 1, 100, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
87 {192,168 , 1, 10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
88 IPSEC_MODE_RX_INFLOW,
89 IPSEC_MODE_TX_INFLOW,
90 0
91 };
93 #if 0
94 netTestConfigMax_t configMax =
95 {
96 {{0x00,0x00,0x02,0x03,0x05,0x07},
97 { 0x00,0x01,0x02,0x03,0x05,0x09}},
98 {{0x00,0x02,0x02,0x03,0x05,0x04},
99 { 0x00,0x03,0x02,0x03,0x05,0x03}},
100 {{0x00,0x04,0x02,0x03,0x05,0x07},
101 { 0x00,0x05,0x02,0x03,0x05,0x09}},
102 {{0x00,0x06,0x02,0x03,0x05,0x04},
103 { 0x00,0x07,0x02,0x03,0x05,0x03}},
104 {{0x00,0x08,0x02,0x03,0x05,0x07},
105 { 0x00,0x09,0x02,0x03,0x05,0x09}},
106 {{0x00,0x0a,0x02,0x03,0x05,0x04},
107 { 0x00,0x0b,0x02,0x03,0x05,0x03}},
108 {{0x00,0x0c,0x02,0x03,0x05,0x07},
109 { 0x00,0x0d,0x02,0x03,0x05,0x09}},
110 {{0x00,0x0e,0x02,0x03,0x05,0x04},
111 { 0x00,0x0f,0x02,0x03,0x05,0x03}},
114 {{0x00,0x10,0x02,0x03,0x05,0x07},
115 { 0x00,0x11,0x02,0x03,0x05,0x09}},
116 {{0x00,0x12,0x02,0x03,0x05,0x04},
117 { 0x00,0x13,0x02,0x03,0x05,0x03}},
118 {{0x00,0x14,0x02,0x03,0x05,0x07},
119 { 0x00,0x15,0x02,0x03,0x05,0x09}},
120 {{0x00,0x16,0x02,0x03,0x05,0x04},
121 { 0x00,0x17,0x02,0x03,0x05,0x03}},
122 {{0x00,0x18,0x02,0x03,0x05,0x07},
123 { 0x00,0x19,0x02,0x03,0x05,0x09}},
124 {{0x00,0x1a,0x02,0x03,0x05,0x04},
125 { 0x00,0x1b,0x02,0x03,0x05,0x03}},
126 {{0x00,0x1c,0x02,0x03,0x05,0x07},
127 { 0x00,0x1d,0x02,0x03,0x05,0x09}},
128 {{0x00,0x1e,0x02,0x03,0x05,0x04},
129 { 0x00,0x1f,0x02,0x03,0x05,0x03}},
131 {{0x00,0x10,0x02,0x03,0x05,0x07},
132 { 0x00,0x11,0x02,0x03,0x05,0x09}},
133 {{0x00,0x12,0x02,0x03,0x05,0x04},
134 { 0x00,0x13,0x02,0x03,0x05,0x03}},
135 {{0x00,0x14,0x02,0x03,0x05,0x07},
136 { 0x00,0x15,0x02,0x03,0x05,0x09}},
137 {{0x00,0x16,0x02,0x03,0x05,0x04},
138 { 0x00,0x17,0x02,0x03,0x05,0x03}},
139 {{0x00,0x18,0x02,0x03,0x05,0x07},
140 { 0x00,0x19,0x02,0x03,0x05,0x09}},
141 {{0x00,0x1a,0x02,0x03,0x05,0x04},
142 { 0x00,0x1b,0x02,0x03,0x05,0x03}},
143 {{0x00,0x1c,0x02,0x03,0x05,0x07},
144 { 0x00,0x1d,0x02,0x03,0x05,0x09}},
145 {{0x00,0x1e,0x02,0x03,0x05,0x04},
146 { 0x00,0x1f,0x02,0x03,0x05,0x03}},
149 {{10, 0, 0, 100, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
150 {10, 0, 1, 100, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}},
151 {{10, 0, 2, 100, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
152 {10, 0, 3, 100, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}},
153 {{10, 0, 4, 100, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
154 {10, 0, 5, 100, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}},
155 {192,168 , 1, 100, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
156 {192,168 , 1, 10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
157 IPSEC_MODE_RX_INFLOW,
158 IPSEC_MODE_TX_INFLOW,
159 0
160 };
161 #endif
164 //#define NP 5000
165 //int n_pkt = NP;
167 Trie *p_trie_sa;
169 /*******************************************
170 *************NETAPI OBJECTS***************
171 *****************************************/
172 static NETAPI_CFG_T our_netapi_default_cfg=
173 {
174 TUNE_NETAPI_PERM_MEM_SZ,
175 128, //start of packet offset for hw to place data on rx for default flow
176 TUNE_NETAPI_QM_CONFIG_MAX_DESC_NUM, //max number of descriptors in system
177 TUNE_NETAPI_NUM_GLOBAL_DESC, //total we will use
178 TUNE_NETAPI_DEFAULT_NUM_BUFFERS, //#descriptors+buffers in default heap
179 64, //#descriptors w/o buffers in default heap
180 TUNE_NETAPI_DEFAULT_BUFFER_SIZE+128+128, //size of buffers in default heap
181 128 , //tail room
182 256 //extra room
183 };
185 Pktlib_HeapHandle ourHeap;
186 Pktlib_HeapHandle specialSmall;
187 Pktlib_HeapHandle specialLarge;
189 PKTIO_HANDLE_T *our_chan;
190 PKTIO_HANDLE_T *netcp_rx_chan;
191 PKTIO_HANDLE_T *netcp_rx_chan2;
192 PKTIO_HANDLE_T *netcp_tx_chan_esp;
193 PKTIO_HANDLE_T *netcp_sb_tx_chan;
194 PKTIO_HANDLE_T *netcp_sb_rx_chan;
195 PKTIO_CFG_T our_chan_cfg={PKTIO_RX_TX, PKTIO_LOCAL, PKTIO_Q_ANY, 8};
196 PKTIO_CFG_T netcp_rx_cfg={PKTIO_RX, PKTIO_NA, PKTIO_NA, 8};
197 PKTIO_CFG_T netcp_rx_cfg2={PKTIO_RX, (PKTIO_GLOBAL|PKTIO_PKT), PKTIO_Q_ANY, 8};
198 PKTIO_CFG_T netcp_tx_cfg={PKTIO_TX, PKTIO_NA, PKTIO_NA, 8};
199 PKTIO_CFG_T netcp_sb_rx_cfg={PKTIO_RX, PKTIO_NA, PKTIO_NA, 8};
200 PKTIO_CFG_T netcp_sb_tx_cfg={PKTIO_TX, PKTIO_NA, PKTIO_NA, 8};
202 void house(NETAPI_SCHED_HANDLE_T *s);
203 NETAPI_T netapi_handle;
204 NETAPI_SCHED_HANDLE_T * our_sched;
205 NETAPI_SCHED_CONFIG_T our_sched_cfg={
206 NETAPI_SCHED_DURATION|NETAPI_SCHED_CBV, 0, house, 5000000 //every 5000000 poll loops
207 };
210 NETCP_CFG_IP_T ip_rule0[IP_CREATE_LOOP_COUNT];
211 NETCP_CFG_IP_T ip_rule1[IP_CREATE_LOOP_COUNT];
212 //NETCP_CFG_IP_T ip_rule0;
213 //NETCP_CFG_IP_T ip_rule1;
215 NETCP_CFG_CLASS_T class_0;
216 NETCP_CFG_CLASS_T class_1;
217 NETCP_CFG_CLASS_T class_2;
218 NETCP_CFG_FLOW_HANDLE_T specialFlow;
221 NETCP_CFG_CLASSIFIER_T class_0_cfg=
222 {
223 NETCP_CFG_CLASS_TYPE_L4,
224 {
225 .c_l4={0,0, NWAL_APP_PLOAD_PROTO_UDP, {2500}}
226 }
227 };
229 NETCP_CFG_CLASSIFIER_T class_1_cfg=
230 {
231 NETCP_CFG_CLASS_TYPE_L4,
232 {
233 .c_l4= {0,0, NWAL_APP_PLOAD_PROTO_UDP, {2502}}
234 }
235 };
237 NETCP_CFG_ROUTE_T class2_route=
238 {
239 NULL, NULL //* to be filled in
240 };
241 NETCP_CFG_CLASSIFIER_T class_2_cfg=
242 {
243 NETCP_CFG_CLASS_TYPE_L3_L4,
244 {
245 .c_l3_l4={0, 4 ,0/*fill in below*/ , NULL, NULL, //L2/L3
246 NWAL_APP_PLOAD_PROTO_UDP, {2504}} //L4
247 }
248 };
250 PKTIO_CONTROL_T zap_channel_control={PKTIO_CLEAR, NULL};
252 /* security objects. (for loopback mode) */
253 netTestSA_t sa_info[SA_CREATE_LOOP_COUNT];
255 NETCP_CFG_IPSEC_POLICY_T rx_policy[SA_CREATE_LOOP_COUNT];
259 NETAPI_SEC_SA_INFO_T rx_sa [14] = {
260 {
261 NWAL_SA_DIR_INBOUND,
262 0x11111111, //spi
263 nwal_IpSecProtoESP, //ESP mode
264 nwal_SA_MODE_TUNNEL, //tunnel mode
265 nwal_IPV4, //v4
266 { 1, 2, 3, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, /* Src IP (them) -> set below */
267 { 1, 2, 3, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, /* dst IP (us)-> set below*/
268 64,/* replayWindow */
269 NWAL_SA_AALG_HMAC_SHA1,
270 NWAL_SA_EALG_AES_CBC,
271 0,0 //na
272 },
273 {
274 NWAL_SA_DIR_INBOUND,
275 0x22222222, //spi
276 nwal_IpSecProtoESP, //ESP mode
277 nwal_SA_MODE_TUNNEL, //tunnel mode
278 nwal_IPV4, //v4
279 { 1, 2, 3, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, /* Src IP (them) -> set below */
280 { 1, 2, 3, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, /* dst IP (us)-> set below*/
281 64,/* replayWindow */
282 NWAL_SA_AALG_HMAC_SHA2_256,
283 NWAL_SA_EALG_AES_CTR,
284 0,0 //na
285 },
286 {
287 NWAL_SA_DIR_INBOUND,
288 0x33333333, //spi
289 nwal_IpSecProtoESP, //ESP mode
290 nwal_SA_MODE_TUNNEL, //tunnel mode
291 nwal_IPV4, //v4
292 { 1, 2, 3, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, /* Src IP (them) -> set below */
293 { 1, 2, 3, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, /* dst IP (us)-> set below*/
294 64,/* replayWindow */
295 NWAL_SA_AALG_HMAC_SHA2_256,
296 NWAL_SA_EALG_3DES_CBC,
297 0,0 //na
298 },
299 {
300 NWAL_SA_DIR_INBOUND,
301 0x44444444, //spi
302 nwal_IpSecProtoESP, //ESP mode
303 nwal_SA_MODE_TUNNEL, //tunnel mode
304 nwal_IPV4, //v4
305 { 1, 2, 3, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, /* Src IP (them) -> set below */
306 { 1, 2, 3, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, /* dst IP (us)-> set below*/
307 64,/* replayWindow */
308 NWAL_SA_AALG_HMAC_MD5,
309 NWAL_SA_EALG_NULL,
310 0,0 //na
311 },
312 {
313 NWAL_SA_DIR_INBOUND,
314 0x55555555, //spi
315 nwal_IpSecProtoESP, //ESP mode
316 nwal_SA_MODE_TUNNEL, //tunnel mode
317 nwal_IPV4, //v4
318 { 1, 2, 3, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, /* Src IP (them) -> set below */
319 { 1, 2, 3, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, /* dst IP (us)-> set below*/
320 64,/* replayWindow */
321 NWAL_SA_AALG_NULL,
322 NWAL_SA_EALG_AES_GCM,
323 0,0 //na
324 },
325 {
326 NWAL_SA_DIR_INBOUND,
327 0x66666666, //spi
328 nwal_IpSecProtoESP, //ESP mode
329 nwal_SA_MODE_TUNNEL, //tunnel mode
330 nwal_IPV4, //v4
331 { 1, 2, 3, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, /* Src IP (them) -> set below */
332 { 1, 2, 3, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, /* dst IP (us)-> set below*/
333 64,/* replayWindow */
334 NWAL_SA_AALG_NULL,
335 NWAL_SA_EALG_AES_CCM,
336 0,0 //na
337 },
338 {
339 NWAL_SA_DIR_INBOUND,
340 0x77777777, //spi
341 nwal_IpSecProtoESP, //ESP mode
342 nwal_SA_MODE_TUNNEL, //tunnel mode
343 nwal_IPV4, //v4
344 { 1, 2, 3, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, /* Src IP (them) -> set below */
345 { 1, 2, 3, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, /* dst IP (us)-> set below*/
346 64,/* replayWindow */
347 NWAL_SA_AALG_AES_XCBC,
348 NWAL_SA_EALG_NULL,
349 0,0 //na
350 },
351 {
352 NWAL_SA_DIR_INBOUND,
353 0x91111111, //spi
354 nwal_IpSecProtoESP, //ESP mode
355 nwal_SA_MODE_TUNNEL, //tunnel mode
356 nwal_IPV4, //v4
357 { 1, 2, 3, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, /* Src IP (them) -> set below */
358 { 1, 2, 3, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, /* dst IP (us)-> set below*/
359 64,/* replayWindow */
360 NWAL_SA_AALG_HMAC_SHA1,
361 NWAL_SA_EALG_AES_CBC,
362 0,0 //na
363 },
364 {
365 NWAL_SA_DIR_INBOUND,
366 0x92222222, //spi
367 nwal_IpSecProtoESP, //ESP mode
368 nwal_SA_MODE_TUNNEL, //tunnel mode
369 nwal_IPV4, //v4
370 { 1, 2, 3, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, /* Src IP (them) -> set below */
371 { 1, 2, 3, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, /* dst IP (us)-> set below*/
372 64,/* replayWindow */
373 NWAL_SA_AALG_HMAC_SHA2_256,
374 NWAL_SA_EALG_AES_CTR,
375 0,0 //na
376 },
377 {
378 NWAL_SA_DIR_INBOUND,
379 0x93333333, //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_SHA2_256,
387 NWAL_SA_EALG_3DES_CBC,
388 0,0 //na
389 },
390 {
391 NWAL_SA_DIR_INBOUND,
392 0x94444444, //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_MD5,
400 NWAL_SA_EALG_NULL,
401 0,0 //na
402 },
403 {
404 NWAL_SA_DIR_INBOUND,
405 0x95555555, //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_NULL,
413 NWAL_SA_EALG_AES_GCM,
414 0,0 //na
415 },
416 {
417 NWAL_SA_DIR_INBOUND,
418 0x96666666, //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_NULL,
426 NWAL_SA_EALG_AES_CCM,
427 0,0 //na
428 },
429 {
430 NWAL_SA_DIR_INBOUND,
431 0x97777777, //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_AES_XCBC,
439 NWAL_SA_EALG_NULL,
440 0,0 //na
441 }
445 };
447 /*tx */
448 NETAPI_SEC_SA_INFO_T tx_sa[14]= {
449 {
450 NWAL_SA_DIR_OUTBOUND,
451 0x11111111, //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 (us) -> set below */
456 { 1, 2, 3, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, /* dst IP (them) -> set below*/
457 64, /* NA replayWindow */
458 NWAL_SA_AALG_HMAC_SHA1,
459 NWAL_SA_EALG_AES_CBC,
460 0,0 //seq no
461 },
462 {
463 NWAL_SA_DIR_OUTBOUND,
464 0x22222222, //spi
465 nwal_IpSecProtoESP, //ESP mode
466 nwal_SA_MODE_TUNNEL, //tunnel mode
467 nwal_IPV4, //v4
468 { 1, 2, 3, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, /* Src IP (us) -> set below */
469 { 1, 2, 3, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, /* dst IP (them) -> set below*/
470 64, /* NA replayWindow */
471 NWAL_SA_AALG_HMAC_SHA2_256,
472 NWAL_SA_EALG_AES_CTR,
473 0,0 //seq no
474 },
475 {
476 NWAL_SA_DIR_OUTBOUND,
477 0x33333333, //spi
478 nwal_IpSecProtoESP, //ESP mode
479 nwal_SA_MODE_TUNNEL, //tunnel mode
480 nwal_IPV4, //v4
481 { 1, 2, 3, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, /* Src IP (us) -> set below */
482 { 1, 2, 3, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, /* dst IP (them) -> set below*/
483 64, /* NA replayWindow */
484 NWAL_SA_AALG_HMAC_SHA2_256,
485 NWAL_SA_EALG_3DES_CBC,
486 0,0 //seq no
487 },
488 {
489 NWAL_SA_DIR_OUTBOUND,
490 0x44444444, //spi
491 nwal_IpSecProtoESP, //ESP mode
492 nwal_SA_MODE_TUNNEL, //tunnel mode
493 nwal_IPV4, //v4
494 { 1, 2, 3, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, /* Src IP (us) -> set below */
495 { 1, 2, 3, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, /* dst IP (them) -> set below*/
496 64, /* NA replayWindow */
497 NWAL_SA_AALG_HMAC_MD5,
498 NWAL_SA_EALG_NULL,
499 },
500 {
501 NWAL_SA_DIR_OUTBOUND,
502 0x55555555, //spi
503 nwal_IpSecProtoESP, //ESP mode
504 nwal_SA_MODE_TUNNEL, //tunnel mode
505 nwal_IPV4, //v4
506 { 1, 2, 3, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, /* Src IP (them) -> set below */
507 { 1, 2, 3, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, /* dst IP (us)-> set below*/
508 64,/* replayWindow */
509 NWAL_SA_AALG_NULL,
510 NWAL_SA_EALG_AES_GCM,
511 0,0 //na
512 },
513 {
514 NWAL_SA_DIR_OUTBOUND,
515 0x66666666, //spi
516 nwal_IpSecProtoESP, //ESP mode
517 nwal_SA_MODE_TUNNEL, //tunnel mode
518 nwal_IPV4, //v4
519 { 1, 2, 3, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, /* Src IP (them) -> set below */
520 { 1, 2, 3, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, /* dst IP (us)-> set below*/
521 64,/* replayWindow */
522 NWAL_SA_AALG_NULL,
523 NWAL_SA_EALG_AES_CCM,
524 0,0 //na
525 },
526 {
527 NWAL_SA_DIR_OUTBOUND,
528 0x77777777, //spi
529 nwal_IpSecProtoESP, //ESP mode
530 nwal_SA_MODE_TUNNEL, //tunnel mode
531 nwal_IPV4, //v4
532 { 1, 2, 3, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, /* Src IP (them) -> set below */
533 { 1, 2, 3, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, /* dst IP (us)-> set below*/
534 64,/* replayWindow */
535 NWAL_SA_AALG_AES_XCBC,
536 NWAL_SA_EALG_NULL,
537 0,0 //na
538 },
539 {
540 NWAL_SA_DIR_OUTBOUND,
541 0x91111111, //spi
542 nwal_IpSecProtoESP, //ESP mode
543 nwal_SA_MODE_TUNNEL, //tunnel mode
544 nwal_IPV4, //v4
545 { 1, 2, 3, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, /* Src IP (us) -> set below */
546 { 1, 2, 3, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, /* dst IP (them) -> set below*/
547 64, /* NA replayWindow */
548 NWAL_SA_AALG_HMAC_SHA1,
549 NWAL_SA_EALG_AES_CBC,
550 0,0 //seq no
551 },
552 {
553 NWAL_SA_DIR_OUTBOUND,
554 0x92222222, //spi
555 nwal_IpSecProtoESP, //ESP mode
556 nwal_SA_MODE_TUNNEL, //tunnel mode
557 nwal_IPV4, //v4
558 { 1, 2, 3, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, /* Src IP (us) -> set below */
559 { 1, 2, 3, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, /* dst IP (them) -> set below*/
560 64, /* NA replayWindow */
561 NWAL_SA_AALG_HMAC_SHA2_256,
562 NWAL_SA_EALG_AES_CTR,
563 0,0 //seq no
564 },
565 {
566 NWAL_SA_DIR_OUTBOUND,
567 0x93333333, //spi
568 nwal_IpSecProtoESP, //ESP mode
569 nwal_SA_MODE_TUNNEL, //tunnel mode
570 nwal_IPV4, //v4
571 { 1, 2, 3, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, /* Src IP (us) -> set below */
572 { 1, 2, 3, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, /* dst IP (them) -> set below*/
573 64, /* NA replayWindow */
574 NWAL_SA_AALG_HMAC_SHA2_256,
575 NWAL_SA_EALG_3DES_CBC,
576 0,0 //seq no
577 },
578 {
579 NWAL_SA_DIR_OUTBOUND,
580 0x94444444, //spi
581 nwal_IpSecProtoESP, //ESP mode
582 nwal_SA_MODE_TUNNEL, //tunnel mode
583 nwal_IPV4, //v4
584 { 1, 2, 3, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, /* Src IP (us) -> set below */
585 { 1, 2, 3, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, /* dst IP (them) -> set below*/
586 64, /* NA replayWindow */
587 NWAL_SA_AALG_HMAC_MD5,
588 NWAL_SA_EALG_NULL,
589 },
590 {
591 NWAL_SA_DIR_OUTBOUND,
592 0x95555555, //spi
593 nwal_IpSecProtoESP, //ESP mode
594 nwal_SA_MODE_TUNNEL, //tunnel mode
595 nwal_IPV4, //v4
596 { 1, 2, 3, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, /* Src IP (them) -> set below */
597 { 1, 2, 3, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, /* dst IP (us)-> set below*/
598 64,/* replayWindow */
599 NWAL_SA_AALG_NULL,
600 NWAL_SA_EALG_AES_GCM,
601 0,0 //na
602 },
603 {
604 NWAL_SA_DIR_OUTBOUND,
605 0x96666666, //spi
606 nwal_IpSecProtoESP, //ESP mode
607 nwal_SA_MODE_TUNNEL, //tunnel mode
608 nwal_IPV4, //v4
609 { 1, 2, 3, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, /* Src IP (them) -> set below */
610 { 1, 2, 3, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, /* dst IP (us)-> set below*/
611 64,/* replayWindow */
612 NWAL_SA_AALG_NULL,
613 NWAL_SA_EALG_AES_CCM,
614 0,0 //na
615 },
616 {
617 NWAL_SA_DIR_OUTBOUND,
618 0x97777777, //spi
619 nwal_IpSecProtoESP, //ESP mode
620 nwal_SA_MODE_TUNNEL, //tunnel mode
621 nwal_IPV4, //v4
622 { 1, 2, 3, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, /* Src IP (them) -> set below */
623 { 1, 2, 3, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, /* dst IP (us)-> set below*/
624 64,/* replayWindow */
625 NWAL_SA_AALG_AES_XCBC,
626 NWAL_SA_EALG_NULL,
627 0,0 //na
628 }
629 };
632 static nwalSecKeyParams_t ourTXKeyParams[14] ={
633 {
634 32, /* encKeySize: CTR 16 bytes Encryption Key and 4 bytes Salt : 24 bytes:NWAL_SA_EALG_3DES_CBC and 0 bytes Salt*/
635 20, /* macKeySize: 16 bytes NWAL_SA_AALG_HMAC_SHA1 */
636 NULL, //set below
637 NULL, //set below
638 },
639 {
640 20, /* encKeySize: CTR 16 bytes Encryption Key and 4 bytes Salt : 24 bytes:NWAL_SA_EALG_AES_CTR and 0 bytes Salt*/
641 32, /* macKeySize: 16 bytes NWAL_SA_AALG_HMAC_SHA2_256 */
642 NULL, //set below
643 NULL, //set below
644 },
645 {
646 24, /* encKeySize: DES-CBC: 24 bytes:NWAL_SA_EALG_3DES_CBC and 0 bytes Salt*/
647 32, /* macKeySize: 16 bytes NWAL_SA_AALG_HMAC_SHA2_256 */
648 NULL, //set below
649 NULL, //set below
650 },
651 {
652 0, /* NULL*/
653 16, /* MD5, 16 bytes */
654 NULL, //set below
655 NULL, //set below
656 },
657 {
658 20, /* encKeySize: GCM 16 bytes Encryption Key and 4 bytes Salt */
659 0, /* macKeySize: 0*/
660 NULL, //set below
661 NULL, //set below
662 },
663 {
664 19, /* encKeySize: CTR 16 bytes Encryption Key and 3 bytes Salt : 24 bytes:NWAL_SA_EALG_AES_CTR and 0 bytes Salt*/
665 0, /* macKeySize 0*/
666 NULL, //set below
667 NULL, //set below
668 },
669 {
670 0, /* encKeySize: CTR 16 bytes Encryption Key and 3 bytes Salt : 24 bytes:NWAL_SA_EALG_AES_CTR and 0 bytes Salt*/
671 16, /* macKeySize 0*/
672 NULL, //set below
673 NULL, //set below
674 },
675 {
676 32, /* encKeySize: CTR 16 bytes Encryption Key and 4 bytes Salt : 24 bytes:NWAL_SA_EALG_3DES_CBC and 0 bytes Salt*/
677 20, /* macKeySize: 16 bytes NWAL_SA_AALG_HMAC_SHA1 */
678 NULL, //set below
679 NULL, //set below
680 },
681 {
682 20, /* encKeySize: CTR 16 bytes Encryption Key and 4 bytes Salt : 24 bytes:NWAL_SA_EALG_AES_CTR and 0 bytes Salt*/
683 32, /* macKeySize: 16 bytes NWAL_SA_AALG_HMAC_SHA2_256 */
684 NULL, //set below
685 NULL, //set below
686 },
687 {
688 24, /* encKeySize: DES-CBC: 24 bytes:NWAL_SA_EALG_3DES_CBC and 0 bytes Salt*/
689 32, /* macKeySize: 16 bytes NWAL_SA_AALG_HMAC_SHA2_256 */
690 NULL, //set below
691 NULL, //set below
692 },
693 {
694 0, /* NULL*/
695 16, /* MD5, 16 bytes */
696 NULL, //set below
697 NULL, //set below
698 },
699 {
700 20, /* encKeySize: GCM 16 bytes Encryption Key and 4 bytes Salt */
701 0, /* macKeySize: 0*/
702 NULL, //set below
703 NULL, //set below
704 },
705 {
706 19, /* encKeySize: CTR 16 bytes Encryption Key and 3 bytes Salt : 24 bytes:NWAL_SA_EALG_AES_CTR and 0 bytes Salt*/
707 0, /* macKeySize 0*/
708 NULL, //set below
709 NULL, //set below
710 },
711 {
712 0, /* encKeySize: CTR 16 bytes Encryption Key and 3 bytes Salt : 24 bytes:NWAL_SA_EALG_AES_CTR and 0 bytes Salt*/
713 16, /* macKeySize 0*/
714 NULL, //set below
715 NULL, //set below
716 }
717 };
719 /* these keys are for aes-ctr and hmac sha2_256 */
720 static nwalSecKeyParams_t ourRXKeyParams[14] ={
721 {
722 32, /* encKeySize: CTR 16 bytes Encryption Key and 4 bytes Salt : 24 bytes:NWAL_SA_EALG_3DES_CBC and 0 bytes Salt*/
723 20, /* macKeySize: 16 bytes NWAL_SA_AALG_HMAC_SHA1 */
724 NULL, //set below
725 NULL, //set below
726 },
727 {
728 20, /* encKeySize: CTR 16 bytes Encryption Key and 4 bytes Salt */
729 32, /* macKeySize: 16 bytes NWAL_SA_AALG_HMAC_SHA2_256 */
730 NULL, //set below
731 NULL, //set below
732 },
733 {
734 24, /* encKeySize: DES-CBC: 24 bytes:NWAL_SA_EALG_3DES_CBC and 0 bytes Salt*/
735 32, /* macKeySize: 16 bytes NWAL_SA_AALG_HMAC_SHA2_256 */
736 NULL, //set below
737 NULL, //set below
738 },
739 {
740 0, /* NWAL_SA_EALG_NULL*/
741 16, /* NWAL_SA_AALG_HMAC_MD5, 16 bytes */
742 NULL, //set below
743 NULL, //set below
744 },
745 {
746 20, /* encKeySize: GCM 16 bytes Encryption Key and 4 bytes Salt */
747 0, /* macKeySize: 0*/
748 NULL, //set below
749 NULL, //set below
750 },
751 {
752 19, /* encKeySize: CTR 16 bytes Encryption Key and 3 bytes Salt t*/
753 0, /* macKeySize 0*/
754 NULL, //set below
755 NULL, //set below
756 },
757 {
758 0, /* encKeySize: CTR 16 bytes Encryption Key and 3 bytes Salt : 24 bytes:NWAL_SA_EALG_AES_CTR and 0 bytes Salt*/
759 16, /* macKeySize 0*/
760 NULL, //set below
761 NULL, //set below
762 },
763 {
764 32, /* encKeySize: CTR 16 bytes Encryption Key and 4 bytes Salt : 24 bytes:NWAL_SA_EALG_3DES_CBC and 0 bytes Salt*/
765 20, /* macKeySize: 16 bytes NWAL_SA_AALG_HMAC_SHA1 */
766 NULL, //set below
767 NULL, //set below
768 },
769 {
770 20, /* encKeySize: CTR 16 bytes Encryption Key and 4 bytes Salt */
771 32, /* macKeySize: 16 bytes NWAL_SA_AALG_HMAC_SHA2_256 */
772 NULL, //set below
773 NULL, //set below
774 },
775 {
776 24, /* encKeySize: DES-CBC: 24 bytes:NWAL_SA_EALG_3DES_CBC and 0 bytes Salt*/
777 32, /* macKeySize: 16 bytes NWAL_SA_AALG_HMAC_SHA2_256 */
778 NULL, //set below
779 NULL, //set below
780 },
781 {
782 0, /* NWAL_SA_EALG_NULL*/
783 16, /* NWAL_SA_AALG_HMAC_MD5, 16 bytes */
784 NULL, //set below
785 NULL, //set below
786 },
787 {
788 20, /* encKeySize: GCM 16 bytes Encryption Key and 4 bytes Salt */
789 0, /* macKeySize: 0*/
790 NULL, //set below
791 NULL, //set below
792 },
793 {
794 19, /* encKeySize: CTR 16 bytes Encryption Key and 3 bytes Salt t*/
795 0, /* macKeySize 0*/
796 NULL, //set below
797 NULL, //set below
798 },
799 {
800 0, /* encKeySize: CTR 16 bytes Encryption Key and 3 bytes Salt : 24 bytes:NWAL_SA_EALG_AES_CTR and 0 bytes Salt*/
801 16, /* macKeySize 0*/
802 NULL, //set below
803 NULL, //set below
804 }
805 };
808 static uint8_t ourAuthKey[36] =
809 {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F,
810 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F,
811 0x20, 0x21, 0x22, 0x23 };
812 ;
814 static uint8_t ourEncrKey[36] =
815 {0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0xFF,
816 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0xFF,
817 0x30, 0x31, 0x32, 0x33 };
820 /*************************END NETAPI OBJECTS***********************/
822 #define START_SRC_IP 0x0a00000a
823 #define DST_IP 0xc0a80001
824 #define NEW_START_SRC_IP 0x9eda000a
825 #define DST_PORT 0x555
826 #define START_SRC_PORT 0x1234
827 #define NEW_START_SRC_PORT 100
828 void update_header(HEAD_T * p_head, int len)
829 {
830 unsigned char *p = (unsigned char *) &p_head->udp[1];
831 len -= (20+14);
832 /* update ip checksum */
833 /* update udp checksum */
834 /* update length */
835 *p= (len&0xff00)>>8;
836 *(p+1) = len&0xff;
837 }
839 //===========stub transmitter==================
840 void send_pkt(Ti_Pkt *pkt, int len)
841 {
842 //just free pkt. Don't send
843 Pktlib_freePacket((Ti_Pkt*)pkt);
844 return;
845 }
848 /* check header */
849 struct LastPktInfo
850 {
851 int iface;
852 int ipcsum;
853 int l4csum;
854 } ;
855 static struct LastPktInfo lpInfo;
858 void recv_cb_bench(struct PKTIO_HANDLE_Tag * channel, Ti_Pkt* p_recv[],
859 PKTIO_METADATA_T meta[], int n_pkts,
860 uint64_t ts )
861 {
862 }
864 /****************************************************************************************/
865 /******************SB Accelerator Callback PKT RECEIVE HANDLER *************************/
866 /****************** Handles Decrypt and Encrypt operation callbacks ******************/
867 /******************************************************************************************/
868 void recv_sb_cb(struct PKTIO_HANDLE_Tag * channel, Ti_Pkt* p_recv[],
869 PKTIO_METADATA_T meta[], int n_pkts,
870 uint64_t ts )
871 {
872 }
874 /******************************************************/
875 /******************PKT RECEIVE HANDLER *************************/
876 /******************************************************/
877 void recv_cb(struct PKTIO_HANDLE_Tag * channel, Ti_Pkt* p_recv[],
878 PKTIO_METADATA_T meta[], int n_pkts,
879 uint64_t ts )
880 {
881 }
883 //******************************************************
884 //use scheduling housekeeping callback to generate pkts
885 //******************************************************
886 static int done_burst=0;
887 void house(NETAPI_SCHED_HANDLE_T * s)
888 {
889 }
891 void build_sa_db(int i)
892 {
893 long tmp_spi;
894 static uint32_t spi = 11111111;
895 if ((tx_sa[0].authMode == NWAL_SA_AALG_HMAC_SHA1) && (tx_sa[0].cipherMode == NWAL_SA_EALG_AES_CBC))
896 {
897 tx_sa[0].spi = rx_sa[0].spi =spi++;
898 /* static configuration, will not change */
899 sa_info[i].tx_payload_info.aadSize = 0;
900 sa_info[i].tx_payload_info.pAad = NULL;
901 sa_info[i].tx_payload_info.pAuthIV = NULL;
902 sa_info[i].tx_payload_info.authOffset = netTest_MAC_HEADER_LEN + netTest_IP_HEADER_LEN; /*done: same for all cipher suites */
903 sa_info[i].tx_payload_info.encOffset = netTest_MAC_HEADER_LEN +
904 netTest_IP_HEADER_LEN +
905 netTest_ESP_HEADER_LEN +
906 netTest_AES_CBC_IV_LEN;
908 /* dynamic configuration, will be calculated on the fly */
909 sa_info[i].tx_payload_info.authSize = 0; /* pkt len - mac - ip -icv (12) */
910 sa_info[i].tx_payload_info.encSize = 0; /* authSize - esp header size (always 8 bytes) */
911 sa_info[i].tx_payload_info.pEncIV = 0;
912 sa_info[i].tx_payload_info.pPkt = 0; /* not being referenced in net_test */
914 sa_info[i].cipherMode = NWAL_SA_EALG_AES_CBC;
915 sa_info[i].inner_ip_offset = sa_info[i].tx_payload_info.encOffset;
916 sa_info[i].auth_tag_size = netTest_ICV_LEN; /* icv or mac size,. always 12 except for AES_CCM/AES_GCM */
918 sa_info[i].tx_pkt_info.enetPort = 0;
919 sa_info[i].tx_pkt_info.ipOffBytes = sa_info[i].tx_payload_info.encOffset;
920 sa_info[i].tx_pkt_info.l4HdrLen = netTest_UDP_HEADER_LEN; /*UDP header len */
921 sa_info[i].tx_pkt_info.l4OffBytes = sa_info[i].inner_ip_offset + netTest_IP_HEADER_LEN;
922 sa_info[i].tx_pkt_info.startOffset = 0;
923 sa_info[i].tx_pkt_info.lpbackPass = 0;
924 sa_info[i].tx_pkt_info.ploadLen = 0; /*sa_info[i].tx_pkt_info.l4OffBytes + 4 */
925 sa_info[i].tx_pkt_info.pPkt = NULL;
926 sa_info[i].tx_pkt_info.saOffBytes = netTest_MAC_HEADER_LEN + netTest_IP_HEADER_LEN;
927 sa_info[i].tx_pkt_info.saPayloadLen = 0;
928 sa_info[i].tx_pkt_info.pseudoHdrChecksum =0;
930 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 ;
932 tmp_spi = htonl((long)(tx_sa[0].spi));
933 trie_insert(p_trie_sa,(char *)&tmp_spi,4, (void *) &sa_info[i]); //asociate with tx sa SPI
936 }
937 else if ((tx_sa[i].authMode == NWAL_SA_AALG_HMAC_SHA2_256) && (tx_sa[i].cipherMode == NWAL_SA_EALG_AES_CTR))
938 {
939 tx_sa[i].spi = rx_sa[i].spi =spi++;
940 /* static configuration, will not change */
941 sa_info[i].tx_payload_info.aadSize = 0;
942 sa_info[i].tx_payload_info.pAad = NULL;
943 sa_info[i].tx_payload_info.pAuthIV = NULL;
944 sa_info[i].tx_payload_info.authOffset = netTest_MAC_HEADER_LEN + netTest_IP_HEADER_LEN; /*done: same for all cipher suites */
945 sa_info[i].tx_payload_info.encOffset = netTest_MAC_HEADER_LEN +
946 netTest_IP_HEADER_LEN +
947 netTest_ESP_HEADER_LEN +
948 netTest_AES_CTR_IV_LEN;
953 /* dynamic configuration, will be calculated on the fly */
954 sa_info[i].tx_payload_info.authSize = 0;
955 sa_info[i].tx_payload_info.encSize = 0;
956 sa_info[i].tx_payload_info.pEncIV = 0;
957 sa_info[i].tx_payload_info.pPkt = 0;
959 sa_info[i].cipherMode = NWAL_SA_EALG_AES_CTR;
960 sa_info[i].inner_ip_offset = sa_info[i].tx_payload_info.encOffset;
961 sa_info[i].auth_tag_size = netTest_ICV_LEN; /* icv or mac size,. always 12 except for AES_CCM/AES_GCM */
964 sa_info[i].tx_pkt_info.enetPort = 0;
965 sa_info[i].tx_pkt_info.ipOffBytes = sa_info[i].tx_payload_info.encOffset;
966 sa_info[i].tx_pkt_info.l4HdrLen = netTest_UDP_HEADER_LEN; /*UDP header len */
967 sa_info[i].tx_pkt_info.l4OffBytes = sa_info[i].inner_ip_offset + netTest_IP_HEADER_LEN;
968 sa_info[i].tx_pkt_info.startOffset = 0;
969 sa_info[i].tx_pkt_info.lpbackPass = 0;
970 sa_info[i].tx_pkt_info.ploadLen = 0; /*sa_info[i].tx_pkt_info.l4OffBytes + 4 */
971 sa_info[i].tx_pkt_info.pPkt = NULL;
972 sa_info[i].tx_pkt_info.saOffBytes = netTest_MAC_HEADER_LEN + netTest_IP_HEADER_LEN;
973 sa_info[i].tx_pkt_info.saPayloadLen = 0;
974 sa_info[i].tx_pkt_info.pseudoHdrChecksum =0;
976 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 ;
977 tmp_spi = htonl((long)(tx_sa[i].spi));
978 trie_insert(p_trie_sa,(char *)&tmp_spi,4, (void *) &sa_info[i]); //asociate with tx sa SPI
979 }
980 else if ((tx_sa[i].authMode == NWAL_SA_AALG_HMAC_SHA2_256) && (tx_sa[i].cipherMode == NWAL_SA_EALG_3DES_CBC))
981 {
982 tx_sa[i].spi = rx_sa[i].spi =spi++;
983 /* static configuration, will not change */
984 sa_info[i].tx_payload_info.aadSize = 0;
985 sa_info[i].tx_payload_info.pAad = NULL;
986 sa_info[i].tx_payload_info.pAuthIV = NULL;
987 sa_info[i].tx_payload_info.authOffset = netTest_MAC_HEADER_LEN + netTest_IP_HEADER_LEN; /*done: same for all cipher suites */
988 sa_info[i].tx_payload_info.encOffset = netTest_MAC_HEADER_LEN +
989 netTest_IP_HEADER_LEN +
990 netTest_ESP_HEADER_LEN +
991 netTest_3DES_CBC_IV_LEN;
993 /* dynamic configuration, will be calculated on the fly */
994 sa_info[i].tx_payload_info.authSize = 0;
995 sa_info[i].tx_payload_info.encSize = 0;
996 sa_info[i].tx_payload_info.pEncIV = 0;
997 sa_info[i].tx_payload_info.pPkt = 0;
999 sa_info[i].cipherMode = NWAL_SA_EALG_3DES_CBC;
1000 sa_info[i].inner_ip_offset = sa_info[i].tx_payload_info.encOffset;
1001 sa_info[i].auth_tag_size = netTest_ICV_LEN; /* icv or mac size,. always 12 except for AES_CCM/AES_GCM */
1004 sa_info[i].tx_pkt_info.enetPort = 0;
1005 sa_info[i].tx_pkt_info.ipOffBytes = sa_info[i].tx_payload_info.encOffset;
1006 sa_info[i].tx_pkt_info.l4HdrLen = netTest_UDP_HEADER_LEN; /*UDP header len */
1007 sa_info[i].tx_pkt_info.l4OffBytes = sa_info[i].inner_ip_offset + netTest_IP_HEADER_LEN;
1008 sa_info[i].tx_pkt_info.startOffset = 0;
1009 sa_info[i].tx_pkt_info.lpbackPass = 0;
1010 sa_info[i].tx_pkt_info.ploadLen = 0; /*sa_info[i].tx_pkt_info.l4OffBytes + 4 */
1011 sa_info[i].tx_pkt_info.pPkt = NULL;
1012 sa_info[i].tx_pkt_info.saOffBytes = netTest_MAC_HEADER_LEN + netTest_IP_HEADER_LEN;
1013 sa_info[i].tx_pkt_info.saPayloadLen = 0;
1014 sa_info[i].tx_pkt_info.pseudoHdrChecksum =0;
1016 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 ;
1018 tmp_spi = htonl((long)(tx_sa[i].spi));
1019 trie_insert(p_trie_sa,(char *)&tmp_spi,4, (void *) &sa_info[i]); //asociate with tx sa SPI
1020 }
1021 else if ((tx_sa[i].authMode == NWAL_SA_AALG_HMAC_MD5) && (rx_sa[i].cipherMode == NWAL_SA_EALG_NULL))
1022 {
1023 tx_sa[i].spi = rx_sa[i].spi =spi++;
1024 /* static configuration, will not change */
1025 sa_info[i].tx_payload_info.aadSize = 0;
1026 sa_info[i].tx_payload_info.pAad = NULL;
1027 sa_info[i].tx_payload_info.pAuthIV = NULL;
1028 sa_info[i].tx_payload_info.authOffset = netTest_MAC_HEADER_LEN + netTest_IP_HEADER_LEN; /*done: same for all cipher suites */
1030 sa_info[i].tx_payload_info.encOffset = netTest_MAC_HEADER_LEN +
1031 netTest_IP_HEADER_LEN +
1032 netTest_ESP_HEADER_LEN +
1033 netTest_NULL_IV_LEN;
1037 /* dynamic configuration, will be calculated on the fly */
1038 sa_info[i].tx_payload_info.authSize = 0;
1039 sa_info[i].tx_payload_info.encSize = 0;
1040 sa_info[i].tx_payload_info.pEncIV = 0;
1041 sa_info[i].tx_payload_info.pPkt = 0;
1043 sa_info[i].cipherMode = NWAL_SA_EALG_NULL;
1044 sa_info[i].inner_ip_offset = sa_info[i].tx_payload_info.encOffset;
1045 sa_info[i].auth_tag_size = netTest_ICV_LEN; /* icv or mac size,. always 12 except for AES_CCM/AES_GCM */
1047 sa_info[i].tx_pkt_info.enetPort = 0;
1048 sa_info[i].tx_pkt_info.ipOffBytes = sa_info[i].tx_payload_info.encOffset;
1049 sa_info[i].tx_pkt_info.l4HdrLen = netTest_UDP_HEADER_LEN; /*UDP header len */
1050 sa_info[i].tx_pkt_info.l4OffBytes = sa_info[i].inner_ip_offset + netTest_IP_HEADER_LEN;
1051 sa_info[i].tx_pkt_info.startOffset = 0;
1052 sa_info[i].tx_pkt_info.lpbackPass = 0;
1053 sa_info[i].tx_pkt_info.ploadLen = 0; /*sa_info[i].tx_pkt_info.l4OffBytes + 4 */
1054 sa_info[i].tx_pkt_info.pPkt = NULL;
1055 sa_info[i].tx_pkt_info.saOffBytes = netTest_MAC_HEADER_LEN + netTest_IP_HEADER_LEN;
1056 sa_info[i].tx_pkt_info.saPayloadLen = 0;
1057 sa_info[i].tx_pkt_info.pseudoHdrChecksum =0;
1059 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 ;
1060 tmp_spi = htonl((long)(tx_sa[i].spi));
1061 trie_insert(p_trie_sa,(char *)&tmp_spi,4, (void *) &sa_info[i]); //asociate with tx sa SPI
1062 }
1063 else if ((tx_sa[i].authMode == NWAL_SA_AALG_NULL) && (rx_sa[i].cipherMode == NWAL_SA_EALG_AES_GCM))
1064 {
1065 tx_sa[i].spi = rx_sa[i].spi =spi++;
1066 /* static configuration, will not change */
1067 sa_info[i].tx_payload_info.aadSize = 0;
1068 sa_info[i].tx_payload_info.pAad = NULL;
1069 sa_info[i].tx_payload_info.pAuthIV = NULL;
1070 sa_info[i].tx_payload_info.authOffset = netTest_MAC_HEADER_LEN + netTest_IP_HEADER_LEN; /*done: same for all cipher suites */
1071 //sa_info[i].tx_payload_info.encIvSize = netTest_AES_GCM_IV_LEN;
1073 sa_info[i].tx_payload_info.encOffset = netTest_MAC_HEADER_LEN +
1074 netTest_IP_HEADER_LEN +
1075 netTest_ESP_HEADER_LEN +
1076 netTest_AES_GCM_IV_LEN;
1080 /* dynamic configuration, will be calculated on the fly */
1081 sa_info[i].tx_payload_info.authSize = 0;
1082 sa_info[i].tx_payload_info.encSize = 0;
1083 //sa_info[i].tx_payload_info.ploadLen = 0;
1084 sa_info[i].tx_payload_info.pEncIV = 0;
1085 sa_info[i].tx_payload_info.pPkt = 0;
1087 sa_info[i].cipherMode = NWAL_SA_EALG_AES_GCM;
1088 sa_info[i].inner_ip_offset = sa_info[i].tx_payload_info.encOffset;
1089 sa_info[i].auth_tag_size = netTest_AES_GCM_CCM_ICV_LEN; /* icv or mac size,. always 12 except for AES_CCM/AES_GCM */
1091 sa_info[i].tx_pkt_info.enetPort = 0;
1092 sa_info[i].tx_pkt_info.ipOffBytes = sa_info[i].tx_payload_info.encOffset;
1093 sa_info[i].tx_pkt_info.l4HdrLen = netTest_UDP_HEADER_LEN; /*UDP header len */
1094 sa_info[i].tx_pkt_info.l4OffBytes = sa_info[i].inner_ip_offset + netTest_IP_HEADER_LEN;
1095 sa_info[i].tx_pkt_info.startOffset = 0;
1096 sa_info[i].tx_pkt_info.lpbackPass = 0;
1097 sa_info[i].tx_pkt_info.ploadLen = 0; /*sa_info[i].tx_pkt_info.l4OffBytes + 4 */
1098 sa_info[i].tx_pkt_info.pPkt = NULL;
1099 sa_info[i].tx_pkt_info.saOffBytes = netTest_MAC_HEADER_LEN + netTest_IP_HEADER_LEN;
1100 sa_info[i].tx_pkt_info.saPayloadLen = 0;
1101 sa_info[i].tx_pkt_info.pseudoHdrChecksum =0;
1103 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 ;
1105 tmp_spi = htonl((long)(tx_sa[i].spi));
1106 trie_insert(p_trie_sa,(char *)&tmp_spi,4, (void *) &sa_info[i]); //asociate with tx sa SPI
1107 }
1108 else if ((tx_sa[i].authMode == NWAL_SA_AALG_NULL) && (rx_sa[i].cipherMode == NWAL_SA_EALG_AES_CCM))
1109 {
1110 tx_sa[i].spi = rx_sa[i].spi =spi++;
1111 /* static configuration, will not change */
1112 sa_info[i].tx_payload_info.aadSize = 0;
1113 sa_info[i].tx_payload_info.pAad = NULL;
1114 //sa_info[i].tx_payload_info.authIvSize = 0;
1115 sa_info[i].tx_payload_info.pAuthIV = NULL;
1116 sa_info[i].tx_payload_info.authOffset = netTest_MAC_HEADER_LEN + netTest_IP_HEADER_LEN; /*done: same for all cipher suites */
1118 sa_info[i].tx_payload_info.encOffset = netTest_MAC_HEADER_LEN +
1119 netTest_IP_HEADER_LEN +
1120 netTest_ESP_HEADER_LEN +
1121 netTest_AES_CCM_IV_LEN;
1123 /* dynamic configuration, will be calculated on the fly */
1124 sa_info[i].tx_payload_info.authSize = 0;
1125 sa_info[i].tx_payload_info.encSize = 0;
1126 //sa_info[i].tx_payload_info.ploadLen = 0;
1127 sa_info[i].tx_payload_info.pEncIV = 0;
1128 sa_info[i].tx_payload_info.pPkt = 0;
1130 sa_info[i].cipherMode = NWAL_SA_EALG_AES_CCM;
1131 sa_info[i].inner_ip_offset = sa_info[i].tx_payload_info.encOffset;
1132 sa_info[i].auth_tag_size = netTest_AES_GCM_CCM_ICV_LEN; /* icv or mac size,. always 12 except for AES_CCM/AES_GCM */
1134 sa_info[i].tx_pkt_info.enetPort = 0;
1135 sa_info[i].tx_pkt_info.ipOffBytes = sa_info[i].tx_payload_info.encOffset;
1136 sa_info[i].tx_pkt_info.l4HdrLen = netTest_UDP_HEADER_LEN; /*UDP header len */
1137 sa_info[i].tx_pkt_info.l4OffBytes = sa_info[i].inner_ip_offset + netTest_IP_HEADER_LEN;
1138 sa_info[i].tx_pkt_info.startOffset = 0;
1139 sa_info[i].tx_pkt_info.lpbackPass = 0;
1140 sa_info[i].tx_pkt_info.ploadLen = 0; /*sa_info[i].tx_pkt_info.l4OffBytes + 4 */
1141 sa_info[i].tx_pkt_info.pPkt = NULL;
1142 sa_info[i].tx_pkt_info.saOffBytes = netTest_MAC_HEADER_LEN + netTest_IP_HEADER_LEN;
1143 sa_info[i].tx_pkt_info.saPayloadLen = 0;
1144 sa_info[i].tx_pkt_info.pseudoHdrChecksum =0;
1146 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 ;
1148 tmp_spi = htonl((long)(tx_sa[i].spi));
1149 trie_insert(p_trie_sa,(char *)&tmp_spi,4, (void *) &sa_info[i]); //asociate with tx sa SPI
1150 }
1151 else if ((tx_sa[i].authMode == NWAL_SA_AALG_AES_XCBC) && (rx_sa[i].cipherMode == NWAL_SA_EALG_NULL))
1152 {
1153 tx_sa[i].spi = rx_sa[i].spi =spi++;
1154 /* static configuration, will not change */
1155 sa_info[i].tx_payload_info.aadSize = 0;
1156 sa_info[i].tx_payload_info.pAad = NULL;
1157 sa_info[i].tx_payload_info.pAuthIV = NULL;
1158 sa_info[i].tx_payload_info.authOffset = netTest_MAC_HEADER_LEN + netTest_IP_HEADER_LEN;
1161 sa_info[i].tx_payload_info.encOffset = netTest_MAC_HEADER_LEN +
1162 netTest_IP_HEADER_LEN +
1163 netTest_ESP_HEADER_LEN +
1164 netTest_NULL_IV_LEN;
1166 /* dynamic configuration, will be calculated on the fly */
1167 sa_info[i].tx_payload_info.authSize = 0;
1168 sa_info[i].tx_payload_info.encSize = 0;
1169 //sa_info[i].tx_payload_info.ploadLen = 0;
1170 sa_info[i].tx_payload_info.pEncIV = 0;
1171 sa_info[i].tx_payload_info.pPkt = 0;
1173 sa_info[i].cipherMode = NWAL_SA_EALG_NULL;
1174 sa_info[i].authMode = NWAL_SA_AALG_AES_XCBC;
1175 sa_info[i].inner_ip_offset = sa_info[i].tx_payload_info.encOffset;
1176 sa_info[i].auth_tag_size = netTest_ICV_LEN; /* icv or mac size,. always 12 except for AES_CCM/AES_GCM , GMAC*/
1178 sa_info[i].tx_pkt_info.enetPort = 0;
1179 sa_info[i].tx_pkt_info.ipOffBytes = sa_info[i].tx_payload_info.encOffset;
1180 sa_info[i].tx_pkt_info.l4HdrLen = netTest_UDP_HEADER_LEN; /*UDP header len */
1181 sa_info[i].tx_pkt_info.l4OffBytes = sa_info[i].inner_ip_offset + netTest_IP_HEADER_LEN;
1182 sa_info[i].tx_pkt_info.startOffset = 0;
1183 sa_info[i].tx_pkt_info.lpbackPass = 0;
1184 sa_info[i].tx_pkt_info.ploadLen = 0; /*sa_info[i].tx_pkt_info.l4OffBytes + 4 */
1185 sa_info[i].tx_pkt_info.pPkt = NULL;
1186 sa_info[i].tx_pkt_info.saOffBytes = netTest_MAC_HEADER_LEN + netTest_IP_HEADER_LEN;
1187 sa_info[i].tx_pkt_info.saPayloadLen = 0;
1188 sa_info[i].tx_pkt_info.pseudoHdrChecksum =0;
1190 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 ;
1192 tmp_spi = htonl((long)(tx_sa[i].spi));
1193 trie_insert(p_trie_sa,(char *)&tmp_spi,4, (void *) &sa_info[i]); //asociate with tx sa SPI
1194 }
1195 else
1196 printf("build_sa_db(): invalid encryption/authentication combination selected\n");
1198 //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);
1199 printf("build_sa_db spi 0x%x\n", spi);
1201 }
1203 /***************************************
1204 ********** test driver*****************
1205 ***************************************/
1206 int main(int argc, char **argv)
1207 {
1208 int err,i, j, count;
1209 Pktlib_HeapCfg heapCfg;
1210 rlim_t oss,ss = 1024*1024;
1211 struct rlimit rl;
1212 int32_t errCode;
1213 Pktlib_HeapIfTable* pPktifTable;
1216 FILE * fpr = NULL;
1219 err= getrlimit(RLIMIT_STACK,&rl);
1220 if (!err) printf(" stack limit = %d\n",rl.rlim_cur); else printf("getrlimit failed\n");
1223 memset(&sa_info, 0, sizeof(sa_info));
1225 /* create netapi */
1226 netapi_handle = netapi_init(NETAPI_SYS_MASTER, &our_netapi_default_cfg);
1228 /* open the main heap */
1229 ourHeap = Pktlib_findHeapByName("netapi");
1230 if (!ourHeap)
1231 {
1232 printf("Pktlib_findHeapByName() fail\n");
1233 exit(1);
1234 }
1236 /* create two secondary heaps */
1237 /* Initialize the heap configuration. */
1238 memset ((void *)&heapCfg, 0, sizeof(Pktlib_HeapCfg));
1240 pPktifTable = netapi_getPktlibIfTable();
1241 /* Populate the heap configuration */
1242 heapCfg.name = "netapi-small";
1243 heapCfg.memRegion = NETAPI_GLOBAL_REGION;
1244 heapCfg.sharedHeap = 1;
1245 heapCfg.useStarvationQueue = 0;
1246 heapCfg.dataBufferSize = 512;
1247 heapCfg.numPkts = 64;
1248 heapCfg.numZeroBufferPackets= 0;
1249 heapCfg.heapInterfaceTable.data_malloc = pPktifTable->data_malloc;
1250 heapCfg.heapInterfaceTable.data_free = pPktifTable->data_free;
1251 heapCfg.dataBufferPktThreshold = 0;
1252 heapCfg.zeroBufferPktThreshold = 0;
1254 specialSmall = Pktlib_createHeap(&heapCfg, &errCode);
1255 heapCfg.name = "netapi-big";
1256 heapCfg.dataBufferSize = 1600;
1257 specialLarge = Pktlib_createHeap(&heapCfg, &errCode);
1258 //register these heaps so poll routine will include their garbage queues.
1259 netapi_registerHeap(netapi_handle, specialSmall);
1260 netapi_registerHeap(netapi_handle, specialLarge);
1262 /* create a pktio channel */
1263 our_chan=pktio_create(netapi_handle,"our1stq",(PKTIO_CB) recv_cb_bench, &our_chan_cfg,&err);
1264 if (!our_chan)
1265 {
1266 printf("pktio create failed err=%d\n",err);
1267 exit(1);
1268 }
1270 /* open netcp default tx, rx queues */
1271 netcp_tx_chan_esp= pktio_open(netapi_handle, NETCP_TX, NULL, &netcp_tx_cfg, &err);
1272 if (!netcp_tx_chan_esp)
1273 {
1274 printf("pktio open TX failed err=%d\n",err);
1275 exit(1);
1276 }
1277 netcp_rx_chan= pktio_open(netapi_handle, NETCP_RX, (PKTIO_CB) recv_cb, &netcp_rx_cfg, &err);
1279 if (!netcp_rx_chan)
1280 {
1281 printf("pktio open RX failed err=%d\n",err);
1282 exit(1);
1283 }
1285 /* create a pktio channel for specially classified pkts */
1286 netcp_rx_chan2= pktio_create(netapi_handle, "classq", (PKTIO_CB) recv_cb, &netcp_rx_cfg2, &err);
1287 if (!netcp_rx_chan2) {printf("pktio create RX2 failed err=%d\n",err); exit(1);}
1289 /* open netcp default tx, rx queues for sideband crypto */
1290 netcp_sb_tx_chan= pktio_open(netapi_handle, NETCP_SB_TX, NULL, &netcp_sb_tx_cfg, &err);
1291 if (!netcp_sb_tx_chan)
1292 {
1293 printf("pktio open SB TX failed err=%d\n",err);
1294 exit(1);
1295 }
1296 netcp_sb_rx_chan= pktio_open(netapi_handle, NETCP_SB_RX, (PKTIO_CB) recv_sb_cb, &netcp_sb_rx_cfg, &err);
1297 if (!netcp_sb_rx_chan)
1298 {
1299 printf("pktio open SB RX failed err=%d\n",err);
1300 exit(1);
1301 }
1303 printf("net_test> %d bytes left in our CMA area\n", netapi_getBufMemRemainder());
1304 /* create scheduler instance */
1305 our_sched =netapi_schedOpen(netapi_handle,&our_sched_cfg, &err);
1306 if (!our_sched) {printf("sched create failed\n"); exit(1);}
1308 //#define PROMISCUOUS
1309 #define ETH0 0
1310 #define ETH1 1
1313 #if 0
1314 /* add mac intefaces */
1315 netcp_cfgCreateMacInterface(
1316 netapi_handle,
1317 &config.mac0[0],
1318 ETH0,0,
1319 (NETCP_CFG_ROUTE_HANDLE_T) NULL,
1320 (NETCP_CFG_VLAN_T ) NULL , //future
1321 1,
1322 &err);
1323 if (err) {printf("addmac0 failed %d\n",err); exit(1); }
1325 //attach an IP to this interface
1326 ip_rule0[0]=netcp_cfgAddIp(
1327 netapi_handle,
1328 ETH0,
1329 nwal_IPV4,
1330 &config.ip0,
1331 NULL, //all IP
1332 (NETCP_CFG_ROUTE_HANDLE_T) NULL,
1333 &err
1334 );
1335 if (err) {printf("addip0 failed %d\n",err); exit(1); }
1337 //create a 2nd mac instance
1338 netcp_cfgCreateMacInterface(
1339 netapi_handle,
1340 &config.mac1[0],
1341 ETH1,1,
1342 (NETCP_CFG_ROUTE_HANDLE_T) NULL,
1343 (NETCP_CFG_VLAN_T ) NULL , //future
1344 1,
1345 &err);
1346 if (err) {printf("addmac1 failed %d\n",err); exit(1); }
1348 //attach an IP to this interface
1349 ip_rule1[0]=netcp_cfgAddIp(
1350 netapi_handle,
1351 ETH1,
1352 nwal_IPV4,
1353 &config.ip1,
1354 NULL, //all IP
1355 (NETCP_CFG_ROUTE_HANDLE_T) NULL,
1356 &err
1357 );
1358 if (err) {printf("addip1 failed %d\n",err); exit(1); }
1359 #endif
1362 #if todo
1363 //attach 2 classifiers to iface 0, ip0
1364 class_0_cfg.u.c_l4.ip = ip_rule0[0];
1365 class_0 = netcp_cfgAddClass(netapi_handle,
1366 &class_0_cfg,
1367 NULL,
1368 NETCP_CFG_ACTION_TO_SW,
1369 &err);
1370 if (err) {printf("addclass0 failed %d\n",err); exit(1);}
1372 class_1_cfg.u.c_l4.ip = ip_rule0[0];
1373 class_1 = netcp_cfgAddClass(netapi_handle,
1374 &class_1_cfg,
1375 NULL,
1376 NETCP_CFG_ACTION_TO_SW,
1377 &err);
1378 if (err) {printf("addclass1 failed %d\n",err); exit(1);}
1381 //3rd classifier has a different IP and route
1382 class_2_cfg.u.c_l3_l4.ip_addr = &config.ip2;
1383 #endif
1385 //create specialFlow for this classifier
1386 {
1387 Pktlib_HeapHandle heaps[2];
1388 //int sizes[2];
1389 heaps[0]= specialSmall;
1390 heaps[1]= specialLarge;
1391 #define SPECIAL_SOP_OFF 128
1392 // sizes[0]=512-SPECIAL_SOP_OFF;
1393 //sizes[1]=1600-SPECIAL_SOP_OFF;
1394 }
1396 //security stuff
1397 p_trie_sa = trie_new();
1398 if (!p_trie_sa) {printf("trie alloc for SA failed\n"); exit(1);}
1400 count = 0;
1402 #ifdef TEST_MAC_IP
1403 for (i = 0; i < MAC_CREATE_LOOP_COUNT ;i++)
1404 {
1405 /* add mac intefaces */
1406 netcp_cfgCreateMacInterface(
1407 netapi_handle,
1408 &config.mac0[0],
1409 i,0,
1410 (NETCP_CFG_ROUTE_HANDLE_T) NULL,
1411 (NETCP_CFG_VLAN_T ) NULL , //future
1412 1,
1413 &err);
1414 if (err) {printf("addmac0 failed %d\n",err); exit(1); }
1415 else
1416 {
1417 printf("addmac0 passed for index %d, mac before %d\n",i, config.mac0[5]);
1418 config.mac0[3]++;
1419 }
1420 }
1422 for (i = 0; i < IP_CREATE_LOOP_COUNT ;i++)
1423 {
1424 //attach an IP to this interface
1425 ip_rule0[i]=netcp_cfgAddIp(
1426 netapi_handle,
1427 0,
1428 nwal_IPV4,
1429 &config.ip0,
1430 NULL, //all IP
1431 (NETCP_CFG_ROUTE_HANDLE_T) NULL,
1432 &err
1433 );
1434 if (err) {printf("addip0 failed %d\n",err); exit(1); }
1435 else
1436 {
1437 printf("addip0 passed for index%d ip[3] %d\n",i, config.ip0.ipv4[3]);
1438 config.ip0.ipv4[3]++;
1439 }
1441 }
1442 #endif
1445 sleep(1);
1446 #ifdef TEST_SA
1448 for (i = 0; i < SA_CREATE_LOOP_COUNT;i++)
1449 {
1450 ourRXKeyParams[0].pEncKey = &ourEncrKey[0];
1451 ourRXKeyParams[0].pAuthKey = &ourAuthKey[0];
1452 memcpy(&(rx_sa[0].src), &config.remote_ipsec_ip,4);
1453 memcpy(&(rx_sa[0].dst), &config.local_ipsec_ip,4);
1455 build_sa_db(i);
1456 count++;
1457 printf("main: calling netapi_secAddSA for rx, count = %d\n", count);
1458 sa_info[i].rx_tunnel = netapi_secAddSA(
1459 netapi_handle,
1460 config.ipsec_if_no, //iface #0
1461 &rx_sa[0],
1462 &ourRXKeyParams[0],
1463 config.ipsec_mode_rx == IPSEC_MODE_RX_SIDEBAND ? NETAPI_SEC_SA_SIDEBAND: NETAPI_SEC_SA_INFLOW,
1464 NULL, //use default route
1465 &(sa_info[i].rx_data_mode_handle),
1466 &(sa_info[i].rx_inflow_mode_handle),
1467 &err);
1468 //if (err) {printf("addRxSa failed %d\n",err); exit(1);}
1469 if (err) {printf("addRxSa failed %d\n",err);}
1472 }
1473 //tx SA
1474 //security stuff
1475 for (i = 0; i <SA_CREATE_LOOP_COUNT;i++)
1476 {
1477 ourTXKeyParams[0].pEncKey = &ourEncrKey[0];
1478 ourTXKeyParams[0].pAuthKey = &ourAuthKey[0];
1479 memcpy(&(tx_sa[0].src), &config.local_ipsec_ip,4);
1480 memcpy(&(tx_sa[0].dst), &config.remote_ipsec_ip,4);
1481 count++;
1482 printf("main: calling netapi_secAddSA for tx, count = %d\n", count);
1483 sa_info[i].tx_tunnel = netapi_secAddSA( netapi_handle,
1484 0, //iface #0
1485 &tx_sa[0],
1486 &ourTXKeyParams[0],
1487 config.ipsec_mode_tx == IPSEC_MODE_TX_SIDEBAND ? NETAPI_SEC_SA_SIDEBAND: NETAPI_SEC_SA_INFLOW,
1488 NULL, //use default route
1489 &(sa_info[i].tx_data_mode_handle),
1490 &(sa_info[i].tx_inflow_mode_handle),
1491 &err);
1492 if (err) {printf("addTxSa failed %d\n",err); exit(1);}
1493 }
1495 #endif
1497 /*************************************************
1498 ************CLEAN UP****************************
1499 ************************************************/
1501 //delete Classifiers
1502 netcp_cfgDelClass(netapi_handle, class_0, &err);
1503 netcp_cfgDelClass(netapi_handle, class_1, &err);
1504 //netcp_cfgDelClass(netapi_handle, class_2, &err);
1506 count = 0;
1507 //delete policy
1508 #ifdef TEST_SA
1509 for (i = 0; i < SA_CREATE_LOOP_COUNT;i++)
1510 {
1511 if (rx_policy[i])
1512 netapi_secDelRxPolicy(netapi_handle, rx_policy[i], &err);
1513 count ++;
1514 //delete tunnels
1515 printf("main: calling netapi_secDelSA for rx, count = %d\n", count);
1516 netapi_secDelSA(netapi_handle, 0, sa_info[i].rx_tunnel, &err);
1517 //sleep(1);
1518 //printf("main: calling netapi_secDelSA for tx, count = %d\n", count);
1519 netapi_secDelSA(netapi_handle, 0, sa_info[i].tx_tunnel, &err);
1520 }
1521 #endif
1523 #ifdef TEST_MAC_IP
1524 //delete IPs and MAC Interfacess
1525 for (i = 0; i < IP_CREATE_LOOP_COUNT;i++)
1526 {
1527 printf("calling netcp_cfgDelIp and for index %d\n", i);
1528 netcp_cfgDelIp(netapi_handle, i, 0, NULL, NULL, ip_rule0[i], &err);
1529 netcp_cfgDelMac(netapi_handle,i,&err);
1530 }
1531 for (i = 0; i < MAC_CREATE_LOOP_COUNT;i++)
1532 {
1533 printf("calling and netcp_cfgDelMac for index %d\n", i);
1534 netcp_cfgDelMac(netapi_handle,i,&err);
1535 }
1536 #endif
1537 //close pktio channels we opened
1538 printf("main: calling pktio_close for netcp_tx_chan_esp\n");
1539 pktio_close(netcp_tx_chan_esp ,&err);
1540 printf("main: calling pktio_close for netcp_rx_chan\n");
1541 pktio_close(netcp_rx_chan ,&err);
1542 printf("main: calling pktio_close for netcp_sb_tx_chan\n");
1543 pktio_close(netcp_sb_tx_chan ,&err);
1544 printf("main: calling pktio_close for netcp_sb_rx_chan\n");
1545 pktio_close(netcp_sb_rx_chan ,&err);
1547 //clear pktio channel we created
1548 pktio_control(our_chan, (PKTIO_CB) NULL, (PKTIO_CFG_T *) NULL, &zap_channel_control, &err);
1549 pktio_control(netcp_rx_chan2, (PKTIO_CB) NULL, (PKTIO_CFG_T *) NULL, &zap_channel_control, &err);
1551 //delete pktio channels we created
1552 pktio_delete(our_chan, &err);
1553 pktio_delete(netcp_rx_chan2,&err);
1554 netapi_shutdown(netapi_handle);
1556 }