| 1 |
# Copyright (C) 2015 Ericsson AB |
| 2 |
# Copyright (c) 2015 Gigamon |
| 3 |
# |
| 4 |
# Licensed under the Apache License, Version 2.0 (the "License"); you may |
| 5 |
# not use this file except in compliance with the License. You may obtain |
| 6 |
# a copy of the License at |
| 7 |
# |
| 8 |
# http://www.apache.org/licenses/LICENSE-2.0 |
| 9 |
# |
| 10 |
# Unless required by applicable law or agreed to in writing, software |
| 11 |
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 12 |
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
| 13 |
# License for the specific language governing permissions and limitations |
| 14 |
# under the License. |
| 15 |
|
| 16 |
import collections |
| 17 |
|
| 18 |
from neutron.agent.common import ovs_lib |
| 19 |
from neutron.agent.linux import utils |
| 20 |
from neutron.conf.agent import common |
| 21 |
from neutron.conf.plugins.ml2.drivers import ovs_conf |
| 22 |
from neutron_lib.plugins.ml2 import ovs_constants as n_ovs_consts |
| 23 |
|
| 24 |
from neutron_taas.services.taas.agents.extensions import taas as taas_base |
| 25 |
import neutron_taas.services.taas.drivers.linux.ovs_constants \ |
| 26 |
as taas_ovs_consts |
| 27 |
import neutron_taas.services.taas.drivers.linux.ovs_utils as taas_ovs_utils |
| 28 |
from oslo_config import cfg |
| 29 |
from oslo_log import helpers as log_helpers |
| 30 |
from oslo_log import log as logging |
| 31 |
|
| 32 |
|
| 33 |
LOG = logging.getLogger(__name__) |
| 34 |
|
| 35 |
TaaS_DRIVER_NAME = 'Taas OVS driver' |
| 36 |
|
| 37 |
|
| 38 |
class OVSBridge_tap_extension(ovs_lib.OVSBridge): |
| 39 |
def __init__(self, br_name, |
| 40 |
root_helper, |
| 41 |
datapath_type=n_ovs_consts.OVS_DATAPATH_SYSTEM): |
| 42 |
super().__init__(br_name, datapath_type=datapath_type) |
| 43 |
|
| 44 |
|
| 45 |
class OvsTaasDriver(taas_base.TaasAgentDriver): |
| 46 |
def __init__(self): |
| 47 |
super().__init__() |
| 48 |
LOG.debug("Initializing Taas OVS Driver") |
| 49 |
self.agent_api = None |
| 50 |
self.root_helper = common.get_root_helper(cfg.CONF) |
| 51 |
ovs_conf.register_ovs_agent_opts(cfg.CONF) |
| 52 |
self.datapath_type = cfg.CONF.OVS.datapath_type |
| 53 |
self.tunnel_types = cfg.CONF.AGENT.tunnel_types |
| 54 |
|
| 55 |
def initialize(self): |
| 56 |
self.int_br = self.agent_api.request_int_br() |
| 57 |
self.tun_br = self.agent_api.request_tun_br() |
| 58 |
self.tap_br = OVSBridge_tap_extension('br-tap', |
| 59 |
self.root_helper, |
| 60 |
datapath_type=self.datapath_type) |
| 61 |
|
| 62 |
# Prepare OVS bridges for TaaS |
| 63 |
self.setup_ovs_bridges() |
| 64 |
|
| 65 |
# Setup key-value manager for ingress BCMC flows |
| 66 |
self.bcmc_kvm = taas_ovs_utils.key_value_mgr(4096) |
| 67 |
|
| 68 |
def periodic_tasks(self, args=None): |
| 69 |
# |
| 70 |
# Regenerate the flow in br-tun's TAAS_SEND_FLOOD table |
| 71 |
# to ensure all existing tunnel ports are included. |
| 72 |
# |
| 73 |
if self.tunnel_types: |
| 74 |
self.update_tunnel_flood_flow() |
| 75 |
|
| 76 |
def setup_ovs_bridges(self): |
| 77 |
# |
| 78 |
# br-int : Integration Bridge |
| 79 |
# br-tap : Tap Bridge |
| 80 |
# br-tun : Tunnel Bridge |
| 81 |
# |
| 82 |
|
| 83 |
# Create br-tap |
| 84 |
self.tap_br.create() |
| 85 |
|
| 86 |
# Connect br-tap to br-int and br-tun |
| 87 |
self.int_br.add_patch_port('patch-int-tap', 'patch-tap-int') |
| 88 |
self.tap_br.add_patch_port('patch-tap-int', 'patch-int-tap') |
| 89 |
if self.tunnel_types: |
| 90 |
self.tun_br.add_patch_port('patch-tun-tap', 'patch-tap-tun') |
| 91 |
self.tap_br.add_patch_port('patch-tap-tun', 'patch-tun-tap') |
| 92 |
|
| 93 |
# Get patch port IDs |
| 94 |
patch_tap_int_id = self.tap_br.get_port_ofport('patch-tap-int') |
| 95 |
if self.tunnel_types: |
| 96 |
patch_tap_tun_id = self.tap_br.get_port_ofport('patch-tap-tun') |
| 97 |
patch_tun_tap_id = self.tun_br.get_port_ofport('patch-tun-tap') |
| 98 |
|
| 99 |
# Purge all existing Taas flows from br-tap and br-tun |
| 100 |
self.tap_br.delete_flows(table=0) |
| 101 |
self.tap_br.delete_flows(table=taas_ovs_consts.TAAS_RECV_LOC) |
| 102 |
self.tap_br.delete_flows(table=taas_ovs_consts.TAAS_RECV_REM) |
| 103 |
|
| 104 |
if self.tunnel_types: |
| 105 |
self.tun_br.delete_flows(table=0, |
| 106 |
in_port=patch_tun_tap_id) |
| 107 |
self.tun_br.delete_flows(table=taas_ovs_consts.TAAS_SEND_UCAST) |
| 108 |
self.tun_br.delete_flows(table=taas_ovs_consts.TAAS_SEND_FLOOD) |
| 109 |
self.tun_br.delete_flows(table=taas_ovs_consts.TAAS_CLASSIFY) |
| 110 |
self.tun_br.delete_flows(table=taas_ovs_consts.TAAS_DST_CHECK) |
| 111 |
self.tun_br.delete_flows(table=taas_ovs_consts.TAAS_SRC_CHECK) |
| 112 |
self.tun_br.delete_flows(table=taas_ovs_consts.TAAS_DST_RESPOND) |
| 113 |
self.tun_br.delete_flows(table=taas_ovs_consts.TAAS_SRC_RESPOND) |
| 114 |
|
| 115 |
# |
| 116 |
# Configure standard TaaS flows in br-tun |
| 117 |
# |
| 118 |
self._setup_flows_for_tun_br(patch_tun_tap_id) |
| 119 |
# |
| 120 |
# Configure standard TaaS flows in br-tap |
| 121 |
# |
| 122 |
self.tap_br.add_flow(table=0, |
| 123 |
priority=1, |
| 124 |
in_port=patch_tap_int_id, |
| 125 |
actions="resubmit(,%s)" % |
| 126 |
taas_ovs_consts.TAAS_RECV_LOC) |
| 127 |
|
| 128 |
if self.tunnel_types: |
| 129 |
self.tap_br.add_flow(table=0, |
| 130 |
priority=1, |
| 131 |
in_port=patch_tap_tun_id, |
| 132 |
actions="resubmit(,%s)" % |
| 133 |
taas_ovs_consts.TAAS_RECV_REM) |
| 134 |
|
| 135 |
self.tap_br.add_flow(table=0, |
| 136 |
priority=0, |
| 137 |
actions="drop") |
| 138 |
|
| 139 |
if self.tunnel_types: |
| 140 |
self.tap_br.add_flow(table=taas_ovs_consts.TAAS_RECV_LOC, |
| 141 |
priority=0, |
| 142 |
actions="output:%s" % str(patch_tap_tun_id)) |
| 143 |
|
| 144 |
self.tap_br.add_flow(table=taas_ovs_consts.TAAS_RECV_REM, |
| 145 |
priority=0, |
| 146 |
actions="drop") |
| 147 |
|
| 148 |
def _setup_flows_for_tun_br(self, patch_tun_tap_id): |
| 149 |
# |
| 150 |
# Configure standard Taas flows in tun_br |
| 151 |
# |
| 152 |
self.tun_br.add_flow(table=0, |
| 153 |
priority=1, |
| 154 |
in_port=patch_tun_tap_id, |
| 155 |
actions="resubmit(,%s)" % |
| 156 |
taas_ovs_consts.TAAS_SEND_UCAST) |
| 157 |
|
| 158 |
self.tun_br.add_flow(table=taas_ovs_consts.TAAS_SEND_UCAST, |
| 159 |
priority=0, |
| 160 |
actions="resubmit(,%s)" % |
| 161 |
taas_ovs_consts.TAAS_SEND_FLOOD) |
| 162 |
|
| 163 |
flow_action = self._create_tunnel_flood_flow_action() |
| 164 |
if flow_action != "": |
| 165 |
self.tun_br.add_flow(table=taas_ovs_consts.TAAS_SEND_FLOOD, |
| 166 |
priority=0, |
| 167 |
actions=flow_action) |
| 168 |
|
| 169 |
self.tun_br.add_flow(table=taas_ovs_consts.TAAS_CLASSIFY, |
| 170 |
priority=2, |
| 171 |
reg0=0, |
| 172 |
actions="resubmit(,%s)" % |
| 173 |
taas_ovs_consts.TAAS_DST_CHECK) |
| 174 |
|
| 175 |
self.tun_br.add_flow(table=taas_ovs_consts.TAAS_CLASSIFY, |
| 176 |
priority=1, |
| 177 |
reg0=1, |
| 178 |
actions="resubmit(,%s)" % |
| 179 |
taas_ovs_consts.TAAS_DST_CHECK) |
| 180 |
|
| 181 |
self.tun_br.add_flow(table=taas_ovs_consts.TAAS_CLASSIFY, |
| 182 |
priority=1, |
| 183 |
reg0=2, |
| 184 |
actions="resubmit(,%s)" % |
| 185 |
taas_ovs_consts.TAAS_SRC_CHECK) |
| 186 |
|
| 187 |
self.tun_br.add_flow(table=taas_ovs_consts.TAAS_DST_CHECK, |
| 188 |
priority=0, |
| 189 |
actions="drop") |
| 190 |
|
| 191 |
self.tun_br.add_flow(table=taas_ovs_consts.TAAS_SRC_CHECK, |
| 192 |
priority=0, |
| 193 |
actions="drop") |
| 194 |
|
| 195 |
self.tun_br.add_flow(table=taas_ovs_consts.TAAS_DST_RESPOND, |
| 196 |
priority=2, |
| 197 |
reg0=0, |
| 198 |
actions="output:%s" % str(patch_tun_tap_id)) |
| 199 |
|
| 200 |
self.tun_br.add_flow( |
| 201 |
table=taas_ovs_consts.TAAS_DST_RESPOND, |
| 202 |
priority=1, reg0=1, |
| 203 |
actions=("output:%s," |
| 204 |
"move:NXM_OF_VLAN_TCI[0..11]->NXM_NX_TUN_ID" |
| 205 |
"[0..11],mod_vlan_vid:2,output:in_port" % |
| 206 |
str(patch_tun_tap_id))) |
| 207 |
|
| 208 |
self.tun_br.add_flow( |
| 209 |
table=taas_ovs_consts.TAAS_SRC_RESPOND, |
| 210 |
priority=1, |
| 211 |
actions=("learn(table=%s,hard_timeout=60," |
| 212 |
"priority=1,NXM_OF_VLAN_TCI[0..11]," |
| 213 |
"load:NXM_OF_VLAN_TCI[0..11]->NXM_NX_TUN_ID" |
| 214 |
"[0..11],load:0->NXM_OF_VLAN_TCI[0..11]," |
| 215 |
"output:NXM_OF_IN_PORT[])" % |
| 216 |
taas_ovs_consts.TAAS_SEND_UCAST)) |
| 217 |
|
| 218 |
def consume_api(self, agent_api): |
| 219 |
self.agent_api = agent_api |
| 220 |
|
| 221 |
@log_helpers.log_method_call |
| 222 |
def create_tap_service(self, tap_service_msg): |
| 223 |
"""Create a tap service |
| 224 |
|
| 225 |
:param tap_service_msg: a dict of the tap_service, |
| 226 |
taas_id which is the VLAN Id reserved for |
| 227 |
mirroring for this tap-service and the neutron |
| 228 |
port of the tap-service: |
| 229 |
{tap_service: {}, taas_id: VID, port: {}} |
| 230 |
""" |
| 231 |
taas_id = tap_service_msg['taas_id'] |
| 232 |
port = tap_service_msg['port'] |
| 233 |
|
| 234 |
# Get OVS port id for tap service port |
| 235 |
ovs_port = self.int_br.get_vif_port_by_id(port['id']) |
| 236 |
ovs_port_id = ovs_port.ofport |
| 237 |
|
| 238 |
# Get VLAN id for tap service port |
| 239 |
port_dict = self.int_br.get_port_tag_dict() |
| 240 |
port_vlan_id = port_dict[ovs_port.port_name] |
| 241 |
|
| 242 |
# Get patch port IDs |
| 243 |
patch_int_tap_id = self.int_br.get_port_ofport('patch-int-tap') |
| 244 |
patch_tap_int_id = self.tap_br.get_port_ofport('patch-tap-int') |
| 245 |
|
| 246 |
# Add flow(s) in br-int |
| 247 |
self.int_br.add_flow(table=0, |
| 248 |
priority=25, |
| 249 |
in_port=patch_int_tap_id, |
| 250 |
dl_vlan=taas_id, |
| 251 |
actions="mod_vlan_vid:%s,output:%s" % |
| 252 |
(str(port_vlan_id), str(ovs_port_id))) |
| 253 |
|
| 254 |
# Add flow(s) in br-tap |
| 255 |
self.tap_br.add_flow(table=taas_ovs_consts.TAAS_RECV_LOC, |
| 256 |
priority=1, |
| 257 |
dl_vlan=taas_id, |
| 258 |
actions="output:in_port") |
| 259 |
|
| 260 |
self.tap_br.add_flow(table=taas_ovs_consts.TAAS_RECV_REM, |
| 261 |
priority=1, |
| 262 |
dl_vlan=taas_id, |
| 263 |
actions="output:%s" % str(patch_tap_int_id)) |
| 264 |
|
| 265 |
# Add flow(s) in br-tun |
| 266 |
if self.tunnel_types: |
| 267 |
for tunnel_type in n_ovs_consts.TUNNEL_NETWORK_TYPES: |
| 268 |
self.tun_br.add_flow( |
| 269 |
table=n_ovs_consts.TUN_TABLE[tunnel_type], |
| 270 |
priority=1, |
| 271 |
tun_id=taas_id, |
| 272 |
actions=("move:NXM_OF_VLAN_TCI[0..11]->" |
| 273 |
"NXM_NX_REG0[0..11],move:NXM_NX_TUN_ID" |
| 274 |
"[0..11]->NXM_OF_VLAN_TCI[0..11]," |
| 275 |
"resubmit(,%s)" % |
| 276 |
taas_ovs_consts.TAAS_CLASSIFY)) |
| 277 |
|
| 278 |
self.tun_br.add_flow(table=taas_ovs_consts.TAAS_DST_CHECK, |
| 279 |
priority=1, |
| 280 |
tun_id=taas_id, |
| 281 |
actions="resubmit(,%s)" % |
| 282 |
taas_ovs_consts.TAAS_DST_RESPOND) |
| 283 |
|
| 284 |
# Get hybrid plug info |
| 285 |
vif_details = port.get('binding:vif_details') |
| 286 |
is_hybrid_plug = vif_details.get('ovs_hybrid_plug') |
| 287 |
|
| 288 |
if is_hybrid_plug: |
| 289 |
ovs_port_name = ovs_port.port_name |
| 290 |
linux_br_name = ovs_port_name.replace('qvo', 'qbr') |
| 291 |
utils.execute(['ip', 'link', 'set', linux_br_name, |
| 292 |
'type', 'bridge', 'ageing_time', 0], |
| 293 |
run_as_root=True, privsep_exec=True) |
| 294 |
|
| 295 |
@log_helpers.log_method_call |
| 296 |
def delete_tap_service(self, tap_service_msg): |
| 297 |
"""Delete a tap service |
| 298 |
|
| 299 |
:param tap_service_msg: a dict of the tap_service, |
| 300 |
taas_id which is the VLAN Id reserved for |
| 301 |
mirroring for this tap-service and the neutron |
| 302 |
port of the tap-service: |
| 303 |
{tap_service: {}, taas_id: VID, port: {}} |
| 304 |
""" |
| 305 |
taas_id = tap_service_msg['taas_id'] |
| 306 |
|
| 307 |
# Get patch port ID |
| 308 |
patch_int_tap_id = self.int_br.get_port_ofport('patch-int-tap') |
| 309 |
|
| 310 |
# Delete flow(s) from br-int |
| 311 |
self.int_br.delete_flows(table=0, |
| 312 |
in_port=patch_int_tap_id, |
| 313 |
dl_vlan=taas_id) |
| 314 |
|
| 315 |
# Delete flow(s) from br-tap |
| 316 |
self.tap_br.delete_flows(table=taas_ovs_consts.TAAS_RECV_LOC, |
| 317 |
dl_vlan=taas_id) |
| 318 |
|
| 319 |
self.tap_br.delete_flows(table=taas_ovs_consts.TAAS_RECV_REM, |
| 320 |
dl_vlan=taas_id) |
| 321 |
|
| 322 |
if self.tunnel_types: |
| 323 |
# Delete flow(s) from br-tun |
| 324 |
for tunnel_type in n_ovs_consts.TUNNEL_NETWORK_TYPES: |
| 325 |
self.tun_br.delete_flows( |
| 326 |
table=n_ovs_consts.TUN_TABLE[tunnel_type], |
| 327 |
tun_id=taas_id) |
| 328 |
|
| 329 |
self.tun_br.delete_flows(table=taas_ovs_consts.TAAS_DST_CHECK, |
| 330 |
tun_id=taas_id) |
| 331 |
|
| 332 |
self.tun_br.delete_flows(table=taas_ovs_consts.TAAS_SRC_CHECK, |
| 333 |
tun_id=taas_id) |
| 334 |
|
| 335 |
@log_helpers.log_method_call |
| 336 |
def create_tap_flow(self, tap_flow_msg): |
| 337 |
"""Create a tap flow |
| 338 |
|
| 339 |
:param tap_flow_msg: a dict of the tap_flow, the mac of the port of |
| 340 |
the tap-flow, taas_id which is the VLAN Id |
| 341 |
reserved for mirroring for the tap-service |
| 342 |
associated with this tap-flow, the neutron port |
| 343 |
of the tap-flow, and the port of the |
| 344 |
tap-service: |
| 345 |
{tap_flow: {}, port_mac: '', taas_id: VID, |
| 346 |
port: {}, tap_service_port: {}} |
| 347 |
""" |
| 348 |
taas_id = tap_flow_msg['taas_id'] |
| 349 |
port = tap_flow_msg['port'] |
| 350 |
direction = tap_flow_msg['tap_flow']['direction'] |
| 351 |
physical_network = tap_flow_msg['tf_nw']['physical_network'] \ |
| 352 |
if 'tf_nw' in tap_flow_msg else None |
| 353 |
network_type = tap_flow_msg['tf_nw']['network_type'] \ |
| 354 |
if 'tf_nw' in tap_flow_msg else None |
| 355 |
|
| 356 |
# Get OVS port id for tap flow port |
| 357 |
ovs_port = self.int_br.get_vif_port_by_id(port['id']) |
| 358 |
ovs_port_id = ovs_port.ofport |
| 359 |
|
| 360 |
# Get patch port ID |
| 361 |
patch_int_tap_id = self.int_br.get_port_ofport('patch-int-tap') |
| 362 |
|
| 363 |
# Add flow(s) in br-int |
| 364 |
if direction in ('OUT', 'BOTH'): |
| 365 |
self.int_br.add_flow(table=0, |
| 366 |
priority=20, |
| 367 |
in_port=ovs_port_id, |
| 368 |
actions="normal,mod_vlan_vid:%s,output:%s" % |
| 369 |
(str(taas_id), str(patch_int_tap_id))) |
| 370 |
|
| 371 |
if direction in ('IN', 'BOTH'): |
| 372 |
port_mac = tap_flow_msg['port_mac'] |
| 373 |
|
| 374 |
# |
| 375 |
# Note: The ingress side flow (for unicast traffic) should |
| 376 |
# include a check for the 'VLAN id of the Neutron |
| 377 |
# network the port belongs to' + 'MAC address of the |
| 378 |
# port', to comply with the requirement that port MAC |
| 379 |
# addresses are unique only within a Neutron network. |
| 380 |
# Unfortunately, at the moment there is no clean way |
| 381 |
# to implement such a check, given OVS's handling of |
| 382 |
# VLAN tags and Neutron's use of the NORMAL action in |
| 383 |
# br-int. |
| 384 |
# |
| 385 |
# We are therefore temporarily disabling the VLAN id |
| 386 |
# check until a mechanism is available to implement |
| 387 |
# it correctly. The {broad,multi}cast flow, which is |
| 388 |
# also dependent on the VLAN id, has been disabled |
| 389 |
# for the same reason. |
| 390 |
# |
| 391 |
|
| 392 |
# Get VLAN id for tap flow port |
| 393 |
# port_dict = self.int_br.get_port_tag_dict() |
| 394 |
# port_vlan_id = port_dict[ovs_port.port_name] |
| 395 |
if not physical_network: |
| 396 |
self.int_br.add_flow( |
| 397 |
table=0, |
| 398 |
priority=20, |
| 399 |
# dl_vlan=port_vlan_id, |
| 400 |
dl_dst=port_mac, |
| 401 |
actions="normal,mod_vlan_vid:%s,output:%s" % |
| 402 |
(str(taas_id), str(patch_int_tap_id)) |
| 403 |
) |
| 404 |
|
| 405 |
else: |
| 406 |
actions = "output:{},mod_vlan_vid:{},output:{}".format( |
| 407 |
str(ovs_port_id), str(taas_id), str(patch_int_tap_id) |
| 408 |
) |
| 409 |
if network_type == 'vlan': |
| 410 |
actions = 'strip_vlan,' + actions |
| 411 |
self.int_br.add_flow( |
| 412 |
table=0, |
| 413 |
priority=20, |
| 414 |
# dl_vlan=port_vlan_id, |
| 415 |
dl_dst=port_mac, |
| 416 |
actions=actions |
| 417 |
) |
| 418 |
|
| 419 |
# self._add_update_ingress_bcmc_flow(port_vlan_id, |
| 420 |
# taas_id, |
| 421 |
# patch_int_tap_id) |
| 422 |
|
| 423 |
# Add flow(s) in br-tun |
| 424 |
if self.tunnel_types: |
| 425 |
for tunnel_type in n_ovs_consts.TUNNEL_NETWORK_TYPES: |
| 426 |
self.tun_br.add_flow( |
| 427 |
table=n_ovs_consts.TUN_TABLE[tunnel_type], |
| 428 |
priority=1, |
| 429 |
tun_id=taas_id, |
| 430 |
actions=("move:NXM_OF_VLAN_TCI[0..11]->" |
| 431 |
"NXM_NX_REG0[0..11],move:NXM_NX_TUN_ID" |
| 432 |
"[0..11]->NXM_OF_VLAN_TCI[0..11]," |
| 433 |
"resubmit(,%s)" % |
| 434 |
taas_ovs_consts.TAAS_CLASSIFY)) |
| 435 |
|
| 436 |
self.tun_br.add_flow(table=taas_ovs_consts.TAAS_SRC_CHECK, |
| 437 |
priority=1, |
| 438 |
tun_id=taas_id, |
| 439 |
actions="resubmit(,%s)" % |
| 440 |
taas_ovs_consts.TAAS_SRC_RESPOND) |
| 441 |
|
| 442 |
@log_helpers.log_method_call |
| 443 |
def delete_tap_flow(self, tap_flow_msg): |
| 444 |
"""Delete a tap flow |
| 445 |
|
| 446 |
:param tap_flow_msg: a dict of the tap_flow, the mac of the port of |
| 447 |
the tap-flow, taas_id which is the VLAN Id |
| 448 |
reserved for mirroring for the tap-service |
| 449 |
associated with this tap-flow, the neutron port |
| 450 |
of the tap-flow, the port of the |
| 451 |
tap-service, the list of source VLAN IDs, and |
| 452 |
VLAN filter list. |
| 453 |
{tap_flow: {}, port_mac: '', taas_id: VID, |
| 454 |
port: {}, tap_service_port: {}, |
| 455 |
source_vlans_list: [], vlan_filter_list: []} |
| 456 |
""" |
| 457 |
port = tap_flow_msg['port'] |
| 458 |
direction = tap_flow_msg['tap_flow']['direction'] |
| 459 |
|
| 460 |
# Get OVS port id for tap flow port |
| 461 |
ovs_port = self.int_br.get_vif_port_by_id(port['id']) |
| 462 |
ovs_port_id = ovs_port.ofport |
| 463 |
|
| 464 |
# Delete flow(s) from br-int |
| 465 |
if direction in ('OUT', 'BOTH'): |
| 466 |
self.int_br.delete_flows(table=0, |
| 467 |
in_port=ovs_port_id) |
| 468 |
|
| 469 |
if direction in ('IN', 'BOTH'): |
| 470 |
port_mac = tap_flow_msg['port_mac'] |
| 471 |
|
| 472 |
# |
| 473 |
# The VLAN id related checks have been temporarily disabled. |
| 474 |
# Please see comment in create_tap_flow() for details. |
| 475 |
# |
| 476 |
|
| 477 |
# taas_id = tap_flow['taas_id'] |
| 478 |
|
| 479 |
# Get VLAN id for tap flow port |
| 480 |
# port_dict = self.int_br.get_port_tag_dict() |
| 481 |
# port_vlan_id = port_dict[ovs_port.port_name] |
| 482 |
|
| 483 |
# Get patch port ID |
| 484 |
# patch_int_tap_id = self.int_br.get_port_ofport('patch-int-tap') |
| 485 |
|
| 486 |
self.int_br.delete_flows(table=0, |
| 487 |
# dl_vlan=port_vlan_id, |
| 488 |
dl_dst=port_mac) |
| 489 |
|
| 490 |
# self._del_update_ingress_bcmc_flow(port_vlan_id, |
| 491 |
# taas_id, |
| 492 |
# patch_int_tap_id) |
| 493 |
|
| 494 |
def update_tunnel_flood_flow(self): |
| 495 |
flow_action = self._create_tunnel_flood_flow_action() |
| 496 |
if flow_action != "": |
| 497 |
self.tun_br.mod_flow(table=taas_ovs_consts.TAAS_SEND_FLOOD, |
| 498 |
actions=flow_action) |
| 499 |
|
| 500 |
def _create_tunnel_flood_flow_action(self): |
| 501 |
port_name_list = self.tun_br.get_port_name_list() |
| 502 |
|
| 503 |
flow_action = ("move:NXM_OF_VLAN_TCI[0..11]->NXM_NX_TUN_ID[0..11]," |
| 504 |
"mod_vlan_vid:1") |
| 505 |
|
| 506 |
tunnel_ports_exist = False |
| 507 |
|
| 508 |
for port_name in port_name_list: |
| 509 |
if port_name not in ('patch-int', 'patch-tun-tap'): |
| 510 |
flow_action += (",output:%d" % |
| 511 |
self.tun_br.get_port_ofport(port_name)) |
| 512 |
tunnel_ports_exist = True |
| 513 |
|
| 514 |
if tunnel_ports_exist: |
| 515 |
return flow_action |
| 516 |
else: |
| 517 |
return "" |
| 518 |
|
| 519 |
def _create_ingress_bcmc_flow_action(self, taas_id_list, out_port_id): |
| 520 |
flow_action = "normal" |
| 521 |
for taas_id in taas_id_list: |
| 522 |
flow_action += (",mod_vlan_vid:%d,output:%d" % |
| 523 |
(taas_id, out_port_id)) |
| 524 |
|
| 525 |
return flow_action |
| 526 |
|
| 527 |
# |
| 528 |
# Adds or updates a special flow in br-int to mirror (duplicate and |
| 529 |
# redirect to 'out_port_id') all ingress broadcast/multicast traffic, |
| 530 |
# associated with a VLAN, to possibly multiple tap service instances. |
| 531 |
# |
| 532 |
def _add_update_ingress_bcmc_flow(self, vlan_id, taas_id, out_port_id): |
| 533 |
# Add a tap service instance affiliation with VLAN |
| 534 |
self.bcmc_kvm.affiliate(vlan_id, taas_id) |
| 535 |
|
| 536 |
# Find all tap service instances affiliated with VLAN |
| 537 |
taas_id_list = self.bcmc_kvm.list_affiliations(vlan_id) |
| 538 |
|
| 539 |
# |
| 540 |
# Add/update flow to mirror ingress BCMC traffic, associated |
| 541 |
# with VLAN, to all affiliated tap-service instances. |
| 542 |
# |
| 543 |
flow_action = self._create_ingress_bcmc_flow_action(taas_id_list, |
| 544 |
out_port_id) |
| 545 |
self.int_br.add_flow(table=0, |
| 546 |
priority=20, |
| 547 |
dl_vlan=vlan_id, |
| 548 |
dl_dst="01:00:00:00:00:00/01:00:00:00:00:00", |
| 549 |
actions=flow_action) |
| 550 |
|
| 551 |
# |
| 552 |
# Removes or updates a special flow in br-int to mirror (duplicate |
| 553 |
# and redirect to 'out_port_id') all ingress broadcast/multicast |
| 554 |
# traffic, associated with a VLAN, to possibly multiple tap-service |
| 555 |
# instances. |
| 556 |
# |
| 557 |
def _del_update_ingress_bcmc_flow(self, vlan_id, taas_id, out_port_id): |
| 558 |
# Remove a tap-service instance affiliation with VLAN |
| 559 |
self.bcmc_kvm.unaffiliate(vlan_id, taas_id) |
| 560 |
|
| 561 |
# Find all tap-service instances affiliated with VLAN |
| 562 |
taas_id_list = self.bcmc_kvm.list_affiliations(vlan_id) |
| 563 |
|
| 564 |
# |
| 565 |
# If there are tap service instances affiliated with VLAN, update |
| 566 |
# the flow to mirror ingress BCMC traffic, associated with VLAN, |
| 567 |
# to all of them. Otherwise, remove the flow. |
| 568 |
# |
| 569 |
if taas_id_list: |
| 570 |
flow_action = self._create_ingress_bcmc_flow_action(taas_id_list, |
| 571 |
out_port_id) |
| 572 |
self.int_br.add_flow(table=0, |
| 573 |
priority=20, |
| 574 |
dl_vlan=vlan_id, |
| 575 |
dl_dst="01:00:00:00:00:00/01:00:00:00:00:00", |
| 576 |
actions=flow_action) |
| 577 |
else: |
| 578 |
self.int_br.delete_flows(table=0, |
| 579 |
dl_vlan=vlan_id, |
| 580 |
dl_dst=("01:00:00:00:00:00/" |
| 581 |
"01:00:00:00:00:00")) |
| 582 |
|
| 583 |
@log_helpers.log_method_call |
| 584 |
def create_tap_mirror(self, tap_mirror_msg): |
| 585 |
source_port = tap_mirror_msg['port'] |
| 586 |
tap_mirror = tap_mirror_msg['tap_mirror'] |
| 587 |
|
| 588 |
type = '' |
| 589 |
patch_int_tap_id = self.int_br.get_port_ofport('patch-int-tap') |
| 590 |
patch_tap_int_id = self.tap_br.get_port_ofport('patch-tap-int') |
| 591 |
|
| 592 |
# Get OVS port id for tap flow port |
| 593 |
ovs_port = self.int_br.get_vif_port_by_id(source_port['id']) |
| 594 |
ovs_port_id = ovs_port.ofport |
| 595 |
|
| 596 |
options = collections.OrderedDict() |
| 597 |
options['remote_ip'] = tap_mirror['remote_ip'] |
| 598 |
if 'erspan' in tap_mirror['mirror_type']: |
| 599 |
type = 'erspan' |
| 600 |
# For ERSPAN type 2 (version I) as that is supported |
| 601 |
# only from taas |
| 602 |
options['erspan_ver'] = "1" |
| 603 |
else: |
| 604 |
type = 'gre' |
| 605 |
directions = tap_mirror['directions'] |
| 606 |
|
| 607 |
for direction, tunnel_id in directions.items(): |
| 608 |
options['erspan_idx'] = str(tunnel_id) |
| 609 |
# Note(lajoskatona): this is treated as hexa, so |
| 610 |
# spanId will be d102, and Index will be d258 in the packet. |
| 611 |
# As OVN doesn't care about this let's have OVS driver the same |
| 612 |
# behaviour. |
| 613 |
options['key'] = str(tunnel_id) |
| 614 |
port_name = 'tm_%s_%s' % (direction.lower(), |
| 615 |
tap_mirror['id'][0:6]) |
| 616 |
attrs = [('type', type), |
| 617 |
('options', options)] |
| 618 |
mirror_of_port = self.tap_br.add_port(port_name, *attrs) |
| 619 |
|
| 620 |
if direction == 'IN': |
| 621 |
self.tap_br.add_flow(table=taas_ovs_consts.TAAS_RECV_LOC, |
| 622 |
priority=20, |
| 623 |
dl_dst=source_port['mac_address'], |
| 624 |
actions="output:%s" % str(mirror_of_port)) |
| 625 |
self.int_br.add_flow( |
| 626 |
table=0, |
| 627 |
priority=20, |
| 628 |
dl_dst=source_port['mac_address'], |
| 629 |
actions="output:%s,resubmit(,%s)" % |
| 630 |
(str(patch_int_tap_id), |
| 631 |
str(n_ovs_consts.PACKET_RATE_LIMIT))) |
| 632 |
if direction == 'OUT': |
| 633 |
self.tap_br.add_flow(table=taas_ovs_consts.TAAS_RECV_LOC, |
| 634 |
priority=20, |
| 635 |
dl_src=source_port['mac_address'], |
| 636 |
actions="output:%s" % str(mirror_of_port)) |
| 637 |
self.int_br.add_flow( |
| 638 |
table=0, |
| 639 |
priority=20, |
| 640 |
in_port=ovs_port_id, |
| 641 |
actions="output:%s,resubmit(,%s)" % |
| 642 |
(str(patch_int_tap_id), |
| 643 |
str(n_ovs_consts.PACKET_RATE_LIMIT))) |
| 644 |
|
| 645 |
# Add flow(s) in br-tap |
| 646 |
self.tap_br.add_flow(table=taas_ovs_consts.TAAS_RECV_LOC, |
| 647 |
priority=1, |
| 648 |
dl_dst=source_port['mac_address'], |
| 649 |
actions="output:in_port") |
| 650 |
|
| 651 |
self.tap_br.add_flow(table=taas_ovs_consts.TAAS_RECV_REM, |
| 652 |
priority=1, |
| 653 |
dl_dst=source_port['mac_address'], |
| 654 |
actions="output:%s" % str(patch_tap_int_id)) |
| 655 |
|
| 656 |
@log_helpers.log_method_call |
| 657 |
def delete_tap_mirror(self, tap_mirror_msg): |
| 658 |
source_port = tap_mirror_msg['port'] |
| 659 |
tap_mirror = tap_mirror_msg['tap_mirror'] |
| 660 |
directions = tap_mirror['directions'] |
| 661 |
|
| 662 |
# Get OVS port id for tap flow port |
| 663 |
ovs_port = self.int_br.get_vif_port_by_id(source_port['id']) |
| 664 |
ovs_port_id = ovs_port.ofport |
| 665 |
|
| 666 |
self.tap_br.delete_flows(table=taas_ovs_consts.TAAS_RECV_REM, |
| 667 |
dl_dst=source_port['mac_address']) |
| 668 |
self.tap_br.delete_flows(table=taas_ovs_consts.TAAS_RECV_LOC, |
| 669 |
dl_dst=source_port['mac_address']) |
| 670 |
|
| 671 |
for direction, tunnel_id in directions.items(): |
| 672 |
if direction == 'IN': |
| 673 |
self.int_br.delete_flows(table=0, |
| 674 |
dl_dst=source_port['mac_address']) |
| 675 |
self.tap_br.delete_flows(table=taas_ovs_consts.TAAS_RECV_LOC, |
| 676 |
dl_dst=source_port['mac_address']) |
| 677 |
if direction == 'OUT': |
| 678 |
self.int_br.delete_flows(table=0, in_port=ovs_port_id) |
| 679 |
self.tap_br.delete_flows(table=taas_ovs_consts.TAAS_RECV_LOC, |
| 680 |
dl_src=source_port['mac_address']) |
| 681 |
port_name = 'tm_%s_%s' % (direction.lower(), |
| 682 |
tap_mirror['id'][0:6]) |
| 683 |
self.tap_br.delete_port(port_name) |