blob: 7f0809e26ecf20d0ee24fe04bb63a8ca9ec70172 [file] [log] [blame]
Hyunsun Moon8539b042015-11-07 22:08:43 -08001/*
Brian O'Connor5ab426f2016-04-09 01:19:45 -07002 * Copyright 2015-present Open Networking Laboratory
Hyunsun Moon8539b042015-11-07 22:08:43 -08003 *
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 */
16package org.onosproject.cordvtn;
17
18import com.google.common.base.MoreObjects;
Hyunsun Moon8539b042015-11-07 22:08:43 -080019import org.onlab.packet.TpPort;
20import org.onosproject.net.DeviceId;
21
22import java.util.Comparator;
23import java.util.Objects;
24
25import static com.google.common.base.Preconditions.checkNotNull;
26
27/**
28 * Representation of a compute infrastructure node for CORD VTN service.
29 */
30public final class CordVtnNode {
31
32 private final String hostname;
Hyunsun Moon133fd792016-02-09 01:55:48 -080033 private final NetworkAddress hostMgmtIp;
34 private final NetworkAddress localMgmtIp;
35 private final NetworkAddress dpIp;
Hyunsun Moon8539b042015-11-07 22:08:43 -080036 private final TpPort ovsdbPort;
Hyunsun Moon133fd792016-02-09 01:55:48 -080037 private final SshAccessInfo sshInfo;
Hyunsun Moon8539b042015-11-07 22:08:43 -080038 private final DeviceId bridgeId;
Hyunsun Moon133fd792016-02-09 01:55:48 -080039 private final String dpIntf;
Hyunsun Moonaf520d32016-03-07 16:37:17 -080040 private final CordVtnNodeState state;
Hyunsun Moon8539b042015-11-07 22:08:43 -080041
42 public static final Comparator<CordVtnNode> CORDVTN_NODE_COMPARATOR =
43 (node1, node2) -> node1.hostname().compareTo(node2.hostname());
44
45 /**
46 * Creates a new node.
47 *
48 * @param hostname hostname
Hyunsun Moon133fd792016-02-09 01:55:48 -080049 * @param hostMgmtIp host management network address
50 * @param localMgmtIp local management network address
51 * @param dpIp data plane network address
52 * @param ovsdbPort port number for OVSDB connection
53 * @param sshInfo SSH access information
Hyunsun Moon8539b042015-11-07 22:08:43 -080054 * @param bridgeId integration bridge identifier
Hyunsun Moon133fd792016-02-09 01:55:48 -080055 * @param dpIntf data plane interface name
Hyunsun Moonaf520d32016-03-07 16:37:17 -080056 * @param state cordvtn node state
Hyunsun Moon8539b042015-11-07 22:08:43 -080057 */
Hyunsun Moon133fd792016-02-09 01:55:48 -080058 public CordVtnNode(String hostname, NetworkAddress hostMgmtIp, NetworkAddress localMgmtIp,
59 NetworkAddress dpIp, TpPort ovsdbPort, SshAccessInfo sshInfo,
Hyunsun Moonaf520d32016-03-07 16:37:17 -080060 DeviceId bridgeId, String dpIntf, CordVtnNodeState state) {
Hyunsun Moon133fd792016-02-09 01:55:48 -080061 this.hostname = checkNotNull(hostname, "hostname cannot be null");
62 this.hostMgmtIp = checkNotNull(hostMgmtIp, "hostMgmtIp cannot be null");
63 this.localMgmtIp = checkNotNull(localMgmtIp, "localMgmtIp cannot be null");
64 this.dpIp = checkNotNull(dpIp, "dpIp cannot be null");
65 this.ovsdbPort = checkNotNull(ovsdbPort, "ovsdbPort cannot be null");
66 this.sshInfo = checkNotNull(sshInfo, "sshInfo cannot be null");
67 this.bridgeId = checkNotNull(bridgeId, "bridgeId cannot be null");
68 this.dpIntf = checkNotNull(dpIntf, "dpIntf cannot be null");
Hyunsun Moonaf520d32016-03-07 16:37:17 -080069 this.state = state;
70 }
71
72 /**
73 * Returns cordvtn node with new state.
74 *
75 * @param node cordvtn node
76 * @param state cordvtn node init state
77 * @return cordvtn node
78 */
79 public static CordVtnNode getUpdatedNode(CordVtnNode node, CordVtnNodeState state) {
80 return new CordVtnNode(node.hostname,
81 node.hostMgmtIp, node.localMgmtIp, node.dpIp,
82 node.ovsdbPort,
83 node.sshInfo,
84 node.bridgeId,
85 node.dpIntf, state);
Hyunsun Moon8539b042015-11-07 22:08:43 -080086 }
87
88 /**
89 * Returns the hostname.
90 *
91 * @return hostname
92 */
93 public String hostname() {
94 return this.hostname;
95 }
96
97 /**
Hyunsun Moon133fd792016-02-09 01:55:48 -080098 * Returns the host management network address.
99 *
100 * @return network address
101 */
102 public NetworkAddress hostMgmtIp() {
103 return this.hostMgmtIp;
104 }
105
106 /**
107 * Returns the local management network address.
108 *
109 * @return network address
110 */
111 public NetworkAddress localMgmtIp() {
112 return this.localMgmtIp;
113 }
114
115 /**
116 * Returns the data plane network address.
117 *
118 * @return network address
119 */
120 public NetworkAddress dpIp() {
121 return this.dpIp;
122 }
123
124 /**
125 * Returns the port number used for OVSDB connection.
126 *
127 * @return port number
128 */
129 public TpPort ovsdbPort() {
130 return this.ovsdbPort;
131 }
132
133 /**
134 * Returns the SSH access information.
135 *
136 * @return ssh access information
137 */
138 public SshAccessInfo sshInfo() {
139 return this.sshInfo;
140 }
141
142 /**
Hyunsun Moon8539b042015-11-07 22:08:43 -0800143 * Returns the identifier of the integration bridge.
144 *
145 * @return device id
146 */
147 public DeviceId intBrId() {
148 return this.bridgeId;
149 }
150
151 /**
152 * Returns the identifier of the OVSDB device.
153 *
154 * @return device id
155 */
156 public DeviceId ovsdbId() {
Hyunsun Moon133fd792016-02-09 01:55:48 -0800157 return DeviceId.deviceId("ovsdb:" + this.hostMgmtIp.ip().toString());
Hyunsun Moon8539b042015-11-07 22:08:43 -0800158 }
159
Hyunsun Moonb219fc42016-01-14 03:42:47 -0800160 /**
Hyunsun Moon133fd792016-02-09 01:55:48 -0800161 * Returns data plane interface name.
Hyunsun Moonb219fc42016-01-14 03:42:47 -0800162 *
Hyunsun Moon133fd792016-02-09 01:55:48 -0800163 * @return data plane interface name
Hyunsun Moonb219fc42016-01-14 03:42:47 -0800164 */
Hyunsun Moon133fd792016-02-09 01:55:48 -0800165 public String dpIntf() {
166 return this.dpIntf;
Hyunsun Moonb219fc42016-01-14 03:42:47 -0800167 }
168
Hyunsun Moonaf520d32016-03-07 16:37:17 -0800169 /**
170 * Returns the state of the node.
171 *
172 * @return state
173 */
174 public CordVtnNodeState state() {
175 return this.state;
176 }
177
Hyunsun Moon8539b042015-11-07 22:08:43 -0800178 @Override
179 public boolean equals(Object obj) {
180 if (this == obj) {
181 return true;
182 }
183
184 if (obj instanceof CordVtnNode) {
185 CordVtnNode that = (CordVtnNode) obj;
Hyunsun Moon80b03872016-03-10 12:40:16 -0800186 if (Objects.equals(hostname, that.hostname) &&
187 Objects.equals(hostMgmtIp, that.hostMgmtIp) &&
188 Objects.equals(localMgmtIp, that.localMgmtIp) &&
189 Objects.equals(dpIp, that.dpIp) &&
190 Objects.equals(ovsdbPort, that.ovsdbPort) &&
191 Objects.equals(sshInfo, that.sshInfo) &&
192 Objects.equals(bridgeId, that.bridgeId) &&
193 Objects.equals(dpIntf, that.dpIntf)) {
Hyunsun Moon8539b042015-11-07 22:08:43 -0800194 return true;
195 }
196 }
197 return false;
198 }
199
200 @Override
201 public int hashCode() {
Hyunsun Moon80b03872016-03-10 12:40:16 -0800202 return Objects.hash(hostname, hostMgmtIp, localMgmtIp, dpIp,
203 ovsdbPort, sshInfo, bridgeId, dpIntf);
Hyunsun Moon8539b042015-11-07 22:08:43 -0800204 }
205
206 @Override
207 public String toString() {
208 return MoreObjects.toStringHelper(getClass())
Hyunsun Moon133fd792016-02-09 01:55:48 -0800209 .add("hostname", hostname)
210 .add("hostMgmtIp", hostMgmtIp)
211 .add("localMgmtIp", localMgmtIp)
212 .add("dpIp", dpIp)
Hyunsun Moon8539b042015-11-07 22:08:43 -0800213 .add("port", ovsdbPort)
Hyunsun Moon133fd792016-02-09 01:55:48 -0800214 .add("sshInfo", sshInfo)
Hyunsun Moon8539b042015-11-07 22:08:43 -0800215 .add("bridgeId", bridgeId)
Hyunsun Moon133fd792016-02-09 01:55:48 -0800216 .add("dpIntf", dpIntf)
Hyunsun Moonaf520d32016-03-07 16:37:17 -0800217 .add("state", state)
Hyunsun Moon8539b042015-11-07 22:08:43 -0800218 .toString();
219 }
220}