Example usage for io.netty.buffer ByteBuf slice

List of usage examples for io.netty.buffer ByteBuf slice

Introduction

In this page you can find the example usage for io.netty.buffer ByteBuf slice.

Prototype

public abstract ByteBuf slice(int index, int length);

Source Link

Document

Returns a slice of this buffer's sub-region.

Usage

From source file:org.opendaylight.protocol.pcep.pcecc.PceccLabelUpdateMessageParserTest.java

License:Open Source License

@Test
public void testPceLabelMapWithoutAddressTlv() throws IOException, PCEPDeserializerException {

    final PceccLabelUpdateMessageParser parser = new PceccLabelUpdateMessageParser(
            this.ctx.getObjectHandlerRegistry());
    final PclabelupdMessageBuilder builder = new PclabelupdMessageBuilder();
    final List<PceLabelUpdates> updates = Lists.newArrayList();
    PceLabelMapCaseBuilder pceLabelMapCaseBuilder = new PceLabelMapCaseBuilder();
    PceLabelMapBuilder pceLabelMap = new PceLabelMapBuilder();
    final FecBuilder fecBuilder = new FecBuilder();
    fecBuilder.setProcessingRule(false);
    fecBuilder.setIgnore(false);/*  w  w w.ja va2s .  c o m*/
    fecBuilder.setFec(new Ipv4NodeIdCaseBuilder().setNodeId(new Ipv4Address("255.144.0.1")).build());

    final LabelBuilder labelBuilder = new LabelBuilder();
    labelBuilder.setProcessingRule(false);
    labelBuilder.setIgnore(false);
    labelBuilder.setLabelNum(new LabelNumber(5001L));
    labelBuilder.setOutLabel(false);
    labelBuilder.setTlvs(
            new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.pcecc.rev160225.label.object.label.TlvsBuilder()
                    .build());
    final SrpBuilder srpBuilder = new SrpBuilder();
    srpBuilder.setIgnore(false);
    srpBuilder.setProcessingRule(false);
    srpBuilder.setOperationId(new SrpIdNumber(1L));

    srpBuilder.setTlvs(
            new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev131222.srp.object.srp.TlvsBuilder()
                    .build());

    pceLabelMap.setFec(fecBuilder.build()).build();
    pceLabelMap.setLabel(labelBuilder.build()).build();
    pceLabelMap.setSrp(srpBuilder.build()).build();
    pceLabelMapCaseBuilder.setPceLabelMap(pceLabelMap.build()).build();

    updates.add(new PceLabelUpdatesBuilder().setPceLabelUpdateType(pceLabelMapCaseBuilder.build()).build());
    builder.setPceLabelUpdates(updates);

    ByteBuf result = Unpooled.wrappedBuffer(PceccLabelMapObjectWithoutAddressTlvBytes);

    assertEquals(new PclabelupdBuilder().setPclabelupdMessage(builder.build()).build(),
            parser.parseMessage(result.slice(4, result.readableBytes() - 4), Collections.<Message>emptyList()));
    ByteBuf buf = Unpooled.buffer(result.readableBytes());
    parser.serializeMessage(new PclabelupdBuilder().setPclabelupdMessage(builder.build()).build(), buf);
    assertArrayEquals(result.array(), buf.array());

}

From source file:org.opendaylight.protocol.pcep.pcecc.PceccNegativeScenarioTest.java

License:Open Source License

@Test
public void testPceccFecIpv4AdjacencyObjectParserHitLengthCheck() throws PCEPDeserializerException {
    try {//  ww w . ja  v  a  2s .c  om
        final PceccFecIpv4AdjacencyObjectParser parser = new PceccFecIpv4AdjacencyObjectParser();
        final ByteBuf result = Unpooled.wrappedBuffer(PceccFecAdjacencyObjectBytes);
        parser.parseObject(new ObjectHeaderImpl(false, false), result.slice(4, result.readableBytes() - 4));
        fail();
    } catch (final PCEPDeserializerException e) {
        assertTrue(e.getMessage().contains("Wrong length of array of bytes. Passed: 4; Expected: >=8."));
    }
}

From source file:org.opendaylight.protocol.pcep.pcecc.PceccNegativeScenarioTest.java

License:Open Source License

