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.impl.PCEPValidatorTest.java

License:Open Source License

@Test
public void testErrorMsg() throws IOException, PCEPDeserializerException {
    ByteBuf result = Unpooled.wrappedBuffer(ByteArray.fileToBytes("src/test/resources/PCErr.5.bin"));

    ErrorObject error1 = new ErrorObjectBuilder().setIgnore(false).setProcessingRule(false).setType((short) 3)
            .setValue((short) 1).build();

    final PCEPErrorMessageParser parser = new PCEPErrorMessageParser(this.ctx.getObjectHandlerRegistry());

    List<Errors> innerErr = new ArrayList<>();

    final PcerrMessageBuilder builder = new PcerrMessageBuilder();

    final List<org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcerr.message.pcerr.message.error.type.request._case.request.Rps> rps = Lists
            .newArrayList();//from w  ww.j  a v a  2s  . c o  m
    rps.add(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcerr.message.pcerr.message.error.type.request._case.request.RpsBuilder()
            .setRp(this.rpFalse).build());

    innerErr.add(new ErrorsBuilder().setErrorObject(error1).build());

    builder.setErrors(innerErr);
    builder.setErrorType(new RequestCaseBuilder().setRequest(new RequestBuilder().setRps(rps).build()).build());

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

    result = Unpooled.wrappedBuffer(ByteArray.fileToBytes("src/test/resources/PCErr.3.bin"));

    error1 = new ErrorObjectBuilder().setIgnore(false).setProcessingRule(false).setType((short) 3)
            .setValue((short) 1).build();

    innerErr = new ArrayList<>();
    innerErr.add(new ErrorsBuilder().setErrorObject(error1).build());

    builder.setErrors(innerErr);
    builder.setErrorType(
            new SessionCaseBuilder().setSession(new SessionBuilder().setOpen(this.open).build()).build());

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

    try {
        parser.serializeMessage(new PcerrBuilder().setPcerrMessage(new PcerrMessageBuilder().build()).build(),
                null);
        fail();
    } catch (final IllegalArgumentException e) {
        assertEquals("Errors should not be empty.", e.getMessage());
    }
    try {
        parser.serializeMessage(new PcerrBuilder()
                .setPcerrMessage(new PcerrMessageBuilder().setErrors(Collections.<Errors>emptyList()).build())
                .build(), null);
        fail();
    } catch (final IllegalArgumentException e) {
        assertEquals("Errors should not be empty.", e.getMessage());
    }
}

From source file:org.opendaylight.protocol.pcep.impl.PCEPValidatorTest.java

License:Open Source License

@Test
public void testReqMsgWithVendorInfoObjects() throws IOException, PCEPDeserializerException {
    final ByteBuf result = Unpooled.wrappedBuffer(ByteArray.fileToBytes("src/test/resources/PCReq.7.bin"));
    final PCEPRequestMessageParser parser = new PCEPRequestMessageParser(this.objectRegistry);

    final PcreqMessageBuilder builder = new PcreqMessageBuilder();
    final List<org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcreq.message.pcreq.message.Requests> reqs1 = Lists
            .newArrayList();/* ww  w  .ja  v  a2 s  . c o m*/
    final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcreq.message.pcreq.message.RequestsBuilder rBuilder = new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcreq.message.pcreq.message.RequestsBuilder();
    rBuilder.setRp(this.rpTrue);
    rBuilder.setVendorInformationObject(this.viObjects);
    final SegmentComputationBuilder sBuilder = new SegmentComputationBuilder();
    sBuilder.setP2p(new P2pBuilder().setEndpointsObj(this.endpoints).setVendorInformationObject(this.viObjects)
            .build());
    rBuilder.setSegmentComputation(sBuilder.build());
    reqs1.add(rBuilder.build());
    builder.setSvec(Lists.newArrayList(
            new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcreq.message.pcreq.message.SvecBuilder()
                    .setSvec(this.svec).setVendorInformationObject(this.viObjects).build()));
    builder.setRequests(reqs1);

    assertEquals(new PcreqBuilder().setPcreqMessage(builder.build()).build(),
            parser.parseMessage(result.slice(4, result.readableBytes() - 4), Collections.<Message>emptyList()));
    final ByteBuf buf = Unpooled.buffer(result.readableBytes());
    parser.serializeMessage(new PcreqBuilder().setPcreqMessage(builder.build()).build(), buf);

    assertArrayEquals(result.array(), buf.array());
}

From source file:org.opendaylight.protocol.pcep.impl.PCEPValidatorTest.java

License:Open Source License

@Test
public void testRepMsgWithVendorInforObjects() throws IOException, PCEPDeserializerException {
    final PCEPReplyMessageParser parser = new PCEPReplyMessageParser(this.objectRegistry);

    final PcrepMessageBuilder builder = new PcrepMessageBuilder();
    RepliesBuilder rBuilder = new RepliesBuilder();
    final ByteBuf result = Unpooled.wrappedBuffer(ByteArray.fileToBytes("src/test/resources/PCRep.6.bin"));
    final List<Replies> replies = Lists.newArrayList();
    rBuilder = new RepliesBuilder();
    rBuilder.setRp(this.rpTrue);
    rBuilder.setVendorInformationObject(this.viObjects);
    final List<Paths> paths = Lists.newArrayList();
    final PathsBuilder paBuilder = new PathsBuilder();
    paBuilder.setEro(this.ero);
    paths.add(paBuilder.build());// w ww. j ava  2s. com
    rBuilder.setResult(new SuccessCaseBuilder()
            .setSuccess(new SuccessBuilder().setPaths(paths).setVendorInformationObject(this.viObjects).build())
            .build()).build();
    replies.add(rBuilder.build());
    builder.setReplies(replies);

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

From source file:org.opendaylight.protocol.pcep.impl.PCEPValidatorTest.java

License:Open Source License

@Test
public void testMonRepMsg() throws PCEPDeserializerException, IOException {
    final PCEPMonitoringReplyMessageParser parser = new PCEPMonitoringReplyMessageParser(this.objectRegistry);
    final PcmonrepMessageBuilder builder = new PcmonrepMessageBuilder();
    builder.setMonitoring(this.monitoring);
    builder.setMonitoringMetricsList(new GeneralMetricsListBuilder()
            .setMetricPce(Lists.newArrayList(new MetricPceBuilder().setPceId(this.pceId).build())).build());

    final byte[] msgBytes = { 0x20, 0x09, 0x00, 0x18,
            /* monitoring object */
            0x13, 0x10, 0x00, 0x0C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x64,
            /* pce-id object */
            0x19, 0x10, 0x00, 0x08, 0x7f, 0x00, 0x00, 0x02 };

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

    builder.setMonitoring(this.monitoring);
    builder.setPccIdReq(this.pccIdReq);
    final SpecificMetricsBuilder smBuilder = new SpecificMetricsBuilder();
    smBuilder.setRp(this.rpTrue);
    final List<MetricPce> metricPces = Lists.newArrayList();
    metricPces.add(new MetricPceBuilder().setOverload(this.overload).setPceId(this.pceId)
            .setProcTime(this.procTime).build());
    metricPces.add(new MetricPceBuilder().setPceId(this.pceId).setProcTime(this.procTime).build());
    smBuilder.setMetricPce(metricPces);/*  w  w w .ja  v a 2s. co  m*/
    final SpecificMetricsBuilder smBuilder2 = new SpecificMetricsBuilder();
    final List<MetricPce> metricPces2 = Lists.newArrayList();
    smBuilder2.setRp(this.rpTrue);
    metricPces2.add(new MetricPceBuilder().setOverload(this.overload).setPceId(this.pceId).build());
    smBuilder2.setMetricPce(metricPces2);
    builder.setMonitoringMetricsList(new SpecificMetricsListBuilder()
            .setSpecificMetrics(Lists.newArrayList(smBuilder.build(), smBuilder2.build())).build());

    result = Unpooled.wrappedBuffer(ByteArray.fileToBytes("src/test/resources/PCMonRep.bin"));
    assertEquals(new PcmonrepBuilder().setPcmonrepMessage(builder.build()).build(),
            parser.parseMessage(result.slice(4, result.readableBytes() - 4), Collections.<Message>emptyList()));
    buf = Unpooled.buffer(result.readableBytes());
    parser.serializeMessage(new PcmonrepBuilder().setPcmonrepMessage(builder.build()).build(), buf);
    assertArrayEquals(result.array(), buf.array());
}

From source file:org.opendaylight.protocol.pcep.impl.PCEPValidatorTest.java

License:Open Source License

@Test
public void testRepWithMonitoring() throws IOException, PCEPDeserializerException {
    final PCEPReplyMessageParser parser = new PCEPReplyMessageParser(this.objectRegistry);

    final PcrepMessageBuilder builder = new PcrepMessageBuilder();
    RepliesBuilder rBuilder = new RepliesBuilder();

    final ByteBuf result = Unpooled.wrappedBuffer(ByteArray.fileToBytes("src/test/resources/PCRepMon.5.bin"));
    final List<Replies> replies4 = Lists.newArrayList();
    rBuilder = new RepliesBuilder();
    rBuilder.setRp(this.rpTrue);
    rBuilder.setMonitoring(this.monitoring);
    rBuilder.setPccIdReq(pccIdReq);//from  ww w. j a v a2 s  .  c  o m
    rBuilder.setMetricPce(Lists.newArrayList(new MetricPceBuilder().setPceId(this.pceId).build()));
    final List<Paths> paths = Lists.newArrayList();
    final PathsBuilder paBuilder = new PathsBuilder();
    paBuilder.setEro(this.ero);
    paBuilder.setLspa(this.lspa);
    paBuilder.setMetrics(Lists.newArrayList(this.metrics));
    paBuilder.setIro(this.iro);
    paBuilder.setOf(this.of);
    paths.add(paBuilder.build());
    rBuilder.setResult(
            new SuccessCaseBuilder().setSuccess(new SuccessBuilder().setPaths(paths).build()).build()).build();
    replies4.add(rBuilder.build());
    builder.setReplies(replies4);

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

From source file:org.opendaylight.protocol.pcep.impl.PCEPValidatorTest.java

License:Open Source License

@Test
public void testReqWithMonitoring() throws IOException, PCEPDeserializerException {
    final ByteBuf result = Unpooled.wrappedBuffer(ByteArray.fileToBytes("src/test/resources/PCReq.8.bin"));

    final PCEPRequestMessageParser parser = new PCEPRequestMessageParser(this.objectRegistry);

    final PcreqMessageBuilder builder = new PcreqMessageBuilder();
    final List<org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcreq.message.pcreq.message.Requests> reqs1 = Lists
            .newArrayList();/*from   w w w  .j  a  v a 2s  .co m*/
    final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcreq.message.pcreq.message.RequestsBuilder rBuilder = new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcreq.message.pcreq.message.RequestsBuilder();
    rBuilder.setRp(this.rpTrue);
    rBuilder.setSegmentComputation(new SegmentComputationBuilder()
            .setP2p(new P2pBuilder().setEndpointsObj(this.endpoints).build()).build());
    reqs1.add(rBuilder.build());
    final MonitoringRequestBuilder monReqBuilder = new MonitoringRequestBuilder();
    monReqBuilder.setMonitoring(this.monitoring);
    monReqBuilder.setPccIdReq(this.pccIdReq);
    monReqBuilder.setPceIdList(Lists.newArrayList(new PceIdListBuilder().setPceId(this.pceId).build()));
    builder.setMonitoringRequest(monReqBuilder.build());
    builder.setRequests(reqs1);

    assertEquals(new PcreqBuilder().setPcreqMessage(builder.build()).build(),
            parser.parseMessage(result.slice(4, result.readableBytes() - 4), Collections.<Message>emptyList()));
    final ByteBuf buf = Unpooled.buffer(result.readableBytes());
    parser.serializeMessage(new PcreqBuilder().setPcreqMessage(builder.build()).build(), buf);

    assertArrayEquals(result.array(), buf.array());
}

From source file:org.opendaylight.protocol.pcep.impl.PCEPValidatorTest.java

License:Open Source License

@Test
public void testMonReqMsg() throws PCEPDeserializerException, IOException {
    final PCEPMonitoringRequestMessageParser parser = new PCEPMonitoringRequestMessageParser(
            this.objectRegistry);

    final PcreqMessageBuilder builder = new PcreqMessageBuilder();
    final MonitoringRequestBuilder monReqBuilder = new MonitoringRequestBuilder();
    monReqBuilder.setMonitoring(this.monitoring);
    monReqBuilder.setPceIdList(Lists.newArrayList(new PceIdListBuilder().setPceId(this.pceId).build()));
    builder.setMonitoringRequest(monReqBuilder.build());
    final byte[] msgBytes = { 0x20, 0x08, 0x00, 0x18,
            /* monitoring object */
            0x13, 0x10, 0x00, 0x0C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x64,
            /* pce-id object */
            0x19, 0x10, 0x00, 0x08, 0x7f, 0x00, 0x00, 0x02 };
    ByteBuf result = Unpooled.wrappedBuffer(msgBytes);
    assertEquals(new PcmonreqBuilder().setPcreqMessage(builder.build()).build(),
            parser.parseMessage(result.slice(4, result.readableBytes() - 4), Collections.<Message>emptyList()));
    ByteBuf buf = Unpooled.buffer(result.readableBytes());
    parser.serializeMessage(new PcmonreqBuilder().setPcreqMessage(builder.build()).build(), buf);
    assertArrayEquals(result.array(), buf.array());

    result = Unpooled.wrappedBuffer(ByteArray.fileToBytes("src/test/resources/PCMonReq.bin"));
    final List<org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcreq.message.pcreq.message.Requests> reqs2 = Lists
            .newArrayList();/*from  w  w  w .j  av  a  2s  .c o m*/
    final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcreq.message.pcreq.message.RequestsBuilder rBuilder1 = new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcreq.message.pcreq.message.RequestsBuilder();
    rBuilder1.setRp(this.rpTrue);
    final P2pBuilder p2pBuilder = new P2pBuilder();
    p2pBuilder.setEndpointsObj(this.endpoints);
    p2pBuilder.setMetrics(Lists.newArrayList(this.metrics));
    p2pBuilder.setIro(this.iro);
    rBuilder1.setSegmentComputation(new SegmentComputationBuilder().setP2p(p2pBuilder.build()).build());
    reqs2.add(rBuilder1.build());
    builder.setRequests(reqs2);
    builder.setSvec(Lists.newArrayList(
            new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcreq.message.pcreq.message.SvecBuilder()
                    .setSvec(this.svec).build()));
    monReqBuilder.setMonitoring(this.monitoring);
    monReqBuilder.setPccIdReq(this.pccIdReq);
    final PceIdList pceIdList = new PceIdListBuilder().setPceId(this.pceId).build();
    monReqBuilder.setPceIdList(Lists.newArrayList(pceIdList, pceIdList));
    builder.setMonitoringRequest(monReqBuilder.build());

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

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

License:Open Source License

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

    final PceccLabelUpdateMessageParser parser = new PceccLabelUpdateMessageParser(
            this.ctx.getObjectHandlerRegistry());
    final PclabelupdMessageBuilder builder = new PclabelupdMessageBuilder();
    final List<PceLabelUpdates> updates = Lists.newArrayList();
    final List<Label> labelList = Lists.newArrayList();

    PceLabelDownloadCaseBuilder pceLabelDownloadCaseBuilder = new PceLabelDownloadCaseBuilder();
    PceLabelDownloadBuilder pceLabelDownload = new PceLabelDownloadBuilder();
    final FecBuilder fecBuilder = new FecBuilder();
    fecBuilder.setProcessingRule(false);
    fecBuilder.setIgnore(false);// w  w w.j av a2s .  c  o m
    fecBuilder.setFec(new Ipv4NodeIdCaseBuilder().setNodeId(new Ipv4Address("255.144.0.1")).build());

    org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.pcecc.rev160225.label.object.label.TlvsBuilder tlvBuilder = new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.pcecc.rev160225.label.object.label.TlvsBuilder();
    AddressBuilder addressBuilder = new AddressBuilder();
    Ipv4Builder ipv4 = new Ipv4Builder();
    ipv4.setIpv4Address(new Ipv4Address("1.1.1.1")).build();
    addressBuilder.setAddressFamily(new Ipv4CaseBuilder().setIpv4(ipv4.build()).build());

    final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.pcecc.rev160225.pce.label.update.pce.label.update.type.pce.label.download._case.pce.label.download.LabelBuilder labelBuilder = new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.pcecc.rev160225.pce.label.update.pce.label.update.type.pce.label.download._case.pce.label.download.LabelBuilder();
    final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.pcecc.rev160225.label.object.LabelBuilder label1 = new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.pcecc.rev160225.label.object.LabelBuilder();
    label1.setOutLabel(false);
    label1.setIgnore(false);
    label1.setProcessingRule(false);
    label1.setLabelNum(new LabelNumber(5001L));
    label1.setTlvs(tlvBuilder.setAddress(addressBuilder.build()).build());

    labelBuilder.setLabel(label1.build());

    org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.pcecc.rev160225.label.object.label.TlvsBuilder tlvBuilder1 = new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.pcecc.rev160225.label.object.label.TlvsBuilder();
    AddressBuilder addressBuilder1 = new AddressBuilder();
    Ipv4Builder ipv41 = new Ipv4Builder();
    ipv41.setIpv4Address(new Ipv4Address("14.10.1.29")).build();
    addressBuilder1.setAddressFamily(new Ipv4CaseBuilder().setIpv4(ipv41.build()).build());

    final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.pcecc.rev160225.pce.label.update.pce.label.update.type.pce.label.download._case.pce.label.download.LabelBuilder labelBuilder1 = new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.pcecc.rev160225.pce.label.update.pce.label.update.type.pce.label.download._case.pce.label.download.LabelBuilder();
    final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.pcecc.rev160225.label.object.LabelBuilder label2 = new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.pcecc.rev160225.label.object.LabelBuilder();
    label2.setOutLabel(true);
    label2.setIgnore(false);
    label2.setProcessingRule(false);
    label2.setLabelNum(new LabelNumber(5001L));
    label2.setTlvs(tlvBuilder1.setAddress(addressBuilder1.build()).build());

    labelBuilder1.setLabel(label2.build());

    labelList.add(labelBuilder.build());
    labelList.add(labelBuilder1.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());

    final LspBuilder lspBuilder = new LspBuilder();
    lspBuilder.setIgnore(false);
    lspBuilder.setProcessingRule(false);
    lspBuilder.setAdministrative(false);
    lspBuilder.setDelegate(false);
    lspBuilder.setPlspId(new PlspId(0L));
    lspBuilder.setOperational(OperationalStatus.Down);
    lspBuilder.setSync(false);
    lspBuilder.setRemove(false);
    lspBuilder.setTlvs(new TlvsBuilder().build());

    pceLabelDownload.setLabel(labelList).build();
    pceLabelDownload.setSrp(srpBuilder.build()).build();
    pceLabelDownload.setLsp(lspBuilder.build());
    pceLabelDownloadCaseBuilder.setPceLabelDownload(pceLabelDownload.build()).build();

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

    ByteBuf result = Unpooled.wrappedBuffer(PceccLabelDownloadWithMultiElementList);

    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.PceccLabelUpdateMessageParserTest.java

License:Open Source License

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

    final PceccLabelUpdateMessageParser parser = new PceccLabelUpdateMessageParser(
            this.ctx.getObjectHandlerRegistry());
    final PclabelupdMessageBuilder builder = new PclabelupdMessageBuilder();
    final List<PceLabelUpdates> updates = Lists.newArrayList();
    final List<Label> labelList = Lists.newArrayList();

    PceLabelDownloadCaseBuilder pceLabelDownloadCaseBuilder = new PceLabelDownloadCaseBuilder();
    PceLabelDownloadBuilder pceLabelDownload = new PceLabelDownloadBuilder();
    final FecBuilder fecBuilder = new FecBuilder();
    fecBuilder.setProcessingRule(false);
    fecBuilder.setIgnore(false);/*from  w w  w  . ja va 2 s.c o  m*/
    fecBuilder.setFec(new Ipv4NodeIdCaseBuilder().setNodeId(new Ipv4Address("255.144.0.1")).build());

    org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.pcecc.rev160225.label.object.label.TlvsBuilder tlvBuilder = new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.pcecc.rev160225.label.object.label.TlvsBuilder();
    AddressBuilder addressBuilder = new AddressBuilder();
    Ipv4Builder ipv4 = new Ipv4Builder();
    ipv4.setIpv4Address(new Ipv4Address("1.1.1.1")).build();
    addressBuilder.setAddressFamily(new Ipv4CaseBuilder().setIpv4(ipv4.build()).build());

    final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.pcecc.rev160225.pce.label.update.pce.label.update.type.pce.label.download._case.pce.label.download.LabelBuilder labelBuilder = new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.pcecc.rev160225.pce.label.update.pce.label.update.type.pce.label.download._case.pce.label.download.LabelBuilder();
    final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.pcecc.rev160225.label.object.LabelBuilder label1 = new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.pcecc.rev160225.label.object.LabelBuilder();
    label1.setOutLabel(false);
    label1.setIgnore(false);
    label1.setProcessingRule(false);
    label1.setLabelNum(new LabelNumber(5001L));
    label1.setTlvs(tlvBuilder.setAddress(addressBuilder.build()).build());

    labelBuilder.setLabel(label1.build());

    labelList.add(labelBuilder.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());

    final LspBuilder lspBuilder = new LspBuilder();
    lspBuilder.setIgnore(false);
    lspBuilder.setProcessingRule(false);
    lspBuilder.setAdministrative(false);
    lspBuilder.setDelegate(false);
    lspBuilder.setPlspId(new PlspId(0L));
    lspBuilder.setOperational(OperationalStatus.Down);
    lspBuilder.setSync(false);
    lspBuilder.setRemove(false);
    lspBuilder.setTlvs(new TlvsBuilder().build());

    pceLabelDownload.setLabel(labelList).build();
    pceLabelDownload.setSrp(srpBuilder.build()).build();
    pceLabelDownload.setLsp(lspBuilder.build());
    pceLabelDownloadCaseBuilder.setPceLabelDownload(pceLabelDownload.build()).build();

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

    ByteBuf result = Unpooled.wrappedBuffer(PceccLabelDownloadWithSingleElementList);

    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.PceccLabelUpdateMessageParserTest.java

License:Open Source License

@Test
public void testPceLabelMapWithAddressTlv() 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);//from  w  w  w .j ava2  s  .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);

    org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.pcecc.rev160225.label.object.label.TlvsBuilder tlvBuilder = new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.pcecc.rev160225.label.object.label.TlvsBuilder();
    AddressBuilder addressBuilder = new AddressBuilder();
    Ipv4Builder ipv4 = new Ipv4Builder();
    ipv4.setIpv4Address(new Ipv4Address("1.1.1.1")).build();
    addressBuilder.setAddressFamily(new Ipv4CaseBuilder().setIpv4(ipv4.build()).build());

    labelBuilder.setTlvs(tlvBuilder.setAddress(addressBuilder.build()).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(PceccLabelMapObjectWithAddressTlvBytes);

    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());

}