081d22869814c6803ec1377cc1f38d99f775da19
1 #ifndef __NET_TEST_UTIL_H__
2 #define __NET_TEST_UTIL_H__
6 #include <stdio.h>
7 #include <stdlib.h>
8 #include <unistd.h>
9 #include <string.h>
12 #include "net_test.h"
14 #ifdef __LINUX_USER_SPACE
15 #define Debug_printf
16 #else
17 #define Debug_printf
18 #endif
23 #define MAX_SEC_INDEX 16
24 #define NET_TEST_MAX_MAC 10
25 #define NET_TEST_MAX_IP 10
26 #define NET_TEST_MAX_FP_THREAD 5
28 #define MAX_LINE_LENGTH 512
29 #define MAX_ROUTES 16
31 /* The input strings requird for parsing certain configuration
32 * paremeters from the config file */
33 #define INIT_CONFIG_IPSEC_MODE_RX "ipsec_mode_rx"
34 #define INIT_CONFIG_IPSEC_MODE_TX "ipsec_mode_tx"
35 #define INIT_CONFIG_IPSEC_IF_NO "ipsec_if"
36 #define INIT_CONFIG_NUM_FP_CORES "fast_path_core"
37 #define INIT_CONFIG_NUM_FP_THREADS "slow_path_core"
38 #define CONFIG_STRING_LEN 128
40 //IPSEC MODE(only choose one rx and one tx)
41 #define IPSEC_MODE_RX_INFLOW 1
42 #define IPSEC_MODE_TX_INFLOW 2
43 #define IPSEC_MODE_RX_SIDEBAND 3
44 #define IPSEC_MODE_TX_SIDEBAND 4
46 #define PKT_LEN 1400
48 typedef struct {
49 unsigned char mac[NET_TEST_MAX_MAC][6];
50 uint8_t num_macs;
51 uint8_t switch_port[NET_TEST_MAX_MAC];
52 nwalIpAddr_t ip[NET_TEST_MAX_IP];
53 uint8_t num_ips;
54 uint8_t attach_iface[NET_TEST_MAX_IP];
55 nwalIpAddr_t local_ipsec_ip;
56 nwalIpAddr_t remote_ipsec_ip;
57 uint8_t ipsec_mode_rx;
58 uint8_t ipsec_mode_tx;
59 uint8_t ipsec_if_no;
60 uint8_t fp_proc_start[NET_TEST_MAX_FP_THREAD];
61 uint8_t fp_proc_end[NET_TEST_MAX_FP_THREAD];
62 uint32_t fp_thread_num[NET_TEST_MAX_FP_THREAD];
63 uint8_t num_fp_threads;
64 uint8_t sp_proc_start[NET_TEST_MAX_FP_THREAD];
65 uint8_t sp_proc_end[NET_TEST_MAX_FP_THREAD];
66 uint32_t sp_thread_num[NET_TEST_MAX_FP_THREAD];
67 uint8_t num_sp_threads;
69 uint8_t auth_key[MAX_SEC_INDEX][36];
70 uint8_t encr_key[MAX_SEC_INDEX][36];
71 uint32_t tunnel_id[MAX_SEC_INDEX];
72 NETAPI_SEC_SA_INFO_T sa_info[MAX_SEC_INDEX];
73 nwalSecKeyParams_t key_params[MAX_SEC_INDEX];
75 } netTestConfig_t;
77 typedef struct
78 {
79 char dir[CONFIG_STRING_LEN];
80 char spi[CONFIG_STRING_LEN];
81 char proto[CONFIG_STRING_LEN];
82 char saMode[CONFIG_STRING_LEN];
83 char ipType[CONFIG_STRING_LEN];
84 char src[CONFIG_STRING_LEN];
85 char dst[CONFIG_STRING_LEN];
86 char replayWindow[CONFIG_STRING_LEN];
87 char authMode[CONFIG_STRING_LEN];
88 char cipherMode[CONFIG_STRING_LEN];
89 char esnLo[CONFIG_STRING_LEN];
90 char esnHi[CONFIG_STRING_LEN];
91 char encKeySize[CONFIG_STRING_LEN];
92 char macKeySize[CONFIG_STRING_LEN];
93 char auth_key[CONFIG_STRING_LEN];
94 char encr_key[CONFIG_STRING_LEN];
95 char tunnel_id[CONFIG_STRING_LEN];
96 } netTestConfigSA_t;
98 typedef struct{
99 char mac[NET_TEST_MAX_MAC][CONFIG_STRING_LEN];
100 char switch_port[NET_TEST_MAX_MAC][CONFIG_STRING_LEN];
101 char ip[NET_TEST_MAX_IP][CONFIG_STRING_LEN];
102 char attach_iface [NET_TEST_MAX_MAC][CONFIG_STRING_LEN];
103 char ipsec_mode_rx[CONFIG_STRING_LEN];
104 char ipsec_mode_tx[CONFIG_STRING_LEN];
105 char routes[MAX_ROUTES][CONFIG_STRING_LEN];
106 char ports[MAX_ROUTES][CONFIG_STRING_LEN];
107 char dst_ips[MAX_ROUTES][CONFIG_STRING_LEN];
108 char paths[MAX_ROUTES][CONFIG_STRING_LEN];
109 char ipsec_if_no[CONFIG_STRING_LEN];
110 char fp_thread_num[NET_TEST_MAX_FP_THREAD][CONFIG_STRING_LEN];
111 char sp_thread_num[NET_TEST_MAX_FP_THREAD][CONFIG_STRING_LEN];
112 char sp[NET_TEST_MAX_FP_THREAD][CONFIG_STRING_LEN];
113 char fp[NET_TEST_MAX_FP_THREAD][CONFIG_STRING_LEN];
114 char tunnel_id[CONFIG_STRING_LEN];
115 netTestConfigSA_t sa_config[MAX_SEC_INDEX];
117 } netTestConfigFile_t;
119 struct LastPktInfo
120 {
121 int iface;
122 int ipcsum;
123 int l4csum;
124 } ;
125 int check_header(HEAD_T * p_head, PKTIO_METADATA_T * p_meta);
127 void mysig(int x);
128 unsigned long peek(unsigned long * p);
129 void dump_descr(unsigned long *p, int n);
130 void dump_header(unsigned long *p, int n, int a, int r);
131 void netapi_dump_buf(unsigned long * buf,uint32_t buf_length);
132 long htonl(long x);
133 unsigned char hex2dec(char *p_s);
134 uint16_t test_utilOnesComplementAdd (uint16_t v1, uint16_t v2);
135 uint16_t test_utilOnesCompChkSum (uint8_t *p, uint32_t nwords);
136 uint16_t test_utilGetIpv4PsudoChkSum (uint8_t *data, uint16_t payloadLen);
137 void print_ipsec_stats(Sa_IpsecStats_t *p_saIpsecStats, nwal_saAALG auth, nwal_saEALG cipher);
138 void print_datamode_stats(Sa_DataModeStats_t *p_saDataModeStats, nwal_saAALG auth, nwal_saEALG cipher);
139 void our_stats_cb_mt(NETAPI_T h, paSysStats_t* pPaStats);
140 void our_stats_cb(NETAPI_T h, paSysStats_t* pPaStats);
141 void parse_one_mac(char * p_mac_str, unsigned char *p_mac);
142 void parse_one_key(char *p_key_str, unsigned char *p_key);
143 void parse_one_ip(char * p_ip_addr_str, unsigned char * p_ip);
144 void parse_mac_address(netTestConfigFile_t *pConfig);
145 void parse_ip_address(netTestConfigFile_t *pConfig);
146 void parse_fp(netTestConfigFile_t *pConfig);
147 void parse_sp(netTestConfigFile_t *pConfig);
148 void parse_ipsec_mode(netTestConfigFile_t *pConfig);
149 void parse_auth_mode(char *auth_mode_str, nwal_saAALG *auth_mode);
150 void parse_encr_mode(char *ency_mode_str, nwal_saEALG*encr_mode);
151 void parse_proto(char *proto_str, nwal_IpSecProto *proto);
152 void parse_mode(char *mode_str, nwal_saMode *mode);
153 void parse_ipType(char *ip_type_str, nwal_IpType *ipType);
154 void parse_spi(char *spi_str, uint32_t *spi);
155 void parse_replayWindow(char *replay_window_str, uint32_t *replay_window);
156 void parse_esn(char *esn_str, uint32_t *esn);
157 void parse_key_size(char *key_size_str, uint16_t *key_size);
158 void parse_tunnel_id(char * tunnel_id_str, uint32_t *tunnel_id);
159 void parse_dir(char* dir_str, nwal_SaDir *dir);
161 void parse_num_fp_cores(netTestConfigFile_t *pConfig);
162 void parse_num_fp_threads(netTestConfigFile_t *pConfig);
163 void parse_num_fp_threads(netTestConfigFile_t *pConfig);
166 void parse_sa(netTestConfigFile_t *pConfig, int i);
167 #ifdef EXPERIMENTAL
168 void parse_routes(netTestConfigFile_t *pConfig);
169 #endif
170 void parse_config_file(FILE * fpr, netTestConfigFile_t *pConfig);
172 void house(NETAPI_SCHED_HANDLE_T *s);
174 void create_interfaces(NETCP_CFG_IP_T *ip_rule0 , NETCP_CFG_IP_T *ip_rule1);
175 void delete_interfaces(NETCP_CFG_IP_T *ip_rule0 , NETCP_CFG_IP_T *ip_rule1);
176 void slow_path_thread(int coreid);
177 void fast_path_thread(int coreid);
178 #endif