1 # Copyright (c) 2018 Huawei Technologies Co.,Ltd.
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.
16 This module exists to provide the vs_epoll ping test for DMM on topology nodes.
20 from resources.libraries.python.ssh import exec_cmd_no_error
21 from resources.libraries.python.DMM.DMMConstants import DMMConstants as con
22 from resources.libraries.python.topology import Topology
24 class SingleCliSer(object):
25 """Test the DMM vs_epoll ping function."""
28 def exec_the_base_vs_epoll_test(dut1_node, dut2_node,
29 dut1_if_name, dut2_if_name,
30 dut1_if_ip, dut2_if_ip):
32 Perform base vs_epoll test on DUT's.
34 :param dut1_node: Node to execute vs_epoll on.
35 :param dut2_node: Node to execute vc_common on.
36 :param dut1_if_name: DUT1 to DUT2 interface name.
37 :param dut2_if_name: DUT2 to DUT1 interface name.
38 :param dut1_if_ip: DUT1 to DUT2 interface ip.
39 :param dut2_if_ip: DUT2 to DUT1 interface ip.
42 :type dut1_if_name: str
43 :type dut2_if_name: str
47 cmd = 'cd {0}/{1} && ./run_dmm.sh {2} {3} {4} {5} ' \
48 .format(con.REMOTE_FW_DIR, con.DMM_SCRIPTS, 0, dut1_if_name,
49 dut1_if_ip, dut2_if_ip)
51 cmd += '2>&1 | tee log_run_dmm.txt &'
52 exec_cmd_no_error(dut1_node, cmd)
55 cmd = 'cd {0}/{1} && ./run_dmm.sh {2} {3} {4} {5} ' \
56 .format(con.REMOTE_FW_DIR, con.DMM_SCRIPTS, 1, dut2_if_name,
57 dut1_if_ip, dut2_if_ip)
59 cmd += '2>&1 | tee log_run_dmm.txt'
60 exec_cmd_no_error(dut2_node, cmd)
63 def get_the_test_result(dut_node):
65 After executing exec_the_base_vs_epoll_test, use this
66 to get the test result.
68 :param dut_node: Node to get the test result on.
70 :returns: Word count of "send 50000" in the log.
73 cmd = 'cat {0}/{1}/log_run_dmm.txt | grep "send 50000" | wc -l' \
74 .format(con.REMOTE_FW_DIR, con.DMM_SCRIPTS)
75 (stdout, _) = exec_cmd_no_error(dut_node, cmd)
79 def echo_dmm_logs(dut_node):
81 Get the prerequisites installation log from DUT.
83 :param dut_node: Node to get the installation log on.
86 cmd = 'cat {0}/{1}/log_install_prereq.txt' \
87 .format(con.REMOTE_FW_DIR, con.DMM_SCRIPTS)
88 exec_cmd_no_error(dut_node, cmd)
91 def exec_the_base_lwip_test(dut1_node, dut2_node,
92 dut1_if_name, dut2_if_name,
93 dut1_if_ip, dut2_if_ip):
94 """Test DMM with LWIP.
96 :param dut1_node: Node to execute vs_epoll on.
97 :param dut2_node: Node to execute vc_common on.
98 :param dut1_if_name: DUT1 to DUT2 interface name.
99 :param dut2_if_name: DUT2 to DUT1 interface name.
100 :param dut1_if_ip: DUT1 to DUT2 interface ip.
101 :param dut2_if_ip: DUT2 to DUT1 interface ip.
102 :type dut1_node: dict
103 :type dut2_node: dict
104 :type dut1_if_name: str
105 :type dut2_if_name: str
106 :type dut1_if_ip: str
107 :type dut2_if_ip: str
109 cmd = 'cd {0}/{1} && ./run_dmm_with_lwip.sh {2} {3} {4} {5} ' \
110 .format(con.REMOTE_FW_DIR, con.DMM_SCRIPTS, 0, dut1_if_name,
111 dut1_if_ip, dut2_if_ip)
113 cmd += '2>&1 | tee log_run_dmm_with_lwip.txt &'
114 exec_cmd_no_error(dut1_node, cmd)
117 cmd = 'cd {0}/{1} && ./run_dmm_with_lwip.sh {2} {3} {4} {5} ' \
118 .format(con.REMOTE_FW_DIR, con.DMM_SCRIPTS, 1, dut2_if_name,
119 dut1_if_ip, dut2_if_ip)
121 cmd += '2>&1 | tee log_run_dmm_with_lwip.txt'
122 exec_cmd_no_error(dut2_node, cmd)
125 def get_lwip_test_result(dut_node):
127 After executing exec_the_base_lwip_test, use this
128 to get the test result.
130 :param dut_node: Node to get the test result on.
132 :returns: Word count of "send 50" in the log.
135 cmd = 'cat {0}/{1}/log_run_dmm_with_lwip.txt | grep "send 50" | wc -l' \
136 .format(con.REMOTE_FW_DIR, con.DMM_SCRIPTS)
138 (stdout, _) = exec_cmd_no_error(dut_node, cmd)
142 def echo_running_log(dut1_node, dut2_node):
146 :param dut1_node: Node to get the running log on.
147 :param dut2_node: Node to get the running log on.
148 :type dut1_node: dict
149 :type dut2_node: dict
151 cmd = 'cat /var/log/nStack/running.log'
152 exec_cmd_no_error(dut1_node, cmd)
153 exec_cmd_no_error(dut2_node, cmd)
156 def echo_dpdk_log(dut1_node, dut2_node):
160 :param dut1_node: Node to get the DPDK log on.
161 :param dut2_node: Node to get the DPDK log on.
162 :type dut1_node: dict
163 :type dut2_node: dict
165 cmd = 'cat /var/log/nstack-dpdk/nstack_dpdk.log'
166 exec_cmd_no_error(dut1_node, cmd)
167 exec_cmd_no_error(dut2_node, cmd)
170 def dmm_get_interface_name(dut_node, dut_interface):
172 Get the interface name.
174 :param dut_node: Node to get the interface name on.
175 :param dut_interface: Interface key.
177 :type dut_interface: str
178 :returns: Interface name.
181 mac = Topology.get_interface_mac(dut_node, dut_interface)
182 cmd = 'ifconfig -a | grep {0}'.format(mac)
183 (stdout, _) = exec_cmd_no_error(dut_node, cmd)
184 interface_name = stdout.split(' ', 1)[0]
185 return interface_name
188 def set_dmm_interface_address(dut_node, ifname, ip_addr, ip4_prefix):
190 Flush ip, set ip, set interface up.
192 :param dut_node: Node to set the interface address on.
193 :param ifname: Interface name.
194 :param ip_addr: IP address to configure.
195 :param ip4_prefix: Prefix length.
199 :type ip4_prefix: int
201 cmd = 'sudo ip -4 addr flush dev {}'.format(ifname)
202 exec_cmd_no_error(dut_node, cmd)
203 cmd = 'sudo ip addr add {}/{} dev {}'\
204 .format(ip_addr, ip4_prefix, ifname)
205 exec_cmd_no_error(dut_node, cmd)
206 cmd = 'sudo ip link set {0} up'.format(ifname)
207 exec_cmd_no_error(dut_node, cmd)