Search in sources :

Example 11 with MappingAddress

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

the class LispSrcDstAddressTest method setUp.

@Before
public void setUp() {
    MappingAddress ma1 = MappingAddresses.ipv4MappingAddress(IP_ADDRESS_1);
    address1 = new LispSrcDstAddress.Builder().withSrcMaskLength(MASK_LENGTH_1).withDstMaskLength(MASK_LENGTH_1).withSrcPrefix(ma1).withDstPrefix(ma1).build();
    sameAsAddress1 = new LispSrcDstAddress.Builder().withSrcMaskLength(MASK_LENGTH_1).withDstMaskLength(MASK_LENGTH_1).withSrcPrefix(ma1).withDstPrefix(ma1).build();
    MappingAddress ma2 = MappingAddresses.ipv4MappingAddress(IP_ADDRESS_2);
    address2 = new LispSrcDstAddress.Builder().withSrcMaskLength(MASK_LENGTH_2).withDstMaskLength(MASK_LENGTH_2).withSrcPrefix(ma2).withDstPrefix(ma2).build();
}
Also used : MappingAddress(org.onosproject.mapping.addresses.MappingAddress) Before(org.junit.Before)

Example 12 with MappingAddress

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

the class LispSrcDstAddressTest method testConstruction.

@Test
public void testConstruction() {
    LispSrcDstAddress address = address1;
    MappingAddress ma = MappingAddresses.ipv4MappingAddress(IP_ADDRESS_1);
    assertThat(address.getSrcMaskLength(), is(MASK_LENGTH_1));
    assertThat(address.getDstMaskLength(), is(MASK_LENGTH_1));
    assertThat(address.getSrcPrefix(), is(ma));
    assertThat(address.getDstPrefix(), is(ma));
}
Also used : MappingAddress(org.onosproject.mapping.addresses.MappingAddress) Test(org.junit.Test)

Example 13 with MappingAddress

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

the class LispListAddressCodec method encode.

@Override
public ObjectNode encode(LispListAddress address, CodecContext context) {
    checkNotNull(address, "LispListAddress cannot be null");
    final ObjectNode result = context.mapper().createObjectNode();
    final JsonCodec<MappingAddress> addressCodec = context.codec(MappingAddress.class);
    if (address.getIpv4() != null) {
        ObjectNode ipv4Node = addressCodec.encode(address.getIpv4(), context);
        result.set(IPV4, ipv4Node);
    }
    if (address.getIpv6() != null) {
        ObjectNode ipv6Node = addressCodec.encode(address.getIpv6(), context);
        result.set(IPV6, ipv6Node);
    }
    if (address.getIpv4() == null && address.getIpv6() == null) {
        log.error("Either IPv4 or IPv6 address should be specified.");
    }
    return result;
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) MappingAddress(org.onosproject.mapping.addresses.MappingAddress)

Example 14 with MappingAddress

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

the class LispMulticastAddressCodec method decode.

@Override
public LispMulticastAddress 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();
    byte srcMaskLength = (byte) nullIsIllegal(json.get(SRC_MASK_LENGTH), SRC_MASK_LENGTH + MISSING_MEMBER_MESSAGE).asInt();
    byte grpMaskLength = (byte) nullIsIllegal(json.get(GRP_MASK_LENGTH), GRP_MASK_LENGTH + MISSING_MEMBER_MESSAGE).asInt();
    final JsonCodec<MappingAddress> addressCodec = context.codec(MappingAddress.class);
    ObjectNode srcAddressJson = get(json, SRC_ADDRESS);
    MappingAddress srcAddress = null;
    if (srcAddressJson != null) {
        srcAddress = addressCodec.decode(srcAddressJson, context);
    }
    ObjectNode grpAddressJson = get(json, GRP_ADDRESS);
    MappingAddress grpAddress = null;
    if (grpAddressJson != null) {
        grpAddress = addressCodec.decode(grpAddressJson, context);
    }
    return new LispMulticastAddress.Builder().withInstanceId(instanceId).withSrcMaskLength(srcMaskLength).withGrpMaskLength(grpMaskLength).withSrcAddress(srcAddress).withGrpAddress(grpAddress).build();
}
Also used : MappingAddress(org.onosproject.mapping.addresses.MappingAddress) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode)

Example 15 with MappingAddress

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

the class LispNatAddressCodec method decode.

@Override
public LispNatAddress decode(ObjectNode json, CodecContext context) {
    if (json == null || !json.isObject()) {
        return null;
    }
    final JsonCodec<MappingAddress> addressCodec = context.codec(MappingAddress.class);
    short msUdpPortNumber = (short) json.get(MS_UDP_PORT_NUMBER).asInt();
    short etrUdpPortNumber = (short) json.get(ETR_UDP_PORT_NUMBER).asInt();
    ObjectNode globalEtrRlocJson = get(json, GLOBAL_ETR_RLOC_ADDRESS);
    ObjectNode msRlocJson = get(json, MS_RLOC_ADDRESS);
    ObjectNode privateEtrRlocJson = get(json, PRIVATE_ETR_RLOC_ADDRESS);
    JsonNode rtrRlocJson = json.get(RTR_RLOC_ADDRESSES);
    MappingAddress globalEtrRlocAddress = null;
    MappingAddress msRlocAddress = null;
    MappingAddress privateEtrRlocAddress = null;
    List<MappingAddress> rtrRlocAddresses = Lists.newArrayList();
    if (globalEtrRlocJson != null) {
        globalEtrRlocAddress = addressCodec.decode(globalEtrRlocJson, context);
    }
    if (msRlocJson != null) {
        msRlocAddress = addressCodec.decode(msRlocJson, context);
    }
    if (privateEtrRlocJson != null) {
        privateEtrRlocAddress = addressCodec.decode(privateEtrRlocJson, context);
    }
    if (rtrRlocJson != null) {
        IntStream.range(0, rtrRlocJson.size()).forEach(i -> rtrRlocAddresses.add(addressCodec.decode(get(rtrRlocJson, i), context)));
    }
    return new LispNatAddress.Builder().withMsUdpPortNumber(msUdpPortNumber).withEtrUdpPortNumber(etrUdpPortNumber).withGlobalEtrRlocAddress(globalEtrRlocAddress).withMsRlocAddress(msRlocAddress).withPrivateEtrRlocAddress(privateEtrRlocAddress).withRtrRlocAddresses(rtrRlocAddresses).build();
}
Also used : MappingAddress(org.onosproject.mapping.addresses.MappingAddress) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) LispNatAddress(org.onosproject.drivers.lisp.extensions.LispNatAddress) JsonNode(com.fasterxml.jackson.databind.JsonNode)

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