Thomas Vachuska | 4f1a60c | 2014-10-28 13:39:07 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2014 Open Networking Laboratory |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
Jonathan Hart | ac60c08 | 2014-09-23 08:55:17 -0700 | [diff] [blame] | 16 | package org.onlab.onos.net.host; |
| 17 | |
Jonathan Hart | c884f1b | 2014-09-24 11:53:33 -0700 | [diff] [blame] | 18 | import java.util.Collections; |
Jonathan Hart | 09585c6 | 2014-09-23 16:58:04 -0700 | [diff] [blame] | 19 | import java.util.HashSet; |
Jonathan Hart | c884f1b | 2014-09-24 11:53:33 -0700 | [diff] [blame] | 20 | import java.util.Objects; |
Jonathan Hart | 09585c6 | 2014-09-23 16:58:04 -0700 | [diff] [blame] | 21 | import java.util.Set; |
| 22 | |
Jonathan Hart | ac60c08 | 2014-09-23 08:55:17 -0700 | [diff] [blame] | 23 | import org.onlab.onos.net.ConnectPoint; |
Jonathan Hart | ac60c08 | 2014-09-23 08:55:17 -0700 | [diff] [blame] | 24 | import org.onlab.packet.MacAddress; |
| 25 | |
Jonathan Hart | 74f9c3b | 2014-09-29 20:03:50 -0700 | [diff] [blame] | 26 | import com.google.common.base.MoreObjects; |
| 27 | |
Jonathan Hart | ac60c08 | 2014-09-23 08:55:17 -0700 | [diff] [blame] | 28 | /** |
| 29 | * Represents address information bound to a port. |
| 30 | */ |
Jonathan Hart | 09585c6 | 2014-09-23 16:58:04 -0700 | [diff] [blame] | 31 | public class PortAddresses { |
| 32 | |
| 33 | private final ConnectPoint connectPoint; |
Pavlin Radoslavov | 76b0ae2 | 2014-10-27 15:33:19 -0700 | [diff] [blame] | 34 | private final Set<InterfaceIpAddress> ipAddresses; |
Jonathan Hart | 09585c6 | 2014-09-23 16:58:04 -0700 | [diff] [blame] | 35 | private final MacAddress macAddress; |
| 36 | |
| 37 | /** |
Pavlin Radoslavov | 76b0ae2 | 2014-10-27 15:33:19 -0700 | [diff] [blame] | 38 | * Constructs a PortAddresses object for the given connection point, with a |
Thomas Vachuska | 4b42077 | 2014-10-30 16:46:17 -0700 | [diff] [blame] | 39 | * set of IP addresses and a MAC address. Both address parameters are |
| 40 | * optional and can be set to null. |
Jonathan Hart | 09585c6 | 2014-09-23 16:58:04 -0700 | [diff] [blame] | 41 | * |
| 42 | * @param connectPoint the connection point these addresses are for |
Pavlin Radoslavov | 76b0ae2 | 2014-10-27 15:33:19 -0700 | [diff] [blame] | 43 | * @param ipAddresses a set of interface IP addresses |
Jonathan Hart | 09585c6 | 2014-09-23 16:58:04 -0700 | [diff] [blame] | 44 | * @param mac a MAC address |
| 45 | */ |
| 46 | public PortAddresses(ConnectPoint connectPoint, |
Pavlin Radoslavov | 76b0ae2 | 2014-10-27 15:33:19 -0700 | [diff] [blame] | 47 | Set<InterfaceIpAddress> ipAddresses, MacAddress mac) { |
Jonathan Hart | 09585c6 | 2014-09-23 16:58:04 -0700 | [diff] [blame] | 48 | this.connectPoint = connectPoint; |
Pavlin Radoslavov | 76b0ae2 | 2014-10-27 15:33:19 -0700 | [diff] [blame] | 49 | this.ipAddresses = (ipAddresses == null) ? |
| 50 | Collections.<InterfaceIpAddress>emptySet() |
| 51 | : new HashSet<>(ipAddresses); |
Jonathan Hart | 09585c6 | 2014-09-23 16:58:04 -0700 | [diff] [blame] | 52 | this.macAddress = mac; |
| 53 | } |
Jonathan Hart | ac60c08 | 2014-09-23 08:55:17 -0700 | [diff] [blame] | 54 | |
| 55 | /** |
| 56 | * Returns the connection point this address information is bound to. |
| 57 | * |
| 58 | * @return the connection point |
| 59 | */ |
Jonathan Hart | 09585c6 | 2014-09-23 16:58:04 -0700 | [diff] [blame] | 60 | public ConnectPoint connectPoint() { |
| 61 | return connectPoint; |
| 62 | } |
Jonathan Hart | ac60c08 | 2014-09-23 08:55:17 -0700 | [diff] [blame] | 63 | |
| 64 | /** |
Pavlin Radoslavov | 76b0ae2 | 2014-10-27 15:33:19 -0700 | [diff] [blame] | 65 | * Returns the set of interface IP addresses. |
Jonathan Hart | ac60c08 | 2014-09-23 08:55:17 -0700 | [diff] [blame] | 66 | * |
Pavlin Radoslavov | 76b0ae2 | 2014-10-27 15:33:19 -0700 | [diff] [blame] | 67 | * @return the interface IP addresses |
Jonathan Hart | ac60c08 | 2014-09-23 08:55:17 -0700 | [diff] [blame] | 68 | */ |
Pavlin Radoslavov | 76b0ae2 | 2014-10-27 15:33:19 -0700 | [diff] [blame] | 69 | public Set<InterfaceIpAddress> ipAddresses() { |
Jonathan Hart | 09585c6 | 2014-09-23 16:58:04 -0700 | [diff] [blame] | 70 | return ipAddresses; |
| 71 | } |
Jonathan Hart | ac60c08 | 2014-09-23 08:55:17 -0700 | [diff] [blame] | 72 | |
| 73 | /** |
Jonathan Hart | 09585c6 | 2014-09-23 16:58:04 -0700 | [diff] [blame] | 74 | * Returns the MAC address. |
Jonathan Hart | ac60c08 | 2014-09-23 08:55:17 -0700 | [diff] [blame] | 75 | * |
Jonathan Hart | 09585c6 | 2014-09-23 16:58:04 -0700 | [diff] [blame] | 76 | * @return the MAC address |
Jonathan Hart | ac60c08 | 2014-09-23 08:55:17 -0700 | [diff] [blame] | 77 | */ |
Jonathan Hart | 09585c6 | 2014-09-23 16:58:04 -0700 | [diff] [blame] | 78 | public MacAddress mac() { |
| 79 | return macAddress; |
| 80 | } |
| 81 | |
Jonathan Hart | c884f1b | 2014-09-24 11:53:33 -0700 | [diff] [blame] | 82 | @Override |
| 83 | public boolean equals(Object other) { |
| 84 | if (this == other) { |
| 85 | return true; |
| 86 | } |
| 87 | |
| 88 | if (!(other instanceof PortAddresses)) { |
| 89 | return false; |
| 90 | } |
| 91 | |
| 92 | PortAddresses otherPa = (PortAddresses) other; |
| 93 | |
| 94 | return Objects.equals(this.connectPoint, otherPa.connectPoint) |
| 95 | && Objects.equals(this.ipAddresses, otherPa.ipAddresses) |
| 96 | && Objects.equals(this.macAddress, otherPa.macAddress); |
| 97 | } |
| 98 | |
| 99 | @Override |
| 100 | public int hashCode() { |
| 101 | return Objects.hash(connectPoint, ipAddresses, macAddress); |
| 102 | } |
Jonathan Hart | 74f9c3b | 2014-09-29 20:03:50 -0700 | [diff] [blame] | 103 | |
| 104 | @Override |
| 105 | public String toString() { |
| 106 | return MoreObjects.toStringHelper(getClass()) |
| 107 | .add("connect-point", connectPoint) |
| 108 | .add("ip-addresses", ipAddresses) |
| 109 | .add("mac-address", macAddress) |
| 110 | .toString(); |
| 111 | } |
Jonathan Hart | ac60c08 | 2014-09-23 08:55:17 -0700 | [diff] [blame] | 112 | } |