blob: 588b03c1adb7669c6526b3ca70772d0c56ce27cb [file] [log] [blame]
Thomas Vachuska781d18b2014-10-27 10:31:25 -07001/*
Thomas Vachuska4f1a60c2014-10-28 13:39:07 -07002 * Copyright 2014 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 Hartbac07a02014-10-13 21:29:54 -070016package org.onlab.onos.sdnip.config;
17
18import java.util.Objects;
19
Jonathan Hartbac07a02014-10-13 21:29:54 -070020import org.onlab.onos.net.ConnectPoint;
21import org.onlab.onos.net.DeviceId;
22import org.onlab.onos.net.PortNumber;
23import org.onlab.packet.IpAddress;
24
Jonathan Hartd7bd9822014-10-20 18:18:02 -070025import com.fasterxml.jackson.annotation.JsonProperty;
Jonathan Hartdc711bd2014-10-15 11:24:23 -070026import com.google.common.base.MoreObjects;
27
Jonathan Hartbac07a02014-10-13 21:29:54 -070028/**
29 * Represents an address of a {@link BgpSpeaker} configured on an
30 * {@link Interface}.
31 * <p/>
32 * Each InterfaceAddress includes the interface name and an IP address.
33 */
34public class InterfaceAddress {
35 private final ConnectPoint connectPoint;
36 private final IpAddress ipAddress;
37
38 /**
Jonathan Hartdc711bd2014-10-15 11:24:23 -070039 * Creates an InterfaceAddress object.
Jonathan Hartbac07a02014-10-13 21:29:54 -070040 *
Jonathan Hartdc711bd2014-10-15 11:24:23 -070041 * @param dpid the DPID of the interface as a String
42 * @param port the port of the interface
Jonathan Hartbac07a02014-10-13 21:29:54 -070043 * @param ipAddress the IP address of a {@link BgpSpeaker} configured on
44 * the interface
45 */
46 public InterfaceAddress(@JsonProperty("interfaceDpid") String dpid,
47 @JsonProperty("interfacePort") int port,
48 @JsonProperty("ipAddress") String ipAddress) {
49 this.connectPoint = new ConnectPoint(
50 DeviceId.deviceId(SdnIpConfigReader.dpidToUri(dpid)),
51 PortNumber.portNumber(port));
52 this.ipAddress = IpAddress.valueOf(ipAddress);
53 }
54
55 /**
56 * Gets the connection point of the peer.
57 *
58 * @return the connection point
59 */
Jonathan Hartdc711bd2014-10-15 11:24:23 -070060 public ConnectPoint connectPoint() {
Jonathan Hartbac07a02014-10-13 21:29:54 -070061 return connectPoint;
62 }
63
64 /**
65 * Gets the IP address of a BGP speaker configured on an {@link Interface}.
66 *
67 * @return the IP address
68 */
Jonathan Hartdc711bd2014-10-15 11:24:23 -070069 public IpAddress ipAddress() {
Jonathan Hartbac07a02014-10-13 21:29:54 -070070 return ipAddress;
71 }
72
73 @Override
74 public int hashCode() {
75 return Objects.hash(connectPoint, ipAddress);
76 }
77
78 @Override
79 public boolean equals(Object obj) {
80 if (obj == this) {
81 return true;
82 }
83
84 if (!(obj instanceof InterfaceAddress)) {
85 return false;
86 }
87
88 InterfaceAddress that = (InterfaceAddress) obj;
89 return Objects.equals(this.connectPoint, that.connectPoint)
90 && Objects.equals(this.ipAddress, that.ipAddress);
91 }
Jonathan Hartdc711bd2014-10-15 11:24:23 -070092
93 @Override
94 public String toString() {
95 return MoreObjects.toStringHelper(getClass())
96 .add("connectPoint", connectPoint)
97 .add("ipAddress", ipAddress)
98 .toString();
99 }
Jonathan Hartbac07a02014-10-13 21:29:54 -0700100}