@Test
public void testPceccFecObjectParserHitLengthCheck() throws PCEPDeserializerException {
    try {/* w  w  w .  ja va 2  s.  c  o m*/
        final PceccFecObjectParser parser = new PceccFecObjectParser();
        final ByteBuf result = Unpooled.wrappedBuffer(PceccFecObjectBytes);
        parser.parseObject(new ObjectHeaderImpl(false, false), result.slice(4, result.readableBytes() - 4));
        fail();
    } catch (final PCEPDeserializerException e) {
        assertTrue(e.getMessage().contains("Wrong length of array of bytes. Passed: 2; Expected: >=4."));
    }
}

From source file:org.opendaylight.protocol.pcep.pcecc.PceccNegativeScenarioTest.java

License:Open Source License

@Test
public void testPceccFecIpv4ObjectParserHitLengthCheck() throws PCEPDeserializerException {
    try {//from   ww w.j a v  a  2s  . c  o  m
        final PceccFecIpv4ObjectParser parser = new PceccFecIpv4ObjectParser();
        final ByteBuf result = Unpooled.wrappedBuffer(PceccFecObjectBytes);
        parser.parseObject(new ObjectHeaderImpl(false, false), result.slice(4, result.readableBytes() - 4));
        fail();
    } catch (final PCEPDeserializerException e) {
        assertTrue(e.getMessage().contains("Wrong length of array of bytes. Passed: 2; Expected: >=4."));
    }
}

From source file:org.opendaylight.protocol.pcep.pcecc.PceccNegativeScenarioTest.java

License:Open Source License

@Test
public void testPceccLabelObjectParserHitLengthCheck() throws PCEPDeserializerException {
    try {//  w  w  w  . jav a2 s.c  o m
        final PceccLabelObjectParser parser = new PceccLabelObjectParser(this.tlvRegistry, this.viTlvRegistry);
        final ByteBuf result = Unpooled.wrappedBuffer(PceccLabelObjectBytes);
        parser.parseObject(new ObjectHeaderImpl(false, false), result.slice(4, result.readableBytes() - 4));
        fail();
    } catch (final PCEPDeserializerException e) {
        assertTrue(e.getMessage().contains("Wrong length of array of bytes. Passed: 4; Expected: >=8."));
    }
}

From source file:org.opendaylight.protocol.pcep.pcecc.PceccNegativeScenarioTest.java

License:Open Source License

@Test
public void testPcepOpenObjectWithLengthCheck() throws PCEPDeserializerException {
    try {/*from   w  w  w. ja va 2  s.co  m*/
        final PcepOpenObjectWithPceccTlvParser parser = new PcepOpenObjectWithPceccTlvParser(this.tlvRegistry,
                this.viTlvRegistry);
        final ByteBuf result = Unpooled.wrappedBuffer(openObjectBytes);
        parser.parseObject(new ObjectHeaderImpl(false, false), result.slice(4, result.readableBytes() - 4));
        fail();
    } catch (final PCEPDeserializerException e) {
        assertTrue(e.getMessage().contains("Wrong length of array of bytes. Passed: 2; Expected: >= 4."));
    }
}

From source file:org.opendaylight.protocol.pcep.pcecc.PceccNegativeScenarioTest.java

License:Open Source License

@Test
public void testPceccLabelUpdateMessageParser() throws IOException, PCEPDeserializerException {
    try {//from  ww  w.  j av a2s  .  c o  m
        final PceccLabelUpdateMessageParser parser = new PceccLabelUpdateMessageParser(
                this.ctx.getObjectHandlerRegistry());

        ByteBuf result = Unpooled.wrappedBuffer(PceccLabelTlvBytes);
        parser.parseMessage(result.slice(4, result.readableBytes() - 4), Collections.<Message>emptyList());

        fail();
    } catch (final PCEPDeserializerException e) {
        assertTrue(e.getMessage().contains("PcLabelUpt message cannot be empty."));
    }
}

From source file:org.opendaylight.protocol.pcep.pcecc.PceccNegativeScenarioTest.java

License:Open Source License

/**
 * testPceccLabelUpdateMessageParserError
 * Description :- Test Error condition when SRP object is missing in LabelUpdateMessage Object.
 * Srp Object missing//  w w  w.  j  av  a  2s. c  o m
 * error type SRP_MISSING(6, 10)
 */
