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.Constants;
22 import org.opendaylight.ovsdb.plugin.api.OvsdbConfigurationService;
23 import org.opendaylight.ovsdb.schema.openvswitch.OpenVSwitch;
24 import org.slf4j.Logger;
25 import org.slf4j.LoggerFactory;
27 import com.google.common.collect.Maps;
29 public class ConfigurationServiceImpl implements org.opendaylight.ovsdb.openstack.netvirt.api.ConfigurationService {
30 static final Logger logger = LoggerFactory.getLogger(ConfigurationServiceImpl.class);
32 private volatile OvsdbConfigurationService ovsdbConfigurationService;
34 private String integrationBridgeName;
35 private String networkBridgeName;
36 private String externalBridgeName;
37 private String tunnelEndpointKey;
39 private Map<Pair<String, String>, String> patchPortNames = Maps.newHashMap();
40 private String providerMappingsKey;
41 private String providerMapping;
43 public ConfigurationServiceImpl() {
44 tunnelEndpointKey = Constants.TUNNEL_ENDPOINT_KEY;
45 integrationBridgeName = Constants.INTEGRATION_BRIDGE;
46 networkBridgeName = Constants.NETWORK_BRIDGE;
47 externalBridgeName = Constants.EXTERNAL_BRIDGE;
48 patchPortNames.put(new ImmutablePair<>(integrationBridgeName, networkBridgeName),
49 Constants.PATCH_PORT_TO_NETWORK_BRIDGE_NAME);
50 patchPortNames.put(new ImmutablePair<>(networkBridgeName, integrationBridgeName),
51 Constants.PATCH_PORT_TO_INTEGRATION_BRIDGE_NAME);
52 providerMappingsKey = Constants.PROVIDER_MAPPINGS_KEY;
53 providerMapping = Constants.PROVIDER_MAPPING;
57 public String getIntegrationBridgeName() {
58 return integrationBridgeName;
62 public void setIntegrationBridgeName(String integrationBridgeName) {
63 this.integrationBridgeName = integrationBridgeName;
67 public String getNetworkBridgeName() {
68 return networkBridgeName;
72 public void setNetworkBridgeName(String networkBridgeName) {
73 this.networkBridgeName = networkBridgeName;
77 public String getExternalBridgeName() {
78 return externalBridgeName;
82 public void setExternalBridgeName(String externalBridgeName) {
83 this.externalBridgeName = externalBridgeName;
87 public String getTunnelEndpointKey() {
88 return tunnelEndpointKey;
92 public void setTunnelEndpointKey(String tunnelEndpointKey) {
93 this.tunnelEndpointKey = tunnelEndpointKey;
97 public String getProviderMappingsKey() {
98 return providerMappingsKey;
102 public void setProviderMappingsKey(String providerMappingsKey) {
103 this.providerMappingsKey = providerMappingsKey;
107 public Map<Pair<String, String>, String> getPatchPortNames() {
108 return patchPortNames;
112 public void setPatchPortNames(Map<Pair<String, String>, String> patchPortNames) {
113 this.patchPortNames = patchPortNames;
117 public String getPatchPortName(Pair portTuple){
118 return this.patchPortNames.get(portTuple);
122 public String getDefaultProviderMapping() {
123 return providerMapping;
127 public void setDefaultProviderMapping(String providerMapping) {
128 this.providerMapping = providerMapping;
132 public InetAddress getTunnelEndPoint(Node node) {
133 InetAddress address = null;
135 Map<String, Row> ovsTable = ovsdbConfigurationService.getRows(node,
136 ovsdbConfigurationService.getTableName(node, OpenVSwitch.class));
138 if (ovsTable == null) {
139 logger.error("OpenVSwitch table is null for Node {} ", node);
143 // While there is only one entry in the HashMap, we can't access it by index...
144 for (Row row : ovsTable.values()) {
145 OpenVSwitch ovsRow = ovsdbConfigurationService.getTypedRow(node, OpenVSwitch.class, row);
146 Map<String, String> configs = ovsRow.getOtherConfigColumn().getData();
148 if (configs == null) {
149 logger.debug("OpenVSwitch table is null for Node {} ", node);
153 String tunnelEndpoint = configs.get(tunnelEndpointKey);
155 if (tunnelEndpoint == null) {
159 address = InetAddress.getByName(tunnelEndpoint);
160 logger.debug("Tunnel Endpoint for Node {} {}", node, address.getHostAddress());
164 catch (Exception e) {
165 logger.error("Error populating Tunnel Endpoint for Node {} ", node, e);
172 public String getOpenflowVersion(Node node) {
174 String configuredVersion = System.getProperty("ovsdb.of.version", "1.3");
175 if (configuredVersion != null){
176 switch (configuredVersion){
178 return Constants.OPENFLOW10;
182 return Constants.OPENFLOW13;
187 Map<String, Row> ovsRows = ovsdbConfigurationService.getRows(node,
188 ovsdbConfigurationService.getTableName(node, OpenVSwitch.class));
190 if (ovsRows == null) {
191 logger.info("The OVS node {} has no Open_vSwitch rows", node.toString());
195 Version ovsVersion = null;
196 // While there is only one entry in the HashMap, we can't access it by index...
197 for (Row row : ovsRows.values()) {
198 OpenVSwitch ovsRow = ovsdbConfigurationService.getTypedRow(node, OpenVSwitch.class, row);
199 Set<String> versionSet = ovsRow.getOvsVersionColumn().getData();
200 if (versionSet != null && versionSet.iterator().hasNext()) {
201 ovsVersion = Version.fromString(versionSet.iterator().next());
205 if (ovsVersion == null || ovsVersion.compareTo(Constants.OPENFLOW13_SUPPORTED) < 0) {
206 return Constants.OPENFLOW10;
209 return Constants.OPENFLOW13;
213 public String getDefaultGatewayMacAddress(Node node) {
214 final String l3gatewayForNode =
215 node != null ? System.getProperty("ovsdb.l3gateway.mac." + node.getNodeIDString()) : null;
216 return l3gatewayForNode != null ? l3gatewayForNode : System.getProperty("ovsdb.l3gateway.mac");