Search in sources :

Example 1 with RepliesBuilder

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.pcrep.message.pcrep.message.RepliesBuilder in project bgpcep by opendaylight.

the class PCEPReplyMessageParser method getValidReply.

protected Replies getValidReply(final List<Object> objects, final List<Message> errors) throws PCEPDeserializerException {
    Object object = objects.remove(0);
    if (!(object instanceof Rp)) {
        errors.add(createErrorMsg(PCEPErrors.RP_MISSING, Optional.absent()));
        return null;
    }
    final Rp rp = (Rp) object;
    final RepliesBuilder repliesBuilder = new RepliesBuilder();
    if (!objects.isEmpty() && objects.get(0) instanceof Monitoring) {
        repliesBuilder.setMonitoring((Monitoring) objects.get(0));
        objects.remove(0);
    }
    if (!objects.isEmpty() && objects.get(0) instanceof PccIdReq) {
        repliesBuilder.setPccIdReq((PccIdReq) objects.get(0));
        objects.remove(0);
    }
    final List<VendorInformationObject> vendorInfo = addVendorInformationObjects(objects);
    Result res = null;
    if (!objects.isEmpty()) {
        if (objects.get(0) instanceof NoPath) {
            res = handleNoPath((NoPath) objects.get(0), objects);
        } else if (objects.get(0) instanceof Ero) {
            res = handleEro((Ero) objects.get(0), objects);
        }
    }
    final List<MetricPce> metricPceList = new ArrayList<>();
    if (!objects.isEmpty() && objects.get(0) instanceof PceId) {
        while (!objects.isEmpty()) {
            metricPceList.add(Util.validateMonitoringMetrics(objects));
        }
    }
    if (!vendorInfo.isEmpty()) {
        repliesBuilder.setVendorInformationObject(vendorInfo);
    }
    if (!metricPceList.isEmpty()) {
        repliesBuilder.setMetricPce(metricPceList);
    }
    return repliesBuilder.setRp(rp).setResult(res).build();
}
Also used : RepliesBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcrep.message.pcrep.message.RepliesBuilder) Ero(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.explicit.route.object.Ero) ArrayList(java.util.ArrayList) Result(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcrep.message.pcrep.message.replies.Result) VendorInformationObject(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.vendor.information.objects.VendorInformationObject) PceId(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pce.id.object.PceId) PccIdReq(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcc.id.req.object.PccIdReq) Object(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.Object) VendorInformationObject(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.vendor.information.objects.VendorInformationObject) NoPath(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcrep.message.pcrep.message.replies.result.failure._case.NoPath) Rp(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.rp.object.Rp) Monitoring(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.monitoring.object.Monitoring) MetricPce(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.monitoring.metrics.MetricPce)

Example 2 with RepliesBuilder

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.pcrep.message.pcrep.message.RepliesBuilder in project bgpcep by opendaylight.

the class PCEPValidatorTest method testRepMsgWithVendorInforObjects.

@Test
public void testRepMsgWithVendorInforObjects() throws IOException, PCEPDeserializerException {
    final PCEPReplyMessageParser parser = new PCEPReplyMessageParser(this.objectRegistry);
    final PcrepMessageBuilder builder = new PcrepMessageBuilder();
    RepliesBuilder repliesBuilder = new RepliesBuilder();
    final ByteBuf result = Unpooled.wrappedBuffer(ByteArray.fileToBytes("src/test/resources/PCRep.6.bin"));
    final List<Replies> replies = new ArrayList<>();
    repliesBuilder = new RepliesBuilder().setRp(this.rpTrue).setVendorInformationObject(this.viObjects);
    final List<Paths> paths = new ArrayList<>();
    final PathsBuilder paBuilder = new PathsBuilder();
    paBuilder.setEro(this.ero);
    paths.add(paBuilder.build());
    repliesBuilder.setResult(new SuccessCaseBuilder().setSuccess(new SuccessBuilder().setPaths(paths).setVendorInformationObject(this.viObjects).build()).build()).build();
    replies.add(repliesBuilder.build());
    builder.setReplies(replies);
    assertEquals(new PcrepBuilder().setPcrepMessage(builder.build()).build(), parser.parseMessage(result.slice(4, result.readableBytes() - 4), Collections.emptyList()));
    final ByteBuf buf = Unpooled.buffer(result.readableBytes());
    parser.serializeMessage(new PcrepBuilder().setPcrepMessage(builder.build()).build(), buf);
    assertArrayEquals(result.array(), buf.array());
}
Also used : RepliesBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.pcrep.message.pcrep.message.RepliesBuilder) PcrepMessageBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.pcrep.message.PcrepMessageBuilder) ArrayList(java.util.ArrayList) ByteBuf(io.netty.buffer.ByteBuf) PathsBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.pcrep.message.pcrep.message.replies.result.success._case.success.PathsBuilder) PCEPReplyMessageParser(org.opendaylight.protocol.pcep.parser.message.PCEPReplyMessageParser) SuccessBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.pcrep.message.pcrep.message.replies.result.success._case.SuccessBuilder) SuccessCaseBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.pcrep.message.pcrep.message.replies.result.SuccessCaseBuilder) PcrepBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.message.rev181109.PcrepBuilder) Paths(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.pcrep.message.pcrep.message.replies.result.success._case.success.Paths) Replies(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.pcrep.message.pcrep.message.Replies) Test(org.junit.Test)

