Beispiel #1
0
/*  Parse the argument (num_pools) given in the command line of the application */
static int
vmdq_parse_args(int argc, char **argv)
{
	int opt;
	int option_index;
	unsigned i;
	const char *prgname = argv[0];
	static struct option long_option[] = {
		{"nb-pools", required_argument, NULL, 0},
		{NULL, 0, 0, 0}
	};

	/* Parse command line */
	while ((opt = getopt_long(argc, argv, "p:", long_option,
		&option_index)) != EOF) {
		switch (opt) {
		/* portmask */
		case 'p':
			enabled_port_mask = parse_portmask(optarg);
			if (enabled_port_mask == 0) {
				printf("invalid portmask\n");
				vmdq_usage(prgname);
				return -1;
			}
			break;
		case 0:
			if (vmdq_parse_num_pools(optarg) == -1) {
				printf("invalid number of pools\n");
				vmdq_usage(prgname);
				return -1;
			}
			break;

		default:
			vmdq_usage(prgname);
			return -1;
		}
	}

	for (i = 0; i < RTE_MAX_ETHPORTS; i++) {
		if (enabled_port_mask & (1 << i))
			ports[num_ports++] = (uint8_t)i;
	}

	if (num_ports < 2 || num_ports % 2) {
		printf("Current enabled port number is %u,"
			"but it should be even and at least 2\n", num_ports);
		return -1;
	}

	return 0;
}
Beispiel #2
0
/* Parse the argument given in the command line of the application */
static int parse_args(int argc, char **argv)
{
	int opt, ret;
	char **argvopt;
	int option_index;
	char *prgname = argv[0];
	static struct option lgopts[] = {
		{NULL, 0, 0, 0}
	};
DUMP(argc);
	argvopt = argv;

	while ((opt = getopt_long(argc, argvopt, "p:a:T",
				  lgopts, &option_index)) != EOF) {

		switch (opt) {
		/* portmask */
		case 'p':
			enabled_port_mask = parse_portmask(optarg);
			if (enabled_port_mask == 0) {
				syslog(LOG_ERR,"invalid portmask\n");
				//l2fwd_usage(prgname);
				return -1;
			}
			break;

		/* nqueue */
		case 'q':
			//l2fwd_rx_queue_per_lcore = l2fwd_parse_nqueue(optarg);
			//if (l2fwd_rx_queue_per_lcore == 0) {
				//printf("invalid queue number\n");
				//l2fwd_usage(prgname);
				//return -1;
			//}
			break;

		default:
			//l2fwd_usage(prgname);
			return -1;
		}
	}

	if (optind >= 0)
		argv[optind-1] = prgname;

	ret = optind-1;
	optind = 0; /* reset getopt lib */
	return ret;
}
Beispiel #3
0
/* Parse the argument given in the command line of the application */
static int
parse_args(int argc, char **argv)
{
	int opt;
	int option_index;
	char **argvopt;
	char *prgname = argv[0];
	static struct option lgopts[] = {
		{"disable-reorder", 0, 0, 0},
		{NULL, 0, 0, 0}
	};

	argvopt = argv;

	while ((opt = getopt_long(argc, argvopt, "p:",
					lgopts, &option_index)) != EOF) {
		switch (opt) {
		/* portmask */
		case 'p':
			portmask = parse_portmask(optarg);
			if (portmask == 0) {
				printf("invalid portmask\n");
				print_usage(prgname);
				return -1;
			}
			break;
		/* long options */
		case 0:
			if (!strcmp(lgopts[option_index].name, "disable-reorder")) {
				printf("reorder disabled\n");
				disable_reorder = 1;
			}
			break;
		default:
			print_usage(prgname);
			return -1;
		}
	}
	if (optind <= 1) {
		print_usage(prgname);
		return -1;
	}

	argv[optind-1] = prgname;
	optind = 0; /* reset getopt lib */
	return 0;
}
Beispiel #4
0
/* Parse the argument given in the command line of the application */
static int
parse_args(int argc, char **argv)
{
	int opt, ret;
	char **argvopt;
	int option_index;
	char *prgname = argv[0];
	static struct option lgopts[] = {
		{ "mac-updating", no_argument, 0, 1},
		{ "no-mac-updating", no_argument, 0, 0},
		{NULL, 0, 0, 0}
	};
	argvopt = argv;

	while ((opt = getopt_long(argc, argvopt, "p:q:T:",
				  lgopts, &option_index)) != EOF) {

		switch (opt) {
		/* portmask */
		case 'p':
			enabled_port_mask = parse_portmask(optarg);
			if (enabled_port_mask == 0) {
				printf("invalid portmask\n");
				return -1;
			}
			break;
		/* long options */
		case 0:
			break;

		default:
			return -1;
		}
	}

	if (optind >= 0)
		argv[optind-1] = prgname;

	ret = optind-1;
	optind = 0; /* reset getopt lib */
	return ret;
}
Beispiel #5
0
int
parse_qw_args(int argc, char **argv)
{
    int opt;

    while ((opt = getopt(argc, argv, "h:p:")) != -1) {
        switch (opt) {
        case 'h':
                usage(argv[0]);
                break;
        case 'p':
                portmask = parse_portmask(optarg);
                break;
        default:
                usage(argv[0]);
        }
    }

    check_core_count();
    check_portmask_value(portmask);

    return 0;
}
Beispiel #6
0
/* Parse the argument given in the command line of the application */
static int
proc_info_parse_args(int argc, char **argv)
{
	int opt;
	int option_index;
	char *prgname = argv[0];
	static struct option long_option[] = {
		{"stats", 0, NULL, 0},
		{"stats-reset", 0, NULL, 0},
		{"xstats", 0, NULL, 0},
		{"metrics", 0, NULL, 0},
		{"xstats-reset", 0, NULL, 0},
		{"xstats-name", required_argument, NULL, 1},
		{"collectd-format", 0, NULL, 0},
		{"xstats-ids", 1, NULL, 1},
		{"host-id", 0, NULL, 0},
		{NULL, 0, 0, 0}
	};

	if (argc == 1)
		proc_info_usage(prgname);

	/* Parse command line */
	while ((opt = getopt_long(argc, argv, "p:m",
			long_option, &option_index)) != EOF) {
		switch (opt) {
		/* portmask */
		case 'p':
			enabled_port_mask = parse_portmask(optarg);
			if (enabled_port_mask == 0) {
				printf("invalid portmask\n");
				proc_info_usage(prgname);
				return -1;
			}
			break;
		case 'm':
			mem_info = 1;
			break;
		case 0:
			/* Print stats */
			if (!strncmp(long_option[option_index].name, "stats",
					MAX_LONG_OPT_SZ))
				enable_stats = 1;
			/* Print xstats */
			else if (!strncmp(long_option[option_index].name, "xstats",
					MAX_LONG_OPT_SZ))
				enable_xstats = 1;
			else if (!strncmp(long_option[option_index].name,
					"metrics",
					MAX_LONG_OPT_SZ))
				enable_metrics = 1;
			/* Reset stats */
			if (!strncmp(long_option[option_index].name, "stats-reset",
					MAX_LONG_OPT_SZ))
				reset_stats = 1;
			/* Reset xstats */
			else if (!strncmp(long_option[option_index].name, "xstats-reset",
					MAX_LONG_OPT_SZ))
				reset_xstats = 1;
			break;
		case 1:
			/* Print xstat single value given by name*/
			if (!strncmp(long_option[option_index].name,
					"xstats-name", MAX_LONG_OPT_SZ)) {
				enable_xstats_name = 1;
				xstats_name = optarg;
				printf("name:%s:%s\n",
						long_option[option_index].name,
						optarg);
			} else if (!strncmp(long_option[option_index].name,
					"xstats-ids",
					MAX_LONG_OPT_SZ))	{
				nb_xstats_ids = parse_xstats_ids(optarg,
						xstats_ids, MAX_NB_XSTATS_IDS);

				if (nb_xstats_ids <= 0) {
					printf("xstats-id list parse error.\n");
					return -1;
				}

			}
			break;
		default:
			proc_info_usage(prgname);
			return -1;
		}
	}
	return 0;
}
Beispiel #7
0
/*
 * Parse the arguments given in the command line of the application.
 */
