2015-08-18 10:16:54 +00:00
|
|
|
package netlink
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestQdiscAddDel(t *testing.T) {
|
2015-08-18 21:07:01 +00:00
|
|
|
tearDown := setUpNetlinkTest(t)
|
|
|
|
defer tearDown()
|
|
|
|
if err := LinkAdd(&Ifb{LinkAttrs{Name: "foo"}}); err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
link, err := LinkByName("foo")
|
2015-08-18 10:16:54 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
2015-08-18 21:07:01 +00:00
|
|
|
if err := LinkSetUp(link); err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
2015-08-19 23:02:04 +00:00
|
|
|
qdisc := &Tbf{
|
2015-08-18 21:07:01 +00:00
|
|
|
QdiscAttrs: QdiscAttrs{
|
|
|
|
LinkIndex: link.Attrs().Index,
|
|
|
|
Handle: MakeHandle(1, 0),
|
|
|
|
Parent: HANDLE_ROOT,
|
|
|
|
},
|
|
|
|
Rate: 131072,
|
|
|
|
Limit: 1220703,
|
|
|
|
Buffer: 16793,
|
|
|
|
}
|
|
|
|
if err := QdiscAdd(qdisc); err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
qdiscs, err := QdiscList(link)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
if len(qdiscs) != 1 {
|
|
|
|
t.Fatal("Failed to add qdisc")
|
|
|
|
}
|
2015-08-19 23:02:04 +00:00
|
|
|
tbf, ok := qdiscs[0].(*Tbf)
|
2015-08-18 21:07:01 +00:00
|
|
|
if !ok {
|
|
|
|
t.Fatal("Qdisc is the wrong type")
|
|
|
|
}
|
|
|
|
if tbf.Rate != qdisc.Rate {
|
|
|
|
t.Fatal("Rate doesn't match")
|
|
|
|
}
|
|
|
|
if tbf.Limit != qdisc.Limit {
|
|
|
|
t.Fatal("Limit doesn't match")
|
|
|
|
}
|
|
|
|
if tbf.Buffer != qdisc.Buffer {
|
|
|
|
t.Fatal("Buffer doesn't match")
|
|
|
|
}
|
|
|
|
if err := QdiscDel(qdisc); err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
2015-08-19 23:02:04 +00:00
|
|
|
qdiscs, err = QdiscList(link)
|
2015-08-18 21:07:01 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
if len(qdiscs) != 0 {
|
|
|
|
t.Fatal("Failed to remove qdisc")
|
2015-08-18 10:16:54 +00:00
|
|
|
}
|
|
|
|
}
|