OVSDB project's OpenFlow 1.3 ProtocolPlugin integration via Controller's MD-SAL infra...
[ovsdb.git] / neutron / src / main / java / org / opendaylight / ovsdb / neutron / InternalNetworkManager.java
index cf6272dffdcaba7945f01c9994feeb702999e9a6..b11ada9353fb2b8fafa3c249b9bce947d2a6edab 100644 (file)
@@ -9,17 +9,9 @@
  */
 package org.opendaylight.ovsdb.neutron;
 
-import java.util.ArrayList;
-import java.util.List;
 import java.util.Map;
-import java.util.Set;
 
-import org.opendaylight.controller.forwardingrulesmanager.FlowConfig;
-import org.opendaylight.controller.forwardingrulesmanager.IForwardingRulesManager;
-import org.opendaylight.controller.sal.action.ActionType;
 import org.opendaylight.controller.sal.core.Node;
-import org.opendaylight.controller.sal.utils.EtherTypes;
-import org.opendaylight.controller.sal.utils.HexEncode;
 import org.opendaylight.controller.sal.utils.ServiceHelper;
 import org.opendaylight.controller.sal.utils.Status;
 import org.opendaylight.controller.sal.utils.StatusCode;
@@ -30,6 +22,7 @@ import org.opendaylight.ovsdb.lib.table.Bridge;
 import org.opendaylight.ovsdb.lib.table.Interface;
 import org.opendaylight.ovsdb.lib.table.Port;
 import org.opendaylight.ovsdb.lib.table.internal.Table;
+import org.opendaylight.ovsdb.neutron.provider.ProviderNetworkManager;
 import org.opendaylight.ovsdb.plugin.IConnectionServiceInternal;
 import org.opendaylight.ovsdb.plugin.OVSDBConfigService;
 import org.opendaylight.ovsdb.plugin.StatusWithUuid;
