blob: 6cb4f2419e97f9e0035dddfe13e8b2ab41ead29c [file] [log] [blame]
tome4729872014-09-23 00:37:37 -07001package org.onlab.onos.cluster;
2
Pavlin Radoslavov444b5192014-10-28 10:45:19 -07003import org.onlab.packet.IpAddress;
tome4729872014-09-23 00:37:37 -07004
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;
Pavlin Radoslavov444b5192014-10-28 10:45:19 -070017 private final IpAddress 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 */
Pavlin Radoslavov444b5192014-10-28 10:45:19 -070033 public DefaultControllerNode(NodeId id, IpAddress 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 */
Pavlin Radoslavov444b5192014-10-28 10:45:19 -070043 public DefaultControllerNode(NodeId id, IpAddress 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
Pavlin Radoslavov444b5192014-10-28 10:45:19 -070055 public IpAddress ip() {
tome4729872014-09-23 00:37:37 -070056 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}