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 if not self.setup_done:
76 if not self.testpmd_args:
77 self.testpmd_args = utils.get_port_mac(self.client, 'eth2')
79 if not self.pktgen_args:
80 server_rev_mac = utils.get_port_mac(self.server, 'eth1')
81 server_send_mac = utils.get_port_mac(self.server, 'eth2')
82 client_src_ip = utils.get_port_ip(self.client, 'eth1')
83 client_dst_ip = utils.get_port_ip(self.client, 'eth2')
85 self.pktgen_args = [client_src_ip, client_dst_ip,
86 server_rev_mac, server_send_mac]
88 options = self.scenario_cfg['options']
89 packetsize = options.get("packetsize", 64)
90 rate = options.get("rate", 100)
92 cmd = "screen sudo -E bash ~/testpmd_fwd.sh %s " % (self.testpmd_args)
93 LOG.debug("Executing command: %s", cmd)
94 self.server.send_command(cmd)
98 cmd = "screen sudo -E bash ~/pktgen_dpdk.sh %s %s %s %s %s %s" % \
99 (self.pktgen_args[0], self.pktgen_args[1], self.pktgen_args[2],
100 self.pktgen_args[3], rate, packetsize)
101 LOG.debug("Executing command: %s", cmd)
102 self.client.send_command(cmd)
104 # wait for finishing test
108 cat ~/result.log -vT \
109 |awk '{match($0,/\[8;40H +[0-9]+/)} \
110 {print substr($0,RSTART,RLENGTH)}' \
111 |grep -v ^$ |awk '{if ($2 != 0) print $2}'\
113 client_status, client_stdout, client_stderr = self.client.execute(cmd)
116 raise RuntimeError(client_stderr)
120 latency_list = client_stdout.split('\n')[0:-2]
121 LOG.info("10 samples of latency: %s", latency_list)
123 for i in latency_list:
124 latency_sum += int(i)
125 avg_latency = latency_sum / len(latency_list)
127 result.update({"avg_latency": avg_latency})
129 if avg_latency and "sla" in self.scenario_cfg:
130 sla_max_latency = int(self.scenario_cfg["sla"]["max_latency"])
131 LOG.info("avg_latency : %d ", avg_latency)
132 LOG.info("sla_max_latency: %d", sla_max_latency)
133 debug_info = "avg_latency %d > sla_max_latency %d" \
134 % (avg_latency, sla_max_latency)
135 assert avg_latency <= sla_max_latency, debug_info