org.onosproject.net.flow.criteria.Criterion Java Examples

The following examples show how to use org.onosproject.net.flow.criteria.Criterion. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ForwardingObjectiveTranslator.java    From onos with Apache License 2.0 6 votes vote down vote up
private void ipv4RoutingRule(ForwardingObjective obj, Set<Criterion> criteriaWithMeta,
                             ObjectiveTranslation.Builder resultBuilder)
        throws FabricPipelinerException {
    final IPCriterion ipDstCriterion = (IPCriterion) criterionNotNull(
            criteriaWithMeta, Criterion.Type.IPV4_DST);

    if (ipDstCriterion.ip().prefixLength() == 0) {
        defaultIpv4Route(obj, resultBuilder);
        return;
    }

    final TrafficSelector selector = DefaultTrafficSelector.builder()
            .add(ipDstCriterion)
            .build();

    resultBuilder.addFlowRule(flowRule(
            obj, FabricConstants.FABRIC_INGRESS_FORWARDING_ROUTING_V4, selector));
}
 
Example #2
Source File: TroubleshootManager.java    From onos with Apache License 2.0 6 votes vote down vote up
/**
 * Handles table 27 in Ofpda which is a fixed table not visible to any controller that handles Mpls Labels.
 *
 * @param packet the incoming packet
 * @return the updated packet
 */
private TrafficSelector handleOfdpa27FixedTable(StaticPacketTrace trace, TrafficSelector packet) {
    log.debug("Handling table 27 on OFDPA, removing mpls ETH Type and change mpls label");
    Criterion mplsCriterion = packet.getCriterion(Criterion.Type.ETH_TYPE);
    ImmutableList.Builder<Instruction> builder = ImmutableList.builder();

    //If the pakcet comes in with the expected elements we update it as per OFDPA spec.
    if (mplsCriterion != null && ((EthTypeCriterion) mplsCriterion).ethType()
            .equals(EtherType.MPLS_UNICAST.ethType())) {
        //TODO update with parsing with eth MPLS pop Instruction for treating label an bos
        Instruction ethInstruction = Instructions.popMpls(((EthTypeCriterion) trace.getInitialPacket()
                .getCriterion(Criterion.Type.ETH_TYPE)).ethType());
        //FIXME what do we use as L3_Unicast mpls Label ?
        //translateInstruction(builder, ethInstruction);
        builder.add(ethInstruction);
    }
    packet = updatePacket(packet, builder.build()).build();
    return packet;
}
 
Example #3
Source File: PolatisOpticalUtility.java    From onos with Apache License 2.0 6 votes vote down vote up
/**
 * Transforms a flow FlowRule object to a variable binding.
 * @param rule FlowRule object
 * @param delete whether it is a delete or edit request
 * @return variable binding
 */
public static VariableBinding fromFlowRule(FlowRule rule, boolean delete) {
    Set<Criterion> criterions = rule.selector().criteria();
    PortNumber inPort = criterions.stream()
            .filter(c -> c instanceof PortCriterion)
            .map(c -> ((PortCriterion) c).port())
            .findAny()
            .orElse(null);
    long input = inPort.toLong();
    List<Instruction> instructions = rule.treatment().immediate();
    PortNumber outPort = instructions.stream()
            .filter(c -> c instanceof Instructions.OutputInstruction)
            .map(c -> ((Instructions.OutputInstruction) c).port())
            .findAny()
            .orElse(null);
    long output = outPort.toLong();
    OID oid = new OID(PORT_PATCH_OID + "." + input);
    Variable var = new UnsignedInteger32(delete ? 0 : output);
    return new VariableBinding(oid, var);
}
 
Example #4
Source File: IntentViewMessageHandler.java    From onos with Apache License 2.0 6 votes vote down vote up
private void buildConnectivityDetails(ConnectivityIntent intent,
                                      StringBuilder sb) {
    Set<Criterion> criteria = intent.selector().criteria();
    List<Instruction> instructions = intent.treatment().allInstructions();
    List<Constraint> constraints = intent.constraints();

    if (!criteria.isEmpty()) {
        sb.append("Selector: ").append(criteria);
    }
    if (!instructions.isEmpty()) {
        sb.append("Treatment: ").append(instructions);
    }
    if (constraints != null && !constraints.isEmpty()) {
        sb.append("Constraints: ").append(constraints);
    }
}
 