@Test
public void testPceccLabelUpdateMessageParserError() throws IOException, PCEPDeserializerException {
    try (PceccActivator a = new PceccActivator()) {
        a.start(ctx);
        final PceccLabelUpdateMessageParser parser = new PceccLabelUpdateMessageParser(
                this.ctx.getObjectHandlerRegistry());

        ByteBuf result = Unpooled.wrappedBuffer(PceccLabelUpdateMessageParserError);
        final List<Message> errors = Lists.newArrayList();

        final PcerrMessageBuilder errMsgBuilder = new PcerrMessageBuilder();
        errMsgBuilder.setErrors(Lists.newArrayList(new ErrorsBuilder()
                .setErrorObject(new ErrorObjectBuilder().setType((short) 6).setValue((short) 10).build())
                .build()));
        final PcerrBuilder builder = new PcerrBuilder();
        builder.setPcerrMessage(errMsgBuilder.build());
        parser.parseMessage(result.slice(4, result.readableBytes() - 4), errors);
        assertFalse(errors.isEmpty());
        assertEquals(new PcerrBuilder().setPcerrMessage(errMsgBuilder.build()).build(), errors.get(0));
    }
}

From source file:org.opendaylight.protocol.pcep.pcecc.PceccObjectParserTest.java

License:Open Source License

@Test
public void testOpenObjectWithPceccTlv() throws PCEPDeserializerException {
    final PcepOpenObjectWithPceccTlvParser parser = new PcepOpenObjectWithPceccTlvParser(this.tlvRegistry,
            this.viTlvRegistry);

    final OpenBuilder builder = new OpenBuilder();
    builder.setProcessingRule(false);//from   ww  w . j  a  v  a  2  s  . c o  m
    builder.setIgnore(false);
    builder.setVersion(new ProtocolVersion((short) 1));
    builder.setKeepalive((short) 30);
    builder.setDeadTimer((short) 120);
    builder.setSessionId((short) 1);

    final Tlvs4Builder pceccTlv = new Tlvs4Builder();
    pceccTlv.setPceccCapability(new PceccCapabilityBuilder().setIldbBit(true).setSBit(true).build()).build();
    final Tlvs1Builder statBuilder = new Tlvs1Builder();
    final Tlvs3Builder syncOptBuilder = new Tlvs3Builder();
    builder.setTlvs(new TlvsBuilder().addAugmentation(Tlvs1.class, statBuilder.build())
            .addAugmentation(Tlvs3.class, syncOptBuilder.build()).addAugmentation(Tlvs4.class, pceccTlv.build())
            .build());

    final ByteBuf result = Unpooled.wrappedBuffer(openObjectBytes);
    assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(false, false),
            result.slice(4, result.readableBytes() - 4)));
    final ByteBuf buffer = Unpooled.buffer();
    parser.serializeObject(builder.build(), buffer);
    assertArrayEquals(openObjectBytes, ByteArray.getAllBytes(buffer));
}

From source file:org.opendaylight.protocol.pcep.pcecc.PceccObjectParserTest.java

License:Open Source License

@Test
public void testPceccLabelObjectParserWithoutAddressTlv() throws PCEPDeserializerException {
    final PceccLabelObjectParser parser = new PceccLabelObjectParser(this.tlvRegistry, this.viTlvRegistry);

    final LabelBuilder builder = new LabelBuilder();
    builder.setProcessingRule(false);/*  w ww.j a  va 2  s  . c o  m*/
    builder.setIgnore(false);
    builder.setLabelNum(new LabelNumber(5001L));
    builder.setOutLabel(true);
    builder.setTlvs(
            new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.pcecc.rev160225.label.object.label.TlvsBuilder()
                    .build());
    final ByteBuf result = Unpooled.wrappedBuffer(PceccLabelObjectBytes);
    assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(false, false),
            result.slice(4, result.readableBytes() - 4)));
    final ByteBuf buffer = Unpooled.buffer();
    parser.serializeObject(builder.build(), buffer);
    assertArrayEquals(PceccLabelObjectBytes, ByteArray.getAllBytes(buffer));
}