Ayaka Koshibe | 74a2392 | 2014-09-09 16:45:39 -0700 | [diff] [blame] | 1 | package org.onlab.onos.net.host; |
| 2 | |
Yuta HIGUCHI | 5fa3dc0 | 2014-10-15 17:08:13 -0700 | [diff] [blame] | 3 | import java.util.Collections; |
| 4 | import java.util.Set; |
| 5 | |
tom | f5d85d4 | 2014-10-02 05:27:56 -0700 | [diff] [blame] | 6 | import org.onlab.onos.net.AbstractDescription; |
Ayaka Koshibe | 74a2392 | 2014-09-09 16:45:39 -0700 | [diff] [blame] | 7 | import org.onlab.onos.net.HostLocation; |
tom | f5d85d4 | 2014-10-02 05:27:56 -0700 | [diff] [blame] | 8 | import org.onlab.onos.net.SparseAnnotations; |
Pavlin Radoslavov | 33f228a | 2014-10-27 19:33:16 -0700 | [diff] [blame^] | 9 | import org.onlab.packet.IpAddress; |
Ayaka Koshibe | a9c199f | 2014-09-16 16:21:40 -0700 | [diff] [blame] | 10 | import org.onlab.packet.MacAddress; |
| 11 | import org.onlab.packet.VlanId; |
Ayaka Koshibe | 74a2392 | 2014-09-09 16:45:39 -0700 | [diff] [blame] | 12 | |
Yuta HIGUCHI | 5fa3dc0 | 2014-10-15 17:08:13 -0700 | [diff] [blame] | 13 | import com.google.common.collect.ImmutableSet; |
| 14 | |
tom | 27ae0e6 | 2014-10-01 20:35:01 -0700 | [diff] [blame] | 15 | import static com.google.common.base.MoreObjects.toStringHelper; |
| 16 | |
| 17 | /** |
| 18 | * Default implementation of an immutable host description. |
| 19 | */ |
tom | f5d85d4 | 2014-10-02 05:27:56 -0700 | [diff] [blame] | 20 | public class DefaultHostDescription extends AbstractDescription |
tom | 27ae0e6 | 2014-10-01 20:35:01 -0700 | [diff] [blame] | 21 | implements HostDescription { |
Ayaka Koshibe | 74a2392 | 2014-09-09 16:45:39 -0700 | [diff] [blame] | 22 | |
Ayaka Koshibe | a9c199f | 2014-09-16 16:21:40 -0700 | [diff] [blame] | 23 | private final MacAddress mac; |
| 24 | private final VlanId vlan; |
Ayaka Koshibe | 74a2392 | 2014-09-09 16:45:39 -0700 | [diff] [blame] | 25 | private final HostLocation location; |
Pavlin Radoslavov | 33f228a | 2014-10-27 19:33:16 -0700 | [diff] [blame^] | 26 | private final Set<IpAddress> ip; |
Ayaka Koshibe | 74a2392 | 2014-09-09 16:45:39 -0700 | [diff] [blame] | 27 | |
tom | 27ae0e6 | 2014-10-01 20:35:01 -0700 | [diff] [blame] | 28 | /** |
| 29 | * Creates a host description using the supplied information. |
| 30 | * |
| 31 | * @param mac host MAC address |
| 32 | * @param vlan host VLAN identifier |
| 33 | * @param location host location |
| 34 | * @param annotations optional key/value annotations map |
| 35 | */ |
Ayaka Koshibe | a9c199f | 2014-09-16 16:21:40 -0700 | [diff] [blame] | 36 | public DefaultHostDescription(MacAddress mac, VlanId vlan, |
tom | 27ae0e6 | 2014-10-01 20:35:01 -0700 | [diff] [blame] | 37 | HostLocation location, |
tom | f5d85d4 | 2014-10-02 05:27:56 -0700 | [diff] [blame] | 38 | SparseAnnotations... annotations) { |
Pavlin Radoslavov | 33f228a | 2014-10-27 19:33:16 -0700 | [diff] [blame^] | 39 | this(mac, vlan, location, Collections.<IpAddress>emptySet(), |
| 40 | annotations); |
Ayaka Koshibe | 1a10098 | 2014-09-13 19:32:19 -0700 | [diff] [blame] | 41 | } |
| 42 | |
tom | 27ae0e6 | 2014-10-01 20:35:01 -0700 | [diff] [blame] | 43 | /** |
| 44 | * Creates a host description using the supplied information. |
| 45 | * |
| 46 | * @param mac host MAC address |
| 47 | * @param vlan host VLAN identifier |
| 48 | * @param location host location |
tom | 093340b | 2014-10-10 00:15:36 -0700 | [diff] [blame] | 49 | * @param ip host IP address |
tom | 27ae0e6 | 2014-10-01 20:35:01 -0700 | [diff] [blame] | 50 | * @param annotations optional key/value annotations map |
| 51 | */ |
Ayaka Koshibe | a9c199f | 2014-09-16 16:21:40 -0700 | [diff] [blame] | 52 | public DefaultHostDescription(MacAddress mac, VlanId vlan, |
Pavlin Radoslavov | 33f228a | 2014-10-27 19:33:16 -0700 | [diff] [blame^] | 53 | HostLocation location, IpAddress ip, |
tom | f5d85d4 | 2014-10-02 05:27:56 -0700 | [diff] [blame] | 54 | SparseAnnotations... annotations) { |
Yuta HIGUCHI | 5fa3dc0 | 2014-10-15 17:08:13 -0700 | [diff] [blame] | 55 | this(mac, vlan, location, ImmutableSet.of(ip), annotations); |
| 56 | } |
| 57 | |
| 58 | /** |
| 59 | * Creates a host description using the supplied information. |
| 60 | * |
| 61 | * @param mac host MAC address |
| 62 | * @param vlan host VLAN identifier |
| 63 | * @param location host location |
| 64 | * @param ip host IP addresses |
| 65 | * @param annotations optional key/value annotations map |
| 66 | */ |
| 67 | public DefaultHostDescription(MacAddress mac, VlanId vlan, |
Pavlin Radoslavov | 33f228a | 2014-10-27 19:33:16 -0700 | [diff] [blame^] | 68 | HostLocation location, Set<IpAddress> ip, |
Yuta HIGUCHI | 5fa3dc0 | 2014-10-15 17:08:13 -0700 | [diff] [blame] | 69 | SparseAnnotations... annotations) { |
tom | 27ae0e6 | 2014-10-01 20:35:01 -0700 | [diff] [blame] | 70 | super(annotations); |
Ayaka Koshibe | 74a2392 | 2014-09-09 16:45:39 -0700 | [diff] [blame] | 71 | this.mac = mac; |
| 72 | this.vlan = vlan; |
tom | 27ae0e6 | 2014-10-01 20:35:01 -0700 | [diff] [blame] | 73 | this.location = location; |
Yuta HIGUCHI | 5fa3dc0 | 2014-10-15 17:08:13 -0700 | [diff] [blame] | 74 | this.ip = ImmutableSet.copyOf(ip); |
Ayaka Koshibe | 74a2392 | 2014-09-09 16:45:39 -0700 | [diff] [blame] | 75 | } |
| 76 | |
| 77 | @Override |
Ayaka Koshibe | a9c199f | 2014-09-16 16:21:40 -0700 | [diff] [blame] | 78 | public MacAddress hwAddress() { |
Ayaka Koshibe | 74a2392 | 2014-09-09 16:45:39 -0700 | [diff] [blame] | 79 | return mac; |
| 80 | } |
| 81 | |
| 82 | @Override |
Ayaka Koshibe | a9c199f | 2014-09-16 16:21:40 -0700 | [diff] [blame] | 83 | public VlanId vlan() { |
Ayaka Koshibe | 74a2392 | 2014-09-09 16:45:39 -0700 | [diff] [blame] | 84 | return vlan; |
| 85 | } |
| 86 | |
| 87 | @Override |
| 88 | public HostLocation location() { |
| 89 | return location; |
| 90 | } |
| 91 | |
| 92 | @Override |
Pavlin Radoslavov | 33f228a | 2014-10-27 19:33:16 -0700 | [diff] [blame^] | 93 | public Set<IpAddress> ipAddress() { |
tom | 093340b | 2014-10-10 00:15:36 -0700 | [diff] [blame] | 94 | return ip; |
Ayaka Koshibe | 74a2392 | 2014-09-09 16:45:39 -0700 | [diff] [blame] | 95 | } |
| 96 | |
| 97 | @Override |
| 98 | public String toString() { |
| 99 | return toStringHelper(this) |
| 100 | .add("mac", mac) |
| 101 | .add("vlan", vlan) |
| 102 | .add("location", location) |
tom | 093340b | 2014-10-10 00:15:36 -0700 | [diff] [blame] | 103 | .add("ipAddress", ip) |
Ayaka Koshibe | 74a2392 | 2014-09-09 16:45:39 -0700 | [diff] [blame] | 104 | .toString(); |
| 105 | } |
| 106 | |
| 107 | } |