.. | .. |
---|
13 | 13 | parser.add_argument("file", help="batch file name") |
---|
14 | 14 | parser.add_argument("-n", "--number", type=int, |
---|
15 | 15 | help="how many lines in batch file") |
---|
| 16 | +parser.add_argument( |
---|
| 17 | + "-a", |
---|
| 18 | + "--handle_start", |
---|
| 19 | + type=int, |
---|
| 20 | + default=1, |
---|
| 21 | + help="start handle range from (default: 1)") |
---|
16 | 22 | parser.add_argument("-o", "--skip_sw", |
---|
17 | 23 | help="skip_sw (offload), by default skip_hw", |
---|
18 | 24 | action="store_true") |
---|
.. | .. |
---|
22 | 28 | parser.add_argument("-p", "--prio", |
---|
23 | 29 | help="all filters have different prio", |
---|
24 | 30 | action="store_true") |
---|
| 31 | +parser.add_argument( |
---|
| 32 | + "-e", |
---|
| 33 | + "--operation", |
---|
| 34 | + choices=['add', 'del', 'replace'], |
---|
| 35 | + default='add', |
---|
| 36 | + help="operation to perform on filters" |
---|
| 37 | + "(default: add filter)") |
---|
| 38 | +parser.add_argument( |
---|
| 39 | + "-m", |
---|
| 40 | + "--mac_prefix", |
---|
| 41 | + type=int, |
---|
| 42 | + default=0, |
---|
| 43 | + choices=range(0, 256), |
---|
| 44 | + help="third byte of source MAC address of flower filter" |
---|
| 45 | + "(default: 0)") |
---|
25 | 46 | args = parser.parse_args() |
---|
26 | 47 | |
---|
27 | 48 | device = args.device |
---|
.. | .. |
---|
30 | 51 | number = 1 |
---|
31 | 52 | if args.number: |
---|
32 | 53 | number = args.number |
---|
| 54 | + |
---|
| 55 | +handle_start = args.handle_start |
---|
33 | 56 | |
---|
34 | 57 | skip = "skip_hw" |
---|
35 | 58 | if args.skip_sw: |
---|
.. | .. |
---|
45 | 68 | if number > 0x4000: |
---|
46 | 69 | number = 0x4000 |
---|
47 | 70 | |
---|
| 71 | +mac_prefix = args.mac_prefix |
---|
| 72 | + |
---|
| 73 | +def format_add_filter(device, prio, handle, skip, src_mac, dst_mac, |
---|
| 74 | + share_action): |
---|
| 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)) |
---|
| 78 | + |
---|
| 79 | + |
---|
| 80 | +def format_rep_filter(device, prio, handle, skip, src_mac, dst_mac, |
---|
| 81 | + share_action): |
---|
| 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)) |
---|
| 85 | + |
---|
| 86 | + |
---|
| 87 | +def format_del_filter(device, prio, handle, skip, src_mac, dst_mac, |
---|
| 88 | + share_action): |
---|
| 89 | + return ("filter del dev {} {} protocol ip ingress handle {} " |
---|
| 90 | + "flower".format(device, prio, handle)) |
---|
| 91 | + |
---|
| 92 | + |
---|
| 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 |
---|
| 98 | + |
---|
48 | 99 | index = 0 |
---|
49 | 100 | for i in range(0x100): |
---|
50 | 101 | for j in range(0x100): |
---|
51 | 102 | for k in range(0x100): |
---|
52 | 103 | mac = ("{:02x}:{:02x}:{:02x}".format(i, j, k)) |
---|
53 | | - src_mac = "e4:11:00:" + mac |
---|
| 104 | + src_mac = "e4:11:{:02x}:{}".format(mac_prefix, mac) |
---|
54 | 105 | dst_mac = "e4:12:00:" + mac |
---|
55 | | - cmd = ("filter add dev {} {} protocol ip parent ffff: flower {} " |
---|
56 | | - "src_mac {} dst_mac {} action drop {}".format |
---|
57 | | - (device, prio, skip, src_mac, dst_mac, share_action)) |
---|
| 106 | + cmd = formatter(device, prio, handle_start + index, skip, src_mac, |
---|
| 107 | + dst_mac, share_action) |
---|
58 | 108 | file.write("{}\n".format(cmd)) |
---|
59 | 109 | index += 1 |
---|
60 | 110 | if index >= number: |
---|