Search in sources :

Example 16 with MappingAddress

use of org.onosproject.mapping.addresses.MappingAddress in project onos by opennetworkinglab.

the class LispSegmentAddressCodec method decode.

@Override
public LispSegmentAddress decode(ObjectNode json, CodecContext context) {
    if (json == null || !json.isObject()) {
        return null;
    }
    int instanceId = nullIsIllegal(json.get(INSTANCE_ID), INSTANCE_ID + 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 LispSegmentAddress.Builder().withInstanceId(instanceId).withAddress(mappingAddress).build();
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) MappingAddress(org.onosproject.mapping.addresses.MappingAddress) LispSegmentAddress(org.onosproject.drivers.lisp.extensions.LispSegmentAddress)

Example 17 with MappingAddress

use of org.onosproject.mapping.addresses.MappingAddress in project onos by opennetworkinglab.

the class LispSrcDstAddressCodec method decode.

@Override
public LispSrcDstAddress decode(ObjectNode json, CodecContext context) {
    if (json == null || !json.isObject()) {
        return null;
    }
    byte srcMaskLength = (byte) nullIsIllegal(json.get(SRC_MASK_LENGTH), SRC_MASK_LENGTH + MISSING_MEMBER_MESSAGE).asInt();
    byte dstMaskLength = (byte) nullIsIllegal(json.get(DST_MASK_LENGTH), DST_MASK_LENGTH + MISSING_MEMBER_MESSAGE).asInt();
    final JsonCodec<MappingAddress> addressCodec = context.codec(MappingAddress.class);
    ObjectNode srcPrefixJson = get(json, SRC_PREFIX);
    MappingAddress srcPrefix = null;
    ObjectNode dstPrefixJson = get(json, DST_PREFIX);
    MappingAddress dstPrefix = null;
    if (srcPrefixJson != null) {
        srcPrefix = addressCodec.decode(srcPrefixJson, context);
    }
    if (dstPrefixJson != null) {
        dstPrefix = addressCodec.decode(dstPrefixJson, context);
    }
    return new LispSrcDstAddress.Builder().withSrcMaskLength(srcMaskLength).withDstMaskLength(dstMaskLength).withSrcPrefix(srcPrefix).withDstPrefix(dstPrefix).build();
}
Also used : LispSrcDstAddress(org.onosproject.drivers.lisp.extensions.LispSrcDstAddress) MappingAddress(org.onosproject.mapping.addresses.MappingAddress) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode)

Example 18 with MappingAddress

use of org.onosproject.mapping.addresses.MappingAddress in project onos by opennetworkinglab.

the class LispSrcDstAddressCodec method encode.

@Override
public ObjectNode encode(LispSrcDstAddress address, CodecContext context) {
    checkNotNull(address, "LispSrcDstAddress cannot be null");
    final JsonCodec<MappingAddress> addressCodec = context.codec(MappingAddress.class);
    final ObjectNode result = context.mapper().createObjectNode().put(SRC_MASK_LENGTH, address.getSrcMaskLength()).put(DST_MASK_LENGTH, address.getDstMaskLength());
    if (address.getSrcPrefix() != null) {
        ObjectNode srcPrefix = addressCodec.encode(address.getSrcPrefix(), context);
        result.set(SRC_PREFIX, srcPrefix);
    }
    if (address.getDstPrefix() != null) {
        ObjectNode dstPrefix = addressCodec.encode(address.getDstPrefix(), context);
        result.set(DST_PREFIX, dstPrefix);
    }
    return result;
}
Also used : MappingAddress(org.onosproject.mapping.addresses.MappingAddress) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode)

Example 19 with MappingAddress

use of org.onosproject.mapping.addresses.MappingAddress in project onos by opennetworkinglab.

the class LispTeRecordCodec method encode.

@Override
public ObjectNode encode(LispTeAddress.TeRecord record, CodecContext context) {
    checkNotNull(record, "LispTeRecord cannot be null");
    final ObjectNode result = context.mapper().createObjectNode().put(LOOKUP, record.isLookup()).put(RLOC_PROBE, record.isRlocProbe()).put(STRICT, record.isStrict());
    if (record.getAddress() != null) {
        final JsonCodec<MappingAddress> addressCodec = context.codec(MappingAddress.class);
        ObjectNode address = addressCodec.encode(record.getAddress(), context);
        result.set(ADDRESS, address);
    }
    return result;
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) MappingAddress(org.onosproject.mapping.addresses.MappingAddress)

Example 20 with MappingAddress

use of org.onosproject.mapping.addresses.MappingAddress in project onos by opennetworkinglab.

the class LispTeRecordCodec method decode.

@Override
public LispTeAddress.TeRecord decode(ObjectNode json, CodecContext context) {
    if (json == null || !json.isObject()) {
        return null;
    }
    boolean isLookup = nullIsIllegal(json.get(LOOKUP), LOOKUP + MISSING_MEMBER_MESSAGE).asBoolean();
    boolean isRlocProbe = nullIsIllegal(json.get(RLOC_PROBE), RLOC_PROBE + MISSING_MEMBER_MESSAGE).asBoolean();
    boolean isStrict = nullIsIllegal(json.get(STRICT), STRICT + MISSING_MEMBER_MESSAGE).asBoolean();
    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 LispTeAddress.TeRecord.Builder().withIsLookup(isLookup).withIsRlocProbe(isRlocProbe).withIsStrict(isStrict).withRtrRlocAddress(mappingAddress).build();
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) MappingAddress(org.onosproject.mapping.addresses.MappingAddress)

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