Search in sources :

Example 1 with HandlerBehaviour

use of org.onosproject.net.driver.HandlerBehaviour 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 2 with HandlerBehaviour

use of org.onosproject.net.driver.HandlerBehaviour in project onos by opennetworkinglab.

the class OplinkOpticalUtility method toFlowRule.

/**
 * Finds the FlowRule from flow rule store by the given ports and channel.
 * Returns an extra flow to remove the flow by ONOS if not found.
 * @param behaviour the parent driver handler
 * @param inPort the input port
 * @param outPort the output port
 * @param channel the specified channel
 * @return the flow rule
 */
public static FlowRule toFlowRule(HandlerBehaviour behaviour, PortNumber inPort, PortNumber outPort, Integer channel) {
    FlowRuleService service = behaviour.handler().get(FlowRuleService.class);
    Iterable<FlowEntry> entries = service.getFlowEntries(behaviour.data().deviceId());
    // Try to Find the flow from flow rule store.
    for (FlowEntry entry : entries) {
        Set<Criterion> criterions = entry.selector().criteria();
        // input port
        PortNumber ip = criterions.stream().filter(c -> c instanceof PortCriterion).map(c -> ((PortCriterion) c).port()).findAny().orElse(null);
        // channel
        Integer ch = criterions.stream().filter(c -> c instanceof OchSignalCriterion).map(c -> ((OchSignalCriterion) c).lambda().spacingMultiplier()).findAny().orElse(null);
        // output port
        PortNumber op = entry.treatment().immediate().stream().filter(c -> c instanceof Instructions.OutputInstruction).map(c -> ((Instructions.OutputInstruction) c).port()).findAny().orElse(null);
        if (inPort.equals(ip) && channel.equals(ch) && outPort.equals(op)) {
            // Find the flow.
            return entry;
        }
    }
    // Cannot find the flow from store. So report an extra flow to remove the flow by ONOS.
    TrafficSelector selector = DefaultTrafficSelector.builder().matchInPort(inPort).add(Criteria.matchOchSignalType(OchSignalType.FIXED_GRID)).add(Criteria.matchLambda(Lambda.ochSignal(GRID_TYPE, CHANNEL_SPACING, channel, SLOT_GRANULARITY))).build();
    TrafficTreatment treatment = DefaultTrafficTreatment.builder().setOutput(outPort).build();
    return DefaultFlowRule.builder().forDevice(behaviour.data().deviceId()).withSelector(selector).withTreatment(treatment).withPriority(DEFAULT_PRIORITY).makePermanent().fromApp(behaviour.handler().get(CoreService.class).getAppId(DEFAULT_APP)).build();
}
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) CoreService(org.onosproject.core.CoreService) Instructions(org.onosproject.net.flow.instructions.Instructions) PortCriterion(org.onosproject.net.flow.criteria.PortCriterion) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment) 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) TrafficSelector(org.onosproject.net.flow.TrafficSelector) DefaultTrafficSelector(org.onosproject.net.flow.DefaultTrafficSelector) FlowRuleService(org.onosproject.net.flow.FlowRuleService) PortNumber(org.onosproject.net.PortNumber) FlowEntry(org.onosproject.net.flow.FlowEntry)

Example 3 with HandlerBehaviour

use of org.onosproject.net.driver.HandlerBehaviour in project onos by opennetworkinglab.

the class PolatisOpticalUtility method toFlowRule.

/**
 * Finds the FlowRule from flow rule store by the given ports and channel.
 * Returns an extra flow to remove the flow by ONOS if not found.
 * @param behaviour the parent driver handler
 * @param inPort the input port
 * @param outPort the output port
 * @return the flow rule
 */
