]> Gitweb @ Texas Instruments - Open Source Git Repositories - git.TI.com/gitweb - keystone-rtos/netapi.git/blob - ti/runtime/netapi/test/net_test.c
This commit adds the following:
[keystone-rtos/netapi.git] / ti / runtime / netapi / test / net_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  *****************************************/
44 #include <stdio.h>
45 #include <stdlib.h>
46 #include <unistd.h>
47 #include <string.h>
48 #include <signal.h>
49 #include <pthread.h>
51 #include "net_test.h"
52 #include "trie.h"
53 #include "string.h"
55 #include <sys/resource.h>
57 #include <ti/drv/sa/salld.h>
58 #include <ti/drv/pa/pa.h>
60 #include "net_test_utils.h"
61 #include "router.h"
63 extern int QUIT;
64 extern STATS_T stats[TUNE_NETAPI_NUM_CORES];
65 extern paSysStats_t netcp_stats;
66 /* Global definitions */
67 #ifdef MULTI_THREAD
68     cpu_set_t cpu_set;
69 #endif
71 netTestConfig_t netTestCfg;
72 static  netTestConfigFile_t config_file;
74 char    input_file_name[] = "net_test_config.txt";
76 nwal_RetValue       nwalRetVal;
77 Pktlib_HeapHandle ourHeap;
79 PKTIO_HANDLE_T *netcp_rx_chan;
80 PKTIO_HANDLE_T *netcp_tx_chan_no_crypto;
81 PKTIO_HANDLE_T *netcp_tx_chan_esp;
82 PKTIO_HANDLE_T *netcp_tx_chan_ah;
83 PKTIO_HANDLE_T *netcp_sb_tx_chan;
84 PKTIO_HANDLE_T *netcp_sb_rx_chan;
86 PKTIO_CFG_T our_chan_cfg={PKTIO_RX_TX, PKTIO_LOCAL, PKTIO_Q_ANY, 8};
87 PKTIO_CFG_T netcp_rx_cfg={PKTIO_RX, PKTIO_NA, PKTIO_NA, 8};
88 PKTIO_CFG_T netcp_rx_cfg2={PKTIO_RX, (PKTIO_GLOBAL|PKTIO_PKT), PKTIO_Q_ANY, 8};
89 PKTIO_CFG_T netcp_tx_cfg={PKTIO_TX, PKTIO_NA, PKTIO_NA, 8};
90 PKTIO_CFG_T netcp_sb_rx_cfg={PKTIO_RX, PKTIO_NA, PKTIO_NA, 8};
91 PKTIO_CFG_T netcp_sb_tx_cfg={PKTIO_TX, PKTIO_NA, PKTIO_NA, 8};
94 NETCP_CFG_EXCEPTION_PKT_T expPkt_appid;
96 Trie *p_trie_sa_rx;
97 Trie *p_trie_sa_tx;
100 /*******************************************
101  *************NETAPI OBJECTS***************
102  *****************************************/
103 static NETAPI_CFG_T our_netapi_default_cfg=
105 TUNE_NETAPI_PERM_MEM_SZ,
106 128,  //start of packet offset for hw to place data on rx for default flow
107 TUNE_NETAPI_QM_CONFIG_MAX_DESC_NUM, //max number of descriptors in system
108 TUNE_NETAPI_NUM_GLOBAL_DESC,        //total we will use
109 TUNE_NETAPI_DEFAULT_NUM_BUFFERS,   //#descriptors+buffers in default heap
110 64, //#descriptors w/o buffers in default heap
111 TUNE_NETAPI_DEFAULT_BUFFER_SIZE+128+128,  //size of buffers in default heap
112 128   ,  //tail room
113 256      //extra room 
114 };
116 NETAPI_T netapi_handle;
117 NETAPI_SCHED_HANDLE_T * our_sched;
118 #ifdef MULTI_THREAD
119 NETAPI_SCHED_HANDLE_T * scheduler[TUNE_NETAPI_NUM_CORES];
120 #endif
121 NETAPI_SCHED_CONFIG_T our_sched_cfg={
122   NETAPI_SCHED_DURATION|NETAPI_SCHED_CBV, 0, house, 5000000  //every 5000000 poll loops
123 };
125 NETCP_CFG_IP_T ip_rule[NET_TEST_MAX_IP];
126 NETCP_CFG_MACIF_T mac[NET_TEST_MAX_MAC];
130 /* security objects. (for loopback mode) */
131 netTestSA_t sa_info[MAX_SEC_INDEX];
133 NETCP_CFG_IPSEC_POLICY_T rx_policy[MAX_SEC_INDEX];
137 /*--------------------------------------------------------------
138  *----------utility to flip a packet and send 
139  *--------------------back to source----------------------------
140  *                   flag=1 => ipsec
141  *--------------------------------------------------------------*/
142 void flip_and_send_pkt(Ti_Pkt *tip,  unsigned char * p_pkt, int len, int flag, uint16_t enet_port)
144     unsigned char mac_temp[6];
145     unsigned char ip_temp[4];
146     unsigned char new_dest_port[2]={0x75,0x30};  // 30000
147     uint16_t blah; 
148     uint16_t i=1;   /* for testing only */
150     uint8_t *p_spi; 
151     netTestSA_t * p_sa_info;
152     netTestSA_t *p_sa_info_tx;
153     uint8_t p_iv[16];
154     uint8_t p_add[8];
155     Cppi_HostDesc*          pPloadDesc;
156     uint8_t ah_len;
157     uint32_t tunnel_id;
158     nwalLocCxtInfo_t    nwalLocCxt;
159     HEAD_T * p_head;
160     HEAD_T temp_head;
161     int pkt_type;
163 #ifdef MULTI_THREAD
164     int coreid=Osal_nwalGetProcId(); //who we are(thread local)
165         //int coreid = our_core;
166 #else
167 int coreid=0;
168 #endif
169               //netapi_dump_buf((long*)p_pkt,len);
170     Pktlib_setPacketLen(tip,len);
171     //flip the mac address
172     memcpy(&mac_temp,&p_pkt[0],6);
173     memcpy(&p_pkt[0],&p_pkt[6],6);
174     memcpy(&p_pkt[6],&mac_temp,6);
175     //memcpy(&p_pkt[0],real_mac_header,6); //for testing to wireshark pc
177     //flip the ip  (outer in case of ipsec)
178     memcpy(&ip_temp, &p_pkt[14+12],4);
179     memcpy(&p_pkt[14+12],&p_pkt[14+12+4],4);
180     memcpy(&p_pkt[14+12+4],&ip_temp,4);
182     p_head=&temp_head;
184     //inner ip &udp for ipsec
185     if (flag) 
186     {
187         memcpy(p_head,&p_pkt[14],sizeof(HEAD_T));
189         if ((p_head->ip[2]&0x0000ff00)==0x00003300)
190         {
191             p_spi = &(p_pkt[netTest_MAC_HEADER_LEN+netTest_IP_HEADER_LEN + 4]);
192             pkt_type = IPSEC_AH_PKT;
193             printf("flip_and_send_pkt: AH packet received\n");
194         }
195         else if ((p_head->ip[2]&0x0000ff00)==0x00003200)
196         {
197             p_spi = &(p_pkt[netTest_MAC_HEADER_LEN+netTest_IP_HEADER_LEN]);
198             pkt_type = IPSEC_ESP_PKT;
199         }
200         else
201         {
202             printf("flip_and_send_pkt: un-supported IPSEC protocol\n");
203             Pktlib_freePacket(tip);
204             return;
205         }
207         p_sa_info = (netTestSA_t *) trie_lookup(p_trie_sa_rx, (char *)p_spi ,4);
208         if (p_sa_info == NULL)
209         {
210             printf("flip_and_send_pkt(): trie_lookup() failed\n");
211             Pktlib_freePacket(tip);
212             return;
213         }
214         tunnel_id = p_sa_info->tunnel_id;
215         p_sa_info_tx = (netTestSA_t *) trie_lookup(p_trie_sa_tx, (char *)&tunnel_id ,4);
216         if (p_sa_info_tx == NULL)
217         {
218             printf("flip_and_send_pkt(): trie_lookup() failed\n");
219             Pktlib_freePacket(tip);
220             return;
221         }
222         //just drop non-udp packet
223         if (p_pkt[p_sa_info->tx_payload_info.encOffset+9]!=0x11)
224         {
225             stats[coreid].n_new+=1;Pktlib_freePacket(tip); return;
226         }
228         /* flip inner IP */
229         memcpy(&ip_temp, &p_pkt[p_sa_info->tx_payload_info.encOffset+12],4);
230         memcpy(&p_pkt[p_sa_info->tx_payload_info.encOffset+12],&p_pkt[p_sa_info->tx_payload_info.encOffset+12+4],4);
231         memcpy(&p_pkt[p_sa_info->tx_payload_info.encOffset+12+4],&ip_temp,4);
232         /* setting udp ports */
233         memcpy(&p_pkt[p_sa_info->tx_payload_info.encOffset+20+2],&new_dest_port[0],2);
234         memset(&p_pkt[p_sa_info->tx_payload_info.encOffset+20+6],0,2); //checksum
236         if (netTestCfg.ipsec_mode_tx == IPSEC_MODE_TX_SIDEBAND)
237         {
238             /* inner ip checksum : leave alone, outer ip, set to 0 (we will compute on way out */
239             memset(&p_pkt[14+10],0,2);
240         }
241     }
242     else
243     {
244         memset(&p_pkt[14+20+6],0,2);//0 udp checksum (we will compute on way out)
245         memcpy(&p_pkt[14+20+2],&new_dest_port[0],2);
246     }
248     /*IPSEC case */ 
249     if (flag)
250     {
251         if (netTestCfg.ipsec_mode_tx == IPSEC_MODE_TX_SIDEBAND)
252         //send to crypto for encryption
253         //12 byte auth tag
254         {
255             PKTIO_METADATA_T meta = {PKTIO_META_SB_TX,{0},0};
256             int err;
257             nwalDmTxPayloadInfo_t meta_tx={0};
258             
259             meta.sa_handle = (void*)p_sa_info_tx->tx_tunnel;  //use TX SA APPID
261             memcpy(&meta_tx, &(p_sa_info->tx_payload_info), sizeof(nwalDmTxPayloadInfo_t));
262             meta_tx.appCtxId = (nwal_AppId)p_sa_info_tx;
263             meta_tx.encSize = len - p_sa_info->tx_payload_info.encOffset -p_sa_info->auth_tag_size;
264             meta_tx.authSize = len - meta_tx.authOffset - p_sa_info->auth_tag_size;
265             meta_tx.pAuthIV=NULL;
266             meta_tx.aadSize=0;
267             meta_tx.pAad=NULL;
268             if (p_sa_info->cipherMode ==  NWAL_SA_EALG_AES_CTR)
269             {
270                 memcpy(&p_iv[0], &p_sa_info->key_params->pEncKey[16], 4);
271                 memcpy(&p_iv[4], &p_pkt[netTest_MAC_HEADER_LEN +netTest_IP_HEADER_LEN + netTest_ESP_HEADER_LEN], 8);
272                 p_iv[12] = 0;
273                 p_iv[13] = 0;
274                 p_iv[14] = 0;
275                 p_iv[15] = 1;
276                 meta_tx.pEncIV = &p_iv[0];
277             }
278             else if ((p_sa_info->cipherMode == NWAL_SA_EALG_AES_GCM) || (p_sa_info->cipherMode == NWAL_SA_EALG_AES_CCM))
279             {
280                 memcpy(&p_iv[0], &p_pkt[netTest_MAC_HEADER_LEN +netTest_IP_HEADER_LEN + netTest_ESP_HEADER_LEN], 8);
281                 meta_tx.pEncIV = &p_iv[0];
282                 memcpy(&p_add[0], &p_pkt[netTest_MAC_HEADER_LEN +netTest_IP_HEADER_LEN], 8);
283                 meta_tx.pAad= &p_add[0];
284                 meta_tx.aadSize = 8;
285             }
286             else if (p_sa_info->authMode == NWAL_SA_AALG_GMAC)
287             {
288                 memcpy(&p_iv[0], &p_pkt[netTest_MAC_HEADER_LEN +netTest_IP_HEADER_LEN + netTest_ESP_HEADER_LEN], 8);
289                 meta_tx.pAuthIV= &p_iv[0];
290                 memcpy(&p_add[0], &p_pkt[netTest_MAC_HEADER_LEN +netTest_IP_HEADER_LEN], 8);
291                 meta_tx.pAad= &p_add[0];
292                 meta_tx.aadSize = 8;
293             }
294             else if (p_sa_info->cipherMode ==  NWAL_SA_EALG_NULL)
295             {
296                 meta_tx.pEncIV = NULL;
297             }
298             else
299             {
300                 meta_tx.pEncIV = &p_pkt[netTest_MAC_HEADER_LEN +netTest_IP_HEADER_LEN + netTest_ESP_HEADER_LEN ];
301             }
302             /* post it to netcp sb tx channel*/
303             meta.u.tx_sb_meta=&meta_tx;
305             pktio_send(netcp_sb_tx_chan,tip,&meta,&err);
306         }
307         else
308         {
309             //INFLOW TX, send pkt directly, asking for IP and UDP checksum offloads AND IPSEC to be applied
310             PKTIO_METADATA_T meta = {PKTIO_META_TX,{0},0};
311             int err;
312             nwalTxPktInfo_t meta_tx={0};
314             meta.sa_handle = (void*)p_sa_info_tx->tx_tunnel;  //use TX SA APPID
316             meta_tx.startOffset = p_sa_info_tx->tx_pkt_info.startOffset;
317             meta_tx.ipOffBytes =p_sa_info_tx->tx_payload_info.encOffset; 
318             meta_tx.l4OffBytes = p_sa_info_tx->tx_pkt_info.l4OffBytes;
319             meta_tx.l4HdrLen = p_sa_info_tx->tx_pkt_info.l4HdrLen;
320             meta_tx.ploadLen = (unsigned) ((p_pkt[meta_tx.l4OffBytes+4]<<8)|p_pkt[meta_tx.l4OffBytes+4+1]) -8 ;
321             meta_tx.saOffBytes=  p_sa_info_tx->tx_pkt_info.saOffBytes;
322             if (pkt_type == IPSEC_AH_PKT)
323             {
324                 memset(&p_pkt[netTest_MAC_HEADER_LEN+netTest_IP_HEADER_LEN+netTest_IPSEC_AH_FIXED_HDR_SIZE],0,netTest_IPSEC_AH_FIXED_HDR_SIZE);
325                 meta_tx.txFlag1 = p_sa_info_tx->tx_pkt_info.txFlag1;
326                 meta_tx.saPayloadLen=len-netTest_MAC_HEADER_LEN;   //don't inlcude mac 
327                 meta_tx.saAhMacSize = 12;
328                 meta_tx.saAhIcvOffBytes = netTest_MAC_HEADER_LEN + netTest_IP_HEADER_LEN + netTest_IPSEC_AH_FIXED_HDR_SIZE;
329                 
330                 meta_tx.enetPort = enet_port;
331                  memcpy(&p_pkt[netTest_MAC_HEADER_LEN+netTest_IP_HEADER_LEN+4],&p_sa_info_tx->spi,4);
332             }
333             else if (pkt_type == IPSEC_ESP_PKT)
334             {
335                 meta_tx.txFlag1 = p_sa_info_tx->tx_pkt_info.txFlag1;
336                 meta_tx.saPayloadLen=len-netTest_MAC_HEADER_LEN-netTest_IP_HEADER_LEN;   //don't include mac and ip outer header
337                 meta_tx.enetPort = 0;
338                  memcpy(&p_pkt[netTest_MAC_HEADER_LEN+netTest_IP_HEADER_LEN],&p_sa_info_tx->spi,4);
339             }
340             else
341             {
342                 printf("flip_and_send_pkt: invalid ESP protocol\n");
343                 return;
344             }
346             meta_tx.pseudoHdrChecksum =
347             test_utilGetIpv4PsudoChkSum(&p_pkt[meta_tx.ipOffBytes],8+ meta_tx.ploadLen);
350             /* post it to netcp tx channel*/
351             meta.u.tx_meta=&meta_tx;
352             if (stats[coreid].sec_tx<20) dump_descr((long *) tip, stats[coreid].sec_tx);
354             if ( pkt_type == IPSEC_ESP_PKT)
355                 pktio_send(netcp_tx_chan_esp,tip,&meta,&err);
356             else if ( pkt_type == IPSEC_AH_PKT)
357                  pktio_send(netcp_tx_chan_ah,tip,&meta,&err);
358             stats[coreid].tx +=1;
359             stats[coreid].sec_tx +=1;
360         }
361     }
362     else  //non ipsec send pkt directly, asking for IP and UDP checksum ofload
363     {
364         PKTIO_METADATA_T meta2 = {PKTIO_META_TX,{0},0};
365         int err;
366         nwalTxPktInfo_t meta_tx2={0};
367         meta2.sa_handle=nwal_HANDLE_INVALID;
368         meta_tx2.txFlag1 = (NWAL_TX_FLAG1_DO_UDP_CHKSUM| NWAL_TX_FLAG1_META_DATA_VALID );
369         meta_tx2.startOffset = 0;
370         meta_tx2.ipOffBytes = netTest_MAC_HEADER_LEN;
371         meta_tx2.l4OffBytes = netTest_MAC_HEADER_LEN +netTest_IP_HEADER_LEN;
372         meta_tx2.l4HdrLen = netTest_UDP_HEADER_LEN;
373         meta_tx2.ploadLen = (unsigned) ((p_pkt[netTest_MAC_HEADER_LEN+netTest_IP_HEADER_LEN+4]<<8)|
374                                         p_pkt[netTest_MAC_HEADER_LEN+netTest_IP_HEADER_LEN+4+1]) -8 ;
375         meta_tx2.pseudoHdrChecksum =
376         test_utilGetIpv4PsudoChkSum(&p_pkt[netTest_MAC_HEADER_LEN],8+ meta_tx2.ploadLen);
378         /* post it to netcp tx channel*/
379         meta2.u.tx_meta=&meta_tx2;
380         printf("flip_and_send_pkt: non-ipsec packet received\n");
381         pktio_send(netcp_tx_chan_no_crypto,tip,&meta2,&err);
382         stats[coreid].tx +=1;
383     }
387 /****************************************************************************************/
388 /******************SB Accelerator Callback PKT RECEIVE HANDLER *************************/
389 /******************  Handles Decrypt and Encrypt operation callbacks ******************/
390 /******************************************************************************************/
391 void recv_sb_cb(struct PKTIO_HANDLE_Tag * channel, Ti_Pkt* p_recv[],
392                          PKTIO_METADATA_T meta[], int n_pkts,
393                          uint64_t ts )
395     int i;
396     int len;
397     int p;
398     HEAD_T * p_res;
399     Ti_Pkt * tip;
400     unsigned int templen;
401     int err;
402     KEY_T key;
403     char * p_pkt;
404     HEAD_T * p_head;
405     HEAD_T temp_head;
406     int tag_cmp=0;
407     unsigned int hash[4];
408     uint8_t *p_spi;
409     netTestSA_t *p_sa_info;
411 #ifdef MULTI_THREAD
412     int coreid=Osal_nwalGetProcId();  //who we are(thread local)
413 #else
414     int coreid=0;
415 #endif
416     //nwal_AppId time;
417     unsigned long time, delta_time;
418     /* loop over received pkts */
419     for(i=0;i<n_pkts;i++)
420    {
421         tip = p_recv[i];
422         Pktlib_getDataBuffer(tip,(uint8_t**)&p_pkt,&templen);//ignore templen
423         len = Pktlib_getPacketLen(tip);//real length
425         /*p_sa_info is for rx context */
426         p_sa_info = (netTestSA_t*)meta[i].u.rx_sb_meta->appCtxId;
427         if (p_sa_info == NULL)
428         {
429             printf("recv_sb_cb(): trie_lookup failed\n");
430             continue;
431         }
433         //is this a decrypt (rx_tunnel) complete
434         if ((int)meta[i].u.rx_sb_meta->appId == p_sa_info->rx_tunnel)
435         {
436             //time = hplib_mUtilGetPmuCCNT();
437             //delta_time = time -(unsigned long) meta[i].u.rx_sb_meta->appCtxId;
438             stats[coreid].total_decrypt_time += delta_time;
439             stats[coreid].sb_rx+=1;
440             //copy hash out of meta data (for some reason it needs endian conversion)
441             hash[0]= htonl( meta[i].u.rx_sb_meta->pAuthTag[0]);
442             hash[1]= htonl( meta[i].u.rx_sb_meta->pAuthTag[1]);
443             hash[2]= htonl( meta[i].u.rx_sb_meta->pAuthTag[2]);
444             hash[3]= htonl( meta[i].u.rx_sb_meta->pAuthTag[3]);
445             if(stats[coreid].sb_rx<=16)
446             {
447                 char *tp = (char *) &hash[0];
448                 //dump_header((long*)p_pkt, stats[coreid].sb_rx, (int)meta[i].u.rx_sb_meta->appId,0);
449             }
450             tag_cmp = memcmp(&p_pkt[len-p_sa_info->auth_tag_size],(char*) &hash[0],p_sa_info->auth_tag_size); //todo, really use meta->authTagLen
451             stats[coreid].n_auth_ok += !(tag_cmp);
452             flip_and_send_pkt(tip, p_pkt, len,1, 0);  //flip packet to echo back and send
453         }
454         //this is an encrypt (tx tunnel) complete
455         else if((int)meta[i].u.rx_sb_meta->appId== p_sa_info->tx_tunnel )
456         {
457             hash[0]= htonl( meta[i].u.rx_sb_meta->pAuthTag[0]);
458             hash[1]= htonl( meta[i].u.rx_sb_meta->pAuthTag[1]);
459             hash[2]= htonl( meta[i].u.rx_sb_meta->pAuthTag[2]);
460             hash[3]= htonl( meta[i].u.rx_sb_meta->pAuthTag[3]);
461             stats[coreid].sb_tx+=1;
462             if(stats[coreid].sb_tx<=16)
463             {
464                 //dump_header((long*)p_pkt, stats[coreid].sb_tx, (int)meta[i].u.rx_sb_meta->appId,0);
465             }
466             //put the computed tag in the packet
467              memcpy(&p_pkt[len-p_sa_info->auth_tag_size],(char*)&hash[0],p_sa_info->auth_tag_size); //todo, really use meta->authTagLen
468             {
469                 PKTIO_METADATA_T meta2 = {PKTIO_META_TX,{0},0};
470                 nwalTxPktInfo_t meta_tx={0};
471                 // now send directly 
472                 meta2.sa_handle=nwal_HANDLE_INVALID;
473                 meta_tx.txFlag1 = (NWAL_TX_FLAG1_DO_IPV4_CHKSUM| NWAL_TX_FLAG1_META_DATA_VALID);//only outer IP header checksum. no udp checksum possible since pkt is already encrypted
474                 meta_tx.startOffset = 0;
475                 meta_tx.ipOffBytes = netTest_MAC_HEADER_LEN;
476                 meta_tx.l4OffBytes = 0;
477                 meta_tx.l4HdrLen = 0;
478                 meta_tx.ploadLen = 0;
479                 time = hplib_mUtilGetPmuCCNT();
480                 delta_time = time -(unsigned long) meta[i].u.rx_sb_meta->appCtxId;
481                 stats[coreid].total_encrypt_time += delta_time;
483                 /* post it to netcp tx channel*/
484                 meta2.u.tx_meta=&meta_tx;
485                 pktio_send(netcp_tx_chan_esp,tip,&meta2,&err);
486                 hplib_cacheWbInv(p_pkt,len);
487                 stats[coreid].tx +=1;
488             }
489         }
490         else printf("netapi recv_sb_cb: unknown appiD %x \n",meta[i].u.rx_sb_meta->appId );
491     }
494 /******************************************************/
495 /******************PKT RECEIVE HANDLER *************************/
496 /******************************************************/
498 void recv_cb(struct PKTIO_HANDLE_Tag * channel, Ti_Pkt* p_recv[],
499                          PKTIO_METADATA_T meta[], int n_pkts,
500                          uint64_t ts )
502     int i;
503     int len;
504     int p;
505     HEAD_T * p_res;
506     Ti_Pkt * tip;
507     unsigned int templen;
508     int err = 0;
509     KEY_T key;
510     char * p_pkt;
511     HEAD_T * p_head;
512     HEAD_T temp_head;
513     netTestSA_t *p_sa_info;
514     uint8_t *p_spi;
515     uint8_t p_iv[16];
516     uint8_t p_add[8];
517     uint8_t p_add1[1500];
518     int16_t       retVal;
520     nwalGlobCxtInfo_t   nwalGlobCxt;
521     nwalLocCxtInfo_t    nwalLocCxt;
523     Cppi_HostDesc*          pPloadDesc;
524     int ifno;
525     uint16_t enet_port = 0;
527 #ifdef MULTI_THREAD
528     int coreid=Osal_nwalGetProcId();  //who we are(thread local)
529     //int coreid = our_core;
530 #else
531     int coreid=0;
532 #endif
533     p_head=&temp_head;
536     /* loop over received pkts */
537     for(i=0;i<n_pkts;i++)
538     {
539         Debug_printf("recv_cb: appId 0x%x\n", meta[i].u.rx_meta->appId);
540         ifno = ((unsigned int)meta[i].u.rx_meta->appId)&0xff;
541         
542         enet_port = meta[i].u.rx_meta->enetPort;
543         tip = p_recv[i];
545         Pktlib_getDataBuffer(tip,(uint8_t**)&p_pkt,&templen);/*ignore templen */
546         len = Pktlib_getPacketLen(tip)-4;   /*real length, subtract mac trailer */
547         Cppi_setData (Cppi_DescType_HOST, (Cppi_Desc *) tip, p_pkt,len);
548         Pktlib_setPacketLen(tip,len);
550         if(((unsigned int)meta[i].u.rx_meta->appId) == expPkt_appid)
551         {
552             Debug_printf("recv_cb: received exception packet\n");
553               Pktlib_freePacket(tip);
554             if(((unsigned int)meta[i].u.rx_meta->rxFlag1  & NWAL_RX_IP_FRAGMENT_PKT) ==
555                                              NWAL_RX_IP_FRAGMENT_PKT)
556             {
557                 stats[coreid].exceptionPktsFrag+=1;
558             }
559             else
560             {
561                 stats[coreid].exceptionPktsOther+=1;
562             }
563             continue;
564         }
565         //debug: validate descriptor */
566         if(Pktlib_getNextPacket(tip) != 0) 
567         {
568             printf(" rcv_cb, nexpkt != NULL");
569         }
571         if(coreid<TUNE_NETAPI_NUM_CORES)
572             stats[coreid].rx+=1;
573         if (ifno < TUNE_NETAPI_MAX_NUM_MAC)
574             stats[coreid].if_rx[ifno]+=1;
577 #ifdef DEBUG_DESC
578         if (stats[coreid].rx<16)
579         {
580             Debug_printf(">rx dmp.."); 
581             dump_descr((long *) tip, stats[coreid].rx);
582         }
583         else if (stats[coreid].rx>99) 
584         {
585             Debug_printf(">rx dmp.."); 
586             dump_descr((long *) tip,stats[coreid].rx);
587         }
588 #endif
589 #if 0
590         if(stats[coreid].rx<=16)
591         {
592             dump_header((long*)p_pkt,stats[coreid].rx, (int)meta[i].u.rx_meta->appId,meta[i].u.rx_meta->rxFlag1);
593              netapi_dump_buf((long*)p_pkt,len);
594         }
595 #endif
596         /* check header */
597         memcpy(p_head,&p_pkt[14],sizeof(HEAD_T));
599         /* check for IPSEC ESP or AH packet, 0x32 is ESP tunnel mode, 0x33 is AH tunnel mode*/
600         if (((p_head->ip[2]&0x0000ff00)==0x00003200) || ((p_head->ip[2]&0x0000ff00)==0x00003300))
601         {
602             if (!check_header(p_head,&meta[i]))
603             {
604                 stats[coreid].n_bad+=1;Pktlib_freePacket(tip); 
605                 continue;
606             }
608             //process IP SEC PACKET
609             if (netTestCfg.ipsec_mode_rx == IPSEC_MODE_RX_SIDEBAND)
610             {
611                 p_spi = &(p_pkt[netTest_MAC_HEADER_LEN+netTest_IP_HEADER_LEN]);
612                 p_sa_info = (netTestSA_t *) trie_lookup(p_trie_sa_rx, (char *)p_spi ,4);
613                 if (p_sa_info == NULL)
614                 {
615                     printf("recv_cb(): trie_lookup() failed\n");
616                     continue;
617                 }
619                 //ship to crypto for decrypt!!
620                 //12 byte auth tag
621                 PKTIO_METADATA_T meta2 = {PKTIO_META_SB_TX,{0},0};
622                 nwalDmTxPayloadInfo_t meta_tx={0};
624                 meta2.sa_handle = (void*) p_sa_info->rx_tunnel;
626                 memcpy(&meta_tx, &(p_sa_info->tx_payload_info), sizeof(nwalDmTxPayloadInfo_t));
628                 meta_tx.encSize = len - p_sa_info->tx_payload_info.encOffset -p_sa_info->auth_tag_size;
629                 meta_tx.authSize = len - meta_tx.authOffset - p_sa_info->auth_tag_size;
631                 if (p_sa_info->cipherMode == NWAL_SA_EALG_AES_CTR)
632                 {
633                     memcpy(&p_iv[0], &p_sa_info->key_params->pEncKey[16], 4);
634                     memcpy(&p_iv[4], &p_pkt[netTest_MAC_HEADER_LEN +netTest_IP_HEADER_LEN + netTest_ESP_HEADER_LEN], 8);
635                     p_iv[12] = 0;
636                     p_iv[13] = 0;
637                     p_iv[14] = 0;
638                     p_iv[15] = 1;
639                     meta_tx.pEncIV = &p_iv[0];
640                  
641                 }
642                 else if ((p_sa_info->cipherMode == NWAL_SA_EALG_AES_GCM) ||
643                             (p_sa_info->cipherMode == NWAL_SA_EALG_AES_CCM))
644                 {
645                         memcpy(&p_iv[0], &p_pkt[netTest_MAC_HEADER_LEN +netTest_IP_HEADER_LEN + netTest_ESP_HEADER_LEN], 8);
646                         meta_tx.pEncIV = &p_iv[0];
647                         /* aad is the ESP header which is 8 bytes */
648                         memcpy(&p_add[0], &p_pkt[netTest_MAC_HEADER_LEN +netTest_IP_HEADER_LEN], 8);
649                         meta_tx.pAad= &p_add[0];
650                         meta_tx.aadSize = 8;
651                 }
652                 else if (p_sa_info->authMode == NWAL_SA_AALG_GMAC)
653                 {
654                     memcpy(&p_iv[0], &p_pkt[netTest_MAC_HEADER_LEN +netTest_IP_HEADER_LEN + netTest_ESP_HEADER_LEN], 8);
655                         meta_tx.pAuthIV= &p_iv[0];
656                         /* aad is the ESP header which is 8 bytes */
657                         memcpy(&p_add[0], &p_pkt[netTest_MAC_HEADER_LEN +netTest_IP_HEADER_LEN], 8);
658                         meta_tx.pAad= &p_add[0];
659                         meta_tx.aadSize = 8;
660                 }
661                 else if (p_sa_info->cipherMode ==  NWAL_SA_EALG_NULL)
662                 {
663                     meta_tx.pEncIV = NULL;
664                 }
665                 else
666                 {
667                     meta_tx.pEncIV = &p_pkt[netTest_MAC_HEADER_LEN +netTest_IP_HEADER_LEN + netTest_ESP_HEADER_LEN ];
668                 }
669                
670                 meta_tx.appCtxId = (nwal_AppId)p_sa_info;
671                 //printf("recv_cb appCtxId: %lu\n", meta_tx.appCtxId);
673                 /* post it to netcp sb tx channel*/
674             meta2.u.tx_sb_meta=&meta_tx;
676                 pktio_send(netcp_sb_tx_chan,tip,&meta2,&err);
677                 continue;
678             }
679             else
680             {
681                 //inflow mode.  flip and send
682                 flip_and_send_pkt(tip,p_pkt,len,1, enet_port);
683             }
684         }
685         else if ((p_head->ip[2]&0x0000ff00)!=0x00001100)
686         {
687             stats[coreid].n_new+=1;Pktlib_freePacket(tip); continue;
688         }
689         else  //non ipsec
690         {
691             if (!check_header(p_head,&meta[i]))
692             {
693                 stats[coreid].n_bad+=1;Pktlib_freePacket(tip); 
694                 continue;
695             }
696             //just flip and send
697             flip_and_send_pkt(tip,p_pkt,len,0, enet_port);
698         }
699     }
702 /* Templates to build command labels at startup up time, required by open_pktio_tx_channels() */
703 nwalTxPktInfo_t txPktInfoESP = 
705     NULL,                                                                                               /* p_pkt */
706     NWAL_TX_FLAG1_DO_IPSEC_ESP_CRYPTO| NWAL_TX_FLAG1_DO_UDP_CHKSUM| NWAL_TX_FLAG1_META_DATA_VALID,      /* txFlags */
707     0,                                                                                                  /* lpbackPass */
708     0,                                                                                                  /* enetport */
709     0,                                                                                                  /* msuSize */
710     0,                                                                                                   /* startOffset */
711     netTest_MAC_HEADER_LEN  + netTest_IP_HEADER_LEN,                                                    /* saOffBytes */
712     0,                                                                                                  /* saPayLoadLen */
713     0               ,                                                                                    /* saAhIcvOffBytes */
714     0,                                                                                                 /* saAhMacSize */
715     0,                                                                                                  /* etherLenOffBytes */
716     0,                                                                                                  /* ipOffBytes */
717     0,                                                                                                  /* l4OffBytes */
718     netTest_UDP_HEADER_LEN,                                                                             /* l4HdrLen */
719     0,                                                                                                  /* pseudoHdrChecksum */
720     0                                                                                                   /* pLoadLen */
721 };
724 nwalTxPktInfo_t txPktInfoAH = 
726     NULL,                                                                                               /* p_pkt */
727     NWAL_TX_FLAG1_DO_IPSEC_AH_CRYPTO| NWAL_TX_FLAG1_DO_UDP_CHKSUM | NWAL_TX_FLAG1_META_DATA_VALID,      /* txFlags */
728     0,                                                                                                  /* lpbackPass */
729     0,                                                                                                  /* enetport */
730     0,                                                                                                  /* msuSize */
731     0,                                                                                                   /* startOffset */
732     netTest_MAC_HEADER_LEN  + netTest_IP_HEADER_LEN,                                                    /* saOffBytes */
733     0,                                                                                                  /* saPayLoadLen */
734     netTest_MAC_HEADER_LEN + netTest_IP_HEADER_LEN + netTest_IPSEC_AH_FIXED_HDR_SIZE,                    /* saAhIcvOffBytes */
735     12,                                                                                                 /* saAhMacSize */
736     0,                                                                                                  /* etherLenOffBytes */
737     0,                                             /* ipOffBytes */
738     0,                                                                                                  /* l4OffBytes */
739     netTest_UDP_HEADER_LEN,                                                                            /* l4HdrLen */
740     0,                                                                                                  /* pseudoHdrChecksum */
741     0                                                                                                   /* pLoadLen */
742 };
744 nwalTxPktInfo_t txPktInfoNoCrypto = 
746     NULL,                                                                                               /* p_pkt */
747     NWAL_TX_FLAG1_DO_UDP_CHKSUM| NWAL_TX_FLAG1_META_DATA_VALID,      /* txFlags */
748     0,                                                                                                  /* lpbackPass */
749     0,                                                                                                  /* enetport */
750     0,                                                                                                  /* msuSize */
751     0,                                                                                                   /* startOffset */
752     0,                                                    /* saOffBytes */
753     0,                                                                                                  /* saPayLoadLen */
754     0               ,                                                                                    /* saAhIcvOffBytes */
755     0,                                                                                                 /* saAhMacSize */
756     0,                                                                                                  /* etherLenOffBytes */
757     0,                                                                                                  /* ipOffBytes */
758     netTest_MAC_HEADER_LEN +netTest_IP_HEADER_LEN,                                        /* l4OffBytes */
759     netTest_UDP_HEADER_LEN,                                                             /* l4HdrLen */
760     0,                                                                         /* pseudoHdrChecksum */
761     0                                                                                                   /* pLoadLen */
762 };
765 void close_pktio_channels(void)
767     int err;
768     pktio_close(netcp_tx_chan_esp ,&err);
769     pktio_close(netcp_tx_chan_ah ,&err);
770     pktio_close(netcp_sb_tx_chan ,&err);
771     pktio_close(netcp_tx_chan_no_crypto,&err);
774 void open_pktio_tx_channels(void)
776     int err;
777     /* open netcp default  TX for ESP packets */
778     netcp_tx_chan_esp= pktio_open(netapi_handle, NETCP_TX, NULL, &netcp_tx_cfg,  &err);
779     if (!netcp_tx_chan_esp)
780     {
781         printf("pktio open TX failed err=%d\n",err);
782         exit(1);
783     }
784     else
785     {
786         if(netTestCfg.ipsec_mode_tx == IPSEC_MODE_TX_INFLOW)
787         {
788             PKTIO_CONTROL_T control;
789             control.op = PKTIO_UPDATE_FAST_PATH;
790             PKTIO_CFG_T cfg;
791             cfg.fast_path_cfg.fp_send_option = PKTIO_FP_ESP_L4CKSUM_PORT;
792             cfg.fast_path_cfg.txPktInfo= &txPktInfoESP;
793             pktio_control(netcp_tx_chan_esp, NULL, &cfg, &control, &err);
794         }
795     }
797     /*/* open netcp default  TX for AH packets */
798     netcp_tx_chan_ah= pktio_open(netapi_handle, NETCP_TX, NULL, &netcp_tx_cfg,  &err);
799     if (!netcp_tx_chan_ah)
800     {
801         printf("pktio open TX failed err=%d\n",err);
802         exit(1);
803     }
804     else
805     {
806         if(netTestCfg.ipsec_mode_tx == IPSEC_MODE_TX_INFLOW)
807         {
808             PKTIO_CONTROL_T control;
809             control.op = PKTIO_UPDATE_FAST_PATH;
810             PKTIO_CFG_T cfg;
811             cfg.fast_path_cfg.fp_send_option = PKTIO_FP_AH_L4CKSUM_PORT;
812             cfg.fast_path_cfg.txPktInfo= &txPktInfoAH;
813             pktio_control(netcp_tx_chan_ah, NULL, &cfg, &control, &err);
814         }
815     }
817     /* open netcp default  TX channels for non-Crypto packets */
818     netcp_tx_chan_no_crypto= pktio_open(netapi_handle, NETCP_TX, NULL, &netcp_tx_cfg,  &err);
819     if (!netcp_tx_chan_no_crypto)
820     {
821         printf("pktio open TX failed err=%d\n",err);
822         exit(1);
823     }
824     else
825     {
826         if(netTestCfg.ipsec_mode_tx == IPSEC_MODE_TX_INFLOW)
827         {
828             PKTIO_CONTROL_T control;
829             control.op = PKTIO_UPDATE_FAST_PATH;
830             PKTIO_CFG_T cfg;
831             cfg.fast_path_cfg.fp_send_option = PKTIO_FP_L4CKSUM_PORT;
832             cfg.fast_path_cfg.txPktInfo= &txPktInfoNoCrypto;
833             pktio_control(netcp_tx_chan_no_crypto, NULL, &cfg, &control, &err);
834         }
835     }
837     /* open netcp default  TX channels for SB crypto */
838     netcp_sb_tx_chan= pktio_open(netapi_handle, NETCP_SB_TX, NULL, &netcp_sb_tx_cfg,  &err);
839     if (!netcp_sb_tx_chan)
840     {
841         printf("pktio open SB TX failed err=%d\n",err);
842         exit(1);
843     }
847 #ifdef MULTI_THREAD
848 NETAPI_T worker_nh[TUNE_NETAPI_NUM_CORES];
850 void slow_path_thread(int thread_num)
852     int err, i;;
854     PKTIO_HANDLE_T *rx_chan;
855     PKTIO_HANDLE_T *sb_rx_chan;
857     printf("slow_path_thread, mypid: %d, core_id %d\n", gettid(), thread_num);
859     CPU_ZERO( &cpu_set);
860     printf("fast_path_thread: settting up for thread number %d\n", thread_num);
861 #ifdef CORTEX_A15
862     for (i = netTestCfg.fp_proc_start[thread_num]; i <= netTestCfg.fp_proc_end[thread_num];i++)
863     {
864         printf("fast_path_thread: setting cpu %d to cpu_set\n", i);
865         CPU_SET( i, &cpu_set);
866     }
867     hplib_utilSetupCore(thread_num, &cpu_set);
868 #else
869     for (i = netTestCfg.fp_proc_start[thread_num]; i <= netTestCfg.fp_proc_end[thread_num];i++)
870     {
871         printf("fast_path_thread: setting cpu %d to cpu_set\n", i);
872         CPU_SET( i, &cpu_set);
873     }
874     hplib_utilSetupCore(thread_num, &cpu_set);
875 #endif
876     worker_nh[thread_num]=netapi_init(NETAPI_CORE_MASTER,NULL);
878     //NETAPI_HANDLE_T * n = (NETAPI_HANDLE_T *) worker_nh[thread_num];
880    /* open netcp default RX channels*/
881     
882     rx_chan = pktio_open(worker_nh[thread_num], NETCP_RX, (PKTIO_CB) recv_cb, &netcp_rx_cfg,  &err);
883     
884     sb_rx_chan = pktio_open(worker_nh[thread_num], NETCP_SB_RX, (PKTIO_CB) recv_sb_cb, &netcp_sb_rx_cfg,  &err);
886     netapi_setCookie(worker_nh[thread_num],(void*) thread_num);
888     scheduler[thread_num] =netapi_schedOpen(worker_nh[thread_num],&our_sched_cfg, &err);
889     if (!scheduler[thread_num]) 
890     {
891         printf("sched create failed for core%d\n",thread_num); 
892         exit(1);
893     }
894     scheduler[thread_num]->config.yield = TRUE;
895     scheduler[thread_num]->config.pollGarbageQ = TRUE;
896     scheduler[thread_num]->config.pollCtrlQ = TRUE;
898     /* Entry point to scheduler */
899     netapi_schedRun(scheduler[thread_num], &err);
900     printf(">net_test: core %d worker thread done\n",thread_num);
902     //pktio_close(tx_chan, &err);
903     pktio_close(rx_chan, &err);
904     pktio_close(sb_rx_chan, &err);
905     netapi_shutdown(worker_nh[thread_num]);
908 void fast_path_thread(int thread_num)
910     int err, i;
911     PKTIO_HANDLE_T *rx_chan;
912     PKTIO_HANDLE_T *sb_rx_chan;
914     CPU_ZERO( &cpu_set);
915     printf("fast_path_thread: settting up for thread number %d\n", thread_num);
916 #ifdef CORTEX_A15
917     for (i = netTestCfg.fp_proc_start[thread_num]; i <= netTestCfg.fp_proc_end[thread_num];i++)
918     {
919         printf("fast_path_thread: setting cpu %d to cpu_set\n", i);
920         CPU_SET( i, &cpu_set);
921     }
922     hplib_utilSetupCore(thread_num, &cpu_set);
923 #else
924     for (i = netTestCfg.fp_proc_start[thread_num]; i <= netTestCfg.fp_proc_end[thread_num];i++)
925     {
926         printf("fast_path_thread: setting cpu %d to cpu_set\n", i);
927         CPU_SET( i, &cpu_set);
928     }
929     hplib_utilSetupCore(thread_num, &cpu_set);
930 #endif
931     worker_nh[thread_num]=netapi_init(NETAPI_CORE_MASTER,NULL);
933     //NETAPI_HANDLE_T * n = (NETAPI_HANDLE_T *) worker_nh[thread_num];
935    /* open netcp default RX channels*/
936     rx_chan = pktio_open(worker_nh[thread_num], NETCP_RX, (PKTIO_CB) recv_cb, &netcp_rx_cfg,  &err);
938     /* create a pktio channel for specially classified pkts */
939     /* open netcp default tx, rx queues for sideband crypto */
940      //sb_tx_chan = pktio_open(worker_nh[thread_num], NETCP_SB_TX, NULL, &netcp_sb_tx_cfg,  &err);
941      sb_rx_chan = pktio_open(worker_nh[thread_num], NETCP_SB_RX, (PKTIO_CB) recv_sb_cb, &netcp_sb_rx_cfg,  &err);
944     
945     netapi_setCookie(worker_nh[thread_num],(void*)thread_num);
946     //our_core = coreid;
947     scheduler[thread_num] =netapi_schedOpen(worker_nh[thread_num],&our_sched_cfg, &err);
948     if (!scheduler[thread_num]) 
949         {
950         printf("sched create failed for core%d\n",thread_num); 
951         exit(1);
952     }
954  
955     scheduler[thread_num]->config.yield = FALSE;
956     scheduler[thread_num]->config.pollGarbageQ = FALSE;
957     scheduler[thread_num]->config.pollCtrlQ = FALSE;
958      //sleep(100000);
959    /* Entry point to scheduler */
960      netapi_schedRun(scheduler[thread_num], &err);
961     printf(">net_test: core %d worker thread done\n",thread_num);
963     pktio_close(rx_chan, &err);
965     pktio_close(sb_rx_chan, &err);
966     netapi_shutdown(worker_nh[thread_num]);
969 #endif
970 /***************************************
971  ********** test driver*****************
972  ***************************************/
973 int main(int argc, char **argv)
975     int err,i;
976     Pktlib_HeapCfg      heapCfg;
977     rlim_t oss,ss = 1024*1024;
978     struct rlimit rl;
979     int32_t             errCode;
980     Pktlib_HeapIfTable*  pPktifTable;
981     /* Local Per Process default resourcese maintained at NWAL */
982     nwalLocCxtInfo_t    nwalLocCxt;
983     //nwalSaIpSecId_t  nwalSaIpSecId;
984     FILE * fpr = NULL;
986     err= getrlimit(RLIMIT_STACK,&rl);
987     if (!err) printf(" stack limit = %d\n",rl.rlim_cur); else printf("getrlimit failed\n");
990      /* install signal handler for ^c */
991     signal(SIGINT,mysig);
993     fpr = fopen(input_file_name, "r");
994     if (fpr == NULL) 
995     {
996         printf("Error in opening %s input file\n", input_file_name);
997         exit(1);
998     }
999     else
1000     {
1001         memset(&config_file, 0, sizeof(netTestConfigFile_t));
1002         memset(&netTestCfg, 0, sizeof(netTestConfig_t));
1003         parse_config_file(fpr,&config_file);
1004     }
1006     memset(&sa_info, 0, sizeof(sa_info));
1009 #ifdef MULTI_THREAD
1010     /* assign main net_test thread to run on core 0 */
1011     CPU_ZERO( &cpu_set);
1012     CPU_SET( 0, &cpu_set);
1013     hplib_utilSetupCore(0, &cpu_set);
1014 #endif
1016     /* create netapi */
1017     netapi_handle = netapi_init(NETAPI_SYS_MASTER, &our_netapi_default_cfg);
1019     /* configure expection packet handling with netapi */
1020     netcp_cfgExceptions(netapi_handle, NETCP_CFG_ALL_EXCEPTIONS, NETCP_CFG_ACTION_DISCARD, (NETCP_CFG_ROUTE_HANDLE_T) NULL);
1021     expPkt_appid = netcp_cfgExceptions(netapi_handle, 7, NETCP_CFG_ACTION_TO_SW, (NETCP_CFG_ROUTE_HANDLE_T) NULL);
1023     /* open the main heap */
1024     ourHeap = Pktlib_findHeapByName("netapi");
1025     if (!ourHeap)
1026     {
1027         printf("Pktlib_findHeapByName()  fail\n");
1028         exit(1);
1029     }
1031     open_pktio_tx_channels();
1034     printf("net_test: %d bytes left in our CMA area\n", netapi_getBufMemRemainder());
1035     /* create scheduler instance */
1036     our_sched =netapi_schedOpen(netapi_handle,&our_sched_cfg, &err);
1037     if (!our_sched) {printf("sched create failed\n"); exit(1);}
1040     /*create net_test MAC interfaces, attach IP to created MAC interfaces */
1041     create_interfaces();
1043     /* lookup Database for SA context, this is used by packet processing routines to get RX and TX SA information*/
1044     p_trie_sa_rx = trie_new();
1045     p_trie_sa_tx = trie_new();
1046     if (!p_trie_sa_rx || !p_trie_sa_tx)
1047         {printf("trie alloc for SA  failed\n"); exit(1);}
1051     /* Create RX SA's, RX Policy and TX SA's, all SA configuration parameters are read from net_test_config.txt file */
1052     create_sec_associations();
1054 #ifdef MULTI_THREAD
1056     char c;
1057     /* create and set affinity of slow path and fast path threads to
1058     * specific CPU cores as specified in the net_test_config.txt file */
1059     create_sp_fp_threads();
1061         //this thread of execution (main) now just waits on user input
1062         for(;;)
1063         {
1064            printf(">");
1065            c=getchar();
1066            if (c=='q') {QUIT=1;break;}
1067            else if (c=='s') our_stats_cb(netapi_handle, &netcp_stats);
1068            else if (c=='h') printf("'q' to quit,  's' for stats, 'h' for help\n");
1069         }
1071         sp_fp_thread_cleanup();
1074 #else
1075     /*********************************************/
1076     /**************Entry point into scheduler ****/
1077     /*********************************************/
1078     //create_sec_associations(netcp_sb_rx_chan, netcp_sb_tx_chan,netcp_tx_chan);
1079     netapi_schedRun(our_sched, &err);
1080 #endif
1082     /* done */
1083     our_stats_cb(netapi_handle, NULL);
1086     /* cleanup*/
1087      delete_sec_associations();
1089     delete_interfaces();
1091     /* close pktio channels we opened via open_pktio_tx_channels() */
1092     close_pktio_channels();
1093     
1094     netapi_shutdown(netapi_handle);
1098 /* Stub functions */
1099 Trie * route_init(void)
1102 void route_add(Trie * Pt, unsigned long * Pdest_ipBE, void * Pour_route)