Search in sources :

Example 21 with PortDescription

use of org.onosproject.net.device.PortDescription in project onos by opennetworkinglab.

the class OplinkHandshakerUtil method buildPortPowerDescriptions.

/**
 * Creates port descriptions with current power.
 *
 * @param portPowers current power
 * @return port descriptions
 */
public List<PortDescription> buildPortPowerDescriptions(List<OFOplinkPortPower> portPowers) {
    DeviceService deviceService = driver.handler().get(DeviceService.class);
    List<Port> ports = deviceService.getPorts(driver.data().deviceId());
    HashMap<Long, OFOplinkPortPower> powerMap = new HashMap<>(portPowers.size());
    // Get each port power value
    portPowers.forEach(power -> powerMap.put((long) power.getPort(), power));
    final List<PortDescription> portDescs = new ArrayList<>();
    for (Port port : ports) {
        DefaultAnnotations.Builder builder = DefaultAnnotations.builder();
        builder.putAll(port.annotations());
        OFOplinkPortPower power = powerMap.get(port.number().toLong());
        if (power != null) {
            // power value is actually signed-short value, down casting to recover sign bit.
            builder.set(OpticalAnnotations.CURRENT_POWER, Short.toString((short) power.getPowerValue()));
        }
        portDescs.add(DefaultPortDescription.builder().withPortNumber(port.number()).isEnabled(port.isEnabled()).type(port.type()).portSpeed(port.portSpeed()).annotations(builder.build()).build());
    }
    return portDescs;
}
Also used : OFOplinkPortPower(org.projectfloodlight.openflow.protocol.OFOplinkPortPower) DefaultAnnotations(org.onosproject.net.DefaultAnnotations) HashMap(java.util.HashMap) Port(org.onosproject.net.Port) DeviceService(org.onosproject.net.device.DeviceService) ArrayList(java.util.ArrayList) PortDescription(org.onosproject.net.device.PortDescription) DefaultPortDescription(org.onosproject.net.device.DefaultPortDescription)

Example 22 with PortDescription

use of org.onosproject.net.device.PortDescription in project onos by opennetworkinglab.

the class OplinkSwitchHandshaker method buildPortDescriptions.

private List<PortDescription> buildPortDescriptions(List<OFCalientPortStatsEntry> entries) {
    DeviceService deviceService = this.handler().get(DeviceService.class);
    List<Port> ports = deviceService.getPorts(this.data().deviceId());
    HashMap<Long, OFCalientPortStatsEntry> statsMap = new HashMap<>(entries.size());
    entries.forEach(entry -> statsMap.put((long) entry.getPortNo().getPortNumber(), entry));
    final List<PortDescription> portDescs = new ArrayList<>();
    for (Port port : ports) {
        DefaultAnnotations.Builder builder = DefaultAnnotations.builder();
        builder.putAll(port.annotations());
        // set fingerprint for the virtual port (port 0)
        if (port.number().toLong() == PROTECTION_VIRTUAL_PORT) {
            builder.set(ProtectionConfigBehaviour.FINGERPRINT, PROTECTION_FINGERPRINT);
        }
        OFCalientPortStatsEntry entry = statsMap.get(port.number().toLong());
        if (entry == null) {
            continue;
        }
        builder.set(CURRENT_POWER, entry.getInportPower());
        builder.set(OUTPUT_POWER, entry.getOutportPower());
        // We just use this code for a short term, and will modify in the future.
        if (entry.getInOperStatus().isEmpty()) {
            builder.set(INPUT_PORT_STATUS, STATUS_IN_SERVICE);
        } else {
            builder.set(INPUT_PORT_STATUS, STATUS_OUT_SERVICE);
        }
        if (entry.getOutOperStatus().isEmpty()) {
            builder.set(OUTPUT_PORT_STATUS, STATUS_IN_SERVICE);
        } else {
            builder.set(OUTPUT_PORT_STATUS, STATUS_OUT_SERVICE);
        }
        portDescs.add(DefaultPortDescription.builder().withPortNumber(port.number()).isEnabled(port.isEnabled()).type(port.type()).portSpeed(port.portSpeed()).annotations(builder.build()).build());
    }
    return portDescs;
}
Also used : OFCalientPortStatsEntry(org.projectfloodlight.openflow.protocol.OFCalientPortStatsEntry) DefaultAnnotations(org.onosproject.net.DefaultAnnotations) HashMap(java.util.HashMap) Port(org.onosproject.net.Port) DeviceService(org.onosproject.net.device.DeviceService) ArrayList(java.util.ArrayList) PortDescription(org.onosproject.net.device.PortDescription) DefaultPortDescription(org.onosproject.net.device.DefaultPortDescription)

