Search in sources :

Example 21 with Instruction

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

the class OplinkOpticalUtility method fromFlowRule.

/**
 * Transforms a flow FlowRule object to an OplinkCrossConnect object.
 * @param behaviour the parent driver handler
 * @param rule FlowRule object
 * @return cross connect object
 */
public static OplinkCrossConnect fromFlowRule(HandlerBehaviour behaviour, FlowRule rule) {
    // TrafficSelector
    Set<Criterion> criterions = rule.selector().criteria();
    int channel = criterions.stream().filter(c -> c instanceof OchSignalCriterion).map(c -> ((OchSignalCriterion) c).lambda().spacingMultiplier()).findAny().orElse(null);
    PortNumber inPort = criterions.stream().filter(c -> c instanceof PortCriterion).map(c -> ((PortCriterion) c).port()).findAny().orElse(null);
    // TrafficTreatment
    List<Instruction> instructions = rule.treatment().immediate();
    PortNumber outPort = instructions.stream().filter(c -> c instanceof Instructions.OutputInstruction).map(c -> ((Instructions.OutputInstruction) c).port()).findAny().orElse(null);
    int attenuation = instructions.stream().filter(c -> c instanceof Instructions.ExtensionInstructionWrapper).map(c -> ((Instructions.ExtensionInstructionWrapper) c).extensionInstruction()).filter(c -> c instanceof OplinkAttenuation).map(c -> ((OplinkAttenuation) c).getAttenuation()).findAny().orElse(DEFAULT_ATT);
    return new OplinkCrossConnect(inPort, outPort, channel, attenuation);
}
Also used : GridType(org.onosproject.net.GridType) DefaultFlowRule(org.onosproject.net.flow.DefaultFlowRule) CoreService(org.onosproject.core.CoreService) PortNumber(org.onosproject.net.PortNumber) FlowEntry(org.onosproject.net.flow.FlowEntry) PortCriterion(org.onosproject.net.flow.criteria.PortCriterion) HandlerBehaviour(org.onosproject.net.driver.HandlerBehaviour) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) OplinkAttenuation(org.onosproject.driver.extensions.OplinkAttenuation) OchSignalCriterion(org.onosproject.net.flow.criteria.OchSignalCriterion) Frequency(org.onlab.util.Frequency) FlowRuleService(org.onosproject.net.flow.FlowRuleService) TrafficSelector(org.onosproject.net.flow.TrafficSelector) Criteria(org.onosproject.net.flow.criteria.Criteria) DefaultTrafficSelector(org.onosproject.net.flow.DefaultTrafficSelector) Criterion(org.onosproject.net.flow.criteria.Criterion) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment) OchSignalType(org.onosproject.net.OchSignalType) Instructions(org.onosproject.net.flow.instructions.Instructions) Instruction(org.onosproject.net.flow.instructions.Instruction) Range(com.google.common.collect.Range) Set(java.util.Set) Lambda(org.onosproject.net.Lambda) List(java.util.List) FlowRule(org.onosproject.net.flow.FlowRule) ChannelSpacing(org.onosproject.net.ChannelSpacing) Instructions(org.onosproject.net.flow.instructions.Instructions) OplinkAttenuation(org.onosproject.driver.extensions.OplinkAttenuation) PortCriterion(org.onosproject.net.flow.criteria.PortCriterion) Instruction(org.onosproject.net.flow.instructions.Instruction) OchSignalCriterion(org.onosproject.net.flow.criteria.OchSignalCriterion) PortCriterion(org.onosproject.net.flow.criteria.PortCriterion) OchSignalCriterion(org.onosproject.net.flow.criteria.OchSignalCriterion) Criterion(org.onosproject.net.flow.criteria.Criterion) PortNumber(org.onosproject.net.PortNumber)

Example 22 with Instruction

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

the class DefaultCheckLoop method findLoop.

/**
 * Enter of the loop checking algorithm.
 *
 * @return the set of loop results; empty, if there is no loop
 */
