Hyunsun Moon | 8539b04 | 2015-11-07 22:08:43 -0800 | [diff] [blame] | 1 | /* |
| 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 | */ |
| 16 | package org.onosproject.cordvtn; |
| 17 | |
| 18 | import com.google.common.base.MoreObjects; |
Hyunsun Moon | 8539b04 | 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 | 133fd79 | 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 | 8539b04 | 2015-11-07 22:08:43 -0800 | [diff] [blame] | 36 | private final TpPort ovsdbPort; |
Hyunsun Moon | 133fd79 | 2016-02-09 01:55:48 -0800 | [diff] [blame^] | 37 | private final SshAccessInfo sshInfo; |
Hyunsun Moon | 8539b04 | 2015-11-07 22:08:43 -0800 | [diff] [blame] | 38 | private final DeviceId bridgeId; |
Hyunsun Moon | 133fd79 | 2016-02-09 01:55:48 -0800 | [diff] [blame^] | 39 | private final String dpIntf; |
Hyunsun Moon | 8539b04 | 2015-11-07 22:08:43 -0800 | [diff] [blame] | 40 | |
| 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 Moon | 133fd79 | 2016-02-09 01:55:48 -0800 | [diff] [blame^] | 48 | * @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 Moon | 8539b04 | 2015-11-07 22:08:43 -0800 | [diff] [blame] | 53 | * @param bridgeId integration bridge identifier |
Hyunsun Moon | 133fd79 | 2016-02-09 01:55:48 -0800 | [diff] [blame^] | 54 | * @param dpIntf data plane interface name |
Hyunsun Moon | 8539b04 | 2015-11-07 22:08:43 -0800 | [diff] [blame] | 55 | */ |
Hyunsun Moon | 133fd79 | 2016-02-09 01:55:48 -0800 | [diff] [blame^] | 56 | 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 Moon | 8539b04 | 2015-11-07 22:08:43 -0800 | [diff] [blame] | 67 | } |
| 68 | |
| 69 | /** |
| 70 | * Returns the hostname. |
| 71 | * |
| 72 | * @return hostname |
| 73 | */ |
| 74 | public String hostname() { |
| 75 | return this.hostname; |
| 76 | } |
| 77 | |
| 78 | /** |
Hyunsun Moon | 133fd79 | 2016-02-09 01:55:48 -0800 | [diff] [blame^] | 79 | * 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 Moon | 8539b04 | 2015-11-07 22:08:43 -0800 | [diff] [blame] | 124 | * 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 Moon | 133fd79 | 2016-02-09 01:55:48 -0800 | [diff] [blame^] | 138 | return DeviceId.deviceId("ovsdb:" + this.hostMgmtIp.ip().toString()); |
Hyunsun Moon | 8539b04 | 2015-11-07 22:08:43 -0800 | [diff] [blame] | 139 | } |
| 140 | |
Hyunsun Moon | b219fc4 | 2016-01-14 03:42:47 -0800 | [diff] [blame] | 141 | /** |
Hyunsun Moon | 133fd79 | 2016-02-09 01:55:48 -0800 | [diff] [blame^] | 142 | * Returns data plane interface name. |
Hyunsun Moon | b219fc4 | 2016-01-14 03:42:47 -0800 | [diff] [blame] | 143 | * |
Hyunsun Moon | 133fd79 | 2016-02-09 01:55:48 -0800 | [diff] [blame^] | 144 | * @return data plane interface name |
Hyunsun Moon | b219fc4 | 2016-01-14 03:42:47 -0800 | [diff] [blame] | 145 | */ |
Hyunsun Moon | 133fd79 | 2016-02-09 01:55:48 -0800 | [diff] [blame^] | 146 | public String dpIntf() { |
| 147 | return this.dpIntf; |
Hyunsun Moon | b219fc4 | 2016-01-14 03:42:47 -0800 | [diff] [blame] | 148 | } |
| 149 | |
Hyunsun Moon | 8539b04 | 2015-11-07 22:08:43 -0800 | [diff] [blame] | 150 | @Override |
| 151 | public boolean equals(Object obj) { |
| 152 | if (this == obj) { |
| 153 | return true; |
| 154 | } |
| 155 | |
Hyunsun Moon | 133fd79 | 2016-02-09 01:55:48 -0800 | [diff] [blame^] | 156 | // hostname here is a network hostname and it is intended to be |
| 157 | // unique throughout the service. |
Hyunsun Moon | 8539b04 | 2015-11-07 22:08:43 -0800 | [diff] [blame] | 158 | if (obj instanceof CordVtnNode) { |
| 159 | CordVtnNode that = (CordVtnNode) obj; |
Hyunsun Moon | b219fc4 | 2016-01-14 03:42:47 -0800 | [diff] [blame] | 160 | if (Objects.equals(hostname, that.hostname)) { |
Hyunsun Moon | 8539b04 | 2015-11-07 22:08:43 -0800 | [diff] [blame] | 161 | return true; |
| 162 | } |
| 163 | } |
| 164 | return false; |
| 165 | } |
| 166 | |
| 167 | @Override |
| 168 | public int hashCode() { |
Daniel Park | c54ac76 | 2016-01-20 10:09:44 +0900 | [diff] [blame] | 169 | return Objects.hash(hostname); |
Hyunsun Moon | 8539b04 | 2015-11-07 22:08:43 -0800 | [diff] [blame] | 170 | } |
| 171 | |
| 172 | @Override |
| 173 | public String toString() { |
| 174 | return MoreObjects.toStringHelper(getClass()) |
Hyunsun Moon | 133fd79 | 2016-02-09 01:55:48 -0800 | [diff] [blame^] | 175 | .add("hostname", hostname) |
| 176 | .add("hostMgmtIp", hostMgmtIp) |
| 177 | .add("localMgmtIp", localMgmtIp) |
| 178 | .add("dpIp", dpIp) |
Hyunsun Moon | 8539b04 | 2015-11-07 22:08:43 -0800 | [diff] [blame] | 179 | .add("port", ovsdbPort) |
Hyunsun Moon | 133fd79 | 2016-02-09 01:55:48 -0800 | [diff] [blame^] | 180 | .add("sshInfo", sshInfo) |
Hyunsun Moon | 8539b04 | 2015-11-07 22:08:43 -0800 | [diff] [blame] | 181 | .add("bridgeId", bridgeId) |
Hyunsun Moon | 133fd79 | 2016-02-09 01:55:48 -0800 | [diff] [blame^] | 182 | .add("dpIntf", dpIntf) |
Hyunsun Moon | 8539b04 | 2015-11-07 22:08:43 -0800 | [diff] [blame] | 183 | .toString(); |
| 184 | } |
| 185 | } |