blob: 86782bf4107c5cde77717b25ed8fad96b6a9b670 [file] [log] [blame]
Thomas Vachuska781d18b2014-10-27 10:31:25 -07001/*
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 Hartbac07a02014-10-13 21:29:54 -070019package org.onlab.onos.sdnip.config;
20
21import java.util.Objects;
22
Jonathan Hartbac07a02014-10-13 21:29:54 -070023import org.onlab.onos.net.ConnectPoint;
24import org.onlab.onos.net.DeviceId;
25import org.onlab.onos.net.PortNumber;
26import org.onlab.packet.IpAddress;
27
Jonathan Hartd7bd9822014-10-20 18:18:02 -070028import com.fasterxml.jackson.annotation.JsonProperty;
Jonathan Hartdc711bd2014-10-15 11:24:23 -070029import com.google.common.base.MoreObjects;
30
Jonathan Hartbac07a02014-10-13 21:29:54 -070031/**
Jonathan Hartdc711bd2014-10-15 11:24:23 -070032 * Configuration details for a BGP peer.
Jonathan Hartbac07a02014-10-13 21:29:54 -070033 */
34public class BgpPeer {
35 private final ConnectPoint connectPoint;
36 private final IpAddress ipAddress;
37
38 /**
Jonathan Hartdc711bd2014-10-15 11:24:23 -070039 * Creates a new BgpPeer.
Jonathan Hartbac07a02014-10-13 21:29:54 -070040 *
Jonathan Hartdc711bd2014-10-15 11:24:23 -070041 * @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 Hartbac07a02014-10-13 21:29:54 -070043 * @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 Hartdc711bd2014-10-15 11:24:23 -070059 public ConnectPoint connectPoint() {
Jonathan Hartbac07a02014-10-13 21:29:54 -070060 return connectPoint;
61 }
62
63 /**
64 * Gets the IP address of the peer.
65 *
66 * @return the IP address
67 */
Jonathan Hartdc711bd2014-10-15 11:24:23 -070068 public IpAddress ipAddress() {
Jonathan Hartbac07a02014-10-13 21:29:54 -070069 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 Hartdc711bd2014-10-15 11:24:23 -070091
92 @Override
93 public String toString() {
94 return MoreObjects.toStringHelper(getClass())
95 .add("connectPoint", connectPoint)
96 .add("ipAddress", ipAddress)
97 .toString();
98 }
Jonathan Hartbac07a02014-10-13 21:29:54 -070099}