Skip to content

Commit e81ef53

Browse files
committed
support to sync ip/route from linux kernel
1 parent 0a8a5e2 commit e81ef53

21 files changed

+83
-56
lines changed

ans/ans_kni.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ static int ans_kni_alloc(uint8_t port_id)
193193
return -1;
194194

195195
memset(&conf, 0, sizeof(conf));
196-
snprintf(conf.name, RTE_KNI_NAMESIZE,"keth%u", port_id);
196+
snprintf(conf.name, RTE_KNI_NAMESIZE, "veth%u", port_id);
197197
conf.group_id = (uint16_t)port_id;
198198
conf.mbuf_size = MAX_PACKET_SZ;
199199

ans/ans_main.c

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -861,7 +861,7 @@ int main(int argc, char **argv)
861861
/* parse application arguments (after the EAL ones) */
862862
ret = ans_parse_args(argc, argv, &ans_user_conf);
863863
if (ret < 0)
864-
rte_exit(EXIT_FAILURE, "Invalid ODP parameters\n");
864+
rte_exit(EXIT_FAILURE, "Invalid ANS parameters\n");
865865

866866

867867
if(ans_user_conf.jumbo_frame_on)
@@ -870,6 +870,11 @@ int main(int argc, char **argv)
870870
ans_port_conf.rxmode.max_rx_pkt_len = ans_user_conf.max_rx_pkt_len;
871871
}
872872

873+
if(ans_user_conf.ipsync_on && !ans_user_conf.kni_on)
874+
{
875+
rte_exit(EXIT_FAILURE, "ipsync is enable, kni shall be enable too.\n");
876+
}
877+
873878
ans_user_conf.lcore_nb = rte_lcore_count();
874879

875880
if (ans_check_lcore_params(&ans_user_conf) < 0)
@@ -912,6 +917,7 @@ int main(int argc, char **argv)
912917
init_conf.pktmbuf_pool[i] = ans_pktmbuf_pool[i];
913918
}
914919

920+
init_conf.ip_sync = ans_user_conf.ipsync_on;
915921
init_conf.port_send = ans_send_packet;
916922
init_conf.port_bypass = ans_bypass_packet;
917923

@@ -924,6 +930,7 @@ int main(int argc, char **argv)
924930
/* add by ans_team for testing ---start */
925931
uint8_t ifname[16];
926932
int portid;
933+
uint16_t kni_id;
927934
struct ether_addr eth_addr;
928935

929936
for(portid= 0; portid < nb_ports; portid++)
@@ -937,12 +944,13 @@ int main(int argc, char **argv)
937944

938945
memset(ifname, 0, sizeof(ifname));
939946

940-
sprintf(ifname, "eth%d", portid);
941-
942-
printf("add %s device\r\n", ifname);
947+
sprintf(ifname, "veth%d", portid);
948+
kni_id = ans_kni_id_get(portid);
949+
950+
printf("add %s device, kni id %d \n", ifname, kni_id);
943951
rte_eth_macaddr_get(portid, &eth_addr);
944-
945-
ans_iface_add(portid, ifname, &eth_addr);
952+
953+
ans_iface_add(portid, kni_id, ifname, &eth_addr);
946954

947955
/* host byte order */
948956
int ip_addr = 0x0a000002;

ans/ans_main.h

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,10 +70,12 @@
7070
#define MAX_TX_QUEUE_PER_PORT RTE_MAX_ETHPORTS
7171
#define MAX_RX_QUEUE_PER_PORT 128
7272

73-
#define CMD_LINE_OPT_CONFIG "config"
74-
#define CMD_LINE_OPT_NO_NUMA "no-numa"
75-
#define CMD_LINE_OPT_ENABLE_KNI "enable-kni"
76-
#define CMD_LINE_OPT_ENABLE_JUMBO "enable-jumbo"
73+
#define CMD_LINE_OPT_CONFIG "config"
74+
#define CMD_LINE_OPT_NO_NUMA "no-numa"
75+
#define CMD_LINE_OPT_ENABLE_KNI "enable-kni"
76+
#define CMD_LINE_OPT_ENABLE_JUMBO "enable-jumbo"
77+
#define CMD_LINE_OPT_ENABLE_IPSYNC "enable-ipsync"
78+
7779

7880
#define MAX_LCORE_PARAMS 512
7981

@@ -106,6 +108,7 @@ struct ans_user_config
106108
uint32_t port_mask;
107109
uint8_t promiscuous_on; /* Ports set in promiscuous mode off by default. */
108110
uint8_t kni_on; /* kni is disable by default. */
111+
uint8_t ipsync_on; /* ipsync is disable by default. sync ip/route from kernel, if ipsync is enable, kni shall also enable */
109112
uint8_t numa_on ; /* NUMA is enabled by default. */
110113
uint8_t jumbo_frame_on;
111114
uint16_t max_rx_pkt_len;

