1 # Copyright (c) 2016-2019 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.
18 from yardstick.tests.unit.network_services.vnf_generic.vnf.test_base import mock_ssh
19 from yardstick.benchmark.contexts import base as ctx_base
20 from yardstick.network_services.vnf_generic.vnf.router_vnf import RouterVNF
23 TEST_FILE_YAML = 'nsb_test_case.yaml'
24 SSH_HELPER = 'yardstick.network_services.vnf_generic.vnf.sample_vnf.VnfSshHelper'
30 class TestRouterVNF(unittest.TestCase):
31 VNFD = {'vnfd:vnfd-catalog':
33 [{'short-name': 'RouterVNF',
35 [{'routing_table': [],
36 'description': 'RouterVNF',
37 'name': 'router-baremetal',
39 'id': 'router-baremetal',
41 [{'virtual-interface':
42 {'dst_mac': '00:00:00:00:00:04',
43 'vpci': '0000:05:00.0',
44 'local_ip': '152.16.100.19',
45 'type': 'PCI-PASSTHROUGH',
46 'netmask': '255.255.255.0',
48 'bandwidth': '10 Gbps',
50 'dst_ip': '152.16.100.20',
51 'local_iface_name': 'xe0',
52 'local_mac': '00:00:00:00:00:02'},
53 'vnfd-connection-point-ref': 'xe0',
56 {'dst_mac': '00:00:00:00:00:03',
57 'vpci': '0000:05:00.1',
58 'local_ip': '152.16.40.19',
59 'type': 'PCI-PASSTHROUGH',
61 'netmask': '255.255.255.0',
63 'bandwidth': '10 Gbps',
64 'dst_ip': '152.16.40.20',
65 'local_iface_name': 'xe1',
66 'local_mac': '00:00:00:00:00:01'},
67 'vnfd-connection-point-ref': 'xe1',
69 'description': 'RouterVNF',
71 {'vdu-id': 'router-baremetal',
77 {'kpi': ['packets_in', 'packets_fwd', 'packets_dropped']},
78 'connection-point': [{'type': 'VPORT', 'name': 'xe0'},
79 {'type': 'VPORT', 'name': 'xe1'}],
80 'id': 'RouterVNF', 'name': 'VPEVnfSsh'}]}}
82 scenario_cfg = {'nodes': {'cpt__0': 'compute_0.compute_nodes',
83 'tg__0': 'trafficgen_1.baremetal',
84 'vnf__0': 'vnf.yardstick'},
85 'options': {'flow': {'count': 128000,
86 'dst_ip': ['10.0.3.26-10.0.3.105'],
87 'dst_port': ['2001-2004'],
88 'src_ip': ['10.0.2.26-10.0.2.105'],
89 'src_port': ['1234-1238']},
90 'framesize': {'downlink': {'1024B': 100},
91 'uplink': {'1024B': 100}},
92 'rfc2544': {'allowed_drop_rate': '0.0001 - 0.1'},
93 'tg__0': {'queues_per_port': 7},
95 'vnf__0': {'nfvi_enable': True}},
96 'runner': {'interval': 35,
99 'topology': 'router-tg-topology.yaml',
100 'traffic_profile': '../../traffic_profiles/ipv4_throughput.yaml',
103 context_cfg = {'nodes': {'tg__1':
104 {'member-vnf-index': '1',
105 'role': 'TrafficGen',
106 'name': 'trafficgen_1.yardstick',
107 'vnfd-id-ref': 'tg__1',
110 {'xe0': {'local_iface_name': 'ens785f0',
111 'vld_id': RouterVNF.UPLINK,
112 'netmask': '255.255.255.0',
113 'local_ip': '152.16.100.20',
114 'dst_mac': '00:00:00:00:00:02',
115 'local_mac': '00:00:00:00:00:04',
116 'dst_ip': '152.16.100.19',
118 'vpci': '0000:05:00.0',
120 'xe1': {'local_iface_name': 'ens785f1',
121 'netmask': '255.255.255.0',
122 'local_ip': '152.16.100.21',
123 'local_mac': '00:00:00:00:00:01',
125 'vpci': '0000:05:00.1',
126 'dpdk_port_num': 1}},
128 'VNF model': 'tg_rfc2544_tpl.yaml',
131 {'name': 'vnf.yardstick',
132 'vnfd-id-ref': 'vnf__1',
135 {'xe0': {'local_iface_name': 'ens786f0',
136 'vld_id': RouterVNF.UPLINK,
137 'netmask': '255.255.255.0',
138 'local_ip': '152.16.100.19',
139 'dst_mac': '00:00:00:00:00:04',
140 'local_mac': '00:00:00:00:00:02',
141 'dst_ip': '152.16.100.20',
143 'vpci': '0000:05:00.0',
145 'xe1': {'local_iface_name': 'ens786f1',
146 'vld_id': RouterVNF.DOWNLINK,
147 'netmask': '255.255.255.0',
148 'local_ip': '152.16.40.19',
149 'dst_mac': '00:00:00:00:00:03',
150 'local_mac': '00:00:00:00:00:01',
151 'dst_ip': '152.16.40.20',
153 'vpci': '0000:05:00.1',
154 'dpdk_port_num': 1}},
156 'member-vnf-index': '2',
162 'VNF model': 'router_vnf.yaml'}}}
164 IP_SHOW_STATS_OUTPUT = """\
165 2: em1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP mode DEFAULT group default qlen 1000
166 link/ether d4:c9:ef:52:7c:4d brd ff:ff:ff:ff:ff:ff
167 RX: bytes packets errors dropped overrun mcast
168 2781945429 3202213 0 0 0 30131
169 RX errors: length crc frame fifo missed
171 TX: bytes packets errors dropped carrier collsns
172 646221183 2145799 0 0 0 0
173 TX errors: aborted fifo window heartbeat
177 'RX:bytes': '2781945429',
182 'RX:packets': '3202213',
183 'RX errors:length': '0',
184 'RX errors:crc': '0',
185 'RX errors:frame': '0',
186 'RX errors:fifo': '0',
187 'RX errors:missed': '0',
188 'TX:bytes': '646221183',
193 'TX:packets': '2145799',
194 'TX errors:aborted': '0',
195 'TX errors:fifo': '0',
196 'TX errors:window': '0',
197 'TX errors:heartbeat': '0',
200 def test___init__(self):
201 vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0]
202 router_vnf = RouterVNF(name, vnfd)
203 self.assertIsNone(router_vnf._vnf_process)
205 def test_get_stats(self):
206 stats = RouterVNF.get_stats(self.IP_SHOW_STATS_OUTPUT)
207 self.assertDictEqual(stats, self.STATS)
209 @mock.patch.object(ctx_base.Context, 'get_physical_node_from_server', return_value='mock_node')
210 @mock.patch("yardstick.network_services.vnf_generic.vnf.sample_vnf.time")
211 @mock.patch(SSH_HELPER)
212 def test_collect_kpi(self, ssh, *args):
215 vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0]
216 router_vnf = RouterVNF(name, vnfd)
217 router_vnf.scenario_helper.scenario_cfg = {
218 'nodes': {router_vnf.name: "mock"}
220 router_vnf.ssh_helper = m
222 'physical_node': 'mock_node',
223 'packets_dropped': 0,
228 self.assertEqual(result, router_vnf.collect_kpi())
230 @mock.patch(SSH_HELPER)
231 def test_run_router(self, ssh):
234 vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0]
235 router_vnf = RouterVNF(name, vnfd)
236 router_vnf.scenario_helper.scenario_cfg = self.scenario_cfg
238 router_vnf.ssh_helper.drop_connection.assert_called_once()
240 @mock.patch.object(ctx_base, 'Context')
241 @mock.patch(SSH_HELPER)
242 def test_instantiate(self, ssh, *args):
245 vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0]
246 router_vnf = RouterVNF(name, vnfd)
247 router_vnf.WAIT_TIME = 0
248 router_vnf.INTERFACE_WAIT = 0
249 self.scenario_cfg.update({"nodes": {"vnf__1": ""}})
250 self.assertIsNone(router_vnf.instantiate(self.scenario_cfg,
253 @mock.patch("yardstick.network_services.vnf_generic.vnf.sample_vnf.time")
254 @mock.patch(SSH_HELPER)
255 def test_terminate(self, ssh, _):
258 vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0]
259 router_vnf = RouterVNF(name, vnfd)
260 router_vnf._vnf_process = mock.MagicMock()
261 router_vnf._vnf_process.terminate = mock.Mock()
262 self.assertIsNone(router_vnf.terminate())