blob: 3aee1a6d4a8a797e2aee07ca47831ea3afe2730e [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
57 */
Pavlin Radoslavov444b5192014-10-28 10:45:19 -070058 public DefaultControllerNode(NodeId id, IpAddress ip, int tcpPort) {
tome4729872014-09-23 00:37:37 -070059 this.id = id;
60 this.ip = ip;
tomee49c372014-09-26 15:14:50 -070061 this.tcpPort = tcpPort;
tome4729872014-09-23 00:37:37 -070062 }
63
64 @Override
65 public NodeId id() {
66 return id;
67 }
68
69 @Override
Pavlin Radoslavov444b5192014-10-28 10:45:19 -070070 public IpAddress ip() {
tome4729872014-09-23 00:37:37 -070071 return ip;
72 }
73
74 @Override
tomee49c372014-09-26 15:14:50 -070075 public int tcpPort() {
76 return tcpPort;
77 }
78
79 @Override
tome4729872014-09-23 00:37:37 -070080 public int hashCode() {
81 return Objects.hash(id);
82 }
83
84 @Override
85 public boolean equals(Object o) {
86 if (this == o) {
87 return true;
88 }
89 if (o instanceof DefaultControllerNode) {
90 DefaultControllerNode that = (DefaultControllerNode) o;
91 return Objects.equals(this.id, that.id);
92 }
93 return false;
94 }
95
96 @Override
97 public String toString() {
tomee49c372014-09-26 15:14:50 -070098 return toStringHelper(this).add("id", id)
99 .add("ip", ip).add("tcpPort", tcpPort).toString();
tome4729872014-09-23 00:37:37 -0700100 }
101
102}