Example 3 with RepliesBuilder

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.pcrep.message.pcrep.message.RepliesBuilder in project bgpcep by opendaylight.

the class PCEPValidatorTest method testReplyMsg.

@Test
public void testReplyMsg() throws IOException, PCEPDeserializerException {
    // only RP
    final PCEPReplyMessageParser parser = new PCEPReplyMessageParser(this.objectRegistry);
    final PcrepMessageBuilder builder = new PcrepMessageBuilder();
    RepliesBuilder repliesBuilder = new RepliesBuilder();
    final List<Replies> replies1 = new ArrayList<>();
    repliesBuilder.setRp(this.rpTrue);
    replies1.add(repliesBuilder.build());
    builder.setReplies(replies1);
    ByteBuf result = Unpooled.wrappedBuffer(ByteArray.fileToBytes("src/test/resources/PCRep.1.bin"));
    assertEquals(new PcrepBuilder().setPcrepMessage(builder.build()).build(), parser.parseMessage(result.slice(4, result.readableBytes() - 4), Collections.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 = new ArrayList<>();
    repliesBuilder = new RepliesBuilder();
    repliesBuilder.setRp(this.rpTrue);
    replies2.add(repliesBuilder.build());
    final RepliesBuilder repliesBuilder2 = new RepliesBuilder();
    repliesBuilder2.setRp(this.rpTrue);
    repliesBuilder2.setResult(new FailureCaseBuilder().setNoPath(this.noPath).build());
    replies2.add(repliesBuilder2.build());
    builder.setReplies(replies2);
    assertEquals(new PcrepBuilder().setPcrepMessage(builder.build()).build(), parser.parseMessage(result.slice(4, result.readableBytes() - 4), Collections.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 = new ArrayList<>();
    repliesBuilder = new RepliesBuilder();
    repliesBuilder.setRp(this.rpTrue);
    repliesBuilder.setResult(new FailureCaseBuilder().setNoPath(this.noPath).setLspa(this.lspa).setMetrics(Lists.newArrayList(this.metrics)).setIro(this.iro).build());
    replies3.add(repliesBuilder.build());
    builder.setReplies(replies3);
    assertEquals(new PcrepBuilder().setPcrepMessage(builder.build()).build(), parser.parseMessage(result.slice(4, result.readableBytes() - 4), Collections.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 = new ArrayList<>();
    repliesBuilder = new RepliesBuilder();
    repliesBuilder.setRp(this.rpTrue);
    final List<Paths> paths = new ArrayList<>();
    final PathsBuilder paBuilder = new PathsBuilder().setEro(this.ero).setLspa(this.lspa).setMetrics(Lists.newArrayList(this.metrics)).setIro(this.iro).setOf(this.of);
    paths.add(paBuilder.build());
    repliesBuilder.setResult(new SuccessCaseBuilder().setSuccess(new SuccessBuilder().setPaths(paths).build()).build()).build();
    replies4.add(repliesBuilder.build());
    builder.setReplies(replies4);
    assertEquals(new PcrepBuilder().setPcrepMessage(builder.build()).build(), parser.parseMessage(result.slice(4, result.readableBytes() - 4), Collections.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.emptyList()).build()).build(), null);
        fail();
    } catch (final IllegalArgumentException e) {
        assertEquals("Replies cannot be null or empty.", e.getMessage());
    }
}
Also used : RepliesBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.pcrep.message.pcrep.message.RepliesBuilder) PcrepMessageBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.pcrep.message.PcrepMessageBuilder) ArrayList(java.util.ArrayList) ByteBuf(io.netty.buffer.ByteBuf) PathsBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.pcrep.message.pcrep.message.replies.result.success._case.success.PathsBuilder) FailureCaseBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.pcrep.message.pcrep.message.replies.result.FailureCaseBuilder) PCEPReplyMessageParser(org.opendaylight.protocol.pcep.parser.message.PCEPReplyMessageParser) SuccessBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.pcrep.message.pcrep.message.replies.result.success._case.SuccessBuilder) SuccessCaseBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.pcrep.message.pcrep.message.replies.result.SuccessCaseBuilder) PcrepBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.message.rev181109.PcrepBuilder) Paths(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.pcrep.message.pcrep.message.replies.result.success._case.success.Paths) Replies(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.pcrep.message.pcrep.message.Replies) Test(org.junit.Test)

Example 4 with RepliesBuilder

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.pcrep.message.pcrep.message.RepliesBuilder in project bgpcep by opendaylight.

the class MessagesUtil method createPcRepMessage.

