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:
Kangjie Xu 2024-01-09 19:55:28 -07:00 committed by Alessandro Boch
parent 8ac83962db
commit 8fa22700b3
3 changed files with 21 additions and 0 deletions

View File

@ -28,6 +28,8 @@ type Qdisc interface {
Type() string
}
type QdiscStatistics ClassStatistics
// 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
// have parent == HANDLE_ROOT.
@ -37,6 +39,7 @@ type QdiscAttrs struct {
Parent uint32
Refcnt uint32 // read only
IngressBlock *uint32
Statistics *QdiscStatistics
}
func (q QdiscAttrs) String() string {

View File

@ -462,6 +462,18 @@ func (h *Handle) QdiscList(link Link) ([]Qdisc, error) {
ingressBlock := new(uint32)
*ingressBlock = native.Uint32(attr.Value)
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

View File

@ -614,6 +614,12 @@ func TestIngressAddDel(t *testing.T) {
if *qdiscs[0].Attrs().IngressBlock != *ingressBlock {
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 {
t.Fatal(err)
}