Search in sources :

Example 11 with ObjectHeaderImpl

use of org.opendaylight.protocol.pcep.spi.ObjectHeaderImpl in project bgpcep by opendaylight.

the class PCEPObjectParserTest method testSvecObject.

@Test
public void testSvecObject() throws IOException, PCEPDeserializerException {
    final PCEPSvecObjectParser parser = new PCEPSvecObjectParser();
    ByteBuf result = Unpooled.wrappedBuffer(ByteArray.fileToBytes("src/test/resources/PCEPSvecObject2.bin"));
    final SvecBuilder builder = new SvecBuilder();
    builder.setProcessingRule(false);
    builder.setIgnore(false);
    builder.setLinkDiverse(false);
    builder.setNodeDiverse(false);
    builder.setSrlgDiverse(false);
    builder.setRequestsIds(Lists.newArrayList(new RequestId(0xFFL)));
    assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(false, false), result.slice(4, result.readableBytes() - 4)));
    ByteBuf buf = Unpooled.buffer();
    parser.serializeObject(builder.build(), buf);
    assertArrayEquals(result.array(), ByteArray.getAllBytes(buf));
    result = Unpooled.wrappedBuffer(ByteArray.fileToBytes("src/test/resources/PCEPSvecObject1_10ReqIDs.bin"));
    builder.setProcessingRule(true);
    builder.setLinkDiverse(true);
    builder.setSrlgDiverse(true);
    final List<RequestId> requestIDs = Lists.newArrayList();
    requestIDs.add(new RequestId(0xFFFFFFFFL));
    requestIDs.add(new RequestId(0x00000001L));
    requestIDs.add(new RequestId(0x01234567L));
    requestIDs.add(new RequestId(0x89ABCDEFL));
    requestIDs.add(new RequestId(0xFEDCBA98L));
    requestIDs.add(new RequestId(0x76543210L));
    requestIDs.add(new RequestId(0x15825266L));
    requestIDs.add(new RequestId(0x48120BBEL));
    requestIDs.add(new RequestId(0x25FB7E52L));
    requestIDs.add(new RequestId(0xB2F2546BL));
    builder.setRequestsIds(requestIDs);
    assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(true, false), result.slice(4, result.readableBytes() - 4)));
    buf = Unpooled.buffer();
    parser.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());
    }
    try {
        parser.parseObject(new ObjectHeaderImpl(true, true), Unpooled.EMPTY_BUFFER);
        fail();
    } catch (final IllegalArgumentException e) {
        assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
    }
}
Also used : RequestId(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.RequestId) ObjectHeaderImpl(org.opendaylight.protocol.pcep.spi.ObjectHeaderImpl) PCEPSvecObjectParser(org.opendaylight.protocol.pcep.parser.object.PCEPSvecObjectParser) SvecBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.svec.object.SvecBuilder) ByteBuf(io.netty.buffer.ByteBuf) Test(org.junit.Test)

Example 12 with ObjectHeaderImpl

use of org.opendaylight.protocol.pcep.spi.ObjectHeaderImpl in project bgpcep by opendaylight.

the class PCEPObjectParserTest method testPceIdIPv6Object.

@Test
public void testPceIdIPv6Object() throws PCEPDeserializerException {
    final byte[] pccIdReqBytes = { /* object header */
    0x19, 0x20, 0x00, 0x14, /* ipv6 header */
    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01 };
    final PCEPPceIdIPv6ObjectParser parser = new PCEPPceIdIPv6ObjectParser();
    final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pce.id.object.PceId pccIdReq = new PceIdBuilder().setIpAddress(new IpAddress(new Ipv6Address("::1"))).build();
    final ByteBuf result = Unpooled.wrappedBuffer(pccIdReqBytes);
    assertEquals(pccIdReq, parser.parseObject(new ObjectHeaderImpl(false, false), result.slice(4, result.readableBytes() - 4)));
    final ByteBuf buf = Unpooled.buffer(pccIdReqBytes.length);
    parser.serializeObject(pccIdReq, buf);
    assertArrayEquals(pccIdReqBytes, buf.array());
}
Also used : ObjectHeaderImpl(org.opendaylight.protocol.pcep.spi.ObjectHeaderImpl) PCEPPceIdIPv6ObjectParser(org.opendaylight.protocol.pcep.parser.object.PCEPPceIdIPv6ObjectParser) PceIdBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pce.id.object.PceIdBuilder) ByteBuf(io.netty.buffer.ByteBuf) IpAddress(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress) Ipv6Address(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv6Address) Subobject(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.exclude.route.object.xro.Subobject) Test(org.junit.Test)

