Search in sources :

Example 51 with MappingAddress

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;
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) MappingAddress(org.onosproject.mapping.addresses.MappingAddress)

Example 52 with MappingAddress

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();
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) MappingAddress(org.onosproject.mapping.addresses.MappingAddress)

Example 53 with MappingAddress

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();
}
Also used : LispAsAddress(org.onosproject.drivers.lisp.extensions.LispAsAddress) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) MappingAddress(org.onosproject.mapping.addresses.MappingAddress)

Example 54 with MappingAddress

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;
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) MappingAddress(org.onosproject.mapping.addresses.MappingAddress)

Example 55 with MappingAddress

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));
}
Also used : MappingAddressJsonMatcher.matchesMappingAddress(org.onosproject.mapping.codec.MappingAddressJsonMatcher.matchesMappingAddress) MappingAddress(org.onosproject.mapping.addresses.MappingAddress) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) Test(org.junit.Test)

Aggregations

MappingAddress (org.onosproject.mapping.addresses.MappingAddress)66 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)34 Test (org.junit.Test)26 Before (org.junit.Before)11 DefaultMappingTreatment (org.onosproject.mapping.DefaultMappingTreatment)7 MappingTreatment (org.onosproject.mapping.MappingTreatment)7 MappingAddressJsonMatcher.matchesMappingAddress (org.onosproject.mapping.codec.MappingAddressJsonMatcher.matchesMappingAddress)7 IpPrefix (org.onlab.packet.IpPrefix)6 MappingInstruction (org.onosproject.mapping.instructions.MappingInstruction)6 DefaultMappingKey (org.onosproject.mapping.DefaultMappingKey)5 MappingKey (org.onosproject.mapping.MappingKey)5 DefaultMappingValue (org.onosproject.mapping.DefaultMappingValue)4 MappingValue (org.onosproject.mapping.MappingValue)4 MappingAction (org.onosproject.mapping.actions.MappingAction)4 JsonNode (com.fasterxml.jackson.databind.JsonNode)3 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)2 EqualsTester (com.google.common.testing.EqualsTester)2 LispNatAddress (org.onosproject.drivers.lisp.extensions.LispNatAddress)2 LispTeRecord (org.onosproject.lisp.msg.types.lcaf.LispTeRecord)2 DefaultMapping (org.onosproject.mapping.DefaultMapping)2