use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.pcep.app.config.rev160707.pcep.dispatcher.config.Tls in project bgpcep by opendaylight.
the class FiniteStateMachineTest method testEstablishTLS.
/**
* Establish PCEPS TLS connection with peer
*/
@Test
public void testEstablishTLS() {
final DefaultPCEPSessionNegotiator negotiator = new DefaultPCEPSessionNegotiator(new DefaultPromise<>(GlobalEventExecutor.INSTANCE), this.channel, this.listener, (short) 1, 20, new OpenBuilder().setKeepalive((short) 1).build(), SslContextFactoryTest.createTlsConfig());
negotiator.channelActive(null);
assertEquals(1, this.msgsSend.size());
assertTrue(this.msgsSend.get(0) instanceof Starttls);
assertEquals(DefaultPCEPSessionNegotiator.State.START_TLS_WAIT, negotiator.getState());
negotiator.handleMessage(this.startTlsMsg);
assertEquals(DefaultPCEPSessionNegotiator.State.OPEN_WAIT, negotiator.getState());
assertEquals(2, this.msgsSend.size());
assertTrue(this.msgsSend.get(1) instanceof Open);
negotiator.handleMessage(this.openMsg);
assertEquals(DefaultPCEPSessionNegotiator.State.KEEP_WAIT, negotiator.getState());
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.pcep.app.config.rev160707.pcep.dispatcher.config.Tls in project bgpcep by opendaylight.
the class FiniteStateMachineTest method testFailedToEstablishTLS.
/**
* As Tls is not configured properly, PCE will send error PCEPErrors.NOT_POSSIBLE_WITHOUT_TLS
*
* @throws Exception exception
*/
@Test
public void testFailedToEstablishTLS() throws Exception {
this.tlsSessionNegotiator.channelActive(null);
assertEquals(1, this.msgsSend.size());
assertTrue(this.msgsSend.get(0) instanceof Starttls);
assertEquals(DefaultPCEPSessionNegotiator.State.START_TLS_WAIT, this.tlsSessionNegotiator.getState());
this.tlsSessionNegotiator.handleMessage(this.startTlsMsg);
assertEquals(2, this.msgsSend.size());
assertTrue(this.msgsSend.get(1) instanceof Pcerr);
final Errors obj = ((Pcerr) this.msgsSend.get(1)).getPcerrMessage().getErrors().get(0);
assertEquals(PCEPErrors.NOT_POSSIBLE_WITHOUT_TLS.getErrorType(), obj.getErrorObject().getType().shortValue());
assertEquals(PCEPErrors.NOT_POSSIBLE_WITHOUT_TLS.getErrorValue(), obj.getErrorObject().getValue().shortValue());
assertEquals(DefaultPCEPSessionNegotiator.State.FINISHED, this.tlsSessionNegotiator.getState());
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.pcep.app.config.rev160707.pcep.dispatcher.config.Tls in project bgpcep by opendaylight.
the class AbstractPCEPSessionNegotiator method handleMessageStartTlsWait.
private boolean handleMessageStartTlsWait(final Message msg) {
if (msg instanceof Starttls) {
final SslContextFactory sslFactory = new SslContextFactory(this.tlsConfiguration);
final SSLContext sslContext = sslFactory.getServerContext();
if (sslContext == null) {
this.sendErrorMessage(PCEPErrors.NOT_POSSIBLE_WITHOUT_TLS);
negotiationFailed(new IllegalStateException("Failed to establish a TLS connection."));
this.state = State.FINISHED;
return true;
}
final SSLEngine engine = sslContext.createSSLEngine();
engine.setNeedClientAuth(true);
engine.setUseClientMode(false);
this.channel.pipeline().addFirst(new SslHandler(engine));
LOG.info("PCEPS TLS connection with peer: {} established succesfully.", this.channel);
startNegotiationWithOpen();
return true;
} else if (!(msg instanceof Pcerr)) {
this.sendErrorMessage(PCEPErrors.NON_STARTTLS_MSG_RCVD);
negotiationFailed(new IllegalStateException("Unexpected message recieved."));
this.state = State.FINISHED;
return true;
}
return false;
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.pcep.app.config.rev160707.pcep.dispatcher.config.Tls in project bgpcep by opendaylight.
the class AbstractPCEPSessionNegotiator method startNegotiation.
@Override
protected final void startNegotiation() {
Preconditions.checkState(this.state == State.IDLE);
if (this.tlsConfiguration != null) {
this.sendMessage(new StarttlsBuilder().setStartTlsMessage(new StartTlsMessageBuilder().build()).build());
this.state = State.START_TLS_WAIT;
scheduleFailTimer();
LOG.info("Started TLS connection negotiation with peer {}", this.channel);
} else {
startNegotiationWithOpen();
}
this.channel.closeFuture().addListener((ChannelFutureListener) f -> cancelTimers());
}
Aggregations