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