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
10 package org.opendaylight.ovsdb.neutron;
12 import java.net.InetAddress;
15 import org.opendaylight.controller.sal.core.Node;
16 import org.opendaylight.controller.sal.utils.ServiceHelper;
17 import org.opendaylight.ovsdb.lib.table.Open_vSwitch;
18 import org.opendaylight.ovsdb.lib.table.Table;
19 import org.opendaylight.ovsdb.plugin.OVSDBConfigService;
20 import org.slf4j.Logger;
21 import org.slf4j.LoggerFactory;
23 public class AdminConfigManager {
24 static final Logger logger = LoggerFactory.getLogger(AdminConfigManager.class);
26 private String integrationBridgeName;
27 private String tunnelBridgeName;
28 private String externalBridgeName;
29 private String tunnelEndpointConfigName;
30 private String patchToIntegration;
31 private String patchToTunnel;
33 // Refer to /etc/quantum/plugins/openvswitch/ovs_quantum_plugin.ini
34 private static String DEFAULT_TUNNEL_ENDPOINT_CONFIG_STRING = "local_ip";
35 private static String DEFAULT_INTEGRATION_BRIDGENAME = "br-int";
36 private static String DEFAULT_TUNNEL_BRIDGENAME = "br-tun";
37 private static String DEFAULT_EXTERNAL_BRIDGENAME = "br-ex";
38 private static String DEFAULT_PATCH_TO_INTEGRATION = "patch-int";
39 private static String DEFAULT_PATCH_TO_TUNNEL = "patch-tun";
40 private static String CONFIG_TUNNEL_ENDPOINT_CONFIG = "tunnel_endpoint_config_string";
41 private static String CONFIG_INTEGRATION_BRIDGENAME = "integration_bridge";
42 private static String CONFIG_TUNNEL_BRIDGENAME = "tunnel_bridge";
43 private static String CONFIG_EXTERNAL_BRIDGENAME = "external_bridge";
44 private static String CONFIG_PATCH_TO_INTEGRATION = "patch-int";
45 private static String CONFIG_PATCH_TO_TUNNEL = "patch-tun";
47 private static AdminConfigManager adminConfiguration = new AdminConfigManager();
49 private AdminConfigManager() {
50 tunnelEndpointConfigName = System.getProperty(CONFIG_TUNNEL_ENDPOINT_CONFIG);
51 integrationBridgeName = System.getProperty(CONFIG_INTEGRATION_BRIDGENAME);
52 tunnelBridgeName = System.getProperty(CONFIG_TUNNEL_BRIDGENAME);
53 externalBridgeName = System.getProperty(CONFIG_EXTERNAL_BRIDGENAME);
54 patchToIntegration = System.getProperty(CONFIG_PATCH_TO_INTEGRATION);
55 patchToTunnel = System.getProperty(CONFIG_PATCH_TO_TUNNEL);
57 if (tunnelEndpointConfigName == null) tunnelEndpointConfigName = DEFAULT_TUNNEL_ENDPOINT_CONFIG_STRING;
58 if (integrationBridgeName == null) integrationBridgeName = DEFAULT_INTEGRATION_BRIDGENAME;
59 if (tunnelBridgeName == null) tunnelBridgeName = DEFAULT_TUNNEL_BRIDGENAME;
60 if (externalBridgeName == null) externalBridgeName = DEFAULT_EXTERNAL_BRIDGENAME;
61 if (patchToIntegration == null) patchToIntegration = DEFAULT_PATCH_TO_INTEGRATION;
62 if (patchToTunnel == null) patchToTunnel = DEFAULT_PATCH_TO_TUNNEL;
65 public static AdminConfigManager getManager() {
66 return adminConfiguration;
69 public String getIntegrationBridgeName() {
70 return integrationBridgeName;
73 public void setIntegrationBridgeName(String integrationBridgeName) {
74 this.integrationBridgeName = integrationBridgeName;
77 public String getTunnelBridgeName() {
78 return tunnelBridgeName;
81 public void setTunnelBridgeName(String tunnelBridgeName) {
82 this.tunnelBridgeName = tunnelBridgeName;
85 public String getExternalBridgeName() {
86 return externalBridgeName;
89 public void setExternalBridgeName (String externalBridgeName) {
90 this.externalBridgeName = externalBridgeName;
93 public String getPatchToIntegration() {
94 return patchToIntegration;
97 public void setPatchToIntegration(String patchToIntegration) {
98 this.patchToIntegration = patchToIntegration;
101 public String getPatchToTunnel() {
102 return patchToTunnel;
105 public void setPatchToTunnel(String patchToTunnel) {
106 this.patchToTunnel = patchToTunnel;
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);
148 public boolean isInterested (String tableName) {
149 return tableName.equalsIgnoreCase(Open_vSwitch.NAME.getName());