1 # Copyright (c) 2016 Cisco and/or its affiliates.
2 # Licensed under the Apache License, Version 2.0 (the "License");
3 # you may not use this file except in compliance with the License.
4 # You may obtain a copy of the License at:
6 # http://www.apache.org/licenses/LICENSE-2.0
8 # Unless required by applicable law or agreed to in writing, software
9 # distributed under the License is distributed on an "AS IS" BASIS,
10 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11 # See the License for the specific language governing permissions and
12 # limitations under the License.
14 """Traffic scripts argument parser library."""
19 class TrafficScriptArg(object):
20 """Traffic scripts argument parser.
22 Parse arguments for traffic script. Default has two arguments '--tx_if'
23 and '--rx_if'. You can provide more arguments. All arguments have string
24 representation of the value.
26 :param more_args: List of aditional arguments (optional).
31 >>> from TrafficScriptArg import TrafficScriptArg
32 >>> args = TrafficScriptArg(['src_mac', 'dst_mac', 'src_ip', 'dst_ip'])
35 def __init__(self, more_args=None):
36 parser = argparse.ArgumentParser()
37 parser.add_argument("--tx_if", help="interface that sends traffic")
38 parser.add_argument("--rx_if", help="interface that receives traffic")
40 if more_args is not None:
42 arg_name = '--{0}'.format(arg)
43 parser.add_argument(arg_name)
46 self._args = vars(parser.parse_args())
48 def get_arg(self, arg_name):
49 """Get argument value.
51 :param arg_name: Argument name.
53 :return: Argument value.
56 arg_val = self._args.get(arg_name)
58 raise Exception("Argument '{0}' not found".format(arg_name))