Search in sources :

Example 61 with PortNumber

use of org.onosproject.net.PortNumber 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)

Example 62 with PortNumber

use of org.onosproject.net.PortNumber 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 63 with PortNumber

use of org.onosproject.net.PortNumber 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 64 with PortNumber

use of org.onosproject.net.PortNumber in project onos by opennetworkinglab.

the class TerminalDeviceDiscovery method parsePortComponent.

/**
 * Parses a component XML doc into a PortDescription.
 *
 * @param component subtree to parse. It must be a component ot type PORT.
 * @param components the full components tree, to cross-ref in
 *  case we need to check transceivers or optical channels.
 *
 * @return PortDescription or null if component does not have onos-index
 */
private PortDescription parsePortComponent(HierarchicalConfiguration component, HierarchicalConfiguration components) {
    Map<String, String> annotations = new HashMap<>();
    String name = component.getString("name");
    String type = component.getString("state/type");
    log.info("Parsing Component {} type {}", name, type);
    annotations.put(OdtnDeviceDescriptionDiscovery.OC_NAME, name);
    annotations.put(OdtnDeviceDescriptionDiscovery.OC_TYPE, type);
    // Store all properties as port properties
    component.configurationsAt("properties/property").forEach(property -> {
        String pn = property.getString("name");
        String pv = property.getString("state/value");
        annotations.put(pn, pv);
    });
    // Assing an ONOS port number
    PortNumber portNum;
    if (annotations.containsKey(ONOS_PORT_INDEX)) {
        portNum = PortNumber.portNumber(Long.parseLong(annotations.get(ONOS_PORT_INDEX)));
    } else {
        log.warn("PORT {} does not include onos-index, hashing...", name);
        portNum = PortNumber.portNumber(name.hashCode());
    }
    log.debug("PORT {} number {}", name, portNum);
    // The heuristic to know if it is client or line side
    if (!annotations.containsKey(PORT_TYPE)) {
        if (hasTransceiverSubComponent(component, components)) {
            annotations.put(PORT_TYPE, OdtnPortType.CLIENT.value());
        } else if (hasOpticalChannelSubComponent(component, components)) {
            annotations.put(PORT_TYPE, OdtnPortType.LINE.value());
        }
    }
    // to be an issue with resource mapping
    if (annotations.get(PORT_TYPE).equals(OdtnPortType.CLIENT.value())) {
        log.debug("Adding CLIENT port");
        Builder builder = DefaultPortDescription.builder();
        builder.type(Type.PACKET);
        builder.withPortNumber(portNum);
        builder.annotations(DefaultAnnotations.builder().putAll(annotations).build());
        return builder.build();
    }
    if (annotations.get(PORT_TYPE).equals(OdtnPortType.LINE.value())) {
        log.debug("Adding LINE port");
        // TODO: To be configured
        OchSignal signalId = OchSignal.newDwdmSlot(ChannelSpacing.CHL_50GHZ, 1);
        return OchPortHelper.ochPortDescription(portNum, true, // TODO Client signal to be discovered
        OduSignalType.ODU4, true, signalId, DefaultAnnotations.builder().putAll(annotations).build());
    }
    log.error("Unknown port type");
    return null;
}
Also used : HashMap(java.util.HashMap) Builder(org.onosproject.net.device.DefaultPortDescription.Builder) OchSignal(org.onosproject.net.OchSignal) PortNumber(org.onosproject.net.PortNumber)

Example 65 with PortNumber

use of org.onosproject.net.PortNumber in project onos by opennetworkinglab.

the class OpenConfigDeviceDiscovery method toPortDescriptionInternal.

/**
 * Converts Component subtree to PortDescription.
 *
 * @param component subtree to parse
 * @return PortDescription or null if component is not an ONOS Port
 */
