Java Code Examples for org.onosproject.net.flowobjective.ForwardingObjective#selector()

The following examples show how to use org.onosproject.net.flowobjective.ForwardingObjective#selector() . 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: AbstractCorsaPipeline.java    From onos with Apache License 2.0 6 votes vote down vote up
private Collection<FlowRule> processSpecific(ForwardingObjective fwd) {
    log.debug("Processing specific forwarding objective");
    TrafficSelector selector = fwd.selector();
    EthTypeCriterion ethTypeCriterion =
            (EthTypeCriterion) selector.getCriterion(Criterion.Type.ETH_TYPE);
    VlanIdCriterion vlanIdCriterion =
            (VlanIdCriterion) selector.getCriterion(Criterion.Type.VLAN_VID);
    if (ethTypeCriterion != null) {
        short et = ethTypeCriterion.ethType().toShort();
        if (et == Ethernet.TYPE_IPV4) {
            return processSpecificRoute(fwd);
        } else if (et == Ethernet.TYPE_VLAN) {
            /* The ForwardingObjective must specify VLAN ethtype in order to use the Transit Circuit */
            return processSpecificSwitch(fwd);
        }
    } else if (vlanIdCriterion != null) {
        return processSpecificSwitch(fwd);
    }

    fail(fwd, ObjectiveError.UNSUPPORTED);
    return ImmutableSet.of();
}
 
Example 2
Source File: OpenVSwitchPipeline.java    From onos with Apache License 2.0 6 votes vote down vote up
private Collection<FlowRule> processVersatile(ForwardingObjective fwd) {
    log.debug("Processing versatile forwarding objective");
    TrafficSelector selector = fwd.selector();
    TrafficTreatment tb = fwd.treatment();
    FlowRule.Builder ruleBuilder = DefaultFlowRule.builder().fromApp(fwd.appId()).withPriority(fwd.priority())
            .forDevice(deviceId).withSelector(selector).withTreatment(tb).makeTemporary(TIME_OUT);
    ruleBuilder.withPriority(fwd.priority());
    if (fwd.priority() == 100) {
        ruleBuilder.forTable(ENCAP_OUTPUT_TABLE);
    } else if (fwd.priority() == 200) {
        ruleBuilder.forTable(TUN_SEND_TABLE);
    } else {
        ruleBuilder.forTable(CLASSIFIER_TABLE);
    }

    if (fwd.permanent()) {
        ruleBuilder.makePermanent();
    }
    return Collections.singletonList(ruleBuilder.build());
}
 
Example 3
Source File: AbstractCorsaPipeline.java    From onos with Apache License 2.0 5 votes vote down vote up
private Collection<FlowRule> processVersatile(ForwardingObjective fwd) {
    log.debug("Processing vesatile forwarding objective");
    TrafficSelector selector = fwd.selector();

    EthTypeCriterion ethType =
            (EthTypeCriterion) selector.getCriterion(Criterion.Type.ETH_TYPE);
    if (ethType == null) {
        log.error("Versatile forwarding objective must include ethType");
        fail(fwd, ObjectiveError.UNKNOWN);
        return ImmutableSet.of();
    }
    Builder rule = DefaultFlowRule.builder()
            .forDevice(deviceId)
            .withSelector(fwd.selector())
            .withTreatment(fwd.treatment())
            .withPriority(fwd.priority())
            .fromApp(fwd.appId())
            .makePermanent();
    if (ethType.ethType().toShort() == Ethernet.TYPE_ARP) {
        return processArpTraffic(fwd, rule);
    } else if (ethType.ethType().toShort() == Ethernet.TYPE_LLDP ||
            ethType.ethType().toShort() == Ethernet.TYPE_BSN) {
        return processLinkDiscovery(fwd, rule);
    } else if (ethType.ethType().toShort() == Ethernet.TYPE_IPV4) {
        return processIpTraffic(fwd, rule);
    }
    log.warn("Driver does not support given versatile forwarding objective");
    fail(fwd, ObjectiveError.UNSUPPORTED);
    return ImmutableSet.of();
}
 
