Search in sources :

Example 21 with DeviceDescription

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

the class ECDeviceStore method mergeAnnotations.

private DefaultAnnotations mergeAnnotations(DeviceId deviceId) {
    ProviderId primaryProviderId = getPrimaryProviderId(deviceId);
    DeviceDescription primaryDeviceDescription = deviceDescriptions.get(new DeviceKey(primaryProviderId, deviceId));
    DefaultAnnotations annotations = DefaultAnnotations.builder().build();
    annotations = merge(annotations, primaryDeviceDescription.annotations());
    for (ProviderId providerId : getAllProviders(deviceId)) {
        if (!providerId.equals(primaryProviderId)) {
            annotations = merge(annotations, deviceDescriptions.get(new DeviceKey(providerId, deviceId)).annotations());
        }
    }
    return annotations;
}
Also used : ProviderId(org.onosproject.net.provider.ProviderId) DeviceDescription(org.onosproject.net.device.DeviceDescription) DefaultAnnotations(org.onosproject.net.DefaultAnnotations)

Example 22 with DeviceDescription

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

the class ECDeviceStore method removeDevice.

@Override
public DeviceEvent removeDevice(DeviceId deviceId) {
    NodeId master = mastershipService.getMasterFor(deviceId);
    // if there exist a master, forward
    // if there is no master, try to become one and process
    boolean relinquishAtEnd = false;
    if (master == null) {
        final MastershipRole myRole = mastershipService.getLocalRole(deviceId);
        if (myRole != MastershipRole.NONE) {
            relinquishAtEnd = true;
        }
        log.debug("Temporarily requesting role for {} to remove", deviceId);
        MastershipRole role = Futures.getUnchecked(mastershipService.requestRoleFor(deviceId));
        if (role == MastershipRole.MASTER) {
            master = localNodeId;
        }
    }
    if (!localNodeId.equals(master)) {
        log.debug("{} has control of {}, forwarding remove request", master, deviceId);
        clusterCommunicator.unicast(deviceId, DEVICE_REMOVE_REQ, SERIALIZER::encode, master).whenComplete((r, e) -> {
            if (e != null) {
                log.error("Failed to forward {} remove request to its master", deviceId, e);
            }
        });
        return null;
    }
    // I have control..
    DeviceEvent event = null;
    final DeviceKey deviceKey = new DeviceKey(getPrimaryProviderId(deviceId), deviceId);
    DeviceDescription removedDeviceDescription = deviceDescriptions.remove(deviceKey);
    if (removedDeviceDescription != null) {
        event = purgeDeviceCache(deviceId);
    }
    if (relinquishAtEnd) {
        log.debug("Relinquishing temporary role acquired for {}", deviceId);
        mastershipService.relinquishMastership(deviceId);
    }
    return event;
}
Also used : DeviceEvent(org.onosproject.net.device.DeviceEvent) DeviceDescription(org.onosproject.net.device.DeviceDescription) NodeId(org.onosproject.cluster.NodeId) MastershipRole(org.onosproject.net.MastershipRole)

Example 23 with DeviceDescription

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

the class LumentumWaveReadyDiscovery method discoverDeviceDetails.

@Override
public DeviceDescription discoverDeviceDetails() {
    DeviceId deviceId = handler().data().deviceId();
    Tl1Controller ctrl = checkNotNull(handler().get(Tl1Controller.class));
    // Something reasonable, unavailable by default
    DeviceDescription defaultDescription = new DefaultDeviceDescription(deviceId.uri(), Device.Type.OTN, LUMENTUM, WAVEREADY, SWVERSION, SERIAL, new ChassisId(), false, DefaultAnnotations.EMPTY);
    Optional<Tl1Device> device = ctrl.getDevice(deviceId);
    if (!device.isPresent()) {
        return defaultDescription;
    }
    // Login
    Tl1Command loginCmd = DefaultTl1Command.builder().withVerb(ACT).withModifier(USER).withAid(device.get().username()).withCtag(100).withParameters(device.get().password()).build();
    Future<String> login = ctrl.sendMsg(deviceId, loginCmd);
    try {
        String loginResponse = login.get(TIMEOUT, TimeUnit.MILLISECONDS);
        if (loginResponse.contains("Access denied")) {
            log.error("Access denied: {}", loginResponse);
            return defaultDescription;
        }
    } catch (InterruptedException | ExecutionException | TimeoutException e) {
        log.error("Login failed", e);
        return defaultDescription;
    }
    // Fetch device description
    Tl1Command ddCmd = DefaultTl1Command.builder().withVerb(RTRV).withModifier(NETYPE).withCtag(101).build();
    Future<String> dd = ctrl.sendMsg(deviceId, ddCmd);
    try {
        String ddResponse = dd.get(TIMEOUT, TimeUnit.MILLISECONDS);
        return new DefaultDeviceDescription(defaultDescription, true, extractAnnotations(ddResponse));
    } catch (InterruptedException | ExecutionException | TimeoutException e) {
        log.error("Device description not found", e);
        return defaultDescription;
    }
}
Also used : DefaultDeviceDescription(org.onosproject.net.device.DefaultDeviceDescription) DeviceDescription(org.onosproject.net.device.DeviceDescription) ChassisId(org.onlab.packet.ChassisId) Tl1Command(org.onosproject.tl1.Tl1Command) DefaultTl1Command(org.onosproject.tl1.DefaultTl1Command) DeviceId(org.onosproject.net.DeviceId) Tl1Controller(org.onosproject.tl1.Tl1Controller) DefaultDeviceDescription(org.onosproject.net.device.DefaultDeviceDescription) Tl1Device(org.onosproject.tl1.Tl1Device) ExecutionException(java.util.concurrent.ExecutionException) TimeoutException(java.util.concurrent.TimeoutException)

