Search in sources :

Example 1 with Ipv6DestinationCase

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.unreach.destination.object.unreach.destination.obj.destination.Ipv6DestinationCase 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);
    }
}
Also used : Destination(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.unreach.destination.object.unreach.destination.obj.Destination) Ipv6DestinationCase(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.unreach.destination.object.unreach.destination.obj.destination.Ipv6DestinationCase) Ipv4DestinationCase(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.unreach.destination.object.unreach.destination.obj.destination.Ipv4DestinationCase) UnreachDestinationObj(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.unreach.destination.object.UnreachDestinationObj)

Example 2 with Ipv6DestinationCase

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.unreach.destination.object.unreach.destination.obj.destination.Ipv6DestinationCase in project bgpcep by opendaylight.

the class PCEPIpv6UnreachDestinationParser method serializeObject.

public static void serializeObject(final Boolean processing, final Boolean ignore, final Ipv6DestinationCase ipv6Case, final ByteBuf buffer) {
    final List<Ipv6AddressNoZone> dest = ipv6Case.getDestinationIpv6Address();
    checkArgument(dest != null, "Destinationipv6Address is mandatory.");
    final ByteBuf body = Unpooled.buffer(Ipv6Util.IPV6_LENGTH * dest.size());
    dest.forEach(ipv6 -> Ipv6Util.writeIpv6Address(ipv6, body));
    ObjectUtil.formatSubobject(TYPE, CLASS, processing, ignore, body, buffer);
}
Also used : ByteBuf(io.netty.buffer.ByteBuf) Ipv6AddressNoZone(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv6AddressNoZone)

Example 3 with Ipv6DestinationCase

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.unreach.destination.object.unreach.destination.obj.destination.Ipv6DestinationCase in project bgpcep by opendaylight.

the class PCEPObjectParserTest method testPCEPIpv6UnreachDestinationObject.

@Test
public void testPCEPIpv6UnreachDestinationObject() throws Exception {
    final byte[] expected = { 0x1c, 0x20, 0x0, 0x14, (byte) 0x0, (byte) 0x0, (byte) 0x0, (byte) 0x0, (byte) 0x0, (byte) 0x0, (byte) 0x0, (byte) 0x0, (byte) 0x0, (byte) 0x0, (byte) 0x0, (byte) 0x0, (byte) 0x0, (byte) 0x0, (byte) 0x0, (byte) 0x1 };
    final PCEPIpv6UnreachDestinationParser parser = new PCEPIpv6UnreachDestinationParser();
    final PCEPUnreachDestinationSerializer serializer = new PCEPUnreachDestinationSerializer();
    final ByteBuf result = Unpooled.wrappedBuffer(expected);
    final UnreachDestinationObjBuilder builder = new UnreachDestinationObjBuilder();
    builder.setProcessingRule(false);
    builder.setIgnore(false);
    final Ipv6DestinationCase dest = new Ipv6DestinationCaseBuilder().setDestinationIpv6Address(Collections.singletonList(new Ipv6AddressNoZone("::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());
    }
}
Also used : Ipv6DestinationCase(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.unreach.destination.object.unreach.destination.obj.destination.Ipv6DestinationCase) ObjectHeaderImpl(org.opendaylight.protocol.pcep.spi.ObjectHeaderImpl) PCEPUnreachDestinationSerializer(org.opendaylight.protocol.pcep.parser.object.unreach.PCEPUnreachDestinationSerializer) Ipv6DestinationCaseBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.unreach.destination.object.unreach.destination.obj.destination.Ipv6DestinationCaseBuilder) PCEPIpv6UnreachDestinationParser(org.opendaylight.protocol.pcep.parser.object.unreach.PCEPIpv6UnreachDestinationParser) ByteBuf(io.netty.buffer.ByteBuf) UnreachDestinationObjBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.unreach.destination.object.UnreachDestinationObjBuilder) Ipv6AddressNoZone(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv6AddressNoZone) Test(org.junit.Test)

Aggregations

ByteBuf (io.netty.buffer.ByteBuf)2 Ipv6AddressNoZone (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv6AddressNoZone)2 Ipv6DestinationCase (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.unreach.destination.object.unreach.destination.obj.destination.Ipv6DestinationCase)2 Test (org.junit.Test)1 PCEPIpv6UnreachDestinationParser (org.opendaylight.protocol.pcep.parser.object.unreach.PCEPIpv6UnreachDestinationParser)1 PCEPUnreachDestinationSerializer (org.opendaylight.protocol.pcep.parser.object.unreach.PCEPUnreachDestinationSerializer)1 ObjectHeaderImpl (org.opendaylight.protocol.pcep.spi.ObjectHeaderImpl)1 UnreachDestinationObj (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.unreach.destination.object.UnreachDestinationObj)1 UnreachDestinationObjBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.unreach.destination.object.UnreachDestinationObjBuilder)1 Destination (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.unreach.destination.object.unreach.destination.obj.Destination)1 Ipv4DestinationCase (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.unreach.destination.object.unreach.destination.obj.destination.Ipv4DestinationCase)1 Ipv6DestinationCaseBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.unreach.destination.object.unreach.destination.obj.destination.Ipv6DestinationCaseBuilder)1