blob: 5f9cfd819393e3fa7d2d880adc09a87db099c41f [file] [log] [blame]
Thomas Vachuska4f1a60c2014-10-28 13:39:07 -07001/*
Brian O'Connor5ab426f2016-04-09 01:19:45 -07002 * Copyright 2014-present Open Networking Laboratory
Thomas Vachuska4f1a60c2014-10-28 13:39:07 -07003 *
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;
Ayaka Koshibe74a23922014-09-09 16:45:39 -070017
Yuta HIGUCHI5fa3dc02014-10-15 17:08:13 -070018import java.util.Collections;
19import java.util.Set;
20
Brian O'Connorabafb502014-12-02 22:26:20 -080021import org.onosproject.net.AbstractDescription;
22import org.onosproject.net.HostLocation;
23import org.onosproject.net.SparseAnnotations;
Pavlin Radoslavov33f228a2014-10-27 19:33:16 -070024import org.onlab.packet.IpAddress;
Ayaka Koshibea9c199f2014-09-16 16:21:40 -070025import org.onlab.packet.MacAddress;
26import org.onlab.packet.VlanId;
Ayaka Koshibe74a23922014-09-09 16:45:39 -070027
Yuta HIGUCHI5fa3dc02014-10-15 17:08:13 -070028import com.google.common.collect.ImmutableSet;
29
tom27ae0e62014-10-01 20:35:01 -070030import static com.google.common.base.MoreObjects.toStringHelper;
HIGUCHI Yuta703a5af2015-11-18 23:43:50 -080031import com.google.common.base.Objects;
tom27ae0e62014-10-01 20:35:01 -070032
33/**
34 * Default implementation of an immutable host description.
35 */
tomf5d85d42014-10-02 05:27:56 -070036public class DefaultHostDescription extends AbstractDescription
tom27ae0e62014-10-01 20:35:01 -070037 implements HostDescription {
Ayaka Koshibe74a23922014-09-09 16:45:39 -070038
Ayaka Koshibea9c199f2014-09-16 16:21:40 -070039 private final MacAddress mac;
40 private final VlanId vlan;
Ayaka Koshibe74a23922014-09-09 16:45:39 -070041 private final HostLocation location;
Pavlin Radoslavov33f228a2014-10-27 19:33:16 -070042 private final Set<IpAddress> ip;
sdn5e935452016-08-30 04:12:54 -070043 private final boolean configured;
Ayaka Koshibe74a23922014-09-09 16:45:39 -070044
tom27ae0e62014-10-01 20:35:01 -070045 /**
46 * Creates a host description using the supplied information.
47 *
48 * @param mac host MAC address
49 * @param vlan host VLAN identifier
50 * @param location host location
51 * @param annotations optional key/value annotations map
52 */
Ayaka Koshibea9c199f2014-09-16 16:21:40 -070053 public DefaultHostDescription(MacAddress mac, VlanId vlan,
tom27ae0e62014-10-01 20:35:01 -070054 HostLocation location,
tomf5d85d42014-10-02 05:27:56 -070055 SparseAnnotations... annotations) {
Sho SHIMIZU21d00692016-08-15 11:15:28 -070056 this(mac, vlan, location, Collections.emptySet(),
Pavlin Radoslavov33f228a2014-10-27 19:33:16 -070057 annotations);
Ayaka Koshibe1a100982014-09-13 19:32:19 -070058 }
59
tom27ae0e62014-10-01 20:35:01 -070060 /**
61 * Creates a host description using the supplied information.
62 *
63 * @param mac host MAC address
64 * @param vlan host VLAN identifier
65 * @param location host location
tom093340b2014-10-10 00:15:36 -070066 * @param ip host IP address
tom27ae0e62014-10-01 20:35:01 -070067 * @param annotations optional key/value annotations map
68 */
Ayaka Koshibea9c199f2014-09-16 16:21:40 -070069 public DefaultHostDescription(MacAddress mac, VlanId vlan,
Pavlin Radoslavov33f228a2014-10-27 19:33:16 -070070 HostLocation location, IpAddress ip,
tomf5d85d42014-10-02 05:27:56 -070071 SparseAnnotations... annotations) {
Yuta HIGUCHI5fa3dc02014-10-15 17:08:13 -070072 this(mac, vlan, location, ImmutableSet.of(ip), annotations);
73 }
74
75 /**
76 * Creates a host description using the supplied information.
77 *
78 * @param mac host MAC address
79 * @param vlan host VLAN identifier
80 * @param location host location
81 * @param ip host IP addresses
82 * @param annotations optional key/value annotations map
83 */
84 public DefaultHostDescription(MacAddress mac, VlanId vlan,
Pavlin Radoslavov33f228a2014-10-27 19:33:16 -070085 HostLocation location, Set<IpAddress> ip,
Yuta HIGUCHI5fa3dc02014-10-15 17:08:13 -070086 SparseAnnotations... annotations) {
sdn5e935452016-08-30 04:12:54 -070087 this(mac, vlan, location, ip, false, annotations);
88 }
89
90 /**
91 * Creates a host description using the supplied information.
92 *
93 * @param mac host MAC address
94 * @param vlan host VLAN identifier
95 * @param location host location
96 * @param configured true if configured via NetworkConfiguration
97 * @param annotations optional key/value annotations map
98 */
99 public DefaultHostDescription(MacAddress mac, VlanId vlan,
100 HostLocation location,
101 boolean configured,
102 SparseAnnotations... annotations) {
103 this(mac, vlan, location, Collections.<IpAddress>emptySet(),
104 configured, annotations);
105 }
106
107 /**
108 * Creates a host description using the supplied information.
109 *
110 * @param mac host MAC address
111 * @param vlan host VLAN identifier
112 * @param location host location
113 * @param ip host IP address
114 * @param configured true if configured via NetworkConfiguration
115 * @param annotations optional key/value annotations map
116 */
117 public DefaultHostDescription(MacAddress mac, VlanId vlan,
118 HostLocation location, Set<IpAddress> ip,
119 boolean configured,
120 SparseAnnotations... annotations) {
tom27ae0e62014-10-01 20:35:01 -0700121 super(annotations);
Ayaka Koshibe74a23922014-09-09 16:45:39 -0700122 this.mac = mac;
123 this.vlan = vlan;
tom27ae0e62014-10-01 20:35:01 -0700124 this.location = location;
Yuta HIGUCHI5fa3dc02014-10-15 17:08:13 -0700125 this.ip = ImmutableSet.copyOf(ip);
sdn5e935452016-08-30 04:12:54 -0700126 this.configured = configured;
Ayaka Koshibe74a23922014-09-09 16:45:39 -0700127 }
128
129 @Override
Ayaka Koshibea9c199f2014-09-16 16:21:40 -0700130 public MacAddress hwAddress() {
Ayaka Koshibe74a23922014-09-09 16:45:39 -0700131 return mac;
132 }
133
134 @Override
Ayaka Koshibea9c199f2014-09-16 16:21:40 -0700135 public VlanId vlan() {
Ayaka Koshibe74a23922014-09-09 16:45:39 -0700136 return vlan;
137 }
138
139 @Override
140 public HostLocation location() {
141 return location;
142 }
143
144 @Override
Pavlin Radoslavov33f228a2014-10-27 19:33:16 -0700145 public Set<IpAddress> ipAddress() {
tom093340b2014-10-10 00:15:36 -0700146 return ip;
Ayaka Koshibe74a23922014-09-09 16:45:39 -0700147 }
148
149 @Override
sdn5e935452016-08-30 04:12:54 -0700150 public boolean configured() {
151 return configured;
152 }
153
154 @Override
Ayaka Koshibe74a23922014-09-09 16:45:39 -0700155 public String toString() {
156 return toStringHelper(this)
157 .add("mac", mac)
158 .add("vlan", vlan)
159 .add("location", location)
tom093340b2014-10-10 00:15:36 -0700160 .add("ipAddress", ip)
sdn5e935452016-08-30 04:12:54 -0700161 .add("configured", configured)
Ayaka Koshibe74a23922014-09-09 16:45:39 -0700162 .toString();
163 }
164
HIGUCHI Yuta703a5af2015-11-18 23:43:50 -0800165 @Override
166 public int hashCode() {
167 return Objects.hashCode(super.hashCode(), mac, vlan, location, ip);
168 }
169
170 @Override
171 public boolean equals(Object object) {
172 if (object != null && getClass() == object.getClass()) {
173 if (!super.equals(object)) {
174 return false;
175 }
176 DefaultHostDescription that = (DefaultHostDescription) object;
177 return Objects.equal(this.mac, that.mac)
178 && Objects.equal(this.vlan, that.vlan)
179 && Objects.equal(this.location, that.location)
180 && Objects.equal(this.ip, that.ip);
181 }
182 return false;
183 }
Ayaka Koshibe74a23922014-09-09 16:45:39 -0700184}