blob: 6477ba67b5a491af5d9522b19d18426781ede91a [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 */
Jonathan Hartbac07a02014-10-13 21:29:54 -070016package org.onlab.onos.sdnip.config;
17
18import java.util.Objects;
19
Jonathan Hartbac07a02014-10-13 21:29:54 -070020import org.onlab.onos.net.ConnectPoint;
21import org.onlab.onos.net.DeviceId;
22import org.onlab.onos.net.PortNumber;
23import org.onlab.packet.IpAddress;
24
Jonathan Hartd7bd9822014-10-20 18:18:02 -070025import com.fasterxml.jackson.annotation.JsonProperty;
Jonathan Hartdc711bd2014-10-15 11:24:23 -070026import com.google.common.base.MoreObjects;
27
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,
43 @JsonProperty("attachmentPort") int port,
44 @JsonProperty("ipAddress") String ipAddress) {
45 this.connectPoint = new ConnectPoint(
Jonathan Hart9965d772014-12-02 10:28:34 -080046 DeviceId.deviceId(SdnIpConfigurationReader.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}