use of org.onosproject.net.Annotations in project onos by opennetworkinglab.
the class GeoDistanceLinkWeight method getLocation.
private GeoLocation getLocation(DeviceId deviceId) {
Device d = deviceService.getDevice(deviceId);
Annotations a = d != null ? d.annotations() : null;
double latitude = getDouble(a, AnnotationKeys.LATITUDE);
double longitude = getDouble(a, AnnotationKeys.LONGITUDE);
return latitude == MAX_VALUE || longitude == MAX_VALUE ? null : new GeoLocation(latitude, longitude);
}
use of org.onosproject.net.Annotations in project onos by opennetworkinglab.
the class HostCodec method decode.
@Override
public Host decode(ObjectNode json, CodecContext context) {
if (json == null || !json.isObject()) {
return null;
}
MacAddress mac = MacAddress.valueOf(nullIsIllegal(json.get(MAC), MAC + MISSING_MEMBER_MESSAGE).asText());
VlanId vlanId = VlanId.vlanId(nullIsIllegal(json.get(VLAN), VLAN + MISSING_MEMBER_MESSAGE).asText());
HostId id = HostId.hostId(mac, vlanId);
ArrayNode locationNodes = nullIsIllegal((ArrayNode) json.get(HOST_LOCATIONS), HOST_LOCATIONS + MISSING_MEMBER_MESSAGE);
Set<HostLocation> hostLocations = context.codec(HostLocation.class).decode(locationNodes, context).stream().collect(Collectors.toSet());
ArrayNode ipNodes = nullIsIllegal((ArrayNode) json.get(IP_ADDRESSES), IP_ADDRESSES + MISSING_MEMBER_MESSAGE);
Set<IpAddress> ips = new HashSet<>();
ipNodes.forEach(ipNode -> {
ips.add(IpAddress.valueOf(ipNode.asText()));
});
// check optional fields
JsonNode innerVlanIdNode = json.get(INNER_VLAN);
VlanId innerVlanId = (null == innerVlanIdNode) ? VlanId.NONE : VlanId.vlanId(innerVlanIdNode.asText());
JsonNode outerTpidNode = json.get(OUTER_TPID);
EthType outerTpid = (null == outerTpidNode) ? EthType.EtherType.UNKNOWN.ethType() : EthType.EtherType.lookup((short) (Integer.decode(outerTpidNode.asText()) & 0xFFFF)).ethType();
JsonNode configuredNode = json.get(IS_CONFIGURED);
boolean configured = (null == configuredNode) ? false : configuredNode.asBoolean();
JsonNode suspendedNode = json.get(IS_SUSPENDED);
boolean suspended = (null == suspendedNode) ? false : suspendedNode.asBoolean();
ArrayNode auxLocationNodes = (ArrayNode) json.get(AUX_LOCATIONS);
Set<HostLocation> auxHostLocations = (null == auxLocationNodes) ? null : context.codec(HostLocation.class).decode(auxLocationNodes, context).stream().collect(Collectors.toSet());
Annotations annotations = extractAnnotations(json, context);
return new DefaultHost(ProviderId.NONE, id, mac, vlanId, hostLocations, auxHostLocations, ips, innerVlanId, outerTpid, configured, suspended, annotations);
}
use of org.onosproject.net.Annotations 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.Annotations in project onos by opennetworkinglab.
the class TopologyViewMessageHandlerBase method deviceDetails.
// Generates a property panel model for device details response
protected PropertyPanel deviceDetails(DeviceId deviceId) {
log.debug("generate prop panel data for device {}", deviceId);
Device device = services.device().getDevice(deviceId);
Annotations annot = device.annotations();
String proto = annot.value(AnnotationKeys.PROTOCOL);
String title = friendlyDevice(deviceId);
LionBundle lion = getLionBundle(LION_TOPO);
PropertyPanel pp = new PropertyPanel(title, lookupGlyph(device)).navPath(DEVICE_NAV_PATH).id(deviceId.toString());
addDeviceBasicProps(pp, deviceId, device, proto, lion);
addLocationProps(pp, annot, lion);
addDeviceCountStats(pp, deviceId, lion);
addDeviceCoreButtons(pp);
return pp;
}
Aggregations