ans/ans_param.c

Lines changed: 40 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,7 @@ static void ans_print_usage(const char *prgname)
172172
" --config (port,queue,lcore): rx queues configuration\n"
173173
" --no-numa: optional, disable numa awareness\n"
174174
" --enable-kni: optional, disable kni awareness\n"
175+
" --enable-ipsync: optional, sync ip/route from kernel kni interface\n"
175176
" --enable-jumbo: enable jumbo frame"
176177
" which max packet len is PKTLEN in decimal (64-9600)\n",
177178
prgname);
@@ -326,6 +327,7 @@ int ans_parse_args(int argc, char **argv, struct ans_user_config *user_conf)
326327
{CMD_LINE_OPT_CONFIG, 1, 0, 0},
327328
{CMD_LINE_OPT_NO_NUMA, 0, 0, 0},
328329
{CMD_LINE_OPT_ENABLE_KNI, 0, 0, 0},
330+
{CMD_LINE_OPT_ENABLE_IPSYNC, 0, 0, 0},
329331
{CMD_LINE_OPT_ENABLE_JUMBO, 0, 0, 0},
330332
{NULL, 0, 0, 0}
331333
};
@@ -357,48 +359,54 @@ int ans_parse_args(int argc, char **argv, struct ans_user_config *user_conf)
357359
/* long options */
358360
case 0:
359361
if (!strncmp(lgopts[option_index].name, CMD_LINE_OPT_CONFIG, sizeof (CMD_LINE_OPT_CONFIG)))
360-
{
361-
ret = ans_parse_config(optarg, user_conf);
362-
if (ret)
363-
{
364-
printf("Invalid config\n");
365-
ans_print_usage(prgname);
366-
return -1;
367-
}
362+
{
363+
ret = ans_parse_config(optarg, user_conf);
364+
if (ret)
365+
{
366+
printf("Invalid config\n");
367+
ans_print_usage(prgname);
368+
return -1;
369+
}
368370
}
369371

370372
if (!strncmp(lgopts[option_index].name, CMD_LINE_OPT_NO_NUMA, sizeof(CMD_LINE_OPT_NO_NUMA)))
371-
{
372-
printf("numa is disabled \n");
373-
user_conf->numa_on = 0;
373+
{
374+
printf("numa is disabled \n");
375+
user_conf->numa_on = 0;
374376
}
375377

376378
if (!strncmp(lgopts[option_index].name, CMD_LINE_OPT_ENABLE_KNI, sizeof(CMD_LINE_OPT_ENABLE_KNI)))
377-
{
378-
printf("KNI is enable \n");
379-
user_conf->kni_on = 1;
379+
{
380+
printf("KNI is enable \n");
381+
user_conf->kni_on = 1;
380382
}
381383

384+
if (!strncmp(lgopts[option_index].name, CMD_LINE_OPT_ENABLE_IPSYNC, sizeof(CMD_LINE_OPT_ENABLE_IPSYNC)))
385+
{
386+
printf("IPSYNC is enable \n");
387+
user_conf->ipsync_on = 1;
388+
}
389+
382390
if (!strncmp(lgopts[option_index].name, CMD_LINE_OPT_ENABLE_JUMBO, sizeof (CMD_LINE_OPT_ENABLE_JUMBO)))
383-
{
384-
struct option lenopts = {"max-pkt-len", required_argument, 0, 0};
385-
386-
printf("jumbo frame is enabled - disabling simple TX path\n");
387-
user_conf->jumbo_frame_on = 1;
388-
389-
/* if no max-pkt-len set, use the default value ETHER_MAX_LEN */
390-
if (0 == getopt_long(argc, argvopt, "", &lenopts, &option_index))
391-
{
392-
ret = ans_parse_max_pkt_len(optarg);
393-
if ((ret < 64) || (ret > MAX_JUMBO_PKT_LEN))
394-
{
395-
printf("invalid packet length\n");
396-
ans_print_usage(prgname);
397-
return -1;
391+
{
392+
struct option lenopts = {"max-pkt-len", required_argument, 0, 0};
393+
394+
printf("jumbo frame is enabled - disabling simple TX path\n");
395+
user_conf->jumbo_frame_on = 1;
396+
397+
/* if no max-pkt-len set, use the default value ETHER_MAX_LEN */
398+
if (0 == getopt_long(argc, argvopt, "", &lenopts, &option_index))
399+
{
400+
ret = ans_parse_max_pkt_len(optarg);
401+
if ((ret < 64) || (ret > MAX_JUMBO_PKT_LEN))
402+
{
403+
printf("invalid packet length\n");
404+
ans_print_usage(prgname);
405+
return -1;
406+
}
407+
user_conf->max_rx_pkt_len = ret;
398408
}
399-
user_conf->max_rx_pkt_len = ret;
400-
}
401-
printf("set jumbo frame max packet length to %u\n", (unsigned int)user_conf->max_rx_pkt_len);
409+
printf("set jumbo frame max packet length to %u\n", (unsigned int)user_conf->max_rx_pkt_len);
402410
}
403411
break;
404412

cli/anscli_main.c

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@
5959
#include "anscli_intf.h"
6060

6161

62-
int main(void)
62+
int main(int argc, char **argv)
6363
{
6464
int ret;
6565
int param_num = 8;
@@ -73,13 +73,17 @@ int main(void)
7373
"--proc-type=secondary",
7474
NULL};
7575

76-
7776
rte_log_set_global_level(RTE_LOG_ERR);
7877
ret = rte_eal_init(param_num, param);
7978
if (ret < 0)
8079
rte_panic("Cannot init EAL\n");
81-
82-
anscli_start();
83-
80+
if(argc > 1)
81+
{
82+
anscli_start(argv[1]);
83+
}
84+
else
85+
{
86+
anscli_start(NULL);
87+
}
8488
return 0;
8589
}

librte_ans/include/ans_errno.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -387,7 +387,8 @@
387387
#define ANS_EROUTE 3001 /* Add route failed */
388388
#define ANS_EADDRESS 3002 /* Add ip address failed */
389389
#define ANS_ENEIGHBOR 3003 /* Add neighbor route failed */
390-
#define ANS_EACL 3004 /* Add ACL failed */
390+
#define ANS_EACL 3004 /* Add ACL failed */
391+
#define ANS_ENETLINK 3005 /* parse netlink message failed */
391392

392393

393394
#define ANS_ERRMEM ANS_ENOMEM /* Out of memory error. */

librte_ans/include/ans_init.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ struct ans_init_config
5252
{
5353
uint64_t lcore_mask; /**< lcore which used to run ans */
5454
uint32_t sock_nb; /**< support max sock connection number */
55+
uint8_t ip_sync; /**< 1: enable ip/route sync from kernel, otherwise disable sync */
5556
cpu_set_t cpu_set; /**< system default cpu set */
5657
struct rte_mempool *pktmbuf_pool[ANS_MAX_NB_SOCKETS]; /**< mbuf pools for each sockets */
5758

librte_ans/include/ans_ip_intf.h

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,8 @@
7777
*
7878
* @param port
7979
* port of the interface
80+
* @param kni_index
81+
* kni index in kernel
8082
* @param if_name
8183
* name of the interface
8284
* @param mac_addr
@@ -85,7 +87,7 @@
8587
* @return 0 - SUCCESS, non-zero - FAILURE
8688
*
8789
*/
88-
int ans_iface_add(uint8_t port, char *if_name, struct ether_addr *mac_addr);
90+
int ans_iface_add(uint8_t port, uint16_t kni_index, char *if_name, struct ether_addr *mac_addr);
8991

9092
/**
9193
* Delete an interface.
@@ -130,9 +132,9 @@ int ans_iface_set_mtu(char *if_name, uint16_t mtu);
130132
* Routing table addition.
131133
*
132134
* @param dest_ipaddr
133-
* ip address of the destination for which the route is being added
135+
* ip address of the destination for which the route is being added, host byte order
134136
* @param gateway_addr
135-
* ip address of gateway
137+
* ip address of gateway, host byte order
136138
* @param netmask
137139
* netmask to be used with route
138140
*
@@ -145,7 +147,7 @@ int ans_add_route(uint32_t dest_ipaddr, uint8_t netmask, uint32_t gateway_addr);
145147
* Routing table deletion.
146148
*
147149
* @param dest_ipaddr
148-
* ip address of the destination for which the route is being deleted
150+
* ip address of the destination for which the route is being deleted, host byte order.
149151
* @param netmask
150152
* netmask to be used with route
151153
*
@@ -169,7 +171,7 @@ int ans_del_route(uint32_t dest_ipaddr, uint8_t netmask);
169171
* @param ifname
170172
* interface name
171173
* @param ip_addr
172-
* IP address
174+
* IP address, host byte order
173175
* @param netmask
174176
* netmask length
175177
*
@@ -184,7 +186,7 @@ int ans_add_ipaddr(char *ifname, uint32_t ip_addr, uint8_t netmask);
184186
* @param ifname
185187
* interface name
186188
* @param ip_addr
187-
* IP address
189+
* IP address, host byte order
188190
* @param netmask
189191
* netmask length
190192
*

librte_ans/librte_ans_broadwell.a

15.1 KB
Binary file not shown.

librte_ans/librte_ans_core2.a

15.1 KB
Binary file not shown.

0 commit comments

Comments
 (0)