]> Gitweb @ Texas Instruments - Open Source Git Repositories - git.TI.com/gitweb - keystone-rtos/netapi.git/blob - ti/runtime/netapi/test/net_test_max_params.c
SDOCM00113322: kernel RX UDP/TCP checksum offload to NETCP breaks user space tranport...
[keystone-rtos/netapi.git] / ti / runtime / netapi / test / net_test_max_params.c
1 /******************************************
2  * File: net_test.c
3  * Purpose: Application for testing out max configuration parameters
4  *          such as SA's, MACs/IP interfaces
5  **************************************************************
6  * FILE:  net_test.c
7  * 
8  * DESCRIPTION:  netapi user space transport
9  *               library  test application
10  * 
11  * REVISION HISTORY:
12  *
13  *  Copyright (c) Texas Instruments Incorporated 2013
14  * 
15  *  Redistribution and use in source and binary forms, with or without 
16  *  modification, are permitted provided that the following conditions 
17  *  are met:
18  *
19  *    Redistributions of source code must retain the above copyright 
20  *    notice, this list of conditions and the following disclaimer.
21  *
22  *    Redistributions in binary form must reproduce the above copyright
23  *    notice, this list of conditions and the following disclaimer in the 
24  *    documentation and/or other materials provided with the   
25  *    distribution.
26  *
27  *    Neither the name of Texas Instruments Incorporated nor the names of
28  *    its contributors may be used to endorse or promote products derived
29  *    from this software without specific prior written permission.
30  *
31  *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 
32  *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 
33  *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
34  *  A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 
35  *  OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 
36  *  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 
37  *  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
38  *  DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
39  *  THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 
40  *  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 
41  *  OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
43  *****************************************/
45 #include "net_test.h"
46 #include "ti/drv/nwal/test/fw_rm.h"
47 #include <signal.h>
48 #include <pthread.h>
50 extern int QUIT;
51 extern netTestStats_T stats[TUNE_NETAPI_NUM_CORES];
52 extern paSysStats_t netcp_stats;
53 /* Global definitions */
54 #ifdef netTest_MULTI_THREAD
55     cpu_set_t cpu_set;
56 #endif
59 #define SA_CREATE_LOOP_COUNT 64
60 #define IP_CREATE_LOOP_COUNT 64
61 #define MAC_CREATE_LOOP_COUNT 59
64 netTestConfig_t netTestCfg;
65 static  netTestConfigFile_t config_file;
67 char    input_file_name[] = "net_test_config_max_iface.txt";
69 nwal_RetValue       nwalRetVal;
70 Pktlib_HeapHandle ourHeap;
72 PKTIO_HANDLE_T *netcp_rx_chan;
73 PKTIO_HANDLE_T *netcp_tx_chan_no_crypto;
74 PKTIO_HANDLE_T *netcp_tx_chan_esp;
75 PKTIO_HANDLE_T *netcp_tx_chan_ah;
76 PKTIO_HANDLE_T *netcp_sb_tx_chan;
77 PKTIO_HANDLE_T *netcp_sb_rx_chan;
79 PKTIO_CFG_T our_chan_cfg={PKTIO_RX_TX, PKTIO_LOCAL, PKTIO_Q_ANY, 8};
80 PKTIO_CFG_T netcp_rx_cfg={PKTIO_RX, PKTIO_NA, PKTIO_NA, 8};
81 PKTIO_CFG_T netcp_rx_cfg2={PKTIO_RX, (PKTIO_GLOBAL|PKTIO_PKT), PKTIO_Q_ANY, 8};
82 PKTIO_CFG_T netcp_tx_cfg={PKTIO_TX, PKTIO_NA, PKTIO_NA, 8};
83 PKTIO_CFG_T netcp_sb_rx_cfg={PKTIO_RX, PKTIO_NA, PKTIO_NA, 8};
84 PKTIO_CFG_T netcp_sb_tx_cfg={PKTIO_TX, PKTIO_NA, PKTIO_NA, 8};
87 NETCP_CFG_EXCEPTION_PKT_T expPkt_appid;
89 Trie *p_trie_sa_rx;
90 Trie *p_trie_sa_tx;
93 /*******************************************
94  *************NETAPI OBJECTS***************
95  *****************************************/
96 static NETAPI_CFG_T our_netapi_default_cfg=
97 {
98 TUNE_NETAPI_PERM_MEM_SZ,
99 128,  //start of packet offset for hw to place data on rx for default flow
100 TUNE_NETAPI_QM_CONFIG_MAX_DESC_NUM, //max number of descriptors in system
101 TUNE_NETAPI_NUM_GLOBAL_DESC,        //total we will use
102 TUNE_NETAPI_DEFAULT_NUM_BUFFERS,   //#descriptors+buffers in default heap
103 64, //#descriptors w/o buffers in default heap
104 TUNE_NETAPI_DEFAULT_BUFFER_SIZE+128+128,  //size of buffers in default heap
105 128,       //tail room
106 256,      //extra room
107 0,
108 NULL,
109 18,
110 0x2000
111 };
113 NETAPI_T netapi_handle;
114 NETAPI_SCHED_HANDLE_T * our_sched;
115 #ifdef netTest_MULTI_THREAD
116 NETAPI_SCHED_HANDLE_T * scheduler[TUNE_NETAPI_NUM_CORES];
117 #endif
118 NETAPI_SCHED_CONFIG_T our_sched_cfg={
119   NETAPI_SCHED_DURATION|NETAPI_SCHED_CBV, 0, house, 5000000  //every 5000000 poll loops
120 };
122 NETCP_CFG_IP_T ip_rule[NET_TEST_MAX_IP];
123 NETCP_CFG_MACIF_T mac[NET_TEST_MAX_MAC];
127 /* security objects. (for loopback mode) */
128 netTestSA_t sa_info[MAX_SEC_INDEX];
130 NETCP_CFG_IPSEC_POLICY_T rx_policy[MAX_SEC_INDEX];
132 /* stub functions */
133 void recv_cb(struct PKTIO_HANDLE_Tag * channel, Ti_Pkt* p_recv[],
134                          PKTIO_METADATA_T meta[], int n_pkts,
135                          uint64_t ts )
137     return;
140 void flip_and_send_pkt(Ti_Pkt *tip,  unsigned char * p_pkt, int len, int flag, uint16_t enet_port)
142     return;
147 void recv_sb_cb(struct PKTIO_HANDLE_Tag * channel, Ti_Pkt* p_recv[],
148                          PKTIO_METADATA_T meta[], int n_pkts,
149                          uint64_t ts )
151     return;
154 Trie * route_init(void)
156     return NULL;
158 void route_add(Trie * Pt, unsigned long * Pdest_ipBE, void * Pour_route)
162 #ifdef netTest_MULTI_THREAD
163 NETAPI_T worker_nh[TUNE_NETAPI_NUM_CORES];
165 void slow_path_thread(uint32_t thread_num)
167     return;
170 void fast_path_thread(uint32_t thread_num)
172     return;
175 #endif
177 /* Templates to build command labels at startup up time, required by open_pktio_tx_channels() */
178 nwalTxPktInfo_t txPktInfoESP = 
180     NULL,                                                                                               /* p_pkt */
181     NWAL_TX_FLAG1_DO_IPSEC_ESP_CRYPTO| NWAL_TX_FLAG1_DO_UDP_CHKSUM| NWAL_TX_FLAG1_META_DATA_VALID,      /* txFlags */
182     0,                                                                                                  /* lpbackPass */
183     0,                                                                                                  /* enetport */
184     0,                                                                                                  /* msuSize */
185     0,                                                                                                   /* startOffset */
186     netTest_MAC_HEADER_LEN  + netTest_IP_HEADER_LEN,                                                    /* saOffBytes */
187     0,                                                                                                  /* saPayLoadLen */
188     0               ,                                                                                    /* saAhIcvOffBytes */
189     0,                                                                                                 /* saAhMacSize */
190     0,                                                                                                  /* etherLenOffBytes */
191     0,                                                                                                  /* ipOffBytes */
192     0,                                                                                                  /* l4OffBytes */
193     netTest_UDP_HEADER_LEN,                                                                             /* l4HdrLen */
194     0,                                                                                                  /* pseudoHdrChecksum */
195     0                                                                                                   /* pLoadLen */
196 };
199 nwalTxPktInfo_t txPktInfoAH = 
201     NULL,                                                                                               /* p_pkt */
202     NWAL_TX_FLAG1_DO_IPSEC_AH_CRYPTO| NWAL_TX_FLAG1_DO_UDP_CHKSUM | NWAL_TX_FLAG1_META_DATA_VALID,      /* txFlags */
203     0,                                                                                                  /* lpbackPass */
204     0,                                                                                                  /* enetport */
205     0,                                                                                                  /* msuSize */
206     0,                                                                                                   /* startOffset */
207     netTest_MAC_HEADER_LEN  + netTest_IP_HEADER_LEN,                                                    /* saOffBytes */
208     0,                                                                                                  /* saPayLoadLen */
209     netTest_MAC_HEADER_LEN + netTest_IP_HEADER_LEN + netTest_IPSEC_AH_FIXED_HDR_SIZE,                    /* saAhIcvOffBytes */
210     12,                                                                                                 /* saAhMacSize */
211     0,                                                                                                  /* etherLenOffBytes */
212     0,                                             /* ipOffBytes */
213     0,                                                                                                  /* l4OffBytes */
214     netTest_UDP_HEADER_LEN,                                                                            /* l4HdrLen */
215     0,                                                                                                  /* pseudoHdrChecksum */
216     0                                                                                                   /* pLoadLen */
217 };
219 nwalTxPktInfo_t txPktInfoNoCrypto = 
221     NULL,                                                                                               /* p_pkt */
222     NWAL_TX_FLAG1_DO_UDP_CHKSUM| NWAL_TX_FLAG1_META_DATA_VALID,      /* txFlags */
223     0,                                                                                                  /* lpbackPass */
224     0,                                                                                                  /* enetport */
225     0,                                                                                                  /* msuSize */
226     0,                                                                                                   /* startOffset */
227     0,                                                    /* saOffBytes */
228     0,                                                                                                  /* saPayLoadLen */
229     0               ,                                                                                    /* saAhIcvOffBytes */
230     0,                                                                                                 /* saAhMacSize */
231     0,                                                                                                  /* etherLenOffBytes */
232     0,                                                                                                  /* ipOffBytes */
233     netTest_MAC_HEADER_LEN +netTest_IP_HEADER_LEN,                                        /* l4OffBytes */
234     netTest_UDP_HEADER_LEN,                                                             /* l4HdrLen */
235     0,                                                                         /* pseudoHdrChecksum */
236     0                                                                                                   /* pLoadLen */
237 };
240 void close_pktio_channels(void)
242     int err;
243     netapi_pktioClose(netcp_tx_chan_esp ,&err);
244     netapi_pktioClose(netcp_tx_chan_ah ,&err);
245     netapi_pktioClose(netcp_sb_tx_chan ,&err);
246     netapi_pktioClose(netcp_tx_chan_no_crypto,&err);
249 void open_pktio_tx_channels(void)
251     int err;
252     /* open netcp default  TX for ESP packets */
253     netcp_tx_chan_esp= netapi_pktioOpen(netapi_handle, NETCP_TX, NULL, &netcp_tx_cfg,  &err);
254     if (!netcp_tx_chan_esp)
255     {
256         printf("pktio open TX failed err=%d\n",err);
257         exit(1);
258     }
259     else
260     {
261         if(netTestCfg.ipsec_mode_tx == IPSEC_MODE_TX_INFLOW)
262         {
263             PKTIO_CONTROL_T control;
264             control.op = PKTIO_UPDATE_FAST_PATH;
265             PKTIO_CFG_T cfg;
266             cfg.fast_path_cfg.fp_send_option = PKTIO_FP_ESP_L4CKSUM_PORT;
267             cfg.fast_path_cfg.txPktInfo= &txPktInfoESP;
268             netapi_pktioControl(netcp_tx_chan_esp, NULL, &cfg, &control, &err);
269         }
270     }
272     /* open netcp default  TX for AH packets */
273     netcp_tx_chan_ah= netapi_pktioOpen(netapi_handle, NETCP_TX, NULL, &netcp_tx_cfg,  &err);
274     if (!netcp_tx_chan_ah)
275     {
276         printf("pktio open TX failed err=%d\n",err);
277         exit(1);
278     }
279     else
280     {
281         if(netTestCfg.ipsec_mode_tx == IPSEC_MODE_TX_INFLOW)
282         {
283             PKTIO_CONTROL_T control;
284             control.op = PKTIO_UPDATE_FAST_PATH;
285             PKTIO_CFG_T cfg;
286             cfg.fast_path_cfg.fp_send_option = PKTIO_FP_AH_L4CKSUM_PORT;
287             cfg.fast_path_cfg.txPktInfo= &txPktInfoAH;
288             netapi_pktioControl(netcp_tx_chan_ah, NULL, &cfg, &control, &err);
289         }
290     }
292     /* open netcp default  TX channels for non-Crypto packets */
293     netcp_tx_chan_no_crypto= netapi_pktioOpen(netapi_handle, NETCP_TX, NULL, &netcp_tx_cfg,  &err);
294     if (!netcp_tx_chan_no_crypto)
295     {
296         printf("pktio open TX failed err=%d\n",err);
297         exit(1);
298     }
299     else
300     {
301         if(netTestCfg.ipsec_mode_tx == IPSEC_MODE_TX_INFLOW)
302         {
303             PKTIO_CONTROL_T control;
304             control.op = PKTIO_UPDATE_FAST_PATH;
305             PKTIO_CFG_T cfg;
306             cfg.fast_path_cfg.fp_send_option = PKTIO_FP_L4CKSUM_PORT;
307             cfg.fast_path_cfg.txPktInfo= &txPktInfoNoCrypto;
308             netapi_pktioControl(netcp_tx_chan_no_crypto, NULL, &cfg, &control, &err);
309         }
310     }
312     /* open netcp default  TX channels for SB crypto */
313     netcp_sb_tx_chan= netapi_pktioOpen(netapi_handle, NETCP_SB_TX, NULL, &netcp_sb_tx_cfg,  &err);
314     if (!netcp_sb_tx_chan)
315     {
316         printf("pktio open SB TX failed err=%d\n",err);
317         exit(1);
318     }
320 /***************************************
321  ********** test driver*****************
322  ***************************************/
323 int main(int argc, char **argv)
325     int err,i;
326     Pktlib_HeapCfg      heapCfg;
327     int32_t             errCode;
328     Pktlib_HeapIfTable*  pPktifTable;
329     FILE * fpr = NULL;
332     setvbuf(stdout,NULL,_IONBF,0);
333      /* install signal handler for ^c */
334     signal(SIGINT,netTest_utilMySig);
336     if (argc == 2)
337     {
338         printf("main: filename1 %s\n", argv[1]);
339         fpr = fopen(argv[1], "r");
340     }
341     else
342     {
343         fpr = fopen(input_file_name, "r");
344     }
345     if (fpr == NULL)
346     {
347         printf("error opening configfile\n");
348         exit(1);
349     }
350     else
351     {
352         memset(&config_file, 0, sizeof(netTestConfigFile_t));
353         memset(&netTestCfg, 0, sizeof(netTestConfig_t));
354         netTest_utilProcessConfigFile(fpr,&config_file);
355 #if 1
356         netTest_utilParseMac(&config_file);
358         /* parse slow path/fast path thread configuration parameters */
359         netTest_utilParseThreadParams(&config_file);
361         netTest_utilParseIP(&config_file);
363         netTest_utilParseIpsecMode(&config_file);
365         /* DSP mac processing */
366         parse_dsp_mac(&config_file.dsp_mac[0]);
368        /* DSP IP processing */
369         parse_dsp_ip(&config_file.dsp_ip[0]);
371         /* IPSEC interface number processing */
372         parse_simple_param_u32((char*)&config_file.ipsec_if_no[0], &netTestCfg.ipsec_if_no);
374         netTest_utilParseSA(&config_file);
375 #endif
376     }
378     memset(&sa_info, 0, sizeof(sa_info));
381 #ifdef netTest_MULTI_THREAD
382     /* assign main net_test thread to run on core 0 */
383     CPU_ZERO( &cpu_set);
384     CPU_SET( 0, &cpu_set);
385     hplib_utilSetupThread(0, &cpu_set, hplib_spinLock_Type_LOL);
386 #endif
388     /* create netapi */
389     netapi_handle = netapi_init(NETAPI_SYS_MASTER, &our_netapi_default_cfg);
390     if (netapi_handle == NULL)
391     {
392         printf("main: netapi_init failure, exiting\n");
393         exit(1);
394     }
396     /* open the main heap */
397     ourHeap = Pktlib_findHeapByName("netapi");
398     if (!ourHeap)
399     {
400         printf("Pktlib_findHeapByName()  fail\n");
401         exit(1);
402     }
404     open_pktio_tx_channels();
406     /* create scheduler instance */
407     our_sched =netapi_schedOpen(netapi_handle,&our_sched_cfg, &err);
408     if (!our_sched) {printf("sched create failed\n"); exit(1);}
411     /*create net_test MAC interfaces, attach IP to created MAC interfaces */
412     netTest_utilCreateInterfaces(netTestCfg.num_macs, netTestCfg.num_ips,0);
414     /* lookup Database for SA context, this is used by packet processing routines to get RX and TX SA information*/
415     p_trie_sa_rx = trie_new();
416     p_trie_sa_tx = trie_new();
417     if (!p_trie_sa_rx || !p_trie_sa_tx)
418         {printf("trie alloc for SA  failed\n"); exit(1);}
421 #ifdef TEST_SA
422     /* Create RX SA's, RX Policy and TX SA's, all SA configuration parameters are read from net_test_config.txt file */
423     netTest_utilCreateSecAssoc();
424 #endif
425 #ifdef netTest_MULTI_THREAD
427     int c;
430         //this thread of execution (main) now just waits on user input
431         for(;;)
432         {
433             printf(">");
434             c=getchar();
435             if (c=='q')
436             {
437                 QUIT=1;
438                 break;
439             }
440             else if (c=='h')
441                 printf("'q' to quit,  's' for stats, 'h' for help\n");
442         }
444 #else
445     /*********************************************/
446     /**************Entry point into scheduler ****/
447     /*********************************************/
448     netapi_schedRun(our_sched, &err);
449 #endif
451     /* cleanup*/
452      netTest_utilDeleteSecAssoc();
454     netTest_utilDeleteInterfaces(netTestCfg.num_macs, netTestCfg.num_ips);
456     /* close pktio channels we opened via open_pktio_tx_channels() */
457     close_pktio_channels();
458     
459     netapi_shutdown(netapi_handle);