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.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.lib.notation.UUID;
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.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.plugin.api.OvsdbConfigurationService;
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;
+
+import org.apache.commons.lang3.tuple.ImmutablePair;
import org.apache.felix.dm.Component;
import org.apache.felix.dm.DependencyManager;
import org.junit.After;
private BundleContext bc;
@Inject
- private OvsdbConfigService ovsdbConfigService;
+ private OvsdbConfigurationService ovsdbConfigurationService;
private Node node = null;
- Component of10Provider;
Component of13Provider;
@Inject
BridgeConfigurationManager bridgeConfigurationManager;
@Inject
- ConfigurationService configurationService;
+ ConfigurationService netVirtConfigurationService;
Boolean tearDownBridge = false;
+ ImmutablePair<UUID, Map<String, String>> tearDownOpenVSwitchOtherConfig = null;
// Configure the OSGi container
@Configuration
propagateSystemProperty("ovsdbserver.ipaddress"),
propagateSystemProperty("ovsdbserver.port"),
+ ConfigurationBundles.mdsalBundles(),
ConfigurationBundles.controllerBundles(),
ConfigurationBundles.ovsdbLibraryBundles(),
ConfigurationBundles.ovsdbDefaultSchemaBundles(),
ConfigurationBundles.ovsdbPluginBundles(),
- ConfigurationBundles.ovsdbNeutronBundles(),
- junitBundles()
+ ConfigurationBundles.ovsdbNeutronBundles()
);
}
- 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);
}
//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);
}
Thread.sleep(5000);
// Create the integration bridge
- bridgeConfigurationManager.prepareNode(node);
+ bridgeConfigurationManager.prepareNode(NodeUtils.getSalNode(node));
Map<String, Row>
bridgeRows =
- ovsdbConfigService.getRows(node, ovsdbConfigService.getTableName(node, Bridge.class));
+ ovsdbConfigurationService.getRows(node, ovsdbConfigurationService.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());
+ Bridge bridgeRow = ovsdbConfigurationService.getTypedRow(node, Bridge.class, bridgeRows.values().iterator().next());
+ Assert.assertEquals(netVirtConfigurationService.getIntegrationBridgeName(), bridgeRow.getName());
- String uuid = bridgeConfigurationManager.getBridgeUuid(node, configurationService.getIntegrationBridgeName());
+ String uuid = bridgeConfigurationManager.getBridgeUuid(NodeUtils.getSalNode(node),
+ netVirtConfigurationService.getIntegrationBridgeName());
Assert.assertEquals(uuid, bridgeRow.getUuid().toString());
tearDownBridge = true;
final String endpointAddress = "10.10.10.10";
- Map<String, Row> ovsRows = ovsdbConfigService.getRows(node,
- ovsdbConfigService.getTableName(node, OpenVSwitch.class));
- OpenVSwitch ovsRow = ovsdbConfigService.getTypedRow(node,
+ Map<String, Row> ovsRows = ovsdbConfigurationService.getRows(node,
+ ovsdbConfigurationService.getTableName(node, OpenVSwitch.class));
+ OpenVSwitch ovsRow = ovsdbConfigurationService.getTypedRow(node,
OpenVSwitch.class,
ovsRows.values().iterator().next());
- Assert.assertEquals(null, configurationService.getTunnelEndPoint(node));
+ Assert.assertEquals(null, netVirtConfigurationService.getTunnelEndPoint(NodeUtils.getSalNode(node)));
+ final UUID originalVersion = ovsRow.getVersion();
+
+ OpenVSwitch updateOvsRow = ovsdbConfigurationService.createTypedRow(node, OpenVSwitch.class);
+
+ updateOvsRow.setOtherConfig(
+ ImmutableMap.of(netVirtConfigurationService.getTunnelEndpointKey(), endpointAddress));
+
+ ovsdbConfigurationService.updateRow(node,
+ ovsdbConfigurationService.getTableName(node, OpenVSwitch.class),
+ null,
+ ovsRow.getUuid().toString(),
+ updateOvsRow.getRow());
+
+ // Remember original value so it can be restored on tearDown
+ tearDownOpenVSwitchOtherConfig = ImmutablePair.of(ovsRow.getUuid(),
+ ovsRow.getOtherConfigColumn().getData());
+
+ // Make sure tunnel end point was set
+ Assert.assertEquals(InetAddress.getByName(endpointAddress),
+ netVirtConfigurationService.getTunnelEndPoint(NodeUtils.getSalNode(node)));
- ovsRow.setOtherConfig(ImmutableMap.of(configurationService.getTunnelEndpointKey(), endpointAddress));
- ovsdbConfigService.updateRow(node,
- ovsdbConfigService.getTableName(node, OpenVSwitch.class),
- null,
- ovsRow.getUuid().toString(),
- ovsRow.getRow());
+ // Fetch rows again, and compare tunnel end point values
+ ovsRows = ovsdbConfigurationService.getRows(node,
+ ovsdbConfigurationService.getTableName(node,
+ OpenVSwitch.class));
+ ovsRow = ovsdbConfigurationService.getTypedRow(node,
+ OpenVSwitch.class,
+ ovsRows.values().iterator().next());
- Assert.assertEquals(InetAddress.getByName(endpointAddress), configurationService.getTunnelEndPoint(node));
+ Assert.assertEquals(ovsRow.getOtherConfigColumn(), updateOvsRow.getOtherConfigColumn());
+
+ // expect version of row to be changed, due to the update
+ Assert.assertNotEquals(ovsRow.getVersion(), originalVersion);
}
@Test
Thread.sleep(5000);
Version ovsVersion = this.getOvsVersion();
+ if (ovsVersion.compareTo(Constants.OPENFLOW13_SUPPORTED) >= 0) {
+ Assert.assertEquals(Constants.OPENFLOW13,
+ netVirtConfigurationService.getOpenflowVersion(NodeUtils.getSalNode(node)));
+ }
+ }
- if (ovsVersion.compareTo(Constants.OPENFLOW13_SUPPORTED) < 0) {
- Assert.assertEquals(Constants.OPENFLOW10, configurationService.getOpenflowVersion(node));
- } else {
- Assert.assertEquals(Constants.OPENFLOW13, configurationService.getOpenflowVersion(node));
+ @Test
+ public void testGetDefaultGatewayMacAddress() throws Exception {
+ // Thread.sleep(5000);
+ String defaultGatewayMacAddress = netVirtConfigurationService.
+ getDefaultGatewayMacAddress(NodeUtils.getSalNode(node));
+
+ if (defaultGatewayMacAddress != null) {
+ String[] splits = defaultGatewayMacAddress.split(":");
+ Assert.assertTrue("Unexpected mac format", splits.length == 6);
}
+ // log.info("testGetDefaultGatewayMacAddress got mac {}", defaultGatewayMacAddress);
}
@After
Thread.sleep(5000);
if (tearDownBridge) {
- String uuid = bridgeConfigurationManager.getBridgeUuid(node,
- configurationService.getIntegrationBridgeName());
- ovsdbConfigService.deleteRow(node, ovsdbConfigService.getTableName(node, Bridge.class), uuid);
+ try {
+ 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());
+ }
tearDownBridge = false;
}
+ if (tearDownOpenVSwitchOtherConfig != null) {
+ try {
+ OpenVSwitch updateOvsRow = ovsdbConfigurationService.createTypedRow(node, OpenVSwitch.class);
+ updateOvsRow.setOtherConfig(tearDownOpenVSwitchOtherConfig.getRight());
+ ovsdbConfigurationService.updateRow(node,
+ ovsdbConfigurationService.getTableName(node, OpenVSwitch.class),
+ null,
+ tearDownOpenVSwitchOtherConfig.getLeft().toString(),
+ updateOvsRow.getRow());
+ } catch (Exception e) {
+ log.error("tearDownOpenVSwitchOtherConfig Exception : " + e.getMessage());
+ }
+ tearDownOpenVSwitchOtherConfig = null;
+ }
+
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,
+ Map<String, Row> ovsRows = ovsdbConfigurationService.getRows(node,
+ ovsdbConfigurationService.getTableName(node, OpenVSwitch.class));
+ OpenVSwitch ovsRow = ovsdbConfigurationService.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;
- }
+ private class FakeOF13Provider implements NetworkingProvider {
@Override
- public Status handleInterfaceDelete(String tunnelType, NeutronNetwork network, Node source, Interface intf,
- boolean isLastInstanceOnNode) {
+ public String getName() {
return null;
}
@Override
- public void initializeFlowRules(Node node) {
-
- }
-
- @Override
- public void initializeOFFlowRules(Node openflowNode) {
-
+ public boolean supportsServices() {
+ return false;
}
- }
-
- private class FakeOF13Provider implements NetworkingProvider {
@Override
public boolean hasPerTenantTunneling() {
}
@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) {
}
}