use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.unreach.destination.object.unreach.destination.obj.destination.Ipv4DestinationCase in project bgpcep by opendaylight.
the class PCEPUnreachDestinationSerializer method serializeObject.
@Override
public void serializeObject(final Object object, final ByteBuf buffer) {
Preconditions.checkArgument(object instanceof UnreachDestinationObj, "Wrong instance of PCEPObject. Passed %s. Needed UnreachDestinationObj.", object.getClass());
final UnreachDestinationObj uPObj = (UnreachDestinationObj) object;
final Destination destination = uPObj.getDestination();
final Boolean processing = object.getProcessingRule();
final Boolean ignore = object.getIgnore();
if (destination instanceof Ipv6DestinationCase) {
final Ipv6DestinationCase ipv6 = (Ipv6DestinationCase) destination;
PCEPIpv6UnreachDestinationParser.serializeObject(processing, ignore, ipv6, buffer);
} else if (destination instanceof Ipv4DestinationCase) {
final Ipv4DestinationCase ipv4 = (Ipv4DestinationCase) destination;
PCEPIpv4UnreachDestinationParser.serializeObject(processing, ignore, ipv4, buffer);
}
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.unreach.destination.object.unreach.destination.obj.destination.Ipv4DestinationCase in project bgpcep by opendaylight.
the class PCEPObjectParserTest method testPCEPIpv4UnreachDestinationObject.
@Test
public void testPCEPIpv4UnreachDestinationObject() throws Exception {
final byte[] expected = { 0x1c, 0x10, 0x0, 0x8, (byte) 0x7F, (byte) 0x0, (byte) 0x0, (byte) 0x1 };
final PCEPIpv4UnreachDestinationParser parser = new PCEPIpv4UnreachDestinationParser();
final PCEPUnreachDestinationSerializer serializer = new PCEPUnreachDestinationSerializer();
final ByteBuf result = Unpooled.wrappedBuffer(expected);
final UnreachDestinationObjBuilder builder = new UnreachDestinationObjBuilder();
builder.setProcessingRule(false);
builder.setIgnore(false);
final Ipv4DestinationCase dest = new Ipv4DestinationCaseBuilder().setDestinationIpv4Address(Collections.singletonList(new Ipv4AddressNoZone("127.0.0.1"))).build();
builder.setDestination(dest);
assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(false, false), result.slice(4, result.readableBytes() - 4)));
final ByteBuf buf = Unpooled.buffer();
serializer.serializeObject(builder.build(), buf);
assertArrayEquals(result.array(), ByteArray.getAllBytes(buf));
try {
parser.parseObject(new ObjectHeaderImpl(true, true), null);
fail();
} catch (final IllegalArgumentException e) {
assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
}
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.unreach.destination.object.unreach.destination.obj.destination.Ipv4DestinationCase in project bgpcep by opendaylight.
the class PCEPIpv4UnreachDestinationParser method serializeObject.
public static void serializeObject(final Boolean processing, final Boolean ignore, final Ipv4DestinationCase ipv4Case, final ByteBuf buffer) {
final List<Ipv4AddressNoZone> dest = ipv4Case.getDestinationIpv4Address();
checkArgument(dest != null, "DestinationIpv4Address is mandatory.");
final ByteBuf body = Unpooled.buffer(Ipv4Util.IP4_LENGTH * dest.size());
dest.forEach(ipv4 -> Ipv4Util.writeIpv4Address(ipv4, body));
ObjectUtil.formatSubobject(TYPE, CLASS, processing, ignore, body, buffer);
}
Aggregations