static int
us_vhost_parse_args(int argc, char **argv)
{
	int opt, ret;
	int option_index;
	unsigned i;
	const char *prgname = argv[0];
	static struct option long_option[] = {
		{"vm2vm", required_argument, NULL, 0},
		{"stats", required_argument, NULL, 0},
		{NULL, 0, 0, 0}
	};

	/* Parse command line */
	while ((opt = getopt_long(argc, argv, "p:",long_option, &option_index)) != EOF) {
		switch (opt) {
		/* Portmask */
		case 'p':
			enabled_port_mask = parse_portmask(optarg);
			if (enabled_port_mask == 0) {
				RTE_LOG(INFO, VHOST_CONFIG, "Invalid portmask\n");
				us_vhost_usage(prgname);
				return -1;
			}
			break;

		case 0:
			/* Enable/disable vm2vm comms. */
			if (!strncmp(long_option[option_index].name, "vm2vm", MAX_LONG_OPT_SZ)) {
				ret = parse_num_opt(optarg, 1);
				if (ret == -1) {
					RTE_LOG(INFO, VHOST_CONFIG, "Invalid argument for vm2vm [0|1]\n");
					us_vhost_usage(prgname);
					return -1;
				} else {
					enable_vm2vm = ret;
				}
			}

			/* Enable/disable stats. */
			if (!strncmp(long_option[option_index].name, "stats", MAX_LONG_OPT_SZ)) {
				ret = parse_num_opt(optarg, INT32_MAX);
				if (ret == -1) {
					RTE_LOG(INFO, VHOST_CONFIG, "Invalid argument for stats [0..N]\n");
					us_vhost_usage(prgname);
					return -1;
				} else {
					enable_stats = ret;
				}
			}
			break;

			/* Invalid option - print options. */
		default:
			us_vhost_usage(prgname);
			return -1;
		}
	}

	for (i = 0; i < RTE_MAX_ETHPORTS; i++) {
		if (enabled_port_mask & (1 << i))
			ports[num_ports++] = (uint8_t)i;
	}

	if ((num_ports ==  0) || (num_ports > MAX_SUP_PORTS)) {
		RTE_LOG(INFO, VHOST_PORT, "Current enabled port number is %u,"
			"but only %u port can be enabled\n",num_ports, MAX_SUP_PORTS);
		return -1;
	}

	return 0;
}
Beispiel #8
0
/*
 * Parse the command line arguments passed to the application; the arguments
 * which no not go directly to DPDK's EAL.
 */
