Skip to content

Commit c4c89ef

Browse files
committed
CONTAINER(DOCKER): support aggregation model while running in container with OVS-DPDK, refer to F-Stack#298.
1 parent 8891572 commit c4c89ef

File tree

3 files changed

+126
-1
lines changed

3 files changed

+126
-1
lines changed

config.ini

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@ idle_sleep=0
3636
# 1-3,4,7 ports 1,2,3,4,7 are enabled
3737
port_list=0
3838

39+
# Number of vdev.
40+
nb_vdev=0
41+
3942
# Port config section
4043
# Correspond to dpdk.port_list's index: port0, port1...
4144
[port0]
@@ -51,6 +54,22 @@ gateway=192.168.1.1
5154
# Packet capture path, this will hurt performance
5255
#pcap=./a.pcap
5356

57+
# Vdev config section
58+
# orrespond to dpdk.nb_vdev's index: vdev0, vdev1...
59+
# iface : Shouldn't set always.
60+
# path : The vuser device path in container. Required.
61+
# queues : The max queues of vuser. Optional, default 1, greater or equal to the number of processes.
62+
# queue_size : Queue size.Optional, default 256.
63+
# mac : The mac address of vuser. Optional, default random, if vhost use phy NIC, it should be set to the phy NIC's mac.
64+
# cq : Optional, if queues = 1, default 0; if queues > 1 default 1.
65+
#[vdev0]
66+
##iface=/usr/local/var/run/openvswitch/vhost-user0
67+
#path=/var/run/openvswitch/vhost-user0
68+
#queues=1
69+
#queue_size=256
70+
#mac=00:00:00:00:00:01
71+
#cq=0
72+
5473
# Kni config: if enabled and method=reject,
5574
# all packets that do not belong to the following tcp_port and udp_port
5675
# will transmit to kernel; if method=accept, all packets that belong to

lib/ff_config.c

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -402,6 +402,61 @@ port_cfg_handler(struct ff_config *cfg, const char *section,
402402
return 1;
403403
}
404404

405+
static int
406+
vdev_cfg_handler(struct ff_config *cfg, const char *section,
407+
const char *name, const char *value) {
408+
409+
if (cfg->dpdk.nb_vdev == 0) {
410+
fprintf(stderr, "vdev_cfg_handler: must config dpdk.nb_vdev first\n");
411+
return 0;
412+
}
413+
414+
if (cfg->dpdk.vdev_cfgs == NULL) {
415+
struct ff_vdev_cfg *vc = calloc(RTE_MAX_ETHPORTS, sizeof(struct ff_vdev_cfg));
416+
if (vc == NULL) {
417+
fprintf(stderr, "vdev_cfg_handler malloc failed\n");
418+
return 0;
419+
}
420+
cfg->dpdk.vdev_cfgs = vc;
421+
}
422+
423+
int vdevid;
424+
int ret = sscanf(section, "vdev%d", &vdevid);
425+
if (ret != 1) {
426+
fprintf(stderr, "vdev_cfg_handler section[%s] error\n", section);
427+
return 0;
428+
}
429+
430+
/* just return true if vdevid >= nb_vdev because it has no effect */
431+
if (vdevid > cfg->dpdk.nb_vdev) {
432+
fprintf(stderr, "vdev_cfg_handler section[%s] bigger than max vdev id\n", section);
433+
return 1;
434+
}
435+
436+
struct ff_vdev_cfg *cur = &cfg->dpdk.vdev_cfgs[vdevid];
437+
if (cur->name == NULL) {
438+
cur->name = strdup(section);
439+
cur->vdev_id = vdevid;
440+
}
441+
442+
if (strcmp(name, "iface") == 0) {
443+
cur->iface = strdup(value);
444+
} else if (strcmp(name, "path") == 0) {
445+
cur->path = strdup(value);
446+
} else if (strcmp(name, "queues") == 0) {
447+
cur->nb_queues = atoi(value);
448+
} else if (strcmp(name, "queue_size") == 0) {
449+
cur->queue_size = atoi(value);
450+
} else if (strcmp(name, "mac") == 0) {
451+
cur->mac = strdup(value);
452+
} else if (strcmp(name, "cq") == 0) {
453+
cur->nb_cq = atoi(value);
454+
}
455+
456+
return 1;
457+
}
458+
459+
405460
static int
406461
ini_parse_handler(void* user, const char* section, const char* name,
407462
const char* value)
@@ -424,6 +479,8 @@ ini_parse_handler(void* user, const char* section, const char* name,
424479
pconfig->dpdk.base_virtaddr= strdup(value);
425480
} else if (MATCH("dpdk", "port_list")) {
426481
return parse_port_list(pconfig, value);
482+
} else if (MATCH("dpdk", "nb_vdev")) {
483+
pconfig->dpdk.nb_vdev = atoi(value);
427484
} else if (MATCH("dpdk", "promiscuous")) {
428485
pconfig->dpdk.promiscuous = atoi(value);
429486
} else if (MATCH("dpdk", "numa_on")) {
@@ -456,6 +513,8 @@ ini_parse_handler(void* user, const char* section, const char* name,
456513
return freebsd_conf_handler(pconfig, "sysctl", name, value);
457514
} else if (strncmp(section, "port", 4) == 0) {
458515
return port_cfg_handler(pconfig, section, name, value);
516+
} else if (strncmp(section, "vdev", 4) == 0) {
517+
return vdev_cfg_handler(pconfig, section, name, value);
459518
}
460519

461520
return 1;
@@ -492,8 +551,40 @@ dpdk_args_setup(struct ff_config *cfg)
492551
dpdk_argv[n++] = strdup(temp);
493552
}
494553

