use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.open.message.OpenMessageBuilder in project bgpcep by opendaylight.
the class PCEPOpenMessageParser method validate.
@Override
protected org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.message.rev181109.Open validate(final Queue<Object> objects, final List<Message> errors) throws PCEPDeserializerException {
checkArgument(objects != null, "Passed list can't be null.");
final Object open = objects.poll();
if (!(open instanceof Open)) {
throw new PCEPDeserializerException("Open message doesn't contain OPEN object.");
}
if (!objects.isEmpty()) {
throw new PCEPDeserializerException("Unprocessed Objects: " + objects);
}
return new OpenBuilder().setOpenMessage(new OpenMessageBuilder().setOpen((Open) open).build()).build();
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.open.message.OpenMessageBuilder in project bgpcep by opendaylight.
the class PCEPValidatorTest method testOpenMsg.
@Test
public void testOpenMsg() throws IOException, PCEPDeserializerException {
new StatefulActivator().start(this.ctx);
final ByteBuf result = Unpooled.wrappedBuffer(ByteArray.fileToBytes("src/test/resources/PCEPOpenMessage1.bin"));
final PCEPOpenMessageParser parser = new PCEPOpenMessageParser(this.ctx.getObjectHandlerRegistry());
final OpenMessageBuilder builder = new OpenMessageBuilder().setOpen(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.open.object.OpenBuilder().setProcessingRule(false).setIgnore(false).setVersion(new ProtocolVersion(Uint8.ONE)).setKeepalive(Uint8.valueOf(30)).setDeadTimer(Uint8.valueOf(120)).setSessionId(Uint8.ONE).setTlvs(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.open.object.open.TlvsBuilder().addAugmentation(new Tlvs1Builder().setStateful(new StatefulBuilder().setLspUpdateCapability(Boolean.TRUE).build()).build()).build()).build());
assertEquals(new OpenBuilder().setOpenMessage(builder.build()).build(), parser.parseMessage(result.slice(4, result.readableBytes() - 4), List.of()));
final ByteBuf buf = Unpooled.buffer(result.readableBytes());
parser.serializeMessage(new OpenBuilder().setOpenMessage(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.open.message.OpenMessageBuilder in project bgpcep by opendaylight.
the class AbstractPCEPSessionNegotiator method startNegotiationWithOpen.
private void startNegotiationWithOpen() {
this.localPrefs = getInitialProposal();
final OpenMessage m = new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.message.rev181109.OpenBuilder().setOpenMessage(new OpenMessageBuilder().setOpen(this.localPrefs).build()).build();
this.sendMessage(m);
this.state = State.OPEN_WAIT;
scheduleFailTimer();
LOG.info("PCEP session with {} started, sent proposal {}", this.channel, this.localPrefs);
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.open.message.OpenMessageBuilder in project bgpcep by opendaylight.
the class AbstractPCEPSessionNegotiator method handleMessagePcerr.
private boolean handleMessagePcerr(final Message msg) {
final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.pcerr.message.PcerrMessage err = ((Pcerr) msg).getPcerrMessage();
if (err.getErrorType() == null) {
final ErrorObject obj = err.getErrors().get(0).getErrorObject();
LOG.warn("Unexpected error received from PCC: type {} value {}", obj.getType(), obj.getValue());
negotiationFailed(new IllegalStateException("Unexpected error received from PCC."));
this.state = State.IDLE;
return true;
}
this.localPrefs = getRevisedProposal(((SessionCase) err.getErrorType()).getSession().getOpen());
if (this.localPrefs == null) {
sendErrorMessage(PCEPErrors.PCERR_NON_ACC_SESSION_CHAR);
negotiationFailed(new IllegalStateException("Peer suggested unacceptable retry proposal"));
this.state = State.FINISHED;
return true;
}
this.sendMessage(new OpenBuilder().setOpenMessage(new OpenMessageBuilder().setOpen(this.localPrefs).build()).build());
if (!this.remoteOK) {
this.state = State.OPEN_WAIT;
}
scheduleFailTimer();
return true;
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.open.message.OpenMessageBuilder in project bgpcep by opendaylight.
the class PCEPValidatorTest method testOpenMsg.
@Test
public void testOpenMsg() throws IOException, PCEPDeserializerException {
final ByteBuf result = Unpooled.wrappedBuffer(ByteArray.fileToBytes("src/test/resources/PCEPOpenMessage1.bin"));
final PCEPOpenMessageParser parser = new PCEPOpenMessageParser(this.ctx.getObjectHandlerRegistry());
final OpenMessageBuilder builder = new OpenMessageBuilder();
final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.open.object.OpenBuilder b = new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.open.object.OpenBuilder().setProcessingRule(false).setIgnore(false).setVersion(new ProtocolVersion(Uint8.ONE)).setKeepalive(Uint8.valueOf(30)).setDeadTimer(Uint8.valueOf(120)).setSessionId(Uint8.ONE).setTlvs(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.open.object.open.TlvsBuilder().build());
builder.setOpen(b.build());
assertEquals(new OpenBuilder().setOpenMessage(builder.build()).build(), parser.parseMessage(result.slice(4, result.readableBytes() - 4), Collections.emptyList()));
final ByteBuf buf = Unpooled.buffer(result.readableBytes());
parser.serializeMessage(new OpenBuilder().setOpenMessage(builder.build()).build(), buf);
assertArrayEquals(result.array(), buf.array());
try {
parser.serializeMessage(new OpenBuilder().setOpenMessage(new OpenMessageBuilder().build()).build(), null);
fail();
} catch (final IllegalArgumentException e) {
assertEquals("Open Object must be present in Open Message.", e.getMessage());
}
}
Aggregations