Search in sources :

Example 26 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 27 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 28 with Annotations

use of org.onosproject.net.Annotations in project onos by opennetworkinglab.

the class LinkCodec method decode.

/**
 * {@inheritDoc}
 *
 * Note: ProviderId is not part of JSON representation.
 *       Returned object will have random ProviderId set.
 */
@Override
public Link decode(ObjectNode json, CodecContext context) {
    if (json == null || !json.isObject()) {
        return null;
    }
    JsonCodec<ConnectPoint> codec = context.codec(ConnectPoint.class);
    // TODO: add providerId to JSON if we need to recover them.
    ProviderId pid = new ProviderId("json", "LinkCodec");
    ConnectPoint src = codec.decode(get(json, SRC), context);
    ConnectPoint dst = codec.decode(get(json, DST), context);
    Type type = Type.valueOf(json.get(TYPE).asText());
    Annotations annotations = extractAnnotations(json, context);
    return DefaultLink.builder().providerId(pid).src(src).dst(dst).type(type).annotations(annotations).build();
}
Also used : ProviderId(org.onosproject.net.provider.ProviderId) Type(org.onosproject.net.Link.Type) Annotations(org.onosproject.net.Annotations) ConnectPoint(org.onosproject.net.ConnectPoint)

Example 29 with Annotations

use of org.onosproject.net.Annotations in project onos by opennetworkinglab.

the class PortCodec method decode.

/**
 * {@inheritDoc}
 *
 * Note: Result of {@link Port#element()} returned Port object,
 *       is not a full Device object.
 *       Only it's DeviceId can be used.
 */
@Override
public Port decode(ObjectNode json, CodecContext context) {
    if (json == null || !json.isObject()) {
        return null;
    }
    DeviceId did = DeviceId.deviceId(json.get(ELEMENT).asText());
    Device device = new DummyDevice(did);
    PortNumber number = portNumber(json.get(PORT_NAME).asText());
    boolean isEnabled = json.get(IS_ENABLED).asBoolean();
    Type type = Type.valueOf(json.get(TYPE).asText().toUpperCase());
    long portSpeed = json.get(PORT_SPEED).asLong();
    Annotations annotations = extractAnnotations(json, context);
    return new DefaultPort(device, number, isEnabled, type, portSpeed, annotations);
}
Also used : Type(org.onosproject.net.Port.Type) DefaultAnnotations(org.onosproject.net.DefaultAnnotations) Annotations(org.onosproject.net.Annotations) DeviceId(org.onosproject.net.DeviceId) Device(org.onosproject.net.Device) DefaultDevice(org.onosproject.net.DefaultDevice) PortNumber(org.onosproject.net.PortNumber) DefaultPort(org.onosproject.net.DefaultPort)

Example 30 with Annotations

use of org.onosproject.net.Annotations in project onos by opennetworkinglab.

the class RegionCodec method decode.

@Override
public Region decode(ObjectNode json, CodecContext context) {
    if (json == null || !json.isObject()) {
        return null;
    }
    // parse masters
    List<Set<NodeId>> masters = new ArrayList<>();
    JsonNode mastersJson = json.get(MASTERS);
    checkNotNull(mastersJson);
    IntStream.range(0, mastersJson.size()).forEach(i -> {
        JsonNode setsJson = mastersJson.get(i);
        final Set<NodeId> nodeIds = Sets.newHashSet();
        if (setsJson != null && setsJson.isArray()) {
            Set<NodeId> localNodeIds = Sets.newHashSet();
            IntStream.range(0, setsJson.size()).forEach(j -> {
                JsonNode nodeIdJson = setsJson.get(j);
                localNodeIds.add(decodeNodeId(nodeIdJson));
            });
            nodeIds.addAll(localNodeIds);
        }
        masters.add(nodeIds);
    });
    RegionId regionId = RegionId.regionId(extractMember(REGION_ID, json));
    String name = extractMember(NAME, json);
    Region.Type type = REGION_TYPE_MAP.get(extractMember(TYPE, json));
    Annotations annots = extractAnnotations(json, context);
    return new DefaultRegion(regionId, name, type, annots, masters);
}
Also used : Set(java.util.Set) Annotations(org.onosproject.net.Annotations) ArrayList(java.util.ArrayList) NodeId(org.onosproject.cluster.NodeId) Region(org.onosproject.net.region.Region) DefaultRegion(org.onosproject.net.region.DefaultRegion) DefaultRegion(org.onosproject.net.region.DefaultRegion) JsonNode(com.fasterxml.jackson.databind.JsonNode) RegionId(org.onosproject.net.region.RegionId)

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