Example #5
Source File: CriterionJsonMatcher.java    From onos with Apache License 2.0 6 votes vote down vote up
/**
 * Matches an eth criterion object.
 *
 * @param criterion criterion to match
 * @return true if the JSON matches the criterion, false otherwise.
 */
private boolean matchCriterion(EthCriterion criterion) {
    final String mac = criterion.mac().toString();
    final String jsonMac = jsonCriterion.get("mac").textValue();
    if (!mac.equals(jsonMac)) {
        description.appendText("mac was " + jsonMac);
        return false;
    }
    if (criterion.type() == Criterion.Type.ETH_DST_MASKED) {
        final String macMask = criterion.mask().toString();
        final String jsonMacMask = jsonCriterion.get("macMask").textValue();
        if (!macMask.equals(jsonMacMask)) {
            description.appendText("macMask was " + jsonMacMask);
            return false;
        }
    }
    return true;
}
 
Example #6
Source File: CriterionCodecTest.java    From onos with Apache License 2.0 6 votes vote down vote up
/**
 * Tests IPv6 Extension Header pseudo-field flags criterion.
 */
@Test
public void matchIPv6ExthdrFlagsTest() {
    int exthdrFlags =
        Criterion.IPv6ExthdrFlags.NONEXT.getValue() |
        Criterion.IPv6ExthdrFlags.ESP.getValue() |
        Criterion.IPv6ExthdrFlags.AUTH.getValue() |
        Criterion.IPv6ExthdrFlags.DEST.getValue() |
        Criterion.IPv6ExthdrFlags.FRAG.getValue() |
        Criterion.IPv6ExthdrFlags.ROUTER.getValue() |
        Criterion.IPv6ExthdrFlags.HOP.getValue() |
        Criterion.IPv6ExthdrFlags.UNREP.getValue() |
        Criterion.IPv6ExthdrFlags.UNSEQ.getValue();
    Criterion criterion = Criteria.matchIPv6ExthdrFlags(exthdrFlags);
    ObjectNode result = criterionCodec.encode(criterion, context);

    assertThat(result, matchesCriterion(criterion));
}
 
Example #7
Source File: HPPipelineV3800.java    From onos with Apache License 2.0 6 votes vote down vote up
@Override
protected void initHardwareCriteria() {
    log.debug("HP V3800 Driver - Initializing hardware supported criteria");

    hardwareCriteria.add(Criterion.Type.IN_PORT);
    hardwareCriteria.add(Criterion.Type.VLAN_VID);
    hardwareCriteria.add(Criterion.Type.VLAN_PCP);

    //Match in hardware is not supported ETH_TYPE == VLAN (0x8100)
    hardwareCriteria.add(Criterion.Type.ETH_TYPE);

    hardwareCriteria.add(Criterion.Type.ETH_SRC);
    hardwareCriteria.add(Criterion.Type.ETH_DST);
    hardwareCriteria.add(Criterion.Type.IPV4_SRC);
    hardwareCriteria.add(Criterion.Type.IPV4_DST);
    hardwareCriteria.add(Criterion.Type.IP_PROTO);
    hardwareCriteria.add(Criterion.Type.IP_DSCP);
    hardwareCriteria.add(Criterion.Type.TCP_SRC);
    hardwareCriteria.add(Criterion.Type.TCP_DST);
}
 
Example #8
Source File: ChannelData.java    From onos with Apache License 2.0 6 votes vote down vote up
/**
 * Returns a ChannelData representation from a flow rule. The rule must contain
 * a Criterion.Type.IN_PORT selector, Criterion.Type.OCH_SIGID selector, and
 * Instruction.Type.OUTPUT instruction.
 *
 * @param rule the flow rule representing the connection
 * @return ChannelData representation of the connection
 */
