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 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 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();
}
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);
}
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);
}
Aggregations