public static Pcrep createPcRepMessage(final Rp rp, final P2p p2p, final ConstrainedPath cpath) {
    /* Prepare Path Object with ERO and Object from the Request */
    final ArrayList<Paths> paths = new ArrayList<>();
    PathsBuilder pathBuilder = buildPath(cpath);
    if (p2p.getLspa() != null) {
        pathBuilder.setLspa(p2p.getLspa());
    }
    if (p2p.getIro() != null) {
        pathBuilder.setIro(p2p.getIro());
    }
    if (p2p.getXro() != null) {
        pathBuilder.setXro(p2p.getXro());
    }
    paths.add(pathBuilder.build());
    /* Prepare Reply with Path Object */
    final RepliesBuilder replyBuilder = new RepliesBuilder().setRp(rp).setResult(new SuccessCaseBuilder().setSuccess(new SuccessBuilder().setPaths(paths).build()).build());
    /* Prepare PcRep Message */
    final PcrepMessageBuilder msgBuilder = new PcrepMessageBuilder().setReplies(Lists.newArrayList(replyBuilder.build()));
    return new PcrepBuilder().setPcrepMessage(msgBuilder.build()).build();
}
Also used : RepliesBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.pcrep.message.pcrep.message.RepliesBuilder) SuccessBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.pcrep.message.pcrep.message.replies.result.success._case.SuccessBuilder) SuccessCaseBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.pcrep.message.pcrep.message.replies.result.SuccessCaseBuilder) PcrepMessageBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.pcrep.message.PcrepMessageBuilder) ArrayList(java.util.ArrayList) PcrepBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.message.rev181109.PcrepBuilder) Paths(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.pcrep.message.pcrep.message.replies.result.success._case.success.Paths) PathsBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.pcrep.message.pcrep.message.replies.result.success._case.success.PathsBuilder)

Example 5 with RepliesBuilder

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.pcrep.message.pcrep.message.RepliesBuilder in project bgpcep by opendaylight.

the class MessagesUtil method createNoPathMessage.

public static Pcrep createNoPathMessage(final Rp rp, final byte reason) {
    /* Prepare NoPath Object */
    final Flags flags = new Flags(false, false, false, false, false, false, reason == UNKNOWN_DESTINATION, reason == UNKNOWN_SOURCE);
    final NoPathVectorBuilder npvBuilder = new NoPathVectorBuilder().setFlags(flags);
    final TlvsBuilder tlvsBuilder = new TlvsBuilder().setNoPathVector(npvBuilder.build());
    final NoPathBuilder npBuilder = new NoPathBuilder().setProcessingRule(false).setIgnore(false).setNatureOfIssue(Uint8.ZERO).setUnsatisfiedConstraints(true).setTlvs(tlvsBuilder.build());
    /* Prepare Reply */
    final RepliesBuilder replyBuilder = new RepliesBuilder().setRp(rp).setResult(new FailureCaseBuilder().setNoPath(npBuilder.build()).build());
    /* Prepare PcRep Message */
    final PcrepMessageBuilder msgBuilder = new PcrepMessageBuilder().setReplies(Lists.newArrayList(replyBuilder.build()));
    return new PcrepBuilder().setPcrepMessage(msgBuilder.build()).build();
}
Also used : FailureCaseBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.pcrep.message.pcrep.message.replies.result.FailureCaseBuilder) RepliesBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.pcrep.message.pcrep.message.RepliesBuilder) NoPathBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.pcrep.message.pcrep.message.replies.result.failure._case.NoPathBuilder) TlvsBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.pcrep.message.pcrep.message.replies.result.failure._case.no.path.TlvsBuilder) PcrepMessageBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.pcrep.message.PcrepMessageBuilder) PcrepBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.message.rev181109.PcrepBuilder) Flags(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.NoPathVectorTlv.Flags) NoPathVectorBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.pcrep.message.pcrep.message.replies.result.failure._case.no.path.tlvs.NoPathVectorBuilder)

Aggregations

ArrayList (java.util.ArrayList)7 RepliesBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.pcrep.message.pcrep.message.RepliesBuilder)7 PcrepBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.message.rev181109.PcrepBuilder)6 PcrepMessageBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.pcrep.message.PcrepMessageBuilder)6 SuccessCaseBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.pcrep.message.pcrep.message.replies.result.SuccessCaseBuilder)5 SuccessBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.pcrep.message.pcrep.message.replies.result.success._case.SuccessBuilder)5 Paths (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.pcrep.message.pcrep.message.replies.result.success._case.success.Paths)5 PathsBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.pcrep.message.pcrep.message.replies.result.success._case.success.PathsBuilder)5 ByteBuf (io.netty.buffer.ByteBuf)4 Test (org.junit.Test)4 PCEPReplyMessageParser (org.opendaylight.protocol.pcep.parser.message.PCEPReplyMessageParser)4 Replies (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.pcrep.message.pcrep.message.Replies)4 FailureCaseBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.pcrep.message.pcrep.message.replies.result.FailureCaseBuilder)2 Bandwidth (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.network.concepts.rev131125.Bandwidth)1 Object (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.Object)1 Ero (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.explicit.route.object.Ero)1 MetricPce (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.monitoring.metrics.MetricPce)1 Monitoring (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.monitoring.object.Monitoring)1 PccIdReq (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcc.id.req.object.PccIdReq)1 PceId (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pce.id.object.PceId)1