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
10 package org.opendaylight.ovsdb.neutron;
12 import java.net.InetAddress;
13 import java.util.ArrayList;
14 import java.util.List;
17 import org.opendaylight.controller.sal.core.Node;
18 import org.opendaylight.controller.sal.utils.ServiceHelper;
19 import org.opendaylight.ovsdb.lib.notation.Row;
20 import org.opendaylight.ovsdb.plugin.OVSDBConfigService;
21 import org.opendaylight.ovsdb.schema.openvswitch.OpenVSwitch;
22 import org.slf4j.Logger;
23 import org.slf4j.LoggerFactory;
25 public class AdminConfigManager implements IAdminConfigManager{
26 static final Logger logger = LoggerFactory.getLogger(AdminConfigManager.class);
28 private String integrationBridgeName;
29 private String networkBridgeName;
30 private String externalBridgeName;
31 private String tunnelEndpointConfigName;
32 private String patchToIntegration;
33 private String patchToNetwork;
34 private String providerMappingsConfigName;
35 private String providerMappings;
37 // Refer to /etc/quantum/plugins/openvswitch/ovs_quantum_plugin.ini
38 private static String DEFAULT_TUNNEL_ENDPOINT_CONFIG_STRING = "local_ip";
39 private static String DEFAULT_INTEGRATION_BRIDGENAME = "br-int";
40 private static String DEFAULT_NETWORK_BRIDGENAME = "br-net";
41 private static String DEFAULT_EXTERNAL_BRIDGENAME = "br-ex";
42 private static String DEFAULT_PATCH_TO_INTEGRATION = "patch-int";
43 private static String DEFAULT_PATCH_TO_NETWORK = "patch-net";
44 private static String CONFIG_TUNNEL_ENDPOINT_CONFIG = "tunnel_endpoint_config_string";
45 private static String CONFIG_INTEGRATION_BRIDGENAME = "integration_bridge";
46 private static String CONFIG_NETWORK_BRIDGENAME = "network_bridge";
47 private static String CONFIG_EXTERNAL_BRIDGENAME = "external_bridge";
48 private static String CONFIG_PATCH_TO_INTEGRATION = "patch-int";
49 private static String CONFIG_PATCH_TO_NETWORK = "patch-net";
50 private static String DEFAULT_PROVIDER_MAPPINGS_CONFIG_STRING = "provider_mappings";
51 private static String CONFIG_PROVIDER_MAPPINGS_CONFIG = "provider_mappings_config_string";
52 private static String CONFIG_PROVIDER_MAPPINGS = "provider_mappings";
54 public AdminConfigManager() {
55 tunnelEndpointConfigName = System.getProperty(CONFIG_TUNNEL_ENDPOINT_CONFIG);
56 integrationBridgeName = System.getProperty(CONFIG_INTEGRATION_BRIDGENAME);
57 networkBridgeName = System.getProperty(CONFIG_NETWORK_BRIDGENAME);
58 externalBridgeName = System.getProperty(CONFIG_EXTERNAL_BRIDGENAME);
59 patchToIntegration = System.getProperty(CONFIG_PATCH_TO_INTEGRATION);
60 patchToNetwork = System.getProperty(CONFIG_PATCH_TO_NETWORK);
61 providerMappingsConfigName = System.getProperty(CONFIG_PROVIDER_MAPPINGS_CONFIG);
62 providerMappings = System.getProperty(CONFIG_PROVIDER_MAPPINGS);
64 if (tunnelEndpointConfigName == null) tunnelEndpointConfigName = DEFAULT_TUNNEL_ENDPOINT_CONFIG_STRING;
65 if (integrationBridgeName == null) integrationBridgeName = DEFAULT_INTEGRATION_BRIDGENAME;
66 if (networkBridgeName == null) networkBridgeName = DEFAULT_NETWORK_BRIDGENAME;
67 if (externalBridgeName == null) externalBridgeName = DEFAULT_EXTERNAL_BRIDGENAME;
68 if (patchToIntegration == null) patchToIntegration = DEFAULT_PATCH_TO_INTEGRATION;
69 if (patchToNetwork == null) patchToNetwork = DEFAULT_PATCH_TO_NETWORK;
70 if (providerMappingsConfigName == null) providerMappingsConfigName = DEFAULT_PROVIDER_MAPPINGS_CONFIG_STRING;
74 public String getIntegrationBridgeName() {
75 return integrationBridgeName;
79 public void setIntegrationBridgeName(String integrationBridgeName) {
80 this.integrationBridgeName = integrationBridgeName;
84 public String getNetworkBridgeName() { return networkBridgeName; }
87 public void setNetworkBridgeName(String networkBridgeName) {
88 this.networkBridgeName = networkBridgeName;
92 public String getExternalBridgeName() {
93 return externalBridgeName;
97 public void setExternalBridgeName (String externalBridgeName) {
98 this.externalBridgeName = externalBridgeName;
102 public String getPatchToIntegration() {
103 return patchToIntegration;
107 public void setPatchToIntegration(String patchToIntegration) {
108 this.patchToIntegration = patchToIntegration;
112 public String getPatchToNetwork() { return patchToNetwork; }
115 public void setPatchToNetwork(String patchToNetwork) {
116 this.patchToNetwork = patchToNetwork;
120 public InetAddress getTunnelEndPoint(Node node) {
121 InetAddress address = null;
122 OVSDBConfigService ovsdbConfig = (OVSDBConfigService)ServiceHelper.getGlobalInstance(OVSDBConfigService.class, this);
124 Map<String, Row> ovsTable = ovsdbConfig.getRows(node, ovsdbConfig.getTableName(node, OpenVSwitch.class));
126 if (ovsTable == null) {
127 logger.error("OpenVSwitch table is null for Node {} ", node);
131 // While there is only one entry in the HashMap, we can't access it by index...
132 for (Row row : ovsTable.values()) {
133 OpenVSwitch ovsRow = ovsdbConfig.getTypedRow(node, OpenVSwitch.class, row);
134 Map<String, String> configs = ovsRow.getOtherConfigColumn().getData();
136 if (configs == null) {
137 logger.debug("OpenVSwitch table is null for Node {} ", node);
141 String tunnelEndpoint = configs.get(tunnelEndpointConfigName);
143 if (tunnelEndpoint == null) {
147 address = InetAddress.getByName(tunnelEndpoint);
148 logger.debug("Tunnel Endpoint for Node {} {}", node, address.getHostAddress());
152 catch (Exception e) {
153 logger.error("Error populating Tunnel Endpoint for Node {} ", node, e);
161 * Return the physical interface mapped to the given neutron physical network.
162 * Provider mappings will be of the following format:
163 * provider_mappings=physnet1:eth1[,physnet2:eth2]
166 public String getPhysicalInterfaceName (Node node, String physicalNetwork) {
169 OVSDBConfigService ovsdbConfig = (OVSDBConfigService) ServiceHelper.getGlobalInstance(OVSDBConfigService.class, this);
171 Map<String, Row> ovsTable = ovsdbConfig.getRows(node, ovsdbConfig.getTableName(node, OpenVSwitch.class));
173 if (ovsTable == null) {
174 logger.error("OpenVSwitch table is null for Node {} ", node);
178 // Loop through all the OpenVSwitch rows looking for the first occurrence of other_config.
179 // The specification does not restrict the number of rows so we choose the first we find.
180 for (Row row : ovsTable.values()) {
182 OpenVSwitch ovsRow = ovsdbConfig.getTypedRow(node, OpenVSwitch.class, row);
183 Map<String, String> configs = ovsRow.getOtherConfigColumn().getData();
185 if (configs == null) {
186 logger.debug("OpenVSwitch table is null for Node {} ", node);
190 providerMaps = configs.get(providerMappingsConfigName);
191 if (providerMaps == null) {
192 providerMaps = providerMappings;
195 if (providerMaps != null) {
196 for (String map : providerMaps.split(",")) {
197 String[] pair = map.split(":");
198 if (pair[0].equals(physicalNetwork)) {
209 } catch (Exception e) {
210 logger.error("Unable to find physical interface for Node: {}, Network {}",
211 node, physicalNetwork, e);
215 logger.error("Physical interface not found for Node: {}, Network {}",
216 node, physicalNetwork);
222 /* Return all physical interfaces configure in bridge mapping
223 * Bridge mappings will be of the following format:
224 * bridge_mappings=physnet1:eth1,physnet2:eth2
225 * Method will return list = {eth1, eth2}
228 public List<String> getAllPhysicalInterfaceNames(Node node) {
229 List<String> phyIfName = new ArrayList<String>();
232 OVSDBConfigService ovsdbConfig = (OVSDBConfigService) ServiceHelper.getGlobalInstance(OVSDBConfigService.class, this);
233 Map<String, Row> ovsTable = ovsdbConfig.getRows(node, ovsdbConfig.getTableName(node, OpenVSwitch.class));
235 if (ovsTable == null) {
236 logger.error("OpenVSwitch table is null for Node {} ", node);
240 // While there is only one entry in the HashMap, we can't access it by index...
241 for (Row row : ovsTable.values()) {
243 OpenVSwitch ovsRow = ovsdbConfig.getTypedRow(node, OpenVSwitch.class, row);
244 Map<String, String> configs = ovsRow.getOtherConfigColumn().getData();
246 if (configs == null) {
247 logger.debug("OpenVSwitch table is null for Node {} ", node);
251 bridgeMaps = configs.get(providerMappingsConfigName);
252 if (bridgeMaps == null) {
253 bridgeMaps = providerMappings;
256 if (bridgeMaps != null) {
257 for (String map : bridgeMaps.split(",")) {
258 String[] pair = map.split(":");
259 phyIfName.add(pair[1]);
263 } catch (Exception e) {
264 logger.error("Unable to find physical interface for Node: {}",
268 logger.debug("Physical interface for Node: {}, If: {}",