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 | /** |
Jonathan Hart | dc711bd | 2014-10-15 11:24:23 -0700 | [diff] [blame] | 32 | * Configuration details for a BGP peer. |
Jonathan Hart | bac07a0 | 2014-10-13 21:29:54 -0700 | [diff] [blame] | 33 | */ |
| 34 | public class BgpPeer { |
| 35 | private final ConnectPoint connectPoint; |
| 36 | private final IpAddress ipAddress; |
| 37 | |
| 38 | /** |
Jonathan Hart | dc711bd | 2014-10-15 11:24:23 -0700 | [diff] [blame] | 39 | * Creates a new BgpPeer. |
Jonathan Hart | bac07a0 | 2014-10-13 21:29:54 -0700 | [diff] [blame] | 40 | * |
Jonathan Hart | dc711bd | 2014-10-15 11:24:23 -0700 | [diff] [blame] | 41 | * @param dpid the DPID of the switch the peer is attached at, as a String |
| 42 | * @param port the port the peer is attached at |
Jonathan Hart | bac07a0 | 2014-10-13 21:29:54 -0700 | [diff] [blame] | 43 | * @param ipAddress the IP address of the peer as a String |
| 44 | */ |
| 45 | public BgpPeer(@JsonProperty("attachmentDpid") String dpid, |
| 46 | @JsonProperty("attachmentPort") int port, |
| 47 | @JsonProperty("ipAddress") String ipAddress) { |
| 48 | this.connectPoint = new ConnectPoint( |
| 49 | DeviceId.deviceId(SdnIpConfigReader.dpidToUri(dpid)), |
| 50 | PortNumber.portNumber(port)); |
| 51 | this.ipAddress = IpAddress.valueOf(ipAddress); |
| 52 | } |
| 53 | |
| 54 | /** |
| 55 | * Gets the connection point of the peer. |
| 56 | * |
| 57 | * @return the connection point |
| 58 | */ |
Jonathan Hart | dc711bd | 2014-10-15 11:24:23 -0700 | [diff] [blame] | 59 | public ConnectPoint connectPoint() { |
Jonathan Hart | bac07a0 | 2014-10-13 21:29:54 -0700 | [diff] [blame] | 60 | return connectPoint; |
| 61 | } |
| 62 | |
| 63 | /** |
| 64 | * Gets the IP address of the peer. |
| 65 | * |
| 66 | * @return the IP address |
| 67 | */ |
Jonathan Hart | dc711bd | 2014-10-15 11:24:23 -0700 | [diff] [blame] | 68 | public IpAddress ipAddress() { |
Jonathan Hart | bac07a0 | 2014-10-13 21:29:54 -0700 | [diff] [blame] | 69 | return ipAddress; |
| 70 | } |
| 71 | |
| 72 | @Override |
| 73 | public int hashCode() { |
| 74 | return Objects.hash(connectPoint, ipAddress); |
| 75 | } |
| 76 | |
| 77 | @Override |
| 78 | public boolean equals(Object obj) { |
| 79 | if (obj == this) { |
| 80 | return true; |
| 81 | } |
| 82 | |
| 83 | if (!(obj instanceof BgpPeer)) { |
| 84 | return false; |
| 85 | } |
| 86 | |
| 87 | BgpPeer that = (BgpPeer) obj; |
| 88 | return Objects.equals(this.connectPoint, that.connectPoint) |
| 89 | && Objects.equals(this.ipAddress, that.ipAddress); |
| 90 | } |
Jonathan Hart | dc711bd | 2014-10-15 11:24:23 -0700 | [diff] [blame] | 91 | |
| 92 | @Override |
| 93 | public String toString() { |
| 94 | return MoreObjects.toStringHelper(getClass()) |
| 95 | .add("connectPoint", connectPoint) |
| 96 | .add("ipAddress", ipAddress) |
| 97 | .toString(); |
| 98 | } |
Jonathan Hart | bac07a0 | 2014-10-13 21:29:54 -0700 | [diff] [blame] | 99 | } |