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

The following examples show how to use org.onosproject.net.flowobjective.ForwardingObjective#nextId() . 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: OvsOfdpaPipeline.java    From onos with Apache License 2.0 6 votes vote down vote up
/**
 * Determines if the forwarding objective will be used for double-tagged packets.
 *
 * @param fwd Forwarding objective
 * @return True if the objective was created for double-tagged packets, false otherwise.
 */
private boolean isDoubleTagged(ForwardingObjective fwd) {
    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
            Group group = groupService.getGroup(deviceId, gkeys.get(0).peekFirst());
            if (group != null) {
                int groupId = group.id().id();
                if (((groupId & ~TYPE_MASK) == L3_UNICAST_TYPE) &&
                        ((groupId & TYPE_L3UG_DOUBLE_VLAN_MASK) == TYPE_L3UG_DOUBLE_VLAN_MASK)) {
                    return true;
                }
            }
        }
    }
    return false;
}
 
Example 2
Source File: ForwardingObjectiveTranslator.java    From onos with Apache License 2.0 6 votes vote down vote up
private static TrafficTreatment nextIdOrTreatment(
        ForwardingObjective obj, PiTableId tableId)
        throws FabricPipelinerException {
    if (obj.nextId() == null) {
        return obj.treatment();
    } else {
        if (!NEXT_ID_ACTIONS.containsKey(tableId)) {
            throw new FabricPipelinerException(format(
                    "BUG? no next_id action set for table %s", tableId));
        }
        return DefaultTrafficTreatment.builder()
                .piTableAction(
                        setNextIdAction(obj.nextId(),
                                        NEXT_ID_ACTIONS.get(tableId)))
                .build();
    }
}
 
Example 3
Source File: ForwardingObjectiveCodec.java    From onos with Apache License 2.0 5 votes vote down vote up
@Override
public ObjectNode encode(ForwardingObjective forwardingObjective, CodecContext context) {

    checkNotNull(forwardingObjective, NOT_NULL_MESSAGE);

    final JsonCodec<TrafficTreatment> trafficTreatmentCodec = context.codec(TrafficTreatment.class);
    final JsonCodec<TrafficSelector> trafficSelectorCodec = context.codec(TrafficSelector.class);

    // encode common properties
    ObjectiveCodecHelper och = new ObjectiveCodecHelper();
    ObjectNode result = och.encode(forwardingObjective, context);

    // encode id
    result.put(ID, forwardingObjective.id());

    // encode flag
    result.put(FLAG, forwardingObjective.flag().toString());

    // encode op
    result.put(OPERATION, forwardingObjective.op().toString());

    // encode selector
    ObjectNode trafficSelectorNode =
            trafficSelectorCodec.encode(forwardingObjective.selector(), context);
    result.set(SELECTOR, trafficSelectorNode);

    // encode nextId
    if (forwardingObjective.nextId() != null) {
        result.put(NEXT_ID, forwardingObjective.nextId());
    }

    // encode treatment
    if (forwardingObjective.treatment() != null) {
        ObjectNode trafficTreatmentNode =
                trafficTreatmentCodec.encode(forwardingObjective.treatment(), context);
        result.set(TREATMENT, trafficTreatmentNode);
    }

    return result;
}
 
Example 4
Source File: FlowObjectiveManager.java    From onos with Apache License 2.0 5 votes vote down vote up
@Override
public void forward(DeviceId deviceId, ForwardingObjective forwardingObjective) {
    checkPermission(FLOWRULE_WRITE);
    if (forwardingObjective.nextId() == null ||
            flowObjectiveStore.getNextGroup(forwardingObjective.nextId()) != null ||
            !queueFwdObjective(deviceId, forwardingObjective)) {
        // fast path
        installerExecutor.execute(new ObjectiveProcessor(deviceId, forwardingObjective, installerExecutor));
    }
}
 
