3 # ============LICENSE_START===================================================
4 # Copyright (C) 2021 Samsung Electronics
5 # ============================================================================
6 # Licensed under the Apache License, Version 2.0 (the "License");
7 # you may not use this file except in compliance with the License.
8 # You may obtain a copy of the License at
10 # http://www.apache.org/licenses/LICENSE-2.0
12 # Unless required by applicable law or agreed to in writing, software
13 # distributed under the License is distributed on an "AS IS" BASIS,
14 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 # See the License for the specific language governing permissions and
16 # limitations under the License.
18 # SPDX-License-Identifier: Apache-2.0
19 # ============LICENSE_END=====================================================
21 from onapsdk.sdc.category_management import ServiceCategory
22 from onapsdk.sdc.service import Service
23 from onapsdk.sdc.properties import Property, ParameterError
24 from onapsdk.sdc.vf import Vf
25 from onapsdk.sdc.vsp import Vsp
26 from onapsdk.sdc.vfc import Vfc
27 from onapsdk.sdc.vendor import Vendor
29 from time import sleep
30 import onapsdk.constants as const
31 from onapsdk.exceptions import APIError, ResourceNotFound
37 logger = logging.getLogger("")
38 logger.setLevel(logging.DEBUG)
39 fh = logging.StreamHandler()
40 fh_formatter = logging.Formatter('%(asctime)s %(levelname)s %(lineno)d:%(filename)s(%(process)d) - %(message)s')
41 fh.setFormatter(fh_formatter)
46 def create_name(name, suffix=SUFFIX):
47 """ helper function to create uniqe name by appending
48 predefined suffix, may be helpful during testing
49 as ONAP does not allow for easy deeltion of services"""
53 def create_service_category(category_names):
54 for cn in category_names:
55 logger.info('creating service category [%s]', cn)
56 ServiceCategory.create(name=cn)
59 def create_vendor(vendor_name):
60 vendor = Vendor(vendor_name)
65 logger.warn("Exception during vendor onboarding, ", e)
71 def create_vsp(name, vendor, onboard=False):
72 logger.info("creating vsp: [%s:%s]", name, vendor)
76 vsp = Vsp(name=name, vendor=vendor)
82 except ResourceNotFound as e:
83 logger.warn(f"Failed to onboard {name}", e)
88 logger.warn("Exception during vsp onboarding, ", e)
96 def create_vf(name, category, vendor, onboard=False):
97 logger.info("create vf: [%s:%s]", name, category)
99 vfc = Vfc('AllottedResource') # seemd incorrect
100 vf = Vf(name=name, category=category, vendor=vendor)
102 if vf.status == const.DRAFT:
117 except ResourceNotFound as e:
125 logger.info("onboarded vf: [%s]", vf.name)
128 def create_service(name, category, vnfs=[], properties=[], role=None, service_type=None):
129 logger.info("create service: [%s:%s]", name, category)
133 srvc = Service(name=name, category=category, properties=properties, role=role, service_type=service_type)
138 if srvc.status == const.DRAFT:
140 srvc.add_resource(vnf)
142 if srvc.status != const.DISTRIBUTED:
144 except ResourceNotFound as e:
153 def create_service_1(name, category, vnfs=[], properties=[], role=None, service_type=None):
154 logger.info("create service: [%s:%s]", name, category)
158 srvc = Service(name=name, category=category, properties=properties, role=role, service_type=service_type)
163 if srvc.status == const.DRAFT:
165 srvc.add_resource(vnf)
166 for c in srvc.components:
167 if c.name == 'SLICE_AR 0':
168 cp = get_component_property(c, 'allottedresource0_providing_service_invariant_uuid')
170 logger.info('setting value on property [%s]', cp)
171 cp.value = "{\\\"get_input\\\":\\\"slice_ar0_allottedresource0_providing_service_invariant_uuid\\\"}"
173 raise ParameterError('no property providing_service_invariant_uuid found')
175 cp = get_component_property(c, 'allottedresource0_providing_service_uuid')
177 cp.value = "{\\\"get_input\\\":\\\"slice_ar0_allottedresource0_providing_service_uuid\\\"}"
179 raise ParameterError('no property providing_service_uuid found')
182 if srvc.status != const.DISTRIBUTED:
184 except ResourceNotFound as e:
194 def get_component_property(component, name):
197 prop = list(filter(lambda x: x.name == name, component.properties))
201 raise ParameterError('no property found')
202 except ParameterError as e:
203 logger.warn("component [%s] has no property [%s]", component.name, name)
206 logger.info("retrived property [%s] for component [%s]", prop.name if prop else 'null', component.name)
211 vendor = create_vendor('aaaa')
212 vsp = create_vsp('test1', vendor)
214 # create custom categories
215 create_service_category(['CST', 'ServiceProfile', 'AN SliceProfile', 'AN NF Slice Profile',
216 'CN SliceProfile', 'TN SliceProfile', 'NST', 'TN BH NSST', 'Alloted Resource',
217 'TN MH NSST', 'TN FH NSST', 'TN Network Requirement', 'AN NF NSST', 'CN NSST', 'AN NSST'])
219 props = [Property('ConnectionLink', 'string', value='{\\"get_input\\":\\"ConnectionLink\\"}'),
220 Property('jitter', 'string', value='10'),
221 Property('latency', 'integer', value=10),
222 Property('maxBandwith', 'integer', value=1000)]
224 srv = create_service(create_name('TN_Network_Requirement'), 'TN Network Requirement', properties=props)
225 vf = create_vf(create_name('TN_Network_Req_AR'), 'Alloted Resource', vendor)
226 for c in vf.components:
227 if c.name == 'AllottedResource 0':
228 c.get_property('providing_service_invariant_uuid').value = srv.unique_uuid
229 c.get_property('providing_service_uuid').value = srv.identifier
230 c.get_property('providing_service_name').value = srv.name
234 props = [Property('pLMNIdList', 'string', value='39-00'),
235 Property('jitter', 'string', value='10'),
236 Property('latency', 'integer', value=10),
237 Property('maxBandwith', 'integer', value=1000)]
240 srv = create_service(create_name('Tn_ONAP_internal_BH'), 'TN BH NSST', vnfs=[vf], role='ONAP_internal',
243 vf_tn_bh_ar = create_vf(create_name('Tn_BH_AR'), 'Alloted Resource', vendor)
244 for c in vf_tn_bh_ar.components:
245 if c.name == 'AllottedResource 0':
246 c.get_property('providing_service_invariant_uuid').value = srv.unique_uuid
247 c.get_property('providing_service_uuid').value = srv.identifier
248 c.get_property('providing_service_name').value = srv.name
250 onboard_vf(vf_tn_bh_ar)
253 props = [Property('anNSSCap', 'org.openecomp.datatypes.NSSCapabilities')]
254 srv = create_service(create_name('EmbbAn_NF'), 'AN NF NSST', role='huawei', service_type='embb', properties=props)
256 vf_embban_nf_ar = create_vf(create_name('EmbbAn_NF_AR'), 'Alloted Resource', vendor)
257 for c in vf_embban_nf_ar.components:
258 if c.name == 'AllottedResource 0':
259 c.get_property('providing_service_invariant_uuid').value = srv.unique_uuid
260 c.get_property('providing_service_uuid').value = srv.identifier
261 c.get_property('providing_service_name').value = srv.name
264 onboard_vf(vf_embban_nf_ar)
267 props = [Property('activityFactor', 'org.openecomp.datatypes.NSSCapabilities', '30'),
268 Property('areaTrafficCapDL', 'org.openecomp.datatypes.NSSCapabilities', '800'),
269 Property('areaTrafficCapUL', 'org.openecomp.datatypes.NSSCapabilities', '800'),
270 Property('expDataRateDL', 'org.openecomp.datatypes.NSSCapabilities', '1000'),
271 Property('expDataReateUL', 'org.openecomp.datatypes.NSSCapabilities', '1000')]
273 srv = Service(name=create_name('EmbbCn_External'),
277 properties=[Property('aname', 'org.openecomp.datatypes.NSSCapabilities',
278 value="[{\\\"latency\\\":35,\\\"maxNumberofUEs\\\":1005,\\\"resourceSharingLevel\\\":\\\"Shared\\\",\\\"sST\\\":\\\"eMBB\\\",\\\"activityFactor\\\":30,\\\"areaTrafficCapDL\\\":800,\\\"areaTrafficCapUL\\\":1000}]")])
282 if srv.status == const.DRAFT:
283 srv.add_deployment_artifact(artifact_type="WORKFLOW", artifact_name="eMBB.zip", artifact="./eMBB.zip",
284 artifact_label="abc")
286 if srv.status != const.DISTRIBUTED:
293 except ResourceNotFound as e:
304 vf_embbcn_external_ar = create_vf(create_name('EmbbCn_External_AR'), 'Alloted Resource', vendor)
305 for c in vf_embbcn_external_ar.components:
306 if c.name == 'AllottedResource 0':
307 c.get_property('providing_service_invariant_uuid').value = srv.unique_uuid
308 c.get_property('providing_service_uuid').value = srv.identifier
309 c.get_property('providing_service_name').value = srv.name
311 onboard_vf(vf_embbcn_external_ar)
313 logger.info("create service EmbbNst_O2")
315 srv = create_service(create_name('EmbbNst_O2'),
318 vnfs = [vf_embbcn_external_ar, vf_embban_nf_ar, vf_tn_bh_ar],
319 properties=[Property('aname', 'org.openecomp.datatypes.NSSCapabilities',
320 value="[{\\\"latency\\\":20,\
321 \\\"maxNumberofUEs\\\":1000,\
322 \\\"maxNumberofConns\\\":100000,\
323 \\\"resourceSharingLevel\\\":\\\"Shared\\\",\
324 \\\"sST\\\":\\\"eMBB\\\",\
325 \\\"activityFactor\\\":60,\
326 \\\"availability\\\":0.6,\
327 \\\"dLThptPerSlice\\\":1000,\
328 \\\"uLThptPerSlice\\\":1000,\
330 \\\"survivalTime\\\":10,\
331 \\\"ueMobilityLevel\\\":\\\"stationary\\\",\
332 \\\"pLMNIdList\\\":\\\"39-00\\\",\
333 \\\"reliability\\\":\\\"99%\\\"}]")])
336 logger.info("create Slice_AR")
337 vf = create_vf(create_name('Slice_AR'), 'Allotted Resource', vendor)
338 for c in vf.components:
339 if c.name == 'AllottedResource 0':
340 cp = get_component_property(c, 'providing_service_invariant_uuid')
342 logger.info('setting value on property [%s]', cp)
343 cp.value = "{\\\"get_input\\\":\\\"allottedresource0_providing_service_invariant_uuid\\\"}"
345 raise ParameterError('no property providing_service_invariant_uuid found')
347 cp = get_component_property(c, 'providing_service_uuid')
349 cp.value = "{\\\"get_input\\\":\\\"allottedresource0_providing_service_uuid\\\"}"
351 raise ParameterError('no property providing_service_uuid found')
357 slice_profile = '[{' \
358 '\\"activityFactor\\":{\\"get_input\\":\\"anSP_activityFactor\\"},' \
359 '\\"areaTrafficCapDL\\":{\\"get_input\\":\\"anSP_areaTrafficCapDL\\"},' \
360 '\\"areaTrafficCapUL\\":{\\"get_input\\":\\"anSP_areaTrafficCapUL\\"},' \
361 '\\"cSAvailabilityTarget\\":{\\"get_input\\":\\"anSP_cSAvailabilityTarget\\"},' \
362 '\\"cSRealibilityMeanTime\\":{\\"get_input\\":\\"anSP_cSRealibilityMeanTime\\"}}]'
363 an_slice_profile = [Property('anSP', 'org.openecomp.datatypes.SliceProfile', slice_profile),
364 Property('ipAddress', 'string', '{\\"get_input\\":\\"ipAddress\\"}'),
365 Property('logicInterfaceId', 'string', '{\\"get_input\\":\\"logicInterfaceId\\"}'),
366 Property('nextHopInfo', 'string', '{\\"get_input\\":\\"nextHopInfo\\"}')]
368 logger.info("create service Slice Profile AN O2")
369 srv_slice_profile_an_o2 = create_service_1(create_name('SliceProfile_AN_O2'),
371 properties = an_slice_profile,
375 logger.info('create service SliceProfile_TN')
376 tn_slice_profile = [Property('jitter', 'string', '{\\"get_input\\":\\"jitter\\"}'),
377 Property('latency', 'integer', '{\\"get_input\\":\\"latency\\"}'),
378 Property('pLMNIdList', 'string', '{\\"get_input\\":\\"pLMNIdList\\"}'),
379 Property('sNSSAI', 'string', '{\\"get_input\\":\\"sNSSAI\\"}'),
380 Property('sST', 'integer', '{\\"get_input\\":\\"sST\\"}'),
381 Property('maxBandwidth', 'integer', '{\\"get_input\\":\\"maxBandwidth\\"}')]
384 srv_slice_profile_tn = create_service_1(create_name('SliceProfile_TN'),
387 properties = tn_slice_profile)
390 logger.info('create slice SliceProfile_CN')
391 cn_slice_profile = [Property('ipAddress', 'string', '{\\"get_input\\":\\"ipAddress\\"}'),
392 Property('logicInterfaceId', 'string', '{\\"get_input\\":\\"logicInterfaceId\\"}'),
393 Property('nextHopInfo', 'string', '{\\"get_input\\":\\"nextHopInfo\\"}')]
394 srv_slice_profile_cn = create_service_1(create_name('SliceProfile_CN'),
397 properties = cn_slice_profile)
400 logger.info('create service ServiceProfile O2')
401 service_profile = '[{' \
402 '\\"resourceSharingLevel\\":{\\"get_input\\":\\"spProp_resourceSharingLevel\\"},' \
403 '\\"sNSSAI\\":{\\"get_input\\":\\"spProp_sNSSAI\\"},' \
404 '\\"coverageAreaTAList\\":{\\"get_input\\":\\"spProp_coverageAreaTAList\\"},' \
405 '\\"sST\\":{\\"get_input\\":\\"spProp_sST\\"},' \
406 '\\"dLThptPerUE\\":{\\"get_input\\":\\"spProp_dLThptPerUE\\"},' \
407 '\\"uEMobilityLevel\\":{\\"get_input\\":\\"spProp_uEMobilityLevel\\"},'\
408 '\\"latency\\":{\\"get_input\\":\\"spProp_latency\\"},' \
409 '\\"uLThptPerUE\\":{\\"get_input\\":\\"spProp_uLThptPerUE\\"},' \
410 '\\"maxNumberofUEs\\":{\\"get_input\\":\\"spProp_maxNumberofUEs\\"}' \
412 service_props = [Property('spProp', 'org.openecomp.datatypes.ServiceProfile', slice_profile)]
413 srv_profile_o2 = create_service_1(create_name('ServiceProfile_O2'),
415 properties=service_props,
416 vnfs = [vf, srv_slice_profile_cn, srv_slice_profile_tn, srv_slice_profile_an_o2],
421 logger.info('create service CST O2')
423 '\\"coverageAreaList\\":{\\"get_input\\":\\"csProp_coverageAreaList\\"},' \
424 '\\"expDataRateDL\\":{\\"get_input\\":\\"csProp_expDataRateDL\\"},' \
425 '\\"expDataRateUL\\":{\\"get_input\\":\\"csProp_expDataRateUL\\"},' \
426 '\\"latency\\":{\\"get_input\\":\\"csProp_latency\\"},' \
427 '\\"maxNumberofUEs\\":{\\"get_input\\":\\"csProp_maxNumberofEUs\\"},' \
428 '\\"resourceSharingLevel\\":{\\"get_input\\":\\"csProp_resourceSharingLevel\\"},' \
429 '\\"uEMobilityLevel\\":{\\"get_input\\":\\"csProp_uEMobilityLevel\\"},' \
430 '\\"useInterval\\":{\\"get_input\\":\\"csProp_useInterval\\"},' \
432 srv = create_service_1(create_name('CST_O2'),
435 service_type = 'embb',
436 vnfs = [srv_profile_o2],
437 properties = [Property('csProp', 'org.openecomp.datatypes.CSProperties', props)])