diff options
author | Chris Mi <chrism@mellanox.com> | 2017-10-26 21:24:42 -0400 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2017-10-29 09:49:31 -0400 |
commit | 7f071998474a9e5f7b98103d3058a1b8ca5887e6 (patch) | |
tree | b0dbf7eab9447f3e5d5059c5418c5ef847001147 /tools | |
parent | 46e235c15ca44f34cb79f4dbec909b8c51999dc1 (diff) |
selftests: Introduce a new script to generate tc batch file
# ./tdc_batch.py -h
usage: tdc_batch.py [-h] [-n NUMBER] [-o] [-s] [-p] device file
TC batch file generator
positional arguments:
device device name
file batch file name
optional arguments:
-h, --help show this help message and exit
-n NUMBER, --number NUMBER
how many lines in batch file
-o, --skip_sw skip_sw (offload), by default skip_hw
-s, --share_action all filters share the same action
-p, --prio all filters have different prio
Acked-by: Jamal Hadi Salim <jhs@mojatatu.com>
Acked-by: Lucas Bates <lucasb@mojatatu.com>
Signed-off-by: Chris Mi <chrism@mellanox.com>
Signed-off-by: Cong Wang <xiyou.wangcong@gmail.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'tools')
-rwxr-xr-x | tools/testing/selftests/tc-testing/tdc_batch.py | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/tools/testing/selftests/tc-testing/tdc_batch.py b/tools/testing/selftests/tc-testing/tdc_batch.py new file mode 100755 index 000000000000..707c6bfef689 --- /dev/null +++ b/tools/testing/selftests/tc-testing/tdc_batch.py | |||
@@ -0,0 +1,62 @@ | |||
1 | #!/usr/bin/python3 | ||
2 | |||
3 | """ | ||
4 | tdc_batch.py - a script to generate TC batch file | ||
5 | |||
6 | Copyright (C) 2017 Chris Mi <chrism@mellanox.com> | ||
7 | """ | ||
8 | |||
9 | import argparse | ||
10 | |||
11 | parser = argparse.ArgumentParser(description='TC batch file generator') | ||
12 | parser.add_argument("device", help="device name") | ||
13 | parser.add_argument("file", help="batch file name") | ||
14 | parser.add_argument("-n", "--number", type=int, | ||
15 | help="how many lines in batch file") | ||
16 | parser.add_argument("-o", "--skip_sw", | ||
17 | help="skip_sw (offload), by default skip_hw", | ||
18 | action="store_true") | ||
19 | parser.add_argument("-s", "--share_action", | ||
20 | help="all filters share the same action", | ||
21 | action="store_true") | ||
22 | parser.add_argument("-p", "--prio", | ||
23 | help="all filters have different prio", | ||
24 | action="store_true") | ||
25 | args = parser.parse_args() | ||
26 | |||
27 | device = args.device | ||
28 | file = open(args.file, 'w') | ||
29 | |||
30 | number = 1 | ||
31 | if args.number: | ||
32 | number = args.number | ||
33 | |||
34 | skip = "skip_hw" | ||
35 | if args.skip_sw: | ||
36 | skip = "skip_sw" | ||
37 | |||
38 | share_action = "" | ||
39 | if args.share_action: | ||
40 | share_action = "index 1" | ||
41 | |||
42 | prio = "prio 1" | ||
43 | if args.prio: | ||
44 | prio = "" | ||
45 | if number > 0x4000: | ||
46 | number = 0x4000 | ||
47 | |||
48 | index = 0 | ||
49 | for i in range(0x100): | ||
50 | for j in range(0x100): | ||
51 | for k in range(0x100): | ||
52 | mac = ("%02x:%02x:%02x" % (i, j, k)) | ||
53 | src_mac = "e4:11:00:" + mac | ||
54 | dst_mac = "e4:12:00:" + mac | ||
55 | cmd = ("filter add dev %s %s protocol ip parent ffff: flower %s " | ||
56 | "src_mac %s dst_mac %s action drop %s" % | ||
57 | (device, prio, skip, src_mac, dst_mac, share_action)) | ||
58 | file.write("%s\n" % cmd) | ||
59 | index += 1 | ||
60 | if index >= number: | ||
61 | file.close() | ||
62 | exit(0) | ||