2 * Copyright (C) 2014 Red Hat, Inc.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
8 * Authors : Madhu Venugopal
11 package org.opendaylight.ovsdb.lib;
13 import io.netty.channel.Channel;
15 import java.net.InetAddress;
16 import java.net.InetSocketAddress;
18 import javax.xml.bind.annotation.XmlElement;
19 import javax.xml.bind.annotation.XmlRootElement;
20 import javax.xml.bind.annotation.XmlTransient;
22 @XmlRootElement(name="Connection")
23 public class OvsdbConnectionInfo {
24 public enum ConnectionType {
29 private Channel channel;
31 private ConnectionType type;
33 public OvsdbConnectionInfo(Channel channel, ConnectionType type) {
34 this.channel = channel;
38 @XmlElement(name="remoteAddress")
39 public InetAddress getRemoteAddress() {
40 return ((InetSocketAddress)channel.remoteAddress()).getAddress();
42 @XmlElement(name="remotePort")
43 public int getRemotePort() {
44 return ((InetSocketAddress)channel.remoteAddress()).getPort();
46 @XmlElement(name="localAddress")
47 public InetAddress getLocalAddress() {
48 return ((InetSocketAddress)channel.localAddress()).getAddress();
50 @XmlElement(name="localPort")
51 public int getLocalPort() {
52 return ((InetSocketAddress)channel.localAddress()).getPort();
54 @XmlElement(name="connectionType")
55 public ConnectionType getType() {
60 public int hashCode() {
63 result = prime * result + ((channel == null) ? 0 : getRemoteAddress().hashCode());
64 result = prime * result + ((type == null) ? 0 : getRemotePort());
65 result = prime * result + ((channel == null) ? 0 : getLocalAddress().hashCode());
66 result = prime * result + ((type == null) ? 0 : getLocalPort());
71 public boolean equals(Object obj) {
76 if (getClass() != obj.getClass())
78 OvsdbConnectionInfo other = (OvsdbConnectionInfo) obj;
79 if (channel == null) {
80 if (other.channel != null)
82 } else if (!getRemoteAddress().equals(other.getRemoteAddress())) {
84 } else if (!getLocalAddress().equals(other.getLocalAddress())) {
86 } else if (getRemotePort() != other.getRemotePort()) {
88 } else if (getLocalPort() != other.getLocalPort()) {
91 if (type != other.type)
97 public String toString() {
98 return "ConnectionInfo [Remote-address=" + this.getRemoteAddress().getHostAddress() +
99 ", Remote-port=" + this.getRemotePort() +
100 ", Local-address" + this.getLocalAddress().getHostAddress() +
101 ", Local-port=" + this.getLocalPort() +
102 ", type=" + type + "]";