aboutsummaryrefslogtreecommitdiffstats
path: root/yardstick/tests/functional/benchmark/scenarios/networking/test_vnf_generic.py
blob: 38f1a978d9e156739822b4f8c0345aff206187c5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
# Copyright (c) 2018 Intel Corporation
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#      http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import copy
import sys

import mock
import unittest

from yardstick import tests as y_tests
from yardstick.common import utils


with mock.patch.dict(sys.modules, y_tests.STL_MOCKS):
    from yardstick.benchmark.scenarios.networking import vnf_generic


TRAFFIC_PROFILE_1 = """
schema: nsb:traffic_profile:0.1
name: rfc2544
description: Traffic profile to run RFC2544 latency
traffic_profile:
  traffic_type : RFC2544Profile
  frame_rate : 100
uplink_0:
  ipv4:
    id: 1
    outer_l2:
      framesize:
        64B: "{{get(imix, 'imix.uplink.64B', '0') }}"
        128B: "{{get(imix, 'imix.uplink.128B', '0') }}"
"""

TRAFFIC_PROFILE_2 = """
{% set vports = get(extra_args, 'vports', 1) %}
traffic_profile:
  traffic_type : RFC2544Profile
{% for vport in range(vports|int) %}
uplink_{{vport}}:
  ipv4: 192.168.0.{{vport}}
{% endfor %}
"""

TOPOLOGY_PROFILE = """
{% set vports = get(extra_args, 'vports', 2) %}
nsd:nsd-catalog:
    nsd:
    -   id: 3tg-topology
        vld:
{% for vport in range(0,vports,2|int) %}
        -   id: uplink_{{loop.index0}}
            name: tg__0 to vnf__0 link {{vport + 1}}
            vnfd-connection-point-ref:
            -   vnfd-connection-point-ref: xe{{vport}}
        -   id: downlink_{{loop.index0}}
            name: vnf__0 to tg__0 link {{vport + 2}}
            vnfd-connection-point-ref:
            -   vnfd-connection-point-ref: xe{{vport+1}}
{% endfor %}
"""

