blob: 5e17e6cd078b29fa3bcc0670328d43d6ea901d7c [file] [log] [blame]
Thomas Vachuska4f1a60c2014-10-28 13:39:07 -07001/*
2 * Copyright 2014 Open Networking Laboratory
3 *
4 * 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
7 *
8 * 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.
15 */
Jonathan Hartac60c082014-09-23 08:55:17 -070016package org.onlab.onos.net.host;
17
Jonathan Hartc884f1b2014-09-24 11:53:33 -070018import java.util.Collections;
Jonathan Hart09585c62014-09-23 16:58:04 -070019import java.util.HashSet;
Jonathan Hartc884f1b2014-09-24 11:53:33 -070020import java.util.Objects;
Jonathan Hart09585c62014-09-23 16:58:04 -070021import java.util.Set;
22
Jonathan Hartac60c082014-09-23 08:55:17 -070023import org.onlab.onos.net.ConnectPoint;
Jonathan Hartac60c082014-09-23 08:55:17 -070024import org.onlab.packet.MacAddress;
25
Jonathan Hart74f9c3b2014-09-29 20:03:50 -070026import com.google.common.base.MoreObjects;
27
Jonathan Hartac60c082014-09-23 08:55:17 -070028/**
29 * Represents address information bound to a port.
30 */
Jonathan Hart09585c62014-09-23 16:58:04 -070031public class PortAddresses {
32
33 private final ConnectPoint connectPoint;
Pavlin Radoslavov76b0ae22014-10-27 15:33:19 -070034 private final Set<InterfaceIpAddress> ipAddresses;
Jonathan Hart09585c62014-09-23 16:58:04 -070035 private final MacAddress macAddress;
36
37 /**
Pavlin Radoslavov76b0ae22014-10-27 15:33:19 -070038 * Constructs a PortAddresses object for the given connection point, with a
Thomas Vachuska4b420772014-10-30 16:46:17 -070039 * set of IP addresses and a MAC address. Both address parameters are
40 * optional and can be set to null.
Jonathan Hart09585c62014-09-23 16:58:04 -070041 *
42 * @param connectPoint the connection point these addresses are for
Pavlin Radoslavov76b0ae22014-10-27 15:33:19 -070043 * @param ipAddresses a set of interface IP addresses
Jonathan Hart09585c62014-09-23 16:58:04 -070044 * @param mac a MAC address
45 */
46 public PortAddresses(ConnectPoint connectPoint,
Pavlin Radoslavov76b0ae22014-10-27 15:33:19 -070047 Set<InterfaceIpAddress> ipAddresses, MacAddress mac) {
Jonathan Hart09585c62014-09-23 16:58:04 -070048 this.connectPoint = connectPoint;
Pavlin Radoslavov76b0ae22014-10-27 15:33:19 -070049 this.ipAddresses = (ipAddresses == null) ?
50 Collections.<InterfaceIpAddress>emptySet()
51 : new HashSet<>(ipAddresses);
Jonathan Hart09585c62014-09-23 16:58:04 -070052 this.macAddress = mac;
53 }
Jonathan Hartac60c082014-09-23 08:55:17 -070054
55 /**
56 * Returns the connection point this address information is bound to.
57 *
58 * @return the connection point
59 */
Jonathan Hart09585c62014-09-23 16:58:04 -070060 public ConnectPoint connectPoint() {
61 return connectPoint;
62 }
Jonathan Hartac60c082014-09-23 08:55:17 -070063
64 /**
Pavlin Radoslavov76b0ae22014-10-27 15:33:19 -070065 * Returns the set of interface IP addresses.
Jonathan Hartac60c082014-09-23 08:55:17 -070066 *
Pavlin Radoslavov76b0ae22014-10-27 15:33:19 -070067 * @return the interface IP addresses
Jonathan Hartac60c082014-09-23 08:55:17 -070068 */
Pavlin Radoslavov76b0ae22014-10-27 15:33:19 -070069 public Set<InterfaceIpAddress> ipAddresses() {
Jonathan Hart09585c62014-09-23 16:58:04 -070070 return ipAddresses;
71 }
Jonathan Hartac60c082014-09-23 08:55:17 -070072
73 /**
Jonathan Hart09585c62014-09-23 16:58:04 -070074 * Returns the MAC address.
Jonathan Hartac60c082014-09-23 08:55:17 -070075 *
Jonathan Hart09585c62014-09-23 16:58:04 -070076 * @return the MAC address
Jonathan Hartac60c082014-09-23 08:55:17 -070077 */
Jonathan Hart09585c62014-09-23 16:58:04 -070078 public MacAddress mac() {
79 return macAddress;
80 }
81
Jonathan Hartc884f1b2014-09-24 11:53:33 -070082 @Override
83 public boolean equals(Object other) {
84 if (this == other) {
85 return true;
86 }
87
88 if (!(other instanceof PortAddresses)) {
89 return false;
90 }
91
92 PortAddresses otherPa = (PortAddresses) other;
93
94 return Objects.equals(this.connectPoint, otherPa.connectPoint)
95 && Objects.equals(this.ipAddresses, otherPa.ipAddresses)
96 && Objects.equals(this.macAddress, otherPa.macAddress);
97 }
98
99 @Override
100 public int hashCode() {
101 return Objects.hash(connectPoint, ipAddresses, macAddress);
102 }
Jonathan Hart74f9c3b2014-09-29 20:03:50 -0700103
104 @Override
105 public String toString() {
106 return MoreObjects.toStringHelper(getClass())
107 .add("connect-point", connectPoint)
108 .add("ip-addresses", ipAddresses)
109 .add("mac-address", macAddress)
110 .toString();
111 }
Jonathan Hartac60c082014-09-23 08:55:17 -0700112}