Merge "Device Info API"
authormichal rehak <mirehak@cisco.com>
Tue, 21 Jun 2016 08:59:33 +0000 (08:59 +0000)
committerGerrit Code Review <gerrit@opendaylight.org>
Tue, 21 Jun 2016 08:59:33 +0000 (08:59 +0000)
openflowplugin-api/src/main/java/org/opendaylight/openflowplugin/api/openflow/connection/ConnectionContext.java
openflowplugin-api/src/main/java/org/opendaylight/openflowplugin/api/openflow/device/DeviceContext.java
openflowplugin-api/src/main/java/org/opendaylight/openflowplugin/api/openflow/device/DeviceInfo.java [new file with mode: 0644]
openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/connection/ConnectionContextImpl.java

index 839541d4e3193300d3884edc3ea28dffc290a94c..4a9cb65d282dab97ef6bad347aa3d7ee5fc49781 100644 (file)
@@ -11,6 +11,7 @@ package org.opendaylight.openflowplugin.api.openflow.connection;
 import org.opendaylight.openflowjava.protocol.api.connection.ConnectionAdapter;
 import org.opendaylight.openflowjava.protocol.api.connection.OutboundQueue;
 import org.opendaylight.openflowjava.protocol.api.connection.OutboundQueueHandlerRegistration;
+import org.opendaylight.openflowplugin.api.openflow.device.DeviceInfo;
 import org.opendaylight.openflowplugin.api.openflow.device.handlers.DeviceDisconnectedHandler;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.FeaturesReply;
@@ -20,7 +21,6 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731
  * Each OpenFlow session is tracked by a Connection Context. These attach to a particular Device Context in such a way,
  * that there is at most one primary session associated with a Device Context.
  * </p>