Example 4
Source File: MockFlowObjectiveService.java    From onos with Apache License 2.0 5 votes vote down vote up
@Override
public void forward(DeviceId deviceId, ForwardingObjective forwardingObjective) {
    TrafficSelector selector = forwardingObjective.selector();
    TrafficTreatment treatment = nextTable.get(forwardingObjective.nextId());
    MacAddress macAddress = ((EthCriterion) selector.getCriterion(Criterion.Type.ETH_DST)).mac();
    VlanId vlanId = ((VlanIdCriterion) selector.getCriterion(Criterion.Type.VLAN_VID)).vlanId();

    boolean popVlan = treatment.allInstructions().stream()
            .filter(instruction -> instruction.type().equals(Instruction.Type.L2MODIFICATION))
            .anyMatch(instruction -> ((L2ModificationInstruction) instruction).subtype()
                    .equals(L2ModificationInstruction.L2SubType.VLAN_POP));
    PortNumber portNumber = treatment.allInstructions().stream()
            .filter(instruction -> instruction.type().equals(Instruction.Type.OUTPUT))
            .map(instruction -> ((Instructions.OutputInstruction) instruction).port()).findFirst().orElse(null);
    if (portNumber == null) {
        throw new IllegalArgumentException();
    }

    Objective.Operation op = forwardingObjective.op();

    MockBridgingTableKey btKey = new MockBridgingTableKey(deviceId, macAddress, vlanId);
    MockBridgingTableValue btValue = new MockBridgingTableValue(popVlan, portNumber);

    if (op.equals(Objective.Operation.ADD)) {
        bridgingTable.put(btKey, btValue);
        forwardingObjective.context().ifPresent(context -> context.onSuccess(forwardingObjective));
    } else if (op.equals(Objective.Operation.REMOVE)) {
        bridgingTable.remove(btKey, btValue);
        forwardingObjective.context().ifPresent(context -> context.onSuccess(forwardingObjective));
    } else {
        forwardingObjective.context().ifPresent(context ->
                context.onError(forwardingObjective, ObjectiveError.UNKNOWN));
        throw new IllegalArgumentException();
    }
}
 
Example 5
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;
}
 
Example 6
Source File: PicaPipeline.java    From onos with Apache License 2.0 5 votes vote down vote up
private Collection<FlowRule> processVersatile(ForwardingObjective fwd) {
    log.debug("Processing versatile forwarding objective");
    TrafficSelector selector = fwd.selector();
    TrafficTreatment treatment = fwd.treatment();
    Collection<FlowRule> flowrules = new ArrayList<FlowRule>();

    // first add this rule for basic single-table operation
    // or non-ARP related multi-table operation
    FlowRule rule = DefaultFlowRule.builder()
            .forDevice(deviceId)
            .withSelector(selector)
            .withTreatment(treatment)
            .withPriority(fwd.priority())
            .fromApp(fwd.appId())
            .makePermanent()
            .forTable(ACL_TABLE).build();
    flowrules.add(rule);

    EthTypeCriterion ethType =
            (EthTypeCriterion) selector.getCriterion(Criterion.Type.ETH_TYPE);
    if (ethType == null) {
        log.warn("No ethType in versatile forwarding obj. Not processing further.");
        return flowrules;
    }

    // now deal with possible mix of ARP with filtering objectives
    // in multi-table scenarios
    if (ethType.ethType().toShort() == Ethernet.TYPE_ARP) {
        if (filters.isEmpty()) {
            pendingVersatiles.add(fwd);
            return flowrules;
        }
        for (Filter filter : filters) {
            flowrules.addAll(processVersatilesWithFilters(filter, fwd));
        }
    }
    return flowrules;
}
 
Example 7
Source File: Ofdpa2Pipeline.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);
    return !((ethType == null) ||
            ((ethType.ethType().toShort() != Ethernet.TYPE_IPV4) &&
                    (ethType.ethType().toShort() != Ethernet.MPLS_UNICAST)) &&
                    (ethType.ethType().toShort() != Ethernet.TYPE_IPV6));
}
 
Example 8
Source File: Ofdpa2Pipeline.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);
    return !(ethDst == null && vlanId == null);
}
 
Example 9
Source File: OltPipeline.java    From onos with Apache License 2.0 5 votes vote down vote up
private void installNoModificationRules(ForwardingObjective fwd) {
    Instructions.OutputInstruction output = (Instructions.OutputInstruction) fetchOutput(fwd, DOWNSTREAM);
    Instructions.MetadataInstruction writeMetadata = fetchWriteMetadata(fwd);
    Instructions.MeterInstruction meter = (Instructions.MeterInstruction) fetchMeter(fwd);

    TrafficSelector selector = fwd.selector();

    Criterion inport = selector.getCriterion(Criterion.Type.IN_PORT);
    Criterion outerVlan = selector.getCriterion(Criterion.Type.VLAN_VID);
    Criterion innerVlan = selector.getCriterion(Criterion.Type.INNER_VLAN_VID);

    if (inport == null || output == null || innerVlan == null || outerVlan == null) {
        log.error("Forwarding objective is underspecified: {}", fwd);
        fail(fwd, ObjectiveError.BADPARAMS);
        return;
    }


    FlowRule.Builder outer = DefaultFlowRule.builder()
            .fromApp(fwd.appId())
            .forDevice(deviceId)
            .makePermanent()
            .withPriority(fwd.priority())
            .withSelector(buildSelector(inport, outerVlan))
            .withTreatment(buildTreatment(output, writeMetadata, meter));

    applyRules(fwd, outer);
}
 
