blob: 7d22877b185c508e1d32193850f0d41eac49de3e [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
12/**
13 * Represents address information bound to a port.
14 */
Jonathan Hart09585c62014-09-23 16:58:04 -070015public class PortAddresses {
16
17 private final ConnectPoint connectPoint;
18 private final Set<IpPrefix> ipAddresses;
19 private final MacAddress macAddress;
20
21 /**
22 * Constructs a PortAddress object for the given connection point, with a
23 * set of IP addresses and a MAC address.
24 * <p/>
25 * Both address parameters are optional and can be set to null.
26 *
27 * @param connectPoint the connection point these addresses are for
28 * @param ips a set of IP addresses
29 * @param mac a MAC address
30 */
31 public PortAddresses(ConnectPoint connectPoint,
32 Set<IpPrefix> ips, MacAddress mac) {
33 this.connectPoint = connectPoint;
Jonathan Hartc884f1b2014-09-24 11:53:33 -070034 this.ipAddresses = (ips == null) ? Collections.<IpPrefix>emptySet() : new HashSet<>(ips);
Jonathan Hart09585c62014-09-23 16:58:04 -070035 this.macAddress = mac;
36 }
Jonathan Hartac60c082014-09-23 08:55:17 -070037
38 /**
39 * Returns the connection point this address information is bound to.
40 *
41 * @return the connection point
42 */
Jonathan Hart09585c62014-09-23 16:58:04 -070043 public ConnectPoint connectPoint() {
44 return connectPoint;
45 }
Jonathan Hartac60c082014-09-23 08:55:17 -070046
47 /**
Jonathan Hart09585c62014-09-23 16:58:04 -070048 * Returns the set of IP addresses.
Jonathan Hartac60c082014-09-23 08:55:17 -070049 *
Jonathan Hart09585c62014-09-23 16:58:04 -070050 * @return the IP addresses
Jonathan Hartac60c082014-09-23 08:55:17 -070051 */
Jonathan Hart09585c62014-09-23 16:58:04 -070052 public Set<IpPrefix> ips() {
53 return ipAddresses;
54 }
Jonathan Hartac60c082014-09-23 08:55:17 -070055
56 /**
Jonathan Hart09585c62014-09-23 16:58:04 -070057 * Returns the MAC address.
Jonathan Hartac60c082014-09-23 08:55:17 -070058 *
Jonathan Hart09585c62014-09-23 16:58:04 -070059 * @return the MAC address
Jonathan Hartac60c082014-09-23 08:55:17 -070060 */
Jonathan Hart09585c62014-09-23 16:58:04 -070061 public MacAddress mac() {
62 return macAddress;
63 }
64
Jonathan Hartc884f1b2014-09-24 11:53:33 -070065 @Override
66 public boolean equals(Object other) {
67 if (this == other) {
68 return true;
69 }
70
71 if (!(other instanceof PortAddresses)) {
72 return false;
73 }
74
75 PortAddresses otherPa = (PortAddresses) other;
76
77 return Objects.equals(this.connectPoint, otherPa.connectPoint)
78 && Objects.equals(this.ipAddresses, otherPa.ipAddresses)
79 && Objects.equals(this.macAddress, otherPa.macAddress);
80 }
81
82 @Override
83 public int hashCode() {
84 return Objects.hash(connectPoint, ipAddresses, macAddress);
85 }
Jonathan Hartac60c082014-09-23 08:55:17 -070086}