ec08efd17cd4d702ddfcbcdcf7d94acc217df30c
[csit.git] / resources / libraries / python / SFC / SFCTest.py
1 # Copyright (c) 2017 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:
5 #
6 #     http://www.apache.org/licenses/LICENSE-2.0
7 #
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.
13
14 """
15 This module implements functionality which configure and start
16 the NSH SFC functional test.
17 """
18
19 from resources.libraries.python.ssh import SSH
20 from resources.libraries.python.constants import Constants as con
21 from resources.libraries.python.topology import Topology
22
23 class SFCTest(object):
24     """Configure and Start the NSH SFC functional tests."""
25
26     @staticmethod
27     def config_and_start_SFC_test(dut_node, dut_if1, dut_if2, if1_adj_mac,
28                                   if2_adj_mac, testtype):
29         """
30         Start the SFC functional on the dut_node.
31
32         :param dut_node: Will execute the SFC on this node.
33         :param dut_if1: The first ingress interface on the DUT.
34         :param dut_if2: The last egress interface on the DUT.
35         :param if1_adj_mac: The interface 1 adjacency MAC.
36         :param if2_adj_mac: The interface 2 adjacency MAC.
37         :param testtype: The SFC functional test type.
38                          (Classifier, Proxy Inbound, Proxy Outbound, SFF).
39         :type dut_node: dict
40         :type dut_if1: str
41         :type dut_if2: str
42         :type if1_adj_mac: str
43         :type if2_adj_mac: str
44         :type testtype: str
45         :returns: none
46         :raises RuntimeError: If the script execute fails.
47         """
48
49         vpp_intf_name1 = Topology.get_interface_name(dut_node, dut_if1)
50         vpp_intf_name2 = Topology.get_interface_name(dut_node, dut_if2)
51
52         ssh = SSH()
53         ssh.connect(dut_node)
54
55         if testtype == "Classifier":
56             exec_shell = "set_sfc_classifier.sh"
57         elif testtype == "Proxy Inbound":
58             exec_shell = "set_nsh_proxy_inbound.sh"
59         elif testtype == "Proxy Outbound":
60             exec_shell = "set_nsh_proxy_outbound.sh"
61         else:
62             exec_shell = "set_sfc_sff.sh"
63
64         cmd = 'cd {0}/tests/nsh_sfc/sfc_scripts/ && sudo ./{1} {2} ' \
65              '{3} {4} {5}'.format(con.REMOTE_FW_DIR, exec_shell, vpp_intf_name1,
66                                vpp_intf_name2, if1_adj_mac, if2_adj_mac)
67
68         (ret_code, _, _) = ssh.exec_command(cmd, timeout=600)
69         if ret_code != 0:
70             raise RuntimeError('Failed to execute SFC setup script ' \
71                  '{0} at node {1}'.format(exec_shell, dut_node['host']))