X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=openstack%2Fnet-virt%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fovsdb%2Fopenstack%2Fnetvirt%2FSouthboundHandler.java;h=6142fcf2d082129b8291b0ed165759edef335ca0;hb=2ebaf23050854274b6af934d434fb9d2fdb37ee6;hp=05b4525a874cb8e019bd94e683317cc664b99756;hpb=8e14a9956d2d914a82f0fa3ab0a6666556cf05a2;p=ovsdb.git diff --git a/openstack/net-virt/src/main/java/org/opendaylight/ovsdb/openstack/netvirt/SouthboundHandler.java b/openstack/net-virt/src/main/java/org/opendaylight/ovsdb/openstack/netvirt/SouthboundHandler.java index 05b4525a8..6142fcf2d 100644 --- a/openstack/net-virt/src/main/java/org/opendaylight/ovsdb/openstack/netvirt/SouthboundHandler.java +++ b/openstack/net-virt/src/main/java/org/opendaylight/ovsdb/openstack/netvirt/SouthboundHandler.java @@ -4,323 +4,217 @@ * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v1.0 which accompanies this distribution, * and is available at http://www.eclipse.org/legal/epl-v10.html - * - * Authors : Madhu Venugopal, Brent Salisbury, Sam Hague, Dave Tucker */ package org.opendaylight.ovsdb.openstack.netvirt; +import java.util.List; + import org.opendaylight.neutron.spi.NeutronNetwork; -import org.opendaylight.ovsdb.lib.notation.Row; -import org.opendaylight.ovsdb.lib.notation.UUID; -import org.opendaylight.ovsdb.openstack.netvirt.api.Action; -import org.opendaylight.ovsdb.openstack.netvirt.api.BridgeConfigurationManager; -import org.opendaylight.ovsdb.openstack.netvirt.api.ConfigurationService; -import org.opendaylight.ovsdb.openstack.netvirt.api.NetworkingProvider; -import org.opendaylight.ovsdb.openstack.netvirt.api.NetworkingProviderManager; -import org.opendaylight.ovsdb.openstack.netvirt.api.NodeCacheListener; -import org.opendaylight.ovsdb.openstack.netvirt.api.TenantNetworkManager; +import org.opendaylight.ovsdb.openstack.netvirt.api.*; import org.opendaylight.ovsdb.openstack.netvirt.impl.NeutronL3Adapter; -import org.opendaylight.ovsdb.plugin.api.OvsdbConfigurationService; -import org.opendaylight.ovsdb.plugin.api.OvsdbConnectionService; -import org.opendaylight.ovsdb.plugin.api.OvsdbInventoryListener; -import org.opendaylight.ovsdb.schema.openvswitch.Bridge; -import org.opendaylight.ovsdb.schema.openvswitch.Interface; -import org.opendaylight.ovsdb.schema.openvswitch.OpenVSwitch; -import org.opendaylight.ovsdb.schema.openvswitch.Port; -import org.opendaylight.ovsdb.utils.mdsal.node.StringConvertor; -import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node; - +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.OvsdbBridgeAugmentation; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.OvsdbNodeAugmentation; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.OvsdbTerminationPointAugmentation; +import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node; +import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.node.TerminationPoint; +import org.opendaylight.yangtools.yang.binding.DataObject; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import java.net.InetAddress; -import java.util.List; -import java.util.Map; -import java.util.Set; -import java.util.concurrent.ConcurrentMap; - +/** + * @author Madhu Venugopal + * @author Brent Salisbury + * @author Dave Tucker + * @author Sam Hague (shague@redhat.com) + */ public class SouthboundHandler extends AbstractHandler implements NodeCacheListener, OvsdbInventoryListener { static final Logger logger = LoggerFactory.getLogger(SouthboundHandler.class); - //private Thread eventThread; // The implementation for each of these services is resolved by the OSGi Service Manager private volatile ConfigurationService configurationService; private volatile BridgeConfigurationManager bridgeConfigurationManager; private volatile TenantNetworkManager tenantNetworkManager; private volatile NetworkingProviderManager networkingProviderManager; - private volatile OvsdbConfigurationService ovsdbConfigurationService; - private volatile OvsdbConnectionService connectionService; private volatile NeutronL3Adapter neutronL3Adapter; - - void init() { - } + private volatile NodeCacheManager nodeCacheManager = null; void start() { this.triggerUpdates(); } - @Override - public void nodeAdded(Node node, InetAddress address, int port) { - logger.info("nodeAdded: {}", node); - this.enqueueEvent(new SouthboundEvent(node, Action.ADD)); - } - - @Override - public void nodeRemoved(Node node) { - this.enqueueEvent(new SouthboundEvent(node, Action.DELETE)); - } - - @Override - public void rowAdded(Node node, String tableName, String uuid, Row row) { - this.enqueueEvent(new SouthboundEvent(node, tableName, uuid, row, Action.ADD)); - } - - @Override - public void rowUpdated(Node node, String tableName, String uuid, Row oldRow, Row newRow) { - if (this.isUpdateOfInterest(node, oldRow, newRow)) { - this.enqueueEvent(new SouthboundEvent(node, tableName, uuid, newRow, Action.UPDATE)); - } + void init() { + logger.info(">>>>>> init {}", this.getClass()); } - /* - * Ignore unnecessary updates to be even considered for processing. - * (Especially stats update are fast and furious). - */ + private SouthboundEvent.Type ovsdbTypeToSouthboundEventType(OvsdbType ovsdbType) { + SouthboundEvent.Type type = SouthboundEvent.Type.NODE; - private boolean isUpdateOfInterest(Node node, Row oldRow, Row newRow) { - if (oldRow == null) return true; - if (newRow.getTableSchema().getName().equals(ovsdbConfigurationService.getTableName(node, Interface.class))) { - // We are NOT interested in Stats only updates - Interface oldIntf = ovsdbConfigurationService.getTypedRow(node, Interface.class, oldRow); - if (oldIntf.getName() == null && oldIntf.getExternalIdsColumn() == null && oldIntf.getMacColumn() == null && - oldIntf.getOpenFlowPortColumn() == null && oldIntf.getOptionsColumn() == null && oldIntf.getOtherConfigColumn() == null && - oldIntf.getTypeColumn() == null) { - logger.trace("IGNORING Interface Update: node {}, row: {}", node, newRow); - return false; - } - } else if (newRow.getTableSchema().getName().equals(ovsdbConfigurationService.getTableName(node, Port.class))) { - // We are NOT interested in Stats only updates - Port oldPort = ovsdbConfigurationService.getTypedRow(node, Port.class, oldRow); - if (oldPort.getName() == null && oldPort.getExternalIdsColumn() == null && oldPort.getMacColumn() == null && - oldPort.getInterfacesColumn() == null && oldPort.getTagColumn() == null && oldPort.getTrunksColumn() == null) { - logger.trace("IGNORING Port Update: node {}, row: {}", node, newRow); - return false; - } - } else if (newRow.getTableSchema().getName().equals(ovsdbConfigurationService.getTableName(node, OpenVSwitch.class))) { - OpenVSwitch oldOpenvSwitch = ovsdbConfigurationService.getTypedRow(node, OpenVSwitch.class, oldRow); - if (oldOpenvSwitch.getOtherConfigColumn()== null) { - /* we are only interested in other_config field change */ - return false; - } + switch (ovsdbType) { + case NODE: + type = SouthboundEvent.Type.NODE; + break; + case BRIDGE: + type = SouthboundEvent.Type.BRIDGE; + break; + case PORT: + type = SouthboundEvent.Type.PORT; + break; + case CONTROLLER: + type = SouthboundEvent.Type.CONTROLLER; + break; + case OPENVSWITCH: + type = SouthboundEvent.Type.OPENVSWITCH; + break; + default: + logger.warn("Invalid OvsdbType: {}", ovsdbType); + break; } - return true; + return type; } @Override - public void rowRemoved(Node node, String tableName, String uuid, Row row, Object context) { - this.enqueueEvent(new SouthboundEvent(node, tableName, uuid, row, context, Action.DELETE)); - } - - public void processNodeUpdate(Node node, Action action) { - if (action == Action.DELETE) return; - logger.trace("Process Node added {}", node); - bridgeConfigurationManager.prepareNode(node); + public void ovsdbUpdate(Node node, DataObject resourceAugmentationData, OvsdbType ovsdbType, Action action) { + logger.info("ovsdbUpdate: {} - {} - <<{}>> <<{}>>", ovsdbType, action, node, resourceAugmentationData); + this.enqueueEvent(new SouthboundEvent(node, resourceAugmentationData, + ovsdbTypeToSouthboundEventType(ovsdbType), action)); } - private void processRowUpdate(Node node, String tableName, String uuid, Row row, - Object context, Action action) { - if (action == Action.DELETE) { - if (tableName.equalsIgnoreCase(ovsdbConfigurationService.getTableName(node, Interface.class))) { - logger.debug("Processing update of {}. Deleted node: {}, uuid: {}, row: {}", tableName, node, uuid, row); - Interface deletedIntf = ovsdbConfigurationService.getTypedRow(node, Interface.class, row); - NeutronNetwork network = null; - if (context == null) { - network = tenantNetworkManager.getTenantNetwork(deletedIntf); - } else { - network = (NeutronNetwork)context; - } - List phyIfName = bridgeConfigurationManager.getAllPhysicalInterfaceNames(node); - logger.info("Delete interface " + deletedIntf.getName()); - - if (deletedIntf.getTypeColumn().getData().equalsIgnoreCase(NetworkHandler.NETWORK_TYPE_VXLAN) || - deletedIntf.getTypeColumn().getData().equalsIgnoreCase(NetworkHandler.NETWORK_TYPE_GRE) || - phyIfName.contains(deletedIntf.getName())) { - /* delete tunnel interfaces or physical interfaces */ - this.handleInterfaceDelete(node, uuid, deletedIntf, false, null); - } else if (network != null && !network.getRouterExternal()) { - logger.debug("Processing update of {}:{} node {} intf {} network {}", - tableName, action, node, uuid, network.getNetworkUUID()); - try { - ConcurrentMap interfaces = this.ovsdbConfigurationService - .getRows(node, ovsdbConfigurationService.getTableName(node, Interface.class)); - if (interfaces != null) { - boolean isLastInstanceOnNode = true; - for (String intfUUID : interfaces.keySet()) { - if (intfUUID.equals(uuid)) continue; - Interface intf = this.ovsdbConfigurationService.getTypedRow(node, Interface.class, interfaces.get(intfUUID)); - NeutronNetwork neutronNetwork = tenantNetworkManager.getTenantNetwork(intf); - if (neutronNetwork != null && neutronNetwork.equals(network)) isLastInstanceOnNode = false; - } - this.handleInterfaceDelete(node, uuid, deletedIntf, isLastInstanceOnNode, network); - } - } catch (Exception e) { - logger.error("Error fetching Interface Rows for node " + node, e); - } - } - } - } - else if (tableName.equalsIgnoreCase(ovsdbConfigurationService.getTableName(node, Interface.class))) { - logger.debug("Processing update of {}:{} node: {}, interface uuid: {}, row: {}", - tableName, action, node, uuid, row); - Interface intf = this.ovsdbConfigurationService.getTypedRow(node, Interface.class, row); - NeutronNetwork network = tenantNetworkManager.getTenantNetwork(intf); - if (network != null && !network.getRouterExternal()) { - if (networkingProviderManager.getProvider(node).hasPerTenantTunneling()) { - int vlan = tenantNetworkManager.networkCreated(node, network.getID()); - String portUUID = this.getPortIdForInterface(node, uuid, intf); - if (portUUID != null) { - logger.debug("Neutron Network {}:{} Created with Internal vlan {} port {}", - network.getNetworkUUID(), network.getNetworkName(), vlan, portUUID); - tenantNetworkManager.programInternalVlan(node, portUUID, network); - } else { - logger.trace("Neutron Network {}:{} Created with Internal vlan {} but have no portUUID", - network.getNetworkUUID(), network.getNetworkName(), vlan); - } - } - this.handleInterfaceUpdate(node, uuid, intf); - } - - } else if (tableName.equalsIgnoreCase(ovsdbConfigurationService.getTableName(node, Port.class))) { - logger.debug("Processing update of {}:{} node: {}, port uuid: {}, row: {}", tableName, action, node, uuid, row); - Port port = this.ovsdbConfigurationService.getTypedRow(node, Port.class, row); - Set interfaceUUIDs = port.getInterfacesColumn().getData(); - for (UUID intfUUID : interfaceUUIDs) { - logger.trace("Scanning interface "+intfUUID); - try { - Row intfRow = this.ovsdbConfigurationService - .getRow(node, ovsdbConfigurationService.getTableName(node, Interface.class), - intfUUID.toString()); - Interface intf = this.ovsdbConfigurationService.getTypedRow(node, Interface.class, intfRow); - NeutronNetwork network = tenantNetworkManager.getTenantNetwork(intf); - if (network != null && !network.getRouterExternal()) { - logger.debug("Processing update of {}:{} node {} intf {} network {}", - tableName, action, node, intfUUID, network.getNetworkUUID()); - tenantNetworkManager.programInternalVlan(node, uuid, network); - this.handleInterfaceUpdate(node, intfUUID.toString(), intf); - } else { - logger.trace("Ignoring update because there is not a neutron network {} for port {}, interface {}", - network, uuid, intfUUID); - } - } catch (Exception e) { - logger.error("Failed to process row update", e); - } + private void handleInterfaceUpdate (Node node, OvsdbTerminationPointAugmentation tp) { + logger.debug("handleInterfaceUpdate <{}> <{}>", node, tp); + NeutronNetwork network = tenantNetworkManager.getTenantNetwork(tp); + if (network != null && !network.getRouterExternal()) { + logger.trace("handleInterfaceUpdate <{}> <{}> network: {}", node, tp, network.getNetworkUUID()); + neutronL3Adapter.handleInterfaceEvent(node, tp, network, Action.UPDATE); + if (bridgeConfigurationManager.createLocalNetwork(node, network)) { + networkingProviderManager.getProvider(node).handleInterfaceUpdate(network, node, tp); } - } else if (tableName.equalsIgnoreCase(ovsdbConfigurationService.getTableName(node, OpenVSwitch.class))) { - logger.debug("Processing update of {}:{} node: {}, ovs uuid: {}, row: {}", tableName, action, node, uuid, row); - try { - ConcurrentMap interfaces = this.ovsdbConfigurationService - .getRows(node, ovsdbConfigurationService.getTableName(node, Interface.class)); - if (interfaces != null) { - for (String intfUUID : interfaces.keySet()) { - Interface intf = ovsdbConfigurationService.getTypedRow(node, Interface.class, interfaces.get(intfUUID)); - this.handleInterfaceUpdate(node, intfUUID, intf); - } - } - } catch (Exception e) { - logger.error("Error fetching Interface Rows for node " + node, e); - } - } else if (tableName.equalsIgnoreCase(ovsdbConfigurationService.getTableName(node, Bridge.class))) { - logger.debug("Processing update of {}:{} node: {}, bridge uuid: {}, row: {}", tableName, action, node, uuid, row); - Bridge bridge = ovsdbConfigurationService.getTypedRow(node, Bridge.class, row); - final Set dpids = bridge.getDatapathIdColumn().getData(); - if (dpids != null && - (bridge.getName().equals(configurationService.getIntegrationBridgeName()) || - bridge.getName().equals(configurationService.getExternalBridgeName()))) { - NetworkingProvider networkingProvider = networkingProviderManager.getProvider(node); - for (String dpid : dpids) { - networkingProvider.notifyFlowCapableNodeEvent(StringConvertor.dpidStringToLong(dpid), action); - } - } - } - } - - private void handleInterfaceUpdate (Node node, String uuid, Interface intf) { - logger.trace("Interface update of node: {}, uuid: {}", node, uuid); - NeutronNetwork network = tenantNetworkManager.getTenantNetwork(intf); - if (network != null) { - neutronL3Adapter.handleInterfaceEvent(node, intf, network, Action.UPDATE); - if (bridgeConfigurationManager.createLocalNetwork(node, network)) - networkingProviderManager.getProvider(node).handleInterfaceUpdate(network, node, intf); } else { - logger.debug("No tenant network found on node: {}, uuid: {} for interface: {}", node, uuid, intf); + logger.debug("No tenant network found on node: <{}> for interface: <{}>", node, tp); } } - private void handleInterfaceDelete (Node node, String uuid, Interface intf, boolean isLastInstanceOnNode, - NeutronNetwork network) { - logger.debug("handleInterfaceDelete: node: {}, uuid: {}, isLastInstanceOnNode: {}, interface: {}", - node, uuid, isLastInstanceOnNode, intf); + private void handleInterfaceDelete (Node node, OvsdbTerminationPointAugmentation intf, + boolean isLastInstanceOnNode, NeutronNetwork network) { + logger.debug("handleInterfaceDelete: node: <{}>, isLastInstanceOnNode: {}, interface: <{}>", + node, isLastInstanceOnNode, intf); neutronL3Adapter.handleInterfaceEvent(node, intf, network, Action.DELETE); List phyIfName = bridgeConfigurationManager.getAllPhysicalInterfaceNames(node); - if (intf.getTypeColumn().getData().equalsIgnoreCase(NetworkHandler.NETWORK_TYPE_VXLAN) || - intf.getTypeColumn().getData().equalsIgnoreCase(NetworkHandler.NETWORK_TYPE_GRE) || - phyIfName.contains(intf.getName())) { - /* delete tunnel or physical interfaces */ - networkingProviderManager.getProvider(node).handleInterfaceDelete(intf.getTypeColumn().getData(), null, node, intf, isLastInstanceOnNode); + if (isInterfaceOfInterest(intf, phyIfName)) { + // delete tunnel or physical interfaces + networkingProviderManager.getProvider(node).handleInterfaceDelete(network.getProviderNetworkType(), + network, node, intf, isLastInstanceOnNode); } else if (network != null) { - if (!network.getProviderNetworkType().equalsIgnoreCase(NetworkHandler.NETWORK_TYPE_VLAN)) { /* vlan doesn't need a tunnel endpoint */ + // vlan doesn't need a tunnel endpoint + if (!network.getProviderNetworkType().equalsIgnoreCase(NetworkHandler.NETWORK_TYPE_VLAN)) { if (configurationService.getTunnelEndPoint(node) == null) { logger.error("Tunnel end-point configuration missing. Please configure it in OpenVSwitch Table"); return; } } - if (isLastInstanceOnNode & networkingProviderManager.getProvider(node).hasPerTenantTunneling()) { - tenantNetworkManager.reclaimInternalVlan(node, uuid, network); - } - networkingProviderManager.getProvider(node).handleInterfaceDelete(network.getProviderNetworkType(), network, node, intf, isLastInstanceOnNode); + networkingProviderManager.getProvider(node).handleInterfaceDelete(network.getProviderNetworkType(), + network, node, intf, isLastInstanceOnNode); } } - private String getPortIdForInterface (Node node, String uuid, Interface intf) { - try { - Map ports = this.ovsdbConfigurationService.getRows(node, ovsdbConfigurationService.getTableName(node, Port.class)); - if (ports == null) return null; - for (String portUUID : ports.keySet()) { - Port port = ovsdbConfigurationService.getTypedRow(node, Port.class, ports.get(portUUID)); - Set interfaceUUIDs = port.getInterfacesColumn().getData(); - logger.trace("Scanning Port {} to identify interface : {} ",port, uuid); - for (UUID intfUUID : interfaceUUIDs) { - if (intfUUID.toString().equalsIgnoreCase(uuid)) { - logger.trace("Found Interface {} -> {}", uuid, portUUID); - return portUUID; - } + private void triggerUpdates() { + List nodes = null; // nodeCacheManager.getBridgeNodes(); + if (nodes == null) return; + for (Node node : nodes) { + OvsdbBridgeAugmentation bridge = node.getAugmentation(OvsdbBridgeAugmentation.class); + if (bridge != null) { + processBridgeUpdate(node, bridge); + } + + List tps = MdsalUtils.extractTerminationPoints(node); + for (TerminationPoint tp : tps) { + OvsdbTerminationPointAugmentation port = tp.getAugmentation(OvsdbTerminationPointAugmentation.class); + if (port != null) { + processPortUpdate(node, port); } } - } catch (Exception e) { - logger.debug("Failed to get Port tag for for Intf " + intf, e); } - return null; } - private void triggerUpdates() { - List nodes = connectionService.getNodes(); - if (nodes == null) return; - for (Node node : nodes) { + private void processPortDelete(Node node, OvsdbTerminationPointAugmentation ovsdbTerminationPointAugmentation, + Object context) { + logger.debug("processPortDelete <{}> <{}>", node, ovsdbTerminationPointAugmentation); + NeutronNetwork network = null; + if (context == null) { + network = tenantNetworkManager.getTenantNetwork(ovsdbTerminationPointAugmentation); + } else { + network = (NeutronNetwork)context; + } + List phyIfName = bridgeConfigurationManager.getAllPhysicalInterfaceNames(node); + if (isInterfaceOfInterest(ovsdbTerminationPointAugmentation, phyIfName)) { + if (network != null) { + this.handleInterfaceDelete(node, ovsdbTerminationPointAugmentation, false, network); + } else { + logger.warn("processPortDelete: network was null, ignoring update"); + } + } else if (network != null && !network.getRouterExternal()) { + logger.debug("Network {}: Delete interface {} attached to bridge {}", network.getNetworkUUID(), + ovsdbTerminationPointAugmentation.getInterfaceUuid(), node.getNodeId()); try { - List tableNames = ovsdbConfigurationService.getTables(node); - if (tableNames == null) continue; - for (String tableName : tableNames) { - Map rows = ovsdbConfigurationService.getRows(node, tableName); - if (rows == null) continue; - for (String uuid : rows.keySet()) { - Row row = rows.get(uuid); - this.rowAdded(node, tableName, uuid, row); + OvsdbBridgeAugmentation ovsdbBridgeAugmentation = MdsalUtils.getBridge(node); + if (ovsdbBridgeAugmentation != null) { + List terminationPoints = node.getTerminationPoint(); + if (!terminationPoints.isEmpty()){ + boolean isLastInstanceOnNode = true; + for (TerminationPoint terminationPoint : terminationPoints) { + OvsdbTerminationPointAugmentation tpAugmentation = + terminationPoint.getAugmentation( OvsdbTerminationPointAugmentation.class); + if (tpAugmentation.getInterfaceUuid().equals( + ovsdbTerminationPointAugmentation.getInterfaceUuid())) { + continue; + } + NeutronNetwork neutronNetwork = tenantNetworkManager.getTenantNetwork(tpAugmentation); + if (neutronNetwork != null && neutronNetwork.equals(network)) { + isLastInstanceOnNode = false; + break; + } + } + this.handleInterfaceDelete(node, ovsdbTerminationPointAugmentation, + isLastInstanceOnNode, network); } } } catch (Exception e) { - logger.error("Exception during OVSDB Southbound update trigger", e); + logger.error("Error fetching Interface Rows for node " + node, e); + } + } + } + + private boolean isInterfaceOfInterest(OvsdbTerminationPointAugmentation terminationPoint, List phyIfName) { + logger.trace("SouthboundHandler#isInterfaceOfInterest: Interface : {}", terminationPoint); + + if(terminationPoint.getInterfaceType() == null){ + logger.warn("No type found for the interface : {}", terminationPoint); + return false; + } + return (MdsalHelper.createOvsdbInterfaceType( + terminationPoint.getInterfaceType()).equals(NetworkHandler.NETWORK_TYPE_VXLAN) + || + MdsalHelper.createOvsdbInterfaceType( + terminationPoint.getInterfaceType()).equals(NetworkHandler.NETWORK_TYPE_GRE) + || + phyIfName.contains(terminationPoint.getName())); + } + + /** + * Notification about an OpenFlow Node + * + * @param node the {@link Node Node} of interest in the notification + * @param action the {@link Action} + * @see NodeCacheListener#notifyNode + */ + @Override + public void notifyNode (Node node, Action action) { + logger.info("notifyNode: action: {}, Node <{}>", action, node); + + if (action.equals(Action.ADD)) { + if (MdsalUtils.getBridge(node) != null) { + networkingProviderManager.getProvider(node).initializeOFFlowRules(node); } } } @@ -334,48 +228,176 @@ public class SouthboundHandler extends AbstractHandler @Override public void processEvent(AbstractEvent abstractEvent) { if (!(abstractEvent instanceof SouthboundEvent)) { - logger.error("Unable to process abstract event " + abstractEvent); + logger.error("processEvent: Unable to process abstract event {}", abstractEvent); return; } SouthboundEvent ev = (SouthboundEvent) abstractEvent; - //logger.info("processEvent: {}", ev); + logger.debug("processEvent: {}", ev); switch (ev.getType()) { case NODE: - try { - processNodeUpdate(ev.getNode(), ev.getAction()); - } catch (Exception e) { - logger.error("Exception caught in ProcessNodeUpdate for node " + ev.getNode(), e); - } + processOvsdbNodeEvent(ev); break; - case ROW: - try { - processRowUpdate(ev.getNode(), ev.getTableName(), ev.getUuid(), ev.getRow(), - ev.getContext(),ev.getAction()); - } catch (Exception e) { - logger.error("Exception caught in ProcessRowUpdate for node " + ev.getNode(), e); - } + + case BRIDGE: + processBridgeEvent(ev); break; + + case PORT: + processPortEvent(ev); + break; + + case OPENVSWITCH: + processOpenVSwitchEvent(ev); + break; + default: logger.warn("Unable to process type " + ev.getType() + - " action " + ev.getAction() + " for node " + ev.getNode()); + " action " + ev.getAction() + " for node " + ev.getNode()); break; } + logger.warn("processEvent done"); } - /** - * Notification about an OpenFlow Node - * - * @param openFlowNode the {@link org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node Node} of interest in the notification - * @param action the {@link Action} - * @see NodeCacheListener#notifyNode - */ - @Override - public void notifyNode (Node openFlowNode, Action action) { - logger.info("notifyNode: Node {} update {} from Controller's inventory Service", - openFlowNode, action); + private void processOvsdbNodeEvent(SouthboundEvent ev) { + switch (ev.getAction()) { + case ADD: + processOvsdbNodeCreate(ev.getNode(), (OvsdbNodeAugmentation) ev.getAugmentationData()); + break; + case UPDATE: + processOvsdbNodeUpdate(ev.getNode(), (OvsdbNodeAugmentation) ev.getAugmentationData()); + break; + case DELETE: + processOvsdbNodeDelete(ev.getNode(), (OvsdbNodeAugmentation) ev.getAugmentationData()); + break; + } + } - if (action.equals(Action.ADD)) { - networkingProviderManager.getProvider(openFlowNode).initializeOFFlowRules(openFlowNode); + private void processOvsdbNodeCreate(Node node, OvsdbNodeAugmentation ovsdbNode) { + logger.info("processOvsdbNodeCreate <{}> <{}>", node, ovsdbNode); + nodeCacheManager.nodeAdded(node); + bridgeConfigurationManager.prepareNode(node); + } + + private void processOvsdbNodeUpdate(Node node, OvsdbNodeAugmentation ovsdbNode) { + logger.info("processOvsdbNodeUpdate <{}> <{}>", node, ovsdbNode); + nodeCacheManager.nodeAdded(node); + } + + private void processOvsdbNodeDelete(Node node, OvsdbNodeAugmentation ovsdbNode) { + logger.info("processOvsdbNodeDelete <{}> <{}>", node, ovsdbNode); + nodeCacheManager.nodeRemoved(node); + /* TODO SB_MIGRATION + * I don't think we want to do this yet + InstanceIdentifier bridgeNodeIid = + MdsalHelper.createInstanceIdentifier(ovsdbNode.getConnectionInfo(), + Constants.INTEGRATION_BRIDGE); + MdsalUtils.delete(LogicalDatastoreType.CONFIGURATION, bridgeNodeIid); + */ + } + + private void processPortEvent(SouthboundEvent ev) { + switch (ev.getAction()) { + case ADD: + case UPDATE: + processPortUpdate(ev.getNode(), (OvsdbTerminationPointAugmentation) ev.getAugmentationData()); + break; + case DELETE: + processPortDelete(ev.getNode(), (OvsdbTerminationPointAugmentation) ev.getAugmentationData(), null); + break; + } + } + + private void processPortUpdate(Node node, OvsdbTerminationPointAugmentation port) { + logger.debug("processPortUpdate <{}> <{}>", node, port); + NeutronNetwork network = tenantNetworkManager.getTenantNetwork(port); + if (network != null && !network.getRouterExternal()) { + this.handleInterfaceUpdate(node, port); } } + + private void processOpenVSwitchEvent(SouthboundEvent ev) { + switch (ev.getAction()) { + case ADD: + case UPDATE: + processOpenVSwitchUpdate(ev.getNode()); + break; + case DELETE: + break; + } + } + + private void processOpenVSwitchUpdate(Node node) { + logger.debug("processOpenVSwitchUpdate {}", node); + // TODO this node might be the OvsdbNode and not have termination points + // Would need to change listener or grab tp nodes in here. + List terminationPoints = MdsalUtils.extractTerminationPoints(node); + for (TerminationPoint terminationPoint : terminationPoints) { + processPortUpdate(node, terminationPoint.getAugmentation(OvsdbTerminationPointAugmentation.class)); + } + } + + private void processBridgeEvent(SouthboundEvent ev) { + switch (ev.getAction()) { + case ADD: + processBridgeCreate(ev.getNode(), (OvsdbBridgeAugmentation) ev.getAugmentationData()); + break; + case UPDATE: + processBridgeUpdate(ev.getNode(), (OvsdbBridgeAugmentation) ev.getAugmentationData()); + break; + case DELETE: + processBridgeDelete(ev.getNode(), (OvsdbBridgeAugmentation) ev.getAugmentationData()); + break; + } + } + + private boolean isMainBridge(Node node, OvsdbBridgeAugmentation bridge) { + boolean rv = false; + String nodeIdStr = node.getNodeId().getValue(); + String bridgeName = nodeIdStr.substring(nodeIdStr.lastIndexOf('/') + 1); + List terminationPoints = MdsalUtils.extractTerminationPoints(node); + if (terminationPoints != null && terminationPoints.size() == 1) { + } + OvsdbTerminationPointAugmentation port = MdsalUtils.extractTerminationPointAugmentation(node, bridgeName); + if (port != null) { + String datapathId = MdsalUtils.getDatapathId(bridge); + // Having a datapathId means the ovsdb node has connected to ODL + if (datapathId != null) { + rv = true; + } else { + logger.info("datapathId not found"); + } + } + return rv; + } + + private void processBridgeCreate(Node node, OvsdbBridgeAugmentation bridge) { + logger.debug("processBridgeCreate <{}> <{}>", node, bridge); + String datapathId = MdsalUtils.getDatapathId(bridge); + // Having a datapathId means the ovsdb node has connected to ODL + if (datapathId != null) { + nodeCacheManager.nodeAdded(node); + } else { + logger.info("processBridgeCreate datapathId not found"); + } + } + + private void processBridgeUpdate(Node node, OvsdbBridgeAugmentation bridge) { + logger.debug("processBridgeUpdate <{}> <{}>", node, bridge); + String datapathId = MdsalUtils.getDatapathId(bridge); + // Having a datapathId means the ovsdb node has connected to ODL + if (datapathId != null) { + nodeCacheManager.nodeAdded(node); + } else { + logger.info("processBridgeUpdate datapathId not found"); + } + } + + private void processBridgeDelete(Node node, OvsdbBridgeAugmentation bridge) { + logger.debug("processBridgeDelete: Delete bridge from config data store: <{}> <{}>", + node, bridge); + nodeCacheManager.nodeRemoved(node); + // TODO SB_MIGRATION + // Not sure if we want to do this yet + MdsalUtils.deleteBridge(node); + } }