private PortDescription toPortDescriptionInternal(HierarchicalConfiguration component) {
    // to access other part of <data> tree:
    // log.warn("parent data Node: {}",
    // ((SubnodeConfiguration) component).getParent().getRootNode().getName());
    Map<String, String> props = new HashMap<>();
    String name = component.getString("name");
    String type = component.getString("state/type");
    checkNotNull(name, "name not found");
    checkNotNull(type, "state/type not found");
    props.put(OdtnDeviceDescriptionDiscovery.OC_NAME, name);
    props.put(OdtnDeviceDescriptionDiscovery.OC_TYPE, type);
    component.configurationsAt("properties/property").forEach(prop -> {
        String pName = prop.getString("name");
        String pValue = prop.getString("config/value");
        props.put(pName, pValue);
    });
    PortNumber number = null;
    if (!props.containsKey(ONOS_PORT_INDEX)) {
        log.info("DEBUG: Component {} does not include onos-index, skipping", name);
        // ODTN: port must have onos-index property
        number = PortNumber.portNumber(COUNTER.getAndIncrement(), name);
    } else {
        number = PortNumber.portNumber(Long.parseLong(props.get(ONOS_PORT_INDEX)), name);
    }
    Builder builder = DefaultPortDescription.builder();
    builder.withPortNumber(number);
    switch(type) {
        case "oc-platform-types:PORT":
        case "PORT":
        case "oc-opt-types:OPTICAL_CHANNEL":
        case "OPTICAL CHANNEL":
            // TODO assign appropriate port type & annotations at some point
            // for now we just need a Port with annotations
            builder.type(Type.OCH);
            props.putIfAbsent(PORT_TYPE, OdtnPortType.LINE.value());
            // Just a heuristics to deal with simple transponder
            // if the device declare odtn-connection-id, just use them
            // if not assign same value to relevant ports types
            props.putIfAbsent(CONNECTION_ID, "the-only-one");
            break;
        case "oc-platform-types:TRANSCEIVER":
        case "TRANSCEIVER":
            // TODO assign appropriate port type & annotations at some point
            // for now we just need a Port with annotations
            builder.type(Type.PACKET);
            props.putIfAbsent(PORT_TYPE, OdtnPortType.CLIENT.value());
            // Just a heuristics to deal with simple transponder
            // if the device declare odtn-connection-id, just use them
            // if not assign same value to relevant ports types
            props.putIfAbsent(CONNECTION_ID, "the-only-one");
            break;
        default:
            log.info("DEBUG: Unknown component type {}", type);
            return null;
    }
    builder.annotations(DefaultAnnotations.builder().putAll(props).build());
    return builder.build();
}
Also used : HashMap(java.util.HashMap) Builder(org.onosproject.net.device.DefaultPortDescription.Builder) PortNumber(org.onosproject.net.PortNumber)

Aggregations

PortNumber (org.onosproject.net.PortNumber)336 DeviceId (org.onosproject.net.DeviceId)136 TrafficTreatment (org.onosproject.net.flow.TrafficTreatment)109 DefaultTrafficTreatment (org.onosproject.net.flow.DefaultTrafficTreatment)103 ConnectPoint (org.onosproject.net.ConnectPoint)82 TrafficSelector (org.onosproject.net.flow.TrafficSelector)80 DefaultTrafficSelector (org.onosproject.net.flow.DefaultTrafficSelector)74 Port (org.onosproject.net.Port)67 ArrayList (java.util.ArrayList)64 Set (java.util.Set)64 List (java.util.List)59 Logger (org.slf4j.Logger)58 Collectors (java.util.stream.Collectors)51 DeviceService (org.onosproject.net.device.DeviceService)49 VlanId (org.onlab.packet.VlanId)42 MacAddress (org.onlab.packet.MacAddress)41 Device (org.onosproject.net.Device)40 FlowRule (org.onosproject.net.flow.FlowRule)40 Optional (java.util.Optional)39 Sets (com.google.common.collect.Sets)35