blob: b2f0af0530d50cb135a7cef2f42aac9ce3636fb7 [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;
Kyuhwi Choi176c83d2016-07-14 11:39:37 +090031 private final String gatewayExternalInterfaceName;
Kyuhwi Choic5b33ea2016-04-26 11:45:32 +090032 private final Ip4Address dataIpAddress;
33
Kyuhwi Choi176c83d2016-07-14 11:39:37 +090034 private GatewayNode(DeviceId gatewayDeviceId, String gatewayExternalInterfaceName,
Kyuhwi Choic5b33ea2016-04-26 11:45:32 +090035 Ip4Address dataIpAddress) {
36 this.gatewayDeviceId = gatewayDeviceId;
Kyuhwi Choi176c83d2016-07-14 11:39:37 +090037 this.gatewayExternalInterfaceName = gatewayExternalInterfaceName;
Kyuhwi Choic5b33ea2016-04-26 11:45:32 +090038 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 Choi176c83d2016-07-14 11:39:37 +090051 * Returns the gateway`s interface name.
Kyuhwi Choic5b33ea2016-04-26 11:45:32 +090052 *
Kyuhwi Choi176c83d2016-07-14 11:39:37 +090053 * @return The gateway`s interface name
Kyuhwi Choic5b33ea2016-04-26 11:45:32 +090054 */
Kyuhwi Choi176c83d2016-07-14 11:39:37 +090055 public String getGatewayExternalInterfaceName() {
56 return gatewayExternalInterfaceName;
Kyuhwi Choic5b33ea2016-04-26 11:45:32 +090057 }
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 Moond331afd2016-07-20 02:19:20 -070068 @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 Choic5b33ea2016-04-26 11:45:32 +0900102 /**
Kyuhwi Choi92d9ea42016-06-13 17:28:00 +0900103 * Returns GatewayNode builder object.
104 *
105 * @return GatewayNode builder
106 */
107 public static GatewayNode.Builder builder() {
108 return new Builder();
109 }
110
111 /**
Kyuhwi Choic5b33ea2016-04-26 11:45:32 +0900112 * GatewayNode Builder class.
113 */
114 public static final class Builder {
115
116 private DeviceId gatewayDeviceId;
Kyuhwi Choi176c83d2016-07-14 11:39:37 +0900117 private String gatewayExternalInterfaceName;
Kyuhwi Choic5b33ea2016-04-26 11:45:32 +0900118 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 Choi176c83d2016-07-14 11:39:37 +0900132 * Sets the gateway`s interface name.
Kyuhwi Choic5b33ea2016-04-26 11:45:32 +0900133 *
Kyuhwi Choi176c83d2016-07-14 11:39:37 +0900134 * @param name The gateway`s interface name
Kyuhwi Choic5b33ea2016-04-26 11:45:32 +0900135 * @return Builder object
136 */
Kyuhwi Choi176c83d2016-07-14 11:39:37 +0900137 public Builder gatewayExternalInterfaceName(String name) {
138 this.gatewayExternalInterfaceName = name;
Kyuhwi Choic5b33ea2016-04-26 11:45:32 +0900139 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 Choi176c83d2016-07-14 11:39:37 +0900159 return new GatewayNode(checkNotNull(gatewayDeviceId), checkNotNull(gatewayExternalInterfaceName),
Kyuhwi Choic5b33ea2016-04-26 11:45:32 +0900160 checkNotNull(dataIpAddress));
161 }
162 }
163}