Merge "Adding Test Cases for Prox PktTouch Standalone SRIOV"
[yardstick.git] / yardstick / tests / unit / network_services / vnf_generic / vnf / test_router_vnf.py
1 # Copyright (c) 2016-2017 Intel Corporation
2 #
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
6 #
7 #      http://www.apache.org/licenses/LICENSE-2.0
8 #
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.
14
15 import unittest
16 import mock
17
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
21
22
23 TEST_FILE_YAML = 'nsb_test_case.yaml'
24 SSH_HELPER = 'yardstick.network_services.vnf_generic.vnf.sample_vnf.VnfSshHelper'
25
26
27 name = 'vnf__1'
28
29
30 class TestRouterVNF(unittest.TestCase):
31     VNFD = {'vnfd:vnfd-catalog':
32             {'vnfd':
33              [{'short-name': 'RouterVNF',
34                'vdu':
35                [{'routing_table': [],
36                  'description': 'RouterVNF',
37                  'name': 'router-baremetal',
38                  'nd_route_tbl': [],
39                  'id': 'router-baremetal',
40                  'external-interface':
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',
47                     'dpdk_port_num': 0,
48                     'bandwidth': '10 Gbps',
49                     'driver': "i40e",
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',
54                    'name': 'xe0'},
55                   {'virtual-interface':
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',
60                     'driver': "i40e",
61                     'netmask': '255.255.255.0',
62                     'dpdk_port_num': 1,
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',
68                    'name': 'xe1'}]}],
69                'description': 'RouterVNF',
70                'mgmt-interface':
71                    {'vdu-id': 'router-baremetal',
72                     'host': '1.2.1.1',
73                     'password': 'r00t',
74                     'user': 'root',
75                     'ip': '1.2.1.1'},
76                'benchmark':
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'}]}}
81
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},
94                                 'traffic_type': 4,
95                                 'vnf__0': {'nfvi_enable': True}},
96                     'runner': {'interval': 35,
97                                'iterations': 10,
98                                'type': 'Iteration'},
99                     'topology': 'router-tg-topology.yaml',
100                     'traffic_profile': '../../traffic_profiles/ipv4_throughput.yaml',
101                     'type': 'NSPerf'}
102
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',
108                               'ip': '1.2.1.1',
109                               'interfaces':
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',
117                                        'driver': 'i40e',
118                                        'vpci': '0000:05:00.0',
119                                        'dpdk_port_num': 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',
124                                        'driver': 'i40e',
125                                        'vpci': '0000:05:00.1',
126                                        'dpdk_port_num': 1}},
127                               'password': 'r00t',
128                               'VNF model': 'tg_rfc2544_tpl.yaml',
129                               'user': 'root'},
130                              'vnf__1':
131                              {'name': 'vnf.yardstick',
132                               'vnfd-id-ref': 'vnf__1',
133                               'ip': '1.2.1.1',
134                               'interfaces':
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',
142                                        'driver': 'i40e',
143                                        'vpci': '0000:05:00.0',
144                                        'dpdk_port_num': 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',
152                                        'driver': 'i40e',
153                                        'vpci': '0000:05:00.1',
154                                        'dpdk_port_num': 1}},
155                               'routing_table': [],
156                               'member-vnf-index': '2',
157                               'host': '1.2.1.1',
158                               'role': 'vnf',
159                               'user': 'root',
160                               'nd_route_tbl': [],
161                               'password': 'r00t',
162                               'VNF model': 'router_vnf.yaml'}}}
163
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
170                0        0       0       0       0
171     TX: bytes  packets  errors  dropped carrier collsns
172     646221183  2145799  0       0       0       0
173     TX errors: aborted fifo    window  heartbeat
174                0        0       0       0
175 """
176     STATS = {
177         'RX:bytes': '2781945429',
178         'RX:dropped': '0',
179         'RX:errors': '0',
180         'RX:mcast': '30131',
181         'RX:overrun': '0',
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',
189         'TX:carrier': '0',
190         'TX:collsns': '0',
191         'TX:dropped': '0',
192         'TX:errors': '0',
193         'TX:packets': '2145799',
194         'TX errors:aborted': '0',
195         'TX errors:fifo': '0',
196         'TX errors:window': '0',
197         'TX errors:heartbeat': '0',
198     }
199
200     def test___init__(self):
201         vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0]
202         router_vnf = RouterVNF(name, vnfd, 'task_id')
203         self.assertIsNone(router_vnf._vnf_process)
204
205     def test_get_stats(self):
206         stats = RouterVNF.get_stats(self.IP_SHOW_STATS_OUTPUT)
207         self.assertDictEqual(stats, self.STATS)
208
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):
213         m = mock_ssh(ssh)
214
215         vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0]
216         router_vnf = RouterVNF(name, vnfd, 'task_id')
217         router_vnf.scenario_helper.scenario_cfg = {
218             'nodes': {router_vnf.name: "mock"}
219         }
220         router_vnf.ssh_helper = m
221         result = {
222             'physical_node': 'mock_node',
223             'packets_dropped': 0,
224             'packets_fwd': 0,
225             'packets_in': 0,
226             'link_stats': {}
227         }
228         self.assertEqual(result, router_vnf.collect_kpi())
229
230     @mock.patch(SSH_HELPER)
231     def test_run_router(self, ssh):
232         mock_ssh(ssh)
233
234         vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0]
235         router_vnf = RouterVNF(name, vnfd, 'task_id')
236         router_vnf.scenario_helper.scenario_cfg = self.scenario_cfg
237         router_vnf._run()
238         router_vnf.ssh_helper.drop_connection.assert_called_once()
239
240     @mock.patch.object(ctx_base, 'Context')
241     @mock.patch(SSH_HELPER)
242     def test_instantiate(self, ssh, *args):
243         mock_ssh(ssh)
244
245         vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0]
246         router_vnf = RouterVNF(name, vnfd, 'task_id')
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,
251                                                  self.context_cfg))
252
253     @mock.patch("yardstick.network_services.vnf_generic.vnf.sample_vnf.time")
254     @mock.patch(SSH_HELPER)
255     def test_terminate(self, ssh, _):
256         mock_ssh(ssh)
257
258         vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0]
259         router_vnf = RouterVNF(name, vnfd, 'task_id')
260         router_vnf._vnf_process = mock.MagicMock()
261         router_vnf._vnf_process.terminate = mock.Mock()
262         self.assertIsNone(router_vnf.terminate())