blob: a034ad1209ef3b82eb6f2918002399ca9fea0ab0 [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 */
Brian O'Connorabafb502014-12-02 22:26:20 -080016package org.onosproject.net.host;
Jonathan Hartac60c082014-09-23 08:55:17 -070017
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.packet.MacAddress;
Jonathan Hart6cd2f352015-01-13 17:44:45 -080024import org.onlab.packet.VlanId;
25import org.onosproject.net.ConnectPoint;
Jonathan Hartac60c082014-09-23 08:55:17 -070026
Jonathan Hart74f9c3b2014-09-29 20:03:50 -070027import com.google.common.base.MoreObjects;
28
Jonathan Hartac60c082014-09-23 08:55:17 -070029/**
30 * Represents address information bound to a port.
31 */
Jonathan Hart09585c62014-09-23 16:58:04 -070032public class PortAddresses {
33
34 private final ConnectPoint connectPoint;
Pavlin Radoslavov76b0ae22014-10-27 15:33:19 -070035 private final Set<InterfaceIpAddress> ipAddresses;
Jonathan Hart09585c62014-09-23 16:58:04 -070036 private final MacAddress macAddress;
Jonathan Hart6cd2f352015-01-13 17:44:45 -080037 private final VlanId vlan;
Jonathan Hart09585c62014-09-23 16:58:04 -070038
39 /**
Pavlin Radoslavov76b0ae22014-10-27 15:33:19 -070040 * Constructs a PortAddresses object for the given connection point, with a
Thomas Vachuska4b420772014-10-30 16:46:17 -070041 * set of IP addresses and a MAC address. Both address parameters are
42 * optional and can be set to null.
Jonathan Hart09585c62014-09-23 16:58:04 -070043 *
44 * @param connectPoint the connection point these addresses are for
Pavlin Radoslavov76b0ae22014-10-27 15:33:19 -070045 * @param ipAddresses a set of interface IP addresses
Jonathan Hart09585c62014-09-23 16:58:04 -070046 * @param mac a MAC address
Jonathan Hart6cd2f352015-01-13 17:44:45 -080047 * @param vlan a VLAN ID
Jonathan Hart09585c62014-09-23 16:58:04 -070048 */
49 public PortAddresses(ConnectPoint connectPoint,
Jonathan Hart6cd2f352015-01-13 17:44:45 -080050 Set<InterfaceIpAddress> ipAddresses, MacAddress mac, VlanId vlan) {
Jonathan Hart09585c62014-09-23 16:58:04 -070051 this.connectPoint = connectPoint;
Pavlin Radoslavov76b0ae22014-10-27 15:33:19 -070052 this.ipAddresses = (ipAddresses == null) ?
53 Collections.<InterfaceIpAddress>emptySet()
54 : new HashSet<>(ipAddresses);
Jonathan Hart09585c62014-09-23 16:58:04 -070055 this.macAddress = mac;
Jonathan Hart6cd2f352015-01-13 17:44:45 -080056 this.vlan = vlan;
Jonathan Hart09585c62014-09-23 16:58:04 -070057 }
Jonathan Hartac60c082014-09-23 08:55:17 -070058
59 /**
60 * Returns the connection point this address information is bound to.
61 *
62 * @return the connection point
63 */
Jonathan Hart09585c62014-09-23 16:58:04 -070064 public ConnectPoint connectPoint() {
65 return connectPoint;
66 }
Jonathan Hartac60c082014-09-23 08:55:17 -070067
68 /**
Pavlin Radoslavov76b0ae22014-10-27 15:33:19 -070069 * Returns the set of interface IP addresses.
Jonathan Hartac60c082014-09-23 08:55:17 -070070 *
Pavlin Radoslavov76b0ae22014-10-27 15:33:19 -070071 * @return the interface IP addresses
Jonathan Hartac60c082014-09-23 08:55:17 -070072 */
Pavlin Radoslavov76b0ae22014-10-27 15:33:19 -070073 public Set<InterfaceIpAddress> ipAddresses() {
Jonathan Hart09585c62014-09-23 16:58:04 -070074 return ipAddresses;
75 }
Jonathan Hartac60c082014-09-23 08:55:17 -070076
77 /**
Jonathan Hart09585c62014-09-23 16:58:04 -070078 * Returns the MAC address.
Jonathan Hartac60c082014-09-23 08:55:17 -070079 *
Jonathan Hart09585c62014-09-23 16:58:04 -070080 * @return the MAC address
Jonathan Hartac60c082014-09-23 08:55:17 -070081 */
Jonathan Hart09585c62014-09-23 16:58:04 -070082 public MacAddress mac() {
83 return macAddress;
84 }
85
Jonathan Hart6cd2f352015-01-13 17:44:45 -080086 /**
87 * Returns the VLAN ID.
88 *
89 * @return the VLAN ID
90 */
91 public VlanId vlan() {
92 return vlan;
93 }
94
Jonathan Hartc884f1b2014-09-24 11:53:33 -070095 @Override
96 public boolean equals(Object other) {
97 if (this == other) {
98 return true;
99 }
100
101 if (!(other instanceof PortAddresses)) {
102 return false;
103 }
104
105 PortAddresses otherPa = (PortAddresses) other;
106
107 return Objects.equals(this.connectPoint, otherPa.connectPoint)
108 && Objects.equals(this.ipAddresses, otherPa.ipAddresses)
Jonathan Hart6cd2f352015-01-13 17:44:45 -0800109 && Objects.equals(this.macAddress, otherPa.macAddress)
110 && Objects.equals(this.vlan, otherPa.vlan);
Jonathan Hartc884f1b2014-09-24 11:53:33 -0700111 }
112
113 @Override
114 public int hashCode() {
Jonathan Hart6cd2f352015-01-13 17:44:45 -0800115 return Objects.hash(connectPoint, ipAddresses, macAddress, vlan);
Jonathan Hartc884f1b2014-09-24 11:53:33 -0700116 }
Jonathan Hart74f9c3b2014-09-29 20:03:50 -0700117
118 @Override
119 public String toString() {
120 return MoreObjects.toStringHelper(getClass())
121 .add("connect-point", connectPoint)
122 .add("ip-addresses", ipAddresses)
123 .add("mac-address", macAddress)
Jonathan Hart6cd2f352015-01-13 17:44:45 -0800124 .add("vlan", vlan)
Jonathan Hart74f9c3b2014-09-29 20:03:50 -0700125 .toString();
126 }
Jonathan Hartac60c082014-09-23 08:55:17 -0700127}