blob: 5d890756af27b056db682bca70816e7fa00cb84c [file] [log] [blame]
Thomas Vachuska781d18b2014-10-27 10:31:25 -07001/*
Thomas Vachuska4f1a60c2014-10-28 13:39:07 -07002 * Copyright 2014 Open Networking Laboratory
Thomas Vachuska781d18b2014-10-27 10:31:25 -07003 *
Thomas Vachuska4f1a60c2014-10-28 13:39:07 -07004 * 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 Vachuska781d18b2014-10-27 10:31:25 -07007 *
Thomas Vachuska4f1a60c2014-10-28 13:39:07 -07008 * 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 Vachuska781d18b2014-10-27 10:31:25 -070015 */
Brian O'Connorabafb502014-12-02 22:26:20 -080016package org.onosproject.sdnip.config;
Jonathan Hartbac07a02014-10-13 21:29:54 -070017
Jonathan Hart43ae2932015-01-20 11:08:20 -080018import com.fasterxml.jackson.annotation.JsonProperty;
19import com.google.common.base.MoreObjects;
Pavlin Radoslavov2020eac2015-01-06 17:26:10 -080020import org.onlab.packet.IpAddress;
Brian O'Connorabafb502014-12-02 22:26:20 -080021import org.onosproject.net.ConnectPoint;
22import org.onosproject.net.DeviceId;
23import org.onosproject.net.PortNumber;
Jonathan Hartbac07a02014-10-13 21:29:54 -070024
Jonathan Hart43ae2932015-01-20 11:08:20 -080025import java.util.Objects;
Jonathan Hartdc711bd2014-10-15 11:24:23 -070026
Jonathan Hartbac07a02014-10-13 21:29:54 -070027/**
Jonathan Hartdc711bd2014-10-15 11:24:23 -070028 * Configuration details for a BGP peer.
Jonathan Hartbac07a02014-10-13 21:29:54 -070029 */
30public class BgpPeer {
31 private final ConnectPoint connectPoint;
32 private final IpAddress ipAddress;
33
34 /**
Jonathan Hartdc711bd2014-10-15 11:24:23 -070035 * Creates a new BgpPeer.
Jonathan Hartbac07a02014-10-13 21:29:54 -070036 *
Jonathan Hartdc711bd2014-10-15 11:24:23 -070037 * @param dpid the DPID of the switch the peer is attached at, as a String
38 * @param port the port the peer is attached at
Jonathan Hartbac07a02014-10-13 21:29:54 -070039 * @param ipAddress the IP address of the peer as a String
40 */
41 public BgpPeer(@JsonProperty("attachmentDpid") String dpid,
Jonathan Hart43ae2932015-01-20 11:08:20 -080042 @JsonProperty("attachmentPort") long port,
Jonathan Hartbac07a02014-10-13 21:29:54 -070043 @JsonProperty("ipAddress") String ipAddress) {
44 this.connectPoint = new ConnectPoint(
Jonathan Hart9965d772014-12-02 10:28:34 -080045 DeviceId.deviceId(SdnIpConfigurationReader.dpidToUri(dpid)),
Jonathan Hartbac07a02014-10-13 21:29:54 -070046 PortNumber.portNumber(port));
47 this.ipAddress = IpAddress.valueOf(ipAddress);
48 }
49
50 /**
51 * Gets the connection point of the peer.
52 *
53 * @return the connection point
54 */
Jonathan Hartdc711bd2014-10-15 11:24:23 -070055 public ConnectPoint connectPoint() {
Jonathan Hartbac07a02014-10-13 21:29:54 -070056 return connectPoint;
57 }
58
59 /**
60 * Gets the IP address of the peer.
61 *
62 * @return the IP address
63 */
Jonathan Hartdc711bd2014-10-15 11:24:23 -070064 public IpAddress ipAddress() {
Jonathan Hartbac07a02014-10-13 21:29:54 -070065 return ipAddress;
66 }
67
68 @Override
69 public int hashCode() {
70 return Objects.hash(connectPoint, ipAddress);
71 }
72
73 @Override
74 public boolean equals(Object obj) {
75 if (obj == this) {
76 return true;
77 }
78
79 if (!(obj instanceof BgpPeer)) {
80 return false;
81 }
82
83 BgpPeer that = (BgpPeer) obj;
84 return Objects.equals(this.connectPoint, that.connectPoint)
85 && Objects.equals(this.ipAddress, that.ipAddress);
86 }
Jonathan Hartdc711bd2014-10-15 11:24:23 -070087
88 @Override
89 public String toString() {
90 return MoreObjects.toStringHelper(getClass())
91 .add("connectPoint", connectPoint)
92 .add("ipAddress", ipAddress)
93 .toString();
94 }
Jonathan Hartbac07a02014-10-13 21:29:54 -070095}