<groupId>commons-codec</groupId>
<artifactId>commons-codec</artifactId>
</dependency>
+ <dependency>
+ <groupId>commons-net</groupId>
+ <artifactId>commons-net</artifactId>
+ </dependency>
<dependency>
<groupId>commons-collections</groupId>
<artifactId>commons-collections</artifactId>
<artifactId>plugin</artifactId>
<version>${ovsdb.plugin.version}</version>
</dependency>
+ <dependency>
+ <groupId>org.opendaylight.ovsdb</groupId>
+ <artifactId>openstack.net-virt</artifactId>
+ <version>${openstack.netvirt.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.opendaylight.ovsdb</groupId>
+ <artifactId>openstack.net-virt</artifactId>
+ <version>${openstack.netvirt.providers.version}</version>
+ </dependency>
<dependency>
<groupId>org.opendaylight.ovsdb</groupId>
<artifactId>northbound</artifactId>
<argLine>-Xmx1024m -XX:MaxPermSize=256m</argLine>
<ovsdb.library.version>1.0.0-SNAPSHOT</ovsdb.library.version>
<ovsdb.plugin.version>1.0.0-SNAPSHOT</ovsdb.plugin.version>
- <ovsdb.neutron.version>0.7.0-SNAPSHOT</ovsdb.neutron.version>
+ <openstack.netvirt.version>1.0.0-SNAPSHOT</openstack.netvirt.version>
+ <openstack.netvirt.providers.version>1.0.0-SNAPSHOT</openstack.netvirt.providers.version>
<ovsdb.northbound.version>0.6.0-SNAPSHOT</ovsdb.northbound.version>
<schema.openvswitch.version>1.0.0-SNAPSHOT</schema.openvswitch.version>
<schema.hardwarevtep.version>1.0.0-SNAPSHOT</schema.hardwarevtep.version>
</dependency>
<dependency>
<groupId>org.opendaylight.ovsdb</groupId>
- <artifactId>neutron</artifactId>
- <version>${ovsdb.neutron.version}</version>
+ <artifactId>openstack.net-virt</artifactId>
+ <version>${openstack.netvirt.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.opendaylight.ovsdb</groupId>
+ <artifactId>openstack.net-virt-providers</artifactId>
+ <version>${openstack.netvirt.providers.version}</version>
</dependency>
<dependency>
<groupId>org.opendaylight.ovsdb</groupId>
<artifactId>org.openflow.openflowj</artifactId>
<version>${openflowj.version}</version>
</dependency>
- <dependency>
- <groupId>org.opendaylight.controller.thirdparty</groupId>
- <artifactId>org.openflow.openflowj</artifactId>
- <version>1.0.2</version>
- </dependency>
<!-- openflowplugin -->
<dependency>
<groupId>org.opendaylight.openflowplugin</groupId>
</dependency>
<dependency>
<groupId>org.opendaylight.ovsdb</groupId>
- <artifactId>neutron</artifactId>
+ <artifactId>openstack.net-virt</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.opendaylight.ovsdb</groupId>
+ <artifactId>openstack.net-virt-providers</artifactId>
</dependency>
<dependency>
<groupId>org.opendaylight.ovsdb</groupId>
<reuseForks>false</reuseForks>
<parallel>none</parallel>
<threadCount>1</threadCount>
- <!-- Including just the Library integration tests till Plugin migration is done -->
- <!-- TODO remove this includes section once the plugin migration is complete -->
- <includes>
- <include>**/*LibraryIT*</include>
- <include>**/*PluginIT*</include>
- <!-- Disabling NorthboundIT tests till the Jenkins / Tomcat issues is resolved in LF servers
- <include>**/*NorthboundIT*</include>
- -->
- </includes>
+ <excludes>
+ <!-- Disabling NorthboundIT tests till the issues are resolved in Jenkins -->
+ <exclude>**/*NorthboundIT*</exclude>
+ </excludes>
</configuration>
</execution>
</executions>
);
}
+ public static Option ovsdbNeutronBundles() {
+ return new DefaultCompositeOption(
+ mavenBundle("commons-net", "commons-net").versionAsInProject(),
+ mavenBundle("org.opendaylight.controller", "configuration").versionAsInProject(),
+ mavenBundle("org.opendaylight.controller", "configuration.implementation").versionAsInProject(),
+ mavenBundle("org.opendaylight.controller", "hosttracker").versionAsInProject(),
+ mavenBundle("org.opendaylight.controller", "hosttracker.implementation").versionAsInProject(),
+ mavenBundle("org.opendaylight.controller", "switchmanager").versionAsInProject(),
+ mavenBundle("org.opendaylight.controller", "switchmanager.implementation").versionAsInProject(),
+ mavenBundle("org.opendaylight.controller", "statisticsmanager").versionAsInProject(),
+ mavenBundle("org.opendaylight.controller", "statisticsmanager.implementation").versionAsInProject(),
+ mavenBundle("org.opendaylight.controller", "topologymanager").versionAsInProject(),
+ mavenBundle("org.opendaylight.controller", "networkconfig.neutron").versionAsInProject(),
+ mavenBundle("org.opendaylight.controller", "connectionmanager").versionAsInProject(),
+ mavenBundle("org.opendaylight.controller", "connectionmanager.implementation").versionAsInProject(),
+ mavenBundle("org.opendaylight.controller", "forwardingrulesmanager").versionAsInProject(),
+ mavenBundle("org.opendaylight.ovsdb", "plugin").versionAsInProject(),
+ mavenBundle("org.opendaylight.ovsdb", "openstack.net-virt").versionAsInProject()
+ );
+ }
+
}
--- /dev/null
+/*
+ * Copyright (C) 2014 Red Hat, Inc.
+ *
+ * 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 : Dave Tucker
+ */
+
+package org.opendaylight.ovsdb.integrationtest.neutron;
+
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.fail;
+import static org.ops4j.pax.exam.CoreOptions.junitBundles;
+import static org.ops4j.pax.exam.CoreOptions.options;
+import static org.ops4j.pax.exam.CoreOptions.propagateSystemProperty;
+import static org.ops4j.pax.exam.CoreOptions.systemProperty;
+
+import org.opendaylight.controller.networkconfig.neutron.NeutronNetwork;
+import org.opendaylight.controller.sal.core.Node;
+import org.opendaylight.controller.sal.utils.Status;
+import org.opendaylight.ovsdb.integrationtest.ConfigurationBundles;
+import org.opendaylight.ovsdb.integrationtest.OvsdbIntegrationTestBase;
+import org.opendaylight.ovsdb.lib.notation.Row;
+import org.opendaylight.ovsdb.lib.notation.Version;
+import org.opendaylight.ovsdb.openstack.netvirt.api.Constants;
+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.plugin.OvsdbConfigService;
+import org.opendaylight.ovsdb.schema.openvswitch.Bridge;
+import org.opendaylight.ovsdb.schema.openvswitch.Interface;
+import org.opendaylight.ovsdb.schema.openvswitch.OpenVSwitch;
+
+import com.google.common.collect.ImmutableMap;
+import org.apache.felix.dm.Component;
+import org.apache.felix.dm.DependencyManager;
+import org.junit.After;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.ops4j.pax.exam.Configuration;
+import org.ops4j.pax.exam.Option;
+import org.ops4j.pax.exam.junit.PaxExam;
+import org.ops4j.pax.exam.spi.reactors.ExamReactorStrategy;
+import org.ops4j.pax.exam.spi.reactors.PerClass;
+import org.ops4j.pax.exam.util.PathUtils;
+import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleContext;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.IOException;
+import java.net.InetAddress;
+import java.util.Map;
+import java.util.Properties;
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.TimeoutException;
+
+import javax.inject.Inject;
+
+
+@RunWith(PaxExam.class)
+@ExamReactorStrategy(PerClass.class)
+public class NeutronIT extends OvsdbIntegrationTestBase {
+ private Logger log = LoggerFactory.getLogger(NeutronIT.class);
+ @Inject
+ private BundleContext bc;
+
+ @Inject
+ private OvsdbConfigService ovsdbConfigService;
+ private Node node = null;
+
+ Component of10Provider;
+ Component of13Provider;
+
+ @Inject
+ BridgeConfigurationManager bridgeConfigurationManager;
+ @Inject
+ ConfigurationService configurationService;
+
+ Boolean tearDownBridge = false;
+
+ // Configure the OSGi container
+ @Configuration
+ public Option[] config() {
+ return options(
+ //
+ systemProperty("logback.configurationFile").value(
+ "file:" + PathUtils.getBaseDir()
+ + "/src/test/resources/logback.xml"
+ ),
+ // To start OSGi console for inspection remotely
+ systemProperty("osgi.console").value("2401"),
+
+ propagateSystemProperty("ovsdbserver.ipaddress"),
+ propagateSystemProperty("ovsdbserver.port"),
+
+ ConfigurationBundles.controllerBundles(),
+ ConfigurationBundles.ovsdbLibraryBundles(),
+ ConfigurationBundles.ovsdbDefaultSchemaBundles(),
+ ConfigurationBundles.ovsdbNeutronBundles(),
+ junitBundles()
+ );
+ }
+
+ private String stateToString(int state) {
+ switch (state) {
+ case Bundle.ACTIVE:
+ return "ACTIVE";
+ case Bundle.INSTALLED:
+ return "INSTALLED";
+ case Bundle.RESOLVED:
+ return "RESOLVED";
+ case Bundle.UNINSTALLED:
+ return "UNINSTALLED";
+ default:
+ return "Not CONVERTED";
+ }
+ }
+
+ @Before
+ public void areWeReady() throws InterruptedException, ExecutionException, IOException, TimeoutException {
+ assertNotNull(bc);
+ boolean debugit = false;
+ Bundle b[] = bc.getBundles();
+ for (Bundle element : b) {
+ int state = element.getState();
+ if (state != Bundle.ACTIVE && state != Bundle.RESOLVED) {
+ log.info("Bundle:" + element.getSymbolicName() + " state:"
+ + stateToString(state));
+ debugit = true;
+ }
+ }
+ if (debugit) {
+ log.debug("Do some debugging because some bundle is unresolved");
+ }
+
+ assertFalse(debugit);
+
+ if (node == null) {
+ try {
+ node = getPluginTestConnection();
+ } catch (Exception e) {
+ fail("Exception : " + e.getMessage());
+ }
+ }
+
+ //Register fake NetworkingProviders
+ Properties of10Properties = new Properties();
+ of10Properties.put(Constants.OPENFLOW_VERSION_PROPERTY, Constants.OPENFLOW10);
+
+ Properties of13Properties = new Properties();
+ of13Properties.put(Constants.OPENFLOW_VERSION_PROPERTY, Constants.OPENFLOW13);
+
+ DependencyManager dm = new DependencyManager(bc);
+
+ of10Provider = dm.createComponent();
+ of10Provider.setInterface(NetworkingProvider.class.getName(), of10Properties);
+ of10Provider.setImplementation(new FakeOF10Provider());
+
+ of13Provider = dm.createComponent();
+ of13Provider.setInterface(NetworkingProvider.class.getName(), of13Properties);
+ of13Provider.setImplementation(new FakeOF13Provider());
+
+ dm.add(of10Provider);
+ dm.add(of13Provider);
+ }
+
+ @Test
+ public void testPrepareNode() throws Exception {
+ Thread.sleep(5000);
+
+ // Create the integration bridge
+ bridgeConfigurationManager.prepareNode(node);
+
+ Map<String, Row>
+ bridgeRows =
+ ovsdbConfigService.getRows(node, ovsdbConfigService.getTableName(node, Bridge.class));
+ Assert.assertEquals(1, bridgeRows.size());
+
+ Bridge bridgeRow = ovsdbConfigService.getTypedRow(node, Bridge.class, bridgeRows.values().iterator().next());
+ Assert.assertEquals(configurationService.getIntegrationBridgeName(), bridgeRow.getName());
+
+ String uuid = bridgeConfigurationManager.getBridgeUuid(node, configurationService.getIntegrationBridgeName());
+ Assert.assertEquals(uuid, bridgeRow.getUuid().toString());
+
+ tearDownBridge = true;
+ }
+
+ @Test
+ public void testGetTunnelEndpoint() throws Exception {
+ Thread.sleep(5000);
+
+ final String endpointAddress = "10.10.10.10";
+
+ Map<String, Row> ovsRows = ovsdbConfigService.getRows(node,
+ ovsdbConfigService.getTableName(node, OpenVSwitch.class));
+ OpenVSwitch ovsRow = ovsdbConfigService.getTypedRow(node,
+ OpenVSwitch.class,
+ ovsRows.values().iterator().next());
+
+ Assert.assertEquals(null, configurationService.getTunnelEndPoint(node));
+
+ ovsRow.setOtherConfig(ImmutableMap.of(configurationService.getTunnelEndpointKey(), endpointAddress));
+ ovsdbConfigService.updateRow(node,
+ ovsdbConfigService.getTableName(node, OpenVSwitch.class),
+ null,
+ ovsRow.getUuid().toString(),
+ ovsRow.getRow());
+
+ Assert.assertEquals(InetAddress.getByName(endpointAddress), configurationService.getTunnelEndPoint(node));
+ }
+
+ @Test
+ public void testGetOpenflowVersion() throws Exception {
+ Thread.sleep(5000);
+
+ Version ovsVersion = this.getOvsVersion();
+
+ if (ovsVersion.compareTo(Constants.OPENFLOW13_SUPPORTED) < 0) {
+ Assert.assertEquals(Constants.OPENFLOW10, configurationService.getOpenflowVersion(node));
+ } else {
+ Assert.assertEquals(Constants.OPENFLOW13, configurationService.getOpenflowVersion(node));
+ }
+ }
+
+ @After
+ public void tearDown() throws InterruptedException {
+ Thread.sleep(5000);
+
+ if (tearDownBridge) {
+ String uuid = bridgeConfigurationManager.getBridgeUuid(node,
+ configurationService.getIntegrationBridgeName());
+ ovsdbConfigService.deleteRow(node, ovsdbConfigService.getTableName(node, Bridge.class), uuid);
+ tearDownBridge = false;
+ }
+
+ DependencyManager dm = new DependencyManager(bc);
+ dm.remove(of10Provider);
+ dm.remove(of13Provider);
+ }
+
+ private Version getOvsVersion(){
+ Map<String, Row> ovsRows = ovsdbConfigService.getRows(node,
+ ovsdbConfigService.getTableName(node, OpenVSwitch.class));
+ OpenVSwitch ovsRow = ovsdbConfigService.getTypedRow(node,
+ OpenVSwitch.class,
+ ovsRows.values().iterator().next());
+ return Version.fromString(ovsRow.getOvsVersionColumn().getData().iterator().next());
+ }
+
+ private class FakeOF10Provider implements NetworkingProvider {
+
+ @Override
+ public boolean hasPerTenantTunneling() {
+ return true;
+ }
+
+ @Override
+ public Status handleInterfaceUpdate(String tunnelType, String tunnelKey) {
+ return null;
+ }
+
+ @Override
+ public Status handleInterfaceUpdate(NeutronNetwork network, Node source, Interface intf) {
+ return null;
+ }
+
+ @Override
+ public Status handleInterfaceDelete(String tunnelType, NeutronNetwork network, Node source, Interface intf,
+ boolean isLastInstanceOnNode) {
+ return null;
+ }
+
+ @Override
+ public void initializeFlowRules(Node node) {
+
+ }
+
+ @Override
+ public void initializeOFFlowRules(Node openflowNode) {
+
+ }
+ }
+
+ private class FakeOF13Provider implements NetworkingProvider {
+
+ @Override
+ public boolean hasPerTenantTunneling() {
+ return false;
+ }
+
+ @Override
+ public Status handleInterfaceUpdate(String tunnelType, String tunnelKey) {
+ return null;
+ }
+
+ @Override
+ public Status handleInterfaceUpdate(NeutronNetwork network, Node source, Interface intf) {
+ return null;
+ }
+
+ @Override
+ public Status handleInterfaceDelete(String tunnelType, NeutronNetwork network, Node source, Interface intf,
+ boolean isLastInstanceOnNode) {
+ return null;
+ }
+
+ @Override
+ public void initializeFlowRules(Node node) {
+
+ }
+
+ @Override
+ public void initializeOFFlowRules(Node openflowNode) {
+
+ }
+ }
+}
*</Import-Package>
<Bundle-Activator>org.opendaylight.ovsdb.lib.Activator</Bundle-Activator>
<Embed-Transitive>true</Embed-Transitive>
- <Export-Package>org.opendaylight.ovsdb.lib,
+ <Export-Package>
+ org.opendaylight.ovsdb.lib,
+ org.opendaylight.ovsdb.lib.error,
org.opendaylight.ovsdb.lib.jsonrpc,
org.opendaylight.ovsdb.lib.notation,
org.opendaylight.ovsdb.lib.operations,
+++ /dev/null
-/*
- * Copyright (C) 2013 Red Hat, Inc.
- *
- * 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, Dave Tucker
- */
-
-package org.opendaylight.ovsdb.neutron;
-
-import org.apache.felix.dm.Component;
-import org.opendaylight.controller.containermanager.IContainerManager;
-import org.opendaylight.controller.forwardingrulesmanager.IForwardingRulesManager;
-import org.opendaylight.controller.networkconfig.neutron.INeutronNetworkAware;
-import org.opendaylight.controller.networkconfig.neutron.INeutronNetworkCRUD;
-import org.opendaylight.controller.networkconfig.neutron.INeutronPortAware;
-import org.opendaylight.controller.networkconfig.neutron.INeutronPortCRUD;
-import org.opendaylight.controller.networkconfig.neutron.INeutronSecurityGroupAware;
-import org.opendaylight.controller.networkconfig.neutron.INeutronSecurityGroupCRUD;
-import org.opendaylight.controller.networkconfig.neutron.INeutronSecurityRuleAware;
-import org.opendaylight.controller.networkconfig.neutron.INeutronSecurityRuleCRUD;
-import org.opendaylight.controller.networkconfig.neutron.INeutronSubnetAware;
-import org.opendaylight.controller.networkconfig.neutron.INeutronSubnetCRUD;
-import org.opendaylight.controller.sal.binding.api.BindingAwareBroker;
-import org.opendaylight.controller.sal.core.ComponentActivatorAbstractBase;
-import org.opendaylight.controller.switchmanager.IInventoryListener;
-import org.opendaylight.ovsdb.neutron.provider.IProviderNetworkManager;
-import org.opendaylight.ovsdb.neutron.provider.ProviderNetworkManager;
-import org.opendaylight.ovsdb.plugin.IConnectionServiceInternal;
-import org.opendaylight.ovsdb.plugin.OvsdbConfigService;
-import org.opendaylight.ovsdb.plugin.OvsdbInventoryListener;
-
-/**
- * OSGi bundle activator for the OVSDB Neutron Interface.
- */
-public class Activator extends ComponentActivatorAbstractBase {
- /**
- * Function called when the activator starts just after some
- * initializations are done by the
- * ComponentActivatorAbstractBase.
- */
- @Override
- public void init() {
- }
-
- /**
- * Function called when the activator stops just before the
- * cleanup done by ComponentActivatorAbstractBase.
- *
- */
- @Override
- public void destroy() {
- }
-
- /**
- * Function that is used to communicate to dependency manager the
- * list of known implementations for services inside a container.
- *
- * @return An array containing all the CLASS objects that will be
- * instantiated in order to get an fully working implementation
- * Object
- */
- @Override
- public Object[] getImplementations() {
- Object[] res = {AdminConfigManager.class,
- InternalNetworkManager.class,
- TenantNetworkManager.class,
- NetworkHandler.class,
- SubnetHandler.class,
- PortHandler.class,
- SouthboundHandler.class,
- PortSecurityHandler.class,
- MDSALConsumer.class,
- ProviderNetworkManager.class};
- return res;
- }
-
- /**
- * Function that is called when configuration of the dependencies
- * is required.
- *
- * @param c dependency manager Component object, used for
- * configuring the dependencies exported and imported
- * @param imp Implementation class that is being configured,
- * needed as long as the same routine can configure multiple
- * implementations
- * @param containerName The containerName being configured, this allow
- * also optional per-container different behavior if needed, usually
- * should not be the case though.
- */
- @Override
- public void configureInstance(Component c, Object imp,
- String containerName) {
- if (imp.equals(AdminConfigManager.class)) {
- c.setInterface(IAdminConfigManager.class.getName(), null);
- }
-
- if (imp.equals(InternalNetworkManager.class)) {
- c.setInterface(IInternalNetworkManager.class.getName(), null);
- c.add(createServiceDependency().setService(IAdminConfigManager.class).setRequired(true));
- c.add(createServiceDependency().setService(IProviderNetworkManager.class));
- }
-
- if (imp.equals(TenantNetworkManager.class)) {
- c.setInterface(ITenantNetworkManager.class.getName(), null);
- c.add(createServiceDependency().setService(IProviderNetworkManager.class));
- }
-
- if (imp.equals(NetworkHandler.class)) {
- c.setInterface(INeutronNetworkAware.class.getName(), null);
- c.add(createServiceDependency().setService(ITenantNetworkManager.class).setRequired(true));
- }
-
- if (imp.equals(SubnetHandler.class)) {
- c.setInterface(INeutronSubnetAware.class.getName(), null);
- }
-
- if (imp.equals(PortHandler.class)) {
- c.setInterface(INeutronPortAware.class.getName(), null);
- }
-
- if (imp.equals(SouthboundHandler.class)) {
- c.setInterface(new String[] {OvsdbInventoryListener.class.getName(), IInventoryListener.class.getName()}, null);
- c.add(createServiceDependency().setService(IAdminConfigManager.class).setRequired(true));
- c.add(createServiceDependency().setService(IInternalNetworkManager.class).setRequired(true));
- c.add(createServiceDependency().setService(ITenantNetworkManager.class).setRequired(true));
- c.add(createServiceDependency().setService(IProviderNetworkManager.class).setRequired(true));
- }
-
- if (imp.equals(MDSALConsumer.class)) {
- c.setInterface(IMDSALConsumer.class.getName(), null);
- }
-
- if (imp.equals(ProviderNetworkManager.class)) {
- c.setInterface(IProviderNetworkManager.class.getName(), null);
- c.add(createServiceDependency()
- .setService(IAdminConfigManager.class)
- .setRequired(true));
- c.add(createServiceDependency()
- .setService(IInternalNetworkManager.class)
- .setRequired(true));
- c.add(createServiceDependency()
- .setService(ITenantNetworkManager.class)
- .setRequired(true));
- }
- if (imp.equals(PortSecurityHandler.class)) {
- c.setInterface(INeutronSecurityRuleAware.class.getName(), null);
- c.setInterface(INeutronSecurityGroupAware.class.getName(), null);
- }
-
- //ToDo: DT: We don't need these dependencies for every implementation...
- //ToDo: DT: Callbacks are only required when behaviour is more complex than simple set/unset operation
- c.add(createServiceDependency().
- setService(OvsdbConfigService.class).
- setCallbacks("setOVSDBConfigService", "unsetOVSDBConfigService").
- setRequired(true));
-
- c.add(createServiceDependency().
- setService(IConnectionServiceInternal.class).
- setCallbacks("setConnectionService", "unsetConnectionService").
- setRequired(true));
-
- c.add(createServiceDependency().
- setService(IContainerManager.class).
- setCallbacks("setContainerManager", "unsetContainerManager").
- setRequired(true));
-
- c.add(createServiceDependency().
- setService(IForwardingRulesManager.class).
- setCallbacks("setForwardingRulesManager", "unsetForwardingRulesManager").
- setRequired(true));
-
- c.add(createServiceDependency()
- .setService(BindingAwareBroker.class)
- .setCallbacks("setBindingAwareBroker", "unsetBindingAwareBroker")
- .setRequired(true));
-
- c.add(createServiceDependency().
- setService(INeutronNetworkCRUD.class).
- setCallbacks("setNeutronNetworkCRUD", "unsetNeutronNetworkCRUD").
- setRequired(true));
- c.add(createServiceDependency().
- setService(INeutronSubnetCRUD.class).
- setCallbacks("setNeutronSubnetCRUD", "unsetNeutronSubnetCRUD").
- setRequired(true));
- c.add(createServiceDependency().
- setService(INeutronPortCRUD.class).
- setCallbacks("setNeutronPortCRUD", "unsetNeutronPortCRUD").
- setRequired(true));
- c.add(createServiceDependency().
- setService(INeutronSecurityRuleCRUD.class).
- setCallbacks("setNeutronSecurityRuleCRUD", "unsetNeutronSecurityRuleCRUD").
- setRequired(true));
- c.add(createServiceDependency().
- setService(INeutronSecurityGroupCRUD.class).
- setCallbacks("setNeutronSecurityGroupCRUD", "unsetNeutronSecurityGroupCRUD").
- setRequired(true));
- }
-}
+++ /dev/null
-/*
- * Copyright (C) 2013 Red Hat, Inc.
- *
- * 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
- */
-package org.opendaylight.ovsdb.neutron;
-
-import java.net.InetAddress;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Map;
-
-import org.opendaylight.controller.sal.core.Node;
-import org.opendaylight.controller.sal.utils.ServiceHelper;
-import org.opendaylight.ovsdb.lib.notation.Row;
-import org.opendaylight.ovsdb.plugin.OvsdbConfigService;
-import org.opendaylight.ovsdb.schema.openvswitch.OpenVSwitch;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-public class AdminConfigManager implements IAdminConfigManager{
- static final Logger logger = LoggerFactory.getLogger(AdminConfigManager.class);
-
- private String integrationBridgeName;
- private String networkBridgeName;
- private String externalBridgeName;
- private String tunnelEndpointConfigName;
- private String patchToIntegration;
- private String patchToNetwork;
- private String providerMappingsConfigName;
- private String providerMappings;
-
- // Refer to /etc/quantum/plugins/openvswitch/ovs_quantum_plugin.ini
- private static String DEFAULT_TUNNEL_ENDPOINT_CONFIG_STRING = "local_ip";
- private static String DEFAULT_INTEGRATION_BRIDGENAME = "br-int";
- private static String DEFAULT_NETWORK_BRIDGENAME = "br-net";
- private static String DEFAULT_EXTERNAL_BRIDGENAME = "br-ex";
- private static String DEFAULT_PATCH_TO_INTEGRATION = "patch-int";
- private static String DEFAULT_PATCH_TO_NETWORK = "patch-net";
- private static String CONFIG_TUNNEL_ENDPOINT_CONFIG = "tunnel_endpoint_config_string";
- private static String CONFIG_INTEGRATION_BRIDGENAME = "integration_bridge";
- private static String CONFIG_NETWORK_BRIDGENAME = "network_bridge";
- private static String CONFIG_EXTERNAL_BRIDGENAME = "external_bridge";
- private static String CONFIG_PATCH_TO_INTEGRATION = "patch-int";
- private static String CONFIG_PATCH_TO_NETWORK = "patch-net";
- private static String DEFAULT_PROVIDER_MAPPINGS_CONFIG_STRING = "provider_mappings";
- private static String CONFIG_PROVIDER_MAPPINGS_CONFIG = "provider_mappings_config_string";
- private static String CONFIG_PROVIDER_MAPPINGS = "provider_mappings";
-
- public AdminConfigManager() {
- tunnelEndpointConfigName = System.getProperty(CONFIG_TUNNEL_ENDPOINT_CONFIG);
- integrationBridgeName = System.getProperty(CONFIG_INTEGRATION_BRIDGENAME);
- networkBridgeName = System.getProperty(CONFIG_NETWORK_BRIDGENAME);
- externalBridgeName = System.getProperty(CONFIG_EXTERNAL_BRIDGENAME);
- patchToIntegration = System.getProperty(CONFIG_PATCH_TO_INTEGRATION);
- patchToNetwork = System.getProperty(CONFIG_PATCH_TO_NETWORK);
- providerMappingsConfigName = System.getProperty(CONFIG_PROVIDER_MAPPINGS_CONFIG);
- providerMappings = System.getProperty(CONFIG_PROVIDER_MAPPINGS);
-
- if (tunnelEndpointConfigName == null) tunnelEndpointConfigName = DEFAULT_TUNNEL_ENDPOINT_CONFIG_STRING;
- if (integrationBridgeName == null) integrationBridgeName = DEFAULT_INTEGRATION_BRIDGENAME;
- if (networkBridgeName == null) networkBridgeName = DEFAULT_NETWORK_BRIDGENAME;
- if (externalBridgeName == null) externalBridgeName = DEFAULT_EXTERNAL_BRIDGENAME;
- if (patchToIntegration == null) patchToIntegration = DEFAULT_PATCH_TO_INTEGRATION;
- if (patchToNetwork == null) patchToNetwork = DEFAULT_PATCH_TO_NETWORK;
- if (providerMappingsConfigName == null) providerMappingsConfigName = DEFAULT_PROVIDER_MAPPINGS_CONFIG_STRING;
- }
-
- @Override
- public String getIntegrationBridgeName() {
- return integrationBridgeName;
- }
-
- @Override
- public void setIntegrationBridgeName(String integrationBridgeName) {
- this.integrationBridgeName = integrationBridgeName;
- }
-
- @Override
- public String getNetworkBridgeName() { return networkBridgeName; }
-
- @Override
- public void setNetworkBridgeName(String networkBridgeName) {
- this.networkBridgeName = networkBridgeName;
- }
-
- @Override
- public String getExternalBridgeName() {
- return externalBridgeName;
- }
-
- @Override
- public void setExternalBridgeName (String externalBridgeName) {
- this.externalBridgeName = externalBridgeName;
- }
-
- @Override
- public String getPatchToIntegration() {
- return patchToIntegration;
- }
-
- @Override
- public void setPatchToIntegration(String patchToIntegration) {
- this.patchToIntegration = patchToIntegration;
- }
-
- @Override
- public String getPatchToNetwork() { return patchToNetwork; }
-
- @Override
- public void setPatchToNetwork(String patchToNetwork) {
- this.patchToNetwork = patchToNetwork;
- }
-
- @Override
- public InetAddress getTunnelEndPoint(Node node) {
- InetAddress address = null;
- OvsdbConfigService ovsdbConfig = (OvsdbConfigService)ServiceHelper.getGlobalInstance(OvsdbConfigService.class, this);
- try {
- Map<String, Row> ovsTable = ovsdbConfig.getRows(node, ovsdbConfig.getTableName(node, OpenVSwitch.class));
-
- if (ovsTable == null) {
- logger.error("OpenVSwitch table is null for Node {} ", node);
- return null;
- }
-
- // While there is only one entry in the HashMap, we can't access it by index...
- for (Row row : ovsTable.values()) {
- OpenVSwitch ovsRow = ovsdbConfig.getTypedRow(node, OpenVSwitch.class, row);
- Map<String, String> configs = ovsRow.getOtherConfigColumn().getData();
-
- if (configs == null) {
- logger.debug("OpenVSwitch table is null for Node {} ", node);
- continue;
- }
-
- String tunnelEndpoint = configs.get(tunnelEndpointConfigName);
-
- if (tunnelEndpoint == null) {
- continue;
- }
-
- address = InetAddress.getByName(tunnelEndpoint);
- logger.debug("Tunnel Endpoint for Node {} {}", node, address.getHostAddress());
- break;
- }
- }
- catch (Exception e) {
- logger.error("Error populating Tunnel Endpoint for Node {} ", node, e);
- }
-
- return address;
- }
-
-
- /*
- * Return the physical interface mapped to the given neutron physical network.
- * Provider mappings will be of the following format:
- * provider_mappings=physnet1:eth1[,physnet2:eth2]
- */
- @Override
- public String getPhysicalInterfaceName (Node node, String physicalNetwork) {
- String phyIf = null;
-
- OvsdbConfigService ovsdbConfig = (OvsdbConfigService) ServiceHelper.getGlobalInstance(OvsdbConfigService.class, this);
- try {
- Map<String, Row> ovsTable = ovsdbConfig.getRows(node, ovsdbConfig.getTableName(node, OpenVSwitch.class));
-
- if (ovsTable == null) {
- logger.error("OpenVSwitch table is null for Node {} ", node);
- return null;
- }
-
- // Loop through all the OpenVSwitch rows looking for the first occurrence of other_config.
- // The specification does not restrict the number of rows so we choose the first we find.
- for (Row row : ovsTable.values()) {
- String providerMaps;
- OpenVSwitch ovsRow = ovsdbConfig.getTypedRow(node, OpenVSwitch.class, row);
- Map<String, String> configs = ovsRow.getOtherConfigColumn().getData();
-
- if (configs == null) {
- logger.debug("OpenVSwitch table is null for Node {} ", node);
- continue;
- }
-
- providerMaps = configs.get(providerMappingsConfigName);
- if (providerMaps == null) {
- providerMaps = providerMappings;
- }
-
- if (providerMaps != null) {
- for (String map : providerMaps.split(",")) {
- String[] pair = map.split(":");
- if (pair[0].equals(physicalNetwork)) {
- phyIf = pair[1];
- break;
- }
- }
- }
-
- if (phyIf != null) {
- break;
- }
- }
- } catch (Exception e) {
- logger.error("Unable to find physical interface for Node: {}, Network {}",
- node, physicalNetwork, e);
- }
-
- if (phyIf == null) {
- logger.error("Physical interface not found for Node: {}, Network {}",
- node, physicalNetwork);
- }
-
- return phyIf;
- }
-
- /* Return all physical interfaces configure in bridge mapping
- * Bridge mappings will be of the following format:
- * bridge_mappings=physnet1:eth1,physnet2:eth2
- * Method will return list = {eth1, eth2}
- */
- @Override
- public List<String> getAllPhysicalInterfaceNames(Node node) {
- List<String> phyIfName = new ArrayList<String>();
-
- try {
- OvsdbConfigService ovsdbConfig = (OvsdbConfigService) ServiceHelper.getGlobalInstance(OvsdbConfigService.class, this);
- Map<String, Row> ovsTable = ovsdbConfig.getRows(node, ovsdbConfig.getTableName(node, OpenVSwitch.class));
-
- if (ovsTable == null) {
- logger.error("OpenVSwitch table is null for Node {} ", node);
- return null;
- }
-
- // While there is only one entry in the HashMap, we can't access it by index...
- for (Row row : ovsTable.values()) {
- String bridgeMaps;
- OpenVSwitch ovsRow = ovsdbConfig.getTypedRow(node, OpenVSwitch.class, row);
- Map<String, String> configs = ovsRow.getOtherConfigColumn().getData();
-
- if (configs == null) {
- logger.debug("OpenVSwitch table is null for Node {} ", node);
- continue;
- }
-
- bridgeMaps = configs.get(providerMappingsConfigName);
- if (bridgeMaps == null) {
- bridgeMaps = providerMappings;
- }
-
- if (bridgeMaps != null) {
- for (String map : bridgeMaps.split(",")) {
- String[] pair = map.split(":");
- phyIfName.add(pair[1]);
- }
- }
- }
- } catch (Exception e) {
- logger.error("Unable to find physical interface for Node: {}",
- node, e);
- }
-
- logger.debug("Physical interface for Node: {}, If: {}",
- node, phyIfName);
-
- return phyIfName;
- }
-}
+++ /dev/null
-/*
- * Copyright (C) 2013 Red Hat, Inc.
- *
- * 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
- */
-package org.opendaylight.ovsdb.neutron;
-
-import java.net.HttpURLConnection;
-import java.util.UUID;
-
-import org.opendaylight.controller.containermanager.IContainerManager;
-import org.opendaylight.controller.forwardingrulesmanager.IForwardingRulesManager;
-import org.opendaylight.controller.networkconfig.neutron.INeutronNetworkCRUD;
-import org.opendaylight.controller.networkconfig.neutron.INeutronPortCRUD;
-import org.opendaylight.controller.networkconfig.neutron.INeutronSecurityGroupCRUD;
-import org.opendaylight.controller.networkconfig.neutron.INeutronSecurityRuleCRUD;
-import org.opendaylight.controller.networkconfig.neutron.INeutronSubnetCRUD;
-import org.opendaylight.controller.sal.utils.Status;
-import org.opendaylight.controller.sal.utils.StatusCode;
-import org.opendaylight.ovsdb.plugin.IConnectionServiceInternal;
-import org.opendaylight.ovsdb.plugin.OvsdbConfigService;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-/**
- * Base utility functions used by neutron handlers.
- */
-public class BaseHandler {
-
- /**
- * Logger instance.
- */
- static final Logger logger = LoggerFactory.getLogger(BaseHandler.class);
-
- /**
- * Neutron UUID identifier length.
- */
- private static final int UUID_LEN = 36;
-
- /**
- * Tenant id length when keystone identifier is used in neutron.
- */
- private static final int KEYSTONE_ID_LEN = 32;
-
- /**
- * UUID version number position.
- */
- private static final int UUID_VERSION_POS = 12;
-
- /**
- * UUID time-low field byte length in hex.
- */
- private static final int UUID_TIME_LOW = 8;
-
- /**
- * UUID time-mid field byte length in hex.
- */
- private static final int UUID_TIME_MID = 4;
-
- /**
- * UUID time-high and version field byte length in hex.
- */
- private static final int UUID_TIME_HIGH_VERSION = 4;
-
- /**
- * UUID clock sequence field byte length in hex.
- */
- private static final int UUID_CLOCK_SEQ = 4;
-
- /**
- * UUID node field byte length in hex.
- */
- private static final int UUID_NODE = 12;
-
- /**
- * UUID time field byte length in hex.
- */
- private static final int UUID_TIME_LEN = (UUID_TIME_LOW +
- UUID_TIME_MID + UUID_TIME_HIGH_VERSION);
-
- /**
- * Convert failure status returned by the manager into
- * neutron API service errors.
- *
- * @param status manager status
- * @return An error to be returned to neutron API service.
- */
- protected static final int getException(Status status) {
- int result = HttpURLConnection.HTTP_INTERNAL_ERROR;
-
- assert !status.isSuccess();
-
- StatusCode code = status.getCode();
- logger.debug(" Execption code - {}, description - {}",
- code, status.getDescription());
-
- if (code == StatusCode.BADREQUEST) {
- result = HttpURLConnection.HTTP_BAD_REQUEST;
- } else if (code == StatusCode.CONFLICT) {
- result = HttpURLConnection.HTTP_CONFLICT;
- } else if (code == StatusCode.NOTACCEPTABLE) {
- result = HttpURLConnection.HTTP_NOT_ACCEPTABLE;
- } else if (code == StatusCode.NOTFOUND) {
- result = HttpURLConnection.HTTP_NOT_FOUND;
- } else {
- result = HttpURLConnection.HTTP_INTERNAL_ERROR;
- }
-
- return result;
- }
-
- /**
- * Verify the validity of neutron object identifiers.
- *
- * @param id neutron object id.
- * @return {@code true} neutron identifier is valid.
- * {@code false} neutron identifier is invalid.
- */
- protected static final boolean isValidNeutronID(String id) {
- if (id == null) {
- return false;
- }
- boolean isValid = false;
- logger.trace("id - {}, length - {} ", id, id.length());
- /**
- * check the string length
- * if length is 36 its a uuid do uuid validation
- * if length is 32 it can be tenant id form keystone
- * if its less than 32 can be valid ID
- */
- if (id.length() == UUID_LEN) {
- try {
- UUID fromUUID = UUID.fromString(id);
- String toUUID = fromUUID.toString();
- isValid = toUUID.equalsIgnoreCase(id);
- } catch(IllegalArgumentException e) {
- logger.error(" IllegalArgumentExecption for id - {} ", id);
- isValid = false;
- }
- } else if ((id.length() > 0) && (id.length() <= KEYSTONE_ID_LEN)) {
- isValid = true;
- } else {
- isValid = false;
- }
- return isValid;
- }
-
- /**
- * Convert UUID to key syntax.
- *
- * @param id neutron object UUID.
- * @return key in compliance to object key.
- */
- private static String convertUUIDToKey(String id) {
-
- String key = null;
- if (id == null) {
- return key;
- }
- logger.trace("id - {}, length - {} ", id, id.length());
- /**
- * ID must be less than 32 bytes,
- * Shorten UUID string length from 36 to 31 as follows:
- * delete UUID Version and hyphen (see RFC4122) field in the UUID
- */
- try {
- StringBuilder tKey = new StringBuilder();
- // remove all the '-'
- for (String retkey: id.split("-")) {
- tKey.append(retkey);
- }
- // remove the version byte
- tKey.deleteCharAt(UUID_VERSION_POS);
- key = tKey.toString();
- } catch(IllegalArgumentException ile) {
- logger.error(" Invalid UUID - {} ", id);
- key = null;
- }
- return key;
- }
-
- /**
- * Convert string id to key syntax.
- *
- * @param id neutron object id.
- * @return key in compliance to object key.
- */
- private static String convertKeystoneIDToKey(String id) {
- String key = null;
- if (id == null) {
- return key;
- }
-
- /**
- * tenant ID if given from openstack keystone does not follow the
- * generic UUID syntax, convert the ID to UUID format for validation
- * and reconvert it to key
- */
-
- logger.trace(" id - {}, length - {} ", id, id.length());
- try {
- StringBuilder tKey = new StringBuilder();
- String tmpStr = id.substring(0, UUID_TIME_LOW);
- tKey.append(tmpStr);
- tKey.append("-");
- tmpStr = id.substring(UUID_TIME_LOW,
- (UUID_TIME_LOW + UUID_TIME_MID));
- tKey.append(tmpStr);
- tKey.append("-");
- tmpStr = id.substring((UUID_TIME_LOW + UUID_TIME_MID),
- UUID_TIME_LEN);
- tKey.append(tmpStr);
- tKey.append("-");
- tmpStr = id.substring(UUID_TIME_LEN,
- (UUID_TIME_LEN + UUID_CLOCK_SEQ));
- tKey.append(tmpStr);
- tKey.append("-");
- tmpStr = id.substring((UUID_TIME_LEN + UUID_CLOCK_SEQ),
- (UUID_TIME_LEN + UUID_CLOCK_SEQ + UUID_NODE));
- tKey.append(tmpStr);
-
- tmpStr = tKey.toString();
- UUID fromUUID = UUID.fromString(tmpStr);
- String toUUID = fromUUID.toString();
- if (toUUID.equalsIgnoreCase(tmpStr)) {
- key = convertUUIDToKey(tmpStr);
- }
- } catch(IndexOutOfBoundsException ibe) {
- logger.error(" Execption! Invalid UUID - {} ", id);
- key = null;
- } catch (IllegalArgumentException iae) {
- logger.error(" Execption! Invalid object ID - {} ", id);
- key = null;
- }
- return key;
- }
-
- /**
- * Convert neutron object id to key syntax.
- *
- * @param neutronID neutron object id.
- * @return key in compliance to object key.
- */
- protected static final String convertNeutronIDToKey(String neutronID) {
- String key = null;
- if (neutronID == null) {
- return key;
- }
-
- logger.trace(" neutronID - {}, length - {} ",
- neutronID, neutronID.length());
- if (!isValidNeutronID(neutronID)) {
- return key;
- }
-
- if (neutronID.length() == UUID_LEN) {
- key = convertUUIDToKey(neutronID);
- } else if (neutronID.length() == KEYSTONE_ID_LEN) {
- key = convertKeystoneIDToKey(neutronID);
- } else {
- key = neutronID;
- }
- return key;
- }
-
- protected IContainerManager containerManager;
-
- public IContainerManager getContainerManager() {
- return containerManager;
- }
-
- public void unsetContainerManager(IContainerManager s) {
- if (s == this.containerManager) {
- this.containerManager = null;
- }
- }
-
- public void setContainerManager(IContainerManager s) {
- this.containerManager = s;
- }
-
- protected IForwardingRulesManager frm;
-
- public IForwardingRulesManager getForwardingRulesManager() {
- return frm;
- }
-
- public void unsetForwardingRulesManager(IForwardingRulesManager s) {
- if (s == this.frm) {
- this.frm = null;
- }
- }
-
- public void setForwardingRulesManager(IForwardingRulesManager s) {
- this.frm = s;
- }
-
- protected OvsdbConfigService ovsdbConfigService;
-
- public OvsdbConfigService getOVSDBConfigService() {
- return ovsdbConfigService;
- }
-
- public void unsetOVSDBConfigService(OvsdbConfigService s) {
- if (s == this.ovsdbConfigService) {
- this.ovsdbConfigService = null;
- }
- }
-
- public void setOVSDBConfigService(OvsdbConfigService s) {
- this.ovsdbConfigService = s;
- }
-
- protected IConnectionServiceInternal connectionService;
-
- public IConnectionServiceInternal getConnectionService() {
- return connectionService;
- }
-
- public void unsetConnectionService(IConnectionServiceInternal s) {
- if (s == this.connectionService) {
- this.connectionService = null;
- }
- }
-
- public void setConnectionService(IConnectionServiceInternal s) {
- this.connectionService = s;
- }
-
- protected INeutronPortCRUD neutronPortCache;
- public INeutronPortCRUD getNeutronPortCRUD() {
- return neutronPortCache;
- }
-
- public void unsetNeutronPortCRUD(INeutronPortCRUD s) {
- if (s == this.neutronPortCache) {
- this.neutronPortCache = null;
- }
- }
-
- public void setNeutronPortCRUD(INeutronPortCRUD s) {
- this.neutronPortCache = s;
- }
-
- protected INeutronSubnetCRUD neutronSubnetCache;
- public INeutronSubnetCRUD getNeutronSubnetCRUD() {
- return neutronSubnetCache;
- }
-
- public void unsetNeutronSubnetCRUD(INeutronSubnetCRUD s) {
- if (s == this.neutronSubnetCache) {
- this.neutronSubnetCache = null;
- }
- }
-
- public void setNeutronSubnetCRUD(INeutronSubnetCRUD s) {
- this.neutronSubnetCache = s;
- }
-
- protected INeutronNetworkCRUD neutronNetworkCache;
- public INeutronNetworkCRUD getNeutronNetworkCRUD() {
- return neutronNetworkCache;
- }
-
- public void unsetNeutronNetworkCRUD(INeutronNetworkCRUD s) {
- if (s == this.neutronNetworkCache) {
- this.neutronNetworkCache = null;
- }
- }
-
- public void setNeutronNetworkCRUD(INeutronNetworkCRUD s) {
- this.neutronNetworkCache = s;
- }
-
- protected INeutronSecurityRuleCRUD neutronSecurityRuleCache;
- public void setNeutronSecurityRuleCache(INeutronSecurityRuleCRUD s) {
- this.neutronSecurityRuleCache = s;
- }
-
- protected INeutronSecurityGroupCRUD neutronSecurityGroupCache;
- public void setNeutronSecurityGroupCache(INeutronSecurityGroupCRUD s) {
- this.neutronSecurityGroupCache = s;
- }
-}
+++ /dev/null
-/*
- * Copyright (C) 2014 Red Hat, Inc.
- *
- * 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 : Dave Tucker
- */
-
-package org.opendaylight.ovsdb.neutron;
-
-import java.net.InetAddress;
-import java.util.List;
-
-import org.opendaylight.controller.sal.core.Node;
-
-public interface IAdminConfigManager {
- public String getIntegrationBridgeName();
- public void setIntegrationBridgeName(String integrationBridgeName);
- public String getNetworkBridgeName();
- public void setNetworkBridgeName(String networkBridgeName);
- public String getPatchToNetwork();
- public void setPatchToNetwork(String patchToNetwork);
- public String getExternalBridgeName();
- public void setExternalBridgeName (String externalBridgeName);
- public String getPatchToIntegration();
- public void setPatchToIntegration(String patchToIntegration);
- public String getPhysicalInterfaceName (Node node, String physicalNetwork);
- public List<String> getAllPhysicalInterfaceNames(Node node);
- public InetAddress getTunnelEndPoint(Node node);
-}
\ No newline at end of file
+++ /dev/null
-/*
- * Copyright (C) 2014 Red Hat, Inc.
- *
- * 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 : Dave Tucker
- */
-
-package org.opendaylight.ovsdb.neutron;
-
-import org.opendaylight.controller.networkconfig.neutron.NeutronNetwork;
-import org.opendaylight.controller.sal.core.Node;
-import org.opendaylight.ovsdb.schema.openvswitch.Bridge;
-
-public interface IInternalNetworkManager {
- public String getInternalBridgeUUID (Node node, String bridgeName);
- public boolean isInternalNetworkNeutronReady(Node node);
- public boolean isInternalNetworkOverlayReady(Node node);
- public boolean isInternalNetworkTunnelReady (Node node);
- public boolean isInternalNetworkVlanReady (Node node, NeutronNetwork network);
- public boolean isPortOnBridge (Node node, Bridge bridge, String portName);
- public void createIntegrationBridge (Node node) throws Exception;
- public boolean createNetNetwork (Node node, NeutronNetwork network) throws Exception;
- public boolean checkAndCreateNetwork (Node node, NeutronNetwork network);
- public void prepareInternalNetwork(Node node);
-}
\ No newline at end of file
+++ /dev/null
-/*
- * Copyright (C) 2014 Red Hat, Inc.
- *
- * 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 : Dave Tucker
- */
-
-package org.opendaylight.ovsdb.neutron;
-
-import org.opendaylight.controller.networkconfig.neutron.NeutronNetwork;
-import org.opendaylight.controller.sal.core.Node;
-import org.opendaylight.ovsdb.schema.openvswitch.Interface;
-
-
-public interface ITenantNetworkManager {
- public static final String EXTERNAL_ID_VM_ID = "vm-id";
- public static final String EXTERNAL_ID_INTERFACE_ID = "iface-id";
- public static final String EXTERNAL_ID_VM_MAC = "attached-mac";
- public int getInternalVlan(Node node, String networkId);
- public void reclaimTenantNetworkInternalVlan(Node node, String portUUID, NeutronNetwork network);
- public void networkCreated (String networkId);
- public int networkCreated (Node node, String networkId);
- public boolean isTenantNetworkPresentInNode(Node node, String segmentationId);
- public String getNetworkIdForSegmentationId (String segmentationId);
- public NeutronNetwork getTenantNetworkForInterface (Interface intf);
- public void programTenantNetworkInternalVlan(Node node, String portUUID, NeutronNetwork network);
- public void networkDeleted(String id);
-}
\ No newline at end of file
+++ /dev/null
-/*
- * Copyright (C) 2013 Red Hat, Inc.
- *
- * 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
- */
-package org.opendaylight.ovsdb.neutron;
-
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.Map;
-import java.util.Set;
-
-import org.opendaylight.controller.networkconfig.neutron.NeutronNetwork;
-import org.opendaylight.controller.sal.core.Node;
-import org.opendaylight.controller.sal.utils.ServiceHelper;
-import org.opendaylight.controller.sal.utils.Status;
-import org.opendaylight.controller.sal.utils.StatusCode;
-import org.opendaylight.ovsdb.lib.notation.Row;
-import org.opendaylight.ovsdb.lib.notation.UUID;
-import org.opendaylight.ovsdb.neutron.provider.IProviderNetworkManager;
-import org.opendaylight.ovsdb.plugin.OvsdbConfigService;
-import org.opendaylight.ovsdb.plugin.StatusWithUuid;
-import org.opendaylight.ovsdb.schema.openvswitch.Bridge;
-import org.opendaylight.ovsdb.schema.openvswitch.Interface;
-import org.opendaylight.ovsdb.schema.openvswitch.Port;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-/**
- * OpenStack Neutron with the OpenvSwitch data plan relies on a typical OVS bridge configurations that
- * consists of br-int (Integration Bridge), br-tun (Tunnel bridge), br-ex (External bridge).
- *
- * In DevStack like setups, the br-tun is not automatically created on the controller nodes.
- * Hence this class attempts to bring all the nodes to be eligible for OpenStack operations.
- *
- */
-public class InternalNetworkManager implements IInternalNetworkManager {
- static final Logger logger = LoggerFactory.getLogger(InternalNetworkManager.class);
- private static final int LLDP_PRIORITY = 1000;
- private static final int NORMAL_PRIORITY = 0;
-
- // The implementation for each of these services is resolved by the OSGi Service Manager
- private volatile IAdminConfigManager adminConfigManager;
- private volatile IProviderNetworkManager providerNetworkManager;
-
- public InternalNetworkManager() {
- }
-
- @Override
- public String getInternalBridgeUUID (Node node, String bridgeName) {
- try {
- OvsdbConfigService ovsdbTable = (OvsdbConfigService)ServiceHelper.getGlobalInstance(OvsdbConfigService.class, this);
- Map<String, Row> bridgeTable = ovsdbTable.getRows(node, ovsdbTable.getTableName(node, Bridge.class));
- if (bridgeTable == null) return null;
- for (String key : bridgeTable.keySet()) {
- Bridge bridge = ovsdbTable.getTypedRow(node, Bridge.class, bridgeTable.get(key));
- if (bridge.getName().equals(bridgeName)) return key;
- }
- } catch (Exception e) {
- logger.error("Error getting Bridge Identifier for {} / {}", node, bridgeName, e);
- }
- return null;
- }
-
- public Bridge getInternalBridge (Node node, String bridgeName) {
- try {
- OvsdbConfigService ovsdbTable = (OvsdbConfigService) ServiceHelper.getGlobalInstance(OvsdbConfigService.class, this);
- Map<String, Row> bridgeTable = ovsdbTable.getRows(node, ovsdbTable.getTableName(node, Bridge.class));
- if (bridgeTable != null) {
- for (String key : bridgeTable.keySet()) {
- Bridge bridge = ovsdbTable.getTypedRow(node, Bridge.class, bridgeTable.get(key));
- if (bridge.getName().equals(bridgeName)) {
- return bridge;
- }
- }
- }
- } catch (Exception e) {
- logger.error("Error getting Bridge Identifier for {} / {}", node, bridgeName, e);
- }
- return null;
- }
-
- @Override
- public boolean isInternalNetworkNeutronReady(Node node) {
- if (this.getInternalBridgeUUID(node, adminConfigManager.getIntegrationBridgeName()) != null) {
- return true;
- } else {
- return false;
- }
- }
-
- @Override
- public boolean isInternalNetworkOverlayReady(Node node) {
- if (!this.isInternalNetworkNeutronReady(node)) {
- return false;
- }
- if (this.getInternalBridgeUUID(node, adminConfigManager.getNetworkBridgeName()) != null) {
- return true;
- } else {
- return false;
- }
- }
-
- @Override
- public boolean isPortOnBridge (Node node, Bridge bridge, String portName) {
- OvsdbConfigService ovsdbTable = (OvsdbConfigService) ServiceHelper.getGlobalInstance(OvsdbConfigService.class, this);
-
- for (UUID portsUUID : bridge.getPortsColumn().getData()) {
- try {
- Row portRow = ovsdbTable.getRow(node, ovsdbTable.getTableName(node, Port.class), portsUUID.toString());
- Port port = ovsdbTable.getTypedRow(node, Port.class, portRow);
- if ((port != null) && port.getName().equalsIgnoreCase(portName)) {
- return true;
- }
- } catch (Exception e) {
- logger.error("Error getting port {} for bridge domain {}/{}", portsUUID, node, bridge.getName(), e);
- }
- }
-
- return false;
- }
-
- public boolean isNetworkPatchCreated (Node node, Bridge intBridge, Bridge netBridge) {
- boolean isPatchCreated = false;
-
- String portName = adminConfigManager.getPatchToNetwork();
- if (isPortOnBridge(node, intBridge, portName)) {
- portName = adminConfigManager.getPatchToIntegration();
- if (isPortOnBridge(node, netBridge, portName)) {
- isPatchCreated = true;
- }
- }
-
- return isPatchCreated;
- }
-
- /* Determine if internal network is ready for tunnel network types.
- * - OF 1.0 requires br-int, br-net and a patch connecting them.
- * - OF 1.3 requires br-int.
- */
- @Override
- public boolean isInternalNetworkTunnelReady (Node node) {
- /* Is br-int created? */
- Bridge intBridge = this.getInternalBridge(node, adminConfigManager.getIntegrationBridgeName());
- if (intBridge == null) {
- return false;
- }
-
- if (providerNetworkManager == null) {
- logger.error("Provider Network Manager is not available");
- return false;
- }
- if (providerNetworkManager.getProvider().hasPerTenantTunneling()) {
- /* Is br-net created? */
- Bridge netBridge = this.getInternalBridge(node, adminConfigManager.getNetworkBridgeName());
- if (netBridge == null) {
- return false;
- }
-
- if (!isNetworkPatchCreated(node, intBridge, netBridge)) {
- return false;
- }
- }
- return true;
- }
-
- /* Determine if internal network is ready for vlan network types.
- * - OF 1.0 requires br-int, br-net, a patch connecting them and
- * physical device added to br-net.
- * - OF 1.3 requires br-int and physical device added to br-int.
- */
- @Override
- public boolean isInternalNetworkVlanReady (Node node, NeutronNetwork network) {
- /* is br-int created */
- Bridge intBridge = this.getInternalBridge(node, adminConfigManager.getIntegrationBridgeName());
- if (intBridge == null) {
- logger.trace("shague isInternalNetworkVlanReady: node: {}, br-int missing", node);
- return false;
- }
-
- if (providerNetworkManager == null) {
- logger.error("Provider Network Manager is not available");
- return false;
- }
- if (providerNetworkManager.getProvider().hasPerTenantTunneling()) {
- /* is br-net created? */
- Bridge netBridge = this.getInternalBridge(node, adminConfigManager.getNetworkBridgeName());
-
- if (netBridge == null) {
- logger.trace("shague isInternalNetworkVlanReady: node: {}, br-net missing", node);
- return false;
- }
-
- if (!isNetworkPatchCreated(node, intBridge, netBridge)) {
- logger.trace("shague isInternalNetworkVlanReady: node: {}, patch missing", node);
- return false;
- }
-
- /* Check if physical device is added to br-net. */
- String phyNetName = adminConfigManager.getPhysicalInterfaceName(node, network.getProviderPhysicalNetwork());
- if (isPortOnBridge(node, netBridge, phyNetName)) {
- return true;
- }
- } else {
- /* Check if physical device is added to br-int. */
- String phyNetName = adminConfigManager.getPhysicalInterfaceName(node, network.getProviderPhysicalNetwork());
- if (isPortOnBridge(node, intBridge, phyNetName)) {
- return true;
- }
- }
-
- logger.trace("shague isInternalNetworkVlanReady: node: {}, eth missing", node);
- return false;
- }
-
- /*
- * Create the integration bridge.
- *
- Bridge br-int
- Port br-int
- Interface br-int
- type: internal
- */
- @Override
- public void createIntegrationBridge (Node node) throws Exception {
- String brInt = adminConfigManager.getIntegrationBridgeName();
-
- Status status = this.addInternalBridge(node, brInt, null, null);
- if (!status.isSuccess()) {
- logger.debug("Integration Bridge Creation Status: {}", status);
- }
- }
-
- /*
- * Create complete network for all network types and OpenFlow versions.
- *
- OF 1.0 vlan:
- Bridge br-int
- Port patch-net
- Interface patch-net
- type: patch
- options: {peer=patch-int}
- Port br-int
- Interface br-int
- type: internal
- Bridge br-net
- Port "eth1"
- Interface "eth1"
- Port patch-int
- Interface patch-int
- type: patch
- options: {peer=patch-net}
- Port br-net
- Interface br-net
- type: internal
-
- OF 1.0 tunnel:
- Bridge br-int
- Port patch-net
- Interface patch-net
- type: patch
- options: {peer=patch-int}
- Port br-int
- Interface br-int
- type: internal
- Bridge "br-net"
- Port patch-int
- Interface patch-int
- type: patch
- options: {peer=patch-net}
- Port br-net
- Interface br-net
- type: internal
-
- OF 1.3 vlan:
- Bridge br-int
- Port "eth1"
- Interface "eth1"
- Port br-int
- Interface br-int
- type: internal
-
- OF 1.3 tunnel:
- Bridge br-int
- Port br-int
- Interface br-int
- type: internal
- */
- @Override
- public boolean createNetNetwork (Node node, NeutronNetwork network) throws Exception {
- Status status;
-
- logger.debug("createNetNetwork: node: {}, network type: {}", node, network.getProviderNetworkType());
-
- if (providerNetworkManager == null) {
- logger.error("Provider Network Manager is not available");
- return false;
- }
- if (providerNetworkManager.getProvider().hasPerTenantTunneling()) { /* indicates OF 1.0 */
- String brInt = adminConfigManager.getIntegrationBridgeName();
- String brNet = adminConfigManager.getNetworkBridgeName();
- String patchNet = adminConfigManager.getPatchToNetwork();
- String patchInt = adminConfigManager.getPatchToIntegration();
-
- status = this.addInternalBridge(node, brInt, patchNet, patchInt);
- if (!status.isSuccess()) {
- logger.debug("{} Bridge Creation Status: {}", brInt, status);
- return false;
- }
- status = this.addInternalBridge(node, brNet, patchInt, patchNet);
- if (!status.isSuccess()) {
- logger.debug("{} Bridge Creation Status: {}", brNet, status);
- return false;
- }
-
- /* For vlan network types add physical port to br-net. */
- if (network.getProviderNetworkType().equalsIgnoreCase(NetworkHandler.NETWORK_TYPE_VLAN)) {
- String phyNetName = adminConfigManager.getPhysicalInterfaceName(node, network.getProviderPhysicalNetwork());
- status = addPortToBridge(node, brNet, phyNetName);
- if (!status.isSuccess()) {
- logger.debug("Add Port {} to Bridge {} Status: {}", phyNetName, brNet, status);
- return false;
- }
- }
- } else {
- String brInt = adminConfigManager.getIntegrationBridgeName();
- status = this.addInternalBridge(node, brInt, null, null);
- if (!status.isSuccess()) {
- logger.debug("{} Bridge Creation Status: {}", brInt, status);
- return false;
- }
-
- /* For vlan network types add physical port to br-int. */
- if (network.getProviderNetworkType().equalsIgnoreCase(NetworkHandler.NETWORK_TYPE_VLAN)) {
- String phyNetName = adminConfigManager.getPhysicalInterfaceName(node, network.getProviderPhysicalNetwork());
- status = addPortToBridge(node, brInt, phyNetName);
- if (!status.isSuccess()) {
- logger.debug("Add Port {} to Bridge {} Status: {}", phyNetName, brInt, status);
- return false;
- }
- }
- }
-
- logger.debug("createNetNetwork: node: {}, status: success", node);
- return true;
- }
-
- private Status addPortToBridge (Node node, String bridgeName, String portName) throws Exception {
- logger.debug("addPortToBridge: Adding port: {} to Bridge {}, Node {}", portName, bridgeName, node);
- OvsdbConfigService ovsdbTable = (OvsdbConfigService)ServiceHelper.getGlobalInstance(OvsdbConfigService.class, this);
-
- String bridgeUUID = this.getInternalBridgeUUID(node, bridgeName);
- if (bridgeUUID == null) {
- logger.error("addPortToBridge: Could not find Bridge {} in Node {}", bridgeName, node);
- return new Status(StatusCode.NOTFOUND, "Could not find "+bridgeName+" in "+node);
- }
-
- /* Check if the port already exists. */
- Row row = ovsdbTable.getRow(node, ovsdbTable.getTableName(node, Bridge.class), bridgeUUID);
- Bridge bridge = ovsdbTable.getTypedRow(node, Bridge.class, row);
- if (bridge != null) {
- if (isPortOnBridge(node, bridge, portName)) {
- logger.debug("addPortToBridge: Port {} already in Bridge {}, Node {}", portName, bridgeName, node);
- return new Status(StatusCode.SUCCESS);
- }
- } else {
- logger.error("addPortToBridge: Could not find Port {} in Bridge {}, Node {}", portName, bridgeName, node);
- return new Status(StatusCode.NOTFOUND, "Could not find "+portName+" in "+bridgeName);
- }
-
- Port port = ovsdbTable.createTypedRow(node, Port.class);
- port.setName(portName);
- StatusWithUuid statusWithUuid = ovsdbTable.insertRow(node, port.getSchema().getName(), bridgeUUID, port.getRow());
- if (!statusWithUuid.isSuccess()) {
- logger.error("addPortToBridge: Failed to add Port {} in Bridge {}, Node {}", portName, bridgeName, node);
- return statusWithUuid;
- }
-
- String portUUID = statusWithUuid.getUuid().toString();
- String interfaceUUID = null;
- int timeout = 6;
- while ((interfaceUUID == null) && (timeout > 0)) {
- Row portRow = ovsdbTable.getRow(node, port.getSchema().getName(), portUUID);
- port = ovsdbTable.getTypedRow(node, Port.class, portRow);
- Set<UUID> interfaces = port.getInterfacesColumn().getData();
- if (interfaces == null || interfaces.size() == 0) {
- // Wait for the OVSDB update to sync up the Local cache.
- Thread.sleep(500);
- timeout--;
- continue;
- }
- interfaceUUID = interfaces.toArray()[0].toString();
- Row intf = ovsdbTable.getRow(node, ovsdbTable.getTableName(node, Interface.class), interfaceUUID);
- if (intf == null) {
- interfaceUUID = null;
- }
- }
-
- if (interfaceUUID == null) {
- logger.error("addPortToBridge: Cannot identify Interface for port {}/{}", portName, portUUID);
- return new Status(StatusCode.INTERNALERROR);
- }
-
- return new Status(StatusCode.SUCCESS);
- }
-
- private Status addPatchPort (Node node, String bridgeUUID, String portName, String peerPortName) throws Exception {
- OvsdbConfigService ovsdbTable = (OvsdbConfigService)ServiceHelper.getGlobalInstance(OvsdbConfigService.class, this);
-
- logger.debug("addPatchPort: node: {}, bridgeUUID: {}, port: {}, peer: {}",
- node, bridgeUUID, portName, peerPortName);
-
- /* Check if the port already exists. */
- Row bridgeRow = ovsdbTable.getRow(node, ovsdbTable.getTableName(node, Bridge.class), bridgeUUID);
- Bridge bridge = ovsdbTable.getTypedRow(node, Bridge.class, bridgeRow);
- if (bridge != null) {
- if (isPortOnBridge(node, bridge, portName)) {
- logger.debug("addPatchPort: Port {} already in Bridge, Node {}", portName, node);
- return new Status(StatusCode.SUCCESS);
- }
- } else {
- logger.error("addPatchPort: Could not find Port {} in Bridge, Node {}", portName, node);
- return new Status(StatusCode.NOTFOUND, "Could not find "+portName+" in Bridge");
- }
-
- Port patchPort = ovsdbTable.createTypedRow(node, Port.class);
- patchPort.setName(portName);
- // Create patch port and interface
- StatusWithUuid statusWithUuid = ovsdbTable.insertRow(node, patchPort.getSchema().getName(), bridgeUUID, patchPort.getRow());
- if (!statusWithUuid.isSuccess()) return statusWithUuid;
-
- String patchPortUUID = statusWithUuid.getUuid().toString();
-
- String interfaceUUID = null;
- int timeout = 6;
- while ((interfaceUUID == null) && (timeout > 0)) {
- Row portRow = ovsdbTable.getRow(node, patchPort.getSchema().getName(), patchPortUUID);
- patchPort = ovsdbTable.getTypedRow(node, Port.class, portRow);
- Set<UUID> interfaces = patchPort.getInterfacesColumn().getData();
- if (interfaces == null || interfaces.size() == 0) {
- // Wait for the OVSDB update to sync up the Local cache.
- Thread.sleep(500);
- timeout--;
- continue;
- }
- interfaceUUID = interfaces.toArray()[0].toString();
- }
-
- if (interfaceUUID == null) {
- return new Status(StatusCode.INTERNALERROR);
- }
-
- Interface intf = ovsdbTable.createTypedRow(node, Interface.class);
- intf.setType("patch");
- Map<String, String> options = new HashMap<String, String>();
- options.put("peer", peerPortName);
- intf.setOptions(options);
- return ovsdbTable.updateRow(node, intf.getSchema().getName(), patchPortUUID, interfaceUUID, intf.getRow());
- }
-
- private Status addInternalBridge (Node node, String bridgeName, String localPatchName, String remotePatchName) throws Exception {
- OvsdbConfigService ovsdbTable = (OvsdbConfigService)ServiceHelper.getGlobalInstance(OvsdbConfigService.class, this);
-
- String bridgeUUID = this.getInternalBridgeUUID(node, bridgeName);
- Bridge bridge = ovsdbTable.createTypedRow(node, Bridge.class);
- Set<String> failMode = new HashSet<String>();
- failMode.add("secure");
- bridge.setFailMode(failMode);
-
- Set<String> protocols = new HashSet<String>();
- if (providerNetworkManager == null) {
- logger.error("Provider Network Manager is not available");
- return new Status(StatusCode.INTERNALERROR);
- }
- if (!providerNetworkManager.getProvider().hasPerTenantTunneling()) {
- protocols.add("OpenFlow13");
- } else {
- protocols.add("OpenFlow10");
- }
- bridge.setProtocols(protocols);
-
- if (bridgeUUID == null) {
- bridge.setName(bridgeName);
-
- StatusWithUuid statusWithUuid = ovsdbTable.insertRow(node, bridge.getSchema().getName(), null, bridge.getRow());
- if (!statusWithUuid.isSuccess()) return statusWithUuid;
- bridgeUUID = statusWithUuid.getUuid().toString();
- Port port = ovsdbTable.createTypedRow(node, Port.class);
- port.setName(bridgeName);
- Status status = ovsdbTable.insertRow(node, port.getSchema().getName(), bridgeUUID, port.getRow());
- logger.debug("addInternalBridge: Inserting Bridge {} {} with protocols {} and status {}",
- bridgeName, bridgeUUID, protocols, status);
- } else {
- Status status = ovsdbTable.updateRow(node, bridge.getSchema().getName(), null, bridgeUUID, bridge.getRow());
- logger.debug("addInternalBridge: Updating Bridge {} {} with protocols {} and status {}",
- bridgeName, bridgeUUID, protocols, status);
- }
-
- ovsdbTable.setOFController(node, bridgeUUID);
-
- if (localPatchName != null && remotePatchName != null && providerNetworkManager.getProvider().hasPerTenantTunneling()) {
- return addPatchPort(node, bridgeUUID, localPatchName, remotePatchName);
- }
- return new Status(StatusCode.SUCCESS);
- }
-
- @Override
- public void prepareInternalNetwork(Node node) {
- try {
- this.createIntegrationBridge(node);
- } catch (Exception e) {
- logger.error("Error creating internal network "+node.toString(), e);
- return;
- }
- if (providerNetworkManager == null) {
- logger.error("Error creating internal network. Provider Network Manager unavailable");
- return;
- }
- providerNetworkManager.getProvider().initializeFlowRules(node);
- }
-
- /*
- * Check if the full network setup is available. If not, create it.
- */
- @Override
- public boolean checkAndCreateNetwork (Node node, NeutronNetwork network) {
- boolean isCreated = false;
- if (network.getProviderNetworkType().equalsIgnoreCase(NetworkHandler.NETWORK_TYPE_VLAN)) {
- if (!this.isInternalNetworkVlanReady(node, network)) {
- try {
- isCreated = this.createNetNetwork(node, network);
- } catch (Exception e) {
- logger.error("Error creating internal net network ", node, e);
- }
- } else {
- isCreated = true;
- }
- } else if (network.getProviderNetworkType().equalsIgnoreCase(NetworkHandler.NETWORK_TYPE_VXLAN) ||
- network.getProviderNetworkType().equalsIgnoreCase(NetworkHandler.NETWORK_TYPE_GRE)) {
- if (!this.isInternalNetworkTunnelReady(node)) {
- try {
- isCreated = this.createNetNetwork(node, network);
- } catch (Exception e) {
- logger.error("Error creating internal net network ", node, e);
- }
- } else {
- isCreated = true;
- }
- }
- return isCreated;
- }
-}
+++ /dev/null
-/*******************************************************************************
- * Copyright (c) 2013 Hewlett-Packard Development Company, L.P.
- * All rights reserved. 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
- *
- * Contributors:
- * Dave Tucker (HP) - Replace tenantVlanMap with a per Node cache
- *******************************************************************************/
-
-package org.opendaylight.ovsdb.neutron;
-
-import java.math.BigInteger;
-import java.util.LinkedList;
-import java.util.Map;
-import java.util.concurrent.ConcurrentHashMap;
-import java.util.concurrent.ConcurrentMap;
-
-import org.opendaylight.controller.sal.core.Node;
-import org.opendaylight.controller.sal.utils.ServiceHelper;
-import org.opendaylight.ovsdb.lib.notation.Row;
-import org.opendaylight.ovsdb.lib.notation.UUID;
-import org.opendaylight.ovsdb.plugin.OvsdbConfigService;
-import org.opendaylight.ovsdb.schema.openvswitch.Interface;
-import org.opendaylight.ovsdb.schema.openvswitch.Port;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-public class NodeConfiguration {
- static final Logger logger = LoggerFactory.getLogger(NodeConfiguration.class);
- private static final int MAX_VLAN = 4096;
- private java.util.Queue<Integer> internalVlans = new LinkedList<>();
- private ConcurrentMap<String, Integer> tenantVlanMap = new ConcurrentHashMap<>();
- private ITenantNetworkManager tenantNetworkManager;
-
- public NodeConfiguration(Node node, ITenantNetworkManager tenantNetworkManager) {
- for (int i = 1; i < MAX_VLAN ; i++) {
- internalVlans.add(i);
- }
- setTenantNetworkManager(tenantNetworkManager);
- initializeNodeConfiguration(node);
- }
-
-
- private void initializeNodeConfiguration(Node node) {
- int vlan = 0;
- String networkId = new String();
- OvsdbConfigService ovsdbTable = (OvsdbConfigService) ServiceHelper.getGlobalInstance(OvsdbConfigService.class, this);
-
- try {
- Map<String, Row> portRows = ovsdbTable.getRows(node, ovsdbTable.getTableName(node, Port.class));
-
- if (portRows == null){
- logger.info("Interface table is null for Node {}", node);
- return;
- }
-
- for (Row row : portRows.values()) {
- Port port = ovsdbTable.getTypedRow(node, Port.class, row);
-
- if (port.getTagColumn() == null) continue;
- BigInteger[] tags = port.getTagColumn().getData().toArray(new BigInteger[0]);
- if (tags.length == 1)
- {
- //There is only one tag here
- vlan = tags[0].intValue();
- }
- else {
- logger.debug("This port ({}) has {} tags", port.getName(), tags.length);
- continue;
- }
-
- for (UUID ifaceId : port.getInterfacesColumn().getData()) {
- Row ifaceRow = ovsdbTable.getRow(node, ovsdbTable.getTableName(node, Interface.class), ifaceId.toString());
- Interface iface = ovsdbTable.getTypedRow(node, Interface.class, ifaceRow);
-
- if (iface == null) {
- logger.error("Interface table is null for Po");
- continue;
- }
-
- networkId = tenantNetworkManager.getTenantNetworkForInterface(iface).getNetworkUUID();
-
- if (networkId != null) break;
- }
-
- if (vlan != 0 && networkId != null) {
-
- this.internalVlanInUse(vlan);
- this.tenantVlanMap.put(networkId, vlan);
-
- } else {
- logger.debug("Node: {} initialized without a vlan", node);
- }
- }
- }
- catch (Exception e) {
- logger.error("Error getting Port table for Node {}: {}", node, e);
- }
- }
-
- /*
- * Return the currently mapped internal vlan or get the next
- * free internal vlan from the available pool and map it to the networkId.
- */
- public int assignInternalVlan (String networkId) {
- Integer mappedVlan = tenantVlanMap.get(networkId);
- if (mappedVlan != null) return mappedVlan;
- mappedVlan = internalVlans.poll();
- if (mappedVlan != null) tenantVlanMap.put(networkId, mappedVlan);
- return mappedVlan;
- }
-
- /*
- * Return the mapped internal vlan to the available pool.
- */
- public int reclaimInternalVlan (String networkId) {
- Integer mappedVlan = tenantVlanMap.get(networkId);
- if (mappedVlan != null) {
- tenantVlanMap.remove(mappedVlan);
- internalVlans.add(mappedVlan);
- return mappedVlan;
- }
- return 0;
- }
-
- /*
- * Remove the internal vlan from the available pool.
- */
- public void internalVlanInUse (int vlan) {
- internalVlans.remove(vlan);
- }
-
- /*
- * Return a vlan from the mapped pool keyed by the networkId.
- */
- public int getInternalVlan (String networkId) {
- Integer vlan = tenantVlanMap.get(networkId);
- if (vlan == null) return 0;
- return vlan.intValue();
- }
-
- public void setTenantNetworkManager(ITenantNetworkManager tenantNetworkManager) {
- this.tenantNetworkManager = tenantNetworkManager;
- }
-}
+++ /dev/null
-/*
- * Copyright (C) 2013 Red Hat, Inc. and others...
- *
- * 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, Dave Tucker
- */
-package org.opendaylight.ovsdb.neutron;
-
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-import java.util.concurrent.ConcurrentHashMap;
-import java.util.concurrent.ConcurrentMap;
-
-import org.opendaylight.controller.containermanager.ContainerConfig;
-import org.opendaylight.controller.containermanager.ContainerFlowConfig;
-import org.opendaylight.controller.containermanager.IContainerManager;
-import org.opendaylight.controller.networkconfig.neutron.INeutronNetworkCRUD;
-import org.opendaylight.controller.networkconfig.neutron.INeutronPortCRUD;
-import org.opendaylight.controller.networkconfig.neutron.NeutronNetwork;
-import org.opendaylight.controller.networkconfig.neutron.NeutronPort;
-import org.opendaylight.controller.sal.core.Node;
-import org.opendaylight.controller.sal.core.NodeConnector;
-import org.opendaylight.controller.sal.utils.HexEncode;
-import org.opendaylight.controller.sal.utils.ServiceHelper;
-import org.opendaylight.controller.sal.utils.Status;
-import org.opendaylight.ovsdb.lib.notation.OvsdbSet;
-import org.opendaylight.ovsdb.lib.notation.Row;
-import org.opendaylight.ovsdb.lib.notation.UUID;
-import org.opendaylight.ovsdb.neutron.provider.IProviderNetworkManager;
-import org.opendaylight.ovsdb.plugin.IConnectionServiceInternal;
-import org.opendaylight.ovsdb.plugin.OvsdbConfigService;
-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.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-public class TenantNetworkManager implements ITenantNetworkManager {
- static final Logger logger = LoggerFactory.getLogger(TenantNetworkManager.class);
- private ConcurrentMap<String, NodeConfiguration> nodeConfigurationCache = new ConcurrentHashMap<>();
-
- // The implementation for each of these services is resolved by the OSGi Service Manager
- private volatile IProviderNetworkManager providerNetworkManager;
-
- private boolean enableContainer = false;
- public TenantNetworkManager() {
- String isTenantContainer = System.getProperty("TenantIsContainer");
- if (isTenantContainer != null && isTenantContainer.equalsIgnoreCase("true")) {
- enableContainer = true;
- }
- }
-
- @Override
- public int getInternalVlan(Node node, String networkId) {
- String nodeUuid = getNodeUUID(node);
- if (nodeUuid == null) {
- logger.error("Unable to get UUID for Node {}", node);
- return 0;
- }
-
- NodeConfiguration nodeConfiguration = nodeConfigurationCache.get(nodeUuid);
-
- if (nodeConfiguration == null) {
- nodeConfiguration = addNodeConfigurationToCache(node);
- }
- Integer vlan = nodeConfiguration.getInternalVlan(networkId);
- if (vlan == null) return 0;
- return vlan.intValue();
- }
-
- private NodeConfiguration addNodeConfigurationToCache(Node node) {
- NodeConfiguration nodeConfiguration = new NodeConfiguration(node, this);
- String nodeUuid = getNodeUUID(node);
- if (nodeUuid == null) {
- logger.error("Cannot get Node UUID for Node {}", node);
- return null;
- }
- this.nodeConfigurationCache.put(nodeUuid, nodeConfiguration);
- return nodeConfigurationCache.get(nodeUuid);
- }
-
- @Override
- public void reclaimTenantNetworkInternalVlan(Node node, String portUUID, NeutronNetwork network) {
- String nodeUuid = getNodeUUID(node);
- if (nodeUuid == null) {
- logger.error("Unable to get UUID for Node {}", node);
- return;
- }
-
- NodeConfiguration nodeConfiguration = nodeConfigurationCache.get(nodeUuid);
-
- // Cache miss
- if (nodeConfiguration == null)
- {
- logger.error("Configuration data unavailable for Node {} ", node);
- return;
- }
-
- int vlan = nodeConfiguration.reclaimInternalVlan(network.getID());
- if (vlan <= 0) {
- logger.error("Unable to get an internalVlan for Network {}", network);
- return;
- }
- logger.debug("Removed Vlan {} on {}", vlan, portUUID);
- }
-
- @Override
- public void networkCreated (String networkId) {
- IConnectionServiceInternal connectionService = (IConnectionServiceInternal)ServiceHelper.getGlobalInstance(IConnectionServiceInternal.class, this);
- List<Node> nodes = connectionService.getNodes();
-
- for (Node node : nodes) {
- this.networkCreated(node, networkId);
- }
-
- }
-
- private String getNodeUUID(Node node) {
- String nodeUuid = new String();
- OvsdbConfigService ovsdbConfigService = (OvsdbConfigService)ServiceHelper.getGlobalInstance(OvsdbConfigService.class, this);
- try {
- Map<String, Row> ovsTable = ovsdbConfigService.getRows(node, ovsdbConfigService.getTableName(node, OpenVSwitch.class));
- nodeUuid = (String)ovsTable.keySet().toArray()[0];
- }
- catch (Exception e) {
- logger.error("Unable to get the Open_vSwitch table for Node {}: {}", node, e);
- }
-
- return nodeUuid;
- }
-
- @Override
- public int networkCreated (Node node, String networkId) {
- String nodeUuid = getNodeUUID(node);
- if (nodeUuid == null) {
- logger.error("Unable to get UUID for Node {}", node);
- return 0;
- }
-
- NodeConfiguration nodeConfiguration = nodeConfigurationCache.get(nodeUuid);
-
- // Cache miss
- if (nodeConfiguration == null)
- {
- nodeConfiguration = addNodeConfigurationToCache(node);
- }
-
- int internalVlan = nodeConfiguration.assignInternalVlan(networkId);
- if (enableContainer && internalVlan != 0) {
- IContainerManager containerManager = (IContainerManager)ServiceHelper.getGlobalInstance(IContainerManager.class, this);
- if (containerManager == null) {
- logger.error("ContainerManager is null. Failed to create Container for {}", networkId);
- return 0;
- }
-
- ContainerConfig config = new ContainerConfig();
- config.setContainer(BaseHandler.convertNeutronIDToKey(networkId));
- Status status = containerManager.addContainer(config);
- logger.debug("Container Creation Status for {} : {}", networkId, status.toString());
-
- ContainerFlowConfig flowConfig = new ContainerFlowConfig("InternalVlan", internalVlan+"",
- null, null, null, null, null);
- List<ContainerFlowConfig> containerFlowConfigs = new ArrayList<ContainerFlowConfig>();
- containerFlowConfigs.add(flowConfig);
- containerManager.addContainerFlows(BaseHandler.convertNeutronIDToKey(networkId), containerFlowConfigs);
- }
- return internalVlan;
- }
-
- /**
- * Are there any TenantNetwork VM present on this Node ?
- * This method uses Interface Table's external-id field to locate the VM.
- */
- @Override
- public boolean isTenantNetworkPresentInNode(Node node, String segmentationId) {
- String networkId = this.getNetworkIdForSegmentationId(segmentationId);
- if (networkId == null) {
- logger.debug("Tenant Network not found with Segmenation-id {}",segmentationId);
- return false;
- }
- if (providerNetworkManager.getProvider().hasPerTenantTunneling()) {
- String nodeUuid = getNodeUUID(node);
- if (nodeUuid == null) {
- logger.debug("Unable to get UUID for Node {}", node);
- return false;
- }
-
- NodeConfiguration nodeConfiguration = nodeConfigurationCache.get(nodeUuid);
-
- // Cache miss
- if (nodeConfiguration == null)
- {
- logger.error("Configuration data unavailable for Node {} ", node);
- return false;
- }
-
- int internalVlan = nodeConfiguration.getInternalVlan(networkId);
- if (internalVlan == 0) {
- logger.debug("No InternalVlan provisioned for Tenant Network {}",networkId);
- return false;
- }
- }
- OvsdbConfigService ovsdbTable = (OvsdbConfigService)ServiceHelper.getGlobalInstance(OvsdbConfigService.class, this);
- try {
- /*
- // Vlan Tag based identification
- Map<String, Row> portTable = ovsdbTable.getRows(node, Port.NAME.getName());
- if (portTable == null) {
- logger.debug("Port table is null for Node {} ", node);
- return false;
- }
-
- for (Row row : portTable.values()) {
- Port port = (Port)row;
- Set<BigInteger> tags = port.getTag();
- if (tags.contains(internalVlan)) {
- logger.debug("Tenant Network {} with Segmenation-id {} is present in Node {} / Port {}",
- networkId, segmentationId, node, port);
- return true;
- }
- }
- */
- // External-id based more accurate VM Location identification
- Map<String, Row> ifTable = ovsdbTable.getRows(node, ovsdbTable.getTableName(node, Interface.class));
- if (ifTable == null) {
- logger.debug("Interface table is null for Node {} ", node);
- return false;
- }
-
- for (Row row : ifTable.values()) {
- Interface intf = ovsdbTable.getTypedRow(node, Interface.class, row);
- Map<String, String> externalIds = intf.getExternalIdsColumn().getData();
- if (externalIds != null && externalIds.get(EXTERNAL_ID_INTERFACE_ID) != null) {
- if (this.isInterfacePresentInTenantNetwork(externalIds.get(EXTERNAL_ID_INTERFACE_ID), networkId)) {
- logger.debug("Tenant Network {} with Segmentation-id {} is present in Node {} / Interface {}",
- networkId, segmentationId, node, intf);
- return true;
- }
- }
- }
-
- } catch (Exception e) {
- logger.error("Error while trying to determine if network is present on node", e);
- return false;
- }
-
- logger.debug("Tenant Network {} with Segmenation-id {} is NOT present in Node {}",
- networkId, segmentationId, node);
-
- return false;
- }
-
- @Override
- public String getNetworkIdForSegmentationId (String segmentationId) {
- INeutronNetworkCRUD neutronNetworkService = (INeutronNetworkCRUD)ServiceHelper.getGlobalInstance(INeutronNetworkCRUD.class, this);
- List <NeutronNetwork> networks = neutronNetworkService.getAllNetworks();
- for (NeutronNetwork network : networks) {
- if (network.getProviderSegmentationID().equalsIgnoreCase(segmentationId)) return network.getNetworkUUID();
- }
- return null;
- }
-
- private boolean isInterfacePresentInTenantNetwork (String portId, String networkId) {
- INeutronPortCRUD neutronPortService = (INeutronPortCRUD)ServiceHelper.getGlobalInstance(INeutronPortCRUD.class, this);
- NeutronPort neutronPort = neutronPortService.getPort(portId);
- if (neutronPort != null && neutronPort.getNetworkUUID().equalsIgnoreCase(networkId)) return true;
- return false;
- }
-
- @Override
- public NeutronNetwork getTenantNetworkForInterface (Interface intf) {
- logger.trace("getTenantNetworkForInterface for {}", intf);
- if (intf == null) return null;
- Map<String, String> externalIds = intf.getExternalIdsColumn().getData();
- logger.trace("externalIds {}", externalIds);
- if (externalIds == null) return null;
- String neutronPortId = externalIds.get(EXTERNAL_ID_INTERFACE_ID);
- if (neutronPortId == null) return null;
- INeutronPortCRUD neutronPortService = (INeutronPortCRUD)ServiceHelper.getGlobalInstance(INeutronPortCRUD.class, this);
- NeutronPort neutronPort = neutronPortService.getPort(neutronPortId);
- logger.trace("neutronPort {}", neutronPort);
- if (neutronPort == null) return null;
- INeutronNetworkCRUD neutronNetworkService = (INeutronNetworkCRUD)ServiceHelper.getGlobalInstance(INeutronNetworkCRUD.class, this);
- NeutronNetwork neutronNetwork = neutronNetworkService.getNetwork(neutronPort.getNetworkUUID());
- logger.debug("{} mappped to {}", intf, neutronNetwork);
- return neutronNetwork;
- }
-
- @Override
- public void programTenantNetworkInternalVlan(Node node, String portUUID, NeutronNetwork network) {
-
- String nodeUuid = getNodeUUID(node);
- if (nodeUuid == null) {
- logger.error("Unable to get UUID for Node {}", node);
- return;
- }
-
- NodeConfiguration nodeConfiguration = nodeConfigurationCache.get(nodeUuid);
-
- // Cache miss
- if (nodeConfiguration == null)
- {
- logger.error("Configuration data unavailable for Node {} ", node);
- return;
- }
-
- int vlan = nodeConfiguration.getInternalVlan(network.getID());
- logger.debug("Programming Vlan {} on {}", vlan, portUUID);
- if (vlan <= 0) {
- logger.error("Unable to get an internalVlan for Network {}", network);
- return;
- }
- OvsdbConfigService ovsdbTable = (OvsdbConfigService)ServiceHelper.getGlobalInstance(OvsdbConfigService.class, this);
- Port port = ovsdbTable.createTypedRow(node, Port.class);
- OvsdbSet<Long> tags = new OvsdbSet<Long>();
- tags.add(Long.valueOf(vlan));
- port.setTag(tags);
- ovsdbTable.updateRow(node, port.getSchema().getName(), null, portUUID, port.getRow());
- if (enableContainer) this.addPortToTenantNetworkContainer(node, portUUID, network);
- }
-
- private void addPortToTenantNetworkContainer(Node node, String portUUID, NeutronNetwork network) {
- IContainerManager containerManager = (IContainerManager)ServiceHelper.getGlobalInstance(IContainerManager.class, this);
- if (containerManager == null) {
- logger.error("ContainerManager is not accessible");
- return;
- }
- OvsdbConfigService ovsdbTable = (OvsdbConfigService)ServiceHelper.getGlobalInstance(OvsdbConfigService.class, this);
- try {
- Row portRow = ovsdbTable.getRow(node, ovsdbTable.getTableName(node, Port.class), portUUID);
- Port port = ovsdbTable.getTypedRow(node, Port.class, portRow);
- if (port == null) {
- logger.trace("Unable to identify Port with UUID {}", portUUID);
- return;
- }
- Set<UUID> interfaces = port.getInterfacesColumn().getData();
- if (interfaces == null) {
- logger.trace("No interfaces available to fetch the OF Port");
- return;
- }
- Bridge bridge = this.getBridgeIdForPort(node, portUUID);
- if (bridge == null) {
- logger.debug("Unable to spot Bridge for Port {} in node {}", port, node);
- return;
- }
- Set<String> dpids = bridge.getDatapathIdColumn().getData();
- if (dpids == null || dpids.size() == 0) return;
- Long dpidLong = Long.valueOf(HexEncode.stringToLong((String)dpids.toArray()[0]));
-
- for (UUID intfUUID : interfaces) {
- Interface intf = (Interface)ovsdbTable.getRow(node,ovsdbTable.getTableName(node, Interface.class), intfUUID.toString());
- if (intf == null) continue;
- Set<Long> of_ports = intf.getOpenFlowPortColumn().getData();
- if (of_ports == null) continue;
- for (Long of_port : of_ports) {
- ContainerConfig config = new ContainerConfig();
- config.setContainer(BaseHandler.convertNeutronIDToKey(network.getID()));
- logger.debug("Adding Port {} to Container : {}", port.toString(), config.getContainer());
- List<String> ncList = new ArrayList<String>();
- Node ofNode = new Node(Node.NodeIDType.OPENFLOW, dpidLong);
- NodeConnector nc = NodeConnector.fromStringNoNode(Node.NodeIDType.OPENFLOW.toString(),
- of_port.intValue()+"",
- ofNode);
- ncList.add(nc.toString());
- config.addNodeConnectors(ncList);
-
- Status status = containerManager.addContainerEntry(BaseHandler.convertNeutronIDToKey(network.getID()), ncList);
-
- if (!status.isSuccess()) {
- logger.error(" Failed {} : to add port {} to container - {}",
- status, nc, network.getID());
- } else {
- logger.error(" Successfully added port {} to container - {}",
- nc, network.getID());
- }
- }
- }
- } catch (Exception e) {
- logger.error("Exception in addPortToTenantNetworkContainer", e);
- }
- }
-
- private Bridge getBridgeIdForPort (Node node, String uuid) {
- OvsdbConfigService ovsdbTable = (OvsdbConfigService)ServiceHelper.getGlobalInstance(OvsdbConfigService.class, this);
- try {
- Map<String, Row> bridges = ovsdbTable.getRows(node, ovsdbTable.getTableName(node, Bridge.class));
- if (bridges == null) return null;
- for (String bridgeUUID : bridges.keySet()) {
- Bridge bridge = ovsdbTable.getTypedRow(node, Bridge.class, bridges.get(bridgeUUID));
- Set<UUID> portUUIDs = bridge.getPortsColumn().getData();
- logger.trace("Scanning Bridge {} to identify Port : {} ",bridge, uuid);
- for (UUID portUUID : portUUIDs) {
- if (portUUID.toString().equalsIgnoreCase(uuid)) {
- logger.trace("Found Port {} -> ", uuid, bridgeUUID);
- return bridge;
- }
- }
- }
- } catch (Exception e) {
- logger.debug("Failed to get BridgeId port {} in Node {}", uuid, node);
- }
- return null;
- }
-
- @Override
- public void networkDeleted(String id) {
- if (!enableContainer) return;
-
- IContainerManager containerManager = (IContainerManager)ServiceHelper.getGlobalInstance(IContainerManager.class, this);
- if (containerManager == null) {
- logger.error("ContainerManager is not accessible");
- return;
- }
-
- String networkID = BaseHandler.convertNeutronIDToKey(id);
- ContainerConfig config = new ContainerConfig();
- config.setContainer(networkID);
- containerManager.removeContainer(config);
- }
-}
+++ /dev/null
-/*
- * Copyright (C) 2014 Red Hat, Inc.
- *
- * 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 : Dave Tucker
- */
-
-package org.opendaylight.ovsdb.neutron.provider;
-
-public interface IProviderNetworkManager {
- NetworkProvider getProvider();
-}
+++ /dev/null
-/*
- * Copyright (C) 2013 Red Hat, Inc.
- *
- * 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, Dave Tucker
- */
-package org.opendaylight.ovsdb.neutron.provider;
-
-import org.opendaylight.ovsdb.neutron.IAdminConfigManager;
-import org.opendaylight.ovsdb.neutron.IInternalNetworkManager;
-import org.opendaylight.ovsdb.neutron.ITenantNetworkManager;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-public class ProviderNetworkManager implements IProviderNetworkManager {
- static final Logger logger = LoggerFactory.getLogger(ProviderNetworkManager.class);
- private NetworkProvider provider;
- protected static final String OPENFLOW_10 = "1.0";
- protected static final String OPENFLOW_13 = "1.3";
-
- // The implementation for each of these services is resolved by the OSGi Service Manager
- private volatile IAdminConfigManager adminConfigManager;
- private volatile IInternalNetworkManager internalNetworkManager;
- private volatile ITenantNetworkManager tenantNetworkManager;
-
- public NetworkProvider getProvider() {
- if (provider != null) return provider;
- String ofVersion = System.getProperty("ovsdb.of.version", OPENFLOW_10);
- switch (ofVersion) {
- case OPENFLOW_13:
- provider = new OF13Provider(adminConfigManager, internalNetworkManager, tenantNetworkManager);
- break;
- case OPENFLOW_10:
- default:
- provider = new OF10Provider(adminConfigManager, internalNetworkManager, tenantNetworkManager);
- break;
- }
- return provider;
- }
-
-}
+++ /dev/null
-/*******************************************************************************
- * Copyright (c) 2013 Hewlett-Packard Development Company, L.P. and others
- * All rights reserved. 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
- *
- * Contributors:
- * Dave Tucker (HP) - Added unit tests for the AdminConfigManager class.
- * Sam Hague - Added unit tests for getPhysicalInterfaceName.
- *******************************************************************************/
-
-package org.opendaylight.ovsdb.neutron;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNull;
-import static org.mockito.Matchers.any;
-import static org.mockito.Matchers.anyObject;
-import static org.mockito.Matchers.anyString;
-import static org.mockito.Matchers.eq;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
-
-import java.net.InetAddress;
-import java.util.HashMap;
-import java.util.Map;
-import java.util.concurrent.ConcurrentHashMap;
-import java.util.concurrent.ConcurrentMap;
-
-import org.junit.Before;
-import org.junit.Ignore;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.opendaylight.controller.sal.core.Node;
-import org.opendaylight.controller.sal.utils.ServiceHelper;
-import org.opendaylight.ovsdb.lib.notation.Row;
-import org.opendaylight.ovsdb.plugin.ConfigurationService;
-import org.opendaylight.ovsdb.plugin.OvsdbConfigService;
-import org.opendaylight.ovsdb.schema.openvswitch.OpenVSwitch;
-import org.powermock.api.mockito.PowerMockito;
-import org.powermock.core.classloader.annotations.PrepareForTest;
-import org.powermock.modules.junit4.PowerMockRunner;
-
-@Ignore("Ignored due to migration from old library to new")
-@RunWith(PowerMockRunner.class)
-@PrepareForTest(ServiceHelper.class)
-public class AdminConfigManagerTest {
-
- AdminConfigManager adminConfigManager;
- private OvsdbConfigService ovsdbConfig;
- private Node node;
- private OpenVSwitch ovsTable;
- private ConcurrentMap<String, Row> ovsMap;
- private Map map;
-
- private static String OPENVSWITCH = "OpenVSwitch";
- private static String PROVIDER_MAPPINGS = "provider_mappings";
- private static String PHYSNET1 = "physnet1";
- private static String ETH1 = "eth1";
- private static String PHYSNET2 = "physnet2";
- private static String ETH2 = "eth2";
- private static String PHYSNET3 = "physnet3";
- private static String ETH3 = "eth3";
- private static String LOCAL_IP = "local_ip";
- private static String IPADDR = "10.10.10.10";
-
- @Before
- public void setUp(){
- adminConfigManager = new AdminConfigManager();
-
- node = mock(Node.class);
- ovsdbConfig = mock(ConfigurationService.class);
- PowerMockito.mockStatic(ServiceHelper.class);
- when(ServiceHelper.getGlobalInstance(eq(OvsdbConfigService.class), anyObject())).thenReturn(ovsdbConfig);
-
- ovsTable = PowerMockito.mock(OpenVSwitch.class);
- ovsMap = new ConcurrentHashMap<>();
- map = new HashMap();
- }
-
- @Test
- public void testGetTunnelEndpoint() throws Exception {
- InetAddress testAddress = InetAddress.getByName("10.10.10.10");
-
- Node mockNode = mock(Node.class);
-
- ConcurrentMap<String, Row> ovsMap = new ConcurrentHashMap<>();
-
- OpenVSwitch ovsTable = PowerMockito.mock(OpenVSwitch.class);
- Map localIp = new HashMap();
- localIp.put("local_ip", "10.10.10.10");
- ovsTable.setOtherConfig(localIp);
- ovsMap.put("OpenVSwitch", ovsTable.getRow());
-
- OvsdbConfigService ovsdbConfig = mock(ConfigurationService.class);
- when(ovsdbConfig.getRows(any(Node.class), anyString())).thenReturn(null)
- .thenReturn(ovsMap);
-
- PowerMockito.mockStatic(ServiceHelper.class);
- when(ServiceHelper.getGlobalInstance(eq(OvsdbConfigService.class), anyObject())).thenReturn(ovsdbConfig);
-
- // OVSDBConfigService is null
- assertEquals(null, adminConfigManager.getTunnelEndPoint(mockNode));
-
- // Success...
- assertEquals(testAddress, adminConfigManager.getTunnelEndPoint(mockNode));
- }
-
- @Test
- public void testGetTunnelEndpointWithNullRows() throws Exception {
- InetAddress testAddress = InetAddress.getByName("10.10.10.10");
-
- Node mockNode = mock(Node.class);
-
- ConcurrentMap<String, Row> ovsMap = new ConcurrentHashMap<>();
-
- OpenVSwitch nullRow = PowerMockito.mock(OpenVSwitch.class);
- OpenVSwitch ovsRow1 = PowerMockito.mock(OpenVSwitch.class);
- OpenVSwitch ovsRow2 = PowerMockito.mock(OpenVSwitch.class);
- Map invalidLocalIp = new HashMap();
- Map localIp = new HashMap();
-
- ovsRow1.setOtherConfig(invalidLocalIp);
-
- localIp.put("local_ip","10.10.10.10");
- ovsRow2.setOtherConfig(localIp);
-
- ovsMap.put("0", nullRow.getRow());
- ovsMap.put("1", ovsRow1.getRow());
- ovsMap.put("2", ovsRow2.getRow());
-
- OvsdbConfigService ovsdbConfig = mock(ConfigurationService.class);
- when(ovsdbConfig.getRows(any(Node.class), anyString())).thenReturn(ovsMap);
-
- PowerMockito.mockStatic(ServiceHelper.class);
- when(ServiceHelper.getGlobalInstance(eq(OvsdbConfigService.class), anyObject())).thenReturn(ovsdbConfig);
-
- // Success...
- assertEquals(testAddress, adminConfigManager.getTunnelEndPoint(mockNode));
- }
-
- // Add key:value pairs to the map.
- // Calling again with the same key will overwrite the current pair.
- private void initMap (String key, String value) {
- map.put(key, value);
- ovsTable.setOtherConfig(map);
- ovsMap.put(OPENVSWITCH, ovsTable.getRow());
- }
-
- @Test
- public void testGetPhysicalInterfaceName () throws Exception {
- when(ovsdbConfig.getRows(any(Node.class), anyString())).thenReturn(ovsMap);
-
- // Check if match can be found with a single pair
- initMap(PROVIDER_MAPPINGS, PHYSNET1 + ":" + ETH1);
- assertEquals("Failed to find " + ETH1 + " in " + map.toString(),
- ETH1, adminConfigManager.getPhysicalInterfaceName(node, PHYSNET1));
-
- // Check if match can be found with different pairs
- initMap(PROVIDER_MAPPINGS, PHYSNET1 + ":" + ETH1 + "," + PHYSNET2 + ":" + ETH2);
- assertEquals("Failed to find " + ETH2 + " in " + map.toString(),
- ETH2, adminConfigManager.getPhysicalInterfaceName(node, PHYSNET2));
-
- // Check if match can be found with duplicate pairs
- initMap(PROVIDER_MAPPINGS, PHYSNET1 + ":" + ETH1 + "," + PHYSNET2 + ":" + ETH2 + "," + PHYSNET2 + ":" + ETH2);
- assertEquals("Failed to find " + ETH2 + " in " + map.toString(),
- ETH2, adminConfigManager.getPhysicalInterfaceName(node, PHYSNET2));
-
- // Check if match can be found with multiple pairs and extra other_config
- initMap(LOCAL_IP, IPADDR);
- assertEquals("Failed to find " + ETH2 + " in " + map.toString(),
- ETH2, adminConfigManager.getPhysicalInterfaceName(node, PHYSNET2));
- }
-
- @Test
- public void testGetPhysicalInterfaceNameNegative () throws Exception {
- when(ovsdbConfig.getRows(any(Node.class), anyString())).thenReturn(null)
- .thenReturn(ovsMap);
-
- // Add a null row, an empty row and a good row to the table
- OpenVSwitch nullRow = PowerMockito.mock(OpenVSwitch.class);
- OpenVSwitch emptyRow = PowerMockito.mock(OpenVSwitch.class);
- Map emptyProviderMap = new HashMap();
- emptyRow.setOtherConfig(emptyProviderMap);
- ovsMap.put("0", nullRow.getRow());
- ovsMap.put("1", emptyRow.getRow());
- initMap(PROVIDER_MAPPINGS, PHYSNET1 + ":" + ETH1);
-
- // Check if no rows/no table is handled
- assertEquals("Failed to return null when ovsdb table is null",
- null, adminConfigManager.getTunnelEndPoint(node));
-
- // Check if the null and empty rows are ignored
- System.out.println("map = " + map.toString());
- System.out.println("ovsMap = " + ovsMap.toString());
- assertEquals("Failed to find " + ETH1 + " in " + map.toString(),
- ETH1, adminConfigManager.getPhysicalInterfaceName(node, PHYSNET1));
-
- // Should not be able to find match
- initMap(PROVIDER_MAPPINGS, PHYSNET1 + ":" + ETH1 + "," + PHYSNET2 + ":" + ETH2);
- assertNull("Found " + ETH3 + " in " + map.toString(),
- adminConfigManager.getPhysicalInterfaceName(node, PHYSNET3));
-
- // Should not be able to find match with mal-formed values
- initMap(PROVIDER_MAPPINGS, PHYSNET1 + "-" + ETH1);
- assertNull("Found " + ETH1 + " in " + map.toString(),
- adminConfigManager.getPhysicalInterfaceName(node, PHYSNET1));
- }
-}
+++ /dev/null
-/*******************************************************************************
- * Copyright (c) 2013 Hewlett-Packard Development Company, L.P.
- * All rights reserved. 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
- *
- * Contributors:
- * Dave Tucker (HP) - Added unit tests for the BaseHandler class.
- * - Migrated test cases to JUnit4
- *******************************************************************************/
-
-package org.opendaylight.ovsdb.neutron;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
-
-import java.net.HttpURLConnection;
-
-import org.junit.Test;
-import org.opendaylight.controller.sal.utils.Status;
-import org.opendaylight.controller.sal.utils.StatusCode;
-
-public class BaseHandlerTest {
-
- String nullString = null;
- String uuid = "ce044452-f22e-4ea4-a3ec-d1cde80cf996";
- String tenantId = "8d62bfa112fb4247aa20edc74235c1ce";
- String neutronId = "6b8fd2";
-
- @Test
- public void testGetException() {
-
- Status badRequest = new Status(StatusCode.BADREQUEST);
- Status conflict = new Status(StatusCode.CONFLICT);
- Status notAcceptable = new Status(StatusCode.NOTACCEPTABLE);
- Status notFound = new Status(StatusCode.NOTFOUND);
- Status internalError = new Status(StatusCode.INTERNALERROR);
-
-
- assertEquals(HttpURLConnection.HTTP_BAD_REQUEST, BaseHandler.getException(badRequest));
- assertEquals(HttpURLConnection.HTTP_CONFLICT, BaseHandler.getException(conflict));
- assertEquals(HttpURLConnection.HTTP_NOT_ACCEPTABLE, BaseHandler.getException(notAcceptable));
- assertEquals(HttpURLConnection.HTTP_NOT_FOUND, BaseHandler.getException(notFound));
- assertEquals(HttpURLConnection.HTTP_INTERNAL_ERROR, BaseHandler.getException(internalError));
-
- }
-
- @Test
- public void testIsValidNeutronID() {
- assertFalse(BaseHandler.isValidNeutronID(nullString));
- assertTrue(BaseHandler.isValidNeutronID(uuid));
- assertTrue(BaseHandler.isValidNeutronID(tenantId));
- assertTrue(BaseHandler.isValidNeutronID(neutronId));
-
- }
-
- @Test
- public void testConvertNeutronIDToKey() {
-
- String uuidResult = BaseHandler.convertNeutronIDToKey(uuid);
- String uuidExpected = "ce044452f22eea4a3ecd1cde80cf996";
-
- String tenantResult = BaseHandler.convertNeutronIDToKey(tenantId);
- String tenantExpected = "8d62bfa112fb247aa20edc74235c1ce";
-
- String neutronResult = BaseHandler.convertNeutronIDToKey(neutronId);
-
- assertEquals(uuidExpected, uuidResult);
- assertEquals(tenantExpected, tenantResult);
- assertEquals(neutronId, neutronResult);
-
- }
-}
+++ /dev/null
-/*******************************************************************************
- * Copyright (c) 2013 Hewlett-Packard Development Company, L.P.
- * All rights reserved. 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
- *
- * Contributors:
- * Dave Tucker (HP) - Added unit tests for the NetworkHandler class.
- *******************************************************************************/
-
-package org.opendaylight.ovsdb.neutron;
-
-import static org.junit.Assert.assertEquals;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.spy;
-import static org.mockito.Mockito.verify;
-import static org.mockito.Mockito.when;
-
-import java.net.HttpURLConnection;
-
-import org.junit.Ignore;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.opendaylight.controller.networkconfig.neutron.NeutronNetwork;
-import org.powermock.core.classloader.annotations.PrepareForTest;
-import org.powermock.modules.junit4.PowerMockRunner;
-
-@RunWith(PowerMockRunner.class)
-@PrepareForTest(TenantNetworkManager.class)
-
-public class NetworkHandlerTest {
-
- NetworkHandler testNetworkHandler = new NetworkHandler();
-
- @Test
- public void testCanCreateNetwork() throws Exception {
- NeutronNetwork mockNet = mock(NeutronNetwork.class);
-
- when(mockNet.isShared())
- .thenReturn(true)
- .thenReturn(false);
-
- assertEquals(HttpURLConnection.HTTP_NOT_ACCEPTABLE, testNetworkHandler.canCreateNetwork(mockNet));
- assertEquals(HttpURLConnection.HTTP_CREATED, testNetworkHandler.canCreateNetwork(mockNet));
-
- }
-
- @Test
- public void testCanUpdateNetwork() {
- NeutronNetwork delta = new NeutronNetwork();
- NeutronNetwork original = new NeutronNetwork();
-
- assertEquals(HttpURLConnection.HTTP_OK, testNetworkHandler.canUpdateNetwork(delta, original));
- }
-
- @Test
- public void testCanDeleteNetwork() throws Exception {
- NeutronNetwork network = new NeutronNetwork();
-
- assertEquals(HttpURLConnection.HTTP_OK, testNetworkHandler.canDeleteNetwork(network));
- }
-
- @Ignore
- @Test
- public void testNeutronNetworkDeleted() throws Exception {
- String netId = "6cfdb7";
-
- NeutronNetwork mockNet = mock(NeutronNetwork.class);
- when(mockNet.isShared()).thenReturn(false);
- when(mockNet.getID()).thenReturn(netId);
-
- NetworkHandler spy = spy(testNetworkHandler);
- TenantNetworkManager tenantNetworkManager = mock(TenantNetworkManager.class);
-
- when(spy.canDeleteNetwork(mockNet))
- .thenReturn(HttpURLConnection.HTTP_BAD_REQUEST)
- .thenCallRealMethod();
-
- spy.neutronNetworkDeleted(mockNet);
- spy.neutronNetworkDeleted(mockNet);
-
- verify(tenantNetworkManager).networkDeleted(netId);
-
- }
-}
--- /dev/null
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <parent>
+ <artifactId>commons</artifactId>
+ <groupId>org.opendaylight.ovsdb</groupId>
+ <version>1.2.0-SNAPSHOT</version>
+ <relativePath>../../commons/parent/pom.xml</relativePath>
+ </parent>
+ <modelVersion>4.0.0</modelVersion>
+
+ <artifactId>openstack.net-virt-providers</artifactId>
+ <version>1.0.0-SNAPSHOT</version>
+ <packaging>bundle</packaging>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.opendaylight.controller</groupId>
+ <artifactId>sal</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.opendaylight.controller</groupId>
+ <artifactId>forwardingrulesmanager</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.opendaylight.controller</groupId>
+ <artifactId>sal-binding-api</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.opendaylight.controller</groupId>
+ <artifactId>sal-common-util</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.opendaylight.controller</groupId>
+ <artifactId>switchmanager</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.opendaylight.controller.model</groupId>
+ <artifactId>model-flow-base</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.opendaylight.controller.model</groupId>
+ <artifactId>model-flow-management</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.opendaylight.controller.model</groupId>
+ <artifactId>model-flow-service</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.opendaylight.controller.model</groupId>
+ <artifactId>model-inventory</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.opendaylight.yangtools</groupId>
+ <artifactId>yang-binding</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.opendaylight.ovsdb</groupId>
+ <artifactId>plugin</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.opendaylight.ovsdb</groupId>
+ <artifactId>openstack.net-virt</artifactId>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>maven-bundle-plugin</artifactId>
+ <version>2.3.6</version>
+ <extensions>true</extensions>
+ <configuration>
+ <instructions>
+ <Import-Package>
+ org.opendaylight.controller.switchmanager,
+ org.opendaylight.controller.forwardingrulesmanager,
+ org.opendaylight.controller.sal.core,
+ org.opendaylight.controller.sal.utils,
+ org.opendaylight.controller.sal.action,
+ org.opendaylight.ovsdb.plugin,
+ org.opendaylight.ovsdb.lib.notation,
+ org.opendaylight.controller.sal.binding.api,
+ org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819,
+ org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes,
+ org.opendaylight.yangtools.yang.binding,
+ org.apache.felix.dm,
+ org.slf4j,
+ org.osgi.framework,
+ *
+ </Import-Package>
+ <Bundle-Activator>org.opendaylight.ovsdb.openstack.netvirt.providers.Activator</Bundle-Activator>
+ </instructions>
+ </configuration>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-checkstyle-plugin</artifactId>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-failsafe-plugin</artifactId>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-surefire-plugin</artifactId>
+ </plugin>
+ <plugin>
+ <groupId>org.jacoco</groupId>
+ <artifactId>jacoco-maven-plugin</artifactId>
+ </plugin>
+ </plugins>
+ </build>
+</project>
\ No newline at end of file
--- /dev/null
+/*
+ * Copyright (C) 2013 Red Hat, Inc.
+ *
+ * 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, Dave Tucker
+ */
+
+package org.opendaylight.ovsdb.openstack.netvirt.providers;
+
+import org.opendaylight.controller.forwardingrulesmanager.IForwardingRulesManager;
+import org.opendaylight.controller.sal.binding.api.BindingAwareBroker;
+import org.opendaylight.controller.sal.core.ComponentActivatorAbstractBase;
+import org.opendaylight.controller.switchmanager.ISwitchManager;
+import org.opendaylight.ovsdb.openstack.netvirt.api.BridgeConfigurationManager;
+import org.opendaylight.ovsdb.openstack.netvirt.api.ConfigurationService;
+import org.opendaylight.ovsdb.openstack.netvirt.api.Constants;
+import org.opendaylight.ovsdb.openstack.netvirt.api.NetworkingProvider;
+import org.opendaylight.ovsdb.openstack.netvirt.api.TenantNetworkManager;
+import org.opendaylight.ovsdb.plugin.IConnectionServiceInternal;
+import org.opendaylight.ovsdb.plugin.OvsdbConfigService;
+
+import org.apache.felix.dm.Component;
+
+import java.util.Properties;
+
+/**
+ * OSGi Bundle Activator for the Neutron providers
+ */
+public class Activator extends ComponentActivatorAbstractBase {
+ /**
+ * Function called when the activator starts just after some
+ * initializations are done by the
+ * ComponentActivatorAbstractBase.
+ */
+ @Override
+ public void init() {
+ }
+
+ /**
+ * Function called when the activator stops just before the
+ * cleanup done by ComponentActivatorAbstractBase.
+ *
+ */
+ @Override
+ public void destroy() {
+ }
+
+ /**
+ * Function that is used to communicate to dependency manager the
+ * list of known implementations for services inside a container.
+ *
+ * @return An array containing all the CLASS objects that will be
+ * instantiated in order to get an fully working implementation
+ * Object
+ */
+ @Override
+ public Object[] getImplementations() {
+ Object[] res = {MdsalConsumerImpl.class,
+ OF10Provider.class,
+ OF13Provider.class};
+ return res;
+ }
+
+ /**
+ * Function that is called when configuration of the dependencies
+ * is required.
+ *
+ * @param c dependency manager Component object, used for
+ * configuring the dependencies exported and imported
+ * @param imp Implementation class that is being configured,
+ * needed as long as the same routine can configure multiple
+ * implementations
+ * @param containerName The containerName being configured, this allow
+ * also optional per-container different behavior if needed, usually
+ * should not be the case though.
+ */
+ @Override
+ public void configureInstance(Component c, Object imp,
+ String containerName) {
+
+ if (imp.equals(MdsalConsumerImpl.class)) {
+ c.setInterface(MdsalConsumer.class.getName(), null);
+ c.add(createServiceDependency().setService(BindingAwareBroker.class).setRequired(true));
+ }
+
+ if (imp.equals(OF10Provider.class)) {
+ Properties of10Properties = new Properties();
+ of10Properties.put(Constants.SOUTHBOUND_PROTOCOL_PROPERTY, "ovsdb");
+ of10Properties.put(Constants.OPENFLOW_VERSION_PROPERTY, Constants.OPENFLOW10);
+
+ c.setInterface(NetworkingProvider.class.getName(), of10Properties);
+ c.add(createServiceDependency()
+ .setService(ConfigurationService.class)
+ .setRequired(true));
+ c.add(createServiceDependency()
+ .setService(BridgeConfigurationManager.class)
+ .setRequired(true));
+ c.add(createServiceDependency()
+ .setService(TenantNetworkManager.class)
+ .setRequired(true));
+ c.add(createServiceDependency().setService(OvsdbConfigService.class).setRequired(true));
+ c.add(createServiceDependency().setService(IConnectionServiceInternal.class).setRequired(true));
+ c.add(createServiceDependency().
+ setService(IForwardingRulesManager.class).
+ setRequired(true));
+ c.add(createServiceDependency().
+ setService(ISwitchManager.class).
+ setRequired(true));
+ }
+
+ if (imp.equals(OF13Provider.class)) {
+ Properties of13Properties = new Properties();
+ of13Properties.put(Constants.SOUTHBOUND_PROTOCOL_PROPERTY, "ovsdb");
+ of13Properties.put(Constants.OPENFLOW_VERSION_PROPERTY, Constants.OPENFLOW13);
+
+ c.setInterface(NetworkingProvider.class.getName(), of13Properties);
+ c.add(createServiceDependency()
+ .setService(ConfigurationService.class)
+ .setRequired(true));
+ c.add(createServiceDependency()
+ .setService(BridgeConfigurationManager.class)
+ .setRequired(true));
+ c.add(createServiceDependency()
+ .setService(TenantNetworkManager.class)
+ .setRequired(true));
+ c.add(createServiceDependency().setService(OvsdbConfigService.class).setRequired(true));
+ c.add(createServiceDependency().setService(IConnectionServiceInternal.class).setRequired(true));
+ c.add(createServiceDependency().setService(MdsalConsumer.class).setRequired(true));
+ }
+ }
+}
* Authors : Madhu Venugopal
*/
-package org.opendaylight.ovsdb.neutron;
+package org.opendaylight.ovsdb.openstack.netvirt.providers;
import org.opendaylight.controller.sal.binding.api.BindingAwareBroker.ConsumerContext;
import org.opendaylight.controller.sal.binding.api.data.DataBrokerService;
-public interface IMDSALConsumer {
+public interface MdsalConsumer {
public ConsumerContext getConsumerContext();
public DataBrokerService getDataBrokerService();
}
* Authors : Madhu Venugopal
*/
-package org.opendaylight.ovsdb.neutron;
-import org.apache.felix.dm.Component;
+package org.opendaylight.ovsdb.openstack.netvirt.providers;
+
import org.opendaylight.controller.sal.binding.api.BindingAwareBroker;
import org.opendaylight.controller.sal.binding.api.BindingAwareBroker.ConsumerContext;
import org.opendaylight.controller.sal.binding.api.BindingAwareConsumer;
import org.opendaylight.controller.sal.binding.api.data.DataBrokerService;
+
+import org.apache.felix.dm.Component;
import org.osgi.framework.BundleContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-public class MDSALConsumer implements BindingAwareConsumer, IMDSALConsumer {
+public class MdsalConsumerImpl implements BindingAwareConsumer, MdsalConsumer {
private BundleContext ctx = null;
- private BindingAwareBroker broker = null;
+ private volatile BindingAwareBroker broker;
private ConsumerContext consumerContext = null;
private DataBrokerService dataBrokerService;
- static final Logger logger = LoggerFactory.getLogger(MDSALConsumer.class);
-
- void setBindingAwareBroker (BindingAwareBroker b) {
- this.broker = b;
- }
-
- void unsetBindingAwareBroker(BindingAwareBroker b) {
- if (this.broker == b) {
- this.broker = null;
- }
- }
+ static final Logger logger = LoggerFactory.getLogger(MdsalConsumerImpl.class);
void init(Component c) {
this.ctx = c.getDependencyManager().getBundleContext();
- logger.info("OVSDB Neutron Registered with MD-SAL");
+ logger.info("Open vSwitch OpenFlow 1.3 Neutron Networking Provider Registered with MD-SAL");
broker.registerConsumer(this, this.ctx);
}
*
* Authors : Madhu Venugopal, Brent Salisbury, Sam Hague, Dave Tucker
*/
-package org.opendaylight.ovsdb.neutron.provider;
-
-import java.net.InetAddress;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
+package org.opendaylight.ovsdb.openstack.netvirt.providers;
import org.opendaylight.controller.forwardingrulesmanager.FlowConfig;
import org.opendaylight.controller.forwardingrulesmanager.IForwardingRulesManager;
import org.opendaylight.controller.sal.core.Node;
import org.opendaylight.controller.sal.utils.EtherTypes;
import org.opendaylight.controller.sal.utils.HexEncode;
-import org.opendaylight.controller.sal.utils.ServiceHelper;
import org.opendaylight.controller.sal.utils.Status;
import org.opendaylight.controller.sal.utils.StatusCode;
import org.opendaylight.controller.switchmanager.ISwitchManager;
import org.opendaylight.controller.switchmanager.Switch;
import org.opendaylight.ovsdb.lib.notation.Row;
import org.opendaylight.ovsdb.lib.notation.UUID;
-import org.opendaylight.ovsdb.neutron.IAdminConfigManager;
-import org.opendaylight.ovsdb.neutron.IInternalNetworkManager;
-import org.opendaylight.ovsdb.neutron.ITenantNetworkManager;
-import org.opendaylight.ovsdb.neutron.NetworkHandler;
+import org.opendaylight.ovsdb.openstack.netvirt.api.Constants;
+import org.opendaylight.ovsdb.openstack.netvirt.NetworkHandler;
+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.TenantNetworkManager;
import org.opendaylight.ovsdb.plugin.IConnectionServiceInternal;
import org.opendaylight.ovsdb.plugin.OvsdbConfigService;
import org.opendaylight.ovsdb.plugin.StatusWithUuid;
import org.opendaylight.ovsdb.schema.openvswitch.Bridge;
import org.opendaylight.ovsdb.schema.openvswitch.Interface;
import org.opendaylight.ovsdb.schema.openvswitch.Port;
+
+import com.google.common.collect.Lists;
+import com.google.common.collect.Maps;
+import org.apache.commons.lang3.tuple.ImmutablePair;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import java.net.InetAddress;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
-public class OF10Provider implements NetworkProvider {
+/**
+ * Open vSwitch OpenFlow 1.0 Networking Provider for OpenStack Neutron
+ */
+public class OF10Provider implements NetworkingProvider {
private static final Logger logger = LoggerFactory.getLogger(OF10Provider.class);
private static final int INGRESS_TUNNEL_FLOW_PRIORITY = 100;
private static final int EGRESS_TUNNEL_FLOW_PRIORITY = 100;
private static final int DROP_FLOW_PRIORITY = 10;
private static final int FLOOD_TUNNEL_FLOW_PRIORITY = 50;
-
- private IAdminConfigManager adminConfigManager;
- private IInternalNetworkManager internalNetworkManager;
- private ITenantNetworkManager tenantNetworkManager;
-
- public OF10Provider(IAdminConfigManager adminConfigManager,
- IInternalNetworkManager internalNetworkManager,
- ITenantNetworkManager tenantNetworkManager) {
- this.adminConfigManager = adminConfigManager;
- this.internalNetworkManager = internalNetworkManager;
- this.tenantNetworkManager = tenantNetworkManager;
+ public static final int LLDP_PRIORITY = 1000;
+ public static final int NORMAL_PRIORITY = 0;
+
+ private volatile ConfigurationService configurationService;
+ private volatile BridgeConfigurationManager bridgeConfigurationManager;
+ private volatile TenantNetworkManager tenantNetworkManager;
+ private volatile OvsdbConfigService ovsdbConfigService;
+ private volatile IConnectionServiceInternal connectionService;
+ private volatile IForwardingRulesManager forwardingRulesManager;
+ private volatile ISwitchManager switchManager;
+
+ public OF10Provider(){
}
@Override
}
private Status getTunnelReadinessStatus (Node node, String tunnelKey) {
- InetAddress srcTunnelEndPoint = adminConfigManager.getTunnelEndPoint(node);
+ InetAddress srcTunnelEndPoint = configurationService.getTunnelEndPoint(node);
if (srcTunnelEndPoint == null) {
logger.error("Tunnel Endpoint not configured for Node {}", node);
return new Status(StatusCode.NOTFOUND, "Tunnel Endpoint not configured for "+ node);
}
- if (!internalNetworkManager.isInternalNetworkOverlayReady(node)) {
+ if (!bridgeConfigurationManager.isNodeOverlayReady(node)) {
logger.warn("{} is not Overlay ready. It might be an OpenStack Controller Node", node);
return new Status(StatusCode.NOTACCEPTABLE, node+" is not Overlay ready");
}
}
private Status getVlanReadinessStatus (Node node, String segmentationId) {
- if (!internalNetworkManager.isInternalNetworkOverlayReady(node)) {
+ if (!bridgeConfigurationManager.isNodeOverlayReady(node)) {
logger.warn("{} is not Overlay ready. It might be an OpenStack Controller Node", node);
return new Status(StatusCode.NOTACCEPTABLE, node+" is not Overlay ready");
}
* and rewrite the Corresponding internal Vlan and pass it on to br-int via the patch port.
*/
private void programLocalIngressTunnelBridgeRules(Node node, long tunnelOFPort, int internalVlan, long patchPort) {
- String brNetId = internalNetworkManager.getInternalBridgeUUID(node, adminConfigManager.getNetworkBridgeName());
+ String brNetId = bridgeConfigurationManager.getBridgeUuid(node, configurationService.getNetworkBridgeName());
if (brNetId == null) {
logger.error("Failed to initialize Flow Rules for {}", node);
return;
}
try {
- OvsdbConfigService ovsdbTable = (OvsdbConfigService)ServiceHelper.getGlobalInstance(OvsdbConfigService.class, this);
- Row row = ovsdbTable.getRow(node, ovsdbTable.getTableName(node, Bridge.class), brNetId);
- Bridge bridge = ovsdbTable.getTypedRow(node, Bridge.class, row);
+ Row row = ovsdbConfigService.getRow(node, ovsdbConfigService.getTableName(node, Bridge.class), brNetId);
+ Bridge bridge = ovsdbConfigService.getTypedRow(node, Bridge.class, row);
Set<String> dpids = bridge.getDatapathIdColumn().getData();
if (dpids == null || dpids.size() == 0) return;
- Long dpidLong = Long.valueOf(HexEncode.stringToLong((String)dpids.toArray()[0]));
+ Long dpidLong = HexEncode.stringToLong((String) dpids.toArray()[0]);
Node ofNode = new Node(Node.NodeIDType.OPENFLOW, dpidLong);
String flowName = "TepMatch"+tunnelOFPort+""+internalVlan;
FlowConfig flow = new FlowConfig();
flow.setInstallInHw(true);
flow.setPriority(INGRESS_TUNNEL_FLOW_PRIORITY+"");
flow.setIngressPort(tunnelOFPort+"");
- List<String> actions = new ArrayList<String>();
+ List<String> actions = Lists.newArrayList();
actions.add(ActionType.SET_VLAN_ID+"="+internalVlan);
actions.add(ActionType.OUTPUT.toString()+"="+patchPort);
flow.setActions(actions);
}
private void removeLocalIngressTunnelBridgeRules(Node node, long tunnelOFPort, int internalVlan, long patchPort) {
- String brNetId = internalNetworkManager.getInternalBridgeUUID(node, adminConfigManager.getNetworkBridgeName());
+ String brNetId = bridgeConfigurationManager.getBridgeUuid(node, configurationService.getNetworkBridgeName());
if (brNetId == null) {
logger.error("Failed to remove Flow Rules for {}", node);
return;
}
try {
- OvsdbConfigService ovsdbTable = (OvsdbConfigService)ServiceHelper.getGlobalInstance(OvsdbConfigService.class, this);
- Row row = ovsdbTable.getRow(node, ovsdbTable.getTableName(node, Bridge.class), brNetId);
- Bridge bridge = ovsdbTable.getTypedRow(node, Bridge.class, row);
+ Row row = ovsdbConfigService.getRow(node, ovsdbConfigService.getTableName(node, Bridge.class), brNetId);
+ Bridge bridge = ovsdbConfigService.getTypedRow(node, Bridge.class, row);
Set<String> dpids = bridge.getDatapathIdColumn().getData();
if (dpids == null || dpids.size() == 0) return;
- Long dpidLong = Long.valueOf(HexEncode.stringToLong((String)dpids.toArray()[0]));
+ Long dpidLong = HexEncode.stringToLong((String) dpids.toArray()[0]);
Node ofNode = new Node(Node.NodeIDType.OPENFLOW, dpidLong);
String flowName = "TepMatch"+tunnelOFPort+""+internalVlan;
*/
private void programRemoteEgressTunnelBridgeRules(Node node, long patchPort, String attachedMac,
int internalVlan, long tunnelOFPort) {
- String brNetId = internalNetworkManager.getInternalBridgeUUID(node, adminConfigManager.getNetworkBridgeName());
+ String brNetId = bridgeConfigurationManager.getBridgeUuid(node, configurationService.getNetworkBridgeName());
if (brNetId == null) {
logger.error("Failed to initialize Flow Rules for {}", node);
return;
}
try {
- OvsdbConfigService ovsdbTable = (OvsdbConfigService)ServiceHelper.getGlobalInstance(OvsdbConfigService.class, this);
- Row row = ovsdbTable.getRow(node, ovsdbTable.getTableName(node, Bridge.class), brNetId);
- Bridge bridge = ovsdbTable.getTypedRow(node, Bridge.class, row);
+ Row row = ovsdbConfigService.getRow(node, ovsdbConfigService.getTableName(node, Bridge.class), brNetId);
+ Bridge bridge = ovsdbConfigService.getTypedRow(node, Bridge.class, row);
Set<String> dpids = bridge.getDatapathIdColumn().getData();
if (dpids == null || dpids.size() == 0) return;
- Long dpidLong = Long.valueOf(HexEncode.stringToLong((String)dpids.toArray()[0]));
+ Long dpidLong = HexEncode.stringToLong((String) dpids.toArray()[0]);
Node ofNode = new Node(Node.NodeIDType.OPENFLOW, dpidLong);
String flowName = "TepMatch"+tunnelOFPort+""+internalVlan+""+HexEncode.stringToLong(attachedMac);
FlowConfig flow = new FlowConfig();
flow.setDstMac(attachedMac);
flow.setIngressPort(patchPort+"");
flow.setVlanId(internalVlan+"");
- List<String> actions = new ArrayList<String>();
+ List<String> actions = Lists.newArrayList();
actions.add(ActionType.POP_VLAN.toString());
actions.add(ActionType.OUTPUT.toString()+"="+tunnelOFPort);
flow.setActions(actions);
private void removeRemoteEgressTunnelBridgeRules(Node node, long patchPort, String attachedMac,
int internalVlan, long tunnelOFPort) {
- String brNetId = internalNetworkManager.getInternalBridgeUUID(node, adminConfigManager.getNetworkBridgeName());
+ String brNetId = bridgeConfigurationManager.getBridgeUuid(node, configurationService.getNetworkBridgeName());
if (brNetId == null) {
logger.error("Failed to initialize Flow Rules for {}", node);
return;
}
try {
- OvsdbConfigService ovsdbTable = (OvsdbConfigService)ServiceHelper.getGlobalInstance(OvsdbConfigService.class, this);
- Row row = ovsdbTable.getRow(node, ovsdbTable.getTableName(node, Bridge.class), brNetId);
- Bridge bridge = ovsdbTable.getTypedRow(node, Bridge.class, row);
+ Row row = ovsdbConfigService.getRow(node, ovsdbConfigService.getTableName(node, Bridge.class), brNetId);
+ Bridge bridge = ovsdbConfigService.getTypedRow(node, Bridge.class, row);
Set<String> dpids = bridge.getDatapathIdColumn().getData();
if (dpids == null || dpids.size() == 0) return;
- Long dpidLong = Long.valueOf(HexEncode.stringToLong((String)dpids.toArray()[0]));
+ Long dpidLong = HexEncode.stringToLong((String) dpids.toArray()[0]);
Node ofNode = new Node(Node.NodeIDType.OPENFLOW, dpidLong);
String flowName = "TepMatch"+tunnelOFPort+""+internalVlan+""+HexEncode.stringToLong(attachedMac);
Status status = this.deleteStaticFlow(ofNode, flowName);
* Also perform the Strip-Vlan action.
*/
private void programFloodEgressTunnelBridgeRules(Node node, long patchPort, int internalVlan, long tunnelOFPort) {
- String brNetId = internalNetworkManager.getInternalBridgeUUID(node, adminConfigManager.getNetworkBridgeName());
+ String brNetId = bridgeConfigurationManager.getBridgeUuid(node, configurationService.getNetworkBridgeName());
if (brNetId == null) {
logger.error("Failed to initialize Flow Rules for {}", node);
return;
}
try {
- OvsdbConfigService ovsdbTable = (OvsdbConfigService)ServiceHelper.getGlobalInstance(OvsdbConfigService.class, this);
- Row row = ovsdbTable.getRow(node, ovsdbTable.getTableName(node, Bridge.class), brNetId);
- Bridge bridge = ovsdbTable.getTypedRow(node, Bridge.class, row);
+ Row row = ovsdbConfigService.getRow(node, ovsdbConfigService.getTableName(node, Bridge.class), brNetId);
+ Bridge bridge = ovsdbConfigService.getTypedRow(node, Bridge.class, row);
Set<String> dpids = bridge.getDatapathIdColumn().getData();
if (dpids == null || dpids.size() == 0) return;
- Long dpidLong = Long.valueOf(HexEncode.stringToLong((String)dpids.toArray()[0]));
+ Long dpidLong = HexEncode.stringToLong((String) dpids.toArray()[0]);
Node ofNode = new Node(Node.NodeIDType.OPENFLOW, dpidLong);
String flowName = "TepFlood"+internalVlan;
- IForwardingRulesManager frm = (IForwardingRulesManager) ServiceHelper.getInstance(
- IForwardingRulesManager.class, "default", this);
- FlowConfig existingFlowConfig = frm.getStaticFlow(flowName, ofNode);
+ FlowConfig existingFlowConfig = forwardingRulesManager.getStaticFlow(flowName, ofNode);
FlowConfig flow = existingFlowConfig;
- Status status = null;
+ Status status;
if (flow == null) {
flow = new FlowConfig();
flow.setName(flowName);
flow.setPriority(FLOOD_TUNNEL_FLOW_PRIORITY+"");
flow.setIngressPort(patchPort+"");
flow.setVlanId(internalVlan+"");
- List<String> actions = new ArrayList<String>();
+ List<String> actions = Lists.newArrayList();
actions.add(ActionType.POP_VLAN.toString());
actions.add(ActionType.OUTPUT.toString()+"="+tunnelOFPort);
flow.setActions(actions);
- status = frm.addStaticFlow(flow);
+ status = forwardingRulesManager.addStaticFlow(flow);
logger.debug("Add Flood Egress Flow Programming Status {} for Flow {} on {} / {}",
status, flow, ofNode, node);
} else {
flow, ofNode, node);
return;
}
- status = frm.modifyStaticFlow(flow);
+ status = forwardingRulesManager.modifyStaticFlow(flow);
logger.debug("Modify Flood Egress Flow Programming Status {} for Flow {} on {} / {}",
status, flow, ofNode, node);
}
}
private void removeFloodEgressTunnelBridgeRules(Node node, long patchPort, int internalVlan, long tunnelOFPort) {
- String brNetId = internalNetworkManager.getInternalBridgeUUID(node, adminConfigManager.getNetworkBridgeName());
+ String brNetId = bridgeConfigurationManager.getBridgeUuid(node, configurationService.getNetworkBridgeName());
if (brNetId == null) {
logger.error("Failed to remove Flow Rules for {}", node);
return;
}
try {
- OvsdbConfigService ovsdbTable = (OvsdbConfigService)ServiceHelper.getGlobalInstance(OvsdbConfigService.class, this);
- Row row = ovsdbTable.getRow(node, ovsdbTable.getTableName(node, Bridge.class), brNetId);
- Bridge bridge = ovsdbTable.getTypedRow(node, Bridge.class, row);
+ Row row = ovsdbConfigService.getRow(node, ovsdbConfigService.getTableName(node, Bridge.class), brNetId);
+ Bridge bridge = ovsdbConfigService.getTypedRow(node, Bridge.class, row);
Set<String> dpids = bridge.getDatapathIdColumn().getData();
if (dpids == null || dpids.size() == 0) return;
- Long dpidLong = Long.valueOf(HexEncode.stringToLong((String)dpids.toArray()[0]));
+ Long dpidLong = HexEncode.stringToLong((String) dpids.toArray()[0]);
Node ofNode = new Node(Node.NodeIDType.OPENFLOW, dpidLong);
String flowName = "TepFlood"+internalVlan;
- IForwardingRulesManager frm = (IForwardingRulesManager) ServiceHelper.getInstance(
- IForwardingRulesManager.class, "default", this);
- FlowConfig flow = frm.getStaticFlow(flowName, ofNode);
- Status status = null;
+ FlowConfig flow = forwardingRulesManager.getStaticFlow(flowName, ofNode);
+ Status status;
if (flow != null) {
- status = frm.removeStaticFlow(flowName, ofNode);
+ status = forwardingRulesManager.removeStaticFlow(flowName, ofNode);
logger.debug("Remove Flood Egress Flow Programming Status {} for Flow {} on {} / {}",
status, flow, ofNode, node);
} else {
- logger.debug("Flood Egress Flow already removed. Skipping removal for Flow {} on {} / {}",
- flow, ofNode, node);
- return;
+ logger.debug("Flood Egress Flow already removed. Skipping removal of flow on {} / {}",
+ ofNode, node);
}
} catch (Exception e) {
logger.error("Failed to remove Flow Rules for {}", node, e);
}
private void programTunnelRules (String tunnelType, String segmentationId, InetAddress dst, Node node,
- Interface intf, boolean local) {
- String networkId = tenantNetworkManager.getNetworkIdForSegmentationId(segmentationId);
+ Interface iface, boolean local) {
+ String networkId = tenantNetworkManager.getNetworkId(segmentationId);
if (networkId == null) {
logger.debug("Tenant Network not found with Segmentation-id {}", segmentationId);
return;
logger.debug("No InternalVlan provisioned for Tenant Network {}",networkId);
return;
}
- Map<String, String> externalIds = intf.getExternalIdsColumn().getData();
+ Map<String, String> externalIds = iface.getExternalIdsColumn().getData();
if (externalIds == null) {
- logger.error("No external_ids seen in {}", intf);
+ logger.error("No external_ids seen in {}", iface);
return;
}
- String attachedMac = externalIds.get(ITenantNetworkManager.EXTERNAL_ID_VM_MAC);
+ String attachedMac = externalIds.get(Constants.EXTERNAL_ID_VM_MAC);
if (attachedMac == null) {
- logger.error("No AttachedMac seen in {}", intf);
+ logger.error("No AttachedMac seen in {}", iface);
return;
}
- String patchInt = adminConfigManager.getPatchToIntegration();
+ String patchInt = configurationService
+ .getPatchPortName(new ImmutablePair<>(configurationService.getNetworkBridgeName(),
+ configurationService.getIntegrationBridgeName()));
long patchOFPort = -1;
try {
- OvsdbConfigService ovsdbTable = (OvsdbConfigService)ServiceHelper.getGlobalInstance(OvsdbConfigService.class, this);
- Map<String, Row> intfs = ovsdbTable.getRows(node, ovsdbTable.getTableName(node, Interface.class));
- if (intfs != null) {
- for (Row row : intfs.values()) {
- Interface patchIntf = ovsdbTable.getTypedRow(node, Interface.class, row);
- if (patchIntf.getName().equalsIgnoreCase(patchInt)) {
- Set<Long> of_ports = patchIntf.getOpenFlowPortColumn().getData();
+ Map<String, Row> ifaces = ovsdbConfigService.getRows(node, ovsdbConfigService.getTableName(node, Interface.class));
+ if (ifaces != null) {
+ for (Row row : ifaces.values()) {
+ Interface patchiface = ovsdbConfigService.getTypedRow(node, Interface.class, row);
+ if (patchiface.getName().equalsIgnoreCase(patchInt)) {
+ Set<Long> of_ports = patchiface.getOpenFlowPortColumn().getData();
if (of_ports == null || of_ports.size() <= 0) {
logger.error("Could NOT Identified Patch port {} on {}", patchInt, node);
continue;
if (patchOFPort == -1) {
logger.error("Cannot identify {} interface on {}", patchInt, node);
}
- for (Row row : intfs.values()) {
- Interface tunIntf = ovsdbTable.getTypedRow(node, Interface.class, row);
- if (tunIntf.getName().equals(this.getTunnelName(tunnelType, segmentationId, dst))) {
- Set<Long> of_ports = tunIntf.getOpenFlowPortColumn().getData();
+ for (Row row : ifaces.values()) {
+ Interface tuniface = ovsdbConfigService.getTypedRow(node, Interface.class, row);
+ if (tuniface.getName().equals(this.getTunnelName(tunnelType, segmentationId, dst))) {
+ Set<Long> of_ports = tuniface.getOpenFlowPortColumn().getData();
if (of_ports == null || of_ports.size() <= 0) {
- logger.warn("Could not Identify Tunnel port {} on {}. Don't panic. It might get converged soon...", tunIntf.getName(), node);
+ logger.warn("Could not Identify Tunnel port {} on {}. Don't panic. It might get converged soon...", tuniface.getName(), node);
continue;
}
long tunnelOFPort = (long)of_ports.toArray()[0];
if (tunnelOFPort == -1) {
- logger.warn("Tunnel Port {} on node {}: OFPort = -1 . Don't panic. It might get converged soon...", tunIntf.getName(), node);
+ logger.warn("Tunnel Port {} on node {}: OFPort = -1 . Don't panic. It might get converged soon...", tuniface.getName(), node);
return;
}
- logger.debug("Identified Tunnel port {} -> OF ({}) on {}", tunIntf.getName(), tunnelOFPort, node);
+ logger.debug("Identified Tunnel port {} -> OF ({}) on {}", tuniface.getName(), tunnelOFPort, node);
if (!local) {
programRemoteEgressTunnelBridgeRules(node, patchOFPort, attachedMac, internalVlan, tunnelOFPort);
}
private void removeTunnelRules (String tunnelType, String segmentationId, InetAddress dst, Node node,
- Interface intf, boolean local) {
- String networkId = tenantNetworkManager.getNetworkIdForSegmentationId(segmentationId);
+ Interface iface, boolean local) {
+ String networkId = tenantNetworkManager.getNetworkId(segmentationId);
if (networkId == null) {
logger.debug("Tenant Network not found with Segmentation-id {}",segmentationId);
return;
}
- int internalVlan = tenantNetworkManager.getInternalVlan(node,networkId);
+ int internalVlan = tenantNetworkManager.getInternalVlan(node, networkId);
if (internalVlan == 0) {
logger.debug("No InternalVlan provisioned for Tenant Network {}",networkId);
return;
}
- Map<String, String> externalIds = intf.getExternalIdsColumn().getData();
+ Map<String, String> externalIds = iface.getExternalIdsColumn().getData();
if (externalIds == null) {
- logger.error("No external_ids seen in {}", intf);
+ logger.error("No external_ids seen in {}", iface);
return;
}
- String attachedMac = externalIds.get(ITenantNetworkManager.EXTERNAL_ID_VM_MAC);
+ String attachedMac = externalIds.get(Constants.EXTERNAL_ID_VM_MAC);
if (attachedMac == null) {
- logger.error("No AttachedMac seen in {}", intf);
+ logger.error("No AttachedMac seen in {}", iface);
return;
}
- String patchInt = adminConfigManager.getPatchToIntegration();
+ String patchInt = configurationService
+ .getPatchPortName(new ImmutablePair<>(configurationService.getNetworkBridgeName(),
+ configurationService.getIntegrationBridgeName()));
long patchOFPort = -1;
try {
- OvsdbConfigService ovsdbTable = (OvsdbConfigService)ServiceHelper.getGlobalInstance(OvsdbConfigService.class, this);
- Map<String, Row> intfs = ovsdbTable.getRows(node, ovsdbTable.getTableName(node, Interface.class));
- if (intfs != null) {
- for (Row row : intfs.values()) {
- Interface patchIntf = ovsdbTable.getTypedRow(node, Interface.class, row);
- if (patchIntf.getName().equalsIgnoreCase(patchInt)) {
- Set<Long> of_ports = patchIntf.getOpenFlowPortColumn().getData();
+ Map<String, Row> ifaces = ovsdbConfigService.getRows(node, ovsdbConfigService.getTableName(node, Interface.class));
+ if (ifaces != null) {
+ for (Row row : ifaces.values()) {
+ Interface patchiface = ovsdbConfigService.getTypedRow(node, Interface.class, row);
+ if (patchiface.getName().equalsIgnoreCase(patchInt)) {
+ Set<Long> of_ports = patchiface.getOpenFlowPortColumn().getData();
if (of_ports == null || of_ports.size() <= 0) {
logger.error("Could NOT Identified Patch port {} on {}", patchInt, node);
continue;
if (patchOFPort == -1) {
logger.error("Cannot identify {} interface on {}", patchInt, node);
}
- for (Row row : intfs.values()) {
- Interface tunIntf = ovsdbTable.getTypedRow(node, Interface.class, row);
- if (tunIntf.getName().equals(this.getTunnelName(tunnelType, segmentationId, dst))) {
- Set<Long> of_ports = tunIntf.getOpenFlowPortColumn().getData();
+ for (Row row : ifaces.values()) {
+ Interface tuniface = ovsdbConfigService.getTypedRow(node, Interface.class, row);
+ if (tuniface.getName().equals(this.getTunnelName(tunnelType, segmentationId, dst))) {
+ Set<Long> of_ports = tuniface.getOpenFlowPortColumn().getData();
if (of_ports == null || of_ports.size() <= 0) {
- logger.error("Could NOT Identify Tunnel port {} on {}", tunIntf.getName(), node);
+ logger.error("Could NOT Identify Tunnel port {} on {}", tuniface.getName(), node);
continue;
}
long tunnelOFPort = (long)of_ports.toArray()[0];
if (tunnelOFPort == -1) {
- logger.error("Could NOT Identify Tunnel port {} -> OF ({}) on {}", tunIntf.getName(), tunnelOFPort, node);
+ logger.error("Could NOT Identify Tunnel port {} -> OF ({}) on {}", tuniface.getName(), tunnelOFPort, node);
return;
}
- logger.debug("Identified Tunnel port {} -> OF ({}) on {}", tunIntf.getName(), tunnelOFPort, node);
+ logger.debug("Identified Tunnel port {} -> OF ({}) on {}", tuniface.getName(), tunnelOFPort, node);
if (!local) {
removeRemoteEgressTunnelBridgeRules(node, patchOFPort, attachedMac, internalVlan, tunnelOFPort);
flow.setInstallInHw(true);
flow.setPriority(DROP_FLOW_PRIORITY+"");
flow.setIngressPort(inOFPort+"");
- List<String> actions = new ArrayList<String>();
+ List<String> actions = Lists.newArrayList();
actions.add(ActionType.DROP+"");
flow.setActions(actions);
Status status = this.addStaticFlow(ofNode, flow);
flow.setPriority(INGRESS_TUNNEL_FLOW_PRIORITY+"");
flow.setIngressPort(inOFPort+"");
flow.setVlanId(fromVlan);
- List<String> actions = new ArrayList<String>();
+ List<String> actions = Lists.newArrayList();
actions.add(ActionType.SET_VLAN_ID+"="+toVlan);
if (outOFPort == -1) {
actions.add(ActionType.HW_PATH.toString());
flow.setPriority(EGRESS_TUNNEL_FLOW_PRIORITY + "");
flow.setIngressPort(inOFPort + "");
flow.setVlanId(vlan);
- List<String> actions = new ArrayList<String>();
+ List<String> actions = Lists.newArrayList();
actions.add(ActionType.OUTPUT.toString()+"="+outOFPort);
flow.setActions(actions);
Status status = this.addStaticFlow(ofNode, flow);
public long getOFPort (Node node, String portName) {
long ofPort = -1;
try {
- OvsdbConfigService ovsdbTable = (OvsdbConfigService)ServiceHelper.getGlobalInstance(OvsdbConfigService.class, this);
- Map<String, Row> intfs = ovsdbTable.getRows(node, ovsdbTable.getTableName(node, Interface.class));
- if (intfs != null) {
- for (Row row : intfs.values()) {
- Interface intf = ovsdbTable.getTypedRow(node, Interface.class, row);
- if (intf.getName().equalsIgnoreCase(portName)) {
- Set<Long> of_ports = intf.getOpenFlowPortColumn().getData();
+ Map<String, Row> ifaces = ovsdbConfigService.getRows(node, ovsdbConfigService.getTableName(node, Interface.class));
+ if (ifaces != null) {
+ for (Row row : ifaces.values()) {
+ Interface iface = ovsdbConfigService.getTypedRow(node, Interface.class, row);
+ if (iface.getName().equalsIgnoreCase(portName)) {
+ Set<Long> of_ports = iface.getOpenFlowPortColumn().getData();
if (of_ports == null || of_ports.size() <= 0) {
logger.error("Could not identify patch port {} on {}", portName, node);
continue;
public long physicalOfPort;
public int internalVlan;
- public vlanNet (NeutronNetwork network, Node node, Interface intf) {
+ public vlanNet (NeutronNetwork network, Node node, Interface iface) {
patchIntOfPort = -1;
patchNetOfPort = -1;
physicalOfPort = -1;
internalVlan = 0;
- initializeVlanNet(network, node, intf);
+ initializeVlanNet(network, node, iface);
}
public boolean isValid () {
- if ((patchIntOfPort != -1) && (patchNetOfPort != -1) && (physicalOfPort != -1) && (internalVlan != -1)) {
- return true;
- } else {
- return false;
- }
+ return (patchIntOfPort != -1) && (patchNetOfPort != -1) && (physicalOfPort != -1) && (internalVlan != -1);
}
public long getPatchIntOfPort () {
return internalVlan;
}
- public void initializeVlanNet (NeutronNetwork network, Node node, Interface intf) {
+ public void initializeVlanNet (NeutronNetwork network, Node node, Interface iface) {
internalVlan = tenantNetworkManager.getInternalVlan(node, network.getNetworkUUID());
if (internalVlan == 0) {
logger.debug("No InternalVlan provisioned for Tenant Network {}", network.getNetworkUUID());
}
/* Get ofports for patch ports and physical interface. */
- String patchToNetworkName = adminConfigManager.getPatchToNetwork();
- String patchToIntegrationName = adminConfigManager.getPatchToIntegration();
- String physNetName = adminConfigManager.getPhysicalInterfaceName(node, network.getProviderPhysicalNetwork());
+ String patchToNetworkName = configurationService
+ .getPatchPortName(new ImmutablePair<>(configurationService.getIntegrationBridgeName(),
+ configurationService.getNetworkBridgeName()));
+
+ String patchToIntegrationName = configurationService
+ .getPatchPortName(new ImmutablePair<>(configurationService.getNetworkBridgeName(),
+ configurationService.getIntegrationBridgeName()));
+
+ String physNetName = bridgeConfigurationManager.getPhysicalInterfaceName(node, network.getProviderPhysicalNetwork());
patchIntOfPort = getOFPort(node, patchToNetworkName);
if (patchIntOfPort == -1) {
physicalOfPort = getOFPort(node, physNetName);
if (physicalOfPort == -1) {
logger.error("Cannot identify {} interface on {}", physNetName, node);
- return;
}
}
}
private Node getOFNode (Node node, String bridgeName) {
- String brUUID = internalNetworkManager.getInternalBridgeUUID(node, bridgeName);
+ String brUUID = bridgeConfigurationManager.getBridgeUuid(node, bridgeName);
if (brUUID == null) {
logger.error("getOFNode: Unable to find {} UUID on node {}", bridgeName, node);
return null;
}
try {
- OvsdbConfigService ovsdbTable = (OvsdbConfigService)ServiceHelper.getGlobalInstance(OvsdbConfigService.class, this);
- Row row = ovsdbTable.getRow(node, ovsdbTable.getTableName(node, Bridge.class), brUUID);
- Bridge bridge = ovsdbTable.getTypedRow(node, Bridge.class, row);
+ Row row = ovsdbConfigService.getRow(node, ovsdbConfigService.getTableName(node, Bridge.class), brUUID);
+ Bridge bridge = ovsdbConfigService.getTypedRow(node, Bridge.class, row);
Set<String> dpids = bridge.getDatapathIdColumn().getData();
if (dpids == null || dpids.size() == 0) {
return null;
}
- Long dpidLong = Long.valueOf(HexEncode.stringToLong((String)dpids.toArray()[0]));
- Node ofNode = new Node(Node.NodeIDType.OPENFLOW, dpidLong);
- return ofNode;
+ Long dpidLong = HexEncode.stringToLong((String) dpids.toArray()[0]);
+ return new Node(Node.NodeIDType.OPENFLOW, dpidLong);
} catch (Exception e) {
logger.error("deleteRule: Failed to delete Flow Rule for {}", node, e);
}
* priority=100,in_port=2,dl_vlan=2001 actions=mod_vlan_vid:1actions=output:1
*/
- private void programVlanRules (NeutronNetwork network, Node node, Interface intf) {
- vlanNet vlanNet = new vlanNet(network, node, intf);
+ private void programVlanRules (NeutronNetwork network, Node node, Interface iface) {
+ vlanNet vlanNet = new vlanNet(network, node, iface);
if (vlanNet.isValid()) {
- String netBrName = adminConfigManager.getNetworkBridgeName();
+ String netBrName = configurationService.getNetworkBridgeName();
String intModVlanFlowName = getIntModVlanFlowName(vlanNet.getPatchNetOfPort(), vlanNet.getInternalVlan()+"", network.getProviderSegmentationID());
String netModVlanFlowName = getNetModVlanFlowName(vlanNet.getPatchNetOfPort(), network.getProviderSegmentationID(), vlanNet.getInternalVlan()+"");
}
}
- private void removeVlanRules (NeutronNetwork network, Node node, Interface intf) {
- vlanNet vlanNet = new vlanNet(network, node, intf);
+ private void removeVlanRules (NeutronNetwork network, Node node, Interface iface) {
+ vlanNet vlanNet = new vlanNet(network, node, iface);
if (vlanNet.isValid()) {
- String netBrName = adminConfigManager.getNetworkBridgeName();
+ String netBrName = configurationService.getNetworkBridgeName();
String intModVlanFlowName = getIntModVlanFlowName(vlanNet.getPatchNetOfPort(), vlanNet.getInternalVlan()+"", network.getProviderSegmentationID());
String netModVlanFlowName = getNetModVlanFlowName(vlanNet.getPatchNetOfPort(), network.getProviderSegmentationID(), vlanNet.getInternalVlan()+"");
}
@Override
- public Status handleInterfaceUpdate(NeutronNetwork network, Node srcNode, Interface intf) {
- logger.debug("handleInterfaceUpdate: networkType: {}, segmentationId: {}, srcNode: {}, intf: {}",
- network.getProviderNetworkType(), network.getProviderSegmentationID(), srcNode, intf.getName());
+ public Status handleInterfaceUpdate(NeutronNetwork network, Node srcNode, Interface iface) {
+ logger.debug("handleInterfaceUpdate: networkType: {}, segmentationId: {}, srcNode: {}, iface: {}",
+ network.getProviderNetworkType(), network.getProviderSegmentationID(), srcNode, iface.getName());
if (network.getProviderNetworkType().equalsIgnoreCase(NetworkHandler.NETWORK_TYPE_VLAN)) {
Status status = getVlanReadinessStatus(srcNode, network.getProviderSegmentationID());
if (!status.isSuccess()) {
return status;
} else {
- this.programVlanRules(network, srcNode, intf);
+ this.programVlanRules(network, srcNode, iface);
return new Status(StatusCode.SUCCESS);
}
} else if (network.getProviderNetworkType().equalsIgnoreCase(NetworkHandler.NETWORK_TYPE_VXLAN) ||
Status status = getTunnelReadinessStatus(srcNode, network.getProviderSegmentationID());
if (!status.isSuccess()) return status;
- IConnectionServiceInternal connectionService = (IConnectionServiceInternal)ServiceHelper.getGlobalInstance(IConnectionServiceInternal.class, this);
List<Node> nodes = connectionService.getNodes();
nodes.remove(srcNode);
for (Node dstNode : nodes) {
status = getTunnelReadinessStatus(dstNode, network.getProviderSegmentationID());
if (!status.isSuccess()) continue;
- InetAddress src = adminConfigManager.getTunnelEndPoint(srcNode);
- InetAddress dst = adminConfigManager.getTunnelEndPoint(dstNode);
+ InetAddress src = configurationService.getTunnelEndPoint(srcNode);
+ InetAddress dst = configurationService.getTunnelEndPoint(dstNode);
status = addTunnelPort(srcNode, network.getProviderNetworkType(), src, dst, network.getProviderSegmentationID());
if (status.isSuccess()) {
- this.programTunnelRules(network.getProviderNetworkType(), network.getProviderSegmentationID(), dst, srcNode, intf, true);
+ this.programTunnelRules(network.getProviderNetworkType(), network.getProviderSegmentationID(), dst, srcNode, iface, true);
status = addTunnelPort(dstNode, network.getProviderNetworkType(), dst, src, network.getProviderSegmentationID());
if (status.isSuccess()) {
- this.programTunnelRules(network.getProviderNetworkType(), network.getProviderSegmentationID(), src, dstNode, intf, false);
+ this.programTunnelRules(network.getProviderNetworkType(), network.getProviderSegmentationID(), src, dstNode, iface, false);
}
}
}
}
@Override
- public Status handleInterfaceDelete(String tunnelType, NeutronNetwork network, Node srcNode, Interface intf, boolean isLastInstanceOnNode) {
+ public Status handleInterfaceDelete(String tunnelType, NeutronNetwork network,
+ Node srcNode,Interface iface, boolean isLastInstanceOnNode) {
Status status = new Status(StatusCode.SUCCESS);
- logger.debug("handleInterfaceDelete: srcNode: {}, networkType: {}, intf: {}, type: {}, isLast: {}",
+ logger.debug("handleInterfaceDelete: srcNode: {}, networkType: {}, iface: {}, type: {}, isLast: {}",
srcNode, (network != null) ? network.getProviderNetworkType() : "",
- intf.getName(), intf.getTypeColumn().getData(), isLastInstanceOnNode);
+ iface.getName(), iface.getTypeColumn().getData(), isLastInstanceOnNode);
- List<String> phyIfName = adminConfigManager.getAllPhysicalInterfaceNames(srcNode);
+ List<String> phyIfName = bridgeConfigurationManager.getAllPhysicalInterfaceNames(srcNode);
if ((network != null) && network.getProviderNetworkType().equalsIgnoreCase(NetworkHandler.NETWORK_TYPE_VLAN)) {
if (isLastInstanceOnNode) {
- this.removeVlanRules(network, srcNode, intf);
+ this.removeVlanRules(network, srcNode, iface);
}
- } else if (intf.getTypeColumn().getData().equalsIgnoreCase(NetworkHandler.NETWORK_TYPE_VXLAN) || intf.getTypeColumn().getData().equalsIgnoreCase(NetworkHandler.NETWORK_TYPE_GRE)) {
+ } else if (iface.getTypeColumn().getData().equalsIgnoreCase(NetworkHandler.NETWORK_TYPE_VXLAN) ||
+ iface.getTypeColumn().getData().equalsIgnoreCase(NetworkHandler.NETWORK_TYPE_GRE)) {
/* Delete tunnel port */
try {
- Map<String, String> options = intf.getOptionsColumn().getData();
+ Map<String, String> options = iface.getOptionsColumn().getData();
InetAddress src = InetAddress.getByName(options.get("local_ip"));
InetAddress dst = InetAddress.getByName(options.get("remote_ip"));
String key = options.get("key");
- status = deleteTunnelPort(srcNode, intf.getTypeColumn().getData(), src, dst, key);
+ status = deleteTunnelPort(srcNode, iface.getTypeColumn().getData(), src, dst, key);
} catch (Exception e) {
logger.error(e.getMessage(), e);
}
- } else if (phyIfName.contains(intf.getName())) {
- deletePhysicalPort(srcNode, intf.getName());
+ } else if (phyIfName.contains(iface.getName())) {
+ deletePhysicalPort(srcNode, iface.getName());
} else {
/* delete all other interfaces */
- IConnectionServiceInternal connectionService = (IConnectionServiceInternal)ServiceHelper.getGlobalInstance(IConnectionServiceInternal.class, this);
List<Node> nodes = connectionService.getNodes();
nodes.remove(srcNode);
for (Node dstNode : nodes) {
- InetAddress src = adminConfigManager.getTunnelEndPoint(srcNode);
- InetAddress dst = adminConfigManager.getTunnelEndPoint(dstNode);
- this.removeTunnelRules(network.getProviderNetworkType(), network.getProviderSegmentationID(), dst, srcNode, intf, true);
+ InetAddress src = configurationService.getTunnelEndPoint(srcNode);
+ InetAddress dst = configurationService.getTunnelEndPoint(dstNode);
+ assert network != null;
+ this.removeTunnelRules(network.getProviderNetworkType(), network.getProviderSegmentationID(), dst, srcNode, iface, true);
if (isLastInstanceOnNode) {
status = deleteTunnelPort(srcNode, network.getProviderNetworkType(), src, dst, network.getProviderSegmentationID());
}
- this.removeTunnelRules(network.getProviderNetworkType(), network.getProviderSegmentationID(), src, dstNode, intf, false);
+ this.removeTunnelRules(network.getProviderNetworkType(), network.getProviderSegmentationID(), src, dstNode, iface, false);
if (status.isSuccess() && isLastInstanceOnNode) {
deleteTunnelPort(dstNode, network.getProviderNetworkType(), dst, src, network.getProviderSegmentationID());
}
private Interface getTunnelInterface (Node node, String tunnelType, InetAddress dst, String key) {
try {
- OvsdbConfigService ovsdbTable = (OvsdbConfigService)ServiceHelper.getGlobalInstance(OvsdbConfigService.class, this);
String portName = getTunnelName(tunnelType, key, dst);
- Map<String, Row> tunIntfs = ovsdbTable.getRows(node, ovsdbTable.getTableName(node, Interface.class));
- if (tunIntfs != null) {
- for (Row row : tunIntfs.values()) {
- Interface tunIntf = ovsdbTable.getTypedRow(node, Interface.class, row);
- if (tunIntf.getName().equals(portName)) return tunIntf;
+ Map<String, Row> tunifaces = ovsdbConfigService.getRows(node, ovsdbConfigService.getTableName(node, Interface.class));
+ if (tunifaces != null) {
+ for (Row row : tunifaces.values()) {
+ Interface tuniface = ovsdbConfigService.getTypedRow(node, Interface.class, row);
+ if (tuniface.getName().equals(portName)) return tuniface;
}
}
}
private boolean isTunnelPresent(Node node, String tunnelName, String bridgeUUID) throws Exception {
- OvsdbConfigService ovsdbTable = (OvsdbConfigService)ServiceHelper.getGlobalInstance(OvsdbConfigService.class, this);
- Row row = ovsdbTable.getRow(node, ovsdbTable.getTableName(node, Bridge.class), bridgeUUID);
- Bridge bridge = ovsdbTable.getTypedRow(node, Bridge.class, row);
+ Row row = ovsdbConfigService.getRow(node, ovsdbConfigService.getTableName(node, Bridge.class), bridgeUUID);
+ Bridge bridge = ovsdbConfigService.getTypedRow(node, Bridge.class, row);
if (bridge != null) {
Set<UUID> ports = bridge.getPortsColumn().getData();
for (UUID portUUID : ports) {
- Row portRow = ovsdbTable.getRow(node, ovsdbTable.getTableName(node, Port.class), portUUID.toString());
- Port port = ovsdbTable.getTypedRow(node, Port.class, portRow);
+ Row portRow = ovsdbConfigService.getRow(node, ovsdbConfigService.getTableName(node, Port.class), portUUID.toString());
+ Port port = ovsdbConfigService.getTypedRow(node, Port.class, portRow);
if (port != null && port.getName().equalsIgnoreCase(tunnelName)) return true;
}
}
}
private String getPortUuid(Node node, String portName, String bridgeUUID) throws Exception {
- OvsdbConfigService ovsdbTable = (OvsdbConfigService)ServiceHelper.getGlobalInstance(OvsdbConfigService.class, this);
- Row row = ovsdbTable.getRow(node, ovsdbTable.getTableName(node, Bridge.class), bridgeUUID);
- Bridge bridge = ovsdbTable.getTypedRow(node, Bridge.class, row);
+ Row row = ovsdbConfigService.getRow(node, ovsdbConfigService.getTableName(node, Bridge.class), bridgeUUID);
+ Bridge bridge = ovsdbConfigService.getTypedRow(node, Bridge.class, row);
if (bridge != null) {
Set<UUID> ports = bridge.getPortsColumn().getData();
for (UUID portUUID : ports) {
- Row portRow = ovsdbTable.getRow(node, ovsdbTable.getTableName(node, Port.class), portUUID.toString());
- Port port = ovsdbTable.getTypedRow(node, Port.class, portRow);
+ Row portRow = ovsdbConfigService.getRow(node, ovsdbConfigService.getTableName(node, Port.class), portUUID.toString());
+ Port port = ovsdbConfigService.getTypedRow(node, Port.class, portRow);
if (port != null && port.getName().equalsIgnoreCase(portName)) return portUUID.toString();
}
}
private Status addTunnelPort (Node node, String tunnelType, InetAddress src, InetAddress dst, String key) {
try {
String bridgeUUID = null;
- String tunnelBridgeName = adminConfigManager.getNetworkBridgeName();
- OvsdbConfigService ovsdbTable = (OvsdbConfigService)ServiceHelper.getGlobalInstance(OvsdbConfigService.class, this);
- Map<String, Row> bridgeTable = ovsdbTable.getRows(node, ovsdbTable.getTableName(node, Bridge.class));
+ String tunnelBridgeName = configurationService.getNetworkBridgeName();
+ Map<String, Row> bridgeTable = ovsdbConfigService.getRows(node, ovsdbConfigService.getTableName(node, Bridge.class));
if (bridgeTable != null) {
for (String uuid : bridgeTable.keySet()) {
- Bridge bridge = ovsdbTable.getTypedRow(node, Bridge.class, bridgeTable.get(uuid));
+ Bridge bridge = ovsdbConfigService.getTypedRow(node, Bridge.class, bridgeTable.get(uuid));
if (bridge.getName().equals(tunnelBridgeName)) {
bridgeUUID = uuid;
break;
return new Status(StatusCode.SUCCESS);
}
- Port tunnelPort = ovsdbTable.createTypedRow(node, Port.class);
+ Port tunnelPort = ovsdbConfigService.createTypedRow(node, Port.class);
tunnelPort.setName(portName);
- StatusWithUuid statusWithUuid = ovsdbTable.insertRow(node, ovsdbTable.getTableName(node, Port.class), bridgeUUID, tunnelPort.getRow());
+ StatusWithUuid statusWithUuid = ovsdbConfigService.insertRow(node, ovsdbConfigService.getTableName(node, Port.class), bridgeUUID, tunnelPort.getRow());
if (!statusWithUuid.isSuccess()) {
logger.error("Failed to insert Tunnel port {} in {}", portName, bridgeUUID);
return statusWithUuid;
String interfaceUUID = null;
int timeout = 6;
while ((interfaceUUID == null) && (timeout > 0)) {
- Row row = ovsdbTable.getRow(node, ovsdbTable.getTableName(node, Port.class), tunnelPortUUID);
- tunnelPort = ovsdbTable.getTypedRow(node, Port.class, row);
+ Row row = ovsdbConfigService.getRow(node, ovsdbConfigService.getTableName(node, Port.class), tunnelPortUUID);
+ tunnelPort = ovsdbConfigService.getTypedRow(node, Port.class, row);
Set<UUID> interfaces = tunnelPort.getInterfacesColumn().getData();
if (interfaces == null || interfaces.size() == 0) {
// Wait for the OVSDB update to sync up the Local cache.
continue;
}
interfaceUUID = interfaces.toArray()[0].toString();
- Row intfRow = ovsdbTable.getRow(node, ovsdbTable.getTableName(node, Interface.class), interfaceUUID);
- Interface intf = ovsdbTable.getTypedRow(node, Interface.class, intfRow);
- if (intf == null) interfaceUUID = null;
+ Row ifaceRow = ovsdbConfigService.getRow(node, ovsdbConfigService.getTableName(node, Interface.class), interfaceUUID);
+ Interface iface = ovsdbConfigService.getTypedRow(node, Interface.class, ifaceRow);
+ if (iface == null) interfaceUUID = null;
}
if (interfaceUUID == null) {
return new Status(StatusCode.INTERNALERROR);
}
- Interface tunInterface = ovsdbTable.createTypedRow(node, Interface.class);
+ Interface tunInterface = ovsdbConfigService.createTypedRow(node, Interface.class);
tunInterface.setType(tunnelType);
- Map<String, String> options = new HashMap<String, String>();
+ Map<String, String> options = Maps.newHashMap();
options.put("key", key);
options.put("local_ip", src.getHostAddress());
options.put("remote_ip", dst.getHostAddress());
tunInterface.setOptions(options);
- Status status = ovsdbTable.updateRow(node, ovsdbTable.getTableName(node, Interface.class), tunnelPortUUID, interfaceUUID, tunInterface.getRow());
+ Status status = ovsdbConfigService.updateRow(node, ovsdbConfigService.getTableName(node, Interface.class), tunnelPortUUID, interfaceUUID, tunInterface.getRow());
logger.debug("Tunnel {} add status : {}", tunInterface, status);
return status;
} catch (Exception e) {
private Status deletePort(Node node, String bridgeName, String portName) {
try {
String bridgeUUID = null;
- OvsdbConfigService ovsdbTable = (OvsdbConfigService)ServiceHelper.getGlobalInstance(OvsdbConfigService.class, this);
- Map<String, Row> bridgeTable = ovsdbTable.getRows(node, ovsdbTable.getTableName(node, Bridge.class));
+ Map<String, Row> bridgeTable = ovsdbConfigService.getRows(node, ovsdbConfigService.getTableName(node, Bridge.class));
if (bridgeTable != null) {
for (String uuid : bridgeTable.keySet()) {
- Bridge bridge = ovsdbTable.getTypedRow(node, Bridge.class, bridgeTable.get(uuid));
+ Bridge bridge = ovsdbConfigService.getTypedRow(node, Bridge.class, bridgeTable.get(uuid));
if (bridge.getName().equals(bridgeName)) {
bridgeUUID = uuid;
break;
String portUUID = this.getPortUuid(node, portName, bridgeUUID);
Status status = new Status(StatusCode.SUCCESS);
if (portUUID != null) {
- status = ovsdbTable.deleteRow(node, ovsdbTable.getTableName(node, Port.class), portUUID);
+ status = ovsdbConfigService.deleteRow(node, ovsdbConfigService.getTableName(node, Port.class), portUUID);
if (!status.isSuccess()) {
logger.error("Failed to delete port {} in {} status : {}", portName, bridgeUUID, status);
return status;
}
private Status deleteTunnelPort (Node node, String tunnelType, InetAddress src, InetAddress dst, String key) {
- String tunnelBridgeName = adminConfigManager.getNetworkBridgeName();
+ String tunnelBridgeName = configurationService.getNetworkBridgeName();
String portName = getTunnelName(tunnelType, key, dst);
- Status status = deletePort(node, tunnelBridgeName, portName);
- return status;
+ return deletePort(node, tunnelBridgeName, portName);
}
- private Status deletePhysicalPort(Node node, String phyIntfName) {
- String netBridgeName = adminConfigManager.getNetworkBridgeName();
- Status status = deletePort(node, netBridgeName, phyIntfName);
- return status;
+ private Status deletePhysicalPort(Node node, String phyIfaceName) {
+ String netBridgeName = configurationService.getNetworkBridgeName();
+ return deletePort(node, netBridgeName, phyIfaceName);
}
@Override
public Status handleInterfaceUpdate(String tunnelType, String tunnelKey) {
- IConnectionServiceInternal connectionService = (IConnectionServiceInternal)ServiceHelper.getGlobalInstance(IConnectionServiceInternal.class, this);
List<Node> nodes = connectionService.getNodes();
for (Node srcNode : nodes) {
this.handleInterfaceUpdate(null, srcNode, null);
@Override
public void initializeFlowRules(Node node) {
- this.initializeFlowRules(node, adminConfigManager.getIntegrationBridgeName());
- this.initializeFlowRules(node, adminConfigManager.getExternalBridgeName());
+ this.initializeFlowRules(node, configurationService.getIntegrationBridgeName());
+ this.initializeFlowRules(node, configurationService.getExternalBridgeName());
}
private void initializeFlowRules(Node node, String bridgeName) {
- String brIntId = this.getInternalBridgeUUID(node, bridgeName);
- if (brIntId == null) {
- if (bridgeName == adminConfigManager.getExternalBridgeName()){
+ String bridgeUuid = bridgeConfigurationManager.getBridgeUuid(node, bridgeName);
+ if (bridgeUuid == null) {
+ if (bridgeName.equals(configurationService.getExternalBridgeName())){
logger.debug("Failed to initialize Flow Rules for bridge {} on node {}. Is the Neutron L3 agent running on this node?");
}
else {
}
try {
- OvsdbConfigService ovsdbTable = (OvsdbConfigService)ServiceHelper.getGlobalInstance(OvsdbConfigService.class, this);
- Row row = ovsdbTable.getRow(node, ovsdbTable.getTableName(node, Bridge.class), brIntId);
- Bridge bridge = ovsdbTable.getTypedRow(node, Bridge.class, row);
+ Row row = ovsdbConfigService.getRow(node, ovsdbConfigService.getTableName(node, Bridge.class), bridgeUuid);
+ Bridge bridge = ovsdbConfigService.getTypedRow(node, Bridge.class, row);
Set<String> dpids = bridge.getDatapathIdColumn().getData();
if (dpids == null || dpids.size() == 0) return;
- Long dpidLong = Long.valueOf(HexEncode.stringToLong((String)dpids.toArray()[0]));
+ Long dpidLong = HexEncode.stringToLong((String) dpids.toArray()[0]);
Node ofNode = new Node(Node.NodeIDType.OPENFLOW, dpidLong);
- ISwitchManager switchManager = (ISwitchManager) ServiceHelper.getInstance(ISwitchManager.class, "default", this);
List<Switch> nodes = switchManager.getNetworkDevices();
if (nodes == null) {
logger.debug("No OF nodes learned yet in {}", node);
flow.setNode(ofNode);
flow.setPriority(NORMAL_PRIORITY+"");
flow.setInstallInHw(true);
- List<String> normalAction = new ArrayList<String>();
+ List<String> normalAction = Lists.newArrayList();
normalAction.add(flowName);
flow.setActions(normalAction);
Status status = this.addStaticFlow(ofNode, flow);
private void initializeLLDPFlowRules(Node ofNode) {
String flowName = "PuntLLDP";
- List<String> puntAction = new ArrayList<String>();
+ List<String> puntAction = Lists.newArrayList();
puntAction.add(ActionType.CONTROLLER.toString());
FlowConfig allowLLDP = new FlowConfig();
}
private Status addStaticFlow (Node ofNode, FlowConfig flowConfig) {
- IForwardingRulesManager frm = (IForwardingRulesManager) ServiceHelper.getInstance(
- IForwardingRulesManager.class, "default", this);
String flowName = flowConfig.getName();
- if (frm.getStaticFlow(flowName, ofNode) != null) {
+ if (forwardingRulesManager.getStaticFlow(flowName, ofNode) != null) {
logger.debug("Flow already exists {} on {}. Skipping installation.", flowName, ofNode);
return new Status(StatusCode.CONFLICT, "Flow with name "+flowName+" exists in node "+ofNode.toString());
}
- return frm.addStaticFlow(flowConfig);
+ return forwardingRulesManager.addStaticFlow(flowConfig);
}
private Status deleteStaticFlow (Node ofNode, String flowName) {
- IForwardingRulesManager frm = (IForwardingRulesManager) ServiceHelper.getInstance(
- IForwardingRulesManager.class, "default", this);
- if (frm.getStaticFlow(flowName, ofNode) == null) {
+ if (forwardingRulesManager.getStaticFlow(flowName, ofNode) == null) {
logger.debug("Flow does not exist {} on {}. Skipping deletion.", flowName, ofNode);
return new Status(StatusCode.SUCCESS);
}
- return frm.removeStaticFlow(flowName,ofNode);
- }
-
- private String getInternalBridgeUUID (Node node, String bridgeName) {
- try {
- OvsdbConfigService ovsdbTable = (OvsdbConfigService)ServiceHelper.getGlobalInstance(OvsdbConfigService.class, this);
- Map<String, Row> bridgeTable = ovsdbTable.getRows(node, ovsdbTable.getTableName(node, Bridge.class));
- if (bridgeTable == null) return null;
- for (String key : bridgeTable.keySet()) {
- Bridge bridge = ovsdbTable.getTypedRow(node, Bridge.class, bridgeTable.get(key));
- if (bridge.getName().equals(bridgeName)) return key;
- }
- } catch (Exception e) {
- logger.error("Error getting Bridge Identifier for {} / {}", node, bridgeName, e);
- }
- return null;
+ return forwardingRulesManager.removeStaticFlow(flowName,ofNode);
}
}
*
* Authors : Madhu Venugopal, Brent Salisbury, Dave Tucker
*/
-package org.opendaylight.ovsdb.neutron.provider;
-
-import java.math.BigInteger;
-import java.net.InetAddress;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-import java.util.concurrent.ExecutionException;
-import java.util.concurrent.Future;
+package org.opendaylight.ovsdb.openstack.netvirt.providers;
import org.opendaylight.controller.md.sal.common.api.TransactionStatus;
import org.opendaylight.controller.md.sal.common.api.data.DataModification;
import org.opendaylight.controller.sal.binding.api.data.DataBrokerService;
import org.opendaylight.controller.sal.core.Node;
import org.opendaylight.controller.sal.utils.HexEncode;
-import org.opendaylight.controller.sal.utils.ServiceHelper;
import org.opendaylight.controller.sal.utils.Status;
import org.opendaylight.controller.sal.utils.StatusCode;
import org.opendaylight.ovsdb.lib.notation.Row;
import org.opendaylight.ovsdb.lib.notation.UUID;
-import org.opendaylight.ovsdb.neutron.IAdminConfigManager;
-import org.opendaylight.ovsdb.neutron.IInternalNetworkManager;
-import org.opendaylight.ovsdb.neutron.IMDSALConsumer;
-import org.opendaylight.ovsdb.neutron.ITenantNetworkManager;
-import org.opendaylight.ovsdb.neutron.NetworkHandler;
+import org.opendaylight.ovsdb.openstack.netvirt.api.Constants;
+import org.opendaylight.ovsdb.openstack.netvirt.NetworkHandler;
+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.TenantNetworkManager;
import org.opendaylight.ovsdb.plugin.IConnectionServiceInternal;
import org.opendaylight.ovsdb.plugin.OvsdbConfigService;
import org.opendaylight.ovsdb.plugin.StatusWithUuid;
import org.opendaylight.yangtools.yang.binding.DataObject;
import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
import org.opendaylight.yangtools.yang.common.RpcResult;
+
+import com.google.common.base.Preconditions;
+import com.google.common.collect.Lists;
+import com.google.common.collect.Maps;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import java.math.BigInteger;
+import java.net.InetAddress;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.Future;
/**
- *
+ * Open vSwitch OpenFlow 1.3 Networking Provider for OpenStack Neutron
*/
-public class OF13Provider implements NetworkProvider {
+public class OF13Provider implements NetworkingProvider {
private static final Logger logger = LoggerFactory.getLogger(OF13Provider.class);
private DataBrokerService dataBrokerService;
private static final short TABLE_0_DEFAULT_INGRESS = 0;
private static final short TABLE_2_LOCAL_FORWARD = 20;
private static Long groupId = 1L;
- private IAdminConfigManager adminConfigManager;
- private IInternalNetworkManager internalNetworkManager;
- private ITenantNetworkManager tenantNetworkManager;
+ private volatile ConfigurationService configurationService;
+ private volatile BridgeConfigurationManager bridgeConfigurationManager;
+ private volatile TenantNetworkManager tenantNetworkManager;
+ private volatile OvsdbConfigService ovsdbConfigService;
+ private volatile IConnectionServiceInternal connectionService;
+ private volatile MdsalConsumer mdsalConsumer;
+
+ public OF13Provider(){
- public OF13Provider(IAdminConfigManager adminConfigManager,
- IInternalNetworkManager internalNetworkManager,
- ITenantNetworkManager tenantNetworkManager) {
- this.adminConfigManager = adminConfigManager;
- this.internalNetworkManager = internalNetworkManager;
- this.tenantNetworkManager = tenantNetworkManager;
}
@Override
}
private Status getTunnelReadinessStatus (Node node, String tunnelKey) {
- InetAddress srcTunnelEndPoint = adminConfigManager.getTunnelEndPoint(node);
+ InetAddress srcTunnelEndPoint = configurationService.getTunnelEndPoint(node);
if (srcTunnelEndPoint == null) {
logger.error("Tunnel Endpoint not configured for Node {}", node);
return new Status(StatusCode.NOTFOUND, "Tunnel Endpoint not configured for "+ node);
}
- if (!internalNetworkManager.isInternalNetworkNeutronReady(node)) {
+ if (!bridgeConfigurationManager.isNodeNeutronReady(node)) {
logger.error(node+" is not Overlay ready");
return new Status(StatusCode.NOTACCEPTABLE, node+" is not Overlay ready");
}
}
private boolean isTunnelPresent(Node node, String tunnelName, String bridgeUUID) throws Exception {
- OvsdbConfigService ovsdbTable = (OvsdbConfigService)ServiceHelper.getGlobalInstance(OvsdbConfigService.class, this);
- Row bridgeRow = ovsdbTable.getRow(node, ovsdbTable.getTableName(node, Bridge.class), bridgeUUID);
- Bridge bridge = ovsdbTable.getTypedRow(node, Bridge.class, bridgeRow);
+ Preconditions.checkNotNull(ovsdbConfigService);
+ Row bridgeRow = ovsdbConfigService.getRow(node, ovsdbConfigService.getTableName(node, Bridge.class), bridgeUUID);
+ Bridge bridge = ovsdbConfigService.getTypedRow(node, Bridge.class, bridgeRow);
if (bridge != null) {
Set<UUID> ports = bridge.getPortsColumn().getData();
for (UUID portUUID : ports) {
- Row portRow = ovsdbTable.getRow(node, ovsdbTable.getTableName(node, Port.class), portUUID.toString());
- Port port = ovsdbTable.getTypedRow(node, Port.class, portRow);
+ Row portRow = ovsdbConfigService.getRow(node, ovsdbConfigService.getTableName(node, Port.class), portUUID.toString());
+ Port port = ovsdbConfigService.getTypedRow(node, Port.class, portRow);
if (port != null && tunnelName.equalsIgnoreCase(port.getName())) return true;
}
}
}
private String getPortUuid(Node node, String name, String bridgeUUID) throws Exception {
- OvsdbConfigService ovsdbTable = (OvsdbConfigService)ServiceHelper.getGlobalInstance(OvsdbConfigService.class, this);
- Row bridgeRow = ovsdbTable.getRow(node, ovsdbTable.getTableName(node, Bridge.class), bridgeUUID);
- Bridge bridge = ovsdbTable.getTypedRow(node, Bridge.class, bridgeRow);
+ Preconditions.checkNotNull(ovsdbConfigService);
+ Row bridgeRow = ovsdbConfigService.getRow(node, ovsdbConfigService.getTableName(node, Bridge.class), bridgeUUID);
+ Bridge bridge = ovsdbConfigService.getTypedRow(node, Bridge.class, bridgeRow);
if (bridge != null) {
Set<UUID> ports = bridge.getPortsColumn().getData();
for (UUID portUUID : ports) {
- Row portRow = ovsdbTable.getRow(node, ovsdbTable.getTableName(node, Port.class), portUUID.toString());
- Port port = ovsdbTable.getTypedRow(node, Port.class, portRow);
+ Row portRow = ovsdbConfigService.getRow(node, ovsdbConfigService.getTableName(node, Port.class), portUUID.toString());
+ Port port = ovsdbConfigService.getTypedRow(node, Port.class, portRow);
if (port != null && name.equalsIgnoreCase(port.getName())) return portUUID.toString();
}
}
}
private Status addTunnelPort (Node node, String tunnelType, InetAddress src, InetAddress dst) {
+ Preconditions.checkNotNull(ovsdbConfigService);
try {
String bridgeUUID = null;
- String tunnelBridgeName = adminConfigManager.getIntegrationBridgeName();
- OvsdbConfigService ovsdbTable = (OvsdbConfigService)ServiceHelper.getGlobalInstance(OvsdbConfigService.class, this);
- Map<String, Row> bridgeTable = ovsdbTable.getRows(node, ovsdbTable.getTableName(node, Bridge.class));
+ String tunnelBridgeName = configurationService.getIntegrationBridgeName();
+ Map<String, Row> bridgeTable = ovsdbConfigService.getRows(node, ovsdbConfigService.getTableName(node, Bridge.class));
if (bridgeTable != null) {
for (String uuid : bridgeTable.keySet()) {
- Bridge bridge = ovsdbTable.getTypedRow(node,Bridge.class, bridgeTable.get(uuid));
+ Bridge bridge = ovsdbConfigService.getTypedRow(node,Bridge.class, bridgeTable.get(uuid));
if (bridge.getName().equals(tunnelBridgeName)) {
bridgeUUID = uuid;
break;
return new Status(StatusCode.SUCCESS);
}
- Port tunnelPort = ovsdbTable.createTypedRow(node, Port.class);
+ Port tunnelPort = ovsdbConfigService.createTypedRow(node, Port.class);
tunnelPort.setName(portName);
- StatusWithUuid statusWithUuid = ovsdbTable.insertRow(node, ovsdbTable.getTableName(node, Port.class), bridgeUUID, tunnelPort.getRow());
+ StatusWithUuid statusWithUuid = ovsdbConfigService.insertRow(node, ovsdbConfigService.getTableName(node, Port.class), bridgeUUID, tunnelPort.getRow());
if (!statusWithUuid.isSuccess()) {
logger.error("Failed to insert Tunnel port {} in {}", portName, bridgeUUID);
return statusWithUuid;
String interfaceUUID = null;
int timeout = 6;
while ((interfaceUUID == null) && (timeout > 0)) {
- Row portRow = ovsdbTable.getRow(node, ovsdbTable.getTableName(node, Port.class), tunnelPortUUID);
- tunnelPort = ovsdbTable.getTypedRow(node, Port.class, portRow);
+ Row portRow = ovsdbConfigService.getRow(node, ovsdbConfigService.getTableName(node, Port.class), tunnelPortUUID);
+ tunnelPort = ovsdbConfigService.getTypedRow(node, Port.class, portRow);
Set<UUID> interfaces = tunnelPort.getInterfacesColumn().getData();
if (interfaces == null || interfaces.size() == 0) {
// Wait for the OVSDB update to sync up the Local cache.
continue;
}
interfaceUUID = interfaces.toArray()[0].toString();
- Row intfRow = ovsdbTable.getRow(node, ovsdbTable.getTableName(node, Interface.class), interfaceUUID);
- Interface intf = ovsdbTable.getTypedRow(node, Interface.class, intfRow);
+ Row intfRow = ovsdbConfigService.getRow(node, ovsdbConfigService.getTableName(node, Interface.class), interfaceUUID);
+ Interface intf = ovsdbConfigService.getTypedRow(node, Interface.class, intfRow);
if (intf == null) interfaceUUID = null;
}
return new Status(StatusCode.INTERNALERROR);
}
- Interface tunInterface = ovsdbTable.createTypedRow(node, Interface.class);
+ Interface tunInterface = ovsdbConfigService.createTypedRow(node, Interface.class);
tunInterface.setType(tunnelType);
- Map<String, String> options = new HashMap<String, String>();
+ Map<String, String> options = Maps.newHashMap();
options.put("key", "flow");
options.put("local_ip", src.getHostAddress());
options.put("remote_ip", dst.getHostAddress());
tunInterface.setOptions(options);
- Status status = ovsdbTable.updateRow(node, ovsdbTable.getTableName(node, Interface.class), tunnelPortUUID, interfaceUUID, tunInterface.getRow());
+ Status status = ovsdbConfigService.updateRow(node, ovsdbConfigService.getTableName(node, Interface.class), tunnelPortUUID, interfaceUUID, tunInterface.getRow());
logger.debug("Tunnel {} add status : {}", tunInterface, status);
return status;
} catch (Exception e) {
/* delete port from ovsdb port table */
private Status deletePort(Node node, String bridgeName, String portName) {
+ Preconditions.checkNotNull(ovsdbConfigService);
try {
String bridgeUUID = null;
- OvsdbConfigService ovsdbTable = (OvsdbConfigService)ServiceHelper.getGlobalInstance(OvsdbConfigService.class, this);
- Map<String, Row> bridgeTable = ovsdbTable.getRows(node, ovsdbTable.getTableName(node, Bridge.class));
+ Map<String, Row> bridgeTable = ovsdbConfigService.getRows(node, ovsdbConfigService.getTableName(node, Bridge.class));
if (bridgeTable != null) {
for (String uuid : bridgeTable.keySet()) {
- Bridge bridge = ovsdbTable.getTypedRow(node, Bridge.class, bridgeTable.get(uuid));
+ Bridge bridge = ovsdbConfigService.getTypedRow(node, Bridge.class, bridgeTable.get(uuid));
if (bridge.getName().equals(bridgeName)) {
bridgeUUID = uuid;
break;
String portUUID = this.getPortUuid(node, portName, bridgeUUID);
Status status = new Status(StatusCode.SUCCESS);
if (portUUID != null) {
- status = ovsdbTable.deleteRow(node, ovsdbTable.getTableName(node, Port.class), portUUID);
+ status = ovsdbConfigService.deleteRow(node, ovsdbConfigService.getTableName(node, Port.class), portUUID);
if (!status.isSuccess()) {
logger.error("Failed to delete port {} in {} status : {}", portName, bridgeUUID,
status);
}
private Status deleteTunnelPort(Node node, String tunnelType, InetAddress src, InetAddress dst) {
- String tunnelBridgeName = adminConfigManager.getIntegrationBridgeName();
+ String tunnelBridgeName = configurationService.getIntegrationBridgeName();
String portName = getTunnelName(tunnelType, dst);
- Status status = deletePort(node, tunnelBridgeName, portName);
- return status;
+ return deletePort(node, tunnelBridgeName, portName);
}
private Status deletePhysicalPort(Node node, String phyIntfName) {
- String intBridgeName = adminConfigManager.getIntegrationBridgeName();
- Status status = deletePort(node, intBridgeName, phyIntfName);
- return status;
+ String intBridgeName = configurationService.getIntegrationBridgeName();
+ return deletePort(node, intBridgeName, phyIntfName);
}
private void programLocalBridgeRules(Node node, Long dpid, String segmentationId, String attachedMac, long localPort) {
segmentationId, ethPort, false);
}
private Long getDpid (Node node, String bridgeUuid) {
+ Preconditions.checkNotNull(ovsdbConfigService);
try {
- OvsdbConfigService ovsdbTable = (OvsdbConfigService) ServiceHelper.getGlobalInstance(OvsdbConfigService.class, this);
- Row bridgeRow = ovsdbTable.getRow(node, ovsdbTable.getTableName(node, Bridge.class), bridgeUuid);
- Bridge bridge = ovsdbTable.getTypedRow(node, Bridge.class, bridgeRow);
+ Row bridgeRow = ovsdbConfigService.getRow(node, ovsdbConfigService.getTableName(node, Bridge.class), bridgeUuid);
+ Bridge bridge = ovsdbConfigService.getTypedRow(node, Bridge.class, bridgeRow);
Set<String> dpids = bridge.getDatapathIdColumn().getData();
if (dpids == null || dpids.size() == 0) return 0L;
- return Long.valueOf(HexEncode.stringToLong((String) dpids.toArray()[0]));
+ return HexEncode.stringToLong((String) dpids.toArray()[0]);
} catch (Exception e) {
logger.error("Error finding Bridge's OF DPID", e);
return 0L;
private Long getIntegrationBridgeOFDPID (Node node) {
try {
- String bridgeName = adminConfigManager.getIntegrationBridgeName();
+ String bridgeName = configurationService.getIntegrationBridgeName();
String brIntId = this.getInternalBridgeUUID(node, bridgeName);
if (brIntId == null) {
logger.error("Unable to spot Bridge Identifier for {} in {}", bridgeName, node);
private Long getExternalBridgeDpid (Node node) {
try {
- String bridgeName = adminConfigManager.getExternalBridgeName();
+ String bridgeName = configurationService.getExternalBridgeName();
String brUuid = this.getInternalBridgeUUID(node, bridgeName);
if (brUuid == null) {
logger.error("Unable to spot Bridge Identifier for {} in {}", bridgeName, node);
return;
}
- String attachedMac = externalIds.get(ITenantNetworkManager.EXTERNAL_ID_VM_MAC);
+ String attachedMac = externalIds.get(Constants.EXTERNAL_ID_VM_MAC);
if (attachedMac == null) {
logger.error("No AttachedMac seen in {}", intf);
return;
return;
}
- String attachedMac = externalIds.get(ITenantNetworkManager.EXTERNAL_ID_VM_MAC);
+ String attachedMac = externalIds.get(Constants.EXTERNAL_ID_VM_MAC);
if (attachedMac == null) {
logger.error("No AttachedMac seen in {}", intf);
return;
private void programTunnelRules (String tunnelType, String segmentationId, InetAddress dst, Node node,
Interface intf, boolean local) {
+
+ Preconditions.checkNotNull(ovsdbConfigService);
+
try {
Long dpid = this.getIntegrationBridgeOFDPID(node);
logger.debug("Openflow Datapath-ID not set for the integration bridge in {}", node);
return;
}
- OvsdbConfigService ovsdbTable = (OvsdbConfigService) ServiceHelper.getGlobalInstance(OvsdbConfigService.class, this);
Set<Long> of_ports = intf.getOpenFlowPortColumn().getData();
if (of_ports == null || of_ports.size() <= 0) {
return;
}
- String attachedMac = externalIds.get(ITenantNetworkManager.EXTERNAL_ID_VM_MAC);
+ String attachedMac = externalIds.get(Constants.EXTERNAL_ID_VM_MAC);
if (attachedMac == null) {
logger.error("No AttachedMac seen in {}", intf);
return;
}
- Map<String, Row> intfs = ovsdbTable.getRows(node, ovsdbTable.getTableName(node, Interface.class));
+ Map<String, Row> intfs = ovsdbConfigService.getRows(node, ovsdbConfigService.getTableName(node, Interface.class));
if (intfs != null) {
for (Row row : intfs.values()) {
- Interface tunIntf = ovsdbTable.getTypedRow(node, Interface.class, row);
+ Interface tunIntf = ovsdbConfigService.getTypedRow(node, Interface.class, row);
if (tunIntf.getName().equals(this.getTunnelName(tunnelType, dst))) {
of_ports = tunIntf.getOpenFlowPortColumn().getData();
if (of_ports == null || of_ports.size() <= 0) {
private void removeTunnelRules (String tunnelType, String segmentationId, InetAddress dst, Node node,
Interface intf, boolean local, boolean isLastInstanceOnNode) {
+
+ Preconditions.checkNotNull(ovsdbConfigService);
try {
Long dpid = this.getIntegrationBridgeOFDPID(node);
logger.debug("Openflow Datapath-ID not set for the integration bridge in {}", node);
return;
}
- OvsdbConfigService ovsdbTable = (OvsdbConfigService) ServiceHelper.getGlobalInstance(OvsdbConfigService.class, this);
Set<Long> of_ports = intf.getOpenFlowPortColumn().getData();
if (of_ports == null || of_ports.size() <= 0) {
return;
}
- String attachedMac = externalIds.get(ITenantNetworkManager.EXTERNAL_ID_VM_MAC);
+ String attachedMac = externalIds.get(Constants.EXTERNAL_ID_VM_MAC);
if (attachedMac == null) {
logger.error("No AttachedMac seen in {}", intf);
return;
}
- Map<String, Row> intfs = ovsdbTable.getRows(node, ovsdbTable.getTableName(node, Interface.class));
+ Map<String, Row> intfs = ovsdbConfigService.getRows(node, ovsdbConfigService.getTableName(node, Interface.class));
if (intfs != null) {
for (Row row : intfs.values()) {
- Interface tunIntf = ovsdbTable.getTypedRow(node, Interface.class, row);
+ Interface tunIntf = ovsdbConfigService.getTypedRow(node, Interface.class, row);
if (tunIntf.getName().equals(this.getTunnelName(tunnelType, dst))) {
of_ports = tunIntf.getOpenFlowPortColumn().getData();
if (of_ports == null || of_ports.size() <= 0) {
}
private void programVlanRules (NeutronNetwork network, Node node, Interface intf) {
+ Preconditions.checkNotNull(ovsdbConfigService);
logger.debug("Program vlan rules for interface {}", intf.getName());
-
try {
Long dpid = this.getIntegrationBridgeOFDPID(node);
logger.debug("Openflow Datapath-ID not set for the integration bridge in {}", node);
return;
}
- OvsdbConfigService ovsdbTable = (OvsdbConfigService) ServiceHelper.getGlobalInstance(OvsdbConfigService.class, this);
Set<Long> of_ports = intf.getOpenFlowPortColumn().getData();
int timeout = 6;
// Wait for the OVSDB update to sync up the Local cache.
Thread.sleep(500);
timeout--;
- continue;
}
}
if (of_ports == null || of_ports.size() <= 0) {
return;
}
- String attachedMac = externalIds.get(tenantNetworkManager.EXTERNAL_ID_VM_MAC);
+ String attachedMac = externalIds.get(Constants.EXTERNAL_ID_VM_MAC);
if (attachedMac == null) {
logger.error("No AttachedMac seen in {}", intf);
return;
}
- Map<String, Row> intfs = ovsdbTable.getRows(node, ovsdbTable.getTableName(node, Interface.class));
+ Map<String, Row> intfs = ovsdbConfigService.getRows(node, ovsdbConfigService.getTableName(node, Interface.class));
if (intfs != null) {
for (Row row : intfs.values()) {
- Interface ethIntf = ovsdbTable.getTypedRow(node, Interface.class, row);
- if (ethIntf.getName().equalsIgnoreCase(adminConfigManager.getPhysicalInterfaceName(node, network.getProviderPhysicalNetwork()))) {
+ Interface ethIntf = ovsdbConfigService.getTypedRow(node, Interface.class, row);
+ if (ethIntf.getName().equalsIgnoreCase(bridgeConfigurationManager.getPhysicalInterfaceName(node, network.getProviderPhysicalNetwork()))) {
of_ports = ethIntf.getOpenFlowPortColumn().getData();
timeout = 6;
while ((of_ports == null) && (timeout > 0)) {
// Wait for the OVSDB update to sync up the Local cache.
Thread.sleep(500);
timeout--;
- continue;
}
}
private void removeVlanRules (NeutronNetwork network, Node node,
Interface intf, boolean isLastInstanceOnNode) {
+ Preconditions.checkNotNull(ovsdbConfigService);
logger.debug("Remove vlan rules for interface {}", intf.getName());
try {
logger.debug("Openflow Datapath-ID not set for the integration bridge in {}", node);
return;
}
- OvsdbConfigService ovsdbTable = (OvsdbConfigService) ServiceHelper.getGlobalInstance(OvsdbConfigService.class, this);
Set<Long> of_ports = intf.getOpenFlowPortColumn().getData();
if (of_ports == null || of_ports.size() <= 0) {
return;
}
- String attachedMac = externalIds.get(tenantNetworkManager.EXTERNAL_ID_VM_MAC);
+ String attachedMac = externalIds.get(Constants.EXTERNAL_ID_VM_MAC);
if (attachedMac == null) {
logger.error("No AttachedMac seen in {}", intf);
return;
}
- Map<String, Row> intfs = ovsdbTable.getRows(node, ovsdbTable.getTableName(node, Interface.class));
+ Map<String, Row> intfs = ovsdbConfigService.getRows(node, ovsdbConfigService.getTableName(node, Interface.class));
if (intfs != null) {
for (Row row : intfs.values()) {
- Interface ethIntf = ovsdbTable.getTypedRow(node, Interface.class, row);
- if (ethIntf.getName().equalsIgnoreCase(adminConfigManager.getPhysicalInterfaceName(node,
+ Interface ethIntf = ovsdbConfigService.getTypedRow(node, Interface.class, row);
+ if (ethIntf.getName().equalsIgnoreCase(bridgeConfigurationManager.getPhysicalInterfaceName(node,
network.getProviderPhysicalNetwork()))) {
of_ports = ethIntf.getOpenFlowPortColumn().getData();
if (of_ports == null || of_ports.size() <= 0) {
@Override
public Status handleInterfaceUpdate(NeutronNetwork network, Node srcNode, Interface intf) {
- IConnectionServiceInternal connectionService = (IConnectionServiceInternal)ServiceHelper.getGlobalInstance(IConnectionServiceInternal.class, this);
+ Preconditions.checkNotNull(connectionService);
List<Node> nodes = connectionService.getNodes();
nodes.remove(srcNode);
this.programLocalRules(network.getProviderNetworkType(), network.getProviderSegmentationID(), srcNode, intf);
} else if (network.getProviderNetworkType().equalsIgnoreCase(NetworkHandler.NETWORK_TYPE_GRE)
|| network.getProviderNetworkType().equalsIgnoreCase(NetworkHandler.NETWORK_TYPE_VXLAN)){
for (Node dstNode : nodes) {
- InetAddress src = adminConfigManager.getTunnelEndPoint(srcNode);
- InetAddress dst = adminConfigManager.getTunnelEndPoint(dstNode);
+ InetAddress src = configurationService.getTunnelEndPoint(srcNode);
+ InetAddress dst = configurationService.getTunnelEndPoint(dstNode);
Status status = addTunnelPort(srcNode, network.getProviderNetworkType(), src, dst);
if (status.isSuccess()) {
this.programTunnelRules(network.getProviderNetworkType(), network.getProviderSegmentationID(), dst, srcNode, intf, true);
}
private Status triggerInterfaceUpdates(Node node) {
+ Preconditions.checkNotNull(ovsdbConfigService);
try {
- OvsdbConfigService ovsdbTable = (OvsdbConfigService)ServiceHelper.getGlobalInstance(OvsdbConfigService.class, this);
- Map<String, Row> intfs = ovsdbTable.getRows(node, ovsdbTable.getTableName(node, Interface.class));
+ Map<String, Row> intfs = ovsdbConfigService.getRows(node, ovsdbConfigService.getTableName(node, Interface.class));
if (intfs != null) {
for (Row row : intfs.values()) {
- Interface intf = ovsdbTable.getTypedRow(node, Interface.class, row);
- NeutronNetwork network = tenantNetworkManager.getTenantNetworkForInterface(intf);
+ Interface intf = ovsdbConfigService.getTypedRow(node, Interface.class, row);
+ NeutronNetwork network = tenantNetworkManager.getTenantNetwork(intf);
logger.debug("Trigger Interface update for {}", intf);
if (network != null) {
this.handleInterfaceUpdate(network, node, intf);
@Override
public Status handleInterfaceDelete(String tunnelType, NeutronNetwork network, Node srcNode, Interface intf,
boolean isLastInstanceOnNode) {
+ Preconditions.checkNotNull(connectionService);
Status status = new Status(StatusCode.SUCCESS);
- IConnectionServiceInternal connectionService = (IConnectionServiceInternal)ServiceHelper.getGlobalInstance(IConnectionServiceInternal.class, this);
List<Node> nodes = connectionService.getNodes();
nodes.remove(srcNode);
logger.info("Delete intf " + intf.getName() + " isLastInstanceOnNode " + isLastInstanceOnNode);
- List<String> phyIfName = adminConfigManager.getAllPhysicalInterfaceNames(srcNode);
+ List<String> phyIfName = bridgeConfigurationManager.getAllPhysicalInterfaceNames(srcNode);
if (intf.getTypeColumn().getData().equalsIgnoreCase(NetworkHandler.NETWORK_TYPE_VXLAN)
|| intf.getTypeColumn().getData().equalsIgnoreCase(NetworkHandler.NETWORK_TYPE_GRE)) {
/* Delete tunnel port */
|| network.getProviderNetworkType().equalsIgnoreCase(NetworkHandler.NETWORK_TYPE_VXLAN)) {
for (Node dstNode : nodes) {
- InetAddress src = adminConfigManager.getTunnelEndPoint(srcNode);
- InetAddress dst = adminConfigManager.getTunnelEndPoint(dstNode);
+ InetAddress src = configurationService.getTunnelEndPoint(srcNode);
+ InetAddress dst = configurationService.getTunnelEndPoint(dstNode);
logger.info("Remove tunnel rules for interface " + intf.getName() + " on srcNode" + srcNode.getNodeIDString());
this.removeTunnelRules(tunnelType, network.getProviderSegmentationID(),
dst, srcNode, intf, true, isLastInstanceOnNode);
@Override
public void initializeFlowRules(Node node) {
- this.initializeFlowRules(node, adminConfigManager.getIntegrationBridgeName());
- this.initializeFlowRules(node, adminConfigManager.getExternalBridgeName());
+ this.initializeFlowRules(node, configurationService.getIntegrationBridgeName());
+ this.initializeFlowRules(node, configurationService.getExternalBridgeName());
this.triggerInterfaceUpdates(node);
}
- /**
- * @param node
- * @param bridgeName
- */
private void initializeFlowRules(Node node, String bridgeName) {
String bridgeUuid = this.getInternalBridgeUUID(node, bridgeName);
if (bridgeUuid == null) {
*/
writeLLDPRule(dpid);
- if (bridgeName == adminConfigManager.getExternalBridgeName()) {
+ if (bridgeName.equals(configurationService.getExternalBridgeName())) {
writeNormalRule(dpid);
}
}
InstructionsBuilder isb = new InstructionsBuilder();
// Instructions List Stores Individual Instructions
- List<Instruction> instructions = new ArrayList<Instruction>();
+ List<Instruction> instructions = Lists.newArrayList();
// Call the InstructionBuilder Methods Containing Actions
createSendToControllerInstructions(ib);
InstructionsBuilder isb = new InstructionsBuilder();
// Instructions List Stores Individual Instructions
- List<Instruction> instructions = new ArrayList<Instruction>();
+ List<Instruction> instructions = Lists.newArrayList();
// Call the InstructionBuilder Methods Containing Actions
createNormalInstructions(ib);
InstructionsBuilder isb = new InstructionsBuilder();
// Instructions List Stores Individual Instructions
- List<Instruction> instructions = new ArrayList<Instruction>();
+ List<Instruction> instructions = Lists.newArrayList();
// Call the InstructionBuilder Methods Containing Actions
createGotoTableInstructions(ib, goToTableId);
InstructionsBuilder isb = new InstructionsBuilder();
// Instructions List Stores Individual Instructions
- List<Instruction> instructions = new ArrayList<Instruction>();
+ List<Instruction> instructions = Lists.newArrayList();
// Call the InstructionBuilder Methods Containing Actions
createGotoTableInstructions(ib, goToTableId);
InstructionsBuilder isb = new InstructionsBuilder();
// Instructions List Stores Individual Instructions
- List<Instruction> instructions = new ArrayList<Instruction>();
+ List<Instruction> instructions = Lists.newArrayList();
// GOTO Instuctions Need to be added first to the List
createGotoTableInstructions(ib, goToTableId);
InstructionsBuilder isb = new InstructionsBuilder();
// Instructions List Stores Individual Instructions
- List<Instruction> instructions = new ArrayList<Instruction>();
+ List<Instruction> instructions = Lists.newArrayList();
// GOTO Instructions Need to be added first to the List
createGotoTableInstructions(ib, goToTableId);
InstructionsBuilder isb = new InstructionsBuilder();
// Instructions List Stores Individual Instructions
- List<Instruction> instructions = new ArrayList<Instruction>();
+ List<Instruction> instructions = Lists.newArrayList();
// Call the InstructionBuilder Methods Containing Actions
createDropInstructions(ib);
InstructionsBuilder isb = new InstructionsBuilder();
// Instructions List Stores Individual Instructions
- List<Instruction> instructions = new ArrayList<Instruction>();
+ List<Instruction> instructions = Lists.newArrayList();
// GOTO Instuctions
createGotoTableInstructions(ib, goToTableId);
InstructionsBuilder isb = new InstructionsBuilder();
// Instructions List Stores Individual Instructions
- List<Instruction> instructions = new ArrayList<Instruction>();
+ List<Instruction> instructions = Lists.newArrayList();
// GOTO Instuctions
createGotoTableInstructions(ib, goToTableId);
// Instantiate the Builders for the OF Actions and Instructions
InstructionBuilder ib = new InstructionBuilder();
InstructionsBuilder isb = new InstructionsBuilder();
- List<Instruction> instructions = new ArrayList<Instruction>();
+ List<Instruction> instructions = Lists.newArrayList();
List<Instruction> existingInstructions = null;
if (flow != null) {
Instructions ins = flow.getInstructions();
flowBuilder.setHardTimeout(0);
flowBuilder.setIdleTimeout(0);
+ //ToDo: Is there something to be done with result of the call to getFlow?
+
Flow flow = this.getFlow(flowBuilder, nodeBuilder);
// Instantiate the Builders for the OF Actions and Instructions
InstructionBuilder ib = new InstructionBuilder();
InstructionsBuilder isb = new InstructionsBuilder();
- List<Instruction> instructions = new ArrayList<Instruction>();
+ List<Instruction> instructions = Lists.newArrayList();
if (write) {
// GOTO Instuction
InstructionsBuilder isb = new InstructionsBuilder();
// Instructions List Stores Individual Instructions
- List<Instruction> instructions = new ArrayList<Instruction>();
+ List<Instruction> instructions = Lists.newArrayList();
// Call the InstructionBuilder Methods Containing Actions
createGotoTableInstructions(ib, goToTableId);
InstructionsBuilder isb = new InstructionsBuilder();
// Instructions List Stores Individual Instructions
- List<Instruction> instructions = new ArrayList<Instruction>();
+ List<Instruction> instructions = Lists.newArrayList();
// Call the InstructionBuilder Methods Containing Actions
//createGotoTableInstructions(ib, goToTableId);
InstructionsBuilder isb = new InstructionsBuilder();
// Instructions List Stores Individual Instructions
- List<Instruction> instructions = new ArrayList<Instruction>();
+ List<Instruction> instructions = Lists.newArrayList();
// Set the Output Port/Iface
createOutputPortInstructions(ib, dpidLong, localPort);
InstructionsBuilder isb = new InstructionsBuilder();
// Instructions List Stores Individual Instructions
- List<Instruction> instructions = new ArrayList<Instruction>();
- List<Instruction> instructions_tmp = new ArrayList<Instruction>();
+ List<Instruction> instructions = Lists.newArrayList();
+ List<Instruction> instructions_tmp = Lists.newArrayList();
/* Strip vlan and store to tmp instruction space*/
createPopVlanInstructions(ib);
// Instantiate the Builders for the OF Actions and Instructions
InstructionBuilder ib = new InstructionBuilder();
InstructionsBuilder isb = new InstructionsBuilder();
- List<Instruction> instructions = new ArrayList<Instruction>();
+ List<Instruction> instructions = Lists.newArrayList();
List<Instruction> existingInstructions = null;
if (flow != null) {
Instructions ins = flow.getInstructions();
// Instantiate the Builders for the OF Actions and Instructions
InstructionBuilder ib = new InstructionBuilder();
InstructionsBuilder isb = new InstructionsBuilder();
- List<Instruction> instructions = new ArrayList<Instruction>();
+ List<Instruction> instructions = Lists.newArrayList();
List<Instruction> existingInstructions = null;
boolean add_pop_vlan = true;
if (flow != null) {
if (write) {
if (existingInstructions != null) {
/* Check if pop vlan is already the first action in action list */
- List<Action> existingActions = null;
+ List<Action> existingActions;
for (Instruction in : existingInstructions) {
if (in.getInstruction() instanceof ApplyActionsCase) {
existingActions = (((ApplyActionsCase)
}
}
} else {
- existingInstructions = new ArrayList<Instruction>();
+ existingInstructions = Lists.newArrayList();
}
if (add_pop_vlan) {
InstructionsBuilder isb = new InstructionsBuilder();
// Instructions List Stores Individual Instructions
- List<Instruction> instructions = new ArrayList<Instruction>();
+ List<Instruction> instructions = Lists.newArrayList();
// Call the InstructionBuilder Methods Containing Actions
createDropInstructions(ib);
InstructionsBuilder isb = new InstructionsBuilder();
// Instructions List Stores Individual Instructions
- List<Instruction> instructions = new ArrayList<Instruction>();
+ List<Instruction> instructions = Lists.newArrayList();
// Call the InstructionBuilder Methods Containing Actions
createDropInstructions(ib);
}
private Group getGroup(GroupBuilder groupBuilder, NodeBuilder nodeBuilder) {
- IMDSALConsumer mdsalConsumer = (IMDSALConsumer) ServiceHelper.getInstance(IMDSALConsumer.class, "default", this);
+ Preconditions.checkNotNull(mdsalConsumer);
if (mdsalConsumer == null) {
logger.error("ERROR finding MDSAL Service. Its possible that writeFlow is called too soon ?");
return null;
}
private Group writeGroup(GroupBuilder groupBuilder, NodeBuilder nodeBuilder) {
- IMDSALConsumer mdsalConsumer = (IMDSALConsumer) ServiceHelper.getInstance(IMDSALConsumer.class, "default", this);
+ Preconditions.checkNotNull(mdsalConsumer);
if (mdsalConsumer == null) {
logger.error("ERROR finding MDSAL Service. Its possible that writeFlow is called too soon ?");
return null;
RpcResult<TransactionStatus> result = commitFuture.get();
TransactionStatus status = result.getResult();
logger.debug("Transaction Status "+status.toString()+" for Group "+groupBuilder.getGroupName());
- } catch (InterruptedException e) {
- logger.error(e.getMessage(), e);
- } catch (ExecutionException e) {
+ } catch (InterruptedException|ExecutionException e) {
logger.error(e.getMessage(), e);
}
return (Group)dataBrokerService.readConfigurationData(path1);
}
private Group removeGroup(GroupBuilder groupBuilder, NodeBuilder nodeBuilder) {
- IMDSALConsumer mdsalConsumer = (IMDSALConsumer) ServiceHelper.getInstance(IMDSALConsumer.class, "default", this);
+ Preconditions.checkNotNull(mdsalConsumer);
if (mdsalConsumer == null) {
logger.error("ERROR finding MDSAL Service. Its possible that writeFlow is called too soon ?");
return null;
RpcResult<TransactionStatus> result = commitFuture.get();
TransactionStatus status = result.getResult();
logger.debug("Transaction Status "+status.toString()+" for Group "+groupBuilder.getGroupName());
- } catch (InterruptedException e) {
- logger.error(e.getMessage(), e);
- } catch (ExecutionException e) {
+ } catch (InterruptedException|ExecutionException e) {
logger.error(e.getMessage(), e);
}
return (Group)dataBrokerService.readConfigurationData(path1);
}
private Flow getFlow(FlowBuilder flowBuilder, NodeBuilder nodeBuilder) {
- IMDSALConsumer mdsalConsumer = (IMDSALConsumer) ServiceHelper.getInstance(IMDSALConsumer.class, "default", this);
+ Preconditions.checkNotNull(mdsalConsumer);
if (mdsalConsumer == null) {
logger.error("ERROR finding MDSAL Service. Its possible that writeFlow is called too soon ?");
return null;
}
private void writeFlow(FlowBuilder flowBuilder, NodeBuilder nodeBuilder) {
- IMDSALConsumer mdsalConsumer = (IMDSALConsumer) ServiceHelper.getInstance(IMDSALConsumer.class, "default", this);
+ Preconditions.checkNotNull(mdsalConsumer);
if (mdsalConsumer == null) {
logger.error("ERROR finding MDSAL Service. Its possible that writeFlow is called too soon ?");
return;
return;
}
DataModification<InstanceIdentifier<?>, DataObject> modification = dataBrokerService.beginTransaction();
- InstanceIdentifier<Flow> path1 = InstanceIdentifier.builder(Nodes.class).child(org.opendaylight.yang.gen.v1.urn.opendaylight.inventory
- .rev130819.nodes.Node.class, nodeBuilder.getKey()).augmentation(FlowCapableNode.class).child(Table.class,
+ InstanceIdentifier<Flow> path1 = InstanceIdentifier.builder(Nodes.class).child(
+ org.opendaylight.yang.gen.v1.urn.opendaylight.inventory
+ .rev130819.nodes.Node.class, nodeBuilder.getKey()).augmentation(FlowCapableNode.class).child(Table.class,
new TableKey(flowBuilder.getTableId())).child(Flow.class, flowBuilder.getKey()).build();
//modification.putOperationalData(nodeBuilderToInstanceId(nodeBuilder), nodeBuilder.build());
//modification.putOperationalData(path1, flowBuilder.build());
RpcResult<TransactionStatus> result = commitFuture.get();
TransactionStatus status = result.getResult();
logger.debug("Transaction Status "+status.toString()+" for Flow "+flowBuilder.getFlowName());
- } catch (InterruptedException e) {
- logger.error(e.getMessage(), e);
- } catch (ExecutionException e) {
+ } catch (InterruptedException|ExecutionException e) {
logger.error(e.getMessage(), e);
}
}
private void removeFlow(FlowBuilder flowBuilder, NodeBuilder nodeBuilder) {
- IMDSALConsumer mdsalConsumer = (IMDSALConsumer) ServiceHelper.getInstance(IMDSALConsumer.class, "default", this);
+ Preconditions.checkNotNull(mdsalConsumer);
if (mdsalConsumer == null) {
logger.error("ERROR finding MDSAL Service.");
return;
RpcResult<TransactionStatus> result = commitFuture.get();
TransactionStatus status = result.getResult();
logger.debug("Transaction Status "+status.toString()+" for Flow "+flowBuilder.getFlowName());
- } catch (InterruptedException e) {
- logger.error(e.getMessage(), e);
- } catch (ExecutionException e) {
+ } catch (InterruptedException|ExecutionException e) {
logger.error(e.getMessage(), e);
}
}
protected static InstructionBuilder createSendToControllerInstructions(InstructionBuilder ib) {
- List<Action> actionList = new ArrayList<Action>();
+ List<Action> actionList = Lists.newArrayList();
ActionBuilder ab = new ActionBuilder();
OutputActionBuilder output = new OutputActionBuilder();
protected static InstructionBuilder createNormalInstructions(InstructionBuilder ib) {
- List<Action> actionList = new ArrayList<Action>();
+ List<Action> actionList = Lists.newArrayList();
ActionBuilder ab = new ActionBuilder();
OutputActionBuilder output = new OutputActionBuilder();
NodeConnectorId ncid = new NodeConnectorId("openflow:" + dpidLong + ":" + port);
logger.debug("createOutputPortInstructions() Node Connector ID is - Type=openflow: DPID={} inPort={} ", dpidLong, port);
- List<Action> actionList = new ArrayList<Action>();
+ List<Action> actionList = Lists.newArrayList();
ActionBuilder ab = new ActionBuilder();
OutputActionBuilder oab = new OutputActionBuilder();
oab.setOutputNodeConnector(ncid);
NodeConnectorId ncid = new NodeConnectorId("openflow:" + dpidLong + ":" + port);
logger.debug("createOutputPortInstructions() Node Connector ID is - Type=openflow: DPID={} port={} existingInstructions={}", dpidLong, port, instructions);
- List<Action> actionList = new ArrayList<Action>();
+ List<Action> actionList = Lists.newArrayList();
ActionBuilder ab = new ActionBuilder();
- List<Action> existingActions = null;
+ List<Action> existingActions;
if (instructions != null) {
for (Instruction in : instructions) {
if (in.getInstruction() instanceof ApplyActionsCase) {
NodeConnectorId ncid = new NodeConnectorId("openflow:" + dpidLong + ":" + port);
logger.debug("createOutputGroupInstructions() Node Connector ID is - Type=openflow: DPID={} port={} existingInstructions={}", dpidLong, port, instructions);
- List<Action> actionList = new ArrayList<Action>();
+ List<Action> actionList = Lists.newArrayList();
ActionBuilder ab = new ActionBuilder();
- List<Action> existingActions = null;
+ List<Action> existingActions;
if (instructions != null) {
for (Instruction in : instructions) {
if (in.getInstruction() instanceof ApplyActionsCase) {
/* the new output action is not in the bucket, add to bucket */
if (!buckets.getBucket().isEmpty()) {
Bucket bucket = buckets.getBucket().get(0);
- List<Action> bucketActionList = new ArrayList<Action>();
+ List<Action> bucketActionList = Lists.newArrayList();
bucketActionList.addAll(bucket.getAction());
/* set order for new action and add to action list */
ab.setOrder(bucketActionList.size());
/* set bucket and buckets list. Reset groupBuilder with new buckets.*/
BucketsBuilder bucketsBuilder = new BucketsBuilder();
- List<Bucket> bucketList = new ArrayList<Bucket>();
+ List<Bucket> bucketList = Lists.newArrayList();
BucketBuilder bucketBuilder = new BucketBuilder();
bucketBuilder.setBucketId(new BucketId((long) 1));
bucketBuilder.setKey(new BucketKey(new BucketId((long) 1)));
groupBuilder.setBarrier(false);
BucketsBuilder bucketBuilder = new BucketsBuilder();
- List<Bucket> bucketList = new ArrayList<Bucket>();
+ List<Bucket> bucketList = Lists.newArrayList();
BucketBuilder bucket = new BucketBuilder();
bucket.setBucketId(new BucketId((long) 1));
bucket.setKey(new BucketKey(new BucketId((long) 1)));
/* put output action to the bucket */
- List<Action> bucketActionList = new ArrayList<Action>();
+ List<Action> bucketActionList = Lists.newArrayList();
/* set order for new action and add to action list */
ab.setOrder(bucketActionList.size());
ab.setKey(new ActionKey(bucketActionList.size()));
NodeConnectorId ncid = new NodeConnectorId("openflow:" + dpidLong + ":" + port);
logger.debug("addOutputPortInstructions() Node Connector ID is - Type=openflow: DPID={} port={} existingInstructions={}", dpidLong, port, instructions);
- List<Action> actionList = new ArrayList<Action>();
+ List<Action> actionList = Lists.newArrayList();
ActionBuilder ab = new ActionBuilder();
- List<Action> existingActions = null;
+ List<Action> existingActions;
if (instructions != null) {
for (Instruction in : instructions) {
if (in.getInstruction() instanceof ApplyActionsCase) {
NodeConnectorId ncid = new NodeConnectorId("openflow:" + dpidLong + ":" + port);
logger.debug("removeOutputPortFromGroup() Node Connector ID is - Type=openflow: DPID={} port={} existingInstructions={}", dpidLong, port, instructions);
- List<Action> actionList = new ArrayList<Action>();
+ List<Action> actionList = Lists.newArrayList();
ActionBuilder ab;
- List<Action> existingActions = null;
+ List<Action> existingActions;
if (instructions != null) {
for (Instruction in : instructions) {
if (in.getInstruction() instanceof ApplyActionsCase) {
/* modify the action bucket in group */
groupBuilder = new GroupBuilder(group);
Buckets buckets = groupBuilder.getBuckets();
- List<Action> bucketActions = new ArrayList<Action>();
+ List<Action> bucketActions = Lists.newArrayList();
for (Bucket bucket : buckets.getBucket()) {
int index = 0;
boolean isPortDeleted = false;
/* rewrite the group to group table */
/* set bucket and buckets list. Reset groupBuilder with new buckets.*/
BucketsBuilder bucketsBuilder = new BucketsBuilder();
- List<Bucket> bucketList = new ArrayList<Bucket>();
+ List<Bucket> bucketList = Lists.newArrayList();
BucketBuilder bucketBuilder = new BucketBuilder();
bucketBuilder.setBucketId(new BucketId((long) 1));
bucketBuilder.setKey(new BucketKey(new BucketId((long) 1)));
NodeConnectorId ncid = new NodeConnectorId("openflow:" + dpidLong + ":" + port);
logger.debug("removeOutputPortFromInstructions() Node Connector ID is - Type=openflow: DPID={} port={} existingInstructions={}", dpidLong, port, instructions);
- List<Action> actionList = new ArrayList<Action>();
+ List<Action> actionList = Lists.newArrayList();
ActionBuilder ab;
- List<Action> existingActions = null;
+ List<Action> existingActions;
if (instructions != null) {
for (Instruction in : instructions) {
if (in.getInstruction() instanceof ApplyActionsCase) {
*/
protected static InstructionBuilder createSetVlanInstructions(InstructionBuilder ib, VlanId vlanId) {
- List<Action> actionList = new ArrayList<Action>();
+ List<Action> actionList = Lists.newArrayList();
ActionBuilder ab = new ActionBuilder();
/* First we push vlan header */
*/
protected static InstructionBuilder createPopVlanInstructions(InstructionBuilder ib) {
- List<Action> actionList = new ArrayList<Action>();
+ List<Action> actionList = Lists.newArrayList();
ActionBuilder ab = new ActionBuilder();
PopVlanActionBuilder popVlanActionBuilder = new PopVlanActionBuilder();
*/
protected static InstructionBuilder createNwSrcInstructions(InstructionBuilder ib, Ipv4Prefix prefixsrc) {
- List<Action> actionList = new ArrayList<Action>();
+ List<Action> actionList = Lists.newArrayList();
ActionBuilder ab = new ActionBuilder();
SetNwSrcActionBuilder setNwsrcActionBuilder = new SetNwSrcActionBuilder();
*/
protected static InstructionBuilder createNwDstInstructions(InstructionBuilder ib, Ipv4Prefix prefixdst) {
- List<Action> actionList = new ArrayList<Action>();
+ List<Action> actionList = Lists.newArrayList();
ActionBuilder ab = new ActionBuilder();
SetNwDstActionBuilder setNwDstActionBuilder = new SetNwDstActionBuilder();
ab.setOrder(0);
// Add our drop action to a list
- List<Action> actionList = new ArrayList<Action>();
+ List<Action> actionList = Lists.newArrayList();
actionList.add(ab.build());
// Create an Apply Action
*/
protected static InstructionBuilder createSetTunnelIdInstructions(InstructionBuilder ib, BigInteger tunnelId) {
- List<Action> actionList = new ArrayList<Action>();
+ List<Action> actionList = Lists.newArrayList();
ActionBuilder ab = new ActionBuilder();
SetFieldBuilder setFieldBuilder = new SetFieldBuilder();
*/
protected static InstructionBuilder createSetSrcTCPPort(InstructionBuilder ib, PortNumber tcpport) {
- List<Action> actionList = new ArrayList<Action>();
+ List<Action> actionList = Lists.newArrayList();
ActionBuilder ab = new ActionBuilder();
SetFieldBuilder setFieldBuilder = new SetFieldBuilder();
*/
protected static InstructionBuilder createSetDstTCPPort(InstructionBuilder ib, PortNumber tcpport) {
- List<Action> actionList = new ArrayList<Action>();
+ List<Action> actionList = Lists.newArrayList();
ActionBuilder ab = new ActionBuilder();
SetFieldBuilder setFieldBuilder = new SetFieldBuilder();
*/
protected static InstructionBuilder createSetSrcUDPPort(InstructionBuilder ib, PortNumber udpport) {
- List<Action> actionList = new ArrayList<Action>();
+ List<Action> actionList = Lists.newArrayList();
ActionBuilder ab = new ActionBuilder();
SetFieldBuilder setFieldBuilder = new SetFieldBuilder();
*/
protected static InstructionBuilder createSetDstUDPPort(InstructionBuilder ib, PortNumber udpport) {
- List<Action> actionList = new ArrayList<Action>();
+ List<Action> actionList = Lists.newArrayList();
ActionBuilder ab = new ActionBuilder();
SetFieldBuilder setFieldBuilder = new SetFieldBuilder();
private static InstructionBuilder createSetIcmpCodeInstruction(InstructionBuilder ib, short code) {
- List<Action> actionList = new ArrayList<Action>();
+ List<Action> actionList = Lists.newArrayList();
ActionBuilder ab = new ActionBuilder();
SetFieldBuilder setFieldBuilder = new SetFieldBuilder();
Icmpv4MatchBuilder icmpv4match = new Icmpv4MatchBuilder();
*/
private static InstructionBuilder createSetIcmpTypeInstruction(InstructionBuilder ib, short type) {
- List<Action> actionList = new ArrayList<Action>();
+ List<Action> actionList = Lists.newArrayList();
ActionBuilder ab = new ActionBuilder();
SetFieldBuilder setFieldBuilder = new SetFieldBuilder();
Icmpv4MatchBuilder icmpv4match = new Icmpv4MatchBuilder();
ab.setAction(new DecNwTtlCaseBuilder().setDecNwTtl(decNwTtl).build());
// Add our drop action to a list
- List<Action> actionList = new ArrayList<Action>();
+ List<Action> actionList = Lists.newArrayList();
actionList.add(ab.build());
// Create an Apply Action
*/
private static InstructionBuilder createSrcArpMacInstructions(InstructionBuilder ib, MacAddress macsrc) {
- List<Action> actionList = new ArrayList<Action>();
+ List<Action> actionList = Lists.newArrayList();
ActionBuilder ab = new ActionBuilder();
SetFieldBuilder setFieldBuilder = new SetFieldBuilder();
*/
private static InstructionBuilder createDstArpMacInstructions(InstructionBuilder ib, MacAddress macdst) {
- List<Action> actionList = new ArrayList<Action>();
+ List<Action> actionList = Lists.newArrayList();
ActionBuilder ab = new ActionBuilder();
SetFieldBuilder setFieldBuilder = new SetFieldBuilder();
*/
private static InstructionBuilder createDstArpIpInstructions(InstructionBuilder ib, Ipv4Prefix dstiparp) {
- List<Action> actionList = new ArrayList<Action>();
+ List<Action> actionList = Lists.newArrayList();
ActionBuilder ab = new ActionBuilder();
SetFieldBuilder setFieldBuilder = new SetFieldBuilder();
*/
private static InstructionBuilder createSrcArpIpInstructions(InstructionBuilder ib, Ipv4Prefix srciparp) {
- List<Action> actionList = new ArrayList<Action>();
+ List<Action> actionList = Lists.newArrayList();
ActionBuilder ab = new ActionBuilder();
SetFieldBuilder setFieldBuilder = new SetFieldBuilder();
@Override
public void initializeOFFlowRules(Node openflowNode) {
- IConnectionServiceInternal connectionService = (IConnectionServiceInternal)ServiceHelper.getGlobalInstance(IConnectionServiceInternal.class, this);
+ Preconditions.checkNotNull(connectionService);
List<Node> ovsNodes = connectionService.getNodes();
if (ovsNodes == null) return;
for (Node ovsNode : ovsNodes) {
logger.debug("Compare openflowNode to OVS node {} vs {} and {}", openflowNode.getID(), brIntDpid, brExDpid);
String openflowID = openflowNode.getID().toString();
if (openflowID.contains(brExDpid.toString())) {
- this.initializeFlowRules(ovsNode, adminConfigManager.getExternalBridgeName());
+ this.initializeFlowRules(ovsNode, configurationService.getExternalBridgeName());
this.triggerInterfaceUpdates(ovsNode);
}
if (openflowID.contains(brIntDpid.toString())) {
- this.initializeFlowRules(ovsNode, adminConfigManager.getIntegrationBridgeName());
+ this.initializeFlowRules(ovsNode, configurationService.getIntegrationBridgeName());
this.triggerInterfaceUpdates(ovsNode);
}
}
}
private String getInternalBridgeUUID (Node node, String bridgeName) {
+ Preconditions.checkNotNull(ovsdbConfigService);
try {
- OvsdbConfigService ovsdbTable = (OvsdbConfigService)ServiceHelper.getGlobalInstance(OvsdbConfigService.class, this);
- Map<String, Row> bridgeTable = ovsdbTable.getRows(node, ovsdbTable.getTableName(node, Bridge.class));
+ Map<String, Row> bridgeTable = ovsdbConfigService.getRows(node, ovsdbConfigService.getTableName(node, Bridge.class));
if (bridgeTable == null) return null;
for (String key : bridgeTable.keySet()) {
- Bridge bridge = ovsdbTable.getTypedRow(node, Bridge.class, bridgeTable.get(key));
+ Bridge bridge = ovsdbConfigService.getTypedRow(node, Bridge.class, bridgeTable.get(key));
if (bridge.getName().equals(bridgeName)) return key;
}
} catch (Exception e) {
<groupId>org.opendaylight.ovsdb</groupId>
<artifactId>commons</artifactId>
<version>1.2.0-SNAPSHOT</version>
- <relativePath>../commons/parent</relativePath>
+ <relativePath>../../commons/parent</relativePath>
</parent>
- <artifactId>neutron</artifactId>
- <version>0.7.0-SNAPSHOT</version>
+ <artifactId>openstack.net-virt</artifactId>
+ <version>1.0.0-SNAPSHOT</version>
<packaging>bundle</packaging>
<dependencies>
- <dependency>
- <groupId>org.opendaylight.controller</groupId>
- <artifactId>containermanager</artifactId>
- </dependency>
- <dependency>
- <groupId>org.opendaylight.controller</groupId>
- <artifactId>forwardingrulesmanager</artifactId>
- </dependency>
<dependency>
<groupId>org.opendaylight.controller</groupId>
<artifactId>networkconfig.neutron</artifactId>
<groupId>org.opendaylight.controller</groupId>
<artifactId>sal</artifactId>
</dependency>
- <dependency>
- <groupId>org.opendaylight.controller</groupId>
- <artifactId>sal-binding-api</artifactId>
- </dependency>
- <dependency>
- <groupId>org.opendaylight.controller</groupId>
- <artifactId>sal-common-util</artifactId>
- </dependency>
<dependency>
<groupId>org.opendaylight.controller</groupId>
<artifactId>switchmanager</artifactId>
</dependency>
- <dependency>
- <groupId>org.opendaylight.controller.model</groupId>
- <artifactId>model-flow-base</artifactId>
- </dependency>
- <dependency>
- <groupId>org.opendaylight.controller.model</groupId>
- <artifactId>model-flow-management</artifactId>
- </dependency>
- <dependency>
- <groupId>org.opendaylight.controller.model</groupId>
- <artifactId>model-flow-service</artifactId>
- </dependency>
- <dependency>
- <groupId>org.opendaylight.controller.model</groupId>
- <artifactId>model-inventory</artifactId>
- </dependency>
<dependency>
<groupId>org.opendaylight.ovsdb</groupId>
<artifactId>library</artifactId>
<groupId>org.opendaylight.ovsdb</groupId>
<artifactId>schema.openvswitch</artifactId>
</dependency>
- <dependency>
- <groupId>org.opendaylight.yangtools</groupId>
- <artifactId>yang-binding</artifactId>
- </dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
- <dependency>
- <groupId>org.mockito</groupId>
- <artifactId>mockito-all</artifactId>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>org.powermock</groupId>
- <artifactId>powermock-api-mockito</artifactId>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>org.powermock</groupId>
- <artifactId>powermock-module-junit4</artifactId>
- <scope>test</scope>
- </dependency>
</dependencies>
<build>
<plugins>
<extensions>true</extensions>
<configuration>
<instructions>
- <Import-Package>org.opendaylight.controller.networkconfig.neutron,
- org.opendaylight.controller.containermanager,
+ <Import-Package>
+ org.opendaylight.controller.networkconfig.neutron,
org.opendaylight.controller.switchmanager,
- org.opendaylight.controller.forwardingrulesmanager,
org.opendaylight.controller.sal.core,
org.opendaylight.controller.sal.utils,
- org.opendaylight.controller.sal.action,
org.opendaylight.ovsdb.plugin,
org.opendaylight.ovsdb.lib.notation,
- org.opendaylight.controller.sal.binding.api,
- org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819,
- org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes,
- org.opendaylight.yangtools.yang.binding,
org.apache.felix.dm,
org.slf4j,
org.osgi.framework,
*</Import-Package>
- <Bundle-Activator>org.opendaylight.ovsdb.neutron.Activator</Bundle-Activator>
+ <Export-Package>
+ org.opendaylight.ovsdb.openstack.netvirt.api
+ </Export-Package>
+ <Bundle-Activator>org.opendaylight.ovsdb.openstack.netvirt.Activator</Bundle-Activator>
</instructions>
</configuration>
</plugin>
--- /dev/null
+/*
+ * Copyright (C) 2013 Red Hat, Inc.
+ *
+ * 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
+ */
+package org.opendaylight.ovsdb.openstack.netvirt;
+
+import org.opendaylight.controller.sal.utils.Status;
+import org.opendaylight.controller.sal.utils.StatusCode;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.net.HttpURLConnection;
+
+/**
+ * Abstract class for utility functions used by neutron handlers.
+ */
+public abstract class AbstractHandler {
+
+ /**
+ * Logger instance.
+ */
+ static final Logger logger = LoggerFactory.getLogger(AbstractHandler.class);
+
+ /**
+ * Convert failure status returned by the manager into
+ * neutron API service errors.
+ *
+ * @param status manager status
+ * @return An error to be returned to neutron API service.
+ */
+ protected static final int getException(Status status) {
+ int result = HttpURLConnection.HTTP_INTERNAL_ERROR;
+
+ assert !status.isSuccess();
+
+ StatusCode code = status.getCode();
+ logger.debug(" Exception code - {}, description - {}",
+ code, status.getDescription());
+
+ if (code == StatusCode.BADREQUEST) {
+ result = HttpURLConnection.HTTP_BAD_REQUEST;
+ } else if (code == StatusCode.CONFLICT) {
+ result = HttpURLConnection.HTTP_CONFLICT;
+ } else if (code == StatusCode.NOTACCEPTABLE) {
+ result = HttpURLConnection.HTTP_NOT_ACCEPTABLE;
+ } else if (code == StatusCode.NOTFOUND) {
+ result = HttpURLConnection.HTTP_NOT_FOUND;
+ } else {
+ result = HttpURLConnection.HTTP_INTERNAL_ERROR;
+ }
+
+ return result;
+ }
+}
--- /dev/null
+/*
+ * Copyright (C) 2013 Red Hat, Inc.
+ *
+ * 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, Dave Tucker
+ */
+
+package org.opendaylight.ovsdb.openstack.netvirt;
+
+import org.opendaylight.controller.networkconfig.neutron.INeutronNetworkAware;
+import org.opendaylight.controller.networkconfig.neutron.INeutronNetworkCRUD;
+import org.opendaylight.controller.networkconfig.neutron.INeutronPortAware;
+import org.opendaylight.controller.networkconfig.neutron.INeutronPortCRUD;
+import org.opendaylight.controller.networkconfig.neutron.INeutronSecurityGroupAware;
+import org.opendaylight.controller.networkconfig.neutron.INeutronSecurityRuleAware;
+import org.opendaylight.controller.networkconfig.neutron.INeutronSubnetAware;
+import org.opendaylight.controller.sal.core.ComponentActivatorAbstractBase;
+import org.opendaylight.controller.switchmanager.IInventoryListener;
+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.TenantNetworkManager;
+import org.opendaylight.ovsdb.openstack.netvirt.api.VlanConfigurationCache;
+import org.opendaylight.ovsdb.openstack.netvirt.impl.BridgeConfigurationManagerImpl;
+import org.opendaylight.ovsdb.openstack.netvirt.impl.ConfigurationServiceImpl;
+import org.opendaylight.ovsdb.openstack.netvirt.impl.ProviderNetworkManagerImpl;
+import org.opendaylight.ovsdb.openstack.netvirt.impl.TenantNetworkManagerImpl;
+import org.opendaylight.ovsdb.openstack.netvirt.impl.VlanConfigurationCacheImpl;
+import org.opendaylight.ovsdb.plugin.IConnectionServiceInternal;
+import org.opendaylight.ovsdb.plugin.OvsdbConfigService;
+import org.opendaylight.ovsdb.plugin.OvsdbInventoryListener;
+
+import org.apache.felix.dm.Component;
+
+/**
+ * OSGi bundle activator for the OVSDB Neutron Interface.
+ */
+public class Activator extends ComponentActivatorAbstractBase {
+ /**
+ * Function called when the activator starts just after some
+ * initializations are done by the
+ * ComponentActivatorAbstractBase.
+ */
+ @Override
+ public void init() {
+ }
+
+ /**
+ * Function called when the activator stops just before the
+ * cleanup done by ComponentActivatorAbstractBase.
+ *
+ */
+ @Override
+ public void destroy() {
+ }
+
+ /**
+ * Function that is used to communicate to dependency manager the
+ * list of known implementations for services inside a container.
+ *
+ * @return An array containing all the CLASS objects that will be
+ * instantiated in order to get an fully working implementation
+ * Object
+ */
+ @Override
+ public Object[] getImplementations() {
+ Object[] res = {ConfigurationServiceImpl.class,
+ BridgeConfigurationManagerImpl.class,
+ TenantNetworkManagerImpl.class,
+ VlanConfigurationCacheImpl.class,
+ NetworkHandler.class,
+ SubnetHandler.class,
+ PortHandler.class,
+ SouthboundHandler.class,
+ PortSecurityHandler.class,
+ ProviderNetworkManagerImpl.class};
+ return res;
+ }
+
+ /**
+ * Function that is called when configuration of the dependencies
+ * is required.
+ *
+ * @param c dependency manager Component object, used for
+ * configuring the dependencies exported and imported
+ * @param imp Implementation class that is being configured,
+ * needed as long as the same routine can configure multiple
+ * implementations
+ * @param containerName The containerName being configured, this allow
+ * also optional per-container different behavior if needed, usually
+ * should not be the case though.
+ */
+ @Override
+ public void configureInstance(Component c, Object imp,
+ String containerName) {
+ if (imp.equals(ConfigurationServiceImpl.class)) {
+ c.setInterface(ConfigurationService.class.getName(), null);
+ c.add(createServiceDependency().setService(OvsdbConfigService.class));
+ }
+
+ if (imp.equals(BridgeConfigurationManagerImpl.class)) {
+ c.setInterface(BridgeConfigurationManager.class.getName(), null);
+ c.add(createServiceDependency().setService(ConfigurationService.class).setRequired(true));
+ c.add(createServiceDependency().setService(NetworkingProviderManager.class));
+ c.add(createServiceDependency().setService(OvsdbConfigService.class));
+ }
+
+ if (imp.equals(TenantNetworkManagerImpl.class)) {
+ c.setInterface(TenantNetworkManager.class.getName(), null);
+ c.add(createServiceDependency().setService(NetworkingProviderManager.class));
+ c.add(createServiceDependency().setService(OvsdbConfigService.class));
+ c.add(createServiceDependency().setService(IConnectionServiceInternal.class));
+ c.add(createServiceDependency().
+ setService(INeutronNetworkCRUD.class).
+ setRequired(true));
+ c.add(createServiceDependency().
+ setService(INeutronPortCRUD.class).
+ setRequired(true));
+ c.add(createServiceDependency().setService(VlanConfigurationCache.class));
+ }
+
+ if (imp.equals(VlanConfigurationCacheImpl.class)) {
+ c.setInterface(VlanConfigurationCache.class.getName(), null);
+ c.add(createServiceDependency().setService(OvsdbConfigService.class));
+ c.add(createServiceDependency().setService(TenantNetworkManager.class));
+ }
+
+ if (imp.equals(NetworkHandler.class)) {
+ c.setInterface(INeutronNetworkAware.class.getName(), null);
+ c.add(createServiceDependency().setService(TenantNetworkManager.class).setRequired(true));
+ c.add(createServiceDependency().setService(BridgeConfigurationManager.class).setRequired(true));
+ c.add(createServiceDependency().setService(ConfigurationService.class).setRequired(true));
+ c.add(createServiceDependency().setService(OvsdbConfigService.class).setRequired(true));
+ c.add(createServiceDependency().setService(IConnectionServiceInternal.class).setRequired(true));
+ c.add(createServiceDependency().setService(INeutronNetworkCRUD.class).setRequired(true));
+ c.add(createServiceDependency().setService(OvsdbInventoryListener.class).setRequired(true));
+ }
+
+ if (imp.equals(SubnetHandler.class)) {
+ c.setInterface(INeutronSubnetAware.class.getName(), null);
+ }
+
+ if (imp.equals(PortHandler.class)) {
+ c.setInterface(INeutronPortAware.class.getName(), null);
+ c.add(createServiceDependency().setService(OvsdbConfigService.class).setRequired(true));
+ c.add(createServiceDependency().setService(IConnectionServiceInternal.class).setRequired(true));
+ c.add(createServiceDependency().setService(INeutronNetworkCRUD.class).setRequired(true));
+ c.add(createServiceDependency().setService(OvsdbInventoryListener.class).setRequired(true));
+ }
+
+ if (imp.equals(SouthboundHandler.class)) {
+ c.setInterface(new String[] {OvsdbInventoryListener.class.getName(),
+ IInventoryListener.class.getName()}, null);
+ c.add(createServiceDependency().setService(ConfigurationService.class).setRequired(true));
+ c.add(createServiceDependency().setService(BridgeConfigurationManager.class).setRequired(true));
+ c.add(createServiceDependency().setService(TenantNetworkManager.class).setRequired(true));
+ c.add(createServiceDependency().setService(NetworkingProviderManager.class).setRequired(true));
+ c.add(createServiceDependency().setService(OvsdbConfigService.class).setRequired(true));
+ c.add(createServiceDependency().setService(IConnectionServiceInternal.class).setRequired(true));
+ }
+
+ if (imp.equals(PortSecurityHandler.class)) {
+ c.setInterface(new String[] {INeutronSecurityRuleAware.class.getName(),
+ INeutronSecurityGroupAware.class.getName()}, null);
+ }
+
+ if (imp.equals(ProviderNetworkManagerImpl.class)) {
+ c.setInterface(NetworkingProviderManager.class.getName(), null);
+ c.add(createServiceDependency()
+ .setService(ConfigurationService.class)
+ .setRequired(true));
+ c.add(createServiceDependency()
+ .setService(NetworkingProvider.class)
+ .setCallbacks("providerAdded", "providerRemoved"));
+ }
+ }
+}
*
* Authors : Madhu Venugopal, Brent Salisbury, Hsin-Yi Shen
*/
-package org.opendaylight.ovsdb.neutron;
-
-import java.net.HttpURLConnection;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.concurrent.ConcurrentMap;
+package org.opendaylight.ovsdb.openstack.netvirt;
import org.opendaylight.controller.networkconfig.neutron.INeutronNetworkAware;
import org.opendaylight.controller.networkconfig.neutron.INeutronNetworkCRUD;
import org.opendaylight.controller.networkconfig.neutron.NeutronNetwork;
import org.opendaylight.controller.sal.core.Node;
-import org.opendaylight.controller.sal.utils.ServiceHelper;
import org.opendaylight.ovsdb.lib.notation.Row;
+import org.opendaylight.ovsdb.openstack.netvirt.api.BridgeConfigurationManager;
+import org.opendaylight.ovsdb.openstack.netvirt.api.ConfigurationService;
+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.schema.openvswitch.Interface;
+
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import java.net.HttpURLConnection;
+import java.util.List;
+import java.util.concurrent.ConcurrentMap;
+
/**
* Handle requests for Neutron Network.
*/
-public class NetworkHandler extends BaseHandler
+public class NetworkHandler extends AbstractHandler
implements INeutronNetworkAware {
public static final String NETWORK_TYPE_VXLAN = "vxlan";
static final Logger logger = LoggerFactory.getLogger(NetworkHandler.class);
// The implementation for each of these services is resolved by the OSGi Service Manager
- private volatile ITenantNetworkManager tenantNetworkManager;
- private volatile IAdminConfigManager adminConfigManager;
+ private volatile TenantNetworkManager tenantNetworkManager;
+ private volatile BridgeConfigurationManager bridgeConfigurationManager;
+ private volatile ConfigurationService configurationService;
+ private volatile OvsdbConfigService ovsdbConfigService;
+ private volatile IConnectionServiceInternal connectionService;
+ private volatile INeutronNetworkCRUD neutronNetworkCache;
+ private volatile OvsdbInventoryListener inventoryListener;
/**
* Invoked when a network creation is requested
return;
}
/* Is this the last Neutron tenant network */
- INeutronNetworkCRUD neutronNetworkService = (INeutronNetworkCRUD)ServiceHelper.getGlobalInstance(INeutronNetworkCRUD.class, this);
- List <NeutronNetwork> networks = new ArrayList<NeutronNetwork>();
- if (neutronNetworkService != null) {
- networks = neutronNetworkService.getAllNetworks();
- OvsdbInventoryListener inventoryListener = (OvsdbInventoryListener)ServiceHelper.getGlobalInstance(OvsdbInventoryListener.class, this);
+ List <NeutronNetwork> networks;
+ if (neutronNetworkCache != null) {
+ networks = neutronNetworkCache.getAllNetworks();
if (networks.isEmpty()) {
logger.trace("neutronNetworkDeleted: last tenant network, delete tunnel ports...");
- IConnectionServiceInternal connectionService = (IConnectionServiceInternal)
- ServiceHelper.getGlobalInstance(IConnectionServiceInternal.class, this);
List<Node> nodes = connectionService.getNodes();
for (Node node : nodes) {
- List<String> phyIfName = adminConfigManager.getAllPhysicalInterfaceNames(node);
+ List<String> phyIfName = bridgeConfigurationManager.getAllPhysicalInterfaceNames(node);
try {
ConcurrentMap<String, Row> interfaces = this.ovsdbConfigService.getRows(node, ovsdbConfigService.getTableName(node, Interface.class));
if (interfaces != null) {
--- /dev/null
+/*
+ * Copyright (C) 2014 Red Hat, Inc.
+ *
+ * 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 : Dave Tucker
+ */
+package org.opendaylight.ovsdb.openstack.netvirt;
+
+import org.opendaylight.ovsdb.openstack.netvirt.api.Constants;
+
+import com.google.common.collect.Lists;
+import com.google.common.collect.Maps;
+
+import java.util.Queue;
+import java.util.concurrent.ConcurrentMap;
+
+public class NodeConfiguration {
+ private java.util.Queue<Integer> internalVlans = Lists.newLinkedList();
+ private ConcurrentMap<String, Integer> tenantVlanMap = Maps.newConcurrentMap();
+
+ public NodeConfiguration() {
+ for (int i = 1; i < Constants.MAX_VLAN; i++) {
+ internalVlans.add(i);
+
+ }
+ }
+
+ public Queue<Integer> getInternalVlans() {
+ return internalVlans;
+ }
+
+ public ConcurrentMap<String, Integer> getTenantVlanMap() {
+ return tenantVlanMap;
+ }
+
+}
*
* Authors : Madhu Venugopal, Brent Salisbury
*/
-package org.opendaylight.ovsdb.neutron;
-
-import java.net.HttpURLConnection;
-import java.util.List;
-import java.util.Map;
-import java.util.concurrent.ConcurrentMap;
+package org.opendaylight.ovsdb.openstack.netvirt;
import org.opendaylight.controller.networkconfig.neutron.INeutronNetworkCRUD;
import org.opendaylight.controller.networkconfig.neutron.INeutronPortAware;
import org.opendaylight.controller.networkconfig.neutron.NeutronNetwork;
import org.opendaylight.controller.networkconfig.neutron.NeutronPort;
import org.opendaylight.controller.sal.core.Node;
-import org.opendaylight.controller.sal.utils.ServiceHelper;
import org.opendaylight.ovsdb.lib.notation.Row;
+import org.opendaylight.ovsdb.openstack.netvirt.api.Constants;
import org.opendaylight.ovsdb.plugin.IConnectionServiceInternal;
+import org.opendaylight.ovsdb.plugin.OvsdbConfigService;
import org.opendaylight.ovsdb.plugin.OvsdbInventoryListener;
import org.opendaylight.ovsdb.schema.openvswitch.Interface;
+
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import java.net.HttpURLConnection;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.ConcurrentMap;
+
/**
* Handle requests for Neutron Port.
*/
-public class PortHandler extends BaseHandler
+public class PortHandler extends AbstractHandler
implements INeutronPortAware {
/**
*/
static final Logger logger = LoggerFactory.getLogger(PortHandler.class);
+ private volatile OvsdbConfigService ovsdbConfigService;
+ private volatile IConnectionServiceInternal connectionService;
+ private volatile INeutronNetworkCRUD neutronNetworkCache;
+ private volatile OvsdbInventoryListener ovsdbInventoryListener;
+
/**
* Invoked when a port creation is requested
* to indicate if the specified port can be created.
return;
}
- IConnectionServiceInternal connectionService = (IConnectionServiceInternal)ServiceHelper.getGlobalInstance(IConnectionServiceInternal.class, this);
- INeutronNetworkCRUD neutronNetworkService = (INeutronNetworkCRUD)ServiceHelper.getGlobalInstance(INeutronNetworkCRUD.class, this);
- NeutronNetwork neutronNetwork = neutronNetworkService.getNetwork(port.getNetworkUUID());
- OvsdbInventoryListener inventoryListener = (OvsdbInventoryListener)ServiceHelper.getGlobalInstance(OvsdbInventoryListener.class, this);
+ NeutronNetwork neutronNetwork = neutronNetworkCache.getNetwork(port.getNetworkUUID());
List<Node> nodes = connectionService.getNodes();
for (Node node : nodes) {
try {
continue;
}
/* Compare Neutron port uuid */
- String neutronPortId = externalIds.get(TenantNetworkManager.EXTERNAL_ID_INTERFACE_ID);
+ String neutronPortId = externalIds.get(Constants.EXTERNAL_ID_INTERFACE_ID);
if (neutronPortId == null) {
continue;
}
if (neutronPortId.equalsIgnoreCase(port.getPortUUID())) {
logger.trace("neutronPortDeleted: Delete interface {}", intf.getName());
- inventoryListener.rowRemoved(node, intf.getSchema().getName(), intfUUID,
- intf.getRow(), neutronNetwork);
+ ovsdbInventoryListener.rowRemoved(node, intf.getSchema().getName(), intfUUID,
+ intf.getRow(), neutronNetwork);
break;
}
}
* Authors : Brent Salisbury, Madhu Venugopal
*/
-package org.opendaylight.ovsdb.neutron;
+package org.opendaylight.ovsdb.openstack.netvirt;
import org.opendaylight.controller.networkconfig.neutron.INeutronSecurityGroupAware;
import org.opendaylight.controller.networkconfig.neutron.INeutronSecurityRuleAware;
import org.opendaylight.controller.networkconfig.neutron.NeutronSecurityGroup;
import org.opendaylight.controller.networkconfig.neutron.NeutronSecurityRule;
+
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* Handle requests for OpenStack Neutron v2.0 Port Security API calls.
*/
-public class PortSecurityHandler extends BaseHandler
+public class PortSecurityHandler extends AbstractHandler
implements INeutronSecurityGroupAware, INeutronSecurityRuleAware{
static final Logger logger = LoggerFactory.getLogger(PortSecurityHandler.class);
*
* Authors : Madhu Venugopal, Brent Salisbury
*/
-package org.opendaylight.ovsdb.neutron;
+package org.opendaylight.ovsdb.openstack.netvirt;
import org.opendaylight.controller.sal.core.Node;
import org.opendaylight.ovsdb.lib.notation.Row;
*
* Authors : Madhu Venugopal, Brent Salisbury, Sam Hague, Dave Tucker
*/
-package org.opendaylight.ovsdb.neutron;
-
-import java.util.ArrayList;
-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;
+package org.opendaylight.ovsdb.openstack.netvirt;
import org.opendaylight.controller.networkconfig.neutron.NeutronNetwork;
import org.opendaylight.controller.sal.core.Node;
import org.opendaylight.controller.switchmanager.IInventoryListener;
import org.opendaylight.ovsdb.lib.notation.Row;
import org.opendaylight.ovsdb.lib.notation.UUID;
-import org.opendaylight.ovsdb.neutron.provider.IProviderNetworkManager;
+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.schema.openvswitch.Interface;
import org.opendaylight.ovsdb.schema.openvswitch.OpenVSwitch;
import org.opendaylight.ovsdb.schema.openvswitch.Port;
+
+import com.google.common.collect.Lists;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-public class SouthboundHandler extends BaseHandler implements OvsdbInventoryListener, IInventoryListener {
+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 {
static final Logger logger = LoggerFactory.getLogger(SouthboundHandler.class);
//private Thread eventThread;
private ExecutorService eventHandler;
List<Node> nodeCache;
// The implementation for each of these services is resolved by the OSGi Service Manager
- private volatile IAdminConfigManager adminConfigManager;
- private volatile IInternalNetworkManager internalNetworkManager;
- private volatile ITenantNetworkManager tenantNetworkManager;
- private volatile IProviderNetworkManager providerNetworkManager;
+ private volatile ConfigurationService configurationService;
+ private volatile BridgeConfigurationManager bridgeConfigurationManager;
+ private volatile TenantNetworkManager tenantNetworkManager;
+ private volatile NetworkingProviderManager networkingProviderManager;
+ private volatile OvsdbConfigService ovsdbConfigService;
+ private volatile IConnectionServiceInternal connectionService;
void init() {
eventHandler = Executors.newSingleThreadExecutor();
- this.events = new LinkedBlockingQueue<SouthboundEvent>();
- nodeCache = new ArrayList<>();
+ this.events = new LinkedBlockingQueue<>();
+ nodeCache = Lists.newArrayList();
}
void start() {
public void processNodeUpdate(Node node, SouthboundEvent.Action action) {
if (action == SouthboundEvent.Action.DELETE) return;
logger.trace("Process Node added {}", node);
- internalNetworkManager.prepareInternalNetwork(node);
+ bridgeConfigurationManager.prepareNode(node);
}
private void processRowUpdate(Node node, String tableName, String uuid, Row row,
Interface deletedIntf = ovsdbConfigService.getTypedRow(node, Interface.class, row);
NeutronNetwork network = null;
if (context == null) {
- network = tenantNetworkManager.getTenantNetworkForInterface(deletedIntf);
+ network = tenantNetworkManager.getTenantNetwork(deletedIntf);
} else {
network = (NeutronNetwork)context;
}
- List<String> phyIfName = adminConfigManager.getAllPhysicalInterfaceNames(node);
+ List<String> phyIfName = bridgeConfigurationManager.getAllPhysicalInterfaceNames(node);
logger.info("Delete interface " + deletedIntf.getName());
if (deletedIntf.getTypeColumn().getData().equalsIgnoreCase(NetworkHandler.NETWORK_TYPE_VXLAN) ||
for (String intfUUID : interfaces.keySet()) {
if (intfUUID.equals(uuid)) continue;
Interface intf = this.ovsdbConfigService.getTypedRow(node, Interface.class, interfaces.get(intfUUID));
- NeutronNetwork neutronNetwork = tenantNetworkManager.getTenantNetworkForInterface(intf);
+ NeutronNetwork neutronNetwork = tenantNetworkManager.getTenantNetwork(intf);
if (neutronNetwork != null && neutronNetwork.equals(network)) isLastInstanceOnNode = false;
}
this.handleInterfaceDelete(node, uuid, deletedIntf, isLastInstanceOnNode, network);
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);
- NeutronNetwork network = tenantNetworkManager.getTenantNetworkForInterface(intf);
+ NeutronNetwork network = tenantNetworkManager.getTenantNetwork(intf);
if (network != null && !network.getRouterExternal()) {
- if (providerNetworkManager.getProvider().hasPerTenantTunneling()) {
+ 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) {
- tenantNetworkManager.programTenantNetworkInternalVlan(node, portUUID, network);
+ tenantNetworkManager.programInternalVlan(node, portUUID, network);
}
}
this.handleInterfaceUpdate(node, uuid, intf);
try {
Row intfRow = this.ovsdbConfigService.getRow(node, ovsdbConfigService.getTableName(node, Interface.class), intfUUID.toString());
Interface intf = this.ovsdbConfigService.getTypedRow(node, Interface.class, intfRow);
- NeutronNetwork network = tenantNetworkManager.getTenantNetworkForInterface(intf);
+ NeutronNetwork network = tenantNetworkManager.getTenantNetwork(intf);
if (network != null && !network.getRouterExternal()) {
- tenantNetworkManager.programTenantNetworkInternalVlan(node, uuid, network);
+ tenantNetworkManager.programInternalVlan(node, uuid, network);
this.handleInterfaceUpdate(node, intfUUID.toString(), intf);
} else {
logger.trace("ignore update because there is not a neutron network.");
private void handleInterfaceUpdate (Node node, String uuid, Interface intf) {
logger.debug("handleInterfaceUpdate: node: {}, uuid: {}", node, uuid);
- NeutronNetwork network = tenantNetworkManager.getTenantNetworkForInterface(intf);
+ NeutronNetwork network = tenantNetworkManager.getTenantNetwork(intf);
if (network != null) {
- if (internalNetworkManager.checkAndCreateNetwork(node, network)) {
- providerNetworkManager.getProvider().handleInterfaceUpdate(network, node, intf);
+ if (bridgeConfigurationManager.createLocalNetwork(node, network)) {
+ networkingProviderManager.getProvider(node).handleInterfaceUpdate(network, node, intf);
}
}
}
logger.debug("handleInterfaceDelete: node: {}, uuid: {}, isLastInstanceOnNode: {}, interface: {}",
node, uuid, isLastInstanceOnNode, intf);
- List<String> phyIfName = adminConfigManager.getAllPhysicalInterfaceNames(node);
+ List<String> 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 */
- providerNetworkManager.getProvider().handleInterfaceDelete(intf.getTypeColumn().getData(), null, node, intf, isLastInstanceOnNode);
+ networkingProviderManager.getProvider(node).handleInterfaceDelete(intf.getTypeColumn().getData(), null, node, intf, isLastInstanceOnNode);
} else if (network != null) {
if (!network.getProviderNetworkType().equalsIgnoreCase(NetworkHandler.NETWORK_TYPE_VLAN)) { /* vlan doesn't need a tunnel endpoint */
- if (adminConfigManager.getTunnelEndPoint(node) == null) {
+ if (configurationService.getTunnelEndPoint(node) == null) {
logger.error("Tunnel end-point configuration missing. Please configure it in OpenVSwitch Table");
return;
}
}
- if (isLastInstanceOnNode & providerNetworkManager.getProvider().hasPerTenantTunneling()) {
- tenantNetworkManager.reclaimTenantNetworkInternalVlan(node, uuid, network);
+ if (isLastInstanceOnNode & networkingProviderManager.getProvider(node).hasPerTenantTunneling()) {
+ tenantNetworkManager.reclaimInternalVlan(node, uuid, network);
}
- providerNetworkManager.getProvider().handleInterfaceDelete(network.getProviderNetworkType(), network, node, intf, isLastInstanceOnNode);
+ networkingProviderManager.getProvider(node).handleInterfaceDelete(network.getProviderNetworkType(), network, node, intf, isLastInstanceOnNode);
}
}
// 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);
- providerNetworkManager.getProvider().initializeOFFlowRules(node);
+ networkingProviderManager.getProvider(node).initializeOFFlowRules(node);
} else if (type.equals(UpdateType.REMOVED)){
nodeCache.remove(node);
}
}
private void triggerUpdates() {
- List<Node> nodes = this.getConnectionService().getNodes();
+ List<Node> nodes = connectionService.getNodes();
if (nodes == null) return;
for (Node node : nodes) {
try {
- List<String> tableNames = this.getOVSDBConfigService().getTables(node);
+ List<String> tableNames = ovsdbConfigService.getTables(node);
if (tableNames == null) continue;
for (String tableName : tableNames) {
- Map<String, Row> rows = this.getOVSDBConfigService().getRows(node, tableName);
+ Map<String, Row> rows = ovsdbConfigService.getRows(node, tableName);
if (rows == null) continue;
for (String uuid : rows.keySet()) {
Row row = rows.get(uuid);
*
* Authors : Madhu Venugopal, Brent Salisbury
*/
-package org.opendaylight.ovsdb.neutron;
-import java.net.HttpURLConnection;
+package org.opendaylight.ovsdb.openstack.netvirt;
import org.opendaylight.controller.networkconfig.neutron.INeutronSubnetAware;
import org.opendaylight.controller.networkconfig.neutron.NeutronSubnet;
+
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-public class SubnetHandler extends BaseHandler implements INeutronSubnetAware {
+import java.net.HttpURLConnection;
+
+public class SubnetHandler extends AbstractHandler implements INeutronSubnetAware {
+
static final Logger logger = LoggerFactory.getLogger(SubnetHandler.class);
+
@Override
public int canCreateSubnet(NeutronSubnet subnet) {
return HttpURLConnection.HTTP_CREATED;
--- /dev/null
+/*
+ * Copyright (C) 2014 Red Hat, Inc.
+ *
+ * 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 : Dave Tucker
+ */
+
+package org.opendaylight.ovsdb.openstack.netvirt.api;
+
+import org.opendaylight.controller.networkconfig.neutron.NeutronNetwork;
+import org.opendaylight.controller.sal.core.Node;
+import org.opendaylight.ovsdb.schema.openvswitch.Bridge;
+
+import java.util.List;
+
+/**
+ * OpenStack Neutron with the Open vSwitch plugin relies on a typical bridge configuration that
+ * consists of br-int (Integration Bridge), br-net (Network bridge), br-ex (External bridge).
+ *
+ * This class ensures that the bridges on each {@link org.opendaylight.controller.sal.core.Node}
+ * are correctly configured for OpenStack Neutron
+ *
+ */
+public interface BridgeConfigurationManager {
+
+ /**
+ * A helper function to get the UUID of a given Bridge
+ * @param node the {@link org.opendaylight.controller.sal.core.Node} where the bridge is configured
+ * @param bridgeName the name of the bridge
+ * @return the UUID of the bridge
+ */
+ public String getBridgeUuid(Node node, String bridgeName);
+
+ /**
+ * Checks for the existence of the Integration Bridge on a given Node
+ * @param node the {@link org.opendaylight.controller.sal.core.Node} where the bridge should be configured
+ * @return True if the bridge exists, False if it does not
+ */
+ public boolean isNodeNeutronReady(Node node);
+
+ /**
+ * Checks for the existence of the Network Bridge on a given Node
+ * @param node the {@link org.opendaylight.controller.sal.core.Node} where the bridge should be configured
+ * @return True if the bridge exists, False if it does not
+ */
+ public boolean isNodeOverlayReady(Node node);
+
+ /**
+ * Checks for the existence of the Network Bridge on a given Node
+ * @param node the {@link org.opendaylight.controller.sal.core.Node} where the bridge should be configured
+ * @return True if the bridge exists, False if it does not
+ */
+
+ /**
+ * Checks that a Node is ready for a Tunnel Network Provider
+ * For OpenFlow 1.0 the Integration, Network Bridge and corresponding patch ports are required
+ * For OpenFlow 1.3 only the Integration Bridge is required
+ * @param node the {@link org.opendaylight.controller.sal.core.Node} where the bridge is configured
+ * @return True or False
+ */
+ public boolean isNodeTunnelReady(Node node);
+
+ /* Determine if internal network is ready for vlan network types.
+ * - OF 1.0 requires br-int, br-net, a patch connecting them and
+ * physical device added to br-net.
+ * - OF 1.3 requires br-int and physical device added to br-int.
+ */
+
+ /**
+ * Checks that a Node is ready for a VLAN Network Provider for the given Network
+ * For OpenFlow 1.0 the Integration Bridge, Network Bridge, patch ports and a physical device connected to the
+ * Network Bridge are required.
+ * For OpenFlow 1.3 the Integration Bridge is required and must have a physical device connected.
+ * @param node the {@link org.opendaylight.controller.sal.core.Node} where the bridge is configured
+ * @param network the {@link org.opendaylight.controller.networkconfig.neutron.NeutronNetwork}
+ * @return True or False
+ */
+ public boolean isNodeVlanReady(Node node, NeutronNetwork network);
+
+ /**
+ * A helper function to determine if a port exists on a given bridge
+ * @param node the {@link org.opendaylight.controller.sal.core.Node} where the bridge is configured
+ * @param bridge the {@link org.opendaylight.ovsdb.schema.openvswitch.Bridge} to query
+ * @param portName the name of the port to search for
+ * @return True if the port exists, otherwise False
+ */
+ public boolean isPortOnBridge (Node node, Bridge bridge, String portName);
+
+
+ /**
+ * Returns true if the bridges required for the provider network type are created
+ * If the bridges are not created, this method will attempt to create them
+ * @param node the {@link org.opendaylight.controller.sal.core.Node} to query
+ * @param network the {@link org.opendaylight.controller.networkconfig.neutron.NeutronNetwork}
+ * @return True or False
+ */
+ public boolean createLocalNetwork(Node node, NeutronNetwork network);
+
+ /**
+ * Prepares the given Node for Neutron Networking by creating the Integration Bridge
+ * @param node the {@link org.opendaylight.controller.sal.core.Node} to prepare
+ */
+ public void prepareNode(Node node);
+
+ /**
+ * Returns the physical interface mapped to the given neutron physical network.
+ * @param node
+ * @param physicalNetwork
+ * @return
+ */
+ public String getPhysicalInterfaceName (Node node, String physicalNetwork);
+
+ /** Returns all physical interfaces configured in the bridge mapping
+ * Bridge mappings will be of the following format:
+ * @param node the {@link org.opendaylight.controller.sal.core.Node} to query
+ * @return a List in the format {eth1, eth2} given bridge_mappings=physnet1:eth1,physnet2:eth2
+ */
+ public List<String> getAllPhysicalInterfaceNames(Node node);
+}
\ No newline at end of file
--- /dev/null
+/*
+ * Copyright (C) 2014 Red Hat, Inc.
+ *
+ * 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 : Dave Tucker
+ */
+
+package org.opendaylight.ovsdb.openstack.netvirt.api;
+
+import org.opendaylight.controller.sal.core.Node;
+
+import org.apache.commons.lang3.tuple.Pair;
+
+import java.net.InetAddress;
+import java.util.Map;
+
+/**
+ * The ConfigurationService handles the configuration of the OpenStack Neutron Integration
+ * It exposes a set of Configuration variables and helper functions for obtaining node-specific
+ * configuration from the Open_vSwitch table of an OVS instance.
+ */
+public interface ConfigurationService {
+
+ /**
+ * Returns the name configured name of the Integration Bridge
+ */
+ public String getIntegrationBridgeName();
+
+ /**
+ * Configures the name of the Integration Bridge
+ */
+ public void setIntegrationBridgeName(String integrationBridgeName);
+
+ /**
+ * Returns the name configured name of the Network Bridge
+ */
+ public String getNetworkBridgeName();
+
+ /**
+ * Configures the name of the Network Bridge
+ */
+ public void setNetworkBridgeName(String networkBridgeName);
+
+ /**
+ * Returns the name configured name of the ExternalBridge
+ */
+ public String getExternalBridgeName();
+
+ /**
+ * Configures the name of the External Bridge
+ */
+ public void setExternalBridgeName(String externalBridgeName);
+
+ /**
+ * Returns the key used to access the Tunnel Endpoint configuration from Open vSwitch
+ */
+ public String getTunnelEndpointKey();
+
+ /**
+ * Sets the key used to access the Tunnel Endpoint configuration from Open vSwitch
+ */
+ public void setTunnelEndpointKey(String tunnelEndpointKey);
+
+ /**
+ * Returns a Map of patch port names where the key is a tuple of source bridge and destination bridge
+ */
+ public Map<Pair<String, String>, String> getPatchPortNames();
+
+ /**
+ * Sets the Map of source/destination bridges to patch port name
+ */
+ public void setPatchPortNames(Map<Pair<String, String>, String> patchPortNames);
+
+ /**
+ * Get the name of a patch port
+ * @param portTuple a {@link org.apache.commons.lang3.tuple.Pair} where L
+ * is the source bridge and R the destination bridge
+ * @return the name of the patch port
+ */
+ public String getPatchPortName(Pair portTuple);
+
+ /**
+ * Returns the key used to access the Tunnel Endpoint configuration from Open vSwitch
+ */
+ public String getProviderMappingsKey();
+
+ /**
+ * Sets the key used to access the Tunnel Endpoint configuration from Open vSwitch
+ */
+ public void setProviderMappingsKey(String providerMappingsKey);
+
+ /**
+ * Gets the default provider mapping
+ */
+ public String getDefaultProviderMapping();
+
+ /**
+ * Sets the default provider mapping
+ */
+ public void setDefaultProviderMapping(String providerMapping);
+
+ /**
+ * Gets the tunnel endpoint address for a given Node
+ * @param node a {@link org.opendaylight.controller.sal.core.Node}
+ * @return the tunnel endpoint
+ * @see java.net.InetAddress
+ */
+ public InetAddress getTunnelEndPoint(Node node);
+
+ /**
+ * Returns the OpenFlow version to be used by the {@link NetworkingProvider}
+ * Default is OpenFlow 1.0. OVS versions greater than 1.10.0 will use OpenFlow 1.3
+ * @param node the node to query
+ * @return the OpenFlow version to use
+ */
+ public String getOpenflowVersion(Node node);
+}
\ No newline at end of file
--- /dev/null
+/*
+ * Copyright (C) 2014 Red Hat, Inc.
+ *
+ * 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 : Dave Tucker
+ */
+package org.opendaylight.ovsdb.openstack.netvirt.api;
+
+import org.opendaylight.ovsdb.lib.notation.Version;
+
+/**
+ * A collection of configuration constants
+ */
+public final class Constants {
+
+ /*
+ * External ID's used by OpenStack Neutron
+ */
+ public static final String EXTERNAL_ID_VM_ID = "vm-id";
+ public static final String EXTERNAL_ID_INTERFACE_ID = "iface-id";
+ public static final String EXTERNAL_ID_VM_MAC = "attached-mac";
+
+ /*
+ * @see http://docs.openstack.org/grizzly/openstack-network/admin/content/ovs_quantum_plugin.html
+ */
+ public static final String TUNNEL_ENDPOINT_KEY = "local_ip";
+ public static final String INTEGRATION_BRIDGE = "br-int";
+ public static final String NETWORK_BRIDGE = "br-net";
+ public static final String EXTERNAL_BRIDGE = "br-ex";
+ public static final String PATCH_PORT_TO_INTEGRATION_BRIDGE_NAME = "patch-int";
+ public static final String PATCH_PORT_TO_NETWORK_BRIDGE_NAME = "patch-net";
+ public static final String PROVIDER_MAPPINGS_KEY = "provider_mappings";
+ public static final String PROVIDER_MAPPING = "physnet1:eth1";
+
+ /*
+ * Flow Priority Defaults
+ */
+ public static final int LLDP_PRIORITY = 1000;
+ public static final int NORMAL_PRIORITY = 0;
+
+ /*
+ * OpenFlow Versions
+ */
+ public static final String OPENFLOW10 = "OpenFlow10";
+ public static final String OPENFLOW13 = "OpenFlow13";
+ public static final Version OPENFLOW13_SUPPORTED = Version.fromString("1.10.0");
+
+ /*
+ * VLAN Constants
+ */
+ public static final int MAX_VLAN = 4094;
+
+ /*
+ * OSGi Service Properties
+ */
+ public static final String SOUTHBOUND_PROTOCOL_PROPERTY = "southboundProtocol";
+ public static final String PROVIDER_TYPE_PROPERTY = "providerType";
+ public static final String OPENFLOW_VERSION_PROPERTY = "openflowVersion";
+}
* Authors : Dave Tucker
*/
-package org.opendaylight.ovsdb.neutron.provider;
+package org.opendaylight.ovsdb.openstack.netvirt.api;
import org.opendaylight.controller.networkconfig.neutron.NeutronNetwork;
import org.opendaylight.controller.sal.core.Node;
import org.opendaylight.controller.sal.utils.Status;
import org.opendaylight.ovsdb.schema.openvswitch.Interface;
-public interface NetworkProvider {
-
- public static final int LLDP_PRIORITY = 1000;
- public static final int NORMAL_PRIORITY = 0;
+/**
+ * The NetworkingProvider interface is implemented by Neutron Networking Providers
+ */
+public interface NetworkingProvider {
+ /**
+ * Return true if the provider supports per-tenant or "static" tunneling
+ */
public boolean hasPerTenantTunneling();
+
+ /**
+ * Handle Interface Update Callback Method
+ */
public Status handleInterfaceUpdate(String tunnelType, String tunnelKey);
+
+ /**
+ * Handle Interface Update Callback Method
+ */
public Status handleInterfaceUpdate(NeutronNetwork network, Node source, Interface intf);
+
+ /**
+ * Handle Interface Delete Callback Method
+ */
public Status handleInterfaceDelete(String tunnelType, NeutronNetwork network, Node source, Interface intf, boolean isLastInstanceOnNode);
- /*
+
+ /**
* Initialize the Flow rules given the OVSDB node.
* This method provides a set of common functionalities to initialize the Flow rules of an OVSDB node
* that are Openflow Version specific. Hence we have this method in addition to the following
*/
public void initializeFlowRules(Node node);
- /*
- * Initialize the Flow rules given the Openflow node
+ /**
+ * Initialize the Flow rules for a given OpenFlow node
*/
public void initializeOFFlowRules(Node openflowNode);
+
}
--- /dev/null
+/*
+ * Copyright (C) 2014 Red Hat, Inc.
+ *
+ * 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 : Dave Tucker
+ */
+
+package org.opendaylight.ovsdb.openstack.netvirt.api;
+
+import org.opendaylight.controller.sal.core.Node;
+
+/**
+ * The NetworkingProviderManager handles the mapping between {@link org.opendaylight.controller.sal.core.Node}
+ * and registered {@link org.opendaylight.ovsdb.openstack.netvirt.api.NetworkingProvider} implementations
+ */
+public interface NetworkingProviderManager {
+ /**
+ * Returns the Networking Provider for a given node
+ * @param node a {@link org.opendaylight.controller.sal.core.Node}
+ * @return a NetworkProvider
+ * @see NetworkingProvider
+ */
+ NetworkingProvider getProvider(Node node);
+}
--- /dev/null
+/*
+ * Copyright (C) 2014 Red Hat, Inc.
+ *
+ * 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 : Dave Tucker
+ */
+
+package org.opendaylight.ovsdb.openstack.netvirt.api;
+
+import org.opendaylight.controller.networkconfig.neutron.NeutronNetwork;
+import org.opendaylight.controller.sal.core.Node;
+import org.opendaylight.ovsdb.schema.openvswitch.Interface;
+
+/**
+ * Open vSwitch isolates Tenant Networks using VLANs on the Integration Bridge
+ * This class manages the provisioning of these VLANs
+ */
+public interface TenantNetworkManager {
+
+ /**
+ * Get the VLAN assigned to the provided Network
+ * @param node the {@link org.opendaylight.controller.sal.core.Node} to query
+ * @param networkId the Neutron Network ID
+ * @return the assigned VLAN ID or 0 in case of an error
+ */
+ public int getInternalVlan(Node node, String networkId);
+
+ /**
+ * Reclaim the assigned VLAN for the given Network
+ * @param node the {@link org.opendaylight.controller.sal.core.Node} to query
+ * @param portUUID the UUID of the neutron Port
+ * @param network the Neutron Network ID
+ */
+ public void reclaimInternalVlan(Node node, String portUUID, NeutronNetwork network);
+
+ /**
+ * Configures the VLAN for a Tenant Network
+ * @param node the {@link org.opendaylight.controller.sal.core.Node} to configure
+ * @param portUUID the UUID of the port to configure
+ * @param network the Neutron Network ID
+ */
+ public void programInternalVlan(Node node, String portUUID, NeutronNetwork network);
+
+ /**
+ * Check is the given network is present on a Node
+ * @param node the {@link org.opendaylight.controller.sal.core.Node} to query
+ * @param segmentationId the Neutron Segementation ID
+ * @return True or False
+ */
+ public boolean isTenantNetworkPresentInNode(Node node, String segmentationId);
+
+ /**
+ * Get the Neutron Network ID for a given Segmentation ID
+ */
+ public String getNetworkId (String segmentationId);
+
+ /**
+ * Get the {@link org.opendaylight.controller.networkconfig.neutron.NeutronNetwork} for a given Interface
+ */
+ public NeutronNetwork getTenantNetwork(Interface intf);
+
+ /**
+ * Network Created Callback
+ */
+ @Deprecated
+ public void networkCreated (String networkId);
+
+ /**
+ * Network Created Callback
+ */
+ public int networkCreated (Node node, String networkId);
+
+ /**
+ * Network Deleted Callback
+ */
+ public void networkDeleted(String id);
+}
\ No newline at end of file
--- /dev/null
+/*
+ * Copyright (C) 2013 Red Hat, Inc.
+ *
+ * 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
+ */
+
+package org.opendaylight.ovsdb.openstack.netvirt.api;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.UUID;
+
+/**
+ * Utilities for validating and converting OpenStack UUID's
+ */
+public final class UuidUtils {
+
+ /**
+ * Neutron UUID identifier length.
+ */
+ private static final int UUID_LEN = 36;
+
+ /**
+ * Tenant id length when keystone identifier is used in neutron.
+ */
+ private static final int KEYSTONE_ID_LEN = 32;
+
+ /**
+ * UUID version number position.
+ */
+ private static final int UUID_VERSION_POS = 12;
+
+ /**
+ * UUID time-low field byte length in hex.
+ */
+ private static final int UUID_TIME_LOW = 8;
+
+ /**
+ * UUID time-mid field byte length in hex.
+ */
+ private static final int UUID_TIME_MID = 4;
+
+ /**
+ * UUID time-high and version field byte length in hex.
+ */
+ private static final int UUID_TIME_HIGH_VERSION = 4;
+
+ /**
+ * UUID clock sequence field byte length in hex.
+ */
+ private static final int UUID_CLOCK_SEQ = 4;
+
+ /**
+ * UUID node field byte length in hex.
+ */
+ private static final int UUID_NODE = 12;
+
+ /**
+ * UUID time field byte length in hex.
+ */
+ private static final int UUID_TIME_LEN = (UUID_TIME_LOW +
+ UUID_TIME_MID + UUID_TIME_HIGH_VERSION);
+
+ static final Logger logger = LoggerFactory.getLogger(UuidUtils.class);
+
+ /**
+ * Convert neutron object id to key syntax.
+ *
+ * @param neutronID neutron object id.
+ * @return key in compliance to object key.
+ */
+ public static String convertNeutronIDToKey(String neutronID) {
+ String key;
+ if (neutronID == null) {
+ return null;
+ }
+
+ logger.trace(" neutronID - {}, length - {} ",
+ neutronID, neutronID.length());
+ if (!isValidNeutronID(neutronID)) {
+ return null;
+ }
+
+ if (neutronID.length() == UUID_LEN) {
+ key = convertUUIDToKey(neutronID);
+ } else if (neutronID.length() == KEYSTONE_ID_LEN) {
+ key = convertKeystoneIDToKey(neutronID);
+ } else {
+ key = neutronID;
+ }
+ return key;
+ }
+
+ /**
+ * Verify the validity of neutron object identifiers.
+ *
+ * @param id neutron object id.
+ * @return {@code true} neutron identifier is valid.
+ * {@code false} neutron identifier is invalid.
+ */
+ public static boolean isValidNeutronID(String id) {
+ if (id == null) {
+ return false;
+ }
+ boolean isValid;
+ logger.trace("id - {}, length - {} ", id, id.length());
+ /**
+ * check the string length
+ * if length is 36 its a uuid do uuid validation
+ * if length is 32 it can be tenant id form keystone
+ * if its less than 32 can be valid ID
+ */
+ if (id.length() == UUID_LEN) {
+ try {
+ UUID fromUUID = UUID.fromString(id);
+ String toUUID = fromUUID.toString();
+ isValid = toUUID.equalsIgnoreCase(id);
+ } catch(IllegalArgumentException e) {
+ logger.error(" IllegalArgumentExecption for id - {} ", id);
+ isValid = false;
+ }
+ } else {
+ isValid = (id.length() > 0) && (id.length() <= KEYSTONE_ID_LEN);
+ }
+ return isValid;
+ }
+
+ /**
+ * Convert UUID to key syntax.
+ *
+ * @param id neutron object UUID.
+ * @return key in compliance to object key.
+ */
+ private static String convertUUIDToKey(String id) {
+
+ String key;
+ if (id == null) {
+ return null;
+ }
+ logger.trace("id - {}, length - {} ", id, id.length());
+ /**
+ * ID must be less than 32 bytes,
+ * Shorten UUID string length from 36 to 31 as follows:
+ * delete UUID Version and hyphen (see RFC4122) field in the UUID
+ */
+ try {
+ StringBuilder tKey = new StringBuilder();
+ // remove all the '-'
+ for (String retkey: id.split("-")) {
+ tKey.append(retkey);
+ }
+ // remove the version byte
+ tKey.deleteCharAt(UUID_VERSION_POS);
+ key = tKey.toString();
+ } catch(IllegalArgumentException ile) {
+ logger.error(" Invalid UUID - {} ", id);
+ key = null;
+ }
+ return key;
+ }
+
+ /**
+ * Convert string id to key syntax.
+ *
+ * @param id neutron object id.
+ * @return key in compliance to object key.
+ */
+ private static String convertKeystoneIDToKey(String id) {
+ String key = null;
+ if (id == null) {
+ return null;
+ }
+
+ /**
+ * tenant ID if given from openstack keystone does not follow the
+ * generic UUID syntax, convert the ID to UUID format for validation
+ * and reconvert it to key
+ */
+
+ logger.trace(" id - {}, length - {} ", id, id.length());
+ try {
+ StringBuilder tKey = new StringBuilder();
+ String tmpStr = id.substring(0, UUID_TIME_LOW);
+ tKey.append(tmpStr);
+ tKey.append("-");
+ tmpStr = id.substring(UUID_TIME_LOW,
+ (UUID_TIME_LOW + UUID_TIME_MID));
+ tKey.append(tmpStr);
+ tKey.append("-");
+ tmpStr = id.substring((UUID_TIME_LOW + UUID_TIME_MID),
+ UUID_TIME_LEN);
+ tKey.append(tmpStr);
+ tKey.append("-");
+ tmpStr = id.substring(UUID_TIME_LEN,
+ (UUID_TIME_LEN + UUID_CLOCK_SEQ));
+ tKey.append(tmpStr);
+ tKey.append("-");
+ tmpStr = id.substring((UUID_TIME_LEN + UUID_CLOCK_SEQ),
+ (UUID_TIME_LEN + UUID_CLOCK_SEQ + UUID_NODE));
+ tKey.append(tmpStr);
+
+ tmpStr = tKey.toString();
+ UUID fromUUID = UUID.fromString(tmpStr);
+ String toUUID = fromUUID.toString();
+ if (toUUID.equalsIgnoreCase(tmpStr)) {
+ key = convertUUIDToKey(tmpStr);
+ }
+ } catch(IndexOutOfBoundsException ibe) {
+ logger.error(" Exception! Invalid UUID - {} ", id);
+ key = null;
+ } catch (IllegalArgumentException iae) {
+ logger.error(" Exception! Invalid object ID - {} ", id);
+ key = null;
+ }
+ return key;
+ }
+
+}
--- /dev/null
+/*
+ * Copyright (C) 2014 Red Hat, Inc.
+ *
+ * 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 : Dave Tucker
+ */
+
+package org.opendaylight.ovsdb.openstack.netvirt.api;
+
+import org.opendaylight.controller.sal.core.Node;
+
+/**
+ * This cache stores the VLAN assignments used for tenant separation within a vSwitch
+ * An assignment consists of a VLAN ID and a tenant network ID.
+ */
+public interface VlanConfigurationCache {
+
+ /**
+ * Assigns a free VLAN ID for the given tenant network
+ * @param node an Open vSwitch {@link org.opendaylight.controller.sal.core.Node}
+ * @param networkId the Neutron Network ID
+ * @return a VLAN ID or 0 in case of an error
+ */
+ public Integer assignInternalVlan (Node node, String networkId);
+
+ /**
+ * Recovers an assigned VLAN ID when it is no longer required
+ * @param node an Open vSwitch {@link org.opendaylight.controller.sal.core.Node}
+ * @param networkId the Neutron Network ID
+ * @return the reclaimed VLAN ID or 0 in case of an error
+ */
+ public Integer reclaimInternalVlan (Node node, String networkId);
+
+ /**
+ * Returns a VLAN ID assigned to a given tenant network
+ * @param node an Open vSwitch {@link org.opendaylight.controller.sal.core.Node}
+ * @param networkId the Neutron Network ID
+ * @return the VLAN ID or 0 in case of an error
+ */
+ public Integer getInternalVlan (Node node, String networkId);
+}
--- /dev/null
+/*
+ * Copyright (C) 2013 Red Hat, Inc.
+ *
+ * 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
+ */
+package org.opendaylight.ovsdb.openstack.netvirt.impl;
+
+import org.opendaylight.controller.networkconfig.neutron.NeutronNetwork;
+import org.opendaylight.controller.sal.core.Node;
+import org.opendaylight.controller.sal.utils.Status;
+import org.opendaylight.controller.sal.utils.StatusCode;
+import org.opendaylight.ovsdb.lib.error.SchemaVersionMismatchException;
+import org.opendaylight.ovsdb.lib.notation.Row;
+import org.opendaylight.ovsdb.lib.notation.UUID;
+import org.opendaylight.ovsdb.openstack.netvirt.NetworkHandler;
+import org.opendaylight.ovsdb.openstack.netvirt.api.BridgeConfigurationManager;
+import org.opendaylight.ovsdb.openstack.netvirt.api.ConfigurationService;
+import org.opendaylight.ovsdb.openstack.netvirt.api.Constants;
+import org.opendaylight.ovsdb.openstack.netvirt.api.NetworkingProviderManager;
+import org.opendaylight.ovsdb.plugin.OvsdbConfigService;
+import org.opendaylight.ovsdb.plugin.StatusWithUuid;
+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 com.google.common.base.Preconditions;
+import com.google.common.collect.Lists;
+import com.google.common.collect.Maps;
+import org.apache.commons.lang3.tuple.ImmutablePair;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+public class BridgeConfigurationManagerImpl implements BridgeConfigurationManager {
+ static final Logger logger = LoggerFactory.getLogger(BridgeConfigurationManagerImpl.class);
+
+ // The implementation for each of these services is resolved by the OSGi Service Manager
+ private volatile ConfigurationService configurationService;
+ private volatile NetworkingProviderManager networkingProviderManager;
+ private volatile OvsdbConfigService ovsdbConfigService;
+
+ public BridgeConfigurationManagerImpl() {
+ }
+
+ @Override
+ public String getBridgeUuid(Node node, String bridgeName) {
+ Preconditions.checkNotNull(ovsdbConfigService);
+ try {
+ Map<String, Row> bridgeTable =
+ ovsdbConfigService.getRows(node, ovsdbConfigService.getTableName(node, Bridge.class));
+ if (bridgeTable == null) return null;
+ for (String key : bridgeTable.keySet()) {
+ Bridge bridge = ovsdbConfigService.getTypedRow(node, Bridge.class, bridgeTable.get(key));
+ if (bridge.getName().equals(bridgeName)) return key;
+ }
+ } catch (Exception e) {
+ logger.error("Error getting Bridge Identifier for {} / {}", node, bridgeName, e);
+ }
+ return null;
+ }
+
+ @Override
+ public boolean isNodeNeutronReady(Node node) {
+ Preconditions.checkNotNull(configurationService);
+ return this.getBridgeUuid(node, configurationService.getIntegrationBridgeName()) != null;
+ }
+
+ @Override
+ public boolean isNodeOverlayReady(Node node) {
+ Preconditions.checkNotNull(configurationService);
+ return this.isNodeNeutronReady(node)
+ && this.getBridgeUuid(node, configurationService.getNetworkBridgeName()) != null;
+ }
+
+ @Override
+ public boolean isPortOnBridge (Node node, Bridge bridge, String portName) {
+ Preconditions.checkNotNull(ovsdbConfigService);
+ for (UUID portsUUID : bridge.getPortsColumn().getData()) {
+ try {
+ Row portRow = ovsdbConfigService.getRow(node,
+ ovsdbConfigService.getTableName(node, Port.class),
+ portsUUID.toString());
+
+ Port port = ovsdbConfigService.getTypedRow(node, Port.class, portRow);
+ if ((port != null) && port.getName().equalsIgnoreCase(portName)) {
+ return true;
+ }
+ } catch (Exception e) {
+ logger.error("Error getting port {} for bridge domain {}/{}", portsUUID, node, bridge.getName(), e);
+ }
+ }
+
+ return false;
+ }
+
+ @Override
+ public boolean isNodeTunnelReady(Node node) {
+ Preconditions.checkNotNull(configurationService);
+ Preconditions.checkNotNull(networkingProviderManager);
+
+ /* Is br-int created? */
+ Bridge intBridge = this.getBridge(node, configurationService.getIntegrationBridgeName());
+ if (intBridge == null) {
+ return false;
+ }
+
+ if (networkingProviderManager == null) {
+ logger.error("Provider Network Manager is not available");
+ return false;
+ }
+ if (networkingProviderManager.getProvider(node).hasPerTenantTunneling()) {
+ /* Is br-net created? */
+ Bridge netBridge = this.getBridge(node, configurationService.getNetworkBridgeName());
+ if (netBridge == null) {
+ return false;
+ }
+
+ if (!isNetworkPatchCreated(node, intBridge, netBridge)) {
+ return false;
+ }
+ }
+ return true;
+ }
+
+ @Override
+ public boolean isNodeVlanReady(Node node, NeutronNetwork network) {
+ Preconditions.checkNotNull(configurationService);
+ Preconditions.checkNotNull(networkingProviderManager);
+
+ /* is br-int created */
+ Bridge intBridge = this.getBridge(node, configurationService.getIntegrationBridgeName());
+ if (intBridge == null) {
+ logger.trace("isNodeVlanReady: node: {}, br-int missing", node);
+ return false;
+ }
+
+ if (networkingProviderManager == null) {
+ logger.error("Provider Network Manager is not available");
+ return false;
+ }
+ if (networkingProviderManager.getProvider(node).hasPerTenantTunneling()) {
+ /* is br-net created? */
+ Bridge netBridge = this.getBridge(node, configurationService.getNetworkBridgeName());
+
+ if (netBridge == null) {
+ logger.trace("isNodeVlanReady: node: {}, br-net missing", node);
+ return false;
+ }
+
+ if (!isNetworkPatchCreated(node, intBridge, netBridge)) {
+ logger.trace("isNodeVlanReady: node: {}, patch missing", node);
+ return false;
+ }
+
+ /* Check if physical device is added to br-net. */
+ String phyNetName = this.getPhysicalInterfaceName(node, network.getProviderPhysicalNetwork());
+ if (isPortOnBridge(node, netBridge, phyNetName)) {
+ return true;
+ }
+ } else {
+ /* Check if physical device is added to br-int. */
+ String phyNetName = this.getPhysicalInterfaceName(node, network.getProviderPhysicalNetwork());
+ if (isPortOnBridge(node, intBridge, phyNetName)) {
+ return true;
+ }
+ }
+
+ logger.trace("isNodeVlanReady: node: {}, eth missing", node);
+ return false;
+ }
+
+ @Override
+ public void prepareNode(Node node) {
+ Preconditions.checkNotNull(networkingProviderManager);
+
+ try {
+ this.createIntegrationBridge(node);
+ } catch (Exception e) {
+ logger.error("Error creating Integration Bridge on " + node.toString(), e);
+ return;
+ }
+ if (networkingProviderManager == null) {
+ logger.error("Error creating internal network. Provider Network Manager unavailable");
+ return;
+ }
+ networkingProviderManager.getProvider(node).initializeFlowRules(node);
+ }
+
+ /*
+ * Check if the full network setup is available. If not, create it.
+ */
+ @Override
+ public boolean createLocalNetwork (Node node, NeutronNetwork network) {
+ boolean isCreated = false;
+ if (network.getProviderNetworkType().equalsIgnoreCase(NetworkHandler.NETWORK_TYPE_VLAN)) {
+ if (!this.isNodeVlanReady(node, network)) {
+ try {
+ isCreated = this.createBridges(node, network);
+ } catch (Exception e) {
+ logger.error("Error creating internal net network ", node, e);
+ }
+ } else {
+ isCreated = true;
+ }
+ } else if (network.getProviderNetworkType().equalsIgnoreCase(NetworkHandler.NETWORK_TYPE_VXLAN) ||
+ network.getProviderNetworkType().equalsIgnoreCase(NetworkHandler.NETWORK_TYPE_GRE)) {
+ if (!this.isNodeTunnelReady(node)) {
+ try {
+ isCreated = this.createBridges(node, network);
+ } catch (Exception e) {
+ logger.error("Error creating internal net network ", node, e);
+ }
+ } else {
+ isCreated = true;
+ }
+ }
+ return isCreated;
+ }
+
+ @Override
+ public String getPhysicalInterfaceName (Node node, String physicalNetwork) {
+ String phyIf = null;
+ try {
+ Map<String, Row> ovsTable =
+ ovsdbConfigService.getRows(node, ovsdbConfigService.getTableName(node, OpenVSwitch.class));
+
+ if (ovsTable == null) {
+ logger.error("OpenVSwitch table is null for Node {} ", node);
+ return null;
+ }
+
+ // Loop through all the Open_vSwitch rows looking for the first occurrence of other_config.
+ // The specification does not restrict the number of rows so we choose the first we find.
+ for (Row row : ovsTable.values()) {
+ String providerMaps;
+ OpenVSwitch ovsRow = ovsdbConfigService.getTypedRow(node, OpenVSwitch.class, row);
+ Map<String, String> configs = ovsRow.getOtherConfigColumn().getData();
+
+ if (configs == null) {
+ logger.debug("OpenVSwitch table is null for Node {} ", node);
+ continue;
+ }
+
+ providerMaps = configs.get(configurationService.getProviderMappingsKey());
+ if (providerMaps == null) {
+ providerMaps = configurationService.getDefaultProviderMapping();
+ }
+
+ if (providerMaps != null) {
+ for (String map : providerMaps.split(",")) {
+ String[] pair = map.split(":");
+ if (pair[0].equals(physicalNetwork)) {
+ phyIf = pair[1];
+ break;
+ }
+ }
+ }
+
+ if (phyIf != null) {
+ break;
+ }
+ }
+ } catch (Exception e) {
+ logger.error("Unable to find physical interface for Node: {}, Network {}",
+ node, physicalNetwork, e);
+ }
+
+ if (phyIf == null) {
+ logger.error("Physical interface not found for Node: {}, Network {}",
+ node, physicalNetwork);
+ }
+
+ return phyIf;
+ }
+
+ @Override
+ public List<String> getAllPhysicalInterfaceNames(Node node) {
+ List<String> phyIfName = Lists.newArrayList();
+
+ try {
+ Map<String, Row> ovsTable =
+ ovsdbConfigService.getRows(node,ovsdbConfigService.getTableName(node, OpenVSwitch.class));
+
+ if (ovsTable == null) {
+ logger.error("OpenVSwitch table is null for Node {} ", node);
+ return null;
+ }
+
+ // While there is only one entry in the HashMap, we can't access it by index...
+ for (Row row : ovsTable.values()) {
+ String bridgeMaps;
+ OpenVSwitch ovsRow = ovsdbConfigService.getTypedRow(node, OpenVSwitch.class, row);
+ Map<String, String> configs = ovsRow.getOtherConfigColumn().getData();
+
+ if (configs == null) {
+ logger.debug("OpenVSwitch table is null for Node {} ", node);
+ continue;
+ }
+
+ bridgeMaps = configs.get(configurationService.getProviderMappingsKey());
+ if (bridgeMaps == null) {
+ bridgeMaps = configurationService.getDefaultProviderMapping();
+ }
+
+ if (bridgeMaps != null) {
+ for (String map : bridgeMaps.split(",")) {
+ String[] pair = map.split(":");
+ phyIfName.add(pair[1]);
+ }
+ }
+ }
+ } catch (Exception e) {
+ logger.error("Unable to find physical interface for Node: {}",
+ node, e);
+ }
+
+ logger.debug("Physical interface for Node: {}, If: {}",
+ node, phyIfName);
+
+ return phyIfName;
+ }
+
+ /**
+ * Returns the Bridge for a given node and bridgeName
+ */
+ public Bridge getBridge (Node node, String bridgeName) {
+ Preconditions.checkNotNull(ovsdbConfigService);
+ try {
+ Map<String, Row> bridgeTable =
+ ovsdbConfigService.getRows(node, ovsdbConfigService.getTableName(node, Bridge.class));
+ if (bridgeTable != null) {
+ for (String key : bridgeTable.keySet()) {
+ Bridge bridge = ovsdbConfigService.getTypedRow(node, Bridge.class, bridgeTable.get(key));
+ if (bridge.getName().equals(bridgeName)) {
+ return bridge;
+ }
+ }
+ }
+ } catch (Exception e) {
+ logger.error("Error getting Bridge Identifier for {} / {}", node, bridgeName, e);
+ }
+ return null;
+ }
+
+ /**
+ * Returns true if a patch port exists between the Integration Bridge and Network Bridge
+ */
+ private boolean isNetworkPatchCreated (Node node, Bridge intBridge, Bridge netBridge) {
+ Preconditions.checkNotNull(configurationService);
+
+ boolean isPatchCreated = false;
+
+ String portName = configurationService.getPatchPortName(new ImmutablePair<>(intBridge, netBridge));
+ if (isPortOnBridge(node, intBridge, portName)) {
+ portName = configurationService.getPatchPortName(new ImmutablePair<>(netBridge, intBridge));
+ if (isPortOnBridge(node, netBridge, portName)) {
+ isPatchCreated = true;
+ }
+ }
+
+ return isPatchCreated;
+ }
+
+ /**
+ * Creates the Integration Bridge
+ */
+ private void createIntegrationBridge (Node node) throws Exception {
+ Preconditions.checkNotNull(configurationService);
+
+ String brInt = configurationService.getIntegrationBridgeName();
+
+ Status status = this.addBridge(node, brInt, null, null);
+ if (!status.isSuccess()) {
+ logger.debug("Integration Bridge Creation Status: {}", status);
+ }
+ }
+
+ /**
+ * Create and configure bridges for all network types and OpenFlow versions.
+ *
+ OF 1.0 vlan:
+ Bridge br-int
+ Port patch-net
+ Interface patch-net
+ type: patch
+ options: {peer=patch-int}
+ Port br-int
+ Interface br-int
+ type: internal
+ Bridge br-net
+ Port "eth1"
+ Interface "eth1"
+ Port patch-int
+ Interface patch-int
+ type: patch
+ options: {peer=patch-net}
+ Port br-net
+ Interface br-net
+ type: internal
+
+ OF 1.0 tunnel:
+ Bridge br-int
+ Port patch-net
+ Interface patch-net
+ type: patch
+ options: {peer=patch-int}
+ Port br-int
+ Interface br-int
+ type: internal
+ Bridge "br-net"
+ Port patch-int
+ Interface patch-int
+ type: patch
+ options: {peer=patch-net}
+ Port br-net
+ Interface br-net
+ type: internal
+
+ OF 1.3 vlan:
+ Bridge br-int
+ Port "eth1"
+ Interface "eth1"
+ Port br-int
+ Interface br-int
+ type: internal
+
+ OF 1.3 tunnel:
+ Bridge br-int
+ Port br-int
+ Interface br-int
+ type: internal
+ */
+ private boolean createBridges(Node node, NeutronNetwork network) throws Exception {
+ Preconditions.checkNotNull(configurationService);
+ Preconditions.checkNotNull(networkingProviderManager);
+ Status status;
+
+ logger.debug("createBridges: node: {}, network type: {}", node, network.getProviderNetworkType());
+
+ if (networkingProviderManager == null) {
+ logger.error("Provider Network Manager is not available");
+ return false;
+ }
+ if (networkingProviderManager.getProvider(node).hasPerTenantTunneling()) { /* indicates OF 1.0 */
+ String brInt = configurationService.getIntegrationBridgeName();
+ String brNet = configurationService.getNetworkBridgeName();
+ String patchNet = configurationService.getPatchPortName(new ImmutablePair<>(brInt, brNet));
+ String patchInt = configurationService.getPatchPortName(new ImmutablePair<>(brNet, brInt));
+
+ status = this.addBridge(node, brInt, patchNet, patchInt);
+ if (!status.isSuccess()) {
+ logger.debug("{} Bridge Creation Status: {}", brInt, status);
+ return false;
+ }
+ status = this.addBridge(node, brNet, patchInt, patchNet);
+ if (!status.isSuccess()) {
+ logger.debug("{} Bridge Creation Status: {}", brNet, status);
+ return false;
+ }
+
+ /* For vlan network types add physical port to br-net. */
+ if (network.getProviderNetworkType().equalsIgnoreCase(NetworkHandler.NETWORK_TYPE_VLAN)) {
+ String phyNetName = this.getPhysicalInterfaceName(node, network.getProviderPhysicalNetwork());
+ status = addPortToBridge(node, brNet, phyNetName);
+ if (!status.isSuccess()) {
+ logger.debug("Add Port {} to Bridge {} Status: {}", phyNetName, brNet, status);
+ return false;
+ }
+ }
+ } else {
+ String brInt = configurationService.getIntegrationBridgeName();
+ status = this.addBridge(node, brInt, null, null);
+ if (!status.isSuccess()) {
+ logger.debug("{} Bridge Creation Status: {}", brInt, status);
+ return false;
+ }
+
+ /* For vlan network types add physical port to br-int. */
+ if (network.getProviderNetworkType().equalsIgnoreCase(NetworkHandler.NETWORK_TYPE_VLAN)) {
+ String phyNetName = this.getPhysicalInterfaceName(node, network.getProviderPhysicalNetwork());
+ status = addPortToBridge(node, brInt, phyNetName);
+ if (!status.isSuccess()) {
+ logger.debug("Add Port {} to Bridge {} Status: {}", phyNetName, brInt, status);
+ return false;
+ }
+ }
+ }
+
+ logger.debug("createNetNetwork: node: {}, status: success", node);
+ return true;
+ }
+
+ /**
+ * Add a Port to a Bridge
+ */
+ private Status addPortToBridge (Node node, String bridgeName, String portName) throws Exception {
+ Preconditions.checkNotNull(ovsdbConfigService);
+
+ logger.debug("addPortToBridge: Adding port: {} to Bridge {}, Node {}", portName, bridgeName, node);
+
+ String bridgeUUID = this.getBridgeUuid(node, bridgeName);
+ if (bridgeUUID == null) {
+ logger.error("addPortToBridge: Could not find Bridge {} in Node {}", bridgeName, node);
+ return new Status(StatusCode.NOTFOUND, "Could not find "+bridgeName+" in "+node);
+ }
+
+ /* Check if the port already exists. */
+ Row row = ovsdbConfigService.getRow(node, ovsdbConfigService.getTableName(node, Bridge.class), bridgeUUID);
+ Bridge bridge = ovsdbConfigService.getTypedRow(node, Bridge.class, row);
+ if (bridge != null) {
+ if (isPortOnBridge(node, bridge, portName)) {
+ logger.debug("addPortToBridge: Port {} already in Bridge {}, Node {}", portName, bridgeName, node);
+ return new Status(StatusCode.SUCCESS);
+ }
+ } else {
+ logger.error("addPortToBridge: Could not find Port {} in Bridge {}, Node {}", portName, bridgeName, node);
+ return new Status(StatusCode.NOTFOUND, "Could not find "+portName+" in "+bridgeName);
+ }
+
+ Port port = ovsdbConfigService.createTypedRow(node, Port.class);
+ port.setName(portName);
+ StatusWithUuid statusWithUuid =
+ ovsdbConfigService.insertRow(node, port.getSchema().getName(), bridgeUUID, port.getRow());
+ if (!statusWithUuid.isSuccess()) {
+ logger.error("addPortToBridge: Failed to add Port {} in Bridge {}, Node {}", portName, bridgeName, node);
+ return statusWithUuid;
+ }
+
+ String portUUID = statusWithUuid.getUuid().toString();
+ String interfaceUUID = null;
+ int timeout = 6;
+ while ((interfaceUUID == null) && (timeout > 0)) {
+ Row portRow = ovsdbConfigService.getRow(node, port.getSchema().getName(), portUUID);
+ port = ovsdbConfigService.getTypedRow(node, Port.class, portRow);
+ Set<UUID> interfaces = port.getInterfacesColumn().getData();
+ if (interfaces == null || interfaces.size() == 0) {
+ // Wait for the OVSDB update to sync up the Local cache.
+ Thread.sleep(500);
+ timeout--;
+ continue;
+ }
+ interfaceUUID = interfaces.toArray()[0].toString();
+ Row intf =ovsdbConfigService.getRow(node,
+ ovsdbConfigService.getTableName(node, Interface.class), interfaceUUID);
+ if (intf == null) {
+ interfaceUUID = null;
+ }
+ }
+
+ if (interfaceUUID == null) {
+ logger.error("addPortToBridge: Cannot identify Interface for port {}/{}", portName, portUUID);
+ return new Status(StatusCode.INTERNALERROR);
+ }
+
+ return new Status(StatusCode.SUCCESS);
+ }
+
+ /**
+ * Add a Patch Port to a Bridge
+ */
+ private Status addPatchPort (Node node, String bridgeUUID, String portName, String peerPortName) throws Exception {
+ Preconditions.checkNotNull(ovsdbConfigService);
+
+ logger.debug("addPatchPort: node: {}, bridgeUUID: {}, port: {}, peer: {}",
+ node, bridgeUUID, portName, peerPortName);
+
+ /* Check if the port already exists. */
+ Row bridgeRow = ovsdbConfigService.getRow(node,
+ ovsdbConfigService.getTableName(node, Bridge.class), bridgeUUID);
+ Bridge bridge = ovsdbConfigService.getTypedRow(node, Bridge.class, bridgeRow);
+ if (bridge != null) {
+ if (isPortOnBridge(node, bridge, portName)) {
+ logger.debug("addPatchPort: Port {} already in Bridge, Node {}", portName, node);
+ return new Status(StatusCode.SUCCESS);
+ }
+ } else {
+ logger.error("addPatchPort: Could not find Port {} in Bridge, Node {}", portName, node);
+ return new Status(StatusCode.NOTFOUND, "Could not find "+portName+" in Bridge");
+ }
+
+ Port patchPort = ovsdbConfigService.createTypedRow(node, Port.class);
+ patchPort.setName(portName);
+ // Create patch port and interface
+ StatusWithUuid statusWithUuid =
+ ovsdbConfigService.insertRow(node, patchPort.getSchema().getName(), bridgeUUID, patchPort.getRow());
+ if (!statusWithUuid.isSuccess()) return statusWithUuid;
+
+ String patchPortUUID = statusWithUuid.getUuid().toString();
+
+ String interfaceUUID = null;
+ int timeout = 6;
+ while ((interfaceUUID == null) && (timeout > 0)) {
+ Row portRow = ovsdbConfigService.getRow(node, patchPort.getSchema().getName(), patchPortUUID);
+ patchPort = ovsdbConfigService.getTypedRow(node, Port.class, portRow);
+ Set<UUID> interfaces = patchPort.getInterfacesColumn().getData();
+ if (interfaces == null || interfaces.size() == 0) {
+ // Wait for the OVSDB update to sync up the Local cache.
+ Thread.sleep(500);
+ timeout--;
+ continue;
+ }
+ interfaceUUID = interfaces.toArray()[0].toString();
+ }
+
+ if (interfaceUUID == null) {
+ return new Status(StatusCode.INTERNALERROR);
+ }
+
+ Interface intf = ovsdbConfigService.createTypedRow(node, Interface.class);
+ intf.setType("patch");
+ Map<String, String> options = Maps.newHashMap();
+ options.put("peer", peerPortName);
+ intf.setOptions(options);
+ return ovsdbConfigService.updateRow(node,
+ intf.getSchema().getName(),
+ patchPortUUID,
+ interfaceUUID,
+ intf.getRow());
+ }
+
+ /**
+ * Add Bridge to a Node
+ */
+ private Status addBridge(Node node, String bridgeName,
+ String localPatchName, String remotePatchName) throws Exception {
+ Preconditions.checkNotNull(ovsdbConfigService);
+
+ String bridgeUUID = this.getBridgeUuid(node, bridgeName);
+ Bridge bridge = ovsdbConfigService.createTypedRow(node, Bridge.class);
+ Set<String> failMode = new HashSet<>();
+ failMode.add("secure");
+ bridge.setFailMode(failMode);
+
+ Set<String> protocols = new HashSet<>();
+ if (networkingProviderManager == null) {
+ logger.error("Provider Network Manager is not available");
+ return new Status(StatusCode.INTERNALERROR);
+ }
+
+ /* ToDo: Plugin should expose an easy way to get the OVS Version or Schema Version
+ * or, alternatively it should not attempt to add set unsupported fields
+ */
+
+ try {
+ if (!networkingProviderManager.getProvider(node).hasPerTenantTunneling()) {
+ protocols.add(Constants.OPENFLOW13);
+ } else {
+ protocols.add(Constants.OPENFLOW10);
+ }
+ bridge.setProtocols(protocols);
+ } catch (SchemaVersionMismatchException e) {
+ logger.info(e.toString());
+ }
+
+ if (bridgeUUID == null) {
+ bridge.setName(bridgeName);
+
+ StatusWithUuid statusWithUuid = ovsdbConfigService.insertRow(node,
+ bridge.getSchema().getName(),
+ null,
+ bridge.getRow());
+ if (!statusWithUuid.isSuccess()) return statusWithUuid;
+ bridgeUUID = statusWithUuid.getUuid().toString();
+ Port port = ovsdbConfigService.createTypedRow(node, Port.class);
+ port.setName(bridgeName);
+ Status status = ovsdbConfigService.insertRow(node, port.getSchema().getName(), bridgeUUID, port.getRow());
+ logger.debug("addBridge: Inserting Bridge {} {} with protocols {} and status {}",
+ bridgeName, bridgeUUID, protocols, status);
+ } else {
+ Status status = ovsdbConfigService.updateRow(node,
+ bridge.getSchema().getName(),
+ null,
+ bridgeUUID,
+ bridge.getRow());
+ logger.debug("addBridge: Updating Bridge {} {} with protocols {} and status {}",
+ bridgeName, bridgeUUID, protocols, status);
+ }
+
+ ovsdbConfigService.setOFController(node, bridgeUUID);
+
+ if (localPatchName != null &&
+ remotePatchName != null &&
+ networkingProviderManager.getProvider(node).hasPerTenantTunneling()) {
+ return addPatchPort(node, bridgeUUID, localPatchName, remotePatchName);
+ }
+ return new Status(StatusCode.SUCCESS);
+ }
+
+
+}
--- /dev/null
+/*
+ * Copyright (C) 2013 Red Hat, Inc.
+ *
+ * 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.impl;
+
+import org.opendaylight.controller.sal.core.Node;
+import org.opendaylight.ovsdb.lib.notation.Row;
+import org.opendaylight.ovsdb.lib.notation.Version;
+import org.opendaylight.ovsdb.openstack.netvirt.api.ConfigurationService;
+import org.opendaylight.ovsdb.openstack.netvirt.api.Constants;
+import org.opendaylight.ovsdb.plugin.OvsdbConfigService;
+import org.opendaylight.ovsdb.schema.openvswitch.OpenVSwitch;
+
+import com.google.common.collect.Maps;
+import org.apache.commons.lang3.tuple.ImmutablePair;
+import org.apache.commons.lang3.tuple.Pair;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.net.InetAddress;
+import java.util.Map;
+import java.util.Set;
+
+public class ConfigurationServiceImpl implements ConfigurationService {
+ static final Logger logger = LoggerFactory.getLogger(ConfigurationServiceImpl.class);
+
+ private volatile OvsdbConfigService ovsdbConfigService;
+
+ private String integrationBridgeName;
+ private String networkBridgeName;
+ private String externalBridgeName;
+ private String tunnelEndpointKey;
+
+ private Map<Pair<String, String>, String> patchPortNames = Maps.newHashMap();
+ private String providerMappingsKey;
+ private String providerMapping;
+
+ public ConfigurationServiceImpl() {
+ tunnelEndpointKey = Constants.TUNNEL_ENDPOINT_KEY;
+ integrationBridgeName = Constants.INTEGRATION_BRIDGE;
+ networkBridgeName = Constants.NETWORK_BRIDGE;
+ externalBridgeName = Constants.EXTERNAL_BRIDGE;
+ patchPortNames.put(new ImmutablePair<>(integrationBridgeName, networkBridgeName),
+ Constants.PATCH_PORT_TO_NETWORK_BRIDGE_NAME);
+ patchPortNames.put(new ImmutablePair<>(networkBridgeName, integrationBridgeName),
+ Constants.PATCH_PORT_TO_INTEGRATION_BRIDGE_NAME);
+ providerMappingsKey = Constants.PROVIDER_MAPPINGS_KEY;
+ providerMapping = Constants.PROVIDER_MAPPING;
+ }
+
+ @Override
+ public String getIntegrationBridgeName() {
+ return integrationBridgeName;
+ }
+
+ @Override
+ public void setIntegrationBridgeName(String integrationBridgeName) {
+ this.integrationBridgeName = integrationBridgeName;
+ }
+
+ @Override
+ public String getNetworkBridgeName() {
+ return networkBridgeName;
+ }
+
+ @Override
+ public void setNetworkBridgeName(String networkBridgeName) {
+ this.networkBridgeName = networkBridgeName;
+ }
+
+ @Override
+ public String getExternalBridgeName() {
+ return externalBridgeName;
+ }
+
+ @Override
+ public void setExternalBridgeName(String externalBridgeName) {
+ this.externalBridgeName = externalBridgeName;
+ }
+
+ @Override
+ public String getTunnelEndpointKey() {
+ return tunnelEndpointKey;
+ }
+
+ @Override
+ public void setTunnelEndpointKey(String tunnelEndpointKey) {
+ this.tunnelEndpointKey = tunnelEndpointKey;
+ }
+
+ @Override
+ public String getProviderMappingsKey() {
+ return providerMappingsKey;
+ }
+
+ @Override
+ public void setProviderMappingsKey(String providerMappingsKey) {
+ this.providerMappingsKey = providerMappingsKey;
+ }
+
+ @Override
+ public Map<Pair<String, String>, String> getPatchPortNames() {
+ return patchPortNames;
+ }
+
+ @Override
+ public void setPatchPortNames(Map<Pair<String, String>, String> patchPortNames) {
+ this.patchPortNames = patchPortNames;
+ }
+
+ public String getPatchPortName(Pair portTuple){
+ return this.patchPortNames.get(portTuple);
+ }
+
+ @Override
+ public String getDefaultProviderMapping() {
+ return providerMapping;
+ }
+
+ @Override
+ public void setDefaultProviderMapping(String providerMapping) {
+ this.providerMapping = providerMapping;
+ }
+
+ @Override
+ public InetAddress getTunnelEndPoint(Node node) {
+ InetAddress address = null;
+ try {
+ Map<String, Row> ovsTable = ovsdbConfigService.getRows(node,
+ ovsdbConfigService.getTableName(node, OpenVSwitch.class));
+
+ if (ovsTable == null) {
+ logger.error("OpenVSwitch table is null for Node {} ", node);
+ return null;
+ }
+
+ // While there is only one entry in the HashMap, we can't access it by index...
+ for (Row row : ovsTable.values()) {
+ OpenVSwitch ovsRow = ovsdbConfigService.getTypedRow(node, OpenVSwitch.class, row);
+ Map<String, String> configs = ovsRow.getOtherConfigColumn().getData();
+
+ if (configs == null) {
+ logger.debug("OpenVSwitch table is null for Node {} ", node);
+ continue;
+ }
+
+ String tunnelEndpoint = configs.get(tunnelEndpointKey);
+
+ if (tunnelEndpoint == null) {
+ continue;
+ }
+
+ address = InetAddress.getByName(tunnelEndpoint);
+ logger.debug("Tunnel Endpoint for Node {} {}", node, address.getHostAddress());
+ break;
+ }
+ }
+ catch (Exception e) {
+ logger.error("Error populating Tunnel Endpoint for Node {} ", node, e);
+ }
+
+ return address;
+ }
+
+ @Override
+ public String getOpenflowVersion(Node node) {
+
+ String configuredVersion = System.getProperty("ovsdb.of.version");
+ if (configuredVersion != null){
+ switch (configuredVersion){
+ case "1.0":
+ return Constants.OPENFLOW10;
+ case "1.3":
+ //fall through
+ default:
+ return Constants.OPENFLOW13;
+
+ }
+ }
+
+ Map<String, Row> ovsRows = ovsdbConfigService.getRows(node,
+ ovsdbConfigService.getTableName(node, OpenVSwitch.class));
+
+ if (ovsRows == null) {
+ logger.info("The OVS node {} has no Open_vSwitch rows", node.toString());
+ return null;
+ }
+
+ Version ovsVersion = null;
+ // While there is only one entry in the HashMap, we can't access it by index...
+ for (Row row : ovsRows.values()) {
+ OpenVSwitch ovsRow = ovsdbConfigService.getTypedRow(node, OpenVSwitch.class, row);
+ Set<String> versionSet = ovsRow.getOvsVersionColumn().getData();
+ if (versionSet != null && versionSet.iterator().hasNext()) {
+ ovsVersion = Version.fromString(versionSet.iterator().next());
+ }
+ }
+
+ if (ovsVersion == null || ovsVersion.compareTo(Constants.OPENFLOW13_SUPPORTED) < 0) {
+ return Constants.OPENFLOW10;
+ }
+
+ return Constants.OPENFLOW13;
+ }
+}
--- /dev/null
+/*
+ * Copyright (C) 2013 Red Hat, Inc.
+ *
+ * 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, Dave Tucker
+ */
+package org.opendaylight.ovsdb.openstack.netvirt.impl;
+
+import org.opendaylight.controller.sal.core.Node;
+import org.opendaylight.ovsdb.openstack.netvirt.api.ConfigurationService;
+import org.opendaylight.ovsdb.openstack.netvirt.api.Constants;
+import org.opendaylight.ovsdb.openstack.netvirt.api.NetworkingProvider;
+import org.opendaylight.ovsdb.openstack.netvirt.api.NetworkingProviderManager;
+
+import com.google.common.base.Preconditions;
+import com.google.common.base.Predicate;
+import com.google.common.collect.Iterables;
+import com.google.common.collect.Maps;
+import org.osgi.framework.ServiceReference;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.HashMap;
+import java.util.Map;
+
+public class ProviderNetworkManagerImpl implements NetworkingProviderManager {
+
+ static final Logger logger = LoggerFactory.getLogger(ProviderNetworkManagerImpl.class);
+ // The provider for each of these services is resolved by the OSGi Service Manager
+ private volatile ConfigurationService configurationService;
+
+ private HashMap<Long, ProviderEntry> providers = Maps.newHashMap();
+ private HashMap<Node, NetworkingProvider> nodeToProviderMapping = Maps.newHashMap();
+
+ public NetworkingProvider getProvider(Node node) {
+ // This will change if/when we move to a commons library
+ Preconditions.checkArgument(node.getType().equals("OVS"));
+
+ if (nodeToProviderMapping.get(node) != null) {
+ return nodeToProviderMapping.get(node);
+ }
+
+ final String targetVersion = configurationService.getOpenflowVersion(node);
+
+ Predicate<ProviderEntry> providerEntryPredicate = new Predicate<ProviderEntry>() {
+ @Override
+ public boolean apply(ProviderEntry providerEntry) {
+ //ToDo: This should match on southboundProtocol and providerType too
+ return providerEntry.getProperties().get(Constants.OPENFLOW_VERSION_PROPERTY).equals(targetVersion);
+ }
+ };
+
+ Iterable<ProviderEntry> matchingProviders = Iterables.filter(providers.values(), providerEntryPredicate);
+ if (!matchingProviders.iterator().hasNext()) {
+ logger.error("No providers matching {} found", targetVersion);
+ }
+
+ // Return the first match as only have one matching provider today
+ // ToDo: Tie-breaking logic
+ NetworkingProvider provider = matchingProviders.iterator().next().getProvider();
+ nodeToProviderMapping.put(node, provider);
+ return provider;
+ }
+
+ public void providerAdded(final ServiceReference ref, final NetworkingProvider provider){
+ Map <String, String> properties = Maps.newHashMap();
+ Long pid = (Long) ref.getProperty(org.osgi.framework.Constants.SERVICE_ID);
+ properties.put(Constants.SOUTHBOUND_PROTOCOL_PROPERTY, (String) ref.getProperty(Constants.SOUTHBOUND_PROTOCOL_PROPERTY));
+ properties.put(Constants.OPENFLOW_VERSION_PROPERTY, (String) ref.getProperty(Constants.OPENFLOW_VERSION_PROPERTY));
+ properties.put(Constants.PROVIDER_TYPE_PROPERTY, (String) ref.getProperty(Constants.PROVIDER_TYPE_PROPERTY));
+ providers.put(pid, new ProviderEntry(provider, properties));
+ logger.info("Neutron Networking Provider Registered: {}, with {} and pid={}", provider.getClass().getName(), properties.toString(), pid);
+ }
+
+ public void providerRemoved(final ServiceReference ref){
+ Long pid = (Long)ref.getProperty(org.osgi.framework.Constants.SERVICE_ID);
+ providers.remove(pid);
+ logger.info("Neutron Networking Provider Removed: {}", pid);
+ }
+
+ private class ProviderEntry {
+ NetworkingProvider provider;
+ Map<String, String> properties;
+
+ ProviderEntry(NetworkingProvider provider, Map<String, String> properties) {
+ this.provider = provider;
+ this.properties = properties;
+ }
+
+ public NetworkingProvider getProvider() {
+ return provider;
+ }
+
+ public Map<String, String> getProperties() {
+ return properties;
+ }
+ }
+
+}
--- /dev/null
+/*
+ * Copyright (C) 2013 Red Hat, Inc. and others...
+ *
+ * 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, Dave Tucker
+ */
+package org.opendaylight.ovsdb.openstack.netvirt.impl;
+
+import org.opendaylight.controller.networkconfig.neutron.INeutronNetworkCRUD;
+import org.opendaylight.controller.networkconfig.neutron.INeutronPortCRUD;
+import org.opendaylight.controller.networkconfig.neutron.NeutronNetwork;
+import org.opendaylight.controller.networkconfig.neutron.NeutronPort;
+import org.opendaylight.controller.sal.core.Node;
+import org.opendaylight.ovsdb.lib.notation.OvsdbSet;
+import org.opendaylight.ovsdb.lib.notation.Row;
+import org.opendaylight.ovsdb.openstack.netvirt.api.Constants;
+import org.opendaylight.ovsdb.openstack.netvirt.api.NetworkingProviderManager;
+import org.opendaylight.ovsdb.openstack.netvirt.api.TenantNetworkManager;
+import org.opendaylight.ovsdb.openstack.netvirt.api.VlanConfigurationCache;
+import org.opendaylight.ovsdb.plugin.IConnectionServiceInternal;
+import org.opendaylight.ovsdb.plugin.OvsdbConfigService;
+import org.opendaylight.ovsdb.schema.openvswitch.Interface;
+import org.opendaylight.ovsdb.schema.openvswitch.Port;
+
+import com.google.common.base.Preconditions;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.List;
+import java.util.Map;
+
+public class TenantNetworkManagerImpl implements TenantNetworkManager {
+ static final Logger logger = LoggerFactory.getLogger(TenantNetworkManagerImpl.class);
+
+ // The implementation for each of these services is resolved by the OSGi Service Manager
+ private volatile NetworkingProviderManager networkingProviderManager;
+ private volatile OvsdbConfigService ovsdbConfigService;
+ private volatile IConnectionServiceInternal connectionService;
+ private volatile INeutronNetworkCRUD neutronNetworkCache;
+ private volatile INeutronPortCRUD neutronPortCache;
+ private volatile VlanConfigurationCache vlanConfigurationCache;
+
+ public TenantNetworkManagerImpl() {
+ }
+
+ @Override
+ public int getInternalVlan(Node node, String networkId) {
+ Integer vlan = vlanConfigurationCache.getInternalVlan(node, networkId);
+ if (vlan == null) return 0;
+ return vlan;
+ }
+
+ @Override
+ public void reclaimInternalVlan(Node node, String portUUID, NeutronNetwork network) {
+ int vlan = vlanConfigurationCache.reclaimInternalVlan(node, network.getID());
+ if (vlan <= 0) {
+ logger.error("Unable to get an internalVlan for Network {}", network);
+ return;
+ }
+ logger.debug("Removed Vlan {} on {}", vlan, portUUID);
+ }
+
+ @Override
+ public void programInternalVlan(Node node, String portUUID, NeutronNetwork network) {
+ Preconditions.checkNotNull(ovsdbConfigService);
+
+ int vlan = vlanConfigurationCache.getInternalVlan(node, network.getID());
+ logger.debug("Programming Vlan {} on {}", vlan, portUUID);
+ if (vlan <= 0) {
+ logger.error("Unable to get an internalVlan for Network {}", network);
+ return;
+ }
+
+ Port port = ovsdbConfigService.createTypedRow(node, Port.class);
+ OvsdbSet<Long> tags = new OvsdbSet<>();
+ tags.add((long) vlan);
+ port.setTag(tags);
+ ovsdbConfigService.updateRow(node, port.getSchema().getName(), null, portUUID, port.getRow());
+ }
+
+ @Override
+ public boolean isTenantNetworkPresentInNode(Node node, String segmentationId) {
+ Preconditions.checkNotNull(ovsdbConfigService);
+
+ String networkId = this.getNetworkId(segmentationId);
+ if (networkId == null) {
+ logger.debug("Tenant Network not found with Segmenation-id {}",segmentationId);
+ return false;
+ }
+ if (networkingProviderManager.getProvider(node).hasPerTenantTunneling()) {
+ int internalVlan = vlanConfigurationCache.getInternalVlan(node, networkId);
+ if (internalVlan == 0) {
+ logger.debug("No InternalVlan provisioned for Tenant Network {}",networkId);
+ return false;
+ }
+ }
+
+ try {
+ /*
+ // Vlan Tag based identification
+ Map<String, Row> portTable = ovsdbConfigService.getRows(node, Port.NAME.getName());
+ if (portTable == null) {
+ logger.debug("Port table is null for Node {} ", node);
+ return false;
+ }
+
+ for (Row row : portTable.values()) {
+ Port port = (Port)row;
+ Set<BigInteger> tags = port.getTag();
+ if (tags.contains(internalVlan)) {
+ logger.debug("Tenant Network {} with Segmenation-id {} is present in Node {} / Port {}",
+ networkId, segmentationId, node, port);
+ return true;
+ }
+ }
+ */
+ // External-id based more accurate VM Location identification
+ Map<String, Row> ifTable = ovsdbConfigService.getRows(node, ovsdbConfigService.getTableName(node, Interface.class));
+ if (ifTable == null) {
+ logger.debug("Interface table is null for Node {} ", node);
+ return false;
+ }
+
+ for (Row row : ifTable.values()) {
+ Interface intf = ovsdbConfigService.getTypedRow(node, Interface.class, row);
+ Map<String, String> externalIds = intf.getExternalIdsColumn().getData();
+ if (externalIds != null && externalIds.get(Constants.EXTERNAL_ID_INTERFACE_ID) != null) {
+ if (this.isInterfacePresentInTenantNetwork(externalIds.get(Constants.EXTERNAL_ID_INTERFACE_ID), networkId)) {
+ logger.debug("Tenant Network {} with Segmentation-id {} is present in Node {} / Interface {}",
+ networkId, segmentationId, node, intf);
+ return true;
+ }
+ }
+ }
+
+ } catch (Exception e) {
+ logger.error("Error while trying to determine if network is present on node", e);
+ return false;
+ }
+
+ logger.debug("Tenant Network {} with Segmenation-id {} is NOT present in Node {}",
+ networkId, segmentationId, node);
+
+ return false;
+ }
+
+ @Override
+ public String getNetworkId(String segmentationId) {
+ List <NeutronNetwork> networks = neutronNetworkCache.getAllNetworks();
+ for (NeutronNetwork network : networks) {
+ if (network.getProviderSegmentationID().equalsIgnoreCase(segmentationId)) return network.getNetworkUUID();
+ }
+ return null;
+ }
+
+ @Override
+ public NeutronNetwork getTenantNetwork(Interface intf) {
+ logger.trace("getTenantNetwork for {}", intf);
+ if (intf == null) return null;
+ Map<String, String> externalIds = intf.getExternalIdsColumn().getData();
+ logger.trace("externalIds {}", externalIds);
+ if (externalIds == null) return null;
+ String neutronPortId = externalIds.get(Constants.EXTERNAL_ID_INTERFACE_ID);
+ if (neutronPortId == null) return null;
+ NeutronPort neutronPort = neutronPortCache.getPort(neutronPortId);
+ logger.trace("neutronPort {}", neutronPort);
+ if (neutronPort == null) return null;
+ NeutronNetwork neutronNetwork = neutronNetworkCache.getNetwork(neutronPort.getNetworkUUID());
+ logger.debug("{} mapped to {}", intf, neutronNetwork);
+ return neutronNetwork;
+ }
+
+ @Override
+ public void networkCreated (String networkId) {
+ List<Node> nodes = connectionService.getNodes();
+
+ for (Node node : nodes) {
+ this.networkCreated(node, networkId);
+ }
+
+ }
+
+ @Override
+ public int networkCreated (Node node, String networkId) {
+ return vlanConfigurationCache.assignInternalVlan(node, networkId);
+ }
+
+ @Override
+ public void networkDeleted(String id) {
+ //ToDo: Delete? This method does nothing how we dropped container support...
+ }
+
+ private boolean isInterfacePresentInTenantNetwork (String portId, String networkId) {
+ NeutronPort neutronPort = neutronPortCache.getPort(portId);
+ return neutronPort != null && neutronPort.getNetworkUUID().equalsIgnoreCase(networkId);
+ }
+
+}
--- /dev/null
+/*
+ * Copyright (c) 2013 Hewlett-Packard Development Company, L.P.
+ *
+ * All rights reserved. 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: Dave Tucker
+*/
+
+package org.opendaylight.ovsdb.openstack.netvirt.impl;
+
+import org.opendaylight.controller.sal.core.Node;
+import org.opendaylight.ovsdb.lib.notation.Row;
+import org.opendaylight.ovsdb.lib.notation.UUID;
+import org.opendaylight.ovsdb.openstack.netvirt.NodeConfiguration;
+import org.opendaylight.ovsdb.openstack.netvirt.api.TenantNetworkManager;
+import org.opendaylight.ovsdb.openstack.netvirt.api.VlanConfigurationCache;
+import org.opendaylight.ovsdb.plugin.OvsdbConfigService;
+import org.opendaylight.ovsdb.schema.openvswitch.Interface;
+import org.opendaylight.ovsdb.schema.openvswitch.OpenVSwitch;
+import org.opendaylight.ovsdb.schema.openvswitch.Port;
+
+import com.google.common.base.Preconditions;
+import com.google.common.collect.Maps;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.Map;
+import java.util.Set;
+
+public class VlanConfigurationCacheImpl implements VlanConfigurationCache {
+ static final Logger logger = LoggerFactory.getLogger(VlanConfigurationCacheImpl.class);
+
+ private Map<String, NodeConfiguration> configurationCache = Maps.newConcurrentMap();
+
+ private volatile TenantNetworkManager tenantNetworkManager;
+ private volatile OvsdbConfigService ovsdbConfigService;
+
+ private NodeConfiguration getNodeConfiguration(Node node){
+ String nodeUuid = getNodeUUID(node);
+ if (configurationCache.get(nodeUuid) != null) {
+ return configurationCache.get(nodeUuid);
+ }
+
+ // Cache miss
+ initializeNodeConfiguration(nodeUuid, node);
+
+ return configurationCache.get(nodeUuid);
+ }
+
+ private String getNodeUUID(Node node) {
+ Preconditions.checkNotNull(ovsdbConfigService);
+ String nodeUuid = new String();
+ try {
+ Map<String, Row> ovsTable = ovsdbConfigService.getRows(node, ovsdbConfigService.getTableName(node, OpenVSwitch.class));
+ nodeUuid = (String)ovsTable.keySet().toArray()[0];
+ }
+ catch (Exception e) {
+ logger.error("Unable to get the Open_vSwitch table for Node {}: {}", node, e);
+ }
+
+ return nodeUuid;
+ }
+
+ private void initializeNodeConfiguration(String nodeUuid, Node node) {
+
+ NodeConfiguration nodeConfiguration = new NodeConfiguration();
+ Integer vlan;
+ String networkId = null;
+
+ try {
+ Map<String, Row> portRows = ovsdbConfigService.getRows(node, ovsdbConfigService.getTableName(node, Port.class));
+
+ if (portRows == null){
+ logger.debug("Port table is null for Node {}", node);
+ return;
+ }
+
+ for (Row row : portRows.values()) {
+ Port port = ovsdbConfigService.getTypedRow(node, Port.class, row);
+
+ if (port.getTagColumn() == null) continue;
+ Set<Long> tags = port.getTagColumn().getData();
+ if (tags.size() == 1)
+ {
+ //There is only one tag here
+ vlan = tags.iterator().next().intValue();
+ }
+ else {
+ logger.debug("This port ({}) has {} tags", port.getName(), tags.size());
+ continue;
+ }
+
+ for (UUID ifaceId : port.getInterfacesColumn().getData()) {
+ Row ifaceRow = ovsdbConfigService.getRow(node, ovsdbConfigService.getTableName(node, Interface.class), ifaceId.toString());
+ Interface iface = ovsdbConfigService.getTypedRow(node, Interface.class, ifaceRow);
+
+ if (iface == null) {
+ logger.debug("Interface table is null");
+ continue;
+ }
+
+ networkId = tenantNetworkManager.getTenantNetwork(iface).getNetworkUUID();
+
+ if (networkId != null) break;
+ }
+
+ if (vlan != 0 && networkId != null) {
+
+ this.internalVlanInUse(nodeConfiguration, vlan);
+ nodeConfiguration.getTenantVlanMap().put(networkId, vlan);
+
+ } else {
+ logger.debug("Node: {} initialized without a vlan", node);
+ }
+ }
+
+ configurationCache.put(nodeUuid, nodeConfiguration);
+ }
+ catch (Exception e) {
+ logger.debug("Error getting Port table for Node {}: {}", node, e);
+ }
+ }
+
+ /*
+ * Return the currently mapped internal vlan or get the next
+ * free internal vlan from the available pool and map it to the networkId.
+ */
+ @Override
+ public Integer assignInternalVlan (Node node, String networkId) {
+ NodeConfiguration nodeConfiguration = getNodeConfiguration(node);
+ Integer mappedVlan = nodeConfiguration.getTenantVlanMap().get(networkId);
+ if (mappedVlan != null) {
+ return mappedVlan;
+ }
+ mappedVlan = nodeConfiguration.getInternalVlans().poll();
+ if (mappedVlan != null) {
+ nodeConfiguration.getTenantVlanMap().put(networkId, mappedVlan);
+ }
+ return mappedVlan;
+ }
+
+ /*
+ * Return the mapped internal vlan to the available pool.
+ */
+ @Override
+ public Integer reclaimInternalVlan (Node node, String networkId) {
+ NodeConfiguration nodeConfiguration = getNodeConfiguration(node);
+ Integer mappedVlan = nodeConfiguration.getTenantVlanMap().get(networkId);
+ if (mappedVlan != null) {
+ nodeConfiguration.getTenantVlanMap().remove(networkId);
+ nodeConfiguration.getInternalVlans().add(mappedVlan);
+ return mappedVlan;
+ }
+ return 0;
+ }
+
+ private void internalVlanInUse (NodeConfiguration nodeConfiguration, Integer vlan) {
+ nodeConfiguration.getInternalVlans().remove(vlan);
+ }
+
+ @Override
+ public Integer getInternalVlan (Node node, String networkId) {
+ NodeConfiguration nodeConfiguration = getNodeConfiguration(node);
+ Integer vlan = nodeConfiguration.getTenantVlanMap().get(networkId);
+ if (vlan == null) return 0;
+ return vlan;
+ }
+
+}
--- /dev/null
+/*
+ * Copyright (C) 2014 Red Hat, Inc.
+ *
+ * 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 : Dave Tucker
+ */
+
+package org.opendaylight.ovsdb.openstack.netvirt;
+
+import org.opendaylight.ovsdb.openstack.netvirt.api.UuidUtils;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+public class UuidUtilsTest {
+
+ static final String NEUTRON_ID = "f1bf546b-79e8-4c42-93c1-147009c85c1d";
+ static final String NEUTRON_KEY = "f1bf546b79e8c4293c1147009c85c1d";
+ static final String INVALID_NEUTRON_ID = "f1bf546b-79e8-4c42-93c1-147009c85c1d-invalid";
+ static final String KEYSTONE_ID = "879704f8cd7d4e60a41177fc99254b5e";
+ static final String KEYSTONE_KEY = "879704f8cd7de60a41177fc99254b5e";
+ static final String GARBAGE = "foobar12345";
+
+ @Test
+ public void testConvertNeutronIDToKey() throws Exception {
+ Assert.assertNull(UuidUtils.convertNeutronIDToKey(null));
+ Assert.assertNull(UuidUtils.convertNeutronIDToKey(INVALID_NEUTRON_ID));
+ Assert.assertEquals(KEYSTONE_KEY,UuidUtils.convertNeutronIDToKey(KEYSTONE_ID));
+ Assert.assertEquals(NEUTRON_KEY, UuidUtils.convertNeutronIDToKey(NEUTRON_ID));
+ /* ToDo: Validation check in this method should be stricter
+ This assertion should ideally fail, but it passes today
+ */
+ Assert.assertEquals(UuidUtils.convertNeutronIDToKey(GARBAGE), GARBAGE);
+ }
+
+ @Test
+ public void testIsValidNeutronID() throws Exception {
+ Assert.assertTrue(UuidUtils.isValidNeutronID(NEUTRON_ID));
+ Assert.assertTrue(UuidUtils.isValidNeutronID(KEYSTONE_ID));
+ Assert.assertFalse(UuidUtils.isValidNeutronID(INVALID_NEUTRON_ID));
+ /* ToDo: Validation check in this method should be stricter
+ This assertion should ideally fail, but it passes today
+ */
+ Assert.assertTrue(UuidUtils.isValidNeutronID(GARBAGE));
+ }
+}
\ No newline at end of file
org.opendaylight.controller.sal.connection,
org.opendaylight.controller.clustering.services,
org.opendaylight.controller.sal.networkconfig.bridgedomain,
+ org.opendaylight.ovsdb.lib.error,
org.opendaylight.ovsdb.lib.notation,
org.opendaylight.ovsdb.lib.operations,
org.opendaylight.ovsdb.lib.message,
import org.opendaylight.controller.sal.utils.Status;
import org.opendaylight.controller.sal.utils.StatusCode;
import org.opendaylight.ovsdb.lib.OvsdbClient;
+import org.opendaylight.ovsdb.lib.error.SchemaVersionMismatchException;
import org.opendaylight.ovsdb.lib.notation.Column;
import org.opendaylight.ovsdb.lib.notation.Mutator;
import org.opendaylight.ovsdb.lib.notation.OvsdbSet;
return false;
}
- OvsdbSet<String> protocols = new OvsdbSet<String>();
+ Bridge bridge = connection.getClient().createTypedRowWrapper(Bridge.class);
+
+ Status updateOperationStatus = null;
+ try {
+ OvsdbSet<String> protocols = new OvsdbSet<String>();
+
+ String ofVersion = System.getProperty("ovsdb.of.version", OPENFLOW_10);
+ switch (ofVersion) {
+ case OPENFLOW_13:
+ protocols.add("OpenFlow13");
+ break;
+ case OPENFLOW_10:
+ //fall through
+ default:
+ protocols.add("OpenFlow10");
+ break;
+ }
+ bridge.setProtocols(protocols);
+ updateOperationStatus = this.updateRow(node, bridge.getSchema().getName(),
+ null, bridgeUUID, bridge.getRow());
+ logger.debug("Bridge {} updated to {} with Status {}", bridgeUUID,
+ protocols.toArray()[0],updateOperationStatus);
- String ofVersion = System.getProperty("ovsdb.of.version", OPENFLOW_10);
- switch (ofVersion) {
- case OPENFLOW_13:
- protocols.add("OpenFlow13");
- break;
- case OPENFLOW_10:
- default:
- protocols.add("OpenFlow10");
- break;
+ } catch (SchemaVersionMismatchException e){
+ logger.debug(e.toString());
}
- Bridge bridge = connection.getClient().createTypedRowWrapper(Bridge.class);
- bridge.setProtocols(protocols);
- Status status = this.updateRow(node, bridge.getSchema().getName(), null, bridgeUUID, bridge.getRow());
- logger.debug("Bridge {} updated to {} with Status {}", bridgeUUID, protocols.toArray()[0], status);
- if (!status.isSuccess()) return status.isSuccess();
+ // If we fail to update the protocols
+ if (updateOperationStatus != null && !updateOperationStatus.isSuccess()) {
+ return updateOperationStatus.isSuccess();
+ }
+ Status status = null;
List<InetAddress> ofControllerAddrs = this.getControllerIPAddresses(connection);
short ofControllerPort = getControllerOFPort();
for (InetAddress ofControllerAddress : ofControllerAddrs) {
String newController = "tcp:"+ofControllerAddress.getHostAddress()+":"+ofControllerPort;
Controller controllerRow = connection.getClient().createTypedRowWrapper(Controller.class);
controllerRow.setTarget(ImmutableSet.of(newController));
+ //ToDo: Status gets overwritten on each iteration. If any operation other than the last fails it's ignored.
status = this.insertRow(node, controllerRow.getSchema().getName(), bridgeUUID, controllerRow.getRow());
}
- return status.isSuccess();
+
+ if (status != null) {
+ return status.isSuccess();
+ }
+
+ return false;
}
<relativePath>commons/parent</relativePath>
</parent>
- <groupId>org.opendaylight.ovsdb</groupId>
<artifactId>ovsdb</artifactId>
<version>1.0.0-SNAPSHOT</version>
<packaging>pom</packaging>
<module>plugin</module>
<module>commons/parent</module>
<module>northbound</module>
- <module>neutron</module>
+ <module>openstack/net-virt</module>
+ <module>openstack/net-virt-providers</module>
<module>distribution/opendaylight</module>
</modules>
</activation>
<modules>
<module>commons/integrationtest</module>
- <module>integrationtest</module>
+ <module>integrationtest</module>
</modules>
<properties>
<skip.integrationtest>false</skip.integrationtest>