Example 5
Source File: FlowObjectiveCompositionManager.java    From onos with Apache License 2.0 5 votes vote down vote up
private boolean queueObjective(DeviceId deviceId, ForwardingObjective fwd) {
    if (fwd.nextId() != null &&
            flowObjectiveStore.getNextGroup(fwd.nextId()) == null) {
        log.trace("Queuing forwarding objective for nextId {}", fwd.nextId());
        if (pendingForwards.putIfAbsent(fwd.nextId(),
                Sets.newHashSet(new PendingNext(deviceId, fwd))) != null) {
            Set<PendingNext> pending = pendingForwards.get(fwd.nextId());
            pending.add(new PendingNext(deviceId, fwd));
        }
        return true;
    }
    return false;
}
 
Example 6
Source File: VirtualNetworkFlowObjectiveManager.java    From onos with Apache License 2.0 5 votes vote down vote up
@Override
public void forward(DeviceId deviceId, ForwardingObjective forwardingObjective) {
    if (forwardingObjective.nextId() == null ||
            forwardingObjective.op() == Objective.Operation.REMOVE ||
            flowObjectiveStore.getNextGroup(forwardingObjective.nextId()) != null ||
            !queueFwdObjective(deviceId, forwardingObjective)) {
        // fast path
        executorService.execute(new ObjectiveInstaller(deviceId, forwardingObjective));
    }
}
 
Example 7
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 8
Source File: AbstractCorsaPipeline.java    From onos with Apache License 2.0 4 votes vote down vote up
private Collection<FlowRule> processSpecificRoute(ForwardingObjective fwd) {
    TrafficSelector filteredSelector =
            DefaultTrafficSelector.builder()
                    .matchEthType(Ethernet.TYPE_IPV4)
                    .matchIPDst(
                            ((IPCriterion) fwd.selector().getCriterion(Criterion.Type.IPV4_DST)).ip())
                    .build();

    TrafficTreatment.Builder tb = processSpecificRoutingTreatment();

    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 ImmutableSet.of();
        }
        tb.group(group.id());
    } else {
        log.error("Missing NextObjective ID for ForwardingObjective {}", fwd.id());
        fail(fwd, ObjectiveError.BADPARAMS);
        return ImmutableSet.of();
    }
    Builder ruleBuilder = DefaultFlowRule.builder()
            .fromApp(fwd.appId())
            .withPriority(fwd.priority())
            .forDevice(deviceId)
            .withSelector(filteredSelector)
            .withTreatment(tb.build());

    ruleBuilder = processSpecificRoutingRule(ruleBuilder);

    if (fwd.permanent()) {
        ruleBuilder.makePermanent();
    } else {
        ruleBuilder.makeTemporary(fwd.timeout());
    }
    return Collections.singletonList(ruleBuilder.build());
}
 
Example 9
Source File: PicaPipeline.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();
    }

    List<FlowRule> ipflows = new ArrayList<FlowRule>();
    for (Filter f: filters) {
        TrafficSelector filteredSelector =
                DefaultTrafficSelector.builder()
                .matchEthType(Ethernet.TYPE_IPV4)
                .matchIPDst(
                            ((IPCriterion)
                                    selector.getCriterion(Criterion.Type.IPV4_DST)).ip())
                .matchEthDst(f.mac())
                .matchVlanId(f.vlanId())
                .build();
        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)
                .withTreatment(tt);
        if (fwd.permanent()) {
            ruleBuilder.makePermanent();
        } else {
            ruleBuilder.makeTemporary(fwd.timeout());
        }
        ruleBuilder.forTable(IP_UNICAST_TABLE);
        ipflows.add(ruleBuilder.build());
    }

    return ipflows;
}
 
Example 10
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 11
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 12
Source File: Ofdpa2Pipeline.java    From onos with Apache License 2.0 4 votes vote down vote up
/**
 * Helper function to create traffic treatment builder for versatile forwarding objectives.
 *
 * @param fwd original forwarding objective
 * @return treatment builder for the flow rule, or null if there is an error.
 */
