blob: 9ae82372fceb9e09445b0249246ea429c427c28c [file] [log] [blame]
Hyunsun Moon8539b042015-11-07 22:08:43 -08001/*
2 * Copyright 2014-2015 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 */
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 Moon8539b042015-11-07 22:08:43 -080040
41 public static final Comparator<CordVtnNode> CORDVTN_NODE_COMPARATOR =
42 (node1, node2) -> node1.hostname().compareTo(node2.hostname());
43
44 /**
45 * Creates a new node.
46 *
47 * @param hostname hostname
Hyunsun Moon133fd792016-02-09 01:55:48 -080048 * @param hostMgmtIp host management network address
49 * @param localMgmtIp local management network address
50 * @param dpIp data plane network address
51 * @param ovsdbPort port number for OVSDB connection
52 * @param sshInfo SSH access information
Hyunsun Moon8539b042015-11-07 22:08:43 -080053 * @param bridgeId integration bridge identifier
Hyunsun Moon133fd792016-02-09 01:55:48 -080054 * @param dpIntf data plane interface name
Hyunsun Moon8539b042015-11-07 22:08:43 -080055 */
Hyunsun Moon133fd792016-02-09 01:55:48 -080056 public CordVtnNode(String hostname, NetworkAddress hostMgmtIp, NetworkAddress localMgmtIp,
57 NetworkAddress dpIp, TpPort ovsdbPort, SshAccessInfo sshInfo,
58 DeviceId bridgeId, String dpIntf) {
59 this.hostname = checkNotNull(hostname, "hostname cannot be null");
60 this.hostMgmtIp = checkNotNull(hostMgmtIp, "hostMgmtIp cannot be null");
61 this.localMgmtIp = checkNotNull(localMgmtIp, "localMgmtIp cannot be null");
62 this.dpIp = checkNotNull(dpIp, "dpIp cannot be null");
63 this.ovsdbPort = checkNotNull(ovsdbPort, "ovsdbPort cannot be null");
64 this.sshInfo = checkNotNull(sshInfo, "sshInfo cannot be null");
65 this.bridgeId = checkNotNull(bridgeId, "bridgeId cannot be null");
66 this.dpIntf = checkNotNull(dpIntf, "dpIntf cannot be null");
Hyunsun Moon8539b042015-11-07 22:08:43 -080067 }
68
69 /**
70 * Returns the hostname.
71 *
72 * @return hostname
73 */
74 public String hostname() {
75 return this.hostname;
76 }
77
78 /**
Hyunsun Moon133fd792016-02-09 01:55:48 -080079 * Returns the host management network address.
80 *
81 * @return network address
82 */
83 public NetworkAddress hostMgmtIp() {
84 return this.hostMgmtIp;
85 }
86
87 /**
88 * Returns the local management network address.
89 *
90 * @return network address
91 */
92 public NetworkAddress localMgmtIp() {
93 return this.localMgmtIp;
94 }
95
96 /**
97 * Returns the data plane network address.
98 *
99 * @return network address
100 */
101 public NetworkAddress dpIp() {
102 return this.dpIp;
103 }
104
105 /**
106 * Returns the port number used for OVSDB connection.
107 *
108 * @return port number
109 */
110 public TpPort ovsdbPort() {
111 return this.ovsdbPort;
112 }
113
114 /**
115 * Returns the SSH access information.
116 *
117 * @return ssh access information
118 */
119 public SshAccessInfo sshInfo() {
120 return this.sshInfo;
121 }
122
123 /**
Hyunsun Moon8539b042015-11-07 22:08:43 -0800124 * Returns the identifier of the integration bridge.
125 *
126 * @return device id
127 */
128 public DeviceId intBrId() {
129 return this.bridgeId;
130 }
131
132 /**
133 * Returns the identifier of the OVSDB device.
134 *
135 * @return device id
136 */
137 public DeviceId ovsdbId() {
Hyunsun Moon133fd792016-02-09 01:55:48 -0800138 return DeviceId.deviceId("ovsdb:" + this.hostMgmtIp.ip().toString());
Hyunsun Moon8539b042015-11-07 22:08:43 -0800139 }
140
Hyunsun Moonb219fc42016-01-14 03:42:47 -0800141 /**
Hyunsun Moon133fd792016-02-09 01:55:48 -0800142 * Returns data plane interface name.
Hyunsun Moonb219fc42016-01-14 03:42:47 -0800143 *
Hyunsun Moon133fd792016-02-09 01:55:48 -0800144 * @return data plane interface name
Hyunsun Moonb219fc42016-01-14 03:42:47 -0800145 */
Hyunsun Moon133fd792016-02-09 01:55:48 -0800146 public String dpIntf() {
147 return this.dpIntf;
Hyunsun Moonb219fc42016-01-14 03:42:47 -0800148 }
149
Hyunsun Moon8539b042015-11-07 22:08:43 -0800150 @Override
151 public boolean equals(Object obj) {
152 if (this == obj) {
153 return true;
154 }
155
Hyunsun Moon133fd792016-02-09 01:55:48 -0800156 // hostname here is a network hostname and it is intended to be
157 // unique throughout the service.
Hyunsun Moon8539b042015-11-07 22:08:43 -0800158 if (obj instanceof CordVtnNode) {
159 CordVtnNode that = (CordVtnNode) obj;
Hyunsun Moonb219fc42016-01-14 03:42:47 -0800160 if (Objects.equals(hostname, that.hostname)) {
Hyunsun Moon8539b042015-11-07 22:08:43 -0800161 return true;
162 }
163 }
164 return false;
165 }
166
167 @Override
168 public int hashCode() {
Daniel Parkc54ac762016-01-20 10:09:44 +0900169 return Objects.hash(hostname);
Hyunsun Moon8539b042015-11-07 22:08:43 -0800170 }
171
172 @Override
173 public String toString() {
174 return MoreObjects.toStringHelper(getClass())
Hyunsun Moon133fd792016-02-09 01:55:48 -0800175 .add("hostname", hostname)
176 .add("hostMgmtIp", hostMgmtIp)
177 .add("localMgmtIp", localMgmtIp)
178 .add("dpIp", dpIp)
Hyunsun Moon8539b042015-11-07 22:08:43 -0800179 .add("port", ovsdbPort)
Hyunsun Moon133fd792016-02-09 01:55:48 -0800180 .add("sshInfo", sshInfo)
Hyunsun Moon8539b042015-11-07 22:08:43 -0800181 .add("bridgeId", bridgeId)
Hyunsun Moon133fd792016-02-09 01:55:48 -0800182 .add("dpIntf", dpIntf)
Hyunsun Moon8539b042015-11-07 22:08:43 -0800183 .toString();
184 }
185}