blob: f5bcdae20694f20f82301a8ca802eaae87dc563b [file] [log] [blame]
gifrerenom0e517792023-04-18 16:38:42 +00001# -*- coding: utf-8 -*-
2
3#######################################################################################
4# This file is part of OSM RO module
5#
6# Copyright ETSI Contributors and Others.
7#
8# Licensed under the Apache License, Version 2.0 (the "License"); you may
9# not use this file except in compliance with the License. You may obtain
10# a copy of the License at
11#
12# http://www.apache.org/licenses/LICENSE-2.0
13#
14# Unless required by applicable law or agreed to in writing, software
15# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
16# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
17# License for the specific language governing permissions and limitations
18# under the License.
19#######################################################################################
20# This work has been performed in the context of the TeraFlow Project -
21# funded by the European Commission under Grant number 101015857 through the
22# Horizon 2020 program.
23# Contributors:
24# - Lluis Gifre <lluis.gifre@cttc.es>
25# - Ricard Vilalta <ricard.vilalta@cttc.es>
26#######################################################################################
27
28"""This file contains the helper methods used to compose the Transport API (TAPI)
29messages sent by the TAPI WIM connector to the WIM."""
30
31
32import copy
33
34from .message_templates import (
35 CREATE_TEMPLATE,
36 DELETE_TEMPLATE,
37 ENDPOINT_TEMPLATE,
38 REQUESTED_CAPACITY_TEMPLATE,
39 VLAN_CONSTRAINT_TEMPLATE,
40)
41
42
43def compose_requested_capacity(capacity, unit="GBPS"):
44 requested_capacity = copy.deepcopy(REQUESTED_CAPACITY_TEMPLATE)
45 total_size = requested_capacity["total-size"]
46 total_size["value"] = capacity
47 total_size["unit"] = "GBPS"
48 return requested_capacity
49
50
51def compose_vlan_constraint(vlan_id):
52 vlan_constraint = copy.deepcopy(VLAN_CONSTRAINT_TEMPLATE)
53 vlan_constraint["vlan-id"] = vlan_id
54 return vlan_constraint
55
56
57def compose_endpoint(sip):
58 sip_uuid = sip["uuid"]
59 endpoint = copy.deepcopy(ENDPOINT_TEMPLATE)
60 endpoint["service-interface-point"]["service-interface-point-uuid"] = sip_uuid
61 endpoint["layer-protocol-name"] = sip["layer-protocol-name"]
62 # TODO: implement smart selection of layer-protocol-qualifier instead of selecting first one available
63 supported_layer_protocol_qualifier = sip["supported-layer-protocol-qualifier"][0]
64 endpoint["layer-protocol-qualifier"] = supported_layer_protocol_qualifier
65 endpoint["local-id"] = sip_uuid
66 return endpoint
67
68
69def compose_create_request(
70 service_uuid,
71 endpoints,
72 bidirectional=False,
73 requested_capacity=None,
74 vlan_constraint=None,
75):
76 request = copy.deepcopy(CREATE_TEMPLATE)
77 con_svc = request["tapi-connectivity:connectivity-service"][0]
78 con_svc["uuid"] = service_uuid
79 con_svc["connectivity-direction"] = (
80 "BIDIRECTIONAL" if bidirectional else "UNIDIRECTIONAL"
81 )
82 con_svc["end-point"] = endpoints
83 if requested_capacity is not None:
84 con_svc["requested-capacity"] = requested_capacity
85 if vlan_constraint is not None:
86 con_svc["vlan-constraint"] = vlan_constraint
87 return request
88
89
90def compose_delete_request(service_uuid):
91 request = copy.deepcopy(DELETE_TEMPLATE)
92 request["tapi-connectivity:input"]["uuid"] = service_uuid
93 return request