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.table.Open_vSwitch;
20 import org.opendaylight.ovsdb.lib.table.Table;
21 import org.opendaylight.ovsdb.plugin.OVSDBConfigService;
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;
73 public String getIntegrationBridgeName() {
74 return integrationBridgeName;
77 public void setIntegrationBridgeName(String integrationBridgeName) {
78 this.integrationBridgeName = integrationBridgeName;
81 public String getNetworkBridgeName() { return networkBridgeName; }
83 public void setNetworkBridgeName(String networkBridgeName) {
84 this.networkBridgeName = networkBridgeName;
87 public String getExternalBridgeName() {
88 return externalBridgeName;
91 public void setExternalBridgeName (String externalBridgeName) {
92 this.externalBridgeName = externalBridgeName;
95 public String getPatchToIntegration() {
96 return patchToIntegration;
99 public void setPatchToIntegration(String patchToIntegration) {
100 this.patchToIntegration = patchToIntegration;
103 public String getPatchToNetwork() { return patchToNetwork; }
105 public void setPatchToNetwork(String patchToNetwork) {
106 this.patchToNetwork = patchToNetwork;
109 public InetAddress getTunnelEndPoint(Node node) {
110 InetAddress address = null;
111 OVSDBConfigService ovsdbConfig = (OVSDBConfigService)ServiceHelper.getGlobalInstance(OVSDBConfigService.class, this);
113 Map<String, Table<?>> ovsTable = ovsdbConfig.getRows(node, Open_vSwitch.NAME.getName());
115 if (ovsTable == null) {
116 logger.error("Open_vSwitch table is null for Node {} ", node);
120 // While there is only one entry in the HashMap, we can't access it by index...
121 for (Table<?> row : ovsTable.values()) {
122 Open_vSwitch ovsRow = (Open_vSwitch)row;
123 Map<String, String> configs = ovsRow.getOther_config();
125 if (configs == null) {
126 logger.debug("Open_vSwitch table is null for Node {} ", node);
130 String tunnelEndpoint = configs.get(tunnelEndpointConfigName);
132 if (tunnelEndpoint == null) {
136 address = InetAddress.getByName(tunnelEndpoint);
137 logger.debug("Tunnel Endpoint for Node {} {}", node, address.getHostAddress());
141 catch (Exception e) {
142 logger.error("Error populating Tunnel Endpoint for Node {} ", node, e);
150 * Return the physical interface mapped to the given neutron physical network.
151 * Provider mappings will be of the following format:
152 * provider_mappings=physnet1:eth1[,physnet2:eth2]
154 public String getPhysicalInterfaceName (Node node, String physicalNetwork) {
157 OVSDBConfigService ovsdbConfig = (OVSDBConfigService) ServiceHelper.getGlobalInstance(OVSDBConfigService.class, this);
159 Map<String, Table<?>> ovsTable = ovsdbConfig.getRows(node, Open_vSwitch.NAME.getName());
161 if (ovsTable == null) {
162 logger.error("Open_vSwitch table is null for Node {} ", node);
166 // Loop through all the Open_vSwitch rows looking for the first occurrence of other_config.
167 // The specification does not restrict the number of rows so we choose the first we find.
168 for (Table<?> row : ovsTable.values()) {
170 Open_vSwitch ovsRow = (Open_vSwitch) row;
171 Map<String, String> configs = ovsRow.getOther_config();
173 if (configs == null) {
174 logger.debug("Open_vSwitch table is null for Node {} ", node);
178 providerMaps = configs.get(providerMappingsConfigName);
179 if (providerMaps == null) {
180 providerMaps = providerMappings;
183 if (providerMaps != null) {
184 for (String map : providerMaps.split(",")) {
185 String[] pair = map.split(":");
186 if (pair[0].equals(physicalNetwork)) {
197 } catch (Exception e) {
198 logger.error("Unable to find physical interface for Node: {}, Network {}",
199 node, physicalNetwork, e);
203 logger.error("Physical interface not found for Node: {}, Network {}",
204 node, physicalNetwork);
210 /* Return all physical interfaces configure in bridge mapping
211 * Bridge mappings will be of the following format:
212 * bridge_mappings=physnet1:eth1,physnet2:eth2
213 * Method will return list = {eth1, eth2}
215 public List<String> getAllPhysicalInterfaceNames(Node node) {
216 List<String> phyIfName = new ArrayList<String>();
219 OVSDBConfigService ovsdbConfig = (OVSDBConfigService) ServiceHelper.getGlobalInstance(OVSDBConfigService.class, this);
220 Map<String, Table<?>> ovsTable = ovsdbConfig.getRows(node, Open_vSwitch.NAME.getName());
222 if (ovsTable == null) {
223 logger.error("Open_vSwitch table is null for Node {} ", node);
227 // While there is only one entry in the HashMap, we can't access it by index...
228 for (Table<?> row : ovsTable.values()) {
230 Open_vSwitch ovsRow = (Open_vSwitch) row;
231 Map<String, String> configs = ovsRow.getOther_config();
233 if (configs == null) {
234 logger.debug("Open_vSwitch table is null for Node {} ", node);
238 bridgeMaps = configs.get(providerMappingsConfigName);
239 if (bridgeMaps == null) {
240 bridgeMaps = providerMappings;
243 if (bridgeMaps != null) {
244 for (String map : bridgeMaps.split(",")) {
245 String[] pair = map.split(":");
246 phyIfName.add(pair[1]);
250 } catch (Exception e) {
251 logger.error("Unable to find physical interface for Node: {}",
255 logger.debug("Physical interface for Node: {}, If: {}",
261 public boolean isInterested (String tableName) {
262 return tableName.equalsIgnoreCase(Open_vSwitch.NAME.getName());