Kyuhwi Choi | c5b33ea | 2016-04-26 11:45:32 +0900 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2016-present 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 | */ |
Hyunsun Moon | 7170129 | 2016-05-09 12:00:54 -0700 | [diff] [blame] | 16 | package org.onosproject.scalablegateway.api; |
Kyuhwi Choi | c5b33ea | 2016-04-26 11:45:32 +0900 | [diff] [blame] | 17 | |
Hyunsun Moon | d331afd | 2016-07-20 02:19:20 -0700 | [diff] [blame^] | 18 | import com.google.common.base.MoreObjects; |
Kyuhwi Choi | c5b33ea | 2016-04-26 11:45:32 +0900 | [diff] [blame] | 19 | import org.onlab.packet.Ip4Address; |
| 20 | import org.onosproject.net.DeviceId; |
| 21 | |
Hyunsun Moon | d331afd | 2016-07-20 02:19:20 -0700 | [diff] [blame^] | 22 | import java.util.Objects; |
| 23 | |
Kyuhwi Choi | c5b33ea | 2016-04-26 11:45:32 +0900 | [diff] [blame] | 24 | import static com.google.common.base.Preconditions.checkNotNull; |
| 25 | |
| 26 | /** |
| 27 | * Represents SONA GatewayNode information. |
| 28 | */ |
| 29 | public final class GatewayNode { |
| 30 | private final DeviceId gatewayDeviceId; |
Kyuhwi Choi | 176c83d | 2016-07-14 11:39:37 +0900 | [diff] [blame] | 31 | private final String gatewayExternalInterfaceName; |
Kyuhwi Choi | c5b33ea | 2016-04-26 11:45:32 +0900 | [diff] [blame] | 32 | private final Ip4Address dataIpAddress; |
| 33 | |
Kyuhwi Choi | 176c83d | 2016-07-14 11:39:37 +0900 | [diff] [blame] | 34 | private GatewayNode(DeviceId gatewayDeviceId, String gatewayExternalInterfaceName, |
Kyuhwi Choi | c5b33ea | 2016-04-26 11:45:32 +0900 | [diff] [blame] | 35 | Ip4Address dataIpAddress) { |
| 36 | this.gatewayDeviceId = gatewayDeviceId; |
Kyuhwi Choi | 176c83d | 2016-07-14 11:39:37 +0900 | [diff] [blame] | 37 | this.gatewayExternalInterfaceName = gatewayExternalInterfaceName; |
Kyuhwi Choi | c5b33ea | 2016-04-26 11:45:32 +0900 | [diff] [blame] | 38 | this.dataIpAddress = dataIpAddress; |
| 39 | } |
| 40 | |
| 41 | /** |
| 42 | * Returns the device id of gateway node. |
| 43 | * |
| 44 | * @return The device id of gateway node |
| 45 | */ |
| 46 | public DeviceId getGatewayDeviceId() { |
| 47 | return gatewayDeviceId; |
| 48 | } |
| 49 | |
| 50 | /** |
Kyuhwi Choi | 176c83d | 2016-07-14 11:39:37 +0900 | [diff] [blame] | 51 | * Returns the gateway`s interface name. |
Kyuhwi Choi | c5b33ea | 2016-04-26 11:45:32 +0900 | [diff] [blame] | 52 | * |
Kyuhwi Choi | 176c83d | 2016-07-14 11:39:37 +0900 | [diff] [blame] | 53 | * @return The gateway`s interface name |
Kyuhwi Choi | c5b33ea | 2016-04-26 11:45:32 +0900 | [diff] [blame] | 54 | */ |
Kyuhwi Choi | 176c83d | 2016-07-14 11:39:37 +0900 | [diff] [blame] | 55 | public String getGatewayExternalInterfaceName() { |
| 56 | return gatewayExternalInterfaceName; |
Kyuhwi Choi | c5b33ea | 2016-04-26 11:45:32 +0900 | [diff] [blame] | 57 | } |
| 58 | |
| 59 | /** |
| 60 | * Returns the data ip address of gateway node. |
| 61 | * |
| 62 | * @return The data ip address of gateway node |
| 63 | */ |
| 64 | public Ip4Address getDataIpAddress() { |
| 65 | return dataIpAddress; |
| 66 | } |
| 67 | |
Hyunsun Moon | d331afd | 2016-07-20 02:19:20 -0700 | [diff] [blame^] | 68 | @Override |
| 69 | public boolean equals(Object obj) { |
| 70 | if (this == obj) { |
| 71 | return true; |
| 72 | } |
| 73 | |
| 74 | if (obj instanceof GatewayNode) { |
| 75 | GatewayNode that = (GatewayNode) obj; |
| 76 | if (Objects.equals(gatewayDeviceId, that.gatewayDeviceId) && |
| 77 | Objects.equals(gatewayExternalInterfaceName, |
| 78 | that.gatewayExternalInterfaceName) && |
| 79 | Objects.equals(dataIpAddress, that.dataIpAddress)) { |
| 80 | return true; |
| 81 | } |
| 82 | } |
| 83 | return false; |
| 84 | } |
| 85 | |
| 86 | @Override |
| 87 | public int hashCode() { |
| 88 | return Objects.hash(gatewayDeviceId, |
| 89 | gatewayExternalInterfaceName, |
| 90 | dataIpAddress); |
| 91 | } |
| 92 | |
| 93 | @Override |
| 94 | public String toString() { |
| 95 | return MoreObjects.toStringHelper(getClass()) |
| 96 | .add("deviceId", gatewayDeviceId) |
| 97 | .add("externalPort", gatewayExternalInterfaceName) |
| 98 | .add("dataIp", dataIpAddress) |
| 99 | .toString(); |
| 100 | } |
| 101 | |
Kyuhwi Choi | c5b33ea | 2016-04-26 11:45:32 +0900 | [diff] [blame] | 102 | /** |
Kyuhwi Choi | 92d9ea4 | 2016-06-13 17:28:00 +0900 | [diff] [blame] | 103 | * Returns GatewayNode builder object. |
| 104 | * |
| 105 | * @return GatewayNode builder |
| 106 | */ |
| 107 | public static GatewayNode.Builder builder() { |
| 108 | return new Builder(); |
| 109 | } |
| 110 | |
| 111 | /** |
Kyuhwi Choi | c5b33ea | 2016-04-26 11:45:32 +0900 | [diff] [blame] | 112 | * GatewayNode Builder class. |
| 113 | */ |
| 114 | public static final class Builder { |
| 115 | |
| 116 | private DeviceId gatewayDeviceId; |
Kyuhwi Choi | 176c83d | 2016-07-14 11:39:37 +0900 | [diff] [blame] | 117 | private String gatewayExternalInterfaceName; |
Kyuhwi Choi | c5b33ea | 2016-04-26 11:45:32 +0900 | [diff] [blame] | 118 | private Ip4Address dataIpAddress; |
| 119 | |
| 120 | /** |
| 121 | * Sets the device id of gateway node. |
| 122 | * |
| 123 | * @param deviceId The device id of gateway node |
| 124 | * @return Builder object |
| 125 | */ |
| 126 | public Builder gatewayDeviceId(DeviceId deviceId) { |
| 127 | this.gatewayDeviceId = deviceId; |
| 128 | return this; |
| 129 | } |
| 130 | |
| 131 | /** |
Kyuhwi Choi | 176c83d | 2016-07-14 11:39:37 +0900 | [diff] [blame] | 132 | * Sets the gateway`s interface name. |
Kyuhwi Choi | c5b33ea | 2016-04-26 11:45:32 +0900 | [diff] [blame] | 133 | * |
Kyuhwi Choi | 176c83d | 2016-07-14 11:39:37 +0900 | [diff] [blame] | 134 | * @param name The gateway`s interface name |
Kyuhwi Choi | c5b33ea | 2016-04-26 11:45:32 +0900 | [diff] [blame] | 135 | * @return Builder object |
| 136 | */ |
Kyuhwi Choi | 176c83d | 2016-07-14 11:39:37 +0900 | [diff] [blame] | 137 | public Builder gatewayExternalInterfaceName(String name) { |
| 138 | this.gatewayExternalInterfaceName = name; |
Kyuhwi Choi | c5b33ea | 2016-04-26 11:45:32 +0900 | [diff] [blame] | 139 | return this; |
| 140 | } |
| 141 | |
| 142 | /** |
| 143 | * Sets the ip address of gateway node for data plain. |
| 144 | * |
| 145 | * @param address The ip address of gateway node |
| 146 | * @return Builder object |
| 147 | */ |
| 148 | public Builder dataIpAddress(Ip4Address address) { |
| 149 | this.dataIpAddress = address; |
| 150 | return this; |
| 151 | } |
| 152 | |
| 153 | /** |
| 154 | * Builds a GatewayNode object. |
| 155 | * |
| 156 | * @return GatewayNode object |
| 157 | */ |
| 158 | public GatewayNode build() { |
Kyuhwi Choi | 176c83d | 2016-07-14 11:39:37 +0900 | [diff] [blame] | 159 | return new GatewayNode(checkNotNull(gatewayDeviceId), checkNotNull(gatewayExternalInterfaceName), |
Kyuhwi Choi | c5b33ea | 2016-04-26 11:45:32 +0900 | [diff] [blame] | 160 | checkNotNull(dataIpAddress)); |
| 161 | } |
| 162 | } |
| 163 | } |