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.
16 from __future__ import absolute_import
21 from tests.unit import STL_MOCKS
22 from tests.unit.network_services.vnf_generic.vnf.test_base import mock_ssh
25 STLClient = mock.MagicMock()
26 stl_patch = mock.patch.dict("sys.modules", STL_MOCKS)
30 from yardstick.network_services.vnf_generic.vnf.router_vnf import RouterVNF
33 TEST_FILE_YAML = 'nsb_test_case.yaml'
34 SSH_HELPER = 'yardstick.network_services.vnf_generic.vnf.sample_vnf.VnfSshHelper'
40 class TestRouterVNF(unittest.TestCase):
41 VNFD = {'vnfd:vnfd-catalog':
43 [{'short-name': 'RouterVNF',
45 [{'routing_table': [],
46 'description': 'RouterVNF',
47 'name': 'router-baremetal',
49 'id': 'router-baremetal',
51 [{'virtual-interface':
52 {'dst_mac': '00:00:00:00:00:04',
53 'vpci': '0000:05:00.0',
54 'local_ip': '152.16.100.19',
55 'type': 'PCI-PASSTHROUGH',
56 'netmask': '255.255.255.0',
58 'bandwidth': '10 Gbps',
60 'dst_ip': '152.16.100.20',
61 'local_iface_name': 'xe0',
62 'local_mac': '00:00:00:00:00:02'},
63 'vnfd-connection-point-ref': 'xe0',
66 {'dst_mac': '00:00:00:00:00:03',
67 'vpci': '0000:05:00.1',
68 'local_ip': '152.16.40.19',
69 'type': 'PCI-PASSTHROUGH',
71 'netmask': '255.255.255.0',
73 'bandwidth': '10 Gbps',
74 'dst_ip': '152.16.40.20',
75 'local_iface_name': 'xe1',
76 'local_mac': '00:00:00:00:00:01'},
77 'vnfd-connection-point-ref': 'xe1',
79 'description': 'RouterVNF',
81 {'vdu-id': 'router-baremetal',
87 {'kpi': ['packets_in', 'packets_fwd', 'packets_dropped']},
88 'connection-point': [{'type': 'VPORT', 'name': 'xe0'},
89 {'type': 'VPORT', 'name': 'xe1'}],
90 'id': 'RouterVNF', 'name': 'VPEVnfSsh'}]}}
92 scenario_cfg = {'nodes': {'cpt__0': 'compute_0.compute_nodes',
93 'tg__0': 'trafficgen_1.baremetal',
94 'vnf__0': 'vnf.yardstick'},
95 'options': {'flow': {'count': 128000,
96 'dst_ip': ['10.0.3.26-10.0.3.105'],
97 'dst_port': ['2001-2004'],
98 'src_ip': ['10.0.2.26-10.0.2.105'],
99 'src_port': ['1234-1238']},
100 'framesize': {'downlink': {'1024B': 100},
101 'uplink': {'1024B': 100}},
102 'rfc2544': {'allowed_drop_rate': '0.0001 - 0.1'},
103 'tg__0': {'queues_per_port': 7},
105 'vnf__0': {'nfvi_enable': True}},
106 'runner': {'interval': 35,
108 'type': 'Iteration'},
109 'topology': 'router-tg-topology.yaml',
110 'traffic_profile': '../../traffic_profiles/ipv4_throughput.yaml',
113 context_cfg = {'nodes': {'tg__1':
114 {'member-vnf-index': '1',
115 'role': 'TrafficGen',
116 'name': 'trafficgen_1.yardstick',
117 'vnfd-id-ref': 'tg__1',
120 {'xe0': {'local_iface_name': 'ens785f0',
121 'vld_id': RouterVNF.UPLINK,
122 'netmask': '255.255.255.0',
123 'local_ip': '152.16.100.20',
124 'dst_mac': '00:00:00:00:00:02',
125 'local_mac': '00:00:00:00:00:04',
126 'dst_ip': '152.16.100.19',
128 'vpci': '0000:05:00.0',
130 'xe1': {'local_iface_name': 'ens785f1',
131 'netmask': '255.255.255.0',
132 'local_ip': '152.16.100.21',
133 'local_mac': '00:00:00:00:00:01',
135 'vpci': '0000:05:00.1',
136 'dpdk_port_num': 1}},
138 'VNF model': 'tg_rfc2544_tpl.yaml',
141 {'name': 'vnf.yardstick',
142 'vnfd-id-ref': 'vnf__1',
145 {'xe0': {'local_iface_name': 'ens786f0',
146 'vld_id': RouterVNF.UPLINK,
147 'netmask': '255.255.255.0',
148 'local_ip': '152.16.100.19',
149 'dst_mac': '00:00:00:00:00:04',
150 'local_mac': '00:00:00:00:00:02',
151 'dst_ip': '152.16.100.20',
153 'vpci': '0000:05:00.0',
155 'xe1': {'local_iface_name': 'ens786f1',
156 'vld_id': RouterVNF.DOWNLINK,
157 'netmask': '255.255.255.0',
158 'local_ip': '152.16.40.19',
159 'dst_mac': '00:00:00:00:00:03',
160 'local_mac': '00:00:00:00:00:01',
161 'dst_ip': '152.16.40.20',
163 'vpci': '0000:05:00.1',
164 'dpdk_port_num': 1}},
166 'member-vnf-index': '2',
172 'VNF model': 'router_vnf.yaml'}}}
174 IP_SHOW_STATS_OUTPUT = """\
175 2: em1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP mode DEFAULT group default qlen 1000
176 link/ether d4:c9:ef:52:7c:4d brd ff:ff:ff:ff:ff:ff
177 RX: bytes packets errors dropped overrun mcast
178 2781945429 3202213 0 0 0 30131
179 RX errors: length crc frame fifo missed
181 TX: bytes packets errors dropped carrier collsns
182 646221183 2145799 0 0 0 0
183 TX errors: aborted fifo window heartbeat
187 'RX:bytes': '2781945429',
192 'RX:packets': '3202213',
193 'RX errors:length': '0',
194 'RX errors:crc': '0',
195 'RX errors:frame': '0',
196 'RX errors:fifo': '0',
197 'RX errors:missed': '0',
198 'TX:bytes': '646221183',
203 'TX:packets': '2145799',
204 'TX errors:aborted': '0',
205 'TX errors:fifo': '0',
206 'TX errors:window': '0',
207 'TX errors:heartbeat': '0',
210 def test___init__(self):
211 vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0]
212 router_vnf = RouterVNF(name, vnfd)
213 self.assertIsNone(router_vnf._vnf_process)
215 def test_get_stats(self):
216 stats = RouterVNF.get_stats(self.IP_SHOW_STATS_OUTPUT)
217 self.assertDictEqual(stats, self.STATS)
219 @mock.patch("yardstick.network_services.vnf_generic.vnf.sample_vnf.time")
220 @mock.patch(SSH_HELPER)
221 def test_collect_kpi(self, ssh, _):
224 vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0]
225 router_vnf = RouterVNF(name, vnfd)
226 router_vnf.ssh_helper = m
227 result = {'packets_dropped': 0, 'packets_fwd': 0, 'packets_in': 0, 'link_stats': {}}
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("yardstick.network_services.vnf_generic.vnf.router_vnf.Context")
241 @mock.patch(SSH_HELPER)
242 def test_instantiate(self, ssh, _):
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())