Example 10
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 11
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 12
Source File: CentecV350Pipeline.java    From onos with Apache License 2.0 4 votes vote down vote up
private Collection<FlowRule> processSpecific(ForwardingObjective fwd) {
    log.debug("Processing specific forwarding objective");
    TrafficSelector selector = fwd.selector();
    EthTypeCriterion ethType =
            (EthTypeCriterion) selector.getCriterion(Criterion.Type.ETH_TYPE);
    if (ethType == null || ethType.ethType().toShort() != Ethernet.TYPE_IPV4) {
        fail(fwd, ObjectiveError.UNSUPPORTED);
        return Collections.emptySet();
    }

    // Must have metadata as key.
    TrafficSelector filteredSelector =
            DefaultTrafficSelector.builder()
                    .matchEthType(Ethernet.TYPE_IPV4)
                    .matchMetadata(DEFAULT_METADATA)
                    .matchIPDst(
                            ((IPCriterion)
                                    selector.getCriterion(Criterion.Type.IPV4_DST)).ip())
                    .build();

    TrafficTreatment.Builder tb = DefaultTrafficTreatment.builder();

    if (fwd.nextId() != null) {
        NextGroup next = flowObjectiveStore.getNextGroup(fwd.nextId());
        GroupKey key = appKryo.deserialize(next.data());
        Group group = groupService.getGroup(deviceId, key);
        if (group == null) {
            log.warn("The group left!");
            fail(fwd, ObjectiveError.GROUPMISSING);
            return Collections.emptySet();
        }
        tb.group(group.id());
    }

    FlowRule.Builder ruleBuilder = DefaultFlowRule.builder()
            .fromApp(fwd.appId())
            .withPriority(ROUTE_TABLE_PRIORITY)
            .forDevice(deviceId)
            .withSelector(filteredSelector)
            .withTreatment(tb.build());

    if (fwd.permanent()) {
        ruleBuilder.makePermanent();
    } else {
        ruleBuilder.makeTemporary(fwd.timeout());
    }

    ruleBuilder.forTable(ROUTE_TABLE);

    return Collections.singletonList(ruleBuilder.build());

}
 
Example 13
Source File: OpenVSwitchPipeline.java    From onos with Apache License 2.0 4 votes vote down vote up
private Collection<FlowRule> processSpecific(ForwardingObjective fwd) {
    log.debug("Processing specific forwarding objective");
    TrafficSelector selector = fwd.selector();
    TrafficTreatment tb = fwd.treatment();
    FlowRule.Builder ruleBuilder = DefaultFlowRule.builder()
            .fromApp(fwd.appId()).withPriority(fwd.priority())
            .forDevice(deviceId).withSelector(selector)
            .withTreatment(tb).makeTemporary(TIME_OUT);
    ruleBuilder.withPriority(fwd.priority());
    if (fwd.permanent()) {
        ruleBuilder.makePermanent();
    }
    Integer transition = null;
    Integer forTable = null;
    // MAC table flow rules
    if (selector.getCriterion(Type.TUNNEL_ID) != null
            && (selector.getCriterion(Type.ETH_DST) != null
                    || selector.getCriterion(Type.ETH_SRC) != null)) {
        forTable = MAC_TABLE;
        return reassemblyFlowRule(ruleBuilder, tb, transition, forTable);
    }
    // CLASSIFIER table flow rules
    if (selector.getCriterion(Type.IN_PORT) != null) {
        forTable = CLASSIFIER_TABLE;
        if (selector.getCriterion(Type.ETH_SRC) != null
                && selector.getCriterion(Type.ETH_DST) != null) {
            transition = L3FWD_TABLE;
        } else if (selector.getCriterion(Type.ETH_SRC) != null
                || selector.getCriterion(Type.TUNNEL_ID) != null) {
            transition = MAC_TABLE;
        } else if (selector.getCriterion(Type.IPV4_DST) != null) {
            transition = DNAT_TABLE;
        } else if (selector.getCriterion(Type.ETH_TYPE) != null
                && selector.getCriterion(Type.ETH_TYPE).equals(Criteria
                        .matchEthType(EtherType.ARP.ethType().toShort()))) {
            transition = ARP_TABLE;
        }
        return reassemblyFlowRule(ruleBuilder, tb, transition, forTable);
    }
    // ARP table flow rules
    if (selector.getCriterion(Type.ETH_TYPE) != null
            && selector.getCriterion(Type.ETH_TYPE).equals(Criteria
                    .matchEthType(EtherType.ARP.ethType().toShort()))) {
        // CLASSIFIER table arp flow rules
        if (selector.getCriterion(Type.TUNNEL_ID) == null) {
            if (selector.getCriterion(Type.ARP_OP) != null) {
                forTable = CLASSIFIER_TABLE;
                return reassemblyFlowRule(ruleBuilder, tb, null, forTable);
            }
            transition = ARP_TABLE;
            forTable = CLASSIFIER_TABLE;
            return reassemblyFlowRule(ruleBuilder, tb, transition, forTable);
        }
        forTable = ARP_TABLE;
        return reassemblyFlowRule(ruleBuilder, tb, transition, forTable);
    }
    // SNAT table flow rules
    if (selector.getCriterion(Type.TUNNEL_ID) != null
            && selector.getCriterion(Type.IPV4_SRC) != null) {
        transition = MAC_TABLE;
        forTable = SNAT_TABLE;
        return reassemblyFlowRule(ruleBuilder, tb, transition, forTable);
    }
    // L3FWD table flow rules
    if (selector.getCriterion(Type.TUNNEL_ID) != null
            && selector.getCriterion(Type.IPV4_DST) != null) {
        transition = MAC_TABLE;
        forTable = L3FWD_TABLE;
        return reassemblyFlowRule(ruleBuilder, tb, transition, forTable);
    }
    // DNAT table flow rules
    if (selector.getCriterion(Type.IPV4_DST) != null) {
        IPCriterion ipCriterion = (IPCriterion) selector.getCriterion(Type.IPV4_DST);
        IpPrefix ipPrefix = ipCriterion.ip();
        // specific CLASSIFIER table flow rules for userdata
        if (ipPrefix.address().equals(IpAddress.valueOf(USERDATA_IP))) {
            forTable = CLASSIFIER_TABLE;
            transition = MAC_TABLE;
            return reassemblyFlowRule(ruleBuilder, tb, transition, forTable);
        }
        transition = L3FWD_TABLE;
        forTable = DNAT_TABLE;
        return reassemblyFlowRule(ruleBuilder, tb, transition, forTable);
    }
    return Collections.singletonList(ruleBuilder.build());
}
 
