blob: f330311d26486cdfad0c2c0040a0e6203e1daf91 [file] [log] [blame]
PJ Waskiewicz292ce962007-08-14 11:21:24 -07001/*
2 * q_rr.c RR.
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; either version
7 * 2 of the License, or (at your option) any later version.
8 *
9 * Authors: PJ Waskiewicz, <peter.p.waskiewicz.jr@intel.com>
10 * Original Authors: Alexey Kuznetsov, <kuznet@ms2.inr.ac.ru> (from PRIO)
PJ Waskiewicz292ce962007-08-14 11:21:24 -070011 */
12
13#include <stdio.h>
14#include <stdlib.h>
15#include <unistd.h>
16#include <syslog.h>
17#include <fcntl.h>
18#include <sys/socket.h>
19#include <netinet/in.h>
20#include <arpa/inet.h>
21#include <string.h>
22
23#include "utils.h"
24#include "tc_util.h"
25
26static void explain(void)
27{
28 fprintf(stderr, "Usage: ... rr bands NUMBER priomap P1 P2... [multiqueue]\n");
29}
30
PJ Waskiewicz292ce962007-08-14 11:21:24 -070031
32static int rr_parse_opt(struct qdisc_util *qu, int argc, char **argv, struct nlmsghdr *n)
33{
PJ Waskiewicz292ce962007-08-14 11:21:24 -070034 int pmap_mode = 0;
35 int idx = 0;
Stephen Hemminger32a121c2016-03-21 11:48:36 -070036 struct tc_prio_qopt opt = {3, { 1, 2, 2, 2, 1, 2, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1 } };
PJ Waskiewicz292ce962007-08-14 11:21:24 -070037 struct rtattr *nest;
38 unsigned char mq = 0;
39
40 while (argc > 0) {
41 if (strcmp(*argv, "bands") == 0) {
42 if (pmap_mode)
43 explain();
44 NEXT_ARG();
45 if (get_integer(&opt.bands, *argv, 10)) {
46 fprintf(stderr, "Illegal \"bands\"\n");
47 return -1;
48 }
PJ Waskiewicz292ce962007-08-14 11:21:24 -070049 } else if (strcmp(*argv, "priomap") == 0) {
50 if (pmap_mode) {
51 fprintf(stderr, "Error: duplicate priomap\n");
52 return -1;
53 }
54 pmap_mode = 1;
55 } else if (strcmp(*argv, "help") == 0) {
56 explain();
57 return -1;
58 } else if (strcmp(*argv, "multiqueue") == 0) {
59 mq = 1;
60 } else {
Stephen Hemminger32a121c2016-03-21 11:48:36 -070061 unsigned int band;
62
PJ Waskiewicz292ce962007-08-14 11:21:24 -070063 if (!pmap_mode) {
64 fprintf(stderr, "What is \"%s\"?\n", *argv);
65 explain();
66 return -1;
67 }
68 if (get_unsigned(&band, *argv, 10)) {
69 fprintf(stderr, "Illegal \"priomap\" element\n");
70 return -1;
71 }
72 if (band > opt.bands) {
73 fprintf(stderr, "\"priomap\" element is out of bands\n");
74 return -1;
75 }
76 if (idx > TC_PRIO_MAX) {
77 fprintf(stderr, "\"priomap\" index > TC_RR_MAX=%u\n", TC_PRIO_MAX);
78 return -1;
79 }
80 opt.priomap[idx++] = band;
81 }
82 argc--; argv++;
83 }
84
85 nest = addattr_nest_compat(n, 1024, TCA_OPTIONS, &opt, sizeof(opt));
86 if (mq)
87 addattr_l(n, 1024, TCA_PRIO_MQ, NULL, 0);
88 addattr_nest_compat_end(n, nest);
89 return 0;
90}
91
Stephen Hemmingerd1f28cf2013-02-12 11:09:03 -080092static int rr_print_opt(struct qdisc_util *qu, FILE *f, struct rtattr *opt)
PJ Waskiewicz292ce962007-08-14 11:21:24 -070093{
94 int i;
95 struct tc_prio_qopt *qopt;
96 struct rtattr *tb[TCA_PRIO_MAX + 1];
97
98 if (opt == NULL)
99 return 0;
100
101 if (parse_rtattr_nested_compat(tb, TCA_PRIO_MAX, opt, qopt,
102 sizeof(*qopt)))
103 return -1;
104
105 fprintf(f, "bands %u priomap ", qopt->bands);
Stephen Hemminger32a121c2016-03-21 11:48:36 -0700106 for (i = 0; i <= TC_PRIO_MAX; i++)
PJ Waskiewicz292ce962007-08-14 11:21:24 -0700107 fprintf(f, " %d", qopt->priomap[i]);
108
109 if (tb[TCA_PRIO_MQ])
110 fprintf(f, " multiqueue: %s ",
Stephen Hemmingerff247462012-04-10 08:47:55 -0700111 rta_getattr_u8(tb[TCA_PRIO_MQ]) ? "on" : "off");
PJ Waskiewicz292ce962007-08-14 11:21:24 -0700112
113 return 0;
114}
115
116struct qdisc_util rr_qdisc_util = {
Stephen Hemminger32a121c2016-03-21 11:48:36 -0700117 .id = "rr",
PJ Waskiewicz292ce962007-08-14 11:21:24 -0700118 .parse_qopt = rr_parse_opt,
119 .print_qopt = rr_print_opt,
120};