Search in sources :

Example 46 with MappingAddress

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

the class LispListAddressCodec method decode.

@Override
public LispListAddress decode(ObjectNode json, CodecContext context) {
    if (json == null || !json.isObject()) {
        return null;
    }
    final JsonCodec<MappingAddress> addressCodec = context.codec(MappingAddress.class);
    ObjectNode ipv4Json = get(json, IPV4);
    ObjectNode ipv6Json = get(json, IPV6);
    MappingAddress ipv4Address = null;
    MappingAddress ipv6Address = null;
    if (ipv4Json != null) {
        ipv4Address = addressCodec.decode(ipv4Json, context);
    }
    if (ipv6Json != null) {
        ipv6Address = addressCodec.decode(ipv6Json, context);
    }
    if (ipv4Json == null && ipv6Json == null) {
        log.error("Either IPv4 or IPv6 address should be specified.");
    }
    return new LispListAddress.Builder().withIpv4(ipv4Address).withIpv6(ipv6Address).build();
}
Also used : MappingAddress(org.onosproject.mapping.addresses.MappingAddress) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) LispListAddress(org.onosproject.drivers.lisp.extensions.LispListAddress)

Example 47 with MappingAddress

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

the class LispMulticastAddressCodec method encode.

@Override
public ObjectNode encode(LispMulticastAddress address, CodecContext context) {
    checkNotNull(address, "LispMulticastAddress cannot be null");
    final ObjectNode result = context.mapper().createObjectNode().put(INSTANCE_ID, address.getInstanceId()).put(SRC_MASK_LENGTH, address.getSrcMaskLength()).put(GRP_MASK_LENGTH, address.getGrpMaskLength());
    final JsonCodec<MappingAddress> addressCodec = context.codec(MappingAddress.class);
    if (address.getSrcAddress() != null) {
        ObjectNode srcAddressNode = addressCodec.encode(address.getSrcAddress(), context);
        result.set(SRC_ADDRESS, srcAddressNode);
    }
    if (address.getGrpAddress() != null) {
        ObjectNode grpAddressNode = addressCodec.encode(address.getGrpAddress(), context);
        result.set(GRP_ADDRESS, grpAddressNode);
    }
    return result;
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) MappingAddress(org.onosproject.mapping.addresses.MappingAddress)

Example 48 with MappingAddress

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

the class LispNatAddressCodec method encode.

@Override
public ObjectNode encode(LispNatAddress address, CodecContext context) {
    checkNotNull(address, "LispListAddress cannot be null");
    final ObjectNode result = context.mapper().createObjectNode().put(MS_UDP_PORT_NUMBER, address.getMsUdpPortNumber()).put(ETR_UDP_PORT_NUMBER, address.getEtrUdpPortNumber());
    final JsonCodec<MappingAddress> addressCodec = context.codec(MappingAddress.class);
    if (address.getGlobalEtrRlocAddress() != null) {
        ObjectNode globalEtrRlocNode = addressCodec.encode(address.getGlobalEtrRlocAddress(), context);
        result.set(GLOBAL_ETR_RLOC_ADDRESS, globalEtrRlocNode);
    }
    if (address.getMsRlocAddress() != null) {
        ObjectNode msRlocNode = addressCodec.encode(address.getMsRlocAddress(), context);
        result.set(MS_RLOC_ADDRESS, msRlocNode);
    }
    if (address.getPrivateEtrRlocAddress() != null) {
        ObjectNode privateEtrRlocNode = addressCodec.encode(address.getPrivateEtrRlocAddress(), context);
        result.set(PRIVATE_ETR_RLOC_ADDRESS, privateEtrRlocNode);
    }
    final ArrayNode jsonRtrRlocNodes = result.putArray(RTR_RLOC_ADDRESSES);
    if (address.getRtrRlocAddresses() != null) {
        for (final MappingAddress mappingAddress : address.getRtrRlocAddresses()) {
            jsonRtrRlocNodes.add(addressCodec.encode(mappingAddress, context));
        }
    }
    return result;
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) MappingAddress(org.onosproject.mapping.addresses.MappingAddress) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode)

Example 49 with MappingAddress

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

the class LispNonceAddressCodec method encode.

@Override
public ObjectNode encode(LispNonceAddress address, CodecContext context) {
    checkNotNull(address, "LispListAddress cannot be null");
    final ObjectNode result = context.mapper().createObjectNode().put(NONCE, address.getNonce());
    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 50 with MappingAddress

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

the class LispNonceAddressCodec method decode.

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

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