Hyunsun Moon | 4edb017 | 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; |
| 19 | import org.onlab.packet.IpAddress; |
| 20 | import org.onlab.packet.TpPort; |
| 21 | import org.onosproject.net.DeviceId; |
| 22 | |
| 23 | import java.util.Comparator; |
| 24 | import java.util.Objects; |
| 25 | |
| 26 | import static com.google.common.base.Preconditions.checkNotNull; |
| 27 | |
| 28 | /** |
| 29 | * Representation of a compute infrastructure node for CORD VTN service. |
| 30 | */ |
| 31 | public final class CordVtnNode { |
| 32 | |
| 33 | private final String hostname; |
| 34 | private final IpAddress ovsdbIp; |
| 35 | private final TpPort ovsdbPort; |
| 36 | private final DeviceId bridgeId; |
Hyunsun Moon | de37257 | 2016-01-14 03:42:47 -0800 | [diff] [blame] | 37 | private final String phyPortName; |
| 38 | private final IpAddress localIp; |
Hyunsun Moon | 4edb017 | 2015-11-07 22:08:43 -0800 | [diff] [blame] | 39 | |
| 40 | public static final Comparator<CordVtnNode> CORDVTN_NODE_COMPARATOR = |
| 41 | (node1, node2) -> node1.hostname().compareTo(node2.hostname()); |
| 42 | |
| 43 | /** |
| 44 | * Creates a new node. |
| 45 | * |
| 46 | * @param hostname hostname |
| 47 | * @param ovsdbIp OVSDB server IP address |
| 48 | * @param ovsdbPort OVSDB server port number |
| 49 | * @param bridgeId integration bridge identifier |
Hyunsun Moon | de37257 | 2016-01-14 03:42:47 -0800 | [diff] [blame] | 50 | * @param phyPortName physical port name |
| 51 | * @param localIp local ip address of data plane |
Hyunsun Moon | 4edb017 | 2015-11-07 22:08:43 -0800 | [diff] [blame] | 52 | */ |
Hyunsun Moon | de37257 | 2016-01-14 03:42:47 -0800 | [diff] [blame] | 53 | public CordVtnNode(String hostname, IpAddress ovsdbIp, TpPort ovsdbPort, |
| 54 | DeviceId bridgeId, String phyPortName, IpAddress localIp) { |
Hyunsun Moon | 4edb017 | 2015-11-07 22:08:43 -0800 | [diff] [blame] | 55 | this.hostname = checkNotNull(hostname); |
| 56 | this.ovsdbIp = checkNotNull(ovsdbIp); |
| 57 | this.ovsdbPort = checkNotNull(ovsdbPort); |
| 58 | this.bridgeId = checkNotNull(bridgeId); |
Hyunsun Moon | de37257 | 2016-01-14 03:42:47 -0800 | [diff] [blame] | 59 | this.phyPortName = checkNotNull(phyPortName); |
| 60 | this.localIp = checkNotNull(localIp); |
Hyunsun Moon | 4edb017 | 2015-11-07 22:08:43 -0800 | [diff] [blame] | 61 | } |
| 62 | |
| 63 | /** |
| 64 | * Returns the OVSDB server IP address. |
| 65 | * |
| 66 | * @return ip address |
| 67 | */ |
| 68 | public IpAddress ovsdbIp() { |
| 69 | return this.ovsdbIp; |
| 70 | } |
| 71 | |
| 72 | /** |
| 73 | * Returns the OVSDB server port number. |
| 74 | * |
| 75 | * @return port number |
| 76 | */ |
| 77 | public TpPort ovsdbPort() { |
| 78 | return this.ovsdbPort; |
| 79 | } |
| 80 | |
| 81 | /** |
| 82 | * Returns the hostname. |
| 83 | * |
| 84 | * @return hostname |
| 85 | */ |
| 86 | public String hostname() { |
| 87 | return this.hostname; |
| 88 | } |
| 89 | |
| 90 | /** |
| 91 | * Returns the identifier of the integration bridge. |
| 92 | * |
| 93 | * @return device id |
| 94 | */ |
| 95 | public DeviceId intBrId() { |
| 96 | return this.bridgeId; |
| 97 | } |
| 98 | |
| 99 | /** |
| 100 | * Returns the identifier of the OVSDB device. |
| 101 | * |
| 102 | * @return device id |
| 103 | */ |
| 104 | public DeviceId ovsdbId() { |
| 105 | return DeviceId.deviceId("ovsdb:" + this.ovsdbIp.toString()); |
| 106 | } |
| 107 | |
Hyunsun Moon | de37257 | 2016-01-14 03:42:47 -0800 | [diff] [blame] | 108 | /** |
| 109 | * Returns physical port name. |
| 110 | * |
| 111 | * @return physical port name |
| 112 | */ |
| 113 | public String phyPortName() { |
| 114 | return this.phyPortName; |
| 115 | } |
| 116 | |
| 117 | /** |
| 118 | * Returns local IP address. |
| 119 | * |
| 120 | * @return ip address |
| 121 | */ |
| 122 | public IpAddress localIp() { |
| 123 | return this.localIp; |
| 124 | } |
| 125 | |
Hyunsun Moon | 4edb017 | 2015-11-07 22:08:43 -0800 | [diff] [blame] | 126 | @Override |
| 127 | public boolean equals(Object obj) { |
| 128 | if (this == obj) { |
| 129 | return true; |
| 130 | } |
| 131 | |
| 132 | if (obj instanceof CordVtnNode) { |
| 133 | CordVtnNode that = (CordVtnNode) obj; |
Hyunsun Moon | de37257 | 2016-01-14 03:42:47 -0800 | [diff] [blame] | 134 | if (Objects.equals(hostname, that.hostname)) { |
Hyunsun Moon | 4edb017 | 2015-11-07 22:08:43 -0800 | [diff] [blame] | 135 | return true; |
| 136 | } |
| 137 | } |
| 138 | return false; |
| 139 | } |
| 140 | |
| 141 | @Override |
| 142 | public int hashCode() { |
| 143 | return Objects.hash(hostname, ovsdbIp, ovsdbPort); |
| 144 | } |
| 145 | |
| 146 | @Override |
| 147 | public String toString() { |
| 148 | return MoreObjects.toStringHelper(getClass()) |
| 149 | .add("host", hostname) |
| 150 | .add("ip", ovsdbIp) |
| 151 | .add("port", ovsdbPort) |
| 152 | .add("bridgeId", bridgeId) |
Hyunsun Moon | de37257 | 2016-01-14 03:42:47 -0800 | [diff] [blame] | 153 | .add("phyPortName", phyPortName) |
| 154 | .add("localIp", localIp) |
Hyunsun Moon | 4edb017 | 2015-11-07 22:08:43 -0800 | [diff] [blame] | 155 | .toString(); |
| 156 | } |
| 157 | } |