protected TrafficTreatment.Builder versatileTreatmentBuilder(ForwardingObjective fwd) {
    // XXX driver does not currently do type checking as per Tables 65-67 in
    // OFDPA 2.0 spec. The only allowed treatment is a punt to the controller.
    TrafficTreatment.Builder ttBuilder = DefaultTrafficTreatment.builder();
    if (fwd.treatment() != null) {
        for (Instruction ins : fwd.treatment().allInstructions()) {
            if (ins instanceof OutputInstruction) {
                OutputInstruction o = (OutputInstruction) ins;
                if (PortNumber.CONTROLLER.equals(o.port())) {
                    ttBuilder.add(o);
                } else {
                    log.warn("Only allowed treatments in versatile forwarding "
                            + "objectives are punts to the controller");
                }
            } else if (ins instanceof NoActionInstruction) {
                // No action is allowed and nothing needs to be done
            } else {
                log.warn("Cannot process instruction in versatile fwd {}", ins);
            }
        }
        if (fwd.treatment().clearedDeferred()) {
            ttBuilder.wipeDeferred();
        }
    }
    if (fwd.nextId() != null) {
        // Override case
        NextGroup next = getGroupForNextObjective(fwd.nextId());
        if (next == null) {
            fail(fwd, ObjectiveError.BADPARAMS);
            return 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 null;
        }
        ttBuilder.deferred().group(group.id());
    }
    return ttBuilder;
}
 
Example 13
Source File: Ofdpa2Pipeline.java    From onos with Apache License 2.0 4 votes vote down vote up
/**
 * In the OF-DPA 2.0 pipeline, versatile forwarding objectives go to the
 * ACL table.
 * @param fwd  the forwarding objective of type 'versatile'
 * @return     a collection of flow rules to be sent to the switch. An empty
 *             collection may be returned if there is a problem in processing
 *             the flow rule
 */
protected Collection<FlowRule> processVersatile(ForwardingObjective fwd) {
    log.debug("Processing versatile forwarding objective:{} in dev:{}",
             fwd.id(), deviceId);
    List<FlowRule> flowRules = new ArrayList<>();
    final AtomicBoolean ethTypeUsed  = new AtomicBoolean(false);

    if (fwd.nextId() == null && fwd.treatment() == null) {
        log.error("Forwarding objective {} from {} must contain "
                + "nextId or Treatment", fwd.selector(), fwd.appId());
        fail(fwd, ObjectiveError.BADPARAMS);
        return Collections.emptySet();
    }

    TrafficSelector.Builder sbuilder = DefaultTrafficSelector.builder();
    fwd.selector().criteria().forEach(criterion -> {
        if (criterion instanceof VlanIdCriterion) {
            VlanId vlanId = ((VlanIdCriterion) criterion).vlanId();
            // ensure that match does not include vlan = NONE as OF-DPA does not
            // match untagged packets this way in the ACL table.
            if (vlanId.equals(VlanId.NONE)) {
                return;
            }
            if (requireVlanExtensions()) {
                OfdpaMatchVlanVid ofdpaMatchVlanVid = new OfdpaMatchVlanVid(vlanId);
                sbuilder.extension(ofdpaMatchVlanVid, deviceId);
            } else {
                sbuilder.matchVlanId(vlanId);
            }
        } else if (criterion instanceof Icmpv6TypeCriterion) {
            byte icmpv6Type = (byte) ((Icmpv6TypeCriterion) criterion).icmpv6Type();
            sbuilder.matchIcmpv6Type(icmpv6Type);
        } else if (criterion instanceof Icmpv6CodeCriterion) {
            byte icmpv6Code = (byte) ((Icmpv6CodeCriterion) criterion).icmpv6Code();
            sbuilder.matchIcmpv6Type(icmpv6Code);
        } else if (criterion instanceof TcpPortCriterion || criterion instanceof UdpPortCriterion) {
            // FIXME: QMX switches do not support L4 dst port matching in ACL table.
            // Currently L4 dst port matching is only used by DHCP relay feature
            // and therefore is safe to be replaced with L4 src port matching.
            // We need to revisit this if L4 dst port is used for other purpose in the future.
            if (!supportIpv6L4Dst() && isIpv6(fwd.selector())) {
                switch (criterion.type()) {
                    case UDP_DST:
                    case UDP_DST_MASKED:
                    case TCP_DST:
                    case TCP_DST_MASKED:
                        break;
                    default:
                        sbuilder.add(criterion);
                }
            } else {
                sbuilder.add(criterion);
            }
        } else if (criterion instanceof EthTypeCriterion) {
            sbuilder.add(criterion);
            ethTypeUsed.set(true);
        } else {
            sbuilder.add(criterion);
        }
    });

    TrafficTreatment.Builder ttBuilder = versatileTreatmentBuilder(fwd);
    if (ttBuilder == null) {
        return Collections.emptySet();
    }

    FlowRule.Builder ruleBuilder = DefaultFlowRule.builder()
            .fromApp(fwd.appId())
            .withPriority(fwd.priority())
            .forDevice(deviceId)
            .withSelector(sbuilder.build())
            .withTreatment(ttBuilder.build())
            .makePermanent()
            .forTable(ACL_TABLE);

    flowRules.add(ruleBuilder.build());

    if (!ethTypeUsed.get() && requireEthType()) {
        log.debug("{} doesn't match on ethType but requireEthType is true, adding complementary ACL flow.",
                  sbuilder.toString());
        sbuilder.matchEthType(Ethernet.TYPE_IPV6);
        FlowRule.Builder ethTypeRuleBuilder = DefaultFlowRule.builder()
                .fromApp(fwd.appId())
                .withPriority(fwd.priority())
                .forDevice(deviceId)
                .withSelector(sbuilder.build())
                .withTreatment(ttBuilder.build())
                .makePermanent()
                .forTable(ACL_TABLE);
        flowRules.add(ethTypeRuleBuilder.build());
    }
    return flowRules;
}
 
