1 # -*- coding: utf-8 -*-
3 # Copyright 2018 University of Bristol - High Performance Networks Research
7 # Contributors: Anderson Bravalheri, Dimitrios Gkounis, Abubakar Siddique
8 # Muqaddas, Navdeep Uniyal, Reza Nejabati and Dimitra Simeonidou
10 # Licensed under the Apache License, Version 2.0 (the "License"); you may
11 # not use this file except in compliance with the License. You may obtain
12 # a copy of the License at
14 # http://www.apache.org/licenses/LICENSE-2.0
16 # Unless required by applicable law or agreed to in writing, software
17 # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
18 # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
19 # License for the specific language governing permissions and limitations
22 # For those usages not covered by the Apache License, Version 2.0 please
23 # contact with: <highperformance-networks@bristol.ac.uk>
25 # Neither the name of the University of Bristol nor the names of its
26 # contributors may be used to endorse or promote products derived from
27 # this software without specific prior written permission.
29 # This work has been performed in the context of DCMS UK 5G Testbeds
30 # & Trials Programme and in the framework of the Metro-Haul project -
31 # funded by the European Commission under Grant number 761727 through the
32 # Horizon 2020 and 5G-PPP programmes.
34 # pylint: disable=W0621
36 from __future__
import unicode_literals
41 from six
.moves
import range
43 from ...tests
.db_helpers
import uuid
, sha1
50 # In the following functions, the identifiers should be simple integers
53 def wim(identifier
=0):
54 return {'name': 'wim%d' % identifier
,
55 'uuid': uuid('wim%d' % identifier
),
56 'wim_url': 'localhost',
60 def tenant(identifier
=0):
61 return {'name': 'tenant%d' % identifier
,
62 'uuid': uuid('tenant%d' % identifier
)}
65 def wim_account(wim
, tenant
):
66 return {'name': 'wim-account%d%d' % (tenant
, wim
),
67 'uuid': uuid('wim-account%d%d' % (tenant
, wim
)),
68 'user': 'user%d%d' % (tenant
, wim
),
69 'password': 'password%d%d' % (tenant
, wim
),
70 'wim_id': uuid('wim%d' % wim
),
74 def wim_tenant_association(wim
, tenant
):
75 return {'nfvo_tenant_id': uuid('tenant%d' % tenant
),
76 'wim_id': uuid('wim%d' % wim
),
77 'wim_account_id': uuid('wim-account%d%d' % (tenant
, wim
))}
80 def wim_set(identifier
=0, tenant
=0):
81 """Records necessary to create a WIM and connect it to a tenant"""
83 {'wims': [wim(identifier
)]},
84 {'wim_accounts': [wim_account(identifier
, tenant
)]},
85 {'wim_nfvo_tenants': [wim_tenant_association(identifier
, tenant
)]}
89 def datacenter(identifier
):
90 return {'uuid': uuid('dc%d' % identifier
),
91 'name': 'dc%d' % identifier
,
93 'vim_url': 'localhost'}
96 def datacenter_account(datacenter
, tenant
):
97 return {'name': 'dc-account%d%d' % (tenant
, datacenter
),
98 'uuid': uuid('dc-account%d%d' % (tenant
, datacenter
)),
99 'datacenter_id': uuid('dc%d' % datacenter
),
103 def datacenter_tenant_association(datacenter
, tenant
):
104 return {'nfvo_tenant_id': uuid('tenant%d' % tenant
),
105 'datacenter_id': uuid('dc%d' % datacenter
),
106 'datacenter_tenant_id':
107 uuid('dc-account%d%d' % (tenant
, datacenter
))}
110 def datacenter_set(identifier
, tenant
):
111 """Records necessary to create a datacenter and connect it to a tenant"""
113 {'datacenters': [datacenter(identifier
)]},
114 {'datacenter_tenants': [datacenter_account(identifier
, tenant
)]},
115 {'tenants_datacenters': [
116 datacenter_tenant_association(identifier
, tenant
)
121 def wim_port_mapping(wim
, datacenter
,
122 pop_dpid
='AA:AA:AA:AA:AA:AA:AA:AA', pop_port
=0,
123 wan_dpid
='BB:BB:BB:BB:BB:BB:BB:BB', wan_port
=0):
124 mapping_info
= {'mapping_type': 'dpid-port',
125 'wan_switch_dpid': wan_dpid
,
126 'wan_switch_port': wan_port
+ datacenter
+ 1}
127 id_
= 'dpid-port|' + sha1(json
.dumps(mapping_info
, sort_keys
=True))
129 return {'wim_id': uuid('wim%d' % wim
),
130 'datacenter_id': uuid('dc%d' % datacenter
),
131 'pop_switch_dpid': pop_dpid
,
132 'pop_switch_port': pop_port
+ wim
+ 1,
133 # ^ Datacenter router have one port managed by each WIM
134 'wan_service_endpoint_id': id_
,
135 # ^ WIM managed router have one port connected to each DC
136 'wan_service_mapping_info': json
.dumps(mapping_info
)}
139 def processed_port_mapping(wim
, datacenter
,
141 pop_dpid
='AA:AA:AA:AA:AA:AA:AA:AA',
142 wan_dpid
='BB:BB:BB:BB:BB:BB:BB:BB'):
143 """Emulate the response of the Persistence class, where the records in the
144 data base are grouped by wim and datacenter
147 'wim_id': uuid('wim%d' % wim
),
148 'datacenter_id': uuid('dc%d' % datacenter
),
149 'wan_pop_port_mappings': [
150 {'pop_switch_dpid': pop_dpid
,
151 'pop_switch_port': wim
+ 1 + i
,
152 'wan_service_endpoint_id':
153 sha1('dpid-port|%s|%d' % (wan_dpid
, datacenter
+ 1 + i
)),
154 'wan_service_mapping_info': {
155 'mapping_type': 'dpid-port',
156 'wan_switch_dpid': wan_dpid
,
157 'wan_switch_port': datacenter
+ 1 + i
}}
158 for i
in range(num_pairs
)
163 def consistent_set(num_wims
=NUM_WIMS
, num_tenants
=NUM_TENANTS
,
164 num_datacenters
=NUM_DATACENTERS
):
166 {'nfvo_tenants': [tenant(i
) for i
in range(num_tenants
)]},
167 {'wims': [wim(j
) for j
in range(num_wims
)]},
170 for i
in range(num_tenants
)
171 for j
in range(num_wims
)
173 {'wim_nfvo_tenants': [
174 wim_tenant_association(j
, i
)
175 for i
in range(num_tenants
)
176 for j
in range(num_wims
)
180 for k
in range(num_datacenters
)
182 {'datacenter_tenants': [
183 datacenter_account(k
, i
)
184 for i
in range(num_tenants
)
185 for k
in range(num_datacenters
)
187 {'tenants_datacenters': [
188 datacenter_tenant_association(k
, i
)
189 for i
in range(num_tenants
)
190 for k
in range(num_datacenters
)
192 {'wim_port_mappings': [
193 wim_port_mapping(j
, k
)
194 for j
in range(num_wims
)
195 for k
in range(num_datacenters
)
200 def instance_nets(num_datacenters
=2, num_links
=2):
201 """Example of multi-site deploy with N datacenters and M WAN links between
202 them (e.g M = 2 -> back and forth)
205 {'uuid': uuid('net%d%d' % (k
, l
)),
206 'datacenter_id': uuid('dc%d' % k
),
207 'datacenter_tenant_id': uuid('dc-account0%d' % k
),
208 'instance_scenario_id': uuid('nsr0'),
209 # ^ instance_scenario_id == NS Record id
210 'sce_net_id': uuid('vld%d' % l
),
211 # ^ scenario net id == VLD id
215 for k
in range(num_datacenters
)
216 for l
in range(num_links
)
220 def wim_actions(action
='CREATE', status
='SCHEDULED',
221 action_id
=None, instance
=0,
222 wim
=0, tenant
=0, num_links
=1):
223 """Create a list of actions for the WIM,
226 action: type of action (CREATE) by default
227 wim: WIM fixture index to create actions for
228 tenant: tenant fixture index to create actions for
229 num_links: number of WAN links to be established by each WIM
232 action_id
= action_id
or 'ACTION-{}'.format(time())
237 'wim_internal_id': uuid('-wim-net%d%d%d' % (wim
, instance
, link
)),
238 'wim_account_id': uuid('wim-account%d%d' % (tenant
, wim
)),
239 'instance_action_id': action_id
,
240 'item': 'instance_wim_nets',
241 'item_id': uuid('wim-net%d%d%d' % (wim
, instance
, link
)),
244 'created_at': time(),
245 'modified_at': time(),
248 for link
in range(num_links
)
252 def instance_action(tenant
=0, instance
=0, action_id
=None,
253 num_tasks
=1, num_done
=0, num_failed
=0):
254 action_id
= action_id
or 'ACTION-{}'.format(time())
258 'tenant_id': uuid('tenant%d' % tenant
),
259 'instance_id': uuid('nsr%d' % instance
),
260 'number_tasks': num_tasks
,
261 'number_done': num_done
,
262 'number_failed': num_failed
,
266 def instance_wim_nets(instance
=0, wim
=0, num_links
=1,
267 status
='SCHEDULED_CREATION'):
268 """Example of multi-site deploy with N wims and M WAN links between
269 them (e.g M = 2 -> back and forth)
273 {'uuid': uuid('wim-net%d%d%d' % (wim
, instance
, l
)),
274 'wim_id': uuid('wim%d' % wim
),
275 'wim_account_id': uuid('wim-account%d' % wim
),
276 'wim_internal_id': uuid('-net%d%d' % (wim
, l
)),
277 'instance_scenario_id': uuid('nsr%d' % instance
),
278 # ^ instance_scenario_id == NS Record id
279 'sce_net_id': uuid('vld%d' % l
),
280 # ^ scenario net id == VLD id
283 for l
in range(num_links
)
287 def instance_vm(instance
=0, vim_info
=None):
288 vim_info
= {'OS-EXT-SRV-ATTR:hypervisor_hostname': 'host%d' % instance
}
290 'uuid': uuid('vm%d' % instance
),
291 'instance_vnf_id': uuid('vnf%d' % instance
),
292 'vm_id': uuid('vm%d' % instance
),
293 'vim_vm_id': uuid('vm%d' % instance
),
295 'vim_info': vim_info
,
299 def instance_interface(instance
=0, interface
=0, datacenter
=0, link
=0):
301 'uuid': uuid('interface%d%d' % (instance
, interface
)),
302 'instance_vm_id': uuid('vm%d' % instance
),
303 'instance_net_id': uuid('net%d%d' % (datacenter
, link
)),
304 'interface_id': uuid('iface%d' % interface
),