blob: a21095744149520c7d67a5ea775a718afd5695cf [file] [log] [blame]
Thomas Vachuska781d18b2014-10-27 10:31:25 -07001/*
Brian O'Connor5ab426f2016-04-09 01:19:45 -07002 * Copyright 2015-present Open Networking Laboratory
Thomas Vachuska781d18b2014-10-27 10:31:25 -07003 *
Thomas Vachuska4f1a60c2014-10-28 13:39:07 -07004 * 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
Thomas Vachuska781d18b2014-10-27 10:31:25 -07007 *
Thomas Vachuska4f1a60c2014-10-28 13:39:07 -07008 * 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.
Thomas Vachuska781d18b2014-10-27 10:31:25 -070015 */
Jonathan Hart2da1e602015-02-18 19:09:24 -080016package org.onosproject.routing.config;
Jonathan Hartbac07a02014-10-13 21:29:54 -070017
Jonathan Hartd7bd9822014-10-20 18:18:02 -070018import com.fasterxml.jackson.annotation.JsonProperty;
Jonathan Hartdc711bd2014-10-15 11:24:23 -070019import com.google.common.base.MoreObjects;
Jonathan Hart90a02c22015-02-13 11:52:07 -080020import org.onlab.packet.IpAddress;
21import org.onosproject.net.ConnectPoint;
22import org.onosproject.net.DeviceId;
23import org.onosproject.net.NetTools;
24import org.onosproject.net.PortNumber;
25
26import java.util.Objects;
Jonathan Hartdc711bd2014-10-15 11:24:23 -070027
Jonathan Hartbac07a02014-10-13 21:29:54 -070028/**
29 * Represents an address of a {@link BgpSpeaker} configured on an
30 * {@link Interface}.
Thomas Vachuska4b420772014-10-30 16:46:17 -070031 * <p>
Jonathan Hartbac07a02014-10-13 21:29:54 -070032 * Each InterfaceAddress includes the interface name and an IP address.
Thomas Vachuska4b420772014-10-30 16:46:17 -070033 * </p>
Jonathan Hartbac07a02014-10-13 21:29:54 -070034 */
35public class InterfaceAddress {
36 private final ConnectPoint connectPoint;
37 private final IpAddress ipAddress;
38
39 /**
Jonathan Hartdc711bd2014-10-15 11:24:23 -070040 * Creates an InterfaceAddress object.
Jonathan Hartbac07a02014-10-13 21:29:54 -070041 *
Jonathan Hartdc711bd2014-10-15 11:24:23 -070042 * @param dpid the DPID of the interface as a String
43 * @param port the port of the interface
Jonathan Hartbac07a02014-10-13 21:29:54 -070044 * @param ipAddress the IP address of a {@link BgpSpeaker} configured on
45 * the interface
46 */
47 public InterfaceAddress(@JsonProperty("interfaceDpid") String dpid,
48 @JsonProperty("interfacePort") int port,
49 @JsonProperty("ipAddress") String ipAddress) {
50 this.connectPoint = new ConnectPoint(
Jonathan Hart90a02c22015-02-13 11:52:07 -080051 DeviceId.deviceId(NetTools.dpidToUri(dpid)),
Jonathan Hartbac07a02014-10-13 21:29:54 -070052 PortNumber.portNumber(port));
53 this.ipAddress = IpAddress.valueOf(ipAddress);
54 }
55
56 /**
57 * Gets the connection point of the peer.
58 *
59 * @return the connection point
60 */
Jonathan Hartdc711bd2014-10-15 11:24:23 -070061 public ConnectPoint connectPoint() {
Jonathan Hartbac07a02014-10-13 21:29:54 -070062 return connectPoint;
63 }
64
65 /**
66 * Gets the IP address of a BGP speaker configured on an {@link Interface}.
67 *
68 * @return the IP address
69 */
Jonathan Hartdc711bd2014-10-15 11:24:23 -070070 public IpAddress ipAddress() {
Jonathan Hartbac07a02014-10-13 21:29:54 -070071 return ipAddress;
72 }
73
74 @Override
75 public int hashCode() {
76 return Objects.hash(connectPoint, ipAddress);
77 }
78
79 @Override
80 public boolean equals(Object obj) {
81 if (obj == this) {
82 return true;
83 }
84
85 if (!(obj instanceof InterfaceAddress)) {
86 return false;
87 }
88
89 InterfaceAddress that = (InterfaceAddress) obj;
90 return Objects.equals(this.connectPoint, that.connectPoint)
91 && Objects.equals(this.ipAddress, that.ipAddress);
92 }
Jonathan Hartdc711bd2014-10-15 11:24:23 -070093
94 @Override
95 public String toString() {
96 return MoreObjects.toStringHelper(getClass())
97 .add("connectPoint", connectPoint)
98 .add("ipAddress", ipAddress)
99 .toString();
100 }
Jonathan Hartbac07a02014-10-13 21:29:54 -0700101}