1 ##############################################################################
2 # Copyright (c) 2016 ZTE corporation and others.
4 # All rights reserved. This program and the accompanying materials
5 # are made available under the terms of the Apache License, Version 2.0
6 # which accompanies this distribution, and is available at
7 # http://www.apache.org/licenses/LICENSE-2.0
8 ##############################################################################
13 import yardstick.ssh as ssh
14 from yardstick.benchmark.scenarios import base
16 LOG = logging.getLogger(__name__)
19 class PktgenDPDKLatency(base.Scenario):
20 """Execute pktgen-dpdk on one vm and execute testpmd on the other vm
23 packetsize - packet size in bytes without the CRC
28 __scenario_type__ = "PktgenDPDKLatency"
30 PKTGEN_DPDK_SCRIPT = 'pktgen_dpdk_latency_benchmark.bash'
31 TESTPMD_SCRIPT = 'testpmd_fwd.bash'
33 def __init__(self, scenario_cfg, context_cfg):
34 self.scenario_cfg = scenario_cfg
35 self.context_cfg = context_cfg
36 self.setup_done = False
40 self.pktgen_dpdk_script = pkg_resources.resource_filename(
41 'yardstick.benchmark.scenarios.networking',
42 PktgenDPDKLatency.PKTGEN_DPDK_SCRIPT)
43 self.testpmd_script = pkg_resources.resource_filename(
44 'yardstick.benchmark.scenarios.networking',
45 PktgenDPDKLatency.TESTPMD_SCRIPT)
46 host = self.context_cfg['host']
47 host_user = host.get('user', 'ubuntu')
48 host_ssh_port = host.get('ssh_port', ssh.DEFAULT_PORT)
49 host_ip = host.get('ip', None)
50 host_key_filename = host.get('key_filename', '~/.ssh/id_rsa')
51 target = self.context_cfg['target']
52 target_user = target.get('user', 'ubuntu')
53 target_ssh_port = target.get('ssh_port', ssh.DEFAULT_PORT)
54 target_ip = target.get('ip', None)
55 target_key_filename = target.get('key_filename', '~/.ssh/id_rsa')
56 LOG.info("user:%s, target:%s", target_user, target_ip)
57 self.server = ssh.SSH(target_user, target_ip,
58 key_filename=target_key_filename,
60 self.server.wait(timeout=600)
63 self.server._put_file_shell(self.testpmd_script, '~/testpmd_fwd.sh')
65 LOG.info("user:%s, host:%s", host_user, host_ip)
66 self.client = ssh.SSH(host_user, host_ip,
67 key_filename=host_key_filename,
69 self.client.wait(timeout=600)
72 self.client._put_file_shell(
73 self.pktgen_dpdk_script, '~/pktgen_dpdk.sh')
75 self.setup_done = True
76 self.testpmd_args = ''
80 def get_port_mac(sshclient, port):
81 cmd = "ifconfig |grep HWaddr |grep %s |awk '{print $5}' " % port
82 LOG.debug("Executing command: %s", cmd)
83 status, stdout, stderr = sshclient.execute(cmd)
86 raise RuntimeError(stderr)
88 return stdout.rstrip()
91 def get_port_ip(sshclient, port):
92 cmd = "ifconfig %s |grep 'inet addr' |awk '{print $2}' \
93 |cut -d ':' -f2 " % port
94 LOG.debug("Executing command: %s", cmd)
95 status, stdout, stderr = sshclient.execute(cmd)
98 raise RuntimeError(stderr)
100 return stdout.rstrip()
102 def run(self, result):
103 """execute the benchmark"""
105 if not self.setup_done:
108 if not self.testpmd_args:
109 self.testpmd_args = self.get_port_mac(self.client, 'eth2')
111 if not self.pktgen_args:
112 server_rev_mac = self.get_port_mac(self.server, 'eth1')
113 server_send_mac = self.get_port_mac(self.server, 'eth2')
114 client_src_ip = self.get_port_ip(self.client, 'eth1')
115 client_dst_ip = self.get_port_ip(self.client, 'eth2')
117 self.pktgen_args = [client_src_ip, client_dst_ip,
118 server_rev_mac, server_send_mac]
120 options = self.scenario_cfg['options']
121 packetsize = options.get("packetsize", 64)
122 rate = options.get("rate", 100)
124 cmd = "screen sudo -E bash ~/testpmd_fwd.sh %s " % (self.testpmd_args)
125 LOG.debug("Executing command: %s", cmd)
126 self.server.send_command(cmd)
130 cmd = "screen sudo -E bash ~/pktgen_dpdk.sh %s %s %s %s %s %s" % \
131 (self.pktgen_args[0], self.pktgen_args[1], self.pktgen_args[2],
132 self.pktgen_args[3], rate, packetsize)
133 LOG.debug("Executing command: %s", cmd)
134 self.client.send_command(cmd)
136 # wait for finishing test
139 cmd = "cat ~/result.log -vT \
140 |awk '{match($0,/\[8;40H +[0-9]+/)} \
141 {print substr($0,RSTART,RLENGTH)}' \
142 |grep -v ^$ |awk '{if ($2 != 0) print $2}'"
143 client_status, client_stdout, client_stderr = self.client.execute(cmd)
146 raise RuntimeError(client_stderr)
150 latency_list = client_stdout.split('\n')[0:-2]
151 LOG.info("10 samples of latency: %s", latency_list)
153 for i in latency_list:
154 latency_sum += int(i)
155 avg_latency = latency_sum / len(latency_list)
157 result.update({"avg_latency": avg_latency})
159 if avg_latency and "sla" in self.scenario_cfg:
160 sla_max_latency = int(self.scenario_cfg["sla"]["max_latency"])
161 LOG.info("avg_latency : %d ", avg_latency)
162 LOG.info("sla_max_latency: %d", sla_max_latency)
163 debug_info = "avg_latency %d > sla_max_latency %d" \
164 % (avg_latency, sla_max_latency)
165 assert avg_latency <= sla_max_latency, debug_info