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
23 STLClient = mock.MagicMock()
24 stl_patch = mock.patch.dict("sys.modules", STL_MOCKS)
28 from yardstick.network_services.vnf_generic.vnf.router_vnf import RouterVNF
31 TEST_FILE_YAML = 'nsb_test_case.yaml'
32 SSH_HELPER = 'yardstick.network_services.vnf_generic.vnf.sample_vnf.VnfSshHelper'
38 class TestRouterVNF(unittest.TestCase):
39 VNFD = {'vnfd:vnfd-catalog':
41 [{'short-name': 'RouterVNF',
43 [{'routing_table': [],
44 'description': 'RouterVNF',
45 'name': 'router-baremetal',
47 'id': 'router-baremetal',
49 [{'virtual-interface':
50 {'dst_mac': '00:00:00:00:00:04',
51 'vpci': '0000:05:00.0',
52 'local_ip': '152.16.100.19',
53 'type': 'PCI-PASSTHROUGH',
54 'netmask': '255.255.255.0',
56 'bandwidth': '10 Gbps',
58 'dst_ip': '152.16.100.20',
59 'local_iface_name': 'xe0',
60 'local_mac': '00:00:00:00:00:02'},
61 'vnfd-connection-point-ref': 'xe0',
64 {'dst_mac': '00:00:00:00:00:03',
65 'vpci': '0000:05:00.1',
66 'local_ip': '152.16.40.19',
67 'type': 'PCI-PASSTHROUGH',
69 'netmask': '255.255.255.0',
71 'bandwidth': '10 Gbps',
72 'dst_ip': '152.16.40.20',
73 'local_iface_name': 'xe1',
74 'local_mac': '00:00:00:00:00:01'},
75 'vnfd-connection-point-ref': 'xe1',
77 'description': 'RouterVNF',
79 {'vdu-id': 'router-baremetal',
85 {'kpi': ['packets_in', 'packets_fwd', 'packets_dropped']},
86 'connection-point': [{'type': 'VPORT', 'name': 'xe0'},
87 {'type': 'VPORT', 'name': 'xe1'}],
88 'id': 'RouterVNF', 'name': 'VPEVnfSsh'}]}}
90 scenario_cfg = {'nodes': {'cpt__0': 'compute_0.compute_nodes',
91 'tg__0': 'trafficgen_1.baremetal',
92 'vnf__0': 'vnf.yardstick'},
93 'options': {'flow': {'count': 128000,
94 'dst_ip': ['10.0.3.26-10.0.3.105'],
95 'dst_port': ['2001-2004'],
96 'src_ip': ['10.0.2.26-10.0.2.105'],
97 'src_port': ['1234-1238']},
98 'framesize': {'downlink': {'1024B': 100},
99 'uplink': {'1024B': 100}},
100 'rfc2544': {'allowed_drop_rate': '0.0001 - 0.1'},
101 'tg__0': {'queues_per_port': 7},
103 'vnf__0': {'nfvi_enable': True}},
104 'runner': {'interval': 35,
106 'type': 'Iteration'},
107 'topology': 'router-tg-topology.yaml',
108 'traffic_profile': '../../traffic_profiles/ipv4_throughput.yaml',
111 context_cfg = {'nodes': {'tg__1':
112 {'member-vnf-index': '1',
113 'role': 'TrafficGen',
114 'name': 'trafficgen_1.yardstick',
115 'vnfd-id-ref': 'tg__1',
118 {'xe0': {'local_iface_name': 'ens785f0',
119 'vld_id': RouterVNF.UPLINK,
120 'netmask': '255.255.255.0',
121 'local_ip': '152.16.100.20',
122 'dst_mac': '00:00:00:00:00:02',
123 'local_mac': '00:00:00:00:00:04',
124 'dst_ip': '152.16.100.19',
126 'vpci': '0000:05:00.0',
128 'xe1': {'local_iface_name': 'ens785f1',
129 'netmask': '255.255.255.0',
130 'local_ip': '152.16.100.21',
131 'local_mac': '00:00:00:00:00:01',
133 'vpci': '0000:05:00.1',
134 'dpdk_port_num': 1}},
136 'VNF model': 'tg_rfc2544_tpl.yaml',
139 {'name': 'vnf.yardstick',
140 'vnfd-id-ref': 'vnf__1',
143 {'xe0': {'local_iface_name': 'ens786f0',
144 'vld_id': RouterVNF.UPLINK,
145 'netmask': '255.255.255.0',
146 'local_ip': '152.16.100.19',
147 'dst_mac': '00:00:00:00:00:04',
148 'local_mac': '00:00:00:00:00:02',
149 'dst_ip': '152.16.100.20',
151 'vpci': '0000:05:00.0',
153 'xe1': {'local_iface_name': 'ens786f1',
154 'vld_id': RouterVNF.DOWNLINK,
155 'netmask': '255.255.255.0',
156 'local_ip': '152.16.40.19',
157 'dst_mac': '00:00:00:00:00:03',
158 'local_mac': '00:00:00:00:00:01',
159 'dst_ip': '152.16.40.20',
161 'vpci': '0000:05:00.1',
162 'dpdk_port_num': 1}},
164 'member-vnf-index': '2',
170 'VNF model': 'router_vnf.yaml'}}}
172 IP_SHOW_STATS_OUTPUT = """\
173 2: em1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP mode DEFAULT group default qlen 1000
174 link/ether d4:c9:ef:52:7c:4d brd ff:ff:ff:ff:ff:ff
175 RX: bytes packets errors dropped overrun mcast
176 2781945429 3202213 0 0 0 30131
177 RX errors: length crc frame fifo missed
179 TX: bytes packets errors dropped carrier collsns
180 646221183 2145799 0 0 0 0
181 TX errors: aborted fifo window heartbeat
185 'RX:bytes': '2781945429',
190 'RX:packets': '3202213',
191 'RX errors:length': '0',
192 'RX errors:crc': '0',
193 'RX errors:frame': '0',
194 'RX errors:fifo': '0',
195 'RX errors:missed': '0',
196 'TX:bytes': '646221183',
201 'TX:packets': '2145799',
202 'TX errors:aborted': '0',
203 'TX errors:fifo': '0',
204 'TX errors:window': '0',
205 'TX errors:heartbeat': '0',
208 def test___init__(self):
209 vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0]
210 router_vnf = RouterVNF(name, vnfd)
211 self.assertIsNone(router_vnf._vnf_process)
213 def test_get_stats(self):
214 stats = RouterVNF.get_stats(self.IP_SHOW_STATS_OUTPUT)
215 self.assertDictEqual(stats, self.STATS)
217 @mock.patch("yardstick.network_services.vnf_generic.vnf.sample_vnf.time")
218 @mock.patch(SSH_HELPER)
219 def test_collect_kpi(self, ssh, _):
222 vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0]
223 router_vnf = RouterVNF(name, vnfd)
224 router_vnf.ssh_helper = m
225 result = {'packets_dropped': 0, 'packets_fwd': 0, 'packets_in': 0, 'link_stats': {}}
226 self.assertEqual(result, router_vnf.collect_kpi())
228 @mock.patch(SSH_HELPER)
229 def test_run_router(self, ssh):
232 vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0]
233 router_vnf = RouterVNF(name, vnfd)
234 router_vnf.scenario_helper.scenario_cfg = self.scenario_cfg
236 router_vnf.ssh_helper.drop_connection.assert_called_once()
238 @mock.patch("yardstick.network_services.vnf_generic.vnf.router_vnf.Context")
239 @mock.patch(SSH_HELPER)
240 def test_instantiate(self, ssh, _):
243 vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0]
244 router_vnf = RouterVNF(name, vnfd)
245 router_vnf.WAIT_TIME = 0
246 router_vnf.INTERFACE_WAIT = 0
247 self.scenario_cfg.update({"nodes": {"vnf__1": ""}})
248 self.assertIsNone(router_vnf.instantiate(self.scenario_cfg,
251 @mock.patch("yardstick.network_services.vnf_generic.vnf.sample_vnf.time")
252 @mock.patch(SSH_HELPER)
253 def test_terminate(self, ssh, _):
256 vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0]
257 router_vnf = RouterVNF(name, vnfd)
258 router_vnf._vnf_process = mock.MagicMock()
259 router_vnf._vnf_process.terminate = mock.Mock()
260 self.assertIsNone(router_vnf.terminate())