class VnfGenericTestCase(unittest.TestCase):

    def setUp(self):
        scenario_cfg = {'topology': 'fake_topology',
                        'task_path': 'fake_path',
                        'traffic_profile': 'fake_fprofile_path'}
        context_cfg = {}
        topology_yaml = {'nsd:nsd-catalog': {'nsd': [mock.Mock()]}}

        with mock.patch.object(utils, 'open_relative_file') as mock_open_path:
            mock_open_path.side_effect = mock.mock_open(read_data=str(topology_yaml))
            self.ns_testcase = vnf_generic.NetworkServiceTestCase(scenario_cfg,
                                                                  context_cfg)
        self.ns_testcase._get_traffic_profile = mock.Mock()
        self.ns_testcase._get_topology = mock.Mock()

    def test__fill_traffic_profile_no_args(self):
        traffic_profile = copy.deepcopy(TRAFFIC_PROFILE_1)
        self.ns_testcase._get_traffic_profile.return_value = traffic_profile

        self.ns_testcase._fill_traffic_profile()
        config = self.ns_testcase.traffic_profile.params
        self.assertEqual('nsb:traffic_profile:0.1', config['schema'])
        self.assertEqual('rfc2544', config['name'])
        self.assertEqual('Traffic profile to run RFC2544 latency',
                         config['description'])
        t_profile = {'traffic_type': 'RFC2544Profile',
                     'frame_rate': 100}
        self.assertEqual(t_profile, config['traffic_profile'])
        uplink_0 = {
            'ipv4': {'id': 1,
                     'outer_l2': {'framesize': {'128B': '0', '64B': '0'}}
                     }
        }
        self.assertEqual(uplink_0, config['uplink_0'])

    def test__fill_traffic_profile_with_args(self):
        traffic_profile = copy.deepcopy(TRAFFIC_PROFILE_2)
        self.ns_testcase._get_traffic_profile.return_value = traffic_profile
        self.ns_testcase.scenario_cfg['extra_args'] = {'vports': 3}

        self.ns_testcase._fill_traffic_profile()
        config = self.ns_testcase.traffic_profile.params
        self.assertEqual({'ipv4': '192.168.0.0'}, config['uplink_0'])
        self.assertEqual({'ipv4': '192.168.0.1'}, config['uplink_1'])
        self.assertEqual({'ipv4': '192.168.0.2'}, config['uplink_2'])
        self.assertNotIn('uplink_3', config)

    def test__fill_traffic_profile_incorrect_args(self):
        traffic_profile = copy.deepcopy(TRAFFIC_PROFILE_2)
        self.ns_testcase._get_traffic_profile.return_value = traffic_profile
        self.ns_testcase.scenario_cfg['extra_args'] = {'incorrect_vports': 3}

        self.ns_testcase._fill_traffic_profile()
        config = self.ns_testcase.traffic_profile.params
        self.assertEqual({'ipv4': '192.168.0.0'}, config['uplink_0'])
        self.assertNotIn('uplink_1', config)

    def test__render_topology_with_args(self):
        topology_profile = copy.deepcopy(TOPOLOGY_PROFILE)
        self.ns_testcase._get_topology.return_value = topology_profile
        self.ns_testcase.scenario_cfg['extra_args'] = {'vports': 6}

        self.ns_testcase._render_topology()
        topology = self.ns_testcase.topology
        self.assertEqual("3tg-topology", topology['id'])
        vld = self.ns_testcase.topology['vld']
        self.assertEqual(len(vld), 6)
        for index, vport in enumerate(range(0, 6, 2)):
            self.assertEqual('uplink_{}'.format(index), vld[vport]['id'])
            self.assertEqual('tg__0 to vnf__0 link {}'.format(vport + 1), vld[vport]['name'])
            self.assertEqual('xe{}'.format(vport),
                             vld[vport]['vnfd-connection-point-ref'][0]
                             ['vnfd-connection-point-ref'])

            self.assertEqual('downlink_{}'.format(index), vld[vport + 1]['id'])
            self.assertEqual('vnf__0 to tg__0 link {}'.format(vport + 2), vld[vport + 1]['name'])
            self.assertEqual('xe{}'.format(vport + 1),
                             vld[vport + 1]['vnfd-connection-point-ref'][0]
                             ['vnfd-connection-point-ref'])

    def test__render_topology_incorrect_args(self):
        topology_profile = copy.deepcopy(TOPOLOGY_PROFILE)
        self.ns_testcase._get_topology.return_value = topology_profile
        self.ns_testcase.scenario_cfg['extra_args'] = {'fake_vports': 5}

        self.ns_testcase._render_topology()

        topology = self.ns_testcase.topology
        self.assertEqual("3tg-topology", topology['id'])
        vld = self.ns_testcase.topology['vld']
        self.assertEqual(len(vld), 2)

        self.assertEqual('uplink_0', vld[0]['id'])
        self.assertEqual('tg__0 to vnf__0 link 1', vld[0]['name'])
        self.assertEqual('xe0',
                         vld[0]['vnfd-connection-point-ref'][0]['vnfd-connection-point-ref'])

        self.assertEqual('downlink_0', vld[1]['id'])
        self.assertEqual('vnf__0 to tg__0 link 2', vld[1]['name'])
        self.assertEqual('xe1',
                         vld[1]['vnfd-connection-point-ref'][0]['vnfd-connection-point-ref'])

    def test__render_topology_no_args(self):
        topology_profile = copy.deepcopy(TOPOLOGY_PROFILE)
        self.ns_testcase._get_topology.return_value = topology_profile

        self.ns_testcase._render_topology()

        topology = self.ns_testcase.topology
        self.assertEqual("3tg-topology", topology['id'])
        vld = self.ns_testcase.topology['vld']
        self.assertEqual(len(vld), 2)

        self.assertEqual('uplink_0', vld[0]['id'])
        self.assertEqual('tg__0 to vnf__0 link 1', vld[0]['name'])
        self.assertEqual('xe0',
                         vld[0]['vnfd-connection-point-ref'][0]['vnfd-connection-point-ref'])

        self.assertEqual('downlink_0', vld[1]['id'])
        self.assertEqual('vnf__0 to tg__0 link 2', vld[1]['name'])
        self.assertEqual('xe1',
                         vld[1]['vnfd-connection-point-ref'][0]['vnfd-connection-point-ref'])