1 # -*- coding: utf-8 -*-
3 #######################################################################################
4 # This file is part of OSM RO module
6 # Copyright ETSI Contributors and Others.
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
12 # http://www.apache.org/licenses/LICENSE-2.0
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
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.
24 # - Lluis Gifre <lluis.gifre@cttc.es>
25 # - Ricard Vilalta <ricard.vilalta@cttc.es>
26 #######################################################################################
28 """This file contains the helper methods used to compose the Transport API (TAPI)
29 messages sent by the TAPI WIM connector to the WIM."""
34 from .message_templates
import (
38 REQUESTED_CAPACITY_TEMPLATE
,
39 VLAN_CONSTRAINT_TEMPLATE
,
43 def 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
51 def compose_vlan_constraint(vlan_id
):
52 vlan_constraint
= copy
.deepcopy(VLAN_CONSTRAINT_TEMPLATE
)
53 vlan_constraint
["vlan-id"] = vlan_id
54 return vlan_constraint
57 def 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
69 def compose_create_request(
73 requested_capacity
=None,
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"
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
90 def compose_delete_request(service_uuid
):
91 request
= copy
.deepcopy(DELETE_TEMPLATE
)
92 request
["tapi-connectivity:input"]["uuid"] = service_uuid