public static FlowRule toFlowRule(HandlerBehaviour behaviour, PortNumber inPort, PortNumber outPort) {
    FlowRuleService service = behaviour.handler().get(FlowRuleService.class);
    Iterable<FlowEntry> entries = service.getFlowEntries(behaviour.data().deviceId());
    // Try to Find the flow from flow rule store.
    for (FlowEntry entry : entries) {
        Set<Criterion> criterions = entry.selector().criteria();
        // input port
        PortNumber ip = criterions.stream().filter(c -> c instanceof PortCriterion).map(c -> ((PortCriterion) c).port()).findAny().orElse(null);
        // output port
        PortNumber op = entry.treatment().immediate().stream().filter(c -> c instanceof Instructions.OutputInstruction).map(c -> ((Instructions.OutputInstruction) c).port()).findAny().orElse(null);
        if (inPort.equals(ip) && outPort.equals(op)) {
            // Find the flow.
            return entry;
        }
    }
    // Cannot find the flow from store. So report an extra flow to remove the flow by ONOS.
    TrafficSelector selector = DefaultTrafficSelector.builder().matchInPort(inPort).build();
    TrafficTreatment treatment = DefaultTrafficTreatment.builder().setOutput(outPort).build();
    return DefaultFlowRule.builder().forDevice(behaviour.data().deviceId()).withSelector(selector).withTreatment(treatment).makePermanent().withPriority(DEFAULT_PRIORITY).fromApp(behaviour.handler().get(CoreService.class).getAppId(DEFAULT_APP)).build();
}
Also used : TrafficTreatment(org.onosproject.net.flow.TrafficTreatment) Instructions(org.onosproject.net.flow.instructions.Instructions) DefaultFlowRule(org.onosproject.net.flow.DefaultFlowRule) CoreService(org.onosproject.core.CoreService) Instruction(org.onosproject.net.flow.instructions.Instruction) Range(com.google.common.collect.Range) PortNumber(org.onosproject.net.PortNumber) FlowEntry(org.onosproject.net.flow.FlowEntry) Set(java.util.Set) PortCriterion(org.onosproject.net.flow.criteria.PortCriterion) HandlerBehaviour(org.onosproject.net.driver.HandlerBehaviour) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) UnsignedInteger32(org.snmp4j.smi.UnsignedInteger32) List(java.util.List) FlowRuleService(org.onosproject.net.flow.FlowRuleService) TrafficSelector(org.onosproject.net.flow.TrafficSelector) FlowRule(org.onosproject.net.flow.FlowRule) VariableBinding(org.snmp4j.smi.VariableBinding) DefaultTrafficSelector(org.onosproject.net.flow.DefaultTrafficSelector) Criterion(org.onosproject.net.flow.criteria.Criterion) Variable(org.snmp4j.smi.Variable) OID(org.snmp4j.smi.OID) CoreService(org.onosproject.core.CoreService) Instructions(org.onosproject.net.flow.instructions.Instructions) PortCriterion(org.onosproject.net.flow.criteria.PortCriterion) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) PortCriterion(org.onosproject.net.flow.criteria.PortCriterion) Criterion(org.onosproject.net.flow.criteria.Criterion) TrafficSelector(org.onosproject.net.flow.TrafficSelector) DefaultTrafficSelector(org.onosproject.net.flow.DefaultTrafficSelector) FlowRuleService(org.onosproject.net.flow.FlowRuleService) PortNumber(org.onosproject.net.PortNumber) FlowEntry(org.onosproject.net.flow.FlowEntry)

Example 4 with HandlerBehaviour

use of org.onosproject.net.driver.HandlerBehaviour in project onos by opennetworkinglab.

the class PolatisOpticalUtility method fromFlowRule.

/**
 * Transforms a flow FlowRule object to a cross-connect object.
 * @param behaviour the parent driver handler
 * @param rule FlowRule object
 * @return cross connect object
 */
