1 # Copyright (c) 2016-2017 Intel Corporation
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
7 # http://www.apache.org/licenses/LICENSE-2.0
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
19 from yardstick.tests import STL_MOCKS
20 from yardstick.tests.unit.network_services.vnf_generic.vnf.test_base import mock_ssh
21 from yardstick.benchmark.contexts import base as ctx_base
24 STLClient = mock.MagicMock()
25 stl_patch = mock.patch.dict("sys.modules", STL_MOCKS)
29 from yardstick.network_services.vnf_generic.vnf.router_vnf import RouterVNF
32 TEST_FILE_YAML = 'nsb_test_case.yaml'
33 SSH_HELPER = 'yardstick.network_services.vnf_generic.vnf.sample_vnf.VnfSshHelper'
39 class TestRouterVNF(unittest.TestCase):
40 VNFD = {'vnfd:vnfd-catalog':
42 [{'short-name': 'RouterVNF',
44 [{'routing_table': [],
45 'description': 'RouterVNF',
46 'name': 'router-baremetal',
48 'id': 'router-baremetal',
50 [{'virtual-interface':
51 {'dst_mac': '00:00:00:00:00:04',
52 'vpci': '0000:05:00.0',
53 'local_ip': '152.16.100.19',
54 'type': 'PCI-PASSTHROUGH',
55 'netmask': '255.255.255.0',
57 'bandwidth': '10 Gbps',
59 'dst_ip': '152.16.100.20',
60 'local_iface_name': 'xe0',
61 'local_mac': '00:00:00:00:00:02'},
62 'vnfd-connection-point-ref': 'xe0',
65 {'dst_mac': '00:00:00:00:00:03',
66 'vpci': '0000:05:00.1',
67 'local_ip': '152.16.40.19',
68 'type': 'PCI-PASSTHROUGH',
70 'netmask': '255.255.255.0',
72 'bandwidth': '10 Gbps',
73 'dst_ip': '152.16.40.20',
74 'local_iface_name': 'xe1',
75 'local_mac': '00:00:00:00:00:01'},
76 'vnfd-connection-point-ref': 'xe1',
78 'description': 'RouterVNF',
80 {'vdu-id': 'router-baremetal',
86 {'kpi': ['packets_in', 'packets_fwd', 'packets_dropped']},
87 'connection-point': [{'type': 'VPORT', 'name': 'xe0'},
88 {'type': 'VPORT', 'name': 'xe1'}],
89 'id': 'RouterVNF', 'name': 'VPEVnfSsh'}]}}
91 scenario_cfg = {'nodes': {'cpt__0': 'compute_0.compute_nodes',
92 'tg__0': 'trafficgen_1.baremetal',
93 'vnf__0': 'vnf.yardstick'},
94 'options': {'flow': {'count': 128000,
95 'dst_ip': ['10.0.3.26-10.0.3.105'],
96 'dst_port': ['2001-2004'],
97 'src_ip': ['10.0.2.26-10.0.2.105'],
98 'src_port': ['1234-1238']},
99 'framesize': {'downlink': {'1024B': 100},
100 'uplink': {'1024B': 100}},
101 'rfc2544': {'allowed_drop_rate': '0.0001 - 0.1'},
102 'tg__0': {'queues_per_port': 7},
104 'vnf__0': {'nfvi_enable': True}},
105 'runner': {'interval': 35,
107 'type': 'Iteration'},
108 'topology': 'router-tg-topology.yaml',
109 'traffic_profile': '../../traffic_profiles/ipv4_throughput.yaml',
112 context_cfg = {'nodes': {'tg__1':
113 {'member-vnf-index': '1',
114 'role': 'TrafficGen',
115 'name': 'trafficgen_1.yardstick',
116 'vnfd-id-ref': 'tg__1',
119 {'xe0': {'local_iface_name': 'ens785f0',
120 'vld_id': RouterVNF.UPLINK,
121 'netmask': '255.255.255.0',
122 'local_ip': '152.16.100.20',
123 'dst_mac': '00:00:00:00:00:02',
124 'local_mac': '00:00:00:00:00:04',
125 'dst_ip': '152.16.100.19',
127 'vpci': '0000:05:00.0',
129 'xe1': {'local_iface_name': 'ens785f1',
130 'netmask': '255.255.255.0',
131 'local_ip': '152.16.100.21',
132 'local_mac': '00:00:00:00:00:01',
134 'vpci': '0000:05:00.1',
135 'dpdk_port_num': 1}},
137 'VNF model': 'tg_rfc2544_tpl.yaml',
140 {'name': 'vnf.yardstick',
141 'vnfd-id-ref': 'vnf__1',
144 {'xe0': {'local_iface_name': 'ens786f0',
145 'vld_id': RouterVNF.UPLINK,
146 'netmask': '255.255.255.0',
147 'local_ip': '152.16.100.19',
148 'dst_mac': '00:00:00:00:00:04',
149 'local_mac': '00:00:00:00:00:02',
150 'dst_ip': '152.16.100.20',
152 'vpci': '0000:05:00.0',
154 'xe1': {'local_iface_name': 'ens786f1',
155 'vld_id': RouterVNF.DOWNLINK,
156 'netmask': '255.255.255.0',
157 'local_ip': '152.16.40.19',
158 'dst_mac': '00:00:00:00:00:03',
159 'local_mac': '00:00:00:00:00:01',
160 'dst_ip': '152.16.40.20',
162 'vpci': '0000:05:00.1',
163 'dpdk_port_num': 1}},
165 'member-vnf-index': '2',
171 'VNF model': 'router_vnf.yaml'}}}
173 IP_SHOW_STATS_OUTPUT = """\
174 2: em1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP mode DEFAULT group default qlen 1000
175 link/ether d4:c9:ef:52:7c:4d brd ff:ff:ff:ff:ff:ff
176 RX: bytes packets errors dropped overrun mcast
177 2781945429 3202213 0 0 0 30131
178 RX errors: length crc frame fifo missed
180 TX: bytes packets errors dropped carrier collsns
181 646221183 2145799 0 0 0 0
182 TX errors: aborted fifo window heartbeat
186 'RX:bytes': '2781945429',
191 'RX:packets': '3202213',
192 'RX errors:length': '0',
193 'RX errors:crc': '0',
194 'RX errors:frame': '0',
195 'RX errors:fifo': '0',
196 'RX errors:missed': '0',
197 'TX:bytes': '646221183',
202 'TX:packets': '2145799',
203 'TX errors:aborted': '0',
204 'TX errors:fifo': '0',
205 'TX errors:window': '0',
206 'TX errors:heartbeat': '0',
209 def test___init__(self):
210 vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0]
211 router_vnf = RouterVNF(name, vnfd)
212 self.assertIsNone(router_vnf._vnf_process)
214 def test_get_stats(self):
215 stats = RouterVNF.get_stats(self.IP_SHOW_STATS_OUTPUT)
216 self.assertDictEqual(stats, self.STATS)
218 @mock.patch.object(ctx_base.Context, 'get_physical_node_from_server', return_value='mock_node')
219 @mock.patch("yardstick.network_services.vnf_generic.vnf.sample_vnf.time")
220 @mock.patch(SSH_HELPER)
221 def test_collect_kpi(self, ssh, *args):
224 vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0]
225 router_vnf = RouterVNF(name, vnfd)
226 router_vnf.scenario_helper.scenario_cfg = {
227 'nodes': {router_vnf.name: "mock"}
229 router_vnf.ssh_helper = m
231 'physical_node': 'mock_node',
232 'packets_dropped': 0,
237 self.assertEqual(result, router_vnf.collect_kpi())
239 @mock.patch(SSH_HELPER)
240 def test_run_router(self, ssh):
243 vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0]
244 router_vnf = RouterVNF(name, vnfd)
245 router_vnf.scenario_helper.scenario_cfg = self.scenario_cfg
247 router_vnf.ssh_helper.drop_connection.assert_called_once()
249 @mock.patch.object(ctx_base, 'Context')
250 @mock.patch(SSH_HELPER)
251 def test_instantiate(self, ssh, *args):
254 vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0]
255 router_vnf = RouterVNF(name, vnfd)
256 router_vnf.WAIT_TIME = 0
257 router_vnf.INTERFACE_WAIT = 0
258 self.scenario_cfg.update({"nodes": {"vnf__1": ""}})
259 self.assertIsNone(router_vnf.instantiate(self.scenario_cfg,
262 @mock.patch("yardstick.network_services.vnf_generic.vnf.sample_vnf.time")
263 @mock.patch(SSH_HELPER)
264 def test_terminate(self, ssh, _):
267 vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0]
268 router_vnf = RouterVNF(name, vnfd)
269 router_vnf._vnf_process = mock.MagicMock()
270 router_vnf._vnf_process.terminate = mock.Mock()
271 self.assertIsNone(router_vnf.terminate())