Search in sources :

Example 1 with DeviceDescriptionDiscovery

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

the class DeviceInjectionConfigMonitor method injectDevice.

private void injectDevice(DeviceId did) {
    Optional<BasicDeviceConfig> basic = Optional.ofNullable(netcfgService.getConfig(did, BasicDeviceConfig.class));
    Optional<DeviceDescriptionDiscovery> discovery = basic.map(BasicDeviceConfig::driver).map(driverService::getDriver).filter(drvr -> drvr.hasBehaviour(DeviceDescriptionDiscovery.class)).map(drvr -> drvr.createBehaviour(new DefaultDriverHandler(new DefaultDriverData(drvr, did)), DeviceDescriptionDiscovery.class));
    if (discovery.isPresent()) {
        providerService.deviceConnected(did, discovery.get().discoverDeviceDetails());
        providerService.updatePorts(did, discovery.get().discoverPortDetails());
    } else {
        String unk = "UNKNOWN";
        DefaultDeviceDescription desc = new DefaultDeviceDescription(did.uri(), basic.map(BasicDeviceConfig::type).orElse(Type.SWITCH), basic.map(BasicDeviceConfig::manufacturer).orElse(unk), basic.map(BasicDeviceConfig::hwVersion).orElse(unk), basic.map(BasicDeviceConfig::swVersion).orElse(unk), basic.map(BasicDeviceConfig::serial).orElse(unk), new ChassisId(), true);
        providerService.deviceConnected(did, desc);
        Optional<DeviceInjectionConfig> inject = Optional.ofNullable(netcfgService.getConfig(did, DeviceInjectionConfig.class));
        String ports = inject.map(DeviceInjectionConfig::ports).orElse("0");
        int numPorts = Integer.parseInt(ports);
        List<PortDescription> portDescs = new ArrayList<>(numPorts);
        for (int i = 1; i <= numPorts; ++i) {
            // TODO inject port details if something like BasicPortConfig was created
            PortNumber number = portNumber(i);
            boolean isEnabled = true;
            portDescs.add(DefaultPortDescription.builder().withPortNumber(number).isEnabled(isEnabled).build());
        }
        providerService.updatePorts(did, portDescs);
    }
}
Also used : NetworkConfigService(org.onosproject.net.config.NetworkConfigService) NetworkConfigRegistry(org.onosproject.net.config.NetworkConfigRegistry) BasicDeviceConfig(org.onosproject.net.config.basics.BasicDeviceConfig) PortNumber.portNumber(org.onosproject.net.PortNumber.portNumber) PortNumber(org.onosproject.net.PortNumber) NetworkConfigEvent(org.onosproject.net.config.NetworkConfigEvent) DeviceService(org.onosproject.net.device.DeviceService) Tools.groupedThreads(org.onlab.util.Tools.groupedThreads) DeviceProviderRegistry(org.onosproject.net.device.DeviceProviderRegistry) DefaultDriverData(org.onosproject.net.driver.DefaultDriverData) DriverService(org.onosproject.net.driver.DriverService) ArrayList(java.util.ArrayList) Component(org.osgi.service.component.annotations.Component) ImmutableList(com.google.common.collect.ImmutableList) DEVICE_SUBJECT_FACTORY(org.onosproject.net.config.basics.SubjectFactories.DEVICE_SUBJECT_FACTORY) DefaultDriverHandler(org.onosproject.net.driver.DefaultDriverHandler) DeviceProvider(org.onosproject.net.device.DeviceProvider) PortDescription(org.onosproject.net.device.PortDescription) DeviceProviderService(org.onosproject.net.device.DeviceProviderService) Activate(org.osgi.service.component.annotations.Activate) DefaultDeviceDescription(org.onosproject.net.device.DefaultDeviceDescription) EnumSet(java.util.EnumSet) ExecutorService(java.util.concurrent.ExecutorService) Type(org.onosproject.net.Device.Type) ImmutableSet(com.google.common.collect.ImmutableSet) Logger(org.slf4j.Logger) MastershipRole(org.onosproject.net.MastershipRole) Deactivate(org.osgi.service.component.annotations.Deactivate) DeviceDescriptionDiscovery(org.onosproject.net.device.DeviceDescriptionDiscovery) Set(java.util.Set) ProviderId(org.onosproject.net.provider.ProviderId) Executors.newSingleThreadExecutor(java.util.concurrent.Executors.newSingleThreadExecutor) Beta(com.google.common.annotations.Beta) ReferenceCardinality(org.osgi.service.component.annotations.ReferenceCardinality) TimeUnit(java.util.concurrent.TimeUnit) ConfigFactory(org.onosproject.net.config.ConfigFactory) DeviceInjectionConfig(org.onosproject.net.config.inject.DeviceInjectionConfig) DefaultPortDescription(org.onosproject.net.device.DefaultPortDescription) List(java.util.List) LoggerFactory.getLogger(org.slf4j.LoggerFactory.getLogger) Optional(java.util.Optional) DeviceId(org.onosproject.net.DeviceId) Reference(org.osgi.service.component.annotations.Reference) NetworkConfigListener(org.onosproject.net.config.NetworkConfigListener) ChassisId(org.onlab.packet.ChassisId) ChassisId(org.onlab.packet.ChassisId) DefaultDriverHandler(org.onosproject.net.driver.DefaultDriverHandler) ArrayList(java.util.ArrayList) DeviceInjectionConfig(org.onosproject.net.config.inject.DeviceInjectionConfig) PortDescription(org.onosproject.net.device.PortDescription) DefaultPortDescription(org.onosproject.net.device.DefaultPortDescription) BasicDeviceConfig(org.onosproject.net.config.basics.BasicDeviceConfig) DeviceDescriptionDiscovery(org.onosproject.net.device.DeviceDescriptionDiscovery) DefaultDeviceDescription(org.onosproject.net.device.DefaultDeviceDescription) PortNumber(org.onosproject.net.PortNumber) DefaultDriverData(org.onosproject.net.driver.DefaultDriverData)

