xref: /linux/tools/testing/selftests/tc-testing/tdc_multibatch.py (revision da1d9caf95def6f0320819cf941c9fd1069ba9e1)
1#!/usr/bin/env python3
2# SPDX-License-Identifier: GPL-2.0
3"""
4tdc_multibatch.py - a thin wrapper over tdc_batch.py to generate multiple batch
5files
6
7Copyright (C) 2019 Vlad Buslov <vladbu@mellanox.com>
8"""
9
10import argparse
11import os
12
13parser = argparse.ArgumentParser(
14    description='TC multiple batch file generator')
15parser.add_argument("device", help="device name")
16parser.add_argument("dir", help="where to put batch files")
17parser.add_argument(
18    "num_filters", type=int, help="how many lines per batch file")
19parser.add_argument("num_files", type=int, help="how many batch files")
20parser.add_argument(
21    "operation",
22    choices=['add', 'del', 'replace'],
23    help="operation to perform on filters")
24parser.add_argument(
25    "-x",
26    "--file_prefix",
27    default="",
28    help="prefix for generated batch file names")
29parser.add_argument(
30    "-d",
31    "--duplicate_handles",
32    action="store_true",
33    help="duplicate filter handle range in all files")
34parser.add_argument(
35    "-a",
36    "--handle_start",
37    type=int,
38    default=1,
39    help="start handle range from (default: 1)")
40parser.add_argument(
41    "-m",
42    "--mac_prefix",
43    type=int,
44    default=0,
45    choices=range(0, 256),
46    help="add this value to third byte of source MAC address of flower filter"
47    "(default: 0)")
48args = parser.parse_args()
49
50device = args.device
51dir = args.dir
52file_prefix = args.file_prefix + args.operation + "_"
53num_filters = args.num_filters
54num_files = args.num_files
55operation = args.operation
56duplicate_handles = args.duplicate_handles
57handle = args.handle_start
58mac_prefix = args.mac_prefix
59
60for i in range(num_files):
61    file = dir + '/' + file_prefix + str(i)
62    os.system("./tdc_batch.py -n {} -a {} -e {} -m {} {} {}".format(
63        num_filters, handle, operation, i + mac_prefix, device, file))
64    if not duplicate_handles:
65        handle += num_filters
66