Example 13 with ObjectHeaderImpl

use of org.opendaylight.protocol.pcep.spi.ObjectHeaderImpl in project bgpcep by opendaylight.

the class PCEPObjectParserTest method testClassTypeObject.

@Test
public void testClassTypeObject() throws PCEPDeserializerException {
    final PCEPClassTypeObjectParser parser = new PCEPClassTypeObjectParser();
    final ByteBuf result = Unpooled.wrappedBuffer(new byte[] { (byte) 0x16, (byte) 0x12, (byte) 0x00, (byte) 0x08, 0, 0, 0, (byte) 0x04 });
    final ClassTypeBuilder builder = new ClassTypeBuilder();
    builder.setProcessingRule(true);
    builder.setIgnore(false);
    builder.setClassType(new ClassType((short) 4));
    assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(true, false), result.slice(4, result.readableBytes() - 4)));
    final ByteBuf buf = Unpooled.buffer();
    parser.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());
    }
    try {
        parser.parseObject(new ObjectHeaderImpl(true, true), Unpooled.EMPTY_BUFFER);
        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) PCEPClassTypeObjectParser(org.opendaylight.protocol.pcep.parser.object.PCEPClassTypeObjectParser) ByteBuf(io.netty.buffer.ByteBuf) ClassTypeBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.classtype.object.ClassTypeBuilder) ClassType(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.ClassType) Test(org.junit.Test)

Example 14 with ObjectHeaderImpl

use of org.opendaylight.protocol.pcep.spi.ObjectHeaderImpl in project bgpcep by opendaylight.

the class PCEPObjectParserTest method testCloseObjectWithVendorInformationTlv.

@Test
public void testCloseObjectWithVendorInformationTlv() throws IOException, PCEPDeserializerException {
    final byte[] closeBytes = { 0x0f, 0x10, 0x00, 0x14, 0x00, 0x00, 0x00, 0x05, /* vendor-information TLV */
    0x00, 0x07, 0x00, 0x08, /* enterprise number */
    0x00, 0x00, 0x00, 0x00, /* enterprise specific information */
    0x00, 0x00, 0x00, 0x05 };
    final PCEPCloseObjectParser parser = new PCEPCloseObjectParser(this.tlvRegistry, this.viTlvRegistry);
    final ByteBuf result = Unpooled.wrappedBuffer(closeBytes);
    final TestEnterpriseSpecificInformation esInfo = new TestEnterpriseSpecificInformation(5);
    final VendorInformationTlv viTlv = new VendorInformationTlvBuilder().setEnterpriseNumber(new EnterpriseNumber(0L)).setEnterpriseSpecificInformation(esInfo).build();
    final CCloseBuilder builder = new CCloseBuilder();
    builder.setProcessingRule(false);
    builder.setIgnore(false);
    builder.setReason((short) 5);
    builder.setTlvs(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.close.object.c.close.TlvsBuilder().setVendorInformationTlv(Lists.newArrayList(viTlv)).build());
    assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(false, false), result.slice(4, result.readableBytes() - 4)));
    final ByteBuf buf = Unpooled.buffer();
    parser.serializeObject(builder.build(), buf);
    assertArrayEquals(result.array(), ByteArray.getAllBytes(buf));
}
Also used : ObjectHeaderImpl(org.opendaylight.protocol.pcep.spi.ObjectHeaderImpl) PCEPCloseObjectParser(org.opendaylight.protocol.pcep.parser.object.PCEPCloseObjectParser) CCloseBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.close.object.CCloseBuilder) ByteBuf(io.netty.buffer.ByteBuf) VendorInformationTlv(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.vendor.information.tlvs.VendorInformationTlv) TestEnterpriseSpecificInformation(org.opendaylight.protocol.pcep.impl.TestVendorInformationTlvParser.TestEnterpriseSpecificInformation) EnterpriseNumber(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.iana.rev130816.EnterpriseNumber) VendorInformationTlvBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.vendor.information.tlvs.VendorInformationTlvBuilder) Subobject(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.exclude.route.object.xro.Subobject) Test(org.junit.Test)

