This is a large commit becuase the sal Node is used all over the code. There is no way to build without doing it all in once shot.
Patch Set 2,3: No changes, just testing openstack integration. Something was broken in controller code causing failures. A rebuild this morning pulled in numerous new artifacts and cleared up the issue.
Change-Id: I9e53f61ad82dc0c6c1c447d9a7d4f2bcf11dbca0
Signed-off-by: Sam Hague <shague@redhat.com>
<artifactId>sal.implementation</artifactId>
<version>${sal.implementation.version}</version>
</dependency>
+ <dependency>
+ <groupId>org.opendaylight.controller</groupId>
+ <artifactId>sal-binding-it</artifactId>
+ <version>${mdsal.version}</version>
+ </dependency>
<dependency>
<groupId>org.opendaylight.controller</groupId>
<artifactId>security</artifactId>
<feature name="odl-ovsdb-plugin" description="OpenDaylight :: OVSDB :: Plugin" version='${ovsdb.plugin.version}'>
<feature version="${sal.version}">odl-adsal-all</feature>
+ <feature version="${openflowplugin.version}">odl-openflowplugin-nsf-services</feature>
<feature version="${ovsdb.library.version}">odl-ovsdb-library</feature>
<feature version="${schema.openvswitch.version}">odl-ovsdb-schema-openvswitch</feature>
<feature version="${schema.hardwarevtep.version}">odl-ovsdb-schema-hardwarevtep</feature>
<feature name="odl-ovsdb-northbound" description="OpenDaylight :: OVSDB :: Northbound" version='${ovsdb.northbound.version}'>
<feature version="${ovsdb.plugin.version}">odl-ovsdb-plugin</feature>
<feature version="${nsf.version}">odl-adsal-northbound</feature>
+ <feature version="${openflowplugin.version}">odl-openflowplugin-nsf-services</feature>
<bundle>mvn:org.opendaylight.ovsdb/northbound/${ovsdb.northbound.version}</bundle>
</feature>
<feature name="odl-ovsdb-compatibility-layer" description="OpenDaylight :: OVSDB :: Plugin Compatibility Layer" version='${ovsdb.plugin.compatibility.layer.version}'>
+ <feature version="${openflowplugin.version}">odl-openflowplugin-nsf-services</feature>
<feature version="${ovsdb.plugin.version}">odl-ovsdb-plugin</feature>
<bundle>mvn:org.opendaylight.ovsdb/ovsdb-plugin-compatibility-layer/${ovsdb.plugin.compatibility.layer.version}</bundle>
</feature>
--- /dev/null
+package org.opendaylight.ovsdb.integrationtest;
+
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Properties;
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.TimeoutException;
+import org.opendaylight.controller.sal.core.Node;
+import org.opendaylight.controller.sal.utils.ServiceHelper;
+import org.opendaylight.ovsdb.plugin.api.ConnectionConstants;
+import org.opendaylight.ovsdb.compatibility.plugin.api.OvsdbConnectionService;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public abstract class CompatOvsdbIntegrationTestBase extends OvsdbIntegrationTestBase {
+ private static final Logger LOG = LoggerFactory.getLogger(OvsdbIntegrationTestBase.class);
+
+ public Node getCompatPluginTestConnection() throws IOException,
+ InterruptedException, ExecutionException, TimeoutException {
+ Properties props = loadProperties();
+ String addressStr = props.getProperty(SERVER_IPADDRESS);
+ String portStr = props.getProperty(SERVER_PORT, DEFAULT_SERVER_PORT);
+ String connectionType = props.getProperty(CONNECTION_TYPE, "active");
+ org.opendaylight.controller.sal.core.Node node = null;
+
+ OvsdbConnectionService connection = (OvsdbConnectionService)
+ ServiceHelper.getGlobalInstance(OvsdbConnectionService.class, this);
+ // If the connection type is active, controller connects to the ovsdb-server
+ if (connectionType.equalsIgnoreCase(CONNECTION_TYPE_ACTIVE)) {
+ if (addressStr == null) {
+ fail(usage());
+ }
+
+ Map<ConnectionConstants, String> params = new HashMap<ConnectionConstants, String>();
+ params.put(ConnectionConstants.ADDRESS, addressStr);
+ params.put(ConnectionConstants.PORT, portStr);
+ node = connection.connect(IDENTIFIER, params);
+ } else if (connectionType.equalsIgnoreCase(CONNECTION_TYPE_PASSIVE)) {
+ // Wait for CONNECTION_INIT_TIMEOUT for the Passive connection to be initiated by the ovsdb-server.
+ Thread.sleep(CONNECTION_INIT_TIMEOUT);
+ List<Node> nodes = connection.getNodes();
+ assertNotNull(nodes);
+ assertTrue(nodes.size() > 0);
+ node = nodes.get(0);
+ }
+
+ if (node != null) {
+ LOG.info("getPluginTestConnection: Successfully connected to {}", node);
+ } else {
+ fail("Connection parameter (" + CONNECTION_TYPE + ") must be active or passive");
+ }
+ return node;
+ }
+}
import static org.ops4j.pax.exam.CoreOptions.systemPackages;
import static org.ops4j.pax.exam.CoreOptions.systemProperty;
+import org.opendaylight.controller.test.sal.binding.it.TestHelper;
import org.ops4j.pax.exam.Option;
import org.ops4j.pax.exam.options.DefaultCompositeOption;
);
}
+ public static Option mdsalBundles() {
+ return new DefaultCompositeOption(
+ //TestHelper.mdSalCoreBundles(),
+ //TestHelper.bindingAwareSalBundles(),
+ TestHelper.configMinumumBundles(),
+ TestHelper.baseModelBundles(),
+ TestHelper.flowCapableModelBundles(),
+ TestHelper.junitAndMockitoBundles()
+ );
+ }
}
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
-import org.opendaylight.controller.sal.core.Node;
import org.opendaylight.controller.sal.utils.ServiceHelper;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node;
import org.opendaylight.ovsdb.lib.OvsdbClient;
import org.opendaylight.ovsdb.lib.OvsdbConnection;
import org.opendaylight.ovsdb.lib.OvsdbConnectionListener;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.fail;
import static org.opendaylight.ovsdb.lib.operations.Operations.op;
-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;
propagateSystemProperty("ovsdbserver.ipaddress"),
propagateSystemProperty("ovsdbserver.port"),
+ ConfigurationBundles.mdsalBundles(),
ConfigurationBundles.controllerBundles(),
ConfigurationBundles.ovsdbLibraryBundles(),
- ConfigurationBundles.ovsdbDefaultSchemaBundles(),
- junitBundles()
+ ConfigurationBundles.ovsdbDefaultSchemaBundles()
);
}
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.sal.core.Node;
import org.opendaylight.controller.sal.utils.Status;
import org.opendaylight.neutron.spi.NeutronNetwork;
+import org.opendaylight.ovsdb.compatibility.plugin.api.NodeUtils;
import org.opendaylight.ovsdb.integrationtest.ConfigurationBundles;
import org.opendaylight.ovsdb.integrationtest.OvsdbIntegrationTestBase;
import org.opendaylight.ovsdb.lib.notation.Row;
import org.opendaylight.ovsdb.schema.openvswitch.Bridge;
import org.opendaylight.ovsdb.schema.openvswitch.Interface;
import org.opendaylight.ovsdb.schema.openvswitch.OpenVSwitch;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node;
import com.google.common.collect.ImmutableMap;
propagateSystemProperty("ovsdbserver.ipaddress"),
propagateSystemProperty("ovsdbserver.port"),
+ ConfigurationBundles.mdsalBundles(),
ConfigurationBundles.controllerBundles(),
ConfigurationBundles.ovsdbLibraryBundles(),
ConfigurationBundles.ovsdbDefaultSchemaBundles(),
ConfigurationBundles.ovsdbPluginBundles(),
- ConfigurationBundles.ovsdbNeutronBundles(),
- junitBundles()
+ ConfigurationBundles.ovsdbNeutronBundles()
);
}
Thread.sleep(5000);
// Create the integration bridge
- bridgeConfigurationManager.prepareNode(node);
+ bridgeConfigurationManager.prepareNode(NodeUtils.getSalNode(node));
Map<String, Row>
bridgeRows =
Bridge bridgeRow = ovsdbConfigurationService.getTypedRow(node, Bridge.class, bridgeRows.values().iterator().next());
Assert.assertEquals(netVirtConfigurationService.getIntegrationBridgeName(), bridgeRow.getName());
- String uuid = bridgeConfigurationManager.getBridgeUuid(node, netVirtConfigurationService.getIntegrationBridgeName());
+ String uuid = bridgeConfigurationManager.getBridgeUuid(NodeUtils.getSalNode(node),
+ netVirtConfigurationService.getIntegrationBridgeName());
Assert.assertEquals(uuid, bridgeRow.getUuid().toString());
tearDownBridge = true;
OpenVSwitch.class,
ovsRows.values().iterator().next());
- Assert.assertEquals(null, netVirtConfigurationService.getTunnelEndPoint(node));
+ Assert.assertEquals(null, netVirtConfigurationService.getTunnelEndPoint(NodeUtils.getSalNode(node)));
final UUID originalVersion = ovsRow.getVersion();
OpenVSwitch updateOvsRow = ovsdbConfigurationService.createTypedRow(node, OpenVSwitch.class);
ovsRow.getOtherConfigColumn().getData());
// Make sure tunnel end point was set
- Assert.assertEquals(InetAddress.getByName(endpointAddress), netVirtConfigurationService.getTunnelEndPoint(node));
+ Assert.assertEquals(InetAddress.getByName(endpointAddress),
+ netVirtConfigurationService.getTunnelEndPoint(NodeUtils.getSalNode(node)));
// Fetch rows again, and compare tunnel end point values
ovsRows = ovsdbConfigurationService.getRows(node,
- ovsdbConfigurationService.getTableName(node, OpenVSwitch.class));
+ ovsdbConfigurationService.getTableName(node,
+ OpenVSwitch.class));
ovsRow = ovsdbConfigurationService.getTypedRow(node,
OpenVSwitch.class,
ovsRows.values().iterator().next());
Version ovsVersion = this.getOvsVersion();
if (ovsVersion.compareTo(Constants.OPENFLOW13_SUPPORTED) >= 0) {
- Assert.assertEquals(Constants.OPENFLOW13, netVirtConfigurationService.getOpenflowVersion(node));
+ Assert.assertEquals(Constants.OPENFLOW13,
+ netVirtConfigurationService.getOpenflowVersion(NodeUtils.getSalNode(node)));
}
}
@Test
public void testGetDefaultGatewayMacAddress() throws Exception {
// Thread.sleep(5000);
- String defaultGatewayMacAddress = netVirtConfigurationService.getDefaultGatewayMacAddress(node);
+ String defaultGatewayMacAddress = netVirtConfigurationService.
+ getDefaultGatewayMacAddress(NodeUtils.getSalNode(node));
if (defaultGatewayMacAddress != null) {
String[] splits = defaultGatewayMacAddress.split(":");
if (tearDownBridge) {
try {
- String uuid = bridgeConfigurationManager.getBridgeUuid(node,
- netVirtConfigurationService.getIntegrationBridgeName());
+ String uuid = bridgeConfigurationManager.getBridgeUuid(NodeUtils.getSalNode(node),
+ netVirtConfigurationService.getIntegrationBridgeName());
ovsdbConfigurationService.deleteRow(node, ovsdbConfigurationService.getTableName(node, Bridge.class), uuid);
} catch (Exception e) {
log.error("tearDownBridge Exception : " + e.getMessage());
}
@Override
- public Status handleInterfaceUpdate(NeutronNetwork network, Node source, Interface intf) {
+ public Status handleInterfaceUpdate(NeutronNetwork network,
+ org.opendaylight.controller.sal.core.Node source, Interface intf) {
return null;
}
@Override
- public Status handleInterfaceDelete(String tunnelType, NeutronNetwork network, Node source, Interface intf,
+ public Status handleInterfaceDelete(String tunnelType, NeutronNetwork network,
+ org.opendaylight.controller.sal.core.Node source, Interface intf,
boolean isLastInstanceOnNode) {
return null;
}
@Override
- public void initializeFlowRules(Node node) {
+ public void initializeFlowRules(org.opendaylight.controller.sal.core.Node node) {
}
@Override
- public void initializeOFFlowRules(Node openflowNode) {
+ public void initializeOFFlowRules(org.opendaylight.controller.sal.core.Node openflowNode) {
}
}
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
-import static org.ops4j.pax.exam.CoreOptions.junitBundles;
import static org.ops4j.pax.exam.CoreOptions.mavenBundle;
import static org.ops4j.pax.exam.CoreOptions.options;
import static org.ops4j.pax.exam.CoreOptions.propagateSystemProperty;
import org.opendaylight.controller.sal.core.Node;
import org.opendaylight.controller.usermanager.IUserManager;
import org.opendaylight.ovsdb.integrationtest.ConfigurationBundles;
-import org.opendaylight.ovsdb.integrationtest.OvsdbIntegrationTestBase;
+import org.opendaylight.ovsdb.integrationtest.CompatOvsdbIntegrationTestBase;
import org.ops4j.pax.exam.Configuration;
import org.ops4j.pax.exam.Option;
import org.ops4j.pax.exam.junit.PaxExamParameterized;
@RunWith(PaxExamParameterized.class)
@ExamReactorStrategy(PerClass.class)
-public class OvsdbNorthboundV2IT extends OvsdbIntegrationTestBase {
+public class OvsdbNorthboundV2IT extends CompatOvsdbIntegrationTestBase {
private Logger log = LoggerFactory.getLogger(OvsdbNorthboundV2IT.class);
public static final String USERNAME = "admin";
for (Map<String, Object> o : object){
Object[] l = o.values().toArray();
parameters.add(l);
+ break;
}
return parameters;
assertTrue(this.userManager != null);
try {
- node = getPluginTestConnection();
+ node = getCompatPluginTestConnection();
} catch (Exception e) {
fail("Exception : "+e.getMessage());
}
propagateSystemProperty("ovsdbserver.ipaddress"),
propagateSystemProperty("ovsdbserver.port"),
+ ConfigurationBundles.mdsalBundles(),
ConfigurationBundles.controllerBundles(),
ConfigurationBundles.controllerNorthboundBundles(),
ConfigurationBundles.ovsdbLibraryBundles(),
ConfigurationBundles.ovsdbDefaultSchemaBundles(),
- mavenBundle("org.opendaylight.ovsdb", "plugin").versionAsInProject(),
- mavenBundle("org.opendaylight.ovsdb", "northbound").versionAsInProject(),
- junitBundles()
+ ConfigurationBundles.ovsdbPluginBundles(),
+ mavenBundle("org.opendaylight.ovsdb", "northbound").versionAsInProject()
);
}
}
import static org.ops4j.pax.exam.CoreOptions.systemProperty;
import org.junit.After;
-import org.opendaylight.controller.sal.core.Node;
import org.opendaylight.controller.sal.utils.ServiceHelper;
import org.opendaylight.ovsdb.integrationtest.ConfigurationBundles;
import org.opendaylight.ovsdb.integrationtest.OvsdbIntegrationTestBase;
import org.opendaylight.ovsdb.plugin.api.StatusWithUuid;
import org.opendaylight.ovsdb.schema.openvswitch.Bridge;
import org.opendaylight.ovsdb.schema.openvswitch.OpenVSwitch;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Sets;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mockito;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeKey;
import org.ops4j.pax.exam.Configuration;
import org.ops4j.pax.exam.Option;
import org.ops4j.pax.exam.junit.PaxExam;
propagateSystemProperty("ovsdbserver.ipaddress"),
propagateSystemProperty("ovsdbserver.port"),
+ ConfigurationBundles.mdsalBundles(),
ConfigurationBundles.controllerBundles(),
ConfigurationBundles.ovsdbLibraryBundles(),
ConfigurationBundles.ovsdbDefaultSchemaBundles(),
- ConfigurationBundles.ovsdbPluginBundles(),
- junitBundles()
+ ConfigurationBundles.ovsdbPluginBundles()
);
}
componentB.setImplementation(listenerB);
dm.add(componentB);
- Node newNode = Node.fromString("OVS|10.10.10.10:65342");
+ NodeId nodeId = new NodeId("OVS|10.10.10.10:65342");
+ NodeKey nodeKey = new NodeKey(nodeId);
+ node = new NodeBuilder()
+ .setId(nodeId)
+ .setKey(nodeKey)
+ .build();
InetAddress address = InetAddress.getByName("10.10.10.10");
int port = 65342;
// Trigger event
- ovsdbInventoryService.notifyNodeAdded(newNode, address, port);
+ ovsdbInventoryService.notifyNodeAdded(node, address, port);
- Mockito.verify(listenerA, Mockito.times(1)).nodeAdded(newNode, address, port);
- Mockito.verify(listenerB, Mockito.times(1)).nodeAdded(newNode, address, port);
+ Mockito.verify(listenerA, Mockito.times(1)).nodeAdded(node, address, port);
+ Mockito.verify(listenerB, Mockito.times(1)).nodeAdded(node, address, port);
dm.remove(componentA);
dm.remove(componentB);
--- /dev/null
+/*
+ * Copyright (c) 2014 Red Hat, Inc. 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
+ *
+ * Authors : Madhu Venugopal
+ */
+package org.opendaylight.ovsdb.integrationtest.plugin;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+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 com.google.common.collect.ImmutableMap;
+import com.google.common.collect.Sets;
+import java.io.IOException;
+import java.net.InetAddress;
+import java.net.UnknownHostException;
+import java.util.List;
+import java.util.concurrent.ConcurrentMap;
+import java.util.concurrent.ExecutionException;
+import javax.inject.Inject;
+import org.apache.felix.dm.Component;
+import org.apache.felix.dm.DependencyManager;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mockito;
+import org.opendaylight.controller.sal.core.ConstructionException;
+import org.opendaylight.controller.sal.core.Node;
+import org.opendaylight.controller.sal.utils.ServiceHelper;
+import org.opendaylight.ovsdb.integrationtest.CompatOvsdbIntegrationTestBase;
+import org.opendaylight.ovsdb.integrationtest.ConfigurationBundles;
+import org.opendaylight.ovsdb.lib.OvsdbClient;
+import org.opendaylight.ovsdb.lib.OvsdbConnectionInfo;
+import org.opendaylight.ovsdb.lib.notation.Row;
+import org.opendaylight.ovsdb.lib.notation.UUID;
+import org.opendaylight.ovsdb.lib.schema.GenericTableSchema;
+import org.opendaylight.ovsdb.plugin.api.Connection;
+import org.opendaylight.ovsdb.compatibility.plugin.api.OvsdbConfigurationService;
+import org.opendaylight.ovsdb.compatibility.plugin.api.OvsdbConnectionService;
+import org.opendaylight.ovsdb.compatibility.plugin.api.OvsdbInventoryListener;
+import org.opendaylight.ovsdb.compatibility.plugin.api.OvsdbInventoryService;
+import org.opendaylight.controller.sal.utils.StatusCode;
+import org.opendaylight.ovsdb.compatibility.plugin.api.StatusWithUuid;
+import org.opendaylight.ovsdb.schema.openvswitch.Bridge;
+import org.opendaylight.ovsdb.schema.openvswitch.OpenVSwitch;
+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.PerSuite;
+import org.ops4j.pax.exam.util.PathUtils;
+import org.osgi.framework.BundleContext;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+@RunWith(PaxExam.class)
+@ExamReactorStrategy(PerSuite.class)
+public class OvsdbPluginV3CompatIT extends CompatOvsdbIntegrationTestBase {
+ private Logger log = LoggerFactory.getLogger(OvsdbPluginV3CompatIT.class);
+ @Inject
+ private BundleContext bc;
+ private OvsdbConfigurationService ovsdbConfigurationService = null;
+ private String databaseName = "Open_vSwitch";
+
+ private Node node = null;
+ private OvsdbClient client = null;
+
+ // 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.mdsalBundles(),
+ ConfigurationBundles.controllerBundles(),
+ ConfigurationBundles.ovsdbLibraryBundles(),
+ ConfigurationBundles.ovsdbDefaultSchemaBundles(),
+ ConfigurationBundles.ovsdbPluginBundles()
+ );
+ }
+
+ @Before
+ public void setUp () throws ExecutionException, InterruptedException, IOException {
+ areWeReady(bc);
+ }
+
+ public void getConnection () throws InterruptedException {
+ try {
+ node = getCompatPluginTestConnection();
+ } catch (Exception e) {
+ fail("Exception : "+e.getMessage());
+ }
+ this.ovsdbConfigurationService = (OvsdbConfigurationService)ServiceHelper.getGlobalInstance(OvsdbConfigurationService.class, this);
+ }
+
+ @Test
+ public void apiTests() throws Exception {
+ getConnection();
+ assertNotNull("Node should not be null", node);
+ assertNotNull("OvsdbConfigurationService should not be null", ovsdbConfigurationService);
+
+ Thread.sleep(1000);
+ OvsdbConnectionService
+ connectionService = (OvsdbConnectionService)ServiceHelper.getGlobalInstance(OvsdbConnectionService.class, this);
+
+ // Check for the ovsdb Connection as seen by the Plugin layer
+ assertNotNull(connectionService.getNodes());
+ assertTrue(connectionService.getNodes().size() > 0);
+ Node node = connectionService.getNodes().get(0);
+ Connection connection = connectionService.getConnection(node);
+ OvsdbConnectionInfo connectionInfo = connection.getClient().getConnectionInfo();
+ String identifier = IDENTIFIER;
+ if (connectionInfo.getType().equals(OvsdbConnectionInfo.ConnectionType.PASSIVE)) {
+ identifier = connectionInfo.getRemoteAddress().getHostAddress()+":"+connectionInfo.getRemotePort();
+ }
+ assertEquals(node, connectionService.getNode("OVS|" + identifier));
+ log.info("Nodes = "+ connectionService.getNodes());
+ /*
+ * Test sequence :
+ * 1. Print Cache and Assert to make sure the bridge is not created yet.
+ * 2. Create a bridge with a valid parent_uuid & Assert to make sure the return status is success.
+ * 3. Assert to make sure the bridge is created with a valid Uuid.
+ * 4. Delete the bridge & Assert to make sure the return status is success.
+ * 5. Assert to make sure the bridge is deleted
+ */
+
+ this.endToEndApiTest(connection, getOpenVSwitchTableUUID(connection));
+ }
+
+ @Test
+ public void testInventoryListeners() throws UnknownHostException {
+ DependencyManager dm = new DependencyManager(bc);
+
+ OvsdbInventoryListener listenerA = Mockito.mock(FakeListener.class);
+ OvsdbInventoryListener listenerB = Mockito.mock(FakeListener.class);
+
+ Component componentA = dm.createComponent();
+ componentA.setInterface(OvsdbInventoryListener.class.getName(), null);
+ componentA.setImplementation(listenerA);
+ dm.add(componentA);
+
+ Component componentB = dm.createComponent();
+ componentB.setInterface(OvsdbInventoryListener.class.getName(), null);
+ componentB.setImplementation(listenerB);
+ dm.add(componentB);
+
+ try {
+ node = new Node("OVS", "10.10.10.10:65342");
+ } catch (ConstructionException e) {
+ log.error("Failed to allocate sal Node", e);
+ }
+ InetAddress address = InetAddress.getByName("10.10.10.10");
+ int port = 65342;
+
+ // Trigger event
+ OvsdbInventoryService
+ ovsdbInventoryService = (OvsdbInventoryService)ServiceHelper
+ .getGlobalInstance(OvsdbInventoryService.class, this);
+ ovsdbInventoryService.notifyNodeAdded(node, address, port);
+
+ Mockito.verify(listenerA, Mockito.times(1)).nodeAdded(node, address, port);
+ Mockito.verify(listenerB, Mockito.times(1)).nodeAdded(node, address, port);
+
+ dm.remove(componentA);
+ dm.remove(componentB);
+
+ }
+
+ public void endToEndApiTest(Connection connection, String parentUuid) throws Exception {
+ // 1. Print Cache and Assert to make sure the bridge is not created yet.
+ printCache();
+
+ // 2. Create a bridge with a valid parent_uuid & Assert to make sure the return status is success.
+ StatusWithUuid status = insertBridge(connection, parentUuid);
+ assertTrue(status.isSuccess());
+
+ // 3. Assert to make sure the bridge is created with a valid Uuid.
+ printCache();
+ Bridge bridge = connection.getClient().getTypedRowWrapper(Bridge.class, null);
+ Row bridgeRow = ovsdbConfigurationService.getRow(node, databaseName, bridge.getSchema().getName(), status.getUuid());
+ assertNotNull(bridgeRow);
+ bridge = connection.getClient().getTypedRowWrapper(Bridge.class, bridgeRow);
+ log.info("Bridge UUID "+bridge.getUuid()+" Status Uuid "+status.getUuid());
+ assertEquals(bridge.getUuid(), status.getUuid());
+
+ bridge = connection.getClient().createTypedRowWrapper(Bridge.class);
+ bridge.setDatapathType("netdev");
+ try {
+ ovsdbConfigurationService.updateRow(node, databaseName, bridge.getSchema().getName(), status.getUuid(), bridge.getRow(), false);
+ } catch (Exception e) {
+ fail("Failed to updated Bridge "+e.getMessage());
+ }
+
+ // 4. Delete the bridge & Assert to make sure the return status is success.
+ try {
+ ovsdbConfigurationService.deleteRow(node, databaseName, bridge.getSchema().getName(), null, new UUID(parentUuid) ,null, status.getUuid());
+ } catch (Exception e) {
+ fail(e.getMessage());
+ }
+
+ // 5. Assert to make sure the bridge is deleted
+ bridgeRow = ovsdbConfigurationService.getRow(node, databaseName, bridge.getSchema().getName(), status.getUuid());
+ assertNull(bridgeRow);
+ }
+
+ public StatusWithUuid insertBridge(Connection connection, String parentUuid) throws Exception {
+ Bridge bridge = connection.getClient().createTypedRowWrapper(Bridge.class);
+ bridge.setName("br_test1");
+ bridge.setStatus(ImmutableMap.of("key", "value"));
+ bridge.setFloodVlans(Sets.newHashSet(34L));
+ try {
+ Row<GenericTableSchema> row = ovsdbConfigurationService.insertTree(node, databaseName, bridge.getSchema().getName(), new UUID(parentUuid), bridge.getRow());
+ bridge = connection.getClient().getTypedRowWrapper(Bridge.class, row);
+ return new StatusWithUuid(StatusCode.SUCCESS, bridge.getUuid());
+ } catch (Exception e) {
+ return new StatusWithUuid(StatusCode.INTERNALERROR);
+ }
+ }
+
+ public String getOpenVSwitchTableUUID(Connection connection) throws Exception {
+ OpenVSwitch openVSwitch = connection.getClient().getTypedRowWrapper(OpenVSwitch.class, null);
+ ConcurrentMap<UUID, Row<GenericTableSchema>> rows = ovsdbConfigurationService.getRows(node, databaseName, openVSwitch.getSchema().getName());
+ if (rows == null || rows.size() == 0) return null;
+ return rows.keySet().toArray()[0].toString();
+ }
+
+ public void printCache() throws Exception {
+ List<String> tables = ovsdbConfigurationService.getTables(node, databaseName);
+ log.info("Tables = "+tables);
+ assertNotNull(tables);
+ for (String table : tables) {
+ log.info("Table "+table);
+ ConcurrentMap<UUID, Row<GenericTableSchema>> rows = ovsdbConfigurationService.getRows(node, databaseName, table);
+ log.info(rows.toString());
+ }
+ }
+
+ public class FakeListener implements OvsdbInventoryListener {
+
+ @Override
+ public void nodeAdded(Node node, InetAddress address, int port) {
+
+ }
+
+ @Override
+ public void nodeRemoved(Node node) {
+
+ }
+
+ @Override
+ public void rowAdded(Node node, String tableName, String uuid, Row row) {
+
+ }
+
+ @Override
+ public void rowUpdated(Node node, String tableName, String uuid, Row old, Row row) {
+
+ }
+
+ @Override
+ public void rowRemoved(Node node, String tableName, String uuid, Row row, Object context) {
+
+ }
+ }
+
+}
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
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.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mockito;
-import org.opendaylight.controller.sal.core.Node;
import org.opendaylight.controller.sal.utils.ServiceHelper;
import org.opendaylight.ovsdb.integrationtest.ConfigurationBundles;
import org.opendaylight.ovsdb.integrationtest.OvsdbIntegrationTestBase;
import org.opendaylight.ovsdb.plugin.api.StatusWithUuid;
import org.opendaylight.ovsdb.schema.openvswitch.Bridge;
import org.opendaylight.ovsdb.schema.openvswitch.OpenVSwitch;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeKey;
import org.ops4j.pax.exam.Configuration;
import org.ops4j.pax.exam.Option;
import org.ops4j.pax.exam.junit.PaxExam;
propagateSystemProperty("ovsdbserver.ipaddress"),
propagateSystemProperty("ovsdbserver.port"),
+ ConfigurationBundles.mdsalBundles(),
ConfigurationBundles.controllerBundles(),
ConfigurationBundles.ovsdbLibraryBundles(),
ConfigurationBundles.ovsdbDefaultSchemaBundles(),
- ConfigurationBundles.ovsdbPluginBundles(),
- junitBundles()
+ ConfigurationBundles.ovsdbPluginBundles()
);
}
componentB.setImplementation(listenerB);
dm.add(componentB);
- Node newNode = Node.fromString("OVS|10.10.10.10:65342");
+ NodeId nodeId = new NodeId("OVS|10.10.10.10:65342");
+ NodeKey nodeKey = new NodeKey(nodeId);
+ node = new NodeBuilder()
+ .setId(nodeId)
+ .setKey(nodeKey)
+ .build();
+
InetAddress address = InetAddress.getByName("10.10.10.10");
int port = 65342;
// Trigger event
- ovsdbInventoryService.notifyNodeAdded(newNode, address, port);
+ ovsdbInventoryService.notifyNodeAdded(node, address, port);
- Mockito.verify(listenerA, Mockito.times(1)).nodeAdded(newNode, address, port);
- Mockito.verify(listenerB, Mockito.times(1)).nodeAdded(newNode, address, port);
+ Mockito.verify(listenerA, Mockito.times(1)).nodeAdded(node, address, port);
+ Mockito.verify(listenerB, Mockito.times(1)).nodeAdded(node, address, port);
dm.remove(componentA);
dm.remove(componentB);
-
}
public void endToEndApiTest(Connection connection, String parentUuid) throws Exception {
propagateSystemProperty("ovsdbserver.ipaddress"),
propagateSystemProperty("ovsdbserver.port"),
+ ConfigurationBundles.mdsalBundles(),
ConfigurationBundles.controllerBundles(),
ConfigurationBundles.ovsdbLibraryBundles(),
- ConfigurationBundles.ovsdbDefaultSchemaBundles(),
- junitBundles()
+ ConfigurationBundles.ovsdbDefaultSchemaBundles()
);
}
propagateSystemProperty("ovsdbserver.ipaddress"),
propagateSystemProperty("ovsdbserver.port"),
+ ConfigurationBundles.mdsalBundles(),
ConfigurationBundles.controllerBundles(),
ConfigurationBundles.ovsdbLibraryBundles(),
- ConfigurationBundles.ovsdbDefaultSchemaBundles(),
- junitBundles()
+ ConfigurationBundles.ovsdbDefaultSchemaBundles()
);
}
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</dependency>
+ <dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-simple</artifactId>
+ </dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
import org.opendaylight.controller.northbound.commons.RestMessages;
import org.opendaylight.controller.northbound.commons.exception.ResourceNotFoundException;
import org.opendaylight.controller.northbound.commons.exception.ServiceUnavailableException;
-import org.opendaylight.controller.sal.core.Node;
import org.opendaylight.controller.sal.utils.ServiceHelper;
import org.opendaylight.ovsdb.lib.OvsdbClient;
import org.opendaylight.ovsdb.plugin.api.Connection;
import org.opendaylight.ovsdb.plugin.api.OvsdbConnectionService;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.DeserializationFeature;
import org.opendaylight.controller.northbound.commons.exception.UnauthorizedException;
import org.opendaylight.controller.northbound.commons.utils.NorthboundUtils;
import org.opendaylight.controller.sal.authorization.Privilege;
-import org.opendaylight.controller.sal.core.Node;
import org.opendaylight.controller.sal.utils.ServiceHelper;
import org.opendaylight.ovsdb.plugin.api.Status;
import org.opendaylight.ovsdb.lib.OvsdbClient;
import org.opendaylight.ovsdb.plugin.api.OvsdbConfigurationService;
import org.opendaylight.ovsdb.plugin.api.OvsdbConnectionService;
import org.opendaylight.ovsdb.plugin.api.StatusWithUuid;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.opendaylight.controller.northbound.commons.RestMessages;
import org.opendaylight.controller.northbound.commons.exception.BadRequestException;
import org.opendaylight.controller.northbound.commons.exception.ServiceUnavailableException;
-import org.opendaylight.controller.sal.core.Node;
import org.opendaylight.controller.sal.utils.ServiceHelper;
import org.opendaylight.ovsdb.lib.OvsdbClient;
import org.opendaylight.ovsdb.lib.notation.Row;
import org.opendaylight.ovsdb.lib.schema.GenericTableSchema;
import org.opendaylight.ovsdb.plugin.api.OvsVswitchdSchemaConstants;
import org.opendaylight.ovsdb.plugin.api.OvsdbConfigurationService;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.DeserializationFeature;
import org.junit.runner.RunWith;
import org.opendaylight.controller.northbound.commons.exception.ResourceNotFoundException;
import org.opendaylight.controller.northbound.commons.exception.ServiceUnavailableException;
-import org.opendaylight.controller.sal.core.Node;
-import org.opendaylight.controller.sal.core.NodeConnector;
import org.opendaylight.controller.sal.utils.ServiceHelper;
import org.opendaylight.ovsdb.plugin.api.Connection;
import org.opendaylight.ovsdb.plugin.api.OvsdbConnectionService;
import org.opendaylight.ovsdb.plugin.impl.ConnectionServiceImpl;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node;
import org.powermock.api.mockito.PowerMockito;
import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.modules.junit4.PowerMockRunner;
@Test
public void testGetOvsdbNode () {
- Node.NodeIDType.registerIDType(OVS, String.class);
- NodeConnector.NodeConnectorIDType.registerIDType(OVS, String.class, OVS);
ConnectionServiceImpl connectionService = new ConnectionServiceImpl();
Connection connection = new Connection(IDENTIFIER, null);
connectionService.putOvsdbConnection(IDENTIFIER, connection);
@Test
public void testGetOvsdbConnection () {
- Node.NodeIDType.registerIDType(OVS, String.class);
- NodeConnector.NodeConnectorIDType.registerIDType(OVS, String.class, OVS);
ConnectionServiceImpl connectionService = new ConnectionServiceImpl();
Connection connection = new Connection(IDENTIFIER, null);
connectionService.putOvsdbConnection(IDENTIFIER, connection);
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</dependency>
+ <dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-simple</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.powermock</groupId>
+ <artifactId>powermock-module-junit4</artifactId>
+ <version>1.5.4</version>
+ <scope>test</scope>
+ </dependency>
</dependencies>
<build>
--- /dev/null
+/*
+ * Copyright (C) 2015 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 : Sam Hague
+ */
+package org.opendaylight.ovsdb.compatibility.plugin.api;
+
+import java.util.ArrayList;
+import java.util.List;
+import org.opendaylight.controller.sal.core.ConstructionException;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeKey;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class NodeUtils {
+ protected static final Logger LOG = LoggerFactory.getLogger(NodeUtils.class);
+
+ public static String getId (String identifier) {
+ String id = identifier;
+
+ String[] pair = identifier.split("\\|");
+ if (pair[0].equals("OVS")) {
+ id = pair[1];
+ }
+ return id;
+ }
+
+ public static Node getMdsalNode (org.opendaylight.controller.sal.core.Node salNode) {
+ String identifier = salNode.getNodeIDString();
+
+ NodeId nodeId = new NodeId("OVS" + "|" + identifier);
+ NodeKey nodeKey = new NodeKey(nodeId);
+ Node node = new NodeBuilder()
+ .setId(nodeId)
+ .setKey(nodeKey)
+ .build();
+
+ return node;
+ }
+
+ public static org.opendaylight.controller.sal.core.Node getSalNode (Node mdsalNode) {
+ String identifier = NodeUtils.getId(mdsalNode.getId().getValue());
+ org.opendaylight.controller.sal.core.Node node = null;
+
+ try {
+ node = new org.opendaylight.controller.sal.core.Node("OVS", identifier);
+ } catch (ConstructionException e) {
+ LOG.error("Failed to allocate sal Node", e);
+ }
+
+ return node;
+ }
+
+ public static List<org.opendaylight.controller.sal.core.Node> getSalNodes (List<Node> mdsalNodes) {
+ List<org.opendaylight.controller.sal.core.Node> nodes = new ArrayList<>();
+
+ for (Node mdsalNode : mdsalNodes) {
+ nodes.add(NodeUtils.getSalNode(mdsalNode));
+ }
+ return nodes;
+ }
+}
import org.opendaylight.controller.sal.core.Node;
import org.opendaylight.controller.sal.utils.Status;
+import org.opendaylight.ovsdb.compatibility.plugin.api.NodeUtils;
import org.opendaylight.ovsdb.compatibility.plugin.api.OvsdbConfigurationService;
import org.opendaylight.ovsdb.compatibility.plugin.api.StatusWithUuid;
import org.opendaylight.ovsdb.compatibility.plugin.error.OvsdbPluginException;
*/
public class ConfigurationServiceImpl implements OvsdbConfigurationService
{
- org.opendaylight.ovsdb.plugin.api.OvsdbConfigurationService pluginOvsdbConfigurationService;
+ private volatile org.opendaylight.ovsdb.plugin.api.OvsdbConfigurationService pluginOvsdbConfigurationService;
void init() {
}
@Override
public StatusWithUuid insertRow(Node node, String tableName, String parentUuid, Row<GenericTableSchema> row) {
- return StatusConvertorUtil.convertOvsdbStatusWithUuidToCompLayerStatusWithUuid(pluginOvsdbConfigurationService.insertRow(node, tableName, parentUuid, row));
+ return StatusConvertorUtil.convertOvsdbStatusWithUuidToCompLayerStatusWithUuid(pluginOvsdbConfigurationService.insertRow(NodeUtils.getMdsalNode(node), tableName, parentUuid, row));
}
@Override
public Status updateRow (Node node, String tableName, String parentUUID, String rowUUID, Row row) {
- return StatusConvertorUtil.convertOvsdbStatusToSalStatus(pluginOvsdbConfigurationService.updateRow(node, tableName, parentUUID, rowUUID, row));
+ return StatusConvertorUtil
+ .convertOvsdbStatusToSalStatus(pluginOvsdbConfigurationService
+ .updateRow(NodeUtils.getMdsalNode(node), tableName, parentUUID, rowUUID, row));
}
@Override
public Status deleteRow(Node node, String tableName, String uuid) {
- return StatusConvertorUtil.convertOvsdbStatusToSalStatus(pluginOvsdbConfigurationService.deleteRow(node, tableName, uuid));
+ return StatusConvertorUtil
+ .convertOvsdbStatusToSalStatus(pluginOvsdbConfigurationService.
+ deleteRow(NodeUtils.getMdsalNode(node), tableName, uuid));
}
@Override
public ConcurrentMap<String, Row> getRows(Node node, String tableName) {
- return pluginOvsdbConfigurationService.getRows(node, tableName);
+ return pluginOvsdbConfigurationService.getRows(NodeUtils.getMdsalNode(node), tableName);
}
@Override
public Row getRow(Node node, String tableName, String uuid) {
- return pluginOvsdbConfigurationService.getRow(node, tableName, uuid);
+ return pluginOvsdbConfigurationService.getRow(NodeUtils.getMdsalNode(node), tableName, uuid);
}
@Override
public List<String> getTables(Node node) {
- return pluginOvsdbConfigurationService.getTables(node);
+ return pluginOvsdbConfigurationService.getTables(NodeUtils.getMdsalNode(node));
}
@Override
public Boolean setOFController(Node node, String bridgeUUID) throws InterruptedException, ExecutionException {
- return pluginOvsdbConfigurationService.setOFController(node, bridgeUUID);
+ return pluginOvsdbConfigurationService.setOFController(NodeUtils.getMdsalNode(node), bridgeUUID);
}
@Override
public <T extends TypedBaseTable<?>> String getTableName(Node node, Class<T> typedClass) {
- return pluginOvsdbConfigurationService.getTableName(node, typedClass);
+ return pluginOvsdbConfigurationService.getTableName(NodeUtils.getMdsalNode(node), typedClass);
}
@Override
public <T extends TypedBaseTable<?>> T getTypedRow(Node node, Class<T> typedClass, Row row) {
- return pluginOvsdbConfigurationService.getTypedRow(node, typedClass, row);
+ return pluginOvsdbConfigurationService.getTypedRow(NodeUtils.getMdsalNode(node), typedClass, row);
}
@Override
public <T extends TypedBaseTable<?>> T createTypedRow(Node node, Class<T> typedClass) {
- return pluginOvsdbConfigurationService.createTypedRow(node, typedClass);
+ return pluginOvsdbConfigurationService.createTypedRow(NodeUtils.getMdsalNode(node), typedClass);
}
@Override
public UUID insertRow(Node node, String databaseName, String tableName, String parentTable, UUID parentUuid,
String parentColumn, Row<GenericTableSchema> row) throws OvsdbPluginException {
- return pluginOvsdbConfigurationService.insertRow(node, databaseName, tableName, parentTable, parentUuid,
- parentColumn, row);
+ return pluginOvsdbConfigurationService
+ .insertRow(NodeUtils.getMdsalNode(node), databaseName, tableName, parentTable, parentUuid,
+ parentColumn, row);
}
@Override
@Override
public Row<GenericTableSchema> insertTree(Node node, String databaseName, String tableName, String parentTable, UUID parentUuid,
String parentColumn, Row<GenericTableSchema> row) throws OvsdbPluginException {
- return pluginOvsdbConfigurationService.insertTree(node, databaseName, tableName, parentTable, parentUuid, parentColumn, row);
+ return pluginOvsdbConfigurationService
+ .insertTree(NodeUtils.getMdsalNode(node), databaseName, tableName, parentTable,
+ parentUuid, parentColumn, row);
}
@Override
public Row<GenericTableSchema> updateRow(Node node, String databaseName,
String tableName, UUID rowUuid, Row<GenericTableSchema> row,
boolean overwrite) throws OvsdbPluginException {
- return pluginOvsdbConfigurationService.updateRow(node, databaseName, tableName, rowUuid, row, overwrite);
+ return pluginOvsdbConfigurationService
+ .updateRow(NodeUtils.getMdsalNode(node), databaseName, tableName, rowUuid, row, overwrite);
}
@Override
public void deleteRow(Node node, String databaseName, String tableName, String parentTable, UUID parentRowUuid,
String parentColumn, UUID rowUuid) throws OvsdbPluginException {
- pluginOvsdbConfigurationService.deleteRow(node, databaseName, tableName, parentTable, parentRowUuid, parentColumn, rowUuid);
+ pluginOvsdbConfigurationService
+ .deleteRow(NodeUtils.getMdsalNode(node), databaseName, tableName, parentTable,
+ parentRowUuid, parentColumn, rowUuid);
}
@Override
@Override
public Row<GenericTableSchema> getRow(Node node, String databaseName,
String tableName, UUID uuid) throws OvsdbPluginException {
- return pluginOvsdbConfigurationService.getRow(node, databaseName, tableName, uuid);
+ return pluginOvsdbConfigurationService
+ .getRow(NodeUtils.getMdsalNode(node), databaseName, tableName, uuid);
}
@Override
public ConcurrentMap<UUID, Row<GenericTableSchema>> getRows(Node node,
String databaseName, String tableName) throws OvsdbPluginException {
- return pluginOvsdbConfigurationService.getRows(node, databaseName, tableName);
+ return pluginOvsdbConfigurationService
+ .getRows(NodeUtils.getMdsalNode(node), databaseName, tableName);
}
@Override
@Override
public List<String> getTables(Node node, String databaseName) throws OvsdbPluginException {
- return pluginOvsdbConfigurationService.getTables(node, databaseName);
+ return pluginOvsdbConfigurationService.getTables(NodeUtils.getMdsalNode(node), databaseName);
}
}
import java.util.Map;
import org.opendaylight.controller.sal.core.Node;
+import org.opendaylight.ovsdb.compatibility.plugin.api.NodeUtils;
import org.opendaylight.ovsdb.compatibility.plugin.api.OvsdbConnectionService;
import org.opendaylight.ovsdb.plugin.api.Connection;
import org.opendaylight.ovsdb.plugin.api.ConnectionConstants;
public class ConnectionServiceImpl implements OvsdbConnectionService{
protected static final Logger logger = LoggerFactory.getLogger(ConnectionServiceImpl.class);
- org.opendaylight.ovsdb.plugin.api.OvsdbConnectionService pluginOvsdbConnectionService;
+ private volatile org.opendaylight.ovsdb.plugin.api.OvsdbConnectionService pluginOvsdbConnectionService;
public void init() {
}
}
@Override
public Connection getConnection(Node node) {
- return pluginOvsdbConnectionService.getConnection(node);
+ return pluginOvsdbConnectionService.getConnection(NodeUtils.getMdsalNode(node));
}
@Override
public Node getNode (String identifier) {
- return pluginOvsdbConnectionService.getNode(identifier);
+ return NodeUtils.getSalNode(pluginOvsdbConnectionService.getNode(identifier));
}
@Override
public List<Node> getNodes() {
- return pluginOvsdbConnectionService.getNodes();
+ return NodeUtils.getSalNodes(pluginOvsdbConnectionService.getNodes());
}
@Override
public Node connect(String identifier, Map<ConnectionConstants, String> params) {
- return pluginOvsdbConnectionService.connect(identifier, params);
+ return NodeUtils.getSalNode(pluginOvsdbConnectionService.connect(identifier, params));
}
}
import org.opendaylight.controller.sal.core.Node;
import org.opendaylight.controller.sal.core.Property;
import org.opendaylight.controller.sal.core.UpdateType;
+import org.opendaylight.ovsdb.compatibility.plugin.api.NodeUtils;
import org.opendaylight.ovsdb.compatibility.plugin.api.OvsdbInventoryListener;
import org.opendaylight.ovsdb.compatibility.plugin.api.OvsdbInventoryService;
import org.opendaylight.ovsdb.lib.message.TableUpdates;
* @author Anil Vishnoi (vishnoianil@gmail.com)
*
*/
-public class InventoryServiceImpl implements OvsdbInventoryService, org.opendaylight.ovsdb.plugin.api.OvsdbInventoryListener {
- org.opendaylight.ovsdb.plugin.api.OvsdbInventoryService pluginOvsdbInventoryService;
+public class InventoryServiceImpl implements OvsdbInventoryService,
+ org.opendaylight.ovsdb.plugin.api.OvsdbInventoryListener {
+ private volatile org.opendaylight.ovsdb.plugin.api.OvsdbInventoryService pluginOvsdbInventoryService;
private Set<OvsdbInventoryListener> ovsdbInventoryListeners = Sets.newCopyOnWriteArraySet();
@Override
public ConcurrentMap<String, ConcurrentMap<String, Row>> getCache(Node n, String databaseName) {
- return pluginOvsdbInventoryService.getCache(n, databaseName);
+ return pluginOvsdbInventoryService.getCache(NodeUtils.getMdsalNode(n), databaseName);
}
@Override
public ConcurrentMap<String, Row> getTableCache(Node n, String databaseName, String tableName) {
- return pluginOvsdbInventoryService.getTableCache(n, databaseName, tableName);
+ return pluginOvsdbInventoryService.getTableCache(NodeUtils.getMdsalNode(n), databaseName, tableName);
}
@Override
public Row getRow(Node n, String databaseName, String tableName, String uuid) {
- return pluginOvsdbInventoryService.getRow(n, databaseName, tableName, uuid);
+ return pluginOvsdbInventoryService.getRow(NodeUtils.getMdsalNode(n), databaseName, tableName, uuid);
}
@Override
public void updateRow(Node n, String databaseName, String tableName, String uuid, Row row) {
- pluginOvsdbInventoryService.updateRow(n, databaseName, tableName, uuid, row);
+ pluginOvsdbInventoryService.updateRow(NodeUtils.getMdsalNode(n), databaseName, tableName, uuid, row);
}
@Override
public void removeRow(Node n, String databaseName, String tableName, String uuid) {
- pluginOvsdbInventoryService.removeRow(n, databaseName, tableName, uuid);
+ pluginOvsdbInventoryService.removeRow(NodeUtils.getMdsalNode(n), databaseName, tableName, uuid);
}
@Override
public void processTableUpdates(Node n, String databaseName, TableUpdates tableUpdates) {
- pluginOvsdbInventoryService.processTableUpdates(n, databaseName, tableUpdates);
+ pluginOvsdbInventoryService.processTableUpdates(NodeUtils.getMdsalNode(n), databaseName, tableUpdates);
}
@Override
public void printCache(Node n) {
- pluginOvsdbInventoryService.printCache(n);
+ pluginOvsdbInventoryService.printCache(NodeUtils.getMdsalNode(n));
}
@Override
public void addNode(Node node, Set<Property> props) {
- pluginOvsdbInventoryService.addNode(node, props);
+ pluginOvsdbInventoryService.addNode(NodeUtils.getMdsalNode(node), props);
}
@Override
public void notifyNodeAdded(Node node, InetAddress address, int port) {
- pluginOvsdbInventoryService.notifyNodeAdded(node, address, port);
+ pluginOvsdbInventoryService.notifyNodeAdded(NodeUtils.getMdsalNode(node), address, port);
}
@Override
public void addNodeProperty(Node node, UpdateType type, Set<Property> props) {
- pluginOvsdbInventoryService.addNodeProperty(node, type, props);
+ pluginOvsdbInventoryService.addNodeProperty(NodeUtils.getMdsalNode(node), type, props);
}
@Override
public void removeNode(Node node) {
- pluginOvsdbInventoryService.removeNode(node);
+ pluginOvsdbInventoryService.removeNode(NodeUtils.getMdsalNode(node));
}
@Override
- public void nodeAdded(Node node, InetAddress address, int port) {
+ public void nodeAdded(org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node node,
+ InetAddress address, int port) {
for(OvsdbInventoryListener listener : this.ovsdbInventoryListeners)
- listener.nodeAdded(node, address, port);
+ listener.nodeAdded(NodeUtils.getSalNode(node), address, port);
}
@Override
- public void nodeRemoved(Node node) {
+ public void nodeRemoved(org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node node) {
for(OvsdbInventoryListener listener : this.ovsdbInventoryListeners)
- listener.nodeRemoved(node);
+ listener.nodeRemoved(NodeUtils.getSalNode(node));
}
@Override
- public void rowAdded(Node node, String tableName, String uuid, Row row) {
+ public void rowAdded(org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node node,
+ String tableName, String uuid, Row row) {
for(OvsdbInventoryListener listener : this.ovsdbInventoryListeners)
- listener.rowAdded(node, tableName, uuid, row);
+ listener.rowAdded(NodeUtils.getSalNode(node), tableName, uuid, row);
}
@Override
- public void rowUpdated(Node node, String tableName, String uuid, Row old,
+ public void rowUpdated(org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node node,
+ String tableName, String uuid, Row old,
Row row) {
for(OvsdbInventoryListener listener : this.ovsdbInventoryListeners)
- listener.rowUpdated(node, tableName, uuid, old, row);
+ listener.rowUpdated(NodeUtils.getSalNode(node), tableName, uuid, old, row);
}
@Override
- public void rowRemoved(Node node, String tableName, String uuid, Row row,
+ public void rowRemoved(org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node node,
+ String tableName, String uuid, Row row,
Object context) {
for(OvsdbInventoryListener listener : this.ovsdbInventoryListeners)
- listener.rowRemoved(node, tableName, uuid, row, context);
+ listener.rowRemoved(NodeUtils.getSalNode(node), tableName, uuid, row, context);
}
}
import org.apache.felix.dm.Component;
import org.opendaylight.controller.sal.core.ComponentActivatorAbstractBase;
+import org.opendaylight.controller.sal.core.Node;
import org.opendaylight.ovsdb.compatibility.plugin.api.OvsdbConfigurationService;
import org.opendaylight.ovsdb.compatibility.plugin.api.OvsdbConnectionService;
import org.opendaylight.ovsdb.compatibility.plugin.api.OvsdbInventoryListener;
*/
@Override
public void init() {
+ Node.NodeIDType.registerIDType("OVS", String.class);
}
/**
*/
@Override
public void destroy() {
+ Node.NodeIDType.unRegisterIDType("OVS");
}
@Override
public Object[] getGlobalImplementations() {
--- /dev/null
+/*
+ * Copyright (C) 2015 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 : Sam Hague
+ */
+package org.opendaylight.ovsdb.compatibility.plugin.impl;
+
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertSame;
+import static org.junit.Assert.fail;
+
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.opendaylight.controller.sal.core.ConstructionException;
+import org.opendaylight.controller.sal.core.Node;
+import org.opendaylight.controller.sal.core.NodeConnector;
+import org.opendaylight.ovsdb.plugin.api.Connection;
+
+public class ConnectionServiceImplTest {
+ private static final String OVS = "OVS";
+ private static final String IDENTIFIER = "192.168.120.31:45001";
+ private static final String OVS_IDENTIFIER = OVS + "|" + IDENTIFIER;
+ private static final String BAD_IDENTIFIER = "BAD" + "|" + IDENTIFIER;
+ private static org.opendaylight.ovsdb.plugin.impl.ConnectionServiceImpl pluginConnectionService;
+ private static ConnectionServiceImpl connectionService;
+
+ @BeforeClass
+ public static void setUp () {
+ Node.NodeIDType.registerIDType(OVS, String.class);
+ NodeConnector.NodeConnectorIDType.registerIDType(OVS, String.class, OVS);
+ pluginConnectionService = new org.opendaylight.ovsdb.plugin.impl.ConnectionServiceImpl();
+ Connection connection = new Connection(IDENTIFIER, null);
+ pluginConnectionService.putOvsdbConnection(IDENTIFIER, connection);
+
+ connectionService = new ConnectionServiceImpl();
+ connectionService.setOvsdbConnectionService(pluginConnectionService);
+ }
+
+ @Test
+ public void testGetNode () {
+ Node node = connectionService.getNode(IDENTIFIER);
+ assertNotNull("Node " + IDENTIFIER + " is null", node);
+
+ node = connectionService.getNode(OVS_IDENTIFIER);
+ assertNotNull("Node " + OVS_IDENTIFIER + " is null", node);
+
+ try {
+ node = connectionService.getNode(BAD_IDENTIFIER);
+ fail("Expected a NullPointerException to be thrown");
+ } catch (NullPointerException e) {
+ assertSame(NullPointerException.class, e.getClass());
+ }
+ }
+
+ @Test
+ public void testGetConnection () {
+ Node node = connectionService.getNode(IDENTIFIER);
+ assertNotNull("Node " + IDENTIFIER + " is null", node);
+
+ Connection connection = connectionService.getConnection(node);
+ assertNotNull("Connection " + IDENTIFIER + " is null", connection);
+
+ try {
+ connection = connectionService.getConnection(null);
+ fail("Expected a NullPointerException to be thrown");
+ } catch (NullPointerException e) {
+ assertSame(NullPointerException.class, e.getClass());
+ }
+
+ try {
+ node = new Node("OVS", BAD_IDENTIFIER);
+ } catch (ConstructionException e) {
+ fail("Exception should not have occurred" + e);
+ }
+ connection = connectionService.getConnection(node);
+ assertNull("Connection " + BAD_IDENTIFIER + " is not null", connection);
+ }
+}
+++ /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 : Sam Hague
- */
-package org.opendaylight.ovsdb.compatibility.plugin.impl;
-
-import static org.junit.Assert.assertTrue;
-import org.junit.Test;
-
-public class NodeFactoryTest {
-
- @Test
- public void testFromString () {
- assertTrue(true);
- }
-}
import org.apache.felix.gogo.commands.Argument;
import org.apache.felix.gogo.commands.Command;
import org.apache.karaf.shell.console.OsgiCommandSupport;
-import org.opendaylight.controller.sal.core.Node;
import org.opendaylight.ovsdb.plugin.api.OvsdbInventoryService;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeKey;
@Command(scope = "ovs", name = "printCache", description="Prints OVSDB Cache")
public class PrintCache extends OsgiCommandSupport{
@Override
protected Object doExecute() throws Exception {
- Node node = Node.fromString(nodeName);
+ NodeId nodeId = new NodeId(nodeName);
+ NodeKey nodeKey = new NodeKey(nodeId);
+ Node node = new NodeBuilder()
+ .setId(nodeId)
+ .setKey(nodeKey)
+ .build();
ovsdbInventory.printCache(node);
return null;
}
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
-import static org.mockito.Mockito.when;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import java.io.PrintStream;
import java.lang.reflect.Field;
import java.util.Set;
-import org.junit.runner.RunWith;
import org.junit.Test;
-import org.opendaylight.controller.sal.core.Node;
-import org.opendaylight.controller.sal.core.NodeConnector;
import org.opendaylight.ovsdb.lib.notation.Column;
import org.opendaylight.ovsdb.lib.notation.Row;
import org.opendaylight.ovsdb.lib.notation.UUID;
import org.opendaylight.ovsdb.lib.schema.GenericTableSchema;
import org.opendaylight.ovsdb.plugin.api.OvsVswitchdSchemaConstants;
import org.opendaylight.ovsdb.plugin.impl.InventoryServiceImpl;
-import org.powermock.api.mockito.PowerMockito;
-import org.powermock.core.classloader.annotations.PrepareForTest;
-import org.powermock.modules.junit4.PowerMockRunner;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeKey;
-@RunWith(PowerMockRunner.class)
-@PrepareForTest(Node.class)
public class PrintCacheTest {
- private static final String NODESTRING = "OVS:10.10.10.10:65342";
+ private static final String NODESTRING = "OVS|10.10.10.10:65342";
private static final String BRIDGES = "bridges";
private static final String OVS = "OVS";
private static final String BRIDGE = "bridge1";
assertNotNull(schema);
assertEquals(Version.fromString("6.12.0"), schema.getVersion());
- // mock a node since PrintCache requires a Node
- Node.NodeIDType.registerIDType(OVS, String.class);
- NodeConnector.NodeConnectorIDType.registerIDType(OVS, String.class, OVS);
- Node node = new Node(OVS, "1");
- PowerMockito.mockStatic(Node.class);
- when(Node.fromString(NODESTRING)).thenReturn(node);
-
// Add params to PrintCache
PrintCache printCacheTest = new PrintCache();
Field cNField = printCacheTest.getClass().getDeclaredField("nodeName");
Column column = new Column(bridges, new UUID(BRIDGE).toString());
Row row = new Row(ovsTable);
row.addColumn(BRIDGES, column);
+
+ NodeId nodeId = new NodeId(NODESTRING);
+ NodeKey nodeKey = new NodeKey(nodeId);
+ Node node = new NodeBuilder()
+ .setId(nodeId)
+ .setKey(nodeKey)
+ .build();
inventoryService.updateRow(node, OvsVswitchdSchemaConstants.DATABASE_NAME, OPENVSWITCH, new UUID("1").toString(), row);
// Test that a populated cache is printed correctly
<artifactId>utils.config</artifactId>
<version>${ovsdb.utils.config.version}</version>
</dependency>
+ <dependency>
+ <groupId>org.opendaylight.controller.model</groupId>
+ <artifactId>model-inventory</artifactId>
+ </dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</dependency>
+ <dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-simple</artifactId>
+ </dependency>
</dependencies>
<build>
*/
package org.opendaylight.ovsdb.plugin.api;
-import org.opendaylight.controller.sal.core.ConstructionException;
-import org.opendaylight.controller.sal.core.Node;
import org.opendaylight.ovsdb.lib.OvsdbClient;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeKey;
+
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
private static final Logger logger = LoggerFactory.getLogger(Connection.class);
public Connection(String identifier, OvsdbClient client) {
-
super();
this.identifier = identifier;
this.client = client;
this.idCounter = 0L;
- try {
- node = new Node("OVS", identifier);
- } catch (ConstructionException e) {
- logger.error("Error creating OVS node with identifier " + identifier, e);
- }
+ NodeId nodeId = new NodeId("OVS" + "|" + identifier);
+ NodeKey nodeKey = new NodeKey(nodeId);
+ node = new NodeBuilder()
+ .setId(nodeId)
+ .setKey(nodeKey)
+ .build();
}
public String getIdentifier() {
import java.util.concurrent.ConcurrentMap;
import java.util.concurrent.ExecutionException;
-import org.opendaylight.controller.sal.core.Node;
-import org.opendaylight.ovsdb.plugin.api.Status;
import org.opendaylight.ovsdb.lib.notation.Row;
import org.opendaylight.ovsdb.lib.notation.UUID;
import org.opendaylight.ovsdb.lib.schema.GenericTableSchema;
import org.opendaylight.ovsdb.lib.schema.typed.TypedBaseTable;
import org.opendaylight.ovsdb.plugin.error.OvsdbPluginException;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node;
public interface OvsdbConfigurationService {
import java.util.List;
import java.util.Map;
-import org.opendaylight.controller.sal.core.Node;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node;
public interface OvsdbConnectionService {
public Connection getConnection(Node node);
*/
package org.opendaylight.ovsdb.plugin.api;
-import org.opendaylight.controller.sal.core.Node;
import org.opendaylight.ovsdb.lib.notation.Row;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node;
import java.net.InetAddress;
import java.util.Set;
import java.util.concurrent.ConcurrentMap;
-import org.opendaylight.controller.sal.core.Node;
import org.opendaylight.controller.sal.core.Property;
import org.opendaylight.controller.sal.core.UpdateType;
import org.opendaylight.ovsdb.lib.message.TableUpdates;
import org.opendaylight.ovsdb.lib.notation.Row;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node;
public interface OvsdbInventoryService {
public ConcurrentMap<String, ConcurrentMap<String, Row>> getCache(Node n, String databaseName);
import java.util.concurrent.ConcurrentMap;
import java.util.concurrent.ExecutionException;
-import org.opendaylight.controller.sal.core.Node;
import org.opendaylight.ovsdb.plugin.api.Status;
import org.opendaylight.ovsdb.plugin.api.StatusCode;
import org.opendaylight.ovsdb.lib.OvsdbClient;
import org.opendaylight.ovsdb.schema.openvswitch.OpenVSwitch;
import org.opendaylight.ovsdb.schema.openvswitch.Port;
import org.opendaylight.ovsdb.utils.config.ConfigProperties;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.concurrent.ConcurrentMap;
import java.util.concurrent.ExecutionException;
-import org.opendaylight.controller.sal.core.Node;
import org.opendaylight.controller.sal.core.Property;
import org.opendaylight.ovsdb.lib.MonitorCallBack;
import org.opendaylight.ovsdb.lib.OvsdbClient;
import org.opendaylight.ovsdb.plugin.api.OvsdbConnectionService;
import org.opendaylight.ovsdb.plugin.api.OvsdbInventoryService;
import org.opendaylight.ovsdb.utils.config.ConfigProperties;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
}
public Status disconnect(Node node) {
- String identifier = (String) node.getID();
- Connection connection = ovsdbConnections.get(identifier);
+ Connection connection = getConnection(node);
if (connection != null) {
- ovsdbConnections.remove(identifier);
+ ovsdbConnections.remove(normalizeId(node.getId().getValue()));
connection.disconnect();
ovsdbInventoryService.removeNode(node);
return new Status(StatusCode.SUCCESS);
this.handlers = handlers;
}
- @Override
- public Connection getConnection(Node node) {
- String identifier = (String) node.getID();
- return ovsdbConnections.get(identifier);
- }
-
- @Override
- public Node getNode (String identifier) {
+ private String normalizeId (String identifier) {
String id = identifier;
String[] pair = identifier.split("\\|");
id = pair[1];
}
- Connection connection = ovsdbConnections.get(id);
+ return id;
+ }
+
+ @Override
+ public Connection getConnection(Node node) {
+ return ovsdbConnections.get(normalizeId(node.getId().getValue()));
+ }
+
+ @Override
+ public Node getNode (String identifier) {
+ Connection connection = ovsdbConnections.get(normalizeId(identifier));
if (connection != null) {
return connection.getNode();
} else {
}
public TableUpdates monitorTables(Node node, DatabaseSchema dbSchema) throws ExecutionException, InterruptedException, IOException {
- String identifier = (String) node.getID();
- Connection connection = ovsdbConnections.get(identifier);
+ Connection connection = getConnection(node);
OvsdbClient client = connection.getClient();
if (dbSchema == null) {
logger.error("Unable to get Database Schema for the ovsdb connection : {}", client.getConnectionInfo());
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
-import org.opendaylight.controller.sal.core.Node;
-import org.opendaylight.controller.sal.core.NodeConnector;
import org.opendaylight.controller.sal.core.Property;
import org.opendaylight.controller.sal.core.UpdateType;
import org.opendaylight.ovsdb.lib.message.TableUpdate;
import org.opendaylight.ovsdb.plugin.api.OvsdbConfigurationService;
import org.opendaylight.ovsdb.plugin.api.OvsdbInventoryListener;
import org.opendaylight.ovsdb.plugin.api.OvsdbInventoryService;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node;
import com.google.common.collect.Sets;
import org.slf4j.Logger;
import org.apache.felix.dm.DependencyActivatorBase;
import org.apache.felix.dm.DependencyManager;
-import org.opendaylight.controller.sal.core.Node;
-import org.opendaylight.controller.sal.core.NodeConnector;
import org.opendaylight.ovsdb.lib.OvsdbConnection;
import org.opendaylight.ovsdb.lib.OvsdbConnectionListener;
import org.opendaylight.ovsdb.plugin.api.OvsdbConfigurationService;
@Override
public void init(BundleContext context, DependencyManager manager) throws Exception {
- Node.NodeIDType.registerIDType("OVS", String.class);
- NodeConnector.NodeConnectorIDType.registerIDType("OVS", String.class, "OVS");
-
manager.add(createComponent()
.setInterface(OvsdbConfigurationService.class.getName(), null)
.setImplementation(ConfigurationServiceImpl.class)
@Override
public void destroy(BundleContext context, DependencyManager manager) throws Exception {
- Node.NodeIDType.unRegisterIDType("OVS");
- NodeConnector.NodeConnectorIDType.unRegisterIDType("OVS");
}
}
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertSame;
+import static org.junit.Assert.fail;
+import org.junit.BeforeClass;
import org.junit.Test;
-import org.opendaylight.controller.sal.core.Node;
-import org.opendaylight.controller.sal.core.NodeConnector;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node;
import org.opendaylight.ovsdb.plugin.api.Connection;
public class ConnectionServiceImplTest {
private static final String IDENTIFIER = "192.168.120.31:45001";
private static final String OVS_IDENTIFIER = OVS + "|" + IDENTIFIER;
private static final String BAD_IDENTIFIER = "BAD" + "|" + IDENTIFIER;
+ private static ConnectionServiceImpl connectionService;
- @Test
- public void testGetNode () {
- Node.NodeIDType.registerIDType(OVS, String.class);
- NodeConnector.NodeConnectorIDType.registerIDType(OVS, String.class, OVS);
- ConnectionServiceImpl connectionService = new ConnectionServiceImpl();
+ @BeforeClass
+ public static void setUp () {
+ connectionService = new ConnectionServiceImpl();
Connection connection = new Connection(IDENTIFIER, null);
connectionService.putOvsdbConnection(IDENTIFIER, connection);
+ }
+ @Test
+ public void testGetNode () {
Node node = connectionService.getNode(IDENTIFIER);
assertNotNull("Node " + IDENTIFIER + " is null", node);
node = connectionService.getNode(IDENTIFIER + "extra");
assertNull("Node " + BAD_IDENTIFIER + " is not null", node);
}
+
+ @Test
+ public void testGetConnection () {
+ Node node = connectionService.getNode(IDENTIFIER);
+ assertNotNull("Node " + IDENTIFIER + " is null", node);
+
+ Connection connection = connectionService.getConnection(node);
+ assertNotNull("Connection " + IDENTIFIER + " is null", connection);
+
+ try {
+ connection = connectionService.getConnection(null);
+ fail("Expected a NullPointerException to be thrown");
+ } catch (NullPointerException e) {
+ assertSame(NullPointerException.class, e.getClass());
+ }
+ }
}
+++ /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 : Sam Hague
- */
-package org.opendaylight.ovsdb.plugin.impl;
-
-import static org.junit.Assert.assertTrue;
-import org.junit.Test;
-
-public class NodeFactoryTest {
-
- @Test
- public void testFromString () {
- assertTrue(true);
- }
-}
<module>plugin</module>
<module>ovsdb-plugin-compatibility-layer</module>
<module>plugin-shell</module>
- <module>plugin-mdsal-adapter</module>
<module>schemas/hardwarevtep</module>
<module>schemas/openvswitch</module>
<module>southbound</module>