private Set<NetworkAnomaly> findLoop() {
    getNetworkSnapshot();
    loops = new HashSet<>();
    excludeDeviceId = new HashSet<>();
    for (Device device : accessDevices) {
        if (excludeDeviceId.contains(device.id())) {
            continue;
        }
        List<FlowEntry> availableFlowEntries = new ArrayList<>();
        flowEntryInfo.get(device.id()).forEach(flowEntry -> {
            if (flowEntry.state() == ADDED) {
                availableFlowEntries.add(flowEntry);
            }
        });
        List<FlowEntry> sortedFlowEntries = sortFlowTable(availableFlowEntries);
        for (FlowEntry flow : sortedFlowEntries) {
            TsLoopPacket pkt = matchBuilder(flow.selector().criteria(), null);
            pkt.pushPathFlow(flow);
            List<Instruction> inst = flow.treatment().immediate();
            for (Instruction instOne : inst) {
                // Attention !!!
                // if you would like to modify the code here,
                // please MAKE VERY SURE that you are clear with
                // the relationship of any invoked methods, and
                // the relationship of params which are passed in and out.
                processOneInstruction(instOne, device.id(), null, pkt, true, flow);
            }
        }
    }
    return loops;
}
Also used : Device(org.onosproject.net.Device) NetworkDiagnosticUtils.isDevice(org.onosproject.fnl.base.NetworkDiagnosticUtils.isDevice) ArrayList(java.util.ArrayList) OutputInstruction(org.onosproject.net.flow.instructions.Instructions.OutputInstruction) Instruction(org.onosproject.net.flow.instructions.Instruction) FlowEntry(org.onosproject.net.flow.FlowEntry) TsLoopPacket(org.onosproject.fnl.base.TsLoopPacket)

Example 23 with Instruction

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

the class GetFlowStatisticsCommand method doExecute.

@Override
protected void doExecute() {
    DeviceService deviceService = get(DeviceService.class);
    FlowStatisticService flowStatsService = get(FlowStatisticService.class);
    String deviceUri = getDeviceId(devicePort);
    String portUri = getPortNumber(devicePort);
    DeviceId ingressDeviceId = deviceId(deviceUri);
    PortNumber ingressPortNumber;
    if (portUri.length() == 0) {
        ingressPortNumber = null;
    } else {
        ingressPortNumber = portNumber(portUri);
    }
    Device device = deviceService.getDevice(ingressDeviceId);
    if (device == null) {
        error("No such device %s", ingressDeviceId.uri());
        return;
    }
    if (ingressPortNumber != null) {
        Port port = deviceService.getPort(ingressDeviceId, ingressPortNumber);
        if (port == null) {
            error("No such port %s on device %s", portUri, ingressDeviceId.uri());
            return;
        }
    }
    if (flowLiveType != null) {
        flowLiveType = flowLiveType.toUpperCase();
    }
    if (instructionType != null) {
        instructionType = instructionType.toUpperCase();
    }
    // convert String to FlowLiveType and check validity
    FlowEntry.FlowLiveType inLiveType;
    if (flowLiveType == null) {
        inLiveType = null;
    } else {
        inLiveType = getFlowLiveType(flowLiveType);
        if (inLiveType == null) {
            error("Invalid flow live type [%s] error", flowLiveType);
            return;
        }
    }
    // convert String to InstructionType and check validity
    Instruction.Type inInstructionType;
    if (instructionType == null) {
        inInstructionType = null;
    } else {
        inInstructionType = getInstructionType(instructionType);
        if (inInstructionType == null) {
            error("Invalid instruction type [%s] error", instructionType);
            return;
        }
    }
    if (showTopn != null) {
        int topn = Integer.parseInt(showTopn);
        if (topn <= 0) {
            // default value
            topn = 100;
        } else if (topn > 1000) {
            // max value
            topn = 1000;
        }
        // print show topn head line with type
        print("deviceId=%s, show TOPN=%s flows, liveType=%s, instruction type=%s", deviceUri, Integer.toString(topn), flowLiveType == null ? "ALL" : flowLiveType, instructionType == null ? "ALL" : instructionType);
        if (ingressPortNumber == null) {
            Map<ConnectPoint, List<FlowEntryWithLoad>> typedFlowLoadMap = flowStatsService.loadTopnByType(device, inLiveType, inInstructionType, topn);
            // print all ports topn flows load for a given device
            for (ConnectPoint cp : typedFlowLoadMap.keySet()) {
                printPortFlowsLoad(cp, typedFlowLoadMap.get(cp));
            }
        } else {
            List<FlowEntryWithLoad> typedFlowLoad = flowStatsService.loadTopnByType(device, ingressPortNumber, inLiveType, inInstructionType, topn);
            // print device/port topn flows load
            ConnectPoint cp = new ConnectPoint(ingressDeviceId, ingressPortNumber);
            printPortFlowsLoad(cp, typedFlowLoad);
        }
    } else if (showAll) {
        // is true?
        // print show all head line with type
        print("deviceId=%s, show ALL flows, liveType=%s, instruction type=%s", deviceUri, flowLiveType == null ? "ALL" : flowLiveType, instructionType == null ? "ALL" : instructionType);
        if (ingressPortNumber == null) {
            Map<ConnectPoint, List<FlowEntryWithLoad>> typedFlowLoadMap = flowStatsService.loadAllByType(device, inLiveType, inInstructionType);
            // print all ports all flows load for a given device
            for (ConnectPoint cp : typedFlowLoadMap.keySet()) {
                printPortFlowsLoad(cp, typedFlowLoadMap.get(cp));
            }
        } else {
            List<FlowEntryWithLoad> typedFlowLoad = flowStatsService.loadAllByType(device, ingressPortNumber, inLiveType, inInstructionType);
            // print device/port all flows load
            ConnectPoint cp = new ConnectPoint(ingressDeviceId, ingressPortNumber);
            printPortFlowsLoad(cp, typedFlowLoad);
        }
    } else {
        // if (showSummary == true) //always is true
        // print show summary head line
        print("deviceId=%s, show SUMMARY flows", deviceUri);
        if (ingressPortNumber == null) {
            Map<ConnectPoint, SummaryFlowEntryWithLoad> summaryFlowLoadMap = flowStatsService.loadSummary(device);
            // print all ports flow load summary for a given device
            for (ConnectPoint cp : summaryFlowLoadMap.keySet()) {
                printPortSummaryLoad(cp, summaryFlowLoadMap.get(cp));
            }
        } else {
            SummaryFlowEntryWithLoad summaryFlowLoad = flowStatsService.loadSummary(device, ingressPortNumber);
            // print device/port flow load summary
            ConnectPoint cp = new ConnectPoint(ingressDeviceId, ingressPortNumber);
            printPortSummaryLoad(cp, summaryFlowLoad);
        }
    }
}
Also used : FlowEntryWithLoad(org.onosproject.net.statistic.FlowEntryWithLoad) SummaryFlowEntryWithLoad(org.onosproject.net.statistic.SummaryFlowEntryWithLoad) DeviceId(org.onosproject.net.DeviceId) Device(org.onosproject.net.Device) Port(org.onosproject.net.Port) DeviceService(org.onosproject.net.device.DeviceService) FlowStatisticService(org.onosproject.net.statistic.FlowStatisticService) Instruction(org.onosproject.net.flow.instructions.Instruction) ConnectPoint(org.onosproject.net.ConnectPoint) ConnectPoint(org.onosproject.net.ConnectPoint) SummaryFlowEntryWithLoad(org.onosproject.net.statistic.SummaryFlowEntryWithLoad) List(java.util.List) PortNumber(org.onosproject.net.PortNumber) FlowEntry(org.onosproject.net.flow.FlowEntry) StoredFlowEntry(org.onosproject.net.flow.StoredFlowEntry) Map(java.util.Map)

