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.ConfigurationService;
31 import org.opendaylight.ovsdb.openstack.netvirt.api.NetworkingProvider;
32 import org.opendaylight.ovsdb.plugin.OvsdbConfigService;
33 import org.opendaylight.ovsdb.schema.openvswitch.Bridge;
34 import org.opendaylight.ovsdb.schema.openvswitch.Interface;
35 import org.opendaylight.ovsdb.schema.openvswitch.OpenVSwitch;
37 import com.google.common.collect.ImmutableMap;
38 import org.apache.felix.dm.Component;
39 import org.apache.felix.dm.DependencyManager;
40 import org.junit.After;
41 import org.junit.Assert;
42 import org.junit.Before;
43 import org.junit.Test;
44 import org.junit.runner.RunWith;
45 import org.ops4j.pax.exam.Configuration;
46 import org.ops4j.pax.exam.Option;
47 import org.ops4j.pax.exam.junit.PaxExam;
48 import org.ops4j.pax.exam.spi.reactors.ExamReactorStrategy;
49 import org.ops4j.pax.exam.spi.reactors.PerClass;
50 import org.ops4j.pax.exam.util.PathUtils;
51 import org.osgi.framework.Bundle;
52 import org.osgi.framework.BundleContext;
53 import org.slf4j.Logger;
54 import org.slf4j.LoggerFactory;
56 import java.io.IOException;
57 import java.net.InetAddress;
59 import java.util.Properties;
60 import java.util.concurrent.ExecutionException;
61 import java.util.concurrent.TimeoutException;
63 import javax.inject.Inject;
66 @RunWith(PaxExam.class)
67 @ExamReactorStrategy(PerClass.class)
68 public class NeutronIT extends OvsdbIntegrationTestBase {
69 private Logger log = LoggerFactory.getLogger(NeutronIT.class);
71 private BundleContext bc;
74 private OvsdbConfigService ovsdbConfigService;
75 private Node node = null;
77 Component of10Provider;
78 Component of13Provider;
81 BridgeConfigurationManager bridgeConfigurationManager;
83 ConfigurationService configurationService;
85 Boolean tearDownBridge = false;
87 // Configure the OSGi container
89 public Option[] config() {
92 systemProperty("logback.configurationFile").value(
93 "file:" + PathUtils.getBaseDir()
94 + "/src/test/resources/logback.xml"
96 // To start OSGi console for inspection remotely
97 systemProperty("osgi.console").value("2401"),
99 propagateSystemProperty("ovsdbserver.ipaddress"),
100 propagateSystemProperty("ovsdbserver.port"),
102 ConfigurationBundles.controllerBundles(),
103 ConfigurationBundles.ovsdbLibraryBundles(),
104 ConfigurationBundles.ovsdbDefaultSchemaBundles(),
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 ovsdbConfigService.getRows(node, ovsdbConfigService.getTableName(node, Bridge.class));
183 Assert.assertEquals(1, bridgeRows.size());
185 Bridge bridgeRow = ovsdbConfigService.getTypedRow(node, Bridge.class, bridgeRows.values().iterator().next());
186 Assert.assertEquals(configurationService.getIntegrationBridgeName(), bridgeRow.getName());
188 String uuid = bridgeConfigurationManager.getBridgeUuid(node, configurationService.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 = ovsdbConfigService.getRows(node,
201 ovsdbConfigService.getTableName(node, OpenVSwitch.class));
202 OpenVSwitch ovsRow = ovsdbConfigService.getTypedRow(node,
204 ovsRows.values().iterator().next());
206 Assert.assertEquals(null, configurationService.getTunnelEndPoint(node));
208 ovsRow.setOtherConfig(ImmutableMap.of(configurationService.getTunnelEndpointKey(), endpointAddress));
209 ovsdbConfigService.updateRow(node,
210 ovsdbConfigService.getTableName(node, OpenVSwitch.class),
212 ovsRow.getUuid().toString(),
215 Assert.assertEquals(InetAddress.getByName(endpointAddress), configurationService.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, configurationService.getOpenflowVersion(node));
227 Assert.assertEquals(Constants.OPENFLOW13, configurationService.getOpenflowVersion(node));
232 public void tearDown() throws InterruptedException {
235 if (tearDownBridge) {
236 String uuid = bridgeConfigurationManager.getBridgeUuid(node,
237 configurationService.getIntegrationBridgeName());
238 ovsdbConfigService.deleteRow(node, ovsdbConfigService.getTableName(node, Bridge.class), uuid);
239 tearDownBridge = false;
242 DependencyManager dm = new DependencyManager(bc);
243 dm.remove(of10Provider);
244 dm.remove(of13Provider);
247 private Version getOvsVersion(){
248 Map<String, Row> ovsRows = ovsdbConfigService.getRows(node,
249 ovsdbConfigService.getTableName(node, OpenVSwitch.class));
250 OpenVSwitch ovsRow = ovsdbConfigService.getTypedRow(node,
252 ovsRows.values().iterator().next());
253 return Version.fromString(ovsRow.getOvsVersionColumn().getData().iterator().next());
256 private class FakeOF10Provider implements NetworkingProvider {
259 public boolean hasPerTenantTunneling() {
264 public Status handleInterfaceUpdate(String tunnelType, String tunnelKey) {
269 public Status handleInterfaceUpdate(NeutronNetwork network, Node source, Interface intf) {
274 public Status handleInterfaceDelete(String tunnelType, NeutronNetwork network, Node source, Interface intf,
275 boolean isLastInstanceOnNode) {
280 public void initializeFlowRules(Node node) {
285 public void initializeOFFlowRules(Node openflowNode) {
290 private class FakeOF13Provider implements NetworkingProvider {
293 public boolean hasPerTenantTunneling() {
298 public Status handleInterfaceUpdate(String tunnelType, String tunnelKey) {
303 public Status handleInterfaceUpdate(NeutronNetwork network, Node source, Interface intf) {
308 public Status handleInterfaceDelete(String tunnelType, NeutronNetwork network, Node source, Interface intf,
309 boolean isLastInstanceOnNode) {
314 public void initializeFlowRules(Node node) {
319 public void initializeOFFlowRules(Node openflowNode) {