554+
if (cfg->dpdk.nb_vdev) {
555+
for (i=0; i<cfg->dpdk.nb_vdev; i++) {
556+
sprintf(temp, "--vdev=virtio_user%d,path=%s",
557+
cfg->dpdk.vdev_cfgs[i].vdev_id,
558+
cfg->dpdk.vdev_cfgs[i].path);
559+
if (cfg->dpdk.vdev_cfgs[i].nb_queues) {
560+
sprintf(temp, "%s,queues=%u",
561+
temp, cfg->dpdk.vdev_cfgs[i].nb_queues);
562+
}
563+
if (cfg->dpdk.vdev_cfgs[i].nb_cq) {
564+
sprintf(temp, "%s,cq=%u",
565+
temp, cfg->dpdk.vdev_cfgs[i].nb_cq);
566+
}
567+
if (cfg->dpdk.vdev_cfgs[i].queue_size) {
568+
sprintf(temp, "%s,queue_size=%u",
569+
temp, cfg->dpdk.vdev_cfgs[i].queue_size);
570+
}
571+
if (cfg->dpdk.vdev_cfgs[i].mac) {
572+
sprintf(temp, "%s,mac=%s",
573+
temp, cfg->dpdk.vdev_cfgs[i].mac);
574+
}
575+
dpdk_argv[n++] = strdup(temp);
576+
}
577+
sprintf(temp, "--no-pci");
578+
dpdk_argv[n++] = strdup(temp);
579+
sprintf(temp, "--file-prefix=container");
580+
dpdk_argv[n++] = strdup(temp);
581+
}
582+
495583
dpdk_argc = n;
496584

585+
for (i=0; i<n; i++)
586+
printf("%s ", dpdk_argv[i]);
587+
497588
return n;
498589
}
499590

lib/ff_config.h

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ extern "C" {
3333

3434
// dpdk argc, argv, max argc: 16, member of dpdk_config
3535
#define DPDK_CONFIG_NUM 16
36-
#define DPDK_CONFIG_MAXLEN 64
36+
#define DPDK_CONFIG_MAXLEN 256
3737
#define DPDK_MAX_LCORE 128
3838

3939
extern int dpdk_argc;
@@ -62,6 +62,19 @@ struct ff_port_cfg {
6262
uint16_t lcore_list[DPDK_MAX_LCORE];
6363
};
6464

65+
struct ff_vdev_cfg {
66+
char *name;
67+
char *iface;
68+
char *path;
69+
char *mac;
70+
uint8_t vdev_id;
71+
uint8_t nb_queues;
72+
uint8_t nb_cq;
73+
uint16_t queue_size;
74+
};
75+
76+
77+
6578
struct ff_freebsd_cfg {
6679
char *name;
6780
char *str;
@@ -88,6 +101,7 @@ struct ff_config {
88101
int nb_procs;
89102
int proc_id;
90103
int promiscuous;
104+
int nb_vdev;
91105
int numa_on;
92106
int tso;
93107
int vlan_strip;
@@ -103,6 +117,7 @@ struct ff_config {
103117
uint16_t *portid_list;
104118
// MAP(portid => struct ff_port_cfg*)
105119
struct ff_port_cfg *port_cfgs;
120+
struct ff_vdev_cfg *vdev_cfgs;
106121
} dpdk;
107122

108123
struct {

0 commit comments

Comments
 (0)