Example 2 with DeviceDescriptionDiscovery

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

the class GeneralDeviceProvider method getDeviceDescription.

private DeviceDescription getDeviceDescription(DeviceId deviceId, boolean defaultAvailable) {
    // Get one from driver or forge.
    final DeviceDescriptionDiscovery deviceDiscovery = getBehaviour(deviceId, DeviceDescriptionDiscovery.class);
    if (deviceDiscovery == null) {
        return forgeDeviceDescription(deviceId, defaultAvailable);
    }
    final DeviceDescription d = deviceDiscovery.discoverDeviceDetails();
    if (d == null) {
        return forgeDeviceDescription(deviceId, defaultAvailable);
    }
    // Enforce defaultAvailable flag over the one obtained from driver.
    return new DefaultDeviceDescription(d, defaultAvailable, d.annotations());
}
Also used : DeviceDescription(org.onosproject.net.device.DeviceDescription) DefaultDeviceDescription(org.onosproject.net.device.DefaultDeviceDescription) DeviceDescriptionDiscovery(org.onosproject.net.device.DeviceDescriptionDiscovery) DefaultDeviceDescription(org.onosproject.net.device.DefaultDeviceDescription)

Example 3 with DeviceDescriptionDiscovery

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

the class RestDeviceProvider method checkAndUpdateDevice.

private void checkAndUpdateDevice(DeviceId deviceId) {
    if (deviceService.getDevice(deviceId) == null) {
        log.warn("Device {} has not been added to store, maybe due to a problem in connectivity", deviceId);
    } else {
        boolean isReachable = isReachable(deviceId);
        if (isReachable && deviceService.isAvailable(deviceId)) {
            Device device = deviceService.getDevice(deviceId);
            if (device.is(DeviceDescriptionDiscovery.class)) {
                DeviceDescriptionDiscovery deviceDescriptionDiscovery = device.as(DeviceDescriptionDiscovery.class);
                DeviceDescription updatedDeviceDescription = deviceDescriptionDiscovery.discoverDeviceDetails();
                if (updatedDeviceDescription != null && !descriptionEquals(device, updatedDeviceDescription)) {
                    providerService.deviceConnected(deviceId, new DefaultDeviceDescription(updatedDeviceDescription, true, updatedDeviceDescription.annotations()));
                }
                // if ports are not discovered, retry the discovery
                if (deviceService.getPorts(deviceId).isEmpty()) {
                    discoverPorts(deviceId);
                }
            } else {
                log.warn("No DeviceDescriptionDiscovery behaviour for device {}", deviceId);
            }
        } else if (!isReachable && deviceService.isAvailable(deviceId)) {
            providerService.deviceDisconnected(deviceId);
        }
    }
}
Also used : DeviceDescription(org.onosproject.net.device.DeviceDescription) DefaultDeviceDescription(org.onosproject.net.device.DefaultDeviceDescription) DeviceDescriptionDiscovery(org.onosproject.net.device.DeviceDescriptionDiscovery) RestSBDevice(org.onosproject.protocol.rest.RestSBDevice) DefaultRestSBDevice(org.onosproject.protocol.rest.DefaultRestSBDevice) Device(org.onosproject.net.Device) DefaultDeviceDescription(org.onosproject.net.device.DefaultDeviceDescription)

Example 4 with DeviceDescriptionDiscovery

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

the class OvsdbDeviceProvider method discoverPorts.

