Add method to register listener for unknown msg 74/59674/2 master
authorTomas Slusny <tomas.slusny@pantheon.tech>
Thu, 29 Jun 2017 13:11:39 +0000 (15:11 +0200)
committerTomas Slusny <tomas.slusny@pantheon.tech>
Thu, 29 Jun 2017 13:46:32 +0000 (15:46 +0200)
Add method to ConnectionAdapter that will allow to register listener for
unknown (alien) messages received from switch.

See also: bug 8772

Change-Id: I3c4e48d0ddfd0a1220850bec5f75aa84e0e662c6
Signed-off-by: Tomas Slusny <tomas.slusny@pantheon.tech>
openflow-protocol-api/src/main/java/org/opendaylight/openflowjava/protocol/api/connection/ConnectionAdapter.java
openflow-protocol-api/src/main/java/org/opendaylight/openflowjava/protocol/api/extensibility/AlienMessageListener.java [new file with mode: 0644]
openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/core/connection/ConnectionAdapterImpl.java

index 89cd461f05add5f9aaf5c56c0072e2b974d497b3..a61ea51336fcb42df898f667df98211a9b65f47d 100644 (file)
@@ -10,6 +10,7 @@ package org.opendaylight.openflowjava.protocol.api.connection;
 import com.google.common.annotations.Beta;
 import java.net.InetSocketAddress;
 import java.util.concurrent.Future;
+import org.opendaylight.openflowjava.protocol.api.extensibility.AlienMessageListener;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.OpenflowProtocolListener;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.OpenflowProtocolService;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.system.rev130927.SystemNotificationsListener;
@@ -35,6 +36,7 @@ public interface ConnectionAdapter extends OpenflowProtocolService {
      * @return address of the remote end - address of a switch if connected
      */
     InetSocketAddress getRemoteAddress();
+
     /**
      * @param messageListener here will be pushed all messages from switch
      */
@@ -45,6 +47,12 @@ public interface ConnectionAdapter extends OpenflowProtocolService {
      */
     void setSystemListener(SystemNotificationsListener systemListener);
 
+    /**
+     * Set handler for alien messages received from device
+     * @param alienMessageListener here will be pushed all alien messages from switch
+     */
+    void setAlienMessageListener(AlienMessageListener alienMessageListener);
+
     /**
      * Throws exception if any of required listeners is missing
      */
diff --git a/openflow-protocol-api/src/main/java/org/opendaylight/openflowjava/protocol/api/extensibility/AlienMessageListener.java b/openflow-protocol-api/src/main/java/org/opendaylight/openflowjava/protocol/api/extensibility/AlienMessageListener.java
new file mode 100644 (file)
index 0000000..a3cd7c6
--- /dev/null
@@ -0,0 +1,19 @@
+/*
+ * Copyright (c) 2017 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.api.extensibility;
+
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.OfHeader;
+
+public interface AlienMessageListener {
+
+    /**
+     * Handler for alien but successfully deserialized messages for device
+     * @param message alien message
+     */
+    void onAlienMessage(OfHeader message);
+}
index 8d9c87466a337039f15719754a57ccbf392118c4..e9de9ca253a27fbb178872ec46d6e139f555410e 100644 (file)
@@ -15,6 +15,7 @@ import java.net.InetSocketAddress;
 import org.opendaylight.openflowjava.protocol.api.connection.ConnectionReadyListener;
 import org.opendaylight.openflowjava.protocol.api.connection.OutboundQueueHandler;
 import org.opendaylight.openflowjava.protocol.api.connection.OutboundQueueHandlerRegistration;
+import org.opendaylight.openflowjava.protocol.api.extensibility.AlienMessageListener;
 import org.opendaylight.openflowjava.protocol.impl.core.OFVersionDetector;
 import org.opendaylight.openflowjava.protocol.impl.core.PipelineHandlers;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.EchoRequestMessage;
@@ -47,6 +48,7 @@ public class ConnectionAdapterImpl extends AbstractConnectionAdapterStatistics i
     private ConnectionReadyListener connectionReadyListener;
     private OpenflowProtocolListener messageListener;
     private SystemNotificationsListener systemListener;
+    private AlienMessageListener alienMessageListener;
     private AbstractOutboundQueueManager<?, ?> outputManager;
     private OFVersionDetector versionDetector;
 
@@ -80,6 +82,11 @@ public class ConnectionAdapterImpl extends AbstractConnectionAdapterStatistics i
         this.systemListener = systemListener;
     }
 
+    @Override
+    public void setAlienMessageListener(final AlienMessageListener alienMessageListener) {
+        this.alienMessageListener = alienMessageListener;
+    }
+
     @Override
     public void consumeDeviceMessage(final DataObject message) {
         LOG.debug("ConsumeIntern msg on {}", channel);
@@ -131,19 +138,24 @@ public class ConnectionAdapterImpl extends AbstractConnectionAdapterStatistics i
             }
         } else if (message instanceof OfHeader) {
             LOG.debug("OF header msg received");
+            boolean found = false;
 
             if (outputManager == null || !outputManager.onMessage((OfHeader) message)) {
                 final RpcResponseKey key = createRpcResponseKey((OfHeader) message);
                 final ResponseExpectedRpcListener<?> listener = findRpcResponse(key);
                 if (listener != null) {
+                    found = true;
                     LOG.debug("Corresponding rpcFuture found");
-                    listener.completed((OfHeader)message);
+                    listener.completed((OfHeader) message);
                     LOG.debug("After setting rpcFuture");
                     responseCache.invalidate(key);
-                } else {
-                    LOG.warn("received unexpected rpc response: {}", key);
                 }
             }
+
+            if (!found && alienMessageListener != null) {
+                LOG.debug("Alien message {} received", message.getImplementedInterface());
+                alienMessageListener.onAlienMessage((OfHeader) message);
+            }
         } else {
             LOG.warn("message listening not supported for type: {}", message.getClass());
         }