2 * Copyright (C) 2014 Red Hat, Inc.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
8 * Authors : Dave Tucker
11 package org.opendaylight.ovsdb.integrationtest.neutron;
13 import static org.junit.Assert.assertFalse;
14 import static org.junit.Assert.assertNotNull;
15 import static org.junit.Assert.fail;
16 import static org.ops4j.pax.exam.CoreOptions.junitBundles;
17 import static org.ops4j.pax.exam.CoreOptions.options;
18 import static org.ops4j.pax.exam.CoreOptions.propagateSystemProperty;
19 import static org.ops4j.pax.exam.CoreOptions.systemProperty;
21 import org.opendaylight.controller.networkconfig.neutron.NeutronNetwork;
22 import org.opendaylight.controller.sal.core.Node;
23 import org.opendaylight.controller.sal.utils.Status;
24 import org.opendaylight.ovsdb.integrationtest.ConfigurationBundles;
25 import org.opendaylight.ovsdb.integrationtest.OvsdbIntegrationTestBase;
26 import org.opendaylight.ovsdb.lib.notation.Row;
27 import org.opendaylight.ovsdb.lib.notation.Version;
28 import org.opendaylight.ovsdb.openstack.netvirt.api.Constants;
29 import org.opendaylight.ovsdb.openstack.netvirt.api.BridgeConfigurationManager;
30 import org.opendaylight.ovsdb.openstack.netvirt.api.NetworkingProvider;
31 import org.opendaylight.ovsdb.plugin.api.OvsdbConfigurationService;
32 import org.opendaylight.ovsdb.schema.openvswitch.Bridge;
33 import org.opendaylight.ovsdb.schema.openvswitch.Interface;
34 import org.opendaylight.ovsdb.schema.openvswitch.OpenVSwitch;
36 import com.google.common.collect.ImmutableMap;
37 import org.apache.felix.dm.Component;
38 import org.apache.felix.dm.DependencyManager;
39 import org.junit.After;
40 import org.junit.Assert;
41 import org.junit.Before;
42 import org.junit.Test;
43 import org.junit.runner.RunWith;
44 import org.ops4j.pax.exam.Configuration;
45 import org.ops4j.pax.exam.Option;
46 import org.ops4j.pax.exam.junit.PaxExam;
47 import org.ops4j.pax.exam.spi.reactors.ExamReactorStrategy;
48 import org.ops4j.pax.exam.spi.reactors.PerClass;
49 import org.ops4j.pax.exam.util.PathUtils;
50 import org.osgi.framework.Bundle;
51 import org.osgi.framework.BundleContext;
52 import org.slf4j.Logger;
53 import org.slf4j.LoggerFactory;
55 import java.io.IOException;
56 import java.net.InetAddress;
58 import java.util.Properties;
59 import java.util.concurrent.ExecutionException;
60 import java.util.concurrent.TimeoutException;
62 import javax.inject.Inject;
65 @RunWith(PaxExam.class)
66 @ExamReactorStrategy(PerClass.class)
67 public class NeutronIT extends OvsdbIntegrationTestBase {
68 private Logger log = LoggerFactory.getLogger(NeutronIT.class);
70 private BundleContext bc;
73 private OvsdbConfigurationService ovsdbConfigurationService;
74 private Node node = null;
76 Component of10Provider;
77 Component of13Provider;
80 BridgeConfigurationManager bridgeConfigurationManager;
82 org.opendaylight.ovsdb.openstack.netvirt.api.ConfigurationService netVirtConfigurationService;
84 Boolean tearDownBridge = false;
86 // Configure the OSGi container
88 public Option[] config() {
91 systemProperty("logback.configurationFile").value(
92 "file:" + PathUtils.getBaseDir()
93 + "/src/test/resources/logback.xml"
95 // To start OSGi console for inspection remotely
96 systemProperty("osgi.console").value("2401"),
98 propagateSystemProperty("ovsdbserver.ipaddress"),
99 propagateSystemProperty("ovsdbserver.port"),
101 ConfigurationBundles.controllerBundles(),
102 ConfigurationBundles.ovsdbLibraryBundles(),
103 ConfigurationBundles.ovsdbDefaultSchemaBundles(),
104 ConfigurationBundles.ovsdbPluginBundles(),
105 ConfigurationBundles.ovsdbNeutronBundles(),
110 private String stateToString(int state) {
114 case Bundle.INSTALLED:
116 case Bundle.RESOLVED:
118 case Bundle.UNINSTALLED:
119 return "UNINSTALLED";
121 return "Not CONVERTED";
126 public void areWeReady() throws InterruptedException, ExecutionException, IOException, TimeoutException {
128 boolean debugit = false;
129 Bundle b[] = bc.getBundles();
130 for (Bundle element : b) {
131 int state = element.getState();
132 if (state != Bundle.ACTIVE && state != Bundle.RESOLVED) {
133 log.info("Bundle:" + element.getSymbolicName() + " state:"
134 + stateToString(state));
139 log.debug("Do some debugging because some bundle is unresolved");
142 assertFalse(debugit);
146 node = getPluginTestConnection();
147 } catch (Exception e) {
148 fail("Exception : " + e.getMessage());
152 //Register fake NetworkingProviders
153 Properties of10Properties = new Properties();
154 of10Properties.put(Constants.OPENFLOW_VERSION_PROPERTY, Constants.OPENFLOW10);
156 Properties of13Properties = new Properties();
157 of13Properties.put(Constants.OPENFLOW_VERSION_PROPERTY, Constants.OPENFLOW13);
159 DependencyManager dm = new DependencyManager(bc);
161 of10Provider = dm.createComponent();
162 of10Provider.setInterface(NetworkingProvider.class.getName(), of10Properties);
163 of10Provider.setImplementation(new FakeOF10Provider());
165 of13Provider = dm.createComponent();
166 of13Provider.setInterface(NetworkingProvider.class.getName(), of13Properties);
167 of13Provider.setImplementation(new FakeOF13Provider());
169 dm.add(of10Provider);
170 dm.add(of13Provider);
174 public void testPrepareNode() throws Exception {
177 // Create the integration bridge
178 bridgeConfigurationManager.prepareNode(node);
182 ovsdbConfigurationService.getRows(node, ovsdbConfigurationService.getTableName(node, Bridge.class));
183 Assert.assertEquals(1, bridgeRows.size());
185 Bridge bridgeRow = ovsdbConfigurationService.getTypedRow(node, Bridge.class, bridgeRows.values().iterator().next());
186 Assert.assertEquals(netVirtConfigurationService.getIntegrationBridgeName(), bridgeRow.getName());
188 String uuid = bridgeConfigurationManager.getBridgeUuid(node, netVirtConfigurationService.getIntegrationBridgeName());
189 Assert.assertEquals(uuid, bridgeRow.getUuid().toString());
191 tearDownBridge = true;
195 public void testGetTunnelEndpoint() throws Exception {
198 final String endpointAddress = "10.10.10.10";
200 Map<String, Row> ovsRows = ovsdbConfigurationService.getRows(node,
201 ovsdbConfigurationService.getTableName(node, OpenVSwitch.class));
202 OpenVSwitch ovsRow = ovsdbConfigurationService.getTypedRow(node,
204 ovsRows.values().iterator().next());
206 Assert.assertEquals(null, netVirtConfigurationService.getTunnelEndPoint(node));
208 ovsRow.setOtherConfig(ImmutableMap.of(netVirtConfigurationService.getTunnelEndpointKey(), endpointAddress));
209 ovsdbConfigurationService.updateRow(node,
210 ovsdbConfigurationService.getTableName(node, OpenVSwitch.class),
212 ovsRow.getUuid().toString(),
215 Assert.assertEquals(InetAddress.getByName(endpointAddress), netVirtConfigurationService.getTunnelEndPoint(node));
219 public void testGetOpenflowVersion() throws Exception {
222 Version ovsVersion = this.getOvsVersion();
224 if (ovsVersion.compareTo(Constants.OPENFLOW13_SUPPORTED) < 0) {
225 Assert.assertEquals(Constants.OPENFLOW10, netVirtConfigurationService.getOpenflowVersion(node));
227 Assert.assertEquals(Constants.OPENFLOW13, netVirtConfigurationService.getOpenflowVersion(node));
232 public void testGetDefaultGatewayMacAddress() throws Exception {
233 // Thread.sleep(5000);
234 String defaultGatewayMacAddress = netVirtConfigurationService.getDefaultGatewayMacAddress(node);
236 if (defaultGatewayMacAddress != null) {
237 String[] splits = defaultGatewayMacAddress.split(":");
238 Assert.assertTrue("Unexpected mac format", splits.length == 6);
240 // log.info("testGetDefaultGatewayMacAddress got mac {}", defaultGatewayMacAddress);
244 public void tearDown() throws InterruptedException {
247 if (tearDownBridge) {
248 String uuid = bridgeConfigurationManager.getBridgeUuid(node,
249 netVirtConfigurationService.getIntegrationBridgeName());
250 ovsdbConfigurationService.deleteRow(node, ovsdbConfigurationService.getTableName(node, Bridge.class), uuid);
251 tearDownBridge = false;
254 DependencyManager dm = new DependencyManager(bc);
255 dm.remove(of10Provider);
256 dm.remove(of13Provider);
259 private Version getOvsVersion(){
260 Map<String, Row> ovsRows = ovsdbConfigurationService.getRows(node,
261 ovsdbConfigurationService.getTableName(node, OpenVSwitch.class));
262 OpenVSwitch ovsRow = ovsdbConfigurationService.getTypedRow(node,
264 ovsRows.values().iterator().next());
265 return Version.fromString(ovsRow.getOvsVersionColumn().getData().iterator().next());
268 private class FakeOF10Provider implements NetworkingProvider {
271 public String getName() {
276 public boolean supportsServices() {
281 public boolean hasPerTenantTunneling() {
286 public Status handleInterfaceUpdate(String tunnelType, String tunnelKey) {
291 public Status handleInterfaceUpdate(NeutronNetwork network, Node source, Interface intf) {
296 public Status handleInterfaceDelete(String tunnelType, NeutronNetwork network, Node source, Interface intf,
297 boolean isLastInstanceOnNode) {
302 public void initializeFlowRules(Node node) {
307 public void initializeOFFlowRules(Node openflowNode) {
312 private class FakeOF13Provider implements NetworkingProvider {
315 public String getName() {
320 public boolean supportsServices() {
325 public boolean hasPerTenantTunneling() {
330 public Status handleInterfaceUpdate(String tunnelType, String tunnelKey) {
335 public Status handleInterfaceUpdate(NeutronNetwork network, Node source, Interface intf) {
340 public Status handleInterfaceDelete(String tunnelType, NeutronNetwork network, Node source, Interface intf,
341 boolean isLastInstanceOnNode) {
346 public void initializeFlowRules(Node node) {
351 public void initializeOFFlowRules(Node openflowNode) {