Simplify FLAT typed traffic pipeline to support ovs multicasting
Change-Id: Iadec2aec97314ee927c608a1a1b06d1e3bdbdf8d
diff --git a/apps/openstacknetworking/api/src/main/java/org/onosproject/openstacknetworking/api/Constants.java b/apps/openstacknetworking/api/src/main/java/org/onosproject/openstacknetworking/api/Constants.java
index 1ee3ee2..a294d3e 100644
--- a/apps/openstacknetworking/api/src/main/java/org/onosproject/openstacknetworking/api/Constants.java
+++ b/apps/openstacknetworking/api/src/main/java/org/onosproject/openstacknetworking/api/Constants.java
@@ -81,10 +81,7 @@
public static final int PRIORITY_EXTERNAL_FLOATING_ROUTING_RULE = 27000;
public static final int PRIORITY_SNAT_RULE = 26000;
public static final int PRIORITY_SWITCHING_RULE = 30000;
- public static final int PRIORITY_FLAT_JUMP_UPSTREAM_RULE = 41000;
public static final int PRIORITY_FLAT_UPSTREAM_RULE = 41000;
- public static final int PRIORITY_FLAT_ARP_UPSTREAM_RULE = 41500;
- public static final int PRIORITY_FLAT_DOWNSTREAM_RULE = 42000;
public static final int PRIORITY_DHCP_RULE = 42000;
public static final int PRIORITY_ADMIN_RULE = 32000;
public static final int PRIORITY_ACL_RULE = 31000;
@@ -114,8 +111,9 @@
public static final int VTAP_FLAT_OUTBOUND_TABLE = 11;
public static final int VTAP_FLAT_OUTBOUND_MIRROR_TABLE = 12;
public static final int DHCP_TABLE = 5;
- public static final int FLAT_TABLE = 20;
public static final int VTAG_TABLE = 30;
+ public static final int PRE_FLAT_TABLE = 31;
+ public static final int FLAT_TABLE = 32;
public static final int ARP_TABLE = 35;
public static final int ACL_EGRESS_TABLE = 40;
public static final int ACL_INGRESS_TABLE = 44;
diff --git a/apps/openstacknetworking/app/src/main/java/org/onosproject/openstacknetworking/impl/OpenstackFlowRuleManager.java b/apps/openstacknetworking/app/src/main/java/org/onosproject/openstacknetworking/impl/OpenstackFlowRuleManager.java
index e1f579e..b2d83cd 100644
--- a/apps/openstacknetworking/app/src/main/java/org/onosproject/openstacknetworking/impl/OpenstackFlowRuleManager.java
+++ b/apps/openstacknetworking/app/src/main/java/org/onosproject/openstacknetworking/impl/OpenstackFlowRuleManager.java
@@ -16,14 +16,12 @@
package org.onosproject.openstacknetworking.impl;
-import org.onlab.packet.Ethernet;
import org.onosproject.cluster.ClusterService;
import org.onosproject.cluster.LeadershipService;
import org.onosproject.cluster.NodeId;
import org.onosproject.core.ApplicationId;
import org.onosproject.core.CoreService;
import org.onosproject.net.DeviceId;
-import org.onosproject.net.Port;
import org.onosproject.net.PortNumber;
import org.onosproject.net.device.DeviceService;
import org.onosproject.net.flow.DefaultFlowRule;
@@ -46,22 +44,14 @@
import org.osgi.service.component.annotations.Deactivate;
import org.osgi.service.component.annotations.Reference;
import org.osgi.service.component.annotations.ReferenceCardinality;
-import org.onosproject.openstacknode.api.OpenstackPhyInterface;
import org.slf4j.Logger;
import java.util.Objects;
-import java.util.Optional;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import static org.onlab.util.Tools.groupedThreads;
-import static org.onosproject.net.AnnotationKeys.PORT_NAME;
-import static org.onosproject.openstacknetworking.api.Constants.DHCP_TABLE;
import static org.onosproject.openstacknetworking.api.Constants.OPENSTACK_NETWORKING_APP_ID;
-import static org.onosproject.openstacknetworking.api.Constants.PRIORITY_FLAT_JUMP_UPSTREAM_RULE;
-import static org.onosproject.openstacknetworking.api.Constants.STAT_FLAT_OUTBOUND_TABLE;
-import static org.onosproject.openstacknetworking.util.OpenstackNetworkingUtil.structurePortName;
-import static org.onosproject.openstacknode.api.Constants.INTEGRATION_TO_PHYSICAL_PREFIX;
import static org.onosproject.openstacknode.api.OpenstackNode.NodeType.COMPUTE;
import static org.slf4j.LoggerFactory.getLogger;
@@ -74,6 +64,8 @@
private final Logger log = getLogger(getClass());
private static final int DROP_PRIORITY = 0;
+ private static final int LOW_PRIORITY = 10000;
+ private static final int MID_PRIORITY = 20000;
private static final int HIGH_PRIORITY = 30000;
private static final int TIMEOUT_SNAT_RULE = 60;
@@ -233,70 +225,17 @@
// table lookup
setupJumpTable(deviceId);
+ // for setting up default FLAT table behavior which is NORMAL
+ setupFlatTable(deviceId);
+
// for outbound table transition
connectTables(deviceId, Constants.STAT_OUTBOUND_TABLE,
Constants.VTAP_OUTBOUND_TABLE);
connectTables(deviceId, Constants.VTAP_OUTBOUND_TABLE,
Constants.FORWARDING_TABLE);
- // for FLAT outbound table transition
- connectTables(deviceId, Constants.STAT_FLAT_OUTBOUND_TABLE,
- Constants.VTAP_FLAT_OUTBOUND_TABLE);
- connectTables(deviceId, Constants.VTAP_FLAT_OUTBOUND_TABLE,
- Constants.FLAT_TABLE);
-
- // for FLAT table drop
- setUpTableMissEntry(deviceId, Constants.FLAT_TABLE);
-
- // for FLAT jump rules
- if (!osNodeService.node(deviceId).phyIntfs().isEmpty()) {
- setFlatJumpRules(deviceId);
- }
- }
-
- private void setFlatJumpRules(DeviceId deviceId) {
- osNodeService.node(deviceId)
- .phyIntfs()
- .forEach(phyInterface ->
- setFlatJumpRulesForPatchPort(deviceId, phyInterface));
- }
-
- private void setFlatJumpRuleForPatchPort(DeviceId deviceId,
- PortNumber portNumber, short ethType) {
- TrafficSelector.Builder selector = DefaultTrafficSelector.builder();
- selector.matchInPort(portNumber)
- .matchEthType(ethType);
-
- TrafficTreatment.Builder treatment = DefaultTrafficTreatment.builder();
- treatment.transition(STAT_FLAT_OUTBOUND_TABLE);
- FlowRule flowRuleForIp = DefaultFlowRule.builder()
- .forDevice(deviceId)
- .withSelector(selector.build())
- .withTreatment(treatment.build())
- .withPriority(PRIORITY_FLAT_JUMP_UPSTREAM_RULE)
- .fromApp(appId)
- .makePermanent()
- .forTable(DHCP_TABLE)
- .build();
-
- applyRule(flowRuleForIp, true);
- }
-
- private void setFlatJumpRulesForPatchPort(DeviceId deviceId,
- OpenstackPhyInterface phyIntf) {
- Optional<Port> patchPort = deviceService.getPorts(deviceId).stream()
- .filter(port -> {
- String annotPortName = port.annotations().value(PORT_NAME);
- String portName = structurePortName(
- INTEGRATION_TO_PHYSICAL_PREFIX + phyIntf.network());
- return Objects.equals(annotPortName, portName);
- })
- .findAny();
-
- patchPort.ifPresent(port -> {
- setFlatJumpRuleForPatchPort(deviceId, port.number(), Ethernet.TYPE_IPV4);
- setFlatJumpRuleForPatchPort(deviceId, port.number(), Ethernet.TYPE_ARP);
- });
+ // for PRE_FLAT and FLAT table transition
+ connectTables(deviceId, Constants.PRE_FLAT_TABLE, Constants.FLAT_TABLE);
}
private void setupJumpTable(DeviceId deviceId) {
@@ -336,6 +275,24 @@
applyRule(flowRule, true);
}
+ private void setupFlatTable(DeviceId deviceId) {
+ TrafficSelector.Builder selector = DefaultTrafficSelector.builder();
+ TrafficTreatment.Builder treatment = DefaultTrafficTreatment.builder()
+ .setOutput(PortNumber.NORMAL);
+
+ FlowRule flowRule = DefaultFlowRule.builder()
+ .forDevice(deviceId)
+ .withSelector(selector.build())
+ .withTreatment(treatment.build())
+ .withPriority(LOW_PRIORITY)
+ .fromApp(appId)
+ .makePermanent()
+ .forTable(Constants.FLAT_TABLE)
+ .build();
+
+ applyRule(flowRule, true);
+ }
+
private class InternalOpenstackNodeListener implements OpenstackNodeListener {
@Override
diff --git a/apps/openstacknetworking/app/src/main/java/org/onosproject/openstacknetworking/impl/OpenstackK8sIntegrationManager.java b/apps/openstacknetworking/app/src/main/java/org/onosproject/openstacknetworking/impl/OpenstackK8sIntegrationManager.java
index ab99742..7c75ecc 100644
--- a/apps/openstacknetworking/app/src/main/java/org/onosproject/openstacknetworking/impl/OpenstackK8sIntegrationManager.java
+++ b/apps/openstacknetworking/app/src/main/java/org/onosproject/openstacknetworking/impl/OpenstackK8sIntegrationManager.java
@@ -16,10 +16,8 @@
package org.onosproject.openstacknetworking.impl;
-import org.onlab.packet.ARP;
import org.onlab.packet.Ethernet;
import org.onlab.packet.IPv4;
-import org.onlab.packet.Ip4Address;
import org.onlab.packet.IpAddress;
import org.onlab.packet.IpPrefix;
import org.onlab.packet.MacAddress;
@@ -55,13 +53,12 @@
import java.util.Objects;
import static org.onosproject.net.AnnotationKeys.PORT_NAME;
-import static org.onosproject.openstacknetworking.api.Constants.DHCP_TABLE;
import static org.onosproject.openstacknetworking.api.Constants.FLAT_TABLE;
+import static org.onosproject.openstacknetworking.api.Constants.PRE_FLAT_TABLE;
import static org.onosproject.openstacknetworking.api.Constants.PRIORITY_CNI_PT_IP_RULE;
-import static org.onosproject.openstacknetworking.api.Constants.PRIORITY_CNI_PT_NODE_PORT_ARP_EXT_RULE;
-import static org.onosproject.openstacknetworking.api.Constants.PRIORITY_CNI_PT_NODE_PORT_ARP_RULE;
import static org.onosproject.openstacknetworking.api.Constants.PRIORITY_CNI_PT_NODE_PORT_IP_RULE;
-import static org.onosproject.openstacknetworking.api.Constants.STAT_FLAT_OUTBOUND_TABLE;
+import static org.onosproject.openstacknetworking.api.Constants.PRIORITY_SWITCHING_RULE;
+import static org.onosproject.openstacknetworking.api.Constants.VTAG_TABLE;
import static org.onosproject.openstacknetworking.api.OpenstackNetwork.Type.FLAT;
import static org.onosproject.openstacknetworking.util.OpenstackNetworkingUtil.shiftIpDomain;
import static org.onosproject.openstacknetworking.util.OpenstackNetworkingUtil.structurePortName;
@@ -145,18 +142,12 @@
public void installCniPtNodePortRules(IpAddress k8sNodeIp, String osK8sExtPortName) {
setNodePortIngressRules(k8sNodeIp, osK8sExtPortName, true);
setNodePortEgressRules(k8sNodeIp, osK8sExtPortName, true);
-
- setArpRequestRules(k8sNodeIp, osK8sExtPortName, true);
- setArpReplyRules(k8sNodeIp, osK8sExtPortName, true);
}
@Override
public void uninstallCniPtNodePortRules(IpAddress k8sNodeIp, String osK8sExtPortName) {
setNodePortIngressRules(k8sNodeIp, osK8sExtPortName, false);
setNodePortEgressRules(k8sNodeIp, osK8sExtPortName, false);
-
- setArpRequestRules(k8sNodeIp, osK8sExtPortName, false);
- setArpReplyRules(k8sNodeIp, osK8sExtPortName, false);
}
private void setNodeToPodIpRules(IpAddress k8sNodeIp,
@@ -260,7 +251,7 @@
TrafficTreatment treatment = DefaultTrafficTreatment.builder()
.setIpDst(k8sNodeIp)
.setEthDst(instPort.macAddress())
- .transition(STAT_FLAT_OUTBOUND_TABLE)
+ .transition(FLAT_TABLE)
.build();
osFlowRuleService.setRule(
@@ -269,9 +260,11 @@
selector,
treatment,
PRIORITY_CNI_PT_IP_RULE,
- DHCP_TABLE,
+ PRE_FLAT_TABLE,
install
);
+
+ setJumpRules(osK8sIntPortNum, osNode, install);
}
private void setNodePortIngressRules(IpAddress k8sNodeIp,
@@ -311,7 +304,7 @@
tcpSelectorBuilder.build(),
treatment,
PRIORITY_CNI_PT_NODE_PORT_IP_RULE,
- FLAT_TABLE,
+ PRE_FLAT_TABLE,
install
);
@@ -321,7 +314,7 @@
udpSelectorBuilder.build(),
treatment,
PRIORITY_CNI_PT_NODE_PORT_IP_RULE,
- FLAT_TABLE,
+ PRE_FLAT_TABLE,
install
);
});
@@ -367,96 +360,11 @@
selector,
treatment,
PRIORITY_CNI_PT_NODE_PORT_IP_RULE,
- DHCP_TABLE,
- install
- );
- }
-
- private void setArpRequestRules(IpAddress k8sNodeIp, String osK8sExtPortName, boolean install) {
- InstancePort instPort = instPortByNodeIp(k8sNodeIp);
-
- if (instPort == null) {
- return;
- }
-
- OpenstackNode osNode = osNodeByNodeIp(k8sNodeIp);
-
- if (osNode == null) {
- return;
- }
-
- PortNumber osK8sExtPortNum = portNumberByNodeIpAndPortName(k8sNodeIp, osK8sExtPortName);
-
- TrafficSelector selector = DefaultTrafficSelector.builder()
- .matchEthType(Ethernet.TYPE_ARP)
- .matchArpOp(ARP.OP_REQUEST)
- .matchInPort(osK8sExtPortNum)
- .build();
-
- TrafficTreatment treatment = DefaultTrafficTreatment.builder()
- .transition(STAT_FLAT_OUTBOUND_TABLE)
- .build();
-
- osFlowRuleService.setRule(
- appId,
- osNode.intgBridge(),
- selector,
- treatment,
- PRIORITY_CNI_PT_NODE_PORT_ARP_RULE,
- DHCP_TABLE,
+ PRE_FLAT_TABLE,
install
);
- Port phyPort = phyPortByInstPort(instPort);
-
- if (phyPort == null) {
- log.warn("No phys interface found for instance port {}", instPort);
- return;
- }
-
- TrafficTreatment extTreatment = DefaultTrafficTreatment.builder()
- .setOutput(phyPort.number())
- .build();
-
- osFlowRuleService.setRule(
- appId,
- osNode.intgBridge(),
- selector,
- extTreatment,
- PRIORITY_CNI_PT_NODE_PORT_ARP_EXT_RULE,
- FLAT_TABLE,
- install
- );
- }
-
- private void setArpReplyRules(IpAddress k8sNodeIp, String osK8sExtPortName, boolean install) {
- OpenstackNode osNode = osNodeByNodeIp(k8sNodeIp);
-
- if (osNode == null) {
- return;
- }
-
- PortNumber osK8sExtPortNum = portNumberByNodeIpAndPortName(k8sNodeIp, osK8sExtPortName);
-
- TrafficSelector selector = DefaultTrafficSelector.builder()
- .matchEthType(Ethernet.TYPE_ARP)
- .matchArpOp(ARP.OP_REPLY)
- .matchArpTpa(Ip4Address.valueOf(NODE_FAKE_IP_STR))
- .build();
-
- TrafficTreatment treatment = DefaultTrafficTreatment.builder()
- .setOutput(osK8sExtPortNum)
- .build();
-
- osFlowRuleService.setRule(
- appId,
- osNode.intgBridge(),
- selector,
- treatment,
- PRIORITY_CNI_PT_NODE_PORT_ARP_RULE,
- FLAT_TABLE,
- install
- );
+ setJumpRules(osK8sExtPortNum, osNode, install);
}
private InstancePort instPortByNodeIp(IpAddress k8sNodeIp) {
@@ -502,4 +410,24 @@
return Objects.equals(annotPortName, portName);
}).findAny().orElse(null);
}
+
+ private void setJumpRules(PortNumber portNumber, OpenstackNode osNode, boolean install) {
+ TrafficSelector jumpSelector = DefaultTrafficSelector.builder()
+ .matchInPort(portNumber)
+ .build();
+
+ TrafficTreatment jumpTreatment = DefaultTrafficTreatment.builder()
+ .transition(PRE_FLAT_TABLE)
+ .build();
+
+ osFlowRuleService.setRule(
+ appId,
+ osNode.intgBridge(),
+ jumpSelector,
+ jumpTreatment,
+ PRIORITY_SWITCHING_RULE,
+ VTAG_TABLE,
+ install
+ );
+ }
}
\ No newline at end of file
diff --git a/apps/openstacknetworking/app/src/main/java/org/onosproject/openstacknetworking/impl/OpenstackSwitchingHandler.java b/apps/openstacknetworking/app/src/main/java/org/onosproject/openstacknetworking/impl/OpenstackSwitchingHandler.java
index fa1341a..b0ffb3d 100644
--- a/apps/openstacknetworking/app/src/main/java/org/onosproject/openstacknetworking/impl/OpenstackSwitchingHandler.java
+++ b/apps/openstacknetworking/app/src/main/java/org/onosproject/openstacknetworking/impl/OpenstackSwitchingHandler.java
@@ -60,30 +60,22 @@
import static java.util.concurrent.Executors.newSingleThreadExecutor;
import static org.onlab.util.Tools.groupedThreads;
-import static org.onosproject.net.AnnotationKeys.PORT_NAME;
import static org.onosproject.openstacknetworking.api.Constants.ACL_EGRESS_TABLE;
import static org.onosproject.openstacknetworking.api.Constants.ARP_BROADCAST_MODE;
import static org.onosproject.openstacknetworking.api.Constants.ARP_TABLE;
-import static org.onosproject.openstacknetworking.api.Constants.DHCP_TABLE;
-import static org.onosproject.openstacknetworking.api.Constants.FLAT_TABLE;
import static org.onosproject.openstacknetworking.api.Constants.FORWARDING_TABLE;
import static org.onosproject.openstacknetworking.api.Constants.OPENSTACK_NETWORKING_APP_ID;
+import static org.onosproject.openstacknetworking.api.Constants.PRE_FLAT_TABLE;
import static org.onosproject.openstacknetworking.api.Constants.PRIORITY_ADMIN_RULE;
-import static org.onosproject.openstacknetworking.api.Constants.PRIORITY_FLAT_DOWNSTREAM_RULE;
-import static org.onosproject.openstacknetworking.api.Constants.PRIORITY_FLAT_JUMP_UPSTREAM_RULE;
-import static org.onosproject.openstacknetworking.api.Constants.PRIORITY_FLAT_UPSTREAM_RULE;
import static org.onosproject.openstacknetworking.api.Constants.PRIORITY_SWITCHING_RULE;
import static org.onosproject.openstacknetworking.api.Constants.PRIORITY_TUNNEL_TAG_RULE;
-import static org.onosproject.openstacknetworking.api.Constants.STAT_FLAT_OUTBOUND_TABLE;
import static org.onosproject.openstacknetworking.api.Constants.VTAG_TABLE;
import static org.onosproject.openstacknetworking.api.InstancePortEvent.Type.OPENSTACK_INSTANCE_MIGRATION_STARTED;
import static org.onosproject.openstacknetworking.util.OpenstackNetworkingUtil.deriveResourceName;
import static org.onosproject.openstacknetworking.util.OpenstackNetworkingUtil.getPropertyValue;
-import static org.onosproject.openstacknetworking.util.OpenstackNetworkingUtil.structurePortName;
import static org.onosproject.openstacknetworking.util.OpenstackNetworkingUtil.swapStaleLocation;
import static org.onosproject.openstacknetworking.util.OpenstackNetworkingUtil.tunnelPortNumByNetId;
import static org.onosproject.openstacknetworking.util.RulePopulatorUtil.buildExtension;
-import static org.onosproject.openstacknode.api.Constants.INTEGRATION_TO_PHYSICAL_PREFIX;
import static org.onosproject.openstacknode.api.OpenstackNode.NodeType.COMPUTE;
import static org.slf4j.LoggerFactory.getLogger;
@@ -168,7 +160,7 @@
.build();
TrafficTreatment treatment = DefaultTrafficTreatment.builder()
- .transition(STAT_FLAT_OUTBOUND_TABLE)
+ .transition(PRE_FLAT_TABLE)
.build();
osFlowRuleService.setRule(
@@ -176,77 +168,11 @@
port.deviceId(),
selector,
treatment,
- PRIORITY_FLAT_JUMP_UPSTREAM_RULE,
- DHCP_TABLE,
+ PRIORITY_SWITCHING_RULE,
+ VTAG_TABLE,
install);
}
- private void setDownstreamRuleForFlat(InstancePort instPort,
- short ethType, boolean install) {
- TrafficSelector.Builder sBuilder = DefaultTrafficSelector.builder();
-
- if (ethType == Ethernet.TYPE_IPV4) {
- sBuilder.matchEthType(Ethernet.TYPE_IPV4)
- .matchIPDst(instPort.ipAddress().toIpPrefix());
- } else if (ethType == Ethernet.TYPE_ARP) {
- sBuilder.matchEthType(Ethernet.TYPE_ARP)
- .matchArpTpa(instPort.ipAddress().getIp4Address());
- }
-
- TrafficTreatment treatment = DefaultTrafficTreatment.builder()
- .setOutput(instPort.portNumber())
- .build();
-
- osFlowRuleService.setRule(
- appId,
- instPort.deviceId(),
- sBuilder.build(),
- treatment,
- PRIORITY_FLAT_DOWNSTREAM_RULE,
- FLAT_TABLE,
- install);
- }
-
- private void setDownstreamRulesForFlat(InstancePort instPort, boolean install) {
- setDownstreamRuleForFlat(instPort, Ethernet.TYPE_IPV4, install);
- setDownstreamRuleForFlat(instPort, Ethernet.TYPE_ARP, install);
- }
-
- private void setUpstreamRulesForFlat(InstancePort instPort, boolean install) {
- TrafficSelector selector = DefaultTrafficSelector.builder()
- .matchInPort(instPort.portNumber())
- .build();
-
- Network network = osNetworkService.network(instPort.networkId());
-
- if (network == null) {
- log.warn("The network does not exist");
- return;
- }
-
- deviceService.getPorts(instPort.deviceId()).stream()
- .filter(port -> {
- String annotPortName = port.annotations().value(PORT_NAME);
- String portName = structurePortName(INTEGRATION_TO_PHYSICAL_PREFIX
- + network.getProviderPhyNet());
- return Objects.equals(annotPortName, portName);
- })
- .findAny().ifPresent(port -> {
- TrafficTreatment treatment = DefaultTrafficTreatment.builder()
- .setOutput(port.number())
- .build();
-
- osFlowRuleService.setRule(
- appId,
- instPort.deviceId(),
- selector,
- treatment,
- PRIORITY_FLAT_UPSTREAM_RULE,
- FLAT_TABLE,
- install);
- });
- }
-
/**
* Configures the flow rules which are used for L2 packet switching.
* Note that these rules will be inserted in switching table (table 5).
@@ -467,9 +393,6 @@
case VLAN:
setNetworkBlockRulesForVlan(network.getProviderSegID(), install);
break;
- case FLAT:
- // TODO: need to find a way to block flat typed network
- break;
default:
break;
}
@@ -742,8 +665,6 @@
private void setNetworkRulesForFlat(InstancePort instPort, boolean install) {
setJumpRulesForFlat(instPort, install);
- setDownstreamRulesForFlat(instPort, install);
- setUpstreamRulesForFlat(instPort, install);
}
/**
@@ -790,8 +711,6 @@
private void removeVportRulesForFlat(InstancePort instPort) {
setJumpRulesForFlat(instPort, false);
- setUpstreamRulesForFlat(instPort, false);
- setDownstreamRulesForFlat(instPort, false);
}
private void instPortDetected(InstancePort instPort) {
diff --git a/apps/openstacknetworking/app/src/main/java/org/onosproject/openstacknetworking/impl/OpenstackSwitchingPhysicalHandler.java b/apps/openstacknetworking/app/src/main/java/org/onosproject/openstacknetworking/impl/OpenstackSwitchingPhysicalHandler.java
index 6a9686b..62e73d7 100644
--- a/apps/openstacknetworking/app/src/main/java/org/onosproject/openstacknetworking/impl/OpenstackSwitchingPhysicalHandler.java
+++ b/apps/openstacknetworking/app/src/main/java/org/onosproject/openstacknetworking/impl/OpenstackSwitchingPhysicalHandler.java
@@ -15,7 +15,6 @@
*/
package org.onosproject.openstacknetworking.impl;
-import org.onlab.packet.Ethernet;
import org.onosproject.cluster.ClusterService;
import org.onosproject.cluster.LeadershipService;
import org.onosproject.core.ApplicationId;
@@ -49,102 +48,78 @@
import static java.util.concurrent.Executors.newSingleThreadExecutor;
import static org.onlab.util.Tools.groupedThreads;
import static org.onosproject.net.AnnotationKeys.PORT_NAME;
-import static org.onosproject.openstacknetworking.api.Constants.DHCP_TABLE;
import static org.onosproject.openstacknetworking.api.Constants.OPENSTACK_NETWORKING_APP_ID;
-import static org.onosproject.openstacknetworking.api.Constants.PRIORITY_FLAT_JUMP_UPSTREAM_RULE;
-import static org.onosproject.openstacknetworking.api.Constants.STAT_FLAT_OUTBOUND_TABLE;
+import static org.onosproject.openstacknetworking.api.Constants.PRE_FLAT_TABLE;
+import static org.onosproject.openstacknetworking.api.Constants.PRIORITY_SWITCHING_RULE;
+import static org.onosproject.openstacknetworking.api.Constants.VTAG_TABLE;
import static org.onosproject.openstacknetworking.util.OpenstackNetworkingUtil.structurePortName;
import static org.onosproject.openstacknode.api.Constants.INTEGRATION_TO_PHYSICAL_PREFIX;
import static org.slf4j.LoggerFactory.getLogger;
-
/**
* Populates switching flow rules on OVS for the physical interfaces.
*/
@Component(immediate = true)
public class OpenstackSwitchingPhysicalHandler {
-
private final Logger log = getLogger(getClass());
-
@Reference(cardinality = ReferenceCardinality.MANDATORY)
protected CoreService coreService;
-
@Reference(cardinality = ReferenceCardinality.MANDATORY)
protected MastershipService mastershipService;
-
@Reference(cardinality = ReferenceCardinality.MANDATORY)
protected DeviceService deviceService;
-
@Reference(cardinality = ReferenceCardinality.MANDATORY)
protected DriverService driverService;
-
@Reference(cardinality = ReferenceCardinality.MANDATORY)
protected ClusterService clusterService;
-
@Reference(cardinality = ReferenceCardinality.MANDATORY)
protected LeadershipService leadershipService;
-
@Reference(cardinality = ReferenceCardinality.MANDATORY)
protected OpenstackFlowRuleService osFlowRuleService;
-
@Reference(cardinality = ReferenceCardinality.MANDATORY)
protected OpenstackNodeService osNodeService;
-
private final ExecutorService eventExecutor = newSingleThreadExecutor(
groupedThreads(this.getClass().getSimpleName(), "event-handler"));
private final InternalDeviceListener internalDeviceListener = new InternalDeviceListener();
-
private ApplicationId appId;
-
@Activate
protected void activate() {
appId = coreService.registerApplication(OPENSTACK_NETWORKING_APP_ID);
deviceService.addListener(internalDeviceListener);
-
log.info("Started");
}
-
@Deactivate
protected void deactivate() {
eventExecutor.shutdown();
deviceService.removeListener(internalDeviceListener);
-
log.info("Stopped");
}
-
/**
* An internal device listener which listens the port events generated from
* OVS integration bridge.
*/
private class InternalDeviceListener implements DeviceListener {
-
@Override
public boolean isRelevant(DeviceEvent event) {
Port port = event.port();
if (port == null) {
return false;
}
-
OpenstackNode osNode = osNodeService.node(event.subject().id());
if (osNode == null) {
return false;
}
-
Set<String> intPatchPorts = osNode.phyIntfs().stream()
.map(pi -> structurePortName(INTEGRATION_TO_PHYSICAL_PREFIX
+ pi.network())).collect(Collectors.toSet());
String portName = port.annotations().value(PORT_NAME);
-
return intPatchPorts.contains(portName);
}
-
private boolean isRelevantHelper(DeviceEvent event) {
return mastershipService.isLocalMaster(event.subject().id());
}
-
@Override
public void event(DeviceEvent event) {
log.info("Device event occurred with type {}", event.type());
-
switch (event.type()) {
case PORT_ADDED:
case PORT_UPDATED:
@@ -157,52 +132,37 @@
break;
}
}
-
private void processPortAddition(DeviceEvent event) {
if (!isRelevantHelper(event)) {
return;
}
-
- setFlatJumpRulesForPatchPort(event.subject().id(),
+ setFlatJumpRuleForPatchPort(event.subject().id(),
event.port().number(), true);
}
-
private void processPortRemoval(DeviceEvent event) {
if (!isRelevantHelper(event)) {
return;
}
-
- setFlatJumpRulesForPatchPort(event.subject().id(),
+ setFlatJumpRuleForPatchPort(event.subject().id(),
event.port().number(), false);
}
-
- private void setFlatJumpRulesForPatchPort(DeviceId deviceId,
- PortNumber portNumber,
- boolean install) {
- setFlatJumpRuleForPatchPort(deviceId, portNumber,
- Ethernet.TYPE_IPV4, install);
- setFlatJumpRuleForPatchPort(deviceId, portNumber,
- Ethernet.TYPE_ARP, install);
- }
-
private void setFlatJumpRuleForPatchPort(DeviceId deviceId,
PortNumber portNumber,
- short ethType, boolean install) {
- TrafficSelector.Builder selector = DefaultTrafficSelector.builder();
- selector.matchInPort(portNumber)
- .matchEthType(ethType);
+ boolean install) {
+ TrafficSelector.Builder selector = DefaultTrafficSelector.builder()
+ .matchInPort(portNumber);
- TrafficTreatment.Builder treatment = DefaultTrafficTreatment.builder();
- treatment.transition(STAT_FLAT_OUTBOUND_TABLE);
+ TrafficTreatment.Builder treatment = DefaultTrafficTreatment.builder()
+ .transition(PRE_FLAT_TABLE);
osFlowRuleService.setRule(
appId,
deviceId,
selector.build(),
treatment.build(),
- PRIORITY_FLAT_JUMP_UPSTREAM_RULE,
- DHCP_TABLE,
+ PRIORITY_SWITCHING_RULE,
+ VTAG_TABLE,
install);
}
}
-}
\ No newline at end of file
+}
diff --git a/apps/openstacknetworking/app/src/test/java/org/onosproject/openstacknetworking/impl/OpenstackFlowRuleManagerTest.java b/apps/openstacknetworking/app/src/test/java/org/onosproject/openstacknetworking/impl/OpenstackFlowRuleManagerTest.java
index bd982f2..8e9be87 100644
--- a/apps/openstacknetworking/app/src/test/java/org/onosproject/openstacknetworking/impl/OpenstackFlowRuleManagerTest.java
+++ b/apps/openstacknetworking/app/src/test/java/org/onosproject/openstacknetworking/impl/OpenstackFlowRuleManagerTest.java
@@ -55,11 +55,10 @@
import static org.onosproject.openstacknetworking.api.Constants.FLAT_TABLE;
import static org.onosproject.openstacknetworking.api.Constants.FORWARDING_TABLE;
import static org.onosproject.openstacknetworking.api.Constants.JUMP_TABLE;
-import static org.onosproject.openstacknetworking.api.Constants.STAT_FLAT_OUTBOUND_TABLE;
+import static org.onosproject.openstacknetworking.api.Constants.PRE_FLAT_TABLE;
import static org.onosproject.openstacknetworking.api.Constants.STAT_INBOUND_TABLE;
import static org.onosproject.openstacknetworking.api.Constants.STAT_OUTBOUND_TABLE;
import static org.onosproject.openstacknetworking.api.Constants.VTAG_TABLE;
-import static org.onosproject.openstacknetworking.api.Constants.VTAP_FLAT_OUTBOUND_TABLE;
import static org.onosproject.openstacknetworking.api.Constants.VTAP_INBOUND_TABLE;
import static org.onosproject.openstacknetworking.api.Constants.VTAP_OUTBOUND_TABLE;
@@ -193,7 +192,7 @@
fros = Sets.newConcurrentHashSet();
target.initializePipeline(DEVICE_ID);
- assertEquals("Flow Rule size was not match", 13, fros.size());
+ assertEquals("Flow Rule size was not match", 12, fros.size());
Map<Integer, Integer> fromToTableMap = Maps.newConcurrentMap();
fromToTableMap.put(STAT_INBOUND_TABLE, VTAP_INBOUND_TABLE);
@@ -204,8 +203,7 @@
fromToTableMap.put(ACL_EGRESS_TABLE, JUMP_TABLE);
fromToTableMap.put(STAT_OUTBOUND_TABLE, VTAP_OUTBOUND_TABLE);
fromToTableMap.put(VTAP_OUTBOUND_TABLE, FORWARDING_TABLE);
- fromToTableMap.put(STAT_FLAT_OUTBOUND_TABLE, VTAP_FLAT_OUTBOUND_TABLE);
- fromToTableMap.put(VTAP_FLAT_OUTBOUND_TABLE, FLAT_TABLE);
+ fromToTableMap.put(PRE_FLAT_TABLE, FLAT_TABLE);
fros.stream().map(FlowRuleOperation::rule).forEach(fr -> {
if (fr.tableId() != JUMP_TABLE && fr.tableId() != FLAT_TABLE) {