libnl 3.9.0
plug.c
1/* SPDX-License-Identifier: LGPL-2.1-only */
2/*
3 * Copyright (c) 2012 Shriram Rajagopalan <rshriram@cs.ubc.ca>
4 */
5
6#include "nl-default.h"
7
8#include <netlink/cli/utils.h>
9#include <netlink/cli/tc.h>
10#include <netlink/route/qdisc/plug.h>
11
12static void print_usage(void)
13{
14 printf(
15"Usage: nl-qdisc-add [...] plug [OPTIONS]...\n"
16"\n"
17"OPTIONS\n"
18" --help Show this help text.\n"
19" --limit Maximum queue length in bytes.\n"
20" --buffer create a new buffer(plug) and queue incoming traffic into it.\n"
21" --release-one release traffic from previous buffer.\n"
22" --release-indefinite stop buffering and release all (buffered and new) packets.\n"
23"\n"
24"EXAMPLE"
25" # Attach plug qdisc with 32KB queue size to ifb0\n"
26" nl-qdisc-add --dev=ifb0 --parent=root plug --limit=32768\n"
27" # Plug network traffic arriving at ifb0\n"
28" nl-qdisc-add --dev=ifb0 --parent=root --update plug --buffer\n"
29" # Unplug traffic arriving at ifb0 indefinitely\n"
30" nl-qdisc-add --dev=ifb0 --parent=root --update plug --release-indefinite\n\n"
31" # If operating in output buffering mode:\n"
32" # at time t=t0, create a new output buffer b0 to hold network output\n"
33" nl-qdisc-add --dev=ifb0 --parent=root --update plug --buffer\n\n"
34" # at time t=t1, take a checkpoint c0, create a new output buffer b1\n"
35" nl-qdisc-add --dev=ifb0 --parent=root --update plug --buffer\n"
36" # at time t=t1+r, after c0 is committed, release b0\n"
37" nl-qdisc-add --dev=ifb0 --parent=root --update plug --release-one\n\n"
38" # at time t=t2, take a checkpoint c1, create a new output buffer b2\n"
39" nl-qdisc-add --dev=ifb0 --parent=root --update plug --buffer\n"
40" # at time t=t2+r, after c1 is committed, release b1\n"
41" nl-qdisc-add --dev=ifb0 --parent=root --update plug --release-one\n");
42}
43
44static void plug_parse_argv(struct rtnl_tc *tc, int argc, char **argv)
45{
46 struct rtnl_qdisc *qdisc = (struct rtnl_qdisc *) tc;
47
48 for (;;) {
49 int c, optidx = 0;
50 enum {
51 ARG_LIMIT = 257,
52 ARG_BUFFER = 258,
53 ARG_RELEASE_ONE = 259,
54 ARG_RELEASE_INDEFINITE = 260,
55 };
56 static struct option long_opts[] = {
57 { "help", 0, 0, 'h' },
58 { "limit", 1, 0, ARG_LIMIT },
59 { "buffer", 0, 0, ARG_BUFFER },
60 { "release-one", 0, 0, ARG_RELEASE_ONE },
61 { "release-indefinite", 0, 0, ARG_RELEASE_INDEFINITE },
62 { 0, 0, 0, 0 }
63 };
64
65 c = getopt_long(argc, argv, "h", long_opts, &optidx);
66 if (c == -1)
67 break;
68
69 switch (c) {
70 case 'h':
71 print_usage();
72 return;
73
74 case ARG_LIMIT:
76 break;
77
78 case ARG_BUFFER:
80 break;
81
82 case ARG_RELEASE_ONE:
84 break;
85
86 case ARG_RELEASE_INDEFINITE:
88 break;
89 }
90 }
91}
92
93static struct nl_cli_tc_module plug_module =
94{
95 .tm_name = "plug",
96 .tm_type = RTNL_TC_TYPE_QDISC,
97 .tm_parse_argv = plug_parse_argv,
98};
99
100static void _nl_init plug_init(void)
101{
102 nl_cli_tc_register(&plug_module);
103}
104
105static void _nl_exit plug_exit(void)
106{
107 nl_cli_tc_unregister(&plug_module);
108}
uint32_t nl_cli_parse_u32(const char *arg)
Parse a text based 32 bit unsigned integer argument.
Definition utils.c:36
int rtnl_qdisc_plug_release_indefinite(struct rtnl_qdisc *qdisc)
Indefinitely unplug the qdisc, releasing all packets.
Definition plug.c:128
int rtnl_qdisc_plug_release_one(struct rtnl_qdisc *qdisc)
Unplug the qdisc, releasing packets from queue head to the last complete buffer, while new traffic co...
Definition plug.c:111
int rtnl_qdisc_plug_buffer(struct rtnl_qdisc *qdisc)
Insert a plug into the qdisc and buffer any incoming network traffic.
Definition plug.c:94
int rtnl_qdisc_plug_set_limit(struct rtnl_qdisc *qdisc, int limit)
Set limit of PLUG qdisc.
Definition plug.c:145