Saurav Das
Committed by Gerrit Code Review

Support for matching on MPLS BOS indicator bit

Change-Id: I9f8c3f499beff7c70b4c829c2846c71007932d94
......@@ -294,6 +294,11 @@ public final class DefaultTrafficSelector implements TrafficSelector {
}
@Override
public Builder matchMplsBos(boolean mplsBos) {
return add(Criteria.matchMplsLabel(mplsBos));
}
@Override
public TrafficSelector.Builder matchTunnelId(long tunnelId) {
return add(Criteria.matchTunnelId(tunnelId));
}
......
......@@ -18,6 +18,7 @@ package org.onosproject.net.flow;
import java.util.Set;
import org.onosproject.net.PortNumber;
import org.onosproject.net.flow.DefaultTrafficSelector.Builder;
import org.onosproject.net.flow.criteria.Criterion;
import org.onlab.packet.IpPrefix;
import org.onlab.packet.Ip6Address;
......@@ -301,6 +302,14 @@ public interface TrafficSelector {
Builder matchMplsLabel(MplsLabel mplsLabel);
/**
* Matches on a MPLS Bottom-of-Stack indicator bit.
*
* @param mplsBos boolean value indicating BOS=1 (true) or BOS=0 (false).
* @return a selection builder
*/
Builder matchMplsBos(boolean mplsBos);
/**
* Matches a tunnel id.
*
* @param tunnelId a tunnel id
......
......@@ -356,6 +356,16 @@ public final class Criteria {
}
/**
* Creates a match on MPLS Bottom-of-Stack indicator bit.
*
* @param mplsBos boolean value indicating true (BOS=1) or false (BOS=0)
* @return match criterion
*/
public static Criterion matchMplsLabel(boolean mplsBos) {
return new MplsBosCriterion(mplsBos);
}
/**
* Creates a match on Tunnel ID.
*
* @param tunnelId Tunnel ID (64 bits)
......
package org.onosproject.net.flow.criteria;
import static com.google.common.base.MoreObjects.toStringHelper;
import java.util.Objects;
/**
* Implementation of MPLS BOS criterion (1 bit).
*/
public class MplsBosCriterion implements Criterion {
private boolean mplsBos;
MplsBosCriterion(boolean mplsBos) {
this.mplsBos = mplsBos;
}
@Override
public Type type() {
return Type.MPLS_BOS;
}
public boolean mplsBos() {
return mplsBos;
}
@Override
public String toString() {
return toStringHelper(type().toString())
.add("bos", mplsBos).toString();
}
@Override
public int hashCode() {
return Objects.hash(type().ordinal(), mplsBos);
}
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj instanceof MplsBosCriterion) {
MplsBosCriterion that = (MplsBosCriterion) obj;
return Objects.equals(mplsBos, that.mplsBos()) &&
Objects.equals(this.type(), that.type());
}
return false;
}
}
......@@ -31,6 +31,7 @@ import java.util.stream.Collectors;
import org.onlab.osgi.ServiceDirectory;
import org.onlab.packet.Ethernet;
import org.onlab.packet.MplsLabel;
import org.onlab.packet.VlanId;
import org.onlab.util.KryoNamespace;
import org.onosproject.core.ApplicationId;
......@@ -618,6 +619,36 @@ public class OFDPA1Pipeline extends AbstractHandlerBehaviour implements Pipeline
//processBridgingTable();
//processAclTable();
//processGroupTable();
//processMplsTable();
}
protected void processMplsTable() {
FlowRuleOperations.Builder ops = FlowRuleOperations.builder();
TrafficSelector.Builder selector = DefaultTrafficSelector.builder();
selector.matchEthType(Ethernet.MPLS_UNICAST);
selector.matchMplsLabel(MplsLabel.mplsLabel(0xff));
selector.matchMplsBos(true);
TrafficTreatment.Builder treatment = DefaultTrafficTreatment.builder();
treatment.popMpls(Ethernet.TYPE_IPV4);
treatment.transition(ACL_TABLE);
FlowRule test = DefaultFlowRule.builder().forDevice(deviceId)
.withSelector(selector.build()).withTreatment(treatment.build())
.withPriority(LOWEST_PRIORITY).fromApp(driverId).makePermanent()
.forTable(25).build();
ops = ops.add(test);
flowRuleService.apply(ops.build(new FlowRuleOperationsContext() {
@Override
public void onSuccess(FlowRuleOperations ops) {
log.info("Initialized mpls table");
}
@Override
public void onError(FlowRuleOperations ops) {
log.info("Failed to initialize mpls table");
}
}));
}
protected void processPortTable() {
......
......@@ -15,7 +15,14 @@
*/
package org.onosproject.provider.of.flow.impl;
import com.google.common.collect.Lists;
import static org.onosproject.net.flow.criteria.Criteria.matchLambda;
import static org.onosproject.net.flow.criteria.Criteria.matchOchSignalType;
import static org.onosproject.provider.of.flow.impl.OpenFlowValueMapper.lookupChannelSpacing;
import static org.onosproject.provider.of.flow.impl.OpenFlowValueMapper.lookupGridType;
import static org.onosproject.provider.of.flow.impl.OpenFlowValueMapper.lookupOchSignalType;
import static org.slf4j.LoggerFactory.getLogger;
import java.util.List;
import org.onlab.packet.Ip4Address;
import org.onlab.packet.Ip4Prefix;
......@@ -78,14 +85,7 @@ import org.projectfloodlight.openflow.types.U8;
import org.projectfloodlight.openflow.types.VlanPcp;
import org.slf4j.Logger;
import java.util.List;
import static org.onosproject.net.flow.criteria.Criteria.matchLambda;
import static org.onosproject.net.flow.criteria.Criteria.matchOchSignalType;
import static org.onosproject.provider.of.flow.impl.OpenFlowValueMapper.lookupChannelSpacing;
import static org.onosproject.provider.of.flow.impl.OpenFlowValueMapper.lookupGridType;
import static org.onosproject.provider.of.flow.impl.OpenFlowValueMapper.lookupOchSignalType;
import static org.slf4j.LoggerFactory.getLogger;
import com.google.common.collect.Lists;
public class FlowEntryBuilder {
private final Logger log = getLogger(getClass());
......@@ -598,6 +598,9 @@ public class FlowEntryBuilder {
builder.matchMplsLabel(MplsLabel.mplsLabel((int) match.get(MatchField.MPLS_LABEL)
.getValue()));
break;
case MPLS_BOS:
builder.matchMplsBos(match.get(MatchField.MPLS_BOS).getValue());
break;
case SCTP_SRC:
builder.matchSctpSrc((short) match.get(MatchField.SCTP_SRC).getPort());
break;
......
......@@ -15,6 +15,10 @@
*/
package org.onosproject.provider.of.flow.impl;
import static org.slf4j.LoggerFactory.getLogger;
import java.util.Optional;
import org.onlab.packet.Ip4Address;
import org.onlab.packet.Ip4Prefix;
import org.onlab.packet.Ip6Address;
......@@ -23,6 +27,7 @@ import org.onlab.packet.VlanId;
import org.onosproject.net.OchSignal;
import org.onosproject.net.flow.FlowRule;
import org.onosproject.net.flow.TrafficSelector;
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.IPCriterion;
......@@ -38,6 +43,7 @@ import org.onosproject.net.flow.criteria.IcmpTypeCriterion;
import org.onosproject.net.flow.criteria.Icmpv6CodeCriterion;
import org.onosproject.net.flow.criteria.Icmpv6TypeCriterion;
import org.onosproject.net.flow.criteria.MetadataCriterion;
import org.onosproject.net.flow.criteria.MplsBosCriterion;
import org.onosproject.net.flow.criteria.MplsCriterion;
import org.onosproject.net.flow.criteria.OchSignalCriterion;
import org.onosproject.net.flow.criteria.OchSignalTypeCriterion;
......@@ -48,7 +54,6 @@ import org.onosproject.net.flow.criteria.TunnelIdCriterion;
import org.onosproject.net.flow.criteria.UdpPortCriterion;
import org.onosproject.net.flow.criteria.VlanIdCriterion;
import org.onosproject.net.flow.criteria.VlanPcpCriterion;
import org.onosproject.net.flow.criteria.Criterion;
import org.projectfloodlight.openflow.protocol.OFFactory;
import org.projectfloodlight.openflow.protocol.OFFlowAdd;
import org.projectfloodlight.openflow.protocol.OFFlowDelete;
......@@ -67,6 +72,7 @@ import org.projectfloodlight.openflow.types.IpEcn;
import org.projectfloodlight.openflow.types.IpProtocol;
import org.projectfloodlight.openflow.types.MacAddress;
import org.projectfloodlight.openflow.types.Masked;
import org.projectfloodlight.openflow.types.OFBooleanValue;
import org.projectfloodlight.openflow.types.OFMetadata;
import org.projectfloodlight.openflow.types.OFPort;
import org.projectfloodlight.openflow.types.OFVlanVidMatch;
......@@ -79,10 +85,6 @@ import org.projectfloodlight.openflow.types.VlanPcp;
import org.projectfloodlight.openflow.types.VlanVid;
import org.slf4j.Logger;
import java.util.Optional;
import static org.slf4j.LoggerFactory.getLogger;
/**
* Builder for OpenFlow flow mods based on FlowRules.
*/
......@@ -401,12 +403,17 @@ public abstract class FlowModBuilder {
mBuilder.setExact(MatchField.TUNNEL_ID,
U64.of(tunnelId.tunnelId()));
break;
case MPLS_BOS:
MplsBosCriterion mplsBos = (MplsBosCriterion) c;
mBuilder.setExact(MatchField.MPLS_BOS,
mplsBos.mplsBos() ? OFBooleanValue.TRUE
: OFBooleanValue.FALSE);
break;
case ARP_OP:
case ARP_SHA:
case ARP_SPA:
case ARP_THA:
case ARP_TPA:
case MPLS_BOS:
case MPLS_TC:
case PBB_ISID:
default:
......