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 org.opendaylight.controller.sal.core.Node;
13 import org.opendaylight.ovsdb.lib.notation.Row;
14 import org.opendaylight.ovsdb.lib.notation.Version;
15 import org.opendaylight.ovsdb.openstack.netvirt.api.Constants;
16 import org.opendaylight.ovsdb.plugin.api.OvsdbConfigurationService;
17 import org.opendaylight.ovsdb.schema.openvswitch.OpenVSwitch;
19 import com.google.common.collect.Maps;
20 import org.apache.commons.lang3.tuple.ImmutablePair;
21 import org.apache.commons.lang3.tuple.Pair;
22 import org.slf4j.Logger;
23 import org.slf4j.LoggerFactory;
25 import java.net.InetAddress;
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;
116 public String getPatchPortName(Pair portTuple){
117 return this.patchPortNames.get(portTuple);
121 public String getDefaultProviderMapping() {
122 return providerMapping;
126 public void setDefaultProviderMapping(String providerMapping) {
127 this.providerMapping = providerMapping;
131 public InetAddress getTunnelEndPoint(Node node) {
132 InetAddress address = null;
134 Map<String, Row> ovsTable = ovsdbConfigurationService.getRows(node,
135 ovsdbConfigurationService.getTableName(node, OpenVSwitch.class));
137 if (ovsTable == null) {
138 logger.error("OpenVSwitch table is null for Node {} ", node);
142 // While there is only one entry in the HashMap, we can't access it by index...
143 for (Row row : ovsTable.values()) {
144 OpenVSwitch ovsRow = ovsdbConfigurationService.getTypedRow(node, OpenVSwitch.class, row);
145 Map<String, String> configs = ovsRow.getOtherConfigColumn().getData();
147 if (configs == null) {
148 logger.debug("OpenVSwitch table is null for Node {} ", node);
152 String tunnelEndpoint = configs.get(tunnelEndpointKey);
154 if (tunnelEndpoint == null) {
158 address = InetAddress.getByName(tunnelEndpoint);
159 logger.debug("Tunnel Endpoint for Node {} {}", node, address.getHostAddress());
163 catch (Exception e) {
164 logger.error("Error populating Tunnel Endpoint for Node {} ", node, e);
171 public String getOpenflowVersion(Node node) {
173 String configuredVersion = System.getProperty("ovsdb.of.version");
174 if (configuredVersion != null){
175 switch (configuredVersion){
177 return Constants.OPENFLOW10;
181 return Constants.OPENFLOW13;
186 Map<String, Row> ovsRows = ovsdbConfigurationService.getRows(node,
187 ovsdbConfigurationService.getTableName(node, OpenVSwitch.class));
189 if (ovsRows == null) {
190 logger.info("The OVS node {} has no Open_vSwitch rows", node.toString());
194 Version ovsVersion = null;
195 // While there is only one entry in the HashMap, we can't access it by index...
196 for (Row row : ovsRows.values()) {
197 OpenVSwitch ovsRow = ovsdbConfigurationService.getTypedRow(node, OpenVSwitch.class, row);
198 Set<String> versionSet = ovsRow.getOvsVersionColumn().getData();
199 if (versionSet != null && versionSet.iterator().hasNext()) {
200 ovsVersion = Version.fromString(versionSet.iterator().next());
204 if (ovsVersion == null || ovsVersion.compareTo(Constants.OPENFLOW13_SUPPORTED) < 0) {
205 return Constants.OPENFLOW10;
208 return Constants.OPENFLOW13;