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 """The WIM connector is responsible for establishing wide area network
37 It receives information from the WimThread/WAN Actions about the endpoints of
38 a link that spans across multiple datacenters and stablish a path between them.
42 from ..http_tools
.errors
import HttpMappedError
45 class WimConnectorError(HttpMappedError
):
46 """Base Exception for all connector related errors"""
49 class WimConnector(object):
50 """Abstract base class for all the WIM connectors
53 wim (dict): WIM record, as stored in the database
54 wim_account (dict): WIM account record, as stored in the database
55 config (dict): optional persistent information related to an specific
56 connector. Inside this dict, a special key,
57 ``service_endpoint_mapping`` provides the internal endpoint
59 logger (logging.Logger): optional logger object. If none is passed
60 ``openmano.wim.wimconn`` is used.
62 The arguments of the constructor are converted to object attributes.
63 An extra property, ``service_endpoint_mapping`` is created from ``config``.
65 def __init__(self
, wim
, wim_account
, config
=None, logger
=None):
66 self
.logger
= logger
or logging
.getLogger('openmano.wim.wimconn')
69 self
.wim_account
= wim_account
70 self
.config
= config
or {}
71 self
.service_endpoint_mapping
= (
72 config
.get('service_endpoint_mapping', []))
74 def check_credentials(self
):
75 """Check if the connector itself can access the WIM.
78 WimConnectorError: Issues regarding authorization, access to
79 external URLs, etc are detected.
81 raise NotImplementedError
83 def get_connectivity_service_status(self
, service_uuid
, conn_info
=None):
84 """Monitor the status of the connectivity service established
87 service_uuid (str): UUID of the connectivity service
88 conn_info (dict or None): Information returned by the connector
89 during the service creation/edition and subsequently stored in
93 dict: JSON/YAML-serializable dict that contains a mandatory key
94 ``wim_status`` associated with one of the following values::
96 {'wim_status': 'ACTIVE'}
97 # The service is up and running.
99 {'wim_status': 'INACTIVE'}
100 # The service was created, but the connector
101 # cannot determine yet if connectivity exists
102 # (ideally, the caller needs to wait and check again).
104 {'wim_status': 'DOWN'}
105 # Connection was previously established,
106 # but an error/failure was detected.
108 {'wim_status': 'ERROR'}
109 # An error occurred when trying to create the service/
110 # establish the connectivity.
112 {'wim_status': 'BUILD'}
113 # Still trying to create the service, the caller
114 # needs to wait and check again.
116 Additionally ``error_msg``(**str**) and ``wim_info``(**dict**)
117 keys can be used to provide additional status explanation or
118 new information available for the connectivity service.
120 raise NotImplementedError
122 def create_connectivity_service(self
, service_type
, connection_points
,
124 """Stablish WAN connectivity between the endpoints
127 service_type (str): ``ELINE`` (L2), ``ELAN`` (L2), ``ETREE`` (L2),
129 connection_points (list): each point corresponds to
130 an entry point from the DC to the transport network. One
131 connection point serves to identify the specific access and
132 some other service parameters, such as encapsulation type.
133 Represented by a dict as follows::
136 "service_endpoint_id": ..., (str[uuid])
137 "service_endpoint_encapsulation_type": ...,
138 (enum: none, dot1q, ...)
139 "service_endpoint_encapsulation_info": {
141 "vlan": ..., (int, present if encapsulation is dot1q)
142 "vni": ... (int, present if encapsulation is vxlan),
143 "peers": [(ipv4_1), (ipv4_2)]
144 (present if encapsulation is vxlan)
148 The service endpoint ID should be previously informed to the WIM
149 engine in the RO when the WIM port mapping is registered.
152 bandwidth (int): value in kilobytes
153 latency (int): value in milliseconds
155 Other QoS might be passed as keyword arguments.
158 tuple: ``(service_id, conn_info)`` containing:
159 - *service_uuid* (str): UUID of the established connectivity
161 - *conn_info* (dict or None): Information to be stored at the
162 database (or ``None``). This information will be provided to
163 the :meth:`~.edit_connectivity_service` and :obj:`~.delete`.
164 **MUST** be JSON/YAML-serializable (plain data structures).
167 WimConnectorException: In case of error.
169 raise NotImplementedError
171 def delete_connectivity_service(self
, service_uuid
, conn_info
=None):
172 """Disconnect multi-site endpoints previously connected
174 This method should receive as arguments both the UUID and the
175 connection info dict (respectively), as returned by
176 :meth:`~.create_connectivity_service` and
177 :meth:`~.edit_connectivity_service`.
180 service_uuid (str): UUID of the connectivity service
181 conn_info (dict or None): Information returned by the connector
182 during the service creation and subsequently stored in the
186 WimConnectorException: In case of error.
188 raise NotImplementedError
190 def edit_connectivity_service(self
, service_uuid
, conn_info
=None,
191 connection_points
=None, **kwargs
):
192 """Change an existing connectivity service.
194 This method's arguments and return value follow the same convention as
195 :meth:`~.create_connectivity_service`.
198 service_uuid (str): UUID of the connectivity service.
199 conn_info (dict or None): Information previously stored in the
201 connection_points (list): If provided, the old list of connection
202 points will be replaced.
205 dict or None: Information to be updated and stored at the
207 When ``None`` is returned, no information should be changed.
208 When an empty dict is returned, the database record will be
210 **MUST** be JSON/YAML-serializable (plain data structures).
213 WimConnectorException: In case of error.
215 raise NotImplementedError
217 def clear_all_connectivity_services(self
):
218 """Delete all WAN Links in a WIM.
220 This method is intended for debugging only, and should delete all the
221 connections controlled by the WIM, not only the WIM connections that
222 a specific RO is aware of.
225 WimConnectorException: In case of error.
227 raise NotImplementedError
229 def get_all_active_connectivity_services(self
):
230 """Provide information about all active connections provisioned by a
234 WimConnectorException: In case of error.
236 raise NotImplementedError