blob: 74fbbe9b83933a1b0bd34aabf740ccb8d3d3fd1b [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;
Deepa Vaddireddy50ad0802016-08-08 19:27:36 +053024import org.onosproject.store.service.WallClockTimestamp;
Pavlin Radoslavov33f228a2014-10-27 19:33:16 -070025import org.onlab.packet.IpAddress;
Ayaka Koshibea9c199f2014-09-16 16:21:40 -070026import org.onlab.packet.MacAddress;
27import org.onlab.packet.VlanId;
Ayaka Koshibe74a23922014-09-09 16:45:39 -070028
Yuta HIGUCHI5fa3dc02014-10-15 17:08:13 -070029import com.google.common.collect.ImmutableSet;
30
tom27ae0e62014-10-01 20:35:01 -070031import static com.google.common.base.MoreObjects.toStringHelper;
HIGUCHI Yuta703a5af2015-11-18 23:43:50 -080032import com.google.common.base.Objects;
tom27ae0e62014-10-01 20:35:01 -070033
34/**
35 * Default implementation of an immutable host description.
36 */
tomf5d85d42014-10-02 05:27:56 -070037public class DefaultHostDescription extends AbstractDescription
tom27ae0e62014-10-01 20:35:01 -070038 implements HostDescription {
Ayaka Koshibe74a23922014-09-09 16:45:39 -070039
Ayaka Koshibea9c199f2014-09-16 16:21:40 -070040 private final MacAddress mac;
41 private final VlanId vlan;
Ayaka Koshibe74a23922014-09-09 16:45:39 -070042 private final HostLocation location;
Pavlin Radoslavov33f228a2014-10-27 19:33:16 -070043 private final Set<IpAddress> ip;
Deepa Vaddireddy50ad0802016-08-08 19:27:36 +053044 private final WallClockTimestamp timestamp;
Ayaka Koshibe74a23922014-09-09 16:45:39 -070045
tom27ae0e62014-10-01 20:35:01 -070046 /**
47 * Creates a host description using the supplied information.
48 *
49 * @param mac host MAC address
50 * @param vlan host VLAN identifier
51 * @param location host location
52 * @param annotations optional key/value annotations map
53 */
Ayaka Koshibea9c199f2014-09-16 16:21:40 -070054 public DefaultHostDescription(MacAddress mac, VlanId vlan,
tom27ae0e62014-10-01 20:35:01 -070055 HostLocation location,
tomf5d85d42014-10-02 05:27:56 -070056 SparseAnnotations... annotations) {
Sho SHIMIZU21d00692016-08-15 11:15:28 -070057 this(mac, vlan, location, Collections.emptySet(),
Pavlin Radoslavov33f228a2014-10-27 19:33:16 -070058 annotations);
Ayaka Koshibe1a100982014-09-13 19:32:19 -070059 }
60
tom27ae0e62014-10-01 20:35:01 -070061 /**
62 * Creates a host description using the supplied information.
63 *
64 * @param mac host MAC address
65 * @param vlan host VLAN identifier
66 * @param location host location
tom093340b2014-10-10 00:15:36 -070067 * @param ip host IP address
tom27ae0e62014-10-01 20:35:01 -070068 * @param annotations optional key/value annotations map
69 */
Ayaka Koshibea9c199f2014-09-16 16:21:40 -070070 public DefaultHostDescription(MacAddress mac, VlanId vlan,
Pavlin Radoslavov33f228a2014-10-27 19:33:16 -070071 HostLocation location, IpAddress ip,
tomf5d85d42014-10-02 05:27:56 -070072 SparseAnnotations... annotations) {
Yuta HIGUCHI5fa3dc02014-10-15 17:08:13 -070073 this(mac, vlan, location, ImmutableSet.of(ip), annotations);
74 }
75
76 /**
77 * Creates a host description using the supplied information.
78 *
79 * @param mac host MAC address
80 * @param vlan host VLAN identifier
81 * @param location host location
82 * @param ip host IP addresses
83 * @param annotations optional key/value annotations map
84 */
85 public DefaultHostDescription(MacAddress mac, VlanId vlan,
Pavlin Radoslavov33f228a2014-10-27 19:33:16 -070086 HostLocation location, Set<IpAddress> ip,
Yuta HIGUCHI5fa3dc02014-10-15 17:08:13 -070087 SparseAnnotations... annotations) {
Deepa Vaddireddy50ad0802016-08-08 19:27:36 +053088 this(mac, vlan, location, ip, new WallClockTimestamp(), annotations);
89 }
90
91 /**
92 * Creates a host description using the supplied information.
93 *
94 * @param mac host MAC address
95 * @param vlan host VLAN identifier
96 * @param location host location
97 * @param ip host IP addresses
98 * @param timestamp host recent updated time
99 * @param annotations optional key/value annotations map
100 */
101 public DefaultHostDescription(MacAddress mac, VlanId vlan,
102 HostLocation location, Set<IpAddress> ip,
103 WallClockTimestamp timestamp, SparseAnnotations... annotations) {
tom27ae0e62014-10-01 20:35:01 -0700104 super(annotations);
Ayaka Koshibe74a23922014-09-09 16:45:39 -0700105 this.mac = mac;
106 this.vlan = vlan;
tom27ae0e62014-10-01 20:35:01 -0700107 this.location = location;
Yuta HIGUCHI5fa3dc02014-10-15 17:08:13 -0700108 this.ip = ImmutableSet.copyOf(ip);
Deepa Vaddireddy50ad0802016-08-08 19:27:36 +0530109 this.timestamp = timestamp;
Ayaka Koshibe74a23922014-09-09 16:45:39 -0700110 }
111
112 @Override
Ayaka Koshibea9c199f2014-09-16 16:21:40 -0700113 public MacAddress hwAddress() {
Ayaka Koshibe74a23922014-09-09 16:45:39 -0700114 return mac;
115 }
116
117 @Override
Ayaka Koshibea9c199f2014-09-16 16:21:40 -0700118 public VlanId vlan() {
Ayaka Koshibe74a23922014-09-09 16:45:39 -0700119 return vlan;
120 }
121
122 @Override
123 public HostLocation location() {
124 return location;
125 }
126
127 @Override
Pavlin Radoslavov33f228a2014-10-27 19:33:16 -0700128 public Set<IpAddress> ipAddress() {
tom093340b2014-10-10 00:15:36 -0700129 return ip;
Ayaka Koshibe74a23922014-09-09 16:45:39 -0700130 }
131
132 @Override
Deepa Vaddireddy50ad0802016-08-08 19:27:36 +0530133 public WallClockTimestamp timestamp() {
134 return timestamp;
135 }
136
137 @Override
Ayaka Koshibe74a23922014-09-09 16:45:39 -0700138 public String toString() {
139 return toStringHelper(this)
140 .add("mac", mac)
141 .add("vlan", vlan)
142 .add("location", location)
tom093340b2014-10-10 00:15:36 -0700143 .add("ipAddress", ip)
Deepa Vaddireddy50ad0802016-08-08 19:27:36 +0530144 .add("timestamp", timestamp)
Ayaka Koshibe74a23922014-09-09 16:45:39 -0700145 .toString();
146 }
147
HIGUCHI Yuta703a5af2015-11-18 23:43:50 -0800148 @Override
149 public int hashCode() {
150 return Objects.hashCode(super.hashCode(), mac, vlan, location, ip);
151 }
152
153 @Override
154 public boolean equals(Object object) {
155 if (object != null && getClass() == object.getClass()) {
156 if (!super.equals(object)) {
157 return false;
158 }
159 DefaultHostDescription that = (DefaultHostDescription) object;
160 return Objects.equal(this.mac, that.mac)
161 && Objects.equal(this.vlan, that.vlan)
162 && Objects.equal(this.location, that.location)
163 && Objects.equal(this.ip, that.ip);
164 }
165 return false;
166 }
Ayaka Koshibe74a23922014-09-09 16:45:39 -0700167}