blob: 4804dafc999271fcd41f1265d767ee9cad9a598f [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;
Yuta HIGUCHIa2639152014-10-14 15:08:10 -070020 // TODO: Should this be IpAddress or IpPrefix?
Jonathan Hart09585c62014-09-23 16:58:04 -070021 private final Set<IpPrefix> ipAddresses;
22 private final MacAddress macAddress;
23
24 /**
25 * Constructs a PortAddress object for the given connection point, with a
26 * set of IP addresses and a MAC address.
27 * <p/>
28 * Both address parameters are optional and can be set to null.
29 *
30 * @param connectPoint the connection point these addresses are for
31 * @param ips a set of IP addresses
32 * @param mac a MAC address
33 */
34 public PortAddresses(ConnectPoint connectPoint,
35 Set<IpPrefix> ips, MacAddress mac) {
36 this.connectPoint = connectPoint;
Jonathan Hartc884f1b2014-09-24 11:53:33 -070037 this.ipAddresses = (ips == null) ? Collections.<IpPrefix>emptySet() : new HashSet<>(ips);
Jonathan Hart09585c62014-09-23 16:58:04 -070038 this.macAddress = mac;
39 }
Jonathan Hartac60c082014-09-23 08:55:17 -070040
41 /**
42 * Returns the connection point this address information is bound to.
43 *
44 * @return the connection point
45 */
Jonathan Hart09585c62014-09-23 16:58:04 -070046 public ConnectPoint connectPoint() {
47 return connectPoint;
48 }
Jonathan Hartac60c082014-09-23 08:55:17 -070049
50 /**
Jonathan Hart09585c62014-09-23 16:58:04 -070051 * Returns the set of IP addresses.
Jonathan Hartac60c082014-09-23 08:55:17 -070052 *
Jonathan Hart09585c62014-09-23 16:58:04 -070053 * @return the IP addresses
Jonathan Hartac60c082014-09-23 08:55:17 -070054 */
Jonathan Hart09585c62014-09-23 16:58:04 -070055 public Set<IpPrefix> ips() {
56 return ipAddresses;
57 }
Jonathan Hartac60c082014-09-23 08:55:17 -070058
59 /**
Jonathan Hart09585c62014-09-23 16:58:04 -070060 * Returns the MAC address.
Jonathan Hartac60c082014-09-23 08:55:17 -070061 *
Jonathan Hart09585c62014-09-23 16:58:04 -070062 * @return the MAC address
Jonathan Hartac60c082014-09-23 08:55:17 -070063 */
Jonathan Hart09585c62014-09-23 16:58:04 -070064 public MacAddress mac() {
65 return macAddress;
66 }
67
Jonathan Hartc884f1b2014-09-24 11:53:33 -070068 @Override
69 public boolean equals(Object other) {
70 if (this == other) {
71 return true;
72 }
73
74 if (!(other instanceof PortAddresses)) {
75 return false;
76 }
77
78 PortAddresses otherPa = (PortAddresses) other;
79
80 return Objects.equals(this.connectPoint, otherPa.connectPoint)
81 && Objects.equals(this.ipAddresses, otherPa.ipAddresses)
82 && Objects.equals(this.macAddress, otherPa.macAddress);
83 }
84
85 @Override
86 public int hashCode() {
87 return Objects.hash(connectPoint, ipAddresses, macAddress);
88 }
Jonathan Hart74f9c3b2014-09-29 20:03:50 -070089
90 @Override
91 public String toString() {
92 return MoreObjects.toStringHelper(getClass())
93 .add("connect-point", connectPoint)
94 .add("ip-addresses", ipAddresses)
95 .add("mac-address", macAddress)
96 .toString();
97 }
Jonathan Hartac60c082014-09-23 08:55:17 -070098}