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