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

The following examples show how to use org.onosproject.net.flowobjective.ForwardingObjective#permanent() . 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: Ofdpa2Pipeline.java    From onos with Apache License 2.0 6 votes vote down vote up
FlowRule defaultRoute(ForwardingObjective fwd,
                                TrafficSelector.Builder complementarySelector,
                                int forTableId,
                                TrafficTreatment.Builder tb) {
    FlowRule.Builder rule = DefaultFlowRule.builder()
            .fromApp(fwd.appId())
            .withPriority(fwd.priority())
            .forDevice(deviceId)
            .withSelector(complementarySelector.build())
            .withTreatment(tb.build())
            .forTable(forTableId);
    if (fwd.permanent()) {
        rule.makePermanent();
    } else {
        rule.makeTemporary(fwd.timeout());
    }
    return rule.build();
}
 
Example 2
Source File: JuniperQfx5100Pipeliner.java    From onos with Apache License 2.0 6 votes vote down vote up
private FlowRule processForward(ForwardingObjective fwd) {

        FlowRule.Builder ruleBuilder = DefaultFlowRule.builder()
                .forDevice(deviceId)
                .withSelector(fwd.selector())
                .withTreatment(fwd.treatment())
                .withPriority(fwd.priority())
                .fromApp(fwd.appId())
                .forTable(DEFAULT_TABLE);
        if (fwd.permanent()) {
            ruleBuilder.makePermanent();
        } else {
            ruleBuilder.makeTemporary(fwd.timeout());
        }

        return ruleBuilder.build();

    }
 
Example 3
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 4
Source File: BasicPipelinerImpl.java    From onos with Apache License 2.0 5 votes vote down vote up
@Override
public void forward(ForwardingObjective obj) {
    if (obj.treatment() == null) {
        obj.context().ifPresent(c -> c.onError(obj, ObjectiveError.UNSUPPORTED));
    }

    // Simply create an equivalent FlowRule for table 0.
    final FlowRule.Builder ruleBuilder = DefaultFlowRule.builder()
            .forTable(INGRESS_TABLE0_CONTROL_TABLE0)
            .forDevice(deviceId)
            .withSelector(obj.selector())
            .fromApp(obj.appId())
            .withPriority(obj.priority())
            .withTreatment(obj.treatment());

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

    switch (obj.op()) {
        case ADD:
            flowRuleService.applyFlowRules(ruleBuilder.build());
            break;
        case REMOVE:
            flowRuleService.removeFlowRules(ruleBuilder.build());
            break;
        default:
            log.warn("Unknown operation {}", obj.op());
    }

    obj.context().ifPresent(c -> c.onSuccess(obj));
}
 
Example 5
Source File: PipelinerImpl.java    From ngsdn-tutorial with Apache License 2.0 4 votes vote down vote up
@Override
public void forward(ForwardingObjective obj) {
    if (obj.treatment() == null) {
        obj.context().ifPresent(c -> c.onError(obj, ObjectiveError.UNSUPPORTED));
    }

    // Whether this objective specifies an OUTPUT:CONTROLLER instruction.
    final boolean hasCloneToCpuAction = obj.treatment()
            .allInstructions().stream()
            .filter(i -> i.type().equals(OUTPUT))
            .map(i -> (Instructions.OutputInstruction) i)
            .anyMatch(i -> i.port().equals(PortNumber.CONTROLLER));

    if (!hasCloneToCpuAction) {
        // We support only objectives for clone to CPU behaviours (e.g. for
        // host and link discovery)
        obj.context().ifPresent(c -> c.onError(obj, ObjectiveError.UNSUPPORTED));
    }

    // Create an equivalent FlowRule with same selector and clone_to_cpu action.
    final PiAction cloneToCpuAction = PiAction.builder()
            .withId(PiActionId.of(CLONE_TO_CPU))
            .build();

    final FlowRule.Builder ruleBuilder = DefaultFlowRule.builder()
            .forTable(PiTableId.of(ACL_TABLE))
            .forDevice(deviceId)
            .withSelector(obj.selector())
            .fromApp(obj.appId())
            .withPriority(obj.priority())
            .withTreatment(DefaultTrafficTreatment.builder()
                                   .piTableAction(cloneToCpuAction).build());

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

    final GroupDescription cloneGroup = Utils.buildCloneGroup(
            obj.appId(),
            deviceId,
            CPU_CLONE_SESSION_ID,
            // Ports where to clone the packet.
            // Just controller in this case.
            Collections.singleton(PortNumber.CONTROLLER));

    switch (obj.op()) {
        case ADD:
            flowRuleService.applyFlowRules(ruleBuilder.build());
            groupService.addGroup(cloneGroup);
            break;
        case REMOVE:
            flowRuleService.removeFlowRules(ruleBuilder.build());
            groupService.removeGroup(deviceId, cloneGroup.appCookie(), obj.appId());
            break;
        default:
            log.warn("Unknown operation {}", obj.op());
    }

    obj.context().ifPresent(c -> c.onSuccess(obj));
}
 
