Search in sources :

Example 1 with LispNonceAddress

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

the class LispNonceAddressCodecTest method setUp.

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

Example 2 with LispNonceAddress

use of org.onosproject.drivers.lisp.extensions.LispNonceAddress 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)

Example 3 with LispNonceAddress

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

the class LispNonceAddressCodecTest method testLispNonceAddressEncode.

/**
 * Tests encoding of a LispNonceAddress object.
 */
@Test
public void testLispNonceAddressEncode() {
    LispNonceAddress address = new LispNonceAddress.Builder().withNonce(NONCE).withAddress(MappingAddresses.ipv4MappingAddress(ADDRESS)).build();
    ObjectNode addressJson = nonceAddressCodec.encode(address, context);
    assertThat("errors in encoding nonce address JSON", addressJson, LispNonceAddressJsonMatcher.matchesNonceAddress(address));
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) LispNonceAddress(org.onosproject.drivers.lisp.extensions.LispNonceAddress) Test(org.junit.Test)

Example 4 with LispNonceAddress

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

the class LispNonceAddressCodecTest method getLispNonceAddress.

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

Example 5 with LispNonceAddress

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

the class LispNonceAddressCodecTest method testLispNonceAddressDecode.

/**
 * Tests decoding of a LispNonceAddress JSON object.
 */
@Test
public void testLispNonceAddressDecode() throws IOException {
    LispNonceAddress address = getLispNonceAddress("LispNonceAddress.json");
    assertThat("incorrect nonce", address.getNonce(), is(NONCE));
    assertThat("incorrect address", address.getAddress(), is(MappingAddresses.ipv4MappingAddress(ADDRESS)));
}
Also used : LispNonceAddress(org.onosproject.drivers.lisp.extensions.LispNonceAddress) Test(org.junit.Test)

Aggregations

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