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

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