3 # Copyright (c) 2016-2017 Intel Corporation
5 # Licensed under the Apache License, Version 2.0 (the "License");
6 # you may not use this file except in compliance with the License.
7 # You may obtain a copy of the License at
9 # http://www.apache.org/licenses/LICENSE-2.0
11 # Unless required by applicable law or agreed to in writing, software
12 # distributed under the License is distributed on an "AS IS" BASIS,
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 # See the License for the specific language governing permissions and
15 # limitations under the License.
18 from __future__ import absolute_import
23 from tests.unit import STL_MOCKS
24 from tests.unit.network_services.vnf_generic.vnf.test_base import mock_ssh
27 STLClient = mock.MagicMock()
28 stl_patch = mock.patch.dict("sys.modules", STL_MOCKS)
32 from yardstick.network_services.vnf_generic.vnf.router_vnf import RouterVNF
35 TEST_FILE_YAML = 'nsb_test_case.yaml'
36 SSH_HELPER = 'yardstick.network_services.vnf_generic.vnf.sample_vnf.VnfSshHelper'
42 class TestRouterVNF(unittest.TestCase):
43 VNFD = {'vnfd:vnfd-catalog':
45 [{'short-name': 'RouterVNF',
47 [{'routing_table': [],
48 'description': 'RouterVNF',
49 'name': 'router-baremetal',
51 'id': 'router-baremetal',
53 [{'virtual-interface':
54 {'dst_mac': '00:00:00:00:00:04',
55 'vpci': '0000:05:00.0',
56 'local_ip': '152.16.100.19',
57 'type': 'PCI-PASSTHROUGH',
58 'netmask': '255.255.255.0',
60 'bandwidth': '10 Gbps',
62 'dst_ip': '152.16.100.20',
63 'local_iface_name': 'xe0',
64 'local_mac': '00:00:00:00:00:02'},
65 'vnfd-connection-point-ref': 'xe0',
68 {'dst_mac': '00:00:00:00:00:03',
69 'vpci': '0000:05:00.1',
70 'local_ip': '152.16.40.19',
71 'type': 'PCI-PASSTHROUGH',
73 'netmask': '255.255.255.0',
75 'bandwidth': '10 Gbps',
76 'dst_ip': '152.16.40.20',
77 'local_iface_name': 'xe1',
78 'local_mac': '00:00:00:00:00:01'},
79 'vnfd-connection-point-ref': 'xe1',
81 'description': 'RouterVNF',
83 {'vdu-id': 'router-baremetal',
89 {'kpi': ['packets_in', 'packets_fwd', 'packets_dropped']},
90 'connection-point': [{'type': 'VPORT', 'name': 'xe0'},
91 {'type': 'VPORT', 'name': 'xe1'}],
92 'id': 'RouterVNF', 'name': 'VPEVnfSsh'}]}}
94 scenario_cfg = {'nodes': {'cpt__0': 'compute_0.compute_nodes',
95 'tg__0': 'trafficgen_1.baremetal',
96 'vnf__0': 'vnf.yardstick'},
97 'options': {'flow': {'count': 128000,
98 'dst_ip': ['10.0.3.26-10.0.3.105'],
99 'dst_port': ['2001-2004'],
100 'src_ip': ['10.0.2.26-10.0.2.105'],
101 'src_port': ['1234-1238']},
102 'framesize': {'downlink': {'1024B': 100},
103 'uplink': {'1024B': 100}},
104 'rfc2544': {'allowed_drop_rate': '0.0001 - 0.1'},
105 'tg__0': {'queues_per_port': 7},
107 'vnf__0': {'nfvi_enable': True}},
108 'runner': {'interval': 35,
110 'type': 'Iteration'},
111 'topology': 'router-tg-topology.yaml',
112 'traffic_profile': '../../traffic_profiles/ipv4_throughput.yaml',
115 context_cfg = {'nodes': {'tg__1':
116 {'member-vnf-index': '1',
117 'role': 'TrafficGen',
118 'name': 'trafficgen_1.yardstick',
119 'vnfd-id-ref': 'tg__1',
122 {'xe0': {'local_iface_name': 'ens785f0',
123 'vld_id': RouterVNF.UPLINK,
124 'netmask': '255.255.255.0',
125 'local_ip': '152.16.100.20',
126 'dst_mac': '00:00:00:00:00:02',
127 'local_mac': '00:00:00:00:00:04',
128 'dst_ip': '152.16.100.19',
130 'vpci': '0000:05:00.0',
132 'xe1': {'local_iface_name': 'ens785f1',
133 'netmask': '255.255.255.0',
134 'local_ip': '152.16.100.21',
135 'local_mac': '00:00:00:00:00:01',
137 'vpci': '0000:05:00.1',
138 'dpdk_port_num': 1}},
140 'VNF model': 'tg_rfc2544_tpl.yaml',
143 {'name': 'vnf.yardstick',
144 'vnfd-id-ref': 'vnf__1',
147 {'xe0': {'local_iface_name': 'ens786f0',
148 'vld_id': RouterVNF.UPLINK,
149 'netmask': '255.255.255.0',
150 'local_ip': '152.16.100.19',
151 'dst_mac': '00:00:00:00:00:04',
152 'local_mac': '00:00:00:00:00:02',
153 'dst_ip': '152.16.100.20',
155 'vpci': '0000:05:00.0',
157 'xe1': {'local_iface_name': 'ens786f1',
158 'vld_id': RouterVNF.DOWNLINK,
159 'netmask': '255.255.255.0',
160 'local_ip': '152.16.40.19',
161 'dst_mac': '00:00:00:00:00:03',
162 'local_mac': '00:00:00:00:00:01',
163 'dst_ip': '152.16.40.20',
165 'vpci': '0000:05:00.1',
166 'dpdk_port_num': 1}},
168 'member-vnf-index': '2',
174 'VNF model': 'router_vnf.yaml'}}}
176 IP_SHOW_STATS_OUTPUT = """\
177 2: em1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP mode DEFAULT group default qlen 1000
178 link/ether d4:c9:ef:52:7c:4d brd ff:ff:ff:ff:ff:ff
179 RX: bytes packets errors dropped overrun mcast
180 2781945429 3202213 0 0 0 30131
181 RX errors: length crc frame fifo missed
183 TX: bytes packets errors dropped carrier collsns
184 646221183 2145799 0 0 0 0
185 TX errors: aborted fifo window heartbeat
189 'RX:bytes': '2781945429',
194 'RX:packets': '3202213',
195 'RX errors:length': '0',
196 'RX errors:crc': '0',
197 'RX errors:frame': '0',
198 'RX errors:fifo': '0',
199 'RX errors:missed': '0',
200 'TX:bytes': '646221183',
205 'TX:packets': '2145799',
206 'TX errors:aborted': '0',
207 'TX errors:fifo': '0',
208 'TX errors:window': '0',
209 'TX errors:heartbeat': '0',
212 def test___init__(self):
213 vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0]
214 router_vnf = RouterVNF(name, vnfd)
215 self.assertIsNone(router_vnf._vnf_process)
217 def test_get_stats(self):
218 stats = RouterVNF.get_stats(self.IP_SHOW_STATS_OUTPUT)
219 self.assertDictEqual(stats, self.STATS)
221 @mock.patch("yardstick.network_services.vnf_generic.vnf.sample_vnf.time")
222 @mock.patch(SSH_HELPER)
223 def test_collect_kpi(self, ssh, _):
226 vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0]
227 router_vnf = RouterVNF(name, vnfd)
228 router_vnf.ssh_helper = m
229 result = {'packets_dropped': 0, 'packets_fwd': 0, 'packets_in': 0, 'link_stats': {}}
230 self.assertEqual(result, router_vnf.collect_kpi())
232 @mock.patch(SSH_HELPER)
233 def test_run_router(self, ssh):
236 vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0]
237 router_vnf = RouterVNF(name, vnfd)
238 router_vnf.scenario_helper.scenario_cfg = self.scenario_cfg
240 router_vnf.ssh_helper.drop_connection.assert_called_once()
242 @mock.patch("yardstick.network_services.vnf_generic.vnf.router_vnf.Context")
243 @mock.patch(SSH_HELPER)
244 def test_instantiate(self, ssh, _):
247 vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0]
248 router_vnf = RouterVNF(name, vnfd)
249 router_vnf.WAIT_TIME = 0
250 router_vnf.INTERFACE_WAIT = 0
251 self.scenario_cfg.update({"nodes": {"vnf__1": ""}})
252 self.assertIsNone(router_vnf.instantiate(self.scenario_cfg,
255 @mock.patch("yardstick.network_services.vnf_generic.vnf.sample_vnf.time")
256 @mock.patch(SSH_HELPER)
257 def test_terminate(self, ssh, _):
260 vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0]
261 router_vnf = RouterVNF(name, vnfd)
262 router_vnf._vnf_process = mock.MagicMock()
263 router_vnf._vnf_process.terminate = mock.Mock()
264 self.assertEqual(None, router_vnf.terminate())
266 if __name__ == '__main__':