Charles Chan
Committed by Yuta HIGUCHI

CORD-389 Fix for Accton 6712 deployment

Related to this topic:
- Disable the meter collector since right now it is not supported
- Implement extension VLAN ID selector/treatment for OFDPA
    Since it requires two special flow entries to match untagged packets
        0x1ffe/no mask (filtering rule, need to go first)
        0x0000/0x1fff setvid 0x0ffe (assignment rule, need to go second)
- Not able to point /32 IP address to ECMP group. Use /31 instead.

In addition:
- Implement serializer for ExtensionCriterion

Change-Id: I621b3ad14014d7e6945c014cdae4f7cd2939288e
Showing 19 changed files with 680 additions and 58 deletions
......@@ -230,6 +230,13 @@ public class RoutingRulePopulator {
public boolean populateIpRuleForRouter(DeviceId deviceId,
IpPrefix ipPrefix, DeviceId destSw,
Set<DeviceId> nextHops) {
// TODO: OFDPA does not support /32 with ECMP group at this moment.
// Use /31 instead
IpPrefix effectivePrefix =
(ipPrefix.prefixLength() == IpPrefix.MAX_INET_MASK_LENGTH) ?
IpPrefix.valueOf(ipPrefix.getIp4Prefix().address(), 31) :
ipPrefix;
int segmentId;
try {
segmentId = config.getSegmentId(destSw);
......@@ -239,7 +246,7 @@ public class RoutingRulePopulator {
}
TrafficSelector.Builder sbuilder = DefaultTrafficSelector.builder();
sbuilder.matchIPDst(ipPrefix);
sbuilder.matchIPDst(effectivePrefix);
sbuilder.matchEthType(Ethernet.TYPE_IPV4);
TrafficSelector selector = sbuilder.build();
......@@ -277,7 +284,7 @@ public class RoutingRulePopulator {
.makePermanent()
.nextStep(nextId)
.withSelector(selector)
.withPriority(2000 * ipPrefix.prefixLength())
.withPriority(2000 * effectivePrefix.prefixLength())
.withFlag(ForwardingObjective.Flag.SPECIFIC);
if (treatment != null) {
fwdBuilder.withTreatment(treatment);
......
......@@ -615,9 +615,9 @@ public final class Criteria {
*
* @param extensionSelector extension selector
* @param deviceId device ID
* @return match criterion
* @return match extension criterion
*/
public static Criterion extension(ExtensionSelector extensionSelector,
public static ExtensionCriterion extension(ExtensionSelector extensionSelector,
DeviceId deviceId) {
return new ExtensionCriterion(extensionSelector, deviceId);
}
......
......@@ -37,8 +37,8 @@ public class ExtensionSelectorType {
NICIRA_MATCH_NSH_CH1(2),
NICIRA_MATCH_NSH_CH2(3),
NICIRA_MATCH_NSH_CH3(4),
NICIRA_MATCH_NSH_CH4(5);
NICIRA_MATCH_NSH_CH4(5),
OFDPA_MATCH_VLAN_VID(16);
private ExtensionSelectorType type;
......
......@@ -34,6 +34,10 @@ public final class ExtensionTreatmentType {
public enum ExtensionTreatmentTypes {
NICIRA_SET_TUNNEL_DST(0),
NICIRA_RESUBMIT(1),
NICIRA_MOV_ARP_SHA_TO_THA(2),
NICIRA_MOV_ARP_SPA_TO_TPA(3),
NICIRA_MOV_ETH_SRC_TO_DST(4),
NICIRA_MOV_IP_SRC_TO_DST(5),
NICIRA_RESUBMIT_TABLE(14),
NICIRA_SET_NSH_SPI(32),
NICIRA_SET_NSH_SI(33),
......@@ -41,10 +45,7 @@ public final class ExtensionTreatmentType {
NICIRA_SET_NSH_CH2(35),
NICIRA_SET_NSH_CH3(36),
NICIRA_SET_NSH_CH4(37),
NICIRA_MOV_ARP_SHA_TO_THA(2),
NICIRA_MOV_ARP_SPA_TO_TPA(3),
NICIRA_MOV_ETH_SRC_TO_DST(4),
NICIRA_MOV_IP_SRC_TO_DST(5);
OFDPA_SET_VLAN_ID(64);
private ExtensionTreatmentType type;
......
/*
* Copyright 2015-2016 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.store.serializers;
import com.esotericsoftware.kryo.Kryo;
import com.esotericsoftware.kryo.Serializer;
import com.esotericsoftware.kryo.io.Input;
import com.esotericsoftware.kryo.io.Output;
import org.onlab.osgi.DefaultServiceDirectory;
import org.onosproject.net.DeviceId;
import org.onosproject.net.behaviour.ExtensionSelectorResolver;
import org.onosproject.net.driver.DefaultDriverData;
import org.onosproject.net.driver.DefaultDriverHandler;
import org.onosproject.net.driver.DriverHandler;
import org.onosproject.net.driver.DriverService;
import org.onosproject.net.flow.criteria.Criteria;
import org.onosproject.net.flow.criteria.ExtensionCriterion;
import org.onosproject.net.flow.criteria.ExtensionSelector;
import org.onosproject.net.flow.criteria.ExtensionSelectorType;
/**
* Serializer for extension criteria.
*/
public class ExtensionCriterionSerializer extends Serializer<ExtensionCriterion> {
/**
* Constructs a extension criterion serializer.
*/
public ExtensionCriterionSerializer() {
super(false, true);
}
@Override
public void write(Kryo kryo, Output output, ExtensionCriterion object) {
kryo.writeClassAndObject(output, object.extensionSelector().type());
kryo.writeClassAndObject(output, object.deviceId());
kryo.writeClassAndObject(output, object.extensionSelector().serialize());
}
@Override
public ExtensionCriterion read(Kryo kryo, Input input,
Class<ExtensionCriterion> type) {
ExtensionSelectorType exType = (ExtensionSelectorType) kryo.readClassAndObject(input);
DeviceId deviceId = (DeviceId) kryo.readClassAndObject(input);
DriverService driverService = DefaultServiceDirectory.getService(DriverService.class);
DriverHandler handler = new DefaultDriverHandler(
new DefaultDriverData(driverService.getDriver(deviceId), deviceId));
ExtensionSelectorResolver resolver = handler.behaviour(ExtensionSelectorResolver.class);
ExtensionSelector selector = resolver.getExtensionSelector(exType);
byte[] bytes = (byte[]) kryo.readClassAndObject(input);
selector.deserialize(bytes);
return Criteria.extension(selector, deviceId);
}
}
/*
* Copyright 2015 Open Networking Laboratory
* Copyright 2015-2016 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.
......@@ -32,11 +32,14 @@ import org.onosproject.net.flow.instructions.ExtensionTreatmentType;
import org.onosproject.net.flow.instructions.Instructions;
/**
* Created by jono on 10/29/15.
* Serializer for extension instructions.
*/
public class ExtensionInstructionSerializer extends
Serializer<Instructions.ExtensionInstructionWrapper> {
/**
* Constructs a extension instruction serializer.
*/
public ExtensionInstructionSerializer() {
super(false, true);
}
......@@ -45,9 +48,7 @@ public class ExtensionInstructionSerializer extends
public void write(Kryo kryo, Output output, Instructions.ExtensionInstructionWrapper object) {
kryo.writeClassAndObject(output, object.extensionInstruction().type());
kryo.writeClassAndObject(output, object.deviceId());
kryo.writeClassAndObject(output, object.extensionInstruction().serialize());
}
@Override
......@@ -61,7 +62,6 @@ public class ExtensionInstructionSerializer extends
new DefaultDriverData(driverService.getDriver(deviceId), deviceId));
ExtensionTreatmentResolver resolver = handler.behaviour(ExtensionTreatmentResolver.class);
ExtensionTreatment instruction = resolver.getExtensionInstruction(exType);
byte[] bytes = (byte[]) kryo.readClassAndObject(input);
......
......@@ -108,6 +108,8 @@ import org.onosproject.net.flow.criteria.ArpPaCriterion;
import org.onosproject.net.flow.criteria.Criterion;
import org.onosproject.net.flow.criteria.EthCriterion;
import org.onosproject.net.flow.criteria.EthTypeCriterion;
import org.onosproject.net.flow.criteria.ExtensionCriterion;
import org.onosproject.net.flow.criteria.ExtensionSelectorType;
import org.onosproject.net.flow.criteria.IPCriterion;
import org.onosproject.net.flow.criteria.IPDscpCriterion;
import org.onosproject.net.flow.criteria.IPEcnCriterion;
......@@ -482,6 +484,8 @@ public final class KryoNamespaces {
.register(new DefaultOutboundPacketSerializer(), DefaultOutboundPacket.class)
.register(new AnnotationsSerializer(), DefaultAnnotations.class)
.register(new ExtensionInstructionSerializer(), Instructions.ExtensionInstructionWrapper.class)
.register(new ExtensionCriterionSerializer(), ExtensionCriterion.class)
.register(ExtensionSelectorType.class)
.register(ExtensionTreatmentType.class)
.register(Versioned.class)
.register(MapEvent.class)
......
/*
* Copyright 2016 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.driver.extensions;
import org.onlab.packet.VlanId;
import org.onosproject.net.behaviour.ExtensionSelectorResolver;
import org.onosproject.net.driver.AbstractHandlerBehaviour;
import org.onosproject.net.flow.criteria.ExtensionSelector;
import org.onosproject.net.flow.criteria.ExtensionSelectorType;
import org.onosproject.net.flow.criteria.ExtensionSelectorType.ExtensionSelectorTypes;
import org.onosproject.openflow.controller.ExtensionSelectorInterpreter;
import org.projectfloodlight.openflow.protocol.OFFactory;
import org.projectfloodlight.openflow.protocol.match.MatchField;
import org.projectfloodlight.openflow.protocol.oxm.OFOxm;
import org.projectfloodlight.openflow.protocol.oxm.OFOxmVlanVid;
import org.projectfloodlight.openflow.protocol.oxm.OFOxmVlanVidMasked;
import org.projectfloodlight.openflow.types.OFVlanVidMatch;
import org.projectfloodlight.openflow.types.VlanVid;
/**
* Interpreter for OFDPA OpenFlow selector extensions.
*/
public class OfdpaExtensionSelectorInterpreter extends AbstractHandlerBehaviour
implements ExtensionSelectorInterpreter, ExtensionSelectorResolver {
@Override
public boolean supported(ExtensionSelectorType extensionSelectorType) {
if (extensionSelectorType.equals(ExtensionSelectorTypes.OFDPA_MATCH_VLAN_VID.type())) {
return true;
}
return false;
}
@Override
public OFOxm<?> mapSelector(OFFactory factory, ExtensionSelector extensionSelector) {
ExtensionSelectorType type = extensionSelector.type();
if (type.equals(ExtensionSelectorType.ExtensionSelectorTypes.OFDPA_MATCH_VLAN_VID.type())) {
VlanId vlanId = ((OfdpaMatchVlanVid) extensionSelector).vlanId();
// Special VLAN 0x0000/0x1FFF required by OFDPA
if (vlanId.toShort() == 0x0000) {
OFVlanVidMatch vid = OFVlanVidMatch.ofRawVid(vlanId.toShort());
OFVlanVidMatch mask = OFVlanVidMatch.ofRawVid((short) 0x1FFF);
return factory.oxms().vlanVidMasked(vid, mask);
// Normal case
} else if (vlanId.equals(VlanId.ANY)) {
return factory.oxms().vlanVidMasked(OFVlanVidMatch.PRESENT, OFVlanVidMatch.PRESENT);
} else if (vlanId.equals(VlanId.NONE)) {
return factory.oxms().vlanVid(OFVlanVidMatch.NONE);
} else {
return factory.oxms().vlanVid(OFVlanVidMatch.ofVlanVid(VlanVid.ofVlan(vlanId.toShort())));
}
}
throw new UnsupportedOperationException(
"Unexpected ExtensionSelector: " + extensionSelector.toString());
}
@Override
public ExtensionSelector mapOxm(OFOxm<?> oxm) {
VlanId vlanId;
if (oxm.getMatchField().equals(MatchField.VLAN_VID)) {
if (oxm.isMasked()) {
OFVlanVidMatch vid = ((OFOxmVlanVidMasked) oxm).getValue();
OFVlanVidMatch mask = ((OFOxmVlanVidMasked) oxm).getMask();
if (vid.equals(OFVlanVidMatch.ofRawVid((short) 0))) {
vlanId = VlanId.vlanId((short) 0);
} else if (vid.equals(OFVlanVidMatch.PRESENT) &&
mask.equals(OFVlanVidMatch.PRESENT)) {
vlanId = VlanId.ANY;
} else {
vlanId = VlanId.vlanId(vid.getVlan());
}
} else {
OFVlanVidMatch vid = ((OFOxmVlanVid) oxm).getValue();
if (!vid.isPresentBitSet()) {
vlanId = VlanId.NONE;
} else {
vlanId = VlanId.vlanId(vid.getVlan());
}
}
return new OfdpaMatchVlanVid(vlanId);
}
throw new UnsupportedOperationException(
"Unexpected OXM: " + oxm.toString());
}
@Override
public ExtensionSelector getExtensionSelector(ExtensionSelectorType type) {
if (type.equals(ExtensionSelectorType.ExtensionSelectorTypes.OFDPA_MATCH_VLAN_VID.type())) {
return new OfdpaMatchVlanVid();
}
throw new UnsupportedOperationException(
"Driver does not support extension type " + type.toString());
}
}
/*
* Copyright 2016 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.driver.extensions;
import org.onlab.packet.VlanId;
import org.onosproject.net.behaviour.ExtensionTreatmentResolver;
import org.onosproject.net.driver.AbstractHandlerBehaviour;
import org.onosproject.net.flow.instructions.ExtensionTreatment;
import org.onosproject.net.flow.instructions.ExtensionTreatmentType;
import org.onosproject.openflow.controller.ExtensionTreatmentInterpreter;
import org.projectfloodlight.openflow.protocol.OFActionType;
import org.projectfloodlight.openflow.protocol.OFFactory;
import org.projectfloodlight.openflow.protocol.action.OFAction;
import org.projectfloodlight.openflow.protocol.action.OFActionSetField;
import org.projectfloodlight.openflow.protocol.oxm.OFOxm;
import org.projectfloodlight.openflow.protocol.oxm.OFOxmVlanVid;
import org.projectfloodlight.openflow.types.OFVlanVidMatch;
/**
* Interpreter for OFDPA OpenFlow treatment extensions.
*/
public class OfdpaExtensionTreatmentInterpreter extends AbstractHandlerBehaviour
implements ExtensionTreatmentInterpreter, ExtensionTreatmentResolver {
@Override
public boolean supported(ExtensionTreatmentType extensionTreatmentType) {
if (extensionTreatmentType.equals(
ExtensionTreatmentType.ExtensionTreatmentTypes.OFDPA_SET_VLAN_ID.type())) {
return true;
}
return false;
}
@Override
public OFAction mapInstruction(OFFactory factory, ExtensionTreatment extensionTreatment) {
ExtensionTreatmentType type = extensionTreatment.type();
if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.OFDPA_SET_VLAN_ID.type())) {
VlanId vlanId = ((OfdpaSetVlanVid) extensionTreatment).vlanId();
// NOTE: OFDPA requires isPresent bit set to zero.
OFVlanVidMatch match = OFVlanVidMatch.ofRawVid(vlanId.toShort());
return factory.actions().setField(factory.oxms().vlanVid(match));
}
throw new UnsupportedOperationException(
"Unexpected ExtensionTreatment: " + extensionTreatment.toString());
}
@Override
public ExtensionTreatment mapAction(OFAction action) {
if (action.getType().equals(OFActionType.SET_FIELD)) {
OFActionSetField setFieldAction = (OFActionSetField) action;
OFOxm<?> oxm = setFieldAction.getField();
switch (oxm.getMatchField().id) {
case VLAN_VID:
OFOxmVlanVid vlanVid = (OFOxmVlanVid) oxm;
return new OfdpaSetVlanVid(VlanId.vlanId(vlanVid.getValue().getRawVid()));
default:
throw new UnsupportedOperationException(
"Driver does not support extension type " + oxm.getMatchField().id);
}
}
throw new UnsupportedOperationException(
"Unexpected OFAction: " + action.toString());
}
@Override
public ExtensionTreatment getExtensionInstruction(ExtensionTreatmentType type) {
if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.OFDPA_SET_VLAN_ID.type())) {
return new OfdpaSetVlanVid();
}
throw new UnsupportedOperationException(
"Driver does not support extension type " + type.toString());
}
}
/*
* Copyright 2016 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.driver.extensions;
import com.google.common.base.MoreObjects;
import org.onlab.packet.VlanId;
import org.onlab.util.KryoNamespace;
import org.onosproject.net.flow.AbstractExtension;
import org.onosproject.net.flow.criteria.ExtensionSelector;
import org.onosproject.net.flow.criteria.ExtensionSelectorType;
import java.util.Objects;
import static com.google.common.base.Preconditions.checkNotNull;
/**
* OFDPA VLAN ID extension match.
*/
public class OfdpaMatchVlanVid extends AbstractExtension implements ExtensionSelector {
private VlanId vlanId;
private static final KryoNamespace APPKRYO = new KryoNamespace.Builder()
.register(VlanId.class)
.build();
/**
* OFDPA VLAN ID extension match.
*/
protected OfdpaMatchVlanVid() {
vlanId = null;
}
/**
* Constructs a new VLAN ID match with given VLAN ID.
*
* @param vlanId VLAN ID
*/
public OfdpaMatchVlanVid(VlanId vlanId) {
checkNotNull(vlanId);
this.vlanId = vlanId;
}
/**
* Gets the VLAN ID.
*
* @return VLAN ID
*/
public VlanId vlanId() {
return vlanId;
}
@Override
public ExtensionSelectorType type() {
return ExtensionSelectorType.ExtensionSelectorTypes.OFDPA_MATCH_VLAN_VID.type();
}
@Override
public void deserialize(byte[] data) {
vlanId = APPKRYO.deserialize(data);
}
@Override
public byte[] serialize() {
return APPKRYO.serialize(vlanId);
}
@Override
public int hashCode() {
return Objects.hash(vlanId);
}
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj instanceof OfdpaMatchVlanVid) {
OfdpaMatchVlanVid that = (OfdpaMatchVlanVid) obj;
return Objects.equals(vlanId, that.vlanId);
}
return false;
}
@Override
public String toString() {
return MoreObjects.toStringHelper(getClass())
.add("vlanId", vlanId)
.toString();
}
}
/*
* Copyright 2016 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.driver.extensions;
import com.google.common.base.MoreObjects;
import org.onlab.packet.VlanId;
import org.onlab.util.KryoNamespace;
import org.onosproject.net.flow.AbstractExtension;
import org.onosproject.net.flow.instructions.ExtensionTreatment;
import org.onosproject.net.flow.instructions.ExtensionTreatmentType;
import java.util.Objects;
import static com.google.common.base.Preconditions.checkNotNull;
/**
* OFDPA set VLAN ID extension instruction.
*/
public class OfdpaSetVlanVid extends AbstractExtension implements ExtensionTreatment {
private VlanId vlanId;
private static final KryoNamespace APPKRYO = new KryoNamespace.Builder()
.register(VlanId.class)
.build();
/**
* Constructs a new set VLAN ID instruction.
*/
protected OfdpaSetVlanVid() {
vlanId = null;
}
/**
* Constructs a new set VLAN ID instruction with given VLAN ID.
*
* @param vlanId VLAN ID
*/
public OfdpaSetVlanVid(VlanId vlanId) {
checkNotNull(vlanId);
this.vlanId = vlanId;
}
/**
* Gets the VLAN ID.
*
* @return VLAN ID
*/
public VlanId vlanId() {
return vlanId;
}
@Override
public ExtensionTreatmentType type() {
return ExtensionTreatmentType.ExtensionTreatmentTypes.OFDPA_SET_VLAN_ID.type();
}
@Override
public void deserialize(byte[] data) {
vlanId = APPKRYO.deserialize(data);
}
@Override
public byte[] serialize() {
return APPKRYO.serialize(vlanId);
}
@Override
public int hashCode() {
return Objects.hash(vlanId);
}
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj instanceof OfdpaSetVlanVid) {
OfdpaSetVlanVid that = (OfdpaSetVlanVid) obj;
return Objects.equals(vlanId, that.vlanId);
}
return false;
}
@Override
public String toString() {
return MoreObjects.toStringHelper(getClass())
.add("vlanId", vlanId)
.toString();
}
}
......@@ -29,11 +29,14 @@ import java.util.concurrent.ConcurrentHashMap;
import org.onlab.osgi.ServiceDirectory;
import org.onlab.packet.Ethernet;
import org.onlab.packet.IpPrefix;
import org.onlab.packet.MacAddress;
import org.onlab.packet.VlanId;
import org.onlab.util.KryoNamespace;
import org.onosproject.core.ApplicationId;
import org.onosproject.core.CoreService;
import org.onosproject.driver.extensions.OfdpaMatchVlanVid;
import org.onosproject.driver.extensions.OfdpaSetVlanVid;
import org.onosproject.net.DeviceId;
import org.onosproject.net.Port;
import org.onosproject.net.PortNumber;
......@@ -55,6 +58,7 @@ import org.onosproject.net.flow.criteria.Criteria;
import org.onosproject.net.flow.criteria.Criterion;
import org.onosproject.net.flow.criteria.EthCriterion;
import org.onosproject.net.flow.criteria.EthTypeCriterion;
import org.onosproject.net.flow.criteria.ExtensionCriterion;
import org.onosproject.net.flow.criteria.IPCriterion;
import org.onosproject.net.flow.criteria.MplsBosCriterion;
import org.onosproject.net.flow.criteria.MplsCriterion;
......@@ -65,6 +69,8 @@ import org.onosproject.net.flow.instructions.Instructions.OutputInstruction;
import org.onosproject.net.flow.instructions.L2ModificationInstruction;
import org.onosproject.net.flow.instructions.L2ModificationInstruction.L2SubType;
import org.onosproject.net.flow.instructions.L2ModificationInstruction.ModVlanIdInstruction;
import org.onosproject.net.flow.instructions.L3ModificationInstruction;
import org.onosproject.net.flow.instructions.L3ModificationInstruction.L3SubType;
import org.onosproject.net.flowobjective.FilteringObjective;
import org.onosproject.net.flowobjective.FlowObjectiveStore;
import org.onosproject.net.flowobjective.ForwardingObjective;
......@@ -348,12 +354,39 @@ public class OFDPA2Pipeline extends AbstractHandlerBehaviour implements Pipeline
log.debug("filtering objective missing dstMac or VLAN, "
+ "cannot program VLAN Table");
} else {
for (FlowRule vlanRule : processVlanIdFilter(portCriterion, vidCriterion,
assignedVlan,
applicationId)) {
/*
* NOTE: Separate vlan filtering rules and assignment rules
* into different stage in order to guarantee that filtering rules
* always go first.
*/
List<FlowRule> allRules = processVlanIdFilter(
portCriterion, vidCriterion, assignedVlan, applicationId);
List<FlowRule> filteringRules = new ArrayList<>();
List<FlowRule> assignmentRules = new ArrayList<>();
allRules.forEach(flowRule -> {
ExtensionCriterion extCriterion =
(ExtensionCriterion) flowRule.selector().getCriterion(Criterion.Type.EXTENSION);
VlanId vlanId = ((OfdpaMatchVlanVid) extCriterion.extensionSelector()).vlanId();
if (vlanId.toShort() != (short) 0) {
filteringRules.add(flowRule);
} else {
assignmentRules.add(flowRule);
}
});
for (FlowRule filteringRule : filteringRules) {
log.debug("adding VLAN filtering rule in VLAN table: {} for dev: {}",
vlanRule, deviceId);
ops = install ? ops.add(vlanRule) : ops.remove(vlanRule);
filteringRule, deviceId);
ops = install ? ops.add(filteringRule) : ops.remove(filteringRule);
}
ops.newStage();
for (FlowRule assignmentRule : assignmentRules) {
log.debug("adding VLAN assignment rule in VLAN table: {} for dev: {}",
assignmentRule, deviceId);
ops = install ? ops.add(assignmentRule) : ops.remove(assignmentRule);
}
}
......@@ -415,27 +448,41 @@ public class OFDPA2Pipeline extends AbstractHandlerBehaviour implements Pipeline
VlanIdCriterion vidCriterion,
VlanId assignedVlan,
ApplicationId applicationId) {
List<FlowRule> rules = new ArrayList<FlowRule>();
List<FlowRule> rules = new ArrayList<>();
TrafficSelector.Builder selector = DefaultTrafficSelector.builder();
TrafficTreatment.Builder treatment = DefaultTrafficTreatment.builder();
selector.matchVlanId(vidCriterion.vlanId());
TrafficSelector.Builder preSelector = null;
TrafficTreatment.Builder preTreatment = null;
treatment.transition(TMAC_TABLE);
VlanId storeVlan = null;
if (vidCriterion.vlanId() == VlanId.NONE) {
// untagged packets are assigned vlans
treatment.pushVlan().setVlanId(assignedVlan);
OfdpaMatchVlanVid ofdpaMatchVlanVid = new OfdpaMatchVlanVid(VlanId.vlanId((short) 0));
selector.extension(ofdpaMatchVlanVid, deviceId);
OfdpaSetVlanVid ofdpaSetVlanVid = new OfdpaSetVlanVid(assignedVlan);
treatment.extension(ofdpaSetVlanVid, deviceId);
// XXX ofdpa will require an additional vlan match on the assigned vlan
// and it may not require the push. This is not in compliance with OF
// standard. Waiting on what the exact flows are going to look like.
storeVlan = assignedVlan;
preSelector = DefaultTrafficSelector.builder();
OfdpaMatchVlanVid preOfdpaMatchVlanVid = new OfdpaMatchVlanVid(assignedVlan);
preSelector.extension(preOfdpaMatchVlanVid, deviceId);
preTreatment = DefaultTrafficTreatment.builder().transition(TMAC_TABLE);
} else {
OfdpaMatchVlanVid ofdpaMatchVlanVid = new OfdpaMatchVlanVid(vidCriterion.vlanId());
selector.extension(ofdpaMatchVlanVid, deviceId);
storeVlan = vidCriterion.vlanId();
}
// ofdpa cannot match on ALL portnumber, so we need to use separate
// rules for each port.
List<PortNumber> portnums = new ArrayList<PortNumber>();
List<PortNumber> portnums = new ArrayList<>();
if (portCriterion.port() == PortNumber.ALL) {
for (Port port : deviceService.getPorts(deviceId)) {
if (port.number().toLong() > 0 && port.number().toLong() < OFPP_MAX) {
......@@ -468,6 +515,20 @@ public class OFDPA2Pipeline extends AbstractHandlerBehaviour implements Pipeline
.fromApp(applicationId)
.makePermanent()
.forTable(VLAN_TABLE).build();
if (preSelector != null) {
preSelector.matchInPort(pnum);
FlowRule preRule = DefaultFlowRule.builder()
.forDevice(deviceId)
.withSelector(preSelector.build())
.withTreatment(preTreatment.build())
.withPriority(DEFAULT_PRIORITY)
.fromApp(applicationId)
.makePermanent()
.forTable(VLAN_TABLE).build();
rules.add(preRule);
}
rules.add(rule);
}
return rules;
......@@ -509,11 +570,12 @@ public class OFDPA2Pipeline extends AbstractHandlerBehaviour implements Pipeline
List<FlowRule> rules = new ArrayList<FlowRule>();
for (PortNumber pnum : portnums) {
OfdpaMatchVlanVid ofdpaMatchVlanVid = new OfdpaMatchVlanVid(vidCriterion.vlanId());
// for unicast IP packets
TrafficSelector.Builder selector = DefaultTrafficSelector.builder();
TrafficTreatment.Builder treatment = DefaultTrafficTreatment.builder();
selector.matchInPort(pnum);
selector.matchVlanId(vidCriterion.vlanId());
selector.extension(ofdpaMatchVlanVid, deviceId);
selector.matchEthType(Ethernet.TYPE_IPV4);
selector.matchEthDst(ethCriterion.mac());
treatment.transition(UNICAST_ROUTING_TABLE);
......@@ -530,7 +592,7 @@ public class OFDPA2Pipeline extends AbstractHandlerBehaviour implements Pipeline
selector = DefaultTrafficSelector.builder();
treatment = DefaultTrafficTreatment.builder();
selector.matchInPort(pnum);
selector.matchVlanId(vidCriterion.vlanId());
selector.extension(ofdpaMatchVlanVid, deviceId);
selector.matchEthType(Ethernet.MPLS_UNICAST);
selector.matchEthDst(ethCriterion.mac());
treatment.transition(MPLS_TABLE_0);
......@@ -697,13 +759,27 @@ public class OFDPA2Pipeline extends AbstractHandlerBehaviour implements Pipeline
int forTableId;
TrafficSelector.Builder filteredSelector = DefaultTrafficSelector.builder();
TrafficTreatment.Builder tb = DefaultTrafficTreatment.builder();
boolean popMpls = false;
if (ethType.ethType().toShort() == Ethernet.TYPE_IPV4) {
IpPrefix ipPrefix = ((IPCriterion)
selector.getCriterion(Criterion.Type.IPV4_DST)).ip();
filteredSelector.matchEthType(Ethernet.TYPE_IPV4)
.matchIPDst(((IPCriterion)
selector.getCriterion(Criterion.Type.IPV4_DST)).ip());
.matchIPDst(ipPrefix);
forTableId = UNICAST_ROUTING_TABLE;
log.debug("processing IPv4 specific forwarding objective {} -> next:{}"
+ " in dev:{}", fwd.id(), fwd.nextId(), deviceId);
if (fwd.treatment() != null) {
for (Instruction instr : fwd.treatment().allInstructions()) {
if (instr instanceof L3ModificationInstruction &&
((L3ModificationInstruction) instr).subtype() == L3SubType.DEC_TTL) {
tb.deferred().add(instr);
}
}
}
} else {
filteredSelector
.matchEthType(Ethernet.MPLS_UNICAST)
......@@ -717,20 +793,23 @@ public class OFDPA2Pipeline extends AbstractHandlerBehaviour implements Pipeline
forTableId = MPLS_TABLE_1;
log.debug("processing MPLS specific forwarding objective {} -> next:{}"
+ " in dev {}", fwd.id(), fwd.nextId(), deviceId);
}
TrafficTreatment.Builder tb = DefaultTrafficTreatment.builder();
boolean popMpls = false;
if (fwd.treatment() != null) {
for (Instruction i : fwd.treatment().allInstructions()) {
/*
* NOTE: OF-DPA does not support immediate instruction in
* L3 unicast and MPLS table.
*/
tb.deferred().add(i);
if (i instanceof L2ModificationInstruction &&
((L2ModificationInstruction) i).subtype() == L2SubType.MPLS_POP) {
for (Instruction instr : fwd.treatment().allInstructions()) {
if (instr instanceof L2ModificationInstruction &&
((L2ModificationInstruction) instr).subtype() == L2SubType.MPLS_POP) {
popMpls = true;
tb.immediate().add(instr);
}
if (instr instanceof L3ModificationInstruction &&
((L3ModificationInstruction) instr).subtype() == L3SubType.DEC_TTL) {
// FIXME Should modify the app to send the correct DEC_MPLS_TTL instruction
tb.immediate().decMplsTtl();
}
if (instr instanceof L3ModificationInstruction &&
((L3ModificationInstruction) instr).subtype() == L3SubType.TTL_IN) {
tb.immediate().add(instr);
}
}
}
}
......@@ -817,7 +896,8 @@ public class OFDPA2Pipeline extends AbstractHandlerBehaviour implements Pipeline
+ "in dev:{} for vlan:{}",
fwd.id(), fwd.nextId(), deviceId, vlanIdCriterion.vlanId());
}
filteredSelectorBuilder.matchVlanId(vlanIdCriterion.vlanId());
OfdpaMatchVlanVid ofdpaMatchVlanVid = new OfdpaMatchVlanVid(vlanIdCriterion.vlanId());
filteredSelectorBuilder.extension(ofdpaMatchVlanVid, deviceId);
TrafficSelector filteredSelector = filteredSelectorBuilder.build();
if (fwd.treatment() != null) {
......
......@@ -92,6 +92,14 @@
manufacturer="Broadcom Corp." hwVersion="OF-DPA.*" swVersion="OF-DPA.*">
<behaviour api="org.onosproject.net.behaviour.Pipeliner"
impl="org.onosproject.driver.pipeline.OFDPA2Pipeline"/>
<behaviour api="org.onosproject.openflow.controller.ExtensionTreatmentInterpreter"
impl="org.onosproject.driver.extensions.OfdpaExtensionTreatmentInterpreter" />
<behaviour api="org.onosproject.net.behaviour.ExtensionTreatmentResolver"
impl="org.onosproject.driver.extensions.OfdpaExtensionTreatmentInterpreter" />
<behaviour api="org.onosproject.openflow.controller.ExtensionSelectorInterpreter"
impl="org.onosproject.driver.extensions.OfdpaExtensionSelectorInterpreter" />
<behaviour api="org.onosproject.net.behaviour.ExtensionSelectorResolver"
impl="org.onosproject.driver.extensions.OfdpaExtensionSelectorInterpreter" />
</driver>
<driver name="pmc-olt" extends="default"
manufacturer="PMC GPON Networks" hwVersion="PASffffffff v-1" swVersion="vOLT.*">
......
......@@ -43,7 +43,7 @@ public interface ExtensionSelectorInterpreter extends HandlerBehaviour {
*
* @param factory OpenFlow factory
* @param extensionSelector extension selector
* @return OpenFlow action
* @return OpenFlow OXM
*/
OFOxm<?> mapSelector(OFFactory factory, ExtensionSelector extensionSelector);
......
......@@ -43,12 +43,16 @@ import org.onosproject.net.flow.FlowEntry.FlowEntryState;
import org.onosproject.net.flow.FlowRule;
import org.onosproject.net.flow.TrafficSelector;
import org.onosproject.net.flow.TrafficTreatment;
import org.onosproject.net.flow.criteria.ExtensionSelectorType.ExtensionSelectorTypes;
import org.onosproject.net.flow.instructions.ExtensionTreatmentType.ExtensionTreatmentTypes;
import org.onosproject.net.flow.instructions.Instructions;
import org.onosproject.openflow.controller.Dpid;
import org.onosproject.openflow.controller.ExtensionSelectorInterpreter;
import org.onosproject.openflow.controller.ExtensionTreatmentInterpreter;
import org.projectfloodlight.openflow.protocol.OFFlowMod;
import org.projectfloodlight.openflow.protocol.OFFlowRemoved;
import org.projectfloodlight.openflow.protocol.OFFlowStatsEntry;
import org.projectfloodlight.openflow.protocol.OFMatchV3;
import org.projectfloodlight.openflow.protocol.OFVersion;
import org.projectfloodlight.openflow.protocol.action.OFAction;
import org.projectfloodlight.openflow.protocol.action.OFActionCircuit;
......@@ -137,7 +141,6 @@ public class FlowEntryBuilder {
public FlowEntryBuilder(Dpid dpid, OFFlowRemoved removed, DriverService driverService) {
this.match = removed.getMatch();
this.removed = removed;
this.dpid = dpid;
this.instructions = null;
this.stat = null;
......@@ -288,6 +291,14 @@ public class FlowEntryBuilder {
private TrafficTreatment.Builder buildActions(List<OFAction> actions,
TrafficTreatment.Builder builder) {
DriverHandler driverHandler = getDriver(dpid);
ExtensionTreatmentInterpreter treatmentInterpreter;
if (driverHandler.hasBehaviour(ExtensionTreatmentInterpreter.class)) {
treatmentInterpreter = driverHandler.behaviour(ExtensionTreatmentInterpreter.class);
} else {
treatmentInterpreter = null;
}
for (OFAction act : actions) {
switch (act.getType()) {
case OUTPUT:
......@@ -312,7 +323,6 @@ public class FlowEntryBuilder {
OFActionSetDlSrc dlsrc = (OFActionSetDlSrc) act;
builder.setEthSrc(
MacAddress.valueOf(dlsrc.getDlAddr().getLong()));
break;
case SET_NW_DST:
OFActionSetNwDst nwdst = (OFActionSetNwDst) act;
......@@ -332,11 +342,8 @@ public class FlowEntryBuilder {
short lambda = ((OFOxmOchSigidBasic) ct.getField()).getValue().getChannelNumber();
builder.add(Instructions.modL0Lambda(Lambda.indexedLambda(lambda)));
} else if (exp.getExperimenter() == 0x2320) {
DriverHandler driver = getDriver(dpid);
ExtensionTreatmentInterpreter interpreter = driver
.behaviour(ExtensionTreatmentInterpreter.class);
if (interpreter != null) {
builder.extension(interpreter.mapAction(exp),
if (treatmentInterpreter != null) {
builder.extension(treatmentInterpreter.mapAction(exp),
DeviceId.deviceId(Dpid.uri(dpid)));
}
} else {
......@@ -405,6 +412,14 @@ public class FlowEntryBuilder {
private void handleSetField(TrafficTreatment.Builder builder, OFActionSetField action) {
DriverHandler driverHandler = getDriver(dpid);
ExtensionTreatmentInterpreter treatmentInterpreter;
if (driverHandler.hasBehaviour(ExtensionTreatmentInterpreter.class)) {
treatmentInterpreter = driverHandler.behaviour(ExtensionTreatmentInterpreter.class);
} else {
treatmentInterpreter = null;
}
OFOxm<?> oxm = action.getField();
switch (oxm.getMatchField().id) {
case VLAN_PCP:
......@@ -413,9 +428,15 @@ public class FlowEntryBuilder {
builder.setVlanPcp(vlanpcp.getValue().getValue());
break;
case VLAN_VID:
if (treatmentInterpreter != null &&
treatmentInterpreter.supported(ExtensionTreatmentTypes.OFDPA_SET_VLAN_ID.type())) {
builder.extension(treatmentInterpreter.mapAction(action),
DeviceId.deviceId(Dpid.uri(dpid)));
} else {
@SuppressWarnings("unchecked")
OFOxm<OFVlanVidMatch> vlanvid = (OFOxm<OFVlanVidMatch>) oxm;
builder.setVlanId(VlanId.vlanId(vlanvid.getValue().getVlan()));
}
break;
case ETH_DST:
@SuppressWarnings("unchecked")
......@@ -475,10 +496,9 @@ public class FlowEntryBuilder {
builder.setUdpSrc(TpPort.tpPort(udpsrc.getValue().getPort()));
break;
case TUNNEL_IPV4_DST:
DriverHandler driver = getDriver(dpid);
ExtensionTreatmentInterpreter interpreter = driver.behaviour(ExtensionTreatmentInterpreter.class);
if (interpreter != null) {
builder.extension(interpreter.mapAction(action), DeviceId.deviceId(Dpid.uri(dpid)));
if (treatmentInterpreter != null &&
treatmentInterpreter.supported(ExtensionTreatmentTypes.NICIRA_SET_TUNNEL_DST.type())) {
builder.extension(treatmentInterpreter.mapAction(action), DeviceId.deviceId(Dpid.uri(dpid)));
}
break;
case EXP_ODU_SIG_ID:
......@@ -567,6 +587,14 @@ public class FlowEntryBuilder {
Ip6Prefix ip6Prefix;
Ip4Address ip;
DriverHandler driverHandler = getDriver(dpid);
ExtensionSelectorInterpreter selectorInterpreter;
if (driverHandler.hasBehaviour(ExtensionSelectorInterpreter.class)) {
selectorInterpreter = driverHandler.behaviour(ExtensionSelectorInterpreter.class);
} else {
selectorInterpreter = null;
}
TrafficSelector.Builder builder = DefaultTrafficSelector.builder();
for (MatchField<?> field : match.getMatchFields()) {
switch (field.id) {
......@@ -596,6 +624,16 @@ public class FlowEntryBuilder {
builder.matchEthType((short) ethType);
break;
case VLAN_VID:
if (selectorInterpreter != null &&
selectorInterpreter.supported(ExtensionSelectorTypes.OFDPA_MATCH_VLAN_VID.type())) {
if (match.getVersion().equals(OFVersion.OF_13)) {
OFOxm oxm = ((OFMatchV3) match).getOxmList().get(MatchField.VLAN_VID);
builder.extension(selectorInterpreter.mapOxm(oxm),
DeviceId.deviceId(Dpid.uri(dpid)));
} else {
break;
}
} else {
VlanId vlanId = null;
if (match.isPartiallyMasked(MatchField.VLAN_VID)) {
Masked<OFVlanVidMatch> masked = match.getMasked(MatchField.VLAN_VID);
......@@ -613,6 +651,7 @@ public class FlowEntryBuilder {
if (vlanId != null) {
builder.matchVlanId(vlanId);
}
}
break;
case VLAN_PCP:
byte vlanPcp = match.get(MatchField.VLAN_PCP).getValue();
......
......@@ -20,6 +20,7 @@ import com.google.common.base.Objects;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Maps;
import com.google.common.collect.Sets;
import org.onosproject.net.driver.DriverService;
import org.onosproject.net.flow.DefaultTypedFlowEntry;
import org.onosproject.net.flow.FlowEntry;
import org.onosproject.net.flow.FlowId;
......@@ -55,9 +56,9 @@ import static org.slf4j.LoggerFactory.getLogger;
* Efficiently and adaptively collects flow statistics for the specified switch.
*/
public class NewAdaptiveFlowStatsCollector {
private final Logger log = getLogger(getClass());
private final DriverService driverService;
private final OpenFlowSwitch sw;
private ScheduledExecutorService adaptiveFlowStatsScheduler =
......@@ -109,9 +110,10 @@ public class NewAdaptiveFlowStatsCollector {
* @param sw switch to pull
* @param pollInterval cal and immediate poll frequency in seconds
*/
NewAdaptiveFlowStatsCollector(OpenFlowSwitch sw, int pollInterval) {
NewAdaptiveFlowStatsCollector(
DriverService driverService, OpenFlowSwitch sw, int pollInterval) {
this.driverService = driverService;
this.sw = sw;
initMemberVars(pollInterval);
}
......@@ -232,7 +234,7 @@ public class NewAdaptiveFlowStatsCollector {
private void ofFlowStatsRequestFlowSend(FlowEntry fe) {
// set find match
Match match = FlowModBuilder.builder(fe, sw.factory(), Optional.empty(),
Optional.empty()).buildMatch();
Optional.of(driverService)).buildMatch();
// set find tableId
TableId tableId = TableId.of(fe.tableId());
// set output port
......
......@@ -219,7 +219,8 @@ public class OpenFlowRuleProvider extends AbstractProvider
private void createCollector(OpenFlowSwitch sw) {
if (adaptiveFlowSampling) {
// NewAdaptiveFlowStatsCollector Constructor
NewAdaptiveFlowStatsCollector fsc = new NewAdaptiveFlowStatsCollector(sw, flowPollFrequency);
NewAdaptiveFlowStatsCollector fsc =
new NewAdaptiveFlowStatsCollector(driverService, sw, flowPollFrequency);
fsc.start();
afsCollectors.put(new Dpid(sw.getId()), fsc);
} else {
......
......@@ -211,10 +211,12 @@ public class OpenFlowMeterProvider extends AbstractProvider implements MeterProv
}
}
// TODO: ONOS-3546 Support per device enabling/disabling via network config
private boolean isMeterSupported(OpenFlowSwitch sw) {
if (sw.factory().getVersion() == OFVersion.OF_10 ||
sw.factory().getVersion() == OFVersion.OF_11 ||
sw.factory().getVersion() == OFVersion.OF_12) {
sw.factory().getVersion() == OFVersion.OF_12 ||
sw.softwareDescription().equals("OF-DPA 2.0")) {
return false;
}
......