Search in sources :

Example 1 with UnreachDestinationObjBuilder

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

the class PCEPIpv4UnreachDestinationParser method parseObject.

@Override
public UnreachDestinationObj parseObject(final ObjectHeader header, final ByteBuf bytes) throws PCEPDeserializerException {
    checkArgument(bytes != null && bytes.isReadable(), "Array of bytes is mandatory. Can't be null or empty.");
    final UnreachDestinationObjBuilder builder = new UnreachDestinationObjBuilder();
    if (bytes.readableBytes() % Ipv4Util.IP4_LENGTH != 0) {
        throw new PCEPDeserializerException("Wrong length of array of bytes.");
    }
    builder.setIgnore(header.getIgnore());
    builder.setProcessingRule(header.getProcessingRule());
    List<Ipv4AddressNoZone> dest = new ArrayList<>();
    while (bytes.isReadable()) {
        dest.add(Ipv4Util.addressForByteBuf(bytes));
    }
    builder.setDestination(new Ipv4DestinationCaseBuilder().setDestinationIpv4Address(dest).build());
    return builder.build();
}
Also used : Ipv4AddressNoZone(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4AddressNoZone) ArrayList(java.util.ArrayList) UnreachDestinationObjBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.unreach.destination.object.UnreachDestinationObjBuilder) PCEPDeserializerException(org.opendaylight.protocol.pcep.spi.PCEPDeserializerException) Ipv4DestinationCaseBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.unreach.destination.object.unreach.destination.obj.destination.Ipv4DestinationCaseBuilder)

Example 2 with UnreachDestinationObjBuilder

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.unreach.destination.object.UnreachDestinationObjBuilder 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)

Example 3 with UnreachDestinationObjBuilder

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.unreach.destination.object.UnreachDestinationObjBuilder 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());
    }
}
Also used : ObjectHeaderImpl(org.opendaylight.protocol.pcep.spi.ObjectHeaderImpl) PCEPIpv4UnreachDestinationParser(org.opendaylight.protocol.pcep.parser.object.unreach.PCEPIpv4UnreachDestinationParser) Ipv4AddressNoZone(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4AddressNoZone) PCEPUnreachDestinationSerializer(org.opendaylight.protocol.pcep.parser.object.unreach.PCEPUnreachDestinationSerializer) Ipv4DestinationCase(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.unreach.destination.object.unreach.destination.obj.destination.Ipv4DestinationCase) ByteBuf(io.netty.buffer.ByteBuf) UnreachDestinationObjBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.unreach.destination.object.UnreachDestinationObjBuilder) Ipv4DestinationCaseBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.unreach.destination.object.unreach.destination.obj.destination.Ipv4DestinationCaseBuilder) Test(org.junit.Test)

Example 4 with UnreachDestinationObjBuilder

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

the class PCEPIpv6UnreachDestinationParser method parseObject.

@Override
public UnreachDestinationObj parseObject(final ObjectHeader header, final ByteBuf bytes) throws PCEPDeserializerException {
    checkArgument(bytes != null && bytes.isReadable(), "Array of bytes is mandatory. Can't be null or empty.");
    final UnreachDestinationObjBuilder builder = new UnreachDestinationObjBuilder();
    if (bytes.readableBytes() % Ipv6Util.IPV6_LENGTH != 0) {
        throw new PCEPDeserializerException("Wrong length of array of bytes.");
    }
    builder.setIgnore(header.getIgnore());
    builder.setProcessingRule(header.getProcessingRule());
    List<Ipv6AddressNoZone> dest = new ArrayList<>();
    while (bytes.isReadable()) {
        dest.add(Ipv6Util.addressForByteBuf(bytes));
    }
    return builder.setDestination(new Ipv6DestinationCaseBuilder().setDestinationIpv6Address(dest).build()).build();
}
Also used : ArrayList(java.util.ArrayList) Ipv6DestinationCaseBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.unreach.destination.object.unreach.destination.obj.destination.Ipv6DestinationCaseBuilder) UnreachDestinationObjBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.unreach.destination.object.UnreachDestinationObjBuilder) PCEPDeserializerException(org.opendaylight.protocol.pcep.spi.PCEPDeserializerException) Ipv6AddressNoZone(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv6AddressNoZone)

Aggregations

UnreachDestinationObjBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.unreach.destination.object.UnreachDestinationObjBuilder)4 ByteBuf (io.netty.buffer.ByteBuf)2 ArrayList (java.util.ArrayList)2 Test (org.junit.Test)2 PCEPUnreachDestinationSerializer (org.opendaylight.protocol.pcep.parser.object.unreach.PCEPUnreachDestinationSerializer)2 ObjectHeaderImpl (org.opendaylight.protocol.pcep.spi.ObjectHeaderImpl)2 PCEPDeserializerException (org.opendaylight.protocol.pcep.spi.PCEPDeserializerException)2 Ipv4AddressNoZone (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4AddressNoZone)2 Ipv6AddressNoZone (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv6AddressNoZone)2 Ipv4DestinationCaseBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.unreach.destination.object.unreach.destination.obj.destination.Ipv4DestinationCaseBuilder)2 Ipv6DestinationCaseBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.unreach.destination.object.unreach.destination.obj.destination.Ipv6DestinationCaseBuilder)2 PCEPIpv4UnreachDestinationParser (org.opendaylight.protocol.pcep.parser.object.unreach.PCEPIpv4UnreachDestinationParser)1 PCEPIpv6UnreachDestinationParser (org.opendaylight.protocol.pcep.parser.object.unreach.PCEPIpv6UnreachDestinationParser)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 Ipv6DestinationCase (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.unreach.destination.object.unreach.destination.obj.destination.Ipv6DestinationCase)1