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;
17 public class OvsdbConnectionInfo {
18 public enum ConnectionType {
22 private Channel channel;
23 private ConnectionType type;
25 public OvsdbConnectionInfo(Channel channel, ConnectionType type) {
26 this.channel = channel;
30 public InetAddress getRemoteAddress() {
31 return ((InetSocketAddress)channel.remoteAddress()).getAddress();
33 public int getRemotePort() {
34 return ((InetSocketAddress)channel.remoteAddress()).getPort();
37 public InetAddress getLocalAddress() {
38 return ((InetSocketAddress)channel.localAddress()).getAddress();
40 public int getLocalPort() {
41 return ((InetSocketAddress)channel.localAddress()).getPort();
44 public ConnectionType getType() {
49 public int hashCode() {
52 result = prime * result + ((channel == null) ? 0 : getRemoteAddress().hashCode());
53 result = prime * result + ((type == null) ? 0 : getRemotePort());
54 result = prime * result + ((channel == null) ? 0 : getLocalAddress().hashCode());
55 result = prime * result + ((type == null) ? 0 : getLocalPort());
60 public boolean equals(Object obj) {
65 if (getClass() != obj.getClass())
67 OvsdbConnectionInfo other = (OvsdbConnectionInfo) obj;
68 if (channel == null) {
69 if (other.channel != null)
71 } else if (!getRemoteAddress().equals(other.getRemoteAddress())) {
73 } else if (!getLocalAddress().equals(other.getLocalAddress())) {
75 } else if (getRemotePort() != other.getRemotePort()) {
77 } else if (getLocalPort() != other.getLocalPort()) {
80 if (type != other.type)
86 public String toString() {
87 return "ConnectionInfo [Remote-address=" + this.getRemoteAddress().getHostAddress() +
88 ", Remote-port=" + this.getRemotePort() +
89 ", Local-address" + this.getLocalAddress().getHostAddress() +
90 ", Local-port=" + this.getLocalPort() +
91 ", type=" + type + "]";