use of org.onosproject.mapping.addresses.MappingAddress in project onos by opennetworkinglab.
the class LispSegmentAddressCodec method encode.
@Override
public ObjectNode encode(LispSegmentAddress address, CodecContext context) {
checkNotNull(address, "LispSegmentAddress cannot be null");
final ObjectNode result = context.mapper().createObjectNode().put(INSTANCE_ID, address.getInstanceId());
if (address.getAddress() != null) {
final JsonCodec<MappingAddress> addressCodec = context.codec(MappingAddress.class);
ObjectNode addressNode = addressCodec.encode(address.getAddress(), context);
result.set(ADDRESS, addressNode);
}
return result;
}
use of org.onosproject.mapping.addresses.MappingAddress in project onos by opennetworkinglab.
the class LispAppDataAddressCodec method decode.
@Override
public LispAppDataAddress decode(ObjectNode json, CodecContext context) {
if (json == null || !json.isObject()) {
return null;
}
byte protocol = (byte) json.get(PROTOCOL).asInt();
int ipTos = json.get(IP_TOS).asInt();
short localPortLow = (short) json.get(LOCAL_PORT_LOW).asInt();
short localPortHigh = (short) json.get(LOCAL_PORT_HIGH).asInt();
short remotePortLow = (short) json.get(REMOTE_PORT_LOW).asInt();
short remotePortHigh = (short) json.get(REMOTE_PORT_HIGH).asInt();
ObjectNode addressJson = get(json, ADDRESS);
MappingAddress mappingAddress = null;
if (addressJson != null) {
final JsonCodec<MappingAddress> addressCodec = context.codec(MappingAddress.class);
mappingAddress = addressCodec.decode(addressJson, context);
}
return new LispAppDataAddress.Builder().withProtocol(protocol).withIpTos(ipTos).withLocalPortLow(localPortLow).withLocalPortHigh(localPortHigh).withRemotePortLow(remotePortLow).withRemotePortHigh(remotePortHigh).withAddress(mappingAddress).build();
}
use of org.onosproject.mapping.addresses.MappingAddress in project onos by opennetworkinglab.
the class LispAsAddressCodec method decode.
@Override
public LispAsAddress decode(ObjectNode json, CodecContext context) {
if (json == null || !json.isObject()) {
return null;
}
int asNumber = nullIsIllegal(json.get(AS_NUMBER), AS_NUMBER + MISSING_MEMBER_MESSAGE).asInt();
ObjectNode addressJson = get(json, ADDRESS);
MappingAddress mappingAddress = null;
if (addressJson != null) {
final JsonCodec<MappingAddress> addressCodec = context.codec(MappingAddress.class);
mappingAddress = addressCodec.decode(addressJson, context);
}
return new LispAsAddress.Builder().withAsNumber(asNumber).withAddress(mappingAddress).build();
}
use of org.onosproject.mapping.addresses.MappingAddress in project onos by opennetworkinglab.
the class LispGcAddressCodec method encode.
@Override
public ObjectNode encode(LispGcAddress address, CodecContext context) {
checkNotNull(address, "LispGcAddress cannot be null");
final ObjectNode result = context.mapper().createObjectNode().put(NORTH, address.isNorth()).put(LATITUDE_DEGREE, address.getLatitudeDegree()).put(LATITUDE_MINUTE, address.getLatitudeMinute()).put(LATITUDE_SECOND, address.getLatitudeSecond()).put(EAST, address.isEast()).put(LONGITUDE_DEGREE, address.getLongitudeDegree()).put(LONGITUDE_MINUTE, address.getLongitudeMinute()).put(LONGITUDE_SECOND, address.getLongitudeSecond()).put(ALTITUDE, address.getAltitude());
if (address.getAddress() != null) {
final JsonCodec<MappingAddress> addressCodec = context.codec(MappingAddress.class);
ObjectNode addressNode = addressCodec.encode(address.getAddress(), context);
result.set(ADDRESS, addressNode);
}
return result;
}
use of org.onosproject.mapping.addresses.MappingAddress in project onos by opennetworkinglab.
the class MappingAddressCodecTest method ipv4MappingAddressTest.
/**
* Tests IPv4 mapping address.
*/
@Test
public void ipv4MappingAddressTest() {
MappingAddress address = MappingAddresses.ipv4MappingAddress(IPV4_PREFIX);
ObjectNode result = addressCodec.encode(address, context);
assertThat(result, matchesMappingAddress(address));
}
Aggregations