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