Merge "Fixing OF Multipart messages 1) So we have a MultipartRequestDesc message...
[openflowjava.git] / openflow-protocol-impl / src / main / java / org / opendaylight / openflowjava / protocol / impl / connection / ConnectionAdapterImpl.java
index 68f1420b487bc2f1c7aa6fd485046caeb476c827..3c83945b93798d2dec8d116345826dbe47d790c0 100644 (file)
@@ -48,6 +48,7 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PortStatusMessage;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.RoleRequestInput;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.RoleRequestOutput;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.SendMultipartRequestMessageInput;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.SetAsyncInput;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.SetConfigInput;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.TableModInput;
@@ -77,13 +78,13 @@ import com.google.common.util.concurrent.SettableFuture;
  * @author michal.polkorab
  */
 public class ConnectionAdapterImpl implements ConnectionFacade {
-    
+
     /** after this time, rpc future response objects will be thrown away (in minutes) */
     public static final int RPC_RESPONSE_EXPIRATION = 1;
 
     protected static final Logger LOG = LoggerFactory
             .getLogger(ConnectionAdapterImpl.class);
-    
+
     private static final String APPLICATION_TAG = "OPENFLOW_LIBRARY";
     private static final String TAG = "OPENFLOW";
     private Channel channel;
@@ -96,7 +97,7 @@ public class ConnectionAdapterImpl implements ConnectionFacade {
     protected ConnectionReadyListener connectionReadyListener;
 
     /**
-     * default ctor 
+     * default ctor
      */
     public ConnectionAdapterImpl() {
         responseCache = CacheBuilder.newBuilder()
@@ -105,7 +106,7 @@ public class ConnectionAdapterImpl implements ConnectionFacade {
                 .removalListener(new ResponseRemovalListener()).build();
         LOG.debug("ConnectionAdapter created");
     }
-    
+
     /**
      * @param channel the channel to be set - used for communication
      */
@@ -180,6 +181,11 @@ public class ConnectionAdapterImpl implements ConnectionFacade {
         return sendToSwitchFuture(input, "packet-out-input sending failed");
     }
 
+    @Override
+    public Future<RpcResult<Void>> sendMultipartRequestMessage(SendMultipartRequestMessageInput input) {
+        return sendToSwitchFuture(input, "multi-part-request sending failed");
+    }
+
     @Override
     public Future<RpcResult<Void>> portMod(PortModInput input) {
         return sendToSwitchFuture(input, "port-mod-input sending failed");
@@ -234,7 +240,7 @@ public class ConnectionAdapterImpl implements ConnectionFacade {
     public void setMessageListener(OpenflowProtocolListener messageListener) {
         this.messageListener = messageListener;
     }
-    
+
     @Override
     public void consume(DataObject message) {
         LOG.debug("ConsumeIntern msg");
@@ -297,38 +303,38 @@ public class ConnectionAdapterImpl implements ConnectionFacade {
     /**
      * sends given message to switch, sending result will be reported via return value
      * @param input message to send
-     * @param failureInfo describes, what type of message caused failure by sending 
+     * @param failureInfo describes, what type of message caused failure by sending
      * @return future object, <ul>
-     *  <li>if send successful, {@link RpcResult} without errors and successful 
+     *  <li>if send successful, {@link RpcResult} without errors and successful
      *  status will be returned, </li>
      *  <li>else {@link RpcResult} will contain errors and failed status</li>
-     *  </ul>    
+     *  </ul>
      */
     private SettableFuture<RpcResult<Void>> sendToSwitchFuture(
             DataObject input, final String failureInfo) {
         LOG.debug("going to flush");
         ChannelFuture resultFuture = channel.writeAndFlush(input);
         LOG.debug("flushed");
-        
+
         ErrorSeverity errorSeverity = ErrorSeverity.ERROR;
         String errorMessage = "check switch connection";
         return handleRpcChannelFuture(resultFuture, failureInfo, errorSeverity, errorMessage);
     }
-    
+
     /**
      * sends given message to switch, sending result or switch response will be reported via return value
      * @param input message to send
      * @param responseClazz type of response
-     * @param failureInfo describes, what type of message caused failure by sending 
+     * @param failureInfo describes, what type of message caused failure by sending
      * @return future object, <ul>
      *  <li>if send fails, {@link RpcResult} will contain errors and failed status </li>
-     *  <li>else {@link RpcResult} will be stored in responseCache and wait for particular timeout 
-     *  ({@link ConnectionAdapterImpl#RPC_RESPONSE_EXPIRATION}), 
+     *  <li>else {@link RpcResult} will be stored in responseCache and wait for particular timeout
+     *  ({@link ConnectionAdapterImpl#RPC_RESPONSE_EXPIRATION}),
      *  <ul><li>either switch will manage to answer
      *  and then corresponding response message will be set into returned future</li>
      *  <li>or response in cache will expire and returned future will be cancelled</li></ul>
      *  </li>
-     *  </ul>     
+     *  </ul>
      */
     private <IN extends OfHeader, OUT extends OfHeader> SettableFuture<RpcResult<OUT>> sendToSwitchExpectRpcResultFuture(
             IN input, Class<OUT> responseClazz, final String failureInfo) {
@@ -338,11 +344,11 @@ public class ConnectionAdapterImpl implements ConnectionFacade {
         responseCache.put(key, rpcResult);
         ChannelFuture resultFuture = channel.writeAndFlush(input);
         LOG.debug("flushed");
-        
+
         ErrorSeverity errorSeverity = ErrorSeverity.ERROR;
         String errorMessage = "check switch connection";
-        
-        return handleRpcChannelFutureWithResponse(resultFuture, failureInfo, errorSeverity, 
+
+        return handleRpcChannelFutureWithResponse(resultFuture, failureInfo, errorSeverity,
                 errorMessage, input, responseClazz, rpcResult, key);
     }
 
@@ -352,37 +358,37 @@ public class ConnectionAdapterImpl implements ConnectionFacade {
      * @return
      */
     private SettableFuture<RpcResult<Void>> handleRpcChannelFuture(
-            ChannelFuture resultFuture, final String failureInfo, 
+            ChannelFuture resultFuture, final String failureInfo,
             final ErrorSeverity errorSeverity, final String errorMessage) {
-        
+
         final SettableFuture<RpcResult<Void>> rpcResult = SettableFuture.create();
         LOG.debug("handlerpcchannelfuture");
         resultFuture.addListener(new GenericFutureListener<io.netty.util.concurrent.Future<? super Void>>() {
-            
+
             @Override
             public void operationComplete(
                     io.netty.util.concurrent.Future<? super Void> future)
                     throws Exception {
                 LOG.debug("operation complete");
                 Collection<RpcError> errors = Collections.emptyList();
-                
+
                 if (future.cause() != null) {
                     LOG.debug("future.cause != null");
-                    RpcError rpcError = buildRpcError(failureInfo, 
+                    RpcError rpcError = buildRpcError(failureInfo,
                             errorSeverity, errorMessage, future.cause());
                     errors = Lists.newArrayList(rpcError);
                 }
-                
+
                 rpcResult.set(Rpcs.getRpcResult(
-                        future.isSuccess(), 
-                        (Void) null, 
+                        future.isSuccess(),
+                        (Void) null,
                         errors)
                 );
             }
         });
         return rpcResult;
     }
-    
+
     /**
      * @param resultFuture
      * @param failureInfo
@@ -398,24 +404,24 @@ public class ConnectionAdapterImpl implements ConnectionFacade {
             final ErrorSeverity errorSeverity, final String errorMessage,
             final IN input, Class<OUT> responseClazz, final SettableFuture<RpcResult<OUT>> rpcResult, final RpcResponseKey key) {
         LOG.debug("handleRpcchanfuture with response");
-        
+
         resultFuture.addListener(new GenericFutureListener<io.netty.util.concurrent.Future<? super Void>>() {
-            
+
             @Override
             public void operationComplete(
                     io.netty.util.concurrent.Future<? super Void> future)
                     throws Exception {
-                
+
                 LOG.debug("operation complete");
                 Collection<RpcError> errors = Collections.emptyList();
                 if (future.cause() != null) {
                     LOG.debug("ChannelFuture.cause != null");
-                    RpcError rpcError = buildRpcError(failureInfo, 
+                    RpcError rpcError = buildRpcError(failureInfo,
                             errorSeverity, errorMessage, future.cause());
                     errors = Lists.newArrayList(rpcError);
                     rpcResult.set(Rpcs.getRpcResult(
-                            future.isSuccess(), 
-                            (OUT) null, 
+                            future.isSuccess(),
+                            (OUT) null,
                             errors)
                             );
                     responseCache.invalidate(key);
@@ -433,18 +439,18 @@ public class ConnectionAdapterImpl implements ConnectionFacade {
     /**
      * @param resultFuture
      * @param failureInfo
-     * @param errorSeverity 
-     * @param message 
+     * @param errorSeverity
+     * @param message
      * @return
      */
     private static SettableFuture<Boolean> handleTransportChannelFuture(
-            ChannelFuture resultFuture, final String failureInfo, 
+            ChannelFuture resultFuture, final String failureInfo,
             final ErrorSeverity errorSeverity, final String message) {
-        
+
         final SettableFuture<Boolean> transportResult = SettableFuture.create();
-        
+
         resultFuture.addListener(new GenericFutureListener<io.netty.util.concurrent.Future<? super Void>>() {
-            
+
             @Override
             public void operationComplete(
                     io.netty.util.concurrent.Future<? super Void> future)
@@ -462,20 +468,20 @@ public class ConnectionAdapterImpl implements ConnectionFacade {
      * @param cause
      * @return
      */
-    protected RpcError buildRpcError(String info, ErrorSeverity severity, String message, 
+    protected RpcError buildRpcError(String info, ErrorSeverity severity, String message,
             Throwable cause) {
-        RpcError error = RpcErrors.getRpcError(APPLICATION_TAG, TAG, info, severity, message, 
+        RpcError error = RpcErrors.getRpcError(APPLICATION_TAG, TAG, info, severity, message,
                 ErrorType.RPC, cause);
         return error;
     }
-    
+
     /**
      * @param cause
      * @return
      */
-    protected RpcError buildTransportError(String info, ErrorSeverity severity, String message, 
+    protected RpcError buildTransportError(String info, ErrorSeverity severity, String message,
             Throwable cause) {
-        RpcError error = RpcErrors.getRpcError(APPLICATION_TAG, TAG, info, severity, message, 
+        RpcError error = RpcErrors.getRpcError(APPLICATION_TAG, TAG, info, severity, message,
                 ErrorType.TRANSPORT, cause);
         return error;
     }
@@ -500,7 +506,7 @@ public class ConnectionAdapterImpl implements ConnectionFacade {
     public void setSystemListener(SystemNotificationsListener systemListener) {
         this.systemListener = systemListener;
     }
-    
+
     @Override
     public void checkListeners() {
         StringBuffer buffer =  new StringBuffer();
@@ -513,7 +519,7 @@ public class ConnectionAdapterImpl implements ConnectionFacade {
         if (connectionReadyListener == null) {
             buffer.append("ConnectionReadyListener ");
         }
-        
+
         if (buffer.length() > 0) {
             throw new IllegalStateException("Missing listeners: " + buffer.toString());
         }
@@ -541,7 +547,7 @@ public class ConnectionAdapterImpl implements ConnectionFacade {
             return null;
         }
     }
-    
+
     @Override
     public void fireConnectionReadyNotification() {
         new Thread(new Runnable() {
@@ -551,12 +557,12 @@ public class ConnectionAdapterImpl implements ConnectionFacade {
             }
         }).start();
     }
-    
-    
+
+
     @Override
     public void setConnectionReadyListener(
             ConnectionReadyListener connectionReadyListener) {
         this.connectionReadyListener = connectionReadyListener;
     }
-    
+
 }