use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.pcrep.message.pcrep.message.replies.result.FailureCaseBuilder in project bgpcep by opendaylight.
the class PCEPReplyMessageParser method parseAttributes.
protected void parseAttributes(final FailureCaseBuilder builder, final Queue<Object> objects) {
final List<Metrics> pathMetrics = new ArrayList<>();
State state = State.INIT;
for (Object obj = objects.peek(); obj != null; obj = objects.peek()) {
state = insertObject(state, obj, builder, pathMetrics);
if (state == State.END) {
break;
}
objects.remove();
}
if (!pathMetrics.isEmpty()) {
builder.setMetrics(pathMetrics);
}
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.pcrep.message.pcrep.message.replies.result.FailureCaseBuilder 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.FailureCaseBuilder 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();
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.pcrep.message.pcrep.message.replies.result.FailureCaseBuilder in project bgpcep by opendaylight.
the class AbstractInstructionExecutor method schedule.
public static FailureCase schedule(final InstructionScheduler scheduler, final AbstractInstructionExecutor fwd) {
final SubmitInstructionInput input = fwd.getInput();
final ListenableFuture<Instruction> listenableFuture;
try {
listenableFuture = scheduler.scheduleInstruction(input);
} catch (final SchedulerException e) {
LOG.info("Instuction {} failed to schedule", input, e);
return new FailureCaseBuilder().setFailure(e.getFailure()).build();
}
Futures.addCallback(listenableFuture, fwd, MoreExecutors.directExecutor());
return null;
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.pcrep.message.pcrep.message.replies.result.FailureCaseBuilder in project bgpcep by opendaylight.
the class PCEPReplyMessageParser method parseAttributes.
protected void parseAttributes(final FailureCaseBuilder 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