Example 24 with DeviceDescription

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

the class StratumDeviceDescriptionDiscovery method discoverDeviceDetails.

@Override
public DeviceDescription discoverDeviceDetails() {
    final DeviceDescription p4Descr = p4runtime.discoverDeviceDetails();
    final DeviceDescription gnoiDescr = gnoi.discoverDeviceDetails();
    final DeviceDescription gnmiDescr = gnmi.discoverDeviceDetails();
    return new DefaultDeviceDescription(data().deviceId().uri(), Device.Type.SWITCH, data().driver().manufacturer(), data().driver().hwVersion(), data().driver().swVersion(), UNKNOWN, p4Descr.chassisId(), // Availability is mandated by P4Runtime.
    p4Descr.isDefaultAvailable(), DefaultAnnotations.builder().putAll(p4Descr.annotations()).putAll(gnmiDescr.annotations()).putAll(gnoiDescr.annotations()).set(AnnotationKeys.PROTOCOL, format("%s, %s, %s", p4Descr.annotations().value(AnnotationKeys.PROTOCOL), gnmiDescr.annotations().value(AnnotationKeys.PROTOCOL), gnoiDescr.annotations().value(AnnotationKeys.PROTOCOL))).build());
}
Also used : DefaultDeviceDescription(org.onosproject.net.device.DefaultDeviceDescription) DeviceDescription(org.onosproject.net.device.DeviceDescription) DefaultDeviceDescription(org.onosproject.net.device.DefaultDeviceDescription)

Example 25 with DeviceDescription

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

the class TopologySimulator method createDevice.

/**
 * Creates simulated device.
 *
 * @param id        device identifier
 * @param chassisId chassis identifier number
 * @param type      device type
 * @param hw        hardware revision
 * @param sw        software revision
 * @param portCount number of device ports
 */
public void createDevice(DeviceId id, int chassisId, Device.Type type, String hw, String sw, int portCount) {
    DeviceDescription desc = new DefaultDeviceDescription(id.uri(), type, "ONF", hw, sw, "1234", new ChassisId(chassisId), DefaultAnnotations.builder().set(AnnotationKeys.NAME, "Switch " + chassisId).build());
    deviceIds.add(id);
    mastershipAdminService.setRoleSync(localNode, id, MASTER);
    deviceProviderService.deviceConnected(id, desc);
    deviceProviderService.updatePorts(id, buildPorts(portCount));
}
Also used : DefaultDeviceDescription(org.onosproject.net.device.DefaultDeviceDescription) DeviceDescription(org.onosproject.net.device.DeviceDescription) ChassisId(org.onlab.packet.ChassisId) DefaultDeviceDescription(org.onosproject.net.device.DefaultDeviceDescription)

Aggregations

DeviceDescription (org.onosproject.net.device.DeviceDescription)44 DefaultDeviceDescription (org.onosproject.net.device.DefaultDeviceDescription)32 ChassisId (org.onlab.packet.ChassisId)14 DeviceId (org.onosproject.net.DeviceId)14 Test (org.junit.Test)11 ProviderId (org.onosproject.net.provider.ProviderId)10 DefaultAnnotations (org.onosproject.net.DefaultAnnotations)9 DeviceEvent (org.onosproject.net.device.DeviceEvent)8 SparseAnnotations (org.onosproject.net.SparseAnnotations)6 DeviceDescriptionDiscovery (org.onosproject.net.device.DeviceDescriptionDiscovery)6 Device (org.onosproject.net.Device)5 PortDescription (org.onosproject.net.device.PortDescription)5 IOException (java.io.IOException)4 ExecutionException (java.util.concurrent.ExecutionException)4 BiFunction (java.util.function.BiFunction)4 Function (java.util.function.Function)4 NodeId (org.onosproject.cluster.NodeId)4 NetconfException (org.onosproject.netconf.NetconfException)4 Arrays (java.util.Arrays)3 HashMap (java.util.HashMap)3