blob: 4ed972fe7057631cfac532afb87f994354805f03 [file] [log] [blame]
Thomas Vachuska4f1a60c2014-10-28 13:39:07 -07001/*
2 * Copyright 2014 Open Networking Laboratory
3 *
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 */
tome4729872014-09-23 00:37:37 -070016package org.onlab.onos.cluster;
17
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;
23
24/**
25 * Default implementation of a controller instance descriptor.
26 */
27public class DefaultControllerNode implements ControllerNode {
28
tomee49c372014-09-26 15:14:50 -070029 private static final int DEFAULT_PORT = 9876;
30
tome4729872014-09-23 00:37:37 -070031 private final NodeId id;
Pavlin Radoslavov444b5192014-10-28 10:45:19 -070032 private final IpAddress ip;
tomee49c372014-09-26 15:14:50 -070033 private final int tcpPort;
tome4729872014-09-23 00:37:37 -070034
tom2d7c65f2014-09-23 01:09:35 -070035 // For serialization
36 private DefaultControllerNode() {
37 this.id = null;
38 this.ip = null;
tomee49c372014-09-26 15:14:50 -070039 this.tcpPort = 0;
tom2d7c65f2014-09-23 01:09:35 -070040 }
41
tome4729872014-09-23 00:37:37 -070042 /**
43 * Creates a new instance with the specified id and IP address.
44 *
45 * @param id instance identifier
46 * @param ip instance IP address
47 */
Pavlin Radoslavov444b5192014-10-28 10:45:19 -070048 public DefaultControllerNode(NodeId id, IpAddress ip) {
tomee49c372014-09-26 15:14:50 -070049 this(id, ip, DEFAULT_PORT);
50 }
51
52 /**
53 * Creates a new instance with the specified id and IP address and TCP port.
54 *
55 * @param id instance identifier
56 * @param ip instance IP address
Yuta HIGUCHI5c947272014-11-03 21:39:21 -080057 * @param tcpPort TCP port
tomee49c372014-09-26 15:14:50 -070058 */
Pavlin Radoslavov444b5192014-10-28 10:45:19 -070059 public DefaultControllerNode(NodeId id, IpAddress ip, int tcpPort) {
tome4729872014-09-23 00:37:37 -070060 this.id = id;
61 this.ip = ip;
tomee49c372014-09-26 15:14:50 -070062 this.tcpPort = tcpPort;
tome4729872014-09-23 00:37:37 -070063 }
64
65 @Override
66 public NodeId id() {
67 return id;
68 }
69
70 @Override
Pavlin Radoslavov444b5192014-10-28 10:45:19 -070071 public IpAddress ip() {
tome4729872014-09-23 00:37:37 -070072 return ip;
73 }
74
75 @Override
tomee49c372014-09-26 15:14:50 -070076 public int tcpPort() {
77 return tcpPort;
78 }
79
80 @Override
tome4729872014-09-23 00:37:37 -070081 public int hashCode() {
82 return Objects.hash(id);
83 }
84
85 @Override
86 public boolean equals(Object o) {
87 if (this == o) {
88 return true;
89 }
90 if (o instanceof DefaultControllerNode) {
91 DefaultControllerNode that = (DefaultControllerNode) o;
92 return Objects.equals(this.id, that.id);
93 }
94 return false;
95 }
96
97 @Override
98 public String toString() {
tomee49c372014-09-26 15:14:50 -070099 return toStringHelper(this).add("id", id)
100 .add("ip", ip).add("tcpPort", tcpPort).toString();
tome4729872014-09-23 00:37:37 -0700101 }
102
103}