Merge "Added test descriptors for vCMTS testcase"
[yardstick.git] / yardstick / tests / unit / network_services / vnf_generic / vnf / test_ipsec_vnf.py
1 # Copyright (c) 2019 Viosoft 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 from multiprocessing import Process
17
18 import mock
19
20 from yardstick.benchmark.contexts import base as ctx_base
21 from yardstick.common import utils
22 from yardstick.network_services.nfvi.resource import ResourceProfile
23 from yardstick.network_services.vnf_generic.vnf import ipsec_vnf
24 from yardstick.network_services.vnf_generic.vnf.base import VnfdHelper
25 from yardstick.network_services.vnf_generic.vnf.ipsec_vnf import \
26     VipsecApproxSetupEnvHelper
27 from yardstick.tests.unit.network_services.vnf_generic.vnf.test_base import \
28     mock_ssh
29
30 SSH_HELPER = 'yardstick.network_services.vnf_generic.vnf.sample_vnf.VnfSshHelper'
31
32 NAME = 'vnf__1'
33
34
35 @mock.patch("yardstick.network_services.vnf_generic.vnf.sample_vnf.Process")
36 class TestVipsecApproxVnf(unittest.TestCase):
37     VNFD = {'vnfd:vnfd-catalog':
38         {'vnfd':
39             [{
40                 "benchmark": {
41                     "kpi": [
42                         "packets_in",
43                         "packets_fwd",
44                         "packets_dropped"
45                     ]
46                 },
47                 "connection-point": [
48                     {
49                         "name": "xe0",
50                         "type": "VPORT"
51                     },
52                     {
53                         "name": "xe1",
54                         "type": "VPORT"
55                     }
56                 ],
57                 "description": "VPP IPsec",
58                 "id": "VipsecApproxVnf",
59                 "mgmt-interface": {
60                     "ip": "10.10.10.101",
61                     "password": "r00t",
62                     "user": "root",
63                     "vdu-id": "ipsecvnf-baremetal"
64                 },
65                 "name": "IpsecVnf",
66                 "short-name": "IpsecVnf",
67                 "vdu": [
68                     {
69                         "description": "VPP Ipsec",
70                         "external-interface": [
71                             {
72                                 "name": "xe0",
73                                 "virtual-interface": {
74                                     "dpdk_port_num": 0,
75                                     "driver": "igb_uio",
76                                     "dst_ip": "192.168.100.1",
77                                     "dst_mac": "90:e2:ba:7c:30:e8",
78                                     "ifname": "xe0",
79                                     "local_ip": "192.168.100.2",
80                                     "local_mac": "90:e2:ba:7c:41:a8",
81                                     "netmask": "255.255.255.0",
82                                     "network": {},
83                                     "node_name": "vnf__0",
84                                     "peer_ifname": "xe0",
85                                     "peer_intf": {
86                                         "dpdk_port_num": 0,
87                                         "driver": "igb_uio",
88                                         "dst_ip": "192.168.100.2",
89                                         "dst_mac": "90:e2:ba:7c:41:a8",
90                                         "ifname": "xe0",
91                                         "local_ip": "192.168.100.1",
92                                         "local_mac": "90:e2:ba:7c:30:e8",
93                                         "netmask": "255.255.255.0",
94                                         "network": {},
95                                         "node_name": "tg__0",
96                                         "peer_ifname": "xe0",
97                                         "peer_name": "vnf__0",
98                                         "vld_id": "uplink_0",
99                                         "vpci": "0000:81:00.0"
100                                     },
101                                     "peer_name": "tg__0",
102                                     "vld_id": "uplink_0",
103                                     "vpci": "0000:ff:06.0"
104                                 },
105                                 "vnfd-connection-point-ref": "xe0"
106                             },
107                             {
108                                 "name": "xe1",
109                                 "virtual-interface": {
110                                     "dpdk_port_num": 1,
111                                     "driver": "igb_uio",
112                                     "dst_ip": "1.1.1.2",
113                                     "dst_mac": "0a:b1:ec:fd:a2:66",
114                                     "ifname": "xe1",
115                                     "local_ip": "1.1.1.1",
116                                     "local_mac": "4e:90:85:d3:c5:13",
117                                     "netmask": "255.255.255.0",
118                                     "network": {},
119                                     "node_name": "vnf__0",
120                                     "peer_ifname": "xe1",
121                                     "peer_intf": {
122                                         "driver": "igb_uio",
123                                         "dst_ip": "1.1.1.1",
124                                         "dst_mac": "4e:90:85:d3:c5:13",
125                                         "ifname": "xe1",
126                                         "local_ip": "1.1.1.2",
127                                         "local_mac": "0a:b1:ec:fd:a2:66",
128                                         "netmask": "255.255.255.0",
129                                         "network": {},
130                                         "node_name": "vnf__1",
131                                         "peer_ifname": "xe1",
132                                         "peer_name": "vnf__0",
133                                         "vld_id": "ciphertext",
134                                         "vpci": "0000:00:07.0"
135                                     },
136                                     "peer_name": "vnf__1",
137                                     "vld_id": "ciphertext",
138                                     "vpci": "0000:ff:07.0"
139                                 },
140                                 "vnfd-connection-point-ref": "xe1"
141                             }
142                         ],
143                         "id": "ipsecvnf-baremetal",
144                         "name": "ipsecvnf-baremetal",
145                         "routing_table": []
146                     }
147                 ]
148             }
149             ]}}
150
151     VNFD_ERROR = {'vnfd:vnfd-catalog':
152         {'vnfd':
153             [{
154                 "benchmark": {
155                     "kpi": [
156                         "packets_in",
157                         "packets_fwd",
158                         "packets_dropped"
159                     ]
160                 },
161                 "connection-point": [
162                     {
163                         "name": "xe0",
164                         "type": "VPORT"
165                     },
166                     {
167                         "name": "xe1",
168                         "type": "VPORT"
169                     }
170                 ],
171                 "description": "VPP IPsec",
172                 "id": "VipsecApproxVnf",
173                 "mgmt-interface": {
174                     "ip": "10.10.10.101",
175                     "password": "r00t",
176                     "user": "root",
177                     "vdu-id": "ipsecvnf-baremetal"
178                 },
179                 "name": "IpsecVnf",
180                 "short-name": "IpsecVnf",
181                 "vdu": [
182                     {
183                         "description": "VPP Ipsec",
184                         "external-interface": [
185                             {
186                                 "name": "xe0",
187                                 "virtual-interface": {
188                                     "dpdk_port_num": 0,
189                                     "driver": "igb_uio",
190                                     "dst_ip": "192.168.100.1",
191                                     "dst_mac": "90:e2:ba:7c:30:e8",
192                                     "ifname": "xe0",
193                                     "local_ip": "192.168.100.2",
194                                     "local_mac": "90:e2:ba:7c:41:a8",
195                                     "netmask": "255.255.255.0",
196                                     "network": {},
197                                     "node_name": "vnf__0",
198                                     "peer_ifname": "xe0",
199                                     "peer_intf": {
200                                         "dpdk_port_num": 0,
201                                         "driver": "igb_uio",
202                                         "dst_ip": "192.168.100.2",
203                                         "dst_mac": "90:e2:ba:7c:41:a8",
204                                         "ifname": "xe0",
205                                         "local_ip": "192.168.100.1",
206                                         "local_mac": "90:e2:ba:7c:30:e8",
207                                         "netmask": "255.255.255.0",
208                                         "network": {},
209                                         "node_name": "tg__0",
210                                         "peer_ifname": "xe0",
211                                         "peer_name": "vnf__0",
212                                         "vld_id": "uplink_0",
213                                         "vpci": "0000:81:00.0"
214                                     },
215                                     "peer_name": "tg__0",
216                                     "vld_id": "uplink_1",
217                                     "vpci": "0000:ff:06.0"
218                                 },
219                                 "vnfd-connection-point-ref": "xe0"
220                             },
221                             {
222                                 "name": "xe1",
223                                 "virtual-interface": {
224                                     "dpdk_port_num": 1,
225                                     "driver": "igb_uio",
226                                     "dst_ip": "1.1.1.2",
227                                     "dst_mac": "0a:b1:ec:fd:a2:66",
228                                     "ifname": "xe1",
229                                     "local_ip": "1.1.1.1",
230                                     "local_mac": "4e:90:85:d3:c5:13",
231                                     "netmask": "255.255.255.0",
232                                     "network": {},
233                                     "node_name": "vnf__1",
234                                     "peer_ifname": "xe1",
235                                     "peer_intf": {
236                                         "driver": "igb_uio",
237                                         "dst_ip": "1.1.1.1",
238                                         "dst_mac": "4e:90:85:d3:c5:13",
239                                         "ifname": "xe1",
240                                         "local_ip": "1.1.1.2",
241                                         "local_mac": "0a:b1:ec:fd:a2:66",
242                                         "netmask": "255.255.255.0",
243                                         "network": {},
244                                         "node_name": "vnf__1",
245                                         "peer_ifname": "xe1",
246                                         "peer_name": "vnf__0",
247                                         "vld_id": "ciphertext",
248                                         "vpci": "0000:00:07.0"
249                                     },
250                                     "peer_name": "vnf__1",
251                                     "vld_id": "ciphertext",
252                                     "vpci": "0000:ff:07.0"
253                                 },
254                                 "vnfd-connection-point-ref": "xe1"
255                             }
256                         ],
257                         "id": "ipsecvnf-baremetal",
258                         "name": "ipsecvnf-baremetal",
259                         "routing_table": []
260                     }
261                 ]
262             }
263             ]}}
264
265     scenario_cfg = {
266         "nodes": {
267             "tg__0": "trafficgen.yardstick-5486cc2f",
268             "vnf__0": "vnf0.yardstick-5486cc2f",
269             "vnf__1": "vnf1.yardstick-5486cc2f"
270         },
271         "options": {
272             "flow": {
273                 "count": 1,
274                 "dst_ip": [
275                     "20.0.0.0-20.0.0.100"
276                 ],
277                 "src_ip": [
278                     "10.0.0.0-10.0.0.100"
279                 ]
280             },
281             "framesize": {
282                 "downlink": {
283                     "64B": 100
284                 },
285                 "uplink": {
286                     "64B": 100
287                 }
288             },
289             "rfc2544": {
290                 "allowed_drop_rate": "0.0 - 0.005"
291             },
292             "tg__0": {
293                 "collectd": {
294                     "interval": 1
295                 },
296                 "queues_per_port": 7
297             },
298             "traffic_type": 4,
299             "vnf__0": {
300                 "collectd": {
301                     "interval": 1
302                 },
303                 "vnf_config": {
304                     "crypto_type": "SW_cryptodev",
305                     "rxq": 1,
306                     "worker_config": "1C/1T",
307                     "worker_threads": 4
308                 }
309             },
310             "vnf__1": {
311                 "collectd": {
312                     "interval": 1
313                 },
314                 "vnf_config": {
315                     "crypto_type": "SW_cryptodev",
316                     "rxq": 1,
317                     "worker_config": "1C/1T",
318                     "worker_threads": 4
319                 }
320             },
321             "vpp_config": {
322                 "crypto_algorithms": "aes-gcm",
323                 "tunnel": 1
324             }
325         },
326         "runner": {
327             "duration": 500,
328             "interval": 10,
329             "object":
330                 "yardstick.benchmark.scenarios.networking.vnf_generic.NetworkServiceTestCase",
331             "output_config": {
332                 "DEFAULT": {
333                     "debug": "False",
334                     "dispatcher": [
335                         "influxdb"
336                     ]
337                 },
338                 "dispatcher_file": {
339                     "debug": "False",
340                     "dispatcher": "influxdb",
341                     "file_path": "/tmp/yardstick.out"
342                 },
343                 "dispatcher_http": {
344                     "debug": "False",
345                     "dispatcher": "influxdb",
346                     "target": "http://127.0.0.1:8000/results",
347                     "timeout": "20"
348                 },
349                 "dispatcher_influxdb": {
350                     "db_name": "yardstick",
351                     "debug": "False",
352                     "dispatcher": "influxdb",
353                     "password": "r00t",
354                     "target": "http://192.168.100.3:8086",
355                     "timeout": "20",
356                     "username": "root"
357                 },
358                 "nsb": {
359                     "bin_path": "/opt/nsb_bin",
360                     "debug": "False",
361                     "dispatcher": "influxdb",
362                     "trex_client_lib": "/opt/nsb_bin/trex_client/stl",
363                     "trex_path": "/opt/nsb_bin/trex/scripts"
364                 }
365             },
366             "runner_id": 1105,
367             "type": "Duration"
368         },
369         "task_id": "5486cc2f-d4d3-4feb-b0df-5e0bcd584c9e",
370         "task_path": "samples/vnf_samples/nsut/ipsec",
371         "tc": "tc_baremetal_rfc2544_ipv4_1flow_sw_aesgcm_4cores_64B_trex",
372         "topology": "vpp-tg-topology-2.yaml",
373         "traffic_profile": "../../traffic_profiles/ipv4_throughput_latency_vpp.yaml",
374         "type": "NSPerf"
375     }
376
377     context_cfg = {
378         "networks": {},
379         "nodes": {
380             "tg__0": {
381                 "VNF model": "../../vnf_descriptors/tg_vpp_tpl.yaml",
382                 "ctx_type": "Node",
383                 "interfaces": {
384                     "xe0": {
385                         "dpdk_port_num": 0,
386                         "driver": "igb_uio",
387                         "dst_ip": "192.168.100.2",
388                         "dst_mac": "90:e2:ba:7c:41:a8",
389                         "ifname": "xe0",
390                         "local_ip": "192.168.100.1",
391                         "local_mac": "90:e2:ba:7c:30:e8",
392                         "netmask": "255.255.255.0",
393                         "network": {},
394                         "node_name": "tg__0",
395                         "peer_ifname": "xe0",
396                         "peer_intf": {
397                             "dpdk_port_num": 0,
398                             "driver": "igb_uio",
399                             "dst_ip": "192.168.100.1",
400                             "dst_mac": "90:e2:ba:7c:30:e8",
401                             "ifname": "xe0",
402                             "local_ip": "192.168.100.2",
403                             "local_mac": "90:e2:ba:7c:41:a8",
404                             "netmask": "255.255.255.0",
405                             "network": {},
406                             "node_name": "vnf__0",
407                             "peer_ifname": "xe0",
408                             "peer_name": "tg__0",
409                             "vld_id": "uplink_0",
410                             "vpci": "0000:00:06.0"
411                         },
412                         "peer_name": "vnf__0",
413                         "vld_id": "uplink_0",
414                         "vpci": "0000:81:00.0"
415                     },
416                     "xe1": {
417                         "dpdk_port_num": 1,
418                         "driver": "igb_uio",
419                         "dst_ip": "192.168.101.2",
420                         "dst_mac": "90:e2:ba:7c:41:a9",
421                         "ifname": "xe1",
422                         "local_ip": "192.168.101.1",
423                         "local_mac": "90:e2:ba:7c:30:e9",
424                         "netmask": "255.255.255.0",
425                         "network": {},
426                         "node_name": "tg__0",
427                         "peer_ifname": "xe0",
428                         "peer_intf": {
429                             "dpdk_port_num": 1,
430                             "driver": "igb_uio",
431                             "dst_ip": "192.168.101.1",
432                             "dst_mac": "90:e2:ba:7c:30:e9",
433                             "ifname": "xe0",
434                             "local_ip": "192.168.101.2",
435                             "local_mac": "90:e2:ba:7c:41:a9",
436                             "netmask": "255.255.255.0",
437                             "network": {},
438                             "node_name": "vnf__1",
439                             "peer_ifname": "xe1",
440                             "peer_name": "tg__0",
441                             "vld_id": "downlink_0",
442                             "vpci": "0000:00:06.0"
443                         },
444                         "peer_name": "vnf__1",
445                         "vld_id": "downlink_0",
446                         "vpci": "0000:81:00.1"
447                     }
448                 },
449                 "ip": "10.10.10.10",
450                 "member-vnf-index": "1",
451                 "name": "trafficgen.yardstick-5486cc2f",
452                 "password": "r00t",
453                 "port": 22,
454                 "role": "TrafficGen",
455                 "user": "root",
456                 "username": "root",
457                 "vnfd-id-ref": "tg__0"
458             },
459             "vnf__0": {
460                 "VNF model": "../../vnf_descriptors/vpp_vnfd.yaml",
461                 "ctx_type": "Node",
462                 "interfaces": {
463                     "xe0": {
464                         "dpdk_port_num": 0,
465                         "driver": "igb_uio",
466                         "dst_ip": "192.168.100.1",
467                         "dst_mac": "90:e2:ba:7c:30:e8",
468                         "ifname": "xe0",
469                         "local_ip": "192.168.100.2",
470                         "local_mac": "90:e2:ba:7c:41:a8",
471                         "netmask": "255.255.255.0",
472                         "network": {},
473                         "node_name": "vnf__0",
474                         "peer_ifname": "xe0",
475                         "peer_intf": {
476                             "dpdk_port_num": 0,
477                             "driver": "igb_uio",
478                             "dst_ip": "192.168.100.2",
479                             "dst_mac": "90:e2:ba:7c:41:a8",
480                             "ifname": "xe0",
481                             "local_ip": "192.168.100.1",
482                             "local_mac": "90:e2:ba:7c:30:e8",
483                             "netmask": "255.255.255.0",
484                             "network": {},
485                             "node_name": "tg__0",
486                             "peer_ifname": "xe0",
487                             "peer_name": "vnf__0",
488                             "vld_id": "uplink_0",
489                             "vpci": "0000:81:00.0"
490                         },
491                         "peer_name": "tg__0",
492                         "vld_id": "uplink_0",
493                         "vpci": "0000:00:06.0"
494                     },
495                     "xe1": {
496                         "dpdk_port_num": 1,
497                         "driver": "igb_uio",
498                         "dst_ip": "1.1.1.2",
499                         "dst_mac": "0a:b1:ec:fd:a2:66",
500                         "ifname": "xe1",
501                         "local_ip": "1.1.1.1",
502                         "local_mac": "4e:90:85:d3:c5:13",
503                         "netmask": "255.255.255.0",
504                         "network": {},
505                         "node_name": "vnf__0",
506                         "peer_ifname": "xe1",
507                         "peer_intf": {
508                             "dpdk_port_num": 1,
509                             "driver": "igb_uio",
510                             "dst_ip": "1.1.1.1",
511                             "dst_mac": "4e:90:85:d3:c5:13",
512                             "ifname": "xe1",
513                             "local_ip": "1.1.1.2",
514                             "local_mac": "0a:b1:ec:fd:a2:66",
515                             "netmask": "255.255.255.0",
516                             "network": {},
517                             "node_name": "vnf__1",
518                             "peer_ifname": "xe1",
519                             "peer_name": "vnf__0",
520                             "vld_id": "ciphertext",
521                             "vpci": "0000:00:07.0"
522                         },
523                         "peer_name": "vnf__1",
524                         "vld_id": "ciphertext",
525                         "vpci": "0000:00:07.0"
526                     }
527                 },
528                 "ip": "10.10.10.101",
529                 "member-vnf-index": "2",
530                 "name": "vnf0.yardstick-5486cc2f",
531                 "password": "r00t",
532                 "port": 22,
533                 "role": "VirtualNetworkFunction",
534                 "user": "root",
535                 "username": "root",
536                 "vnfd-id-ref": "vnf__0"
537             },
538             "vnf__1": {
539                 "VNF model": "../../vnf_descriptors/vpp_vnfd.yaml",
540                 "ctx_type": "Node",
541                 "interfaces": {
542                     "xe0": {
543                         "dpdk_port_num": 0,
544                         "driver": "igb_uio",
545                         "dst_ip": "192.168.101.1",
546                         "dst_mac": "90:e2:ba:7c:30:e9",
547                         "ifname": "xe0",
548                         "local_ip": "192.168.101.2",
549                         "local_mac": "90:e2:ba:7c:41:a9",
550                         "netmask": "255.255.255.0",
551                         "network": {},
552                         "node_name": "vnf__1",
553                         "peer_ifname": "xe1",
554                         "peer_intf": {
555                             "dpdk_port_num": 1,
556                             "driver": "igb_uio",
557                             "dst_ip": "192.168.101.2",
558                             "dst_mac": "90:e2:ba:7c:41:a9",
559                             "ifname": "xe1",
560                             "local_ip": "192.168.101.1",
561                             "local_mac": "90:e2:ba:7c:30:e9",
562                             "netmask": "255.255.255.0",
563                             "network": {},
564                             "node_name": "tg__0",
565                             "peer_ifname": "xe0",
566                             "peer_name": "vnf__1",
567                             "vld_id": "downlink_0",
568                             "vpci": "0000:81:00.1"
569                         },
570                         "peer_name": "tg__0",
571                         "vld_id": "downlink_0",
572                         "vpci": "0000:00:06.0"
573                     },
574                     "xe1": {
575                         "dpdk_port_num": 1,
576                         "driver": "igb_uio",
577                         "dst_ip": "1.1.1.1",
578                         "dst_mac": "4e:90:85:d3:c5:13",
579                         "ifname": "xe1",
580                         "local_ip": "1.1.1.2",
581                         "local_mac": "0a:b1:ec:fd:a2:66",
582                         "netmask": "255.255.255.0",
583                         "network": {},
584                         "node_name": "vnf__1",
585                         "peer_ifname": "xe1",
586                         "peer_intf": {
587                             "dpdk_port_num": 1,
588                             "driver": "igb_uio",
589                             "dst_ip": "1.1.1.2",
590                             "dst_mac": "0a:b1:ec:fd:a2:66",
591                             "ifname": "xe1",
592                             "local_ip": "1.1.1.1",
593                             "local_mac": "4e:90:85:d3:c5:13",
594                             "netmask": "255.255.255.0",
595                             "network": {},
596                             "node_name": "vnf__0",
597                             "peer_ifname": "xe1",
598                             "peer_name": "vnf__1",
599                             "vld_id": "ciphertext",
600                             "vpci": "0000:00:07.0"
601                         },
602                         "peer_name": "vnf__0",
603                         "vld_id": "ciphertext",
604                         "vpci": "0000:00:07.0"
605                     }
606                 },
607                 "ip": "10.10.10.102",
608                 "member-vnf-index": "3",
609                 "name": "vnf1.yardstick-5486cc2f",
610                 "password": "r00t",
611                 "port": 22,
612                 "role": "VirtualNetworkFunction",
613                 "user": "root",
614                 "username": "root",
615                 "vnfd-id-ref": "vnf__1"
616             }
617         }
618     }
619
620     def test___init__(self, *args):
621         vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0]
622         vipsec_vnf = ipsec_vnf.VipsecApproxVnf(NAME, vnfd)
623         self.assertIsNone(vipsec_vnf._vnf_process)
624
625     @mock.patch(SSH_HELPER)
626     def test__run(self, ssh, *args):
627         mock_ssh(ssh)
628
629         vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0]
630         vipsec_vnf = ipsec_vnf.VipsecApproxVnf(NAME, vnfd)
631         vipsec_vnf._build_config = mock.MagicMock()
632         vipsec_vnf.setup_helper.kill_vnf = mock.MagicMock()
633         vipsec_vnf.setup_helper.create_ipsec_tunnels = mock.MagicMock()
634         vipsec_vnf.queue_wrapper = mock.MagicMock()
635         vipsec_vnf.scenario_helper.scenario_cfg = self.scenario_cfg
636         vipsec_vnf.vnf_cfg = {'lb_config': 'SW',
637                               'lb_count': 1,
638                               'worker_config': '1C/1T',
639                               'worker_threads': 1}
640         vipsec_vnf.all_options = {'traffic_type': '4',
641                                   'topology': 'nsb_test_case.yaml'}
642         vipsec_vnf._run()
643         # vipsec_vnf.setup_helper.ssh_helper.execute.assert_called_once()
644
645     @mock.patch(SSH_HELPER)
646     def test_wait_for_instantiate(self, ssh, *args):
647         mock_ssh(ssh)
648
649         mock_process = mock.Mock(autospec=Process)
650         mock_process.is_alive.return_value = True
651         mock_process.exitcode = 432
652
653         vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0]
654         vipsec_vnf = ipsec_vnf.VipsecApproxVnf(NAME, vnfd)
655         vipsec_vnf.resource_helper.resource = mock.MagicMock()
656         vipsec_vnf.setup_helper = mock.MagicMock()
657         vipsec_vnf.setup_helper.check_status.return_value = True
658         vipsec_vnf._vnf_process = mock_process
659         vipsec_vnf.WAIT_TIME = 0
660         self.assertEqual(vipsec_vnf.wait_for_instantiate(), 432)
661
662     @mock.patch(SSH_HELPER)
663     def test_wait_for_instantiate_crash(self, ssh, *args):
664         mock_ssh(ssh)
665
666         mock_process = mock.Mock(autospec=Process)
667         mock_process.is_alive.return_value = False
668         mock_process.exitcode = 432
669
670         vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0]
671         vipsec_vnf = ipsec_vnf.VipsecApproxVnf(NAME, vnfd)
672         vipsec_vnf.resource_helper.resource = mock.MagicMock()
673         vipsec_vnf.setup_helper = mock.MagicMock()
674         vipsec_vnf.setup_helper.check_status.return_value = False
675         vipsec_vnf._vnf_process = mock_process
676         vipsec_vnf.WAIT_TIME = 0
677         vipsec_vnf.WAIT_TIME_FOR_SCRIPT = 0
678
679         with self.assertRaises(RuntimeError) as raised:
680             vipsec_vnf.wait_for_instantiate()
681
682         self.assertIn('VNF process died', str(raised.exception))
683
684     @mock.patch.object(ctx_base.Context, 'get_physical_node_from_server',
685                        return_value='mock_node')
686     @mock.patch.object(ipsec_vnf.VipsecApproxSetupEnvHelper,
687                        'get_vpp_statistics',
688                        return_value={'packets_in': 0, 'packets_fwd': 0,
689                                      'packets_dropped': 0})
690     @mock.patch(SSH_HELPER)
691     def test_collect_kpi(self, ssh, *args):
692         mock_ssh(ssh)
693
694         vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0]
695         vipsec_vnf = ipsec_vnf.VipsecApproxVnf(NAME, vnfd)
696         vipsec_vnf.scenario_helper.scenario_cfg = {
697             'nodes': {vipsec_vnf.name: "mock"}
698         }
699         result = {
700             'collect_stats': {'packets_in': 0, 'packets_fwd': 0,
701                               'packets_dropped': 0},
702             'physical_node': 'mock_node'
703         }
704         self.assertEqual(result, vipsec_vnf.collect_kpi())
705
706     @mock.patch.object(utils, 'find_relative_file')
707     @mock.patch(
708         "yardstick.network_services.vnf_generic.vnf.sample_vnf.Context")
709     @mock.patch(SSH_HELPER)
710     def test_instantiate(self, ssh, *args):
711         mock_ssh(ssh)
712
713         vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0]
714         vipsec_vnf = ipsec_vnf.VipsecApproxVnf(NAME, vnfd)
715         vipsec_vnf.deploy_helper = mock.MagicMock()
716         vipsec_vnf.resource_helper = mock.MagicMock()
717         vipsec_vnf._build_config = mock.MagicMock()
718         vipsec_vnf.WAIT_TIME = 0
719         self.scenario_cfg.update({"nodes": {"vnf__1": ""}})
720         self.assertIsNone(vipsec_vnf.instantiate(self.scenario_cfg,
721                                                  self.context_cfg))
722
723     @mock.patch.object(ipsec_vnf.VipsecApproxSetupEnvHelper, 'kill_vnf',
724                        return_value='')
725     @mock.patch("yardstick.network_services.vnf_generic.vnf.sample_vnf.time")
726     @mock.patch(SSH_HELPER)
727     def test_terminate(self, ssh, *args):
728         mock_ssh(ssh)
729
730         vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0]
731         vipsec_vnf = ipsec_vnf.VipsecApproxVnf(NAME, vnfd)
732         vipsec_vnf._vnf_process = mock.MagicMock()
733         vipsec_vnf._vnf_process.terminate = mock.Mock()
734         self.assertIsNone(vipsec_vnf.terminate())
735
736
737 class TestVipsecApproxSetupEnvHelper(unittest.TestCase):
738     ALL_OPTIONS = {
739         "flow": {
740             "count": 1,
741             "dst_ip": [
742                 "20.0.0.0-20.0.0.100"
743             ],
744             "src_ip": [
745                 "10.0.0.0-10.0.0.100"
746             ]
747         },
748         "framesize": {
749             "downlink": {
750                 "64B": 100
751             },
752             "uplink": {
753                 "64B": 100
754             }
755         },
756         "rfc2544": {
757             "allowed_drop_rate": "0.0 - 0.005"
758         },
759         "tg__0": {
760             "collectd": {
761                 "interval": 1
762             },
763             "queues_per_port": 7
764         },
765         "traffic_type": 4,
766         "vnf__0": {
767             "collectd": {
768                 "interval": 1
769             },
770             "vnf_config": {
771                 "crypto_type": "SW_cryptodev",
772                 "rxq": 1,
773                 "worker_config": "1C/1T",
774                 "worker_threads": 4
775             }
776         },
777         "vnf__1": {
778             "collectd": {
779                 "interval": 1
780             },
781             "vnf_config": {
782                 "crypto_type": "SW_cryptodev",
783                 "rxq": 1,
784                 "worker_config": "1C/1T",
785                 "worker_threads": 4
786             }
787         },
788         "vpp_config": {
789             "crypto_algorithms": "aes-gcm",
790             "tunnel": 1
791         }
792     }
793
794     ALL_OPTIONS_ERROR = {
795         "flow_error": {
796             "count": 1,
797             "dst_ip": [
798                 "20.0.0.0-20.0.0.100"
799             ],
800             "src_ip": [
801                 "10.0.0.0-10.0.0.100"
802             ]
803         },
804         "framesize": {
805             "downlink": {
806                 "64B": 100
807             },
808             "uplink": {
809                 "64B": 100
810             }
811         },
812         "rfc2544": {
813             "allowed_drop_rate": "0.0 - 0.005"
814         },
815         "tg__0": {
816             "collectd": {
817                 "interval": 1
818             },
819             "queues_per_port": 7
820         },
821         "traffic_type": 4,
822         "vnf__0": {
823             "collectd": {
824                 "interval": 1
825             },
826             "vnf_config": {
827                 "crypto_type": "SW_cryptodev",
828                 "rxq": 1,
829                 "worker_config": "1C/1T",
830                 "worker_threads": 4
831             }
832         },
833         "vnf__1": {
834             "collectd": {
835                 "interval": 1
836             },
837             "vnf_config": {
838                 "crypto_type": "SW_cryptodev",
839                 "rxq": 1,
840                 "worker_config": "1C/1T",
841                 "worker_threads": 4
842             }
843         },
844         "vpp_config": {
845             "crypto_algorithms": "aes-gcm",
846             "tunnel": 1
847         }
848     }
849
850     OPTIONS = {
851         "collectd": {
852             "interval": 1
853         },
854         "vnf_config": {
855             "crypto_type": "SW_cryptodev",
856             "rxq": 1,
857             "worker_config": "1C/1T",
858             "worker_threads": 4
859         }
860     }
861
862     CPU_LAYOUT = {'cpuinfo': [[0, 0, 0, 0, 0, 0, 0, 0],
863                               [1, 0, 0, 0, 0, 1, 1, 0],
864                               [2, 1, 0, 0, 0, 2, 2, 1],
865                               [3, 1, 0, 0, 0, 3, 3, 1],
866                               [4, 2, 0, 0, 0, 4, 4, 2],
867                               [5, 2, 0, 0, 0, 5, 5, 2],
868                               [6, 3, 0, 0, 0, 6, 6, 3],
869                               [7, 3, 0, 0, 0, 7, 7, 3],
870                               [8, 4, 0, 0, 0, 8, 8, 4],
871                               [9, 5, 0, 1, 0, 9, 9, 4],
872                               [10, 6, 0, 1, 0, 10, 10, 5],
873                               [11, 6, 0, 1, 0, 11, 11, 5],
874                               [12, 7, 0, 1, 0, 12, 12, 6],
875                               [13, 7, 0, 1, 0, 13, 13, 6],
876                               [14, 8, 0, 1, 0, 14, 14, 7],
877                               [15, 8, 0, 1, 0, 15, 15, 7],
878                               [16, 9, 0, 1, 0, 16, 16, 8],
879                               [17, 9, 0, 1, 0, 17, 17, 8]]}
880
881     VPP_INTERFACES_DUMP = [
882         {
883             "sw_if_index": 0,
884             "sup_sw_if_index": 0,
885             "l2_address_length": 0,
886             "l2_address": [0, 0, 0, 0, 0, 0, 0, 0],
887             "interface_name": "local0",
888             "admin_up_down": 0,
889             "link_up_down": 0,
890             "link_duplex": 0,
891             "link_speed": 0,
892             "mtu": 0,
893             "sub_id": 0,
894             "sub_dot1ad": 0,
895             "sub_number_of_tags": 0,
896             "sub_outer_vlan_id": 0,
897             "sub_inner_vlan_id": 0,
898             "sub_exact_match": 0,
899             "sub_default": 0,
900             "sub_outer_vlan_id_any": 0,
901             "sub_inner_vlan_id_any": 0,
902             "vtr_op": 0,
903             "vtr_push_dot1q": 0,
904             "vtr_tag1": 0,
905             "vtr_tag2": 0
906         },
907         {
908             "sw_if_index": 1,
909             "sup_sw_if_index": 1,
910             "l2_address_length": 6,
911             "l2_address": [144, 226, 186, 124, 65, 168, 0, 0],
912             "interface_name": "TenGigabitEthernetff/6/0",
913             "admin_up_down": 0,
914             "link_up_down": 0,
915             "link_duplex": 2,
916             "link_speed": 32,
917             "mtu": 9202,
918             "sub_id": 0,
919             "sub_dot1ad": 0,
920             "sub_number_of_tags": 0,
921             "sub_outer_vlan_id": 0,
922             "sub_inner_vlan_id": 0,
923             "sub_exact_match": 0,
924             "sub_default": 0,
925             "sub_outer_vlan_id_any": 0,
926             "sub_inner_vlan_id_any": 0,
927             "vtr_op": 0,
928             "vtr_push_dot1q": 0,
929             "vtr_tag1": 0,
930             "vtr_tag2": 0
931         },
932         {
933             "sw_if_index": 2,
934             "sup_sw_if_index": 2,
935             "l2_address_length": 6,
936             "l2_address": [78, 144, 133, 211, 197, 19, 0, 0],
937             "interface_name": "VirtualFunctionEthernetff/7/0",
938             "admin_up_down": 0,
939             "link_up_down": 0,
940             "link_duplex": 2,
941             "link_speed": 32,
942             "mtu": 9206,
943             "sub_id": 0,
944             "sub_dot1ad": 0,
945             "sub_number_of_tags": 0,
946             "sub_outer_vlan_id": 0,
947             "sub_inner_vlan_id": 0,
948             "sub_exact_match": 0,
949             "sub_default": 0,
950             "sub_outer_vlan_id_any": 0,
951             "sub_inner_vlan_id_any": 0,
952             "vtr_op": 0,
953             "vtr_push_dot1q": 0,
954             "vtr_tag1": 0,
955             "vtr_tag2": 0
956         }
957     ]
958
959     VPP_INTERFACES_STATUS = \
960         '              Name               Idx    State  MTU (L3/IP4/IP6/MPLS)' \
961         'Counter          Count     \n' \
962         'TenGigabitEthernetff/6/0          1     up         9000/0/0/0    \n' \
963         'VirtualFunctionEthernetff/7/0     2     up         9000/0/0/0    \n' \
964         'ipsec0                            2     up         9000/0/0/0    \n' \
965         'local0                            0     down          0/0/0/0      '
966
967     VPP_INTERFACES_STATUS_FALSE = \
968         '              Name               Idx    State  MTU (L3/IP4/IP6/MPLS)' \
969         'Counter          Count     \n' \
970         'TenGigabitEthernetff/6/0          1     down         9000/0/0/0  \n' \
971         'VirtualFunctionEthernetff/7/0     2     down         9000/0/0/0  \n' \
972         'ipsec0                            2     down         9000/0/0/0  \n' \
973         'local0                            0     down          0/0/0/0      '
974
975     def test__get_crypto_type(self):
976         vnfd_helper = VnfdHelper(
977             TestVipsecApproxVnf.VNFD['vnfd:vnfd-catalog']['vnfd'][0])
978         ssh_helper = mock.Mock()
979         scenario_helper = mock.Mock()
980         scenario_helper.options = self.OPTIONS
981
982         ipsec_approx_setup_helper = VipsecApproxSetupEnvHelper(vnfd_helper,
983                                                                ssh_helper,
984                                                                scenario_helper)
985         self.assertEqual('SW_cryptodev',
986                          ipsec_approx_setup_helper._get_crypto_type())
987
988     def test__get_crypto_algorithms(self):
989         vnfd_helper = VnfdHelper(
990             TestVipsecApproxVnf.VNFD['vnfd:vnfd-catalog']['vnfd'][0])
991         ssh_helper = mock.Mock()
992         scenario_helper = mock.Mock()
993         scenario_helper.all_options = self.ALL_OPTIONS
994
995         ipsec_approx_setup_helper = VipsecApproxSetupEnvHelper(vnfd_helper,
996                                                                ssh_helper,
997                                                                scenario_helper)
998         self.assertEqual('aes-gcm',
999                          ipsec_approx_setup_helper._get_crypto_algorithms())
1000
1001     def test__get_n_tunnels(self):
1002         vnfd_helper = VnfdHelper(
1003             TestVipsecApproxVnf.VNFD['vnfd:vnfd-catalog']['vnfd'][0])
1004         ssh_helper = mock.Mock()
1005         scenario_helper = mock.Mock()
1006         scenario_helper.all_options = self.ALL_OPTIONS
1007
1008         ipsec_approx_setup_helper = VipsecApproxSetupEnvHelper(vnfd_helper,
1009                                                                ssh_helper,
1010                                                                scenario_helper)
1011         self.assertEqual(1, ipsec_approx_setup_helper._get_n_tunnels())
1012
1013     def test__get_n_connections(self):
1014         vnfd_helper = VnfdHelper(
1015             TestVipsecApproxVnf.VNFD['vnfd:vnfd-catalog']['vnfd'][0])
1016         ssh_helper = mock.Mock()
1017         scenario_helper = mock.Mock()
1018         scenario_helper.all_options = self.ALL_OPTIONS
1019
1020         ipsec_approx_setup_helper = VipsecApproxSetupEnvHelper(vnfd_helper,
1021                                                                ssh_helper,
1022                                                                scenario_helper)
1023         self.assertEqual(1, ipsec_approx_setup_helper._get_n_connections())
1024
1025     def test__get_n_connections_error(self):
1026         vnfd_helper = VnfdHelper(
1027             TestVipsecApproxVnf.VNFD['vnfd:vnfd-catalog']['vnfd'][0])
1028         ssh_helper = mock.Mock()
1029         scenario_helper = mock.Mock()
1030         scenario_helper.all_options = self.ALL_OPTIONS_ERROR
1031
1032         ipsec_approx_setup_helper = VipsecApproxSetupEnvHelper(vnfd_helper,
1033                                                                ssh_helper,
1034                                                                scenario_helper)
1035         with self.assertRaises(KeyError) as raised:
1036             ipsec_approx_setup_helper._get_n_connections()
1037         self.assertIn(
1038             'Missing flow definition in scenario section of the task definition file',
1039             str(raised.exception))
1040
1041     def test__get_flow_src_start_ip(self):
1042         vnfd_helper = VnfdHelper(
1043             TestVipsecApproxVnf.VNFD['vnfd:vnfd-catalog']['vnfd'][0])
1044         ssh_helper = mock.Mock()
1045         scenario_helper = mock.Mock()
1046         scenario_helper.all_options = self.ALL_OPTIONS
1047
1048         ipsec_approx_setup_helper = VipsecApproxSetupEnvHelper(vnfd_helper,
1049                                                                ssh_helper,
1050                                                                scenario_helper)
1051         self.assertEqual('10.0.0.0',
1052                          ipsec_approx_setup_helper._get_flow_src_start_ip())
1053
1054     def test__get_flow_src_start_ip_vnf1(self):
1055         vnfd_helper = VnfdHelper(
1056             TestVipsecApproxVnf.VNFD_ERROR['vnfd:vnfd-catalog']['vnfd'][0])
1057         ssh_helper = mock.Mock()
1058         scenario_helper = mock.Mock()
1059         scenario_helper.all_options = self.ALL_OPTIONS
1060
1061         ipsec_approx_setup_helper = VipsecApproxSetupEnvHelper(vnfd_helper,
1062                                                                ssh_helper,
1063                                                                scenario_helper)
1064         self.assertEqual('20.0.0.0',
1065                          ipsec_approx_setup_helper._get_flow_src_start_ip())
1066
1067     def test__get_flow_src_start_ip_error(self):
1068         vnfd_helper = VnfdHelper(
1069             TestVipsecApproxVnf.VNFD['vnfd:vnfd-catalog']['vnfd'][0])
1070         ssh_helper = mock.Mock()
1071         scenario_helper = mock.Mock()
1072         scenario_helper.all_options = self.ALL_OPTIONS_ERROR
1073
1074         ipsec_approx_setup_helper = VipsecApproxSetupEnvHelper(vnfd_helper,
1075                                                                ssh_helper,
1076                                                                scenario_helper)
1077         with self.assertRaises(KeyError) as raised:
1078             ipsec_approx_setup_helper._get_flow_src_start_ip()
1079         self.assertIn(
1080             'Missing flow definition in scenario section of the task definition file',
1081             str(raised.exception))
1082
1083     def test__get_flow_dst_start_ip(self):
1084         vnfd_helper = VnfdHelper(
1085             TestVipsecApproxVnf.VNFD['vnfd:vnfd-catalog']['vnfd'][0])
1086         ssh_helper = mock.Mock()
1087         scenario_helper = mock.Mock()
1088         scenario_helper.all_options = self.ALL_OPTIONS
1089
1090         ipsec_approx_setup_helper = VipsecApproxSetupEnvHelper(vnfd_helper,
1091                                                                ssh_helper,
1092                                                                scenario_helper)
1093         self.assertEqual('20.0.0.0',
1094                          ipsec_approx_setup_helper._get_flow_dst_start_ip())
1095
1096     def test__get_flow_dst_start_ip_vnf1(self):
1097         vnfd_helper = VnfdHelper(
1098             TestVipsecApproxVnf.VNFD_ERROR['vnfd:vnfd-catalog']['vnfd'][0])
1099         ssh_helper = mock.Mock()
1100         scenario_helper = mock.Mock()
1101         scenario_helper.all_options = self.ALL_OPTIONS
1102
1103         ipsec_approx_setup_helper = VipsecApproxSetupEnvHelper(vnfd_helper,
1104                                                                ssh_helper,
1105                                                                scenario_helper)
1106         self.assertEqual('10.0.0.0',
1107                          ipsec_approx_setup_helper._get_flow_dst_start_ip())
1108
1109     def test__get_flow_dst_start_ip_error(self):
1110         vnfd_helper = VnfdHelper(
1111             TestVipsecApproxVnf.VNFD['vnfd:vnfd-catalog']['vnfd'][0])
1112         ssh_helper = mock.Mock()
1113         scenario_helper = mock.Mock()
1114         scenario_helper.all_options = self.ALL_OPTIONS_ERROR
1115
1116         ipsec_approx_setup_helper = VipsecApproxSetupEnvHelper(vnfd_helper,
1117                                                                ssh_helper,
1118                                                                scenario_helper)
1119         with self.assertRaises(KeyError) as raised:
1120             ipsec_approx_setup_helper._get_flow_dst_start_ip()
1121         self.assertIn(
1122             'Missing flow definition in scenario section of the task definition file',
1123             str(raised.exception))
1124
1125     def test_build_config(self):
1126         vnfd_helper = VnfdHelper(
1127             TestVipsecApproxVnf.VNFD['vnfd:vnfd-catalog']['vnfd'][0])
1128         ssh_helper = mock.Mock()
1129         scenario_helper = mock.Mock()
1130
1131         ipsec_approx_setup_helper = VipsecApproxSetupEnvHelper(vnfd_helper,
1132                                                                ssh_helper,
1133                                                                scenario_helper)
1134         ipsec_approx_setup_helper.build_config()
1135
1136     @mock.patch.object(utils, 'setup_hugepages')
1137     def test_setup_vnf_environment(self, *args):
1138         vnfd_helper = VnfdHelper(
1139             TestVipsecApproxVnf.VNFD['vnfd:vnfd-catalog']['vnfd'][0])
1140         ssh_helper = mock.Mock()
1141         ssh_helper.execute.return_value = 0, '0', ''
1142         scenario_helper = mock.Mock()
1143         scenario_helper.nodes = [None, None]
1144         scenario_helper.options = self.OPTIONS
1145         scenario_helper.all_options = self.ALL_OPTIONS
1146
1147         ipsec_approx_setup_helper = VipsecApproxSetupEnvHelper(vnfd_helper,
1148                                                                ssh_helper,
1149                                                                scenario_helper)
1150         self.assertIsInstance(
1151             ipsec_approx_setup_helper.setup_vnf_environment(),
1152             ResourceProfile)
1153
1154     def test_calculate_frame_size(self):
1155         vnfd_helper = VnfdHelper(
1156             TestVipsecApproxVnf.VNFD['vnfd:vnfd-catalog']['vnfd'][0])
1157         ssh_helper = mock.Mock()
1158         scenario_helper = mock.Mock()
1159
1160         ipsec_approx_setup_helper = VipsecApproxSetupEnvHelper(vnfd_helper,
1161                                                                ssh_helper,
1162                                                                scenario_helper)
1163         self.assertEqual(16984 / 48,
1164                          ipsec_approx_setup_helper.calculate_frame_size(
1165                              {'64B': 28, '570B': 16, '1518B': 4}))
1166
1167     def test_calculate_frame_size_64(self):
1168         vnfd_helper = VnfdHelper(
1169             TestVipsecApproxVnf.VNFD['vnfd:vnfd-catalog']['vnfd'][0])
1170         ssh_helper = mock.Mock()
1171         scenario_helper = mock.Mock()
1172
1173         ipsec_approx_setup_helper = VipsecApproxSetupEnvHelper(vnfd_helper,
1174                                                                ssh_helper,
1175                                                                scenario_helper)
1176         self.assertEqual(64,
1177                          ipsec_approx_setup_helper.calculate_frame_size({}))
1178
1179     def test_calculate_frame_size_64_error(self):
1180         vnfd_helper = VnfdHelper(
1181             TestVipsecApproxVnf.VNFD['vnfd:vnfd-catalog']['vnfd'][0])
1182         ssh_helper = mock.Mock()
1183         scenario_helper = mock.Mock()
1184
1185         ipsec_approx_setup_helper = VipsecApproxSetupEnvHelper(vnfd_helper,
1186                                                                ssh_helper,
1187                                                                scenario_helper)
1188         self.assertEqual(64,
1189                          ipsec_approx_setup_helper.calculate_frame_size(
1190                              {'64B': -28, '570B': 16, '1518B': 4}))
1191
1192     def test_check_status(self):
1193         vnfd_helper = VnfdHelper(
1194             TestVipsecApproxVnf.VNFD['vnfd:vnfd-catalog']['vnfd'][0])
1195         ssh_helper = mock.Mock()
1196         ssh_helper.execute.return_value = 0, self.VPP_INTERFACES_STATUS, ''
1197         scenario_helper = mock.Mock()
1198
1199         ipsec_approx_setup_helper = VipsecApproxSetupEnvHelper(vnfd_helper,
1200                                                                ssh_helper,
1201                                                                scenario_helper)
1202         self.assertTrue(ipsec_approx_setup_helper.check_status())
1203
1204     def test_check_status_false(self):
1205         vnfd_helper = VnfdHelper(
1206             TestVipsecApproxVnf.VNFD['vnfd:vnfd-catalog']['vnfd'][0])
1207         ssh_helper = mock.Mock()
1208         ssh_helper.execute.return_value = 0, self.VPP_INTERFACES_STATUS_FALSE, ''
1209         scenario_helper = mock.Mock()
1210
1211         ipsec_approx_setup_helper = VipsecApproxSetupEnvHelper(vnfd_helper,
1212                                                                ssh_helper,
1213                                                                scenario_helper)
1214         self.assertFalse(ipsec_approx_setup_helper.check_status())
1215
1216     def test_get_vpp_statistics(self):
1217         vnfd_helper = VnfdHelper(
1218             TestVipsecApproxVnf.VNFD['vnfd:vnfd-catalog']['vnfd'][0])
1219         ssh_helper = mock.Mock()
1220         scenario_helper = mock.Mock()
1221
1222         ipsec_approx_setup_helper = VipsecApproxSetupEnvHelper(vnfd_helper,
1223                                                                ssh_helper,
1224                                                                scenario_helper)
1225         ipsec_approx_setup_helper.get_vpp_statistics()
1226
1227     def test_create_ipsec_tunnels(self):
1228         vnfd_helper = VnfdHelper(
1229             TestVipsecApproxVnf.VNFD['vnfd:vnfd-catalog']['vnfd'][0])
1230         ssh_helper = mock.Mock()
1231         scenario_helper = mock.Mock()
1232
1233         ipsec_approx_setup_helper = VipsecApproxSetupEnvHelper(vnfd_helper,
1234                                                                ssh_helper,
1235                                                                scenario_helper)
1236         ipsec_approx_setup_helper.create_ipsec_tunnels()
1237
1238     def test_find_raw_data_interface(self):
1239         expected = {'dpdk_port_num': 0,
1240                     'driver': 'igb_uio',
1241                     'dst_ip': '192.168.100.1',
1242                     'dst_mac': '90:e2:ba:7c:30:e8',
1243                     'ifname': 'xe0',
1244                     'local_ip': '192.168.100.2',
1245                     'local_mac': '90:e2:ba:7c:41:a8',
1246                     'netmask': '255.255.255.0',
1247                     'network': {},
1248                     'node_name': 'vnf__0',
1249                     'peer_ifname': 'xe0',
1250                     'peer_intf': {'dpdk_port_num': 0,
1251                                   'driver': 'igb_uio',
1252                                   'dst_ip': '192.168.100.2',
1253                                   'dst_mac': '90:e2:ba:7c:41:a8',
1254                                   'ifname': 'xe0',
1255                                   'local_ip': '192.168.100.1',
1256                                   'local_mac': '90:e2:ba:7c:30:e8',
1257                                   'netmask': '255.255.255.0',
1258                                   'network': {},
1259                                   'node_name': 'tg__0',
1260                                   'peer_ifname': 'xe0',
1261                                   'peer_name': 'vnf__0',
1262                                   'vld_id': 'uplink_0',
1263                                   'vpci': '0000:81:00.0'},
1264                     'peer_name': 'tg__0',
1265                     'vld_id': 'uplink_0',
1266                     'vpci': '0000:ff:06.0'}
1267         vnfd_helper = VnfdHelper(
1268             TestVipsecApproxVnf.VNFD['vnfd:vnfd-catalog']['vnfd'][0])
1269         ssh_helper = mock.Mock()
1270         scenario_helper = mock.Mock()
1271
1272         ipsec_approx_setup_helper = VipsecApproxSetupEnvHelper(vnfd_helper,
1273                                                                ssh_helper,
1274                                                                scenario_helper)
1275         self.assertEqual(expected,
1276                          ipsec_approx_setup_helper.find_raw_data_interface())
1277
1278     def test_find_raw_data_interface_error(self):
1279         vnfd_helper = VnfdHelper(
1280             TestVipsecApproxVnf.VNFD_ERROR['vnfd:vnfd-catalog']['vnfd'][0])
1281         ssh_helper = mock.Mock()
1282         scenario_helper = mock.Mock()
1283
1284         ipsec_approx_setup_helper = VipsecApproxSetupEnvHelper(vnfd_helper,
1285                                                                ssh_helper,
1286                                                                scenario_helper)
1287         with self.assertRaises(KeyError):
1288             ipsec_approx_setup_helper.find_raw_data_interface()
1289
1290     def test_find_encrypted_data_interface(self):
1291         expected = {'dpdk_port_num': 1,
1292                     'driver': 'igb_uio',
1293                     'dst_ip': '1.1.1.2',
1294                     'dst_mac': '0a:b1:ec:fd:a2:66',
1295                     'ifname': 'xe1',
1296                     'local_ip': '1.1.1.1',
1297                     'local_mac': '4e:90:85:d3:c5:13',
1298                     'netmask': '255.255.255.0',
1299                     'network': {},
1300                     'node_name': 'vnf__0',
1301                     'peer_ifname': 'xe1',
1302                     'peer_intf': {'driver': 'igb_uio',
1303                                   'dst_ip': '1.1.1.1',
1304                                   'dst_mac': '4e:90:85:d3:c5:13',
1305                                   'ifname': 'xe1',
1306                                   'local_ip': '1.1.1.2',
1307                                   'local_mac': '0a:b1:ec:fd:a2:66',
1308                                   'netmask': '255.255.255.0',
1309                                   'network': {},
1310                                   'node_name': 'vnf__1',
1311                                   'peer_ifname': 'xe1',
1312                                   'peer_name': 'vnf__0',
1313                                   'vld_id': 'ciphertext',
1314                                   'vpci': '0000:00:07.0'},
1315                     'peer_name': 'vnf__1',
1316                     'vld_id': 'ciphertext',
1317                     'vpci': '0000:ff:07.0'}
1318         vnfd_helper = VnfdHelper(
1319             TestVipsecApproxVnf.VNFD['vnfd:vnfd-catalog']['vnfd'][0])
1320         ssh_helper = mock.Mock()
1321         scenario_helper = mock.Mock()
1322
1323         ipsec_approx_setup_helper = VipsecApproxSetupEnvHelper(vnfd_helper,
1324                                                                ssh_helper,
1325                                                                scenario_helper)
1326         self.assertEqual(expected,
1327                          ipsec_approx_setup_helper.find_encrypted_data_interface())