1 /******************************************************************************
2 * File: net_test_router.c
3 * Purpose: net_test_router application
4 ******************************************************************************
5 * FILE: net_test_router.c
6 *
7 * DESCRIPTION: netapi user space transport
8 * library net_test_router 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 "trie.h"
46 #include <signal.h>
47 #include <pthread.h>
48 #include <sys/resource.h>
49 #include "router.h"
50 extern int QUIT;
52 /* Global definitions */
54 netTestConfig_t netTestCfg;
55 static netTestConfigFile_t config_file;
57 char input_file_name[] = "net_test_config.txt";
59 nwal_RetValue nwalRetVal;
60 Pktlib_HeapHandle ourHeap;
62 PKTIO_HANDLE_T *netcp_tx_chan_no_crypto;
63 PKTIO_HANDLE_T *netcp_rx_chan;
64 PKTIO_HANDLE_T *netcp_tx_chan_esp;
65 PKTIO_HANDLE_T *netcp_tx_chan_ah;
70 PKTIO_CFG_T netcp_rx_cfg={PKTIO_RX, PKTIO_NA, PKTIO_NA, 8};
71 PKTIO_CFG_T netcp_tx_cfg={PKTIO_TX, PKTIO_NA, PKTIO_NA, 8};
75 NETCP_CFG_EXCEPTION_PKT_T expPkt_appid;
77 Trie *p_trie_sa_rx;
78 Trie *p_trie_sa_tx;
81 #include "router.c"
82 Trie * our_router;
84 OUR_ROUTE_T routes[MAX_ROUTES]=
86 {
87 {0,{0xD4,0xbe,0xd9,0x00,0xd3,0x7e, 0x00,0x01,0x02,0x03,0x14,0x02,0x08,0x00},0},
88 {0,{0x00,0x00,0x0,0x00,0x0,0x0, 0x00,0x00,0x00,0x00,0x00,0x00,0x08,0x00},0},
89 {0,{0xD4,0xbe,0xd9,0x00,0xd3,0x7e, 0x00,0x01,0x02,0x03,0x14,0x02,0x08,0x00},0},
90 {0,{0x00,0x15,0x60,0xa1,0xf7,0xbe, 0x00,0x01,0x02,0x03,0x04,0x05,0x08,0x00},0},
91 {0,{0xd4,0xbe,0xd9,0x00,0xd3,0x7e, 0x00,0x01,0x02,0x03,0x04,0x05,0x08,0x00},0}
92 };
93 unsigned int ip[MAX_ROUTES]={BE(0x0a0100c8),BE(0x0a00000a),BE(0x0a02000a),BE(0xc0a8010a),BE(0x9eda6719)};
95 void recv_cb_router(struct PKTIO_HANDLE_Tag * channel, Ti_Pkt* p_recv[],
96 PKTIO_METADATA_T meta[], int n_pkts,
97 uint64_t ts );
100 extern netTestStats_T stats[TUNE_NETAPI_NUM_CORES];
101 extern paSysStats_t netcp_stats;
103 /*******************************************
104 *************NETAPI OBJECTS***************
105 *****************************************/
106 static NETAPI_CFG_T our_netapi_default_cfg=
107 {
108 TUNE_NETAPI_PERM_MEM_SZ,
109 128, //start of packet offset for hw to place data on rx for default flow
110 TUNE_NETAPI_QM_CONFIG_MAX_DESC_NUM, //max number of descriptors in system
111 TUNE_NETAPI_NUM_GLOBAL_DESC, //total we will use
112 TUNE_NETAPI_DEFAULT_NUM_BUFFERS, //#descriptors+buffers in default heap
113 64, //#descriptors w/o buffers in default heap
114 TUNE_NETAPI_DEFAULT_BUFFER_SIZE+128+128, //size of buffers in default heap
115 128 , //tail room
116 256 //extra room
117 };
121 void house(NETAPI_SCHED_HANDLE_T *s);
122 NETAPI_T netapi_handle;
123 NETAPI_SCHED_HANDLE_T * our_sched;
124 #ifdef netTest_MULTI_THREAD
125 NETAPI_SCHED_HANDLE_T * scheduler[TUNE_NETAPI_NUM_CORES];
126 #endif
127 NETAPI_SCHED_CONFIG_T our_sched_cfg={
128 NETAPI_SCHED_DURATION|NETAPI_SCHED_CBV, 0, house, 5000000 //every 5000000 poll loops
129 };
132 NETCP_CFG_IP_T ip_rule[NET_TEST_MAX_IP];
133 NETCP_CFG_MACIF_T mac[NET_TEST_MAX_MAC];
137 /* security objects. (for loopback mode) */
138 netTestSA_t sa_info[MAX_SEC_INDEX];
141 NETCP_CFG_IPSEC_POLICY_T rx_policy[MAX_SEC_INDEX];
146 /*************************END NETAPI OBJECTS***********************/
148 void update_header(netTestHead_T * p_head, int len)
149 {
150 unsigned char *p = (unsigned char *) &p_head->udp[1];
151 len -= (20+14);
152 /* update ip checksum */
153 /* update udp checksum */
154 /* update length */
155 *p= (len&0xff00)>>8;
156 *(p+1) = len&0xff;
157 }
159 #ifdef netTest_MULTI_THREAD
160 /* Templates to build command labels at startup up time, required by open_pktio_tx_channels() */
161 nwalTxPktInfo_t txPktInfoESP =
162 {
163 NULL, /* p_pkt */
164 NWAL_TX_FLAG1_DO_IPSEC_ESP_CRYPTO| NWAL_TX_FLAG1_DO_IPV4_CHKSUM| NWAL_TX_FLAG1_META_DATA_VALID, /* txFlags */
165 0, /* lpbackPass */
166 1, /* enetport */
167 0, /* msuSize */
168 0, /* startOffset */
169 netTest_MAC_HEADER_LEN + netTest_IP_HEADER_LEN, /* saOffBytes */
170 0, /* saPayLoadLen */
171 0 , /* saAhIcvOffBytes */
172 0, /* saAhMacSize */
173 0, /* etherLenOffBytes */
174 netTest_MAC_HEADER_LEN, /* ipOffBytes */
175 0, /* l4OffBytes */
176 0, /* l4HdrLen */
177 0, /* pseudoHdrChecksum */
178 0 /* pLoadLen */
179 };
182 nwalTxPktInfo_t txPktInfoAH =
183 {
184 NULL, /* p_pkt */
185 NWAL_TX_FLAG1_DO_IPSEC_AH_CRYPTO| NWAL_TX_FLAG1_DO_IPV4_CHKSUM | NWAL_TX_FLAG1_META_DATA_VALID, /* txFlags */
186 0, /* lpbackPass */
187 0, /* enetport */
188 0, /* msuSize */
189 0, /* startOffset */
190 netTest_MAC_HEADER_LEN + netTest_IP_HEADER_LEN, /* saOffBytes */
191 0, /* saPayLoadLen */
192 netTest_MAC_HEADER_LEN + netTest_IP_HEADER_LEN + netTest_IPSEC_AH_FIXED_HDR_SIZE, /* saAhIcvOffBytes */
193 12, /* saAhMacSize */
194 0, /* etherLenOffBytes */
195 netTest_MAC_HEADER_LEN, /* ipOffBytes */
196 0, /* l4OffBytes */
197 netTest_UDP_HEADER_LEN, /* l4HdrLen */
198 0, /* pseudoHdrChecksum */
199 0 /* pLoadLen */
200 };
202 nwalTxPktInfo_t txPktInfoNoCrypto =
203 {
204 NULL, /* p_pkt */
205 NWAL_TX_FLAG1_DO_IPV4_CHKSUM| NWAL_TX_FLAG1_META_DATA_VALID, /* txFlags */
206 0, /* lpbackPass */
207 0, /* enetport */
208 0, /* msuSize */
209 0, /* startOffset */
210 0, /* saOffBytes */
211 0, /* saPayLoadLen */
212 0 , /* saAhIcvOffBytes */
213 0, /* saAhMacSize */
214 0, /* etherLenOffBytes */
215 netTest_MAC_HEADER_LEN, /* ipOffBytes */
216 netTest_MAC_HEADER_LEN +netTest_IP_HEADER_LEN, /* l4OffBytes */
217 netTest_UDP_HEADER_LEN, /* l4HdrLen */
218 0, /* pseudoHdrChecksum */
219 0 /* pLoadLen */
220 };
222 void close_pktio_channels(void)
223 {
224 int err;
225 netapi_pktioClose(netcp_tx_chan_no_crypto ,&err);
226 netapi_pktioClose(netcp_tx_chan_esp ,&err);
227 netapi_pktioClose(netcp_tx_chan_ah ,&err);
228 }
232 void open_pktio_tx_channels()
233 {
234 int err;
235 /* open netcp default TX channels */
236 netcp_tx_chan_no_crypto= netapi_pktioOpen(netapi_handle, NETCP_TX, NULL, &netcp_tx_cfg, &err);
237 if (!netcp_tx_chan_no_crypto)
238 {
239 netapi_Log("pktio open TX failed err=%d\n",err);
240 exit(1);
241 }
242 else
243 {
244 if(netTestCfg.ipsec_mode_tx == IPSEC_MODE_TX_INFLOW)
245 {
246 PKTIO_CONTROL_T control;
247 control.op = PKTIO_UPDATE_FAST_PATH;
248 PKTIO_CFG_T cfg;
249 cfg.fast_path_cfg.fp_send_option = PKTIO_FP_NO_CRYPTO_NO_CKSUM_PORT;
250 cfg.fast_path_cfg.txPktInfo= &txPktInfoNoCrypto;
251 //netapi_pktioControl(netcp_tx_chan_no_crypto, NULL, &cfg, &control, &err);
252 }
253 }
254 /* open netcp default TX for ESP packets */
255 netcp_tx_chan_esp= netapi_pktioOpen(netapi_handle, NETCP_TX, NULL, &netcp_tx_cfg, &err);
256 if (!netcp_tx_chan_esp)
257 {
258 netapi_Log("pktio open TX failed err=%d\n",err);
259 exit(1);
260 }
261 else
262 {
263 if(netTestCfg.ipsec_mode_tx == IPSEC_MODE_TX_INFLOW)
264 {
265 PKTIO_CONTROL_T control;
266 control.op = PKTIO_UPDATE_FAST_PATH;
267 PKTIO_CFG_T cfg;
268 cfg.fast_path_cfg.fp_send_option = PKTIO_FP_ESP_PORT;
269 cfg.fast_path_cfg.txPktInfo= &txPktInfoESP;
270 //netapi_pktioControl(netcp_tx_chan_esp, NULL, &cfg, &control, &err);
271 }
272 }
274 /*/* open netcp default TX for AH packets */
275 netcp_tx_chan_ah= netapi_pktioOpen(netapi_handle, NETCP_TX, NULL, &netcp_tx_cfg, &err);
276 if (!netcp_tx_chan_ah)
277 {
278 netapi_Log("pktio open TX failed err=%d\n",err);
279 exit(1);
280 }
281 else
282 {
283 if(netTestCfg.ipsec_mode_tx == IPSEC_MODE_TX_INFLOW)
284 {
285 PKTIO_CONTROL_T control;
286 control.op = PKTIO_UPDATE_FAST_PATH;
287 PKTIO_CFG_T cfg;
288 cfg.fast_path_cfg.fp_send_option = PKTIO_FP_AH_PORT;
289 cfg.fast_path_cfg.txPktInfo= &txPktInfoAH;
290 //netapi_pktioControl(netcp_tx_chan_ah, NULL, &cfg, &control, &err);
291 }
292 }
293 }
298 NETAPI_T worker_nh[TUNE_NETAPI_NUM_CORES];
299 void slow_path_thread(uint32_t index)
300 {
301 int err,i;
302 uint32_t thread_num;
303 PKTIO_HANDLE_T *rx_chan;
304 PKTIO_HANDLE_T *sb_tx_chan;
305 PKTIO_HANDLE_T *sb_rx_chan;
306 cpu_set_t cpu_set;
308 thread_num = netTestCfg.sp_thread_num[index];
309 printf("slow_path_thread for index %d called for thread %d\n", index, thread_num);
311 CPU_ZERO( &cpu_set);
312 #ifdef CORTEX_A15
313 for (i = netTestCfg.sp_proc_start[index]; i <= netTestCfg.sp_proc_end[index];i++)
314 {
315 printf("slow_path_thread: setting cpu %d to cpu_set\n", i);
316 CPU_SET( i, &cpu_set);
317 }
318 hplib_utilSetupThread(thread_num, &cpu_set);
319 #else
320 for (i = netTestCfg.sp_proc_start[index]; i <= netTestCfg.sp_proc_end[index];i++)
321 {
322 printf("slow_path_thread: setting cpu %d to cpu_set\n", i);
323 CPU_SET( i, &cpu_set);
324 }
325 hplib_utilSetupThread(thread_num, &cpu_set);
326 #endif
327 worker_nh[thread_num]=netapi_init(NETAPI_CORE_MASTER,NULL);
329 NETAPI_HANDLE_T * n = (NETAPI_HANDLE_T *) worker_nh[thread_num];
331 /* open netcp RX channel */
332 //rx_chan = netapi_pktioOpen(worker_nh[thread_num], NETCP_RX, (PKTIO_CB) recv_cb_router, &netcp_rx_cfg, &err);
336 netapi_setCookie(worker_nh[thread_num],(void*) (thread_num | NET_TEST_SP_THREAD_MASK));
338 scheduler[thread_num] =netapi_schedOpen(worker_nh[thread_num],&our_sched_cfg, &err);
339 if (!scheduler[thread_num])
340 {
341 netapi_Log("sched create failed for core%d\n",thread_num);
342 exit(1);
343 }
344 scheduler[thread_num]->config.yield = FALSE;
345 scheduler[thread_num]->config.pollGarbageQ = TRUE;
346 scheduler[thread_num]->config.pollCtrlQ = TRUE;
347 /*********************************************/
348 /**************Entry point into scheduler ****/
349 /*********************************************/
350 netapi_schedRun(scheduler[thread_num], &err);
351 netapi_Log("slow_path_thread: core %d worker thread done\n",thread_num);
353 //netapi_pktioClose(rx_chan, &err);
354 netapi_shutdown(worker_nh[thread_num]);
355 }
358 void fast_path_thread(uint32_t index)
359 {
360 int err,i;
361 uint32_t thread_num;
362 PKTIO_HANDLE_T *rx_chan;
363 PKTIO_HANDLE_T *sb_tx_chan;
365 cpu_set_t cpu_set;
367 thread_num = netTestCfg.fp_thread_num[index];
368 printf("fast_path_thread for index %d called for thread %d\n", index, thread_num);
369 CPU_ZERO( &cpu_set);
370 #ifdef CORTEX_A15
371 for (i = netTestCfg.fp_proc_start[index]; i <= netTestCfg.fp_proc_end[index];i++)
372 {
373 printf("fast_path_thread: setting cpu %d to cpu_set\n", i);
374 CPU_SET( i, &cpu_set);
375 }
376 hplib_utilSetupThread(thread_num, &cpu_set);
377 #else
378 for (i = netTestCfg.fp_proc_start[index]; i <= netTestCfg.fp_proc_end[index];i++)
379 {
380 printf("fast_path_thread: setting cpu %d to cpu_set\n", i);
381 CPU_SET( i, &cpu_set);
382 }
383 hplib_utilSetupThread(thread_num, &cpu_set);
384 #endif
385 worker_nh[thread_num]=netapi_init(NETAPI_CORE_MASTER,NULL);
387 NETAPI_HANDLE_T * n = (NETAPI_HANDLE_T *) worker_nh[thread_num];
389 /* open netcp RX channel */
390 rx_chan = netapi_pktioOpen(worker_nh[thread_num], NETCP_RX, (PKTIO_CB) recv_cb_router, &netcp_rx_cfg, &err);
391 netapi_setCookie(worker_nh[thread_num],(void*)thread_num);
393 scheduler[thread_num] =netapi_schedOpen(worker_nh[thread_num],&our_sched_cfg, &err);
394 if (!scheduler[thread_num])
395 {
396 netapi_Log("sched create failed for core%d\n",thread_num);
397 exit(1);
398 }
400 /*********************************************/
401 /**************Entry point into scheduler ****/
402 /*********************************************/
403 scheduler[thread_num]->config.yield = FALSE;
404 scheduler[thread_num]->config.pollGarbageQ = FALSE;
405 scheduler[thread_num]->config.pollCtrlQ = FALSE;
406 //sleep(100000);
407 netapi_schedRun(scheduler[thread_num], &err);
408 netapi_Log("fast_path_thread: core %d worker thread done\n",thread_num);
410 netapi_pktioClose(rx_chan, &err);
411 netapi_shutdown(worker_nh[thread_num]);
412 }
413 #endif
415 /***************************************
416 ********** test driver*****************
417 ***************************************/
418 int main(int argc, char **argv)
419 {
420 int err,i;
421 Pktlib_HeapCfg heapCfg;
422 int32_t errCode;
423 Pktlib_HeapIfTable* pPktifTable;
424 FILE * fpr = NULL;
426 cpu_set_t cpu_set;
427 /* install signal handler for ^c */
428 signal(SIGINT,netTest_utilMySig);
430 if (argc == 2)
431 {
432 fpr = fopen(argv[1], "r");
433 }
434 else
435 {
436 fpr = fopen(input_file_name, "r");
437 }
438 if (fpr == NULL)
439 {
440 exit(1);
441 }
442 else
443 {
444 memset(&config_file, 0, sizeof(netTestConfigFile_t));
445 memset(&netTestCfg, 0, sizeof(netTestConfig_t));
446 netTest_utilProcessConfigFile(fpr,&config_file);
447 netTest_utilParseMac(&config_file);
449 /* parse slow path/fast path thread configuration parameters */
450 netTest_utilParseThreadParams(&config_file);
452 netTest_utilParseIP(&config_file);
454 netTest_utilParseIpsecMode(&config_file);
456 /* DSP mac processing */
457 parse_dsp_mac(&config_file.dsp_mac[0]);
459 /* DSP IP processing */
460 parse_dsp_ip(&config_file.dsp_ip[0]);
462 netTest_utilParseRoutes(&config_file, &routes[0], &our_router);
464 /* IPSEC interface number processing */
465 parse_simple_param_u32((char*)&config_file.ipsec_if_no[0], &netTestCfg.ipsec_if_no);
467 netTest_utilParseSA(&config_file);
468 }
470 memset(&sa_info, 0, sizeof(sa_info));
472 #ifdef netTest_MULTI_THREAD
473 /* assign main net_test thread to run on core 0 */
474 CPU_ZERO( &cpu_set);
475 CPU_SET( 0, &cpu_set);
476 hplib_utilSetupThread(0, &cpu_set);
477 #endif
478 /* create netapi */
479 netapi_handle = netapi_init(NETAPI_SYS_MASTER, &our_netapi_default_cfg);
481 /* configure expection packet handling with netapi */
482 netapi_netcpCfgExceptions(netapi_handle, NETCP_CFG_ALL_EXCEPTIONS, NETCP_CFG_ACTION_DISCARD, (NETCP_CFG_ROUTE_HANDLE_T) NULL);
483 expPkt_appid = netapi_netcpCfgExceptions(netapi_handle, 7, NETCP_CFG_ACTION_TO_SW, (NETCP_CFG_ROUTE_HANDLE_T) NULL);
485 /* open the main heap */
486 ourHeap = Pktlib_findHeapByName("netapi");
487 if (!ourHeap)
488 {
489 netapi_Log("Pktlib_findHeapByName() fail\n");
490 exit(1);
491 }
493 /* Open all required PKTIO TX channels */
494 open_pktio_tx_channels();
496 netapi_Log("net_test> %d bytes left in our CMA area\n", netapi_getBufMemRemainder());
497 /* create scheduler instance */
498 our_sched =netapi_schedOpen(netapi_handle,&our_sched_cfg, &err);
499 if (!our_sched) {netapi_Log("sched create failed\n"); exit(1);}
502 /*create net_test MAC interfaces, attach IP to created MAC interfaces */
503 netTest_utilCreateInterfaces(netTestCfg.num_macs, netTestCfg.num_ips);
505 /* Lookup Database for SA context, this is used by packet processing routines to get RX and TX SA information*/
506 p_trie_sa_rx = trie_new();
507 p_trie_sa_tx = trie_new();
508 if (!p_trie_sa_rx || !p_trie_sa_tx)
509 {netapi_Log("trie alloc for SA failed\n"); exit(1);}
511 /* Create RX SA's, RX Policy and TX SA's, all SA configuration parameters are read from net_test_config.txt file */
512 netTest_utilCreateSecAssoc();
515 #ifdef netTest_MULTI_THREAD
516 {
517 char c;
518 /* create and set affinity of slow path and fast path threads to
519 * specific CPU cores as specified in the net_test_config.txt file */
520 netTest_utilCreateSpFpThreads(netTestCfg.num_sp_threads,
521 (NET_TEST_FUNC_PTR) slow_path_thread,
522 netTestCfg.num_fp_threads,
523 (NET_TEST_FUNC_PTR) fast_path_thread);
525 //this thread of execution (main) now just waits on user input
526 for(;;)
527 {
528 printf(">");
529 c=getchar();
530 if (c=='q') {QUIT=1;break;}
531 else if (c=='s') netTest_utilsStatsCb(netapi_handle, &netcp_stats);
532 else if (c=='h') printf("'q' to quit, 's' for stats, 'h' for help\n");
533 }
534 netTest_utilRemoveSpFpThreads(netTestCfg.num_sp_threads, netTestCfg.num_fp_threads);
535 }
536 #else
537 /*********************************************/
538 /**************Entry point into scheduler ****/
539 /*********************************************/
540 netapi_schedRun(our_sched, &err);
541 #endif
543 /* done */
544 netTest_utilsStatsCb(netapi_handle, NULL);
548 /* cleanup*/
549 netTest_utilDeleteSecAssoc();
550 netTest_utilDeleteInterfaces(netTestCfg.num_macs, netTestCfg.num_ips);
552 /* close pktio channels we opened via open_pktio_tx_channels() */
553 close_pktio_channels();
554 netapi_shutdown(netapi_handle);
555 }
557 static inline void send_it(Ti_Pkt *tip, int len, netTestSA_t * p_sec, int out_port)
558 {
559 unsigned long st1;
560 unsigned long st2;
561 int err=0;
562 PKTIO_METADATA_T meta2 = {PKTIO_META_TX,{0},0};
563 nwalTxPktInfo_t meta_tx2={0};
564 st1=hplib_mUtilGetPmuCCNT();
565 #ifdef netTest_MULTI_THREAD
566 int coreid=Osal_nwalGetProcId(); //who we are(thread local)
567 //int coreid = our_core;
568 #else
569 int coreid=0;
570 #endif
571 if (len<60)
572 {
573 unsigned int templen;
574 char * p_pkt;
575 len=60;
576 Pktlib_getDataBuffer(tip,(uint8_t**)&p_pkt,&templen);//ignore templen
577 Cppi_setData (Cppi_DescType_HOST, (Cppi_Desc *) tip, p_pkt,len);
578 stats[coreid].tx_min+=1;
579 }
580 Pktlib_setPacketLen(tip,len);
581 meta_tx2.txFlag1 = (NWAL_TX_FLAG1_DO_IPV4_CHKSUM| NWAL_TX_FLAG1_META_DATA_VALID );
582 meta_tx2.startOffset = 0;
583 meta_tx2.ipOffBytes = netTest_MAC_HEADER_LEN;
584 meta_tx2.ploadLen = len ;
585 meta_tx2.enetPort=out_port;
586 if(p_sec)
587 {
588 meta_tx2.txFlag1 |= NWAL_TX_FLAG1_DO_IPSEC_ESP_CRYPTO ;
589 //meta2.sa_handle = (void*)p_sec->tx_tunnel;
590 meta2.sa_handle=p_sec->tx_inflow_mode_handle;
591 meta_tx2.saOffBytes=netTest_MAC_HEADER_LEN + netTest_IP_HEADER_LEN;
592 meta_tx2.saPayloadLen=len-netTest_MAC_HEADER_LEN - netTest_IP_HEADER_LEN; //don't include tag, mac and outer header
593 meta2.u.tx_meta=&meta_tx2;
594 netapi_pktioSend(netcp_tx_chan_esp,tip,&meta2,&err);
595 stats[coreid].sec_tx+=1;
596 }
597 else
598 {
599 meta2.u.tx_meta=&meta_tx2;
600 netapi_pktioSend(netcp_tx_chan_no_crypto,tip,&meta2,&err);
602 }
603 stats[coreid].tx +=1;
604 st2=hplib_mUtilGetPmuCCNT();
605 stats[coreid].send_cycles += (unsigned long long) (st2-st1);
606 }
607 void recv_cb_router(struct PKTIO_HANDLE_Tag * channel, Ti_Pkt* p_recv[],
608 PKTIO_METADATA_T meta[], int n_pkts,
609 uint64_t ts )
610 {
611 int i;
612 int len;
613 int p;
614 Ti_Pkt * tip;
615 unsigned int templen;
616 char * p_pkt;
617 netTestHead_T temp_head;
618 unsigned int appid;
619 IP_netTestHead_T th;
620 netTestSA_t *sec_data=NULL;
621 unsigned long t1;
622 unsigned long t2;
623 unsigned long long ct1;
624 unsigned long long ct2;
625 unsigned short ip_pl;
626 unsigned long long n_c_ops;
627 int ifno;
628 int out_port;
629 #ifdef netTest_MULTI_THREAD
630 int coreid=Osal_nwalGetProcId(); //who we are(thread local)
631 //int coreid = our_core;
632 #else
633 int coreid=0;
634 #endif
635 t1=hplib_mUtilGetPmuCCNT();
636 ct1 =Osal_cache_op_measure(&n_c_ops);
637 for(i=0;i<n_pkts;i++)
638 {
639 ifno = ((unsigned int)meta[i].u.rx_meta->appId)&0xff;
640 if(coreid<TUNE_NETAPI_NUM_CORES) stats[coreid].rx+=1;
641 if (ifno < TUNE_NETAPI_MAX_NUM_MAC) stats[coreid].if_rx[ifno]+=1;
642 tip = p_recv[i];
643 Pktlib_getDataBuffer(tip,(uint8_t**)&p_pkt,&templen);//ignore templen
644 len = Pktlib_getPacketLen(tip)-4;//real length, subtract mac trailer
645 stats[coreid].rx+=1;
646 appid = ((unsigned int)meta[i].u.rx_meta->appId)&0xff000000;
647 switch(appid)
648 {
649 case(NETAPI_NETCP_MATCH_IPSEC):
650 case(NETAPI_NETCP_MATCH_IPSEC_POLICY):
651 {
652 int tailen=12+2;
653 memcpy(&temp_head,&p_pkt[14],sizeof(netTestHead_T));
654 if (!netTest_utilCheckHeader(&temp_head,&meta[i])) {
655 stats[coreid].n_bad+=1;
656 Pktlib_freePacket(tip);
657 continue;
658 }
659 tailen+=p_pkt[len-12-2]; //padding length (12)should come from sec_ptr
660 p_pkt = &p_pkt[8+16+20]; //16= iv len, should come from sec_ptr
661 len -= (8+16+20+tailen); //16= iv len should come from sec ptr
663 //now check inner headder.
664 memcpy(&th,&p_pkt[14],20);
665 if (!netTest_utilCheckHeader(&temp_head,&meta[i])) {
666 stats[coreid].n_bad+=1;
667 Pktlib_freePacket(tip);
668 continue;
669 }
670 Cppi_setData (Cppi_DescType_HOST, (Cppi_Desc *) tip, p_pkt,len);
671 Pktlib_setPacketLen(tip,len);
673 if (route_pkt(our_router, tip, &th, p_pkt, &len,&sec_data,&out_port)<0)
674 {
675 stats[coreid].n_bad+=1;
676 Pktlib_freePacket(tip);
677 }
678 else
679 {
680 send_it(tip,len,sec_data,out_port);
681 }
682 break;
683 }
684 case(NETAPI_NETCP_MATCH_GENERIC_MAC):
685 if((p_pkt[12]!=0x8)||(p_pkt[13]!=0x00))
686 {
687 stats[coreid].n_new+=1;
688 Pktlib_freePacket(tip);
689 continue;
690 }
691 if (!netTest_utilCheckHeader(&temp_head,&meta[i]))
692 {
693 stats[coreid].n_bad+=1;
694 Pktlib_freePacket(tip);
695 continue;
696 }
697 memcpy(&th,&p_pkt[14],20);
698 ip_pl= (((unsigned char *)&th.w1)[2]<<8) | ((unsigned char *)&th.w1)[3];
699 if ((ip_pl+14)<60)
700 {
701 len-= (60-(ip_pl+14));
702 stats[coreid].rx_min+=1;
703 }
704 Pktlib_setPacketLen(tip,len);
705 if (route_pkt(our_router, tip, &th, p_pkt, &len,&sec_data,&out_port)<0)
706 {
707 stats[coreid].n_bad+=1;
708 Pktlib_freePacket(tip);
709 }
710 else
711 {
712 send_it(tip,len,sec_data,out_port);
713 }
714 break;
715 case(NETAPI_NETCP_MATCH_GENERIC_IP):
716 Pktlib_freePacket(tip);
717 stats[coreid].n_new=1;
718 break;
719 default:
720 stats[coreid].n_new+=1;
721 Pktlib_freePacket(tip);
722 break;
723 }
724 }
725 t2=hplib_mUtilGetPmuCCNT();
726 ct2 =Osal_cache_op_measure(&n_c_ops);
727 stats[coreid].app_cycles += (unsigned long long) (t2-t1);
728 stats[coreid].tx_cache_cycles += (unsigned long long) (ct2-ct1);
729 return;
730 }
732 /* STUB functions required for compilation */
733 void recv_cb(struct PKTIO_HANDLE_Tag * channel, Ti_Pkt* p_recv[],
734 PKTIO_METADATA_T meta[], int n_pkts,
735 uint64_t ts )
736 {
737 }
739 void recv_sb_cb(struct PKTIO_HANDLE_Tag * channel, Ti_Pkt* p_recv[],
740 PKTIO_METADATA_T meta[], int n_pkts,
741 uint64_t ts )
742 {
743 }