Search in sources :

Example 1 with OplinkAttenuation

use of org.onosproject.driver.extensions.OplinkAttenuation in project onos by opennetworkinglab.

the class OplinkOpticalPowerConfig method setChannelTargetPower.

private boolean setChannelTargetPower(PortNumber port, OchSignal channel, long power) {
    log.debug("Set port{} channel{} attenuation.", port, channel.channelSpacing());
    FlowRuleService service = handler().get(FlowRuleService.class);
    Iterable<FlowEntry> entries = service.getFlowEntries(data().deviceId());
    for (FlowEntry entry : entries) {
        OplinkCrossConnect crossConnect = OplinkOpticalUtility.fromFlowRule(this, entry);
        // The channel port might be input port or output port.
        if ((port.equals(crossConnect.getInPort()) || port.equals(crossConnect.getOutPort())) && channel.spacingMultiplier() == crossConnect.getChannel()) {
            log.debug("Flow is found, modify the flow with attenuation.");
            // Modify attenuation in treatment
            TrafficTreatment treatment = DefaultTrafficTreatment.builder().setOutput(crossConnect.getOutPort()).extension(new OplinkAttenuation((int) power), data().deviceId()).build();
            // Apply the new flow rule
            service.applyFlowRules(DefaultFlowRule.builder().forDevice(data().deviceId()).makePermanent().withSelector(entry.selector()).withTreatment(treatment).withPriority(entry.priority()).withCookie(entry.id().value()).build());
            return true;
        }
    }
    return false;
}
Also used : OplinkAttenuation(org.onosproject.driver.extensions.OplinkAttenuation) FlowRuleService(org.onosproject.net.flow.FlowRuleService) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) FlowEntry(org.onosproject.net.flow.FlowEntry)

Example 2 with OplinkAttenuation

use of org.onosproject.driver.extensions.OplinkAttenuation 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 3 with OplinkAttenuation

use of org.onosproject.driver.extensions.OplinkAttenuation in project onos by opennetworkinglab.

the class OplinkPowerConfigUtil method setChannelAttenuation.

/**
 * Sets specified channle attenuation.
 *
 * @param portNum the port number
 * @param och channel signal
 * @param power attenuation in 0.01 dB
 */
private void setChannelAttenuation(PortNumber portNum, OchSignal och, long power) {
    FlowEntry flowEntry = findFlow(portNum, och);
    if (flowEntry == null) {
        log.warn("Target channel power not set");
        return;
    }
    final DriverHandler handler = behaviour.handler();
    for (Instruction ins : flowEntry.treatment().allInstructions()) {
        if (ins.type() != Instruction.Type.EXTENSION) {
            continue;
        }
        ExtensionTreatment ext = ((Instructions.ExtensionInstructionWrapper) ins).extensionInstruction();
        if (ext.type() == ExtensionTreatmentType.ExtensionTreatmentTypes.OPLINK_ATTENUATION.type()) {
            ((OplinkAttenuation) ext).setAttenuation((int) power);
            FlowRuleService service = handler.get(FlowRuleService.class);
            service.applyFlowRules(flowEntry);
            return;
        }
    }
    addAttenuation(flowEntry, power);
}
Also used : DriverHandler(org.onosproject.net.driver.DriverHandler) OplinkAttenuation(org.onosproject.driver.extensions.OplinkAttenuation) Instruction(org.onosproject.net.flow.instructions.Instruction) FlowRuleService(org.onosproject.net.flow.FlowRuleService) FlowEntry(org.onosproject.net.flow.FlowEntry) ExtensionTreatment(org.onosproject.net.flow.instructions.ExtensionTreatment)

Example 4 with OplinkAttenuation

use of org.onosproject.driver.extensions.OplinkAttenuation in project onos by opennetworkinglab.

the class OplinkPowerConfigUtil method addAttenuation.

/**
 * Replace flow with new flow containing Oplink attenuation extension instruction. Also resets metrics.
 *
 * @param flowEntry flow entry
 * @param power power value
 */
private void addAttenuation(FlowEntry flowEntry, long power) {
    FlowRule.Builder flowBuilder = new DefaultFlowRule.Builder().withCookie(flowEntry.id().value()).withPriority(flowEntry.priority()).forDevice(flowEntry.deviceId()).forTable(flowEntry.tableId());
    if (flowEntry.isPermanent()) {
        flowBuilder.makePermanent();
    } else {
        flowBuilder.makeTemporary(flowEntry.timeout());
    }
    flowBuilder.withSelector(flowEntry.selector());
    // Copy original instructions and add attenuation instruction
    TrafficTreatment.Builder treatmentBuilder = DefaultTrafficTreatment.builder();
    flowEntry.treatment().allInstructions().forEach(ins -> treatmentBuilder.add(ins));
    final DriverHandler handler = behaviour.handler();
    treatmentBuilder.add(Instructions.extension(new OplinkAttenuation((int) power), handler.data().deviceId()));
    flowBuilder.withTreatment(treatmentBuilder.build());
    FlowRuleService service = handler.get(FlowRuleService.class);
    service.applyFlowRules(flowBuilder.build());
}
Also used : DriverHandler(org.onosproject.net.driver.DriverHandler) OplinkAttenuation(org.onosproject.driver.extensions.OplinkAttenuation) DefaultFlowRule(org.onosproject.net.flow.DefaultFlowRule) FlowRule(org.onosproject.net.flow.FlowRule) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment) FlowRuleService(org.onosproject.net.flow.FlowRuleService)

Aggregations

OplinkAttenuation (org.onosproject.driver.extensions.OplinkAttenuation)4 FlowRuleService (org.onosproject.net.flow.FlowRuleService)4 DefaultTrafficTreatment (org.onosproject.net.flow.DefaultTrafficTreatment)3 FlowEntry (org.onosproject.net.flow.FlowEntry)3 TrafficTreatment (org.onosproject.net.flow.TrafficTreatment)3 DriverHandler (org.onosproject.net.driver.DriverHandler)2 DefaultFlowRule (org.onosproject.net.flow.DefaultFlowRule)2 FlowRule (org.onosproject.net.flow.FlowRule)2 Instruction (org.onosproject.net.flow.instructions.Instruction)2 Range (com.google.common.collect.Range)1 List (java.util.List)1 Set (java.util.Set)1 Frequency (org.onlab.util.Frequency)1 CoreService (org.onosproject.core.CoreService)1 ChannelSpacing (org.onosproject.net.ChannelSpacing)1 GridType (org.onosproject.net.GridType)1 Lambda (org.onosproject.net.Lambda)1 OchSignalType (org.onosproject.net.OchSignalType)1 PortNumber (org.onosproject.net.PortNumber)1 HandlerBehaviour (org.onosproject.net.driver.HandlerBehaviour)1