Example 24 with Instruction

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

the class HPPipelineV1 method checkUnSupportedFeatures.

// Return TRUE if ForwardingObjective fwd includes unsupported features
@Override
protected boolean checkUnSupportedFeatures(TrafficSelector selector, TrafficTreatment treatment) {
    boolean unsupportedFeatures = false;
    for (Criterion criterion : selector.criteria()) {
        if (this.unsupportedCriteria.contains(criterion.type())) {
            log.warn("HP V1 Driver - unsupported criteria {}", criterion.type());
            unsupportedFeatures = true;
        }
    }
    for (Instruction instruction : treatment.allInstructions()) {
        if (this.unsupportedInstructions.contains(instruction.type())) {
            log.warn("HP V1 Driver - unsupported instruction {}", instruction.type());
            unsupportedFeatures = true;
        }
        if (instruction.type() == Instruction.Type.L2MODIFICATION) {
            if (this.unsupportedL2mod.contains(((L2ModificationInstruction) instruction).subtype())) {
                log.warn("HP V1 Driver - unsupported L2MODIFICATION instruction {}", ((L2ModificationInstruction) instruction).subtype());
                unsupportedFeatures = true;
            }
        }
        if (instruction.type() == Instruction.Type.L3MODIFICATION) {
            if (this.unsupportedL3mod.contains(((L3ModificationInstruction) instruction).subtype())) {
                log.warn("HP V1 Driver - unsupported L3MODIFICATION instruction {}", ((L3ModificationInstruction) instruction).subtype());
                unsupportedFeatures = true;
            }
        }
    }
    return unsupportedFeatures;
}
Also used : EthTypeCriterion(org.onosproject.net.flow.criteria.EthTypeCriterion) PortCriterion(org.onosproject.net.flow.criteria.PortCriterion) EthCriterion(org.onosproject.net.flow.criteria.EthCriterion) VlanIdCriterion(org.onosproject.net.flow.criteria.VlanIdCriterion) IPCriterion(org.onosproject.net.flow.criteria.IPCriterion) Criterion(org.onosproject.net.flow.criteria.Criterion) L3ModificationInstruction(org.onosproject.net.flow.instructions.L3ModificationInstruction) Instruction(org.onosproject.net.flow.instructions.Instruction) L2ModificationInstruction(org.onosproject.net.flow.instructions.L2ModificationInstruction)

