blob: 86ea14c09eeedec1db53789c80f9685ae6e8fb6e [file] [log] [blame]
tome4729872014-09-23 00:37:37 -07001package org.onlab.onos.cluster;
2
3import org.onlab.packet.IpPrefix;
4
5import java.util.Objects;
6
7import static com.google.common.base.MoreObjects.toStringHelper;
8
9/**
10 * Default implementation of a controller instance descriptor.
11 */
12public class DefaultControllerNode implements ControllerNode {
13
14 private final NodeId id;
15 private final IpPrefix ip;
16
tom2d7c65f2014-09-23 01:09:35 -070017 // For serialization
18 private DefaultControllerNode() {
19 this.id = null;
20 this.ip = null;
21 }
22
tome4729872014-09-23 00:37:37 -070023 /**
24 * Creates a new instance with the specified id and IP address.
25 *
26 * @param id instance identifier
27 * @param ip instance IP address
28 */
29 public DefaultControllerNode(NodeId id, IpPrefix ip) {
30 this.id = id;
31 this.ip = ip;
32 }
33
34 @Override
35 public NodeId id() {
36 return id;
37 }
38
39 @Override
40 public IpPrefix ip() {
41 return ip;
42 }
43
44 @Override
45 public int hashCode() {
46 return Objects.hash(id);
47 }
48
49 @Override
50 public boolean equals(Object o) {
51 if (this == o) {
52 return true;
53 }
54 if (o instanceof DefaultControllerNode) {
55 DefaultControllerNode that = (DefaultControllerNode) o;
56 return Objects.equals(this.id, that.id);
57 }
58 return false;
59 }
60
61 @Override
62 public String toString() {
63 return toStringHelper(this).add("id", id).add("ip", ip).toString();
64 }
65
66}