Search in sources :

Example 1 with LispListAddress

use of org.onosproject.drivers.lisp.extensions.LispListAddress in project onos by opennetworkinglab.

the class LispListAddressCodecTest method getLispListAddress.

/**
 * Reads in a LispListAddress from the given resource and decodes it.
 *
 * @param resourceName resource to use to read the JSON for the rule
 * @return decoded LispListAddress
 * @throws IOException if processing the resource fails
 */
private LispListAddress getLispListAddress(String resourceName) throws IOException {
    InputStream jsonStream = LispListAddressCodecTest.class.getResourceAsStream(resourceName);
    JsonNode json = context.mapper().readTree(jsonStream);
    assertThat("JSON string should not be null", json, notNullValue());
    LispListAddress listAddress = listAddressCodec.decode((ObjectNode) json, context);
    assertThat("decoded address should not be null", listAddress, notNullValue());
    return listAddress;
}
Also used : InputStream(java.io.InputStream) LispListAddress(org.onosproject.drivers.lisp.extensions.LispListAddress) JsonNode(com.fasterxml.jackson.databind.JsonNode)

Example 2 with LispListAddress

use of org.onosproject.drivers.lisp.extensions.LispListAddress in project onos by opennetworkinglab.

the class LispListAddressCodecTest method testLispListAddressDecode.

/**
 * Tests decoding of a LispListAddress JSON object.
 */
@Test
public void testLispListAddressDecode() throws IOException {
    LispListAddress address = getLispListAddress("LispListAddress.json");
    assertThat("incorrect IPv4 address", address.getIpv4(), is(MappingAddresses.ipv4MappingAddress(IPV4_PREFIX)));
    assertThat("incorrect IPv6 address", address.getIpv6(), is(MappingAddresses.ipv6MappingAddress(IPV6_PREFIX)));
}
Also used : LispListAddress(org.onosproject.drivers.lisp.extensions.LispListAddress) Test(org.junit.Test)

Example 3 with LispListAddress

use of org.onosproject.drivers.lisp.extensions.LispListAddress 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 4 with LispListAddress

use of org.onosproject.drivers.lisp.extensions.LispListAddress in project onos by opennetworkinglab.

the class LispListAddressCodecTest method testLispListAddressEncode.

/**
 * Tests encoding of a LispListAddress object.
 */
@Test
public void testLispListAddressEncode() {
    LispListAddress address = new LispListAddress.Builder().withIpv4(MappingAddresses.ipv4MappingAddress(IPV4_PREFIX)).withIpv6(MappingAddresses.ipv6MappingAddress(IPV6_PREFIX)).build();
    ObjectNode addressJson = listAddressCodec.encode(address, context);
    assertThat("errors in encoding List address JSON", addressJson, LispListAddressJsonMatcher.matchesListAddress(address));
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) LispListAddress(org.onosproject.drivers.lisp.extensions.LispListAddress) Test(org.junit.Test)

Example 5 with LispListAddress

use of org.onosproject.drivers.lisp.extensions.LispListAddress in project onos by opennetworkinglab.

the class LispListAddressCodecTest method setUp.

/**
 * Sets up for each test.
 * Creates a context and fetches the LispListAddress codec.
 */
@Before
public void setUp() {
    CodecManager manager = new CodecManager();
    registrator = new LispMappingExtensionCodecRegistrator();
    registrator.codecService = manager;
    registrator.activate();
    context = new LispMappingExtensionCodecContextAdapter(registrator.codecService);
    listAddressCodec = context.codec(LispListAddress.class);
    assertThat("List address codec should not be null", listAddressCodec, notNullValue());
}
Also used : LispListAddress(org.onosproject.drivers.lisp.extensions.LispListAddress) CodecManager(org.onosproject.codec.impl.CodecManager) LispMappingExtensionCodecRegistrator(org.onosproject.drivers.lisp.extensions.LispMappingExtensionCodecRegistrator) Before(org.junit.Before)

Aggregations

LispListAddress (org.onosproject.drivers.lisp.extensions.LispListAddress)5 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)2 Test (org.junit.Test)2 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 InputStream (java.io.InputStream)1 Before (org.junit.Before)1 CodecManager (org.onosproject.codec.impl.CodecManager)1 LispMappingExtensionCodecRegistrator (org.onosproject.drivers.lisp.extensions.LispMappingExtensionCodecRegistrator)1 MappingAddress (org.onosproject.mapping.addresses.MappingAddress)1