public static ChannelData fromFlow(FlowRule rule) {
    checkNotNull(rule);

    Criterion in = rule.selector().getCriterion(Criterion.Type.IN_PORT);
    checkNotNull(in);
    PortNumber inPort = ((PortCriterion) in).port();

    Criterion och = rule.selector().getCriterion(Criterion.Type.OCH_SIGID);
    OchSignal ochSignal = och == null ? null : ((OchSignalCriterion) och).lambda();

    PortNumber outPort = null;
    List<Instruction> instructions = rule.treatment().allInstructions();
    for (Instruction ins : instructions) {
        if (ins.type() == Instruction.Type.OUTPUT) {
            outPort = ((Instructions.OutputInstruction) ins).port();
        }
    }
    checkNotNull(outPort);

    return new ChannelData(inPort, outPort, ochSignal);
}
 
Example #9
Source File: TroubleshootPingAllCommand.java    From onos with Apache License 2.0 6 votes vote down vote up
private void printResultOnly(StaticPacketTrace trace, boolean ipv4) {
    if (trace.getEndpointHosts().isPresent()) {
        Host source = trace.getEndpointHosts().get().getLeft();
        Host destination = trace.getEndpointHosts().get().getRight();
        IpAddress srcIP;
        IpAddress dstIP;
        if (ipv4 && trace.getInitialPacket().getCriterion(Criterion.Type.IPV4_SRC) != null) {
            srcIP = ((IPCriterion) trace.getInitialPacket().getCriterion(Criterion.Type.IPV4_SRC)).ip().address();
            dstIP = ((IPCriterion) trace.getInitialPacket().getCriterion(Criterion.Type.IPV4_DST)).ip().address();
            print("Source %s (%s) --> Destination %s (%s)", source.id(), srcIP, destination.id(), dstIP);
        } else if (trace.getInitialPacket().getCriterion(Criterion.Type.IPV6_SRC) != null) {
            srcIP = ((IPCriterion) trace.getInitialPacket().getCriterion(Criterion.Type.IPV6_SRC)).ip().address();
            dstIP = ((IPCriterion) trace.getInitialPacket().getCriterion(Criterion.Type.IPV6_DST)).ip().address();
            print("Source %s (%s) --> Destination %s (%s)", source.id(), srcIP, destination.id(), dstIP);
        } else {
            print("Source %s --> Destination %s", source.id(), destination.id());
        }
        print("%s", trace.resultMessage());
    } else {
        print("Can't gather host information from trace");
        print("%s", trace.resultMessage());
    }
}
 
Example #10
Source File: HPPipelineV2.java    From onos with Apache License 2.0 6 votes vote down vote up
@Override
protected void initHardwareCriteria() {
    log.debug("HP V2 Driver - Initializing hardware supported criteria");

    hardwareCriteria.add(Criterion.Type.IN_PORT);
    hardwareCriteria.add(Criterion.Type.VLAN_VID);
    hardwareCriteria.add(Criterion.Type.VLAN_PCP);

    //Match in hardware is not supported ETH_TYPE == VLAN (0x8100)
    hardwareCriteria.add(Criterion.Type.ETH_TYPE);

    hardwareCriteria.add(Criterion.Type.ETH_SRC);
    hardwareCriteria.add(Criterion.Type.ETH_DST);
    hardwareCriteria.add(Criterion.Type.IPV4_SRC);
    hardwareCriteria.add(Criterion.Type.IPV4_DST);
    hardwareCriteria.add(Criterion.Type.IP_PROTO);
    hardwareCriteria.add(Criterion.Type.IP_DSCP);
    hardwareCriteria.add(Criterion.Type.TCP_SRC);
    hardwareCriteria.add(Criterion.Type.TCP_DST);
}
 
Example #11
Source File: T3WebResource.java    From onos with Apache License 2.0 6 votes vote down vote up
private ObjectNode getGroupObj(ConnectPoint connectPoint, GroupsInDevice output, boolean verbose) {
    ArrayNode groupArray = mapper.createArrayNode();
    ObjectNode groupsObj = mapper.createObjectNode();
    if (output.getOutput().equals(connectPoint)) {
        output.getGroups().forEach(group -> {
            ObjectNode groups = mapper.createObjectNode();
            if (verbose) {
                groups = codec(Group.class).encode(group, this);
            } else {
                groups.put("groupId", group.id().toString());
            }
            groupArray.add(groups);
        });
        ArrayNode node = mapper.createArrayNode();
        for (Criterion packet : output.getFinalPacket().criteria()) {
            node.add(packet.toString());
        }
        groupsObj.set("outgoing packet", node);
    }
    groupsObj.set("groups", groupArray);
    return groupsObj;
}
 