public static CrossConnects fromFlowRule(HandlerBehaviour behaviour, FlowRule rule) {
    // TrafficSelector
    Set<Criterion> criterions = rule.selector().criteria();
    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);
    DefaultCrossConnects crossConnects = new DefaultCrossConnects();
    DefaultPair p = new DefaultPair();
    p.ingress(new PortFormat(inPort.toLong()));
    p.egress(new PortFormat(outPort.toLong()));
    crossConnects.addToPair(p);
    return crossConnects;
}
Also used : TrafficTreatment(org.onosproject.net.flow.TrafficTreatment) Instructions(org.onosproject.net.flow.instructions.Instructions) PortFormat(org.onosproject.yang.gen.v1.opticalswitch.rev20180322.opticalswitch.PortFormat) DefaultFlowRule(org.onosproject.net.flow.DefaultFlowRule) CoreService(org.onosproject.core.CoreService) Instruction(org.onosproject.net.flow.instructions.Instruction) Range(com.google.common.collect.Range) PortNumber(org.onosproject.net.PortNumber) FlowEntry(org.onosproject.net.flow.FlowEntry) Pair(org.onosproject.yang.gen.v1.opticalswitch.rev20180322.opticalswitch.crossconnects.Pair) Set(java.util.Set) PortCriterion(org.onosproject.net.flow.criteria.PortCriterion) HandlerBehaviour(org.onosproject.net.driver.HandlerBehaviour) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) List(java.util.List) FlowRuleService(org.onosproject.net.flow.FlowRuleService) TrafficSelector(org.onosproject.net.flow.TrafficSelector) CrossConnects(org.onosproject.yang.gen.v1.opticalswitch.rev20180322.opticalswitch.CrossConnects) DefaultPair(org.onosproject.yang.gen.v1.opticalswitch.rev20180322.opticalswitch.crossconnects.DefaultPair) FlowRule(org.onosproject.net.flow.FlowRule) DefaultTrafficSelector(org.onosproject.net.flow.DefaultTrafficSelector) Criterion(org.onosproject.net.flow.criteria.Criterion) DefaultCrossConnects(org.onosproject.yang.gen.v1.opticalswitch.rev20180322.opticalswitch.DefaultCrossConnects) PortCriterion(org.onosproject.net.flow.criteria.PortCriterion) Criterion(org.onosproject.net.flow.criteria.Criterion) DefaultCrossConnects(org.onosproject.yang.gen.v1.opticalswitch.rev20180322.opticalswitch.DefaultCrossConnects) PortFormat(org.onosproject.yang.gen.v1.opticalswitch.rev20180322.opticalswitch.PortFormat) DefaultPair(org.onosproject.yang.gen.v1.opticalswitch.rev20180322.opticalswitch.crossconnects.DefaultPair) Instructions(org.onosproject.net.flow.instructions.Instructions) PortCriterion(org.onosproject.net.flow.criteria.PortCriterion) PortNumber(org.onosproject.net.PortNumber) Instruction(org.onosproject.net.flow.instructions.Instruction)

Example 5 with HandlerBehaviour

use of org.onosproject.net.driver.HandlerBehaviour in project onos by opennetworkinglab.

the class PolatisOpticalUtility method toFlowRule.

/**
 * Finds the FlowRule from flow rule store by the given ports and channel.
 * Returns an extra flow to remove the flow by ONOS if not found.
 * @param behaviour the parent driver handler
 * @param inPort the input port
 * @param outPort the output port
 * @return the flow rule
 */
