Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

htb class cannot limit rate #258

Closed
yandd opened this issue Aug 18, 2017 · 3 comments
Closed

htb class cannot limit rate #258

yandd opened this issue Aug 18, 2017 · 3 comments

Comments

@yandd
Copy link
Contributor

yandd commented Aug 18, 2017

demo is here, https://play.golang.org/p/sCA-isfWEw

		class := netlink.NewHtbClass(netlink.ClassAttrs{
			LinkIndex: link.Attrs().Index,
			Handle:    classidHandle,
			Parent:    parentHandle,
		}, netlink.HtbClassAttrs{
			Rate: uint64(*rate),
			Ceil: uint64(*ceil),
		})
		err = netlink.ClassReplace(class)
		if err != nil {
			fmt.Println("del class failed:", err)
			os.Exit(1)
		}
./tc_class -replace -dev=eth0 -parent=1: -classid=1:1 -rate=1000000 -ceil=1000000

The command above cannot limit the rate, but use 'tc' command can query the class info, and 'tc' command can limit the rate

tc -s -d class show dev eth0

test case:

tc qdisc add dev eth0 root handle 1: htb r2q 1
tc class replace dev eth0 parent 1: classid 1:1 htb rate 1mbit ceil 1mbit burst 1mbit
tc filter add dev eth0 parent 1: prio 1 protocol ip u32 match ip src $LIMIT_IP flowid 1:1
@yandd
Copy link
Contributor Author

yandd commented Aug 21, 2017

in filter_class.go, you cannot do that:

func CalcRtable(rate *nl.TcRateSpec, rtab [256]uint32, cellLog int, mtu uint32, linklayer int) int {
	bps := rate.Rate
	mpu := rate.Mpu
	var sz uint
	if mtu == 0 {
		mtu = 2047
	}
	if cellLog < 0 {
		cellLog = 0
		for (mtu >> uint(cellLog)) > 255 {
			cellLog++
		}
	}
	for i := 0; i < 256; i++ {
		sz = AdjustSize(uint((i+1)<<uint32(cellLog)), uint(mpu), linklayer)
		rtab[i] = uint32(Xmittime(uint64(bps), uint32(sz)))
	}
	rate.CellAlign = -1
	rate.CellLog = uint8(cellLog)
	rate.Linklayer = uint8(linklayer & nl.TC_LINKLAYER_MASK)
	return cellLog
}

It must be like this:

func CalcRtable(rate *nl.TcRateSpec, rtab *[256]uint32, cellLog int, mtu uint32, linklayer int) int {
	bps := rate.Rate
	mpu := rate.Mpu
	var sz uint
	if mtu == 0 {
		mtu = 2047
	}
	if cellLog < 0 {
		cellLog = 0
		for (mtu >> uint(cellLog)) > 255 {
			cellLog++
		}
	}
	for i := 0; i < 256; i++ {
		sz = AdjustSize(uint((i+1)<<uint32(cellLog)), uint(mpu), linklayer)
		(*rtab)[i] = uint32(Xmittime(uint64(bps), uint32(sz)))
	}
	rate.CellAlign = -1
	rate.CellLog = uint8(cellLog)
	rate.Linklayer = uint8(linklayer & nl.TC_LINKLAYER_MASK)
	return cellLog
}

@yandd
Copy link
Contributor Author

yandd commented Aug 21, 2017

I fixed it in pr #259 , and class replace work now!

@yandd
Copy link
Contributor Author

yandd commented Nov 14, 2017

Solved with commit aa48b8c

@yandd yandd closed this as completed Nov 14, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant