use of org.onosproject.net.driver.DriverHandler 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.driver.DriverHandler 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.DriverHandler in project onos by opennetworkinglab.
the class NetconfControllerConfig method getControllers.
@Override
public List<ControllerInfo> getControllers() {
DriverHandler handler = handler();
NetconfController controller = handler.get(NetconfController.class);
MastershipService mastershipService = handler.get(MastershipService.class);
DeviceId deviceId = handler.data().deviceId();
Preconditions.checkNotNull(controller, "Netconf controller is null");
List<ControllerInfo> controllers = new ArrayList<>();
if (mastershipService.isLocalMaster(deviceId)) {
try {
String reply = controller.getNetconfDevice(deviceId).getSession().getConfig(DatastoreId.RUNNING);
log.debug("Reply XML {}", reply);
controllers.addAll(XmlConfigParser.parseStreamControllers(XmlConfigParser.loadXml(new ByteArrayInputStream(reply.getBytes(StandardCharsets.UTF_8)))));
} catch (NetconfException e) {
log.error("Cannot communicate with device {} ", deviceId, e);
}
} else {
log.warn("I'm not master for {} please use master, {} to execute command", deviceId, mastershipService.getMasterFor(deviceId));
}
return controllers;
}
use of org.onosproject.net.driver.DriverHandler in project onos by opennetworkinglab.
the class NetconfControllerConfig method setControllers.
@Override
public void setControllers(List<ControllerInfo> controllers) {
DriverHandler handler = handler();
NetconfController controller = handler.get(NetconfController.class);
DeviceId deviceId = handler.data().deviceId();
Preconditions.checkNotNull(controller, "Netconf controller is null");
MastershipService mastershipService = handler.get(MastershipService.class);
if (mastershipService.isLocalMaster(deviceId)) {
try {
NetconfDevice device = controller.getNetconfDevice(deviceId);
String config = null;
try {
String reply = device.getSession().getConfig(DatastoreId.RUNNING);
log.info("reply XML {}", reply);
config = XmlConfigParser.createControllersConfig(XmlConfigParser.loadXml(getClass().getResourceAsStream("controllers.xml")), XmlConfigParser.loadXml(new ByteArrayInputStream(reply.getBytes(StandardCharsets.UTF_8))), "running", "merge", "create", controllers);
} catch (NetconfException e) {
log.error("Cannot comunicate to device {} , exception {}", deviceId, e.getMessage());
return;
}
device.getSession().editConfig(config.substring(config.indexOf("-->") + 3));
} catch (NullPointerException e) {
log.warn("No NETCONF device with requested parameters " + e);
throw new NullPointerException("No NETCONF device with requested parameters " + e);
} catch (NetconfException e) {
log.error("Cannot comunicate to device {} , exception {}", deviceId, e.getMessage());
}
} else {
log.warn("I'm not master for {} please use master, {} to execute command", deviceId, mastershipService.getMasterFor(deviceId));
}
}
use of org.onosproject.net.driver.DriverHandler in project onos by opennetworkinglab.
the class ResourceDeviceListener method queryMplsLabels.
private Set<MplsLabel> queryMplsLabels(DeviceId device, PortNumber port) {
try {
DriverHandler handler = driverService.createHandler(device);
if (handler == null || !handler.hasBehaviour(MplsQuery.class)) {
return ImmutableSet.of();
}
MplsQuery query = handler.behaviour(MplsQuery.class);
if (query == null) {
return ImmutableSet.of();
}
return query.queryMplsLabels(port);
} catch (ItemNotFoundException e) {
return ImmutableSet.of();
}
}
Aggregations