Example 14
Source File: SoftRouterPipeline.java    From onos with Apache License 2.0 4 votes vote down vote up
/**
 * SoftRouter has a single specific table - the FIB Table. It emulates
 * LPM matching of dstIP by using higher priority flows for longer prefixes.
 * Flows are forwarded using flow-actions
 *
 * @param fwd The forwarding objective of type simple
 * @return A collection of flow rules meant to be delivered to the flowrule
 *         subsystem. Typically the returned collection has a single flowrule.
 *         May return empty collection in case of failures.
 *
 */
private Collection<FlowRule> processSpecific(ForwardingObjective fwd) {
    log.debug("Processing specific forwarding objective to next:{}", fwd.nextId());
    TrafficSelector selector = fwd.selector();
    EthTypeCriterion ethType =
            (EthTypeCriterion) selector.getCriterion(Criterion.Type.ETH_TYPE);
    // XXX currently supporting only the L3 unicast table
    if (ethType == null || (ethType.ethType().toShort() != TYPE_IPV4
            && ethType.ethType().toShort() != Ethernet.TYPE_IPV6)) {
        fail(fwd, ObjectiveError.UNSUPPORTED);
        return Collections.emptySet();
    }
    //We build the selector according the eth type.
    IpPrefix ipPrefix;
    TrafficSelector.Builder filteredSelector;
    if (ethType.ethType().toShort() == TYPE_IPV4) {
        ipPrefix = ((IPCriterion)
                selector.getCriterion(Criterion.Type.IPV4_DST)).ip();

        filteredSelector = DefaultTrafficSelector.builder()
                .matchEthType(TYPE_IPV4);
    } else {
        ipPrefix = ((IPCriterion)
                selector.getCriterion(Criterion.Type.IPV6_DST)).ip();

        filteredSelector = DefaultTrafficSelector.builder()
                .matchEthType(Ethernet.TYPE_IPV6);
    }
    // If the prefix is different from the default via.
    if (ipPrefix.prefixLength() != 0) {
        if (ethType.ethType().toShort() == TYPE_IPV4) {
            filteredSelector.matchIPDst(ipPrefix);
        } else {
            filteredSelector.matchIPv6Dst(ipPrefix);
        }
    }

    TrafficTreatment tt = null;
    if (fwd.nextId() != null) {
        NextGroup next = flowObjectiveStore.getNextGroup(fwd.nextId());
        if (next == null) {
            log.error("next-id {} does not exist in store", fwd.nextId());
            return Collections.emptySet();
        }
        tt = appKryo.deserialize(next.data());
        if (tt == null)  {
            log.error("Error in deserializing next-id {}", fwd.nextId());
            return Collections.emptySet();
        }
    }

    FlowRule.Builder ruleBuilder = DefaultFlowRule.builder()
            .fromApp(fwd.appId())
            .withPriority(fwd.priority())
            .forDevice(deviceId)
            .withSelector(filteredSelector.build());

    if (tt != null) {
        ruleBuilder.withTreatment(tt);
    }

    if (fwd.permanent()) {
        ruleBuilder.makePermanent();
    } else {
        ruleBuilder.makeTemporary(fwd.timeout());
    }

    ruleBuilder.forTable(FIB_TABLE);
    return Collections.singletonList(ruleBuilder.build());
}
 