Example 15 with ObjectHeaderImpl

use of org.opendaylight.protocol.pcep.spi.ObjectHeaderImpl in project bgpcep by opendaylight.

the class PCEPObjectParserTest method testOpenObjectWOTLV.

@Test
public void testOpenObjectWOTLV() throws PCEPDeserializerException, IOException {
    final PCEPOpenObjectParser parser = new PCEPOpenObjectParser(this.tlvRegistry, this.viTlvRegistry);
    final ByteBuf result = Unpooled.wrappedBuffer(ByteArray.fileToBytes("src/test/resources/PCEPOpenObject1.bin"));
    final OpenBuilder builder = new OpenBuilder();
    builder.setProcessingRule(false);
    builder.setIgnore(false);
    builder.setVersion(new ProtocolVersion((short) 1));
    builder.setKeepalive((short) 30);
    builder.setDeadTimer((short) 120);
    builder.setSessionId((short) 1);
    builder.setTlvs(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.open.object.open.TlvsBuilder().build());
    assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(false, false), result.slice(4, result.readableBytes() - 4)));
    final ByteBuf buf = Unpooled.buffer();
    parser.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());
    }
    try {
        parser.parseObject(new ObjectHeaderImpl(true, true), Unpooled.EMPTY_BUFFER);
        fail();
    } catch (final IllegalArgumentException e) {
        assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
    }
}
Also used : OpenBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.open.object.OpenBuilder) ObjectHeaderImpl(org.opendaylight.protocol.pcep.spi.ObjectHeaderImpl) ByteBuf(io.netty.buffer.ByteBuf) ProtocolVersion(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.ProtocolVersion) TlvsBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcep.error.object.error.object.TlvsBuilder) PCEPOpenObjectParser(org.opendaylight.protocol.pcep.parser.object.PCEPOpenObjectParser) Subobject(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.exclude.route.object.xro.Subobject) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)49 ObjectHeaderImpl (org.opendaylight.protocol.pcep.spi.ObjectHeaderImpl)49 ByteBuf (io.netty.buffer.ByteBuf)46 Subobject (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.exclude.route.object.xro.Subobject)14 TlvsBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcep.error.object.error.object.TlvsBuilder)8 IpAddress (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress)6 UnknownObject (org.opendaylight.protocol.pcep.spi.UnknownObject)4 IpPrefix (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpPrefix)4 Ipv4Prefix (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Prefix)4 ObjectHeader (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.ObjectHeader)4 RequestId (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.RequestId)4 VendorInformationObject (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.vendor.information.objects.VendorInformationObject)4 AsNumber (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.AsNumber)3 Ipv4Address (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Address)3 Bandwidth (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.network.concepts.rev131125.Bandwidth)3 TlvsBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev171025.srp.object.srp.TlvsBuilder)3 SymbolicPathName (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev171025.symbolic.path.name.tlv.SymbolicPathName)3 SymbolicPathNameBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev171025.symbolic.path.name.tlv.SymbolicPathNameBuilder)3 ProtocolVersion (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.ProtocolVersion)3 SubobjectBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.exclude.route.object.xro.SubobjectBuilder)3