mirror of
https://github.com/luscis/openlan.git
synced 2025-10-30 04:01:45 +08:00
fea: support rate limit.
This commit is contained in:
@@ -2,6 +2,7 @@ package cswitch
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"os"
|
||||
"strings"
|
||||
"sync"
|
||||
@@ -599,3 +600,21 @@ func (v *Switch) Reload() {
|
||||
func (v *Switch) Save() {
|
||||
v.cfg.Save()
|
||||
}
|
||||
|
||||
func (v *Switch) AddRate(device string, mbit int) {
|
||||
kbits := fmt.Sprintf("%dMbit", mbit)
|
||||
burst := "64Kb"
|
||||
latency := "400ms"
|
||||
|
||||
out, err := libol.Exec("tc", "qdisc", "add", "dev", device, "root", "tbf", "rate", kbits, "burst", burst, "latency", latency)
|
||||
if err != nil {
|
||||
v.out.Warn("Switch.AddRate: %s %d %s", device, mbit, out)
|
||||
}
|
||||
}
|
||||
|
||||
func (v *Switch) DelRate(device string) {
|
||||
out, err := libol.Exec("tc", "qdisc", "del", "dev", device, "root")
|
||||
if err != nil {
|
||||
v.out.Warn("Switch.AddRate: %s %s", device, out)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user