Skip to content
Snippets Groups Projects
Select Git revision
  • 7f071998474a9e5f7b98103d3058a1b8ca5887e6
  • master default
  • android-container
  • nanopc-t4
  • for-kernelci
  • WIP-syscall
  • v4.16-rc5
  • v4.16-rc4
  • v4.16-rc3
  • v4.16-rc2
  • v4.16-rc1
  • v4.15
  • v4.15-rc9
  • v4.15-rc8
  • v4.15-rc7
  • v4.15-rc6
  • v4.15-rc5
  • v4.15-rc4
  • v4.15-rc3
  • v4.15-rc2
  • v4.15-rc1
  • v4.14
  • v4.14-rc8
  • v4.14-rc7
  • v4.14-rc6
  • v4.14-rc5
26 results

tdc_batch.py

Blame
  • tdc_batch.py 1.74 KiB
    #!/usr/bin/python3
    
    """
    tdc_batch.py - a script to generate TC batch file
    
    Copyright (C) 2017 Chris Mi <chrism@mellanox.com>
    """
    
    import argparse
    
    parser = argparse.ArgumentParser(description='TC batch file generator')
    parser.add_argument("device", help="device name")
    parser.add_argument("file", help="batch file name")
    parser.add_argument("-n", "--number", type=int,
                        help="how many lines in batch file")
    parser.add_argument("-o", "--skip_sw",
                        help="skip_sw (offload), by default skip_hw",
                        action="store_true")
    parser.add_argument("-s", "--share_action",
                        help="all filters share the same action",
                        action="store_true")
    parser.add_argument("-p", "--prio",
                        help="all filters have different prio",
                        action="store_true")
    args = parser.parse_args()
    
    device = args.device
    file = open(args.file, 'w')
    
    number = 1
    if args.number:
        number = args.number
    
    skip = "skip_hw"
    if args.skip_sw:
        skip = "skip_sw"
    
    share_action = ""
    if args.share_action:
        share_action = "index 1"
    
    prio = "prio 1"
    if args.prio:
        prio = ""
        if number > 0x4000:
            number = 0x4000
    
    index = 0
    for i in range(0x100):
        for j in range(0x100):
            for k in range(0x100):
                mac = ("%02x:%02x:%02x" % (i, j, k))
                src_mac = "e4:11:00:" + mac
                dst_mac = "e4:12:00:" + mac
                cmd = ("filter add dev %s %s protocol ip parent ffff: flower %s "
                       "src_mac %s dst_mac %s action drop %s" %
                       (device, prio, skip, src_mac, dst_mac, share_action))
                file.write("%s\n" % cmd)
                index += 1
                if index >= number:
                    file.close()
                    exit(0)