Example #12
Source File: TroubleshootManager.java    From onos with Apache License 2.0 6 votes vote down vote up
/**
 * If the initial packet comes tagged with a Vlan we output it with that to ONOS.
 * If ONOS applied a vlan we remove it.
 *
 * @param outputPath the output
 * @param trace      the trace we are building
 */

private void handleVlanToController(GroupsInDevice outputPath, StaticPacketTrace trace) {

    VlanIdCriterion initialVid = (VlanIdCriterion) trace.getInitialPacket().getCriterion(Criterion.Type.VLAN_VID);
    VlanIdCriterion finalVid = (VlanIdCriterion) outputPath.getFinalPacket().getCriterion(Criterion.Type.VLAN_VID);

    if (initialVid != null && !initialVid.equals(finalVid) && initialVid.vlanId().equals(VlanId.NONE)) {

        Set<Criterion> finalCriteria = new HashSet<>(outputPath.getFinalPacket().criteria());
        //removing the final vlanId
        finalCriteria.remove(finalVid);
        Builder packetUpdated = DefaultTrafficSelector.builder();
        finalCriteria.forEach(packetUpdated::add);
        //Initial was none so we set it to that
        packetUpdated.add(Criteria.matchVlanId(VlanId.NONE));
        //Update final packet
        outputPath.setFinalPacket(packetUpdated.build());
    }
}
 
Example #13
Source File: ForwardingObjectiveTranslator.java    From onos with Apache License 2.0 6 votes vote down vote up
private void processVersatileFwd(ForwardingObjective obj,
                                 ObjectiveTranslation.Builder resultBuilder)
        throws FabricPipelinerException {

    final Set<Criterion.Type> unsupportedCriteria = obj.selector().criteria()
            .stream()
            .map(Criterion::type)
            .filter(t -> !ACL_CRITERIA.contains(t))
            .collect(Collectors.toSet());

    if (!unsupportedCriteria.isEmpty()) {
        throw new FabricPipelinerException(format(
                "unsupported ACL criteria %s", unsupportedCriteria.toString()));
    }

    aclRule(obj, resultBuilder);
}
 
Example #14
Source File: TroubleshootMcastCommand.java    From onos with Apache License 2.0 6 votes vote down vote up
private StaticPacketTrace printTrace(StaticPacketTrace previousTrace, StaticPacketTrace trace) {
    if (previousTrace == null || !previousTrace.equals(trace)) {
        print("%s", StringUtils.rightPad("", 125, '-'));
        previousTrace = trace;
        ConnectPoint initialConnectPoint = trace.getInitialConnectPoint();
        TrafficSelector initialPacket = trace.getInitialPacket();
        boolean isIPv4 = ((EthTypeCriterion) initialPacket.getCriterion(Criterion.Type.ETH_TYPE))
                .ethType().equals(EthType.EtherType.IPV4.ethType()
                );
        IpPrefix group = ((IPCriterion) (isIPv4 ? trace.getInitialPacket()
                .getCriterion(Criterion.Type.IPV4_DST) : trace.getInitialPacket()
                .getCriterion(Criterion.Type.IPV6_DST))).ip();
        print("Source %s, group %s", initialConnectPoint, group);
    }
    StringBuilder destinations = new StringBuilder();
    if (trace.getCompletePaths().size() > 1) {
        destinations.append("Sinks: ");
    } else {
        destinations.append("Sink: ");
    }
    trace.getCompletePaths().forEach(path -> {
        destinations.append(path.get(path.size() - 1) + " ");
    });
    print("%s", destinations.toString());
    return previousTrace;
}
 
Example #15
Source File: DecodeCriterionCodecHelper.java    From onos with Apache License 2.0 5 votes vote down vote up
@Override
public Criterion decodeCriterion(ObjectNode json) {
    byte priority = (byte) nullIsIllegal(json.get(CriterionCodec.PRIORITY),
            CriterionCodec.PRIORITY + MISSING_MEMBER_MESSAGE).asInt();

    return Criteria.matchVlanPcp(priority);
}
 
