Skip to content

Commit

Permalink
Add support for TCA_HTB_DIRECT_QLEN in HTB qdisc
Browse files Browse the repository at this point in the history
- Extend Htb struct in qdisc.go to include DirectQlen field
- Implement the DirectQlen option in qdisc_linux.go
- Modify TestHtbAddDel test to validate DirectQlen changes
  • Loading branch information
bc-lee authored and aboch committed Jul 3, 2024
1 parent 7b12054 commit a1c5e02
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 3 deletions.
2 changes: 2 additions & 0 deletions qdisc.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ type Htb struct {
Defcls uint32
Debug uint32
DirectPkts uint32
DirectQlen *uint32
}

func NewHtb(attrs QdiscAttrs) *Htb {
Expand All @@ -133,6 +134,7 @@ func NewHtb(attrs QdiscAttrs) *Htb {
Rate2Quantum: 10,
Debug: 0,
DirectPkts: 0,
DirectQlen: nil,
}
}

Expand Down
8 changes: 5 additions & 3 deletions qdisc_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,9 @@ func qdiscPayload(req *nl.NetlinkRequest, qdisc Qdisc) error {
opt.Debug = qdisc.Debug
opt.DirectPkts = qdisc.DirectPkts
options.AddRtAttr(nl.TCA_HTB_INIT, opt.Serialize())
// options.AddRtAttr(nl.TCA_HTB_DIRECT_QLEN, opt.Serialize())
if qdisc.DirectQlen != nil {
options.AddRtAttr(nl.TCA_HTB_DIRECT_QLEN, nl.Uint32Attr(*qdisc.DirectQlen))
}
case *Hfsc:
opt := nl.TcHfscOpt{}
opt.Defcls = qdisc.Defcls
Expand Down Expand Up @@ -526,8 +528,8 @@ func parseHtbData(qdisc Qdisc, data []syscall.NetlinkRouteAttr) error {
htb.Debug = opt.Debug
htb.DirectPkts = opt.DirectPkts
case nl.TCA_HTB_DIRECT_QLEN:
// TODO
//htb.DirectQlen = native.uint32(datum.Value)
directQlen := native.Uint32(datum.Value)
htb.DirectQlen = &directQlen
}
}
return nil
Expand Down
5 changes: 5 additions & 0 deletions qdisc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,8 @@ func TestHtbAddDel(t *testing.T) {

qdisc := NewHtb(attrs)
qdisc.Rate2Quantum = 5
directQlen := uint32(10)
qdisc.DirectQlen = &directQlen
if err := QdiscAdd(qdisc); err != nil {
t.Fatal(err)
}
Expand All @@ -111,6 +113,9 @@ func TestHtbAddDel(t *testing.T) {
if htb.Debug != qdisc.Debug {
t.Fatal("Debug doesn't match")
}
if htb.DirectQlen == nil || *htb.DirectQlen != directQlen {
t.Fatalf("DirectQlen doesn't match. Expected %d, got %v", directQlen, htb.DirectQlen)
}
if err := QdiscDel(qdisc); err != nil {
t.Fatal(err)
}
Expand Down

0 comments on commit a1c5e02

Please sign in to comment.