Search in sources :

Example 1 with LispAsAddress

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

the class LispAsAddressCodecTest method getLispAsAddress.

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

Example 2 with LispAsAddress

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

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

the class LispAsAddressCodecTest method testLispAsAddressEncode.

/**
 * Tests encoding of a LispAsAddress object.
 */
@Test
public void testLispAsAddressEncode() {
    LispAsAddress address = new LispAsAddress.Builder().withAsNumber(AS_NUMBER).withAddress(MappingAddresses.ipv4MappingAddress(IPV4_PREFIX)).build();
    ObjectNode addressJson = asAddressCodec.encode(address, context);
    assertThat("errors in encoding AS address JSON", addressJson, LispAsAddressJsonMatcher.matchesAsAddress(address));
}
Also used : LispAsAddress(org.onosproject.drivers.lisp.extensions.LispAsAddress) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) Test(org.junit.Test)

Example 4 with LispAsAddress

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

the class LispAsAddressCodecTest method setUp.

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

Example 5 with LispAsAddress

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

the class LispAsAddressCodecTest method testLispAsAddressDecode.

/**
 * Tests decoding of a LispAsAddress JSON object.
 */
@Test
public void testLispAsAddressDecode() throws IOException {
    LispAsAddress address = getLispAsAddress("LispAsAddress.json");
    assertThat("incorrect AS number", address.getAsNumber(), is(AS_NUMBER));
    assertThat("incorrect mapping address", address.getAddress(), is(MappingAddresses.ipv4MappingAddress(IPV4_PREFIX)));
}
Also used : LispAsAddress(org.onosproject.drivers.lisp.extensions.LispAsAddress) Test(org.junit.Test)

Aggregations

LispAsAddress (org.onosproject.drivers.lisp.extensions.LispAsAddress)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