Example 25 with Instruction

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

the class HPPipelineV2 method checkUnSupportedFeatures.

// Return TRUE if ForwardingObjective fwd includes UNSUPPORTED features
@Override
protected boolean checkUnSupportedFeatures(TrafficSelector selector, TrafficTreatment treatment) {
    boolean unsupportedFeatures = false;
    for (Criterion criterion : selector.criteria()) {
        if (this.unsupportedCriteria.contains(criterion.type())) {
            log.warn("HP V2 Driver - unsupported criteria {}", criterion.type());
            unsupportedFeatures = true;
        }
    }
    for (Instruction instruction : treatment.allInstructions()) {
        if (this.unsupportedInstructions.contains(instruction.type())) {
            log.warn("HP V2 Driver - unsupported instruction {}", instruction.type());
            unsupportedFeatures = true;
        }
        if (instruction.type() == Instruction.Type.L2MODIFICATION) {
            if (this.unsupportedL2mod.contains(((L2ModificationInstruction) instruction).subtype())) {
                log.warn("HP V2 Driver - unsupported L2MODIFICATION instruction {}", ((L2ModificationInstruction) instruction).subtype());
                unsupportedFeatures = true;
            }
        }
        if (instruction.type() == Instruction.Type.L3MODIFICATION) {
            if (this.unsupportedL3mod.contains(((L3ModificationInstruction) instruction).subtype())) {
                log.warn("HP V2 Driver - unsupported L3MODIFICATION instruction {}", ((L3ModificationInstruction) instruction).subtype());
                unsupportedFeatures = true;
            }
        }
    }
    return unsupportedFeatures;
}
Also used : EthTypeCriterion(org.onosproject.net.flow.criteria.EthTypeCriterion) PortCriterion(org.onosproject.net.flow.criteria.PortCriterion) EthCriterion(org.onosproject.net.flow.criteria.EthCriterion) VlanIdCriterion(org.onosproject.net.flow.criteria.VlanIdCriterion) IPCriterion(org.onosproject.net.flow.criteria.IPCriterion) Criterion(org.onosproject.net.flow.criteria.Criterion) L3ModificationInstruction(org.onosproject.net.flow.instructions.L3ModificationInstruction) Instruction(org.onosproject.net.flow.instructions.Instruction) L2ModificationInstruction(org.onosproject.net.flow.instructions.L2ModificationInstruction)

Aggregations

Instruction (org.onosproject.net.flow.instructions.Instruction)104 L2ModificationInstruction (org.onosproject.net.flow.instructions.L2ModificationInstruction)59 TrafficTreatment (org.onosproject.net.flow.TrafficTreatment)48 DefaultTrafficTreatment (org.onosproject.net.flow.DefaultTrafficTreatment)44 Criterion (org.onosproject.net.flow.criteria.Criterion)42 TrafficSelector (org.onosproject.net.flow.TrafficSelector)34 VlanIdCriterion (org.onosproject.net.flow.criteria.VlanIdCriterion)33 Instructions (org.onosproject.net.flow.instructions.Instructions)33 OutputInstruction (org.onosproject.net.flow.instructions.Instructions.OutputInstruction)32 L3ModificationInstruction (org.onosproject.net.flow.instructions.L3ModificationInstruction)32 PortNumber (org.onosproject.net.PortNumber)30 DefaultTrafficSelector (org.onosproject.net.flow.DefaultTrafficSelector)28 EthTypeCriterion (org.onosproject.net.flow.criteria.EthTypeCriterion)27 IPCriterion (org.onosproject.net.flow.criteria.IPCriterion)26 VlanId (org.onlab.packet.VlanId)25 DeviceId (org.onosproject.net.DeviceId)25 EthCriterion (org.onosproject.net.flow.criteria.EthCriterion)25 PortCriterion (org.onosproject.net.flow.criteria.PortCriterion)25 FlowRule (org.onosproject.net.flow.FlowRule)24 Group (org.onosproject.net.group.Group)23