Thomas Vachuska | 781d18b | 2014-10-27 10:31:25 -0700 | [diff] [blame] | 1 | /* |
| 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 Hart | bac07a0 | 2014-10-13 21:29:54 -0700 | [diff] [blame] | 19 | package org.onlab.onos.sdnip.config; |
| 20 | |
| 21 | import java.util.Objects; |
| 22 | |
Jonathan Hart | bac07a0 | 2014-10-13 21:29:54 -0700 | [diff] [blame] | 23 | import org.onlab.onos.net.ConnectPoint; |
| 24 | import org.onlab.onos.net.DeviceId; |
| 25 | import org.onlab.onos.net.PortNumber; |
| 26 | import org.onlab.packet.IpAddress; |
| 27 | |
Jonathan Hart | d7bd982 | 2014-10-20 18:18:02 -0700 | [diff] [blame] | 28 | import com.fasterxml.jackson.annotation.JsonProperty; |
Jonathan Hart | dc711bd | 2014-10-15 11:24:23 -0700 | [diff] [blame] | 29 | import com.google.common.base.MoreObjects; |
| 30 | |
Jonathan Hart | bac07a0 | 2014-10-13 21:29:54 -0700 | [diff] [blame] | 31 | /** |
| 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 | */ |
| 37 | public class InterfaceAddress { |
| 38 | private final ConnectPoint connectPoint; |
| 39 | private final IpAddress ipAddress; |
| 40 | |
| 41 | /** |
Jonathan Hart | dc711bd | 2014-10-15 11:24:23 -0700 | [diff] [blame] | 42 | * Creates an InterfaceAddress object. |
Jonathan Hart | bac07a0 | 2014-10-13 21:29:54 -0700 | [diff] [blame] | 43 | * |
Jonathan Hart | dc711bd | 2014-10-15 11:24:23 -0700 | [diff] [blame] | 44 | * @param dpid the DPID of the interface as a String |
| 45 | * @param port the port of the interface |
Jonathan Hart | bac07a0 | 2014-10-13 21:29:54 -0700 | [diff] [blame] | 46 | * @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 Hart | dc711bd | 2014-10-15 11:24:23 -0700 | [diff] [blame] | 63 | public ConnectPoint connectPoint() { |
Jonathan Hart | bac07a0 | 2014-10-13 21:29:54 -0700 | [diff] [blame] | 64 | 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 Hart | dc711bd | 2014-10-15 11:24:23 -0700 | [diff] [blame] | 72 | public IpAddress ipAddress() { |
Jonathan Hart | bac07a0 | 2014-10-13 21:29:54 -0700 | [diff] [blame] | 73 | 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 Hart | dc711bd | 2014-10-15 11:24:23 -0700 | [diff] [blame] | 95 | |
| 96 | @Override |
| 97 | public String toString() { |
| 98 | return MoreObjects.toStringHelper(getClass()) |
| 99 | .add("connectPoint", connectPoint) |
| 100 | .add("ipAddress", ipAddress) |
| 101 | .toString(); |
| 102 | } |
Jonathan Hart | bac07a0 | 2014-10-13 21:29:54 -0700 | [diff] [blame] | 103 | } |