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 import yardstick.common.utils as utils
16 from yardstick.benchmark.scenarios import base
19 LOG = logging.getLogger(__name__)
22 class PktgenDPDKLatency(base.Scenario):
23 """Execute pktgen-dpdk on one vm and execute testpmd on the other vm
26 packetsize - packet size in bytes without the CRC
31 __scenario_type__ = "PktgenDPDKLatency"
33 PKTGEN_DPDK_SCRIPT = 'pktgen_dpdk_latency_benchmark.bash'
34 TESTPMD_SCRIPT = 'testpmd_fwd.bash'
36 def __init__(self, scenario_cfg, context_cfg):
37 self.scenario_cfg = scenario_cfg
38 self.context_cfg = context_cfg
39 self.setup_done = False
43 self.pktgen_dpdk_script = pkg_resources.resource_filename(
44 'yardstick.benchmark.scenarios.networking',
45 PktgenDPDKLatency.PKTGEN_DPDK_SCRIPT)
46 self.testpmd_script = pkg_resources.resource_filename(
47 'yardstick.benchmark.scenarios.networking',
48 PktgenDPDKLatency.TESTPMD_SCRIPT)
49 host = self.context_cfg['host']
50 target = self.context_cfg['target']
51 LOG.info("user:%s, target:%s", target['user'], target['ip'])
52 self.server = ssh.SSH.from_node(target, defaults={"user": "ubuntu"})
53 self.server.wait(timeout=600)
56 self.server._put_file_shell(self.testpmd_script, '~/testpmd_fwd.sh')
58 LOG.info("user:%s, host:%s", host['user'], host['ip'])
59 self.client = ssh.SSH.from_node(host, defaults={"user": "ubuntu"})
60 self.client.wait(timeout=600)
63 self.client._put_file_shell(
64 self.pktgen_dpdk_script, '~/pktgen_dpdk.sh')
66 self.setup_done = True
67 self.testpmd_args = ''
70 def run(self, result):
71 """execute the benchmark"""
73 options = self.scenario_cfg['options']
74 eth1 = options.get("eth1", "ens4")
75 eth2 = options.get("eth2", "ens5")
76 if not self.setup_done:
79 if not self.testpmd_args:
80 self.testpmd_args = utils.get_port_mac(self.client, eth2)
82 if not self.pktgen_args:
83 server_rev_mac = utils.get_port_mac(self.server, eth1)
84 server_send_mac = utils.get_port_mac(self.server, eth2)
85 client_src_ip = utils.get_port_ip(self.client, eth1)
86 client_dst_ip = utils.get_port_ip(self.client, eth2)
88 self.pktgen_args = [client_src_ip, client_dst_ip,
89 server_rev_mac, server_send_mac]
91 packetsize = options.get("packetsize", 64)
92 rate = options.get("rate", 100)
94 cmd = "screen sudo -E bash ~/testpmd_fwd.sh %s %s %s" % \
95 (self.testpmd_args, eth1, eth2)
96 LOG.debug("Executing command: %s", cmd)
97 self.server.send_command(cmd)
101 cmd = "screen sudo -E bash ~/pktgen_dpdk.sh %s %s %s %s %s %s %s %s" % \
102 (self.pktgen_args[0], self.pktgen_args[1], self.pktgen_args[2],
103 self.pktgen_args[3], rate, packetsize, eth1, eth2)
104 LOG.debug("Executing command: %s", cmd)
105 self.client.send_command(cmd)
107 # wait for finishing test
111 cat ~/result.log -vT \
112 |awk '{match($0,/\[8;40H +[0-9]+/)} \
113 {print substr($0,RSTART,RLENGTH)}' \
114 |grep -v ^$ |awk '{if ($2 != 0) print $2}'\
116 client_status, client_stdout, client_stderr = self.client.execute(cmd)
119 raise RuntimeError(client_stderr)
123 latency_list = client_stdout.split('\n')[0:-2]
124 LOG.info("10 samples of latency: %s", latency_list)
126 for i in latency_list:
127 latency_sum += int(i)
128 avg_latency = latency_sum / len(latency_list)
130 result.update({"avg_latency": avg_latency})
132 if avg_latency and "sla" in self.scenario_cfg:
133 sla_max_latency = int(self.scenario_cfg["sla"]["max_latency"])
134 LOG.info("avg_latency : %d ", avg_latency)
135 LOG.info("sla_max_latency: %d", sla_max_latency)
136 debug_info = "avg_latency %d > sla_max_latency %d" \
137 % (avg_latency, sla_max_latency)
138 assert avg_latency <= sla_max_latency, debug_info