Search in sources :

Example 31 with Port

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

the class ECDeviceStore method refreshDevicePortCache.

private List<DeviceEvent> refreshDevicePortCache(ProviderId providerId, DeviceId deviceId, Optional<PortNumber> portNumber) {
    Device device = devices.get(deviceId);
    checkArgument(device != null, DEVICE_NOT_FOUND, deviceId);
    List<DeviceEvent> events = Lists.newArrayList();
    Map<PortNumber, Port> ports = devicePorts.computeIfAbsent(deviceId, key -> Maps.newConcurrentMap());
    List<PortDescription> descriptions = Lists.newArrayList();
    portDescriptions.entrySet().forEach(e -> {
        PortKey key = e.getKey();
        PortDescription value = e.getValue();
        if (key.deviceId().equals(deviceId) && key.providerId().equals(providerId)) {
            if (portNumber.isPresent()) {
                if (portNumber.get().equals(key.portNumber())) {
                    descriptions.add(value);
                }
            } else {
                descriptions.add(value);
            }
        }
    });
    for (PortDescription description : descriptions) {
        final PortNumber number = description.portNumber();
        ports.compute(number, (k, existingPort) -> {
            Port newPort = composePort(device, number);
            if (existingPort == null) {
                events.add(new DeviceEvent(PORT_ADDED, device, newPort));
            } else {
                if (existingPort.isEnabled() != newPort.isEnabled() || existingPort.type() != newPort.type() || existingPort.portSpeed() != newPort.portSpeed() || !AnnotationsUtil.isEqual(existingPort.annotations(), newPort.annotations())) {
                    events.add(new DeviceEvent(PORT_UPDATED, device, newPort));
                }
            }
            return newPort;
        });
    }
    return events;
}
Also used : DeviceEvent(org.onosproject.net.device.DeviceEvent) DefaultDevice(org.onosproject.net.DefaultDevice) Device(org.onosproject.net.Device) Port(org.onosproject.net.Port) DefaultPort(org.onosproject.net.DefaultPort) PortDescription(org.onosproject.net.device.PortDescription) PortNumber(org.onosproject.net.PortNumber)

Example 32 with Port

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

the class ECDeviceStore method composePort.

/**
 * Returns a Port, merging descriptions from multiple Providers.
 *
 * @param device   device the port is on
 * @param number   port number
 * @return Port instance
 */
private Port composePort(Device device, PortNumber number) {
    Map<ProviderId, PortDescription> descriptions = Maps.newHashMap();
    portDescriptions.entrySet().forEach(entry -> {
        PortKey portKey = entry.getKey();
        if (portKey.deviceId().equals(device.id()) && portKey.portNumber().equals(number)) {
            descriptions.put(portKey.providerId(), entry.getValue());
        }
    });
    ProviderId primary = getPrimaryProviderId(device.id());
    PortDescription primaryDescription = descriptions.get(primary);
    // if no primary, assume not enabled
    boolean isEnabled = false;
    DefaultAnnotations annotations = DefaultAnnotations.builder().build();
    if (primaryDescription != null) {
        isEnabled = primaryDescription.isEnabled();
        annotations = merge(annotations, primaryDescription.annotations());
    }
    Port updated = null;
    for (Entry<ProviderId, PortDescription> e : descriptions.entrySet()) {
        if (e.getKey().equals(primary)) {
            continue;
        }
        annotations = merge(annotations, e.getValue().annotations());
        updated = buildTypedPort(device, number, isEnabled, e.getValue(), annotations);
    }
    if (primaryDescription == null) {
        return updated == null ? new DefaultPort(device, number, false, annotations) : updated;
    }
    return updated == null ? buildTypedPort(device, number, isEnabled, primaryDescription, annotations) : updated;
}
Also used : ProviderId(org.onosproject.net.provider.ProviderId) DefaultAnnotations(org.onosproject.net.DefaultAnnotations) Port(org.onosproject.net.Port) DefaultPort(org.onosproject.net.DefaultPort) PortDescription(org.onosproject.net.device.PortDescription) DefaultPort(org.onosproject.net.DefaultPort)

Example 33 with Port

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

the class LumentumNetconfRoadmDiscovery method parseLumentumRoadmPorts.

/**
 * Parses a configuration and returns a set of ports.
 *
 * @param cfg a hierarchical configuration
 * @return a list of port descriptions
 */