public static FlowRule toFlowRule(HandlerBehaviour behaviour, PortNumber inPort, PortNumber outPort) {
    FlowRuleService service = behaviour.handler().get(FlowRuleService.class);
    Iterable<FlowEntry> entries = service.getFlowEntries(behaviour.data().deviceId());
    // Try to Find the flow from flow rule store.
    for (FlowEntry entry : entries) {
        Set<Criterion> criterions = entry.selector().criteria();
        // input port
        PortNumber ip = criterions.stream().filter(c -> c instanceof PortCriterion).map(c -> ((PortCriterion) c).port()).findAny().orElse(null);
        // output port
        PortNumber op = entry.treatment().immediate().stream().filter(c -> c instanceof Instructions.OutputInstruction).map(c -> ((Instructions.OutputInstruction) c).port()).findAny().orElse(null);
        if (inPort.equals(ip) && outPort.equals(op)) {
            // Find the flow.
            return entry;
        }
    }
    // Cannot find the flow from store. So report an extra flow to remove the flow by ONOS.
    TrafficSelector selector = DefaultTrafficSelector.builder().matchInPort(inPort).build();
    TrafficTreatment treatment = DefaultTrafficTreatment.builder().setOutput(outPort).build();
    return DefaultFlowRule.builder().forDevice(behaviour.data().deviceId()).withSelector(selector).withTreatment(treatment).makePermanent().withPriority(DEFAULT_PRIORITY).fromApp(behaviour.handler().get(CoreService.class).getAppId(DEFAULT_APP)).build();
}
Also used : TrafficTreatment(org.onosproject.net.flow.TrafficTreatment) Instructions(org.onosproject.net.flow.instructions.Instructions) PortFormat(org.onosproject.yang.gen.v1.opticalswitch.rev20180322.opticalswitch.PortFormat) DefaultFlowRule(org.onosproject.net.flow.DefaultFlowRule) CoreService(org.onosproject.core.CoreService) Instruction(org.onosproject.net.flow.instructions.Instruction) Range(com.google.common.collect.Range) PortNumber(org.onosproject.net.PortNumber) FlowEntry(org.onosproject.net.flow.FlowEntry) Pair(org.onosproject.yang.gen.v1.opticalswitch.rev20180322.opticalswitch.crossconnects.Pair) Set(java.util.Set) PortCriterion(org.onosproject.net.flow.criteria.PortCriterion) HandlerBehaviour(org.onosproject.net.driver.HandlerBehaviour) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) List(java.util.List) FlowRuleService(org.onosproject.net.flow.FlowRuleService) TrafficSelector(org.onosproject.net.flow.TrafficSelector) CrossConnects(org.onosproject.yang.gen.v1.opticalswitch.rev20180322.opticalswitch.CrossConnects) DefaultPair(org.onosproject.yang.gen.v1.opticalswitch.rev20180322.opticalswitch.crossconnects.DefaultPair) FlowRule(org.onosproject.net.flow.FlowRule) DefaultTrafficSelector(org.onosproject.net.flow.DefaultTrafficSelector) Criterion(org.onosproject.net.flow.criteria.Criterion) DefaultCrossConnects(org.onosproject.yang.gen.v1.opticalswitch.rev20180322.opticalswitch.DefaultCrossConnects) CoreService(org.onosproject.core.CoreService) Instructions(org.onosproject.net.flow.instructions.Instructions) PortCriterion(org.onosproject.net.flow.criteria.PortCriterion) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) PortCriterion(org.onosproject.net.flow.criteria.PortCriterion) Criterion(org.onosproject.net.flow.criteria.Criterion) TrafficSelector(org.onosproject.net.flow.TrafficSelector) DefaultTrafficSelector(org.onosproject.net.flow.DefaultTrafficSelector) FlowRuleService(org.onosproject.net.flow.FlowRuleService) PortNumber(org.onosproject.net.PortNumber) FlowEntry(org.onosproject.net.flow.FlowEntry)

Aggregations

Range (com.google.common.collect.Range)5 List (java.util.List)5 Set (java.util.Set)5 CoreService (org.onosproject.core.CoreService)5 PortNumber (org.onosproject.net.PortNumber)5 HandlerBehaviour (org.onosproject.net.driver.HandlerBehaviour)5 DefaultFlowRule (org.onosproject.net.flow.DefaultFlowRule)5 DefaultTrafficSelector (org.onosproject.net.flow.DefaultTrafficSelector)5 DefaultTrafficTreatment (org.onosproject.net.flow.DefaultTrafficTreatment)5 FlowEntry (org.onosproject.net.flow.FlowEntry)5 FlowRule (org.onosproject.net.flow.FlowRule)5 FlowRuleService (org.onosproject.net.flow.FlowRuleService)5 TrafficSelector (org.onosproject.net.flow.TrafficSelector)5 TrafficTreatment (org.onosproject.net.flow.TrafficTreatment)5 Criterion (org.onosproject.net.flow.criteria.Criterion)5 PortCriterion (org.onosproject.net.flow.criteria.PortCriterion)5 Instruction (org.onosproject.net.flow.instructions.Instruction)5 Instructions (org.onosproject.net.flow.instructions.Instructions)5 Frequency (org.onlab.util.Frequency)2 OplinkAttenuation (org.onosproject.driver.extensions.OplinkAttenuation)2