use of org.onosproject.net.device.DefaultDeviceDescription in project onos by opennetworkinglab.
the class LumentumWaveReadyDiscovery method discoverDeviceDetails.
@Override
public DeviceDescription discoverDeviceDetails() {
DeviceId deviceId = handler().data().deviceId();
Tl1Controller ctrl = checkNotNull(handler().get(Tl1Controller.class));
// Something reasonable, unavailable by default
DeviceDescription defaultDescription = new DefaultDeviceDescription(deviceId.uri(), Device.Type.OTN, LUMENTUM, WAVEREADY, SWVERSION, SERIAL, new ChassisId(), false, DefaultAnnotations.EMPTY);
Optional<Tl1Device> device = ctrl.getDevice(deviceId);
if (!device.isPresent()) {
return defaultDescription;
}
// Login
Tl1Command loginCmd = DefaultTl1Command.builder().withVerb(ACT).withModifier(USER).withAid(device.get().username()).withCtag(100).withParameters(device.get().password()).build();
Future<String> login = ctrl.sendMsg(deviceId, loginCmd);
try {
String loginResponse = login.get(TIMEOUT, TimeUnit.MILLISECONDS);
if (loginResponse.contains("Access denied")) {
log.error("Access denied: {}", loginResponse);
return defaultDescription;
}
} catch (InterruptedException | ExecutionException | TimeoutException e) {
log.error("Login failed", e);
return defaultDescription;
}
// Fetch device description
Tl1Command ddCmd = DefaultTl1Command.builder().withVerb(RTRV).withModifier(NETYPE).withCtag(101).build();
Future<String> dd = ctrl.sendMsg(deviceId, ddCmd);
try {
String ddResponse = dd.get(TIMEOUT, TimeUnit.MILLISECONDS);
return new DefaultDeviceDescription(defaultDescription, true, extractAnnotations(ddResponse));
} catch (InterruptedException | ExecutionException | TimeoutException e) {
log.error("Device description not found", e);
return defaultDescription;
}
}
use of org.onosproject.net.device.DefaultDeviceDescription in project onos by opennetworkinglab.
the class XmppDeviceProvider method connectDevice.
private void connectDevice(XmppDeviceId xmppDeviceId) {
DeviceId deviceId = DeviceId.deviceId(xmppDeviceId.id());
String ipAddress = controller.getDevice(xmppDeviceId).getIpAddress().getAddress().getHostAddress();
// Assumption: manufacturer is uniquely identified by domain part of JID
String manufacturer = xmppDeviceId.getJid().getDomain();
ChassisId cid = new ChassisId();
SparseAnnotations annotations = DefaultAnnotations.builder().set(AnnotationKeys.PROTOCOL, XMPP.toUpperCase()).set("IpAddress", ipAddress).build();
DeviceDescription deviceDescription = new DefaultDeviceDescription(deviceId.uri(), Device.Type.OTHER, manufacturer, HARDWARE_VERSION, SOFTWARE_VERSION, SERIAL_NUMBER, cid, true, annotations);
if (deviceService.getDevice(deviceId) == null) {
providerService.deviceConnected(deviceId, deviceDescription);
}
}
use of org.onosproject.net.device.DefaultDeviceDescription 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.device.DefaultDeviceDescription 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.DefaultDeviceDescription in project onos by opennetworkinglab.
the class NokiaOpenConfigDeviceDiscovery method discoverDeviceDetails.
@Override
public DeviceDescription discoverDeviceDetails() {
DeviceId did = data().deviceId();
NetconfSession ns = getNetconfSessionAndLogin(did, USER_NAME, PASSWORD);
if (ns == null) {
log.error("DiscoverDeviceDetails called with null session for {}", did);
return null;
}
log.info("Discovering device details {}", handler().data().deviceId());
String hwVersion = "1830", swVersion = "OpenAgent";
try {
String reply = ns.requestSync(buildGetSystemSoftwareRpc());
XMLConfiguration cfg = (XMLConfiguration) XmlConfigParser.loadXmlString(getDataOfRpcReply(reply));
hwVersion = cfg.getString("components.component.state.description");
swVersion = cfg.getString("components.component.state.version");
} catch (NetconfException e) {
log.error("Error discovering device details on {}", data().deviceId(), e);
}
return new DefaultDeviceDescription(handler().data().deviceId().uri(), Device.Type.ROADM_OTN, "NOKIA", hwVersion, swVersion, "", new ChassisId("1"));
}
Aggregations