diff options
author | 2016-11-13 17:17:36 +0200 | |
---|---|---|
committer | 2016-11-13 17:17:36 +0200 | |
commit | 6e1919c3aebabc0977a8ab40b5c60cbd0e7114d0 (patch) | |
tree | 502aa78527ee4de1723e4a32c291dfcdb71cea23 /scripts/automation/trex_control_plane/stl/trex_stl_lib/utils | |
parent | ab28fccc187c6134eeb0400ce0b113a77e498bb2 (diff) |
RX features - pre-resolve stage
Signed-off-by: imarom <imarom@cisco.com>
Diffstat (limited to 'scripts/automation/trex_control_plane/stl/trex_stl_lib/utils')
-rw-r--r-- | scripts/automation/trex_control_plane/stl/trex_stl_lib/utils/common.py | 5 | ||||
-rwxr-xr-x | scripts/automation/trex_control_plane/stl/trex_stl_lib/utils/parsing_opts.py | 33 |
2 files changed, 36 insertions, 2 deletions
diff --git a/scripts/automation/trex_control_plane/stl/trex_stl_lib/utils/common.py b/scripts/automation/trex_control_plane/stl/trex_stl_lib/utils/common.py index f0da9a08..d4ac973d 100644 --- a/scripts/automation/trex_control_plane/stl/trex_stl_lib/utils/common.py +++ b/scripts/automation/trex_control_plane/stl/trex_stl_lib/utils/common.py @@ -4,6 +4,7 @@ import string import random import time import socket +import re try: import pwd @@ -93,3 +94,7 @@ def is_valid_ipv4 (addr): return True except socket.error: return False + +def is_valid_mac (mac): + return bool(re.match("[0-9a-f]{2}([-:])[0-9a-f]{2}(\\1[0-9a-f]{2}){4}$", mac.lower())) + diff --git a/scripts/automation/trex_control_plane/stl/trex_stl_lib/utils/parsing_opts.py b/scripts/automation/trex_control_plane/stl/trex_stl_lib/utils/parsing_opts.py index b93a797d..80260d4a 100755 --- a/scripts/automation/trex_control_plane/stl/trex_stl_lib/utils/parsing_opts.py +++ b/scripts/automation/trex_control_plane/stl/trex_stl_lib/utils/parsing_opts.py @@ -1,6 +1,6 @@ import argparse from collections import namedtuple, OrderedDict -from .common import list_intersect, list_difference +from .common import list_intersect, list_difference, is_valid_ipv4, is_valid_mac from .text_opts import format_text from ..trex_stl_types import * from .constants import ON_OFF_DICT, UP_DOWN_DICT, FLOW_CTRL_DICT @@ -45,12 +45,14 @@ FLOW_CTRL = 28 SUPPORTED = 29 RX_FILTER_MODE = 30 - OUTPUT_FILENAME = 31 ALL_FILES = 32 LIMIT = 33 PORT_RESTART = 34 +IPV4 = 35 +DEST = 36 + GLOBAL_STATS = 50 PORT_STATS = 51 PORT_STATUS = 52 @@ -224,8 +226,20 @@ def is_valid_file(filename): return filename +def check_ipv4_addr (ipv4_str): + if not is_valid_ipv4(ipv4_str): + raise argparse.ArgumentTypeError("invalid IPv4 address: '{0}'".format(ipv4_str)) + + return ipv4_str + +def check_dest_addr (addr): + if not (is_valid_ipv4(addr) or is_valid_mac(addr)): + raise argparse.ArgumentTypeError("not a valid IPv4 or MAC address: '{0}'".format(addr)) + + return addr + def decode_tunables (tunable_str): tunables = {} @@ -316,6 +330,21 @@ OPTIONS_DB = {MULTIPLIER: ArgumentPack(['-m', '--multiplier'], 'choices': ['hw', 'all']}), + IPV4: ArgumentPack(['--ipv4'], + {'help': 'IPv4 address(s) for the port(s)', + 'dest': 'ipv4', + 'nargs': '+', + 'default': None, + 'type': check_ipv4_addr}), + + DEST: ArgumentPack(['--dest'], + {'help': 'Destination address(s) for the port(s) in either IPv4 or MAC format', + 'dest': 'dest', + 'nargs': '+', + 'default': None, + 'type': check_dest_addr}), + + OUTPUT_FILENAME: ArgumentPack(['-o', '--output'], {'help': 'Output PCAP filename', 'dest': 'output_filename', |