]> Gitweb @ Texas Instruments - Open Source Git Repositories - git.TI.com/gitweb - keystone-rtos/netapi.git/blob - ti/runtime/netapi/test/net_test_loopback.c
1a07f690ec4182783b32d3d2fe9335eb34c47ddd
[keystone-rtos/netapi.git] / ti / runtime / netapi / test / net_test_loopback.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:
11  *
12  *  Copyright (c) Texas Instruments Incorporated 2013
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 "net_test.h"
45 #include "ti/drv/nwal/test/fw_rm.h"
46 #include <signal.h>
47 #include <pthread.h>
49 extern int QUIT;
50 extern netTestStats_T stats[TUNE_NETAPI_NUM_CORES];
51 extern paSysStats_t netcp_stats;
54 netTestConfig_t netTestCfg;
55 static netTestConfigFile_t config_file;
56 char    input_file_name[] = "/etc/netapi/net_test_config.txt";
57 nwal_RetValue       nwalRetVal;
58 Pktlib_HeapHandle   ourHeap;
60 PKTIO_HANDLE_T *netcp_rx_chan;
61 PKTIO_HANDLE_T *netcp_tx_chan_no_crypto;
62 PKTIO_HANDLE_T *netcp_tx_chan_esp;
63 PKTIO_HANDLE_T *netcp_tx_chan_ah;
64 PKTIO_HANDLE_T *netcp_sb_tx_chan;
65 PKTIO_HANDLE_T *netcp_sb_rx_chan;
67 PKTIO_CFG_T netcp_rx_cfg={PKTIO_RX, PKTIO_NA, PKTIO_NA, 8};
68 PKTIO_CFG_T netcp_rx_cfg2={PKTIO_RX, (PKTIO_GLOBAL|PKTIO_PKT), PKTIO_Q_ANY, 8};
69 PKTIO_CFG_T netcp_tx_cfg={PKTIO_TX, PKTIO_NA, PKTIO_NA, 8};
70 PKTIO_CFG_T netcp_sb_rx_cfg={PKTIO_RX, PKTIO_NA, PKTIO_NA, 8};
71 PKTIO_CFG_T netcp_sb_tx_cfg={PKTIO_TX, PKTIO_NA, PKTIO_NA, 8};
73 NETCP_CFG_IP_T ip_rule[NET_TEST_MAX_IP];
74 NETCP_CFG_MACIF_T mac[NET_TEST_MAX_MAC];
76 #ifdef netTest_DSP_FASTPATH
77 PKTIO_HANDLE_T *dsp_pktio_channels[CPU_NUM_REM_FAST_PATH_CORES];
78 NETCP_CFG_CLASS_T dsp_classifers[CPU_NUM_REM_FAST_PATH_CORES];
79 NETCP_CFG_FLOW_HANDLE_T dsp_flow_handles[CPU_NUM_REM_FAST_PATH_CORES];
80 #endif
81 NETCP_CFG_EXCEPTION_PKT_T expPkt_appid;
83 Trie *p_trie_sa_rx;
84 Trie *p_trie_sa_tx;
87 /*******************************************
88  *************NETAPI OBJECTS***************
89  *****************************************/
90 static NETAPI_CFG_T our_netapi_default_cfg=
91 {
92     TUNE_NETAPI_PERM_MEM_SZ,
93     128,  //start of packet offset for hw to place data on rx for default flow
94     TUNE_NETAPI_QM_CONFIG_MAX_DESC_NUM, //max number of descriptors in system
95     TUNE_NETAPI_NUM_GLOBAL_DESC,        //total we will use
96     TUNE_NETAPI_DEFAULT_NUM_BUFFERS,   //#descriptors+buffers in default heap
97     64, //#descriptors w/o buffers in default heap
98     TUNE_NETAPI_DEFAULT_BUFFER_SIZE+128+128,  //size of buffers in default heap
99     128   ,  //tail room
100     256      //extra room
101 };
103 NETAPI_T netapi_handle;
104 NETAPI_SCHED_HANDLE_T * our_sched;
105 #ifdef netTest_MULTI_THREAD
106 NETAPI_SCHED_HANDLE_T * scheduler[TUNE_NETAPI_NUM_CORES];
107 #endif
108 NETAPI_SCHED_CONFIG_T our_sched_cfg={
109   NETAPI_SCHED_DURATION|NETAPI_SCHED_CBV, 0, house, 5000000  //every 5000000 poll loops
110 };
112 netTestSA_t sa_info[MAX_SEC_INDEX];
113 NETCP_CFG_IPSEC_POLICY_T rx_policy[MAX_SEC_INDEX];
120 /********************************************************************
121  * FUNCTION PURPOSE:  Utility function to flip and packet and send
122  *                    it back to its source.
123  ********************************************************************
124  * DESCRIPTION:   Utility function to flip and packet and send
125  *                    it back to its source.
126  ********************************************************************/
127 void flip_and_send_pkt(Ti_Pkt *tip,  unsigned char * p_pkt, int len, int flag, uint16_t enet_port)
129     unsigned char mac_temp[6];
130     unsigned char ip_temp[4];
131     unsigned char new_dest_port[2]={0x75,0x30};  // 30000
132     uint16_t dest_udp_port_config = 0;
133     uint16_t blah; 
134     uint16_t i=1;   /* for testing only */
136     uint8_t *p_spi; 
137     netTestSA_t * p_sa_info;
138     netTestSA_t *p_sa_info_tx;
139     uint8_t p_iv[16];
140     uint8_t p_add[8];
141     Cppi_HostDesc*          pPloadDesc;
142     uint8_t ah_len;
143     uint32_t tunnel_id;
144     nwalLocCxtInfo_t    nwalLocCxt;
145     netTestHead_T * p_head;
146     netTestHead_T temp_head;
147     int pkt_type;
149 #ifdef netTest_MULTI_THREAD
150     int coreid=Osal_nwalGetProcId(); //who we are(thread local)
151         //int coreid = our_core;
152 #else
153 int coreid=0;
154 #endif
155               // netTest_utilDumpBuffer((long*)p_pkt,len);
156     Pktlib_setPacketLen(tip,len);
157     //flip the mac address
158     memcpy(&mac_temp,&p_pkt[0],6);
159     memcpy(&p_pkt[0],&p_pkt[6],6);
160     memcpy(&p_pkt[6],&mac_temp,6);
161     //memcpy(&p_pkt[0],real_mac_header,6); //for testing to wireshark pc
163     //flip the ip  (outer in case of ipsec)
164     memcpy(&ip_temp, &p_pkt[netTest_MAC_HEADER_LEN+12],4);
165     memcpy(&p_pkt[netTest_MAC_HEADER_LEN+12],&p_pkt[netTest_MAC_HEADER_LEN+12+4],4);
166     memcpy(&p_pkt[netTest_MAC_HEADER_LEN+12+4],&ip_temp,4);
168     p_head=&temp_head;
170     //inner ip &udp for ipsec
171     if (flag) 
172     {
173         memcpy(p_head,&p_pkt[netTest_MAC_HEADER_LEN],sizeof(netTestHead_T));
175         if ((p_head->ip[2]&0x0000ff00)==0x00003300)
176         {
177             p_spi = &(p_pkt[netTest_MAC_HEADER_LEN+netTest_IP_HEADER_LEN + 4]);
178             pkt_type = netTest_IPSEC_AH_PKT;
179         }
180         else if ((p_head->ip[2]&0x0000ff00)==0x00003200)
181         {
182             p_spi = &(p_pkt[netTest_MAC_HEADER_LEN+netTest_IP_HEADER_LEN]);
183             pkt_type = netTest_IPSEC_ESP_PKT;
184         }
185         else
186         {
187             netapi_Log("flip_and_send_pkt: un-supported IPSEC protocol\n");
188             Pktlib_freePacket(tip);
189             return;
190         }
192         p_sa_info = (netTestSA_t *) trie_lookup(p_trie_sa_rx, (char *)p_spi ,4);
193         if (p_sa_info == NULL)
194         {
195             netapi_Log("flip_and_send_pkt(): trie_lookup() failed\n");
196             Pktlib_freePacket(tip);
197             return;
198         }
199         tunnel_id = p_sa_info->tunnel_id;
200         p_sa_info_tx = (netTestSA_t *) trie_lookup(p_trie_sa_tx, (char *)&tunnel_id ,4);
201         if (p_sa_info_tx == NULL)
202         {
203             netapi_Log("flip_and_send_pkt(): trie_lookup() failed\n");
204             Pktlib_freePacket(tip);
205             return;
206         }
207         //just drop non-udp packet
208         if (p_pkt[p_sa_info->tx_payload_info.encOffset+9]!=0x11)
209         {
210             stats[coreid].n_new+=1;Pktlib_freePacket(tip); return;
211         }
213         /* flip inner IP */
214         memcpy(&ip_temp, &p_pkt[p_sa_info->tx_payload_info.encOffset+12],4);
215         memcpy(&p_pkt[p_sa_info->tx_payload_info.encOffset+12],&p_pkt[p_sa_info->tx_payload_info.encOffset+12+4],4);
216         memcpy(&p_pkt[p_sa_info->tx_payload_info.encOffset+12+4],&ip_temp,4);
217         /* setting udp ports */
218         if (netTestCfg.dest_udp_port_config == 0)
219         {
220             memcpy(&p_pkt[p_sa_info->tx_payload_info.encOffset+netTest_IP_HEADER_LEN+2],
221                    &p_pkt[p_sa_info->tx_payload_info.encOffset+netTest_IP_HEADER_LEN],2);
222         }
223         else
224         {
225            dest_udp_port_config = htons(netTestCfg.dest_udp_port_config);
226             memcpy(&p_pkt[p_sa_info->tx_payload_info.encOffset+netTest_IP_HEADER_LEN+2],
227                    &dest_udp_port_config,2);
228         }
229         memset(&p_pkt[p_sa_info->tx_payload_info.encOffset+netTest_IP_HEADER_LEN+6],0,2); //checksum
231         if (netTestCfg.ipsec_mode_tx == IPSEC_MODE_TX_SIDEBAND)
232         {
233             /* inner ip checksum : leave alone, outer ip, set to 0 (we will compute on way out */
234             memset(&p_pkt[netTest_MAC_HEADER_LEN+10],0,2);
235         }
236     }
237     else
238     {
239         /* flip udp port */
240         if (netTestCfg.dest_udp_port_config == 0)
241         {
242             memcpy(&p_pkt[netTest_MAC_HEADER_LEN+netTest_IP_HEADER_LEN+2],
243                    &p_pkt[netTest_MAC_HEADER_LEN+netTest_IP_HEADER_LEN],2);
244         }
245         else
246         {
247             dest_udp_port_config = htons(netTestCfg.dest_udp_port_config);
248             //memcpy(&p_pkt[netTest_MAC_HEADER_LEN+20+2],&new_dest_port[0],2);
249             memcpy(&p_pkt[netTest_MAC_HEADER_LEN+netTest_IP_HEADER_LEN+2],&dest_udp_port_config,2);
250         }
252         memset(&p_pkt[netTest_MAC_HEADER_LEN+netTest_IP_HEADER_LEN+6],0,2);//0 udp checksum (we will compute on way out)
253     }
255     /*IPSEC case */ 
256     if (flag)
257     {
258         if (netTestCfg.ipsec_mode_tx == IPSEC_MODE_TX_SIDEBAND)
259         //send to crypto for encryption
260         //12 byte auth tag
261         {
262             PKTIO_METADATA_T meta = {PKTIO_META_SB_TX,{0},0};
263             int err;
264             nwalDmTxPayloadInfo_t meta_tx={0};
265             
266             meta.sa_handle = (void*)p_sa_info_tx->tx_tunnel;  //use TX SA APPID
268             memcpy(&meta_tx, &(p_sa_info->tx_payload_info), sizeof(nwalDmTxPayloadInfo_t));
269             meta_tx.appCtxId = (nwal_AppId)p_sa_info_tx;
270             meta_tx.encSize = len - p_sa_info->tx_payload_info.encOffset -p_sa_info->auth_tag_size;
271             meta_tx.authSize = len - meta_tx.authOffset - p_sa_info->auth_tag_size;
272             meta_tx.pAuthIV=NULL;
273             meta_tx.aadSize=0;
274             meta_tx.pAad=NULL;
275             if (p_sa_info->cipherMode ==  NWAL_SA_EALG_AES_CTR)
276             {
277                 memcpy(&p_iv[0], &p_sa_info->key_params->pEncKey[16], 4);
278                 memcpy(&p_iv[4], &p_pkt[netTest_MAC_HEADER_LEN +netTest_IP_HEADER_LEN + netTest_ESP_HEADER_LEN], 8);
279                 p_iv[12] = 0;
280                 p_iv[13] = 0;
281                 p_iv[14] = 0;
282                 p_iv[15] = 1;
283                 meta_tx.pEncIV = &p_iv[0];
284             }
285             else if ((p_sa_info->cipherMode == NWAL_SA_EALG_AES_GCM) || (p_sa_info->cipherMode == NWAL_SA_EALG_AES_CCM))
286             {
287                 memcpy(&p_iv[0], &p_pkt[netTest_MAC_HEADER_LEN +netTest_IP_HEADER_LEN + netTest_ESP_HEADER_LEN], 8);
288                 meta_tx.pEncIV = &p_iv[0];
289                 memcpy(&p_add[0], &p_pkt[netTest_MAC_HEADER_LEN +netTest_IP_HEADER_LEN], 8);
290                 meta_tx.pAad= &p_add[0];
291                 meta_tx.aadSize = 8;
292             }
293             else if (p_sa_info->authMode == NWAL_SA_AALG_GMAC)
294             {
295                 memcpy(&p_iv[0], &p_pkt[netTest_MAC_HEADER_LEN +netTest_IP_HEADER_LEN + netTest_ESP_HEADER_LEN], 8);
296                 meta_tx.pAuthIV= &p_iv[0];
297                 memcpy(&p_add[0], &p_pkt[netTest_MAC_HEADER_LEN +netTest_IP_HEADER_LEN], 8);
298                 meta_tx.pAad= &p_add[0];
299                 meta_tx.aadSize = 8;
300             }
301             else if (p_sa_info->cipherMode ==  NWAL_SA_EALG_NULL)
302             {
303                 meta_tx.pEncIV = NULL;
304             }
305             else
306             {
307                 meta_tx.pEncIV = &p_pkt[netTest_MAC_HEADER_LEN +netTest_IP_HEADER_LEN + netTest_ESP_HEADER_LEN ];
308             }
309             /* post it to netcp sb tx channel*/
310             meta.u.tx_sb_meta=&meta_tx;
312             netapi_pktioSend(netcp_sb_tx_chan,tip,&meta,&err);
313         }
314         else
315         {
316             //INFLOW TX, send pkt directly, asking for IP and UDP checksum offloads AND IPSEC to be applied
317             PKTIO_METADATA_T meta = {PKTIO_META_TX,{0},0};
318             int err;
319             nwalTxPktInfo_t meta_tx={0};
321             meta.sa_handle = (void*)p_sa_info_tx->tx_tunnel;  //use TX SA APPID
323             meta_tx.startOffset = p_sa_info_tx->tx_pkt_info.startOffset;
324             meta_tx.ipOffBytes =p_sa_info_tx->tx_payload_info.encOffset; 
325             meta_tx.l4OffBytes = p_sa_info_tx->tx_pkt_info.l4OffBytes;
326             meta_tx.l4HdrLen = p_sa_info_tx->tx_pkt_info.l4HdrLen;
327             meta_tx.ploadLen = (unsigned) ((p_pkt[meta_tx.l4OffBytes+4]<<8)|p_pkt[meta_tx.l4OffBytes+4+1]) -8 ;
328             meta_tx.saOffBytes=  p_sa_info_tx->tx_pkt_info.saOffBytes;
329             if (pkt_type == netTest_IPSEC_AH_PKT)
330             {
331                 memset(&p_pkt[netTest_MAC_HEADER_LEN+netTest_IP_HEADER_LEN+netTest_IPSEC_AH_FIXED_HDR_SIZE],0,netTest_IPSEC_AH_FIXED_HDR_SIZE);
332                 meta_tx.txFlag1 = p_sa_info_tx->tx_pkt_info.txFlag1;
333                 meta_tx.saPayloadLen=len-netTest_MAC_HEADER_LEN;   //don't inlcude mac 
334                 meta_tx.saAhMacSize = 12;
335                 meta_tx.saAhIcvOffBytes = netTest_MAC_HEADER_LEN + netTest_IP_HEADER_LEN + netTest_IPSEC_AH_FIXED_HDR_SIZE;
336                 
337                 meta_tx.enetPort = enet_port;
338                  memcpy(&p_pkt[netTest_MAC_HEADER_LEN+netTest_IP_HEADER_LEN+4],&p_sa_info_tx->spi,4);
339             }
340             else if (pkt_type == netTest_IPSEC_ESP_PKT)
341             {
342                 meta_tx.txFlag1 = p_sa_info_tx->tx_pkt_info.txFlag1;
343                 meta_tx.saPayloadLen=len-netTest_MAC_HEADER_LEN-netTest_IP_HEADER_LEN;   //don't include mac and ip outer header
344                 meta_tx.enetPort = 0;
345                  memcpy(&p_pkt[netTest_MAC_HEADER_LEN+netTest_IP_HEADER_LEN],&p_sa_info_tx->spi,4);
346             }
347             else
348             {
349                 printf("flip_and_send_pkt: invalid ESP protocol\n");
350                 return;
351             }
353             meta_tx.pseudoHdrChecksum =
354             netTest_utilGetIPv4PsudoChkSum(&p_pkt[meta_tx.ipOffBytes],8+ meta_tx.ploadLen);
357             /* post it to netcp tx channel*/
358             meta.u.tx_meta=&meta_tx;
359 #ifdef DEBUG_DESC
360             if (stats[coreid].sec_tx<20) netTest_utilDumpDescr((long *) tip, stats[coreid].sec_tx);
361 #endif
362             if ( pkt_type == netTest_IPSEC_ESP_PKT)
363                 netapi_pktioSend(netcp_tx_chan_esp,tip,&meta,&err);
364             else if ( pkt_type == netTest_IPSEC_AH_PKT)
365                  netapi_pktioSend(netcp_tx_chan_ah,tip,&meta,&err);
366             stats[coreid].tx +=1;
367             stats[coreid].sec_tx +=1;
368         }
369     }
370     else  //non ipsec send pkt directly, asking for IP and UDP checksum ofload
371     {
372         PKTIO_METADATA_T meta2 = {PKTIO_META_TX,{0},0};
373         int err;
374         nwalTxPktInfo_t meta_tx2={0};
375         meta2.sa_handle=nwal_HANDLE_INVALID;
376         meta_tx2.txFlag1 = (NWAL_TX_FLAG1_DO_UDP_CHKSUM| NWAL_TX_FLAG1_META_DATA_VALID );
377         meta_tx2.startOffset = 0;
378         meta_tx2.ipOffBytes = netTest_MAC_HEADER_LEN;
379         meta_tx2.l4OffBytes = netTest_MAC_HEADER_LEN +netTest_IP_HEADER_LEN;
380         meta_tx2.l4HdrLen = netTest_UDP_HEADER_LEN;
381         meta_tx2.ploadLen = (unsigned) ((p_pkt[netTest_MAC_HEADER_LEN+netTest_IP_HEADER_LEN+4]<<8)|
382                                         p_pkt[netTest_MAC_HEADER_LEN+netTest_IP_HEADER_LEN+4+1]) -8 ;
383         meta_tx2.pseudoHdrChecksum =
384         netTest_utilGetIPv4PsudoChkSum(&p_pkt[netTest_MAC_HEADER_LEN],8+ meta_tx2.ploadLen);
386         /* post it to netcp tx channel*/
387         meta2.u.tx_meta=&meta_tx2;
388         netapi_pktioSend(netcp_tx_chan_no_crypto,tip,&meta2,&err);
389         stats[coreid].tx +=1;
390     }
394 /**********************************************************************
395  * FUNCTION PURPOSE:  Sideband Accelerator Callback PKT RECEIVE HANDLER
396  **********************************************************************
397  * DESCRIPTION:   Sideband Accelerator Callback PKT RECEIVE HANDLER
398  *                Handles Decrypt and Encrypt operation callbacks
399  **********************************************************************/
400 void recv_sb_cb(struct PKTIO_HANDLE_Tag * channel, Ti_Pkt* p_recv[],
401                          PKTIO_METADATA_T meta[], int n_pkts,
402                          uint64_t ts )
404     int i;
405     int len;
406     int p;
407     netTestHead_T * p_res;
408     Ti_Pkt * tip;
409     unsigned int templen;
410     int err;
411     char * p_pkt;
412     netTestHead_T * p_head;
413     netTestHead_T temp_head;
414     int tag_cmp=0;
415     unsigned int hash[4];
416     uint8_t *p_spi;
417     netTestSA_t *p_sa_info;
419 #ifdef netTest_MULTI_THREAD
420     int coreid=Osal_nwalGetProcId();  //who we are(thread local)
421 #else
422     int coreid=0;
423 #endif
424     //nwal_AppId time;
425     unsigned long time, delta_time;
426     /* loop over received pkts */
427     for(i=0;i<n_pkts;i++)
428    {
429         tip = p_recv[i];
430         Pktlib_getDataBuffer(tip,(uint8_t**)&p_pkt,&templen);//ignore templen
431         len = Pktlib_getPacketLen(tip);//real length
433         /*p_sa_info is for rx context */
434         p_sa_info = (netTestSA_t*)meta[i].u.rx_sb_meta->appCtxId;
435         if (p_sa_info == NULL)
436         {
437             printf("recv_sb_cb(): trie_lookup failed\n");
438             continue;
439         }
441         //is this a decrypt (rx_tunnel) complete
442         if ((int)meta[i].u.rx_sb_meta->appId == p_sa_info->rx_tunnel)
443         {
444             //time = hplib_mUtilGetPmuCCNT();
445             //delta_time = time -(unsigned long) meta[i].u.rx_sb_meta->appCtxId;
446             stats[coreid].total_decrypt_time += delta_time;
447             stats[coreid].sb_rx+=1;
448             //copy hash out of meta data (for some reason it needs endian conversion)
449             hash[0]= netTest_utilHtonl( meta[i].u.rx_sb_meta->pAuthTag[0]);
450             hash[1]= netTest_utilHtonl( meta[i].u.rx_sb_meta->pAuthTag[1]);
451             hash[2]= netTest_utilHtonl( meta[i].u.rx_sb_meta->pAuthTag[2]);
452             hash[3]= netTest_utilHtonl( meta[i].u.rx_sb_meta->pAuthTag[3]);
453             if(stats[coreid].sb_rx<=16)
454             {
455                 char *tp = (char *) &hash[0];
456                 //netTest_utilDumpHeader((long*)p_pkt, stats[coreid].sb_rx, (int)meta[i].u.rx_sb_meta->appId,0);
457             }
458             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
459             stats[coreid].n_auth_ok += !(tag_cmp);
460             flip_and_send_pkt(tip, p_pkt, len,1, 0);  //flip packet to echo back and send
461         }
462         //this is an encrypt (tx tunnel) complete
463         else if((int)meta[i].u.rx_sb_meta->appId== p_sa_info->tx_tunnel )
464         {
465             hash[0]= netTest_utilHtonl( meta[i].u.rx_sb_meta->pAuthTag[0]);
466             hash[1]= netTest_utilHtonl( meta[i].u.rx_sb_meta->pAuthTag[1]);
467             hash[2]= netTest_utilHtonl( meta[i].u.rx_sb_meta->pAuthTag[2]);
468             hash[3]= netTest_utilHtonl( meta[i].u.rx_sb_meta->pAuthTag[3]);
469             stats[coreid].sb_tx+=1;
470             if(stats[coreid].sb_tx<=16)
471             {
472                 //netTest_utilDumpHeader((long*)p_pkt, stats[coreid].sb_tx, (int)meta[i].u.rx_sb_meta->appId,0);
473             }
474             //put the computed tag in the packet
475              memcpy(&p_pkt[len-p_sa_info->auth_tag_size],(char*)&hash[0],p_sa_info->auth_tag_size); //todo, really use meta->authTagLen
476             {
477                 PKTIO_METADATA_T meta2 = {PKTIO_META_TX,{0},0};
478                 nwalTxPktInfo_t meta_tx={0};
479                 // now send directly 
480                 meta2.sa_handle=nwal_HANDLE_INVALID;
481                 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
482                 meta_tx.startOffset = 0;
483                 meta_tx.ipOffBytes = netTest_MAC_HEADER_LEN;
484                 meta_tx.l4OffBytes = 0;
485                 meta_tx.l4HdrLen = 0;
486                 meta_tx.ploadLen = 0;
487                 time = hplib_mUtilGetPmuCCNT();
488                 delta_time = time -(unsigned long) meta[i].u.rx_sb_meta->appCtxId;
489                 stats[coreid].total_encrypt_time += delta_time;
491                 /* post it to netcp tx channel*/
492                 meta2.u.tx_meta=&meta_tx;
493                 netapi_pktioSend(netcp_tx_chan_esp,tip,&meta2,&err);
494                 hplib_cacheWbInv(p_pkt,len);
495                 stats[coreid].tx +=1;
496             }
497         }
498         else printf("netapi recv_sb_cb: unknown appiD %x \n",meta[i].u.rx_sb_meta->appId );
499     }
502 /**********************************************************************
503  * FUNCTION PURPOSE:  Packet receive Callback
504  *
505  **********************************************************************
506  * DESCRIPTION:   packet Receive callback
507  **********************************************************************/
508 void recv_cb(struct PKTIO_HANDLE_Tag * channel, Ti_Pkt* p_recv[],
509                          PKTIO_METADATA_T meta[], int n_pkts,
510                          uint64_t ts )
512     int i;
513     int len;
514     int p;
515     netTestHead_T * p_res;
516     Ti_Pkt * tip;
517     unsigned int templen;
518     int err = 0;
519     char * p_pkt;
520     netTestHead_T * p_head;
521     netTestHead_T temp_head;
522     netTestSA_t *p_sa_info;
523     uint8_t *p_spi;
524     uint8_t p_iv[16];
525     uint8_t p_add[8];
526     uint8_t p_add1[1500];
527     int16_t       retVal;
528     unsigned long t1;
529     unsigned long t2;
530     unsigned long long ct1;
531     unsigned long long ct2;
532     unsigned long long n_c_ops;
533     nwalGlobCxtInfo_t   nwalGlobCxt;
534     nwalLocCxtInfo_t    nwalLocCxt;
536     Cppi_HostDesc*          pPloadDesc;
537     int ifno;
538     uint16_t enet_port = 0;
540 #ifdef netTest_MULTI_THREAD
541     int coreid=Osal_nwalGetProcId();  //who we are(thread local)
542 #else
543     int coreid=0;
544 #endif
545     p_head=&temp_head;
547     t1=hplib_mUtilGetPmuCCNT();
548     ct1 =Osal_cache_op_measure(&n_c_ops);
550     /* loop over received pkts */
551     for(i=0;i<n_pkts;i++)
552     {
553         ifno = ((unsigned int)meta[i].u.rx_meta->appId)&0xff;
554         
555         enet_port = meta[i].u.rx_meta->enetPort;
556         tip = p_recv[i];
558         Pktlib_getDataBuffer(tip,(uint8_t**)&p_pkt,&templen);/*ignore templen */
559         len = Pktlib_getPacketLen(tip)-4;   /*real length, subtract mac trailer */
560         Cppi_setData (Cppi_DescType_HOST, (Cppi_Desc *) tip, p_pkt,len);
561         Pktlib_setPacketLen(tip,len);
563         if(((unsigned int)meta[i].u.rx_meta->appId) == expPkt_appid)
564         {
565             netapi_Log("recv_cb: received exception packet\n");
566             Pktlib_freePacket(tip);
567             if(((unsigned int)meta[i].u.rx_meta->rxFlag1  & NWAL_RX_IP_FRAGMENT_PKT) ==
568                                              NWAL_RX_IP_FRAGMENT_PKT)
569             {
570                 stats[coreid].exceptionPktsFrag+=1;
571             }
572             else
573             {
574                 stats[coreid].exceptionPktsOther+=1;
575             }
576             continue;
577         }
578         //debug: validate descriptor */
579         if(Pktlib_getNextPacket(tip) != 0) 
580         {
581             printf(" rcv_cb, nexpkt != NULL");
582         }
584         if(coreid<TUNE_NETAPI_NUM_CORES)
585             stats[coreid].rx+=1;
586         if (ifno < TUNE_NETAPI_MAX_NUM_MAC)
587             stats[coreid].if_rx[ifno]+=1;
590 #ifdef DEBUG_DESC
591         if (stats[coreid].rx<16)
592         {
593             netapi_Log(">rx dmp.."); 
594             netTest_utilDumpDescr((long *) tip, stats[coreid].rx);
595         }
596         else if (stats[coreid].rx>99) 
597         {
598             netapi_Log(">rx dmp.."); 
599             netTest_utilDumpDescr((long *) tip,stats[coreid].rx);
600         }
601 #endif
602 #if 0
603         //
604         if(stats[coreid].rx<=16)
605         {
606             netTest_utilDumpHeader((long*)p_pkt,stats[coreid].rx, (int)meta[i].u.rx_meta->appId,meta[i].u.rx_meta->rxFlag1);
607             netTest_utilDumpBuffer((long*)p_pkt,len);
608         }
609 #endif
610         /* check header */
611         memcpy(p_head,&p_pkt[netTest_MAC_HEADER_LEN],sizeof(netTestHead_T));
613         /* check for IPSEC ESP or AH packet, 0x32 is ESP tunnel mode, 0x33 is AH tunnel mode*/
614         if (((p_head->ip[2]&0x0000ff00)==0x00003200) || ((p_head->ip[2]&0x0000ff00)==0x00003300))
615         {
616             if (!netTest_utilCheckHeader(p_head,&meta[i]))
617             {
618                 printf("recv_cb: error in ipsec pkt\n");
619                 stats[coreid].n_bad+=1;Pktlib_freePacket(tip); 
620                 continue;
621             }
623             //process IP SEC PACKET
624             if (netTestCfg.ipsec_mode_rx == IPSEC_MODE_RX_SIDEBAND)
625             {
626                 p_spi = &(p_pkt[netTest_MAC_HEADER_LEN+netTest_IP_HEADER_LEN]);
627                 p_sa_info = (netTestSA_t *) trie_lookup(p_trie_sa_rx, (char *)p_spi ,4);
628                 if (p_sa_info == NULL)
629                 {
630                     printf("recv_cb(): trie_lookup() failed\n");
631                     continue;
632                 }
634                 //ship to crypto for decrypt!!
635                 //12 byte auth tag
636                 PKTIO_METADATA_T meta2 = {PKTIO_META_SB_TX,{0},0};
637                 nwalDmTxPayloadInfo_t meta_tx={0};
639                 meta2.sa_handle = (void*) p_sa_info->rx_tunnel;
641                 memcpy(&meta_tx, &(p_sa_info->tx_payload_info), sizeof(nwalDmTxPayloadInfo_t));
643                 meta_tx.encSize = len - p_sa_info->tx_payload_info.encOffset -p_sa_info->auth_tag_size;
644                 meta_tx.authSize = len - meta_tx.authOffset - p_sa_info->auth_tag_size;
646                 if (p_sa_info->cipherMode == NWAL_SA_EALG_AES_CTR)
647                 {
648                     memcpy(&p_iv[0], &p_sa_info->key_params->pEncKey[16], 4);
649                     memcpy(&p_iv[4], &p_pkt[netTest_MAC_HEADER_LEN +netTest_IP_HEADER_LEN + netTest_ESP_HEADER_LEN], 8);
650                     p_iv[12] = 0;
651                     p_iv[13] = 0;
652                     p_iv[14] = 0;
653                     p_iv[15] = 1;
654                     meta_tx.pEncIV = &p_iv[0];
655                  
656                 }
657                 else if ((p_sa_info->cipherMode == NWAL_SA_EALG_AES_GCM) ||
658                             (p_sa_info->cipherMode == NWAL_SA_EALG_AES_CCM))
659                 {
660                         memcpy(&p_iv[0], &p_pkt[netTest_MAC_HEADER_LEN +netTest_IP_HEADER_LEN + netTest_ESP_HEADER_LEN], 8);
661                         meta_tx.pEncIV = &p_iv[0];
662                         /* aad is the ESP header which is 8 bytes */
663                         memcpy(&p_add[0], &p_pkt[netTest_MAC_HEADER_LEN +netTest_IP_HEADER_LEN], 8);
664                         meta_tx.pAad= &p_add[0];
665                         meta_tx.aadSize = 8;
666                 }
667                 else if (p_sa_info->authMode == NWAL_SA_AALG_GMAC)
668                 {
669                     memcpy(&p_iv[0], &p_pkt[netTest_MAC_HEADER_LEN +netTest_IP_HEADER_LEN + netTest_ESP_HEADER_LEN], 8);
670                         meta_tx.pAuthIV= &p_iv[0];
671                         /* aad is the ESP header which is 8 bytes */
672                         memcpy(&p_add[0], &p_pkt[netTest_MAC_HEADER_LEN +netTest_IP_HEADER_LEN], 8);
673                         meta_tx.pAad= &p_add[0];
674                         meta_tx.aadSize = 8;
675                 }
676                 else if (p_sa_info->cipherMode ==  NWAL_SA_EALG_NULL)
677                 {
678                     meta_tx.pEncIV = NULL;
679                 }
680                 else
681                 {
682                     meta_tx.pEncIV = &p_pkt[netTest_MAC_HEADER_LEN +netTest_IP_HEADER_LEN + netTest_ESP_HEADER_LEN ];
683                 }
684                
685                 meta_tx.appCtxId = (nwal_AppId)p_sa_info;
687                 /* post it to netcp sb tx channel*/
688                 meta2.u.tx_sb_meta=&meta_tx;
690                 netapi_pktioSend(netcp_sb_tx_chan,tip,&meta2,&err);
691                 continue;
692             }
693             else
694             {
695                 //inflow mode.  flip and send
696                 flip_and_send_pkt(tip,p_pkt,len,1, enet_port);
697             }
698         }
699         /* check for udp protocol */
700         else if ((p_head->ip[2]&0x0000ff00)!=0x00001100)
701          //else if ((p_head->ip[2]&0x00ff0000)!=0x00110000)
702         {
703             stats[coreid].n_new+=1;Pktlib_freePacket(tip); continue;
704         }
705         else  //non ipsec
706         {
707             if (!netTest_utilCheckHeader(p_head,&meta[i]))
708             {
709                 stats[coreid].n_bad+=1;Pktlib_freePacket(tip);
710                 continue;
711             }
712             //just flip and send
713             flip_and_send_pkt(tip,p_pkt,len,0, enet_port);
714         }
715     }
716     t2=hplib_mUtilGetPmuCCNT();
717     ct2 =Osal_cache_op_measure(&n_c_ops);
718     stats[coreid].app_cycles +=  (unsigned long long) (t2-t1);
719     stats[coreid].tx_cache_cycles += (unsigned long long) (ct2-ct1);
722 /* Templates to build command labels at startup up time, required by open_pktio_tx_channels() */
723 nwalTxPktInfo_t txPktInfoESP = 
725     NULL,                                                                                               /* p_pkt */
726     NWAL_TX_FLAG1_DO_IPSEC_ESP_CRYPTO| NWAL_TX_FLAG1_DO_UDP_CHKSUM| NWAL_TX_FLAG1_META_DATA_VALID,      /* txFlags */
727     0,                                                                                                  /* lpbackPass */
728     0,                                                                                                  /* enetport */
729     0,                                                                                                  /* msuSize */
730     0,                                                                                                   /* startOffset */
731     netTest_MAC_HEADER_LEN  + netTest_IP_HEADER_LEN,                                                    /* saOffBytes */
732     0,                                                                                                  /* saPayLoadLen */
733     0               ,                                                                                    /* saAhIcvOffBytes */
734     0,                                                                                                 /* saAhMacSize */
735     0,                                                                                                  /* etherLenOffBytes */
736     0,                                                                                                  /* ipOffBytes */
737     0,                                                                                                  /* l4OffBytes */
738     netTest_UDP_HEADER_LEN,                                                                             /* l4HdrLen */
739     0,                                                                                                  /* pseudoHdrChecksum */
740     0                                                                                                   /* pLoadLen */
741 };
744 nwalTxPktInfo_t txPktInfoAH = 
746     NULL,                                                                                               /* p_pkt */
747     NWAL_TX_FLAG1_DO_IPSEC_AH_CRYPTO| 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     netTest_MAC_HEADER_LEN  + netTest_IP_HEADER_LEN,                                                    /* saOffBytes */
753     0,                                                                                                  /* saPayLoadLen */
754     netTest_MAC_HEADER_LEN + netTest_IP_HEADER_LEN + netTest_IPSEC_AH_FIXED_HDR_SIZE,                    /* saAhIcvOffBytes */
755     12,                                                                                                 /* saAhMacSize */
756     0,                                                                                                  /* etherLenOffBytes */
757     0,                                             /* ipOffBytes */
758     0,                                                                                                  /* l4OffBytes */
759     netTest_UDP_HEADER_LEN,                                                                            /* l4HdrLen */
760     0,                                                                                                  /* pseudoHdrChecksum */
761     0                                                                                                   /* pLoadLen */
762 };
764 nwalTxPktInfo_t txPktInfoNoCrypto = 
766     NULL,                                                                                               /* p_pkt */
767     NWAL_TX_FLAG1_DO_UDP_CHKSUM| NWAL_TX_FLAG1_META_DATA_VALID,      /* txFlags */
768     0,                                                                                                  /* lpbackPass */
769     0,                                                                                                  /* enetport */
770     0,                                                                                                  /* msuSize */
771     0,                                                                                                   /* startOffset */
772     0,                                                    /* saOffBytes */
773     0,                                                                                                  /* saPayLoadLen */
774     0               ,                                                                                    /* saAhIcvOffBytes */
775     0,                                                                                                 /* saAhMacSize */
776     0,                                                                                                  /* etherLenOffBytes */
777     0,                                                                                                  /* ipOffBytes */
778     netTest_MAC_HEADER_LEN +netTest_IP_HEADER_LEN,                                        /* l4OffBytes */
779     netTest_UDP_HEADER_LEN,                                                             /* l4HdrLen */
780     0,                                                                         /* pseudoHdrChecksum */
781     0                                                                                                   /* pLoadLen */
782 };
785 void close_pktio_channels(void)
787     int err;
788     netapi_pktioClose(netcp_tx_chan_esp ,&err);
789     netapi_pktioClose(netcp_tx_chan_ah ,&err);
790     netapi_pktioClose(netcp_sb_tx_chan ,&err);
791     netapi_pktioClose(netcp_tx_chan_no_crypto,&err);
794 void open_pktio_tx_channels(void)
796     int err;
797     /* open netcp default  TX for ESP packets */
798     netcp_tx_chan_esp= netapi_pktioOpen(netapi_handle, NETCP_TX, NULL, &netcp_tx_cfg,  &err);
799     if (!netcp_tx_chan_esp)
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_ESP_L4CKSUM_PORT;
812             cfg.fast_path_cfg.txPktInfo= &txPktInfoESP;
813             netapi_pktioControl(netcp_tx_chan_esp, NULL, &cfg, &control, &err);
814         }
815     }
817     /*/* open netcp default  TX for AH packets */
818     netcp_tx_chan_ah= netapi_pktioOpen(netapi_handle, NETCP_TX, NULL, &netcp_tx_cfg,  &err);
819     if (!netcp_tx_chan_ah)
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_AH_L4CKSUM_PORT;
832             cfg.fast_path_cfg.txPktInfo= &txPktInfoAH;
833             netapi_pktioControl(netcp_tx_chan_ah, NULL, &cfg, &control, &err);
834         }
835     }
837     /* open netcp default  TX channels for non-Crypto packets */
838     netcp_tx_chan_no_crypto= netapi_pktioOpen(netapi_handle, NETCP_TX, NULL, &netcp_tx_cfg,  &err);
839     if (!netcp_tx_chan_no_crypto)
840     {
841         printf("pktio open TX failed err=%d\n",err);
842         exit(1);
843     }
844     else
845     {
846         if(netTestCfg.ipsec_mode_tx == IPSEC_MODE_TX_INFLOW)
847         {
848             PKTIO_CONTROL_T control;
849             control.op = PKTIO_UPDATE_FAST_PATH;
850             PKTIO_CFG_T cfg;
851             cfg.fast_path_cfg.fp_send_option = PKTIO_FP_L4CKSUM_PORT;
852             cfg.fast_path_cfg.txPktInfo= &txPktInfoNoCrypto;
853             netapi_pktioControl(netcp_tx_chan_no_crypto, NULL, &cfg, &control, &err);
854         }
855     }
857     /* open netcp default  TX channels for SB crypto */
858     netcp_sb_tx_chan= netapi_pktioOpen(netapi_handle, NETCP_SB_TX, NULL, &netcp_sb_tx_cfg,  &err);
859     if (!netcp_sb_tx_chan)
860     {
861         printf("pktio open SB TX failed err=%d\n",err);
862         exit(1);
863     }
866 #ifdef netTest_DSP_FASTPATH
867 void setup_netTestDSPFastPath(NETAPI_T handle)
870     int i;
871     int err = 0;
872     PKTIO_CFG_T dsp_pktio_cfg;
873     NETCP_CFG_CLASSIFIER_T dsp_classi;
874     NETCP_CFG_ROUTE_T dsp_route;
876     memset(&dsp_pktio_cfg, 0, sizeof (PKTIO_CFG_T));
877     memset(&dsp_classi, 0, sizeof (NETCP_CFG_CLASSIFIER_T));
878     memset(&dsp_route, 0, sizeof (NETCP_CFG_ROUTE_T));
879     char dsp_name[32];
880     for (i = 0; i < CPU_NUM_REM_FAST_PATH_CORES; i++)
881     {
882         sprintf(&dsp_name[0],"%s%d","dsp_chan", i);
883         dsp_pktio_cfg.flags1 = PKTIO_RX;
884         dsp_pktio_cfg.flags2 = PKTIO_GLOBAL | PKTIO_PKT;
885         dsp_pktio_cfg.qnum = TEST_NWAL_BASE_REM_FP_RX_PKT_QUEUE + i;
886         dsp_pktio_cfg.max_n = 8;
888         /* pktio channels created here will NOT be POLLED by net_test arm application */
889         dsp_pktio_channels[i] = netapi_pktioCreate(handle,
890                                                &dsp_name[0],
891                                                (PKTIO_CB)recv_cb,
892                                                &dsp_pktio_cfg,
893                                                &err);
894         if (!dsp_pktio_channels[i])
895         {
896             netapi_Log("setup_netTestDSPFastPath: failed for core %d\n", i);
897         }
899         dsp_classi.classType =NETCP_CFG_CLASS_TYPE_L4;
900         dsp_classi.u.c_l4.iface = netTestCfg.dsp_mac;
901         
902         dsp_classi.u.c_l4.ip = ip_rule[netTestCfg.dsp_ip];
903         dsp_classi.u.c_l4.proto = NWAL_APP_PLOAD_PROTO_UDP;
904         dsp_classi.u.c_l4.appProto.udpPort = TEST_NWAL_BASE_REM_FP_UDP_PORT + i;
906         dsp_route.p_dest_q = dsp_pktio_channels[i];
907        
908         dsp_route.p_flow = (NETCP_CFG_FLOW_T*)NETCP_DEFAULT_FLOW;
909         
910         dsp_classifers[i] = netapi_netcpCfgAddClass(handle, 
911                                 &dsp_classi, 
912                                 (NETCP_CFG_ROUTE_HANDLE_T) &dsp_route, 
913                                 NETCP_CFG_ACTION_TO_SW,
914                                 NULL,
915                                 &err);
917         if (err != NETAPI_ERR_OK)
918         {
919             netapi_Log("setup_netTestDSPFastPath: netapi_netcpCfgAddClass failed for core %d\n", i);
920         }
921     }
922     printf("DSP Path fath setup complete\n");
925 void teardown_netTestDSPFastPath()
927     int i;
928     int err=0;
930     for (i = 0; i < CPU_NUM_REM_FAST_PATH_CORES; i++)
931     {
932         netapi_netcpCfgDelClass(netapi_handle,
933                                 dsp_classifers[i],
934                                 &err);
935         if (err != NETAPI_ERR_OK)
936         {
937             printf("teardown_netTestDSPFastPath: netapi_netcpCfgDelClass failed for core %d\n", i);
938         }
940         netapi_pktioDelete(dsp_pktio_channels[i],
941                            &err);
942         if (err != NETAPI_ERR_OK)
943         {
944             printf("teardown_netTestDSPFastPath: netapi_pktioDelete failed for core %d\n", i);
945         }
946     }
947     printf("DSP Path fath teardown complete\n");
949 #endif
952 #ifdef netTest_MULTI_THREAD
953 NETAPI_T worker_nh[TUNE_NETAPI_NUM_CORES];
955 void slow_path_thread(uint32_t index)
957     int err, i;;
958     uint32_t thread_num;
959     PKTIO_HANDLE_T *rx_chan;
960     PKTIO_HANDLE_T *sb_rx_chan;
963     cpu_set_t cpu_set;
965     thread_num = netTestCfg.sp_thread_num[index];
966     netapi_Log("slow_path_thread, mypid: %d, core_id %d\n", gettid(), netTestCfg.sp_thread_num[index]);
968     CPU_ZERO( &cpu_set);
969 #ifdef CORTEX_A8
970     for (i = netTestCfg.sp_proc_start[index]; i <= netTestCfg.sp_proc_end[index];i++)
971     {
972         printf("slow_path_thread: setting cpu %d to cpu_set\n", i);
973         CPU_SET( 0, &cpu_set);
974     }
975     hplib_utilSetupThread(thread_num, &cpu_set);
976 #else
977     for (i = netTestCfg.sp_proc_start[index]; i <= netTestCfg.sp_proc_end[index];i++)
978     {
979         printf("slow_path_thread: setting cpu %d to cpu_set\n", i);
980         CPU_SET( i, &cpu_set);
981     }
982     hplib_utilSetupThread(thread_num, &cpu_set);
983 #endif
984     worker_nh[thread_num] = netapi_init(NETAPI_CORE_MASTER,NULL);
985     if (worker_nh[thread_num] == NULL)
986     {
987         printf("slow_path_thread: netapi_init failure, exiting\n");
988         exit(1);
989     }
990     netapi_setCookie(worker_nh[thread_num],(void*)(thread_num | NET_TEST_SP_THREAD_MASK));
992     scheduler[thread_num] =netapi_schedOpen(worker_nh[thread_num],&our_sched_cfg, &err);
993     if (!scheduler[thread_num]) 
994     {
995         printf("sched create failed for core%d\n",thread_num);
996         goto ERR_slow_path_thread;
997     }
998     scheduler[thread_num]->config.yield = TRUE;
999     scheduler[thread_num]->config.pollGarbageQ = TRUE;
1000     scheduler[thread_num]->config.pollCtrlQ = TRUE;
1001     printf("Slow Path thread: %d setup complete, running on ARM CORE: %d\n", i,i);
1002     /* Entry point to scheduler */
1003     netapi_schedRun(scheduler[thread_num], &err);
1005 ERR_slow_path_thread:
1006     netapi_shutdown(worker_nh[thread_num]);
1009 void fast_path_thread(uint32_t index)
1011     int err, i;
1012     PKTIO_HANDLE_T *rx_chan;
1013     PKTIO_HANDLE_T *sb_rx_chan;
1014     uint32_t thread_num;
1017     cpu_set_t cpu_set;
1019     CPU_ZERO( &cpu_set);
1020     thread_num = netTestCfg.fp_thread_num[index];
1021 #ifdef CORTEX_A8
1022     for (i = netTestCfg.fp_proc_start[index]; i <= netTestCfg.fp_proc_end[index];i++)
1023     {
1024         CPU_SET( 0, &cpu_set);
1025     }
1026     hplib_utilSetupThread(thread_num, &cpu_set);
1027 #else
1028     for (i = netTestCfg.fp_proc_start[index]; i <= netTestCfg.fp_proc_end[index];i++)
1029     {
1030         netapi_Log("fast_path_thread: start core %d, end core %d\n",
1031                 netTestCfg.fp_proc_start[index],
1032                 netTestCfg.fp_proc_end[index]);
1033         netapi_Log("fast_path_thread: setting cpu %d to cpu_set\n", i);
1034         CPU_SET( i, &cpu_set);
1035     }
1036     hplib_utilSetupThread(thread_num, &cpu_set);
1037 #endif
1038     worker_nh[thread_num]=netapi_init(NETAPI_CORE_MASTER,NULL);
1039     if (worker_nh[thread_num] == NULL)
1040     {
1041         printf("fast_path_thread: netapi_init failure, exiting\n");
1042         exit(1);
1043     }
1044     /* open netcp default RX channels*/
1045     rx_chan = netapi_pktioOpen(worker_nh[thread_num], NETCP_RX, (PKTIO_CB) recv_cb, &netcp_rx_cfg,  &err);
1047     /* create a pktio channel for specially classified pkts */
1048     /* open netcp default tx, rx queues for sideband crypto */
1049     sb_rx_chan = netapi_pktioOpen(worker_nh[thread_num], NETCP_SB_RX, (PKTIO_CB) recv_sb_cb, &netcp_sb_rx_cfg,  &err);
1051     netapi_setCookie(worker_nh[thread_num],(void*)thread_num);
1052     
1053     scheduler[thread_num] =netapi_schedOpen(worker_nh[thread_num],&our_sched_cfg, &err);
1054     if (!scheduler[thread_num]) 
1055         {
1056         printf("sched create failed for core%d\n",thread_num);
1057         goto ERR_fast_path_thread;
1058         //exit(1);
1059     }
1061  
1062     scheduler[thread_num]->config.yield = FALSE;
1063     scheduler[thread_num]->config.pollGarbageQ = FALSE;
1064     scheduler[thread_num]->config.pollCtrlQ = FALSE;
1065      //sleep(100000);
1066    /* Entry point to scheduler */
1067     printf("Fast Path thread: %d setup complete, running on ARM CORE: %d\n", i,i);
1068     netapi_schedRun(scheduler[thread_num], &err);
1070 ERR_fast_path_thread:
1071     netapi_pktioClose(rx_chan, &err);
1072     netapi_pktioClose(sb_rx_chan, &err);
1074     netapi_shutdown(worker_nh[thread_num]);
1077 #endif
1078 /***************************************
1079  ********** test driver*****************
1080  ***************************************/
1081 int main(int argc, char **argv)
1083     int err,i;
1084     Pktlib_HeapCfg      heapCfg;
1085     int32_t             errCode;
1086     Pktlib_HeapIfTable*  pPktifTable;
1087     FILE * fpr = NULL;
1089 #ifdef netTest_MULTI_THREAD
1090     cpu_set_t cpu_set;
1091 #endif
1092      /* install signal handler for ^c */
1093     signal(SIGINT,netTest_utilMySig);
1095     if (argc == 2)
1096     {
1097         printf("main: filename1 %s\n", argv[1]);
1098         fpr = fopen(argv[1], "r");
1099     }
1100     else
1101     {
1102         fpr = fopen(input_file_name, "r");
1103     }
1104     if (fpr == NULL)
1105     {
1106         printf("Cant open config file: filepath %s, %s\n", input_file_name, strerror(errno));
1107         exit(1);
1108     }
1109     else
1110     {
1111         memset(&config_file, 0, sizeof(netTestConfigFile_t));
1112         memset(&netTestCfg, 0, sizeof(netTestConfig_t));
1113         
1114         netTest_utilProcessConfigFile(fpr,&config_file);
1116         netTest_utilParseMac(&config_file);
1118         /* parse slow path/fast path thread configuration parameters */
1119         netTest_utilParseThreadParams(&config_file);
1121         netTest_utilParseIP(&config_file);
1123         netTest_utilParseIpsecMode(&config_file);
1125         /* DSP mac processing */
1126         parse_dsp_mac(&config_file.dsp_mac[0]);
1128        /* DSP IP processing */
1129         parse_dsp_ip(&config_file.dsp_ip[0]);
1131         /* IPSEC interface number processing */
1132         parse_simple_param_u32((char*)&config_file.ipsec_if_no[0], &netTestCfg.ipsec_if_no);
1134         netTest_utilParseSA(&config_file);
1136         parse_simple_param_u32(&config_file.dest_udp_port_config, &netTestCfg.dest_udp_port_config);
1137     }
1139     memset(&sa_info, 0, sizeof(sa_info));
1142 #ifdef netTest_MULTI_THREAD
1143     /* assign main net_test thread to run on core 0 */
1144     CPU_ZERO( &cpu_set);
1145     CPU_SET( 0, &cpu_set);
1146     hplib_utilSetupThread(0, &cpu_set);
1147 #endif
1149     /* create netapi */
1150     netapi_handle = netapi_init(NETAPI_SYS_MASTER, &our_netapi_default_cfg);
1152     if (netapi_handle == NULL)
1153     {
1154         printf("main: netapi_init failure, exiting\n");
1155         exit(1);
1156     }
1160     /* configure expection packet handling with netapi */
1161     netapi_netcpCfgExceptions(netapi_handle,
1162                               NETCP_CFG_ALL_EXCEPTIONS,
1163                               NETCP_CFG_ACTION_DISCARD, 
1164                               (NETCP_CFG_ROUTE_HANDLE_T) NULL);
1165     expPkt_appid = netapi_netcpCfgExceptions(netapi_handle, 
1166                                              7,
1167                                              NETCP_CFG_ACTION_TO_SW,
1168                                              (NETCP_CFG_ROUTE_HANDLE_T) NULL);
1170     /* open the main heap */
1171     ourHeap = Pktlib_findHeapByName("netapi");
1172     if (!ourHeap)
1173     {
1174         printf("Pktlib_findHeapByName()  fail\n");
1175         exit(1);
1176     }
1178     open_pktio_tx_channels();
1180     /* create scheduler instance */
1181     our_sched =netapi_schedOpen(netapi_handle,&our_sched_cfg, &err);
1182     if (!our_sched) {printf("sched create failed\n"); exit(1);}
1185     /*create net_test MAC interfaces, attach IP to created MAC interfaces */
1186     netTest_utilCreateInterfaces(netTestCfg.num_macs, netTestCfg.num_ips);
1188     /* lookup Database for SA context, this is used by packet processing routines to get RX and TX SA information*/
1189     p_trie_sa_rx = trie_new();
1190     p_trie_sa_tx = trie_new();
1191     if (!p_trie_sa_rx || !p_trie_sa_tx)
1192     {
1193         printf("trie alloc for SA  failed\n");
1194         exit(1);
1195     }
1197 #ifdef netTest_DSP_FASTPATH
1198     setup_netTestDSPFastPath(netapi_handle);
1199 #endif
1201     /* Create RX SA's, RX Policy and TX SA's, all SA configuration parameters are read from net_test_config.txt file */
1202     netTest_utilCreateSecAssoc();
1204 #ifdef netTest_MULTI_THREAD
1206     /* create and set affinity of slow path and fast path threads to
1207     * specific CPU cores as specified in the net_test_config.txt file */
1208     netTest_utilCreateSpFpThreads(netTestCfg.num_sp_threads, 
1209                                   (NET_TEST_FUNC_PTR) slow_path_thread,
1210                                   netTestCfg.num_fp_threads,
1211                                   (NET_TEST_FUNC_PTR) fast_path_thread);
1213     printf("\n net_test_loopback running ....\n");
1214     printf("\n Enter 's' for stats or 'q'to quit net_test_loopback app, or 'h' for help\n");
1216     char c;
1217         //this thread of execution (main) now just waits on user input
1218         for(;;)
1219         {
1220            printf(">");
1221            c=getchar();
1222            if (c=='q')
1223             {
1224                 QUIT=1;
1225                 printf("net_test_loopback: please wait for application shutdown and resource cleanup\n");
1226                 break;
1227            }
1228            else if (c=='s') netTest_utilsStatsCb(netapi_handle, &netcp_stats);
1229            else if (c=='h') printf("'q' to quit,  's' for stats, 'h' for help\n");
1230         }
1232         netTest_utilRemoveSpFpThreads(netTestCfg.num_sp_threads, netTestCfg.num_fp_threads);
1235 #else
1236     /*********************************************/
1237     /**************Entry point into scheduler ****/
1238     /*********************************************/
1239     //netTest_utilCreateSecAssoc(netcp_sb_rx_chan, netcp_sb_tx_chan,netcp_tx_chan);
1240     netapi_schedRun(our_sched, &err);
1241 #endif
1243     /* done */
1244     netTest_utilsStatsCb(netapi_handle, NULL);
1247     /* cleanup*/
1248      netTest_utilDeleteSecAssoc();
1250     netTest_utilDeleteInterfaces(netTestCfg.num_macs, netTestCfg.num_ips);
1252     /* close pktio channels we opened via open_pktio_tx_channels() */
1253     close_pktio_channels();
1254 #ifdef netTest_DSP_FASTPATH
1255     teardown_netTestDSPFastPath();
1256 #endif
1258     netapi_shutdown(netapi_handle);
1259     printf("net_test shutdown complete\n");
1263 #if 1
1264 /* Stub functions */
1265 Trie * route_init(void)
1268 void route_add(Trie * Pt, unsigned long * Pdest_ipBE, void * Pour_route)
1271 #endif