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;
}
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)));
}
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();
}
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));
}
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());
}
Aggregations