From a8075ff20b2046f847b91085aa27f2b336823337 Mon Sep 17 00:00:00 2001 From: Deepak S Date: Fri, 30 Dec 2016 09:21:22 -0800 Subject: Introducing Generic framework to do pre-deployment VNF & Network service testing This patch introduces the framework which is aligned with ETSI-TST001 This patch adds: 1. NetworkServiceTestCase introduces following functions --> setup --> Verify if infrastructure mapping can meet topology --> Load VNF models --> Fill traffic profile with information from topology --> Provision VNFs --> Run experiment (traffic) --> run -> Yardstick calls run() at intervals defined in the yaml and produces timestamped samples --> teardown --> Stop VNFs 2. TrafficProfile is a generic class to get traffic profile for a given testcase and select the traffic generator for testcase. 3. QueueFileWrapper is a class to send/recive cmds to vnf 4. GenericVNF is a generic class to instantiate VNF 5. GenericTrafficGen is a generic class to run/listen/verify traffic. JIRA: YARDSTICK-483 Change-Id: Ic453c917d34dcb508a7f3afb459011da85f6402e Signed-off-by: Deepak S --- .../benchmark/scenarios/networking/imix_voice.yaml | 41 +++ .../networking/ipv4_1flow_Packets_vpe.yaml | 18 + .../scenarios/networking/ipv4_throughput_vpe.yaml | 101 +++++ .../scenarios/networking/test_vnf_generic.py | 410 +++++++++++++++++++++ .../scenarios/networking/tg_trex_tpl.yaml | 75 ++++ .../scenarios/networking/vpe_vnf_topology.yaml | 50 +++ .../network_services/traffic_profile/__init__.py | 0 .../network_services/traffic_profile/test_base.py | 62 ++++ .../unit/network_services/vnf_generic/__init__.py | 0 .../network_services/vnf_generic/test_vnfdgen.py | 218 +++++++++++ .../network_services/vnf_generic/vnf/__init__.py | 0 .../network_services/vnf_generic/vnf/test_base.py | 270 ++++++++++++++ .../benchmark/scenarios/networking/vnf_generic.py | 328 +++++++++++++++++ .../network_services/traffic_profile/__init__.py | 0 yardstick/network_services/traffic_profile/base.py | 64 ++++ yardstick/network_services/vnf_generic/__init__.py | 0 .../network_services/vnf_generic/vnf/__init__.py | 0 yardstick/network_services/vnf_generic/vnf/base.py | 327 ++++++++++++++++ yardstick/network_services/vnf_generic/vnfdgen.py | 71 ++++ 19 files changed, 2035 insertions(+) create mode 100644 tests/unit/benchmark/scenarios/networking/imix_voice.yaml create mode 100644 tests/unit/benchmark/scenarios/networking/ipv4_1flow_Packets_vpe.yaml create mode 100644 tests/unit/benchmark/scenarios/networking/ipv4_throughput_vpe.yaml create mode 100644 tests/unit/benchmark/scenarios/networking/test_vnf_generic.py create mode 100644 tests/unit/benchmark/scenarios/networking/tg_trex_tpl.yaml create mode 100644 tests/unit/benchmark/scenarios/networking/vpe_vnf_topology.yaml create mode 100644 tests/unit/network_services/traffic_profile/__init__.py create mode 100644 tests/unit/network_services/traffic_profile/test_base.py create mode 100644 tests/unit/network_services/vnf_generic/__init__.py create mode 100644 tests/unit/network_services/vnf_generic/test_vnfdgen.py create mode 100644 tests/unit/network_services/vnf_generic/vnf/__init__.py create mode 100644 tests/unit/network_services/vnf_generic/vnf/test_base.py create mode 100644 yardstick/benchmark/scenarios/networking/vnf_generic.py create mode 100644 yardstick/network_services/traffic_profile/__init__.py create mode 100644 yardstick/network_services/traffic_profile/base.py create mode 100644 yardstick/network_services/vnf_generic/__init__.py create mode 100644 yardstick/network_services/vnf_generic/vnf/__init__.py create mode 100644 yardstick/network_services/vnf_generic/vnf/base.py create mode 100644 yardstick/network_services/vnf_generic/vnfdgen.py diff --git a/tests/unit/benchmark/scenarios/networking/imix_voice.yaml b/tests/unit/benchmark/scenarios/networking/imix_voice.yaml new file mode 100644 index 000000000..b8f8e5358 --- /dev/null +++ b/tests/unit/benchmark/scenarios/networking/imix_voice.yaml @@ -0,0 +1,41 @@ +# 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. + +#imix definition for voice traffic +# +# it is a typical case for testing the synthetic VNF performance. +# +#percentage of the packets can be less than 100% +#the traffic in downstream and upstream direction could be different + +schema: "nsb:imix:0.1" + +imix: + private: + imix_small: 100 #ipv4 case - 72B should be 0 ipv6 case - 84B + imix_128B: 0 + imix_256B: 0 + imix_373B: 0 + imix_570B: 0 + imix_1400B: 0 + imix_1500B: 0 + + public: + imix_small: 100 #ipv4 case - 72B ipv6 - 84B + imix_128B: 0 + imix_256B: 0 + imix_373B: 0 + imix_570B: 0 + imix_1400B: 0 + imix_1500B: 0 diff --git a/tests/unit/benchmark/scenarios/networking/ipv4_1flow_Packets_vpe.yaml b/tests/unit/benchmark/scenarios/networking/ipv4_1flow_Packets_vpe.yaml new file mode 100644 index 000000000..f3046f463 --- /dev/null +++ b/tests/unit/benchmark/scenarios/networking/ipv4_1flow_Packets_vpe.yaml @@ -0,0 +1,18 @@ +# 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. + +flow: + srcip4_range: '152.16.0.20' + dstip4_range: '152.40.0.20' + count: 1 diff --git a/tests/unit/benchmark/scenarios/networking/ipv4_throughput_vpe.yaml b/tests/unit/benchmark/scenarios/networking/ipv4_throughput_vpe.yaml new file mode 100644 index 000000000..cfa166a74 --- /dev/null +++ b/tests/unit/benchmark/scenarios/networking/ipv4_throughput_vpe.yaml @@ -0,0 +1,101 @@ +# 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. + +# flow definition for ACL tests - 1K flows - ipv4 only +# +# the number of flows defines the widest range of parameters +# for example if srcip_range=1.0.0.1-1.0.0.255 and dst_ip_range=10.0.0.1-10.0.1.255 +# and it should define only 16 flows +# +#there is assumption that packets generated will have a random sequences of following addresses pairs +# in the packets +# 1. src=1.x.x.x(x.x.x =random from 1..255) dst=10.x.x.x (random from 1..512) +# 2. src=1.x.x.x(x.x.x =random from 1..255) dst=10.x.x.x (random from 1..512) +# ... +# 512. src=1.x.x.x(x.x.x =random from 1..255) dst=10.x.x.x (random from 1..512) +# +# not all combination should be filled +# Any other field with random range will be added to flow definition +# +# the example.yaml provides all possibilities for traffic generation +# +# the profile defines a public and private side to make limited traffic correlation +# between private and public side same way as it is made by IXIA solution. +# +schema: "isb:traffic_profile:0.1" + +# This file is a template, it will be filled with values from tc.yaml before passing to the traffic generator + +name: rfc2544 +description: Traffic profile to run RFC2544 latency +traffic_profile: + traffic_type : RFC2544Profile # defines traffic behavior - constant or look for highest possible throughput + frame_rate : 100 # pc of linerate + # that specifies a range (e.g. ipv4 address, port) + + +private: + ipv4: + outer_l2: + framesize: + 64B: "{{ get(imix, 'imix.private.imix_small', '0') }}" + 128B: "{{ get(imix, 'imix.private.imix_128B', '0') }}" + 256B: "{{ get(imix, 'imix.private.imix_256B', '0') }}" + 373b: "{{ get(imix, 'imix.private.imix_373B', '0') }}" + 570B: "{{get(imix, 'imix.private.imix_570B', '0') }}" + 1400B: "{{get(imix, 'imix.private.imix_1400B', '0') }}" + 1518B: "{{get(imix, 'imix.private.imix_1500B', '0') }}" + + QinQ: + S-VLAN: + id: 128 + priority: 0 + cfi: 0 + C-VLAN: + id: 512 + priority: 0 + cfi: 0 + + outer_l3v4: + proto: "tcp" + srcip4: "{{get(flow, 'flow.srcip4_range', '192.168.0.0-192.168.255.255') }}" + dstip4: "{{get(flow, 'flow.dstip4_range', '192.16.0.0-192.16.0.31') }}" + ttl: 32 + dscp: 32 + + outer_l4: + srcport: "{{get(flow, 'flow.srcport_range', '0') }}" + dstport: "{{get(flow, 'flow.dstport_range', '0') }}" +public: + ipv4: + outer_l2: + framesize: + 64B: "{{ get(imix, 'imix.private.imix_small', '0') }}" + 128B: "{{ get(imix, 'imix.private.imix_128B', '0') }}" + 256B: "{{ get(imix, 'imix.private.imix_256B', '0') }}" + 373b: "{{ get(imix, 'imix.private.imix_373B', '0') }}" + 570B: "{{get(imix, 'imix.private.imix_570B', '0') }}" + 1400B: "{{get(imix, 'imix.private.imix_1400B', '0') }}" + 1518B: "{{get(imix, 'imix.private.imix_1500B', '0') }}" + + outer_l3v4: + proto: "tcp" + srcip4: "{{get(flow, 'flow.dstip4_range', '192.16.0.0-192.16.0.31') }}" + dstip4: "{{get(flow, 'flow.srcip4_range', '192.168.0.0-192.168.255.255') }}" + ttl: 32 + dscp: 32 + + outer_l4: + srcport: "{{get(flow, 'flow.dstport_range', '0') }}" + dstport: "{{get(flow, 'flow.srcport_range', '0') }}" diff --git a/tests/unit/benchmark/scenarios/networking/test_vnf_generic.py b/tests/unit/benchmark/scenarios/networking/test_vnf_generic.py new file mode 100644 index 000000000..7dfd9e3a1 --- /dev/null +++ b/tests/unit/benchmark/scenarios/networking/test_vnf_generic.py @@ -0,0 +1,410 @@ +#!/usr/bin/env python + +# 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. +# + +# Unittest for yardstick.benchmark.scenarios.networking.test_vnf_generic + +from __future__ import absolute_import +import unittest +import mock +import os + +from yardstick.benchmark.scenarios.networking.vnf_generic import \ + ssh_manager, NetworkServiceTestCase, IncorrectConfig, IncorrectSetup +from yardstick.network_services.collector.subscriber import Collector +from yardstick.network_services.vnf_generic.vnf.base import \ + GenericTrafficGen, GenericVNF + +COMPLETE_TREX_VNFD = \ + {'vnfd:vnfd-catalog': + {'vnfd': + [{'benchmark': + {'kpi': + ['rx_throughput_fps', + 'tx_throughput_fps', + 'tx_throughput_mbps', + 'rx_throughput_mbps', + 'tx_throughput_pc_linerate', + 'rx_throughput_pc_linerate', + 'min_latency', + 'max_latency', + 'avg_latency']}, + 'connection-point': [{'name': 'xe0', + 'type': 'VPORT'}, + {'name': 'xe1', + 'type': 'VPORT'}], + 'description': 'TRex stateless traffic generator for RFC2544', + 'id': 'TrexTrafficGen', + 'mgmt-interface': {'ip': '1.1.1.1', + 'password': 'berta', + 'user': 'berta', + 'vdu-id': 'trexgen-baremetal'}, + 'name': 'trexgen', + 'short-name': 'trexgen', + 'vdu': [{'description': 'TRex stateless traffic generator for RFC2544', + 'external-interface': + [{'name': 'xe0', + 'virtual-interface': {'bandwidth': '10 Gbps', + 'dst_ip': '1.1.1.1', + 'dst_mac': '00:01:02:03:04:05', + 'local_ip': '1.1.1.2', + 'local_mac': '00:01:02:03:05:05', + 'type': 'PCI-PASSTHROUGH', + 'netmask': "255.255.255.0", + 'driver': 'i40', + 'vpci': '0000:00:10.2'}, + 'vnfd-connection-point-ref': 'xe0'}, + {'name': 'xe1', + 'virtual-interface': {'bandwidth': '10 Gbps', + 'dst_ip': '2.1.1.1', + 'dst_mac': '00:01:02:03:04:06', + 'local_ip': '2.1.1.2', + 'local_mac': '00:01:02:03:05:06', + 'type': 'PCI-PASSTHROUGH', + 'netmask': "255.255.255.0", + 'driver': 'i40', + 'vpci': '0000:00:10.1'}, + 'vnfd-connection-point-ref': 'xe1'}], + 'id': 'trexgen-baremetal', + 'name': 'trexgen-baremetal'}]}]}} + +IP_ADDR_SHOW = """ +28: eth1: mtu 1500 qdisc mq state UP """ +"""group default qlen 1000 + link/ether 90:e2:ba:a7:6a:c8 brd ff:ff:ff:ff:ff:ff + inet 1.1.1.1/8 brd 1.255.255.255 scope global eth1 + inet6 fe80::92e2:baff:fea7:6ac8/64 scope link + valid_lft forever preferred_lft forever +29: eth5: mtu 1500 qdisc mq state UP """ +"""group default qlen 1000 + link/ether 90:e2:ba:a7:6a:c9 brd ff:ff:ff:ff:ff:ff + inet 2.1.1.1/8 brd 2.255.255.255 scope global eth5 + inet6 fe80::92e2:baff:fea7:6ac9/64 scope link tentative + valid_lft forever preferred_lft forever +""" + +SYS_CLASS_NET = """ +lrwxrwxrwx 1 root root 0 sie 10 14:16 eth1 -> """ +"""../../devices/pci0000:80/0000:80:02.2/0000:84:00.1/net/eth1 +lrwxrwxrwx 1 root root 0 sie 3 10:37 eth2 -> """ +"""../../devices/pci0000:00/0000:00:01.1/0000:84:00.2/net/eth5 +""" + +TRAFFIC_PROFILE = { + "schema": "isb:traffic_profile:0.1", + "name": "fixed", + "description": "Fixed traffic profile to run UDP traffic", + "traffic_profile": { + "traffic_type": "FixedTraffic", + "frame_rate": 100, # pps + "flow_number": 10, + "frame_size": 64}} + + +class TestNetworkServiceTestCase(unittest.TestCase): + def setUp(self): + self.context_cfg = \ + {'nodes': + {'trexgen__1': {'role': 'TrafficGen', + 'name': 'trafficgen_1.yardstick', + 'ip': '10.10.10.11', + 'interfaces': + {'xe0': + {'netmask': '255.255.255.0', + 'local_ip': '152.16.100.20', + 'local_mac': '00:00:00:00:00:01', + 'driver': 'i40e', + 'vpci': '0000:07:00.0', + 'dpdk_port_num': 0}, + 'xe1': + {'netmask': '255.255.255.0', + 'local_ip': '152.16.40.20', + 'local_mac': '00:00:00:00:00:02', + 'driver': 'i40e', + 'vpci': '0000:07:00.1', + 'dpdk_port_num': 1}}, + 'password': 'r00t', + 'user': 'root'}, + 'trexvnf__1': {'name': 'vnf.yardstick', + 'ip': '10.10.10.12', + 'interfaces': + {'xe0': + {'netmask': '255.255.255.0', + 'local_ip': '152.16.100.19', + 'local_mac': '00:00:00:00:00:03', + 'driver': 'i40e', + 'vpci': '0000:07:00.0', + 'dpdk_port_num': 0}, + 'xe1': {'netmask': '255.255.255.0', + 'local_ip': '152.16.40.19', + 'local_mac': '00:00:00:00:00:04', + 'driver': 'i40e', + 'vpci': '0000:07:00.1', + 'dpdk_port_num': 1}}, + 'routing_table': [{'netmask': '255.255.255.0', + 'gateway': '152.16.100.20', + 'network': '152.16.100.20', + 'if': 'xe0'}, + {'netmask': '255.255.255.0', + 'gateway': '152.16.40.20', + 'network': '152.16.40.20', + 'if': 'xe1'}], + 'host': '10.223.197.164', + 'role': 'vnf', + 'user': 'root', + 'nd_route_tbl': + [{'netmask': '112', + 'gateway': '0064:ff9b:0:0:0:0:9810:6414', + 'network': '0064:ff9b:0:0:0:0:9810:6414', + 'if': 'xe0'}, + {'netmask': '112', + 'gateway': '0064:ff9b:0:0:0:0:9810:2814', + 'network': '0064:ff9b:0:0:0:0:9810:2814', + 'if': 'xe1'}], + 'password': 'r00t'}}} + + self.topology = \ + {'short-name': 'trex-tg-topology', + 'constituent-vnfd': + [{'member-vnf-index': '1', + 'VNF model': 'tg_trex_tpl.yaml', + 'vnfd-id-ref': 'trexgen__1'}, + {'member-vnf-index': '2', + 'VNF model': 'tg_trex_tpl.yaml', + 'vnfd-id-ref': 'trexvnf__1'}], + 'description': 'trex-tg-topology', + 'name': 'trex-tg-topology', + 'vld': [{'vnfd-connection-point-ref': [ + {'vnfd-connection-point-ref': 'xe0', + 'member-vnf-index-ref': '1', + 'vnfd-id-ref': 'trexgen'}, + {'vnfd-connection-point-ref': 'xe0', + 'member-vnf-index-ref': '2', + 'vnfd-id-ref': 'trexgen'}], + 'type': 'ELAN', + 'id': 'private', + 'name': 'trexgen__1 to trexvnf__1 link 1'}, + {'vnfd-connection-point-ref': [ + {'vnfd-connection-point-ref': 'xe1', + 'member-vnf-index-ref': '1', + 'vnfd-id-ref': 'trexgen'}, + {'vnfd-connection-point-ref': 'xe1', + 'member-vnf-index-ref': '2', + 'vnfd-id-ref': 'trexgen'}], + 'type': 'ELAN', + 'id': 'public', + 'name': 'trexvnf__1 to trexgen__1 link 2'}], + 'id': 'trex-tg-topology'} + + self.scenario_cfg = {'tc_options': + {'rfc2544': {'allowed_drop_rate': '0.8 - 1'}}, + 'task_id': 'a70bdf4a-8e67-47a3-9dc1-273c14506eb7', + 'tc': 'tc_ipv4_1Mflow_64B_packetsize', + 'runner': {'object': 'NetworkServiceTestCase', + 'interval': 35, + 'output_filename': 'yardstick.out', + 'runner_id': 74476, + 'duration': 400, 'type': 'Duration'}, + 'traffic_profile': 'ipv4_throughput_vpe.yaml', + 'traffic_options': + {'flow': 'ipv4_1flow_Packets_vpe.yaml', + 'imix': 'imix_voice.yaml'}, + 'type': 'ISB', + 'nodes': {'tg__2': 'trafficgen_2.yardstick', + 'tg__1': 'trafficgen_1.yardstick', + 'vnf__1': 'vnf.yardstick'}, + 'topology': 'vpe_vnf_topology.yaml'} + + self.scenario_cfg["topology"] = \ + self._get_file_abspath("vpe_vnf_topology.yaml") + self.s = NetworkServiceTestCase(self.scenario_cfg, self.context_cfg) + + def _get_file_abspath(self, filename): + curr_path = os.path.dirname(os.path.abspath(__file__)) + file_path = os.path.join(curr_path, filename) + return file_path + + def test_ssh_manager(self): + with mock.patch("yardstick.ssh.SSH") as ssh: + ssh_mock = mock.Mock(autospec=ssh.SSH) + ssh_mock.execute = \ + mock.Mock(return_value=(0, SYS_CLASS_NET+IP_ADDR_SHOW, "")) + ssh.return_value = ssh_mock + for node, node_dict in self.context_cfg["nodes"].items(): + with ssh_manager(node_dict) as conn: + self.assertIsNotNone(conn) + + def test___init__(self): + assert self.topology + + def test___get_traffic_flow(self): + self.scenario_cfg["traffic_options"]["flow"] = \ + self._get_file_abspath("ipv4_1flow_Packets_vpe.yaml") + result = {'flow': {'dstip4_range': '152.40.0.20', + 'srcip4_range': '152.16.0.20', 'count': 1}} + self.assertEqual(result, self.s._get_traffic_flow(self.scenario_cfg)) + + def test___get_traffic_flow_error(self): + self.scenario_cfg["traffic_options"]["flow"] = \ + "ipv4_1flow_Packets_vpe.yaml1" + self.assertEqual({}, self.s._get_traffic_flow(self.scenario_cfg)) + + def test_get_vnf_impl_invalid(self): + self.assertRaises(IncorrectConfig, self.s.get_vnf_impl, + COMPLETE_TREX_VNFD['vnfd:vnfd-catalog']['vnfd'][0]) + + def test_load_vnf_models_invalid(self): + self.context_cfg["nodes"]['trexgen__1']['VNF model'] = \ + self._get_file_abspath("tg_trex_tpl.yaml") + self.context_cfg["nodes"]['trexvnf__1']['VNF model'] = \ + self._get_file_abspath("tg_trex_tpl.yaml") + + vnf = mock.Mock(autospec=GenericVNF) + self.s.get_vnf_impl = mock.Mock(return_value=vnf) + + self.assertIsNotNone(self.s.load_vnf_models(self.context_cfg)) + + def test_map_topology_to_infrastructure(self): + with mock.patch("yardstick.ssh.SSH") as ssh: + ssh_mock = mock.Mock(autospec=ssh.SSH) + ssh_mock.execute = \ + mock.Mock(return_value=(0, SYS_CLASS_NET+IP_ADDR_SHOW, "")) + ssh.return_value = ssh_mock + self.s.map_topology_to_infrastructure(self.context_cfg, + self.topology) + self.assertEqual("tg_trex_tpl.yaml", + self.context_cfg["nodes"]['trexgen__1']['VNF model']) + self.assertEqual("tg_trex_tpl.yaml", + self.context_cfg["nodes"]['trexvnf__1']['VNF model']) + + def test_map_topology_to_infrastructure_insufficient_nodes(self): + del self.context_cfg['nodes']['trexvnf__1'] + with mock.patch("yardstick.ssh.SSH") as ssh: + ssh_mock = mock.Mock(autospec=ssh.SSH) + ssh_mock.execute = \ + mock.Mock(return_value=(1, SYS_CLASS_NET+IP_ADDR_SHOW, "")) + ssh.return_value = ssh_mock + + self.assertRaises(IncorrectSetup, + self.s.map_topology_to_infrastructure, + self.context_cfg, self.topology) + + def test_map_topology_to_infrastructure_config_invalid(self): + del self.context_cfg\ + ['nodes']['trexvnf__1']['interfaces']['xe0']['local_mac'] + with mock.patch("yardstick.ssh.SSH") as ssh: + ssh_mock = mock.Mock(autospec=ssh.SSH) + ssh_mock.execute = \ + mock.Mock(return_value=(0, SYS_CLASS_NET+IP_ADDR_SHOW, "")) + ssh.return_value = ssh_mock + + self.assertRaises(IncorrectConfig, + self.s.map_topology_to_infrastructure, + self.context_cfg, self.topology) + + def test__resolve_topology_invalid_config(self): + with mock.patch("yardstick.ssh.SSH") as ssh: + ssh_mock = mock.Mock(autospec=ssh.SSH) + ssh_mock.execute = \ + mock.Mock(return_value=(0, SYS_CLASS_NET+IP_ADDR_SHOW, "")) + ssh.return_value = ssh_mock + + del self.context_cfg['nodes'] + self.assertRaises(IncorrectConfig, self.s._resolve_topology, + self.context_cfg, self.topology) + + self.topology['vld'][0]['vnfd-connection-point-ref'].append( + self.topology['vld'][0]['vnfd-connection-point-ref']) + self.assertRaises(IncorrectConfig, self.s._resolve_topology, + self.context_cfg, self.topology) + + def test_run(self): + tgen = mock.Mock(autospec=GenericTrafficGen) + tgen.traffic_finished = True + verified_dict = {"verified": True} + tgen.verify_traffic = lambda x: verified_dict + tgen.name = "tgen__1" + vnf = mock.Mock(autospec=GenericVNF) + vnf.runs_traffic = False + self.s.vnfs = [tgen, vnf] + self.s.traffic_profile = mock.Mock() + self.s.collector = mock.Mock(autospec=Collector) + self.s.collector.get_kpi = \ + mock.Mock(return_value={tgen.name: verified_dict}) + result = {} + self.s.run(result) + self.assertDictEqual(result, {tgen.name: verified_dict}) + + def test_setup(self): + with mock.patch("yardstick.ssh.SSH") as ssh: + ssh_mock = mock.Mock(autospec=ssh.SSH) + ssh_mock.execute = \ + mock.Mock(return_value=(0, SYS_CLASS_NET+IP_ADDR_SHOW, "")) + ssh.return_value = ssh_mock + + tgen = mock.Mock(autospec=GenericTrafficGen) + tgen.traffic_finished = True + verified_dict = {"verified": True} + tgen.verify_traffic = lambda x: verified_dict + tgen.terminate = mock.Mock(return_value=True) + tgen.name = "tgen__1" + vnf = mock.Mock(autospec=GenericVNF) + vnf.runs_traffic = False + vnf.terminate = mock.Mock(return_value=True) + self.s.vnfs = [tgen, vnf] + self.s.traffic_profile = mock.Mock() + self.s.collector = mock.Mock(autospec=Collector) + self.s.collector.get_kpi = \ + mock.Mock(return_value={tgen.name: verified_dict}) + self.s.map_topology_to_infrastructure = mock.Mock(return_value=0) + self.s.load_vnf_models = mock.Mock(return_value=self.s.vnfs) + self.s._fill_traffic_profile = \ + mock.Mock(return_value=TRAFFIC_PROFILE) + self.assertEqual(None, self.s.setup()) + + def test__get_traffic_profile(self): + self.scenario_cfg["traffic_profile"] = \ + self._get_file_abspath("ipv4_throughput_vpe.yaml") + self.assertIsNotNone(self.s._get_traffic_profile(self.scenario_cfg, + self.context_cfg)) + + def test__get_traffic_profile_exception(self): + self.assertRaises(IOError, self.s._get_traffic_profile, + self.scenario_cfg, self.context_cfg) + + def test___get_traffic_imix_exception(self): + self.assertEqual({}, self.s._get_traffic_imix(self.scenario_cfg)) + + def test__fill_traffic_profile(self): + self.scenario_cfg["traffic_profile"] = \ + self._get_file_abspath("ipv4_throughput_vpe.yaml") + self.scenario_cfg["traffic_options"]["flow"] = \ + self._get_file_abspath("ipv4_1flow_Packets_vpe.yaml") + self.scenario_cfg["traffic_options"]["imix"] = \ + self._get_file_abspath("imix_voice.yaml") + self.assertRaises(RuntimeError, self.s._fill_traffic_profile, + self.scenario_cfg, self.context_cfg) + + def test_teardown(self): + vnf = mock.Mock(autospec=GenericVNF) + vnf.terminate = \ + mock.Mock(return_value=True) + self.s.vnfs = [vnf] + self.s.traffic_profile = mock.Mock() + self.s.collector = mock.Mock(autospec=Collector) + self.s.collector.stop = \ + mock.Mock(return_value=True) + self.assertIsNone(self.s.teardown()) diff --git a/tests/unit/benchmark/scenarios/networking/tg_trex_tpl.yaml b/tests/unit/benchmark/scenarios/networking/tg_trex_tpl.yaml new file mode 100644 index 000000000..b1641836b --- /dev/null +++ b/tests/unit/benchmark/scenarios/networking/tg_trex_tpl.yaml @@ -0,0 +1,75 @@ +# 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. + +vnfd:vnfd-catalog: + vnfd: + - id: TrexTrafficGen # NSPerf class mapping + name: trexgen + short-name: trexgen + description: TRex stateless traffic generator for tests + vm-flavor: + vcpu-count: '4' + memory-mb: '4096' + mgmt-interface: + vdu-id: trexgen-baremetal + user: '{{user}}' # Value filled by vnfdgen + password: '{{password}}' # Value filled by vnfdgen + ip: '{{ip}}' # Value filled by vnfdgen + connection-point: + - name: xe0 + type: VPORT + - name: xe1 + type: VPORT + vdu: + - id: trexgen-baremetal + name: trexgen-baremetal + description: TRex stateless traffic generator for tests + external-interface: + - name: xe0 + virtual-interface: + type: PCI-PASSTHROUGH + # Substitution variables MUST be quoted. Otherwise Python can misinterpet them. + vpci: '{{ interfaces.xe0.vpci }}' # Value filled by vnfdgen + local_ip: '{{ interfaces.xe0.local_ip }}' # Value filled by vnfdgen + driver: '{{ interfaces.xe0.driver}}' # Value filled by vnfdgen + dst_ip: '{{ interfaces.xe0.dst_ip }}' # Value filled by vnfdgen + local_mac: '{{ interfaces.xe0.local_mac }}' # Value filled by vnfdgen + dst_mac: '{{ interfaces.xe0.dst_mac }}' # Value filled by vnfdgen + vld_id: '{{ interfaces.xe0.vld_id }}' # Value filled by vnfdgen + bandwidth: 10 Gbps + vnfd-connection-point-ref: xe0 + - name: xe1 + virtual-interface: + type: PCI-PASSTHROUGH + vpci: '{{ interfaces.xe1.vpci }}' # Value filled by vnfdgen + local_ip: '{{ interfaces.xe1.local_ip }}' # Value filled by vnfdgen + driver: '{{ interfaces.xe1.driver}}' # Value filled by vnfdgen + dst_ip: '{{ interfaces.xe1.dst_ip }}' # Value filled by vnfdgen + local_mac: '{{ interfaces.xe1.local_mac }}' # Value filled by vnfdgen + dst_mac: '{{ interfaces.xe1.dst_mac }}' # Value filled by vnfdgen + vld_id: '{{ interfaces.xe1.vld_id }}' # Value filled by vnfdgen + bandwidth: 10 Gbps + vnfd-connection-point-ref: xe1 + + benchmark: + kpi: + - rx_throughput_fps + - tx_throughput_fps + - tx_throughput_mbps + - rx_throughput_mbps + - tx_throughput_pc_linerate + - rx_throughput_pc_linerate + - min_latency + - max_latency + - avg_latency diff --git a/tests/unit/benchmark/scenarios/networking/vpe_vnf_topology.yaml b/tests/unit/benchmark/scenarios/networking/vpe_vnf_topology.yaml new file mode 100644 index 000000000..0de4b6e79 --- /dev/null +++ b/tests/unit/benchmark/scenarios/networking/vpe_vnf_topology.yaml @@ -0,0 +1,50 @@ +# 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. + +nsd:nsd-catalog: + nsd: + - id: VPE + name: VPE + short-name: VPE + description: scenario with VPE,L3fwd and VNF + constituent-vnfd: + - member-vnf-index: '1' + vnfd-id-ref: tg__1 + VNF model: ../../vnf_descriptors/tg_rfc2544_tpl.yaml #tg_vpe_upstream.yaml #VPE VNF + - member-vnf-index: '2' + vnfd-id-ref: vnf__1 + VNF model: ../../vnf_descriptors/vpe_vnf.yaml #tg_l3fwd.yaml #tg_trex_tpl.yaml #TREX + + vld: + - id: private + name: tg__1 to vnf__1 link 1 + type: ELAN + vnfd-connection-point-ref: + - member-vnf-index-ref: '1' + vnfd-connection-point-ref: xe0 + vnfd-id-ref: tg__1 #TREX + - member-vnf-index-ref: '2' + vnfd-connection-point-ref: xe0 + vnfd-id-ref: vnf__1 #VNF + + - id: public + name: vnf__1 to tg__1 link 2 + type: ELAN + vnfd-connection-point-ref: + - member-vnf-index-ref: '2' + vnfd-connection-point-ref: xe1 + vnfd-id-ref: vnf__1 #L3fwd + - member-vnf-index-ref: '1' + vnfd-connection-point-ref: xe1 + vnfd-id-ref: tg__1 #VPE VNF diff --git a/tests/unit/network_services/traffic_profile/__init__.py b/tests/unit/network_services/traffic_profile/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/tests/unit/network_services/traffic_profile/test_base.py b/tests/unit/network_services/traffic_profile/test_base.py new file mode 100644 index 000000000..72b097b52 --- /dev/null +++ b/tests/unit/network_services/traffic_profile/test_base.py @@ -0,0 +1,62 @@ +#!/usr/bin/env python + +# 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. +# + +# Unittest for yardstick.network_services.traffic_profile.test_base + +from __future__ import absolute_import +import unittest +import mock + +from yardstick.network_services.traffic_profile.base import \ + TrafficProfile, DummyProfile + + +class TestTrafficProfile(unittest.TestCase): + TRAFFIC_PROFILE = { + "schema": "isb:traffic_profile:0.1", + "name": "fixed", + "description": "Fixed traffic profile to run UDP traffic", + "traffic_profile": { + "traffic_type": "FixedTraffic", + "frame_rate": 100, # pps + "flow_number": 10, + "frame_size": 64}} + + def _get_res_mock(self, **kw): + _mock = mock.MagicMock() + for k, v in kw.items(): + setattr(_mock, k, v) + return _mock + + def test___init__(self): + traffic_profile = TrafficProfile(self.TRAFFIC_PROFILE) + self.assertEqual(self.TRAFFIC_PROFILE, traffic_profile.params) + + def test_execute(self): + traffic_profile = TrafficProfile(self.TRAFFIC_PROFILE) + self.assertRaises(NotImplementedError, traffic_profile.execute, {}) + + def test_get(self): + traffic_profile = TrafficProfile(self.TRAFFIC_PROFILE) + self.assertRaises(RuntimeError, traffic_profile.get, + self.TRAFFIC_PROFILE) + + +class TestDummyProfile(unittest.TestCase): + def test_execute(self): + dummy_profile = DummyProfile(TrafficProfile) + self.assertIsNone(dummy_profile.execute({})) diff --git a/tests/unit/network_services/vnf_generic/__init__.py b/tests/unit/network_services/vnf_generic/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/tests/unit/network_services/vnf_generic/test_vnfdgen.py b/tests/unit/network_services/vnf_generic/test_vnfdgen.py new file mode 100644 index 000000000..6d5fb0c7a --- /dev/null +++ b/tests/unit/network_services/vnf_generic/test_vnfdgen.py @@ -0,0 +1,218 @@ +#!/usr/bin/env python + +# 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. +# + +# Unittest for yardstick.network_services.vnf_generic.vnfdgen + +from __future__ import absolute_import +import unittest +from six.moves import range + +from yardstick.network_services.vnf_generic import vnfdgen + +TREX_VNFD_TEMPLATE = """ +vnfd:vnfd-catalog: + vnfd: + - id: TrexTrafficGen # ISB class mapping + name: trexgen + short-name: trexgen + description: TRex stateless traffic generator for RFC2544 + mgmt-interface: + vdu-id: trexgen-baremetal + user: {{user}} # Value filled by vnfdgen + password: {{password}} # Value filled by vnfdgen + ip: {{ip}} # Value filled by vnfdgen + connection-point: + - name: xe0 + type: VPORT + - name: xe1 + type: VPORT + vdu: + - id: trexgen-baremetal + name: trexgen-baremetal + description: TRex stateless traffic generator for RFC2544 + external-interface: + - name: xe0 + virtual-interface: + type: PCI-PASSTHROUGH + vpci: '{{ interfaces.xe0.vpci}}' + local_ip: '{{ interfaces.xe0.local_ip }}' + dst_ip: '{{ interfaces.xe0.dst_ip }}' + local_mac: '{{ interfaces.xe0.local_mac }}' + dst_mac: '{{ interfaces.xe0.dst_mac }}' + bandwidth: 10 Gbps + vnfd-connection-point-ref: xe0 + - name: xe1 + virtual-interface: + type: PCI-PASSTHROUGH + vpci: '{{ interfaces.xe1.vpci }}' + local_ip: '{{ interfaces.xe1.local_ip }}' + dst_ip: '{{ interfaces.xe1.dst_ip }}' + local_mac: '{{ interfaces.xe1.local_mac }}' + dst_mac: '{{ interfaces.xe1.dst_mac }}' + bandwidth: 10 Gbps + vnfd-connection-point-ref: xe1 + + benchmark: + kpi: + - rx_throughput_fps + - tx_throughput_fps + - tx_throughput_mbps + - rx_throughput_mbps + - tx_throughput_pc_linerate + - rx_throughput_pc_linerate + - min_latency + - max_latency + - avg_latency +""" + +COMPLETE_TREX_VNFD = \ + {'vnfd:vnfd-catalog': + {'vnfd': + [{'benchmark': + {'kpi': + ['rx_throughput_fps', + 'tx_throughput_fps', + 'tx_throughput_mbps', + 'rx_throughput_mbps', + 'tx_throughput_pc_linerate', + 'rx_throughput_pc_linerate', + 'min_latency', + 'max_latency', + 'avg_latency']}, + 'connection-point': [{'name': 'xe0', + 'type': 'VPORT'}, + {'name': 'xe1', + 'type': 'VPORT'}], + 'description': 'TRex stateless traffic generator for RFC2544', + 'id': 'TrexTrafficGen', + 'mgmt-interface': {'ip': '1.1.1.1', + 'password': 'berta', + 'user': 'berta', + 'vdu-id': 'trexgen-baremetal'}, + 'name': 'trexgen', + 'short-name': 'trexgen', + 'vdu': [{'description': 'TRex stateless traffic generator for RFC2544', + 'external-interface': + [{'name': 'xe0', + 'virtual-interface': {'bandwidth': '10 Gbps', + 'dst_ip': '1.1.1.1', + 'dst_mac': '00:01:02:03:04:05', + 'local_ip': '1.1.1.2', + 'local_mac': '00:01:02:03:05:05', + 'type': 'PCI-PASSTHROUGH', + 'vpci': '0000:00:10.2'}, + 'vnfd-connection-point-ref': 'xe0'}, + {'name': 'xe1', + 'virtual-interface': {'bandwidth': '10 Gbps', + 'dst_ip': '2.1.1.1', + 'dst_mac': '00:01:02:03:04:06', + 'local_ip': '2.1.1.2', + 'local_mac': '00:01:02:03:05:06', + 'type': 'PCI-PASSTHROUGH', + 'vpci': '0000:00:10.1'}, + 'vnfd-connection-point-ref': 'xe1'}], + 'id': 'trexgen-baremetal', + 'name': 'trexgen-baremetal'}]}]}} + +NODE_CFG = {'ip': '1.1.1.1', + 'name': 'demeter', + 'password': 'berta', + 'role': 'TrafficGen', + 'user': 'berta', + 'interfaces': {'xe0': {'dpdk_port_num': 1, + 'dst_ip': '1.1.1.1', + 'dst_mac': '00:01:02:03:04:05', + 'local_ip': '1.1.1.2', + 'local_mac': '00:01:02:03:05:05', + 'vpci': '0000:00:10.2'}, + 'xe1': {'dpdk_port_num': 0, + 'dst_ip': '2.1.1.1', + 'dst_mac': '00:01:02:03:04:06', + 'local_ip': '2.1.1.2', + 'local_mac': '00:01:02:03:05:06', + 'vpci': '0000:00:10.1'}}} + + +TRAFFIC_PROFILE_TPL = """ +private: + - ipv4: + outer_l2: + framesize: + 64B: "{{ get(imix, 'private.imix_small', 10) }}" + 128B: "{{ get(imix, 'private.imix_128B', 10) }}" + 256B: "{{ get(imix, 'private.imix_256B', 10) }}" + 373B: "{{ get(imix, 'private.imix_373B', 10) }}" + 570B: "{{get(imix, 'private.imix_570B', 10) }}" + 1400B: "{{get(imix, 'private.imix_1400B', 10) }}" + 1518B: "{{get(imix, 'private.imix_1500B', 40) }}" +""" + +TRAFFIC_PROFILE = { + "private": [{"ipv4": {"outer_l2": + {"framesize": {"64B": '10', "128B": '10', + "256B": '10', "373B": '10', + "570B": '10', "1400B": '10', + "1518B": '40'}}}}]} + + +class TestVnfdGen(unittest.TestCase): + """ Class to verify VNFS testcases """ + + def test_generate_vnfd(self): + """ Function to verify vnfd generation based on template """ + self.maxDiff = None + generated_vnfd = vnfdgen.generate_vnfd(TREX_VNFD_TEMPLATE, NODE_CFG) + self.assertDictEqual(COMPLETE_TREX_VNFD, generated_vnfd) + + def test_generate_tp_no_vars(self): + """ Function to verify traffic profile generation without imix """ + + self.maxDiff = None + generated_tp = vnfdgen.generate_vnfd(TRAFFIC_PROFILE_TPL, {"imix": {}}) + self.assertDictEqual(TRAFFIC_PROFILE, generated_tp) + + def test_dict_flatten_empty_dict(self): + self.assertEqual(vnfdgen.dict_key_flatten({}), {}) + + def test_dict_flatten_int(self): + d = {'a': 1, 'b': 2} + self.assertEqual(vnfdgen.dict_key_flatten(d), d) + + def test_dict_flatten_str(self): + d = {'a': "1", 'b': '2'} + self.assertEqual(vnfdgen.dict_key_flatten(d), d) + + def test_dict_flatten_list(self): + d = {'a': 1, 'b': list(range(2))} + self.assertEqual(vnfdgen.dict_key_flatten(d), + {'a': 1, 'b0': 0, 'b1': 1}) + + def test_dict_flatten_dict(self): + d = {'a': 1, 'b': {x: x for x in list(range(2))}} + self.assertEqual(vnfdgen.dict_key_flatten(d), + {'a': 1, 'b.0': 0, 'b.1': 1}) + + def test_generate_tp_single_var(self): + """ Function to verify traffic profile generation with imix """ + + generated_tp = \ + vnfdgen.generate_vnfd(TRAFFIC_PROFILE_TPL, + {"imix": {"private": {"imix_small": '20'}}}) + self.maxDiff = None + tp2 = dict(TRAFFIC_PROFILE) + tp2["private"][0]["ipv4"]["outer_l2"]["framesize"]["64B"] = '20' + self.assertDictEqual(tp2, generated_tp) diff --git a/tests/unit/network_services/vnf_generic/vnf/__init__.py b/tests/unit/network_services/vnf_generic/vnf/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/tests/unit/network_services/vnf_generic/vnf/test_base.py b/tests/unit/network_services/vnf_generic/vnf/test_base.py new file mode 100644 index 000000000..b1203f8e8 --- /dev/null +++ b/tests/unit/network_services/vnf_generic/vnf/test_base.py @@ -0,0 +1,270 @@ +#!/usr/bin/env python + +# 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. +# + +# Unittest for yardstick.network_services.vnf_generic.vnf.test_base + +from __future__ import absolute_import +import unittest +import mock +from multiprocessing import Queue + +from yardstick.network_services.vnf_generic.vnf.base import \ + QueueFileWrapper, GenericVNF, GenericTrafficGen + +IP_PIPELINE_CFG_FILE_TPL = """ +arp_route_tbl = ({port0_local_ip_hex},{port0_netmask_hex},1,""" +"""{port1_local_ip_hex}) ({port1_local_ip_hex},{port1_netmask_hex},0,""" +"""{port0_local_ip_hex})""" + +IP_PIPELINE_ND_CFG_FILE_TPL = """ +nd_route_tbl = ({port1_dst_ip_hex6},""" +"""{port1_dst_netmask_hex6},1,{port1_dst_ip_hex6})""" + + +class TestQueueFileWrapper(unittest.TestCase): + def setUp(self): + self.prompt = "pipeline>" + self.q_in = Queue() + self.q_out = Queue() + + def test___init__(self): + queue_file_wrapper = \ + QueueFileWrapper(self.q_in, self.q_out, self.prompt) + self.assertEqual(queue_file_wrapper.prompt, self.prompt) + + def test_clear(self): + queue_file_wrapper = \ + QueueFileWrapper(self.q_in, self.q_out, self.prompt) + queue_file_wrapper.bufsize = 5 + queue_file_wrapper.write("pipeline>") + queue_file_wrapper.close() + self.assertEqual(queue_file_wrapper.q_out.empty(), True) + + def test_close(self): + queue_file_wrapper = \ + QueueFileWrapper(self.q_in, self.q_out, self.prompt) + self.assertEqual(None, queue_file_wrapper.close()) + + def test_read(self): + queue_file_wrapper = \ + QueueFileWrapper(self.q_in, self.q_out, self.prompt) + queue_file_wrapper.q_in.put("pipeline>") + self.assertEqual("pipeline>", queue_file_wrapper.read(20)) + + def test_write(self): + queue_file_wrapper = \ + QueueFileWrapper(self.q_in, self.q_out, self.prompt) + queue_file_wrapper.write("pipeline>") + self.assertIsNotNone(queue_file_wrapper.q_out.empty()) + + +class TestGenericVNF(unittest.TestCase): + VNFD = {'vnfd:vnfd-catalog': + {'vnfd': + [{'short-name': 'VpeVnf', + 'vdu': + [{'routing_table': + [{'network': '152.16.100.20', + 'netmask': '255.255.255.0', + 'gateway': '152.16.100.20', + 'if': 'xe0'}, + {'network': '152.16.40.20', + 'netmask': '255.255.255.0', + 'gateway': '152.16.40.20', + 'if': 'xe1'}], + 'description': 'VPE approximation using DPDK', + 'name': 'vpevnf-baremetal', + 'nd_route_tbl': + [{'network': '0064:ff9b:0:0:0:0:9810:6414', + 'netmask': '112', + 'gateway': '0064:ff9b:0:0:0:0:9810:6414', + 'if': 'xe0'}, + {'network': '0064:ff9b:0:0:0:0:9810:2814', + 'netmask': '112', + 'gateway': '0064:ff9b:0:0:0:0:9810:2814', + 'if': 'xe1'}], + 'id': 'vpevnf-baremetal', + 'external-interface': + [{'virtual-interface': + {'dst_mac': '00:00:00:00:00:03', + 'vpci': '0000:05:00.0', + 'local_ip': '152.16.100.19', + 'type': 'PCI-PASSTHROUGH', + 'netmask': '255.255.255.0', + 'dpdk_port_num': '0', + 'bandwidth': '10 Gbps', + 'dst_ip': '152.16.100.20', + 'local_mac': '00:00:00:00:00:01'}, + 'vnfd-connection-point-ref': 'xe0', + 'name': 'xe0'}, + {'virtual-interface': + {'dst_mac': '00:00:00:00:00:04', + 'vpci': '0000:05:00.1', + 'local_ip': '152.16.40.19', + 'type': 'PCI-PASSTHROUGH', + 'netmask': '255.255.255.0', + 'dpdk_port_num': '1', + 'bandwidth': '10 Gbps', + 'dst_ip': '152.16.40.20', + 'local_mac': '00:00:00:00:00:02'}, + 'vnfd-connection-point-ref': 'xe1', + 'name': 'xe1'}]}], + 'description': 'Vpe approximation using DPDK', + 'mgmt-interface': + {'vdu-id': 'vpevnf-baremetal', + 'host': '1.1.1.1', + 'password': 'r00t', + 'user': 'root', + 'ip': '1.1.1.1'}, + 'benchmark': + {'kpi': ['packets_in', 'packets_fwd', 'packets_dropped']}, + 'connection-point': [{'type': 'VPORT', 'name': 'xe0'}, + {'type': 'VPORT', 'name': 'xe1'}], + 'id': 'VpeApproxVnf', 'name': 'VPEVnfSsh'}]}} + + def test___init__(self): + generic_vn_f = GenericVNF(self.VNFD['vnfd:vnfd-catalog']['vnfd'][0]) + assert generic_vn_f.kpi + + def test_collect_kpi(self): + generic_vn_f = GenericVNF(self.VNFD['vnfd:vnfd-catalog']['vnfd'][0]) + self.assertRaises(NotImplementedError, generic_vn_f.collect_kpi) + + def test_get_ip_version(self): + ip_addr = "152.16.1.1" + generic_vn_f = GenericVNF(self.VNFD['vnfd:vnfd-catalog']['vnfd'][0]) + self.assertEqual(4, generic_vn_f.get_ip_version(ip_addr)) + + @mock.patch('yardstick.network_services.vnf_generic.vnf.base.LOG') + def test_get_ip_version_error(self, mock_LOG): + ip_addr = "152.16.1.1.1" + generic_vn_f = GenericVNF(self.VNFD['vnfd:vnfd-catalog']['vnfd'][0]) + self.assertRaises(ValueError, generic_vn_f.get_ip_version(ip_addr)) + + def test_ip_to_hex(self): + generic_vn_f = GenericVNF(self.VNFD['vnfd:vnfd-catalog']['vnfd'][0]) + hex_ip = generic_vn_f._ip_to_hex("192.168.10.1") + self.assertEqual("C0A80A01", hex_ip) + + def test_append_routes(self): + generic_vn_f = GenericVNF(self.VNFD['vnfd:vnfd-catalog']['vnfd'][0]) + arp_route = generic_vn_f._append_routes(IP_PIPELINE_CFG_FILE_TPL) + expected = '\narp_route_tbl = (98106414,FFFFFF00,0,98106414)' \ + ' (98102814,FFFFFF00,1,98102814)\n,' + self.assertEqual(expected, arp_route) + + def test_append_nd_routes(self): + generic_vn_f = GenericVNF(self.VNFD['vnfd:vnfd-catalog']['vnfd'][0]) + nd_route = generic_vn_f._append_nd_routes(IP_PIPELINE_ND_CFG_FILE_TPL) + expected = '\nnd_route_tbl = (0064:ff9b:0:0:0:0:9810:6414,112,0,' \ + '0064:ff9b:0:0:0:0:9810:6414) '\ + '(0064:ff9b:0:0:0:0:9810:2814,112,'\ + '1,0064:ff9b:0:0:0:0:9810:2814)\n,' + self.assertEqual(expected, nd_route) + + def test_get_port0localip6(self): + generic_vn_f = GenericVNF(self.VNFD['vnfd:vnfd-catalog']['vnfd'][0]) + port0_v6 = generic_vn_f._get_port0localip6() + expected = '0064:ff9b:0:0:0:0:9810:6414' + self.assertEqual(expected, port0_v6) + + def test_get_port1localip6(self): + generic_vn_f = GenericVNF(self.VNFD['vnfd:vnfd-catalog']['vnfd'][0]) + port1_v6 = generic_vn_f._get_port1localip6() + expected = '0064:ff9b:0:0:0:0:9810:2814' + self.assertEqual(expected, port1_v6) + + def test_get_port0prefixip6(self): + generic_vn_f = GenericVNF(self.VNFD['vnfd:vnfd-catalog']['vnfd'][0]) + port0_v6 = generic_vn_f._get_port0prefixlen6() + self.assertEqual('112', port0_v6) + + def test_get_port1prefixip6(self): + generic_vn_f = GenericVNF(self.VNFD['vnfd:vnfd-catalog']['vnfd'][0]) + port1_v6 = generic_vn_f._get_port1prefixlen6() + self.assertEqual('112', port1_v6) + + def test_get_port0gateway6(self): + generic_vn_f = GenericVNF(self.VNFD['vnfd:vnfd-catalog']['vnfd'][0]) + port0_v6 = generic_vn_f._get_port0gateway6() + self.assertEqual('0064:ff9b:0:0:0:0:9810:6414', port0_v6) + + def test_get_port1gateway6(self): + generic_vn_f = GenericVNF(self.VNFD['vnfd:vnfd-catalog']['vnfd'][0]) + port1_v6 = generic_vn_f._get_port1gateway6() + self.assertEqual('0064:ff9b:0:0:0:0:9810:2814', port1_v6) + + def test_get_dpdk_port_num(self): + generic_vn_f = GenericVNF(self.VNFD['vnfd:vnfd-catalog']['vnfd'][0]) + port_num = generic_vn_f._get_dpdk_port_num('xe0') + self.assertEqual('0', port_num) + + def test__get_kpi_definition(self): + vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0] + generic_vn_f = GenericVNF(vnfd) + kpi = \ + generic_vn_f._get_kpi_definition(vnfd) + self.assertEqual(kpi, ['packets_in', 'packets_fwd', 'packets_dropped']) + + def test_instantiate(self): + generic_vn_f = GenericVNF(self.VNFD['vnfd:vnfd-catalog']['vnfd'][0]) + self.assertRaises(NotImplementedError, + generic_vn_f.instantiate, {}, {}) + + def test_scale(self): + generic_vn_f = GenericVNF(self.VNFD['vnfd:vnfd-catalog']['vnfd'][0]) + self.assertRaises(NotImplementedError, generic_vn_f.scale) + + def test_terminate(self): + generic_vn_f = GenericVNF(self.VNFD['vnfd:vnfd-catalog']['vnfd'][0]) + self.assertRaises(NotImplementedError, generic_vn_f.terminate) + + +class TestGenericTrafficGen(unittest.TestCase): + def test___init__(self): + vnfd = TestGenericVNF.VNFD['vnfd:vnfd-catalog']['vnfd'][0] + generic_traffic_gen = \ + GenericTrafficGen(vnfd) + assert generic_traffic_gen.name == "tgen__1" + + def test_listen_traffic(self): + vnfd = TestGenericVNF.VNFD['vnfd:vnfd-catalog']['vnfd'][0] + generic_traffic_gen = \ + GenericTrafficGen(vnfd) + traffic_profile = {} + self.assertIsNone(generic_traffic_gen.listen_traffic(traffic_profile)) + + def test_run_traffic(self): + vnfd = TestGenericVNF.VNFD['vnfd:vnfd-catalog']['vnfd'][0] + generic_traffic_gen = \ + GenericTrafficGen(vnfd) + traffic_profile = {} + self.assertRaises(NotImplementedError, + generic_traffic_gen.run_traffic, traffic_profile) + + def test_terminate(self): + vnfd = TestGenericVNF.VNFD['vnfd:vnfd-catalog']['vnfd'][0] + generic_traffic_gen = \ + GenericTrafficGen(vnfd) + self.assertRaises(NotImplementedError, generic_traffic_gen.terminate) + + def test_verify_traffic(self): + vnfd = TestGenericVNF.VNFD['vnfd:vnfd-catalog']['vnfd'][0] + generic_traffic_gen = \ + GenericTrafficGen(vnfd) + traffic_profile = {} + self.assertIsNone(generic_traffic_gen.verify_traffic(traffic_profile)) diff --git a/yardstick/benchmark/scenarios/networking/vnf_generic.py b/yardstick/benchmark/scenarios/networking/vnf_generic.py new file mode 100644 index 000000000..d7ba418c3 --- /dev/null +++ b/yardstick/benchmark/scenarios/networking/vnf_generic.py @@ -0,0 +1,328 @@ +# 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. +""" NSPerf specific scenario definition """ + +from __future__ import absolute_import +import logging +from contextlib import contextmanager +import yaml + +from yardstick.benchmark.scenarios import base +from yardstick.common.utils import import_modules_from_package, itersubclasses +from yardstick.network_services.collector.subscriber import Collector +from yardstick.network_services.vnf_generic import vnfdgen +from yardstick.network_services.vnf_generic.vnf.base import GenericVNF +from yardstick.network_services.traffic_profile.base import TrafficProfile +from yardstick import ssh + +LOG = logging.getLogger(__name__) + + +class SSHError(Exception): + """Class handles ssh connection error exception""" + pass + + +class SSHTimeout(SSHError): + """Class handles ssh connection timeout exception""" + pass + + +class IncorrectConfig(Exception): + """Class handles incorrect configuration during setup""" + pass + + +class IncorrectSetup(Exception): + """Class handles incorrect setup during setup""" + pass + + +@contextmanager +def ssh_manager(node): + """ + args -> network device mappings + returns -> ssh connection ready to be used + """ + conn = None + try: + ssh_port = node.get("ssh_port", ssh.DEFAULT_PORT) + conn = ssh.SSH(user=node.get("user", ""), + host=node.get("ip", ""), + password=node.get("password", ""), + port=ssh_port) + conn.wait() + + except (SSHError) as error: + LOG.info("connect failed to %s, due to %s", node.get("ip", ""), error) + try: + if conn: + yield conn + else: + yield False + finally: + if conn: + conn.close() + + +class NetworkServiceTestCase(base.Scenario): + """Class handles Generic framework to do pre-deployment VNF & + Network service testing """ + + __scenario_type__ = "NSPerf" + + def __init__(self, scenario_cfg, context_cfg): # Yardstick API + super(NetworkServiceTestCase, self).__init__() + self.scenario_cfg = scenario_cfg + self.context_cfg = context_cfg + + # fixme: create schema to validate all fields have been provided + with open(scenario_cfg["topology"]) as stream: + self.topology = yaml.load(stream)["nsd:nsd-catalog"]["nsd"][0] + self.vnfs = [] + self.collector = None + self.traffic_profile = None + + @classmethod + def _get_traffic_flow(cls, scenario_cfg): + try: + with open(scenario_cfg["traffic_options"]["flow"]) as fflow: + flow = yaml.load(fflow) + except (KeyError, IOError, OSError): + flow = {} + return flow + + @classmethod + def _get_traffic_imix(cls, scenario_cfg): + try: + with open(scenario_cfg["traffic_options"]["imix"]) as fimix: + imix = yaml.load(fimix) + except (KeyError, IOError, OSError): + imix = {} + return imix + + @classmethod + def _get_traffic_profile(cls, scenario_cfg, context_cfg): + traffic_profile_tpl = "" + private = {} + public = {} + try: + with open(scenario_cfg["traffic_profile"]) as infile: + traffic_profile_tpl = infile.read() + + except (KeyError, IOError, OSError): + raise + + return [traffic_profile_tpl, private, public] + + def _fill_traffic_profile(self, scenario_cfg, context_cfg): + traffic_profile = {} + + flow = self._get_traffic_flow(scenario_cfg) + + imix = self._get_traffic_imix(scenario_cfg) + + traffic_mapping, private, public = \ + self._get_traffic_profile(scenario_cfg, context_cfg) + + traffic_profile = vnfdgen.generate_vnfd(traffic_mapping, + {"imix": imix, "flow": flow, + "private": private, + "public": public}) + + return TrafficProfile.get(traffic_profile) + + @classmethod + def _find_vnf_name_from_id(cls, topology, vnf_id): + return next((vnfd["vnfd-id-ref"] + for vnfd in topology["constituent-vnfd"] + if vnf_id == vnfd["member-vnf-index"]), None) + + def _resolve_topology(self, context_cfg, topology): + for vld in topology["vld"]: + if len(vld["vnfd-connection-point-ref"]) > 2: + raise IncorrectConfig("Topology file corrupted, " + "too many endpoint for connection") + + node_0, node_1 = vld["vnfd-connection-point-ref"] + + node0 = self._find_vnf_name_from_id(topology, + node_0["member-vnf-index-ref"]) + node1 = self._find_vnf_name_from_id(topology, + node_1["member-vnf-index-ref"]) + + if0 = node_0["vnfd-connection-point-ref"] + if1 = node_1["vnfd-connection-point-ref"] + + try: + nodes = context_cfg["nodes"] + nodes[node0]["interfaces"][if0]["vld_id"] = vld["id"] + nodes[node1]["interfaces"][if1]["vld_id"] = vld["id"] + + nodes[node0]["interfaces"][if0]["dst_mac"] = \ + nodes[node1]["interfaces"][if1]["local_mac"] + nodes[node0]["interfaces"][if0]["dst_ip"] = \ + nodes[node1]["interfaces"][if1]["local_ip"] + + nodes[node1]["interfaces"][if1]["dst_mac"] = \ + nodes[node0]["interfaces"][if0]["local_mac"] + nodes[node1]["interfaces"][if1]["dst_ip"] = \ + nodes[node0]["interfaces"][if0]["local_ip"] + except KeyError: + raise IncorrectConfig("Required interface not found," + "topology file corrupted") + + @classmethod + def _find_list_index_from_vnf_idx(cls, topology, vnf_idx): + return next((topology["constituent-vnfd"].index(vnfd) + for vnfd in topology["constituent-vnfd"] + if vnf_idx == vnfd["member-vnf-index"]), None) + + def _update_context_with_topology(self, context_cfg, topology): + for idx in topology["constituent-vnfd"]: + vnf_idx = idx["member-vnf-index"] + nodes = context_cfg["nodes"] + node = self._find_vnf_name_from_id(topology, vnf_idx) + list_idx = self._find_list_index_from_vnf_idx(topology, vnf_idx) + nodes[node].update(topology["constituent-vnfd"][list_idx]) + + def map_topology_to_infrastructure(self, context_cfg, topology): + """ This method should verify if the available resources defined in pod.yaml + match the topology.yaml file. + + :param topology: + :return: None. Side effect: context_cfg is updated + """ + + for node, node_dict in context_cfg["nodes"].items(): + + cmd = "PATH=$PATH:/sbin:/usr/sbin ip addr show" + with ssh_manager(node_dict) as conn: + exit_status = conn.execute(cmd)[0] + if exit_status != 0: + raise IncorrectSetup("Node's %s lacks ip tool." % node) + + for interface in node_dict["interfaces"]: + network = node_dict["interfaces"][interface] + keys = ["vpci", "local_ip", "netmask", + "local_mac", "driver", "dpdk_port_num"] + missing = set(keys).difference(network) + if missing: + raise IncorrectConfig("Require interface fields '%s' " + "not found, topology file " + "corrupted" % ', '.join(missing)) + + # 3. Use topology file to find connections & resolve dest address + self._resolve_topology(context_cfg, topology) + self._update_context_with_topology(context_cfg, topology) + + @classmethod + def get_vnf_impl(cls, vnf_model): + """ Find the implementing class from vnf_model["vnf"]["name"] field + + :param vnf_model: dictionary containing a parsed vnfd + :return: subclass of GenericVNF + """ + import_modules_from_package( + "yardstick.network_services.vnf_generic.vnf") + expected_name = vnf_model['id'] + impl = [c for c in itersubclasses(GenericVNF) + if c.__name__ == expected_name] + try: + return next(iter(impl)) + except StopIteration: + raise IncorrectConfig("No implementation for %s", expected_name) + + def load_vnf_models(self, context_cfg): + """ Create VNF objects based on YAML descriptors + + :param context_cfg: + :return: + """ + vnfs = [] + for node in context_cfg["nodes"]: + LOG.debug(context_cfg["nodes"][node]) + with open(context_cfg["nodes"][node]["VNF model"]) as stream: + vnf_model = stream.read() + vnfd = vnfdgen.generate_vnfd(vnf_model, context_cfg["nodes"][node]) + vnf_impl = self.get_vnf_impl(vnfd["vnfd:vnfd-catalog"]["vnfd"][0]) + vnf_instance = vnf_impl(vnfd["vnfd:vnfd-catalog"]["vnfd"][0]) + vnf_instance.name = node + vnfs.append(vnf_instance) + + return vnfs + + def setup(self): + """ Setup infrastructure, provission VNFs & start traffic + + :return: + """ + + # 1. Verify if infrastructure mapping can meet topology + self.map_topology_to_infrastructure(self.context_cfg, self.topology) + # 1a. Load VNF models + self.vnfs = self.load_vnf_models(self.context_cfg) + # 1b. Fill traffic profile with information from topology + self.traffic_profile = self._fill_traffic_profile(self.scenario_cfg, + self.context_cfg) + + # 2. Provision VNFs + try: + for vnf in self.vnfs: + LOG.info("Instantiating %s", vnf.name) + vnf.instantiate(self.scenario_cfg, self.context_cfg) + except RuntimeError: + for vnf in self.vnfs: + vnf.terminate() + raise + + # 3. Run experiment + # Start listeners first to avoid losing packets + traffic_runners = [vnf for vnf in self.vnfs if vnf.runs_traffic] + for traffic_gen in traffic_runners: + traffic_gen.listen_traffic(self.traffic_profile) + + # register collector with yardstick for KPI collection. + self.collector = Collector(self.vnfs, self.traffic_profile) + self.collector.start() + + # Start the actual traffic + for traffic_gen in traffic_runners: + LOG.info("Starting traffic on %s", traffic_gen.name) + traffic_gen.run_traffic(self.traffic_profile) + + def run(self, result): # yardstick API + """ Yardstick calls run() at intervals defined in the yaml and + produces timestamped samples + + :param result: dictionary with results to update + :return: None + """ + + for vnf in self.vnfs: + # Result example: + # {"VNF1: { "tput" : [1000, 999] }, "VNF2": { "latency": 100 }} + LOG.debug("vnf") + result.update(self.collector.get_kpi(vnf)) + + def teardown(self): + """ Stop the collector and terminate VNF & TG instance + + :return + """ + + self.collector.stop() + for vnf in self.vnfs: + LOG.info("Stopping %s", vnf.name) + vnf.terminate() diff --git a/yardstick/network_services/traffic_profile/__init__.py b/yardstick/network_services/traffic_profile/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/yardstick/network_services/traffic_profile/base.py b/yardstick/network_services/traffic_profile/base.py new file mode 100644 index 000000000..906498586 --- /dev/null +++ b/yardstick/network_services/traffic_profile/base.py @@ -0,0 +1,64 @@ +# 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. +""" Base class for the generic traffic profile implementation """ + +from __future__ import absolute_import +from yardstick.common.utils import import_modules_from_package, itersubclasses + + +class TrafficProfile(object): + """ + This class defines the behavior + + """ + + @staticmethod + def get(tp_config): + """Get the traffic profile instance for the given traffic type + + :param tp_config: loaded YAML file + :return: + """ + profile_class = tp_config["traffic_profile"]["traffic_type"] + import_modules_from_package( + "yardstick.network_services.traffic_profile") + try: + return next(c for c in itersubclasses(TrafficProfile) + if c.__name__ == profile_class)(tp_config) + except StopIteration: + raise RuntimeError("No implementation for %s", profile_class) + + def __init__(self, tp_config): + # e.g. RFC2544 start_ip, stop_ip, drop_rate, + # IMIX = {"10K": 0.1, "100M": 0.5} + self.params = tp_config + + def execute(self, traffic_generator): + """ This methods defines the behavior of the traffic generator. + It will be called in a loop until the traffic generator exits. + + :param traffic_generator: TrafficGen instance + :return: None + """ + raise NotImplementedError() + + +class DummyProfile(TrafficProfile): + """ + This is an empty TrafficProfile implementation - if it is used, + the traffic will be completely handled by the Traffic Generator + implementation with no regard for the Traffic Profile. + """ + def execute(self, traffic_generator): + pass diff --git a/yardstick/network_services/vnf_generic/__init__.py b/yardstick/network_services/vnf_generic/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/yardstick/network_services/vnf_generic/vnf/__init__.py b/yardstick/network_services/vnf_generic/vnf/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/yardstick/network_services/vnf_generic/vnf/base.py b/yardstick/network_services/vnf_generic/vnf/base.py new file mode 100644 index 000000000..1d770f724 --- /dev/null +++ b/yardstick/network_services/vnf_generic/vnf/base.py @@ -0,0 +1,327 @@ +# 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. +""" Base class implementation for generic vnf implementation """ + +from __future__ import absolute_import +import logging +import ipaddress +import six + +from yardstick.network_services.utils import get_nsb_option + +LOG = logging.getLogger(__name__) + + +class QueueFileWrapper(object): + """ Class providing file-like API for talking with SSH connection """ + + def __init__(self, q_in, q_out, prompt): + self.q_in = q_in + self.q_out = q_out + self.closed = False + self.buf = [] + self.bufsize = 20 + self.prompt = prompt + + def read(self, size): + """ read chunk from input queue """ + if self.q_in.qsize() > 0 and size: + in_data = self.q_in.get() + return in_data + + def write(self, chunk): + """ write chunk to output queue """ + self.buf.append(chunk) + # flush on prompt or if we exceed bufsize + + size = sum(len(c) for c in self.buf) + if self.prompt in chunk or size > self.bufsize: + out = ''.join(self.buf) + self.buf = [] + self.q_out.put(out) + + def close(self): + """ close multiprocessing queue """ + pass + + def clear(self): + """ clear queue """ + while self.q_out.qsize() > 0: + self.q_out.get() + + +class GenericVNF(object): + """ Class providing file-like API for generic VNF implementation """ + def __init__(self, vnfd): + super(GenericVNF, self).__init__() + self.vnfd = vnfd # fixme: parse this into a structure + # List of statistics we can obtain from this VNF + # - ETSI MANO 6.3.1.1 monitoring_parameter + self.kpi = self._get_kpi_definition(vnfd) + # Standard dictionary containing params like thread no, buffer size etc + self.config = {} + self.runs_traffic = False + self.name = "vnf__1" # name in topology file + self.bin_path = get_nsb_option("bin_path", "") + + @classmethod + def _get_kpi_definition(cls, vnfd): + """ Get list of KPIs defined in VNFD + + :param vnfd: + :return: list of KPIs, e.g. ['throughput', 'latency'] + """ + return vnfd['benchmark']['kpi'] + + @classmethod + def get_ip_version(cls, ip_addr): + """ get ip address version v6 or v4 """ + try: + address = ipaddress.ip_address(six.text_type(ip_addr)) + except ValueError: + LOG.error(ip_addr, " is not valid") + return + else: + return address.version + + def _ip_to_hex(self, ip_addr): + ip_to_convert = ip_addr.split(".") + ip_x = ip_addr + if self.get_ip_version(ip_addr) == 4: + ip_to_convert = ip_addr.split(".") + ip_octect = [int(octect) for octect in ip_to_convert] + ip_x = "{0[0]:02X}{0[1]:02X}{0[2]:02X}{0[3]:02X}".format(ip_octect) + return ip_x + + def _get_dpdk_port_num(self, name): + for intf in self.vnfd['vdu'][0]['external-interface']: + if name == intf['name']: + return intf['virtual-interface']['dpdk_port_num'] + + def _append_routes(self, ip_pipeline_cfg): + if 'routing_table' in self.vnfd['vdu'][0]: + routing_table = self.vnfd['vdu'][0]['routing_table'] + + where = ip_pipeline_cfg.find("arp_route_tbl") + link = ip_pipeline_cfg[:where] + route_add = ip_pipeline_cfg[where:] + + tmp = route_add.find('\n') + route_add = route_add[tmp:] + + cmds = "arp_route_tbl =" + + for route in routing_table: + net = self._ip_to_hex(route['network']) + net_nm = self._ip_to_hex(route['netmask']) + net_gw = self._ip_to_hex(route['gateway']) + port = self._get_dpdk_port_num(route['if']) + cmd = \ + " ({port0_local_ip_hex},{port0_netmask_hex},{dpdk_port},"\ + "{port1_local_ip_hex})".format(port0_local_ip_hex=net, + port0_netmask_hex=net_nm, + dpdk_port=port, + port1_local_ip_hex=net_gw) + cmds += cmd + + cmds += '\n' + ip_pipeline_cfg = link + cmds + route_add + + return ip_pipeline_cfg + + def _append_nd_routes(self, ip_pipeline_cfg): + if 'nd_route_tbl' in self.vnfd['vdu'][0]: + routing_table = self.vnfd['vdu'][0]['nd_route_tbl'] + + where = ip_pipeline_cfg.find("nd_route_tbl") + link = ip_pipeline_cfg[:where] + route_nd = ip_pipeline_cfg[where:] + + tmp = route_nd.find('\n') + route_nd = route_nd[tmp:] + + cmds = "nd_route_tbl =" + + for route in routing_table: + net = route['network'] + net_nm = route['netmask'] + net_gw = route['gateway'] + port = self._get_dpdk_port_num(route['if']) + cmd = \ + " ({port0_local_ip_hex},{port0_netmask_hex},{dpdk_port},"\ + "{port1_local_ip_hex})".format(port0_local_ip_hex=net, + port0_netmask_hex=net_nm, + dpdk_port=port, + port1_local_ip_hex=net_gw) + cmds += cmd + + cmds += '\n' + ip_pipeline_cfg = link + cmds + route_nd + + return ip_pipeline_cfg + + def _get_port0localip6(self): + return_value = "" + if 'nd_route_tbl' in self.vnfd['vdu'][0]: + routing_table = self.vnfd['vdu'][0]['nd_route_tbl'] + + inc = 0 + for route in routing_table: + inc += 1 + if inc == 1: + return_value = route['network'] + LOG.info("_get_port0localip6 : %s", return_value) + return return_value + + def _get_port1localip6(self): + return_value = "" + if 'nd_route_tbl' in self.vnfd['vdu'][0]: + routing_table = self.vnfd['vdu'][0]['nd_route_tbl'] + + inc = 0 + for route in routing_table: + inc += 1 + if inc == 2: + return_value = route['network'] + LOG.info("_get_port1localip6 : %s", return_value) + return return_value + + def _get_port0prefixlen6(self): + return_value = "" + if 'nd_route_tbl' in self.vnfd['vdu'][0]: + routing_table = self.vnfd['vdu'][0]['nd_route_tbl'] + + inc = 0 + for route in routing_table: + inc += 1 + if inc == 1: + return_value = route['netmask'] + LOG.info("_get_port0prefixlen6 : %s", return_value) + return return_value + + def _get_port1prefixlen6(self): + return_value = "" + if 'nd_route_tbl' in self.vnfd['vdu'][0]: + routing_table = self.vnfd['vdu'][0]['nd_route_tbl'] + + inc = 0 + for route in routing_table: + inc += 1 + if inc == 2: + return_value = route['netmask'] + LOG.info("_get_port1prefixlen6 : %s", return_value) + return return_value + + def _get_port0gateway6(self): + return_value = "" + if 'nd_route_tbl' in self.vnfd['vdu'][0]: + routing_table = self.vnfd['vdu'][0]['nd_route_tbl'] + + inc = 0 + for route in routing_table: + inc += 1 + if inc == 1: + return_value = route['network'] + LOG.info("_get_port0gateway6 : %s", return_value) + return return_value + + def _get_port1gateway6(self): + return_value = "" + if 'nd_route_tbl' in self.vnfd['vdu'][0]: + routing_table = self.vnfd['vdu'][0]['nd_route_tbl'] + + inc = 0 + for route in routing_table: + inc += 1 + if inc == 2: + return_value = route['network'] + LOG.info("_get_port1gateway6 : %s", return_value) + return return_value + + def instantiate(self, scenario_cfg, context_cfg): + """ Prepare VNF for operation and start the VNF process/VM + + :param scenario_cfg: + :param context_cfg: + :return: True/False + """ + raise NotImplementedError() + + def terminate(self): + """ Kill all VNF processes + + :return: + """ + raise NotImplementedError() + + def scale(self, flavor=""): + """ + + :param flavor: + :return: + """ + raise NotImplementedError() + + def collect_kpi(self): + """This method should return a dictionary containing the + selected KPI at a given point of time. + + :return: {"kpi": value, "kpi2": value} + """ + raise NotImplementedError() + + +class GenericTrafficGen(GenericVNF): + """ Class providing file-like API for generic traffic generator """ + + def __init__(self, vnfd): + super(GenericTrafficGen, self).__init__(vnfd) + self.runs_traffic = True + self.traffic_finished = False + self.name = "tgen__1" # name in topology file + + def run_traffic(self, traffic_profile): + """ Generate traffic on the wire according to the given params. + Method is non-blocking, returns immediately when traffic process + is running. Mandatory. + + :param traffic_profile: + :return: True/False + """ + raise NotImplementedError() + + def listen_traffic(self, traffic_profile): + """ Listen to traffic with the given parameters. + Method is non-blocking, returns immediately when traffic process + is running. Optional. + + :param traffic_profile: + :return: True/False + """ + pass + + def verify_traffic(self, traffic_profile): + """ Verify captured traffic after it has ended. Optional. + + :param traffic_profile: + :return: dict + """ + pass + + def terminate(self): + """ After this method finishes, all traffic processes should stop. Mandatory. + + :return: True/False + """ + raise NotImplementedError() diff --git a/yardstick/network_services/vnf_generic/vnfdgen.py b/yardstick/network_services/vnf_generic/vnfdgen.py new file mode 100644 index 000000000..9a02050a2 --- /dev/null +++ b/yardstick/network_services/vnf_generic/vnfdgen.py @@ -0,0 +1,71 @@ +# 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. +""" Generic file to map and build vnf discriptor """ + +from __future__ import absolute_import +import collections +import yaml +import six + +from yardstick.common.task_template import TaskTemplate + + +def generate_vnfd(vnf_model, node): + """ + + :param vnf_model: VNF definition template, e.g. tg_ping_tpl.yaml + :param node: node configuration taken from pod.yaml + :return: Complete VNF Descriptor that will be taken + as input for GenericVNF.__init__ + """ + node["get"] = get + rendered_vnfd = TaskTemplate.render(vnf_model, **node) + # This is done to get rid of issues with serializing node + del node["get"] + filled_vnfd = yaml.load(rendered_vnfd) + return filled_vnfd + + +def dict_key_flatten(data): + """ Convert nested dict structure to dotted key + (e.g. {"a":{"b":1}} -> {"a.b":1} + + :param data: nested dictionary + :return: flat dicrionary + """ + next_data = {} + + if not any((isinstance(v, collections.Iterable) and not isinstance(v, str)) + for v in data.values()): + return data + + for key, val in six.iteritems(data): + if isinstance(val, collections.Mapping): + for n_k, n_v in six.iteritems(val): + next_data["%s.%s" % (key, n_k)] = n_v + elif isinstance(val, collections.Iterable) and not isinstance(val, + str): + for index, item in enumerate(val): + next_data["%s%d" % (key, index)] = item + else: + next_data[key] = val + + return dict_key_flatten(next_data) + + +def get(obj, key, *args): + """ Get template key from dictionary, get default value or raise an exception + """ + data = dict_key_flatten(obj) + return data.get(key, *args) -- cgit 1.2.3-korg