Merge "add basic lib - plugin communication"
authorDaniel Bartos <daniel.bartos@pantheon.sk>
Thu, 12 Sep 2013 05:54:23 +0000 (05:54 +0000)
committerGerrit Code Review <gerrit@opendaylight.org>
Thu, 12 Sep 2013 05:54:23 +0000 (05:54 +0000)
openflow-protocol-api/src/main/java/org/opendaylight/openflowjava/protocol/api/connection/ConnectionAdapter.java [new file with mode: 0644]
openflow-protocol-api/src/main/java/org/opendaylight/openflowjava/protocol/api/connection/SwitchConnectionHandler.java [new file with mode: 0644]
openflow-protocol-impl/pom.xml
openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/connection/ConnectionAdapterFactory.java [new file with mode: 0644]
openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/connection/ConnectionAdapterImpl.java [new file with mode: 0644]
openflow-protocol-spi/src/main/java/org/opendaylight/openflowjava/protocol/spi/connection/SwitchConnectionProvider.java [new file with mode: 0644]
pom.xml

diff --git a/openflow-protocol-api/src/main/java/org/opendaylight/openflowjava/protocol/api/connection/ConnectionAdapter.java b/openflow-protocol-api/src/main/java/org/opendaylight/openflowjava/protocol/api/connection/ConnectionAdapter.java
new file mode 100644 (file)
index 0000000..04a9ecc
--- /dev/null
@@ -0,0 +1,36 @@
+/**
+ * Copyright (c) 2013 Cisco Systems, Inc. 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.connection;
+
+import java.util.concurrent.Future;
+
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.OpenflowProtocolListener;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.OpenflowProtocolService;
+
+/**
+ * @author mirehak
+ */
+public interface ConnectionAdapter extends OpenflowProtocolService {
+
+    /**
+     * disconnect corresponding switch
+     * @return future set to true, when disconnect completed
+     */
+    public Future<Boolean> disconnect();
+    
+    /**
+     * @return true, if connection to switch is alive
+     */
+    public boolean isAlive();
+    
+    /**
+     * @param messageListener here will be pushed all messages from switch
+     */
+    public void setMessageListener(OpenflowProtocolListener messageListener);
+}
diff --git a/openflow-protocol-api/src/main/java/org/opendaylight/openflowjava/protocol/api/connection/SwitchConnectionHandler.java b/openflow-protocol-api/src/main/java/org/opendaylight/openflowjava/protocol/api/connection/SwitchConnectionHandler.java
new file mode 100644 (file)
index 0000000..0495710
--- /dev/null
@@ -0,0 +1,30 @@
+/**
+ * Copyright (c) 2013 Cisco Systems, Inc. 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.connection;
+
+import java.net.InetAddress;
+
+/**
+ * @author mirehak
+ *
+ */
+public interface SwitchConnectionHandler {
+    
+    /**
+     * @param connection to switch proving message sending/receiving, connection management
+     */
+    public void onSwitchConnected(ConnectionAdapter connection);
+    
+    /**
+     * @param switchAddress
+     * @return true, if connection from switch having given address shell be accepted; false otherwise
+     */
+    public boolean accept(InetAddress switchAddress);
+
+}
index d4677833d7388571a608036e5fac1a1a8d0ad3c4..659cc64118ccbc96cddb3c6c2d99bbce0a7996ec 100644 (file)
             <artifactId>openflow-protocol-spi</artifactId>
             <version>${project.version}</version>
         </dependency>
+        <dependency>
+            <groupId>org.opendaylight.controller</groupId>
+            <artifactId>sal-common-util</artifactId>
+            <version>${yang.prototype.version}</version>
+        </dependency>
         <dependency>
             <groupId>io.netty</groupId>
             <artifactId>netty-all</artifactId>
diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/connection/ConnectionAdapterFactory.java b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/connection/ConnectionAdapterFactory.java
new file mode 100644 (file)
index 0000000..2ca3dec
--- /dev/null
@@ -0,0 +1,31 @@
+/**
+ * Copyright (c) 2013 Cisco Systems, Inc. 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.connection;
+
+import io.netty.channel.socket.SocketChannel;
+
+import org.opendaylight.openflowjava.protocol.api.connection.ConnectionAdapter;
+
+/**
+ * @author mirehak
+ *
+ */
+public abstract class ConnectionAdapterFactory {
+
+    /**
+     * @param ch
+     * @return connection adapter tcp-implementation
+     */
+    public static ConnectionAdapter createConnectionAdapter(SocketChannel ch) {
+        ConnectionAdapterImpl connectionAdapter = new ConnectionAdapterImpl();
+        connectionAdapter.setChannel(ch);
+        return connectionAdapter;
+    }
+
+}
diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/connection/ConnectionAdapterImpl.java b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/connection/ConnectionAdapterImpl.java
new file mode 100644 (file)
index 0000000..076cc4a
--- /dev/null
@@ -0,0 +1,285 @@
+/**
+ * Copyright (c) 2013 Cisco Systems, Inc. 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.connection;
+
+import io.netty.channel.Channel;
+import io.netty.channel.ChannelFuture;
+import io.netty.util.concurrent.GenericFutureListener;
+
+import java.util.Collection;
+import java.util.concurrent.Future;
+
+import org.opendaylight.controller.sal.common.util.Rpcs;
+import org.opendaylight.openflowjava.protocol.api.connection.ConnectionAdapter;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.BarrierInput;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.BarrierOutput;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.EchoInput;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.EchoOutput;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.EchoReplyInput;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.ExperimenterInput;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.FlowModInput;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.GetConfigInput;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.GetConfigOutput;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.GetFeaturesInput;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.GetFeaturesOutput;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.GetQueueConfigInput;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.GetQueueConfigOutput;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.GroupModInput;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.HelloInput;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MeterModInput;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.OpenflowProtocolListener;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PacketOutInput;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PortModInput;
+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.SetConfigInput;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.TableModInput;
+import org.opendaylight.yangtools.yang.common.RpcError;
+import org.opendaylight.yangtools.yang.common.RpcError.ErrorSeverity;
+import org.opendaylight.yangtools.yang.common.RpcResult;
+
+import com.google.common.collect.Lists;
+import com.google.common.util.concurrent.SettableFuture;
+
+/**
+ * @author mirehak
+ *
+ */
+public class ConnectionAdapterImpl implements ConnectionAdapter {
+    
+    private static final String APPLICATION_TAG = "OPENFLOW_LIBRARY";
+    private static final String TAG = "OPENFLOW";
+    private Channel channel;
+    private OpenflowProtocolListener messageListener;
+    
+    /**
+     * @param channel the channel to set
+     */
+    public void setChannel(Channel channel) {
+        this.channel = channel;
+    }
+
+    @Override
+    public Future<RpcResult<BarrierOutput>> barrier(BarrierInput input) {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+    @Override
+    public Future<RpcResult<EchoOutput>> echo(EchoInput input) {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+    @Override
+    public Future<RpcResult<Void>> echoReply(EchoReplyInput input) {
+        return sendToSwitchFuture(input, "echo reply sending failed");
+    }
+
+    @Override
+    public Future<RpcResult<Void>> experimenter(ExperimenterInput input) {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+    @Override
+    public Future<RpcResult<Void>> flowMod(FlowModInput input) {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+    @Override
+    public Future<RpcResult<GetConfigOutput>> getConfig(GetConfigInput input) {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+    @Override
+    public Future<RpcResult<GetFeaturesOutput>> getFeatures(
+            GetFeaturesInput input) {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+    @Override
+    public Future<RpcResult<GetQueueConfigOutput>> getQueueConfig(
+            GetQueueConfigInput input) {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+    @Override
+    public Future<RpcResult<Void>> groupMod(GroupModInput input) {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+    @Override
+    public Future<RpcResult<Void>> hello(HelloInput input) {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+    @Override
+    public Future<RpcResult<Void>> meterMod(MeterModInput input) {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+    @Override
+    public Future<RpcResult<Void>> packetOut(PacketOutInput input) {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+    @Override
+    public Future<RpcResult<Void>> portMod(PortModInput input) {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+    @Override
+    public Future<RpcResult<RoleRequestOutput>> roleRequest(
+            RoleRequestInput input) {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+    @Override
+    public Future<RpcResult<Void>> setConfig(SetConfigInput input) {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+    @Override
+    public Future<RpcResult<Void>> tableMod(TableModInput input) {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+    @Override
+    public Future<Boolean> disconnect() {
+        ChannelFuture disconnectResult = channel.disconnect();
+        
+        String failureInfo = "switch disconnecting failed";
+        ErrorSeverity errorSeverity = ErrorSeverity.ERROR;
+        String message = "Check the switch connection";
+        return handleTransportChannelFuture(disconnectResult, failureInfo, errorSeverity, message);
+    }
+
+    @Override
+    public boolean isAlive() {
+        return channel.isOpen();
+    }
+
+    @Override
+    public void setMessageListener(OpenflowProtocolListener messageListener) {
+        this.messageListener = messageListener;
+    }
+
+    /**
+     * @param input
+     * @return
+     */
+    private SettableFuture<RpcResult<Void>> sendToSwitchFuture(
+            EchoReplyInput input, final String failureInfo) {
+        ChannelFuture resultFuture = channel.writeAndFlush(input);
+        
+        ErrorSeverity errorSeverity = ErrorSeverity.ERROR;
+        String message = "check switch connection";
+        return handleRpcChannelFuture(resultFuture, failureInfo, errorSeverity, message);
+    }
+
+    /**
+     * @param resultFuture
+     * @param failureInfo
+     * @return
+     */
+    private SettableFuture<RpcResult<Void>> handleRpcChannelFuture(
+            ChannelFuture resultFuture, final String failureInfo, 
+            final ErrorSeverity errorSeverity, final String message) {
+        
+        final SettableFuture<RpcResult<Void>> rpcResult = 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)
+                    throws Exception {
+                Collection<RpcError> errors = null;
+                
+                if (future.cause() != null) {
+                    RpcError rpcError = buildRpcError(failureInfo, 
+                            errorSeverity, message, future.cause());
+                    errors = Lists.newArrayList(rpcError);
+                }
+                
+                rpcResult.set(Rpcs.getRpcResult(
+                        future.isSuccess(), 
+                        (Void) null, 
+                        errors)
+                );
+            }
+        });
+        return rpcResult;
+    }
+    
+    /**
+     * @param resultFuture
+     * @param failureInfo
+     * @return
+     */
+    private SettableFuture<Boolean> handleTransportChannelFuture(
+            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)
+                    throws Exception {
+                transportResult.set(future.isSuccess());
+            }
+        });
+        return transportResult;
+    }
+
+    /**
+     * @param cause
+     * @return
+     */
+    protected RpcError buildRpcError(String info, ErrorSeverity severity, String message, 
+            Throwable cause) {
+        // TODO - uncomment, when sal-common-util merged
+//        RpcError error = RpcErrors.getRpcError(APPLICATION_TAG, TAG, info, severity, message, 
+//                ErrorType.RPC, cause);
+//        return error;
+        
+        return null;
+    }
+    
+    /**
+     * @param cause
+     * @return
+     */
+    protected RpcError buildTransportError(String info, ErrorSeverity severity, String message, 
+            Throwable cause) {
+        // TODO - uncomment, when sal-common-util merged
+//        RpcError error = RpcErrors.getRpcError(APPLICATION_TAG, TAG, info, severity, message, 
+//                ErrorType.TRANSPORT, cause);
+//        return error;
+        
+        return null;
+    }
+
+}
diff --git a/openflow-protocol-spi/src/main/java/org/opendaylight/openflowjava/protocol/spi/connection/SwitchConnectionProvider.java b/openflow-protocol-spi/src/main/java/org/opendaylight/openflowjava/protocol/spi/connection/SwitchConnectionProvider.java
new file mode 100644 (file)
index 0000000..c6f8ba4
--- /dev/null
@@ -0,0 +1,46 @@
+/**
+ * Copyright (c) 2013 Cisco Systems, Inc. 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.spi.connection;
+
+import java.util.concurrent.Future;
+
+import org.opendaylight.openflowjava.protocol.api.connection.SwitchConnectionHandler;
+
+/**
+ * @author mirehak
+ *
+ */
+public interface SwitchConnectionProvider {
+
+    /**
+     * @param configuration contains protocols, ports, addresses and similar connection parameters
+     * TODO - create configuration interface proposal
+     */
+    public void configure(Object configuration);
+    
+    /**
+     * start listening to switches, but please don't forget to do
+     * {@link #setSwitchConnectionListener(SwitchConnectionHandler)} first
+     * @return future, triggered to true, when all listening channels are up and running
+     */
+    public Future<Boolean> startup();
+    
+    /**
+     * stop listening to switches
+     * @return future, triggered to true, when all listening channels are down
+     */
+    public Future<Boolean> shutdown();
+    
+    
+    /**
+     * @param switchConListener instance being informed when new switch connects
+     */
+    public void setSwitchConnectionListener(SwitchConnectionHandler switchConListener);
+    
+}
diff --git a/pom.xml b/pom.xml
index 71e2ee36d3d8358b06fe901ff82f52d0ffba5c1f..ff99572be59223e705f358ba9d7c5dfff4d783f7 100644 (file)
--- a/pom.xml
+++ b/pom.xml
@@ -29,6 +29,7 @@
         <sonar.skippedModules>org.openflow.openflowj,net.sf.jung2</sonar.skippedModules>
         <logback.version>1.0.9</logback.version>
         <slf4j.version>1.7.2</slf4j.version>
+       <yang.prototype.version>1.0-SNAPSHOT</yang.prototype.version>
     </properties>
 
     <pluginRepositories>