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