1 package org.opendaylight.ovsdb.neutron;
3 import java.net.InetAddress;
4 import java.net.UnknownHostException;
5 import java.util.HashMap;
8 import org.opendaylight.controller.sal.core.Node;
9 import org.opendaylight.controller.sal.utils.ServiceHelper;
10 import org.opendaylight.ovsdb.lib.table.Open_vSwitch;
11 import org.opendaylight.ovsdb.lib.table.internal.Table;
12 import org.opendaylight.ovsdb.plugin.OVSDBConfigService;
13 import org.slf4j.Logger;
14 import org.slf4j.LoggerFactory;
16 public class AdminConfigManager {
17 static final Logger logger = LoggerFactory.getLogger(AdminConfigManager.class);
19 private String integrationBridgeName;
20 private String tunnelBridgeName;
21 private String externalBridgeName;
22 private String tunnelEndpointConfigName;
23 private Map<Node, InetAddress> tunnelEndpoints;
25 // Refer to /etc/quantum/plugins/openvswitch/ovs_quantum_plugin.ini
26 private static String DEFAULT_TUNNEL_ENDPOINT_CONFIG_STRING = "local_ip";
27 private static String DEFAULT_INTEGRATION_BRIDGENAME = "br-int";
28 private static String DEFAULT_TUNNEL_BRIDGENAME = "br-tun";
29 private static String DEFAULT_EXTERNAL_BRIDGENAME = "br-ex";
30 private static String CONFIG_TUNNEL_ENDPOINT_CONFIG = "tunnel_endpoint_config_string";
31 private static String CONFIG_INTEGRATION_BRIDGENAME = "integration_bridge";
32 private static String CONFIG_TUNNEL_BRIDGENAME = "tunnel_bridge";
33 private static String CONFIG_EXTERNAL_BRIDGENAME = "external_bridge";
35 private static AdminConfigManager adminConfiguration = new AdminConfigManager();
37 private AdminConfigManager() {
38 tunnelEndpoints = new HashMap<Node, InetAddress>();
39 tunnelEndpointConfigName = System.getProperty(CONFIG_TUNNEL_ENDPOINT_CONFIG);
40 integrationBridgeName = System.getProperty(CONFIG_INTEGRATION_BRIDGENAME);
41 tunnelBridgeName = System.getProperty(CONFIG_TUNNEL_BRIDGENAME);
42 externalBridgeName = System.getProperty(CONFIG_EXTERNAL_BRIDGENAME);
44 if (tunnelEndpointConfigName == null) tunnelEndpointConfigName = DEFAULT_TUNNEL_ENDPOINT_CONFIG_STRING;
45 if (integrationBridgeName == null) integrationBridgeName = DEFAULT_INTEGRATION_BRIDGENAME;
46 if (tunnelBridgeName == null) tunnelBridgeName = DEFAULT_TUNNEL_BRIDGENAME;
47 if (externalBridgeName == null) externalBridgeName = DEFAULT_EXTERNAL_BRIDGENAME;
50 public static AdminConfigManager getManager() {
51 return adminConfiguration;
54 public String getIntegrationBridgeName() {
55 return integrationBridgeName;
58 public void setIntegrationBridgeName(String integrationBridgeName) {
59 this.integrationBridgeName = integrationBridgeName;
62 public String getTunnelBridgeName() {
63 return tunnelBridgeName;
66 public void setTunnelBridgeName(String tunnelBridgeName) {
67 this.tunnelBridgeName = tunnelBridgeName;
70 public String getExternalBridgeName() {
71 return externalBridgeName;
74 public void setExternalBridgeName (String externalBridgeName) {
75 this.externalBridgeName = externalBridgeName;
78 public InetAddress getTunnelEndPoint(Node node) {
79 return tunnelEndpoints.get(node);
82 public void addTunnelEndpoint (Node node, InetAddress address) {
83 tunnelEndpoints.put(node, address);
86 public boolean isInterested (String tableName) {
87 return tableName.equalsIgnoreCase(Open_vSwitch.NAME.getName());
90 private void populateTunnelEndpoint (Node node, Open_vSwitch row) {
91 Map<String, String> configs = row.getOther_config();
92 if (configs != null) {
93 String tunnelEndpoint = configs.get(tunnelEndpointConfigName);
94 if (tunnelEndpoint != null) {
96 InetAddress address = InetAddress.getByName(tunnelEndpoint);
97 addTunnelEndpoint(node, address);
98 logger.debug("Tunnel Endpoint for Node {} {}", node, address.getHostAddress());
99 } catch (UnknownHostException e) {
106 public void populateTunnelEndpoint (Node node) {
107 OVSDBConfigService ovsdbTable = (OVSDBConfigService)ServiceHelper.getGlobalInstance(OVSDBConfigService.class, this);
109 Map<String, Table<?>> openvswitchTable = ovsdbTable.getRows(node, Open_vSwitch.NAME.getName());
110 if (openvswitchTable == null) {
111 logger.debug("Open_vSwitch table is null for Node {} ", node);
115 for (Table<?> row : openvswitchTable.values()) {
116 populateTunnelEndpoint(node, (Open_vSwitch)row);
118 } catch (Exception e) {
119 logger.error("Error populating Tunnel Endpoint for Node {} ", node, e);
123 // Use this later if there is a need to update the tunnel-endpoint dynamically
124 public void populateTunnelEndpoint (Node node, String tableName, Table<?> row) {
125 OVSDBConfigService ovsdbTable = (OVSDBConfigService)ServiceHelper.getGlobalInstance(OVSDBConfigService.class, this);
127 if (isInterested(tableName)) {
128 populateTunnelEndpoint(node, (Open_vSwitch)row);
130 } catch (Exception e) {
131 logger.error("Error populating Tunnel Endpoint for Node {} ", node, e);