@@ -119,8 +112,10 @@ public class InternalNetworkManager {
 
         Status status = this.addInternalBridge(node, brInt, patchTun, patchInt);
         if (!status.isSuccess()) logger.debug("Integration Bridge Creation Status : "+status.toString());
-        status = this.addInternalBridge(node, brTun, patchInt, patchTun);
-        if (!status.isSuccess()) logger.debug("Tunnel Bridge Creation Status : "+status.toString());
+        if (ProviderNetworkManager.getManager().hasPerTenantTunneling()) {
+            status = this.addInternalBridge(node, brTun, patchInt, patchTun);
+            if (!status.isSuccess()) logger.debug("Tunnel Bridge Creation Status : "+status.toString());
+        }
     }
 
     /*
@@ -145,6 +140,11 @@ public class InternalNetworkManager {
         if (bridgeUUID == null) {
             Bridge bridge = new Bridge();
             bridge.setName(bridgeName);
+            if (!ProviderNetworkManager.getManager().hasPerTenantTunneling()) {
+                OvsDBSet<String> protocols = new OvsDBSet<String>();
+                protocols.add("OpenFlow13");
+                bridge.setProtocols(protocols);
+            }
 
             StatusWithUuid statusWithUuid = ovsdbTable.insertRow(node, Bridge.NAME.getName(), null, bridge);
             if (!statusWithUuid.isSuccess()) return statusWithUuid;
@@ -157,7 +157,7 @@ public class InternalNetworkManager {
         IConnectionServiceInternal connectionService = (IConnectionServiceInternal)ServiceHelper.getGlobalInstance(IConnectionServiceInternal.class, this);
         connectionService.setOFController(node, bridgeUUID);
 
-        if (localPathName != null && remotePatchName != null) {
+        if (localPathName != null && remotePatchName != null && ProviderNetworkManager.getManager().hasPerTenantTunneling()) {
             return addPatchPort(node, bridgeUUID, localPathName, remotePatchName);
         }
         return new Status(StatusCode.SUCCESS);
@@ -200,95 +200,12 @@ public class InternalNetworkManager {
         return ovsdbTable.updateRow(node, Interface.NAME.getName(), patchPortUUID, interfaceUUID, tunInterface);
     }
 
-    private void initializeOFNormalFlowRules(Node node, String bridgeName) {
-        String brIntId = this.getInternalBridgeUUID(node, bridgeName);
-        if (brIntId == null) {
-            logger.error("Failed to initialize Flow Rules for {}", node);
-            return;
-        }
-        try {
-            OVSDBConfigService ovsdbTable = (OVSDBConfigService)ServiceHelper.getGlobalInstance(OVSDBConfigService.class, this);
-            Bridge bridge = (Bridge) ovsdbTable.getRow(node, Bridge.NAME.getName(), brIntId);
-            Set<String> dpids = bridge.getDatapath_id();
-            if (dpids == null || dpids.size() ==  0) return;
-            Long dpidLong = Long.valueOf(HexEncode.stringToLong((String)dpids.toArray()[0]));
-            Node ofNode = new Node(Node.NodeIDType.OPENFLOW, dpidLong);
-            IForwardingRulesManager frm = (IForwardingRulesManager) ServiceHelper.getInstance(
-                    IForwardingRulesManager.class, "default", this);
-            String flowName = ActionType.HW_PATH.toString();
-            FlowConfig flow = new FlowConfig();
-            flow.setName("NORMAL");
-            flow.setNode(ofNode);
-            flow.setPriority(NORMAL_PRIORITY+"");
-            flow.setInstallInHw(true);
-            List<String> normalAction = new ArrayList<String>();
-            normalAction.add(flowName);
-            flow.setActions(normalAction);
-            Status status = null;
-            if (frm.getStaticFlow(flowName, ofNode) == null) {
-                status = frm.addStaticFlow(flow);
-                logger.debug("Flow Programming Add Status {} for Flow {} on {} / {}", status, flow, ofNode, node);
-            } else {
-                status = frm.modifyStaticFlow(flow);
-                logger.debug("Flow Programming Modify Status {} for Flow {} on {} / {}", status, flow, ofNode, node);
-            }
-        } catch (Exception e) {
-            logger.error("Failed to initialize Flow Rules for {}", node, e);
-        }
-    }
-
-    private void initializeLLDPFlowRules(Node node, String bridgeName) {
-        String brIntId = this.getInternalBridgeUUID(node, bridgeName);
-        if (brIntId == null) {
-            logger.error("Failed to initialize Flow Rules for {}", node);
-            return;
-        }
-        try {
-            OVSDBConfigService ovsdbTable = (OVSDBConfigService)ServiceHelper.getGlobalInstance(OVSDBConfigService.class, this);
-            Bridge bridge = (Bridge) ovsdbTable.getRow(node, Bridge.NAME.getName(), brIntId);
-            Set<String> dpids = bridge.getDatapath_id();
-            if (dpids == null || dpids.size() ==  0) return;
-            Long dpidLong = Long.valueOf(HexEncode.stringToLong((String)dpids.toArray()[0]));
-            Node ofNode = new Node(Node.NodeIDType.OPENFLOW, dpidLong);
-            IForwardingRulesManager frm = (IForwardingRulesManager) ServiceHelper.getInstance(
-                    IForwardingRulesManager.class, "default", this);
-            String flowName = "PuntLLDP";
-            List<String> puntAction = new ArrayList<String>();
-            puntAction.add(ActionType.CONTROLLER.toString());
-
-            FlowConfig allowLLDP = new FlowConfig();
-            allowLLDP.setInstallInHw(true);
-            allowLLDP.setName(flowName);
-            allowLLDP.setPriority(LLDP_PRIORITY+"");
-            allowLLDP.setNode(ofNode);
-            allowLLDP.setInstallInHw(true);
-            allowLLDP.setEtherType("0x" + Integer.toHexString(EtherTypes.LLDP.intValue())
-                    .toUpperCase());
-            allowLLDP.setActions(puntAction);
-            Status status = null;
-            if (frm.getStaticFlow(flowName, ofNode) == null) {
-                status = frm.addStaticFlow(allowLLDP);
-                logger.debug("LLDP Flow Add Status {} for Flow {} on {} / {}", status, allowLLDP, ofNode, node);
-            } else {
-                status = frm.modifyStaticFlow(allowLLDP);
-                logger.debug("LLDP Flow Modify Status {} for Flow {} on {} / {}", status, allowLLDP, ofNode, node);
-            }
-        } catch (Exception e) {
-            logger.error("Failed to initialize Flow Rules for {}", node, e);
-        }
-    }
-
     public void prepareInternalNetwork(Node node) {
         try {
             this.createInternalNetworkForOverlay(node);
         } catch (Exception e) {
             logger.error("Error creating internal network "+node.toString(), e);
         }
-        //Install NORMAL flows on all the bridges to make sure that we dont end up punting traffic to the OF Controller
-        this.initializeOFNormalFlowRules(node, AdminConfigManager.getManager().getIntegrationBridgeName());
-        this.initializeOFNormalFlowRules(node, AdminConfigManager.getManager().getExternalBridgeName());
-        this.initializeOFNormalFlowRules(node, AdminConfigManager.getManager().getTunnelBridgeName());
-        this.initializeLLDPFlowRules(node, AdminConfigManager.getManager().getTunnelBridgeName());
-        this.initializeLLDPFlowRules(node, AdminConfigManager.getManager().getIntegrationBridgeName());
+        ProviderNetworkManager.getManager().initializeFlowRules(node);
     }
 }