Changeset View
Changeset View
Standalone View
Standalone View
head/tools/tools/netmap/vale-ctl.c
Show First 20 Lines • Show All 76 Lines • ▼ Show 20 Lines | void parse_nmr_config(const char* conf, struct nmreq *nmr) | ||||
} | } | ||||
D("txr %d txd %d rxr %d rxd %d", | D("txr %d txd %d rxr %d rxd %d", | ||||
nmr->nr_tx_rings, nmr->nr_tx_slots, | nmr->nr_tx_rings, nmr->nr_tx_slots, | ||||
nmr->nr_rx_rings, nmr->nr_rx_slots); | nmr->nr_rx_rings, nmr->nr_rx_slots); | ||||
free(w); | free(w); | ||||
} | } | ||||
static int | static int | ||||
bdg_ctl(const char *name, int nr_cmd, int nr_arg, char *nmr_config) | bdg_ctl(const char *name, int nr_cmd, int nr_arg, char *nmr_config, int nr_arg2) | ||||
{ | { | ||||
struct nmreq nmr; | struct nmreq nmr; | ||||
int error = 0; | int error = 0; | ||||
int fd = open("/dev/netmap", O_RDWR); | int fd = open("/dev/netmap", O_RDWR); | ||||
if (fd == -1) { | if (fd == -1) { | ||||
D("Unable to open /dev/netmap"); | D("Unable to open /dev/netmap"); | ||||
return -1; | return -1; | ||||
} | } | ||||
bzero(&nmr, sizeof(nmr)); | bzero(&nmr, sizeof(nmr)); | ||||
nmr.nr_version = NETMAP_API; | nmr.nr_version = NETMAP_API; | ||||
if (name != NULL) /* might be NULL */ | if (name != NULL) /* might be NULL */ | ||||
strncpy(nmr.nr_name, name, sizeof(nmr.nr_name)); | strncpy(nmr.nr_name, name, sizeof(nmr.nr_name)-1); | ||||
nmr.nr_cmd = nr_cmd; | nmr.nr_cmd = nr_cmd; | ||||
parse_nmr_config(nmr_config, &nmr); | parse_nmr_config(nmr_config, &nmr); | ||||
nmr.nr_arg2 = nr_arg2; | |||||
switch (nr_cmd) { | switch (nr_cmd) { | ||||
case NETMAP_BDG_DELIF: | case NETMAP_BDG_DELIF: | ||||
case NETMAP_BDG_NEWIF: | case NETMAP_BDG_NEWIF: | ||||
error = ioctl(fd, NIOCREGIF, &nmr); | error = ioctl(fd, NIOCREGIF, &nmr); | ||||
if (error == -1) { | if (error == -1) { | ||||
ND("Unable to %s %s", nr_cmd == NETMAP_BDG_DELIF ? "delete":"create", name); | ND("Unable to %s %s", nr_cmd == NETMAP_BDG_DELIF ? "delete":"create", name); | ||||
perror(name); | perror(name); | ||||
▲ Show 20 Lines • Show All 80 Lines • ▼ Show 20 Lines | default: /* GINFO */ | ||||
} else | } else | ||||
D("%s: %d queues.", name, nmr.nr_rx_rings); | D("%s: %d queues.", name, nmr.nr_rx_rings); | ||||
break; | break; | ||||
} | } | ||||
close(fd); | close(fd); | ||||
return error; | return error; | ||||
} | } | ||||
int | static void | ||||
main(int argc, char *argv[]) | usage(int errcode) | ||||
{ | { | ||||
int ch, nr_cmd = 0, nr_arg = 0; | |||||
const char *command = basename(argv[0]); | |||||
char *name = NULL, *nmr_config = NULL; | |||||
if (argc > 5) { | |||||
usage: | |||||
fprintf(stderr, | fprintf(stderr, | ||||
"Usage:\n" | "Usage:\n" | ||||
"%s arguments\n" | "vale-ctl arguments\n" | ||||
"\t-g interface interface name to get info\n" | "\t-g interface interface name to get info\n" | ||||
"\t-d interface interface name to be detached\n" | "\t-d interface interface name to be detached\n" | ||||
"\t-a interface interface name to be attached\n" | "\t-a interface interface name to be attached\n" | ||||
"\t-h interface interface name to be attached with the host stack\n" | "\t-h interface interface name to be attached with the host stack\n" | ||||
"\t-n interface interface name to be created\n" | "\t-n interface interface name to be created\n" | ||||
"\t-r interface interface name to be deleted\n" | "\t-r interface interface name to be deleted\n" | ||||
"\t-l list all or specified bridge's interfaces (default)\n" | "\t-l list all or specified bridge's interfaces (default)\n" | ||||
"\t-C string ring/slot setting of an interface creating by -n\n" | "\t-C string ring/slot setting of an interface creating by -n\n" | ||||
"\t-p interface start polling. Additional -C x,y,z configures\n" | "\t-p interface start polling. Additional -C x,y,z configures\n" | ||||
"\t\t x: 0 (REG_ALL_NIC) or 1 (REG_ONE_NIC),\n" | "\t\t x: 0 (REG_ALL_NIC) or 1 (REG_ONE_NIC),\n" | ||||
"\t\t y: CPU core id for ALL_NIC and core/ring for ONE_NIC\n" | "\t\t y: CPU core id for ALL_NIC and core/ring for ONE_NIC\n" | ||||
"\t\t z: (ONE_NIC only) num of total cores/rings\n" | "\t\t z: (ONE_NIC only) num of total cores/rings\n" | ||||
"\t-P interface stop polling\n" | "\t-P interface stop polling\n" | ||||
"", command); | "\t-m memid to use when creating a new interface\n"); | ||||
return 0; | exit(errcode); | ||||
} | } | ||||
while ((ch = getopt(argc, argv, "d:a:h:g:l:n:r:C:p:P:")) != -1) { | int | ||||
if (ch != 'C') | main(int argc, char *argv[]) | ||||
{ | |||||
int ch, nr_cmd = 0, nr_arg = 0; | |||||
char *name = NULL, *nmr_config = NULL; | |||||
int nr_arg2 = 0; | |||||
while ((ch = getopt(argc, argv, "d:a:h:g:l:n:r:C:p:P:m:")) != -1) { | |||||
if (ch != 'C' && ch != 'm') | |||||
name = optarg; /* default */ | name = optarg; /* default */ | ||||
switch (ch) { | switch (ch) { | ||||
default: | default: | ||||
fprintf(stderr, "bad option %c %s", ch, optarg); | fprintf(stderr, "bad option %c %s", ch, optarg); | ||||
goto usage; | usage(-1); | ||||
break; | |||||
case 'd': | case 'd': | ||||
nr_cmd = NETMAP_BDG_DETACH; | nr_cmd = NETMAP_BDG_DETACH; | ||||
break; | break; | ||||
case 'a': | case 'a': | ||||
nr_cmd = NETMAP_BDG_ATTACH; | nr_cmd = NETMAP_BDG_ATTACH; | ||||
break; | break; | ||||
case 'h': | case 'h': | ||||
nr_cmd = NETMAP_BDG_ATTACH; | nr_cmd = NETMAP_BDG_ATTACH; | ||||
nr_arg = NETMAP_BDG_HOST; | nr_arg = NETMAP_BDG_HOST; | ||||
break; | break; | ||||
case 'n': | case 'n': | ||||
nr_cmd = NETMAP_BDG_NEWIF; | nr_cmd = NETMAP_BDG_NEWIF; | ||||
break; | break; | ||||
case 'r': | case 'r': | ||||
nr_cmd = NETMAP_BDG_DELIF; | nr_cmd = NETMAP_BDG_DELIF; | ||||
break; | break; | ||||
case 'g': | case 'g': | ||||
nr_cmd = 0; | nr_cmd = 0; | ||||
break; | break; | ||||
case 'l': | case 'l': | ||||
nr_cmd = NETMAP_BDG_LIST; | nr_cmd = NETMAP_BDG_LIST; | ||||
if (optind < argc && argv[optind][0] == '-') | |||||
name = NULL; | |||||
break; | break; | ||||
case 'C': | case 'C': | ||||
nmr_config = strdup(optarg); | nmr_config = strdup(optarg); | ||||
break; | break; | ||||
case 'p': | case 'p': | ||||
nr_cmd = NETMAP_BDG_POLLING_ON; | nr_cmd = NETMAP_BDG_POLLING_ON; | ||||
break; | break; | ||||
case 'P': | case 'P': | ||||
nr_cmd = NETMAP_BDG_POLLING_OFF; | nr_cmd = NETMAP_BDG_POLLING_OFF; | ||||
break; | break; | ||||
case 'm': | |||||
nr_arg2 = atoi(optarg); | |||||
break; | |||||
} | } | ||||
} | } | ||||
if (optind != argc) { | if (optind != argc) { | ||||
// fprintf(stderr, "optind %d argc %d\n", optind, argc); | // fprintf(stderr, "optind %d argc %d\n", optind, argc); | ||||
goto usage; | usage(-1); | ||||
} | } | ||||
if (argc == 1) | if (argc == 1) { | ||||
nr_cmd = NETMAP_BDG_LIST; | nr_cmd = NETMAP_BDG_LIST; | ||||
return bdg_ctl(name, nr_cmd, nr_arg, nmr_config) ? 1 : 0; | name = NULL; | ||||
} | |||||
return bdg_ctl(name, nr_cmd, nr_arg, nmr_config, nr_arg2) ? 1 : 0; | |||||
} | } |