Search in sources :

Example 1 with CrossConnectCache

use of org.onosproject.driver.optical.flowrule.CrossConnectCache in project onos by opennetworkinglab.

the class LumentumSdnRoadmFlowRuleProgrammable method applyFlowRules.

@Override
public Collection<FlowRule> applyFlowRules(Collection<FlowRule> rules) {
    try {
        snmp = new LumentumSnmpDevice(data().deviceId());
    } catch (IOException e) {
        log.error("Failed to connect to device: ", e);
    }
    // Line ports
    DeviceService deviceService = this.handler().get(DeviceService.class);
    List<Port> ports = deviceService.getPorts(data().deviceId());
    List<PortNumber> linePorts = ports.subList(ports.size() - 2, ports.size()).stream().map(p -> p.number()).collect(Collectors.toList());
    // Apply the valid rules on the device
    Collection<FlowRule> added = rules.stream().map(r -> new CrossConnectFlowRule(r, linePorts)).filter(xc -> installCrossConnect(xc)).collect(Collectors.toList());
    // Cache the cookie/priority
    CrossConnectCache cache = this.handler().get(CrossConnectCache.class);
    added.forEach(xc -> cache.set(Objects.hash(data().deviceId(), xc.selector(), xc.treatment()), xc.id(), xc.priority()));
    return added;
}
Also used : GridType(org.onosproject.net.GridType) Arrays(java.util.Arrays) FlowRuleProgrammable(org.onosproject.net.flow.FlowRuleProgrammable) TreeEvent(org.snmp4j.util.TreeEvent) DefaultFlowRule(org.onosproject.net.flow.DefaultFlowRule) PortNumber(org.onosproject.net.PortNumber) DeviceService(org.onosproject.net.device.DeviceService) LoggerFactory(org.slf4j.LoggerFactory) FlowEntry(org.onosproject.net.flow.FlowEntry) PDU(org.snmp4j.PDU) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) AbstractHandlerBehaviour(org.onosproject.net.driver.AbstractHandlerBehaviour) Preconditions.checkArgument(com.google.common.base.Preconditions.checkArgument) Lists(com.google.common.collect.Lists) TrafficSelector(org.onosproject.net.flow.TrafficSelector) Pair(org.apache.commons.lang3.tuple.Pair) Port(org.onosproject.net.Port) VariableBinding(org.snmp4j.smi.VariableBinding) Criteria(org.onosproject.net.flow.criteria.Criteria) LinkedList(java.util.LinkedList) CrossConnectFlowRule(org.onosproject.driver.optical.flowrule.CrossConnectFlowRule) DefaultTrafficSelector(org.onosproject.net.flow.DefaultTrafficSelector) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment) OchSignalType(org.onosproject.net.OchSignalType) DefaultFlowEntry(org.onosproject.net.flow.DefaultFlowEntry) Logger(org.slf4j.Logger) Collection(java.util.Collection) IOException(java.io.IOException) Integer32(org.snmp4j.smi.Integer32) Collectors(java.util.stream.Collectors) FlowId(org.onosproject.net.flow.FlowId) OchSignal(org.onosproject.net.OchSignal) Objects(java.util.Objects) UnsignedInteger32(org.snmp4j.smi.UnsignedInteger32) List(java.util.List) ResponseEvent(org.snmp4j.event.ResponseEvent) FlowRule(org.onosproject.net.flow.FlowRule) ChannelSpacing(org.onosproject.net.ChannelSpacing) CrossConnectCache(org.onosproject.driver.optical.flowrule.CrossConnectCache) Collections(java.util.Collections) OID(org.snmp4j.smi.OID) CrossConnectCache(org.onosproject.driver.optical.flowrule.CrossConnectCache) Port(org.onosproject.net.Port) DeviceService(org.onosproject.net.device.DeviceService) CrossConnectFlowRule(org.onosproject.driver.optical.flowrule.CrossConnectFlowRule) IOException(java.io.IOException) DefaultFlowRule(org.onosproject.net.flow.DefaultFlowRule) CrossConnectFlowRule(org.onosproject.driver.optical.flowrule.CrossConnectFlowRule) FlowRule(org.onosproject.net.flow.FlowRule) PortNumber(org.onosproject.net.PortNumber)

