Ayaka Koshibe | 74a2392 | 2014-09-09 16:45:39 -0700 | [diff] [blame] | 1 | package org.onlab.onos.net.host; |
| 2 | |
tom | 27ae0e6 | 2014-10-01 20:35:01 -0700 | [diff] [blame^] | 3 | import com.google.common.collect.ImmutableSet; |
| 4 | import org.onlab.onos.net.AbstractAnnotated; |
Ayaka Koshibe | 74a2392 | 2014-09-09 16:45:39 -0700 | [diff] [blame] | 5 | import org.onlab.onos.net.HostLocation; |
Ayaka Koshibe | 1d56fe4 | 2014-09-19 16:51:58 -0700 | [diff] [blame] | 6 | import org.onlab.packet.IpPrefix; |
Ayaka Koshibe | a9c199f | 2014-09-16 16:21:40 -0700 | [diff] [blame] | 7 | import org.onlab.packet.MacAddress; |
| 8 | import org.onlab.packet.VlanId; |
Ayaka Koshibe | 74a2392 | 2014-09-09 16:45:39 -0700 | [diff] [blame] | 9 | |
tom | 27ae0e6 | 2014-10-01 20:35:01 -0700 | [diff] [blame^] | 10 | import java.util.HashSet; |
| 11 | import java.util.Map; |
| 12 | import java.util.Set; |
Ayaka Koshibe | e565275 | 2014-09-10 23:27:34 -0700 | [diff] [blame] | 13 | |
tom | 27ae0e6 | 2014-10-01 20:35:01 -0700 | [diff] [blame^] | 14 | import static com.google.common.base.MoreObjects.toStringHelper; |
| 15 | |
| 16 | /** |
| 17 | * Default implementation of an immutable host description. |
| 18 | */ |
| 19 | public class DefaultHostDescription extends AbstractAnnotated |
| 20 | implements HostDescription { |
Ayaka Koshibe | 74a2392 | 2014-09-09 16:45:39 -0700 | [diff] [blame] | 21 | |
Ayaka Koshibe | a9c199f | 2014-09-16 16:21:40 -0700 | [diff] [blame] | 22 | private final MacAddress mac; |
| 23 | private final VlanId vlan; |
Ayaka Koshibe | 74a2392 | 2014-09-09 16:45:39 -0700 | [diff] [blame] | 24 | private final HostLocation location; |
Ayaka Koshibe | 1d56fe4 | 2014-09-19 16:51:58 -0700 | [diff] [blame] | 25 | private final Set<IpPrefix> ips; |
Ayaka Koshibe | 74a2392 | 2014-09-09 16:45:39 -0700 | [diff] [blame] | 26 | |
tom | 27ae0e6 | 2014-10-01 20:35:01 -0700 | [diff] [blame^] | 27 | /** |
| 28 | * Creates a host description using the supplied information. |
| 29 | * |
| 30 | * @param mac host MAC address |
| 31 | * @param vlan host VLAN identifier |
| 32 | * @param location host location |
| 33 | * @param annotations optional key/value annotations map |
| 34 | */ |
| 35 | @SafeVarargs |
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, |
| 38 | Map<String, String>... annotations) { |
| 39 | this(mac, vlan, location, new HashSet<IpPrefix>(), annotations); |
Ayaka Koshibe | 1a10098 | 2014-09-13 19:32:19 -0700 | [diff] [blame] | 40 | } |
| 41 | |
tom | 27ae0e6 | 2014-10-01 20:35:01 -0700 | [diff] [blame^] | 42 | /** |
| 43 | * Creates a host description using the supplied information. |
| 44 | * |
| 45 | * @param mac host MAC address |
| 46 | * @param vlan host VLAN identifier |
| 47 | * @param location host location |
| 48 | * @param ips of host IP addresses |
| 49 | * @param annotations optional key/value annotations map |
| 50 | */ |
| 51 | @SafeVarargs |
Ayaka Koshibe | a9c199f | 2014-09-16 16:21:40 -0700 | [diff] [blame] | 52 | public DefaultHostDescription(MacAddress mac, VlanId vlan, |
tom | 27ae0e6 | 2014-10-01 20:35:01 -0700 | [diff] [blame^] | 53 | HostLocation location, Set<IpPrefix> ips, |
| 54 | Map<String, String>... annotations) { |
| 55 | super(annotations); |
Ayaka Koshibe | 74a2392 | 2014-09-09 16:45:39 -0700 | [diff] [blame] | 56 | this.mac = mac; |
| 57 | this.vlan = vlan; |
tom | 27ae0e6 | 2014-10-01 20:35:01 -0700 | [diff] [blame^] | 58 | this.location = location; |
| 59 | this.ips = new HashSet<>(ips); |
Ayaka Koshibe | 74a2392 | 2014-09-09 16:45:39 -0700 | [diff] [blame] | 60 | } |
| 61 | |
| 62 | @Override |
Ayaka Koshibe | a9c199f | 2014-09-16 16:21:40 -0700 | [diff] [blame] | 63 | public MacAddress hwAddress() { |
Ayaka Koshibe | 74a2392 | 2014-09-09 16:45:39 -0700 | [diff] [blame] | 64 | return mac; |
| 65 | } |
| 66 | |
| 67 | @Override |
Ayaka Koshibe | a9c199f | 2014-09-16 16:21:40 -0700 | [diff] [blame] | 68 | public VlanId vlan() { |
Ayaka Koshibe | 74a2392 | 2014-09-09 16:45:39 -0700 | [diff] [blame] | 69 | return vlan; |
| 70 | } |
| 71 | |
| 72 | @Override |
| 73 | public HostLocation location() { |
| 74 | return location; |
| 75 | } |
| 76 | |
| 77 | @Override |
Ayaka Koshibe | 1d56fe4 | 2014-09-19 16:51:58 -0700 | [diff] [blame] | 78 | public Set<IpPrefix> ipAddresses() { |
Ayaka Koshibe | e565275 | 2014-09-10 23:27:34 -0700 | [diff] [blame] | 79 | return ImmutableSet.copyOf(ips); |
Ayaka Koshibe | 74a2392 | 2014-09-09 16:45:39 -0700 | [diff] [blame] | 80 | } |
| 81 | |
| 82 | @Override |
| 83 | public String toString() { |
| 84 | return toStringHelper(this) |
| 85 | .add("mac", mac) |
| 86 | .add("vlan", vlan) |
| 87 | .add("location", location) |
| 88 | .add("ipAddresses", ips) |
| 89 | .toString(); |
| 90 | } |
| 91 | |
| 92 | } |