2
0

950-add-cake-to-tc.patch 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775
  1. diff --git a/include/linux/pkt_sched.h b/include/linux/pkt_sched.h
  2. index 8d2530d..c55a9a8 100644
  3. --- a/include/linux/pkt_sched.h
  4. +++ b/include/linux/pkt_sched.h
  5. @@ -850,4 +850,60 @@ struct tc_pie_xstats {
  6. __u32 maxq; /* maximum queue size */
  7. __u32 ecn_mark; /* packets marked with ecn*/
  8. };
  9. +
  10. +/* CAKE */
  11. +enum {
  12. + TCA_CAKE_UNSPEC,
  13. + TCA_CAKE_BASE_RATE,
  14. + TCA_CAKE_DIFFSERV_MODE,
  15. + TCA_CAKE_ATM,
  16. + TCA_CAKE_FLOW_MODE,
  17. + TCA_CAKE_OVERHEAD,
  18. + TCA_CAKE_RTT,
  19. + TCA_CAKE_TARGET,
  20. + TCA_CAKE_AUTORATE,
  21. + TCA_CAKE_MEMORY,
  22. + TCA_CAKE_NAT,
  23. + TCA_CAKE_ETHERNET,
  24. + TCA_CAKE_WASH,
  25. + TCA_CAKE_MPU,
  26. + __TCA_CAKE_MAX
  27. +};
  28. +#define TCA_CAKE_MAX (__TCA_CAKE_MAX - 1)
  29. +
  30. +struct tc_cake_traffic_stats {
  31. + __u32 packets;
  32. + __u32 link_ms;
  33. + __u64 bytes;
  34. +};
  35. +
  36. +#define TC_CAKE_MAX_TINS (8)
  37. +struct tc_cake_xstats {
  38. + __u16 version; /* == 4, increments when struct extended */
  39. + __u8 max_tins; /* == TC_CAKE_MAX_TINS */
  40. + __u8 tin_cnt; /* <= TC_CAKE_MAX_TINS */
  41. +
  42. + __u32 threshold_rate [TC_CAKE_MAX_TINS];
  43. + __u32 target_us [TC_CAKE_MAX_TINS];
  44. + struct tc_cake_traffic_stats sent [TC_CAKE_MAX_TINS];
  45. + struct tc_cake_traffic_stats dropped [TC_CAKE_MAX_TINS];
  46. + struct tc_cake_traffic_stats ecn_marked[TC_CAKE_MAX_TINS];
  47. + struct tc_cake_traffic_stats backlog [TC_CAKE_MAX_TINS];
  48. + __u32 interval_us [TC_CAKE_MAX_TINS];
  49. + __u32 way_indirect_hits[TC_CAKE_MAX_TINS];
  50. + __u32 way_misses [TC_CAKE_MAX_TINS];
  51. + __u32 way_collisions [TC_CAKE_MAX_TINS];
  52. + __u32 peak_delay_us [TC_CAKE_MAX_TINS]; /* ~= delay to bulk flows */
  53. + __u32 avge_delay_us [TC_CAKE_MAX_TINS];
  54. + __u32 base_delay_us [TC_CAKE_MAX_TINS]; /* ~= delay to sparse flows */
  55. + __u16 sparse_flows [TC_CAKE_MAX_TINS];
  56. + __u16 bulk_flows [TC_CAKE_MAX_TINS];
  57. + __u16 unresponse_flows [TC_CAKE_MAX_TINS]; /* v4 - was u32 last_len */
  58. + __u16 spare [TC_CAKE_MAX_TINS]; /* v4 - split last_len */
  59. + __u32 max_skblen [TC_CAKE_MAX_TINS];
  60. + __u32 capacity_estimate; /* version 2 */
  61. + __u32 memory_limit; /* version 3 */
  62. + __u32 memory_used; /* version 3 */
  63. +};
  64. +
  65. #endif
  66. diff --git a/tc/Makefile b/tc/Makefile
  67. index 56acbaa..d421b8e 100644
  68. --- a/tc/Makefile
  69. +++ b/tc/Makefile
  70. @@ -63,6 +63,7 @@ TCMODULES += q_codel.o
  71. TCMODULES += q_fq_codel.o
  72. TCMODULES += q_fq.o
  73. TCMODULES += q_pie.o
  74. +TCMODULES += q_cake.o
  75. TCMODULES += q_hhf.o
  76. TCMODULES += e_bpf.o
  77. diff --git a/tc/q_cake.c b/tc/q_cake.c
  78. new file mode 100644
  79. index 0000000..acbe56c
  80. --- /dev/null
  81. +++ b/tc/q_cake.c
  82. @@ -0,0 +1,692 @@
  83. +/*
  84. + * Common Applications Kept Enhanced -- CAKE
  85. + *
  86. + * Copyright (C) 2014-2015 Jonathan Morton <chromatix99@gmail.com>
  87. + *
  88. + * Redistribution and use in source and binary forms, with or without
  89. + * modification, are permitted provided that the following conditions
  90. + * are met:
  91. + * 1. Redistributions of source code must retain the above copyright
  92. + * notice, this list of conditions, and the following disclaimer,
  93. + * without modification.
  94. + * 2. Redistributions in binary form must reproduce the above copyright
  95. + * notice, this list of conditions and the following disclaimer in the
  96. + * documentation and/or other materials provided with the distribution.
  97. + * 3. The names of the authors may not be used to endorse or promote products
  98. + * derived from this software without specific prior written permission.
  99. + *
  100. + * Alternatively, provided that this notice is retained in full, this
  101. + * software may be distributed under the terms of the GNU General
  102. + * Public License ("GPL") version 2, in which case the provisions of the
  103. + * GPL apply INSTEAD OF those given above.
  104. + *
  105. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  106. + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  107. + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  108. + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  109. + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  110. + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  111. + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  112. + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  113. + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  114. + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  115. + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  116. + * DAMAGE.
  117. + *
  118. + */
  119. +
  120. +#include <stddef.h>
  121. +#include <stdio.h>
  122. +#include <stdlib.h>
  123. +#include <unistd.h>
  124. +#include <syslog.h>
  125. +#include <fcntl.h>
  126. +#include <sys/socket.h>
  127. +#include <netinet/in.h>
  128. +#include <arpa/inet.h>
  129. +#include <string.h>
  130. +
  131. +#include "utils.h"
  132. +#include "tc_util.h"
  133. +
  134. +static void explain(void)
  135. +{
  136. + fprintf(stderr,
  137. +"Usage: ... cake [ bandwidth RATE | unlimited* | autorate_ingress ]\n"
  138. +" [ rtt TIME | datacentre | lan | metro | regional |\n"
  139. +" internet* | oceanic | satellite | interplanetary ]\n"
  140. +" [ besteffort | diffserv8 | diffserv4 | diffserv-llt |\n"
  141. +" diffserv3* ]\n"
  142. +" [ flowblind | srchost | dsthost | hosts | flows |\n"
  143. +" dual-srchost | dual-dsthost | triple-isolate* ]\n"
  144. +" [ nat | nonat* ]\n"
  145. +" [ wash | nowash * ]\n"
  146. +" [ memlimit LIMIT ]\n"
  147. +" [ ptm | atm | noatm* ] [ overhead N | conservative | raw* ]\n"
  148. +" [ mpu N ]\n"
  149. +" (* marks defaults)\n");
  150. +}
  151. +
  152. +static int cake_parse_opt(struct qdisc_util *qu, int argc, char **argv,
  153. + struct nlmsghdr *n)
  154. +{
  155. + int unlimited = 0;
  156. + unsigned bandwidth = 0;
  157. + unsigned interval = 0;
  158. + unsigned target = 0;
  159. + unsigned diffserv = 0;
  160. + unsigned memlimit = 0;
  161. + int overhead = 0;
  162. + bool overhead_set = false;
  163. + bool overhead_override = false;
  164. + int wash = -1;
  165. + int mpu = 0;
  166. + int flowmode = -1;
  167. + int nat = -1;
  168. + int atm = -1;
  169. + int autorate = -1;
  170. + struct rtattr *tail;
  171. +
  172. + while (argc > 0) {
  173. + if (strcmp(*argv, "bandwidth") == 0) {
  174. + NEXT_ARG();
  175. + if (get_rate(&bandwidth, *argv)) {
  176. + fprintf(stderr, "Illegal \"bandwidth\"\n");
  177. + return -1;
  178. + }
  179. + unlimited = 0;
  180. + autorate = 0;
  181. + } else if (strcmp(*argv, "unlimited") == 0) {
  182. + bandwidth = 0;
  183. + unlimited = 1;
  184. + autorate = 0;
  185. + } else if (strcmp(*argv, "autorate_ingress") == 0) {
  186. + autorate = 1;
  187. +
  188. + } else if (strcmp(*argv, "rtt") == 0) {
  189. + NEXT_ARG();
  190. + if (get_time(&interval, *argv)) {
  191. + fprintf(stderr, "Illegal \"rtt\"\n");
  192. + return -1;
  193. + }
  194. + target = interval / 20;
  195. + if(!target)
  196. + target = 1;
  197. + } else if (strcmp(*argv, "datacentre") == 0) {
  198. + interval = 100;
  199. + target = 5;
  200. + } else if (strcmp(*argv, "lan") == 0) {
  201. + interval = 1000;
  202. + target = 50;
  203. + } else if (strcmp(*argv, "metro") == 0) {
  204. + interval = 10000;
  205. + target = 500;
  206. + } else if (strcmp(*argv, "regional") == 0) {
  207. + interval = 30000;
  208. + target = 1500;
  209. + } else if (strcmp(*argv, "internet") == 0) {
  210. + interval = 100000;
  211. + target = 5000;
  212. + } else if (strcmp(*argv, "oceanic") == 0) {
  213. + interval = 300000;
  214. + target = 15000;
  215. + } else if (strcmp(*argv, "satellite") == 0) {
  216. + interval = 1000000;
  217. + target = 50000;
  218. + } else if (strcmp(*argv, "interplanetary") == 0) {
  219. + interval = 3600000000U;
  220. + target = 5000;
  221. +
  222. + } else if (strcmp(*argv, "besteffort") == 0) {
  223. + diffserv = 1;
  224. + } else if (strcmp(*argv, "precedence") == 0) {
  225. + diffserv = 2;
  226. + } else if (strcmp(*argv, "diffserv8") == 0) {
  227. + diffserv = 3;
  228. + } else if (strcmp(*argv, "diffserv4") == 0) {
  229. + diffserv = 4;
  230. + } else if (strcmp(*argv, "diffserv") == 0) {
  231. + diffserv = 4;
  232. + } else if (strcmp(*argv, "diffserv-llt") == 0) {
  233. + diffserv = 5;
  234. + } else if (strcmp(*argv, "diffserv3") == 0) {
  235. + diffserv = 6;
  236. +
  237. + } else if (strcmp(*argv, "nowash") == 0) {
  238. + wash = 0;
  239. + } else if (strcmp(*argv, "wash") == 0) {
  240. + wash = 1;
  241. +
  242. + } else if (strcmp(*argv, "flowblind") == 0) {
  243. + flowmode = 0;
  244. + } else if (strcmp(*argv, "srchost") == 0) {
  245. + flowmode = 1;
  246. + } else if (strcmp(*argv, "dsthost") == 0) {
  247. + flowmode = 2;
  248. + } else if (strcmp(*argv, "hosts") == 0) {
  249. + flowmode = 3;
  250. + } else if (strcmp(*argv, "flows") == 0) {
  251. + flowmode = 4;
  252. + } else if (strcmp(*argv, "dual-srchost") == 0) {
  253. + flowmode = 5;
  254. + } else if (strcmp(*argv, "dual-dsthost") == 0) {
  255. + flowmode = 6;
  256. + } else if (strcmp(*argv, "triple-isolate") == 0) {
  257. + flowmode = 7;
  258. +
  259. + } else if (strcmp(*argv, "nat") == 0) {
  260. + nat = 1;
  261. + } else if (strcmp(*argv, "nonat") == 0) {
  262. + nat = 0;
  263. +
  264. + } else if (strcmp(*argv, "ptm") == 0) {
  265. + atm = 2;
  266. + } else if (strcmp(*argv, "atm") == 0) {
  267. + atm = 1;
  268. + } else if (strcmp(*argv, "noatm") == 0) {
  269. + atm = 0;
  270. +
  271. + } else if (strcmp(*argv, "raw") == 0) {
  272. + atm = 0;
  273. + overhead = 0;
  274. + overhead_set = true;
  275. + overhead_override = true;
  276. + } else if (strcmp(*argv, "conservative") == 0) {
  277. + /*
  278. + * Deliberately over-estimate overhead:
  279. + * one whole ATM cell plus ATM framing.
  280. + * A safe choice if the actual overhead is unknown.
  281. + */
  282. + atm = 1;
  283. + overhead = 48;
  284. + overhead_set = true;
  285. +
  286. + /* Various ADSL framing schemes, all over ATM cells */
  287. + } else if (strcmp(*argv, "ipoa-vcmux") == 0) {
  288. + atm = 1;
  289. + overhead += 8;
  290. + overhead_set = true;
  291. + } else if (strcmp(*argv, "ipoa-llcsnap") == 0) {
  292. + atm = 1;
  293. + overhead += 16;
  294. + overhead_set = true;
  295. + } else if (strcmp(*argv, "bridged-vcmux") == 0) {
  296. + atm = 1;
  297. + overhead += 24;
  298. + overhead_set = true;
  299. + } else if (strcmp(*argv, "bridged-llcsnap") == 0) {
  300. + atm = 1;
  301. + overhead += 32;
  302. + overhead_set = true;
  303. + } else if (strcmp(*argv, "pppoa-vcmux") == 0) {
  304. + atm = 1;
  305. + overhead += 10;
  306. + overhead_set = true;
  307. + } else if (strcmp(*argv, "pppoa-llc") == 0) {
  308. + atm = 1;
  309. + overhead += 14;
  310. + overhead_set = true;
  311. + } else if (strcmp(*argv, "pppoe-vcmux") == 0) {
  312. + atm = 1;
  313. + overhead += 32;
  314. + overhead_set = true;
  315. + } else if (strcmp(*argv, "pppoe-llcsnap") == 0) {
  316. + atm = 1;
  317. + overhead += 40;
  318. + overhead_set = true;
  319. +
  320. + /* Typical VDSL2 framing schemes, both over PTM */
  321. + /* PTM has 64b/65b coding which absorbs some bandwidth */
  322. + } else if (strcmp(*argv, "pppoe-ptm") == 0) {
  323. + atm = 2;
  324. + overhead += 27;
  325. + overhead_set = true;
  326. + } else if (strcmp(*argv, "bridged-ptm") == 0) {
  327. + atm = 2;
  328. + overhead += 19;
  329. + overhead_set = true;
  330. +
  331. + } else if (strcmp(*argv, "via-ethernet") == 0) {
  332. + /*
  333. + * We used to use this flag to manually compensate for
  334. + * Linux including the Ethernet header on Ethernet-type
  335. + * interfaces, but not on IP-type interfaces.
  336. + *
  337. + * It is no longer needed, because Cake now adjusts for
  338. + * that automatically, and is thus ignored.
  339. + *
  340. + * It would be deleted entirely, but it appears in the
  341. + * stats output when the automatic compensation is active.
  342. + */
  343. +
  344. + } else if (strcmp(*argv, "ethernet") == 0) {
  345. + /* ethernet pre-amble & interframe gap & FCS
  346. + * you may need to add vlan tag */
  347. + overhead += 38;
  348. + overhead_set = true;
  349. + mpu = 84;
  350. +
  351. + /* Additional Ethernet-related overhead used by some ISPs */
  352. + } else if (strcmp(*argv, "ether-vlan") == 0) {
  353. + /* 802.1q VLAN tag - may be repeated */
  354. + overhead += 4;
  355. + overhead_set = true;
  356. +
  357. + /*
  358. + * DOCSIS cable shapers account for Ethernet frame with FCS,
  359. + * but not interframe gap nor preamble.
  360. + */
  361. + } else if (strcmp(*argv, "docsis") == 0) {
  362. + atm = 0;
  363. + overhead += 18;
  364. + overhead_set = true;
  365. + mpu = 64;
  366. +
  367. + } else if (strcmp(*argv, "overhead") == 0) {
  368. + char* p = NULL;
  369. + NEXT_ARG();
  370. + overhead = strtol(*argv, &p, 10);
  371. + if(!p || *p || !*argv || overhead < -64 || overhead > 256) {
  372. + fprintf(stderr, "Illegal \"overhead\", valid range is -64 to 256\\n");
  373. + return -1;
  374. + }
  375. + overhead_set = true;
  376. +
  377. + } else if (strcmp(*argv, "mpu") == 0) {
  378. + char* p = NULL;
  379. + NEXT_ARG();
  380. + mpu = strtol(*argv, &p, 10);
  381. + if(!p || *p || !*argv || mpu < 0 || mpu > 256) {
  382. + fprintf(stderr, "Illegal \"mpu\", valid range is 0 to 256\\n");
  383. + return -1;
  384. + }
  385. +
  386. + } else if (strcmp(*argv, "memlimit") == 0) {
  387. + NEXT_ARG();
  388. + if(get_size(&memlimit, *argv)) {
  389. + fprintf(stderr, "Illegal value for \"memlimit\": \"%s\"\n", *argv);
  390. + return -1;
  391. + }
  392. +
  393. + } else if (strcmp(*argv, "help") == 0) {
  394. + explain();
  395. + return -1;
  396. + } else {
  397. + fprintf(stderr, "What is \"%s\"?\n", *argv);
  398. + explain();
  399. + return -1;
  400. + }
  401. + argc--; argv++;
  402. + }
  403. +
  404. + tail = NLMSG_TAIL(n);
  405. + addattr_l(n, 1024, TCA_OPTIONS, NULL, 0);
  406. + if (bandwidth || unlimited)
  407. + addattr_l(n, 1024, TCA_CAKE_BASE_RATE, &bandwidth, sizeof(bandwidth));
  408. + if (diffserv)
  409. + addattr_l(n, 1024, TCA_CAKE_DIFFSERV_MODE, &diffserv, sizeof(diffserv));
  410. + if (atm != -1)
  411. + addattr_l(n, 1024, TCA_CAKE_ATM, &atm, sizeof(atm));
  412. + if (flowmode != -1)
  413. + addattr_l(n, 1024, TCA_CAKE_FLOW_MODE, &flowmode, sizeof(flowmode));
  414. + if (overhead_set)
  415. + addattr_l(n, 1024, TCA_CAKE_OVERHEAD, &overhead, sizeof(overhead));
  416. + if (overhead_override) {
  417. + unsigned zero = 0;
  418. + addattr_l(n, 1024, TCA_CAKE_ETHERNET, &zero, sizeof(zero));
  419. + }
  420. + if (mpu > 0)
  421. + addattr_l(n, 1024, TCA_CAKE_MPU, &mpu, sizeof(mpu));
  422. + if (interval)
  423. + addattr_l(n, 1024, TCA_CAKE_RTT, &interval, sizeof(interval));
  424. + if (target)
  425. + addattr_l(n, 1024, TCA_CAKE_TARGET, &target, sizeof(target));
  426. + if (autorate != -1)
  427. + addattr_l(n, 1024, TCA_CAKE_AUTORATE, &autorate, sizeof(autorate));
  428. + if (memlimit)
  429. + addattr_l(n, 1024, TCA_CAKE_MEMORY, &memlimit, sizeof(memlimit));
  430. + if (nat != -1)
  431. + addattr_l(n, 1024, TCA_CAKE_NAT, &nat, sizeof(nat));
  432. + if (wash != -1)
  433. + addattr_l(n, 1024, TCA_CAKE_WASH, &wash, sizeof(wash));
  434. +
  435. + tail->rta_len = (void *) NLMSG_TAIL(n) - (void *) tail;
  436. + return 0;
  437. +}
  438. +
  439. +
  440. +static int cake_print_opt(struct qdisc_util *qu, FILE *f, struct rtattr *opt)
  441. +{
  442. + struct rtattr *tb[TCA_CAKE_MAX + 1];
  443. + unsigned bandwidth = 0;
  444. + unsigned diffserv = 0;
  445. + unsigned flowmode = 0;
  446. + unsigned interval = 0;
  447. + unsigned memlimit = 0;
  448. + int overhead = 0;
  449. + int ethernet = 0;
  450. + int mpu = 0;
  451. + int atm = 0;
  452. + int nat = 0;
  453. + int autorate = 0;
  454. + int wash = 0;
  455. + SPRINT_BUF(b1);
  456. + SPRINT_BUF(b2);
  457. +
  458. + if (opt == NULL)
  459. + return 0;
  460. +
  461. + parse_rtattr_nested(tb, TCA_CAKE_MAX, opt);
  462. +
  463. + if (tb[TCA_CAKE_BASE_RATE] &&
  464. + RTA_PAYLOAD(tb[TCA_CAKE_BASE_RATE]) >= sizeof(__u32)) {
  465. + bandwidth = rta_getattr_u32(tb[TCA_CAKE_BASE_RATE]);
  466. + if(bandwidth)
  467. + fprintf(f, "bandwidth %s ", sprint_rate(bandwidth, b1));
  468. + else
  469. + fprintf(f, "unlimited ");
  470. + }
  471. + if (tb[TCA_CAKE_AUTORATE] &&
  472. + RTA_PAYLOAD(tb[TCA_CAKE_AUTORATE]) >= sizeof(__u32)) {
  473. + autorate = rta_getattr_u32(tb[TCA_CAKE_AUTORATE]);
  474. + if(autorate == 1)
  475. + fprintf(f, "autorate_ingress ");
  476. + else if(autorate)
  477. + fprintf(f, "(?autorate?) ");
  478. + }
  479. + if (tb[TCA_CAKE_DIFFSERV_MODE] &&
  480. + RTA_PAYLOAD(tb[TCA_CAKE_DIFFSERV_MODE]) >= sizeof(__u32)) {
  481. + diffserv = rta_getattr_u32(tb[TCA_CAKE_DIFFSERV_MODE]);
  482. + switch(diffserv) {
  483. + case 1:
  484. + fprintf(f, "besteffort ");
  485. + break;
  486. + case 2:
  487. + fprintf(f, "precedence ");
  488. + break;
  489. + case 3:
  490. + fprintf(f, "diffserv8 ");
  491. + break;
  492. + case 4:
  493. + fprintf(f, "diffserv4 ");
  494. + break;
  495. + case 5:
  496. + fprintf(f, "diffserv-llt ");
  497. + break;
  498. + case 6:
  499. + fprintf(f, "diffserv3 ");
  500. + break;
  501. + default:
  502. + fprintf(f, "(?diffserv?) ");
  503. + break;
  504. + };
  505. + }
  506. + if (tb[TCA_CAKE_FLOW_MODE] &&
  507. + RTA_PAYLOAD(tb[TCA_CAKE_FLOW_MODE]) >= sizeof(__u32)) {
  508. + flowmode = rta_getattr_u32(tb[TCA_CAKE_FLOW_MODE]);
  509. + nat = !!(flowmode & 64);
  510. + flowmode &= ~64;
  511. + switch(flowmode) {
  512. + case 0:
  513. + fprintf(f, "flowblind ");
  514. + break;
  515. + case 1:
  516. + fprintf(f, "srchost ");
  517. + break;
  518. + case 2:
  519. + fprintf(f, "dsthost ");
  520. + break;
  521. + case 3:
  522. + fprintf(f, "hosts ");
  523. + break;
  524. + case 4:
  525. + fprintf(f, "flows ");
  526. + break;
  527. + case 5:
  528. + fprintf(f, "dual-srchost ");
  529. + break;
  530. + case 6:
  531. + fprintf(f, "dual-dsthost ");
  532. + break;
  533. + case 7:
  534. + fprintf(f, "triple-isolate ");
  535. + break;
  536. + default:
  537. + fprintf(f, "(?flowmode?) ");
  538. + break;
  539. + };
  540. +
  541. + if(nat)
  542. + fprintf(f, "nat ");
  543. + }
  544. + if (tb[TCA_CAKE_WASH] &&
  545. + RTA_PAYLOAD(tb[TCA_CAKE_WASH]) >= sizeof(__u32)) {
  546. + wash = rta_getattr_u32(tb[TCA_CAKE_WASH]);
  547. + }
  548. + if (tb[TCA_CAKE_ATM] &&
  549. + RTA_PAYLOAD(tb[TCA_CAKE_ATM]) >= sizeof(__u32)) {
  550. + atm = rta_getattr_u32(tb[TCA_CAKE_ATM]);
  551. + }
  552. + if (tb[TCA_CAKE_OVERHEAD] &&
  553. + RTA_PAYLOAD(tb[TCA_CAKE_OVERHEAD]) >= sizeof(__u32)) {
  554. + overhead = rta_getattr_u32(tb[TCA_CAKE_OVERHEAD]);
  555. + }
  556. + if (tb[TCA_CAKE_MPU] &&
  557. + RTA_PAYLOAD(tb[TCA_CAKE_MPU]) >= sizeof(__u32)) {
  558. + mpu = rta_getattr_u32(tb[TCA_CAKE_MPU]);
  559. + }
  560. + if (tb[TCA_CAKE_ETHERNET] &&
  561. + RTA_PAYLOAD(tb[TCA_CAKE_ETHERNET]) >= sizeof(__u32)) {
  562. + ethernet = rta_getattr_u32(tb[TCA_CAKE_ETHERNET]);
  563. + }
  564. + if (tb[TCA_CAKE_RTT] &&
  565. + RTA_PAYLOAD(tb[TCA_CAKE_RTT]) >= sizeof(__u32)) {
  566. + interval = rta_getattr_u32(tb[TCA_CAKE_RTT]);
  567. + }
  568. +
  569. + if (wash)
  570. + fprintf(f,"wash ");
  571. +
  572. + if (interval)
  573. + fprintf(f, "rtt %s ", sprint_time(interval, b2));
  574. +
  575. + if (!atm && overhead == ethernet) {
  576. + fprintf(f, "raw ");
  577. + } else {
  578. + if (atm == 1)
  579. + fprintf(f, "atm ");
  580. + else if (atm == 2)
  581. + fprintf(f, "ptm ");
  582. + else
  583. + fprintf(f, "noatm ");
  584. +
  585. + fprintf(f, "overhead %d ", overhead);
  586. +
  587. + // This is actually the *amount* of automatic compensation, but we only report
  588. + // its presence as a boolean for now.
  589. + if (ethernet)
  590. + fprintf(f, "via-ethernet ");
  591. + }
  592. +
  593. + if (mpu) {
  594. + fprintf(f, "mpu %d ", mpu);
  595. + }
  596. +
  597. + if (memlimit)
  598. + fprintf(f, "memlimit %s", sprint_size(memlimit, b1));
  599. +
  600. + return 0;
  601. +}
  602. +
  603. +static int cake_print_xstats(struct qdisc_util *qu, FILE *f,
  604. + struct rtattr *xstats)
  605. +{
  606. + /* fq_codel stats format borrowed */
  607. + struct tc_fq_codel_xstats *st;
  608. + struct tc_cake_xstats *stnc;
  609. + SPRINT_BUF(b1);
  610. + SPRINT_BUF(b2);
  611. +
  612. + if (xstats == NULL)
  613. + return 0;
  614. +
  615. + if (RTA_PAYLOAD(xstats) < sizeof(st->type))
  616. + return -1;
  617. +
  618. + st = RTA_DATA(xstats);
  619. + stnc = RTA_DATA(xstats);
  620. +
  621. + if (st->type == TCA_FQ_CODEL_XSTATS_QDISC && RTA_PAYLOAD(xstats) >= sizeof(*st)) {
  622. + fprintf(f, " maxpacket %u drop_overlimit %u new_flow_count %u ecn_mark %u",
  623. + st->qdisc_stats.maxpacket,
  624. + st->qdisc_stats.drop_overlimit,
  625. + st->qdisc_stats.new_flow_count,
  626. + st->qdisc_stats.ecn_mark);
  627. + fprintf(f, "\n new_flows_len %u old_flows_len %u",
  628. + st->qdisc_stats.new_flows_len,
  629. + st->qdisc_stats.old_flows_len);
  630. + } else if (st->type == TCA_FQ_CODEL_XSTATS_CLASS && RTA_PAYLOAD(xstats) >= sizeof(*st)) {
  631. + fprintf(f, " deficit %d count %u lastcount %u ldelay %s",
  632. + st->class_stats.deficit,
  633. + st->class_stats.count,
  634. + st->class_stats.lastcount,
  635. + sprint_time(st->class_stats.ldelay, b1));
  636. + if (st->class_stats.dropping) {
  637. + fprintf(f, " dropping");
  638. + if (st->class_stats.drop_next < 0)
  639. + fprintf(f, " drop_next -%s",
  640. + sprint_time(-st->class_stats.drop_next, b1));
  641. + else
  642. + fprintf(f, " drop_next %s",
  643. + sprint_time(st->class_stats.drop_next, b1));
  644. + }
  645. + } else if (stnc->version >= 1 && stnc->version < 0xFF
  646. + && stnc->max_tins == TC_CAKE_MAX_TINS
  647. + && RTA_PAYLOAD(xstats) >= offsetof(struct tc_cake_xstats, capacity_estimate))
  648. + {
  649. + int i;
  650. +
  651. + if(stnc->version >= 3)
  652. + fprintf(f, " memory used: %s of %s\n", sprint_size(stnc->memory_used, b1), sprint_size(stnc->memory_limit, b2));
  653. +
  654. + if(stnc->version >= 2)
  655. + fprintf(f, " capacity estimate: %s\n", sprint_rate(stnc->capacity_estimate, b1));
  656. +
  657. + switch(stnc->tin_cnt) {
  658. + case 3:
  659. + fprintf(f, " Bulk Best Effort Voice\n");
  660. + break;
  661. +
  662. + case 4:
  663. + fprintf(f, " Bulk Best Effort Video Voice\n");
  664. + break;
  665. +
  666. + case 5:
  667. + fprintf(f, " Low Loss Best Effort Low Delay Bulk Net Control\n");
  668. + break;
  669. +
  670. + default:
  671. + fprintf(f, " ");
  672. + for(i=0; i < stnc->tin_cnt; i++)
  673. + fprintf(f, " Tin %u", i);
  674. + fprintf(f, "\n");
  675. + };
  676. +
  677. + fprintf(f, " thresh ");
  678. + for(i=0; i < stnc->tin_cnt; i++)
  679. + fprintf(f, "%12s", sprint_rate(stnc->threshold_rate[i], b1));
  680. + fprintf(f, "\n");
  681. +
  682. + fprintf(f, " target ");
  683. + for(i=0; i < stnc->tin_cnt; i++)
  684. + fprintf(f, "%12s", sprint_time(stnc->target_us[i], b1));
  685. + fprintf(f, "\n");
  686. +
  687. + fprintf(f, " interval");
  688. + for(i=0; i < stnc->tin_cnt; i++)
  689. + fprintf(f, "%12s", sprint_time(stnc->interval_us[i], b1));
  690. + fprintf(f, "\n");
  691. +
  692. + fprintf(f, " pk_delay");
  693. + for(i=0; i < stnc->tin_cnt; i++)
  694. + fprintf(f, "%12s", sprint_time(stnc->peak_delay_us[i], b1));
  695. + fprintf(f, "\n");
  696. +
  697. + fprintf(f, " av_delay");
  698. + for(i=0; i < stnc->tin_cnt; i++)
  699. + fprintf(f, "%12s", sprint_time(stnc->avge_delay_us[i], b1));
  700. + fprintf(f, "\n");
  701. +
  702. + fprintf(f, " sp_delay");
  703. + for(i=0; i < stnc->tin_cnt; i++)
  704. + fprintf(f, "%12s", sprint_time(stnc->base_delay_us[i], b1));
  705. + fprintf(f, "\n");
  706. +
  707. + fprintf(f, " pkts ");
  708. + for(i=0; i < stnc->tin_cnt; i++)
  709. + fprintf(f, "%12u", stnc->sent[i].packets);
  710. + fprintf(f, "\n");
  711. +
  712. + fprintf(f, " bytes ");
  713. + for(i=0; i < stnc->tin_cnt; i++)
  714. + fprintf(f, "%12llu", stnc->sent[i].bytes);
  715. + fprintf(f, "\n");
  716. +
  717. + fprintf(f, " way_inds");
  718. + for(i=0; i < stnc->tin_cnt; i++)
  719. + fprintf(f, "%12u", stnc->way_indirect_hits[i]);
  720. + fprintf(f, "\n");
  721. +
  722. + fprintf(f, " way_miss");
  723. + for(i=0; i < stnc->tin_cnt; i++)
  724. + fprintf(f, "%12u", stnc->way_misses[i]);
  725. + fprintf(f, "\n");
  726. +
  727. + fprintf(f, " way_cols");
  728. + for(i=0; i < stnc->tin_cnt; i++)
  729. + fprintf(f, "%12u", stnc->way_collisions[i]);
  730. + fprintf(f, "\n");
  731. +
  732. + fprintf(f, " drops ");
  733. + for(i=0; i < stnc->tin_cnt; i++)
  734. + fprintf(f, "%12u", stnc->dropped[i].packets);
  735. + fprintf(f, "\n");
  736. +
  737. + fprintf(f, " marks ");
  738. + for(i=0; i < stnc->tin_cnt; i++)
  739. + fprintf(f, "%12u", stnc->ecn_marked[i].packets);
  740. + fprintf(f, "\n");
  741. +
  742. + fprintf(f, " sp_flows");
  743. + for(i=0; i < stnc->tin_cnt; i++)
  744. + fprintf(f, "%12u", stnc->sparse_flows[i]);
  745. + fprintf(f, "\n");
  746. +
  747. + fprintf(f, " bk_flows");
  748. + for(i=0; i < stnc->tin_cnt; i++)
  749. + fprintf(f, "%12u", stnc->bulk_flows[i]);
  750. + fprintf(f, "\n");
  751. +
  752. + if(stnc->version >= 4) {
  753. + fprintf(f, " un_flows");
  754. + for(i=0; i < stnc->tin_cnt; i++)
  755. + fprintf(f, "%12u", stnc->unresponse_flows[i]);
  756. + fprintf(f, "\n");
  757. + }
  758. +
  759. + fprintf(f, " max_len ");
  760. + for(i=0; i < stnc->tin_cnt; i++)
  761. + fprintf(f, "%12u", stnc->max_skblen[i]);
  762. + fprintf(f, "\n");
  763. + } else {
  764. + return -1;
  765. + }
  766. + return 0;
  767. +}
  768. +
  769. +struct qdisc_util cake_qdisc_util = {
  770. + .id = "cake",
  771. + .parse_qopt = cake_parse_opt,
  772. + .print_qopt = cake_print_opt,
  773. + .print_xstats = cake_print_xstats,
  774. +};