diff options
author | 2017-02-06 09:50:55 +0000 | |
---|---|---|
committer | 2017-02-06 09:50:55 +0000 | |
commit | 5bd185f75c1c9f886c0125e8bc9d2d6f8bced138 (patch) | |
tree | fcd3f19271fa5cbd2d90efb97b6de15e55172be3 /yardstick | |
parent | 0c99c83ffaa58757dd8d9c0bb3adef783f5cb037 (diff) | |
parent | 8b15550fd60efc464aa19589cc0ea638ded20f3d (diff) |
Merge "Adding ping based sample VNF appliance"
Diffstat (limited to 'yardstick')
-rw-r--r-- | yardstick/network_services/traffic_profile/fixed.py | 60 | ||||
-rw-r--r-- | yardstick/network_services/vnf_generic/vnf/tg_ping.py | 167 |
2 files changed, 227 insertions, 0 deletions
diff --git a/yardstick/network_services/traffic_profile/fixed.py b/yardstick/network_services/traffic_profile/fixed.py new file mode 100644 index 000000000..a456c2bd7 --- /dev/null +++ b/yardstick/network_services/traffic_profile/fixed.py @@ -0,0 +1,60 @@ +# Copyright (c) 2016-2017 Intel Corporation +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +""" Fixed traffic profile definitions """ + +from __future__ import absolute_import + +from yardstick.network_services.traffic_profile.base import TrafficProfile +from stl.trex_stl_lib.trex_stl_streams import STLTXCont +from stl.trex_stl_lib.trex_stl_client import STLStream +from stl.trex_stl_lib.trex_stl_packet_builder_scapy import STLPktBuilder +from stl.trex_stl_lib import api as Pkt + + +class FixedProfile(TrafficProfile): + """ + This profile adds a single stream at the beginning of the traffic session + """ + def __init__(self, tp_config): + super(FixedProfile, self).__init__(tp_config) + self.first_run = True + + def execute(self, traffic_generator): + if self.first_run: + for index, ports in enumerate(traffic_generator.my_ports): + ext_intf = \ + traffic_generator.vnfd["vdu"][0]["external-interface"] + virtual_interface = ext_intf[index]["virtual-interface"] + src_ip = virtual_interface["local_ip"] + dst_ip = virtual_interface["dst_ip"] + + traffic_generator.client.add_streams( + self._create_stream(src_ip, dst_ip), + ports=[ports]) + + traffic_generator.client.start(ports=traffic_generator.my_ports) + self.first_run = False + + def _create_stream(self, src_ip, dst_ip): + base_frame = \ + Pkt.Ether() / Pkt.IP(src=src_ip, dst=dst_ip) / Pkt.UDP(dport=12, + sport=1025) + + frame_size = self.params["traffic_profile"]["frame_size"] + pad_size = max(0, frame_size - len(base_frame)) + frame = base_frame / ("x" * max(0, pad_size)) + + frame_rate = self.params["traffic_profile"]["frame_rate"] + return STLStream(packet=STLPktBuilder(pkt=frame), + mode=STLTXCont(pps=frame_rate)) diff --git a/yardstick/network_services/vnf_generic/vnf/tg_ping.py b/yardstick/network_services/vnf_generic/vnf/tg_ping.py new file mode 100644 index 000000000..2844a5c01 --- /dev/null +++ b/yardstick/network_services/vnf_generic/vnf/tg_ping.py @@ -0,0 +1,167 @@ +# Copyright (c) 2016-2017 Intel Corporation +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +""" PING acts as traffic generation and vnf definitions based on IETS Spec """ + +from __future__ import absolute_import +from __future__ import print_function +import logging +import multiprocessing +import re +import time +import os + +from yardstick import ssh +from yardstick.network_services.vnf_generic.vnf.base import GenericTrafficGen +from yardstick.network_services.utils import provision_tool + +LOG = logging.getLogger(__name__) + + +class PingParser(object): + """ Class providing file-like API for talking with SSH connection """ + + def __init__(self, q_out): + self.queue = q_out + self.closed = False + + def write(self, chunk): + """ 64 bytes from 10.102.22.93: icmp_seq=1 ttl=64 time=0.296 ms """ + match = re.search(r"icmp_seq=(\d+).*time=([0-9.]+)", chunk) + LOG.debug("Parser called on %s", chunk) + if match: + # IMPORTANT: in order for the data to be properly taken + # in by InfluxDB, it needs to be converted to numeric types + self.queue.put({"packets_received": float(match.group(1)), + "rtt": float(match.group(2))}) + + def close(self): + ''' close the ssh connection ''' + pass + + def clear(self): + ''' clear queue till Empty ''' + while self.queue.qsize() > 0: + self.queue.get() + + +class PingTrafficGen(GenericTrafficGen): + """ + This traffic generator can ping a single IP with pingsize + and target given in traffic profile + """ + + def __init__(self, vnfd): + super(PingTrafficGen, self).__init__(vnfd) + self._result = {} + self._parser = None + self._queue = None + self._traffic_process = None + + mgmt_interface = vnfd["mgmt-interface"] + ssh_port = mgmt_interface.get("ssh_port", ssh.DEFAULT_PORT) + LOG.debug("Connecting to %s", mgmt_interface["ip"]) + + self.connection = ssh.SSH(mgmt_interface["user"], mgmt_interface["ip"], + password=mgmt_interface["password"], + port=ssh_port) + self.connection.wait() + + def _bind_device_kernel(self, connection): + dpdk_nic_bind = \ + provision_tool(self.connection, + os.path.join(self.bin_path, "dpdk_nic_bind.py")) + + drivers = {intf["virtual-interface"]["vpci"]: + intf["virtual-interface"]["driver"] + for intf in self.vnfd["vdu"][0]["external-interface"]} + + commands = \ + ['"{0}" --force -b "{1}" "{2}"'.format(dpdk_nic_bind, value, key) + for key, value in drivers.items()] + for command in commands: + connection.execute(command) + + for index, out in enumerate(self.vnfd["vdu"][0]["external-interface"]): + vpci = out["virtual-interface"]["vpci"] + net = "find /sys/class/net -lname '*{}*' -printf '%f'".format(vpci) + out = connection.execute(net)[1] + ifname = out.split('/')[-1].strip('\n') + self.vnfd["vdu"][0]["external-interface"][index][ + "virtual-interface"]["local_iface_name"] = ifname + + def scale(self, flavor=""): + ''' scale vnfbased on flavor input ''' + super(PingTrafficGen, self).scale(flavor) + + def instantiate(self, scenario_cfg, context_cfg): + self._result = {"packets_received": 0, "rtt": 0} + self._bind_device_kernel(self.connection) + + def run_traffic(self, traffic_profile): + self._queue = multiprocessing.Queue() + self._parser = PingParser(self._queue) + self._traffic_process = \ + multiprocessing.Process(target=self._traffic_runner, + args=(traffic_profile, self._parser)) + self._traffic_process.start() + # Wait for traffic process to start + time.sleep(4) + return self._traffic_process.is_alive() + + def listen_traffic(self, traffic_profile): + """ Not needed for ping + + :param traffic_profile: + :return: + """ + pass + + def _traffic_runner(self, traffic_profile, filewrapper): + + mgmt_interface = self.vnfd["mgmt-interface"] + ssh_port = mgmt_interface.get("ssh_port", ssh.DEFAULT_PORT) + self.connection = ssh.SSH(mgmt_interface["user"], mgmt_interface["ip"], + password=mgmt_interface["password"], + port=ssh_port) + self.connection.wait() + external_interface = self.vnfd["vdu"][0]["external-interface"] + virtual_interface = external_interface[0]["virtual-interface"] + target_ip = virtual_interface["dst_ip"].split('/')[0] + local_ip = virtual_interface["local_ip"].split('/')[0] + local_if_name = \ + virtual_interface["local_iface_name"].split('/')[0] + packet_size = traffic_profile.params["traffic_profile"]["frame_size"] + + run_cmd = [] + + run_cmd.append("ip addr flush %s" % local_if_name) + run_cmd.append("ip addr add %s/24 dev %s" % (local_ip, local_if_name)) + run_cmd.append("ip link set %s up" % local_if_name) + + for cmd in run_cmd: + self.connection.execute(cmd) + + ping_cmd = ("ping -s %s %s" % (packet_size, target_ip)) + self.connection.run(ping_cmd, stdout=filewrapper, + keep_stdin_open=True, pty=True) + + def collect_kpi(self): + if not self._queue.empty(): + kpi = self._queue.get() + self._result.update(kpi) + return self._result + + def terminate(self): + if self._traffic_process is not None: + self._traffic_process.terminate() |