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;
* 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 <mbobak@cisco.com> on 25.2.2015.
*/
public interface ConnectionContext {
* change internal state to {@link ConnectionContext.CONNECTION_STATE#WORKING}
*/
void changeStateToWorking();
+
+ /**
+ * Create and return basic device info
+ * @return
+ */
+ DeviceInfo gainDeviceInfo();
}
--- /dev/null
+/*
+ * 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();
+
+}
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;
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;
+ }
+ }
}