4 tdc_batch.py - a script to generate TC batch file
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")
21 help="start handle range from (default: 1)")
22 parser.add_argument("-o", "--skip_sw",
23 help="skip_sw (offload), by default skip_hw",
25 parser.add_argument("-s", "--share_action",
26 help="all filters share the same action",
28 parser.add_argument("-p", "--prio",
29 help="all filters have different prio",
34 choices=['add', 'del', 'replace'],
36 help="operation to perform on filters"
37 "(default: add filter)")
43 choices=range(0, 256),
44 help="third byte of source MAC address of flower filter"
46 args = parser.parse_args()
49 file = open(args.file, 'w')
55 handle_start = args.handle_start
63 share_action = "index 1"
71 mac_prefix = args.mac_prefix
73 def format_add_filter(device, prio, handle, skip, src_mac, dst_mac,
75 return ("filter add dev {} {} protocol ip ingress handle {} "
76 " flower {} src_mac {} dst_mac {} action drop {}".format(
77 device, prio, handle, skip, src_mac, dst_mac, share_action))
80 def format_rep_filter(device, prio, handle, skip, src_mac, dst_mac,
82 return ("filter replace dev {} {} protocol ip ingress handle {} "
83 " flower {} src_mac {} dst_mac {} action drop {}".format(
84 device, prio, handle, skip, src_mac, dst_mac, share_action))
87 def format_del_filter(device, prio, handle, skip, src_mac, dst_mac,
89 return ("filter del dev {} {} protocol ip ingress handle {} "
90 "flower".format(device, prio, handle))
93 formatter = format_add_filter
94 if args.operation == "del":
95 formatter = format_del_filter
96 elif args.operation == "replace":
97 formatter = format_rep_filter
100 for i in range(0x100):
101 for j in range(0x100):
102 for k in range(0x100):
103 mac = ("{:02x}:{:02x}:{:02x}".format(i, j, k))
104 src_mac = "e4:11:{:02x}:{}".format(mac_prefix, mac)
105 dst_mac = "e4:12:00:" + mac
106 cmd = formatter(device, prio, handle_start + index, skip, src_mac,
107 dst_mac, share_action)
108 file.write("{}\n".format(cmd))