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;
13 import java.net.UnknownHostException;
14 import java.util.HashMap;
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.internal.Table;
21 import org.opendaylight.ovsdb.plugin.OVSDBConfigService;
22 import org.slf4j.Logger;
23 import org.slf4j.LoggerFactory;
25 public class AdminConfigManager {
26 static final Logger logger = LoggerFactory.getLogger(AdminConfigManager.class);
28 private String integrationBridgeName;
29 private String tunnelBridgeName;
30 private String externalBridgeName;
31 private String tunnelEndpointConfigName;
32 private String patchToIntegration;
33 private String patchToTunnel;
34 private Map<Node, InetAddress> tunnelEndpoints;
36 // Refer to /etc/quantum/plugins/openvswitch/ovs_quantum_plugin.ini
37 private static String DEFAULT_TUNNEL_ENDPOINT_CONFIG_STRING = "local_ip";
38 private static String DEFAULT_INTEGRATION_BRIDGENAME = "br-int";
39 private static String DEFAULT_TUNNEL_BRIDGENAME = "br-tun";
40 private static String DEFAULT_EXTERNAL_BRIDGENAME = "br-ex";
41 private static String DEFAULT_PATCH_TO_INTEGRATION = "patch-int";
42 private static String DEFAULT_PATCH_TO_TUNNEL = "patch-tun";
43 private static String CONFIG_TUNNEL_ENDPOINT_CONFIG = "tunnel_endpoint_config_string";
44 private static String CONFIG_INTEGRATION_BRIDGENAME = "integration_bridge";
45 private static String CONFIG_TUNNEL_BRIDGENAME = "tunnel_bridge";
46 private static String CONFIG_EXTERNAL_BRIDGENAME = "external_bridge";
47 private static String CONFIG_PATCH_TO_INTEGRATION = "patch-int";
48 private static String CONFIG_PATCH_TO_TUNNEL = "patch-tun";
50 private static AdminConfigManager adminConfiguration = new AdminConfigManager();
52 private AdminConfigManager() {
53 tunnelEndpoints = new HashMap<Node, InetAddress>();
54 tunnelEndpointConfigName = System.getProperty(CONFIG_TUNNEL_ENDPOINT_CONFIG);
55 integrationBridgeName = System.getProperty(CONFIG_INTEGRATION_BRIDGENAME);
56 tunnelBridgeName = System.getProperty(CONFIG_TUNNEL_BRIDGENAME);
57 externalBridgeName = System.getProperty(CONFIG_EXTERNAL_BRIDGENAME);
58 patchToIntegration = System.getProperty(CONFIG_PATCH_TO_INTEGRATION);
59 patchToTunnel = System.getProperty(CONFIG_PATCH_TO_TUNNEL);
61 if (tunnelEndpointConfigName == null) tunnelEndpointConfigName = DEFAULT_TUNNEL_ENDPOINT_CONFIG_STRING;
62 if (integrationBridgeName == null) integrationBridgeName = DEFAULT_INTEGRATION_BRIDGENAME;
63 if (tunnelBridgeName == null) tunnelBridgeName = DEFAULT_TUNNEL_BRIDGENAME;
64 if (externalBridgeName == null) externalBridgeName = DEFAULT_EXTERNAL_BRIDGENAME;
65 if (patchToIntegration == null) patchToIntegration = DEFAULT_PATCH_TO_INTEGRATION;
66 if (patchToTunnel == null) patchToTunnel = DEFAULT_PATCH_TO_TUNNEL;
69 public static AdminConfigManager getManager() {
70 return adminConfiguration;
73 public String getIntegrationBridgeName() {
74 return integrationBridgeName;
77 public void setIntegrationBridgeName(String integrationBridgeName) {
78 this.integrationBridgeName = integrationBridgeName;
81 public String getTunnelBridgeName() {
82 return tunnelBridgeName;
85 public void setTunnelBridgeName(String tunnelBridgeName) {
86 this.tunnelBridgeName = tunnelBridgeName;
89 public String getExternalBridgeName() {
90 return externalBridgeName;
93 public void setExternalBridgeName (String externalBridgeName) {
94 this.externalBridgeName = externalBridgeName;
97 public String getPatchToIntegration() {
98 return patchToIntegration;
101 public void setPatchToIntegration(String patchToIntegration) {
102 this.patchToIntegration = patchToIntegration;
105 public String getPatchToTunnel() {
106 return patchToTunnel;
109 public void setPatchToTunnel(String patchToTunnel) {
110 this.patchToTunnel = patchToTunnel;
113 public InetAddress getTunnelEndPoint(Node node) {
114 return tunnelEndpoints.get(node);
117 public void addTunnelEndpoint (Node node, InetAddress address) {
118 tunnelEndpoints.put(node, address);
121 public boolean isInterested (String tableName) {
122 return tableName.equalsIgnoreCase(Open_vSwitch.NAME.getName());
125 private void populateTunnelEndpoint (Node node, Open_vSwitch row) {
126 Map<String, String> configs = row.getOther_config();
127 if (configs != null) {
128 String tunnelEndpoint = configs.get(tunnelEndpointConfigName);
129 if (tunnelEndpoint != null) {
131 InetAddress address = InetAddress.getByName(tunnelEndpoint);
132 addTunnelEndpoint(node, address);
133 logger.debug("Tunnel Endpoint for Node {} {}", node, address.getHostAddress());
134 } catch (UnknownHostException e) {
135 logger.error("Unable to add tunnel endpoint for node " + node, e);
141 public void populateTunnelEndpoint (Node node) {
142 OVSDBConfigService ovsdbTable = (OVSDBConfigService)ServiceHelper.getGlobalInstance(OVSDBConfigService.class, this);
144 Map<String, Table<?>> openvswitchTable = ovsdbTable.getRows(node, Open_vSwitch.NAME.getName());
145 if (openvswitchTable == null) {
146 logger.debug("Open_vSwitch table is null for Node {} ", node);
150 for (Table<?> row : openvswitchTable.values()) {
151 populateTunnelEndpoint(node, (Open_vSwitch)row);
153 } catch (Exception e) {
154 logger.error("Error populating Tunnel Endpoint for Node {} ", node, e);
158 // Use this later if there is a need to update the tunnel-endpoint dynamically
159 public void populateTunnelEndpoint (Node node, String tableName, Table<?> row) {
160 OVSDBConfigService ovsdbTable = (OVSDBConfigService)ServiceHelper.getGlobalInstance(OVSDBConfigService.class, this);
162 if (isInterested(tableName)) {
163 populateTunnelEndpoint(node, (Open_vSwitch)row);
165 } catch (Exception e) {
166 logger.error("Error populating Tunnel Endpoint for Node {} ", node, e);