Search in sources :

Example 6 with FlowId

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

the class RoadmCrossConnectCommand method addRule.

/**
 * This method creates a XC on the device based on the parameters passed by the user.
 * Takes as an input "global" parameters (passed by user through the console).
 * @return - return the FlowId of the installed rule.
 */
protected FlowId addRule() {
    // Preparing parameters
    DeviceId device = DeviceId.deviceId(deviceId);
    PortNumber inPort = PortNumber.portNumber(srcPort);
    PortNumber outPort = PortNumber.portNumber(dstPort);
    OchSignal signal = createOchSignal(freq, sw, gridType, channelSpacing);
    if (inPort == null) {
        print("[addRule] Not able to find srcPort in the ONOS database");
        log.debug("[addRule] Not able to find srcPort in the ONOS database");
        return null;
    }
    if (outPort == null) {
        print("[addRule] Not able to find dstPort in the ONOS database");
        log.debug("[addRule] Not able to find dstPort in the ONOS database");
        return null;
    }
    if (signal == null) {
        print("[addRule] Not able to compose an OchSignal with passed parameters. Double check them");
        log.debug("[addRule] Not able to compose an OchSignal with passed parameters. Double check them");
        return null;
    }
    RoadmService manager = AbstractShellCommand.get(RoadmService.class);
    print("Adding XC for the device %s between port %s and port %s on frequency %s with bandwidth %s", deviceId, srcPort, dstPort, freq, sw);
    log.info("[addRule] Adding XC for the device {} between port {} and port {} " + "on frequency {} with bandwidth {}", deviceId, srcPort, dstPort, freq, sw);
    FlowId flow = manager.createConnection(device, 100, true, -1, inPort, outPort, signal);
    if (flow != null) {
        return flow;
    } else {
        return null;
    }
}
Also used : FlowId(org.onosproject.net.flow.FlowId) RoadmService(org.onosproject.roadm.RoadmService) DeviceId(org.onosproject.net.DeviceId) OchSignal(org.onosproject.net.OchSignal) PortNumber(org.onosproject.net.PortNumber)

Example 7 with FlowId

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

the class RoadmCrossConnectCommand method dropRule.

/**
 * This function drops XC installed on the device, which is matching parsed criteria.
 * Takes as an input "global" parameters (passed by user through the console).
 * @return - returns number of the rules that were dropped.
 */
protected FlowId dropRule() {
    // Preparing parameters
    DeviceId device = DeviceId.deviceId(deviceId);
    PortNumber inPort = PortNumber.portNumber(srcPort);
    PortNumber outPort = PortNumber.portNumber(dstPort);
    // Creating some variables
    OchSignal ochSignal = null;
    PortNumber inputPortNumber = null;
    PortNumber outputPortNumber = null;
    // Main idea: Go over all flow rules (read out from the storage) of current device and
    // filter them based on input and output port with respect to OchSignal
    FlowRuleService fr = AbstractShellCommand.get(FlowRuleService.class);
    Iterable<FlowEntry> flowRules = fr.getFlowEntries(device);
    FlowId flowId = null;
    OchSignal referenceSignal = createOchSignal(freq, sw, gridType, channelSpacing);
    for (FlowEntry flowRule : flowRules) {
        // Taken from FlowRuleParser
        for (Criterion c : flowRule.selector().criteria()) {
            if (c instanceof OchSignalCriterion) {
                ochSignal = ((OchSignalCriterion) c).lambda();
            }
            if (c instanceof PortCriterion) {
                // obtain input port
                inputPortNumber = ((PortCriterion) c).port();
            }
        }
        for (Instruction i : flowRule.treatment().immediate()) {
            if (i instanceof L0ModificationInstruction.ModOchSignalInstruction) {
                ochSignal = ((L0ModificationInstruction.ModOchSignalInstruction) i).lambda();
            }
            if (i instanceof Instructions.OutputInstruction) {
                // obtain output port
                outputPortNumber = ((Instructions.OutputInstruction) i).port();
            }
        }
        // If we found match, then let's delete this rule
        if ((ochSignal.centralFrequency().equals(referenceSignal.centralFrequency())) & (ochSignal.slotWidth().equals(referenceSignal.slotWidth())) & (inputPortNumber.equals(inPort)) & (outputPortNumber.equals(outPort))) {
            flowId = flowRule.id();
            RoadmService manager = AbstractShellCommand.get(RoadmService.class);
            manager.removeConnection(device, flowId);
            print("Dropping existing XC from the device %s", deviceId);
            return flowId;
        }
    }
    return null;
}
Also used : DeviceId(org.onosproject.net.DeviceId) OchSignal(org.onosproject.net.OchSignal) Instructions(org.onosproject.net.flow.instructions.Instructions) PortCriterion(org.onosproject.net.flow.criteria.PortCriterion) L0ModificationInstruction(org.onosproject.net.flow.instructions.L0ModificationInstruction) Instruction(org.onosproject.net.flow.instructions.Instruction) L0ModificationInstruction(org.onosproject.net.flow.instructions.L0ModificationInstruction) FlowId(org.onosproject.net.flow.FlowId) OchSignalCriterion(org.onosproject.net.flow.criteria.OchSignalCriterion) RoadmService(org.onosproject.roadm.RoadmService) 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) FlowRuleService(org.onosproject.net.flow.FlowRuleService) FlowEntry(org.onosproject.net.flow.FlowEntry)