private void discoverPorts(DeviceId deviceId) {
    Device device = deviceService.getDevice(deviceId);
    if (device.is(DeviceDescriptionDiscovery.class)) {
        DeviceDescriptionDiscovery deviceDescriptionDiscovery = device.as(DeviceDescriptionDiscovery.class);
        providerService.updatePorts(deviceId, deviceDescriptionDiscovery.discoverPortDetails());
    } else {
        log.warn("Device " + deviceId + " does not support behaviour DeviceDescriptionDiscovery");
    }
}
Also used : DeviceDescriptionDiscovery(org.onosproject.net.device.DeviceDescriptionDiscovery) Device(org.onosproject.net.Device)

Example 5 with DeviceDescriptionDiscovery

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

the class RestDeviceProvider method getDesc.

private DeviceDescription getDesc(RestSBDevice restSBDev) {
    DeviceId deviceId = restSBDev.deviceId();
    Driver driver = getDriver(restSBDev);
    if (restSBDev.isProxy()) {
        if (driver != null && driver.hasBehaviour(DevicesDiscovery.class)) {
            // Creates the driver to communicate with the server
            DevicesDiscovery devicesDiscovery = devicesDiscovery(restSBDev, driver);
            return devicesDiscovery.deviceDetails(deviceId);
        } else {
            log.warn("Driver not found for {}", restSBDev);
            return null;
        }
    } else if (driver != null && driver.hasBehaviour(DeviceDescriptionDiscovery.class)) {
        DriverHandler h = driverService.createHandler(deviceId);
        DeviceDescriptionDiscovery deviceDiscovery = h.behaviour(DeviceDescriptionDiscovery.class);
        return deviceDiscovery.discoverDeviceDetails();
    }
    ChassisId cid = new ChassisId();
    String ipAddress = restSBDev.ip().toString();
    SparseAnnotations annotations = DefaultAnnotations.builder().set(IPADDRESS, ipAddress).set(AnnotationKeys.PROTOCOL, REST.toUpperCase()).build();
    String manufacturer = UNKNOWN;
    String hwVersion = UNKNOWN;
    String swVersion = UNKNOWN;
    String serialNumber = UNKNOWN;
    Device device = deviceService.getDevice(deviceId);
    if (device != null) {
        manufacturer = device.manufacturer();
        hwVersion = device.hwVersion();
        swVersion = device.swVersion();
        serialNumber = device.serialNumber();
    }
    return new DefaultDeviceDescription(deviceId.uri(), Device.Type.SWITCH, manufacturer, hwVersion, swVersion, serialNumber, cid, annotations);
}
Also used : SparseAnnotations(org.onosproject.net.SparseAnnotations) ChassisId(org.onlab.packet.ChassisId) DeviceDescriptionDiscovery(org.onosproject.net.device.DeviceDescriptionDiscovery) DeviceId(org.onosproject.net.DeviceId) RestSBDevice(org.onosproject.protocol.rest.RestSBDevice) DefaultRestSBDevice(org.onosproject.protocol.rest.DefaultRestSBDevice) Device(org.onosproject.net.Device) DefaultDeviceDescription(org.onosproject.net.device.DefaultDeviceDescription) DefaultDriverHandler(org.onosproject.net.driver.DefaultDriverHandler) DriverHandler(org.onosproject.net.driver.DriverHandler) Driver(org.onosproject.net.driver.Driver) DevicesDiscovery(org.onosproject.net.behaviour.DevicesDiscovery)

Aggregations

DeviceDescriptionDiscovery (org.onosproject.net.device.DeviceDescriptionDiscovery)10 DefaultDeviceDescription (org.onosproject.net.device.DefaultDeviceDescription)6 Device (org.onosproject.net.Device)5 DeviceDescription (org.onosproject.net.device.DeviceDescription)5 DeviceId (org.onosproject.net.DeviceId)4 DefaultDriverHandler (org.onosproject.net.driver.DefaultDriverHandler)4 Driver (org.onosproject.net.driver.Driver)3 DriverHandler (org.onosproject.net.driver.DriverHandler)3 ChassisId (org.onlab.packet.ChassisId)2 DevicesDiscovery (org.onosproject.net.behaviour.DevicesDiscovery)2 DefaultDriverData (org.onosproject.net.driver.DefaultDriverData)2 DefaultRestSBDevice (org.onosproject.protocol.rest.DefaultRestSBDevice)2 RestSBDevice (org.onosproject.protocol.rest.RestSBDevice)2 Beta (com.google.common.annotations.Beta)1 ImmutableList (com.google.common.collect.ImmutableList)1 ImmutableSet (com.google.common.collect.ImmutableSet)1 ArrayList (java.util.ArrayList)1 EnumSet (java.util.EnumSet)1 List (java.util.List)1 Optional (java.util.Optional)1