Example 15
Source File: NokiaOltPipeline.java    From onos with Apache License 2.0 4 votes vote down vote up
private void installDownstreamRules(ForwardingObjective fwd) {
    List<Pair<Instruction, Instruction>> vlanOps =
            vlanOps(fwd,
                    L2ModificationInstruction.L2SubType.VLAN_POP);

    if (vlanOps == null) {
        return;
    }

    Instructions.OutputInstruction output = (Instructions.OutputInstruction) fetchOutput(fwd, "downstream");

    if (output == null) {
        return;
    }

    Pair<Instruction, Instruction> popAndRewrite = vlanOps.remove(0);

    TrafficSelector selector = fwd.selector();

    Criterion outerVlan = selector.getCriterion(Criterion.Type.VLAN_VID);
    Criterion innerVlan = selector.getCriterion(Criterion.Type.INNER_VLAN_VID);
    Criterion inport = selector.getCriterion(Criterion.Type.IN_PORT);
    Criterion bullshit = Criteria.matchMetadata(output.port().toLong());

    if (outerVlan == null || innerVlan == null || inport == null) {
        log.error("Forwarding objective is underspecified: {}", fwd);
        fail(fwd, ObjectiveError.BADPARAMS);
        return;
    }

    Criterion innerVid = Criteria.matchVlanId(((VlanIdCriterion) innerVlan).vlanId());

    FlowRule.Builder outer = DefaultFlowRule.builder()
            .fromApp(fwd.appId())
            .forDevice(deviceId)
            .makePermanent()
            .withPriority(fwd.priority())
            .withSelector(buildSelector(inport, outerVlan, bullshit))
            .withTreatment(buildTreatment(popAndRewrite.getLeft(),
                    Instructions.transition(QQ_TABLE)));

    FlowRule.Builder inner = DefaultFlowRule.builder()
            .fromApp(fwd.appId())
            .forDevice(deviceId)
            .forTable(QQ_TABLE)
            .makePermanent()
            .withPriority(fwd.priority())
            .withSelector(buildSelector(inport, innerVid))
            .withTreatment(buildTreatment(popAndRewrite.getLeft(),
                                          output));

    applyRules(fwd, inner, outer);

}
 
Example 16
Source File: NokiaOltPipeline.java    From onos with Apache License 2.0 4 votes vote down vote up
@Override
public void forward(ForwardingObjective fwd) {

    if (checkForMulticast(fwd)) {
        processMulticastRule(fwd);
        return;
    }

    if (checkForEAPOL(fwd)) {
        log.warn("Discarding EAPOL flow which is not supported on this pipeline");
        return;
    }

    TrafficTreatment treatment = fwd.treatment();

    List<Instruction> instructions = treatment.allInstructions();

    Optional<Instruction> vlanIntruction = instructions.stream()
            .filter(i -> i.type() == Instruction.Type.L2MODIFICATION)
            .filter(i -> ((L2ModificationInstruction) i).subtype() ==
                    L2ModificationInstruction.L2SubType.VLAN_PUSH ||
                    ((L2ModificationInstruction) i).subtype() ==
                            L2ModificationInstruction.L2SubType.VLAN_POP)
            .findAny();

    if (vlanIntruction.isPresent()) {
        L2ModificationInstruction vlanIns =
                (L2ModificationInstruction) vlanIntruction.get();

        if (vlanIns.subtype() == L2ModificationInstruction.L2SubType.VLAN_PUSH) {
            installUpstreamRules(fwd);
        } else if (vlanIns.subtype() == L2ModificationInstruction.L2SubType.VLAN_POP) {
            installDownstreamRules(fwd);
        } else {
            log.error("Unknown OLT operation: {}", fwd);
            fail(fwd, ObjectiveError.UNSUPPORTED);
            return;
        }

        pass(fwd);
    } else {
        TrafficSelector selector = fwd.selector();

        if (fwd.treatment() != null) {
            // Deal with SPECIFIC and VERSATILE in the same manner.
            FlowRule.Builder ruleBuilder = DefaultFlowRule.builder()
                    .forDevice(deviceId)
                    .withSelector(selector)
                    .fromApp(fwd.appId())
                    .withPriority(fwd.priority())
                    .withTreatment(fwd.treatment());

            if (fwd.permanent()) {
                ruleBuilder.makePermanent();
            } else {
                ruleBuilder.makeTemporary(fwd.timeout());
            }
            installObjective(ruleBuilder, fwd);

        } else {
            log.error("No treatment error: {}", fwd);
            fail(fwd, ObjectiveError.UNSUPPORTED);
        }
    }

}
 
