blob: d06a7c9b81849b19f34aa45b9ce9a94aa08f2505 [file] [log] [blame]
Thomas Vachuska781d18b2014-10-27 10:31:25 -07001/*
2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements. See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership. The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License. You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing,
13 * software distributed under the License is distributed on an
14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 * KIND, either express or implied. See the License for the
16 * specific language governing permissions and limitations
17 * under the License.
18 */
Jonathan Hartbac07a02014-10-13 21:29:54 -070019package org.onlab.onos.sdnip.config;
20
21import java.util.Objects;
22
Jonathan Hartbac07a02014-10-13 21:29:54 -070023import org.onlab.onos.net.ConnectPoint;
24import org.onlab.onos.net.DeviceId;
25import org.onlab.onos.net.PortNumber;
26import org.onlab.packet.IpAddress;
27
Jonathan Hartd7bd9822014-10-20 18:18:02 -070028import com.fasterxml.jackson.annotation.JsonProperty;
Jonathan Hartdc711bd2014-10-15 11:24:23 -070029import com.google.common.base.MoreObjects;
30
Jonathan Hartbac07a02014-10-13 21:29:54 -070031/**
32 * Represents an address of a {@link BgpSpeaker} configured on an
33 * {@link Interface}.
34 * <p/>
35 * Each InterfaceAddress includes the interface name and an IP address.
36 */
37public class InterfaceAddress {
38 private final ConnectPoint connectPoint;
39 private final IpAddress ipAddress;
40
41 /**
Jonathan Hartdc711bd2014-10-15 11:24:23 -070042 * Creates an InterfaceAddress object.
Jonathan Hartbac07a02014-10-13 21:29:54 -070043 *
Jonathan Hartdc711bd2014-10-15 11:24:23 -070044 * @param dpid the DPID of the interface as a String
45 * @param port the port of the interface
Jonathan Hartbac07a02014-10-13 21:29:54 -070046 * @param ipAddress the IP address of a {@link BgpSpeaker} configured on
47 * the interface
48 */
49 public InterfaceAddress(@JsonProperty("interfaceDpid") String dpid,
50 @JsonProperty("interfacePort") int port,
51 @JsonProperty("ipAddress") String ipAddress) {
52 this.connectPoint = new ConnectPoint(
53 DeviceId.deviceId(SdnIpConfigReader.dpidToUri(dpid)),
54 PortNumber.portNumber(port));
55 this.ipAddress = IpAddress.valueOf(ipAddress);
56 }
57
58 /**
59 * Gets the connection point of the peer.
60 *
61 * @return the connection point
62 */
Jonathan Hartdc711bd2014-10-15 11:24:23 -070063 public ConnectPoint connectPoint() {
Jonathan Hartbac07a02014-10-13 21:29:54 -070064 return connectPoint;
65 }
66
67 /**
68 * Gets the IP address of a BGP speaker configured on an {@link Interface}.
69 *
70 * @return the IP address
71 */
Jonathan Hartdc711bd2014-10-15 11:24:23 -070072 public IpAddress ipAddress() {
Jonathan Hartbac07a02014-10-13 21:29:54 -070073 return ipAddress;
74 }
75
76 @Override
77 public int hashCode() {
78 return Objects.hash(connectPoint, ipAddress);
79 }
80
81 @Override
82 public boolean equals(Object obj) {
83 if (obj == this) {
84 return true;
85 }
86
87 if (!(obj instanceof InterfaceAddress)) {
88 return false;
89 }
90
91 InterfaceAddress that = (InterfaceAddress) obj;
92 return Objects.equals(this.connectPoint, that.connectPoint)
93 && Objects.equals(this.ipAddress, that.ipAddress);
94 }
Jonathan Hartdc711bd2014-10-15 11:24:23 -070095
96 @Override
97 public String toString() {
98 return MoreObjects.toStringHelper(getClass())
99 .add("connectPoint", connectPoint)
100 .add("ipAddress", ipAddress)
101 .toString();
102 }
Jonathan Hartbac07a02014-10-13 21:29:54 -0700103}