Extensibility support (serialization part)
[openflowjava.git] / openflow-protocol-impl / src / main / java / org / opendaylight / openflowjava / protocol / impl / core / PublishingChannelInitializer.java
index 953831042c56e84d718593518a9da35df31c7306..5a35864b4184f429daa3585dbdb7208090ba5fd3 100644 (file)
@@ -1,4 +1,11 @@
-/* Copyright (C)2013 Pantheon Technologies, s.r.o. All rights reserved. */
+/*
+ * Copyright (c) 2013 Pantheon Technologies s.r.o. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+
 package org.opendaylight.openflowjava.protocol.impl.core;
 
 import io.netty.channel.Channel;
@@ -14,6 +21,7 @@ import org.opendaylight.openflowjava.protocol.api.connection.SwitchConnectionHan
 import org.opendaylight.openflowjava.protocol.impl.connection.ConnectionAdapterFactory;
 import org.opendaylight.openflowjava.protocol.impl.connection.ConnectionFacade;
 import org.opendaylight.openflowjava.protocol.impl.core.TcpHandler.COMPONENT_NAMES;
+import org.opendaylight.openflowjava.protocol.impl.serialization.SerializationFactory;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -29,7 +37,8 @@ public class PublishingChannelInitializer extends ChannelInitializer<SocketChann
     private SwitchConnectionHandler switchConnectionHandler;
     private long switchIdleTimeout;
     private boolean encryption;
-    
+    private SerializationFactory serializationFactory;
+
     /**
      * default ctor
      */
@@ -40,7 +49,10 @@ public class PublishingChannelInitializer extends ChannelInitializer<SocketChann
     @Override
     protected void initChannel(SocketChannel ch) {
         InetAddress switchAddress = ch.remoteAddress().getAddress();
-        LOGGER.info("Incoming connection from (remote address): " + switchAddress.toString());
+        int port = ch.localAddress().getPort();
+        int remotePort = ch.remoteAddress().getPort();
+        LOGGER.info("Incoming connection from (remote address): " + switchAddress.toString()
+                + ":" + remotePort + " --> :" + port);
         if (!switchConnectionHandler.accept(switchAddress)) {
             ch.disconnect();
             LOGGER.info("Incoming connection rejected");
@@ -63,9 +75,14 @@ public class PublishingChannelInitializer extends ChannelInitializer<SocketChann
             }
             ch.pipeline().addLast(COMPONENT_NAMES.OF_FRAME_DECODER.name(), new OFFrameDecoder());
             ch.pipeline().addLast(COMPONENT_NAMES.OF_VERSION_DETECTOR.name(), new OFVersionDetector());
-            ch.pipeline().addLast(COMPONENT_NAMES.OF_DECODER.name(), new OF13Decoder());
-            ch.pipeline().addLast(COMPONENT_NAMES.OF_ENCODER.name(), new OF13Encoder());
+            ch.pipeline().addLast(COMPONENT_NAMES.OF_DECODER.name(), new OFDecoder());
+            OFEncoder ofEncoder = new OFEncoder();
+            ofEncoder.setSerializationFactory(serializationFactory);
+            ch.pipeline().addLast(COMPONENT_NAMES.OF_ENCODER.name(), ofEncoder);
             ch.pipeline().addLast(COMPONENT_NAMES.DELEGATING_INBOUND_HANDLER.name(), new DelegatingInboundHandler(connectionFacade));
+            if (!encryption) {
+                connectionFacade.fireConnectionReadyNotification();
+            }
         } catch (Exception e) {
             LOGGER.error(e.getMessage(), e);
             ch.close();
@@ -106,5 +123,11 @@ public class PublishingChannelInitializer extends ChannelInitializer<SocketChann
     public void setEncryption(boolean tlsSupported) {
         encryption = tlsSupported;
     }
-    
+
+    /**
+     * @param serializationFactory
+     */
+    public void setSerializationFactory(SerializationFactory serializationFactory) {
+        this.serializationFactory = serializationFactory;
+    }
 }