Example 14
Source File: OvsOfdpaPipeline.java    From onos with Apache License 2.0 4 votes vote down vote up
@Override
protected TrafficTreatment.Builder versatileTreatmentBuilder(ForwardingObjective fwd) {
    // XXX driver does not currently do type checking as per Tables 65-67 in
    // OFDPA 2.0 spec. The only allowed treatment is a punt to the controller.
    TrafficTreatment.Builder ttBuilder = DefaultTrafficTreatment.builder();
    if (fwd.treatment() != null) {
        for (Instruction ins : fwd.treatment().allInstructions()) {
            if (ins instanceof OutputInstruction) {
                OutputInstruction o = (OutputInstruction) ins;
                if (PortNumber.CONTROLLER.equals(o.port())) {
                    ttBuilder.transition(PUNT_TABLE);
                } else {
                    log.warn("Only allowed treatments in versatile forwarding "
                            + "objectives are punts to the controller");
                }
            } else if (ins instanceof NoActionInstruction) {
                // No action is allowed and nothing needs to be done
            } else {
                log.warn("Cannot process instruction in versatile fwd {}", ins);
            }
        }
        if (fwd.treatment().clearedDeferred()) {
            ttBuilder.wipeDeferred();
        }
    }
    if (fwd.nextId() != null) {
        // Override case
        NextGroup next = getGroupForNextObjective(fwd.nextId());
        if (next == null) {
            fail(fwd, ObjectiveError.BADPARAMS);
            return 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 null;
        }
        ttBuilder.deferred().group(group.id());
    }
    return ttBuilder;
}
 
Example 15
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 16
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();
}
 
