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 ##############################################################################
9 from __future__ import absolute_import
14 import yardstick.ssh as ssh
15 from yardstick.benchmark.scenarios import base
17 LOG = logging.getLogger(__name__)
20 class PktgenDPDKLatency(base.Scenario):
21 """Execute pktgen-dpdk on one vm and execute testpmd on the other vm
24 packetsize - packet size in bytes without the CRC
29 __scenario_type__ = "PktgenDPDKLatency"
31 PKTGEN_DPDK_SCRIPT = 'pktgen_dpdk_latency_benchmark.bash'
32 TESTPMD_SCRIPT = 'testpmd_fwd.bash'
34 def __init__(self, scenario_cfg, context_cfg):
35 self.scenario_cfg = scenario_cfg
36 self.context_cfg = context_cfg
37 self.setup_done = False
41 self.pktgen_dpdk_script = pkg_resources.resource_filename(
42 'yardstick.benchmark.scenarios.networking',
43 PktgenDPDKLatency.PKTGEN_DPDK_SCRIPT)
44 self.testpmd_script = pkg_resources.resource_filename(
45 'yardstick.benchmark.scenarios.networking',
46 PktgenDPDKLatency.TESTPMD_SCRIPT)
47 host = self.context_cfg['host']
48 host_user = host.get('user', 'ubuntu')
49 host_ssh_port = host.get('ssh_port', ssh.DEFAULT_PORT)
50 host_ip = host.get('ip', None)
51 host_key_filename = host.get('key_filename', '~/.ssh/id_rsa')
52 target = self.context_cfg['target']
53 target_user = target.get('user', 'ubuntu')
54 target_ssh_port = target.get('ssh_port', ssh.DEFAULT_PORT)
55 target_ip = target.get('ip', None)
56 target_key_filename = target.get('key_filename', '~/.ssh/id_rsa')
57 LOG.info("user:%s, target:%s", target_user, target_ip)
58 self.server = ssh.SSH(target_user, target_ip,
59 key_filename=target_key_filename,
61 self.server.wait(timeout=600)
64 self.server._put_file_shell(self.testpmd_script, '~/testpmd_fwd.sh')
66 LOG.info("user:%s, host:%s", host_user, host_ip)
67 self.client = ssh.SSH(host_user, host_ip,
68 key_filename=host_key_filename,
70 self.client.wait(timeout=600)
73 self.client._put_file_shell(
74 self.pktgen_dpdk_script, '~/pktgen_dpdk.sh')
76 self.setup_done = True
77 self.testpmd_args = ''
81 def get_port_mac(sshclient, port):
82 cmd = "ifconfig |grep HWaddr |grep %s |awk '{print $5}' " % port
83 LOG.debug("Executing command: %s", cmd)
84 status, stdout, stderr = sshclient.execute(cmd)
87 raise RuntimeError(stderr)
89 return stdout.rstrip()
92 def get_port_ip(sshclient, port):
93 cmd = "ifconfig %s |grep 'inet addr' |awk '{print $2}' \
94 |cut -d ':' -f2 " % port
95 LOG.debug("Executing command: %s", cmd)
96 status, stdout, stderr = sshclient.execute(cmd)
99 raise RuntimeError(stderr)
101 return stdout.rstrip()
103 def run(self, result):
104 """execute the benchmark"""
106 if not self.setup_done:
109 if not self.testpmd_args:
110 self.testpmd_args = self.get_port_mac(self.client, 'eth2')
112 if not self.pktgen_args:
113 server_rev_mac = self.get_port_mac(self.server, 'eth1')
114 server_send_mac = self.get_port_mac(self.server, 'eth2')
115 client_src_ip = self.get_port_ip(self.client, 'eth1')
116 client_dst_ip = self.get_port_ip(self.client, 'eth2')
118 self.pktgen_args = [client_src_ip, client_dst_ip,
119 server_rev_mac, server_send_mac]
121 options = self.scenario_cfg['options']
122 packetsize = options.get("packetsize", 64)
123 rate = options.get("rate", 100)
125 cmd = "screen sudo -E bash ~/testpmd_fwd.sh %s " % (self.testpmd_args)
126 LOG.debug("Executing command: %s", cmd)
127 self.server.send_command(cmd)
131 cmd = "screen sudo -E bash ~/pktgen_dpdk.sh %s %s %s %s %s %s" % \
132 (self.pktgen_args[0], self.pktgen_args[1], self.pktgen_args[2],
133 self.pktgen_args[3], rate, packetsize)
134 LOG.debug("Executing command: %s", cmd)
135 self.client.send_command(cmd)
137 # wait for finishing test
141 cat ~/result.log -vT \
142 |awk '{match($0,/\[8;40H +[0-9]+/)} \
143 {print substr($0,RSTART,RLENGTH)}' \
144 |grep -v ^$ |awk '{if ($2 != 0) print $2}'\
146 client_status, client_stdout, client_stderr = self.client.execute(cmd)
149 raise RuntimeError(client_stderr)
153 latency_list = client_stdout.split('\n')[0:-2]
154 LOG.info("10 samples of latency: %s", latency_list)
156 for i in latency_list:
157 latency_sum += int(i)
158 avg_latency = latency_sum / len(latency_list)
160 result.update({"avg_latency": avg_latency})
162 if avg_latency and "sla" in self.scenario_cfg:
163 sla_max_latency = int(self.scenario_cfg["sla"]["max_latency"])
164 LOG.info("avg_latency : %d ", avg_latency)
165 LOG.info("sla_max_latency: %d", sla_max_latency)
166 debug_info = "avg_latency %d > sla_max_latency %d" \
167 % (avg_latency, sla_max_latency)
168 assert avg_latency <= sla_max_latency, debug_info