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