Example #16
Source File: ForwardingObjectiveTranslator.java    From onos with Apache License 2.0 5 votes vote down vote up
private void processSpecificFwd(ForwardingObjective obj,
                                ObjectiveTranslation.Builder resultBuilder)
        throws FabricPipelinerException {

    final Set<Criterion> criteriaWithMeta = Sets.newHashSet(obj.selector().criteria());

    // FIXME: Is this really needed? Meta is such an ambiguous field...
    // Why would we match on a META field?
    if (obj.meta() != null) {
        criteriaWithMeta.addAll(obj.meta().criteria());
    }

    final ForwardingFunctionType fft = ForwardingFunctionType.getForwardingFunctionType(obj);

    switch (fft) {
        case UNKNOWN:
            throw new FabricPipelinerException(
                    "unable to detect forwarding function type");
        case L2_UNICAST:
            bridgingRule(obj, criteriaWithMeta, resultBuilder, false);
            break;
        case L2_BROADCAST:
            bridgingRule(obj, criteriaWithMeta, resultBuilder, true);
            break;
        case IPV4_ROUTING:
        case IPV4_ROUTING_MULTICAST:
            ipv4RoutingRule(obj, criteriaWithMeta, resultBuilder);
            break;
        case MPLS_SEGMENT_ROUTING:
            mplsRule(obj, criteriaWithMeta, resultBuilder);
            break;
        case IPV6_ROUTING:
        case IPV6_ROUTING_MULTICAST:
        default:
            throw new FabricPipelinerException(format(
                    "unsupported forwarding function type '%s'",
                    fft));
    }
}
 
Example #17
Source File: OltPipeline.java    From onos with Apache License 2.0 5 votes vote down vote up
private boolean checkAnyVlanMatchCriteria(ForwardingObjective fwd) {
    Criterion anyValueVlanCriterion = fwd.selector().criteria().stream()
            .filter(c -> c.type().equals(Criterion.Type.VLAN_VID))
            .filter(vc -> ((VlanIdCriterion) vc).vlanId().toShort() == VlanId.ANY_VALUE)
            .findAny().orElse(null);

    if (anyValueVlanCriterion == null) {
        log.debug("Any value vlan match criteria is not found, criteria {}",
                  fwd.selector().criteria());
        return false;
    }

    return true;
}
 
Example #18
Source File: CriterionCodecTest.java    From onos with Apache License 2.0 5 votes vote down vote up
/**
 * Tests in physical port criterion.
 */
@Test
public void matchInPhyPortTest() {
    Criterion criterion = Criteria.matchInPhyPort(port);
    ObjectNode result = criterionCodec.encode(criterion, context);
    assertThat(result, matchesCriterion(criterion));
}
 
Example #19
Source File: OltPipeline.java    From onos with Apache License 2.0 5 votes vote down vote up
private void provisionEthTypeBasedFilter(FilteringObjective filter,
                                         EthTypeCriterion ethType,
                                         Instructions.OutputInstruction output) {

    Instruction meter = filter.meta().metered();
    Instruction writeMetadata = filter.meta().writeMetadata();

    Criterion vlanId = filterForCriterion(filter.conditions(), Criterion.Type.VLAN_VID);

    TrafficSelector selector = buildSelector(filter.key(), ethType, vlanId);
    TrafficTreatment treatment = buildTreatment(output, meter, writeMetadata);
    buildAndApplyRule(filter, selector, treatment);

}
 
Example #20
Source File: SpringOpenTTP.java    From onos with Apache License 2.0 5 votes vote down vote up
private boolean isSupportedEthDstObjective(ForwardingObjective fwd) {
    TrafficSelector selector = fwd.selector();
    EthCriterion ethDst = (EthCriterion) selector
            .getCriterion(Criterion.Type.ETH_DST);
    VlanIdCriterion vlanId = (VlanIdCriterion) selector
            .getCriterion(Criterion.Type.VLAN_VID);
    if (ethDst == null && vlanId == null) {
        return false;
    }
    return true;
}
 
