1
2 /*
3 * src/lib/cli/qdisc/plug.c plug module for CLI lib
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation version 2.1
8 * of the License.
9 *
10 * Copyright (c) 2012 Shriram Rajagopalan <rshriram@cs.ubc.ca>
11 */
12
13 #include <netlink/cli/utils.h>
14 #include <netlink/cli/tc.h>
15 #include <netlink/route/qdisc/plug.h>
16
print_usage(void)17 static void print_usage(void)
18 {
19 printf(
20 "Usage: nl-qdisc-add [...] plug [OPTIONS]...\n"
21 "\n"
22 "OPTIONS\n"
23 " --help Show this help text.\n"
24 " --limit Maximum queue length in bytes.\n"
25 " --buffer create a new buffer(plug) and queue incoming traffic into it.\n"
26 " --release-one release traffic from previous buffer.\n"
27 " --release-indefinite stop buffering and release all (buffered and new) packets.\n"
28 "\n"
29 "EXAMPLE"
30 " # Attach plug qdisc with 32KB queue size to ifb0\n"
31 " nl-qdisc-add --dev=ifb0 --parent=root plug --limit=32768\n"
32 " # Plug network traffic arriving at ifb0\n"
33 " nl-qdisc-add --dev=ifb0 --parent=root --update plug --buffer\n"
34 " # Unplug traffic arriving at ifb0 indefinitely\n"
35 " nl-qdisc-add --dev=ifb0 --parent=root --update plug --release-indefinite\n\n"
36 " # If operating in output buffering mode:\n"
37 " # at time t=t0, create a new output buffer b0 to hold network output\n"
38 " nl-qdisc-add --dev=ifb0 --parent=root --update plug --buffer\n\n"
39 " # at time t=t1, take a checkpoint c0, create a new output buffer b1\n"
40 " nl-qdisc-add --dev=ifb0 --parent=root --update plug --buffer\n"
41 " # at time t=t1+r, after c0 is committed, release b0\n"
42 " nl-qdisc-add --dev=ifb0 --parent=root --update plug --release-one\n\n"
43 " # at time t=t2, take a checkpoint c1, create a new output buffer b2\n"
44 " nl-qdisc-add --dev=ifb0 --parent=root --update plug --buffer\n"
45 " # at time t=t2+r, after c1 is committed, release b1\n"
46 " nl-qdisc-add --dev=ifb0 --parent=root --update plug --release-one\n");
47 }
48
plug_parse_argv(struct rtnl_tc * tc,int argc,char ** argv)49 static void plug_parse_argv(struct rtnl_tc *tc, int argc, char **argv)
50 {
51 struct rtnl_qdisc *qdisc = (struct rtnl_qdisc *) tc;
52
53 for (;;) {
54 int c, optidx = 0;
55 enum {
56 ARG_LIMIT = 257,
57 ARG_BUFFER = 258,
58 ARG_RELEASE_ONE = 259,
59 ARG_RELEASE_INDEFINITE = 260,
60 };
61 static struct option long_opts[] = {
62 { "help", 0, 0, 'h' },
63 { "limit", 1, 0, ARG_LIMIT },
64 { "buffer", 0, 0, ARG_BUFFER },
65 { "release-one", 0, 0, ARG_RELEASE_ONE },
66 { "release-indefinite", 0, 0, ARG_RELEASE_INDEFINITE },
67 { 0, 0, 0, 0 }
68 };
69
70 c = getopt_long(argc, argv, "h", long_opts, &optidx);
71 if (c == -1)
72 break;
73
74 switch (c) {
75 case 'h':
76 print_usage();
77 return;
78
79 case ARG_LIMIT:
80 rtnl_qdisc_plug_set_limit(qdisc, nl_cli_parse_u32(optarg));
81 break;
82
83 case ARG_BUFFER:
84 rtnl_qdisc_plug_buffer(qdisc);
85 break;
86
87 case ARG_RELEASE_ONE:
88 rtnl_qdisc_plug_release_one(qdisc);
89 break;
90
91 case ARG_RELEASE_INDEFINITE:
92 rtnl_qdisc_plug_release_indefinite(qdisc);
93 break;
94 }
95 }
96 }
97
98 static struct nl_cli_tc_module plug_module =
99 {
100 .tm_name = "plug",
101 .tm_type = RTNL_TC_TYPE_QDISC,
102 .tm_parse_argv = plug_parse_argv,
103 };
104
plug_init(void)105 static void __init plug_init(void)
106 {
107 nl_cli_tc_register(&plug_module);
108 }
109
plug_exit(void)110 static void __exit plug_exit(void)
111 {
112 nl_cli_tc_unregister(&plug_module);
113 }
114