*/
package org.opendaylight.ovsdb.openstack.netvirt;
-import org.opendaylight.controller.networkconfig.neutron.NeutronNetwork;
-import org.opendaylight.controller.sal.core.Node;
-import org.opendaylight.controller.sal.core.NodeConnector;
-import org.opendaylight.controller.sal.core.Property;
-import org.opendaylight.controller.sal.core.UpdateType;
-import org.opendaylight.controller.switchmanager.IInventoryListener;
+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.NetworkingProviderManager;
import org.opendaylight.ovsdb.openstack.netvirt.api.TenantNetworkManager;
-import org.opendaylight.ovsdb.plugin.IConnectionServiceInternal;
-import org.opendaylight.ovsdb.plugin.OvsdbConfigService;
-import org.opendaylight.ovsdb.plugin.OvsdbInventoryListener;
+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.Interface;
import org.opendaylight.ovsdb.schema.openvswitch.OpenVSwitch;
import org.opendaylight.ovsdb.schema.openvswitch.Port;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node;
-import com.google.common.collect.Lists;
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.BlockingQueue;
import java.util.concurrent.ConcurrentMap;
-import java.util.concurrent.ExecutorService;
-import java.util.concurrent.Executors;
-import java.util.concurrent.LinkedBlockingQueue;
-public class SouthboundHandler extends AbstractHandler implements OvsdbInventoryListener, IInventoryListener {
+public class SouthboundHandler extends AbstractHandler implements OvsdbInventoryListener {
static final Logger logger = LoggerFactory.getLogger(SouthboundHandler.class);
//private Thread eventThread;
- private ExecutorService eventHandler;
- private BlockingQueue<SouthboundEvent> events;
- List<Node> nodeCache;
// 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 OvsdbConfigService ovsdbConfigService;
- private volatile IConnectionServiceInternal connectionService;
+ private volatile OvsdbConfigurationService ovsdbConfigurationService;
+ private volatile OvsdbConnectionService connectionService;
+ private volatile NeutronL3Adapter neutronL3Adapter;
void init() {
- eventHandler = Executors.newSingleThreadExecutor();
- this.events = new LinkedBlockingQueue<>();
- nodeCache = Lists.newArrayList();
}
void start() {
- eventHandler.submit(new Runnable() {
- @Override
- public void run() {
- while (true) {
- SouthboundEvent ev;
- try {
- ev = events.take();
- } catch (InterruptedException e) {
- logger.info("The event handler thread was interrupted, shutting down", e);
- return;
- }
- 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);
- }
- 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);
- }
- break;
- default:
- logger.warn("Unable to process action " + ev.getAction() + " for node " + ev.getNode());
- }
- }
- }
- });
this.triggerUpdates();
}
- void stop() {
- eventHandler.shutdownNow();
- }
-
@Override
- public void nodeAdded(Node node) {
- this.enqueueEvent(new SouthboundEvent(node, SouthboundEvent.Action.ADD));
+ 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, SouthboundEvent.Action.DELETE));
+ 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, SouthboundEvent.Action.ADD));
+ 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, SouthboundEvent.Action.UPDATE));
+ this.enqueueEvent(new SouthboundEvent(node, tableName, uuid, newRow, Action.UPDATE));
}
}
/*
- * Ignore unneccesary updates to be even considered for processing.
+ * Ignore unnecessary updates to be even considered for processing.
* (Especially stats update are fast and furious).
*/
private boolean isUpdateOfInterest(Node node, Row oldRow, Row newRow) {
if (oldRow == null) return true;
- if (newRow.getTableSchema().getName().equals(ovsdbConfigService.getTableName(node, Interface.class))) {
+ if (newRow.getTableSchema().getName().equals(ovsdbConfigurationService.getTableName(node, Interface.class))) {
// We are NOT interested in Stats only updates
- Interface oldIntf = ovsdbConfigService.getTypedRow(node, Interface.class, oldRow);
+ 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(ovsdbConfigService.getTableName(node, Port.class))) {
+ } else if (newRow.getTableSchema().getName().equals(ovsdbConfigurationService.getTableName(node, Port.class))) {
// We are NOT interested in Stats only updates
- Port oldPort = ovsdbConfigService.getTypedRow(node, Port.class, oldRow);
+ 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(ovsdbConfigService.getTableName(node, OpenVSwitch.class))) {
- OpenVSwitch oldOpenvSwitch = ovsdbConfigService.getTypedRow(node, OpenVSwitch.class, oldRow);
+ } 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;
@Override
public void rowRemoved(Node node, String tableName, String uuid, Row row, Object context) {
- this.enqueueEvent(new SouthboundEvent(node, tableName, uuid, row, context, SouthboundEvent.Action.DELETE));
+ this.enqueueEvent(new SouthboundEvent(node, tableName, uuid, row, context, Action.DELETE));
}
- private void enqueueEvent (SouthboundEvent event) {
- try {
- events.put(event);
- } catch (InterruptedException e) {
- logger.error("Thread was interrupted while trying to enqueue event ", e);
- }
- }
-
- public void processNodeUpdate(Node node, SouthboundEvent.Action action) {
- if (action == SouthboundEvent.Action.DELETE) return;
+ public void processNodeUpdate(Node node, Action action) {
+ if (action == Action.DELETE) return;
logger.trace("Process Node added {}", node);
bridgeConfigurationManager.prepareNode(node);
}
private void processRowUpdate(Node node, String tableName, String uuid, Row row,
- Object context, SouthboundEvent.Action action) {
- if (action == SouthboundEvent.Action.DELETE) {
- if (tableName.equalsIgnoreCase(ovsdbConfigService.getTableName(node, Interface.class))) {
- logger.debug("processRowUpdate: {} Deleted node: {}, uuid: {}, row: {}", tableName, node, uuid, row);
- Interface deletedIntf = ovsdbConfigService.getTypedRow(node, Interface.class, 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);
/* 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<String, Row> interfaces = this.ovsdbConfigService.getRows(node, ovsdbConfigService.getTableName(node, Interface.class));
+ ConcurrentMap<String, Row> 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.ovsdbConfigService.getTypedRow(node, Interface.class, interfaces.get(intfUUID));
+ Interface intf = this.ovsdbConfigurationService.getTypedRow(node, Interface.class, interfaces.get(intfUUID));
NeutronNetwork neutronNetwork = tenantNetworkManager.getTenantNetwork(intf);
if (neutronNetwork != null && neutronNetwork.equals(network)) isLastInstanceOnNode = false;
}
}
}
}
- else if (tableName.equalsIgnoreCase(ovsdbConfigService.getTableName(node, Interface.class))) {
- logger.debug("processRowUpdate: {} Added / Updated node: {}, uuid: {}, row: {}", tableName, node, uuid, row);
- Interface intf = this.ovsdbConfigService.getTypedRow(node, Interface.class, row);
+ 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());
- logger.trace("Neutron Network {}:{} Created with Internal Vlan: {}", network.getNetworkUUID(), network.getNetworkName(), vlan);
-
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(ovsdbConfigService.getTableName(node, Port.class))) {
- logger.debug("processRowUpdate: {} Added / Updated node: {}, uuid: {}, row: {}", tableName, node, uuid, row);
- Port port = this.ovsdbConfigService.getTypedRow(node, Port.class, row);
+
+ } 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<UUID> interfaceUUIDs = port.getInterfacesColumn().getData();
for (UUID intfUUID : interfaceUUIDs) {
logger.trace("Scanning interface "+intfUUID);
try {
- Row intfRow = this.ovsdbConfigService.getRow(node, ovsdbConfigService.getTableName(node, Interface.class), intfUUID.toString());
- Interface intf = this.ovsdbConfigService.getTypedRow(node, Interface.class, intfRow);
+ 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("ignore update because there is not a neutron network.");
+ 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);
}
}
- } else if (tableName.equalsIgnoreCase(ovsdbConfigService.getTableName(node, OpenVSwitch.class))) {
- logger.debug("processRowUpdate: {} Added / Updated node: {}, uuid: {}, row: {}", tableName, node, uuid, row);
+ } 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<String, Row> interfaces = this.ovsdbConfigService.getRows(node, ovsdbConfigService.getTableName(node, Interface.class));
+ ConcurrentMap<String, Row> interfaces = this.ovsdbConfigurationService
+ .getRows(node, ovsdbConfigurationService.getTableName(node, Interface.class));
if (interfaces != null) {
for (String intfUUID : interfaces.keySet()) {
- Interface intf = ovsdbConfigService.getTypedRow(node, Interface.class, interfaces.get(intfUUID));
+ Interface intf = ovsdbConfigurationService.getTypedRow(node, Interface.class, interfaces.get(intfUUID));
this.handleInterfaceUpdate(node, intfUUID, intf);
}
}
}
private void handleInterfaceUpdate (Node node, String uuid, Interface intf) {
- logger.debug("handleInterfaceUpdate: node: {}, uuid: {}", node, uuid);
+ logger.trace("Interface update of node: {}, uuid: {}", node, uuid);
NeutronNetwork network = tenantNetworkManager.getTenantNetwork(intf);
if (network != null) {
- if (bridgeConfigurationManager.createLocalNetwork(node, network)) {
+ 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("handleInterfaceDelete: node: {}, uuid: {}, isLastInstanceOnNode: {}, interface: {}",
node, uuid, isLastInstanceOnNode, intf);
+ neutronL3Adapter.handleInterfaceEvent(node, intf, network, Action.DELETE);
List<String> phyIfName = bridgeConfigurationManager.getAllPhysicalInterfaceNames(node);
if (intf.getTypeColumn().getData().equalsIgnoreCase(NetworkHandler.NETWORK_TYPE_VXLAN) ||
intf.getTypeColumn().getData().equalsIgnoreCase(NetworkHandler.NETWORK_TYPE_GRE) ||
private String getPortIdForInterface (Node node, String uuid, Interface intf) {
try {
- Map<String, Row> ports = this.ovsdbConfigService.getRows(node, ovsdbConfigService.getTableName(node, Port.class));
+ Map<String, Row> ports = this.ovsdbConfigurationService.getRows(node, ovsdbConfigurationService.getTableName(node, Port.class));
if (ports == null) return null;
for (String portUUID : ports.keySet()) {
- Port port = ovsdbConfigService.getTypedRow(node, Port.class, ports.get(portUUID));
+ Port port = ovsdbConfigurationService.getTypedRow(node, Port.class, ports.get(portUUID));
Set<UUID> interfaceUUIDs = port.getInterfacesColumn().getData();
logger.trace("Scanning Port {} to identify interface : {} ",port, uuid);
for (UUID intfUUID : interfaceUUIDs) {
}
}
} catch (Exception e) {
- logger.debug("Failed to add Port tag for for Intf {}",intf, e);
+ logger.debug("Failed to get Port tag for for Intf " + intf, e);
}
return null;
}
- @Override
- public void notifyNode(Node node, UpdateType type, Map<String, Property> propMap) {
- logger.debug("notifyNode: Node {} update {} from Controller's inventory Service", node, type);
-
- // Add the Node Type check back once the Consistency issue is resolved between MD-SAL and AD-SAL
- if (!type.equals(UpdateType.REMOVED) && !nodeCache.contains(node)) {
- nodeCache.add(node);
- networkingProviderManager.getProvider(node).initializeOFFlowRules(node);
- } else if (type.equals(UpdateType.REMOVED)){
- nodeCache.remove(node);
- }
- }
-
- @Override
- public void notifyNodeConnector(NodeConnector nodeConnector, UpdateType type, Map<String, Property> propMap) {
- //We are not interested in the nodeConnectors at this moment
- }
-
private void triggerUpdates() {
List<Node> nodes = connectionService.getNodes();
if (nodes == null) return;
for (Node node : nodes) {
try {
- List<String> tableNames = ovsdbConfigService.getTables(node);
+ List<String> tableNames = ovsdbConfigurationService.getTables(node);
if (tableNames == null) continue;
for (String tableName : tableNames) {
- Map<String, Row> rows = ovsdbConfigService.getRows(node, tableName);
+ Map<String, Row> rows = ovsdbConfigurationService.getRows(node, tableName);
if (rows == null) continue;
for (String uuid : rows.keySet()) {
Row row = rows.get(uuid);
}
}
}
+
+ /**
+ * Process the event.
+ *
+ * @param abstractEvent the {@link org.opendaylight.ovsdb.openstack.netvirt.AbstractEvent} event to be handled.
+ * @see EventDispatcher
+ */
+ @Override
+ public void processEvent(AbstractEvent abstractEvent) {
+ if (!(abstractEvent instanceof SouthboundEvent)) {
+ logger.error("Unable to process abstract event " + abstractEvent);
+ return;
+ }
+ SouthboundEvent ev = (SouthboundEvent) abstractEvent;
+ 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);
+ }
+ 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);
+ }
+ break;
+ default:
+ logger.warn("Unable to process type " + ev.getType() +
+ " action " + ev.getAction() + " for node " + ev.getNode());
+ break;
+ }
+ }
}