Search in sources :

Example 16 with DeviceService

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

the class PeerConnectPointCompleter method choices.

@Override
protected List<String> choices() {
    DeviceService deviceService = getService(DeviceService.class);
    LinkService linkService = getService(LinkService.class);
    Optional<ConnectPoint> port = Arrays.asList(commandLine.getArguments()).stream().filter(s -> s.contains(":") && s.contains("/")).map(s -> {
        try {
            return deviceConnectPoint(s);
        } catch (IllegalArgumentException e) {
            // silently ill-formed String
            return null;
        }
    }).filter(Objects::nonNull).filter(cp -> deviceService.getPort(cp) != null).findFirst();
    if (!port.isPresent()) {
        // no candidate
        return Collections.emptyList();
    }
    final ConnectPoint cp = port.get();
    return linkService.getLinks(cp).stream().flatMap(l -> Stream.of(l.src(), l.dst())).filter(peer -> !cp.equals(peer)).distinct().map(ConnectPoint::toString).collect(Collectors.toList());
}
Also used : Arrays(java.util.Arrays) DefaultServiceDirectory.getService(org.onlab.osgi.DefaultServiceDirectory.getService) DeviceService(org.onosproject.net.device.DeviceService) ConnectPoint.deviceConnectPoint(org.onosproject.net.ConnectPoint.deviceConnectPoint) Collectors(java.util.stream.Collectors) ConnectPoint(org.onosproject.net.ConnectPoint) Objects(java.util.Objects) AbstractChoicesCompleter(org.onosproject.cli.AbstractChoicesCompleter) List(java.util.List) Stream(java.util.stream.Stream) Service(org.apache.karaf.shell.api.action.lifecycle.Service) LinkService(org.onosproject.net.link.LinkService) Optional(java.util.Optional) Collections(java.util.Collections) DeviceService(org.onosproject.net.device.DeviceService) Objects(java.util.Objects) LinkService(org.onosproject.net.link.LinkService) ConnectPoint.deviceConnectPoint(org.onosproject.net.ConnectPoint.deviceConnectPoint) ConnectPoint(org.onosproject.net.ConnectPoint)

Example 17 with DeviceService

use of org.onosproject.net.device.DeviceService 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 18 with DeviceService

use of org.onosproject.net.device.DeviceService 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 19 with DeviceService

use of org.onosproject.net.device.DeviceService 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 20 with DeviceService

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

the class OvsdbControllerConfig method getOvsdbClientService.

// Used for getting OvsdbClientService.
private OvsdbClientService getOvsdbClientService(DriverHandler handler) {
    OvsdbController ovsController = handler.get(OvsdbController.class);
    DeviceService deviceService = handler.get(DeviceService.class);
    DeviceId ofDeviceId = handler.data().deviceId();
    String[] mgmtAddress = deviceService.getDevice(ofDeviceId).annotations().value(AnnotationKeys.MANAGEMENT_ADDRESS).split(":");
    String targetIp = mgmtAddress[0];
    TpPort targetPort = null;
    if (mgmtAddress.length > 1) {
        targetPort = TpPort.tpPort(Integer.parseInt(mgmtAddress[1]));
    }
    List<OvsdbNodeId> nodeIds = ovsController.getNodeIds().stream().filter(nodeId -> nodeId.getIpAddress().equals(targetIp)).collect(Collectors.toList());
    if (nodeIds.isEmpty()) {
        // TODO decide what port?
        ovsController.connect(IpAddress.valueOf(targetIp), targetPort == null ? TpPort.tpPort(OvsdbConstant.OVSDBPORT) : targetPort);
        // FIXME... connect is async
        delay(1000);
    }
    List<OvsdbClientService> clientServices = ovsController.getNodeIds().stream().filter(nodeId -> nodeId.getIpAddress().equals(targetIp)).map(ovsController::getOvsdbClient).filter(cs -> cs.getBridges().stream().anyMatch(b -> dpidMatches(b, ofDeviceId))).collect(Collectors.toList());
    checkState(!clientServices.isEmpty(), "No clientServices found");
    // FIXME add connection to management address if null --> done ?
    return !clientServices.isEmpty() ? clientServices.get(0) : null;
}
Also used : TpPort(org.onlab.packet.TpPort) ControllerInfo(org.onosproject.net.behaviour.ControllerInfo) ImmutableSet(com.google.common.collect.ImmutableSet) OvsdbNodeId(org.onosproject.ovsdb.controller.OvsdbNodeId) DeviceService(org.onosproject.net.device.DeviceService) Set(java.util.Set) AnnotationKeys(org.onosproject.net.AnnotationKeys) ControllerConfig(org.onosproject.net.behaviour.ControllerConfig) Collectors(java.util.stream.Collectors) AbstractHandlerBehaviour(org.onosproject.net.driver.AbstractHandlerBehaviour) ArrayList(java.util.ArrayList) Preconditions.checkState(com.google.common.base.Preconditions.checkState) List(java.util.List) Preconditions.checkArgument(com.google.common.base.Preconditions.checkArgument) DriverHandler(org.onosproject.net.driver.DriverHandler) OvsdbController(org.onosproject.ovsdb.controller.OvsdbController) Tools.delay(org.onlab.util.Tools.delay) OvsdbBridge(org.onosproject.ovsdb.controller.OvsdbBridge) OvsdbConstant(org.onosproject.ovsdb.controller.OvsdbConstant) OvsdbClientService(org.onosproject.ovsdb.controller.OvsdbClientService) DeviceId(org.onosproject.net.DeviceId) IpAddress(org.onlab.packet.IpAddress) OvsdbClientService(org.onosproject.ovsdb.controller.OvsdbClientService) DeviceId(org.onosproject.net.DeviceId) DeviceService(org.onosproject.net.device.DeviceService) TpPort(org.onlab.packet.TpPort) OvsdbController(org.onosproject.ovsdb.controller.OvsdbController) OvsdbNodeId(org.onosproject.ovsdb.controller.OvsdbNodeId)

Aggregations

DeviceService (org.onosproject.net.device.DeviceService)187 Device (org.onosproject.net.Device)75 DeviceId (org.onosproject.net.DeviceId)73 Port (org.onosproject.net.Port)59 ConnectPoint (org.onosproject.net.ConnectPoint)42 PortNumber (org.onosproject.net.PortNumber)40 List (java.util.List)30 Collectors (java.util.stream.Collectors)24 Set (java.util.Set)23 AbstractHandlerBehaviour (org.onosproject.net.driver.AbstractHandlerBehaviour)19 Logger (org.slf4j.Logger)19 ArrayList (java.util.ArrayList)18 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)17 Optional (java.util.Optional)17 Test (org.junit.Test)16 JsonNode (com.fasterxml.jackson.databind.JsonNode)15 Collections (java.util.Collections)15 VirtualNetwork (org.onosproject.incubator.net.virtual.VirtualNetwork)15 DriverHandler (org.onosproject.net.driver.DriverHandler)15 Collection (java.util.Collection)14