linux_test.go 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634
  1. // +build linux
  2. /*
  3. Copyright 2015 The Kubernetes Authors.
  4. Licensed under the Apache License, Version 2.0 (the "License");
  5. you may not use this file except in compliance with the License.
  6. You may obtain a copy of the License at
  7. http://www.apache.org/licenses/LICENSE-2.0
  8. Unless required by applicable law or agreed to in writing, software
  9. distributed under the License is distributed on an "AS IS" BASIS,
  10. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  11. See the License for the specific language governing permissions and
  12. limitations under the License.
  13. */
  14. package bandwidth
  15. import (
  16. "errors"
  17. "reflect"
  18. "strings"
  19. "testing"
  20. "k8s.io/kubernetes/pkg/api/resource"
  21. "k8s.io/kubernetes/pkg/util/exec"
  22. )
  23. var tcClassOutput = `class htb 1:1 root prio 0 rate 10000bit ceil 10000bit burst 1600b cburst 1600b
  24. class htb 1:2 root prio 0 rate 10000bit ceil 10000bit burst 1600b cburst 1600b
  25. class htb 1:3 root prio 0 rate 10000bit ceil 10000bit burst 1600b cburst 1600b
  26. class htb 1:4 root prio 0 rate 10000bit ceil 10000bit burst 1600b cburst 1600b
  27. `
  28. var tcClassOutput2 = `class htb 1:1 root prio 0 rate 10000bit ceil 10000bit burst 1600b cburst 1600b
  29. class htb 1:2 root prio 0 rate 10000bit ceil 10000bit burst 1600b cburst 1600b
  30. class htb 1:3 root prio 0 rate 10000bit ceil 10000bit burst 1600b cburst 1600b
  31. class htb 1:4 root prio 0 rate 10000bit ceil 10000bit burst 1600b cburst 1600b
  32. class htb 1:5 root prio 0 rate 10000bit ceil 10000bit burst 1600b cburst 1600b
  33. `
  34. func TestNextClassID(t *testing.T) {
  35. tests := []struct {
  36. output string
  37. expectErr bool
  38. expected int
  39. err error
  40. }{
  41. {
  42. output: tcClassOutput,
  43. expected: 5,
  44. },
  45. {
  46. output: "\n",
  47. expected: 1,
  48. },
  49. {
  50. expected: -1,
  51. expectErr: true,
  52. err: errors.New("test error"),
  53. },
  54. }
  55. for _, test := range tests {
  56. fcmd := exec.FakeCmd{
  57. CombinedOutputScript: []exec.FakeCombinedOutputAction{
  58. func() ([]byte, error) { return []byte(test.output), test.err },
  59. },
  60. }
  61. fexec := exec.FakeExec{
  62. CommandScript: []exec.FakeCommandAction{
  63. func(cmd string, args ...string) exec.Cmd {
  64. return exec.InitFakeCmd(&fcmd, cmd, args...)
  65. },
  66. },
  67. }
  68. shaper := &tcShaper{e: &fexec}
  69. class, err := shaper.nextClassID()
  70. if test.expectErr {
  71. if err == nil {
  72. t.Errorf("unexpected non-error")
  73. }
  74. } else {
  75. if err != nil {
  76. t.Errorf("unexpected error: %v", err)
  77. }
  78. if class != test.expected {
  79. t.Errorf("expected: %d, found %d", test.expected, class)
  80. }
  81. }
  82. }
  83. }
  84. func TestHexCIDR(t *testing.T) {
  85. tests := []struct {
  86. input string
  87. output string
  88. expectErr bool
  89. }{
  90. {
  91. input: "1.2.0.0/16",
  92. output: "01020000/ffff0000",
  93. },
  94. {
  95. input: "172.17.0.2/32",
  96. output: "ac110002/ffffffff",
  97. },
  98. {
  99. input: "foo",
  100. expectErr: true,
  101. },
  102. }
  103. for _, test := range tests {
  104. output, err := hexCIDR(test.input)
  105. if test.expectErr {
  106. if err == nil {
  107. t.Error("unexpected non-error")
  108. }
  109. } else {
  110. if err != nil {
  111. t.Errorf("unexpected error: %v", err)
  112. }
  113. if output != test.output {
  114. t.Errorf("expected: %s, saw: %s", test.output, output)
  115. }
  116. input, err := asciiCIDR(output)
  117. if err != nil {
  118. t.Errorf("unexpected error: %v", err)
  119. }
  120. if input != test.input {
  121. t.Errorf("expected: %s, saw: %s", test.input, input)
  122. }
  123. }
  124. }
  125. }
  126. var tcFilterOutput = `filter parent 1: protocol ip pref 1 u32
  127. filter parent 1: protocol ip pref 1 u32 fh 800: ht divisor 1
  128. filter parent 1: protocol ip pref 1 u32 fh 800::800 order 2048 key ht 800 bkt 0 flowid 1:1
  129. match ac110002/ffffffff at 16
  130. filter parent 1: protocol ip pref 1 u32 fh 800::801 order 2049 key ht 800 bkt 0 flowid 1:2
  131. match 01020000/ffff0000 at 16
  132. `
  133. func TestFindCIDRClass(t *testing.T) {
  134. tests := []struct {
  135. cidr string
  136. output string
  137. expectErr bool
  138. expectNotFound bool
  139. expectedClass string
  140. expectedHandle string
  141. err error
  142. }{
  143. {
  144. cidr: "172.17.0.2/32",
  145. output: tcFilterOutput,
  146. expectedClass: "1:1",
  147. expectedHandle: "800::800",
  148. },
  149. {
  150. cidr: "1.2.3.4/16",
  151. output: tcFilterOutput,
  152. expectedClass: "1:2",
  153. expectedHandle: "800::801",
  154. },
  155. {
  156. cidr: "2.2.3.4/16",
  157. output: tcFilterOutput,
  158. expectNotFound: true,
  159. },
  160. {
  161. err: errors.New("test error"),
  162. expectErr: true,
  163. },
  164. }
  165. for _, test := range tests {
  166. fcmd := exec.FakeCmd{
  167. CombinedOutputScript: []exec.FakeCombinedOutputAction{
  168. func() ([]byte, error) { return []byte(test.output), test.err },
  169. },
  170. }
  171. fexec := exec.FakeExec{
  172. CommandScript: []exec.FakeCommandAction{
  173. func(cmd string, args ...string) exec.Cmd {
  174. return exec.InitFakeCmd(&fcmd, cmd, args...)
  175. },
  176. },
  177. }
  178. shaper := &tcShaper{e: &fexec}
  179. class, handle, found, err := shaper.findCIDRClass(test.cidr)
  180. if test.expectErr {
  181. if err == nil {
  182. t.Errorf("unexpected non-error")
  183. }
  184. } else {
  185. if err != nil {
  186. t.Errorf("unexpected error: %v", err)
  187. }
  188. if test.expectNotFound {
  189. if found {
  190. t.Errorf("unexpectedly found an interface: %s %s", class, handle)
  191. }
  192. } else {
  193. if class != test.expectedClass {
  194. t.Errorf("expected: %s, found %s", test.expectedClass, class)
  195. }
  196. if handle != test.expectedHandle {
  197. t.Errorf("expected: %s, found %s", test.expectedHandle, handle)
  198. }
  199. }
  200. }
  201. }
  202. }
  203. func TestGetCIDRs(t *testing.T) {
  204. fcmd := exec.FakeCmd{
  205. CombinedOutputScript: []exec.FakeCombinedOutputAction{
  206. func() ([]byte, error) { return []byte(tcFilterOutput), nil },
  207. },
  208. }
  209. fexec := exec.FakeExec{
  210. CommandScript: []exec.FakeCommandAction{
  211. func(cmd string, args ...string) exec.Cmd {
  212. return exec.InitFakeCmd(&fcmd, cmd, args...)
  213. },
  214. },
  215. }
  216. shaper := &tcShaper{e: &fexec}
  217. cidrs, err := shaper.GetCIDRs()
  218. if err != nil {
  219. t.Errorf("unexpected error: %v", err)
  220. }
  221. expectedCidrs := []string{"172.17.0.2/32", "1.2.0.0/16"}
  222. if !reflect.DeepEqual(cidrs, expectedCidrs) {
  223. t.Errorf("expected: %v, saw: %v", expectedCidrs, cidrs)
  224. }
  225. }
  226. func TestLimit(t *testing.T) {
  227. tests := []struct {
  228. cidr string
  229. ingress *resource.Quantity
  230. egress *resource.Quantity
  231. expectErr bool
  232. expectedCalls int
  233. err error
  234. }{
  235. {
  236. cidr: "1.2.3.4/32",
  237. ingress: resource.NewQuantity(10, resource.DecimalSI),
  238. egress: resource.NewQuantity(20, resource.DecimalSI),
  239. expectedCalls: 6,
  240. },
  241. {
  242. cidr: "1.2.3.4/32",
  243. ingress: resource.NewQuantity(10, resource.DecimalSI),
  244. egress: nil,
  245. expectedCalls: 3,
  246. },
  247. {
  248. cidr: "1.2.3.4/32",
  249. ingress: nil,
  250. egress: resource.NewQuantity(20, resource.DecimalSI),
  251. expectedCalls: 3,
  252. },
  253. {
  254. cidr: "1.2.3.4/32",
  255. ingress: nil,
  256. egress: nil,
  257. expectedCalls: 0,
  258. },
  259. {
  260. err: errors.New("test error"),
  261. ingress: resource.NewQuantity(10, resource.DecimalSI),
  262. egress: resource.NewQuantity(20, resource.DecimalSI),
  263. expectErr: true,
  264. },
  265. }
  266. for _, test := range tests {
  267. fcmd := exec.FakeCmd{
  268. CombinedOutputScript: []exec.FakeCombinedOutputAction{
  269. func() ([]byte, error) { return []byte(tcClassOutput), test.err },
  270. func() ([]byte, error) { return []byte{}, test.err },
  271. func() ([]byte, error) { return []byte{}, test.err },
  272. func() ([]byte, error) { return []byte(tcClassOutput2), test.err },
  273. func() ([]byte, error) { return []byte{}, test.err },
  274. func() ([]byte, error) { return []byte{}, test.err },
  275. },
  276. }
  277. fexec := exec.FakeExec{
  278. CommandScript: []exec.FakeCommandAction{
  279. func(cmd string, args ...string) exec.Cmd { return exec.InitFakeCmd(&fcmd, cmd, args...) },
  280. func(cmd string, args ...string) exec.Cmd { return exec.InitFakeCmd(&fcmd, cmd, args...) },
  281. func(cmd string, args ...string) exec.Cmd { return exec.InitFakeCmd(&fcmd, cmd, args...) },
  282. func(cmd string, args ...string) exec.Cmd { return exec.InitFakeCmd(&fcmd, cmd, args...) },
  283. func(cmd string, args ...string) exec.Cmd { return exec.InitFakeCmd(&fcmd, cmd, args...) },
  284. func(cmd string, args ...string) exec.Cmd { return exec.InitFakeCmd(&fcmd, cmd, args...) },
  285. },
  286. }
  287. iface := "cbr0"
  288. shaper := &tcShaper{e: &fexec, iface: iface}
  289. if err := shaper.Limit(test.cidr, test.ingress, test.egress); err != nil && !test.expectErr {
  290. t.Errorf("unexpected error: %v", err)
  291. return
  292. } else if err == nil && test.expectErr {
  293. t.Error("unexpected non-error")
  294. return
  295. }
  296. // No more testing in the error case
  297. if test.expectErr {
  298. if fcmd.CombinedOutputCalls != 1 {
  299. t.Errorf("unexpected number of calls: %d, expected: 1", fcmd.CombinedOutputCalls)
  300. }
  301. return
  302. }
  303. if fcmd.CombinedOutputCalls != test.expectedCalls {
  304. t.Errorf("unexpected number of calls: %d, expected: %d", fcmd.CombinedOutputCalls, test.expectedCalls)
  305. }
  306. for ix := range fcmd.CombinedOutputLog {
  307. output := fcmd.CombinedOutputLog[ix]
  308. if output[0] != "tc" {
  309. t.Errorf("unexpected command: %s, expected tc", output[0])
  310. }
  311. if output[4] != iface {
  312. t.Errorf("unexpected interface: %s, expected %s (%v)", output[4], iface, output)
  313. }
  314. if ix == 1 {
  315. var expectedRate string
  316. if test.ingress != nil {
  317. expectedRate = makeKBitString(test.ingress)
  318. } else {
  319. expectedRate = makeKBitString(test.egress)
  320. }
  321. if output[11] != expectedRate {
  322. t.Errorf("unexpected ingress: %s, expected: %s", output[11], expectedRate)
  323. }
  324. if output[8] != "1:5" {
  325. t.Errorf("unexpected class: %s, expected: %s", output[8], "1:5")
  326. }
  327. }
  328. if ix == 2 {
  329. if output[15] != test.cidr {
  330. t.Errorf("unexpected cidr: %s, expected: %s", output[15], test.cidr)
  331. }
  332. if output[17] != "1:5" {
  333. t.Errorf("unexpected class: %s, expected: %s", output[17], "1:5")
  334. }
  335. }
  336. if ix == 4 {
  337. if output[11] != makeKBitString(test.egress) {
  338. t.Errorf("unexpected egress: %s, expected: %s", output[11], makeKBitString(test.egress))
  339. }
  340. if output[8] != "1:6" {
  341. t.Errorf("unexpected class: %s, expected: %s", output[8], "1:6")
  342. }
  343. }
  344. if ix == 5 {
  345. if output[15] != test.cidr {
  346. t.Errorf("unexpected cidr: %s, expected: %s", output[15], test.cidr)
  347. }
  348. if output[17] != "1:6" {
  349. t.Errorf("unexpected class: %s, expected: %s", output[17], "1:5")
  350. }
  351. }
  352. }
  353. }
  354. }
  355. func TestReset(t *testing.T) {
  356. tests := []struct {
  357. cidr string
  358. err error
  359. expectErr bool
  360. expectedHandle string
  361. expectedClass string
  362. }{
  363. {
  364. cidr: "1.2.3.4/16",
  365. expectedHandle: "800::801",
  366. expectedClass: "1:2",
  367. },
  368. {
  369. cidr: "172.17.0.2/32",
  370. expectedHandle: "800::800",
  371. expectedClass: "1:1",
  372. },
  373. {
  374. err: errors.New("test error"),
  375. expectErr: true,
  376. },
  377. }
  378. for _, test := range tests {
  379. fcmd := exec.FakeCmd{
  380. CombinedOutputScript: []exec.FakeCombinedOutputAction{
  381. func() ([]byte, error) { return []byte(tcFilterOutput), test.err },
  382. func() ([]byte, error) { return []byte{}, test.err },
  383. func() ([]byte, error) { return []byte{}, test.err },
  384. },
  385. }
  386. fexec := exec.FakeExec{
  387. CommandScript: []exec.FakeCommandAction{
  388. func(cmd string, args ...string) exec.Cmd { return exec.InitFakeCmd(&fcmd, cmd, args...) },
  389. func(cmd string, args ...string) exec.Cmd { return exec.InitFakeCmd(&fcmd, cmd, args...) },
  390. func(cmd string, args ...string) exec.Cmd { return exec.InitFakeCmd(&fcmd, cmd, args...) },
  391. },
  392. }
  393. iface := "cbr0"
  394. shaper := &tcShaper{e: &fexec, iface: iface}
  395. if err := shaper.Reset(test.cidr); err != nil && !test.expectErr {
  396. t.Errorf("unexpected error: %v", err)
  397. return
  398. } else if test.expectErr && err == nil {
  399. t.Error("unexpected non-error")
  400. return
  401. }
  402. // No more testing in the error case
  403. if test.expectErr {
  404. if fcmd.CombinedOutputCalls != 1 {
  405. t.Errorf("unexpected number of calls: %d, expected: 1", fcmd.CombinedOutputCalls)
  406. }
  407. return
  408. }
  409. if fcmd.CombinedOutputCalls != 3 {
  410. t.Errorf("unexpected number of calls: %d, expected: 3", fcmd.CombinedOutputCalls)
  411. }
  412. for ix := range fcmd.CombinedOutputLog {
  413. output := fcmd.CombinedOutputLog[ix]
  414. if output[0] != "tc" {
  415. t.Errorf("unexpected command: %s, expected tc", output[0])
  416. }
  417. if output[4] != iface {
  418. t.Errorf("unexpected interface: %s, expected %s (%v)", output[4], iface, output)
  419. }
  420. if ix == 1 && output[12] != test.expectedHandle {
  421. t.Errorf("unexpected handle: %s, expected: %s", output[12], test.expectedHandle)
  422. }
  423. if ix == 2 && output[8] != test.expectedClass {
  424. t.Errorf("unexpected class: %s, expected: %s", output[8], test.expectedClass)
  425. }
  426. }
  427. }
  428. }
  429. var tcQdisc = "qdisc htb 1: root refcnt 2 r2q 10 default 30 direct_packets_stat 0\n"
  430. func TestReconcileInterfaceExists(t *testing.T) {
  431. fcmd := exec.FakeCmd{
  432. CombinedOutputScript: []exec.FakeCombinedOutputAction{
  433. func() ([]byte, error) { return []byte(tcQdisc), nil },
  434. },
  435. }
  436. fexec := exec.FakeExec{
  437. CommandScript: []exec.FakeCommandAction{
  438. func(cmd string, args ...string) exec.Cmd { return exec.InitFakeCmd(&fcmd, cmd, args...) },
  439. },
  440. }
  441. iface := "cbr0"
  442. shaper := &tcShaper{e: &fexec, iface: iface}
  443. err := shaper.ReconcileInterface()
  444. if err != nil {
  445. t.Errorf("unexpected error: %v", err)
  446. }
  447. if fcmd.CombinedOutputCalls != 1 {
  448. t.Errorf("unexpected number of calls: %d", fcmd.CombinedOutputCalls)
  449. }
  450. output := fcmd.CombinedOutputLog[0]
  451. if len(output) != 5 {
  452. t.Errorf("unexpected command: %v", output)
  453. }
  454. if output[0] != "tc" {
  455. t.Errorf("unexpected command: %s", output[0])
  456. }
  457. if output[4] != iface {
  458. t.Errorf("unexpected interface: %s, expected %s", output[4], iface)
  459. }
  460. if output[2] != "show" {
  461. t.Errorf("unexpected action: %s", output[2])
  462. }
  463. }
  464. func testReconcileInterfaceHasNoData(t *testing.T, output string) {
  465. fcmd := exec.FakeCmd{
  466. CombinedOutputScript: []exec.FakeCombinedOutputAction{
  467. func() ([]byte, error) { return []byte(output), nil },
  468. func() ([]byte, error) { return []byte(output), nil },
  469. },
  470. }
  471. fexec := exec.FakeExec{
  472. CommandScript: []exec.FakeCommandAction{
  473. func(cmd string, args ...string) exec.Cmd { return exec.InitFakeCmd(&fcmd, cmd, args...) },
  474. func(cmd string, args ...string) exec.Cmd { return exec.InitFakeCmd(&fcmd, cmd, args...) },
  475. },
  476. }
  477. iface := "cbr0"
  478. shaper := &tcShaper{e: &fexec, iface: iface}
  479. err := shaper.ReconcileInterface()
  480. if err != nil {
  481. t.Errorf("unexpected error: %v", err)
  482. }
  483. if fcmd.CombinedOutputCalls != 2 {
  484. t.Errorf("unexpected number of calls: %d", fcmd.CombinedOutputCalls)
  485. }
  486. for ix, output := range fcmd.CombinedOutputLog {
  487. if output[0] != "tc" {
  488. t.Errorf("unexpected command: %s", output[0])
  489. }
  490. if output[4] != iface {
  491. t.Errorf("unexpected interface: %s, expected %s", output[4], iface)
  492. }
  493. if ix == 0 {
  494. if len(output) != 5 {
  495. t.Errorf("unexpected command: %v", output)
  496. }
  497. if output[2] != "show" {
  498. t.Errorf("unexpected action: %s", output[2])
  499. }
  500. }
  501. if ix == 1 {
  502. if len(output) != 11 {
  503. t.Errorf("unexpected command: %v", output)
  504. }
  505. if output[2] != "add" {
  506. t.Errorf("unexpected action: %s", output[2])
  507. }
  508. if output[7] != "1:" {
  509. t.Errorf("unexpected root class: %s", output[7])
  510. }
  511. if output[8] != "htb" {
  512. t.Errorf("unexpected qdisc algo: %s", output[8])
  513. }
  514. }
  515. }
  516. }
  517. func TestReconcileInterfaceDoesntExist(t *testing.T) {
  518. testReconcileInterfaceHasNoData(t, "\n")
  519. }
  520. var tcQdiscNoqueue = "qdisc noqueue 0: root refcnt 2 \n"
  521. func TestReconcileInterfaceExistsWithNoqueue(t *testing.T) {
  522. testReconcileInterfaceHasNoData(t, tcQdiscNoqueue)
  523. }
  524. var tcQdiscWrong = []string{
  525. "qdisc htb 2: root refcnt 2 r2q 10 default 30 direct_packets_stat 0\n",
  526. "qdisc foo 1: root refcnt 2 r2q 10 default 30 direct_packets_stat 0\n",
  527. }
  528. func TestReconcileInterfaceIsWrong(t *testing.T) {
  529. for _, test := range tcQdiscWrong {
  530. fcmd := exec.FakeCmd{
  531. CombinedOutputScript: []exec.FakeCombinedOutputAction{
  532. func() ([]byte, error) { return []byte(test), nil },
  533. func() ([]byte, error) { return []byte("\n"), nil },
  534. func() ([]byte, error) { return []byte("\n"), nil },
  535. },
  536. }
  537. fexec := exec.FakeExec{
  538. CommandScript: []exec.FakeCommandAction{
  539. func(cmd string, args ...string) exec.Cmd { return exec.InitFakeCmd(&fcmd, cmd, args...) },
  540. func(cmd string, args ...string) exec.Cmd { return exec.InitFakeCmd(&fcmd, cmd, args...) },
  541. func(cmd string, args ...string) exec.Cmd { return exec.InitFakeCmd(&fcmd, cmd, args...) },
  542. },
  543. }
  544. iface := "cbr0"
  545. shaper := &tcShaper{e: &fexec, iface: iface}
  546. err := shaper.ReconcileInterface()
  547. if err != nil {
  548. t.Errorf("unexpected error: %v", err)
  549. }
  550. if fcmd.CombinedOutputCalls != 3 {
  551. t.Errorf("unexpected number of calls: %d", fcmd.CombinedOutputCalls)
  552. }
  553. for ix, output := range fcmd.CombinedOutputLog {
  554. if output[0] != "tc" {
  555. t.Errorf("unexpected command: %s", output[0])
  556. }
  557. if output[4] != iface {
  558. t.Errorf("unexpected interface: %s, expected %s", output[4], iface)
  559. }
  560. if ix == 0 {
  561. if len(output) != 5 {
  562. t.Errorf("unexpected command: %v", output)
  563. }
  564. if output[2] != "show" {
  565. t.Errorf("unexpected action: %s", output[2])
  566. }
  567. }
  568. if ix == 1 {
  569. if len(output) != 8 {
  570. t.Errorf("unexpected command: %v", output)
  571. }
  572. if output[2] != "delete" {
  573. t.Errorf("unexpected action: %s", output[2])
  574. }
  575. if output[7] != strings.Split(test, " ")[2] {
  576. t.Errorf("unexpected class: %s, expected: %s", output[7], strings.Split(test, " ")[2])
  577. }
  578. }
  579. if ix == 2 {
  580. if len(output) != 11 {
  581. t.Errorf("unexpected command: %v", output)
  582. }
  583. if output[7] != "1:" {
  584. t.Errorf("unexpected root class: %s", output[7])
  585. }
  586. if output[8] != "htb" {
  587. t.Errorf("unexpected qdisc algo: %s", output[8])
  588. }
  589. }
  590. }
  591. }
  592. }