Example 23 with PortDescription

use of org.onosproject.net.device.PortDescription in project onos by opennetworkinglab.

the class GnmiTerminalDeviceDiscovery method discoverPortDetails.

@Override
public List<PortDescription> discoverPortDetails() {
    if (!setupBehaviour("discoverPortDetails()")) {
        return Collections.emptyList();
    }
    // Get all components
    Gnmi.Path path = GnmiPathBuilder.newBuilder().addElem("components").addElem("component").withKeyValue("name", "*").build();
    Gnmi.GetRequest req = Gnmi.GetRequest.newBuilder().addPath(path).setEncoding(Gnmi.Encoding.PROTO).build();
    Gnmi.GetResponse resp;
    try {
        resp = client.get(req).get();
    } catch (ExecutionException | InterruptedException e) {
        log.warn("unable to get components via gNMI: {}", e.getMessage());
        return Collections.emptyList();
    }
    Multimap<String, Gnmi.Update> componentUpdates = HashMultimap.create();
    resp.getNotificationList().stream().map(Gnmi.Notification::getUpdateList).flatMap(List::stream).forEach(u -> {
        // Get component name
        // /components/component[name=?]
        Gnmi.Path p = u.getPath();
        if (p.getElemCount() < 2) {
            // Invalid path
            return;
        }
        String name = p.getElem(1).getKeyOrDefault("name", null);
        // name -> a set of gNMI updates
        if (name != null) {
            componentUpdates.put(name, u);
        }
    });
    Stream<PortDescription> normalPorts = super.discoverPortDetails().stream();
    Stream<PortDescription> opticalPorts = componentUpdates.keySet().stream().map(name -> convertComponentToOdtnPortDesc(name, componentUpdates.get(name))).filter(Objects::nonNull);
    return Streams.concat(normalPorts, opticalPorts).collect(Collectors.toList());
}
Also used : GnmiUtils.pathToString(org.onosproject.gnmi.api.GnmiUtils.pathToString) Gnmi(gnmi.Gnmi) PortNumber(org.onosproject.net.PortNumber) LoggerFactory(org.slf4j.LoggerFactory) Multimap(com.google.common.collect.Multimap) AnnotationKeys(org.onosproject.net.AnnotationKeys) HashMultimap(com.google.common.collect.HashMultimap) OchPortHelper(org.onosproject.net.optical.device.OchPortHelper) Map(java.util.Map) PortDescription(org.onosproject.net.device.PortDescription) GnmiPathBuilder(org.onosproject.gnmi.api.GnmiUtils.GnmiPathBuilder) OduSignalType(org.onosproject.net.OduSignalType) DefaultDeviceDescription(org.onosproject.net.device.DefaultDeviceDescription) DeviceDescription(org.onosproject.net.device.DeviceDescription) Logger(org.slf4j.Logger) Device(org.onosproject.net.Device) Collection(java.util.Collection) OdtnDeviceDescriptionDiscovery(org.onosproject.odtn.behaviour.OdtnDeviceDescriptionDiscovery) Streams(com.google.common.collect.Streams) Maps(com.google.common.collect.Maps) Collectors(java.util.stream.Collectors) OchSignal(org.onosproject.net.OchSignal) Objects(java.util.Objects) ExecutionException(java.util.concurrent.ExecutionException) DefaultAnnotations(org.onosproject.net.DefaultAnnotations) List(java.util.List) Stream(java.util.stream.Stream) OpenConfigGnmiDeviceDescriptionDiscovery(org.onosproject.drivers.gnmi.OpenConfigGnmiDeviceDescriptionDiscovery) ChannelSpacing(org.onosproject.net.ChannelSpacing) Collections(java.util.Collections) Gnmi(gnmi.Gnmi) PortDescription(org.onosproject.net.device.PortDescription) GnmiUtils.pathToString(org.onosproject.gnmi.api.GnmiUtils.pathToString) Objects(java.util.Objects) ExecutionException(java.util.concurrent.ExecutionException)

Example 24 with PortDescription

use of org.onosproject.net.device.PortDescription in project onos by opennetworkinglab.

the class OpenRoadmDeviceDescription method discoverPortDetails.

/**
 * Returns a list of PortDescriptions for the device.
 *
 * @return a list of descriptions.
 */
/*
     * Assumptions: ROADM degree ports are Oms carrying 80 lambdas (should be
     *              configurable)
     *              ROADM SRG (client) ports are OCh carrying ODU4 (should be
     *              configurable)
     */
