Search in sources :

Example 6 with OutputInstruction

use of org.onosproject.net.flow.instructions.Instructions.OutputInstruction in project onos by opennetworkinglab.

the class PolatisInternalConnectivity method filterUsedPorts.

private Set<PortNumber> filterUsedPorts(Set<PortNumber> ports, Collection<FlowEntry> flowEntries) {
    if (ports.isEmpty() || flowEntries.isEmpty()) {
        return ports;
    }
    for (FlowEntry flowEntry : flowEntries) {
        PortNumber inputPort = ((PortCriterion) flowEntry.selector().getCriterion(Criterion.Type.IN_PORT)).port();
        ports.remove(inputPort);
        PortNumber outputPort = ((OutputInstruction) flowEntry.treatment().allInstructions().get(0)).port();
        ports.remove(outputPort);
        log.debug("Cross-connection {}-{} removed from output port list", inputPort, outputPort);
    }
    log.debug("Ports after filtering out used ones: " + ports);
    return ports;
}
Also used : OutputInstruction(org.onosproject.net.flow.instructions.Instructions.OutputInstruction) PortCriterion(org.onosproject.net.flow.criteria.PortCriterion) PortNumber(org.onosproject.net.PortNumber) FlowEntry(org.onosproject.net.flow.FlowEntry)

Example 7 with OutputInstruction

use of org.onosproject.net.flow.instructions.Instructions.OutputInstruction in project onos by opennetworkinglab.

the class OvsOfdpaPipeline method versatileTreatmentBuilder.

@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;
}
Also used : OutputInstruction(org.onosproject.net.flow.instructions.Instructions.OutputInstruction) NextGroup(org.onosproject.net.behaviour.NextGroup) NextGroup(org.onosproject.net.behaviour.NextGroup) Group(org.onosproject.net.group.Group) NoActionInstruction(org.onosproject.net.flow.instructions.Instructions.NoActionInstruction) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment) L2ModificationInstruction(org.onosproject.net.flow.instructions.L2ModificationInstruction) OutputInstruction(org.onosproject.net.flow.instructions.Instructions.OutputInstruction) L3ModificationInstruction(org.onosproject.net.flow.instructions.L3ModificationInstruction) Instruction(org.onosproject.net.flow.instructions.Instruction) NoActionInstruction(org.onosproject.net.flow.instructions.Instructions.NoActionInstruction) Deque(java.util.Deque)

Example 8 with OutputInstruction

use of org.onosproject.net.flow.instructions.Instructions.OutputInstruction in project onos by opennetworkinglab.

the class Ofdpa2Pipeline method versatileTreatmentBuilder.

/**
 * 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;
}
Also used : OutputInstruction(org.onosproject.net.flow.instructions.Instructions.OutputInstruction) NextGroup(org.onosproject.net.behaviour.NextGroup) NextGroup(org.onosproject.net.behaviour.NextGroup) Group(org.onosproject.net.group.Group) NoActionInstruction(org.onosproject.net.flow.instructions.Instructions.NoActionInstruction) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment) L2ModificationInstruction(org.onosproject.net.flow.instructions.L2ModificationInstruction) L3ModificationInstruction(org.onosproject.net.flow.instructions.L3ModificationInstruction) Instruction(org.onosproject.net.flow.instructions.Instruction) NoActionInstruction(org.onosproject.net.flow.instructions.Instructions.NoActionInstruction) OutputInstruction(org.onosproject.net.flow.instructions.Instructions.OutputInstruction) ModMplsHeaderInstruction(org.onosproject.net.flow.instructions.L2ModificationInstruction.ModMplsHeaderInstruction) ArrayDeque(java.util.ArrayDeque) Deque(java.util.Deque)

Example 9 with OutputInstruction

use of org.onosproject.net.flow.instructions.Instructions.OutputInstruction in project onos by opennetworkinglab.

the class InstructionJsonMatcher method matchOutputInstruction.

// TODO: need to add matchModVlanHeaderInstruction
/**
 * Matches the contents of an output instruction.
 *
 * @param instructionJson JSON instruction to match
 * @param description Description object used for recording errors
 * @return true if contents match, false otherwise
 */
private boolean matchOutputInstruction(JsonNode instructionJson, Description description) {
    final String jsonType = instructionJson.get("type").textValue();
    OutputInstruction instructionToMatch = (OutputInstruction) instruction;
    if (!instructionToMatch.type().name().equals(jsonType)) {
        description.appendText("type was " + jsonType);
        return false;
    }
    if (instructionJson.get("port").isLong() || instructionJson.get("port").isInt()) {
        final long jsonPort = instructionJson.get("port").asLong();
        if (instructionToMatch.port().toLong() != (jsonPort)) {
            description.appendText("port was " + jsonPort);
            return false;
        }
    } else if (instructionJson.get("port").isTextual()) {
        final String jsonPort = instructionJson.get("port").textValue();
        if (!instructionToMatch.port().toString().equals(jsonPort)) {
            description.appendText("port was " + jsonPort);
            return false;
        }
    } else {
        final String jsonPort = instructionJson.get("port").toString();
        description.appendText("Unmatching types ");
        description.appendText("instructionToMatch " + instructionToMatch.port().toString());
        description.appendText("jsonPort " + jsonPort);
    }
    return true;
}
Also used : OutputInstruction(org.onosproject.net.flow.instructions.Instructions.OutputInstruction) HexString(org.onlab.util.HexString)

