Example usage for io.netty.buffer ByteBuf array

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

Introduction

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

Prototype

public abstract byte[] array();

Source Link

Document

Returns the backing byte array of this buffer.

Usage

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

License:Open Source License

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

    final PCEPCloseMessageParser parser = new PCEPCloseMessageParser(this.objectRegistry);
    final CloseBuilder builder = new CloseBuilder().setCCloseMessage(
            new CCloseMessageBuilder().setCClose(new CCloseBuilder().setIgnore(false).setProcessingRule(false)
                    .setReason((short) 5).setTlvs(new TlvsBuilder().build()).build()).build());

    assertEquals(builder.build(),// w  w  w  . j a  v  a 2  s  .c o  m
            parser.parseMessage(result.slice(4, result.readableBytes() - 4), Collections.<Message>emptyList()));
    final ByteBuf buf = Unpooled.buffer(result.readableBytes());
    parser.serializeMessage(builder.build(), buf);
    assertArrayEquals(result.array(), buf.array());

    try {
        parser.serializeMessage(new CloseBuilder().setCCloseMessage(new CCloseMessageBuilder().build()).build(),
                null);
        fail();
    } catch (final IllegalArgumentException e) {
        assertEquals("Close Object must be present in Close Message.", e.getMessage());
    }
}

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

License:Open Source License

@Test
public void testRequestMsg() throws IOException, PCEPDeserializerException {
    ByteBuf result = Unpooled
            .wrappedBuffer(ByteArray.fileToBytes("src/test/resources/PCEPRequestMessage1.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. 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.setSegmentComputation(new SegmentComputationBuilder()
            .setP2p(new P2pBuilder().setEndpointsObj(this.endpoints).build()).build());
    reqs1.add(rBuilder.build());
    builder.setRequests(reqs1);

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

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

    result = Unpooled.wrappedBuffer(ByteArray.fileToBytes("src/test/resources/PCReq.3.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();
    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()));

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

    try {
        parser.serializeMessage(new PcreqBuilder().setPcreqMessage(new PcreqMessageBuilder().build()).build(),
                null);
        fail();
    } catch (final IllegalArgumentException e) {
        assertEquals("Requests cannot be null or empty.", e.getMessage());
    }
    try {
        parser.serializeMessage(new PcreqBuilder()
                .setPcreqMessage(
                        new PcreqMessageBuilder().setRequests(Collections.<Requests>emptyList()).build())
                .build(), null);
        fail();
    } catch (final IllegalArgumentException e) {
        assertEquals("Requests cannot be null or empty.", e.getMessage());
    }
}

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

License:Open Source License

@Test
public void testReplyMsg() throws IOException, PCEPDeserializerException {
    // only RP//ww w.  j av a 2s . com
    ByteBuf result = Unpooled.wrappedBuffer(ByteArray.fileToBytes("src/test/resources/PCRep.1.bin"));

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

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

    final List<Replies> replies1 = Lists.newArrayList();
    rBuilder.setRp(this.rpTrue);
    replies1.add(rBuilder.build());
    builder.setReplies(replies1);

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

    // simple Failure
    result = Unpooled.wrappedBuffer(ByteArray.fileToBytes("src/test/resources/PCRep.2.bin"));
    final List<Replies> replies2 = Lists.newArrayList();
    rBuilder = new RepliesBuilder();
    rBuilder.setRp(this.rpTrue);
    replies2.add(rBuilder.build());
    final RepliesBuilder rBuilder2 = new RepliesBuilder();
    rBuilder2.setRp(this.rpTrue);
    rBuilder2.setResult(new FailureCaseBuilder().setNoPath(this.noPath).build());
    replies2.add(rBuilder2.build());
    builder.setReplies(replies2);

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

    // Failure with attributes
    result = Unpooled.wrappedBuffer(ByteArray.fileToBytes("src/test/resources/PCRep.3.bin"));
    final List<Replies> replies3 = Lists.newArrayList();
    rBuilder = new RepliesBuilder();
    rBuilder.setRp(this.rpTrue);
    rBuilder.setResult(new FailureCaseBuilder().setNoPath(this.noPath).setLspa(this.lspa)
            .setMetrics(Lists.newArrayList(this.metrics)).setIro(this.iro).build());
    replies3.add(rBuilder.build());
    builder.setReplies(replies3);

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

    // Success
    result = Unpooled.wrappedBuffer(ByteArray.fileToBytes("src/test/resources/PCRep.5.bin"));
    final List<Replies> replies4 = Lists.newArrayList();
    rBuilder = new RepliesBuilder();
    rBuilder.setRp(this.rpTrue);
    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()));
    buf = Unpooled.buffer(result.readableBytes());
    parser.serializeMessage(new PcrepBuilder().setPcrepMessage(builder.build()).build(), buf);
    assertArrayEquals(result.array(), buf.array());

    try {
        parser.serializeMessage(new PcrepBuilder().setPcrepMessage(new PcrepMessageBuilder().build()).build(),
                null);
        fail();
    } catch (final IllegalArgumentException e) {
        assertEquals("Replies cannot be null or empty.", e.getMessage());
    }
    try {
        parser.serializeMessage(new PcrepBuilder()
                .setPcrepMessage(new PcrepMessageBuilder().setReplies(Collections.<Replies>emptyList()).build())
                .build(), null);
        fail();
    } catch (final IllegalArgumentException e) {
        assertEquals("Replies cannot be null or empty.", e.getMessage());
    }
}

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

