blob: d23b7a32bbf9e93bc6520170bc236a1245ab7060 [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
tomee49c372014-09-26 15:14:50 -070014 private static final int DEFAULT_PORT = 9876;
15
tome4729872014-09-23 00:37:37 -070016 private final NodeId id;
17 private final IpPrefix ip;
tomee49c372014-09-26 15:14:50 -070018 private final int tcpPort;
tome4729872014-09-23 00:37:37 -070019
tom2d7c65f2014-09-23 01:09:35 -070020 // For serialization
21 private DefaultControllerNode() {
22 this.id = null;
23 this.ip = null;
tomee49c372014-09-26 15:14:50 -070024 this.tcpPort = 0;
tom2d7c65f2014-09-23 01:09:35 -070025 }
26
tome4729872014-09-23 00:37:37 -070027 /**
28 * Creates a new instance with the specified id and IP address.
29 *
30 * @param id instance identifier
31 * @param ip instance IP address
32 */
33 public DefaultControllerNode(NodeId id, IpPrefix ip) {
tomee49c372014-09-26 15:14:50 -070034 this(id, ip, DEFAULT_PORT);
35 }
36
37 /**
38 * Creates a new instance with the specified id and IP address and TCP port.
39 *
40 * @param id instance identifier
41 * @param ip instance IP address
42 */
43 public DefaultControllerNode(NodeId id, IpPrefix ip, int tcpPort) {
tome4729872014-09-23 00:37:37 -070044 this.id = id;
45 this.ip = ip;
tomee49c372014-09-26 15:14:50 -070046 this.tcpPort = tcpPort;
tome4729872014-09-23 00:37:37 -070047 }
48
49 @Override
50 public NodeId id() {
51 return id;
52 }
53
54 @Override
55 public IpPrefix ip() {
56 return ip;
57 }
58
59 @Override
tomee49c372014-09-26 15:14:50 -070060 public int tcpPort() {
61 return tcpPort;
62 }
63
64 @Override
tome4729872014-09-23 00:37:37 -070065 public int hashCode() {
66 return Objects.hash(id);
67 }
68
69 @Override
70 public boolean equals(Object o) {
71 if (this == o) {
72 return true;
73 }
74 if (o instanceof DefaultControllerNode) {
75 DefaultControllerNode that = (DefaultControllerNode) o;
76 return Objects.equals(this.id, that.id);
77 }
78 return false;
79 }
80
81 @Override
82 public String toString() {
tomee49c372014-09-26 15:14:50 -070083 return toStringHelper(this).add("id", id)
84 .add("ip", ip).add("tcpPort", tcpPort).toString();
tome4729872014-09-23 00:37:37 -070085 }
86
87}