Search in sources :

Example 1 with RoadmService

use of org.onosproject.roadm.RoadmService 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 2 with RoadmService

use of org.onosproject.roadm.RoadmService 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)

Aggregations

DeviceId (org.onosproject.net.DeviceId)2 OchSignal (org.onosproject.net.OchSignal)2 PortNumber (org.onosproject.net.PortNumber)2 FlowId (org.onosproject.net.flow.FlowId)2 RoadmService (org.onosproject.roadm.RoadmService)2 FlowEntry (org.onosproject.net.flow.FlowEntry)1 FlowRuleService (org.onosproject.net.flow.FlowRuleService)1 Criterion (org.onosproject.net.flow.criteria.Criterion)1 OchSignalCriterion (org.onosproject.net.flow.criteria.OchSignalCriterion)1 PortCriterion (org.onosproject.net.flow.criteria.PortCriterion)1 Instruction (org.onosproject.net.flow.instructions.Instruction)1 Instructions (org.onosproject.net.flow.instructions.Instructions)1 L0ModificationInstruction (org.onosproject.net.flow.instructions.L0ModificationInstruction)1