use of org.onosproject.net.device.DefaultDeviceDescription in project onos by opennetworkinglab.
the class TerminalDeviceDiscovery method discoverDeviceDetails.
/**
* Returns a DeviceDescription with Device info.
*
* @return DeviceDescription or null
*
* //CHECKSTYLE:OFF
* <pre>{@code
* <data>
* <components xmlns="http://openconfig.net/yang/platform">
* <component>
* <state>
* <name>FIRMWARE</name>
* <type>oc-platform-types:OPERATING_SYSTEM</type>
* <description>CTTC METRO-HAUL Emulated OpenConfig TerminalDevice</description>
* <version>0.0.1</version>
* </state>
* </component>
* </components>
* </data>
*}</pre>
* //CHECKSTYLE:ON
*/
@Override
public DeviceDescription discoverDeviceDetails() {
log.info("TerminalDeviceDiscovery::discoverDeviceDetails device {}", did());
boolean defaultAvailable = true;
SparseAnnotations annotations = DefaultAnnotations.builder().build();
// Other option "OTHER", we use ROADM for now
org.onosproject.net.Device.Type type = Device.Type.TERMINAL_DEVICE;
// Some defaults
String vendor = "NOVENDOR";
String hwVersion = "0.2.1";
String swVersion = "0.2.1";
String serialNumber = "0xCAFEBEEF";
String chassisId = "128";
// Get the session,
NetconfSession session = getNetconfSession(did());
if (session != null) {
try {
String reply = session.get(getDeviceDetailsBuilder());
// <rpc-reply> as root node
XMLConfiguration xconf = (XMLConfiguration) XmlConfigParser.loadXmlString(reply);
vendor = xconf.getString("data/components/component/state/mfg-name", vendor);
serialNumber = xconf.getString("data/components/component/state/serial-no", serialNumber);
// Requires OpenConfig >= 2018
swVersion = xconf.getString("data/components/component/state/software-version", swVersion);
hwVersion = xconf.getString("data/components/component/state/hardware-version", hwVersion);
} catch (Exception e) {
throw new IllegalStateException(new NetconfException("Failed to retrieve version info.", e));
}
} else {
log.info("TerminalDeviceDiscovery::discoverDeviceDetails - No netconf session for {}", did());
}
log.info("VENDOR {}", vendor);
log.info("HWVERSION {}", hwVersion);
log.info("SWVERSION {}", swVersion);
log.info("SERIAL {}", serialNumber);
log.info("CHASSISID {}", chassisId);
ChassisId cid = new ChassisId(Long.valueOf(chassisId, 10));
return new DefaultDeviceDescription(did().uri(), type, vendor, hwVersion, swVersion, serialNumber, cid, defaultAvailable, annotations);
}
use of org.onosproject.net.device.DefaultDeviceDescription in project onos by opennetworkinglab.
the class TapiDeviceDescriptionDiscovery method discoverDeviceDetails.
@Override
public DeviceDescription discoverDeviceDetails() {
log.debug("Getting device description");
DeviceService deviceService = checkNotNull(handler().get(DeviceService.class));
DeviceId deviceId = handler().data().deviceId();
Device device = deviceService.getDevice(deviceId);
if (device == null) {
// TODO need to obtain from the device.
return new DefaultDeviceDescription(deviceId.uri(), Device.Type.OLS, "Tapi", "0", "2.1", "Unknown", new ChassisId(), DefaultAnnotations.builder().set("protocol", "REST").build());
} else {
return new DefaultDeviceDescription(device.id().uri(), Device.Type.OLS, device.manufacturer(), device.hwVersion(), device.swVersion(), device.serialNumber(), device.chassisId());
}
}
use of org.onosproject.net.device.DefaultDeviceDescription in project onos by opennetworkinglab.
the class DeviceManagerTest method connectDevice.
private void connectDevice(DeviceId deviceId, String swVersion) {
DeviceDescription description = new DefaultDeviceDescription(deviceId.uri(), SWITCH, MFR, HW, swVersion, SN, CID);
providerService.deviceConnected(deviceId, description);
assertNotNull("device should be found", service.getDevice(DID1));
}
use of org.onosproject.net.device.DefaultDeviceDescription in project onos by opennetworkinglab.
the class BasicDeviceOperator method combine.
/**
* Generates a DeviceDescription containing fields from a DeviceDescription and
* a DeviceConfig.
*
* @param cfg the device config entity from network config
* @param descr a DeviceDescription
* @return DeviceDescription based on both sources
*/
public static DeviceDescription combine(BasicDeviceConfig cfg, DeviceDescription descr) {
if (cfg == null || descr == null) {
return descr;
}
Device.Type type = descr.type();
if (cfg.type() != null && cfg.type() != type) {
type = cfg.type();
}
String manufacturer = descr.manufacturer();
if (cfg.manufacturer() != null && !cfg.manufacturer().equals(manufacturer)) {
manufacturer = cfg.manufacturer();
}
String hwVersion = descr.hwVersion();
if (cfg.hwVersion() != null && !cfg.hwVersion().equals(hwVersion)) {
hwVersion = cfg.hwVersion();
}
String swVersion = descr.swVersion();
if (cfg.swVersion() != null && !cfg.swVersion().equals(swVersion)) {
swVersion = cfg.swVersion();
}
String serial = descr.serialNumber();
if (cfg.serial() != null && !cfg.serial().equals(serial)) {
serial = cfg.serial();
}
SparseAnnotations sa = combine(cfg, descr.annotations());
return new DefaultDeviceDescription(descr.deviceUri(), type, manufacturer, hwVersion, swVersion, serial, descr.chassisId(), descr.isDefaultAvailable(), sa);
}
use of org.onosproject.net.device.DefaultDeviceDescription in project onos by opennetworkinglab.
the class DeviceProtoTranslator method translate.
/**
* Translates gRPC DeviceDescription to {@link DeviceDescriptionProtoOuterClass}.
*
* @param deviceDescription gRPC message
* @return {@link DeviceDescriptionProtoOuterClass}
*/
public static DeviceDescription translate(DeviceDescriptionProto deviceDescription) {
URI uri = URI.create(deviceDescription.getDeviceUri());
Type type = translate(deviceDescription.getType());
String manufacturer = deviceDescription.getManufacturer();
String hwVersion = deviceDescription.getHwVersion();
String swVersion = deviceDescription.getSwVersion();
String serialNumber = deviceDescription.getSerialNumber();
ChassisId chassis = new ChassisId(deviceDescription.getChassisId());
boolean defaultAvailable = deviceDescription.getIsDefaultAvailable();
return new DefaultDeviceDescription(uri, type, manufacturer, hwVersion, swVersion, serialNumber, chassis, defaultAvailable, AnnotationsTranslator.asAnnotations(deviceDescription.getAnnotationsMap()));
}
Aggregations