Example 17
Source File: Ofdpa2Pipeline.java    From onos with Apache License 2.0 4 votes vote down vote up
/**
 * Handles forwarding rules to the L2 bridging table. Flow actions are not
 * allowed in the bridging table - instead we use L2 Interface group or
 * L2 flood group
 *
 * @param fwd the forwarding objective
 * @return A collection of flow rules, or an empty set
 */
protected Collection<FlowRule> processEthDstSpecific(ForwardingObjective fwd) {
    List<FlowRule> rules = new ArrayList<>();

    // Build filtered selector
    TrafficSelector selector = fwd.selector();
    EthCriterion ethCriterion = (EthCriterion) selector
            .getCriterion(Criterion.Type.ETH_DST);
    VlanIdCriterion vlanIdCriterion = (VlanIdCriterion) selector
            .getCriterion(Criterion.Type.VLAN_VID);

    if (vlanIdCriterion == null) {
        log.warn("Forwarding objective for bridging requires vlan. Not "
                + "installing fwd:{} in dev:{}", fwd.id(), deviceId);
        fail(fwd, ObjectiveError.BADPARAMS);
        return Collections.emptySet();
    }

    TrafficSelector.Builder filteredSelectorBuilder =
            DefaultTrafficSelector.builder();

    if (!ethCriterion.mac().equals(NONE) &&
            !ethCriterion.mac().equals(BROADCAST)) {
        filteredSelectorBuilder.matchEthDst(ethCriterion.mac());
        log.debug("processing L2 forwarding objective:{} -> next:{} in dev:{}",
                  fwd.id(), fwd.nextId(), deviceId);
    } else {
        // Use wildcard DST_MAC if the MacAddress is None or Broadcast
        log.debug("processing L2 Broadcast forwarding objective:{} -> next:{} "
                + "in dev:{} for vlan:{}",
                  fwd.id(), fwd.nextId(), deviceId, vlanIdCriterion.vlanId());
    }
    if (requireVlanExtensions()) {
        OfdpaMatchVlanVid ofdpaMatchVlanVid = new OfdpaMatchVlanVid(vlanIdCriterion.vlanId());
        filteredSelectorBuilder.extension(ofdpaMatchVlanVid, deviceId);
    } else {
        filteredSelectorBuilder.matchVlanId(vlanIdCriterion.vlanId());
    }
    TrafficSelector filteredSelector = filteredSelectorBuilder.build();

    if (fwd.treatment() != null) {
        log.warn("Ignoring traffic treatment in fwd rule {} meant for L2 table"
                + "for dev:{}. Expecting only nextId", fwd.id(), deviceId);
    }

    TrafficTreatment.Builder treatmentBuilder = DefaultTrafficTreatment.builder();
    if (fwd.nextId() != null) {
        NextGroup next = getGroupForNextObjective(fwd.nextId());
        if (next != null) {
            List<Deque<GroupKey>> gkeys = appKryo.deserialize(next.data());
            // we only need the top level group's key to point the flow to it
            Group group = groupService.getGroup(deviceId, gkeys.get(0).peekFirst());
            if (group != null) {
                treatmentBuilder.deferred().group(group.id());
            } else {
                log.warn("Group with key:{} for next-id:{} not found in dev:{}",
                         gkeys.get(0).peekFirst(), fwd.nextId(), deviceId);
                fail(fwd, ObjectiveError.GROUPMISSING);
                return Collections.emptySet();
            }
        }
    }
    treatmentBuilder.immediate().transition(ACL_TABLE);
    TrafficTreatment filteredTreatment = treatmentBuilder.build();

    // Build bridging table entries
    FlowRule.Builder flowRuleBuilder = DefaultFlowRule.builder();
    flowRuleBuilder.fromApp(fwd.appId())
            .withPriority(fwd.priority())
            .forDevice(deviceId)
            .withSelector(filteredSelector)
            .withTreatment(filteredTreatment)
            .forTable(BRIDGING_TABLE);
    if (fwd.permanent()) {
        flowRuleBuilder.makePermanent();
    } else {
        flowRuleBuilder.makeTemporary(fwd.timeout());
    }
    rules.add(flowRuleBuilder.build());
    return rules;
}
 
