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 if (stats[coreid].sec_tx<20) netTest_utilDumpDescr((long *) tip, stats[coreid].sec_tx);
367 if ( pkt_type == netTest_IPSEC_ESP_PKT)
368 netapi_pktioSend(netcp_tx_chan_esp,tip,&meta,&err);
369 else if ( pkt_type == netTest_IPSEC_AH_PKT)
370 netapi_pktioSend(netcp_tx_chan_ah,tip,&meta,&err);
371 stats[coreid].tx +=1;
372 stats[coreid].sec_tx +=1;
373 }
374 }
375 else //non ipsec send pkt directly, asking for IP and UDP checksum ofload
376 {
377 PKTIO_METADATA_T meta2 = {PKTIO_META_TX,{0},0};
378 int err;
379 nwalTxPktInfo_t meta_tx2={0};
380 meta2.sa_handle=nwal_HANDLE_INVALID;
381 meta_tx2.txFlag1 = (NWAL_TX_FLAG1_DO_UDP_CHKSUM| NWAL_TX_FLAG1_META_DATA_VALID );
382 meta_tx2.startOffset = 0;
383 meta_tx2.ipOffBytes = netTest_MAC_HEADER_LEN;
384 meta_tx2.l4OffBytes = netTest_MAC_HEADER_LEN +netTest_IP_HEADER_LEN;
385 meta_tx2.l4HdrLen = netTest_UDP_HEADER_LEN;
386 meta_tx2.ploadLen = (unsigned) ((p_pkt[netTest_MAC_HEADER_LEN+netTest_IP_HEADER_LEN+4]<<8)|
387 p_pkt[netTest_MAC_HEADER_LEN+netTest_IP_HEADER_LEN+4+1]) -8 ;
388 meta_tx2.pseudoHdrChecksum =
389 netTest_utilGetIPv4PsudoChkSum(&p_pkt[netTest_MAC_HEADER_LEN],8+ meta_tx2.ploadLen);
391 /* post it to netcp tx channel*/
392 meta2.u.tx_meta=&meta_tx2;
393 netapi_pktioSend(netcp_tx_chan_no_crypto,tip,&meta2,&err);
394 stats[coreid].tx +=1;
395 }
396 }
399 /**********************************************************************
400 * FUNCTION PURPOSE: Sideband Accelerator Callback PKT RECEIVE HANDLER
401 **********************************************************************
402 * DESCRIPTION: Sideband Accelerator Callback PKT RECEIVE HANDLER
403 * Handles Decrypt and Encrypt operation callbacks
404 **********************************************************************/
405 void recv_sb_cb(struct PKTIO_HANDLE_Tag * channel, Ti_Pkt* p_recv[],
406 PKTIO_METADATA_T meta[], int n_pkts,
407 uint64_t ts )
408 {
409 int i;
410 int len;
411 int p;
412 netTestHead_T * p_res;
413 Ti_Pkt * tip;
414 unsigned int templen;
415 int err;
416 char * p_pkt;
417 netTestHead_T * p_head;
418 netTestHead_T temp_head;
419 int tag_cmp=0;
420 unsigned int hash[4];
421 uint8_t *p_spi;
422 netTestSA_t *p_sa_info;
424 #ifdef netTest_MULTI_THREAD
425 int coreid=Osal_nwalGetProcId(); //who we are(thread local)
426 #else
427 int coreid=0;
428 #endif
429 //nwal_AppId time;
430 unsigned long time, delta_time;
431 /* loop over received pkts */
432 for(i=0;i<n_pkts;i++)
433 {
434 tip = p_recv[i];
435 Pktlib_getDataBuffer(tip,(uint8_t**)&p_pkt,&templen);//ignore templen
436 len = Pktlib_getPacketLen(tip);//real length
438 /*p_sa_info is for rx context */
439 p_sa_info = (netTestSA_t*)meta[i].u.rx_sb_meta->appCtxId;
440 if (p_sa_info == NULL)
441 {
442 printf("recv_sb_cb(): trie_lookup failed\n");
443 continue;
444 }
446 //is this a decrypt (rx_tunnel) complete
447 if ((int)meta[i].u.rx_sb_meta->appId == p_sa_info->rx_tunnel)
448 {
449 //time = hplib_mUtilGetPmuCCNT();
450 //delta_time = time -(unsigned long) meta[i].u.rx_sb_meta->appCtxId;
451 stats[coreid].total_decrypt_time += delta_time;
452 stats[coreid].sb_rx+=1;
453 //copy hash out of meta data (for some reason it needs endian conversion)
454 hash[0]= netTest_utilHtonl( meta[i].u.rx_sb_meta->pAuthTag[0]);
455 hash[1]= netTest_utilHtonl( meta[i].u.rx_sb_meta->pAuthTag[1]);
456 hash[2]= netTest_utilHtonl( meta[i].u.rx_sb_meta->pAuthTag[2]);
457 hash[3]= netTest_utilHtonl( meta[i].u.rx_sb_meta->pAuthTag[3]);
458 if(stats[coreid].sb_rx<=16)
459 {
460 char *tp = (char *) &hash[0];
461 //netTest_utilDumpHeader((long*)p_pkt, stats[coreid].sb_rx, (int)meta[i].u.rx_sb_meta->appId,0);
462 }
463 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
464 stats[coreid].n_auth_ok += !(tag_cmp);
465 flip_and_send_pkt(tip, p_pkt, len,1, 0); //flip packet to echo back and send
466 }
467 //this is an encrypt (tx tunnel) complete
468 else if((int)meta[i].u.rx_sb_meta->appId== p_sa_info->tx_tunnel )
469 {
470 hash[0]= netTest_utilHtonl( meta[i].u.rx_sb_meta->pAuthTag[0]);
471 hash[1]= netTest_utilHtonl( meta[i].u.rx_sb_meta->pAuthTag[1]);
472 hash[2]= netTest_utilHtonl( meta[i].u.rx_sb_meta->pAuthTag[2]);
473 hash[3]= netTest_utilHtonl( meta[i].u.rx_sb_meta->pAuthTag[3]);
474 stats[coreid].sb_tx+=1;
475 if(stats[coreid].sb_tx<=16)
476 {
477 //netTest_utilDumpHeader((long*)p_pkt, stats[coreid].sb_tx, (int)meta[i].u.rx_sb_meta->appId,0);
478 }
479 //put the computed tag in the packet
480 memcpy(&p_pkt[len-p_sa_info->auth_tag_size],(char*)&hash[0],p_sa_info->auth_tag_size); //todo, really use meta->authTagLen
481 {
482 PKTIO_METADATA_T meta2 = {PKTIO_META_TX,{0},0};
483 nwalTxPktInfo_t meta_tx={0};
484 // now send directly
485 meta2.sa_handle=nwal_HANDLE_INVALID;
486 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
487 meta_tx.startOffset = 0;
488 meta_tx.ipOffBytes = netTest_MAC_HEADER_LEN;
489 meta_tx.l4OffBytes = 0;
490 meta_tx.l4HdrLen = 0;
491 meta_tx.ploadLen = 0;
492 time = hplib_mUtilGetPmuCCNT();
493 delta_time = time -(unsigned long) meta[i].u.rx_sb_meta->appCtxId;
494 stats[coreid].total_encrypt_time += delta_time;
496 /* post it to netcp tx channel*/
497 meta2.u.tx_meta=&meta_tx;
498 netapi_pktioSend(netcp_tx_chan_esp,tip,&meta2,&err);
499 hplib_cacheWbInv(p_pkt,len);
500 stats[coreid].tx +=1;
501 }
502 }
503 else printf("netapi recv_sb_cb: unknown appiD %x \n",meta[i].u.rx_sb_meta->appId );
504 }
505 }
507 /**********************************************************************
508 * FUNCTION PURPOSE: Packet receive Callback
509 *
510 **********************************************************************
511 * DESCRIPTION: packet Receive callback
512 **********************************************************************/
513 void recv_cb(struct PKTIO_HANDLE_Tag * channel, Ti_Pkt* p_recv[],
514 PKTIO_METADATA_T meta[], int n_pkts,
515 uint64_t ts )
516 {
517 int i;
518 int len;
519 int p;
520 netTestHead_T * p_res;
521 Ti_Pkt * tip;
522 unsigned int templen;
523 int err = 0;
524 char * p_pkt;
525 netTestHead_T * p_head;
526 netTestHead_T temp_head;
527 netTestSA_t *p_sa_info;
528 uint8_t *p_spi;
529 uint8_t p_iv[16];
530 uint8_t p_add[8];
531 uint8_t p_add1[1500];
532 int16_t retVal;
534 nwalGlobCxtInfo_t nwalGlobCxt;
535 nwalLocCxtInfo_t nwalLocCxt;
537 Cppi_HostDesc* pPloadDesc;
538 int ifno;
539 uint16_t enet_port = 0;
541 #ifdef netTest_MULTI_THREAD
542 int coreid=Osal_nwalGetProcId(); //who we are(thread local)
543 //int coreid = our_core;
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 thread_num)
969 {
970 int err, i;;
972 PKTIO_HANDLE_T *rx_chan;
973 PKTIO_HANDLE_T *sb_rx_chan;
975 printf("slow_path_thread, mypid: %d, core_id %d\n", gettid(), thread_num);
977 CPU_ZERO( &cpu_set);
978 printf("slow_path_thread: settting up for thread number %d\n", thread_num);
979 #ifdef CORTEX_A15
980 for (i = netTestCfg.sp_proc_start[thread_num]; i <= netTestCfg.sp_proc_end[thread_num];i++)
981 {
982 printf("slow_path_thread: setting cpu %d to cpu_set\n", i);
983 CPU_SET( i, &cpu_set);
984 }
985 hplib_utilSetupCore(thread_num, &cpu_set);
986 #else
987 for (i = netTestCfg.sp_proc_start[thread_num]; i <= netTestCfg.sp_proc_end[thread_num];i++)
988 {
989 printf("slow_path_thread: setting cpu %d to cpu_set\n", i);
990 CPU_SET( i, &cpu_set);
991 }
992 hplib_utilSetupCore(thread_num, &cpu_set);
993 #endif
994 worker_nh[thread_num]=netapi_init(NETAPI_CORE_MASTER,NULL);
996 netapi_setCookie(worker_nh[thread_num],(void*)(thread_num | NET_TEST_SP_THREAD_MASK));
998 scheduler[thread_num] =netapi_schedOpen(worker_nh[thread_num],&our_sched_cfg, &err);
999 if (!scheduler[thread_num])
1000 {
1001 printf("sched create failed for core%d\n",thread_num);
1002 exit(1);
1003 }
1004 scheduler[thread_num]->config.yield = TRUE;
1005 scheduler[thread_num]->config.pollGarbageQ = TRUE;
1006 scheduler[thread_num]->config.pollCtrlQ = TRUE;
1008 /* Entry point to scheduler */
1009 netapi_schedRun(scheduler[thread_num], &err);
1010 printf(">net_test: core %d worker thread done\n",thread_num);
1012 netapi_shutdown(worker_nh[thread_num]);
1013 }
1015 void fast_path_thread(uint32_t thread_num)
1016 {
1017 int err, i;
1018 PKTIO_HANDLE_T *rx_chan;
1019 PKTIO_HANDLE_T *sb_rx_chan;
1021 CPU_ZERO( &cpu_set);
1022 printf("fast_path_thread: settting up for thread number %d\n", thread_num);
1023 #ifdef CORTEX_A15
1024 for (i = netTestCfg.fp_proc_start[thread_num]; i <= netTestCfg.fp_proc_end[thread_num];i++)
1025 {
1026 printf("fast_path_thread: setting cpu %d to cpu_set\n", i);
1027 CPU_SET( i, &cpu_set);
1028 }
1029 hplib_utilSetupCore(thread_num, &cpu_set);
1030 #else
1031 for (i = netTestCfg.fp_proc_start[thread_num]; i <= netTestCfg.fp_proc_end[thread_num];i++)
1032 {
1033 printf("fast_path_thread: setting cpu %d to cpu_set\n", i);
1034 CPU_SET( i, &cpu_set);
1035 }
1036 hplib_utilSetupCore(thread_num, &cpu_set);
1037 #endif
1038 worker_nh[thread_num]=netapi_init(NETAPI_CORE_MASTER,NULL);
1040 /* open netcp default RX channels*/
1041 rx_chan = netapi_pktioOpen(worker_nh[thread_num], NETCP_RX, (PKTIO_CB) recv_cb, &netcp_rx_cfg, &err);
1043 /* create a pktio channel for specially classified pkts */
1044 /* open netcp default tx, rx queues for sideband crypto */
1045 //sb_tx_chan = netapi_pktioOpen(worker_nh[thread_num], NETCP_SB_TX, NULL, &netcp_sb_tx_cfg, &err);
1046 sb_rx_chan = netapi_pktioOpen(worker_nh[thread_num], NETCP_SB_RX, (PKTIO_CB) recv_sb_cb, &netcp_sb_rx_cfg, &err);
1048 netapi_setCookie(worker_nh[thread_num],(void*)thread_num);
1050 scheduler[thread_num] =netapi_schedOpen(worker_nh[thread_num],&our_sched_cfg, &err);
1051 if (!scheduler[thread_num])
1052 {
1053 printf("sched create failed for core%d\n",thread_num);
1054 exit(1);
1055 }
1058 scheduler[thread_num]->config.yield = FALSE;
1059 scheduler[thread_num]->config.pollGarbageQ = FALSE;
1060 scheduler[thread_num]->config.pollCtrlQ = FALSE;
1061 //sleep(100000);
1062 /* Entry point to scheduler */
1063 netapi_schedRun(scheduler[thread_num], &err);
1064 printf(">net_test: core %d worker thread done\n",thread_num);
1066 netapi_pktioClose(rx_chan, &err);
1068 netapi_pktioClose(sb_rx_chan, &err);
1069 netapi_shutdown(worker_nh[thread_num]);
1070 }
1072 #endif
1073 /***************************************
1074 ********** test driver*****************
1075 ***************************************/
1076 int main(int argc, char **argv)
1077 {
1078 int err,i;
1079 Pktlib_HeapCfg heapCfg;
1080 int32_t errCode;
1081 Pktlib_HeapIfTable* pPktifTable;
1082 FILE * fpr = NULL;
1084 /* install signal handler for ^c */
1085 signal(SIGINT,netTest_utilMySig);
1087 if (argc == 2)
1088 {
1089 printf("main: filename1 %s\n", argv[1]);
1090 fpr = fopen(argv[1], "r");
1091 }
1092 else
1093 {
1094 fpr = fopen(input_file_name, "r");
1095 }
1096 if (fpr == NULL)
1097 {
1098 exit(1);
1099 }
1100 else
1101 {
1102 memset(&config_file, 0, sizeof(netTestConfigFile_t));
1103 memset(&netTestCfg, 0, sizeof(netTestConfig_t));
1105 netTest_utilProcessConfigFile(fpr,&config_file);
1107 netTest_utilParseMac(&config_file);
1109 /* parse slow path/fast path thread configuration parameters */
1110 netTest_utilParseThreadParams(&config_file);
1112 netTest_utilParseIP(&config_file);
1114 netTest_utilParseIpsecMode(&config_file);
1116 /* DSP mac processing */
1117 parse_dsp_mac(&config_file.dsp_mac[0]);
1119 /* DSP IP processing */
1120 parse_dsp_ip(&config_file.dsp_ip[0]);
1122 /* IPSEC interface number processing */
1123 parse_simple_param_u32((char*)&config_file.ipsec_if_no[0], &netTestCfg.ipsec_if_no);
1125 netTest_utilParseSA(&config_file);
1127 parse_simple_param_u32(&config_file.dest_udp_port_config, &netTestCfg.dest_udp_port_config);
1128 }
1130 memset(&sa_info, 0, sizeof(sa_info));
1133 #ifdef netTest_MULTI_THREAD
1134 /* assign main net_test thread to run on core 0 */
1135 CPU_ZERO( &cpu_set);
1136 CPU_SET( 0, &cpu_set);
1137 hplib_utilSetupCore(0, &cpu_set);
1138 #endif
1140 /* create netapi */
1141 netapi_handle = netapi_init(NETAPI_SYS_MASTER, &our_netapi_default_cfg);
1143 /* configure expection packet handling with netapi */
1144 netapi_netcpCfgExceptions(netapi_handle,
1145 NETCP_CFG_ALL_EXCEPTIONS,
1146 NETCP_CFG_ACTION_DISCARD,
1147 (NETCP_CFG_ROUTE_HANDLE_T) NULL);
1148 expPkt_appid = netapi_netcpCfgExceptions(netapi_handle,
1149 7,
1150 NETCP_CFG_ACTION_TO_SW,
1151 (NETCP_CFG_ROUTE_HANDLE_T) NULL);
1153 /* open the main heap */
1154 ourHeap = Pktlib_findHeapByName("netapi");
1155 if (!ourHeap)
1156 {
1157 printf("Pktlib_findHeapByName() fail\n");
1158 exit(1);
1159 }
1161 open_pktio_tx_channels();
1163 printf("net_test: %d bytes left in our CMA area\n", netapi_getBufMemRemainder());
1164 /* create scheduler instance */
1165 our_sched =netapi_schedOpen(netapi_handle,&our_sched_cfg, &err);
1166 if (!our_sched) {printf("sched create failed\n"); exit(1);}
1169 /*create net_test MAC interfaces, attach IP to created MAC interfaces */
1170 netTest_utilCreateInterfaces(netTestCfg.num_macs, netTestCfg.num_ips);
1172 /* lookup Database for SA context, this is used by packet processing routines to get RX and TX SA information*/
1173 p_trie_sa_rx = trie_new();
1174 p_trie_sa_tx = trie_new();
1175 if (!p_trie_sa_rx || !p_trie_sa_tx)
1176 {printf("trie alloc for SA failed\n"); exit(1);}
1178 #ifdef netTest_DSP_FASTPATH
1179 setup_netTestDSPFastPath(netapi_handle);
1180 #endif
1182 /* Create RX SA's, RX Policy and TX SA's, all SA configuration parameters are read from net_test_config.txt file */
1183 netTest_utilCreateSecAssoc();
1185 #ifdef netTest_MULTI_THREAD
1186 {
1187 #if 0
1188 nwalGlobCxtInfo_t nwalGlobCxt;
1189 nwalLocCxtInfo_t nwalLocCxt;
1190 int count;
1191 NETAPI_HANDLE_T * n = (NETAPI_HANDLE_T *) netapi_handle;
1193 nwal_getGlobCxtInfo(((NETAPI_GLOBAL_T*) (n->global))->nwal_context.nwalInstHandle,&nwalGlobCxt);
1196 printf("*******NWAL Global Context Info Dump Begin *******\n");
1197 printf("rxPaSaFlowId:%d,rxSaPaFlowId:%d rxDefPktQ:0x%x \n",
1198 nwalGlobCxt.rxPaSaFlowId,nwalGlobCxt.rxSaPaFlowId,
1199 nwalGlobCxt.rxDefPktQ);
1200 printf("defFlowQ:0x%x,passCppiHandle:0x%x extErr:%d \n",
1201 nwalGlobCxt.defFlowQ,nwalGlobCxt.passCppiHandle,
1202 nwalGlobCxt.extErr);
1203 for(count=0;count < nwalGlobCxt.numPaPDSPs;count++)
1204 {
1205 printf("NetCP PASS PDSP - %d Version:0x%x \n",
1206 count,nwalGlobCxt.pdspVer[count]);
1207 }
1208 printf("*******NWAL Global Context Info Dump End *******\n\n");
1211 nwal_getLocCxtInfo(((NETAPI_GLOBAL_T*) (n->global))->nwal_context.nwalInstHandle,&nwalLocCxt);
1212 printf("*******NWAL Local Context Info Dump Begin *******\n");
1213 printf("rxCtlQ:%d,rxL4PktQ:%d \n",
1214 nwalLocCxt.rxCtlQ,
1215 nwalLocCxt.rxL4PktQ);
1216 printf("rxPktFlowId:0x%x,rxCtlFlowId:0x%x extErr:%d \n",
1217 nwalLocCxt.rxPktFlowId
1218 ,nwalLocCxt.rxCtlFlowId,
1219 nwalLocCxt.extErr);
1221 printf("*******NWAL Local Context Info Dump End *******\n\n");
1223 #endif
1225 /* create and set affinity of slow path and fast path threads to
1226 * specific CPU cores as specified in the net_test_config.txt file */
1227 netTest_utilCreateSpFpThreads(netTestCfg.num_sp_threads,
1228 (NET_TEST_FUNC_PTR) slow_path_thread,
1229 netTestCfg.num_fp_threads,
1230 (NET_TEST_FUNC_PTR) fast_path_thread);
1232 char c;
1233 //this thread of execution (main) now just waits on user input
1234 for(;;)
1235 {
1236 printf(">");
1237 c=getchar();
1238 if (c=='q') {QUIT=1;break;}
1239 else if (c=='s') netTest_utilsStatsCb(netapi_handle, &netcp_stats);
1240 else if (c=='h') printf("'q' to quit, 's' for stats, 'h' for help\n");
1241 }
1243 netTest_utilRemoveSpFpThreads(netTestCfg.num_sp_threads, netTestCfg.num_fp_threads);
1245 }
1246 #else
1247 /*********************************************/
1248 /**************Entry point into scheduler ****/
1249 /*********************************************/
1250 //netTest_utilCreateSecAssoc(netcp_sb_rx_chan, netcp_sb_tx_chan,netcp_tx_chan);
1251 netapi_schedRun(our_sched, &err);
1252 #endif
1254 /* done */
1255 netTest_utilsStatsCb(netapi_handle, NULL);
1258 /* cleanup*/
1259 netTest_utilDeleteSecAssoc();
1261 netTest_utilDeleteInterfaces(netTestCfg.num_macs, netTestCfg.num_ips);
1263 /* close pktio channels we opened via open_pktio_tx_channels() */
1264 close_pktio_channels();
1265 #ifdef netTest_DSP_FASTPATH
1266 teardown_netTestDSPFastPath();
1267 #endif
1268 netapi_shutdown(netapi_handle);
1270 }
1272 #if 1
1273 /* Stub functions */
1274 Trie * route_init(void)
1275 {
1276 }
1277 void route_add(Trie * Pt, unsigned long * Pdest_ipBE, void * Pour_route)
1278 {
1279 }
1280 #endif