Example 17
Source File: Ofdpa3Pipeline.java    From onos with Apache License 2.0 4 votes vote down vote up
private Collection<FlowRule> processTermPwVersatile(ForwardingObjective forwardingObjective,
                                                    ModTunnelIdInstruction modTunnelIdInstruction,
                                                    OutputInstruction outputInstruction) {
    TrafficTreatment.Builder flowTreatment;
    TrafficSelector.Builder flowSelector;
    // We divide the mpls actions from the tunnel actions. We need
    // this to order the actions in the final treatment.
    TrafficTreatment.Builder mplsTreatment = DefaultTrafficTreatment.builder();
    createMplsTreatment(forwardingObjective.treatment(), mplsTreatment);
    // The match of the forwarding objective is ready to go.
    flowSelector = DefaultTrafficSelector.builder(forwardingObjective.selector());
    // We verify the tunnel id and mpls port are correct.
    long tunnelId = MPLS_TUNNEL_ID_BASE | modTunnelIdInstruction.tunnelId();
    if (tunnelId > MPLS_TUNNEL_ID_MAX) {
        log.error("Pw Versatile Forwarding Objective must include tunnel id < {}",
                  MPLS_TUNNEL_ID_MAX);
        fail(forwardingObjective, ObjectiveError.BADPARAMS);
        return Collections.emptySet();
    }
    // 0x0002XXXX is NNI interface.
    int mplsLogicalPort = ((int) outputInstruction.port().toLong()) | MPLS_NNI_PORT_BASE;
    if (mplsLogicalPort > MPLS_NNI_PORT_MAX) {
        log.error("Pw Versatile Forwarding Objective invalid logical port {}",
                  mplsLogicalPort);
        fail(forwardingObjective, ObjectiveError.BADPARAMS);
        return Collections.emptySet();
    }
    // Next id cannot be null.
    if (forwardingObjective.nextId() == null) {
        log.error("Pw Versatile Forwarding Objective must contain nextId ",
                  forwardingObjective.nextId());
        fail(forwardingObjective, ObjectiveError.BADPARAMS);
        return Collections.emptySet();
    }
    // We retrieve the l2 interface group and point the mpls
    // flow to this.
    NextGroup next = getGroupForNextObjective(forwardingObjective.nextId());
    if (next == null) {
        log.warn("next-id:{} not found in dev:{}", forwardingObjective.nextId(), deviceId);
        fail(forwardingObjective, ObjectiveError.GROUPMISSING);
        return Collections.emptySet();
    }
    List<Deque<GroupKey>> gkeys = appKryo.deserialize(next.data());
    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(), forwardingObjective.nextId(), deviceId);
        fail(forwardingObjective, ObjectiveError.GROUPMISSING);
        return Collections.emptySet();
    }
    // We prepare the treatment for the mpls flow table.
    // The order of the actions has to be strictly this
    // according to the OFDPA 2.0 specification.
    flowTreatment = DefaultTrafficTreatment.builder(mplsTreatment.build());
    flowTreatment.extension(new Ofdpa3PopCw(), deviceId);
    // Even though the specification and the xml/json files
    // specify is allowed, the switch rejects the flow. In the
    // OFDPA 3.0 EA0 version was necessary
    //flowTreatment.popVlan();
    flowTreatment.extension(new Ofdpa3PopL2Header(), deviceId);
    flowTreatment.setTunnelId(tunnelId);
    flowTreatment.extension(new Ofdpa3SetMplsL2Port(mplsLogicalPort), deviceId);
    flowTreatment.extension(new Ofdpa3SetMplsType(VPWS), deviceId);
    flowTreatment.transition(MPLS_TYPE_TABLE);
    flowTreatment.deferred().group(group.id());
    // We prepare the flow rule for the mpls table.
    FlowRule.Builder ruleBuilder = DefaultFlowRule.builder()
            .fromApp(forwardingObjective.appId())
            .withPriority(forwardingObjective.priority())
            .forDevice(deviceId)
            .withSelector(flowSelector.build())
            .withTreatment(flowTreatment.build())
            .makePermanent()
            .forTable(MPLS_TABLE_1);
    return Collections.singletonList(ruleBuilder.build());
}