use of org.onosproject.drivers.lisp.extensions.LispTeAddress in project onos by opennetworkinglab.
the class LispTeAddressCodec method decode.
@Override
public LispTeAddress decode(ObjectNode json, CodecContext context) {
if (json == null || !json.isObject()) {
return null;
}
final JsonCodec<LispTeAddress.TeRecord> recordCodec = context.codec(LispTeAddress.TeRecord.class);
JsonNode recordsJson = nullIsIllegal(json.get(TE_RECORDS), TE_RECORDS + MISSING_MEMBER_MESSAGE);
List<LispTeAddress.TeRecord> records = Lists.newArrayList();
if (recordsJson != null) {
IntStream.range(0, recordsJson.size()).forEach(i -> records.add(recordCodec.decode(get(recordsJson, i), context)));
}
return new LispTeAddress.Builder().withTeRecords(records).build();
}
use of org.onosproject.drivers.lisp.extensions.LispTeAddress in project onos by opennetworkinglab.
the class LispTeAddressCodec method encode.
@Override
public ObjectNode encode(LispTeAddress address, CodecContext context) {
checkNotNull(address, "LispTeAddress cannot be null");
final ObjectNode result = context.mapper().createObjectNode();
final ArrayNode jsonRecords = result.putArray(TE_RECORDS);
final JsonCodec<LispTeAddress.TeRecord> recordCodec = context.codec(LispTeAddress.TeRecord.class);
for (final LispTeAddress.TeRecord record : address.getTeRecords()) {
jsonRecords.add(recordCodec.encode(record, context));
}
return result;
}
use of org.onosproject.drivers.lisp.extensions.LispTeAddress in project onos by opennetworkinglab.
the class LispTeAddressCodecTest method getLispTeAddress.
/**
* Reads in a LispTeAddress from the given resource and decodes it.
*
* @param resourceName resource to use to read the JSON for the rule
* @return decoded LispTeAddress
* @throws IOException if processing the resource fails
*/
private LispTeAddress getLispTeAddress(String resourceName) throws IOException {
InputStream jsonStream = LispTeAddressCodecTest.class.getResourceAsStream(resourceName);
JsonNode json = context.mapper().readTree(jsonStream);
assertThat("JSON string should not be null", json, notNullValue());
LispTeAddress teAddress = teAddressCodec.decode((ObjectNode) json, context);
assertThat("decoded address should not be null", teAddress, notNullValue());
return teAddress;
}
use of org.onosproject.drivers.lisp.extensions.LispTeAddress in project onos by opennetworkinglab.
the class LispTeAddressCodecTest method setUp.
/**
* Sets up for each test.
* Creates a context and fetches the LispTeAddress codec.
*/
@Before
public void setUp() {
CodecManager manager = new CodecManager();
registrator = new LispMappingExtensionCodecRegistrator();
registrator.codecService = manager;
registrator.activate();
context = new LispMappingExtensionCodecContextAdapter(registrator.codecService);
teAddressCodec = context.codec(LispTeAddress.class);
assertThat("Traffic Engineering address codec should not be null", teAddressCodec, notNullValue());
record1 = new LispTeAddress.TeRecord.Builder().withIsLookup(LOOKUP_1).withIsRlocProbe(RLOC_PROBE_1).withIsStrict(STRICT_1).withRtrRlocAddress(MappingAddresses.ipv4MappingAddress(IPV4_ADDRESS_1)).build();
record2 = new LispTeAddress.TeRecord.Builder().withIsLookup(LOOKUP_2).withIsRlocProbe(RLOC_PROBE_2).withIsStrict(STRICT_2).withRtrRlocAddress(MappingAddresses.ipv4MappingAddress(IPV4_ADDRESS_2)).build();
}
use of org.onosproject.drivers.lisp.extensions.LispTeAddress in project onos by opennetworkinglab.
the class LispTeAddressCodecTest method testLispTeAddressDecode.
/**
* Tests decoding of a LispTeAddress JSON object.
*/
@Test
public void testLispTeAddressDecode() throws IOException {
LispTeAddress address = getLispTeAddress("LispTeAddress.json");
new EqualsTester().addEqualityGroup(address.getTeRecords().get(0), record1).addEqualityGroup(address.getTeRecords().get(1), record2).testEquals();
}
Aggregations