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 | |
| 12 | /** |
| 13 | * Represents address information bound to a port. |
| 14 | */ |
Jonathan Hart | 09585c6 | 2014-09-23 16:58:04 -0700 | [diff] [blame] | 15 | public 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 Hart | c884f1b | 2014-09-24 11:53:33 -0700 | [diff] [blame^] | 34 | this.ipAddresses = (ips == null) ? Collections.<IpPrefix>emptySet() : new HashSet<>(ips); |
Jonathan Hart | 09585c6 | 2014-09-23 16:58:04 -0700 | [diff] [blame] | 35 | this.macAddress = mac; |
| 36 | } |
Jonathan Hart | ac60c08 | 2014-09-23 08:55:17 -0700 | [diff] [blame] | 37 | |
| 38 | /** |
| 39 | * Returns the connection point this address information is bound to. |
| 40 | * |
| 41 | * @return the connection point |
| 42 | */ |
Jonathan Hart | 09585c6 | 2014-09-23 16:58:04 -0700 | [diff] [blame] | 43 | public ConnectPoint connectPoint() { |
| 44 | return connectPoint; |
| 45 | } |
Jonathan Hart | ac60c08 | 2014-09-23 08:55:17 -0700 | [diff] [blame] | 46 | |
| 47 | /** |
Jonathan Hart | 09585c6 | 2014-09-23 16:58:04 -0700 | [diff] [blame] | 48 | * Returns the set of IP addresses. |
Jonathan Hart | ac60c08 | 2014-09-23 08:55:17 -0700 | [diff] [blame] | 49 | * |
Jonathan Hart | 09585c6 | 2014-09-23 16:58:04 -0700 | [diff] [blame] | 50 | * @return the 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 | public Set<IpPrefix> ips() { |
| 53 | return ipAddresses; |
| 54 | } |
Jonathan Hart | ac60c08 | 2014-09-23 08:55:17 -0700 | [diff] [blame] | 55 | |
| 56 | /** |
Jonathan Hart | 09585c6 | 2014-09-23 16:58:04 -0700 | [diff] [blame] | 57 | * Returns the MAC address. |
Jonathan Hart | ac60c08 | 2014-09-23 08:55:17 -0700 | [diff] [blame] | 58 | * |
Jonathan Hart | 09585c6 | 2014-09-23 16:58:04 -0700 | [diff] [blame] | 59 | * @return 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 | public MacAddress mac() { |
| 62 | return macAddress; |
| 63 | } |
| 64 | |
Jonathan Hart | c884f1b | 2014-09-24 11:53:33 -0700 | [diff] [blame^] | 65 | @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 Hart | ac60c08 | 2014-09-23 08:55:17 -0700 | [diff] [blame] | 86 | } |