| 1 |
# Licensed under the Apache License, Version 2.0 (the "License"); you may |
| 2 |
# not use this file except in compliance with the License. You may obtain |
| 3 |
# a copy of the License at |
| 4 |
# |
| 5 |
# http://www.apache.org/licenses/LICENSE-2.0 |
| 6 |
# |
| 7 |
# Unless required by applicable law or agreed to in writing, software |
| 8 |
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 9 |
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
| 10 |
# License for the specific language governing permissions and limitations |
| 11 |
# under the License. |
| 12 |
|
| 13 |
from neutron_lib.api.definitions import tap_mirror as tap_m_api_def |
| 14 |
from oslo_log import helpers as log_helpers |
| 15 |
from oslo_log import log as logging |
| 16 |
|
| 17 |
from neutron_taas.services.taas import service_drivers |
| 18 |
from neutron_taas.services.taas.service_drivers.ovn import helper |
| 19 |
|
| 20 |
|
| 21 |
LOG = logging.getLogger(__name__) |
| 22 |
|
| 23 |
|
| 24 |
class TaasOvnDriver(service_drivers.TaasBaseDriver): |
| 25 |
"""Taas OVN Service Driver class""" |
| 26 |
|
| 27 |
driver_name = "TaaS OVN Driver" |
| 28 |
more_supported_extension_aliases = [tap_m_api_def.ALIAS] |
| 29 |
|
| 30 |
def __init__(self, service_plugin): |
| 31 |
LOG.debug("Loading Taas OVN Driver.") |
| 32 |
super().__init__(service_plugin) |
| 33 |
self._ovn_helper = helper.TaasOvnProviderHelper() |
| 34 |
|
| 35 |
def __del__(self): |
| 36 |
self._ovn_helper.shutdown() |
| 37 |
|
| 38 |
@log_helpers.log_method_call |
| 39 |
def create_tap_service_precommit(self, context): |
| 40 |
raise NotImplementedError( |
| 41 |
f"Create tap service is not supported by {self.driver_name}.") |
| 42 |
|
| 43 |
@log_helpers.log_method_call |
| 44 |
def create_tap_service_postcommit(self, context): |
| 45 |
raise NotImplementedError( |
| 46 |
f"Create tap service is not supported by {self.driver_name}.") |
| 47 |
|
| 48 |
@log_helpers.log_method_call |
| 49 |
def delete_tap_service_precommit(self, context): |
| 50 |
raise NotImplementedError( |
| 51 |
f"Delete tap service is not supported by {self.driver_name}.") |
| 52 |
|
| 53 |
@log_helpers.log_method_call |
| 54 |
def delete_tap_service_postcommit(self, context): |
| 55 |
raise NotImplementedError( |
| 56 |
f"Delete tap service is not supported by {self.driver_name}.") |
| 57 |
|
| 58 |
@log_helpers.log_method_call |
| 59 |
def create_tap_flow_precommit(self, context): |
| 60 |
raise NotImplementedError( |
| 61 |
f"Create tap flow is not supported by {self.driver_name}.") |
| 62 |
|
| 63 |
@log_helpers.log_method_call |
| 64 |
def create_tap_flow_postcommit(self, context): |
| 65 |
raise NotImplementedError( |
| 66 |
f"Create tap flow is not supported by {self.driver_name}.") |
| 67 |
|
| 68 |
@log_helpers.log_method_call |
| 69 |
def delete_tap_flow_precommit(self, context): |
| 70 |
raise NotImplementedError( |
| 71 |
f"Delete tap flow is not supported by {self.driver_name}.") |
| 72 |
|
| 73 |
@log_helpers.log_method_call |
| 74 |
def delete_tap_flow_postcommit(self, context): |
| 75 |
raise NotImplementedError( |
| 76 |
f"Delete tap flow is not supported by {self.driver_name}.") |
| 77 |
|
| 78 |
@log_helpers.log_method_call |
| 79 |
def create_tap_mirror_precommit(self, context): |
| 80 |
pass |
| 81 |
|
| 82 |
@log_helpers.log_method_call |
| 83 |
def create_tap_mirror_postcommit(self, context): |
| 84 |
LOG.info('create_tap_mirror_postcommit %s', context.tap_mirror) |
| 85 |
t_m = context.tap_mirror |
| 86 |
type = 'erspan' if 'erspan' in t_m['mirror_type'] else 'gre' |
| 87 |
directions = t_m['directions'] |
| 88 |
for direction, tunnel_id in directions.items(): |
| 89 |
mirror_port_name = 'tm_%s_%s' % (direction.lower(), t_m['id'][0:6]) |
| 90 |
ovn_direction = ('from-lport' if direction == 'OUT' |
| 91 |
else 'to-lport' if direction == 'IN' |
| 92 |
else 'both') |
| 93 |
request = {'type': 'mirror_add', |
| 94 |
'info': {'name': mirror_port_name, |
| 95 |
'direction_filter': ovn_direction, |
| 96 |
'dest': t_m['remote_ip'], |
| 97 |
'mirror_type': type, |
| 98 |
'index': int(tunnel_id), |
| 99 |
'port_id': t_m['port_id']}} |
| 100 |
self._ovn_helper.add_request(request) |
| 101 |
|
| 102 |
@log_helpers.log_method_call |
| 103 |
def delete_tap_mirror_precommit(self, context): |
| 104 |
LOG.info('delete_tap_mirror_precommit %s', context.tap_mirror) |
| 105 |
t_m = context.tap_mirror |
| 106 |
directions = t_m['directions'] |
| 107 |
for direction, tunnel_id in directions.items(): |
| 108 |
mirror_port_name = 'tm_%s_%s' % (direction.lower(), t_m['id'][0:6]) |
| 109 |
request = { |
| 110 |
'type': 'mirror_del', |
| 111 |
'info': {'id': t_m['id'], |
| 112 |
'name': mirror_port_name, |
| 113 |
'sink': t_m['remote_ip'], |
| 114 |
'port_id': t_m['port_id']} |
| 115 |
} |
| 116 |
self._ovn_helper.add_request(request) |
| 117 |
|
| 118 |
@log_helpers.log_method_call |
| 119 |
def delete_tap_mirror_postcommit(self, context): |
| 120 |
pass |