use of org.onosproject.net.behaviour.DevicesDiscovery in project onos by opennetworkinglab.
the class RestDeviceProvider method devicesDiscovery.
private DevicesDiscovery devicesDiscovery(RestSBDevice restSBDevice, Driver driver) {
DriverData driverData = new DefaultDriverData(driver, restSBDevice.deviceId());
DevicesDiscovery devicesDiscovery = driver.createBehaviour(driverData, DevicesDiscovery.class);
devicesDiscovery.setHandler(new DefaultDriverHandler(driverData));
return devicesDiscovery;
}
use of org.onosproject.net.behaviour.DevicesDiscovery 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);
}
use of org.onosproject.net.behaviour.DevicesDiscovery 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);
}
}
Aggregations