BgpRouter app supports both OVSSwitch and Corsa HW switch.
Change-Id: Ic0174338af3dbb76e1195b0f94d53a13a60cc0e7
diff --git a/apps/bgprouter/src/main/java/org/onosproject/bgprouter/BgpRouter.java b/apps/bgprouter/src/main/java/org/onosproject/bgprouter/BgpRouter.java
index 1035cd6..3266ac1 100644
--- a/apps/bgprouter/src/main/java/org/onosproject/bgprouter/BgpRouter.java
+++ b/apps/bgprouter/src/main/java/org/onosproject/bgprouter/BgpRouter.java
@@ -453,7 +453,7 @@
FlowRuleOperations.Builder ops = FlowRuleOperations.builder();
FlowRule rule;
- selector.matchEthType(Ethernet.TYPE_VLAN);
+ selector.matchVlanId(VlanId.ANY);
treatment.transition(FlowRule.Type.VLAN);
rule = new DefaultFlowRule(deviceId, selector.build(),
diff --git a/openflow/drivers/src/main/java/org/onosproject/openflow/drivers/DriverManager.java b/openflow/drivers/src/main/java/org/onosproject/openflow/drivers/DriverManager.java
index 17f79f3..bfd60d9 100644
--- a/openflow/drivers/src/main/java/org/onosproject/openflow/drivers/DriverManager.java
+++ b/openflow/drivers/src/main/java/org/onosproject/openflow/drivers/DriverManager.java
@@ -60,7 +60,11 @@
String hw = desc.getHwDesc();
if (dpid.equals(corsaDpid)) {
- return new OFCorsaSwitchDriver(dpid, desc);
+ if (hw.startsWith("Open vSwitch")) {
+ return new OFOVSSwitchCorsaTTP(dpid, desc);
+ } else {
+ return new OFCorsaSwitchDriver(dpid, desc);
+ }
}
if (vendor.startsWith("Stanford University, Ericsson Research and CPqD Research")
diff --git a/openflow/drivers/src/main/java/org/onosproject/openflow/drivers/OFCorsaSwitchDriver.java b/openflow/drivers/src/main/java/org/onosproject/openflow/drivers/OFCorsaSwitchDriver.java
index 6b32bcd..5cbdc0f 100644
--- a/openflow/drivers/src/main/java/org/onosproject/openflow/drivers/OFCorsaSwitchDriver.java
+++ b/openflow/drivers/src/main/java/org/onosproject/openflow/drivers/OFCorsaSwitchDriver.java
@@ -16,6 +16,7 @@
package org.onosproject.openflow.drivers;
import com.google.common.collect.Lists;
+import org.onlab.packet.Ethernet;
import org.onosproject.openflow.controller.Dpid;
import org.onosproject.openflow.controller.driver.AbstractOpenFlowSwitch;
import org.onosproject.openflow.controller.driver.SwitchDriverSubHandshakeAlreadyStarted;
@@ -24,11 +25,17 @@
import org.projectfloodlight.openflow.protocol.OFBarrierRequest;
import org.projectfloodlight.openflow.protocol.OFDescStatsReply;
import org.projectfloodlight.openflow.protocol.OFFlowMod;
+import org.projectfloodlight.openflow.protocol.OFMatchV3;
import org.projectfloodlight.openflow.protocol.OFMessage;
import org.projectfloodlight.openflow.protocol.OFType;
import org.projectfloodlight.openflow.protocol.instruction.OFInstruction;
import org.projectfloodlight.openflow.protocol.instruction.OFInstructionGotoTable;
+import org.projectfloodlight.openflow.protocol.match.Match;
+import org.projectfloodlight.openflow.protocol.match.MatchField;
+import org.projectfloodlight.openflow.protocol.oxm.OFOxm;
+import org.projectfloodlight.openflow.types.EthType;
import org.projectfloodlight.openflow.types.OFGroup;
+import org.projectfloodlight.openflow.types.OFVlanVidMatch;
import org.projectfloodlight.openflow.types.TableId;
import java.util.ArrayList;
@@ -41,14 +48,15 @@
*/
public class OFCorsaSwitchDriver extends AbstractOpenFlowSwitch {
- private static final int FIRST_TABLE = 0;
- private static final int VLAN_MPLS_TABLE = 1;
- private static final int VLAN_TABLE = 2;
- private static final int MPLS_TABLE = 3;
- private static final int ETHER_TABLE = 4;
- private static final int COS_MAP_TABLE = 5;
- private static final int FIB_TABLE = 6;
- private static final int LOCAL_TABLE = 9;
+ protected static final int FIRST_TABLE = 0;
+ protected static final int VLAN_MPLS_TABLE = 1;
+ protected static final int VLAN_TABLE = 2;
+ protected static final int MPLS_TABLE = 3;
+ protected static final int ETHER_TABLE = 4;
+ protected static final int COS_MAP_TABLE = 5;
+ protected static final int FIB_TABLE = 6;
+ protected static final int LOCAL_TABLE = 9;
+
private AtomicBoolean handShakeComplete = new AtomicBoolean(false);
@@ -192,6 +200,17 @@
log.warn("Unknown table type: {}", type);
}
builder.setInstructions(newInstructions);
+
+ OFMatchV3 match = (OFMatchV3) flowMod.getMatch();
+ for (OFOxm oxm: match.getOxmList()) {
+ if (oxm.getMatchField() == MatchField.VLAN_VID &&
+ oxm.getValue().equals(OFVlanVidMatch.PRESENT)) {
+ Match.Builder mBuilder = factory().buildMatchV3();
+ mBuilder.setExact(MatchField.ETH_TYPE, EthType.of(Ethernet.TYPE_VLAN));
+ builder.setMatch(mBuilder.build());
+ }
+ }
+
OFMessage msgnew = builder.build();
channel.write(Collections.singletonList(msgnew));
log.debug("Installed {}", msgnew);
diff --git a/openflow/drivers/src/main/java/org/onosproject/openflow/drivers/OFOVSSwitchCorsaTTP.java b/openflow/drivers/src/main/java/org/onosproject/openflow/drivers/OFOVSSwitchCorsaTTP.java
new file mode 100644
index 0000000..46fb87e
--- /dev/null
+++ b/openflow/drivers/src/main/java/org/onosproject/openflow/drivers/OFOVSSwitchCorsaTTP.java
@@ -0,0 +1,139 @@
+/*
+ * Copyright 2015 Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.onosproject.openflow.drivers;
+
+import com.google.common.collect.Lists;
+import org.onosproject.openflow.controller.Dpid;
+import org.projectfloodlight.openflow.protocol.OFDescStatsReply;
+import org.projectfloodlight.openflow.protocol.OFFlowMod;
+import org.projectfloodlight.openflow.protocol.OFMessage;
+import org.projectfloodlight.openflow.protocol.OFType;
+import org.projectfloodlight.openflow.protocol.instruction.OFInstruction;
+import org.projectfloodlight.openflow.protocol.instruction.OFInstructionGotoTable;
+import org.projectfloodlight.openflow.types.TableId;
+
+import java.util.Collections;
+import java.util.List;
+
+public class OFOVSSwitchCorsaTTP extends OFCorsaSwitchDriver {
+
+ OFOVSSwitchCorsaTTP(Dpid dpid, OFDescStatsReply desc) {
+ super(dpid, desc);
+ }
+
+ @Override
+ public void transformAndSendMsg(OFMessage msg, TableType type) {
+ log.trace("Trying to send {} of TableType {}", msg, type);
+ if (msg.getType() == OFType.FLOW_MOD) {
+ OFFlowMod flowMod = (OFFlowMod) msg;
+ OFFlowMod.Builder builder = flowMod.createBuilder();
+ List<OFInstruction> instructions = flowMod.getInstructions();
+ List<OFInstruction> newInstructions = Lists.newArrayList();
+ for (OFInstruction i : instructions) {
+ if (i instanceof OFInstructionGotoTable) {
+ OFInstructionGotoTable gotoTable = (OFInstructionGotoTable) i;
+ TableType tid = TableType.values()[gotoTable.getTableId().getValue()];
+ switch (tid) {
+ case VLAN_MPLS:
+ newInstructions.add(
+ gotoTable.createBuilder()
+ .setTableId(TableId.of(VLAN_MPLS_TABLE)).build());
+ break;
+ case VLAN:
+ newInstructions.add(
+ gotoTable.createBuilder()
+ .setTableId(TableId.of(VLAN_TABLE)).build());
+ break;
+ case ETHER:
+ newInstructions.add(
+ gotoTable.createBuilder()
+ .setTableId(TableId.of(ETHER_TABLE)).build());
+ break;
+ case COS:
+ newInstructions.add(
+ gotoTable.createBuilder()
+ .setTableId(TableId.of(COS_MAP_TABLE)).build());
+ break;
+ case IP:
+ newInstructions.add(
+ gotoTable.createBuilder()
+ .setTableId(TableId.of(FIB_TABLE)).build());
+ break;
+ case MPLS:
+ newInstructions.add(
+ gotoTable.createBuilder()
+ .setTableId(TableId.of(MPLS_TABLE)).build());
+ break;
+ case ACL:
+ newInstructions.add(
+ gotoTable.createBuilder()
+ .setTableId(TableId.of(LOCAL_TABLE)).build());
+ break;
+ case NONE:
+ log.error("Should never have to go to Table 0");
+ /*newInstructions.add(
+ gotoTable.createBuilder()
+ .setTableId(TableId.of(0)).build());
+ */
+ break;
+ default:
+ log.warn("Unknown table type: {}", tid);
+ }
+ } else {
+ newInstructions.add(i);
+ }
+ }
+ switch (type) {
+ case VLAN_MPLS:
+ builder.setTableId(TableId.of(VLAN_MPLS_TABLE));
+ break;
+ case VLAN:
+ builder.setTableId(TableId.of(VLAN_TABLE));
+ break;
+ case ETHER:
+ builder.setTableId(TableId.of(ETHER_TABLE));
+ break;
+ case COS:
+ builder.setTableId(TableId.of(COS_MAP_TABLE));
+ break;
+ case IP:
+ builder.setTableId(TableId.of(FIB_TABLE));
+ break;
+ case MPLS:
+ builder.setTableId(TableId.of(MPLS_TABLE));
+ break;
+ case ACL:
+ builder.setTableId(TableId.of(LOCAL_TABLE));
+ break;
+ case FIRST:
+ builder.setTableId(TableId.of(FIRST_TABLE));
+ break;
+ case NONE:
+ builder.setTableId(TableId.of(LOCAL_TABLE));
+ break;
+ default:
+ log.warn("Unknown table type: {}", type);
+ }
+ builder.setInstructions(newInstructions);
+ OFMessage msgnew = builder.build();
+ channel.write(Collections.singletonList(msgnew));
+ log.debug("Installed {}", msgnew);
+
+ } else {
+ channel.write(Collections.singletonList(msg));
+ }
+ }
+}
diff --git a/providers/openflow/flow/src/main/java/org/onosproject/provider/of/flow/impl/FlowEntryBuilder.java b/providers/openflow/flow/src/main/java/org/onosproject/provider/of/flow/impl/FlowEntryBuilder.java
index 17bfc11..0e7e31a 100644
--- a/providers/openflow/flow/src/main/java/org/onosproject/provider/of/flow/impl/FlowEntryBuilder.java
+++ b/providers/openflow/flow/src/main/java/org/onosproject/provider/of/flow/impl/FlowEntryBuilder.java
@@ -61,6 +61,7 @@
import org.projectfloodlight.openflow.protocol.oxm.OFOxm;
import org.projectfloodlight.openflow.protocol.oxm.OFOxmOchSigidBasic;
import org.projectfloodlight.openflow.protocol.ver13.OFFactoryVer13;
+import org.projectfloodlight.openflow.types.EthType;
import org.projectfloodlight.openflow.types.IPv4Address;
import org.projectfloodlight.openflow.types.IPv6Address;
import org.projectfloodlight.openflow.types.Masked;
@@ -466,7 +467,11 @@
break;
case ETH_TYPE:
int ethType = match.get(MatchField.ETH_TYPE).getValue();
- builder.matchEthType((short) ethType);
+ if (ethType == EthType.VLAN_FRAME.getValue()) {
+ builder.matchVlanId(VlanId.ANY);
+ } else {
+ builder.matchEthType((short) ethType);
+ }
break;
case VLAN_VID:
VlanId vlanId = null;