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: rev 0.0.1
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 <stdio.h>
45 #include <stdlib.h>
46 #include <unistd.h>
47 #include <string.h>
48 #include <signal.h>
49 #include <pthread.h>
51 #include "net_test.h"
52 #include "trie.h"
53 #include "string.h"
55 #include <sys/resource.h>
57 #include <ti/drv/sa/salld.h>
58 #include <ti/drv/pa/pa.h>
60 #include "net_test_utils.h"
62 extern int QUIT;
64 /* Global definitions */
65 #ifdef MULTI_THREAD
66 cpu_set_t cpu_set;
67 #endif
69 netTestConfig_t netTestCfg;
70 static netTestConfigFile_t config_file;
72 char input_file_name[] = "net_test_config.txt";
74 nwal_RetValue nwalRetVal;
75 Pktlib_HeapHandle ourHeap;
77 PKTIO_HANDLE_T *netcp_tx_chan_no_crypto;
78 PKTIO_HANDLE_T *netcp_rx_chan;
79 PKTIO_HANDLE_T *netcp_tx_chan_esp;
80 PKTIO_HANDLE_T *netcp_tx_chan_ah;
85 PKTIO_CFG_T netcp_rx_cfg={PKTIO_RX, PKTIO_NA, PKTIO_NA, 8};
86 PKTIO_CFG_T netcp_tx_cfg={PKTIO_TX, PKTIO_NA, PKTIO_NA, 8};
90 NETCP_CFG_EXCEPTION_PKT_T expPkt_appid;
92 Trie *p_trie_sa_rx;
93 Trie *p_trie_sa_tx;
96 #include "router.c"
97 extern Trie * our_router;
98 extern OUR_ROUTE_T routes[];
100 unsigned int ip[MAX_ROUTES]={BE(0x0a0100c8),BE(0x0a00000a),BE(0x0a02000a),BE(0xc0a8010a),BE(0x9eda6719)};
102 void recv_cb_router(struct PKTIO_HANDLE_Tag * channel, Ti_Pkt* p_recv[],
103 PKTIO_METADATA_T meta[], int n_pkts,
104 uint64_t ts );
107 extern STATS_T stats[TUNE_NETAPI_NUM_CORES];
108 extern paSysStats_t netcp_stats;
110 /*******************************************
111 *************NETAPI OBJECTS***************
112 *****************************************/
113 static NETAPI_CFG_T our_netapi_default_cfg=
114 {
115 TUNE_NETAPI_PERM_MEM_SZ,
116 128, //start of packet offset for hw to place data on rx for default flow
117 TUNE_NETAPI_QM_CONFIG_MAX_DESC_NUM, //max number of descriptors in system
118 TUNE_NETAPI_NUM_GLOBAL_DESC, //total we will use
119 TUNE_NETAPI_DEFAULT_NUM_BUFFERS, //#descriptors+buffers in default heap
120 64, //#descriptors w/o buffers in default heap
121 TUNE_NETAPI_DEFAULT_BUFFER_SIZE+128+128, //size of buffers in default heap
122 128 , //tail room
123 256 //extra room
124 };
128 void house(NETAPI_SCHED_HANDLE_T *s);
129 NETAPI_T netapi_handle;
130 NETAPI_SCHED_HANDLE_T * our_sched;
131 #ifdef MULTI_THREAD
132 NETAPI_SCHED_HANDLE_T * scheduler[TUNE_NETAPI_NUM_CORES];
133 #endif
134 NETAPI_SCHED_CONFIG_T our_sched_cfg={
135 NETAPI_SCHED_DURATION|NETAPI_SCHED_CBV, 0, house, 5000000 //every 5000000 poll loops
136 };
139 NETCP_CFG_IP_T ip_rule0;
140 NETCP_CFG_IP_T ip_rule1;
144 /* security objects. (for loopback mode) */
145 netTestSA_t sa_info[MAX_SEC_INDEX];
148 NETCP_CFG_IPSEC_POLICY_T rx_policy[MAX_SEC_INDEX];
153 /*************************END NETAPI OBJECTS***********************/
155 void update_header(HEAD_T * p_head, int len)
156 {
157 unsigned char *p = (unsigned char *) &p_head->udp[1];
158 len -= (20+14);
159 /* update ip checksum */
160 /* update udp checksum */
161 /* update length */
162 *p= (len&0xff00)>>8;
163 *(p+1) = len&0xff;
164 }
166 #ifdef MULTI_THREAD
167 /* Templates to build command labels at startup up time, required by open_pktio_tx_channels() */
168 nwalTxPktInfo_t txPktInfoESP =
169 {
170 NULL, /* p_pkt */
171 NWAL_TX_FLAG1_DO_IPSEC_ESP_CRYPTO| NWAL_TX_FLAG1_DO_IPV4_CHKSUM| NWAL_TX_FLAG1_META_DATA_VALID, /* txFlags */
172 0, /* lpbackPass */
173 0, /* enetport */
174 0, /* msuSize */
175 0, /* startOffset */
176 netTest_MAC_HEADER_LEN + netTest_IP_HEADER_LEN, /* saOffBytes */
177 0, /* saPayLoadLen */
178 0 , /* saAhIcvOffBytes */
179 0, /* saAhMacSize */
180 0, /* etherLenOffBytes */
181 netTest_MAC_HEADER_LEN, /* ipOffBytes */
182 0, /* l4OffBytes */
183 0, /* l4HdrLen */
184 0, /* pseudoHdrChecksum */
185 0 /* pLoadLen */
186 };
189 nwalTxPktInfo_t txPktInfoAH =
190 {
191 NULL, /* p_pkt */
192 NWAL_TX_FLAG1_DO_IPSEC_AH_CRYPTO| NWAL_TX_FLAG1_DO_IPV4_CHKSUM | NWAL_TX_FLAG1_META_DATA_VALID, /* txFlags */
193 0, /* lpbackPass */
194 0, /* enetport */
195 0, /* msuSize */
196 0, /* startOffset */
197 netTest_MAC_HEADER_LEN + netTest_IP_HEADER_LEN, /* saOffBytes */
198 0, /* saPayLoadLen */
199 netTest_MAC_HEADER_LEN + netTest_IP_HEADER_LEN + netTest_IPSEC_AH_FIXED_HDR_SIZE, /* saAhIcvOffBytes */
200 12, /* saAhMacSize */
201 0, /* etherLenOffBytes */
202 netTest_MAC_HEADER_LEN, /* ipOffBytes */
203 0, /* l4OffBytes */
204 netTest_UDP_HEADER_LEN, /* l4HdrLen */
205 0, /* pseudoHdrChecksum */
206 0 /* pLoadLen */
207 };
209 nwalTxPktInfo_t txPktInfoNoCrypto =
210 {
211 NULL, /* p_pkt */
212 NWAL_TX_FLAG1_DO_IPV4_CHKSUM| NWAL_TX_FLAG1_META_DATA_VALID, /* txFlags */
213 0, /* lpbackPass */
214 0, /* enetport */
215 0, /* msuSize */
216 0, /* startOffset */
217 0, /* saOffBytes */
218 0, /* saPayLoadLen */
219 0 , /* saAhIcvOffBytes */
220 0, /* saAhMacSize */
221 0, /* etherLenOffBytes */
222 netTest_MAC_HEADER_LEN, /* ipOffBytes */
223 netTest_MAC_HEADER_LEN +netTest_IP_HEADER_LEN, /* l4OffBytes */
224 netTest_UDP_HEADER_LEN, /* l4HdrLen */
225 0, /* pseudoHdrChecksum */
226 0 /* pLoadLen */
227 };
229 void close_pktio_channels(void)
230 {
231 int err;
232 pktio_close(netcp_tx_chan_no_crypto ,&err);
233 pktio_close(netcp_tx_chan_esp ,&err);
234 pktio_close(netcp_tx_chan_ah ,&err);
235 }
239 void open_pktio_tx_channels()
240 {
241 int err;
242 /* open netcp default TX channels */
243 netcp_tx_chan_no_crypto= pktio_open(netapi_handle, NETCP_TX, NULL, &netcp_tx_cfg, &err);
244 if (!netcp_tx_chan_no_crypto)
245 {
246 Debug_printf("pktio open TX failed err=%d\n",err);
247 exit(1);
248 }
249 else
250 {
251 if(netTestCfg.ipsec_mode_tx == IPSEC_MODE_TX_INFLOW)
252 {
253 PKTIO_CONTROL_T control;
254 control.op = PKTIO_UPDATE_FAST_PATH;
255 PKTIO_CFG_T cfg;
256 cfg.fast_path_cfg.fp_send_option = PKTIO_FP_NO_CRYPTO_NO_CKSUM_PORT;
257 cfg.fast_path_cfg.txPktInfo= &txPktInfoNoCrypto;
258 pktio_control(netcp_tx_chan_no_crypto, NULL, &cfg, &control, &err);
259 }
260 }
261 /* open netcp default TX for ESP packets */
262 netcp_tx_chan_esp= pktio_open(netapi_handle, NETCP_TX, NULL, &netcp_tx_cfg, &err);
263 if (!netcp_tx_chan_esp)
264 {
265 Debug_printf("pktio open TX failed err=%d\n",err);
266 exit(1);
267 }
268 else
269 {
270 if(netTestCfg.ipsec_mode_tx == IPSEC_MODE_TX_INFLOW)
271 {
272 PKTIO_CONTROL_T control;
273 control.op = PKTIO_UPDATE_FAST_PATH;
274 PKTIO_CFG_T cfg;
275 cfg.fast_path_cfg.fp_send_option = PKTIO_FP_ESP_PORT;
276 cfg.fast_path_cfg.txPktInfo= &txPktInfoESP;
277 pktio_control(netcp_tx_chan_esp, NULL, &cfg, &control, &err);
278 }
279 }
281 /*/* open netcp default TX for AH packets */
282 netcp_tx_chan_ah= pktio_open(netapi_handle, NETCP_TX, NULL, &netcp_tx_cfg, &err);
283 if (!netcp_tx_chan_ah)
284 {
285 Debug_printf("pktio open TX failed err=%d\n",err);
286 exit(1);
287 }
288 else
289 {
290 if(netTestCfg.ipsec_mode_tx == IPSEC_MODE_TX_INFLOW)
291 {
292 PKTIO_CONTROL_T control;
293 control.op = PKTIO_UPDATE_FAST_PATH;
294 PKTIO_CFG_T cfg;
295 cfg.fast_path_cfg.fp_send_option = PKTIO_FP_AH_PORT;
296 cfg.fast_path_cfg.txPktInfo= &txPktInfoAH;
297 pktio_control(netcp_tx_chan_ah, NULL, &cfg, &control, &err);
298 }
299 }
300 }
305 NETAPI_T worker_nh[TUNE_NETAPI_NUM_CORES];
306 void slow_path_thread(int coreid)
307 {
308 int err;
309 PKTIO_HANDLE_T *rx_chan;
310 PKTIO_HANDLE_T *sb_tx_chan;
311 PKTIO_HANDLE_T *sb_rx_chan;
314 CPU_ZERO( &cpu_set);
315 #ifdef CORTEX_A15
316 CPU_SET( coreid, &cpu_set);
317 hplib_utilSetupCore(coreid, &cpu_set);
318 #else
319 CPU_SET( 0, &cpu_set);
320 hplib_utilSetupCore(coreid+1, &cpu_set);
321 #endif
322 worker_nh[coreid]=netapi_init(NETAPI_CORE_MASTER,NULL);
324 NETAPI_HANDLE_T * n = (NETAPI_HANDLE_T *) worker_nh[coreid];
326 /* open netcp RX channel */
327 rx_chan = pktio_open(worker_nh[coreid], NETCP_RX, (PKTIO_CB) recv_cb_router, &netcp_rx_cfg, &err);
331 netapi_setCookie(worker_nh[coreid],(void*)coreid);
333 scheduler[coreid] =netapi_schedOpen(worker_nh[coreid],&our_sched_cfg, &err);
334 if (!scheduler[coreid])
335 {
336 Debug_printf("sched create failed for core%d\n",coreid);
337 exit(1);
338 }
339 scheduler[coreid]->config.yield = FALSE;
340 scheduler[coreid]->config.pollGarbageQ = TRUE;
341 scheduler[coreid]->config.pollCtrlQ = TRUE;
342 /*********************************************/
343 /**************Entry point into scheduler ****/
344 /*********************************************/
345 netapi_schedRun(scheduler[coreid], &err);
346 Debug_printf(">net_test: core %d worker thread done\n",coreid);
348 pktio_close(rx_chan, &err);
349 netapi_shutdown(worker_nh[coreid]);
350 }
353 void fast_path_thread(int coreid)
354 {
355 int err;
356 PKTIO_HANDLE_T *rx_chan;
357 PKTIO_HANDLE_T *sb_tx_chan;
358 //PKTIO_HANDLE_T *sb_rx_chan;
360 #ifdef CORTEX_A15
361 CPU_SET( coreid, &cpu_set);
362 hplib_utilSetupCore(coreid, &cpu_set);
363 #else
364 CPU_SET( 0, &cpu_set);
365 hplib_utilSetupCore(coreid + 1, &cpu_set);
366 #endif
367 worker_nh[coreid]=netapi_init(NETAPI_CORE_MASTER,NULL);
369 NETAPI_HANDLE_T * n = (NETAPI_HANDLE_T *) worker_nh[coreid];
371 /* open netcp RX channel */
372 rx_chan = pktio_open(worker_nh[coreid], NETCP_RX, (PKTIO_CB) recv_cb_router, &netcp_rx_cfg, &err);
373 netapi_setCookie(worker_nh[coreid],(void*)coreid);
375 scheduler[coreid] =netapi_schedOpen(worker_nh[coreid],&our_sched_cfg, &err);
376 if (!scheduler[coreid])
377 {
378 Debug_printf("sched create failed for core%d\n",coreid);
379 exit(1);
380 }
382 /*********************************************/
383 /**************Entry point into scheduler ****/
384 /*********************************************/
385 scheduler[coreid]->config.yield = FALSE;
386 scheduler[coreid]->config.pollGarbageQ = FALSE;
387 scheduler[coreid]->config.pollCtrlQ = FALSE;
388 //sleep(100000);
389 netapi_schedRun(scheduler[coreid], &err);
390 Debug_printf(">net_test: core %d worker thread done\n",coreid);
392 pktio_close(rx_chan, &err);
393 netapi_shutdown(worker_nh[coreid]);
394 \r}
396 #endif
398 /***************************************
399 ********** test driver*****************
400 ***************************************/
401 int main(int argc, char **argv)
402 {
403 int err,i;
404 Pktlib_HeapCfg heapCfg;
405 rlim_t oss,ss = 1024*1024;
406 struct rlimit rl;
407 int32_t errCode;
408 Pktlib_HeapIfTable* pPktifTable;
409 /* Local Per Process default resourcese maintained at NWAL */
410 nwalLocCxtInfo_t nwalLocCxt;
412 FILE * fpr = NULL;
415 err= getrlimit(RLIMIT_STACK,&rl);
416 if (!err) Debug_printf(" stack limit = %d\n",rl.rlim_cur); else Debug_printf("getrlimit failed\n");
418 /* install signal handler for ^c */
419 signal(SIGINT,mysig);
421 fpr = fopen(input_file_name, "r");
422 if (fpr == NULL)
423 {
424 Debug_printf("Error in opening %s input file\n", input_file_name);
425 exit(1);
426 }
427 else
428 {
429 memset(&config_file, 0, sizeof(netTestConfigFile_t));
430 memset(&netTestCfg, 0, sizeof(netTestConfig_t));
431 parse_config_file(fpr,&config_file);
432 }
434 memset(&sa_info, 0, sizeof(sa_info));
436 #ifdef MULTI_THREAD
437 /* assign main net_test thread to run on core 0 */
438 CPU_ZERO( &cpu_set);
439 CPU_SET( 0, &cpu_set);
440 hplib_utilSetupCore(0, &cpu_set);
441 #endif
442 /* create netapi */
443 netapi_handle = netapi_init(NETAPI_SYS_MASTER, &our_netapi_default_cfg);
445 /* configure expection packet handling with netapi */
446 netcp_cfgExceptions(netapi_handle, NETCP_CFG_ALL_EXCEPTIONS, NETCP_CFG_ACTION_DISCARD, (NETCP_CFG_ROUTE_HANDLE_T) NULL);
447 expPkt_appid = netcp_cfgExceptions(netapi_handle, 7, NETCP_CFG_ACTION_TO_SW, (NETCP_CFG_ROUTE_HANDLE_T) NULL);
449 /* open the main heap */
450 ourHeap = Pktlib_findHeapByName("netapi");
451 if (!ourHeap)
452 {
453 Debug_printf("Pktlib_findHeapByName() fail\n");
454 exit(1);
455 }
457 /* Open all required PKTIO TX channels */
458 open_pktio_tx_channels();
460 Debug_printf("net_test> %d bytes left in our CMA area\n", netapi_getBufMemRemainder());
461 /* create scheduler instance */
462 our_sched =netapi_schedOpen(netapi_handle,&our_sched_cfg, &err);
463 if (!our_sched) {Debug_printf("sched create failed\n"); exit(1);}
466 /*create net_test MAC interfaces, attach IP to created MAC interfaces */
467 create_interfaces(&ip_rule0, &ip_rule1);
469 /* Lookup Database for SA context, this is used by packet processing routines to get RX and TX SA information*/
470 p_trie_sa_rx = trie_new();
471 p_trie_sa_tx = trie_new();
472 if (!p_trie_sa_rx || !p_trie_sa_tx)
473 {Debug_printf("trie alloc for SA failed\n"); exit(1);}
475 /* Create RX SA's, RX Policy and TX SA's, all SA configuration parameters are read from net_test_config.txt file */
476 create_sec_associations();
479 #ifdef MULTI_THREAD
480 {
481 char c;
482 /* create and set affinity of slow path and fast path threads to
483 * specific CPU cores as specified in the net_test_config.txt file */
484 create_sp_fp_threads();
487 //this thread of execution (main) now just waits on user input
488 for(;;)
489 {
490 printf(">");
491 c=getchar();
492 if (c=='q') {QUIT=1;break;}
493 else if (c=='s') our_stats_cb(netapi_handle, &netcp_stats);
494 else if (c=='h') Debug_printf("'q' to quit, 's' for stats, 'h' for help\n");
495 }
497 }
498 #else
499 /*********************************************/
500 /**************Entry point into scheduler ****/
501 /*********************************************/
502 netapi_schedRun(our_sched, &err);
503 #endif
505 /* done */
506 our_stats_cb(netapi_handle, NULL);
510 /* cleanup*/
511 delete_sec_associations();
512 delete_interfaces( &ip_rule0, &ip_rule1);
514 /* close pktio channels we opened via open_pktio_tx_channels() */
515 close_pktio_channels();
516 }
518 static inline void send_it(Ti_Pkt *tip, int len, ROUTE_SEC_T * p_sec, int out_port)
519 {
520 unsigned long st1;
521 unsigned long st2;
522 int err=0;
523 PKTIO_METADATA_T meta2 = {PKTIO_META_TX,{0},0};
524 nwalTxPktInfo_t meta_tx2={0};
525 st1=hplib_mUtilGetPmuCCNT();
526 #ifdef MULTI_THREAD
527 int coreid=Osal_nwalGetProcId(); //who we are(thread local)
528 //int coreid = our_core;
529 #else
530 int coreid=0;
531 #endif
532 if (len<60)
533 {
534 unsigned int templen;
535 char * p_pkt;
536 len=60;
537 Pktlib_getDataBuffer(tip,(uint8_t**)&p_pkt,&templen);//ignore templen
538 Cppi_setData (Cppi_DescType_HOST, (Cppi_Desc *) tip, p_pkt,len);
539 stats[coreid].tx_min+=1;
540 }
541 Pktlib_setPacketLen(tip,len);
542 meta_tx2.txFlag1 = (NWAL_TX_FLAG1_DO_IPV4_CHKSUM| NWAL_TX_FLAG1_META_DATA_VALID );
543 meta_tx2.startOffset = 0;
544 meta_tx2.ipOffBytes = netTest_MAC_HEADER_LEN;
545 meta_tx2.ploadLen = len ;
546 meta_tx2.enetPort=out_port;
547 if(p_sec)
548 {
549 meta_tx2.txFlag1 |= NWAL_TX_FLAG1_DO_IPSEC_ESP_CRYPTO ;
550 meta2.sa_handle = (void*)p_sec->tx_tunnel;
551 meta_tx2.saOffBytes=netTest_MAC_HEADER_LEN + netTest_IP_HEADER_LEN;
552 meta_tx2.saPayloadLen=len-netTest_MAC_HEADER_LEN - netTest_IP_HEADER_LEN; //don't include tag, mac and outer header
553 meta2.u.tx_meta=&meta_tx2;
554 pktio_send(netcp_tx_chan_esp,tip,&meta2,&err);
555 stats[coreid].sec_tx+=1;
556 }
557 else
558 {
559 meta2.u.tx_meta=&meta_tx2;
560 pktio_send(netcp_tx_chan_no_crypto,tip,&meta2,&err);
562 }
563 stats[coreid].tx +=1;
564 st2=hplib_mUtilGetPmuCCNT();
565 stats[coreid].send_cycles += (unsigned long long) (st2-st1);
566 }
567 void recv_cb_router(struct PKTIO_HANDLE_Tag * channel, Ti_Pkt* p_recv[],
568 PKTIO_METADATA_T meta[], int n_pkts,
569 uint64_t ts )
570 {
571 int i;
572 int len;
573 int p;
574 Ti_Pkt * tip;
575 unsigned int templen;
576 char * p_pkt;
577 HEAD_T temp_head;
578 unsigned int appid;
579 IP_HEAD_T th;
580 ROUTE_SEC_T *sec_data=NULL;
581 unsigned long t1;
582 unsigned long t2;
583 unsigned long long ct1;
584 unsigned long long ct2;
585 unsigned short ip_pl;
586 unsigned long long n_c_ops;
587 int ifno;
588 int out_port;
589 #ifdef MULTI_THREAD
590 int coreid=Osal_nwalGetProcId(); //who we are(thread local)
591 //int coreid = our_core;
592 #else
593 int coreid=0;
594 #endif
595 t1=hplib_mUtilGetPmuCCNT();
596 ct1 =Osal_cache_op_measure(&n_c_ops);
597 for(i=0;i<n_pkts;i++)
598 {
599 ifno = ((unsigned int)meta[i].u.rx_meta->appId)&0xff;
600 if(coreid<TUNE_NETAPI_NUM_CORES) stats[coreid].rx+=1;
601 if (ifno < TUNE_NETAPI_MAX_NUM_MAC) stats[coreid].if_rx[ifno]+=1;
602 tip = p_recv[i];
603 Pktlib_getDataBuffer(tip,(uint8_t**)&p_pkt,&templen);//ignore templen
604 len = Pktlib_getPacketLen(tip)-4;//real length, subtract mac trailer
605 stats[coreid].rx+=1;
606 appid = ((unsigned int)meta[i].u.rx_meta->appId)&0xff000000;
607 switch(appid)
608 {
609 case(NETAPI_NETCP_MATCH_IPSEC):
610 case(NETAPI_NETCP_MATCH_IPSEC_POLICY):
611 {
612 int tailen=12+2;
613 memcpy(&temp_head,&p_pkt[14],sizeof(HEAD_T));
614 if (!check_header(&temp_head,&meta[i])) {
615 stats[coreid].n_bad+=1;
616 Pktlib_freePacket(tip);
617 continue;
618 }
619 tailen+=p_pkt[len-12-2]; //padding length (12)should come from sec_ptr
620 p_pkt = &p_pkt[8+16+20]; //16= iv len, should come from sec_ptr
621 len -= (8+16+20+tailen); //16= iv len should come from sec ptr
623 //now check inner headder.
624 memcpy(&th,&p_pkt[14],20);
625 if (!check_header(&temp_head,&meta[i])) {
626 stats[coreid].n_bad+=1;
627 Pktlib_freePacket(tip);
628 continue;
629 }
630 Cppi_setData (Cppi_DescType_HOST, (Cppi_Desc *) tip, p_pkt,len);
631 Pktlib_setPacketLen(tip,len);
633 if (route_pkt(our_router, tip, &th, p_pkt, &len,&sec_data,&out_port)<0)
634 {
635 stats[coreid].n_bad+=1;
636 Pktlib_freePacket(tip);
637 }
638 else
639 {
640 send_it(tip,len,sec_data,out_port);
641 }
642 break;
643 }
644 case(NETAPI_NETCP_MATCH_GENERIC_MAC):
645 if((p_pkt[12]!=0x8)||(p_pkt[13]!=0x00))
646 {
647 stats[coreid].n_new+=1;
648 Pktlib_freePacket(tip);
649 continue;
650 }
651 if (!check_header(&temp_head,&meta[i]))
652 {
653 stats[coreid].n_bad+=1;
654 Pktlib_freePacket(tip);
655 continue;
656 }
657 memcpy(&th,&p_pkt[14],20);
658 ip_pl= (((unsigned char *)&th.w1)[2]<<8) | ((unsigned char *)&th.w1)[3];
659 if ((ip_pl+14)<60)
660 {
661 len-= (60-(ip_pl+14));
662 stats[coreid].rx_min+=1;
663 }
664 Pktlib_setPacketLen(tip,len);
665 if (route_pkt(our_router, tip, &th, p_pkt, &len,&sec_data,&out_port)<0)
666 {
667 stats[coreid].n_bad+=1;
668 Pktlib_freePacket(tip);
669 }
670 else
671 {
672 send_it(tip,len,sec_data,out_port);
673 }
674 break;
675 case(NETAPI_NETCP_MATCH_GENERIC_IP):
676 Pktlib_freePacket(tip);
677 stats[coreid].n_new=1;
678 break;
679 default:
680 stats[coreid].n_new+=1;
681 Pktlib_freePacket(tip);
682 break;
683 }
684 }
685 t2=hplib_mUtilGetPmuCCNT();
686 ct2 =Osal_cache_op_measure(&n_c_ops);
687 stats[coreid].app_cycles += (unsigned long long) (t2-t1);
688 stats[coreid].tx_cache_cycles += (unsigned long long) (ct2-ct1);
689 return;
690 }
692 /* STUB functions required for compilation */
693 void recv_cb(struct PKTIO_HANDLE_Tag * channel, Ti_Pkt* p_recv[],
694 PKTIO_METADATA_T meta[], int n_pkts,
695 uint64_t ts )
696 {
697 }
699 void recv_sb_cb(struct PKTIO_HANDLE_Tag * channel, Ti_Pkt* p_recv[],
700 PKTIO_METADATA_T meta[], int n_pkts,
701 uint64_t ts )
702 {
703 }