~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/tools/testing/selftests/tc-testing/tdc_batch.py

Version: ~ [ linux-6.12-rc7 ] ~ [ linux-6.11.7 ] ~ [ linux-6.10.14 ] ~ [ linux-6.9.12 ] ~ [ linux-6.8.12 ] ~ [ linux-6.7.12 ] ~ [ linux-6.6.60 ] ~ [ linux-6.5.13 ] ~ [ linux-6.4.16 ] ~ [ linux-6.3.13 ] ~ [ linux-6.2.16 ] ~ [ linux-6.1.116 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.171 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.229 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.285 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.323 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.336 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.337 ] ~ [ linux-4.4.302 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.12 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 #!/usr/bin/env 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(
 17     "-a",
 18     "--handle_start",
 19     type=int,
 20     default=1,
 21     help="start handle range from (default: 1)")
 22 parser.add_argument("-o", "--skip_sw",
 23                     help="skip_sw (offload), by default skip_hw",
 24                     action="store_true")
 25 parser.add_argument("-s", "--share_action",
 26                     help="all filters share the same action",
 27                     action="store_true")
 28 parser.add_argument("-p", "--prio",
 29                     help="all filters have different prio",
 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)")
 46 args = parser.parse_args()
 47 
 48 device = args.device
 49 file = open(args.file, 'w')
 50 
 51 number = 1
 52 if args.number:
 53     number = args.number
 54 
 55 handle_start = args.handle_start
 56 
 57 skip = "skip_hw"
 58 if args.skip_sw:
 59     skip = "skip_sw"
 60 
 61 share_action = ""
 62 if args.share_action:
 63     share_action = "index 1"
 64 
 65 prio = "prio 1"
 66 if args.prio:
 67     prio = ""
 68     if number > 0x4000:
 69         number = 0x4000
 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 
 99 index = 0
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))
109             index += 1
110             if index >= number:
111                 file.close()
112                 exit(0)

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

sflogo.php