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 |
Jonathan Hart | 09585c6 | 2014-09-23 16:58:04 -0700 | [diff] [blame] | 39 | * set of IP addresses and a MAC address. |
| 40 | * <p/> |
| 41 | * Both address parameters are optional and can be set to null. |
| 42 | * |
| 43 | * @param connectPoint the connection point these addresses are for |
Pavlin Radoslavov | 76b0ae2 | 2014-10-27 15:33:19 -0700 | [diff] [blame] | 44 | * @param ipAddresses a set of interface IP addresses |
Jonathan Hart | 09585c6 | 2014-09-23 16:58:04 -0700 | [diff] [blame] | 45 | * @param mac a MAC address |
| 46 | */ |
| 47 | public PortAddresses(ConnectPoint connectPoint, |
Pavlin Radoslavov | 76b0ae2 | 2014-10-27 15:33:19 -0700 | [diff] [blame] | 48 | Set<InterfaceIpAddress> ipAddresses, MacAddress mac) { |
Jonathan Hart | 09585c6 | 2014-09-23 16:58:04 -0700 | [diff] [blame] | 49 | this.connectPoint = connectPoint; |
Pavlin Radoslavov | 76b0ae2 | 2014-10-27 15:33:19 -0700 | [diff] [blame] | 50 | this.ipAddresses = (ipAddresses == null) ? |
| 51 | Collections.<InterfaceIpAddress>emptySet() |
| 52 | : new HashSet<>(ipAddresses); |
Jonathan Hart | 09585c6 | 2014-09-23 16:58:04 -0700 | [diff] [blame] | 53 | this.macAddress = mac; |
| 54 | } |
Jonathan Hart | ac60c08 | 2014-09-23 08:55:17 -0700 | [diff] [blame] | 55 | |
| 56 | /** |
| 57 | * Returns the connection point this address information is bound to. |
| 58 | * |
| 59 | * @return the connection point |
| 60 | */ |
Jonathan Hart | 09585c6 | 2014-09-23 16:58:04 -0700 | [diff] [blame] | 61 | public ConnectPoint connectPoint() { |
| 62 | return connectPoint; |
| 63 | } |
Jonathan Hart | ac60c08 | 2014-09-23 08:55:17 -0700 | [diff] [blame] | 64 | |
| 65 | /** |
Pavlin Radoslavov | 76b0ae2 | 2014-10-27 15:33:19 -0700 | [diff] [blame] | 66 | * Returns the set of interface IP addresses. |
Jonathan Hart | ac60c08 | 2014-09-23 08:55:17 -0700 | [diff] [blame] | 67 | * |
Pavlin Radoslavov | 76b0ae2 | 2014-10-27 15:33:19 -0700 | [diff] [blame] | 68 | * @return the interface IP addresses |
Jonathan Hart | ac60c08 | 2014-09-23 08:55:17 -0700 | [diff] [blame] | 69 | */ |
Pavlin Radoslavov | 76b0ae2 | 2014-10-27 15:33:19 -0700 | [diff] [blame] | 70 | public Set<InterfaceIpAddress> ipAddresses() { |
Jonathan Hart | 09585c6 | 2014-09-23 16:58:04 -0700 | [diff] [blame] | 71 | return ipAddresses; |
| 72 | } |
Jonathan Hart | ac60c08 | 2014-09-23 08:55:17 -0700 | [diff] [blame] | 73 | |
| 74 | /** |
Jonathan Hart | 09585c6 | 2014-09-23 16:58:04 -0700 | [diff] [blame] | 75 | * Returns the MAC address. |
Jonathan Hart | ac60c08 | 2014-09-23 08:55:17 -0700 | [diff] [blame] | 76 | * |
Jonathan Hart | 09585c6 | 2014-09-23 16:58:04 -0700 | [diff] [blame] | 77 | * @return the MAC address |
Jonathan Hart | ac60c08 | 2014-09-23 08:55:17 -0700 | [diff] [blame] | 78 | */ |
Jonathan Hart | 09585c6 | 2014-09-23 16:58:04 -0700 | [diff] [blame] | 79 | public MacAddress mac() { |
| 80 | return macAddress; |
| 81 | } |
| 82 | |
Jonathan Hart | c884f1b | 2014-09-24 11:53:33 -0700 | [diff] [blame] | 83 | @Override |
| 84 | public boolean equals(Object other) { |
| 85 | if (this == other) { |
| 86 | return true; |
| 87 | } |
| 88 | |
| 89 | if (!(other instanceof PortAddresses)) { |
| 90 | return false; |
| 91 | } |
| 92 | |
| 93 | PortAddresses otherPa = (PortAddresses) other; |
| 94 | |
| 95 | return Objects.equals(this.connectPoint, otherPa.connectPoint) |
| 96 | && Objects.equals(this.ipAddresses, otherPa.ipAddresses) |
| 97 | && Objects.equals(this.macAddress, otherPa.macAddress); |
| 98 | } |
| 99 | |
| 100 | @Override |
| 101 | public int hashCode() { |
| 102 | return Objects.hash(connectPoint, ipAddresses, macAddress); |
| 103 | } |
Jonathan Hart | 74f9c3b | 2014-09-29 20:03:50 -0700 | [diff] [blame] | 104 | |
| 105 | @Override |
| 106 | public String toString() { |
| 107 | return MoreObjects.toStringHelper(getClass()) |
| 108 | .add("connect-point", connectPoint) |
| 109 | .add("ip-addresses", ipAddresses) |
| 110 | .add("mac-address", macAddress) |
| 111 | .toString(); |
| 112 | } |
Jonathan Hart | ac60c08 | 2014-09-23 08:55:17 -0700 | [diff] [blame] | 113 | } |