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 SDN connector is responsible for establishing both wide area network connectivity (WIM)
35 and intranet SDN connectivity.
37 It receives information from ports to be connected .
41 from ..http_tools
.errors
import HttpMappedError
44 class SdnConnectorError(HttpMappedError
):
45 """Base Exception for all connector related errors
46 provide the parameter 'http_code' (int) with the error code:
48 Unauthorized = 401 (e.g. credentials are not valid)
49 Not_Found = 404 (e.g. try to edit or delete a non existing connectivity service)
51 Method_Not_Allowed = 405
53 Request_Timeout = 408 (e.g timeout reaching server, or cannot reach the server)
55 Service_Unavailable = 503
56 Internal_Server_Error = 500
60 class SdnConnectorBase(object):
61 """Abstract base class for all the SDN connectors
64 wim (dict): WIM record, as stored in the database
65 wim_account (dict): WIM account record, as stored in the database
67 The arguments of the constructor are converted to object attributes.
68 An extra property, ``service_endpoint_mapping`` is created from ``config``.
70 def __init__(self
, wim
, wim_account
, config
=None, logger
=None):
73 :param wim: (dict). Contains among others 'wim_url'
74 :param wim_account: (dict). Contains among others 'uuid' (internal id), 'name',
75 'sdn' (True if is intended for SDN-assist or False if intended for WIM), 'user', 'password'.
76 :param config: (dict or None): Particular information of plugin. These keys if present have a common meaning:
77 'mapping_not_needed': (bool) False by default or if missing, indicates that mapping is not needed.
78 'service_endpoint_mapping': (list) provides the internal endpoint mapping. The meaning is:
79 KEY meaning for WIM meaning for SDN assist
80 -------- -------- --------
81 device_id pop_switch_dpid compute_id
82 device_interface_id pop_switch_port compute_pci_address
83 service_endpoint_id wan_service_endpoint_id SDN_service_endpoint_id
84 service_mapping_info wan_service_mapping_info SDN_service_mapping_info
85 contains extra information if needed. Text in Yaml format
86 switch_dpid wan_switch_dpid SDN_switch_dpid
87 switch_port wan_switch_port SDN_switch_port
88 datacenter_id vim_account vim_account
89 id: (internal, do not use)
90 wim_id: (internal, do not use)
91 :param logger (logging.Logger): optional logger object. If none is passed 'openmano.sdn.sdnconn' is used.
93 self
.logger
= logger
or logging
.getLogger('openmano.sdnconn')
96 self
.wim_account
= wim_account
97 self
.config
= config
or {}
98 self
.service_endpoint_mapping
= (
99 self
.config
.get('service_endpoint_mapping', []))
101 def check_credentials(self
):
102 """Check if the connector itself can access the SDN/WIM with the provided url (wim.wim_url),
103 user (wim_account.user), and password (wim_account.password)
106 SdnConnectorError: Issues regarding authorization, access to
107 external URLs, etc are detected.
109 raise NotImplementedError
111 def get_connectivity_service_status(self
, service_uuid
, conn_info
=None):
112 """Monitor the status of the connectivity service established
115 service_uuid (str): UUID of the connectivity service
116 conn_info (dict or None): Information returned by the connector
117 during the service creation/edition and subsequently stored in
121 dict: JSON/YAML-serializable dict that contains a mandatory key
122 ``sdn_status`` associated with one of the following values::
124 {'sdn_status': 'ACTIVE'}
125 # The service is up and running.
127 {'sdn_status': 'INACTIVE'}
128 # The service was created, but the connector
129 # cannot determine yet if connectivity exists
130 # (ideally, the caller needs to wait and check again).
132 {'sdn_status': 'DOWN'}
133 # Connection was previously established,
134 # but an error/failure was detected.
136 {'sdn_status': 'ERROR'}
137 # An error occurred when trying to create the service/
138 # establish the connectivity.
140 {'sdn_status': 'BUILD'}
141 # Still trying to create the service, the caller
142 # needs to wait and check again.
144 Additionally ``error_msg``(**str**) and ``sdn_info``(**dict**)
145 keys can be used to provide additional status explanation or
146 new information available for the connectivity service.
148 raise NotImplementedError
150 def create_connectivity_service(self
, service_type
, connection_points
, **kwargs
):
152 Stablish SDN/WAN connectivity between the endpoints
153 :param service_type: (str): ``ELINE`` (L2), ``ELAN`` (L2), ``ETREE`` (L2), ``L3``.
154 :param connection_points: (list): each point corresponds to
155 an entry point to be connected. For WIM: from the DC to the transport network.
156 For SDN: Compute/PCI to the transport network. One
157 connection point serves to identify the specific access and
158 some other service parameters, such as encapsulation type.
159 Each item of the list is a dict with:
160 "service_endpoint_id": (str)(uuid) Same meaning that for 'service_endpoint_mapping' (see __init__)
161 In case the config attribute mapping_not_needed is True, this value is not relevant. In this case
162 it will contain the string "device_id:device_interface_id"
163 "service_endpoint_encapsulation_type": None, "dot1q", ...
164 "service_endpoint_encapsulation_info": (dict) with:
165 "vlan": ..., (int, present if encapsulation is dot1q)
166 "vni": ... (int, present if encapsulation is vxlan),
167 "peers": [(ipv4_1), (ipv4_2)] (present if encapsulation is vxlan)
169 "device_id": ..., same meaning that for 'service_endpoint_mapping' (see __init__)
170 "device_interface_id": same meaning that for 'service_endpoint_mapping' (see __init__)
171 "switch_dpid": ..., present if mapping has been found for this device_id,device_interface_id
172 "swith_port": ... present if mapping has been found for this device_id,device_interface_id
173 "service_mapping_info": present if mapping has been found for this device_id,device_interface_id
174 :param kwargs: For future versions:
175 bandwidth (int): value in kilobytes
176 latency (int): value in milliseconds
177 Other QoS might be passed as keyword arguments.
178 :return: tuple: ``(service_id, conn_info)`` containing:
179 - *service_uuid* (str): UUID of the established connectivity service
180 - *conn_info* (dict or None): Information to be stored at the database (or ``None``).
181 This information will be provided to the :meth:`~.edit_connectivity_service` and :obj:`~.delete`.
182 **MUST** be JSON/YAML-serializable (plain data structures).
183 :raises: SdnConnectorException: In case of error. Nothing should be created in this case.
184 Provide the parameter http_code
186 raise NotImplementedError
188 def delete_connectivity_service(self
, service_uuid
, conn_info
=None):
190 Disconnect multi-site endpoints previously connected
192 :param service_uuid: The one returned by create_connectivity_service
193 :param conn_info: The one returned by last call to 'create_connectivity_service' or 'edit_connectivity_service'
194 if they do not return None
196 :raises: SdnConnectorException: In case of error. The parameter http_code must be filled
198 raise NotImplementedError
200 def edit_connectivity_service(self
, service_uuid
, conn_info
=None, connection_points
=None, **kwargs
):
201 """ Change an existing connectivity service.
203 This method's arguments and return value follow the same convention as
204 :meth:`~.create_connectivity_service`.
206 :param service_uuid: UUID of the connectivity service.
207 :param conn_info: (dict or None): Information previously returned by last call to create_connectivity_service
208 or edit_connectivity_service
209 :param connection_points: (list): If provided, the old list of connection points will be replaced.
210 :param kwargs: Same meaning that create_connectivity_service
211 :return: dict or None: Information to be updated and stored at the database.
212 When ``None`` is returned, no information should be changed.
213 When an empty dict is returned, the database record will be deleted.
214 **MUST** be JSON/YAML-serializable (plain data structures).
216 SdnConnectorException: In case of error.
219 def clear_all_connectivity_services(self
):
220 """Delete all WAN Links in a WIM.
222 This method is intended for debugging only, and should delete all the
223 connections controlled by the WIM/SDN, not only the connections that
224 a specific RO is aware of.
227 SdnConnectorException: In case of error.
229 raise NotImplementedError
231 def get_all_active_connectivity_services(self
):
232 """Provide information about all active connections provisioned by a
236 SdnConnectorException: In case of error.
238 raise NotImplementedError