Example 18
Source File: Ofdpa2Pipeline.java    From onos with Apache License 2.0 4 votes vote down vote up
private int buildIpv4Selector(TrafficSelector.Builder builderToUpdate,
                                TrafficSelector.Builder extBuilder,
                                ForwardingObjective fwd,
                                boolean allowDefaultRoute) {
    TrafficSelector selector = fwd.selector();

    IpPrefix ipv4Dst = ((IPCriterion) selector.getCriterion(Criterion.Type.IPV4_DST)).ip();
    if (ipv4Dst.isMulticast()) {
        if (ipv4Dst.prefixLength() != 32) {
            log.warn("Multicast specific forwarding objective can only be /32");
            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_IPV4).matchIPDst(ipv4Dst);
        log.debug("processing IPv4 multicast specific forwarding objective {} -> next:{}"
                          + " in dev:{}", fwd.id(), fwd.nextId(), deviceId);
    } else {
        if (ipv4Dst.prefixLength() == 0) {
            if (allowDefaultRoute) {
                // The entire IPV4_DST field is wildcarded intentionally
                builderToUpdate.matchEthType(Ethernet.TYPE_IPV4);
            } else {
                // NOTE: The switch does not support matching 0.0.0.0/0
                // Split it into 0.0.0.0/1 and 128.0.0.0/1
                builderToUpdate.matchEthType(Ethernet.TYPE_IPV4)
                        .matchIPDst(IpPrefix.valueOf("0.0.0.0/1"));
                extBuilder.matchEthType(Ethernet.TYPE_IPV4)
                        .matchIPDst(IpPrefix.valueOf("128.0.0.0/1"));
            }
        } else {
            builderToUpdate.matchEthType(Ethernet.TYPE_IPV4).matchIPDst(ipv4Dst);
        }
        log.debug("processing IPv4 unicast specific forwarding objective {} -> next:{}"
                          + " in dev:{}", fwd.id(), fwd.nextId(), deviceId);
    }
    return 0;
}
 
Example 19
Source File: OvsOfdpaPipeline.java    From onos with Apache License 2.0 4 votes vote down vote up
@Override
protected Collection<FlowRule> processEthDstSpecific(ForwardingObjective fwd) {
    List<FlowRule> rules = new ArrayList<>();

    // Build filtered selector
    TrafficSelector selector = fwd.selector();
    EthCriterion ethCriterion = (EthCriterion) selector
            .getCriterion(Criterion.Type.ETH_DST);
    VlanIdCriterion vlanIdCriterion = (VlanIdCriterion) selector
            .getCriterion(VLAN_VID);

    if (vlanIdCriterion == null) {
        log.warn("Forwarding objective for bridging requires vlan. Not "
                + "installing fwd:{} in dev:{}", fwd.id(), deviceId);
        fail(fwd, ObjectiveError.BADPARAMS);
        return Collections.emptySet();
    }

    TrafficSelector.Builder filteredSelectorBuilder =
            DefaultTrafficSelector.builder();
    // Do not match MacAddress for subnet broadcast entry
    if (!ethCriterion.mac().equals(NONE) && !ethCriterion.mac().equals(BROADCAST)) {
        filteredSelectorBuilder.matchEthDst(ethCriterion.mac());
        log.debug("processing L2 forwarding objective:{} -> next:{} in dev:{}",
                fwd.id(), fwd.nextId(), deviceId);
    } else {
        log.debug("processing L2 Broadcast forwarding objective:{} -> next:{} "
                        + "in dev:{} for vlan:{}",
                fwd.id(), fwd.nextId(), deviceId, vlanIdCriterion.vlanId());
    }
    filteredSelectorBuilder.matchVlanId(vlanIdCriterion.vlanId());
    TrafficSelector filteredSelector = filteredSelectorBuilder.build();

    if (fwd.treatment() != null) {
        log.warn("Ignoring traffic treatment in fwd rule {} meant for L2 table"
                + "for dev:{}. Expecting only nextId", fwd.id(), deviceId);
    }

    TrafficTreatment.Builder treatmentBuilder = DefaultTrafficTreatment.builder();
    if (fwd.nextId() != null) {
        NextGroup next = getGroupForNextObjective(fwd.nextId());
        if (next != null) {
            List<Deque<GroupKey>> gkeys = appKryo.deserialize(next.data());
            // we only need the top level group's key to point the flow to it
            Group group = groupService.getGroup(deviceId, gkeys.get(0).peekFirst());
            if (group != null) {
                treatmentBuilder.deferred().group(group.id());
            } else {
                log.warn("Group with key:{} for next-id:{} not found in dev:{}",
                        gkeys.get(0).peekFirst(), fwd.nextId(), deviceId);
                fail(fwd, ObjectiveError.GROUPMISSING);
                return Collections.emptySet();
            }
        }
    }
    treatmentBuilder.immediate().transition(ACL_TABLE);
    TrafficTreatment filteredTreatment = treatmentBuilder.build();

    // Build bridging table entries
    FlowRule.Builder flowRuleBuilder = DefaultFlowRule.builder();
    flowRuleBuilder.fromApp(fwd.appId())
            .withPriority(fwd.priority())
            .forDevice(deviceId)
            .withSelector(filteredSelector)
            .withTreatment(filteredTreatment)
            .forTable(BRIDGING_TABLE);
    if (fwd.permanent()) {
        flowRuleBuilder.makePermanent();
    } else {
        flowRuleBuilder.makeTemporary(fwd.timeout());
    }
    rules.add(flowRuleBuilder.build());
    return rules;
}
 