License:Open Source License

@Test
public void testNotificationMsg() throws IOException, PCEPDeserializerException {
    final CNotification cn1 = new CNotificationBuilder().setIgnore(false).setProcessingRule(false)
            .setType((short) 1).setValue((short) 1).build();

    final List<org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcntf.message.pcntf.message.notifications.Notifications> innerNot = Lists
            .newArrayList();//from  w w w . j  a  v  a2  s .co m
    innerNot.add(
            new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcntf.message.pcntf.message.notifications.NotificationsBuilder()
                    .setCNotification(cn1).build());
    final List<Rps> rps = Lists.newArrayList();
    rps.add(new RpsBuilder().setRp(this.rpFalse).build());

    final ByteBuf result = Unpooled.wrappedBuffer(ByteArray.fileToBytes("src/test/resources/PCNtf.5.bin"));

    final PCEPNotificationMessageParser parser = new PCEPNotificationMessageParser(this.objectRegistry);
    final PcntfMessageBuilder builder = new PcntfMessageBuilder();

    final List<Notifications> nots = Lists.newArrayList();
    final NotificationsBuilder b = new NotificationsBuilder();
    b.setNotifications(innerNot);
    b.setRps(rps);
    nots.add(b.build());

    final List<org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcntf.message.pcntf.message.notifications.Notifications> innerNot1 = Lists
            .newArrayList();
    innerNot1.add(
            new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcntf.message.pcntf.message.notifications.NotificationsBuilder()
                    .setCNotification(cn1).build());
    innerNot1.add(
            new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcntf.message.pcntf.message.notifications.NotificationsBuilder()
                    .setCNotification(cn1).build());
    final List<Rps> rps1 = Lists.newArrayList();
    rps1.add(new RpsBuilder().setRp(this.rpFalse).build());
    rps1.add(new RpsBuilder().setRp(this.rpFalse).build());

    b.setNotifications(innerNot1);
    b.setRps(rps1);
    nots.add(b.build());
    builder.setNotifications(nots);

    assertEquals(new PcntfBuilder().setPcntfMessage(builder.build()).build(),
            parser.parseMessage(result.slice(4, result.readableBytes() - 4), Collections.<Message>emptyList()));
    final ByteBuf buf = Unpooled.buffer(result.readableBytes());
    parser.serializeMessage(new PcntfBuilder().setPcntfMessage(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 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 www .j a v  a2 s  .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();/*from   w  w  w. ja v a  2 s.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.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());//from  w  w w .  j av  a2s  .c  om
    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);//from   w w w .j a va  2 s.  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  w ww  .  ja va 2s.  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();/* www  .  ja va2 s . com*/
    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());
}