Hyunsun Moon | 4edb017 | 2015-11-07 22:08:43 -0800 | [diff] [blame] | 1 | /* |
Brian O'Connor | 8e57fd5 | 2016-04-09 01:19:45 -0700 | [diff] [blame] | 2 | * Copyright 2015-present Open Networking Laboratory |
Hyunsun Moon | 4edb017 | 2015-11-07 22:08:43 -0800 | [diff] [blame] | 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 | */ |
Hyunsun Moon | f948020 | 2016-04-14 16:13:42 -0700 | [diff] [blame^] | 16 | package org.onosproject.cordvtn.api; |
Hyunsun Moon | 4edb017 | 2015-11-07 22:08:43 -0800 | [diff] [blame] | 17 | |
| 18 | import com.google.common.base.MoreObjects; |
Hyunsun Moon | 4edb017 | 2015-11-07 22:08:43 -0800 | [diff] [blame] | 19 | import org.onlab.packet.TpPort; |
| 20 | import org.onosproject.net.DeviceId; |
| 21 | |
| 22 | import java.util.Comparator; |
| 23 | import java.util.Objects; |
| 24 | |
| 25 | import static com.google.common.base.Preconditions.checkNotNull; |
| 26 | |
| 27 | /** |
| 28 | * Representation of a compute infrastructure node for CORD VTN service. |
| 29 | */ |
| 30 | public final class CordVtnNode { |
| 31 | |
| 32 | private final String hostname; |
Hyunsun Moon | 126171d | 2016-02-09 01:55:48 -0800 | [diff] [blame] | 33 | private final NetworkAddress hostMgmtIp; |
| 34 | private final NetworkAddress localMgmtIp; |
| 35 | private final NetworkAddress dpIp; |
Hyunsun Moon | 4edb017 | 2015-11-07 22:08:43 -0800 | [diff] [blame] | 36 | private final TpPort ovsdbPort; |
Hyunsun Moon | 126171d | 2016-02-09 01:55:48 -0800 | [diff] [blame] | 37 | private final SshAccessInfo sshInfo; |
Hyunsun Moon | 4edb017 | 2015-11-07 22:08:43 -0800 | [diff] [blame] | 38 | private final DeviceId bridgeId; |
Hyunsun Moon | 126171d | 2016-02-09 01:55:48 -0800 | [diff] [blame] | 39 | private final String dpIntf; |
Hyunsun Moon | 58ddbdc | 2016-03-07 16:37:17 -0800 | [diff] [blame] | 40 | private final CordVtnNodeState state; |
Hyunsun Moon | 4edb017 | 2015-11-07 22:08:43 -0800 | [diff] [blame] | 41 | |
| 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 Moon | 126171d | 2016-02-09 01:55:48 -0800 | [diff] [blame] | 49 | * @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 Moon | 4edb017 | 2015-11-07 22:08:43 -0800 | [diff] [blame] | 54 | * @param bridgeId integration bridge identifier |
Hyunsun Moon | 126171d | 2016-02-09 01:55:48 -0800 | [diff] [blame] | 55 | * @param dpIntf data plane interface name |
Hyunsun Moon | 58ddbdc | 2016-03-07 16:37:17 -0800 | [diff] [blame] | 56 | * @param state cordvtn node state |
Hyunsun Moon | 4edb017 | 2015-11-07 22:08:43 -0800 | [diff] [blame] | 57 | */ |
Hyunsun Moon | 126171d | 2016-02-09 01:55:48 -0800 | [diff] [blame] | 58 | public CordVtnNode(String hostname, NetworkAddress hostMgmtIp, NetworkAddress localMgmtIp, |
| 59 | NetworkAddress dpIp, TpPort ovsdbPort, SshAccessInfo sshInfo, |
Hyunsun Moon | 58ddbdc | 2016-03-07 16:37:17 -0800 | [diff] [blame] | 60 | DeviceId bridgeId, String dpIntf, CordVtnNodeState state) { |
Hyunsun Moon | 126171d | 2016-02-09 01:55:48 -0800 | [diff] [blame] | 61 | 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 Moon | 58ddbdc | 2016-03-07 16:37:17 -0800 | [diff] [blame] | 69 | 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 Moon | 4edb017 | 2015-11-07 22:08:43 -0800 | [diff] [blame] | 86 | } |
| 87 | |
| 88 | /** |
| 89 | * Returns the hostname. |
| 90 | * |
| 91 | * @return hostname |
| 92 | */ |
| 93 | public String hostname() { |
| 94 | return this.hostname; |
| 95 | } |
| 96 | |
| 97 | /** |
Hyunsun Moon | 126171d | 2016-02-09 01:55:48 -0800 | [diff] [blame] | 98 | * 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 Moon | 4edb017 | 2015-11-07 22:08:43 -0800 | [diff] [blame] | 143 | * 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 Moon | 126171d | 2016-02-09 01:55:48 -0800 | [diff] [blame] | 157 | return DeviceId.deviceId("ovsdb:" + this.hostMgmtIp.ip().toString()); |
Hyunsun Moon | 4edb017 | 2015-11-07 22:08:43 -0800 | [diff] [blame] | 158 | } |
| 159 | |
Hyunsun Moon | de37257 | 2016-01-14 03:42:47 -0800 | [diff] [blame] | 160 | /** |
Hyunsun Moon | 126171d | 2016-02-09 01:55:48 -0800 | [diff] [blame] | 161 | * Returns data plane interface name. |
Hyunsun Moon | de37257 | 2016-01-14 03:42:47 -0800 | [diff] [blame] | 162 | * |
Hyunsun Moon | 126171d | 2016-02-09 01:55:48 -0800 | [diff] [blame] | 163 | * @return data plane interface name |
Hyunsun Moon | de37257 | 2016-01-14 03:42:47 -0800 | [diff] [blame] | 164 | */ |
Hyunsun Moon | 126171d | 2016-02-09 01:55:48 -0800 | [diff] [blame] | 165 | public String dpIntf() { |
| 166 | return this.dpIntf; |
Hyunsun Moon | de37257 | 2016-01-14 03:42:47 -0800 | [diff] [blame] | 167 | } |
| 168 | |
Hyunsun Moon | 58ddbdc | 2016-03-07 16:37:17 -0800 | [diff] [blame] | 169 | /** |
| 170 | * Returns the state of the node. |
| 171 | * |
| 172 | * @return state |
| 173 | */ |
| 174 | public CordVtnNodeState state() { |
| 175 | return this.state; |
| 176 | } |
| 177 | |
Hyunsun Moon | 4edb017 | 2015-11-07 22:08:43 -0800 | [diff] [blame] | 178 | @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 Moon | ff55e81 | 2016-03-10 12:40:16 -0800 | [diff] [blame] | 186 | 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 Moon | 4edb017 | 2015-11-07 22:08:43 -0800 | [diff] [blame] | 194 | return true; |
| 195 | } |
| 196 | } |
| 197 | return false; |
| 198 | } |
| 199 | |
| 200 | @Override |
| 201 | public int hashCode() { |
Hyunsun Moon | ff55e81 | 2016-03-10 12:40:16 -0800 | [diff] [blame] | 202 | return Objects.hash(hostname, hostMgmtIp, localMgmtIp, dpIp, |
| 203 | ovsdbPort, sshInfo, bridgeId, dpIntf); |
Hyunsun Moon | 4edb017 | 2015-11-07 22:08:43 -0800 | [diff] [blame] | 204 | } |
| 205 | |
| 206 | @Override |
| 207 | public String toString() { |
| 208 | return MoreObjects.toStringHelper(getClass()) |
Hyunsun Moon | 126171d | 2016-02-09 01:55:48 -0800 | [diff] [blame] | 209 | .add("hostname", hostname) |
| 210 | .add("hostMgmtIp", hostMgmtIp) |
| 211 | .add("localMgmtIp", localMgmtIp) |
| 212 | .add("dpIp", dpIp) |
Hyunsun Moon | 4edb017 | 2015-11-07 22:08:43 -0800 | [diff] [blame] | 213 | .add("port", ovsdbPort) |
Hyunsun Moon | 126171d | 2016-02-09 01:55:48 -0800 | [diff] [blame] | 214 | .add("sshInfo", sshInfo) |
Hyunsun Moon | 4edb017 | 2015-11-07 22:08:43 -0800 | [diff] [blame] | 215 | .add("bridgeId", bridgeId) |
Hyunsun Moon | 126171d | 2016-02-09 01:55:48 -0800 | [diff] [blame] | 216 | .add("dpIntf", dpIntf) |
Hyunsun Moon | 58ddbdc | 2016-03-07 16:37:17 -0800 | [diff] [blame] | 217 | .add("state", state) |
Hyunsun Moon | 4edb017 | 2015-11-07 22:08:43 -0800 | [diff] [blame] | 218 | .toString(); |
| 219 | } |
| 220 | } |