static int parse_app_args(int argc, char** argv, app_params* p)
{
    int opt;
    char** argvopt;
    int option_index;
    unsigned int nb_workers;
    static struct option lgopts[] = {
        { NULL, 0, 0, 0 }
    };

    // set default args
    p->enabled_port_mask = parse_portmask(STR(DEFAULT_PORT_MASK));
    p->kafka_topic = STR(DEFAULT_KAFKA_TOPIC);
    p->rx_burst_size = DEFAULT_RX_BURST_SIZE;
    p->tx_burst_size = DEFAULT_TX_BURST_SIZE;
    p->nb_rx_desc = DEFAULT_NB_RX_DESC;
    p->nb_rx_queue = DEFAULT_NB_RX_QUEUE;
    p->tx_ring_size = DEFAULT_TX_RING_SIZE;

    // parse arguments to this application
    argvopt = argv;
    while ((opt = getopt_long(argc, argvopt, "b:c:d:hp:q:s:t:w:x:", lgopts, &option_index)) != EOF) {
        switch (opt) {

            // help
            case 'h':
                print_usage();
                return -1;

            // rx burst size
            case 'b':
                p->rx_burst_size = atoi(optarg);
                if(p->rx_burst_size < 1 || p->rx_burst_size > MAX_RX_BURST_SIZE) {
                    fprintf(stderr, "Invalid burst size; burst=%u must be in [1, %u]. \n", p->rx_burst_size, MAX_RX_BURST_SIZE);
                    print_usage();
                    return -1;
                }
                break;

            // tx burst size
            case 'w':
                p->tx_burst_size = atoi(optarg);
                if(p->tx_burst_size < 1) {
                    fprintf(stderr, "Invalid burst size; burst=%u must be > 0. \n", p->tx_burst_size);
                    print_usage();
                    return -1;
                }
                break;

            // number of receive descriptors
            case 'd':
                p->nb_rx_desc = atoi(optarg);
                if (p->nb_rx_desc < 1) {
                    fprintf(stderr, "Invalid num of receive descriptors: '%s' \n", optarg);
                    print_usage();
                    return -1;
                }
                break;

            // size of each transmit ring
            case 'x':
                p->tx_ring_size = atoi(optarg);

                break;

            // number of receive queues for each device
            case 'q':
                p->nb_rx_queue = atoi(optarg);
                if (p->nb_rx_queue < 1) {
                    fprintf(stderr, "Invalid num of receive queues: '%s' \n", optarg);
                    print_usage();
                    return -1;
                }
                break;

          // port mask
          case 'p':
              p->enabled_port_mask = parse_portmask(optarg);
              if (p->enabled_port_mask == 0) {
                  fprintf(stderr, "Invalid portmask: '%s'\n", optarg);
                  print_usage();
                  return -1;
              }
              break;

          // kafka topic
          case 't':
              p->kafka_topic = strdup(optarg);
              if (!valid(p->kafka_topic)) {
                  printf("Invalid kafka topic: '%s'\n", optarg);
                  print_usage();
                  return -1;
              }
              break;

          // kafka config path
          case 'c':
              p->kafka_config_path = strdup(optarg);
              if (!valid(p->kafka_config_path) || !file_exists(p->kafka_config_path)) {
                  fprintf(stderr, "Invalid kafka config: '%s'\n", optarg);
                  print_usage();
                  return -1;
              }
              break;

          // kafka stats path
          case 's':
              p->kafka_stats_path = strdup(optarg);
              break;

          default:
              print_usage();
              return -1;
          }
    }

    // check number of ethernet devices
    if (rte_eth_dev_count() == 0) {
         rte_exit(EXIT_FAILURE, "No ethernet ports detected.\n");
     }

    // check number of workers
    nb_workers = rte_lcore_count() - 1;

    // need at least 1 worker for each receive queue
    if(nb_workers < p->nb_rx_queue) {
        rte_exit(EXIT_FAILURE, "Minimum 1 worker per receive queue; workers=%u rx_queues=%u. \n",
            nb_workers, p->nb_rx_queue);
    }

    p->nb_rx_workers = p->nb_rx_queue;
    p->nb_tx_workers = nb_workers - p->nb_rx_workers;

    printf("[ -p PORT_MASK ] defined as %d \n", p->enabled_port_mask);
    printf("[ -b RX_BURST_SIZE ] defined as %d \n", p->rx_burst_size);
    printf("[ -w TX_BURST_SIZE ] defined as %d \n", p->tx_burst_size);
    printf("[ -d NB_RX_DESC ] defined as %d \n", p->nb_rx_desc);
    printf("[ -x TX_RING_SIZE ] defined as %d \n", p->tx_ring_size);
    printf("[ -q NB_RX_QUEUE ] defined as %d \n", p->nb_rx_queue);
    printf("[ -t KAFKA_TOPIC ] defined as %s \n", p->kafka_topic);
    printf("[ -c KAFKA_CONFIG ] defined as %s \n", p->kafka_config_path);
    printf("[ -s KAFKA_STATS ] defined as %s \n", p->kafka_stats_path);
    printf("[ NUM_RX_WORKERS ] defined as %d \n", p->nb_rx_workers);
    printf("[ NUM_TX_WORKERS ] defined as %d \n", p->nb_tx_workers);

    // reset getopt lib
    optind = 0;
    return 0;
}
Beispiel #9
0
/**
 * Parse the command line arguments passed to the application.
 */
