Search in sources :

Example 36 with Annotations

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);
}
Also used : Annotations(org.onosproject.net.Annotations) Device(org.onosproject.net.Device) GeoLocation(org.onlab.util.GeoLocation)

Example 37 with Annotations

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);
}
Also used : JsonNode(com.fasterxml.jackson.databind.JsonNode) MacAddress(org.onlab.packet.MacAddress) HostId(org.onosproject.net.HostId) DefaultHost(org.onosproject.net.DefaultHost) EthType(org.onlab.packet.EthType) Annotations(org.onosproject.net.Annotations) HostLocation(org.onosproject.net.HostLocation) IpAddress(org.onlab.packet.IpAddress) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) VlanId(org.onlab.packet.VlanId) HashSet(java.util.HashSet)

Example 38 with 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);
}
Also used : ProviderId(org.onosproject.net.provider.ProviderId) Type(org.onosproject.net.Device.Type) ChassisId(org.onlab.packet.ChassisId) DefaultAnnotations(org.onosproject.net.DefaultAnnotations) Annotations(org.onosproject.net.Annotations) DeviceId(org.onosproject.net.DeviceId) DefaultDevice(org.onosproject.net.DefaultDevice)

Example 39 with 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;
}
Also used : Annotations(org.onosproject.net.Annotations) Device(org.onosproject.net.Device) TopoUtils.compactLinkString(org.onosproject.ui.topo.TopoUtils.compactLinkString) LionBundle(org.onosproject.ui.lion.LionBundle) PropertyPanel(org.onosproject.ui.topo.PropertyPanel)

Aggregations

Annotations (org.onosproject.net.Annotations)39 DefaultAnnotations (org.onosproject.net.DefaultAnnotations)25 Test (org.junit.Test)9 Device (org.onosproject.net.Device)9 Port (org.onosproject.net.Port)8 ArrayList (java.util.ArrayList)6 DefaultDevice (org.onosproject.net.DefaultDevice)6 DefaultPort (org.onosproject.net.DefaultPort)6 SparseAnnotations (org.onosproject.net.SparseAnnotations)5 IpAddress (org.onlab.packet.IpAddress)4 DefaultPath (org.onosproject.net.DefaultPath)4 PortNumber (org.onosproject.net.PortNumber)4 ProviderId (org.onosproject.net.provider.ProviderId)4 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)3 Set (java.util.Set)3 Before (org.junit.Before)3 Frequency (org.onlab.util.Frequency)3 NodeId (org.onosproject.cluster.NodeId)3 ConnectPoint (org.onosproject.net.ConnectPoint)3 DefaultHost (org.onosproject.net.DefaultHost)3