Example #21
Source File: SpringOpenTTP.java    From onos with Apache License 2.0 5 votes vote down vote up
private boolean isSupportedEthTypeObjective(ForwardingObjective fwd) {
    TrafficSelector selector = fwd.selector();
    EthTypeCriterion ethType = (EthTypeCriterion) selector
            .getCriterion(Criterion.Type.ETH_TYPE);
    if ((ethType == null) ||
            ((ethType.ethType().toShort() != Ethernet.TYPE_IPV4) &&
                    (ethType.ethType().toShort() != Ethernet.MPLS_UNICAST))) {
        return false;
    }
    return true;
}
 
Example #22
Source File: DecodeCriterionCodecHelper.java    From onos with Apache License 2.0 5 votes vote down vote up
@Override
public Criterion decodeCriterion(ObjectNode json) {
    MacAddress mac = MacAddress.valueOf(nullIsIllegal(json.get(CriterionCodec.MAC),
            CriterionCodec.MAC + MISSING_MEMBER_MESSAGE).asText());

    return Criteria.matchEthSrc(mac);
}
 
Example #23
Source File: TrafficSelectorCodecTest.java    From onos with Apache License 2.0 5 votes vote down vote up
/**
 * Tests decoding of a traffic selector JSON object.
 */
@Test
public void testTrafficSelectorDecode() throws IOException {
    TrafficSelector selector = getSelector("TrafficSelector.json");

    Set<Criterion> criteria = selector.criteria();
    assertThat(criteria.size(), is(4));

    ImmutableSet<String> types = ImmutableSet.of("IN_PORT", "ETH_SRC", "ETH_DST", "ETH_TYPE");

    criteria.forEach(c -> assertThat(types.contains(c.type().name()), is(true)));
}
 
Example #24
Source File: CriterionCodecTest.java    From onos with Apache License 2.0 5 votes vote down vote up
/**
 * Tests ICMP type criterion.
 */
@Test
public void matchIcmpTypeTest() {
    Criterion criterion = Criteria.matchIcmpType((byte) 250);
    ObjectNode result = criterionCodec.encode(criterion, context);
    assertThat(result, matchesCriterion(criterion));
}
 
Example #25
Source File: CriterionCodecTest.java    From onos with Apache License 2.0 5 votes vote down vote up
/**
 * Tests IPV6 SLL criterion.
 */
@Test
public void matchIPv6NDSourceLinkLayerAddressTest() {
    Criterion criterion = Criteria.matchIPv6NDSourceLinkLayerAddress(mac1);
    ObjectNode result = criterionCodec.encode(criterion, context);
    assertThat(result, matchesCriterion(criterion));
}
 
Example #26
Source File: NokiaOltPipeline.java    From onos with Apache License 2.0 5 votes vote down vote up
private boolean hasUntaggedVlanTag(TrafficSelector selector) {
    Iterator<Criterion> iter = selector.criteria().iterator();

    while (iter.hasNext()) {
        Criterion criterion = iter.next();
        if (criterion.type() == Criterion.Type.VLAN_VID &&
                ((VlanIdCriterion) criterion).vlanId().toShort() == VlanId.UNTAGGED) {
            return true;
        }
    }

    return false;
}
 
Example #27
Source File: TroubleshootManagerTest.java    From onos with Apache License 2.0 5 votes vote down vote up
/**
 * Test HW support in a single device with 2 flow rules to check hit of static HW rules.
 */
@Test
public void hardwareTest() throws Exception {

    StaticPacketTrace traceSuccess = testSuccess(PACKET_OK, HARDWARE_DEVICE_IN_CP,
            HARDWARE_DEVICE, HARDWARE_DEVICE_OUT_CP, 1, 1);

    assertEquals("wrong ETH type", EthType.EtherType.IPV4.ethType(),
            ((EthTypeCriterion) traceSuccess.getGroupOuputs(HARDWARE_DEVICE).get(0).getFinalPacket()
                    .getCriterion(Criterion.Type.ETH_TYPE)).ethType());

}
 
