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 | 43ae293 | 2015-01-20 11:08:20 -0800 | [diff] [blame] | 18 | import com.fasterxml.jackson.annotation.JsonProperty; |
| 19 | import com.google.common.base.MoreObjects; |
Pavlin Radoslavov | 2020eac | 2015-01-06 17:26:10 -0800 | [diff] [blame] | 20 | import org.onlab.packet.IpAddress; |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 21 | import org.onosproject.net.ConnectPoint; |
| 22 | import org.onosproject.net.DeviceId; |
Jonathan Hart | 90a02c2 | 2015-02-13 11:52:07 -0800 | [diff] [blame] | 23 | import org.onosproject.net.NetTools; |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 24 | import org.onosproject.net.PortNumber; |
Jonathan Hart | bac07a0 | 2014-10-13 21:29:54 -0700 | [diff] [blame] | 25 | |
Jonathan Hart | 43ae293 | 2015-01-20 11:08:20 -0800 | [diff] [blame] | 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 | /** |
Jonathan Hart | dc711bd | 2014-10-15 11:24:23 -0700 | [diff] [blame] | 29 | * Configuration details for a BGP peer. |
Jonathan Hart | bac07a0 | 2014-10-13 21:29:54 -0700 | [diff] [blame] | 30 | */ |
| 31 | public class BgpPeer { |
| 32 | private final ConnectPoint connectPoint; |
| 33 | private final IpAddress ipAddress; |
| 34 | |
| 35 | /** |
Jonathan Hart | dc711bd | 2014-10-15 11:24:23 -0700 | [diff] [blame] | 36 | * Creates a new BgpPeer. |
Jonathan Hart | bac07a0 | 2014-10-13 21:29:54 -0700 | [diff] [blame] | 37 | * |
Jonathan Hart | dc711bd | 2014-10-15 11:24:23 -0700 | [diff] [blame] | 38 | * @param dpid the DPID of the switch the peer is attached at, as a String |
| 39 | * @param port the port the peer is attached at |
Jonathan Hart | bac07a0 | 2014-10-13 21:29:54 -0700 | [diff] [blame] | 40 | * @param ipAddress the IP address of the peer as a String |
| 41 | */ |
| 42 | public BgpPeer(@JsonProperty("attachmentDpid") String dpid, |
Jonathan Hart | 43ae293 | 2015-01-20 11:08:20 -0800 | [diff] [blame] | 43 | @JsonProperty("attachmentPort") long port, |
Jonathan Hart | bac07a0 | 2014-10-13 21:29:54 -0700 | [diff] [blame] | 44 | @JsonProperty("ipAddress") String ipAddress) { |
| 45 | this.connectPoint = new ConnectPoint( |
Jonathan Hart | 90a02c2 | 2015-02-13 11:52:07 -0800 | [diff] [blame] | 46 | DeviceId.deviceId(NetTools.dpidToUri(dpid)), |
Jonathan Hart | bac07a0 | 2014-10-13 21:29:54 -0700 | [diff] [blame] | 47 | PortNumber.portNumber(port)); |
| 48 | this.ipAddress = IpAddress.valueOf(ipAddress); |
| 49 | } |
| 50 | |
| 51 | /** |
| 52 | * Gets the connection point of the peer. |
| 53 | * |
| 54 | * @return the connection point |
| 55 | */ |
Jonathan Hart | dc711bd | 2014-10-15 11:24:23 -0700 | [diff] [blame] | 56 | public ConnectPoint connectPoint() { |
Jonathan Hart | bac07a0 | 2014-10-13 21:29:54 -0700 | [diff] [blame] | 57 | return connectPoint; |
| 58 | } |
| 59 | |
| 60 | /** |
| 61 | * Gets the IP address of the peer. |
| 62 | * |
| 63 | * @return the IP address |
| 64 | */ |
Jonathan Hart | dc711bd | 2014-10-15 11:24:23 -0700 | [diff] [blame] | 65 | public IpAddress ipAddress() { |
Jonathan Hart | bac07a0 | 2014-10-13 21:29:54 -0700 | [diff] [blame] | 66 | return ipAddress; |
| 67 | } |
| 68 | |
| 69 | @Override |
| 70 | public int hashCode() { |
| 71 | return Objects.hash(connectPoint, ipAddress); |
| 72 | } |
| 73 | |
| 74 | @Override |
| 75 | public boolean equals(Object obj) { |
| 76 | if (obj == this) { |
| 77 | return true; |
| 78 | } |
| 79 | |
| 80 | if (!(obj instanceof BgpPeer)) { |
| 81 | return false; |
| 82 | } |
| 83 | |
| 84 | BgpPeer that = (BgpPeer) obj; |
| 85 | return Objects.equals(this.connectPoint, that.connectPoint) |
| 86 | && Objects.equals(this.ipAddress, that.ipAddress); |
| 87 | } |
Jonathan Hart | dc711bd | 2014-10-15 11:24:23 -0700 | [diff] [blame] | 88 | |
| 89 | @Override |
| 90 | public String toString() { |
| 91 | return MoreObjects.toStringHelper(getClass()) |
| 92 | .add("connectPoint", connectPoint) |
| 93 | .add("ipAddress", ipAddress) |
| 94 | .toString(); |
| 95 | } |
Jonathan Hart | bac07a0 | 2014-10-13 21:29:54 -0700 | [diff] [blame] | 96 | } |