Example 10 with OutputInstruction

use of org.onosproject.net.flow.instructions.Instructions.OutputInstruction in project onos by opennetworkinglab.

the class SoftRouterPipeline method processVersatile.

/**
 * SoftRouter has a single versatile table - the filter table.
 * This table can be used to filter entries that reach the next table (FIB table).
 * It can also be used to punt packets to the controller and/or bypass
 * the FIB table to forward out of a port.
 *
 * @param fwd The forwarding objective of type versatile
 * @return  A collection of flow rules meant to be delivered to the flowrule
 *          subsystem. May return empty collection in case of failures.
 */
private Collection<FlowRule> processVersatile(ForwardingObjective fwd) {
    log.debug("Received versatile fwd: to next:{}", fwd.nextId());
    Collection<FlowRule> flowrules = new ArrayList<>();
    if (fwd.nextId() == null && fwd.treatment() == null) {
        log.error("Forwarding objective {} from {} must contain " + "nextId or Treatment", fwd.selector(), fwd.appId());
        return Collections.emptySet();
    }
    int tableId = FILTER_TABLE;
    // so that it only takes effect if the packet misses the FIB rules
    if (fwd.treatment() != null && containsPunt(fwd.treatment()) && fwd.selector() != null && matchesIp(fwd.selector()) && !matchesControlTraffic(fwd.selector())) {
        tableId = FIB_TABLE;
    }
    TrafficTreatment.Builder ttBuilder = DefaultTrafficTreatment.builder();
    if (fwd.treatment() != null) {
        fwd.treatment().immediate().forEach(ins -> ttBuilder.add(ins));
    }
    // convert nextId to flow actions
    if (fwd.nextId() != null) {
        // only acceptable value is output to port
        NextGroup next = flowObjectiveStore.getNextGroup(fwd.nextId());
        if (next == null) {
            log.error("next-id {} does not exist in store", fwd.nextId());
            return Collections.emptySet();
        }
        TrafficTreatment nt = appKryo.deserialize(next.data());
        if (nt == null) {
            log.error("Error in deserializing next-id {}", fwd.nextId());
            return Collections.emptySet();
        }
        for (Instruction ins : nt.allInstructions()) {
            if (ins instanceof OutputInstruction) {
                ttBuilder.add(ins);
            }
        }
    }
    FlowRule rule = DefaultFlowRule.builder().withSelector(fwd.selector()).withTreatment(ttBuilder.build()).forTable(tableId).makePermanent().forDevice(deviceId).fromApp(fwd.appId()).withPriority(fwd.priority()).build();
    flowrules.add(rule);
    return flowrules;
}
Also used : NextGroup(org.onosproject.net.behaviour.NextGroup) OutputInstruction(org.onosproject.net.flow.instructions.Instructions.OutputInstruction) ArrayList(java.util.ArrayList) DefaultFlowRule(org.onosproject.net.flow.DefaultFlowRule) FlowRule(org.onosproject.net.flow.FlowRule) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment) OutputInstruction(org.onosproject.net.flow.instructions.Instructions.OutputInstruction) Instruction(org.onosproject.net.flow.instructions.Instruction)

Aggregations

OutputInstruction (org.onosproject.net.flow.instructions.Instructions.OutputInstruction)34 Instruction (org.onosproject.net.flow.instructions.Instruction)21 PortNumber (org.onosproject.net.PortNumber)17 DeviceId (org.onosproject.net.DeviceId)15 ConnectPoint (org.onosproject.net.ConnectPoint)11 Port (org.onosproject.net.Port)10 L2ModificationInstruction (org.onosproject.net.flow.instructions.L2ModificationInstruction)9 TrafficTreatment (org.onosproject.net.flow.TrafficTreatment)7 Criterion (org.onosproject.net.flow.criteria.Criterion)7 Group (org.onosproject.net.group.Group)7 Collection (java.util.Collection)6 DeviceService (org.onosproject.net.device.DeviceService)6 FlowEntry (org.onosproject.net.flow.FlowEntry)6 ImmutableList (com.google.common.collect.ImmutableList)5 HashSet (java.util.HashSet)5 Ethernet (org.onlab.packet.Ethernet)5 AbstractHandlerBehaviour (org.onosproject.net.driver.AbstractHandlerBehaviour)5 IPCriterion (org.onosproject.net.flow.criteria.IPCriterion)5 ModEtherInstruction (org.onosproject.net.flow.instructions.L2ModificationInstruction.ModEtherInstruction)5 ModVlanIdInstruction (org.onosproject.net.flow.instructions.L2ModificationInstruction.ModVlanIdInstruction)5