Example #28
Source File: DecodeCriterionCodecHelper.java    From onos with Apache License 2.0 5 votes vote down vote up
@Override
public Criterion decodeCriterion(ObjectNode json) {
    JsonNode ethTypeNode = nullIsIllegal(json.get(CriterionCodec.ETH_TYPE),
                                      CriterionCodec.ETH_TYPE + MISSING_MEMBER_MESSAGE);
    int ethType;
    if (ethTypeNode.isInt()) {
        ethType = ethTypeNode.asInt();
    } else {
        ethType = Integer.decode(ethTypeNode.textValue());
    }
    return Criteria.matchEthType(ethType);
}
 
Example #29
Source File: OvsCorsaPipeline.java    From onos with Apache License 2.0 5 votes vote down vote up
@Override
protected Collection<FlowRule> processIpTraffic(ForwardingObjective fwd, FlowRule.Builder rule) {
    IPCriterion ipSrc = (IPCriterion) fwd.selector()
            .getCriterion(Criterion.Type.IPV4_SRC);
    if (ipSrc != null) {
        log.warn("Driver does not currently handle matching Src IP");
        fail(fwd, ObjectiveError.UNSUPPORTED);
        return Collections.emptySet();
    }
    IPCriterion ipDst = (IPCriterion) fwd.selector()
            .getCriterion(Criterion.Type.IPV4_DST);
    if (ipDst != null) {
        log.error("Driver handles Dst IP matching as specific forwarding "
                + "objective, not versatile");
        fail(fwd, ObjectiveError.UNSUPPORTED);
        return Collections.emptySet();
    }
    IPProtocolCriterion ipProto = (IPProtocolCriterion) fwd.selector()
            .getCriterion(Criterion.Type.IP_PROTO);
    if (ipProto != null && ipProto.protocol() == IPv4.PROTOCOL_TCP) {
        log.warn("Driver automatically punts all packets reaching the "
                + "LOCAL table to the controller");
        pass(fwd);
        return Collections.emptySet();
    }
    return Collections.emptySet();
}
 
Example #30
Source File: Ofdpa2Pipeline.java    From onos with Apache License 2.0 5 votes vote down vote up
/**
 * Helper method to build Ipv6 selector using the selector provided by
 * a forwarding objective.
 *
 * @param builderToUpdate the builder to update
 * @param fwd the selector to read
 * @return 0 if the update ends correctly. -1 if the matches
 * are not yet supported
 */
int buildIpv6Selector(TrafficSelector.Builder builderToUpdate,
                                ForwardingObjective fwd) {

    TrafficSelector selector = fwd.selector();

    IpPrefix ipv6Dst = ((IPCriterion) selector.getCriterion(Criterion.Type.IPV6_DST)).ip();
    if (ipv6Dst.isMulticast()) {
        if (ipv6Dst.prefixLength() != IpAddress.INET6_BIT_LENGTH) {
            log.warn("Multicast specific forwarding objective can only be /128");
            fail(fwd, ObjectiveError.BADPARAMS);
            return -1;
        }
        VlanId assignedVlan = readVlanFromSelector(fwd.meta());
        if (assignedVlan == null) {
            log.warn("VLAN ID required by multicast specific fwd obj is missing. Abort.");
            fail(fwd, ObjectiveError.BADPARAMS);
            return -1;
        }
        if (requireVlanExtensions()) {
            OfdpaMatchVlanVid ofdpaMatchVlanVid = new OfdpaMatchVlanVid(assignedVlan);
            builderToUpdate.extension(ofdpaMatchVlanVid, deviceId);
        } else {
            builderToUpdate.matchVlanId(assignedVlan);
        }
        builderToUpdate.matchEthType(Ethernet.TYPE_IPV6).matchIPv6Dst(ipv6Dst);
        log.debug("processing IPv6 multicast specific forwarding objective {} -> next:{}"
                          + " in dev:{}", fwd.id(), fwd.nextId(), deviceId);
    } else {
       if (ipv6Dst.prefixLength() != 0) {
           builderToUpdate.matchIPv6Dst(ipv6Dst);
       }
    builderToUpdate.matchEthType(Ethernet.TYPE_IPV6);
    log.debug("processing IPv6 unicast specific forwarding objective {} -> next:{}"
                          + " in dev:{}", fwd.id(), fwd.nextId(), deviceId);
    }
    return 0;
}