use of org.opendaylight.openflowjava.protocol.impl.core.connection.ConnectionFacade in project openflowplugin by opendaylight.
the class OFDatagramPacketHandler method decode.
@Override
protected void decode(ChannelHandlerContext ctx, DatagramPacket msg, List<Object> out) throws Exception {
LOG.debug("OFDatagramPacketFramer");
MessageConsumer consumer = UdpConnectionMap.getMessageConsumer(msg.sender());
if (consumer == null) {
ConnectionFacade connectionFacade = adapterFactory.createConnectionFacade(ctx.channel(), msg.sender(), false, channelOutboundQueueSize);
connectionHandler.onSwitchConnected(connectionFacade);
connectionFacade.checkListeners();
UdpConnectionMap.addConnection(msg.sender(), connectionFacade);
}
ByteBuf bb = msg.content();
int readableBytes = bb.readableBytes();
if (readableBytes < LENGTH_OF_HEADER) {
if (LOG.isDebugEnabled()) {
LOG.debug("skipping bytebuf - too few bytes for header: {} < {}", readableBytes, LENGTH_OF_HEADER);
LOG.debug("bb: {}", ByteBufUtils.byteBufToHexString(bb));
}
return;
}
int length = bb.getUnsignedShort(bb.readerIndex() + LENGTH_INDEX_IN_HEADER);
LOG.debug("length of actual message: {}", length);
if (readableBytes < length) {
if (LOG.isDebugEnabled()) {
LOG.debug("skipping bytebuf - too few bytes for msg: {} < {}", readableBytes, length);
LOG.debug("bytebuffer: {}", ByteBufUtils.byteBufToHexString(bb));
}
return;
}
LOG.debug("OF Protocol message received, type:{}", bb.getByte(bb.readerIndex() + 1));
byte version = bb.readByte();
if (version == EncodeConstants.OF13_VERSION_ID || version == EncodeConstants.OF10_VERSION_ID) {
LOG.debug("detected version: {}", version);
ByteBuf messageBuffer = bb.slice();
out.add(new VersionMessageUdpWrapper(version, messageBuffer, msg.sender()));
messageBuffer.retain();
} else {
LOG.warn("detected version: {} - currently not supported", version);
}
bb.skipBytes(bb.readableBytes());
}
use of org.opendaylight.openflowjava.protocol.impl.core.connection.ConnectionFacade in project openflowplugin by opendaylight.
the class TcpChannelInitializer method initChannel.
@Override
@SuppressWarnings("checkstyle:IllegalCatch")
protected void initChannel(final SocketChannel ch) {
if (ch.remoteAddress() != null) {
final InetAddress switchAddress = ch.remoteAddress().getAddress();
final int port = ch.localAddress().getPort();
final int remotePort = ch.remoteAddress().getPort();
LOG.debug("Incoming connection from (remote address): {}:{} --> :{}", switchAddress.toString(), remotePort, port);
if (!getSwitchConnectionHandler().accept(switchAddress)) {
ch.disconnect();
LOG.debug("Incoming connection rejected");
return;
}
}
LOG.debug("Incoming connection accepted - building pipeline");
allChannels.add(ch);
ConnectionFacade connectionFacade = null;
connectionFacade = connectionAdapterFactory.createConnectionFacade(ch, null, useBarrier(), getChannelOutboundQueueSize());
try {
LOG.debug("Calling OF plugin: {}", getSwitchConnectionHandler());
getSwitchConnectionHandler().onSwitchConnected(connectionFacade);
connectionFacade.checkListeners();
ch.pipeline().addLast(PipelineHandlers.IDLE_HANDLER.name(), new IdleHandler(getSwitchIdleTimeout(), TimeUnit.MILLISECONDS));
boolean tlsPresent = false;
// If this channel is configured to support SSL it will only support SSL
if (getTlsConfiguration() != null) {
tlsPresent = true;
final SslContextFactory sslFactory = new SslContextFactory(getTlsConfiguration());
final SSLEngine engine = sslFactory.getServerContext().createSSLEngine();
engine.setNeedClientAuth(true);
engine.setUseClientMode(false);
List<String> suitesList = getTlsConfiguration().getCipherSuites();
if (suitesList != null && !suitesList.isEmpty()) {
LOG.debug("Requested Cipher Suites are: {}", suitesList);
String[] suites = suitesList.toArray(new String[suitesList.size()]);
engine.setEnabledCipherSuites(suites);
LOG.debug("Cipher suites enabled in SSLEngine are: {}", Arrays.toString(engine.getEnabledCipherSuites()));
}
final SslHandler ssl = new SslHandler(engine);
final Future<Channel> handshakeFuture = ssl.handshakeFuture();
final ConnectionFacade finalConnectionFacade = connectionFacade;
handshakeFuture.addListener(future -> finalConnectionFacade.fireConnectionReadyNotification());
ch.pipeline().addLast(PipelineHandlers.SSL_HANDLER.name(), ssl);
}
ch.pipeline().addLast(PipelineHandlers.OF_FRAME_DECODER.name(), new OFFrameDecoder(connectionFacade, tlsPresent));
ch.pipeline().addLast(PipelineHandlers.OF_VERSION_DETECTOR.name(), new OFVersionDetector());
final OFDecoder ofDecoder = new OFDecoder();
ofDecoder.setDeserializationFactory(getDeserializationFactory());
ch.pipeline().addLast(PipelineHandlers.OF_DECODER.name(), ofDecoder);
final OFEncoder ofEncoder = new OFEncoder();
ofEncoder.setSerializationFactory(getSerializationFactory());
ch.pipeline().addLast(PipelineHandlers.OF_ENCODER.name(), ofEncoder);
ch.pipeline().addLast(PipelineHandlers.DELEGATING_INBOUND_HANDLER.name(), new DelegatingInboundHandler(connectionFacade));
if (!tlsPresent) {
connectionFacade.fireConnectionReadyNotification();
}
} catch (RuntimeException e) {
LOG.warn("Failed to initialize channel", e);
ch.close();
}
}
Aggregations