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 for (i = 0; i < 1; i++)
871 {
872 sprintf(&dsp_name[0],"%s%d","dsp_chan", i);
873 printf("netTest_utilCreateInterfaces: %s\n",&dsp_name[0]);
875 dsp_pktio_cfg.flags1 = PKTIO_RX;
876 dsp_pktio_cfg.flags2 = PKTIO_GLOBAL | PKTIO_PKT;
877 dsp_pktio_cfg.qnum = TEST_NWAL_BASE_REM_FP_RX_PKT_QUEUE + i;
878 dsp_pktio_cfg.max_n = 8;
880 /* pktio channels created here will NOT be POLLED by net_test arm application */
881 dsp_pktio_channels[i] = netapi_pktioCreate(handle,
882 &dsp_name[0],
883 (PKTIO_CB)recv_cb,
884 &dsp_pktio_cfg,
885 &err);
886 if (dsp_pktio_channels[i])
887 {
888 printf("setup_netTestDSPFastPath: sucess for core %d\n", i);
889 }
890 else
891 {
892 printf("setup_netTestDSPFastPath: failed for core %d\n", i);
893 }
895 dsp_classi.classType =NETCP_CFG_CLASS_TYPE_L4;
896 dsp_classi.u.c_l4.iface = netTestCfg.dsp_mac;
898 dsp_classi.u.c_l4.ip = ip_rule[netTestCfg.dsp_ip];
899 dsp_classi.u.c_l4.proto = NWAL_APP_PLOAD_PROTO_UDP;
900 dsp_classi.u.c_l4.appProto.udpPort = TEST_NWAL_BASE_REM_FP_UDP_PORT + i;
902 dsp_route.p_dest_q = dsp_pktio_channels[i];
904 dsp_route.p_flow = (NETCP_CFG_FLOW_T*)NETCP_DEFAULT_FLOW;
907 dsp_classifers[i] = netapi_netcpCfgAddClass(handle,
908 &dsp_classi,
909 (NETCP_CFG_ROUTE_HANDLE_T) &dsp_route,
910 NETCP_CFG_ACTION_TO_SW,
911 NULL,
912 &err);
914 if (err == NETAPI_ERR_OK)
915 {
916 printf("setup_netTestDSPFastPath: netapi_netcpCfgAddClass sucess for core %d\n", i);
917 }
918 else
919 {
920 printf("setup_netTestDSPFastPath: netapi_netcpCfgAddClass failed for core %d\n", i);
921 }
922 }
923 }
925 void teardown_netTestDSPFastPath()
926 {
927 int i;
928 int err=0;
930 for (i = 0; i < CPU_NUM_REM_FAST_PATH_CORES; i++)
931 {
932 netapi_netcpCfgDelClass(netapi_handle,
933 dsp_classifers[i],
934 &err);
935 if (err == NETAPI_ERR_OK)
936 {
937 printf("teardown_netTestDSPFastPath: netapi_netcpCfgDelClass sucess for core %d\n", i);
938 }
939 else
940 {
941 printf("teardown_netTestDSPFastPath: netapi_netcpCfgDelClass failed for core %d\n", i);
942 }
944 netapi_pktioDelete(dsp_pktio_channels[i],
945 &err);
946 if (err == NETAPI_ERR_OK)
947 {
948 printf("teardown_netTestDSPFastPath: netapi_pktioDelete sucess for core %d\n", i);
949 }
950 else
951 {
952 printf("teardown_netTestDSPFastPath: netapi_pktioDelete failed for core %d\n", i);
953 }
954 }
955 }
956 #endif
959 #ifdef netTest_MULTI_THREAD
960 NETAPI_T worker_nh[TUNE_NETAPI_NUM_CORES];
962 void slow_path_thread(uint32_t index)
963 {
964 int err, i;;
965 uint32_t thread_num;
966 PKTIO_HANDLE_T *rx_chan;
967 PKTIO_HANDLE_T *sb_rx_chan;
970 cpu_set_t cpu_set;
972 thread_num = netTestCfg.sp_thread_num[index];
973 printf("slow_path_thread, mypid: %d, core_id %d\n", gettid(), netTestCfg.sp_thread_num[index]);
975 CPU_ZERO( &cpu_set);
976 printf("slow_path_thread: settting up for thread number %d\n", thread_num);
977 #ifdef CORTEX_A8
978 for (i = netTestCfg.sp_proc_start[index]; i <= netTestCfg.sp_proc_end[index];i++)
979 {
980 printf("slow_path_thread: setting cpu %d to cpu_set\n", i);
981 CPU_SET( 0, &cpu_set);
982 }
983 hplib_utilSetupThread(thread_num, &cpu_set);
984 #else
985 for (i = netTestCfg.sp_proc_start[index]; i <= netTestCfg.sp_proc_end[index];i++)
986 {
987 printf("slow_path_thread: setting cpu %d to cpu_set\n", i);
988 CPU_SET( i, &cpu_set);
989 }
990 hplib_utilSetupThread(thread_num, &cpu_set);
991 #endif
992 worker_nh[thread_num]=netapi_init(NETAPI_CORE_MASTER,NULL);
994 netapi_setCookie(worker_nh[thread_num],(void*)(thread_num | NET_TEST_SP_THREAD_MASK));
996 scheduler[thread_num] =netapi_schedOpen(worker_nh[thread_num],&our_sched_cfg, &err);
997 if (!scheduler[thread_num])
998 {
999 printf("sched create failed for core%d\n",thread_num);
1000 exit(1);
1001 }
1002 scheduler[thread_num]->config.yield = TRUE;
1003 scheduler[thread_num]->config.pollGarbageQ = TRUE;
1004 scheduler[thread_num]->config.pollCtrlQ = TRUE;
1006 /* Entry point to scheduler */
1007 netapi_schedRun(scheduler[thread_num], &err);
1008 printf(">net_test: core %d worker thread done\n",thread_num);
1010 netapi_shutdown(worker_nh[thread_num]);
1011 }
1013 void fast_path_thread(uint32_t index)
1014 {
1015 int err, i;
1016 PKTIO_HANDLE_T *rx_chan;
1017 PKTIO_HANDLE_T *sb_rx_chan;
1018 uint32_t thread_num;
1021 cpu_set_t cpu_set;
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_A8
1027 for (i = netTestCfg.fp_proc_start[index]; i <= netTestCfg.fp_proc_end[index];i++)
1028 {
1029 printf("fast_path_thread: setting cpu %d to cpu_set\n", i);
1030 CPU_SET( 0, &cpu_set);
1031 }
1032 hplib_utilSetupThread(thread_num, &cpu_set);
1033 #else
1034 for (i = netTestCfg.fp_proc_start[index]; i <= netTestCfg.fp_proc_end[index];i++)
1035 {
1036 printf("fast_path_thread: start core %d, end core %d\n",
1037 netTestCfg.fp_proc_start[index],
1038 netTestCfg.fp_proc_end[index]);
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 #ifdef netTest_MULTI_THREAD
1091 cpu_set_t cpu_set;
1092 #endif
1093 /* install signal handler for ^c */
1094 signal(SIGINT,netTest_utilMySig);
1096 if (argc == 2)
1097 {
1098 printf("main: filename1 %s\n", argv[1]);
1099 fpr = fopen(argv[1], "r");
1100 }
1101 else
1102 {
1103 fpr = fopen(input_file_name, "r");
1104 }
1105 if (fpr == NULL)
1106 {
1107 printf("Cant open config file: filepath %s, %s\n", input_file_name, strerror(errno));
1108 exit(1);
1109 }
1110 else
1111 {
1112 memset(&config_file, 0, sizeof(netTestConfigFile_t));
1113 memset(&netTestCfg, 0, sizeof(netTestConfig_t));
1115 netTest_utilProcessConfigFile(fpr,&config_file);
1117 netTest_utilParseMac(&config_file);
1119 /* parse slow path/fast path thread configuration parameters */
1120 netTest_utilParseThreadParams(&config_file);
1122 netTest_utilParseIP(&config_file);
1124 netTest_utilParseIpsecMode(&config_file);
1126 /* DSP mac processing */
1127 parse_dsp_mac(&config_file.dsp_mac[0]);
1129 /* DSP IP processing */
1130 parse_dsp_ip(&config_file.dsp_ip[0]);
1132 /* IPSEC interface number processing */
1133 parse_simple_param_u32((char*)&config_file.ipsec_if_no[0], &netTestCfg.ipsec_if_no);
1135 netTest_utilParseSA(&config_file);
1137 parse_simple_param_u32(&config_file.dest_udp_port_config, &netTestCfg.dest_udp_port_config);
1138 }
1140 memset(&sa_info, 0, sizeof(sa_info));
1143 #ifdef netTest_MULTI_THREAD
1144 /* assign main net_test thread to run on core 0 */
1145 CPU_ZERO( &cpu_set);
1146 CPU_SET( 0, &cpu_set);
1147 hplib_utilSetupThread(0, &cpu_set);
1148 #endif
1150 /* create netapi */
1151 netapi_handle = netapi_init(NETAPI_SYS_MASTER, &our_netapi_default_cfg);
1153 /* configure expection packet handling with netapi */
1154 netapi_netcpCfgExceptions(netapi_handle,
1155 NETCP_CFG_ALL_EXCEPTIONS,
1156 NETCP_CFG_ACTION_DISCARD,
1157 (NETCP_CFG_ROUTE_HANDLE_T) NULL);
1158 expPkt_appid = netapi_netcpCfgExceptions(netapi_handle,
1159 7,
1160 NETCP_CFG_ACTION_TO_SW,
1161 (NETCP_CFG_ROUTE_HANDLE_T) NULL);
1163 /* open the main heap */
1164 ourHeap = Pktlib_findHeapByName("netapi");
1165 if (!ourHeap)
1166 {
1167 printf("Pktlib_findHeapByName() fail\n");
1168 exit(1);
1169 }
1171 open_pktio_tx_channels();
1173 printf("net_test: %d bytes left in our CMA area\n", netapi_getBufMemRemainder());
1174 /* create scheduler instance */
1175 our_sched =netapi_schedOpen(netapi_handle,&our_sched_cfg, &err);
1176 if (!our_sched) {printf("sched create failed\n"); exit(1);}
1179 /*create net_test MAC interfaces, attach IP to created MAC interfaces */
1180 netTest_utilCreateInterfaces(netTestCfg.num_macs, netTestCfg.num_ips);
1182 /* lookup Database for SA context, this is used by packet processing routines to get RX and TX SA information*/
1183 p_trie_sa_rx = trie_new();
1184 p_trie_sa_tx = trie_new();
1185 if (!p_trie_sa_rx || !p_trie_sa_tx)
1186 {printf("trie alloc for SA failed\n"); exit(1);}
1188 #ifdef netTest_DSP_FASTPATH
1189 setup_netTestDSPFastPath(netapi_handle);
1190 #endif
1192 /* Create RX SA's, RX Policy and TX SA's, all SA configuration parameters are read from net_test_config.txt file */
1193 netTest_utilCreateSecAssoc();
1195 #ifdef netTest_MULTI_THREAD
1196 {
1197 #if 0
1198 nwalGlobCxtInfo_t nwalGlobCxt;
1199 nwalLocCxtInfo_t nwalLocCxt;
1200 int count;
1201 NETAPI_HANDLE_T * n = (NETAPI_HANDLE_T *) netapi_handle;
1203 nwal_getGlobCxtInfo(((NETAPI_GLOBAL_T*) (n->global))->nwal_context.nwalInstHandle,&nwalGlobCxt);
1206 printf("*******NWAL Global Context Info Dump Begin *******\n");
1207 printf("rxPaSaFlowId:%d,rxSaPaFlowId:%d rxDefPktQ:0x%x \n",
1208 nwalGlobCxt.rxPaSaFlowId,nwalGlobCxt.rxSaPaFlowId,
1209 nwalGlobCxt.rxDefPktQ);
1210 printf("defFlowQ:0x%x,passCppiHandle:0x%x extErr:%d \n",
1211 nwalGlobCxt.defFlowQ,nwalGlobCxt.passCppiHandle,
1212 nwalGlobCxt.extErr);
1213 for(count=0;count < nwalGlobCxt.numPaPDSPs;count++)
1214 {
1215 printf("NetCP PASS PDSP - %d Version:0x%x \n",
1216 count,nwalGlobCxt.pdspVer[count]);
1217 }
1218 printf("*******NWAL Global Context Info Dump End *******\n\n");
1221 nwal_getLocCxtInfo(((NETAPI_GLOBAL_T*) (n->global))->nwal_context.nwalInstHandle,&nwalLocCxt);
1222 printf("*******NWAL Local Context Info Dump Begin *******\n");
1223 printf("rxCtlQ:%d,rxL4PktQ:%d \n",
1224 nwalLocCxt.rxCtlQ,
1225 nwalLocCxt.rxL4PktQ);
1226 printf("rxPktFlowId:0x%x,rxCtlFlowId:0x%x extErr:%d \n",
1227 nwalLocCxt.rxPktFlowId
1228 ,nwalLocCxt.rxCtlFlowId,
1229 nwalLocCxt.extErr);
1231 printf("*******NWAL Local Context Info Dump End *******\n\n");
1233 #endif
1235 /* create and set affinity of slow path and fast path threads to
1236 * specific CPU cores as specified in the net_test_config.txt file */
1237 netTest_utilCreateSpFpThreads(netTestCfg.num_sp_threads,
1238 (NET_TEST_FUNC_PTR) slow_path_thread,
1239 netTestCfg.num_fp_threads,
1240 (NET_TEST_FUNC_PTR) fast_path_thread);
1242 char c;
1243 //this thread of execution (main) now just waits on user input
1244 for(;;)
1245 {
1246 printf(">");
1247 c=getchar();
1248 if (c=='q') {QUIT=1;break;}
1249 else if (c=='s') netTest_utilsStatsCb(netapi_handle, &netcp_stats);
1250 else if (c=='h') printf("'q' to quit, 's' for stats, 'h' for help\n");
1251 }
1253 netTest_utilRemoveSpFpThreads(netTestCfg.num_sp_threads, netTestCfg.num_fp_threads);
1255 }
1256 #else
1257 /*********************************************/
1258 /**************Entry point into scheduler ****/
1259 /*********************************************/
1260 //netTest_utilCreateSecAssoc(netcp_sb_rx_chan, netcp_sb_tx_chan,netcp_tx_chan);
1261 netapi_schedRun(our_sched, &err);
1262 #endif
1264 /* done */
1265 netTest_utilsStatsCb(netapi_handle, NULL);
1268 /* cleanup*/
1269 netTest_utilDeleteSecAssoc();
1271 netTest_utilDeleteInterfaces(netTestCfg.num_macs, netTestCfg.num_ips);
1273 /* close pktio channels we opened via open_pktio_tx_channels() */
1274 close_pktio_channels();
1275 #ifdef netTest_DSP_FASTPATH
1276 teardown_netTestDSPFastPath();
1277 #endif
1278 netapi_shutdown(netapi_handle);
1280 }
1282 #if 1
1283 /* Stub functions */
1284 Trie * route_init(void)
1285 {
1286 }
1287 void route_add(Trie * Pt, unsigned long * Pdest_ipBE, void * Pour_route)
1288 {
1289 }
1290 #endif