blob: 26371d010bafbc513cc759ecb3fb82951c94c7c9 [file] [log] [blame]
Kyuhwi Choic5b33ea2016-04-26 11:45:32 +09001/*
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 Moon71701292016-05-09 12:00:54 -070016package org.onosproject.scalablegateway.api;
Kyuhwi Choic5b33ea2016-04-26 11:45:32 +090017
Hyunsun Moond331afd2016-07-20 02:19:20 -070018import com.google.common.base.MoreObjects;
Kyuhwi Choic5b33ea2016-04-26 11:45:32 +090019import org.onlab.packet.Ip4Address;
20import org.onosproject.net.DeviceId;
21
Hyunsun Moond331afd2016-07-20 02:19:20 -070022import java.util.Objects;
23
Kyuhwi Choic5b33ea2016-04-26 11:45:32 +090024import static com.google.common.base.Preconditions.checkNotNull;
25
26/**
27 * Represents SONA GatewayNode information.
28 */
29public final class GatewayNode {
30 private final DeviceId gatewayDeviceId;
Hyunsun Moonf9a16ed2016-07-20 21:59:48 -070031 private final String uplinkIntf;
Kyuhwi Choic5b33ea2016-04-26 11:45:32 +090032 private final Ip4Address dataIpAddress;
33
Hyunsun Moonf9a16ed2016-07-20 21:59:48 -070034 private GatewayNode(DeviceId gatewayDeviceId, String uplinkIntf, Ip4Address dataIpAddress) {
Kyuhwi Choic5b33ea2016-04-26 11:45:32 +090035 this.gatewayDeviceId = gatewayDeviceId;
Hyunsun Moonf9a16ed2016-07-20 21:59:48 -070036 this.uplinkIntf = uplinkIntf;
Kyuhwi Choic5b33ea2016-04-26 11:45:32 +090037 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 Choi176c83d2016-07-14 11:39:37 +090050 * Returns the gateway`s interface name.
Kyuhwi Choic5b33ea2016-04-26 11:45:32 +090051 *
Kyuhwi Choi176c83d2016-07-14 11:39:37 +090052 * @return The gateway`s interface name
Kyuhwi Choic5b33ea2016-04-26 11:45:32 +090053 */
Hyunsun Moonf9a16ed2016-07-20 21:59:48 -070054 public String getUplinkIntf() {
55 return uplinkIntf;
Kyuhwi Choic5b33ea2016-04-26 11:45:32 +090056 }
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 Moond331afd2016-07-20 02:19:20 -070067 @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 Moonf9a16ed2016-07-20 21:59:48 -070076 Objects.equals(uplinkIntf, that.uplinkIntf) &&
Hyunsun Moond331afd2016-07-20 02:19:20 -070077 Objects.equals(dataIpAddress, that.dataIpAddress)) {
78 return true;
79 }
80 }
81 return false;
82 }
83
84 @Override
85 public int hashCode() {
Hyunsun Moonf9a16ed2016-07-20 21:59:48 -070086 return Objects.hash(gatewayDeviceId, uplinkIntf, dataIpAddress);
Hyunsun Moond331afd2016-07-20 02:19:20 -070087 }
88
89 @Override
90 public String toString() {
91 return MoreObjects.toStringHelper(getClass())
Hyunsun Moonf9a16ed2016-07-20 21:59:48 -070092 .add("gatewayDeviceId", gatewayDeviceId)
93 .add("uplinkInterface", uplinkIntf)
94 .add("dataIpAddress", dataIpAddress)
Hyunsun Moond331afd2016-07-20 02:19:20 -070095 .toString();
96 }
97
Kyuhwi Choic5b33ea2016-04-26 11:45:32 +090098 /**
Kyuhwi Choi92d9ea42016-06-13 17:28:00 +090099 * Returns GatewayNode builder object.
100 *
101 * @return GatewayNode builder
102 */
103 public static GatewayNode.Builder builder() {
104 return new Builder();
105 }
106
107 /**
Kyuhwi Choic5b33ea2016-04-26 11:45:32 +0900108 * GatewayNode Builder class.
109 */
110 public static final class Builder {
111
112 private DeviceId gatewayDeviceId;
Hyunsun Moonf9a16ed2016-07-20 21:59:48 -0700113 private String uplinkIntf;
Kyuhwi Choic5b33ea2016-04-26 11:45:32 +0900114 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 Moonf9a16ed2016-07-20 21:59:48 -0700128 * Sets the gateway`s uplink interface name.
Kyuhwi Choic5b33ea2016-04-26 11:45:32 +0900129 *
Kyuhwi Choi176c83d2016-07-14 11:39:37 +0900130 * @param name The gateway`s interface name
Kyuhwi Choic5b33ea2016-04-26 11:45:32 +0900131 * @return Builder object
132 */
Hyunsun Moonf9a16ed2016-07-20 21:59:48 -0700133 public Builder uplinkIntf(String name) {
134 this.uplinkIntf = name;
Kyuhwi Choic5b33ea2016-04-26 11:45:32 +0900135 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 Moonf9a16ed2016-07-20 21:59:48 -0700155 return new GatewayNode(checkNotNull(gatewayDeviceId), checkNotNull(uplinkIntf),
156 checkNotNull(dataIpAddress));
Kyuhwi Choic5b33ea2016-04-26 11:45:32 +0900157 }
158 }
159}