use of org.onosproject.net.driver.Driver in project onos by opennetworkinglab.
the class RestDeviceProvider method getDriver.
private Driver getDriver(RestSBDevice restSBDev) {
String driverName = netCfgService.getConfig(restSBDev.deviceId(), BasicDeviceConfig.class).driver();
Driver driver = driverService.getDriver(driverName);
if (driver == null) {
driver = driverService.getDriver(restSBDev.manufacturer().get(), restSBDev.hwVersion().get(), restSBDev.swVersion().get());
}
checkNotNull(driver, DRIVERNULL);
return driver;
}
use of org.onosproject.net.driver.Driver 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.driver.Driver in project onos by opennetworkinglab.
the class OpenFlowMeterProvider method isMeterCapable.
/**
* Determine whether the given switch is meter-capable.
*
* @param sw switch
* @return the boolean value of meterCapable property, or true if it is not configured.
*/
private boolean isMeterCapable(OpenFlowSwitch sw) {
Driver driver;
try {
driver = driverService.getDriver(DeviceId.deviceId(Dpid.uri(sw.getDpid())));
} catch (ItemNotFoundException e) {
driver = driverService.getDriver(sw.manufacturerDescription(), sw.hardwareDescription(), sw.softwareDescription());
}
String isMeterCapable = driver.getProperty(METER_CAPABLE);
return isMeterCapable == null || Boolean.parseBoolean(isMeterCapable);
}
use of org.onosproject.net.driver.Driver in project onos by opennetworkinglab.
the class DriverRegistryManager method registerProvider.
@Override
public void registerProvider(DriverProvider provider) {
provider.getDrivers().forEach(driver -> {
Driver d = addDriver(driver);
driverByKey.put(key(driver.manufacturer(), driver.hwVersion(), driver.swVersion()), d);
d.behaviours().forEach(b -> {
Class<? extends Behaviour> implementation = d.implementation(b);
classes.put(b.getName(), b);
classes.put(implementation.getName(), implementation);
});
post(new DriverEvent(DRIVER_ENHANCED, driver));
});
providers.add(provider);
checkRequiredDrivers();
}
use of org.onosproject.net.driver.Driver in project onos by opennetworkinglab.
the class TopologyViewMessageHandlerBase method deviceMessage.
// Produces a device event message to the client.
protected ObjectNode deviceMessage(DeviceEvent event) {
Device device = event.subject();
String uiType = device.annotations().value(AnnotationKeys.UI_TYPE);
String driverName = device.annotations().value(DRIVER);
Driver driver = driverName == null ? null : services.driver().getDriver(driverName);
String devType = uiType != null ? uiType : (driver != null ? driver.getProperty(AnnotationKeys.UI_TYPE) : null);
if (devType == null) {
devType = device.type().toString().toLowerCase();
}
String name = device.annotations().value(AnnotationKeys.NAME);
name = isNullOrEmpty(name) ? device.id().toString() : name;
ObjectNode payload = objectNode().put("id", device.id().toString()).put("type", devType).put("online", services.device().isAvailable(device.id())).put("master", master(device.id()));
payload.set("labels", labels("", name, device.id().toString()));
payload.set("props", props(device.annotations()));
BasicDeviceConfig cfg = get(NetworkConfigService.class).getConfig(device.id(), BasicDeviceConfig.class);
if (!addLocation(cfg, payload)) {
addMetaUi(device.id().toString(), payload);
}
String type = DEVICE_EVENT.get(event.type());
return JsonUtils.envelope(type, payload);
}
Aggregations