use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.message.rev181109.Open 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());
}
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.message.rev181109.Open in project bgpcep by opendaylight.
the class BasePCEPSessionProposalFactory method getSessionProposal.
@Override
public Open getSessionProposal(final InetSocketAddress address, final int sessionId, final PCEPPeerProposal peerProposal) {
final OpenBuilder oBuilder = new OpenBuilder().setSessionId(Uint8.valueOf(sessionId)).setKeepalive(Uint8.valueOf(BasePCEPSessionProposalFactory.this.keepAlive));
if (BasePCEPSessionProposalFactory.this.keepAlive == 0) {
oBuilder.setDeadTimer(Uint8.ZERO);
} else {
oBuilder.setDeadTimer(Uint8.valueOf(BasePCEPSessionProposalFactory.this.deadTimer));
}
final TlvsBuilder builder = new TlvsBuilder();
addTlvs(address, builder);
if (peerProposal != null) {
peerProposal.setPeerSpecificProposal(address, builder);
}
return oBuilder.setTlvs(builder.build()).build();
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.message.rev181109.Open in project bgpcep by opendaylight.
the class PCEPSessionState method getRemotePref.
private static PeerPref getRemotePref(final Open open, final Channel channel) {
final PeerPrefBuilder peerBuilder = new PeerPrefBuilder();
peerBuilder.setDeadtimer(open.getDeadTimer()).setKeepalive(open.getKeepalive()).setIpAddress(((InetSocketAddress) channel.remoteAddress()).getAddress().getHostAddress()).setSessionId(open.getSessionId().toUint16());
return peerBuilder.build();
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.message.rev181109.Open in project bgpcep by opendaylight.
the class Util method createErrorMessage.
public static Pcerr createErrorMessage(final PCEPErrors error, final Open openObject) {
final PcerrBuilder errMessageBuilder = new PcerrBuilder();
final ErrorObject err = new ErrorObjectBuilder().setType(error.getErrorType()).setValue(error.getErrorValue()).build();
if (openObject == null) {
return errMessageBuilder.setPcerrMessage(new PcerrMessageBuilder().setErrors(Collections.singletonList(new ErrorsBuilder().setErrorObject(err).build())).build()).build();
}
final ErrorType type = new SessionCaseBuilder().setSession(new SessionBuilder().setOpen(openObject).build()).build();
return errMessageBuilder.setPcerrMessage(new PcerrMessageBuilder().setErrors(Collections.singletonList(new ErrorsBuilder().setErrorObject(err).build())).setErrorType(type).build()).build();
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.message.rev181109.Open in project bgpcep by opendaylight.
the class FiniteStateMachineTest method testErrorOneSeven.
/**
* KeepWaitTimer expired.
*
* @throws Exception exception
*/
@Test
public void testErrorOneSeven() throws Exception {
this.serverSession.channelActive(null);
assertEquals(1, this.msgsSend.size());
assertTrue(this.msgsSend.get(0) instanceof Open);
this.serverSession.handleMessage(this.openMsg);
checkEquals(() -> {
for (final Notification m : this.msgsSend) {
if (m instanceof Pcerr) {
final Errors obj = ((Pcerr) m).getPcerrMessage().getErrors().get(0);
assertEquals(Uint8.ONE, obj.getErrorObject().getType());
assertEquals(Uint8.valueOf(7), obj.getErrorObject().getValue());
}
}
});
}
Aggregations