use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.pcrep.message.pcrep.message.replies.result.success._case.success.PathsBuilder 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());
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.pcrep.message.pcrep.message.replies.result.success._case.success.PathsBuilder 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());
}
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.pcrep.message.pcrep.message.replies.result.success._case.success.PathsBuilder 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();
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.pcrep.message.pcrep.message.replies.result.success._case.success.PathsBuilder in project bgpcep by opendaylight.
the class PCEPReplyMessageParser method handleEro.
private Result handleEro(final Ero ero, final List<Object> objects) {
objects.remove(0);
final SuccessBuilder builder = new SuccessBuilder();
final List<Paths> paths = new ArrayList<>();
final PathsBuilder pBuilder = new PathsBuilder();
pBuilder.setEro(ero);
while (!objects.isEmpty() && !(objects.get(0) instanceof PceId)) {
final List<VendorInformationObject> vendorInfoObjects = addVendorInformationObjects(objects);
if (!vendorInfoObjects.isEmpty()) {
builder.setVendorInformationObject(vendorInfoObjects);
}
this.parsePath(pBuilder, objects);
paths.add(pBuilder.build());
}
builder.setPaths(paths);
return new SuccessCaseBuilder().setSuccess(builder.build()).build();
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.pcrep.message.pcrep.message.replies.result.success._case.success.PathsBuilder in project bgpcep by opendaylight.
the class PCEPReplyMessageParser method parsePath.
protected void parsePath(final PathsBuilder builder, final List<Object> objects) {
final List<Metrics> pathMetrics = new ArrayList<>();
Object obj;
State state = State.INIT;
while (!objects.isEmpty() && !state.equals(State.END)) {
obj = objects.get(0);
state = insertObject(state, obj, builder, pathMetrics);
if (!state.equals(State.END)) {
objects.remove(0);
}
}
if (!pathMetrics.isEmpty()) {
builder.setMetrics(pathMetrics);
}
}
Aggregations