Example 2 with CrossConnectCache

use of org.onosproject.driver.optical.flowrule.CrossConnectCache in project onos by opennetworkinglab.

the class LumentumSdnRoadmFlowRuleProgrammable method fetchRules.

// Returns the currently installed flow entries on the device.
private List<FlowRule> fetchRules(OID oid, boolean isAdd, PortNumber linePort) {
    List<FlowRule> rules = new LinkedList<>();
    for (TreeEvent event : snmp.get(oid)) {
        if (event == null) {
            continue;
        }
        VariableBinding[] varBindings = event.getVariableBindings();
        for (VariableBinding varBinding : varBindings) {
            CrossConnectCache cache = this.handler().get(CrossConnectCache.class);
            if (varBinding.getVariable().toInt() == IN_SERVICE) {
                int channel = varBinding.getOid().removeLast();
                PortNumber addDropPort = getAddDropPort(channel, isAdd);
                if (addDropPort == null) {
                    continue;
                }
                TrafficSelector selector = DefaultTrafficSelector.builder().matchInPort(isAdd ? addDropPort : linePort).add(Criteria.matchOchSignalType(OchSignalType.FIXED_GRID)).add(Criteria.matchLambda(toOchSignal(channel))).build();
                TrafficTreatment treatment = DefaultTrafficTreatment.builder().setOutput(isAdd ? linePort : addDropPort).build();
                // Lookup flow ID and priority
                int hash = Objects.hash(data().deviceId(), selector, treatment);
                Pair<FlowId, Integer> lookup = cache.get(hash);
                if (lookup == null) {
                    continue;
                }
                FlowRule fr = DefaultFlowRule.builder().forDevice(data().deviceId()).makePermanent().withSelector(selector).withTreatment(treatment).withPriority(lookup.getRight()).withCookie(lookup.getLeft().value()).build();
                rules.add(fr);
            }
        }
    }
    return rules;
}
Also used : CrossConnectCache(org.onosproject.driver.optical.flowrule.CrossConnectCache) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment) LinkedList(java.util.LinkedList) TreeEvent(org.snmp4j.util.TreeEvent) FlowId(org.onosproject.net.flow.FlowId) TrafficSelector(org.onosproject.net.flow.TrafficSelector) DefaultTrafficSelector(org.onosproject.net.flow.DefaultTrafficSelector) DefaultFlowRule(org.onosproject.net.flow.DefaultFlowRule) CrossConnectFlowRule(org.onosproject.driver.optical.flowrule.CrossConnectFlowRule) FlowRule(org.onosproject.net.flow.FlowRule) PortNumber(org.onosproject.net.PortNumber) VariableBinding(org.snmp4j.smi.VariableBinding)

Example 3 with CrossConnectCache

use of org.onosproject.driver.optical.flowrule.CrossConnectCache in project onos by opennetworkinglab.

the class LumentumSdnRoadmFlowRuleProgrammable method removeFlowRules.