int parse_args(int argc, char** argv)
{
    int opt;
    char** argvopt;
    int option_index;
    char* prgname = argv[0];
    static struct option lgopts[] = {
        { NULL, 0, 0, 0 }
    };

    // initialize args
    memset(&app, 0, sizeof(struct app_params));

    // parse arguments to this application
    argvopt = argv;
    while ((opt = getopt_long(argc, argvopt, "p:b:t:c:", lgopts, &option_index)) != EOF) {
        switch (opt) {

        // portmask
        case 'p':
            app.enabled_port_mask = parse_portmask(optarg);
            if (app.enabled_port_mask == 0) {
                printf("Error: Invalid portmask: '%s'\n", optarg);
                print_usage(prgname);
                return -1;
            }
            break;

        // kafka topic
        case 't':
            app.kafka_topic = strdup(optarg);
            if (!valid(app.kafka_topic)) {
                printf("Error: Invalid kafka topic: '%s'\n", optarg);
                print_usage(prgname);
                return -1;
            }
            break;

        // kafka config path
        case 'c':
            app.kafka_config_path = strdup(optarg);
            if (!valid(app.kafka_config_path) || !file_exists(app.kafka_config_path)) {
                printf("Error: Invalid kafka config: '%s'\n", optarg);
                print_usage(prgname);
                return -1;
            }
            break;

        default:
            printf("Error: Invalid argument: '%s'\n", optarg);
            print_usage(prgname);
            return -1;
        }
    }

    // check for required command-line arguments
    if (app.enabled_port_mask == 0) {
        printf("Error: Missing -p PORTMASK\n");
        print_usage(prgname);
        return -1;
    }

    if (!valid(app.kafka_topic)) {
        printf("Error: Missing -t KAFKATOPIC\n");
        print_usage(prgname);
        return -1;
    }

    argv[optind - 1] = prgname;

    // reset getopt lib
    optind = 0;
    return 0;
}