bandwidth: use regexp to handle tc output

fix newly-added 'chain N' output from 'tc filter show dev XXX'
This commit is contained in:
chenyaqi01
2019-10-07 15:09:57 +08:00
committed by chendotjs
parent c86aec0564
commit ef5c920325
2 changed files with 40 additions and 10 deletions

View File

@@ -212,6 +212,13 @@ filter parent 1: protocol ip pref 1 u32 fh 800::800 order 2048 key ht 800 bkt 0
filter parent 1: protocol ip pref 1 u32 fh 800::801 order 2049 key ht 800 bkt 0 flowid 1:2
match 01020000/ffff0000 at 16
`
var tcFilterOutputNewVersion = `filter parent 1: protocol ip pref 1 u32
filter parent 1: protocol ip pref 1 u32 chain 0 fh 800: ht divisor 1
filter parent 1: protocol ip pref 1 u32 chain 0 fh 800::800 order 2048 key ht 800 bkt 0 flowid 1:1 not_in_hw
match ac110002/ffffffff at 16
filter parent 1: protocol ip pref 1 u32 chain 0 fh 800::801 order 2049 key ht 800 bkt 0 flowid 1:2 not_in_hw
match 01020000/ffff0000 at 16
`
func TestFindCIDRClass(t *testing.T) {
tests := []struct {
@@ -240,6 +247,23 @@ func TestFindCIDRClass(t *testing.T) {
output: tcFilterOutput,
expectNotFound: true,
},
{
cidr: "172.17.0.2/32",
output: tcFilterOutputNewVersion,
expectedClass: "1:1",
expectedHandle: "800::800",
},
{
cidr: "1.2.3.4/16",
output: tcFilterOutputNewVersion,
expectedClass: "1:2",
expectedHandle: "800::801",
},
{
cidr: "2.2.3.4/16",
output: tcFilterOutputNewVersion,
expectNotFound: true,
},
{
err: errors.New("test error"),
expectErr: true,