@Override
public Collection<FlowRule> removeFlowRules(Collection<FlowRule> rules) {
    try {
        snmp = new LumentumSnmpDevice(data().deviceId());
    } catch (IOException e) {
        log.error("Failed to connect to device: ", e);
    }
    // Line ports
    DeviceService deviceService = this.handler().get(DeviceService.class);
    List<Port> ports = deviceService.getPorts(data().deviceId());
    List<PortNumber> linePorts = ports.subList(ports.size() - 2, ports.size()).stream().map(p -> p.number()).collect(Collectors.toList());
    // Apply the valid rules on the device
    Collection<FlowRule> removed = rules.stream().map(r -> new CrossConnectFlowRule(r, linePorts)).filter(xc -> removeCrossConnect(xc)).collect(Collectors.toList());
    // Remove flow rule from cache
    CrossConnectCache cache = this.handler().get(CrossConnectCache.class);
    removed.forEach(xc -> cache.remove(Objects.hash(data().deviceId(), xc.selector(), xc.treatment())));
    return removed;
}
Also used : GridType(org.onosproject.net.GridType) Arrays(java.util.Arrays) FlowRuleProgrammable(org.onosproject.net.flow.FlowRuleProgrammable) TreeEvent(org.snmp4j.util.TreeEvent) DefaultFlowRule(org.onosproject.net.flow.DefaultFlowRule) PortNumber(org.onosproject.net.PortNumber) DeviceService(org.onosproject.net.device.DeviceService) LoggerFactory(org.slf4j.LoggerFactory) FlowEntry(org.onosproject.net.flow.FlowEntry) PDU(org.snmp4j.PDU) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) AbstractHandlerBehaviour(org.onosproject.net.driver.AbstractHandlerBehaviour) Preconditions.checkArgument(com.google.common.base.Preconditions.checkArgument) Lists(com.google.common.collect.Lists) TrafficSelector(org.onosproject.net.flow.TrafficSelector) Pair(org.apache.commons.lang3.tuple.Pair) Port(org.onosproject.net.Port) VariableBinding(org.snmp4j.smi.VariableBinding) Criteria(org.onosproject.net.flow.criteria.Criteria) LinkedList(java.util.LinkedList) CrossConnectFlowRule(org.onosproject.driver.optical.flowrule.CrossConnectFlowRule) DefaultTrafficSelector(org.onosproject.net.flow.DefaultTrafficSelector) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment) OchSignalType(org.onosproject.net.OchSignalType) DefaultFlowEntry(org.onosproject.net.flow.DefaultFlowEntry) Logger(org.slf4j.Logger) Collection(java.util.Collection) IOException(java.io.IOException) Integer32(org.snmp4j.smi.Integer32) Collectors(java.util.stream.Collectors) FlowId(org.onosproject.net.flow.FlowId) OchSignal(org.onosproject.net.OchSignal) Objects(java.util.Objects) UnsignedInteger32(org.snmp4j.smi.UnsignedInteger32) List(java.util.List) ResponseEvent(org.snmp4j.event.ResponseEvent) FlowRule(org.onosproject.net.flow.FlowRule) ChannelSpacing(org.onosproject.net.ChannelSpacing) CrossConnectCache(org.onosproject.driver.optical.flowrule.CrossConnectCache) Collections(java.util.Collections) OID(org.snmp4j.smi.OID) CrossConnectCache(org.onosproject.driver.optical.flowrule.CrossConnectCache) Port(org.onosproject.net.Port) DeviceService(org.onosproject.net.device.DeviceService) CrossConnectFlowRule(org.onosproject.driver.optical.flowrule.CrossConnectFlowRule) IOException(java.io.IOException) DefaultFlowRule(org.onosproject.net.flow.DefaultFlowRule) CrossConnectFlowRule(org.onosproject.driver.optical.flowrule.CrossConnectFlowRule) FlowRule(org.onosproject.net.flow.FlowRule) PortNumber(org.onosproject.net.PortNumber)

Aggregations

LinkedList (java.util.LinkedList)3 CrossConnectCache (org.onosproject.driver.optical.flowrule.CrossConnectCache)3 CrossConnectFlowRule (org.onosproject.driver.optical.flowrule.CrossConnectFlowRule)3 PortNumber (org.onosproject.net.PortNumber)3 DefaultFlowRule (org.onosproject.net.flow.DefaultFlowRule)3 DefaultTrafficSelector (org.onosproject.net.flow.DefaultTrafficSelector)3 DefaultTrafficTreatment (org.onosproject.net.flow.DefaultTrafficTreatment)3 FlowId (org.onosproject.net.flow.FlowId)3 FlowRule (org.onosproject.net.flow.FlowRule)3 TrafficSelector (org.onosproject.net.flow.TrafficSelector)3 TrafficTreatment (org.onosproject.net.flow.TrafficTreatment)3 VariableBinding (org.snmp4j.smi.VariableBinding)3 TreeEvent (org.snmp4j.util.TreeEvent)3 Preconditions.checkArgument (com.google.common.base.Preconditions.checkArgument)2 Lists (com.google.common.collect.Lists)2 IOException (java.io.IOException)2 Arrays (java.util.Arrays)2 Collection (java.util.Collection)2 Collections (java.util.Collections)2 List (java.util.List)2