use of org.onosproject.net.device.DeviceDescriptionDiscovery in project onos by opennetworkinglab.
the class RestDeviceProvider method deviceAdded.
private void deviceAdded(RestSBDevice restSBDev) {
checkNotNull(restSBDev, DEVICENULL);
Driver driver = getDriver(restSBDev);
// Check if the server is controlling a single or multiple devices
if (restSBDev.isProxy()) {
if (driver.hasBehaviour(DevicesDiscovery.class)) {
DevicesDiscovery devicesDiscovery = devicesDiscovery(restSBDev, driver);
Set<DeviceId> deviceIds = devicesDiscovery.deviceIds();
restSBDev.setActive(true);
deviceIds.forEach(deviceId -> {
controller.addProxiedDevice(deviceId, restSBDev);
DeviceDescription devDesc = devicesDiscovery.deviceDetails(deviceId);
checkNotNull(devDesc, "DeviceDescription cannot be null");
providerService.deviceConnected(deviceId, mergeAnn(restSBDev.deviceId(), devDesc));
if (driver.hasBehaviour(DeviceDescriptionDiscovery.class)) {
DriverHandler h = driverService.createHandler(deviceId);
DeviceDescriptionDiscovery devDisc = h.behaviour(DeviceDescriptionDiscovery.class);
providerService.updatePorts(deviceId, devDisc.discoverPortDetails());
}
checkAndUpdateDevice(deviceId);
});
} else {
log.warn("Device is proxy but driver does not have proxy discovery behaviour {}", restSBDev);
}
} else {
DeviceId deviceId = restSBDev.deviceId();
if (driver != null && driver.hasBehaviour(DevicesDiscovery.class)) {
restSBDev.setActive(true);
DevicesDiscovery devicesDiscovery = devicesDiscovery(restSBDev, driver);
DeviceDescription deviceDescription = devicesDiscovery.deviceDetails(deviceId);
checkNotNull(deviceDescription, "DeviceDescription cannot be null");
providerService.deviceConnected(deviceId, deviceDescription);
if (driver.hasBehaviour(DeviceDescriptionDiscovery.class)) {
DriverHandler h = driverService.createHandler(deviceId);
DeviceDescriptionDiscovery deviceDiscovery = h.behaviour(DeviceDescriptionDiscovery.class);
providerService.updatePorts(deviceId, deviceDiscovery.discoverPortDetails());
}
} else {
DeviceDescription deviceDescription = getDesc(restSBDev);
restSBDev.setActive(true);
providerService.deviceConnected(deviceId, deviceDescription);
}
checkAndUpdateDevice(deviceId);
}
}
use of org.onosproject.net.device.DeviceDescriptionDiscovery in project onos by opennetworkinglab.
the class Tl1DeviceProvider method updateDevice.
/**
* Tries to update the device and port descriptions through the {@code DeviceDescriptionDiscovery} behaviour.
*
* @param deviceId the device
*/
void updateDevice(DeviceId deviceId) {
Device device = deviceService.getDevice(deviceId);
if (!device.is(DeviceDescriptionDiscovery.class)) {
return;
}
try {
// Update device description
DeviceDescriptionDiscovery discovery = device.as(DeviceDescriptionDiscovery.class);
DeviceDescription dd = discovery.discoverDeviceDetails();
if (dd == null) {
return;
}
providerService.deviceConnected(deviceId, new DefaultDeviceDescription(dd, true, dd.annotations()));
// Update ports
providerService.updatePorts(deviceId, discovery.discoverPortDetails());
} catch (IllegalStateException | IllegalArgumentException e) {
log.error("Cannot update device description {}", deviceId, e);
}
}
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");
}
}
use of org.onosproject.net.device.DeviceDescriptionDiscovery in project onos by opennetworkinglab.
the class AbstractDeviceProvider method discoverDevice.
/**
* Discovers the device details using the device discovery behaviour of
* the supplied driver handler context for interacting with a specific
* device.
*
* @param handler driver handler context
*/
protected void discoverDevice(DriverHandler handler) {
DeviceId deviceId = handler.data().deviceId();
DeviceDescriptionDiscovery discovery = handler.behaviour(DeviceDescriptionDiscovery.class);
DeviceDescription description = discovery.discoverDeviceDetails();
if (description != null) {
providerService.deviceConnected(deviceId, description);
} else {
log.info("No other description given for device {}", deviceId);
}
providerService.updatePorts(deviceId, discovery.discoverPortDetails());
}
use of org.onosproject.net.device.DeviceDescriptionDiscovery in project onos by opennetworkinglab.
the class NetconfDeviceProvider method getDeviceDescription.
private DeviceDescription getDeviceDescription(DeviceId deviceId, NetconfDeviceConfig config) {
Driver driver = driverService.getDriver(deviceId);
if (driver.hasBehaviour(DeviceDescriptionDiscovery.class)) {
final DriverData data = new DefaultDriverData(driver, deviceId);
final DriverHandler handler = new DefaultDriverHandler(data);
// creating the behaviour because the core has yet no notion of device.
DeviceDescriptionDiscovery deviceDescriptionDiscovery = driver.createBehaviour(handler, DeviceDescriptionDiscovery.class);
return getDeviceRepresentation(deviceId, config, deviceDescriptionDiscovery);
} else {
return existingOrEmptyDescription(deviceId, config);
}
}
Aggregations