2 * Copyright (C) 2013 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 : Madhu Venugopal, Brent Salisbury, Sam Hague, Dave Tucker
10 package org.opendaylight.ovsdb.openstack.netvirt.impl;
12 import java.net.InetAddress;
16 import org.apache.commons.lang3.tuple.ImmutablePair;
17 import org.apache.commons.lang3.tuple.Pair;
18 import org.opendaylight.controller.sal.core.Node;
19 import org.opendaylight.ovsdb.lib.notation.Row;
20 import org.opendaylight.ovsdb.lib.notation.Version;
21 import org.opendaylight.ovsdb.openstack.netvirt.api.ConfigurationService;
22 import org.opendaylight.ovsdb.openstack.netvirt.api.Constants;
23 import org.opendaylight.ovsdb.plugin.api.OvsdbConfigurationService;
24 import org.opendaylight.ovsdb.schema.openvswitch.OpenVSwitch;
25 import org.opendaylight.ovsdb.utils.config.ConfigProperties;
27 import org.slf4j.Logger;
28 import org.slf4j.LoggerFactory;
30 import com.google.common.collect.Maps;
32 public class ConfigurationServiceImpl implements ConfigurationService {
33 static final Logger logger = LoggerFactory.getLogger(ConfigurationServiceImpl.class);
35 private volatile OvsdbConfigurationService ovsdbConfigurationService;
37 private String integrationBridgeName;
38 private String networkBridgeName;
39 private String externalBridgeName;
40 private String tunnelEndpointKey;
42 private Map<Pair<String, String>, String> patchPortNames = Maps.newHashMap();
43 private String providerMappingsKey;
44 private String providerMapping;
46 public ConfigurationServiceImpl() {
47 tunnelEndpointKey = Constants.TUNNEL_ENDPOINT_KEY;
48 integrationBridgeName = Constants.INTEGRATION_BRIDGE;
49 networkBridgeName = Constants.NETWORK_BRIDGE;
50 externalBridgeName = Constants.EXTERNAL_BRIDGE;
51 patchPortNames.put(new ImmutablePair<>(integrationBridgeName, networkBridgeName),
52 Constants.PATCH_PORT_TO_NETWORK_BRIDGE_NAME);
53 patchPortNames.put(new ImmutablePair<>(networkBridgeName, integrationBridgeName),
54 Constants.PATCH_PORT_TO_INTEGRATION_BRIDGE_NAME);
55 providerMappingsKey = Constants.PROVIDER_MAPPINGS_KEY;
56 providerMapping = Constants.PROVIDER_MAPPING;
60 public String getIntegrationBridgeName() {
61 return integrationBridgeName;
65 public void setIntegrationBridgeName(String integrationBridgeName) {
66 this.integrationBridgeName = integrationBridgeName;
70 public String getNetworkBridgeName() {
71 return networkBridgeName;
75 public void setNetworkBridgeName(String networkBridgeName) {
76 this.networkBridgeName = networkBridgeName;
80 public String getExternalBridgeName() {
81 return externalBridgeName;
85 public void setExternalBridgeName(String externalBridgeName) {
86 this.externalBridgeName = externalBridgeName;
90 public String getTunnelEndpointKey() {
91 return tunnelEndpointKey;
95 public void setTunnelEndpointKey(String tunnelEndpointKey) {
96 this.tunnelEndpointKey = tunnelEndpointKey;
100 public String getProviderMappingsKey() {
101 return providerMappingsKey;
105 public void setProviderMappingsKey(String providerMappingsKey) {
106 this.providerMappingsKey = providerMappingsKey;
110 public Map<Pair<String, String>, String> getPatchPortNames() {
111 return patchPortNames;
115 public void setPatchPortNames(Map<Pair<String, String>, String> patchPortNames) {
116 this.patchPortNames = patchPortNames;
120 public String getPatchPortName(Pair portTuple){
121 return this.patchPortNames.get(portTuple);
125 public String getDefaultProviderMapping() {
126 return providerMapping;
130 public void setDefaultProviderMapping(String providerMapping) {
131 this.providerMapping = providerMapping;
135 public InetAddress getTunnelEndPoint(Node node) {
136 InetAddress address = null;
138 Map<String, Row> ovsTable = ovsdbConfigurationService.getRows(node,
139 ovsdbConfigurationService.getTableName(node, OpenVSwitch.class));
141 if (ovsTable == null) {
142 logger.error("OpenVSwitch table is null for Node {} ", node);
146 // While there is only one entry in the HashMap, we can't access it by index...
147 for (Row row : ovsTable.values()) {
148 OpenVSwitch ovsRow = ovsdbConfigurationService.getTypedRow(node, OpenVSwitch.class, row);
149 Map<String, String> configs = ovsRow.getOtherConfigColumn().getData();
151 if (configs == null) {
152 logger.debug("OpenVSwitch table is null for Node {} ", node);
156 String tunnelEndpoint = configs.get(tunnelEndpointKey);
158 if (tunnelEndpoint == null) {
162 address = InetAddress.getByName(tunnelEndpoint);
163 logger.debug("Tunnel Endpoint for Node {} {}", node, address.getHostAddress());
167 catch (Exception e) {
168 logger.error("Error populating Tunnel Endpoint for Node {} ", node, e);
175 public String getOpenflowVersion(Node node) {
177 String configuredVersion = ConfigProperties.getProperty(this.getClass(), "ovsdb.of.version", "1.3");
178 if (configuredVersion != null){
179 switch (configuredVersion){
181 return Constants.OPENFLOW10;
185 return Constants.OPENFLOW13;
190 Map<String, Row> ovsRows = ovsdbConfigurationService.getRows(node,
191 ovsdbConfigurationService.getTableName(node, OpenVSwitch.class));
193 if (ovsRows == null) {
194 logger.info("The OVS node {} has no Open_vSwitch rows", node.toString());
198 Version ovsVersion = null;
199 // While there is only one entry in the HashMap, we can't access it by index...
200 for (Row row : ovsRows.values()) {
201 OpenVSwitch ovsRow = ovsdbConfigurationService.getTypedRow(node, OpenVSwitch.class, row);
202 Set<String> versionSet = ovsRow.getOvsVersionColumn().getData();
203 if (versionSet != null && versionSet.iterator().hasNext()) {
204 ovsVersion = Version.fromString(versionSet.iterator().next());
208 if (ovsVersion == null || ovsVersion.compareTo(Constants.OPENFLOW13_SUPPORTED) < 0) {
209 return Constants.OPENFLOW10;
212 return Constants.OPENFLOW13;
216 public String getDefaultGatewayMacAddress(Node node) {
217 final String l3gatewayForNode =
219 ConfigProperties.getProperty(this.getClass(), "ovsdb.l3gateway.mac." + node.getNodeIDString()) : null;
220 return l3gatewayForNode != null ?
221 l3gatewayForNode : ConfigProperties.getProperty(this.getClass(), "ovsdb.l3gateway.mac");