1 package org.opendaylight.openflowjava.protocol.impl.core;
\r
3 import io.netty.channel.Channel;
\r
4 import io.netty.channel.ChannelInitializer;
\r
5 import io.netty.channel.group.DefaultChannelGroup;
\r
6 import io.netty.channel.socket.SocketChannel;
\r
8 import java.net.InetAddress;
\r
9 import java.util.Iterator;
\r
11 import org.opendaylight.openflowjava.protocol.api.connection.SwitchConnectionHandler;
\r
12 import org.opendaylight.openflowjava.protocol.impl.connection.ConnectionAdapterFactory;
\r
13 import org.opendaylight.openflowjava.protocol.impl.connection.ConnectionFacade;
\r
14 import org.opendaylight.openflowjava.protocol.impl.core.TcpHandler.COMPONENT_NAMES;
\r
15 import org.slf4j.Logger;
\r
16 import org.slf4j.LoggerFactory;
\r
19 * @author michal.polkorab
\r
22 public class PublishingChannelInitializer extends ChannelInitializer<SocketChannel> {
\r
24 private static final Logger LOGGER = LoggerFactory
\r
25 .getLogger(PublishingChannelInitializer.class);
\r
26 private DefaultChannelGroup allChannels;
\r
27 private SwitchConnectionHandler switchConnectionHandler;
\r
32 public PublishingChannelInitializer() {
\r
33 allChannels = new DefaultChannelGroup("netty-receiver", null);
\r
37 protected void initChannel(SocketChannel ch) {
\r
38 InetAddress switchAddress = ch.remoteAddress().getAddress();
\r
39 LOGGER.info("Incoming connection from (remote address): " + switchAddress.toString());
\r
40 if (!switchConnectionHandler.accept(switchAddress)) {
\r
42 LOGGER.info("Incoming connection rejected");
\r
45 LOGGER.info("Incoming connection accepted - building pipeline");
\r
46 allChannels.add(ch);
\r
47 ConnectionFacade connectionAdapter = null;
\r
48 connectionAdapter = ConnectionAdapterFactory.createConnectionAdapter(ch);
\r
50 LOGGER.debug("calling plugin: "+switchConnectionHandler);
\r
51 switchConnectionHandler.onSwitchConnected(connectionAdapter);
\r
52 connectionAdapter.checkListeners();
\r
53 ch.pipeline().addLast(COMPONENT_NAMES.TLS_DETECTOR.name(), new TlsDetector());
\r
54 ch.pipeline().addLast(COMPONENT_NAMES.DELEGATING_INBOUND_HANDLER.name(), new DelegatingInboundHandler(connectionAdapter));
\r
55 } catch (Exception e) {
\r
56 LOGGER.error(e.getMessage(), e);
\r
62 * @return iterator through active connections
\r
64 public Iterator<Channel> getConnectionIterator() {
\r
65 return allChannels.iterator();
\r
69 * @return amount of active channels
\r
72 return allChannels.size();
\r
76 * @param switchConnectionHandler the switchConnectionHandler to set
\r
78 public void setSwitchConnectionHandler(SwitchConnectionHandler switchConnectionHandler) {
\r
79 this.switchConnectionHandler = switchConnectionHandler;
\r