示例#1
0
文件: hfsc.c 项目: Happy-Ferret/libnl
static void hfsc_parse_class_argv(struct rtnl_tc *tc, int argc, char **argv)
{
	struct rtnl_class *class = (struct rtnl_class *) tc;
	int arg_ok = 0, ret = -EINVAL;

	for (;;) {
		int c, optidx = 0;
		enum {
			ARG_RT = 257,
			ARG_LS = 258,
			ARG_SC,
			ARG_UL,
		};
		static struct option long_opts[] = {
			{ "help", 0, 0, 'h' },
			{ "rt", 1, 0, ARG_RT },
			{ "ls", 1, 0, ARG_LS },
			{ "sc", 1, 0, ARG_SC },
			{ "ul", 1, 0, ARG_UL },
			{ 0, 0, 0, 0 }
		};
		struct tc_service_curve tsc;

		c = getopt_long(argc, argv, "h", long_opts, &optidx);
		if (c == -1)
			break;

		switch (c) {
		case 'h':
			print_class_usage();
			return;

		case ARG_RT:
			ret = hfsc_get_sc(optarg, &tsc);
			if (ret < 0) {
				nl_cli_fatal(ret, "Unable to parse sc "
					"\"%s\": Invalid format.", optarg);
			}

			rtnl_class_hfsc_set_rsc(class, &tsc);
			arg_ok++;
			break;

		case ARG_LS:
			ret = hfsc_get_sc(optarg, &tsc);
			if (ret < 0) {
				nl_cli_fatal(ret, "Unable to parse sc "
					"\"%s\": Invalid format.", optarg);
			}

			rtnl_class_hfsc_set_fsc(class, &tsc);
			arg_ok++;
			break;

		case ARG_SC:
			ret = hfsc_get_sc(optarg, &tsc);
			if (ret < 0) {
				nl_cli_fatal(ret, "Unable to parse sc "
					"\"%s\": Invalid format.", optarg);
			}

			rtnl_class_hfsc_set_rsc(class, &tsc);
			rtnl_class_hfsc_set_fsc(class, &tsc);
			arg_ok++;
			break;

		case ARG_UL:
			ret = hfsc_get_sc(optarg, &tsc);
			if (ret < 0) {
				nl_cli_fatal(ret, "Unable to parse sc "
					"\"%s\": Invalid format.", optarg);
			}

			rtnl_class_hfsc_set_usc(class, &tsc);
			arg_ok++;
			break;
		}
	}

	if (!arg_ok)
		nl_cli_fatal(ret, "Invalid arguments");
}
示例#2
0
static void htb_parse_class_argv(struct rtnl_tc *tc, int argc, char **argv)
{
	struct rtnl_class *class = (struct rtnl_class *) tc;
	long rate;

	for (;;) {
		int c, optidx = 0;
		enum {
			ARG_RATE = 257,
			ARG_QUANTUM = 258,
			ARG_CEIL,
			ARG_PRIO,
			ARG_BURST,
			ARG_CBURST,
		};
		static struct option long_opts[] = {
			{ "help", 0, 0, 'h' },
			{ "rate", 1, 0, ARG_RATE },
			{ "quantum", 1, 0, ARG_QUANTUM },
			{ "ceil", 1, 0, ARG_CEIL },
			{ "prio", 1, 0, ARG_PRIO },
			{ "burst", 1, 0, ARG_BURST },
			{ "cburst", 1, 0, ARG_CBURST },
			{ 0, 0, 0, 0 }
		};
	
		c = getopt_long(argc, argv, "h", long_opts, &optidx);
		if (c == -1)
			break;

		switch (c) {
		case 'h':
			print_class_usage();
			return;

		case ARG_RATE:
			rate = nl_size2int(optarg);
			if (rate < 0) {
				nl_cli_fatal(rate, "Unable to parse htb rate "
					"\"%s\": Invalid format.", optarg);
			}

			rtnl_htb_set_rate(class, rate);
			break;

		case ARG_CEIL:
			rate = nl_size2int(optarg);
			if (rate < 0) {
				nl_cli_fatal(rate, "Unable to parse htb ceil rate "
					"\"%s\": Invalid format.", optarg);
			}

			rtnl_htb_set_ceil(class, rate);
			break;

		case ARG_PRIO:
			rtnl_htb_set_prio(class, nl_cli_parse_u32(optarg));
			break;

		case ARG_QUANTUM:
			rate = nl_size2int(optarg);
			if (rate < 0) {
				nl_cli_fatal(rate, "Unable to parse quantum "
					"\"%s\": Invalid format.", optarg);
			}

			rtnl_htb_set_quantum(class, rate);
			break;

		case ARG_BURST:
			rate = nl_size2int(optarg);
			if (rate < 0) {
				nl_cli_fatal(rate, "Unable to parse burst "
					"\"%s\": Invalid format.", optarg);
			}

			rtnl_htb_set_rbuffer(class, rate);
			break;

		case ARG_CBURST:
			rate = nl_size2int(optarg);
			if (rate < 0) {
				nl_cli_fatal(rate, "Unable to parse cburst "
					"\"%s\": Invalid format.", optarg);
			}

			rtnl_htb_set_cbuffer(class, rate);
			break;
		}
 	}
}