8340a20bef9a9abde358404e29817e91d8664e6c
[ovsdb.git] / neutron / src / main / java / org / opendaylight / ovsdb / neutron / provider / ProviderNetworkManager.java
1 /*
2  * Copyright (C) 2013 Red Hat, Inc.
3  *
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
7  *
8  * Authors : Madhu Venugopal, Brent Salisbury
9  */
10 package org.opendaylight.ovsdb.neutron.provider;
11
12 import java.util.Map;
13
14 import org.opendaylight.controller.sal.core.Node;
15 import org.opendaylight.controller.sal.utils.ServiceHelper;
16 import org.opendaylight.controller.sal.utils.Status;
17 import org.opendaylight.ovsdb.lib.table.Bridge;
18 import org.opendaylight.ovsdb.lib.table.Interface;
19 import org.opendaylight.ovsdb.lib.table.internal.Table;
20 import org.opendaylight.ovsdb.plugin.OVSDBConfigService;
21 import org.slf4j.Logger;
22 import org.slf4j.LoggerFactory;
23
24 public abstract class ProviderNetworkManager {
25     static final Logger logger = LoggerFactory.getLogger(ProviderNetworkManager.class);
26     private static ProviderNetworkManager provider;
27     protected static final int LLDP_PRIORITY = 1000;
28     protected static final int NORMAL_PRIORITY = 0;
29     protected static final String OPENFLOW_10 = "1.0";
30     protected static final String OPENFLOW_13 = "1.3";
31
32     public static ProviderNetworkManager getManager() {
33         if (provider != null) return provider;
34         String ofVersion = System.getProperty("ovsdb.of.version", OPENFLOW_10);
35         switch (ofVersion) {
36             case OPENFLOW_13:
37                 provider = new OF13ProviderManager();
38                 break;
39             case OPENFLOW_10:
40             default:
41                 provider = new OF10ProviderManager();
42                 break;
43         }
44         return provider;
45     }
46
47     protected String getInternalBridgeUUID (Node node, String bridgeName) {
48         try {
49             OVSDBConfigService ovsdbTable = (OVSDBConfigService)ServiceHelper.getGlobalInstance(OVSDBConfigService.class, this);
50             Map<String, Table<?>> bridgeTable = ovsdbTable.getRows(node, Bridge.NAME.getName());
51             if (bridgeTable == null) return null;
52             for (String key : bridgeTable.keySet()) {
53                 Bridge bridge = (Bridge)bridgeTable.get(key);
54                 if (bridge.getName().equals(bridgeName)) return key;
55             }
56         } catch (Exception e) {
57             logger.error("Error getting Bridge Identifier for {} / {}", node, bridgeName, e);
58         }
59         return null;
60     }
61
62     public abstract boolean hasPerTenantTunneling();
63     public abstract Status handleInterfaceUpdate(String tunnelType, String tunnelKey);
64     public abstract Status handleInterfaceUpdate(String tunnelType, String tunnelKey, Node source, Interface intf);
65     public abstract Status handleInterfaceDelete(String tunnelType, String tunnelKey, Node source, Interface intf, boolean isLastInstanceOnNode);
66     /*
67      * Initialize the Flow rules given the OVSDB node.
68      * This method provides a set of common functionalities to initialize the Flow rules of an OVSDB node
69      * that are Openflow Version specific. Hence we have this method in addition to the following
70      * Openflow Node specific initialization method.
71      */
72     public abstract void initializeFlowRules(Node node);
73
74     /*
75      * Initialize the Flow rules given the Openflow node
76      */
77     public abstract void initializeOFFlowRules(Node openflowNode);
78 }