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