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