@Override
public List<PortDescription> discoverPortDetails() {
    NetconfSession session = getNetconfSession(did());
    if (session == null) {
        log.error("discoverPortDetails null session for {}", did());
        return ImmutableList.of();
    }
    if (!getDevice().annotations().keys().contains("openroadm-node-id")) {
        log.error("Unable to run PortDiscovery: missing openroadm-node-id annotation." + " Probable failure during DeviceDiscovery. Aborting!");
        return ImmutableList.of();
    }
    List<HierarchicalConfiguration> externalLinks = getExternalLinks(session);
    List<PortDescription> list = new ArrayList<PortDescription>();
    discoverDegreePorts(session, list, externalLinks);
    discoverSrgPorts(session, list, externalLinks);
    return list;
}
Also used : NetconfSession(org.onosproject.netconf.NetconfSession) ArrayList(java.util.ArrayList) PortDescription(org.onosproject.net.device.PortDescription) HierarchicalConfiguration(org.apache.commons.configuration.HierarchicalConfiguration)

Example 25 with PortDescription

use of org.onosproject.net.device.PortDescription in project onos by opennetworkinglab.

the class OvsdbBridgeConfig method getPorts.

@Override
public Collection<PortDescription> getPorts() {
    OvsdbClientService client = getOvsdbClientService(handler());
    if (client == null) {
        return Collections.emptyList();
    }
    Set<OvsdbPort> ports = client.getPorts();
    return ports.stream().map(x -> DefaultPortDescription.builder().withPortNumber(PortNumber.portNumber(x.portNumber().value())).isEnabled(true).annotations(DefaultAnnotations.builder().set("portName", x.portName().value()).build()).build()).collect(Collectors.toSet());
}
Also used : DefaultBridgeDescription(org.onosproject.net.behaviour.DefaultBridgeDescription) OvsdbNodeId(org.onosproject.ovsdb.controller.OvsdbNodeId) BridgeDescription(org.onosproject.net.behaviour.BridgeDescription) Collection(java.util.Collection) BridgeName(org.onosproject.net.behaviour.BridgeName) PortNumber(org.onosproject.net.PortNumber) Set(java.util.Set) Collectors(java.util.stream.Collectors) ArrayList(java.util.ArrayList) AbstractHandlerBehaviour(org.onosproject.net.driver.AbstractHandlerBehaviour) List(java.util.List) DefaultAnnotations(org.onosproject.net.DefaultAnnotations) DefaultPortDescription(org.onosproject.net.device.DefaultPortDescription) DriverHandler(org.onosproject.net.driver.DriverHandler) OvsdbController(org.onosproject.ovsdb.controller.OvsdbController) OvsdbBridge(org.onosproject.ovsdb.controller.OvsdbBridge) OvsdbPort(org.onosproject.ovsdb.controller.OvsdbPort) PortDescription(org.onosproject.net.device.PortDescription) OvsdbClientService(org.onosproject.ovsdb.controller.OvsdbClientService) DeviceId(org.onosproject.net.DeviceId) Collections(java.util.Collections) IpAddress(org.onlab.packet.IpAddress) BridgeConfig(org.onosproject.net.behaviour.BridgeConfig) OvsdbClientService(org.onosproject.ovsdb.controller.OvsdbClientService) OvsdbPort(org.onosproject.ovsdb.controller.OvsdbPort)

Aggregations

PortDescription (org.onosproject.net.device.PortDescription)81 DefaultPortDescription (org.onosproject.net.device.DefaultPortDescription)41 Test (org.junit.Test)25 DefaultAnnotations (org.onosproject.net.DefaultAnnotations)25 PortNumber (org.onosproject.net.PortNumber)24 DeviceId (org.onosproject.net.DeviceId)23 ArrayList (java.util.ArrayList)22 Port (org.onosproject.net.Port)22 DeviceEvent (org.onosproject.net.device.DeviceEvent)14 ProviderId (org.onosproject.net.provider.ProviderId)13 Device (org.onosproject.net.Device)12 HierarchicalConfiguration (org.apache.commons.configuration.HierarchicalConfiguration)11 DefaultPort (org.onosproject.net.DefaultPort)9 DeviceService (org.onosproject.net.device.DeviceService)9 NetconfSession (org.onosproject.netconf.NetconfSession)8 IOException (java.io.IOException)7 HashMap (java.util.HashMap)7 OduCltPortHelper.oduCltPortDescription (org.onosproject.net.optical.device.OduCltPortHelper.oduCltPortDescription)7 OmsPortHelper.omsPortDescription (org.onosproject.net.optical.device.OmsPortHelper.omsPortDescription)7 OchPortHelper.ochPortDescription (org.onosproject.net.optical.device.OchPortHelper.ochPortDescription)6