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);
}
}
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());
}
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);
}
}
}
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 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);
}
Aggregations