Example 8 with FlowId

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

the class CienaRestDevice method fetchRule.

private FlowRule fetchRule(PortNumber port) {
    Frequency frequency = getFrequency(port);
    if (frequency == null) {
        return null;
    }
    int channel = getChannelFromFrequency(frequency);
    /*
         * both inPort and outPort will be same as WaveServer only deal with same port ptp-indexes
         * channel and spaceMultiplier are same.
         * TODO: find a way to get both inPort and outPort for future when inPort may not be equal to outPort
         */
    TrafficSelector selector = DefaultTrafficSelector.builder().matchInPort(port).add(Criteria.matchOchSignalType(OchSignalType.FIXED_GRID)).add(Criteria.matchLambda(OchSignal.newDwdmSlot(CHANNEL_SPACING, channel))).build();
    TrafficTreatment treatment = DefaultTrafficTreatment.builder().setOutput(port).build();
    int hash = Objects.hash(deviceId, selector, treatment);
    Pair<FlowId, Integer> lookup = crossConnectCache.get(hash);
    if (lookup == null) {
        return null;
    }
    return DefaultFlowRule.builder().forDevice(deviceId).makePermanent().withSelector(selector).withTreatment(treatment).withPriority(lookup.getRight()).withCookie(lookup.getLeft().value()).build();
}
Also used : FlowId(org.onosproject.net.flow.FlowId) Frequency(org.onlab.util.Frequency) TrafficSelector(org.onosproject.net.flow.TrafficSelector) DefaultTrafficSelector(org.onosproject.net.flow.DefaultTrafficSelector) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment)

Aggregations

FlowId (org.onosproject.net.flow.FlowId)8 DeviceId (org.onosproject.net.DeviceId)4 PortNumber (org.onosproject.net.PortNumber)3 OchSignal (org.onosproject.net.OchSignal)2 DefaultFlowEntry (org.onosproject.net.flow.DefaultFlowEntry)2 DefaultTrafficSelector (org.onosproject.net.flow.DefaultTrafficSelector)2 DefaultTrafficTreatment (org.onosproject.net.flow.DefaultTrafficTreatment)2 StoredFlowEntry (org.onosproject.net.flow.StoredFlowEntry)2 TrafficSelector (org.onosproject.net.flow.TrafficSelector)2 TrafficTreatment (org.onosproject.net.flow.TrafficTreatment)2 RoadmService (org.onosproject.roadm.RoadmService)2 LinkedList (java.util.LinkedList)1 Frequency (org.onlab.util.Frequency)1 CrossConnectCache (org.onosproject.driver.optical.flowrule.CrossConnectCache)1 CrossConnectFlowRule (org.onosproject.driver.optical.flowrule.CrossConnectFlowRule)1 DeviceService (org.onosproject.net.device.DeviceService)1 DefaultFlowRule (org.onosproject.net.flow.DefaultFlowRule)1 FlowEntry (org.onosproject.net.flow.FlowEntry)1 FlowRule (org.onosproject.net.flow.FlowRule)1 FlowRuleService (org.onosproject.net.flow.FlowRuleService)1