mirror of https://github.com/vishvananda/netlink
qdisc: add statistics for qdisc
qdisc statistics is exposed in netlink response but not parsed, here we parse it and expose it via struct QdiscStatistics. Signed-off-by: Kangjie Xu <kanxu@ebay.com>
This commit is contained in:
parent
8ac83962db
commit
8fa22700b3
3
qdisc.go
3
qdisc.go
|
@ -28,6 +28,8 @@ type Qdisc interface {
|
||||||
Type() string
|
Type() string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type QdiscStatistics ClassStatistics
|
||||||
|
|
||||||
// QdiscAttrs represents a netlink qdisc. A qdisc is associated with a link,
|
// QdiscAttrs represents a netlink qdisc. A qdisc is associated with a link,
|
||||||
// has a handle, a parent and a refcnt. The root qdisc of a device should
|
// has a handle, a parent and a refcnt. The root qdisc of a device should
|
||||||
// have parent == HANDLE_ROOT.
|
// have parent == HANDLE_ROOT.
|
||||||
|
@ -37,6 +39,7 @@ type QdiscAttrs struct {
|
||||||
Parent uint32
|
Parent uint32
|
||||||
Refcnt uint32 // read only
|
Refcnt uint32 // read only
|
||||||
IngressBlock *uint32
|
IngressBlock *uint32
|
||||||
|
Statistics *QdiscStatistics
|
||||||
}
|
}
|
||||||
|
|
||||||
func (q QdiscAttrs) String() string {
|
func (q QdiscAttrs) String() string {
|
||||||
|
|
|
@ -462,6 +462,18 @@ func (h *Handle) QdiscList(link Link) ([]Qdisc, error) {
|
||||||
ingressBlock := new(uint32)
|
ingressBlock := new(uint32)
|
||||||
*ingressBlock = native.Uint32(attr.Value)
|
*ingressBlock = native.Uint32(attr.Value)
|
||||||
base.IngressBlock = ingressBlock
|
base.IngressBlock = ingressBlock
|
||||||
|
case nl.TCA_STATS:
|
||||||
|
s, err := parseTcStats(attr.Value)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
base.Statistics = (*QdiscStatistics)(s)
|
||||||
|
case nl.TCA_STATS2:
|
||||||
|
s, err := parseTcStats2(attr.Value)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
base.Statistics = (*QdiscStatistics)(s)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
*qdisc.Attrs() = base
|
*qdisc.Attrs() = base
|
||||||
|
|
|
@ -614,6 +614,12 @@ func TestIngressAddDel(t *testing.T) {
|
||||||
if *qdiscs[0].Attrs().IngressBlock != *ingressBlock {
|
if *qdiscs[0].Attrs().IngressBlock != *ingressBlock {
|
||||||
t.Fatal("IngressBlock does not match")
|
t.Fatal("IngressBlock does not match")
|
||||||
}
|
}
|
||||||
|
if qdiscs[0].Attrs().Statistics == nil {
|
||||||
|
t.Fatal("Statistics is nil")
|
||||||
|
}
|
||||||
|
if qdiscs[0].Attrs().Statistics.Basic.Bytes != 0 || qdiscs[0].Attrs().Statistics.Basic.Packets != 0 {
|
||||||
|
t.Fatal("Statistics is not zero")
|
||||||
|
}
|
||||||
if err = QdiscDel(qdisc); err != nil {
|
if err = QdiscDel(qdisc); err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue