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)
128 {
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};
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;
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 }
391 }
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 )
403 {
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 }
500 }
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 )
511 {
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;
529 nwalGlobCxtInfo_t nwalGlobCxt;
530 nwalLocCxtInfo_t nwalLocCxt;
532 Cppi_HostDesc* pPloadDesc;
533 int ifno;
534 uint16_t enet_port = 0;
536 #ifdef netTest_MULTI_THREAD
537 int coreid=Osal_nwalGetProcId(); //who we are(thread local)
538 #else
539 int coreid=0;
540 #endif
541 p_head=&temp_head;
543 /* loop over received pkts */
544 for(i=0;i<n_pkts;i++)
545 {
546 ifno = ((unsigned int)meta[i].u.rx_meta->appId)&0xff;
548 enet_port = meta[i].u.rx_meta->enetPort;
549 tip = p_recv[i];
551 Pktlib_getDataBuffer(tip,(uint8_t**)&p_pkt,&templen);/*ignore templen */
552 len = Pktlib_getPacketLen(tip)-4; /*real length, subtract mac trailer */
553 Cppi_setData (Cppi_DescType_HOST, (Cppi_Desc *) tip, p_pkt,len);
554 Pktlib_setPacketLen(tip,len);
556 if(((unsigned int)meta[i].u.rx_meta->appId) == expPkt_appid)
557 {
558 netapi_Log("recv_cb: received exception packet\n");
559 Pktlib_freePacket(tip);
560 if(((unsigned int)meta[i].u.rx_meta->rxFlag1 & NWAL_RX_IP_FRAGMENT_PKT) ==
561 NWAL_RX_IP_FRAGMENT_PKT)
562 {
563 stats[coreid].exceptionPktsFrag+=1;
564 }
565 else
566 {
567 stats[coreid].exceptionPktsOther+=1;
568 }
569 continue;
570 }
571 //debug: validate descriptor */
572 if(Pktlib_getNextPacket(tip) != 0)
573 {
574 printf(" rcv_cb, nexpkt != NULL");
575 }
577 if(coreid<TUNE_NETAPI_NUM_CORES)
578 stats[coreid].rx+=1;
579 if (ifno < TUNE_NETAPI_MAX_NUM_MAC)
580 stats[coreid].if_rx[ifno]+=1;
583 #ifdef DEBUG_DESC
584 if (stats[coreid].rx<16)
585 {
586 netapi_Log(">rx dmp..");
587 netTest_utilDumpDescr((long *) tip, stats[coreid].rx);
588 }
589 else if (stats[coreid].rx>99)
590 {
591 netapi_Log(">rx dmp..");
592 netTest_utilDumpDescr((long *) tip,stats[coreid].rx);
593 }
594 #endif
595 #if 0
596 //
597 if(stats[coreid].rx<=16)
598 {
599 netTest_utilDumpHeader((long*)p_pkt,stats[coreid].rx, (int)meta[i].u.rx_meta->appId,meta[i].u.rx_meta->rxFlag1);
600 netTest_utilDumpBuffer((long*)p_pkt,len);
601 }
602 #endif
603 /* check header */
604 memcpy(p_head,&p_pkt[netTest_MAC_HEADER_LEN],sizeof(netTestHead_T));
606 /* check for IPSEC ESP or AH packet, 0x32 is ESP tunnel mode, 0x33 is AH tunnel mode*/
607 if (((p_head->ip[2]&0x0000ff00)==0x00003200) || ((p_head->ip[2]&0x0000ff00)==0x00003300))
608 {
609 if (!netTest_utilCheckHeader(p_head,&meta[i]))
610 {
611 printf("recv_cb: error in ipsec pkt\n");
612 stats[coreid].n_bad+=1;Pktlib_freePacket(tip);
613 continue;
614 }
616 //process IP SEC PACKET
617 if (netTestCfg.ipsec_mode_rx == IPSEC_MODE_RX_SIDEBAND)
618 {
619 p_spi = &(p_pkt[netTest_MAC_HEADER_LEN+netTest_IP_HEADER_LEN]);
620 p_sa_info = (netTestSA_t *) trie_lookup(p_trie_sa_rx, (char *)p_spi ,4);
621 if (p_sa_info == NULL)
622 {
623 printf("recv_cb(): trie_lookup() failed\n");
624 continue;
625 }
627 //ship to crypto for decrypt!!
628 //12 byte auth tag
629 PKTIO_METADATA_T meta2 = {PKTIO_META_SB_TX,{0},0};
630 nwalDmTxPayloadInfo_t meta_tx={0};
632 meta2.sa_handle = (void*) p_sa_info->rx_tunnel;
634 memcpy(&meta_tx, &(p_sa_info->tx_payload_info), sizeof(nwalDmTxPayloadInfo_t));
636 meta_tx.encSize = len - p_sa_info->tx_payload_info.encOffset -p_sa_info->auth_tag_size;
637 meta_tx.authSize = len - meta_tx.authOffset - p_sa_info->auth_tag_size;
639 if (p_sa_info->cipherMode == NWAL_SA_EALG_AES_CTR)
640 {
641 memcpy(&p_iv[0], &p_sa_info->key_params->pEncKey[16], 4);
642 memcpy(&p_iv[4], &p_pkt[netTest_MAC_HEADER_LEN +netTest_IP_HEADER_LEN + netTest_ESP_HEADER_LEN], 8);
643 p_iv[12] = 0;
644 p_iv[13] = 0;
645 p_iv[14] = 0;
646 p_iv[15] = 1;
647 meta_tx.pEncIV = &p_iv[0];
649 }
650 else if ((p_sa_info->cipherMode == NWAL_SA_EALG_AES_GCM) ||
651 (p_sa_info->cipherMode == NWAL_SA_EALG_AES_CCM))
652 {
653 memcpy(&p_iv[0], &p_pkt[netTest_MAC_HEADER_LEN +netTest_IP_HEADER_LEN + netTest_ESP_HEADER_LEN], 8);
654 meta_tx.pEncIV = &p_iv[0];
655 /* aad is the ESP header which is 8 bytes */
656 memcpy(&p_add[0], &p_pkt[netTest_MAC_HEADER_LEN +netTest_IP_HEADER_LEN], 8);
657 meta_tx.pAad= &p_add[0];
658 meta_tx.aadSize = 8;
659 }
660 else if (p_sa_info->authMode == NWAL_SA_AALG_GMAC)
661 {
662 memcpy(&p_iv[0], &p_pkt[netTest_MAC_HEADER_LEN +netTest_IP_HEADER_LEN + netTest_ESP_HEADER_LEN], 8);
663 meta_tx.pAuthIV= &p_iv[0];
664 /* aad is the ESP header which is 8 bytes */
665 memcpy(&p_add[0], &p_pkt[netTest_MAC_HEADER_LEN +netTest_IP_HEADER_LEN], 8);
666 meta_tx.pAad= &p_add[0];
667 meta_tx.aadSize = 8;
668 }
669 else if (p_sa_info->cipherMode == NWAL_SA_EALG_NULL)
670 {
671 meta_tx.pEncIV = NULL;
672 }
673 else
674 {
675 meta_tx.pEncIV = &p_pkt[netTest_MAC_HEADER_LEN +netTest_IP_HEADER_LEN + netTest_ESP_HEADER_LEN ];
676 }
678 meta_tx.appCtxId = (nwal_AppId)p_sa_info;
680 /* post it to netcp sb tx channel*/
681 meta2.u.tx_sb_meta=&meta_tx;
683 netapi_pktioSend(netcp_sb_tx_chan,tip,&meta2,&err);
684 continue;
685 }
686 else
687 {
688 //inflow mode. flip and send
689 flip_and_send_pkt(tip,p_pkt,len,1, enet_port);
690 }
691 }
692 /* check for udp protocol */
693 else if ((p_head->ip[2]&0x0000ff00)!=0x00001100)
694 //else if ((p_head->ip[2]&0x00ff0000)!=0x00110000)
695 {
696 stats[coreid].n_new+=1;Pktlib_freePacket(tip); continue;
697 }
698 else //non ipsec
699 {
700 if (!netTest_utilCheckHeader(p_head,&meta[i]))
701 {
702 stats[coreid].n_bad+=1;Pktlib_freePacket(tip);
703 continue;
704 }
705 //just flip and send
706 flip_and_send_pkt(tip,p_pkt,len,0, enet_port);
707 }
708 }
709 }
711 /* Templates to build command labels at startup up time, required by open_pktio_tx_channels() */
712 nwalTxPktInfo_t txPktInfoESP =
713 {
714 NULL, /* p_pkt */
715 NWAL_TX_FLAG1_DO_IPSEC_ESP_CRYPTO| NWAL_TX_FLAG1_DO_UDP_CHKSUM| NWAL_TX_FLAG1_META_DATA_VALID, /* txFlags */
716 0, /* lpbackPass */
717 0, /* enetport */
718 0, /* msuSize */
719 0, /* startOffset */
720 netTest_MAC_HEADER_LEN + netTest_IP_HEADER_LEN, /* saOffBytes */
721 0, /* saPayLoadLen */
722 0 , /* saAhIcvOffBytes */
723 0, /* saAhMacSize */
724 0, /* etherLenOffBytes */
725 0, /* ipOffBytes */
726 0, /* l4OffBytes */
727 netTest_UDP_HEADER_LEN, /* l4HdrLen */
728 0, /* pseudoHdrChecksum */
729 0 /* pLoadLen */
730 };
733 nwalTxPktInfo_t txPktInfoAH =
734 {
735 NULL, /* p_pkt */
736 NWAL_TX_FLAG1_DO_IPSEC_AH_CRYPTO| NWAL_TX_FLAG1_DO_UDP_CHKSUM | NWAL_TX_FLAG1_META_DATA_VALID, /* txFlags */
737 0, /* lpbackPass */
738 0, /* enetport */
739 0, /* msuSize */
740 0, /* startOffset */
741 netTest_MAC_HEADER_LEN + netTest_IP_HEADER_LEN, /* saOffBytes */
742 0, /* saPayLoadLen */
743 netTest_MAC_HEADER_LEN + netTest_IP_HEADER_LEN + netTest_IPSEC_AH_FIXED_HDR_SIZE, /* saAhIcvOffBytes */
744 12, /* saAhMacSize */
745 0, /* etherLenOffBytes */
746 0, /* ipOffBytes */
747 0, /* l4OffBytes */
748 netTest_UDP_HEADER_LEN, /* l4HdrLen */
749 0, /* pseudoHdrChecksum */
750 0 /* pLoadLen */
751 };
753 nwalTxPktInfo_t txPktInfoNoCrypto =
754 {
755 NULL, /* p_pkt */
756 NWAL_TX_FLAG1_DO_UDP_CHKSUM| NWAL_TX_FLAG1_META_DATA_VALID, /* txFlags */
757 0, /* lpbackPass */
758 0, /* enetport */
759 0, /* msuSize */
760 0, /* startOffset */
761 0, /* saOffBytes */
762 0, /* saPayLoadLen */
763 0 , /* saAhIcvOffBytes */
764 0, /* saAhMacSize */
765 0, /* etherLenOffBytes */
766 0, /* ipOffBytes */
767 netTest_MAC_HEADER_LEN +netTest_IP_HEADER_LEN, /* l4OffBytes */
768 netTest_UDP_HEADER_LEN, /* l4HdrLen */
769 0, /* pseudoHdrChecksum */
770 0 /* pLoadLen */
771 };
774 void close_pktio_channels(void)
775 {
776 int err;
777 netapi_pktioClose(netcp_tx_chan_esp ,&err);
778 netapi_pktioClose(netcp_tx_chan_ah ,&err);
779 netapi_pktioClose(netcp_sb_tx_chan ,&err);
780 netapi_pktioClose(netcp_tx_chan_no_crypto,&err);
781 }
783 void open_pktio_tx_channels(void)
784 {
785 int err;
786 /* open netcp default TX for ESP packets */
787 netcp_tx_chan_esp= netapi_pktioOpen(netapi_handle, NETCP_TX, NULL, &netcp_tx_cfg, &err);
788 if (!netcp_tx_chan_esp)
789 {
790 printf("pktio open TX failed err=%d\n",err);
791 exit(1);
792 }
793 else
794 {
795 if(netTestCfg.ipsec_mode_tx == IPSEC_MODE_TX_INFLOW)
796 {
797 PKTIO_CONTROL_T control;
798 control.op = PKTIO_UPDATE_FAST_PATH;
799 PKTIO_CFG_T cfg;
800 cfg.fast_path_cfg.fp_send_option = PKTIO_FP_ESP_L4CKSUM_PORT;
801 cfg.fast_path_cfg.txPktInfo= &txPktInfoESP;
802 netapi_pktioControl(netcp_tx_chan_esp, NULL, &cfg, &control, &err);
803 }
804 }
806 /*/* open netcp default TX for AH packets */
807 netcp_tx_chan_ah= netapi_pktioOpen(netapi_handle, NETCP_TX, NULL, &netcp_tx_cfg, &err);
808 if (!netcp_tx_chan_ah)
809 {
810 printf("pktio open TX failed err=%d\n",err);
811 exit(1);
812 }
813 else
814 {
815 if(netTestCfg.ipsec_mode_tx == IPSEC_MODE_TX_INFLOW)
816 {
817 PKTIO_CONTROL_T control;
818 control.op = PKTIO_UPDATE_FAST_PATH;
819 PKTIO_CFG_T cfg;
820 cfg.fast_path_cfg.fp_send_option = PKTIO_FP_AH_L4CKSUM_PORT;
821 cfg.fast_path_cfg.txPktInfo= &txPktInfoAH;
822 netapi_pktioControl(netcp_tx_chan_ah, NULL, &cfg, &control, &err);
823 }
824 }
826 /* open netcp default TX channels for non-Crypto packets */
827 netcp_tx_chan_no_crypto= netapi_pktioOpen(netapi_handle, NETCP_TX, NULL, &netcp_tx_cfg, &err);
828 if (!netcp_tx_chan_no_crypto)
829 {
830 printf("pktio open TX failed err=%d\n",err);
831 exit(1);
832 }
833 else
834 {
835 if(netTestCfg.ipsec_mode_tx == IPSEC_MODE_TX_INFLOW)
836 {
837 PKTIO_CONTROL_T control;
838 control.op = PKTIO_UPDATE_FAST_PATH;
839 PKTIO_CFG_T cfg;
840 cfg.fast_path_cfg.fp_send_option = PKTIO_FP_L4CKSUM_PORT;
841 cfg.fast_path_cfg.txPktInfo= &txPktInfoNoCrypto;
842 netapi_pktioControl(netcp_tx_chan_no_crypto, NULL, &cfg, &control, &err);
843 }
844 }
846 /* open netcp default TX channels for SB crypto */
847 netcp_sb_tx_chan= netapi_pktioOpen(netapi_handle, NETCP_SB_TX, NULL, &netcp_sb_tx_cfg, &err);
848 if (!netcp_sb_tx_chan)
849 {
850 printf("pktio open SB TX failed err=%d\n",err);
851 exit(1);
852 }
853 }
855 #ifdef netTest_DSP_FASTPATH
856 void setup_netTestDSPFastPath(NETAPI_T handle)
858 {
859 int i;
860 int err = 0;
861 PKTIO_CFG_T dsp_pktio_cfg;
862 NETCP_CFG_CLASSIFIER_T dsp_classi;
863 NETCP_CFG_ROUTE_T dsp_route;
865 memset(&dsp_pktio_cfg, 0, sizeof (PKTIO_CFG_T));
866 memset(&dsp_classi, 0, sizeof (NETCP_CFG_CLASSIFIER_T));
867 memset(&dsp_route, 0, sizeof (NETCP_CFG_ROUTE_T));
868 char dsp_name[32];
869 for (i = 0; i < CPU_NUM_REM_FAST_PATH_CORES; i++)
870 {
871 sprintf(&dsp_name[0],"%s%d","dsp_chan", i);
872 dsp_pktio_cfg.flags1 = PKTIO_RX;
873 dsp_pktio_cfg.flags2 = PKTIO_GLOBAL | PKTIO_PKT;
874 dsp_pktio_cfg.qnum = TEST_NWAL_BASE_REM_FP_RX_PKT_QUEUE + i;
875 dsp_pktio_cfg.max_n = 8;
877 /* pktio channels created here will NOT be POLLED by net_test arm application */
878 dsp_pktio_channels[i] = netapi_pktioCreate(handle,
879 &dsp_name[0],
880 (PKTIO_CB)recv_cb,
881 &dsp_pktio_cfg,
882 &err);
883 if (!dsp_pktio_channels[i])
884 {
885 netapi_Log("setup_netTestDSPFastPath: failed for core %d\n", i);
886 }
888 dsp_classi.classType =NETCP_CFG_CLASS_TYPE_L4;
889 dsp_classi.u.c_l4.iface = netTestCfg.dsp_mac;
891 dsp_classi.u.c_l4.ip = ip_rule[netTestCfg.dsp_ip];
892 dsp_classi.u.c_l4.proto = NWAL_APP_PLOAD_PROTO_UDP;
893 dsp_classi.u.c_l4.appProto.udpPort = TEST_NWAL_BASE_REM_FP_UDP_PORT + i;
895 dsp_route.p_dest_q = dsp_pktio_channels[i];
897 dsp_route.p_flow = (NETCP_CFG_FLOW_T*)NETCP_DEFAULT_FLOW;
899 dsp_classifers[i] = netapi_netcpCfgAddClass(handle,
900 &dsp_classi,
901 (NETCP_CFG_ROUTE_HANDLE_T) &dsp_route,
902 NETCP_CFG_ACTION_TO_SW,
903 NULL,
904 &err);
906 if (err != NETAPI_ERR_OK)
907 {
908 netapi_Log("setup_netTestDSPFastPath: netapi_netcpCfgAddClass failed for core %d\n", i);
909 }
910 }
911 printf("DSP Path fath setup complete\n");
912 }
914 void teardown_netTestDSPFastPath()
915 {
916 int i;
917 int err=0;
919 for (i = 0; i < CPU_NUM_REM_FAST_PATH_CORES; i++)
920 {
921 netapi_netcpCfgDelClass(netapi_handle,
922 dsp_classifers[i],
923 &err);
924 if (err != NETAPI_ERR_OK)
925 {
926 printf("teardown_netTestDSPFastPath: netapi_netcpCfgDelClass failed for core %d\n", i);
927 }
929 netapi_pktioDelete(dsp_pktio_channels[i],
930 &err);
931 if (err != NETAPI_ERR_OK)
932 {
933 printf("teardown_netTestDSPFastPath: netapi_pktioDelete failed for core %d\n", i);
934 }
935 }
936 printf("DSP Path fath teardown complete\n");
937 }
938 #endif
941 #ifdef netTest_MULTI_THREAD
942 NETAPI_T worker_nh[TUNE_NETAPI_NUM_CORES];
944 void slow_path_thread(uint32_t index)
945 {
946 int err, i;;
947 uint32_t thread_num;
948 PKTIO_HANDLE_T *rx_chan;
949 PKTIO_HANDLE_T *sb_rx_chan;
952 cpu_set_t cpu_set;
954 thread_num = netTestCfg.sp_thread_num[index];
955 netapi_Log("slow_path_thread, mypid: %d, core_id %d\n", gettid(), netTestCfg.sp_thread_num[index]);
957 CPU_ZERO( &cpu_set);
958 #ifdef CORTEX_A8
959 for (i = netTestCfg.sp_proc_start[index]; i <= netTestCfg.sp_proc_end[index];i++)
960 {
961 printf("slow_path_thread: setting cpu %d to cpu_set\n", i);
962 CPU_SET( 0, &cpu_set);
963 }
964 hplib_utilSetupThread(thread_num, &cpu_set);
965 #else
966 for (i = netTestCfg.sp_proc_start[index]; i <= netTestCfg.sp_proc_end[index];i++)
967 {
968 printf("slow_path_thread: setting cpu %d to cpu_set\n", i);
969 CPU_SET( i, &cpu_set);
970 }
971 hplib_utilSetupThread(thread_num, &cpu_set);
972 #endif
973 worker_nh[thread_num]=netapi_init(NETAPI_CORE_MASTER,NULL);
975 netapi_setCookie(worker_nh[thread_num],(void*)(thread_num | NET_TEST_SP_THREAD_MASK));
977 scheduler[thread_num] =netapi_schedOpen(worker_nh[thread_num],&our_sched_cfg, &err);
978 if (!scheduler[thread_num])
979 {
980 printf("sched create failed for core%d\n",thread_num);
981 exit(1);
982 }
983 scheduler[thread_num]->config.yield = TRUE;
984 scheduler[thread_num]->config.pollGarbageQ = TRUE;
985 scheduler[thread_num]->config.pollCtrlQ = TRUE;
986 printf("Slow Path thread: %d setup complete, running on ARM CORE: %d\n", i,i);
987 /* Entry point to scheduler */
988 netapi_schedRun(scheduler[thread_num], &err);
990 netapi_shutdown(worker_nh[thread_num]);
991 }
993 void fast_path_thread(uint32_t index)
994 {
995 int err, i;
996 PKTIO_HANDLE_T *rx_chan;
997 PKTIO_HANDLE_T *sb_rx_chan;
998 uint32_t thread_num;
1001 cpu_set_t cpu_set;
1003 CPU_ZERO( &cpu_set);
1004 thread_num = netTestCfg.fp_thread_num[index];
1005 #ifdef CORTEX_A8
1006 for (i = netTestCfg.fp_proc_start[index]; i <= netTestCfg.fp_proc_end[index];i++)
1007 {
1008 CPU_SET( 0, &cpu_set);
1009 }
1010 hplib_utilSetupThread(thread_num, &cpu_set);
1011 #else
1012 for (i = netTestCfg.fp_proc_start[index]; i <= netTestCfg.fp_proc_end[index];i++)
1013 {
1014 netapi_Log("fast_path_thread: start core %d, end core %d\n",
1015 netTestCfg.fp_proc_start[index],
1016 netTestCfg.fp_proc_end[index]);
1017 netapi_Log("fast_path_thread: setting cpu %d to cpu_set\n", i);
1018 CPU_SET( i, &cpu_set);
1019 }
1020 hplib_utilSetupThread(thread_num, &cpu_set);
1021 #endif
1022 worker_nh[thread_num]=netapi_init(NETAPI_CORE_MASTER,NULL);
1024 /* open netcp default RX channels*/
1025 rx_chan = netapi_pktioOpen(worker_nh[thread_num], NETCP_RX, (PKTIO_CB) recv_cb, &netcp_rx_cfg, &err);
1027 /* create a pktio channel for specially classified pkts */
1028 /* open netcp default tx, rx queues for sideband crypto */
1029 //sb_tx_chan = netapi_pktioOpen(worker_nh[thread_num], NETCP_SB_TX, NULL, &netcp_sb_tx_cfg, &err);
1030 sb_rx_chan = netapi_pktioOpen(worker_nh[thread_num], NETCP_SB_RX, (PKTIO_CB) recv_sb_cb, &netcp_sb_rx_cfg, &err);
1032 netapi_setCookie(worker_nh[thread_num],(void*)thread_num);
1034 scheduler[thread_num] =netapi_schedOpen(worker_nh[thread_num],&our_sched_cfg, &err);
1035 if (!scheduler[thread_num])
1036 {
1037 printf("sched create failed for core%d\n",thread_num);
1038 exit(1);
1039 }
1042 scheduler[thread_num]->config.yield = FALSE;
1043 scheduler[thread_num]->config.pollGarbageQ = FALSE;
1044 scheduler[thread_num]->config.pollCtrlQ = FALSE;
1045 //sleep(100000);
1046 /* Entry point to scheduler */
1047 printf("Fast Path thread: %d setup complete, running on ARM CORE: %d\n", i,i);
1048 netapi_schedRun(scheduler[thread_num], &err);
1049 netapi_pktioClose(rx_chan, &err);
1051 netapi_pktioClose(sb_rx_chan, &err);
1052 netapi_shutdown(worker_nh[thread_num]);
1053 }
1055 #endif
1056 /***************************************
1057 ********** test driver*****************
1058 ***************************************/
1059 int main(int argc, char **argv)
1060 {
1061 int err,i;
1062 Pktlib_HeapCfg heapCfg;
1063 int32_t errCode;
1064 Pktlib_HeapIfTable* pPktifTable;
1065 FILE * fpr = NULL;
1067 #ifdef netTest_MULTI_THREAD
1068 cpu_set_t cpu_set;
1069 #endif
1070 /* install signal handler for ^c */
1071 signal(SIGINT,netTest_utilMySig);
1073 if (argc == 2)
1074 {
1075 printf("main: filename1 %s\n", argv[1]);
1076 fpr = fopen(argv[1], "r");
1077 }
1078 else
1079 {
1080 fpr = fopen(input_file_name, "r");
1081 }
1082 if (fpr == NULL)
1083 {
1084 printf("Cant open config file: filepath %s, %s\n", input_file_name, strerror(errno));
1085 exit(1);
1086 }
1087 else
1088 {
1089 memset(&config_file, 0, sizeof(netTestConfigFile_t));
1090 memset(&netTestCfg, 0, sizeof(netTestConfig_t));
1092 netTest_utilProcessConfigFile(fpr,&config_file);
1094 netTest_utilParseMac(&config_file);
1096 /* parse slow path/fast path thread configuration parameters */
1097 netTest_utilParseThreadParams(&config_file);
1099 netTest_utilParseIP(&config_file);
1101 netTest_utilParseIpsecMode(&config_file);
1103 /* DSP mac processing */
1104 parse_dsp_mac(&config_file.dsp_mac[0]);
1106 /* DSP IP processing */
1107 parse_dsp_ip(&config_file.dsp_ip[0]);
1109 /* IPSEC interface number processing */
1110 parse_simple_param_u32((char*)&config_file.ipsec_if_no[0], &netTestCfg.ipsec_if_no);
1112 netTest_utilParseSA(&config_file);
1114 parse_simple_param_u32(&config_file.dest_udp_port_config, &netTestCfg.dest_udp_port_config);
1115 }
1117 memset(&sa_info, 0, sizeof(sa_info));
1120 #ifdef netTest_MULTI_THREAD
1121 /* assign main net_test thread to run on core 0 */
1122 CPU_ZERO( &cpu_set);
1123 CPU_SET( 0, &cpu_set);
1124 hplib_utilSetupThread(0, &cpu_set);
1125 #endif
1127 /* create netapi */
1128 netapi_handle = netapi_init(NETAPI_SYS_MASTER, &our_netapi_default_cfg);
1130 /* configure expection packet handling with netapi */
1131 netapi_netcpCfgExceptions(netapi_handle,
1132 NETCP_CFG_ALL_EXCEPTIONS,
1133 NETCP_CFG_ACTION_DISCARD,
1134 (NETCP_CFG_ROUTE_HANDLE_T) NULL);
1135 expPkt_appid = netapi_netcpCfgExceptions(netapi_handle,
1136 7,
1137 NETCP_CFG_ACTION_TO_SW,
1138 (NETCP_CFG_ROUTE_HANDLE_T) NULL);
1140 /* open the main heap */
1141 ourHeap = Pktlib_findHeapByName("netapi");
1142 if (!ourHeap)
1143 {
1144 printf("Pktlib_findHeapByName() fail\n");
1145 exit(1);
1146 }
1148 open_pktio_tx_channels();
1150 /* create scheduler instance */
1151 our_sched =netapi_schedOpen(netapi_handle,&our_sched_cfg, &err);
1152 if (!our_sched) {printf("sched create failed\n"); exit(1);}
1155 /*create net_test MAC interfaces, attach IP to created MAC interfaces */
1156 netTest_utilCreateInterfaces(netTestCfg.num_macs, netTestCfg.num_ips);
1158 /* lookup Database for SA context, this is used by packet processing routines to get RX and TX SA information*/
1159 p_trie_sa_rx = trie_new();
1160 p_trie_sa_tx = trie_new();
1161 if (!p_trie_sa_rx || !p_trie_sa_tx)
1162 {
1163 printf("trie alloc for SA failed\n");
1164 exit(1);
1165 }
1167 #ifdef netTest_DSP_FASTPATH
1168 setup_netTestDSPFastPath(netapi_handle);
1169 #endif
1171 /* Create RX SA's, RX Policy and TX SA's, all SA configuration parameters are read from net_test_config.txt file */
1172 netTest_utilCreateSecAssoc();
1174 #ifdef netTest_MULTI_THREAD
1175 {
1176 /* create and set affinity of slow path and fast path threads to
1177 * specific CPU cores as specified in the net_test_config.txt file */
1178 netTest_utilCreateSpFpThreads(netTestCfg.num_sp_threads,
1179 (NET_TEST_FUNC_PTR) slow_path_thread,
1180 netTestCfg.num_fp_threads,
1181 (NET_TEST_FUNC_PTR) fast_path_thread);
1183 printf("\n net_test_loopback running ....\n");
1184 printf("\n Enter 's' for stats or 'q'to quit net_test_loopback app, or 'h' for help\n");
1186 char c;
1187 //this thread of execution (main) now just waits on user input
1188 for(;;)
1189 {
1190 printf(">");
1191 c=getchar();
1192 if (c=='q')
1193 {
1194 QUIT=1;
1195 printf("net_test_loopback: please wait for application shutdown and resource cleanup\n");
1196 break;
1197 }
1198 else if (c=='s') netTest_utilsStatsCb(netapi_handle, &netcp_stats);
1199 else if (c=='h') printf("'q' to quit, 's' for stats, 'h' for help\n");
1200 }
1202 netTest_utilRemoveSpFpThreads(netTestCfg.num_sp_threads, netTestCfg.num_fp_threads);
1204 }
1205 #else
1206 /*********************************************/
1207 /**************Entry point into scheduler ****/
1208 /*********************************************/
1209 //netTest_utilCreateSecAssoc(netcp_sb_rx_chan, netcp_sb_tx_chan,netcp_tx_chan);
1210 netapi_schedRun(our_sched, &err);
1211 #endif
1213 /* done */
1214 netTest_utilsStatsCb(netapi_handle, NULL);
1217 /* cleanup*/
1218 netTest_utilDeleteSecAssoc();
1220 netTest_utilDeleteInterfaces(netTestCfg.num_macs, netTestCfg.num_ips);
1222 /* close pktio channels we opened via open_pktio_tx_channels() */
1223 close_pktio_channels();
1224 #ifdef netTest_DSP_FASTPATH
1225 teardown_netTestDSPFastPath();
1226 #endif
1228 netapi_shutdown(netapi_handle);
1229 printf("net_test shutdown complete\n");
1231 }
1233 #if 1
1234 /* Stub functions */
1235 Trie * route_init(void)
1236 {
1237 }
1238 void route_add(Trie * Pt, unsigned long * Pdest_ipBE, void * Pour_route)
1239 {
1240 }
1241 #endif