Search in sources :

Example 21 with Port

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

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

the class OplinkPowerConfigUtil method getPortPower.

/**
 * Find specified port power from port description.
 *
 * @param portNum the port number
 * @param annotation annotation in port description
 * @return power value in 0.01 dBm
 */
private Long getPortPower(PortNumber portNum, String annotation) {
    // Check if switch is connected, otherwise do not return value in store, which is obsolete.
    if (getOpenFlowDevice() == null) {
        // Warning already exists in method getOpenFlowDevice()
        return null;
    }
    final DriverHandler handler = behaviour.handler();
    DeviceService deviceService = handler.get(DeviceService.class);
    Port port = deviceService.getPort(handler.data().deviceId(), portNum);
    if (port == null) {
        log.warn("Unexpected port: {}", portNum);
        return null;
    }
    String power = port.annotations().value(annotation);
    if (power == null) {
        // Do not need warning here for port polling.
        log.debug("Cannot get {} from port {}.", annotation, portNum);
        return null;
    }
    return Long.valueOf(power);
}
Also used : Port(org.onosproject.net.Port) DriverHandler(org.onosproject.net.driver.DriverHandler) DeviceService(org.onosproject.net.device.DeviceService)

Example 23 with Port

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

the class TapiDeviceLambdaQuery method queryLambdas.

@Override
public Set<OchSignal> queryLambdas(PortNumber port) {
    RestSBController controller = checkNotNull(handler().get(RestSBController.class));
    DeviceService deviceService = checkNotNull(handler().get(DeviceService.class));
    DeviceId deviceId = did();
    Device dev = deviceService.getDevice(deviceId);
    if (dev == null) {
        log.error("Device {} does not exist", deviceId);
        return ImmutableSet.of();
    }
    Port p = deviceService.getPort(dev.id(), port);
    if (p == null) {
        log.error("Port {} does not exist", port);
        return ImmutableSet.of();
    }
    String uuid = p.annotations().value(UUID);
    try {
        InputStream inputStream = controller.get(deviceId, SIP_REQUEST_DATA_API + uuid, MediaType.APPLICATION_JSON_TYPE);
        log.debug("Service interface point UUID: {}", uuid);
        JsonNode sipAttributes = new ObjectMapper().readTree(inputStream);
        JsonNode mcPool = sipAttributes.get(MEDIA_CHANNEL_SERVICE_INTERFACE_POINT_SPEC).get(MC_POOL);
        // This creates a hashset of OChSignals representing the spectrum availability at the target port.
        return TapiDeviceHelper.getOchSignal(mcPool);
    } catch (IOException e) {
        log.error("Exception discoverPortDetails() {}", did(), e);
        return ImmutableSet.of();
    }
}
Also used : RestSBController(org.onosproject.protocol.rest.RestSBController) DeviceId(org.onosproject.net.DeviceId) Device(org.onosproject.net.Device) InputStream(java.io.InputStream) Port(org.onosproject.net.Port) DeviceService(org.onosproject.net.device.DeviceService) JsonNode(com.fasterxml.jackson.databind.JsonNode) IOException(java.io.IOException) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 24 with Port

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

the class DefaultTributarySlotQuery method queryTributarySlots.

@Override
public Set<TributarySlot> queryTributarySlots(PortNumber port) {
    // currently return all slots by default.
    DeviceService deviceService = opticalView(this.handler().get(DeviceService.class));
    Port p = deviceService.getPort(this.data().deviceId(), port);
    if (p == null) {
        return Collections.emptySet();
    }
    switch(p.type()) {
        case OCH:
            return queryOchTributarySlots(p);
        case OTU:
            return queryOtuTributarySlots(p);
        default:
            return Collections.emptySet();
    }
}
Also used : OtuPort(org.onosproject.net.optical.OtuPort) Port(org.onosproject.net.Port) OchPort(org.onosproject.net.optical.OchPort) DeviceService(org.onosproject.net.device.DeviceService)

Example 25 with Port

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

the class OFOpticalSwitch13LambdaQuery method queryLambdas.

@Override
public Set<OchSignal> queryLambdas(PortNumber port) {
    DeviceService deviceService = opticalView(this.handler().get(DeviceService.class));
    Port p = deviceService.getPort(this.data().deviceId(), port);
    // Only OMS ports expose lambda resources
    if (p == null || !p.type().equals(Port.Type.OMS)) {
        return Collections.emptySet();
    }
    short lambdaCount = ((OmsPort) p).totalChannels();
    // OMS ports expose 'lambdaCount' fixed grid lambdas of 50GHz width, starting from min-frequency 191.7 THz.
    return IntStream.rangeClosed(1, lambdaCount).mapToObj(x -> OchSignal.newDwdmSlot(ChannelSpacing.CHL_50GHZ, x)).collect(GuavaCollectors.toImmutableSet());
}
Also used : IntStream(java.util.stream.IntStream) LambdaQuery(org.onosproject.net.behaviour.LambdaQuery) PortNumber(org.onosproject.net.PortNumber) DeviceService(org.onosproject.net.device.DeviceService) Set(java.util.Set) GuavaCollectors(org.onlab.util.GuavaCollectors) AbstractHandlerBehaviour(org.onosproject.net.driver.AbstractHandlerBehaviour) OchSignal(org.onosproject.net.OchSignal) OmsPort(org.onosproject.net.optical.OmsPort) OpticalDeviceServiceView.opticalView(org.onosproject.net.optical.device.OpticalDeviceServiceView.opticalView) Port(org.onosproject.net.Port) ChannelSpacing(org.onosproject.net.ChannelSpacing) Collections(java.util.Collections) OmsPort(org.onosproject.net.optical.OmsPort) OmsPort(org.onosproject.net.optical.OmsPort) Port(org.onosproject.net.Port) DeviceService(org.onosproject.net.device.DeviceService)

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