Thomas Vachuska | 781d18b | 2014-10-27 10:31:25 -0700 | [diff] [blame] | 1 | /* |
Ray Milkey | 34c9590 | 2015-04-15 09:47:53 -0700 | [diff] [blame] | 2 | * Copyright 2014-2015 Open Networking Laboratory |
Thomas Vachuska | 781d18b | 2014-10-27 10:31:25 -0700 | [diff] [blame] | 3 | * |
Thomas Vachuska | 4f1a60c | 2014-10-28 13:39:07 -0700 | [diff] [blame] | 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 |
Thomas Vachuska | 781d18b | 2014-10-27 10:31:25 -0700 | [diff] [blame] | 7 | * |
Thomas Vachuska | 4f1a60c | 2014-10-28 13:39:07 -0700 | [diff] [blame] | 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. |
Thomas Vachuska | 781d18b | 2014-10-27 10:31:25 -0700 | [diff] [blame] | 15 | */ |
Jonathan Hart | 2da1e60 | 2015-02-18 19:09:24 -0800 | [diff] [blame] | 16 | package org.onosproject.routing.config; |
Jonathan Hart | bac07a0 | 2014-10-13 21:29:54 -0700 | [diff] [blame] | 17 | |
Jonathan Hart | d7bd982 | 2014-10-20 18:18:02 -0700 | [diff] [blame] | 18 | import com.fasterxml.jackson.annotation.JsonProperty; |
Jonathan Hart | dc711bd | 2014-10-15 11:24:23 -0700 | [diff] [blame] | 19 | import com.google.common.base.MoreObjects; |
Jonathan Hart | 90a02c2 | 2015-02-13 11:52:07 -0800 | [diff] [blame] | 20 | import org.onlab.packet.IpAddress; |
| 21 | import org.onosproject.net.ConnectPoint; |
| 22 | import org.onosproject.net.DeviceId; |
| 23 | import org.onosproject.net.NetTools; |
| 24 | import org.onosproject.net.PortNumber; |
| 25 | |
| 26 | import java.util.Objects; |
Jonathan Hart | dc711bd | 2014-10-15 11:24:23 -0700 | [diff] [blame] | 27 | |
Jonathan Hart | bac07a0 | 2014-10-13 21:29:54 -0700 | [diff] [blame] | 28 | /** |
| 29 | * Represents an address of a {@link BgpSpeaker} configured on an |
| 30 | * {@link Interface}. |
Thomas Vachuska | 4b42077 | 2014-10-30 16:46:17 -0700 | [diff] [blame] | 31 | * <p> |
Jonathan Hart | bac07a0 | 2014-10-13 21:29:54 -0700 | [diff] [blame] | 32 | * Each InterfaceAddress includes the interface name and an IP address. |
Thomas Vachuska | 4b42077 | 2014-10-30 16:46:17 -0700 | [diff] [blame] | 33 | * </p> |
Jonathan Hart | bac07a0 | 2014-10-13 21:29:54 -0700 | [diff] [blame] | 34 | */ |
| 35 | public class InterfaceAddress { |
| 36 | private final ConnectPoint connectPoint; |
| 37 | private final IpAddress ipAddress; |
| 38 | |
| 39 | /** |
Jonathan Hart | dc711bd | 2014-10-15 11:24:23 -0700 | [diff] [blame] | 40 | * Creates an InterfaceAddress object. |
Jonathan Hart | bac07a0 | 2014-10-13 21:29:54 -0700 | [diff] [blame] | 41 | * |
Jonathan Hart | dc711bd | 2014-10-15 11:24:23 -0700 | [diff] [blame] | 42 | * @param dpid the DPID of the interface as a String |
| 43 | * @param port the port of the interface |
Jonathan Hart | bac07a0 | 2014-10-13 21:29:54 -0700 | [diff] [blame] | 44 | * @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 Hart | 90a02c2 | 2015-02-13 11:52:07 -0800 | [diff] [blame] | 51 | DeviceId.deviceId(NetTools.dpidToUri(dpid)), |
Jonathan Hart | bac07a0 | 2014-10-13 21:29:54 -0700 | [diff] [blame] | 52 | 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 Hart | dc711bd | 2014-10-15 11:24:23 -0700 | [diff] [blame] | 61 | public ConnectPoint connectPoint() { |
Jonathan Hart | bac07a0 | 2014-10-13 21:29:54 -0700 | [diff] [blame] | 62 | 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 Hart | dc711bd | 2014-10-15 11:24:23 -0700 | [diff] [blame] | 70 | public IpAddress ipAddress() { |
Jonathan Hart | bac07a0 | 2014-10-13 21:29:54 -0700 | [diff] [blame] | 71 | 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 Hart | dc711bd | 2014-10-15 11:24:23 -0700 | [diff] [blame] | 93 | |
| 94 | @Override |
| 95 | public String toString() { |
| 96 | return MoreObjects.toStringHelper(getClass()) |
| 97 | .add("connectPoint", connectPoint) |
| 98 | .add("ipAddress", ipAddress) |
| 99 | .toString(); |
| 100 | } |
Jonathan Hart | bac07a0 | 2014-10-13 21:29:54 -0700 | [diff] [blame] | 101 | } |