Example 20
Source File: OvsOfdpaPipeline.java    From onos with Apache License 2.0 4 votes vote down vote up
/**
 * Handles forwarding rules to the IP Unicast Routing.
 *
 * @param fwd the forwarding objective
 * @return A collection of flow rules, or an empty set
 */
protected Collection<FlowRule> processDoubleTaggedFwd(ForwardingObjective fwd) {
    // inner for UNICAST_ROUTING_TABLE_1, outer for UNICAST_ROUTING_TABLE
    TrafficSelector selector = fwd.selector();
    TrafficSelector.Builder sBuilder = DefaultTrafficSelector.builder();
    TrafficTreatment.Builder innerTtb = DefaultTrafficTreatment.builder();
    TrafficTreatment.Builder outerTtb = DefaultTrafficTreatment.builder();

    EthTypeCriterion ethType =
            (EthTypeCriterion) selector.getCriterion(Criterion.Type.ETH_TYPE);

    if (ethType.ethType().toShort() == Ethernet.TYPE_IPV4) {
        sBuilder.matchEthType(Ethernet.TYPE_IPV4);
        sBuilder.matchVlanId(VlanId.ANY);
        IpPrefix ipv4Dst = ((IPCriterion) selector.getCriterion(Criterion.Type.IPV4_DST)).ip();
        if (!ipv4Dst.isMulticast() && ipv4Dst.prefixLength() == 32) {
            sBuilder.matchIPDst(ipv4Dst);
            if (fwd.nextId() != null) {
                NextGroup next = getGroupForNextObjective(fwd.nextId());
                if (next != null) {
                    List<Deque<GroupKey>> gkeys = appKryo.deserialize(next.data());
                    // we only need the top level group's key to point the flow to it
                    Group group = groupService.getGroup(deviceId, gkeys.get(0).peekFirst());
                    if (group == null) {
                        log.warn("Group with key:{} for next-id:{} not found in dev:{}",
                                 gkeys.get(0).peekFirst(), fwd.nextId(), deviceId);
                        fail(fwd, ObjectiveError.GROUPMISSING);
                        return Collections.emptySet();
                    }
                    outerTtb.immediate().setVlanId(extractDummyVlanIdFromGroupId(group.id().id()));
                    //ACTSET_OUTPUT in OVS will match output action in write_action() set.
                    outerTtb.deferred().setOutput(extractOutputPortFromGroupId(group.id().id()));
                    outerTtb.transition(EGRESS_VLAN_FLOW_TABLE_IN_INGRESS);
                    innerTtb.deferred().group(group.id());
                    innerTtb.transition(ACL_TABLE);

                    FlowRule.Builder innerRuleBuilder = DefaultFlowRule.builder()
                            .fromApp(fwd.appId())
                            .withPriority(fwd.priority())
                            .forDevice(deviceId)
                            .withSelector(sBuilder.build())
                            .withTreatment(innerTtb.build())
                            .forTable(UNICAST_ROUTING_TABLE_1);
                    if (fwd.permanent()) {
                        innerRuleBuilder.makePermanent();
                    } else {
                        innerRuleBuilder.makeTemporary(fwd.timeout());
                    }
                    Collection<FlowRule> flowRuleCollection = new HashSet<>();
                    flowRuleCollection.add(innerRuleBuilder.build());

                    FlowRule.Builder outerRuleBuilder = DefaultFlowRule.builder()
                            .fromApp(fwd.appId())
                            .withPriority(fwd.priority())
                            .forDevice(deviceId)
                            .withSelector(sBuilder.build())
                            .withTreatment(outerTtb.build())
                            .forTable(UNICAST_ROUTING_TABLE);
                    if (fwd.permanent()) {
                        outerRuleBuilder.makePermanent();
                    } else {
                        outerRuleBuilder.makeTemporary(fwd.timeout());
                    }
                    flowRuleCollection.add(innerRuleBuilder.build());
                    flowRuleCollection.add(outerRuleBuilder.build());
                    return flowRuleCollection;
                } else {
                    log.warn("Cannot find group for nextId:{} in dev:{}. Aborting fwd:{}",
                             fwd.nextId(), deviceId, fwd.id());
                    fail(fwd, ObjectiveError.FLOWINSTALLATIONFAILED);
                    return Collections.emptySet();
                }
            } else {
                log.warn("NextId is not specified in fwd:{}", fwd.id());
                fail(fwd, ObjectiveError.FLOWINSTALLATIONFAILED);
                return Collections.emptySet();
            }
        }
    }
    return Collections.emptySet();
}