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