use of org.onosproject.net.Device.Type 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()));
}
use of org.onosproject.net.Device.Type in project onos by opennetworkinglab.
the class DeviceCodec method decode.
/**
* {@inheritDoc}
*
* Note: ProviderId is not part of JSON representation.
* Returned object will have random ProviderId set.
*/
@Override
public Device decode(ObjectNode json, CodecContext context) {
if (json == null || !json.isObject()) {
return null;
}
DeviceId id = deviceId(json.get(ID).asText());
// TODO: add providerId to JSON if we need to recover them.
ProviderId pid = new ProviderId(id.uri().getScheme(), "DeviceCodec");
Type type = Type.valueOf(json.get(TYPE).asText());
String mfr = json.get(MFR).asText();
String hw = json.get(HW).asText();
String sw = json.get(SW).asText();
String serial = json.get(SERIAL).asText();
ChassisId chassisId = new ChassisId(json.get(CHASSIS_ID).asText());
Annotations annotations = extractAnnotations(json, context);
return new DefaultDevice(pid, id, type, mfr, hw, sw, serial, chassisId, annotations);
}
use of org.onosproject.net.Device.Type in project onos by opennetworkinglab.
the class SimpleDeviceStore method composeDevice.
/**
* Returns a Device, merging description given from multiple Providers.
*
* @param deviceId device identifier
* @param providerDescs Collection of Descriptions from multiple providers
* @return Device instance
*/
private Device composeDevice(DeviceId deviceId, Map<ProviderId, DeviceDescriptions> providerDescs) {
checkArgument(!providerDescs.isEmpty(), "No Device descriptions supplied");
ProviderId primary = pickPrimaryPid(providerDescs);
DeviceDescriptions desc = providerDescs.get(primary);
final DeviceDescription base = desc.getDeviceDesc();
Type type = base.type();
String manufacturer = base.manufacturer();
String hwVersion = base.hwVersion();
String swVersion = base.swVersion();
String serialNumber = base.serialNumber();
ChassisId chassisId = base.chassisId();
DefaultAnnotations annotations = DefaultAnnotations.builder().build();
annotations = merge(annotations, base.annotations());
for (Entry<ProviderId, DeviceDescriptions> e : providerDescs.entrySet()) {
if (e.getKey().equals(primary)) {
continue;
}
// TODO: should keep track of Description timestamp
// and only merge conflicting keys when timestamp is newer
// Currently assuming there will never be a key conflict between
// providers
// annotation merging. not so efficient, should revisit later
annotations = merge(annotations, e.getValue().getDeviceDesc().annotations());
}
return new DefaultDevice(primary, deviceId, type, manufacturer, hwVersion, swVersion, serialNumber, chassisId, annotations);
}
Aggregations