blob: 728d922a72be17dca6733ec51341ce9b99a776fd [file] [log] [blame]
Jonathan Hartac60c082014-09-23 08:55:17 -07001package org.onlab.onos.net.host;
2
Jonathan Hartc884f1b2014-09-24 11:53:33 -07003import java.util.Collections;
Jonathan Hart09585c62014-09-23 16:58:04 -07004import java.util.HashSet;
Jonathan Hartc884f1b2014-09-24 11:53:33 -07005import java.util.Objects;
Jonathan Hart09585c62014-09-23 16:58:04 -07006import java.util.Set;
7
Jonathan Hartac60c082014-09-23 08:55:17 -07008import org.onlab.onos.net.ConnectPoint;
Jonathan Hart09585c62014-09-23 16:58:04 -07009import org.onlab.packet.IpPrefix;
Jonathan Hartac60c082014-09-23 08:55:17 -070010import org.onlab.packet.MacAddress;
11
Jonathan Hart74f9c3b2014-09-29 20:03:50 -070012import com.google.common.base.MoreObjects;
13
Jonathan Hartac60c082014-09-23 08:55:17 -070014/**
15 * Represents address information bound to a port.
16 */
Jonathan Hart09585c62014-09-23 16:58:04 -070017public class PortAddresses {
18
19 private final ConnectPoint connectPoint;
20 private final Set<IpPrefix> ipAddresses;
21 private final MacAddress macAddress;
22
23 /**
24 * Constructs a PortAddress object for the given connection point, with a
25 * set of IP addresses and a MAC address.
26 * <p/>
27 * Both address parameters are optional and can be set to null.
28 *
29 * @param connectPoint the connection point these addresses are for
30 * @param ips a set of IP addresses
31 * @param mac a MAC address
32 */
33 public PortAddresses(ConnectPoint connectPoint,
34 Set<IpPrefix> ips, MacAddress mac) {
35 this.connectPoint = connectPoint;
Jonathan Hartc884f1b2014-09-24 11:53:33 -070036 this.ipAddresses = (ips == null) ? Collections.<IpPrefix>emptySet() : new HashSet<>(ips);
Jonathan Hart09585c62014-09-23 16:58:04 -070037 this.macAddress = mac;
38 }
Jonathan Hartac60c082014-09-23 08:55:17 -070039
40 /**
41 * Returns the connection point this address information is bound to.
42 *
43 * @return the connection point
44 */
Jonathan Hart09585c62014-09-23 16:58:04 -070045 public ConnectPoint connectPoint() {
46 return connectPoint;
47 }
Jonathan Hartac60c082014-09-23 08:55:17 -070048
49 /**
Jonathan Hart09585c62014-09-23 16:58:04 -070050 * Returns the set of IP addresses.
Jonathan Hartac60c082014-09-23 08:55:17 -070051 *
Jonathan Hart09585c62014-09-23 16:58:04 -070052 * @return the IP addresses
Jonathan Hartac60c082014-09-23 08:55:17 -070053 */
Jonathan Hart09585c62014-09-23 16:58:04 -070054 public Set<IpPrefix> ips() {
55 return ipAddresses;
56 }
Jonathan Hartac60c082014-09-23 08:55:17 -070057
58 /**
Jonathan Hart09585c62014-09-23 16:58:04 -070059 * Returns the MAC address.
Jonathan Hartac60c082014-09-23 08:55:17 -070060 *
Jonathan Hart09585c62014-09-23 16:58:04 -070061 * @return the MAC address
Jonathan Hartac60c082014-09-23 08:55:17 -070062 */
Jonathan Hart09585c62014-09-23 16:58:04 -070063 public MacAddress mac() {
64 return macAddress;
65 }
66
Jonathan Hartc884f1b2014-09-24 11:53:33 -070067 @Override
68 public boolean equals(Object other) {
69 if (this == other) {
70 return true;
71 }
72
73 if (!(other instanceof PortAddresses)) {
74 return false;
75 }
76
77 PortAddresses otherPa = (PortAddresses) other;
78
79 return Objects.equals(this.connectPoint, otherPa.connectPoint)
80 && Objects.equals(this.ipAddresses, otherPa.ipAddresses)
81 && Objects.equals(this.macAddress, otherPa.macAddress);
82 }
83
84 @Override
85 public int hashCode() {
86 return Objects.hash(connectPoint, ipAddresses, macAddress);
87 }
Jonathan Hart74f9c3b2014-09-29 20:03:50 -070088
89 @Override
90 public String toString() {
91 return MoreObjects.toStringHelper(getClass())
92 .add("connect-point", connectPoint)
93 .add("ip-addresses", ipAddresses)
94 .add("mac-address", macAddress)
95 .toString();
96 }
Jonathan Hartac60c082014-09-23 08:55:17 -070097}