blob: e08177f72de7236b75260d7f54a031df4be4a163 [file] [log] [blame]
Thomas Vachuska781d18b2014-10-27 10:31:25 -07001/*
Brian O'Connor5ab426f2016-04-09 01:19:45 -07002 * Copyright 2015-present 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 */
Jonathan Hart2da1e602015-02-18 19:09:24 -080016package org.onosproject.routing.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;
Jonathan Hart90a02c22015-02-13 11:52:07 -080023import org.onosproject.net.NetTools;
Brian O'Connorabafb502014-12-02 22:26:20 -080024import org.onosproject.net.PortNumber;
Jonathan Hartbac07a02014-10-13 21:29:54 -070025
Jonathan Hart43ae2932015-01-20 11:08:20 -080026import java.util.Objects;
Jonathan Hartdc711bd2014-10-15 11:24:23 -070027
Jonathan Hartbac07a02014-10-13 21:29:54 -070028/**
Jonathan Hartdc711bd2014-10-15 11:24:23 -070029 * Configuration details for a BGP peer.
Jonathan Hartbac07a02014-10-13 21:29:54 -070030 */
31public class BgpPeer {
32 private final ConnectPoint connectPoint;
33 private final IpAddress ipAddress;
34
35 /**
Jonathan Hartdc711bd2014-10-15 11:24:23 -070036 * Creates a new BgpPeer.
Jonathan Hartbac07a02014-10-13 21:29:54 -070037 *
Jonathan Hartdc711bd2014-10-15 11:24:23 -070038 * @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 Hartbac07a02014-10-13 21:29:54 -070040 * @param ipAddress the IP address of the peer as a String
41 */
42 public BgpPeer(@JsonProperty("attachmentDpid") String dpid,
Jonathan Hart43ae2932015-01-20 11:08:20 -080043 @JsonProperty("attachmentPort") long port,
Jonathan Hartbac07a02014-10-13 21:29:54 -070044 @JsonProperty("ipAddress") String ipAddress) {
45 this.connectPoint = new ConnectPoint(
Jonathan Hart90a02c22015-02-13 11:52:07 -080046 DeviceId.deviceId(NetTools.dpidToUri(dpid)),
Jonathan Hartbac07a02014-10-13 21:29:54 -070047 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 Hartdc711bd2014-10-15 11:24:23 -070056 public ConnectPoint connectPoint() {
Jonathan Hartbac07a02014-10-13 21:29:54 -070057 return connectPoint;
58 }
59
60 /**
61 * Gets the IP address of the peer.
62 *
63 * @return the IP address
64 */
Jonathan Hartdc711bd2014-10-15 11:24:23 -070065 public IpAddress ipAddress() {
Jonathan Hartbac07a02014-10-13 21:29:54 -070066 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 Hartdc711bd2014-10-15 11:24:23 -070088
89 @Override
90 public String toString() {
91 return MoreObjects.toStringHelper(getClass())
92 .add("connectPoint", connectPoint)
93 .add("ipAddress", ipAddress)
94 .toString();
95 }
Jonathan Hartbac07a02014-10-13 21:29:54 -070096}