/*
- * Copyright (C) 2013 Red Hat, Inc.
+ * Copyright (c) 2013, 2015 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, Brent Salisbury, Sam Hague, Dave Tucker
*/
+
package org.opendaylight.ovsdb.openstack.netvirt.impl;
+import com.google.common.collect.Maps;
import java.net.InetAddress;
+import java.net.UnknownHostException;
import java.util.Map;
-import java.util.Set;
import org.apache.commons.lang3.tuple.ImmutablePair;
import org.apache.commons.lang3.tuple.Pair;
-import org.opendaylight.controller.sal.core.Node;
-import org.opendaylight.ovsdb.lib.notation.Row;
-import org.opendaylight.ovsdb.lib.notation.Version;
+import org.opendaylight.ovsdb.openstack.netvirt.ConfigInterface;
import org.opendaylight.ovsdb.openstack.netvirt.api.ConfigurationService;
import org.opendaylight.ovsdb.openstack.netvirt.api.Constants;
-import org.opendaylight.ovsdb.plugin.api.OvsdbConfigurationService;
-import org.opendaylight.ovsdb.schema.openvswitch.OpenVSwitch;
+import org.opendaylight.ovsdb.openstack.netvirt.api.OvsdbTables;
+import org.opendaylight.ovsdb.openstack.netvirt.api.Southbound;
+import org.opendaylight.ovsdb.utils.config.ConfigProperties;
+import org.opendaylight.ovsdb.utils.servicehelper.ServiceHelper;
+import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node;
-import org.osgi.framework.Bundle;
-import org.osgi.framework.BundleContext;
-import org.osgi.framework.FrameworkUtil;
+import org.osgi.framework.ServiceReference;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import com.google.common.collect.Maps;
-
-public class ConfigurationServiceImpl implements ConfigurationService {
- static final Logger logger = LoggerFactory.getLogger(ConfigurationServiceImpl.class);
-
- private volatile OvsdbConfigurationService ovsdbConfigurationService;
+public class ConfigurationServiceImpl implements ConfigurationService, ConfigInterface {
+ private static final Logger LOG = LoggerFactory.getLogger(ConfigurationServiceImpl.class);
private String integrationBridgeName;
private String networkBridgeName;
private Map<Pair<String, String>, String> patchPortNames = Maps.newHashMap();
private String providerMappingsKey;
private String providerMapping;
+ private Southbound southbound;
public ConfigurationServiceImpl() {
tunnelEndpointKey = Constants.TUNNEL_ENDPOINT_KEY;
Constants.PATCH_PORT_TO_NETWORK_BRIDGE_NAME);
patchPortNames.put(new ImmutablePair<>(networkBridgeName, integrationBridgeName),
Constants.PATCH_PORT_TO_INTEGRATION_BRIDGE_NAME);
+ patchPortNames.put(new ImmutablePair<>(integrationBridgeName, externalBridgeName),
+ Constants.PATCH_PORT_TO_EXTERNAL_BRIDGE_NAME);
+ patchPortNames.put(new ImmutablePair<>(externalBridgeName, integrationBridgeName),
+ Constants.PATCH_PORT_TO_INTEGRATION_BRIDGE_NAME);
providerMappingsKey = Constants.PROVIDER_MAPPINGS_KEY;
providerMapping = Constants.PROVIDER_MAPPING;
}
@Override
public InetAddress getTunnelEndPoint(Node node) {
InetAddress address = null;
- try {
- Map<String, Row> ovsTable = ovsdbConfigurationService.getRows(node,
- ovsdbConfigurationService.getTableName(node, OpenVSwitch.class));
-
- if (ovsTable == null) {
- logger.error("OpenVSwitch table is null for Node {} ", node);
- return null;
- }
-
- // While there is only one entry in the HashMap, we can't access it by index...
- for (Row row : ovsTable.values()) {
- OpenVSwitch ovsRow = ovsdbConfigurationService.getTypedRow(node, OpenVSwitch.class, row);
- Map<String, String> configs = ovsRow.getOtherConfigColumn().getData();
-
- if (configs == null) {
- logger.debug("OpenVSwitch table is null for Node {} ", node);
- continue;
- }
-
- String tunnelEndpoint = configs.get(tunnelEndpointKey);
-
- if (tunnelEndpoint == null) {
- continue;
- }
-
+ String tunnelEndpoint = southbound.getOtherConfig(node, OvsdbTables.OPENVSWITCH, tunnelEndpointKey);
+ if (tunnelEndpoint != null) {
+ try {
address = InetAddress.getByName(tunnelEndpoint);
- logger.debug("Tunnel Endpoint for Node {} {}", node, address.getHostAddress());
- break;
+ LOG.debug("Tunnel Endpoint for Node {} {}", node, address.getHostAddress());
+ } catch (UnknownHostException e) {
+ LOG.error("Error populating Tunnel Endpoint for Node {} ", node, e);
}
}
- catch (Exception e) {
- logger.error("Error populating Tunnel Endpoint for Node {} ", node, e);
- }
-
return address;
}
@Override
public String getOpenflowVersion(Node node) {
+ return Constants.OPENFLOW13;
+ }
- String configuredVersion = System.getProperty("ovsdb.of.version", "1.3");
- if (configuredVersion != null){
- switch (configuredVersion){
- case "1.0":
- return Constants.OPENFLOW10;
- case "1.3":
- //fall through
- default:
- return Constants.OPENFLOW13;
-
- }
- }
-
- Map<String, Row> ovsRows = ovsdbConfigurationService.getRows(node,
- ovsdbConfigurationService.getTableName(node, OpenVSwitch.class));
+ @Override
+ public boolean isL3ForwardingEnabled() {
+ final String enabledPropertyStr = ConfigProperties.getProperty(this.getClass(), "ovsdb.l3.fwd.enabled");
+ return enabledPropertyStr != null && enabledPropertyStr.equalsIgnoreCase("yes");
+ }
- if (ovsRows == null) {
- logger.info("The OVS node {} has no Open_vSwitch rows", node.toString());
- return null;
- }
+ @Override
+ public boolean isDistributedArpDisabled() {
+ final String strARPDisabled = ConfigProperties.getProperty(this.getClass(), "ovsdb.l3.arp.responder.disabled");
+ return strARPDisabled != null && strARPDisabled.equalsIgnoreCase("yes");
+ }
- Version ovsVersion = null;
- // While there is only one entry in the HashMap, we can't access it by index...
- for (Row row : ovsRows.values()) {
- OpenVSwitch ovsRow = ovsdbConfigurationService.getTypedRow(node, OpenVSwitch.class, row);
- Set<String> versionSet = ovsRow.getOvsVersionColumn().getData();
- if (versionSet != null && versionSet.iterator().hasNext()) {
- ovsVersion = Version.fromString(versionSet.iterator().next());
- }
+ @Override
+ public String getDefaultGatewayMacAddress(Node node) {
+ String l3gatewayForNode = null;
+ if (node != null) {
+ l3gatewayForNode = ConfigProperties.getProperty(this.getClass(),
+ "ovsdb.l3gateway.mac." + node.getNodeId().getValue());
}
-
- if (ovsVersion == null || ovsVersion.compareTo(Constants.OPENFLOW13_SUPPORTED) < 0) {
- return Constants.OPENFLOW10;
+ if (l3gatewayForNode == null) {
+ l3gatewayForNode = ConfigProperties.getProperty(this.getClass(), "ovsdb.l3gateway.mac");
}
-
- return Constants.OPENFLOW13;
+ return l3gatewayForNode;
}
@Override
- public String getDefaultGatewayMacAddress(Node node) {
- final String l3gatewayForNode =
- node != null ? getProperty(this.getClass(), "ovsdb.l3gateway.mac." + node.getNodeIDString()) : null;
- return l3gatewayForNode != null ? l3gatewayForNode : getProperty(this.getClass(), "ovsdb.l3gateway.mac");
+ public boolean isUserSpaceEnabled() {
+ final String enabledPropertyStr = ConfigProperties.getProperty(this.getClass(), "ovsdb.userspace.enabled");
+ return enabledPropertyStr != null && enabledPropertyStr.equalsIgnoreCase("yes");
}
- // TODO: move getProperty() to a common module
- private static String getProperty(Class<?> classParam, final String propertyStr) {
- String value = null;
- Bundle bundle = FrameworkUtil.getBundle(classParam);
+ @Override
+ public void setDependencies(ServiceReference serviceReference) {
+ southbound =
+ (Southbound) ServiceHelper.getGlobalInstance(Southbound.class, this);
+ }
- if (bundle != null) {
- BundleContext bundleContext = bundle.getBundleContext();
- if (bundleContext != null) {
- value = bundleContext.getProperty(propertyStr);
- }
- }
- if (value == null) {
- value = System.getProperty(propertyStr);
- }
- return value;
+ @Override
+ public void setDependencies(Object impl) {
}
}