blob: deaea5e28653bfd880ad951d76fd596d0688f2fd [file] [log] [blame]
Thomas Vachuska4f1a60c2014-10-28 13:39:07 -07001/*
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 Hartac60c082014-09-23 08:55:17 -070016package org.onlab.onos.net.host;
17
Jonathan Hartc884f1b2014-09-24 11:53:33 -070018import java.util.Collections;
Jonathan Hart09585c62014-09-23 16:58:04 -070019import java.util.HashSet;
Jonathan Hartc884f1b2014-09-24 11:53:33 -070020import java.util.Objects;
Jonathan Hart09585c62014-09-23 16:58:04 -070021import java.util.Set;
22
Jonathan Hartac60c082014-09-23 08:55:17 -070023import org.onlab.onos.net.ConnectPoint;
Jonathan Hartac60c082014-09-23 08:55:17 -070024import org.onlab.packet.MacAddress;
25
Jonathan Hart74f9c3b2014-09-29 20:03:50 -070026import com.google.common.base.MoreObjects;
27
Jonathan Hartac60c082014-09-23 08:55:17 -070028/**
29 * Represents address information bound to a port.
30 */
Jonathan Hart09585c62014-09-23 16:58:04 -070031public class PortAddresses {
32
33 private final ConnectPoint connectPoint;
Pavlin Radoslavov76b0ae22014-10-27 15:33:19 -070034 private final Set<InterfaceIpAddress> ipAddresses;
Jonathan Hart09585c62014-09-23 16:58:04 -070035 private final MacAddress macAddress;
36
37 /**
Pavlin Radoslavov76b0ae22014-10-27 15:33:19 -070038 * Constructs a PortAddresses object for the given connection point, with a
Jonathan Hart09585c62014-09-23 16:58:04 -070039 * 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 Radoslavov76b0ae22014-10-27 15:33:19 -070044 * @param ipAddresses a set of interface IP addresses
Jonathan Hart09585c62014-09-23 16:58:04 -070045 * @param mac a MAC address
46 */
47 public PortAddresses(ConnectPoint connectPoint,
Pavlin Radoslavov76b0ae22014-10-27 15:33:19 -070048 Set<InterfaceIpAddress> ipAddresses, MacAddress mac) {
Jonathan Hart09585c62014-09-23 16:58:04 -070049 this.connectPoint = connectPoint;
Pavlin Radoslavov76b0ae22014-10-27 15:33:19 -070050 this.ipAddresses = (ipAddresses == null) ?
51 Collections.<InterfaceIpAddress>emptySet()
52 : new HashSet<>(ipAddresses);
Jonathan Hart09585c62014-09-23 16:58:04 -070053 this.macAddress = mac;
54 }
Jonathan Hartac60c082014-09-23 08:55:17 -070055
56 /**
57 * Returns the connection point this address information is bound to.
58 *
59 * @return the connection point
60 */
Jonathan Hart09585c62014-09-23 16:58:04 -070061 public ConnectPoint connectPoint() {
62 return connectPoint;
63 }
Jonathan Hartac60c082014-09-23 08:55:17 -070064
65 /**
Pavlin Radoslavov76b0ae22014-10-27 15:33:19 -070066 * Returns the set of interface IP addresses.
Jonathan Hartac60c082014-09-23 08:55:17 -070067 *
Pavlin Radoslavov76b0ae22014-10-27 15:33:19 -070068 * @return the interface IP addresses
Jonathan Hartac60c082014-09-23 08:55:17 -070069 */
Pavlin Radoslavov76b0ae22014-10-27 15:33:19 -070070 public Set<InterfaceIpAddress> ipAddresses() {
Jonathan Hart09585c62014-09-23 16:58:04 -070071 return ipAddresses;
72 }
Jonathan Hartac60c082014-09-23 08:55:17 -070073
74 /**
Jonathan Hart09585c62014-09-23 16:58:04 -070075 * Returns the MAC address.
Jonathan Hartac60c082014-09-23 08:55:17 -070076 *
Jonathan Hart09585c62014-09-23 16:58:04 -070077 * @return the MAC address
Jonathan Hartac60c082014-09-23 08:55:17 -070078 */
Jonathan Hart09585c62014-09-23 16:58:04 -070079 public MacAddress mac() {
80 return macAddress;
81 }
82
Jonathan Hartc884f1b2014-09-24 11:53:33 -070083 @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 Hart74f9c3b2014-09-29 20:03:50 -0700104
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 Hartac60c082014-09-23 08:55:17 -0700113}