protected List<PortDescription> parseLumentumRoadmPorts(HierarchicalConfiguration cfg) {
    List<PortDescription> portDescriptions = Lists.newArrayList();
    List<HierarchicalConfiguration> ports = cfg.configurationsAt(PHYSICAL_PORT);
    ports.stream().forEach(pcfg -> {
        DefaultAnnotations.Builder annotations = DefaultAnnotations.builder();
        // Load port number
        PortNumber portNum = PortNumber.portNumber(pcfg.getString(DN).substring(pcfg.getString(DN).lastIndexOf(DN_PORT) + 5));
        // Load port state
        String maintenanceState = pcfg.getString(MAINTENANCE_STATE);
        boolean isEnabled = ((maintenanceState != null) && (maintenanceState).equals(IN_SERVICE));
        // Load port type (FIBER/COPPER)
        Port.Type type = null;
        for (Object o : pcfg.getList(PORT_EXTENSION)) {
            String s = (String) o;
            if (s.contains(OPTICAL_INPUT) || s.contains(OPTICAL_OUTPUT)) {
                type = Port.Type.FIBER;
                log.debug("Loaded OPTICAL port {}", portNum);
            } else if (s.contains(PORT_ETHERNET) || s.contains(PORT_PLUGGABLE)) {
                type = Port.Type.COPPER;
                log.debug("Loaded PACKET port {}", portNum);
            }
        }
        // Load port speed of Ethernet interface, expressed in Mb/s
        // should be the speed of optical port
        Long speed = 0L;
        if (type != null) {
            if (type.equals(Port.Type.COPPER)) {
                String speedString = pcfg.getString(PORT_SPEED);
                log.debug("--- port {} loaded speed {}", portNum, speedString);
                if (speedString != null) {
                    if (speedString.contains("Mb")) {
                        speed = Long.parseLong(speedString.substring(speedString.lastIndexOf("speed_") + 6, speedString.lastIndexOf("Mb")));
                    }
                    if (speedString.contains("Gb")) {
                        speed = 1000 * Long.parseLong(speedString.substring(speedString.lastIndexOf("speed_") + 6, speedString.lastIndexOf("Gb")));
                    }
                } else {
                    log.error("Lumentum NETCONF - Port speed of Ethernet port not correctly loaded");
                }
            }
        } else {
            log.error("Port Type not correctly loaded");
        }
        /**
         * Setting the reverse port value for the unidirectional ports.
         *
         * In this device each port includes an input fiber and an output fiber.
         * The 20 input  fibers are numbered from MIN_MUX_PORT = 4101 to MAX_MUX_PORT = 4120.
         * The 20 output fibers are numbered from MIN_DEM_PORT = 5201 to MAX_DEM_PORT = 5220.
         *
         * Where port 520x is always the reverse of 410x.
         */
        if ((portNum.toLong() >= MIN_MUX_PORT) && (portNum.toLong() <= MAX_MUX_PORT)) {
            Long reversePortId = portNum.toLong() + DELTA_MUX_DEM_PORT;
            annotations.set(OpticalPathIntent.REVERSE_PORT_ANNOTATION_KEY, reversePortId.toString());
        }
        if ((portNum.toLong() >= MIN_DEM_PORT) && (portNum.toLong() <= MAX_DEM_PORT)) {
            Long reversePortId = portNum.toLong() - DELTA_MUX_DEM_PORT;
            annotations.set(OpticalPathIntent.REVERSE_PORT_ANNOTATION_KEY, reversePortId.toString());
        }
        // Load other information
        pcfg.getKeys().forEachRemaining(k -> {
            if (!k.contains(DN) && !k.contains(PORT_SPEED) && !k.contains(PORT_EXTENSION) && !k.contains(MAINTENANCE_STATE)) {
                String value = pcfg.getString(k);
                if (!value.isEmpty()) {
                    k = StringUtils.replaceEach(k, new String[] { "loteeth:", "lotep:", "lotepopt:", "config.", "=", ":", "state." }, new String[] { "", "", "", "", "", "", "" });
                    annotations.set(k, value);
                    // To visualize port name in the ROADM app GUI
                    if (k.equals(PORT_NAME)) {
                        annotations.set(AnnotationKeys.PORT_NAME, value);
                    }
                }
            }
        });
        log.debug("Lumentum NETCONF - retrieved port {},{},{},{},{}", portNum, isEnabled, type, speed, annotations.build());
        if ((type == Port.Type.FIBER) && ((annotations.build().value(AnnotationKeys.PORT_NAME)).contains(MUX_PORT_NAME) || (annotations.build().value(AnnotationKeys.PORT_NAME)).contains(DEMUX_PORT_NAME) || (annotations.build().value(AnnotationKeys.PORT_NAME)).contains(LINE_PORT_NAME))) {
            // These are the ports supporting OchSignals
            portDescriptions.add(omsPortDescription(portNum, isEnabled, START_CENTER_FREQ_50, END_CENTER_FREQ_50, CHANNEL_SPACING_50.frequency(), annotations.build()));
        } else {
            // These are COPPER ports, or FIBER ports not supporting OchSignals
            DefaultPortDescription.Builder portDescriptionBuilder = DefaultPortDescription.builder();
            portDescriptionBuilder.withPortNumber(portNum).isEnabled(isEnabled).type(type).portSpeed(speed).annotations(annotations.build());
            portDescriptions.add(portDescriptionBuilder.build());
        }
    });
    return portDescriptions;
}
Also used : DefaultAnnotations(org.onosproject.net.DefaultAnnotations) Port(org.onosproject.net.Port) OmsPortHelper.omsPortDescription(org.onosproject.net.optical.device.OmsPortHelper.omsPortDescription) PortDescription(org.onosproject.net.device.PortDescription) DefaultPortDescription(org.onosproject.net.device.DefaultPortDescription) HierarchicalConfiguration(org.apache.commons.configuration.HierarchicalConfiguration) DefaultPortDescription(org.onosproject.net.device.DefaultPortDescription) PortNumber(org.onosproject.net.PortNumber)

Example 34 with Port

use of org.onosproject.net.Port 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 35 with Port

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

Aggregations

Port (org.onosproject.net.Port)200 DeviceService (org.onosproject.net.device.DeviceService)92 PortNumber (org.onosproject.net.PortNumber)85 ConnectPoint (org.onosproject.net.ConnectPoint)78 DeviceId (org.onosproject.net.DeviceId)76 Device (org.onosproject.net.Device)63 List (java.util.List)51 Set (java.util.Set)47 Optional (java.util.Optional)43 DefaultPort (org.onosproject.net.DefaultPort)38 Logger (org.slf4j.Logger)38 ArrayList (java.util.ArrayList)36 Collectors (java.util.stream.Collectors)35 Collections (java.util.Collections)34 Collection (java.util.Collection)33 TrafficTreatment (org.onosproject.net.flow.TrafficTreatment)33 Test (org.junit.Test)31 Ethernet (org.onlab.packet.Ethernet)31 Map (java.util.Map)29 Sets (com.google.common.collect.Sets)28