libnl  3.6.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 <netlink/cli/utils.h>
7 #include <netlink/cli/tc.h>
8 #include <netlink/route/qdisc/plug.h>
9 
10 static void print_usage(void)
11 {
12  printf(
13 "Usage: nl-qdisc-add [...] plug [OPTIONS]...\n"
14 "\n"
15 "OPTIONS\n"
16 " --help Show this help text.\n"
17 " --limit Maximum queue length in bytes.\n"
18 " --buffer create a new buffer(plug) and queue incoming traffic into it.\n"
19 " --release-one release traffic from previous buffer.\n"
20 " --release-indefinite stop buffering and release all (buffered and new) packets.\n"
21 "\n"
22 "EXAMPLE"
23 " # Attach plug qdisc with 32KB queue size to ifb0\n"
24 " nl-qdisc-add --dev=ifb0 --parent=root plug --limit=32768\n"
25 " # Plug network traffic arriving at ifb0\n"
26 " nl-qdisc-add --dev=ifb0 --parent=root --update plug --buffer\n"
27 " # Unplug traffic arriving at ifb0 indefinitely\n"
28 " nl-qdisc-add --dev=ifb0 --parent=root --update plug --release-indefinite\n\n"
29 " # If operating in output buffering mode:\n"
30 " # at time t=t0, create a new output buffer b0 to hold network output\n"
31 " nl-qdisc-add --dev=ifb0 --parent=root --update plug --buffer\n\n"
32 " # at time t=t1, take a checkpoint c0, create a new output buffer b1\n"
33 " nl-qdisc-add --dev=ifb0 --parent=root --update plug --buffer\n"
34 " # at time t=t1+r, after c0 is committed, release b0\n"
35 " nl-qdisc-add --dev=ifb0 --parent=root --update plug --release-one\n\n"
36 " # at time t=t2, take a checkpoint c1, create a new output buffer b2\n"
37 " nl-qdisc-add --dev=ifb0 --parent=root --update plug --buffer\n"
38 " # at time t=t2+r, after c1 is committed, release b1\n"
39 " nl-qdisc-add --dev=ifb0 --parent=root --update plug --release-one\n");
40 }
41 
42 static void plug_parse_argv(struct rtnl_tc *tc, int argc, char **argv)
43 {
44  struct rtnl_qdisc *qdisc = (struct rtnl_qdisc *) tc;
45 
46  for (;;) {
47  int c, optidx = 0;
48  enum {
49  ARG_LIMIT = 257,
50  ARG_BUFFER = 258,
51  ARG_RELEASE_ONE = 259,
52  ARG_RELEASE_INDEFINITE = 260,
53  };
54  static struct option long_opts[] = {
55  { "help", 0, 0, 'h' },
56  { "limit", 1, 0, ARG_LIMIT },
57  { "buffer", 0, 0, ARG_BUFFER },
58  { "release-one", 0, 0, ARG_RELEASE_ONE },
59  { "release-indefinite", 0, 0, ARG_RELEASE_INDEFINITE },
60  { 0, 0, 0, 0 }
61  };
62 
63  c = getopt_long(argc, argv, "h", long_opts, &optidx);
64  if (c == -1)
65  break;
66 
67  switch (c) {
68  case 'h':
69  print_usage();
70  return;
71 
72  case ARG_LIMIT:
74  break;
75 
76  case ARG_BUFFER:
78  break;
79 
80  case ARG_RELEASE_ONE:
82  break;
83 
84  case ARG_RELEASE_INDEFINITE:
86  break;
87  }
88  }
89 }
90 
91 static struct nl_cli_tc_module plug_module =
92 {
93  .tm_name = "plug",
94  .tm_type = RTNL_TC_TYPE_QDISC,
95  .tm_parse_argv = plug_parse_argv,
96 };
97 
98 static void __init plug_init(void)
99 {
100  nl_cli_tc_register(&plug_module);
101 }
102 
103 static void __exit plug_exit(void)
104 {
105  nl_cli_tc_unregister(&plug_module);
106 }
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:122
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:105
int rtnl_qdisc_plug_buffer(struct rtnl_qdisc *qdisc)
Insert a plug into the qdisc and buffer any incoming network traffic.
Definition: plug.c:88
int rtnl_qdisc_plug_set_limit(struct rtnl_qdisc *qdisc, int limit)
Set limit of PLUG qdisc.
Definition: plug.c:139