diff options
author | Tibor Frank <tifrank@cisco.com> | 2017-03-13 13:22:08 +0100 |
---|---|---|
committer | Tibor Frank <tifrank@cisco.com> | 2017-04-18 11:24:44 +0200 |
commit | 28bab4e715a123199972bdc5f79f6a508a879fd6 (patch) | |
tree | 0b6c3a3aa71eb80143eae2c62086a61e153818c6 /resources/libraries/python/SNATUtil.py | |
parent | 4da982b7a0f5872de2cc721607894216a20892f4 (diff) |
CSIT-545: Performance tests for SNAT
- High level definition (HLD)
- Low level definition (LLD)
- Add keywords to set SNAT
- Add tests according to HLD, LLD
Change-Id: I7bf0b1870ac9c3adb36bb6590be9a3eb4ea8aa9a
Signed-off-by: Tibor Frank <tifrank@cisco.com>
Diffstat (limited to 'resources/libraries/python/SNATUtil.py')
-rw-r--r-- | resources/libraries/python/SNATUtil.py | 171 |
1 files changed, 171 insertions, 0 deletions
diff --git a/resources/libraries/python/SNATUtil.py b/resources/libraries/python/SNATUtil.py new file mode 100644 index 0000000000..02cf493a93 --- /dev/null +++ b/resources/libraries/python/SNATUtil.py @@ -0,0 +1,171 @@ +# Copyright (c) 2017 Cisco and/or its affiliates. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at: +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +"""SNAT utilities library.""" + +from resources.libraries.python.VatExecutor import VatTerminal + + +class SNATUtil(object): + """This class defines the methods to set SNAT.""" + + def __init__(self): + pass + + @staticmethod + def set_snat_interfaces(node, int_in, int_out): + """Set inside and outside interfaces for SNAT. + + :param node: DUT node. + :param int_in: Inside interface. + :param int_out: Outside interface. + :type node: dict + :type int_in: str + :type int_out: str + :returns: Response of the command. + :rtype: str + :raises RuntimeError: If setting of inside and outside interfaces for + SNAT fails. + """ + + try: + with VatTerminal(node, json_param=False) as vat: + response = vat.vat_terminal_exec_cmd_from_template( + 'snat/snat_set_interfaces.vat', + int_in=int_in, int_out=int_out) + return response + except: + raise RuntimeError("Setting of inside and outside interfaces for " + "SNAT failed!") + + @staticmethod + def set_snat_deterministic(node, ip_in, subnet_in, ip_out, subnet_out): + """Set deterministic behaviour of SNAT. + + :param node: DUT node. + :param ip_in: Inside IP. + :param subnet_in: Inside IP subnet. + :param ip_out: Outside IP. + :param subnet_out: Outside IP subnet. + :type node: dict + :type ip_in: str + :type subnet_in: str or int + :type ip_out: str + :type subnet_out: str or int + :returns: Response of the command. + :rtype: str + :raises RuntimeError: If setting of deterministic behaviour of SNAT + fails. + """ + + try: + with VatTerminal(node, json_param=False) as vat: + response = vat.vat_terminal_exec_cmd_from_template( + 'snat/snat_set_deterministic.vat', + ip_in=ip_in, subnet_in=subnet_in, + ip_out=ip_out, subnet_out=subnet_out) + return response + except: + raise RuntimeError("Setting of deterministic behaviour of SNAT " + "failed!") + + @staticmethod + def set_snat_workers(node, lcores): + """Set SNAT workers. + + :param node: DUT node. + :param lcores: list of cores, format: range e.g. 1-5 or list of ranges + e.g.: 1-5,18-22. + :type node: dict + :type lcores: str + :returns: Response of the command. + :rtype: str + :raises RuntimeError: If setting of SNAT workers fails. + """ + + try: + with VatTerminal(node, json_param=False) as vat: + response = vat.vat_terminal_exec_cmd_from_template( + 'snat/snat_set_workers.vat', lcores=lcores) + return response + except: + raise RuntimeError("Setting of SNAT workers failed!") + + @staticmethod + def show_snat(node): + """Show the SNAT settings. + + :param node: DUT node. + :type node: dict + :returns: Response of the command. + :rtype: str + :raises RuntimeError: If getting of SNAT settings fails. + """ + + try: + with VatTerminal(node, json_param=False) as vat: + response = vat.vat_terminal_exec_cmd_from_template( + 'snat/snat_show_snat.vat') + return response + except: + raise RuntimeError("Getting of SNAT settings failed!") + + @staticmethod + def show_snat_deterministic_forward(node, ip_addr): + """Show forward IP address and port(s). + + :param node: DUT node. + :param ip_addr: IP address. + :type node: dict + :type ip_addr: str + :returns: Response of the command. + :rtype: str + :raises RuntimeError: If command 'exec snat deterministic forward' + fails. + """ + + try: + with VatTerminal(node, json_param=False) as vat: + response = vat.vat_terminal_exec_cmd_from_template( + 'snat/snat_deterministic_forward.vat', ip=ip_addr) + return response + except: + raise RuntimeError("Command 'exec snat deterministic forward {ip}'" + " failed!".format(ip=ip_addr)) + + @staticmethod + def show_snat_deterministic_reverse(node, ip_addr, port): + """Show reverse IP address. + + :param node: DUT node. + :param ip_addr: IP address. + :param port: Port. + :type node: dict + :type ip_addr: str + :type port: str or int + :returns: Response of the command. + :rtype: str + :raises RuntimeError: If command 'exec snat deterministic reverse' + fails. + """ + + try: + with VatTerminal(node, json_param=False) as vat: + response = vat.vat_terminal_exec_cmd_from_template( + 'snat/snat_deterministic_reverse.vat', + ip=ip_addr, port=port) + return response + except: + raise RuntimeError( + "Command 'exec snat deterministic reverse {ip}:{port}'" + " failed!".format(ip=ip_addr, port=port)) |