blob: b2f0af0530d50cb135a7cef2f42aac9ce3636fb7 [file] [log] [blame]
/*
* Copyright 2016-present Open Networking Laboratory
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.onosproject.scalablegateway.api;
import com.google.common.base.MoreObjects;
import org.onlab.packet.Ip4Address;
import org.onosproject.net.DeviceId;
import java.util.Objects;
import static com.google.common.base.Preconditions.checkNotNull;
/**
* Represents SONA GatewayNode information.
*/
public final class GatewayNode {
private final DeviceId gatewayDeviceId;
private final String gatewayExternalInterfaceName;
private final Ip4Address dataIpAddress;
private GatewayNode(DeviceId gatewayDeviceId, String gatewayExternalInterfaceName,
Ip4Address dataIpAddress) {
this.gatewayDeviceId = gatewayDeviceId;
this.gatewayExternalInterfaceName = gatewayExternalInterfaceName;
this.dataIpAddress = dataIpAddress;
}
/**
* Returns the device id of gateway node.
*
* @return The device id of gateway node
*/
public DeviceId getGatewayDeviceId() {
return gatewayDeviceId;
}
/**
* Returns the gateway`s interface name.
*
* @return The gateway`s interface name
*/
public String getGatewayExternalInterfaceName() {
return gatewayExternalInterfaceName;
}
/**
* Returns the data ip address of gateway node.
*
* @return The data ip address of gateway node
*/
public Ip4Address getDataIpAddress() {
return dataIpAddress;
}
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj instanceof GatewayNode) {
GatewayNode that = (GatewayNode) obj;
if (Objects.equals(gatewayDeviceId, that.gatewayDeviceId) &&
Objects.equals(gatewayExternalInterfaceName,
that.gatewayExternalInterfaceName) &&
Objects.equals(dataIpAddress, that.dataIpAddress)) {
return true;
}
}
return false;
}
@Override
public int hashCode() {
return Objects.hash(gatewayDeviceId,
gatewayExternalInterfaceName,
dataIpAddress);
}
@Override
public String toString() {
return MoreObjects.toStringHelper(getClass())
.add("deviceId", gatewayDeviceId)
.add("externalPort", gatewayExternalInterfaceName)
.add("dataIp", dataIpAddress)
.toString();
}
/**
* Returns GatewayNode builder object.
*
* @return GatewayNode builder
*/
public static GatewayNode.Builder builder() {
return new Builder();
}
/**
* GatewayNode Builder class.
*/
public static final class Builder {
private DeviceId gatewayDeviceId;
private String gatewayExternalInterfaceName;
private Ip4Address dataIpAddress;
/**
* Sets the device id of gateway node.
*
* @param deviceId The device id of gateway node
* @return Builder object
*/
public Builder gatewayDeviceId(DeviceId deviceId) {
this.gatewayDeviceId = deviceId;
return this;
}
/**
* Sets the gateway`s interface name.
*
* @param name The gateway`s interface name
* @return Builder object
*/
public Builder gatewayExternalInterfaceName(String name) {
this.gatewayExternalInterfaceName = name;
return this;
}
/**
* Sets the ip address of gateway node for data plain.
*
* @param address The ip address of gateway node
* @return Builder object
*/
public Builder dataIpAddress(Ip4Address address) {
this.dataIpAddress = address;
return this;
}
/**
* Builds a GatewayNode object.
*
* @return GatewayNode object
*/
public GatewayNode build() {
return new GatewayNode(checkNotNull(gatewayDeviceId), checkNotNull(gatewayExternalInterfaceName),
checkNotNull(dataIpAddress));
}
}
}