blob: 09a2a99ca401707c65e7b675b7d52a08ce4b0234 [file] [log] [blame]
Thomas Vachuska4f1a60c2014-10-28 13:39:07 -07001/*
Brian O'Connor5ab426f2016-04-09 01:19:45 -07002 * Copyright 2014-present Open Networking Laboratory
Thomas Vachuska4f1a60c2014-10-28 13:39:07 -07003 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
Brian O'Connorabafb502014-12-02 22:26:20 -080016package org.onosproject.cluster;
tome4729872014-09-23 00:37:37 -070017
Pavlin Radoslavov444b5192014-10-28 10:45:19 -070018import org.onlab.packet.IpAddress;
tome4729872014-09-23 00:37:37 -070019
20import java.util.Objects;
21
22import static com.google.common.base.MoreObjects.toStringHelper;
HIGUCHI Yutaca9cc8e2015-10-29 23:26:51 -070023import static com.google.common.base.Preconditions.checkNotNull;
tome4729872014-09-23 00:37:37 -070024
25/**
26 * Default implementation of a controller instance descriptor.
27 */
28public class DefaultControllerNode implements ControllerNode {
29
Thomas Vachuskade563cf2015-04-01 00:28:50 -070030 public static final int DEFAULT_PORT = 9876;
tomee49c372014-09-26 15:14:50 -070031
tome4729872014-09-23 00:37:37 -070032 private final NodeId id;
Pavlin Radoslavov444b5192014-10-28 10:45:19 -070033 private final IpAddress ip;
tomee49c372014-09-26 15:14:50 -070034 private final int tcpPort;
tome4729872014-09-23 00:37:37 -070035
tom2d7c65f2014-09-23 01:09:35 -070036 // For serialization
37 private DefaultControllerNode() {
38 this.id = null;
39 this.ip = null;
tomee49c372014-09-26 15:14:50 -070040 this.tcpPort = 0;
tom2d7c65f2014-09-23 01:09:35 -070041 }
42
tome4729872014-09-23 00:37:37 -070043 /**
44 * Creates a new instance with the specified id and IP address.
45 *
46 * @param id instance identifier
47 * @param ip instance IP address
48 */
Pavlin Radoslavov444b5192014-10-28 10:45:19 -070049 public DefaultControllerNode(NodeId id, IpAddress ip) {
tomee49c372014-09-26 15:14:50 -070050 this(id, ip, DEFAULT_PORT);
51 }
52
53 /**
54 * Creates a new instance with the specified id and IP address and TCP port.
55 *
56 * @param id instance identifier
57 * @param ip instance IP address
Yuta HIGUCHI5c947272014-11-03 21:39:21 -080058 * @param tcpPort TCP port
tomee49c372014-09-26 15:14:50 -070059 */
Pavlin Radoslavov444b5192014-10-28 10:45:19 -070060 public DefaultControllerNode(NodeId id, IpAddress ip, int tcpPort) {
HIGUCHI Yutaca9cc8e2015-10-29 23:26:51 -070061 this.id = checkNotNull(id);
tome4729872014-09-23 00:37:37 -070062 this.ip = ip;
tomee49c372014-09-26 15:14:50 -070063 this.tcpPort = tcpPort;
tome4729872014-09-23 00:37:37 -070064 }
65
66 @Override
67 public NodeId id() {
68 return id;
69 }
70
71 @Override
Pavlin Radoslavov444b5192014-10-28 10:45:19 -070072 public IpAddress ip() {
tome4729872014-09-23 00:37:37 -070073 return ip;
74 }
75
76 @Override
tomee49c372014-09-26 15:14:50 -070077 public int tcpPort() {
78 return tcpPort;
79 }
80
81 @Override
tome4729872014-09-23 00:37:37 -070082 public int hashCode() {
HIGUCHI Yutaca9cc8e2015-10-29 23:26:51 -070083 return id.hashCode();
tome4729872014-09-23 00:37:37 -070084 }
85
86 @Override
87 public boolean equals(Object o) {
88 if (this == o) {
89 return true;
90 }
91 if (o instanceof DefaultControllerNode) {
92 DefaultControllerNode that = (DefaultControllerNode) o;
93 return Objects.equals(this.id, that.id);
94 }
95 return false;
96 }
97
98 @Override
99 public String toString() {
tomee49c372014-09-26 15:14:50 -0700100 return toStringHelper(this).add("id", id)
101 .add("ip", ip).add("tcpPort", tcpPort).toString();
tome4729872014-09-23 00:37:37 -0700102 }
103
104}