- * Created by Martin Bobak &lt;mbobak@cisco.com&gt; on 25.2.2015.
  */
 public interface ConnectionContext {
 
@@ -136,4 +136,10 @@ public interface ConnectionContext {
      * change internal state to {@link ConnectionContext.CONNECTION_STATE#WORKING}
      */
     void changeStateToWorking();
+
+    /**
+     * Create and return basic device info
+     * @return
+     */
+    DeviceInfo gainDeviceInfo();
 }
index b2c70f70535cd40d58c6e22fb07a6199f927c3af..81c2ce6f454a3b9eba016b85a769f998965e8ab6 100644 (file)
@@ -43,7 +43,6 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.role.service.rev150727.OfpR
  * Context can have at any point in time. Should this quota be exceeded, any further attempt to make
  * a request to the switch will fail immediately, with proper error indication.
  * </p>
- * Created by Martin Bobak &lt;mbobak@cisco.com&gt; on 25.2.2015.
  */
 public interface DeviceContext extends AutoCloseable,
         DeviceReplyProcessor,
diff --git a/openflowplugin-api/src/main/java/org/opendaylight/openflowplugin/api/openflow/device/DeviceInfo.java b/openflowplugin-api/src/main/java/org/opendaylight/openflowplugin/api/openflow/device/DeviceInfo.java
new file mode 100644 (file)
index 0000000..af59666
--- /dev/null
@@ -0,0 +1,49 @@
+/*
+ * Copyright (c) 2015 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.openflowplugin.api.openflow.device;
+
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.IpAddress;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeKey;
+import org.opendaylight.yangtools.yang.binding.KeyedInstanceIdentifier;
+
+import java.math.BigInteger;
+
+/**
+ * API defining basic device information
+ */
+public interface DeviceInfo {
+
+    /**
+     * @return id of encapsulated node
+     */
+    NodeId getNodeId();
+
+    /**
+     * @return {@link Node} instance identifier
+     */
+    KeyedInstanceIdentifier<Node, NodeKey> getNodeInstanceIdentifier();
+
+    /**
+     * @return version
+     */
+    Short getVersion();
+
+    /**
+     * @return datapathId
+     */
+    BigInteger getDatapathId();
+
+    /**
+     * @return IP adress
+     */
+    IpAddress getIpAddress();
+
+}
index 191ea623ff3315e0dfc397a9cb1f1c03008bcbe1..bb5678138d432fa5c2d197c4879093c85c1be826 100644 (file)
@@ -23,10 +23,17 @@ import org.opendaylight.openflowjava.protocol.api.connection.OutboundQueueHandle
 import org.opendaylight.openflowplugin.api.openflow.connection.ConnectionContext;
 import org.opendaylight.openflowplugin.api.openflow.connection.HandshakeContext;
 import org.opendaylight.openflowplugin.api.openflow.connection.OutboundQueueProvider;
+import org.opendaylight.openflowplugin.api.openflow.device.DeviceInfo;
 import org.opendaylight.openflowplugin.api.openflow.device.handlers.DeviceDisconnectedHandler;
 import org.opendaylight.openflowplugin.impl.statistics.ofpspecific.SessionStatistics;
+import org.opendaylight.openflowplugin.impl.util.DeviceStateUtil;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.IetfInetUtil;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.IpAddress;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeKey;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.FeaturesReply;
+import org.opendaylight.yangtools.yang.binding.KeyedInstanceIdentifier;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -219,8 +226,95 @@ public class ConnectionContextImpl implements ConnectionContext {
         connectionState = CONNECTION_STATE.WORKING;
     }
 
+    @Override
+    public DeviceInfo gainDeviceInfo() {
+        return new DeviceInfoImpl(
+                nodeId,
+                DeviceStateUtil.createNodeInstanceIdentifier(nodeId),
+                featuresReply.getVersion(),
+                featuresReply.getDatapathId(),
+                IetfInetUtil.INSTANCE.ipAddressFor(connectionAdapter.getRemoteAddress().getAddress()));
+    }
+
     @Override
     public void setHandshakeContext(HandshakeContext handshakeContext) {
         this.handshakeContext = handshakeContext;
     }
+
+
+    private class DeviceInfoImpl implements DeviceInfo {
+
+        final private NodeId nodeId;
+        final private KeyedInstanceIdentifier<Node, NodeKey> nodeII;
+        final private Short version;
+        final private BigInteger datapathId;
+        final private IpAddress ipAddress;
+        private boolean valid;
+        private boolean sync;
+
+        DeviceInfoImpl(
+                final NodeId nodeId,
+                final KeyedInstanceIdentifier<Node, NodeKey> nodeII,
+                final Short version,
+                final BigInteger datapathId,
+                final IpAddress ipAddress) {
+            this.nodeId = nodeId;
+            this.nodeII = nodeII;
+            this.version = version;
+            this.datapathId = datapathId;
+            this.ipAddress = ipAddress;
+            this.valid = false;
+            this.sync = false;
+        }
+
+        @Override
+        public NodeId getNodeId() {
+            return nodeId;
+        }
+
+        @Override
+        public KeyedInstanceIdentifier<Node, NodeKey> getNodeInstanceIdentifier() {
+            return nodeII;
+        }
+
+        @Override
+        public Short getVersion() {
+            return version;
+        }
+
+        @Override
+        public BigInteger getDatapathId() {
+            return datapathId;
+        }
+
+        @Override
+        public IpAddress getIpAddress() {
+            return null;
+        }
+
+        @Override
+        public boolean equals(Object o) {
+            if (this == o) return true;
+            if (o == null || getClass() != o.getClass()) return false;
+
+            DeviceInfoImpl that = (DeviceInfoImpl) o;
+
+            if (!nodeId.equals(that.nodeId)) return false;
+            if (!nodeII.equals(that.nodeII)) return false;
+            if (!version.equals(that.version)) return false;
+            if (!datapathId.equals(that.datapathId)) return false;
+            return ipAddress.equals(that.ipAddress);
+
+        }
+
+        @Override
+        public int hashCode() {
+            int result = nodeId.hashCode();
+            result = 31 * result + nodeII.hashCode();
+            result = 31 * result + version.hashCode();
+            result = 31 * result + datapathId.hashCode();
+            result = 31 * result + ipAddress.hashCode();
+            return result;
+        }
+    }
 }