Thomas Vachuska | 4f1a60c | 2014-10-28 13:39:07 -0700 | [diff] [blame] | 1 | /* |
Brian O'Connor | 5ab426f | 2016-04-09 01:19:45 -0700 | [diff] [blame] | 2 | * Copyright 2014-present Open Networking Laboratory |
Thomas Vachuska | 4f1a60c | 2014-10-28 13:39:07 -0700 | [diff] [blame] | 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'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 16 | package org.onosproject.net.host; |
Ayaka Koshibe | 74a2392 | 2014-09-09 16:45:39 -0700 | [diff] [blame] | 17 | |
Yuta HIGUCHI | 5fa3dc0 | 2014-10-15 17:08:13 -0700 | [diff] [blame] | 18 | import java.util.Collections; |
| 19 | import java.util.Set; |
| 20 | |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 21 | import org.onosproject.net.AbstractDescription; |
| 22 | import org.onosproject.net.HostLocation; |
| 23 | import org.onosproject.net.SparseAnnotations; |
Deepa Vaddireddy | 50ad080 | 2016-08-08 19:27:36 +0530 | [diff] [blame^] | 24 | import org.onosproject.store.service.WallClockTimestamp; |
Pavlin Radoslavov | 33f228a | 2014-10-27 19:33:16 -0700 | [diff] [blame] | 25 | import org.onlab.packet.IpAddress; |
Ayaka Koshibe | a9c199f | 2014-09-16 16:21:40 -0700 | [diff] [blame] | 26 | import org.onlab.packet.MacAddress; |
| 27 | import org.onlab.packet.VlanId; |
Ayaka Koshibe | 74a2392 | 2014-09-09 16:45:39 -0700 | [diff] [blame] | 28 | |
Yuta HIGUCHI | 5fa3dc0 | 2014-10-15 17:08:13 -0700 | [diff] [blame] | 29 | import com.google.common.collect.ImmutableSet; |
| 30 | |
tom | 27ae0e6 | 2014-10-01 20:35:01 -0700 | [diff] [blame] | 31 | import static com.google.common.base.MoreObjects.toStringHelper; |
HIGUCHI Yuta | 703a5af | 2015-11-18 23:43:50 -0800 | [diff] [blame] | 32 | import com.google.common.base.Objects; |
tom | 27ae0e6 | 2014-10-01 20:35:01 -0700 | [diff] [blame] | 33 | |
| 34 | /** |
| 35 | * Default implementation of an immutable host description. |
| 36 | */ |
tom | f5d85d4 | 2014-10-02 05:27:56 -0700 | [diff] [blame] | 37 | public class DefaultHostDescription extends AbstractDescription |
tom | 27ae0e6 | 2014-10-01 20:35:01 -0700 | [diff] [blame] | 38 | implements HostDescription { |
Ayaka Koshibe | 74a2392 | 2014-09-09 16:45:39 -0700 | [diff] [blame] | 39 | |
Ayaka Koshibe | a9c199f | 2014-09-16 16:21:40 -0700 | [diff] [blame] | 40 | private final MacAddress mac; |
| 41 | private final VlanId vlan; |
Ayaka Koshibe | 74a2392 | 2014-09-09 16:45:39 -0700 | [diff] [blame] | 42 | private final HostLocation location; |
Pavlin Radoslavov | 33f228a | 2014-10-27 19:33:16 -0700 | [diff] [blame] | 43 | private final Set<IpAddress> ip; |
Deepa Vaddireddy | 50ad080 | 2016-08-08 19:27:36 +0530 | [diff] [blame^] | 44 | private final WallClockTimestamp timestamp; |
Ayaka Koshibe | 74a2392 | 2014-09-09 16:45:39 -0700 | [diff] [blame] | 45 | |
tom | 27ae0e6 | 2014-10-01 20:35:01 -0700 | [diff] [blame] | 46 | /** |
| 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 Koshibe | a9c199f | 2014-09-16 16:21:40 -0700 | [diff] [blame] | 54 | public DefaultHostDescription(MacAddress mac, VlanId vlan, |
tom | 27ae0e6 | 2014-10-01 20:35:01 -0700 | [diff] [blame] | 55 | HostLocation location, |
tom | f5d85d4 | 2014-10-02 05:27:56 -0700 | [diff] [blame] | 56 | SparseAnnotations... annotations) { |
Sho SHIMIZU | 21d0069 | 2016-08-15 11:15:28 -0700 | [diff] [blame] | 57 | this(mac, vlan, location, Collections.emptySet(), |
Pavlin Radoslavov | 33f228a | 2014-10-27 19:33:16 -0700 | [diff] [blame] | 58 | annotations); |
Ayaka Koshibe | 1a10098 | 2014-09-13 19:32:19 -0700 | [diff] [blame] | 59 | } |
| 60 | |
tom | 27ae0e6 | 2014-10-01 20:35:01 -0700 | [diff] [blame] | 61 | /** |
| 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 |
tom | 093340b | 2014-10-10 00:15:36 -0700 | [diff] [blame] | 67 | * @param ip host IP address |
tom | 27ae0e6 | 2014-10-01 20:35:01 -0700 | [diff] [blame] | 68 | * @param annotations optional key/value annotations map |
| 69 | */ |
Ayaka Koshibe | a9c199f | 2014-09-16 16:21:40 -0700 | [diff] [blame] | 70 | public DefaultHostDescription(MacAddress mac, VlanId vlan, |
Pavlin Radoslavov | 33f228a | 2014-10-27 19:33:16 -0700 | [diff] [blame] | 71 | HostLocation location, IpAddress ip, |
tom | f5d85d4 | 2014-10-02 05:27:56 -0700 | [diff] [blame] | 72 | SparseAnnotations... annotations) { |
Yuta HIGUCHI | 5fa3dc0 | 2014-10-15 17:08:13 -0700 | [diff] [blame] | 73 | 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 Radoslavov | 33f228a | 2014-10-27 19:33:16 -0700 | [diff] [blame] | 86 | HostLocation location, Set<IpAddress> ip, |
Yuta HIGUCHI | 5fa3dc0 | 2014-10-15 17:08:13 -0700 | [diff] [blame] | 87 | SparseAnnotations... annotations) { |
Deepa Vaddireddy | 50ad080 | 2016-08-08 19:27:36 +0530 | [diff] [blame^] | 88 | 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) { |
tom | 27ae0e6 | 2014-10-01 20:35:01 -0700 | [diff] [blame] | 104 | super(annotations); |
Ayaka Koshibe | 74a2392 | 2014-09-09 16:45:39 -0700 | [diff] [blame] | 105 | this.mac = mac; |
| 106 | this.vlan = vlan; |
tom | 27ae0e6 | 2014-10-01 20:35:01 -0700 | [diff] [blame] | 107 | this.location = location; |
Yuta HIGUCHI | 5fa3dc0 | 2014-10-15 17:08:13 -0700 | [diff] [blame] | 108 | this.ip = ImmutableSet.copyOf(ip); |
Deepa Vaddireddy | 50ad080 | 2016-08-08 19:27:36 +0530 | [diff] [blame^] | 109 | this.timestamp = timestamp; |
Ayaka Koshibe | 74a2392 | 2014-09-09 16:45:39 -0700 | [diff] [blame] | 110 | } |
| 111 | |
| 112 | @Override |
Ayaka Koshibe | a9c199f | 2014-09-16 16:21:40 -0700 | [diff] [blame] | 113 | public MacAddress hwAddress() { |
Ayaka Koshibe | 74a2392 | 2014-09-09 16:45:39 -0700 | [diff] [blame] | 114 | return mac; |
| 115 | } |
| 116 | |
| 117 | @Override |
Ayaka Koshibe | a9c199f | 2014-09-16 16:21:40 -0700 | [diff] [blame] | 118 | public VlanId vlan() { |
Ayaka Koshibe | 74a2392 | 2014-09-09 16:45:39 -0700 | [diff] [blame] | 119 | return vlan; |
| 120 | } |
| 121 | |
| 122 | @Override |
| 123 | public HostLocation location() { |
| 124 | return location; |
| 125 | } |
| 126 | |
| 127 | @Override |
Pavlin Radoslavov | 33f228a | 2014-10-27 19:33:16 -0700 | [diff] [blame] | 128 | public Set<IpAddress> ipAddress() { |
tom | 093340b | 2014-10-10 00:15:36 -0700 | [diff] [blame] | 129 | return ip; |
Ayaka Koshibe | 74a2392 | 2014-09-09 16:45:39 -0700 | [diff] [blame] | 130 | } |
| 131 | |
| 132 | @Override |
Deepa Vaddireddy | 50ad080 | 2016-08-08 19:27:36 +0530 | [diff] [blame^] | 133 | public WallClockTimestamp timestamp() { |
| 134 | return timestamp; |
| 135 | } |
| 136 | |
| 137 | @Override |
Ayaka Koshibe | 74a2392 | 2014-09-09 16:45:39 -0700 | [diff] [blame] | 138 | public String toString() { |
| 139 | return toStringHelper(this) |
| 140 | .add("mac", mac) |
| 141 | .add("vlan", vlan) |
| 142 | .add("location", location) |
tom | 093340b | 2014-10-10 00:15:36 -0700 | [diff] [blame] | 143 | .add("ipAddress", ip) |
Deepa Vaddireddy | 50ad080 | 2016-08-08 19:27:36 +0530 | [diff] [blame^] | 144 | .add("timestamp", timestamp) |
Ayaka Koshibe | 74a2392 | 2014-09-09 16:45:39 -0700 | [diff] [blame] | 145 | .toString(); |
| 146 | } |
| 147 | |
HIGUCHI Yuta | 703a5af | 2015-11-18 23:43:50 -0800 | [diff] [blame] | 148 | @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 Koshibe | 74a2392 | 2014-09-09 16:45:39 -0700 | [diff] [blame] | 167 | } |