Jonathan Hart | ac60c08 | 2014-09-23 08:55:17 -0700 | [diff] [blame] | 1 | package org.onlab.onos.net.host; |
| 2 | |
Jonathan Hart | c884f1b | 2014-09-24 11:53:33 -0700 | [diff] [blame] | 3 | import java.util.Collections; |
Jonathan Hart | 09585c6 | 2014-09-23 16:58:04 -0700 | [diff] [blame] | 4 | import java.util.HashSet; |
Jonathan Hart | c884f1b | 2014-09-24 11:53:33 -0700 | [diff] [blame] | 5 | import java.util.Objects; |
Jonathan Hart | 09585c6 | 2014-09-23 16:58:04 -0700 | [diff] [blame] | 6 | import java.util.Set; |
| 7 | |
Jonathan Hart | ac60c08 | 2014-09-23 08:55:17 -0700 | [diff] [blame] | 8 | import org.onlab.onos.net.ConnectPoint; |
Jonathan Hart | 09585c6 | 2014-09-23 16:58:04 -0700 | [diff] [blame] | 9 | import org.onlab.packet.IpPrefix; |
Jonathan Hart | ac60c08 | 2014-09-23 08:55:17 -0700 | [diff] [blame] | 10 | import org.onlab.packet.MacAddress; |
| 11 | |
Jonathan Hart | 74f9c3b | 2014-09-29 20:03:50 -0700 | [diff] [blame^] | 12 | import com.google.common.base.MoreObjects; |
| 13 | |
Jonathan Hart | ac60c08 | 2014-09-23 08:55:17 -0700 | [diff] [blame] | 14 | /** |
| 15 | * Represents address information bound to a port. |
| 16 | */ |
Jonathan Hart | 09585c6 | 2014-09-23 16:58:04 -0700 | [diff] [blame] | 17 | public 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 Hart | c884f1b | 2014-09-24 11:53:33 -0700 | [diff] [blame] | 36 | this.ipAddresses = (ips == null) ? Collections.<IpPrefix>emptySet() : new HashSet<>(ips); |
Jonathan Hart | 09585c6 | 2014-09-23 16:58:04 -0700 | [diff] [blame] | 37 | this.macAddress = mac; |
| 38 | } |
Jonathan Hart | ac60c08 | 2014-09-23 08:55:17 -0700 | [diff] [blame] | 39 | |
| 40 | /** |
| 41 | * Returns the connection point this address information is bound to. |
| 42 | * |
| 43 | * @return the connection point |
| 44 | */ |
Jonathan Hart | 09585c6 | 2014-09-23 16:58:04 -0700 | [diff] [blame] | 45 | public ConnectPoint connectPoint() { |
| 46 | return connectPoint; |
| 47 | } |
Jonathan Hart | ac60c08 | 2014-09-23 08:55:17 -0700 | [diff] [blame] | 48 | |
| 49 | /** |
Jonathan Hart | 09585c6 | 2014-09-23 16:58:04 -0700 | [diff] [blame] | 50 | * Returns the set of IP addresses. |
Jonathan Hart | ac60c08 | 2014-09-23 08:55:17 -0700 | [diff] [blame] | 51 | * |
Jonathan Hart | 09585c6 | 2014-09-23 16:58:04 -0700 | [diff] [blame] | 52 | * @return the IP addresses |
Jonathan Hart | ac60c08 | 2014-09-23 08:55:17 -0700 | [diff] [blame] | 53 | */ |
Jonathan Hart | 09585c6 | 2014-09-23 16:58:04 -0700 | [diff] [blame] | 54 | public Set<IpPrefix> ips() { |
| 55 | return ipAddresses; |
| 56 | } |
Jonathan Hart | ac60c08 | 2014-09-23 08:55:17 -0700 | [diff] [blame] | 57 | |
| 58 | /** |
Jonathan Hart | 09585c6 | 2014-09-23 16:58:04 -0700 | [diff] [blame] | 59 | * Returns the MAC address. |
Jonathan Hart | ac60c08 | 2014-09-23 08:55:17 -0700 | [diff] [blame] | 60 | * |
Jonathan Hart | 09585c6 | 2014-09-23 16:58:04 -0700 | [diff] [blame] | 61 | * @return the MAC address |
Jonathan Hart | ac60c08 | 2014-09-23 08:55:17 -0700 | [diff] [blame] | 62 | */ |
Jonathan Hart | 09585c6 | 2014-09-23 16:58:04 -0700 | [diff] [blame] | 63 | public MacAddress mac() { |
| 64 | return macAddress; |
| 65 | } |
| 66 | |
Jonathan Hart | c884f1b | 2014-09-24 11:53:33 -0700 | [diff] [blame] | 67 | @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 Hart | 74f9c3b | 2014-09-29 20:03:50 -0700 | [diff] [blame^] | 88 | |
| 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 Hart | ac60c08 | 2014-09-23 08:55:17 -0700 | [diff] [blame] | 97 | } |