2
0
mirror of https://github.com/edk2-porting/linux-next.git synced 2024-12-26 14:14:01 +08:00
linux-next/tools/testing/selftests/tc-testing/tdc_batch.py
BTaskaya 3adc1c63e2 tc: python3, string formattings
This patch converts old type string formattings to new type string
formattings for adapting Linux Traffic Control (tc) unit testing suite
python3.

Linux Traffic Control (tc) unit testing suite's code quality improved is improved with this patch.
According to python documentation;
"The built-in string class provides the ability to do complex variable substitutions and
value formatting via the format() method described in PEP 3101. "
but the project was using old type formattings and new type string formattings together,
this patch's main purpose is converting all old types to new types.

Following files changed:
 1. tools/testing/selftests/tc-testing/tdc.py
 2. tools/testing/selftests/tc-testing/tdc_batch.py

Following PEP rules applied:
 1. PEP8 - Code Styling
 2. PEP3101 - Advanced Code Formatting

 Signed-off-by: Batuhan Osman Taskaya <batuhanosmantaskaya@gmail.com>

Signed-off-by: David S. Miller <davem@davemloft.net>
2018-02-26 13:31:22 -05:00

63 lines
1.8 KiB
Python
Executable File

#!/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}".format(i, j, k))
src_mac = "e4:11:00:" + mac
dst_mac = "e4:12:00:" + mac
cmd = ("filter add dev {} {} protocol ip parent ffff: flower {} "
"src_mac {} dst_mac {} action drop {}".format
(device, prio, skip, src_mac, dst_mac, share_action))
file.write("{}\n".format(cmd))
index += 1
if index >= number:
file.close()
exit(0)