Search in sources :

Example 1 with LispGcAddress

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

the class LispGcAddressCodec method decode.

@Override
public LispGcAddress decode(ObjectNode json, CodecContext context) {
    if (json == null || !json.isObject()) {
        return null;
    }
    boolean north = nullIsIllegal(json.get(NORTH), NORTH + MISSING_MEMBER_MESSAGE).asBoolean();
    short latitudeDegree = (short) nullIsIllegal(json.get(LATITUDE_DEGREE), LATITUDE_DEGREE + MISSING_MEMBER_MESSAGE).asInt();
    byte latitudeMinute = (byte) nullIsIllegal(json.get(LATITUDE_MINUTE), LATITUDE_MINUTE + MISSING_MEMBER_MESSAGE).asInt();
    byte latitudeSecond = (byte) nullIsIllegal(json.get(LATITUDE_SECOND), LATITUDE_SECOND + MISSING_MEMBER_MESSAGE).asInt();
    boolean east = nullIsIllegal(json.get(EAST), EAST + MISSING_MEMBER_MESSAGE).asBoolean();
    short longitudeDegree = (short) nullIsIllegal(json.get(LONGITUDE_DEGREE), LONGITUDE_DEGREE + MISSING_MEMBER_MESSAGE).asInt();
    byte longitudeMinute = (byte) nullIsIllegal(json.get(LONGITUDE_MINUTE), LONGITUDE_MINUTE + MISSING_MEMBER_MESSAGE).asInt();
    byte longitudeSecond = (byte) nullIsIllegal(json.get(LONGITUDE_SECOND), LONGITUDE_SECOND + MISSING_MEMBER_MESSAGE).asInt();
    int altitude = nullIsIllegal(json.get(ALTITUDE), ALTITUDE + 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 LispGcAddress.Builder().withIsNorth(north).withLatitudeDegree(latitudeDegree).withLatitudeMinute(latitudeMinute).withLatitudeSecond(latitudeSecond).withIsEast(east).withLongitudeDegree(longitudeDegree).withLongitudeMinute(longitudeMinute).withLongitudeSecond(longitudeSecond).withAltitude(altitude).withAddress(mappingAddress).build();
}
Also used : LispGcAddress(org.onosproject.drivers.lisp.extensions.LispGcAddress) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) MappingAddress(org.onosproject.mapping.addresses.MappingAddress)

Example 2 with LispGcAddress

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

the class LispGcAddressCodecTest method getLispGcAddress.

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

Example 3 with LispGcAddress

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

the class LispGcAddressCodecTest method testLispGcAddressDecode.

/**
 * Tests decoding of a LispGcAddress JSON object.
 */
@Test
public void testLispGcAddressDecode() throws IOException {
    LispGcAddress address = getLispGcAddress("LispGcAddress.json");
    assertThat("incorrect north", address.isNorth(), is(NORTH));
    assertThat("incorrect latitude degree", address.getLatitudeDegree(), is(LATITUDE_DEGREE));
    assertThat("incorrect latitude minute", address.getLatitudeMinute(), is(LATITUDE_MINUTE));
    assertThat("incorrect latitude second", address.getLatitudeSecond(), is(LATITUDE_SECOND));
    assertThat("incorrect east", address.isEast(), is(EAST));
    assertThat("incorrect longitude degree", address.getLongitudeDegree(), is(LONGITUDE_DEGREE));
    assertThat("incorrect longitude minute", address.getLongitudeMinute(), is(LONGITUDE_MINUTE));
    assertThat("incorrect longitude second", address.getLongitudeSecond(), is(LONGITUDE_SECOND));
    assertThat("incorrect altitude", address.getAltitude(), is(ALTITUDE));
    assertThat("incorrect mapping address", address.getAddress(), is(MappingAddresses.ipv4MappingAddress(IPV4_PREFIX)));
}
Also used : LispGcAddress(org.onosproject.drivers.lisp.extensions.LispGcAddress) Test(org.junit.Test)

Example 4 with LispGcAddress

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

the class LispGcAddressCodecTest method setUp.

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

Example 5 with LispGcAddress

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

the class LispGcAddressCodecTest method testLispGcAddressEncode.

/**
 * Tests encoding of a LispGcAddress object.
 */
@Test
public void testLispGcAddressEncode() {
    LispGcAddress address = new LispGcAddress.Builder().withIsNorth(NORTH).withLatitudeDegree(LATITUDE_DEGREE).withLatitudeMinute(LATITUDE_MINUTE).withLatitudeSecond(LATITUDE_SECOND).withIsEast(EAST).withLongitudeDegree(LONGITUDE_DEGREE).withLongitudeMinute(LONGITUDE_MINUTE).withLongitudeSecond(LONGITUDE_SECOND).withAltitude(ALTITUDE).withAddress(MappingAddresses.ipv4MappingAddress(IPV4_PREFIX)).build();
    ObjectNode addressJson = gcAddressCodec.encode(address, context);
    assertThat("errors in encoding Geo Coordinate address JSON", addressJson, LispGcAddressJsonMatcher.matchesGcAddress(address));
}
Also used : LispGcAddress(org.onosproject.drivers.lisp.extensions.LispGcAddress) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) Test(org.junit.Test)

Aggregations

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