Example 6
Source File: PipelinerImpl.java    From onos-p4-tutorial with Apache License 2.0 4 votes vote down vote up
@Override
public void forward(ForwardingObjective obj) {
    if (obj.treatment() == null) {
        obj.context().ifPresent(c -> c.onError(obj, ObjectiveError.UNSUPPORTED));
    }

    // Whether this objective specifies an OUTPUT:CONTROLLER instruction.
    final boolean hasCloneToCpuAction = obj.treatment()
            .allInstructions().stream()
            .filter(i -> i.type().equals(OUTPUT))
            .map(i -> (Instructions.OutputInstruction) i)
            .anyMatch(i -> i.port().equals(PortNumber.CONTROLLER));

    if (!hasCloneToCpuAction) {
        // We support only objectives for clone to CPU behaviours (e.g. for
        // host and link discovery)
        obj.context().ifPresent(c -> c.onError(obj, ObjectiveError.UNSUPPORTED));
    }

    // Create an equivalent FlowRule with same selector and clone_to_cpu action.
    final PiAction cloneToCpuAction = PiAction.builder()
            .withId(PiActionId.of(CLONE_TO_CPU))
            .build();

    final FlowRule.Builder ruleBuilder = DefaultFlowRule.builder()
            .forTable(PiTableId.of(ACL_TABLE))
            .forDevice(deviceId)
            .withSelector(obj.selector())
            .fromApp(obj.appId())
            .withPriority(obj.priority())
            .withTreatment(DefaultTrafficTreatment.builder()
                                   .piTableAction(cloneToCpuAction).build());

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

    final GroupDescription cloneGroup = Utils.buildCloneGroup(
            obj.appId(),
            deviceId,
            CPU_CLONE_SESSION_ID,
            // Ports where to clone the packet.
            // Just controller in this case.
            Collections.singleton(PortNumber.CONTROLLER));

    switch (obj.op()) {
        case ADD:
            flowRuleService.applyFlowRules(ruleBuilder.build());
            groupService.addGroup(cloneGroup);
            break;
        case REMOVE:
            flowRuleService.removeFlowRules(ruleBuilder.build());
            groupService.removeGroup(deviceId, cloneGroup.appCookie(), obj.appId());
            break;
        default:
            log.warn("Unknown operation {}", obj.op());
    }

    obj.context().ifPresent(c -> c.onSuccess(obj));
}
 
Example 7
Source File: PipelinerImpl.java    From onos-p4-tutorial with Apache License 2.0 4 votes vote down vote up
@Override
public void forward(ForwardingObjective obj) {
    if (obj.treatment() == null) {
        obj.context().ifPresent(c -> c.onError(obj, ObjectiveError.UNSUPPORTED));
    }

    // Whether this objective specifies an OUTPUT:CONTROLLER instruction.
    final boolean hasCloneToCpuAction = obj.treatment()
            .allInstructions().stream()
            .filter(i -> i.type().equals(OUTPUT))
            .map(i -> (Instructions.OutputInstruction) i)
            .anyMatch(i -> i.port().equals(PortNumber.CONTROLLER));

    if (!hasCloneToCpuAction) {
        // We support only objectives for clone to CPU behaviours (e.g. for
        // host and link discovery)
        obj.context().ifPresent(c -> c.onError(obj, ObjectiveError.UNSUPPORTED));
    }

    // Create an equivalent FlowRule with same selector and clone_to_cpu action.
    final PiAction cloneToCpuAction = PiAction.builder()
            .withId(PiActionId.of(CLONE_TO_CPU))
            .build();

    final FlowRule.Builder ruleBuilder = DefaultFlowRule.builder()
            .forTable(PiTableId.of(ACL_TABLE))
            .forDevice(deviceId)
            .withSelector(obj.selector())
            .fromApp(obj.appId())
            .withPriority(obj.priority())
            .withTreatment(DefaultTrafficTreatment.builder()
                                   .piTableAction(cloneToCpuAction).build());

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

    final GroupDescription cloneGroup = Utils.buildCloneGroup(
            obj.appId(),
            deviceId,
            CPU_CLONE_SESSION_ID,
            // Ports where to clone the packet.
            // Just controller in this case.
            Collections.singleton(PortNumber.CONTROLLER));

    switch (obj.op()) {
        case ADD:
            flowRuleService.applyFlowRules(ruleBuilder.build());
            groupService.addGroup(cloneGroup);
            break;
        case REMOVE:
            flowRuleService.removeFlowRules(ruleBuilder.build());
            groupService.removeGroup(deviceId, cloneGroup.appCookie(), obj.appId());
            break;
        default:
            log.warn("Unknown operation {}", obj.op());
    }

    obj.context().ifPresent(c -> c.onSuccess(obj));
}
 
Example 8
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 9
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 10
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 11
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 12
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 13
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 14
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 15
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 16
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());
}