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