blob: 61901832cffc48428a16e3b6c5b5855aa074fbf6 [file] [log] [blame]
Ayaka Koshibe74a23922014-09-09 16:45:39 -07001package org.onlab.onos.net.host;
2
tom27ae0e62014-10-01 20:35:01 -07003import com.google.common.collect.ImmutableSet;
4import org.onlab.onos.net.AbstractAnnotated;
Ayaka Koshibe74a23922014-09-09 16:45:39 -07005import org.onlab.onos.net.HostLocation;
Ayaka Koshibe1d56fe42014-09-19 16:51:58 -07006import org.onlab.packet.IpPrefix;
Ayaka Koshibea9c199f2014-09-16 16:21:40 -07007import org.onlab.packet.MacAddress;
8import org.onlab.packet.VlanId;
Ayaka Koshibe74a23922014-09-09 16:45:39 -07009
tom27ae0e62014-10-01 20:35:01 -070010import java.util.HashSet;
11import java.util.Map;
12import java.util.Set;
Ayaka Koshibee5652752014-09-10 23:27:34 -070013
tom27ae0e62014-10-01 20:35:01 -070014import static com.google.common.base.MoreObjects.toStringHelper;
15
16/**
17 * Default implementation of an immutable host description.
18 */
19public class DefaultHostDescription extends AbstractAnnotated
20 implements HostDescription {
Ayaka Koshibe74a23922014-09-09 16:45:39 -070021
Ayaka Koshibea9c199f2014-09-16 16:21:40 -070022 private final MacAddress mac;
23 private final VlanId vlan;
Ayaka Koshibe74a23922014-09-09 16:45:39 -070024 private final HostLocation location;
Ayaka Koshibe1d56fe42014-09-19 16:51:58 -070025 private final Set<IpPrefix> ips;
Ayaka Koshibe74a23922014-09-09 16:45:39 -070026
tom27ae0e62014-10-01 20:35:01 -070027 /**
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 Koshibea9c199f2014-09-16 16:21:40 -070036 public DefaultHostDescription(MacAddress mac, VlanId vlan,
tom27ae0e62014-10-01 20:35:01 -070037 HostLocation location,
38 Map<String, String>... annotations) {
39 this(mac, vlan, location, new HashSet<IpPrefix>(), annotations);
Ayaka Koshibe1a100982014-09-13 19:32:19 -070040 }
41
tom27ae0e62014-10-01 20:35:01 -070042 /**
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 Koshibea9c199f2014-09-16 16:21:40 -070052 public DefaultHostDescription(MacAddress mac, VlanId vlan,
tom27ae0e62014-10-01 20:35:01 -070053 HostLocation location, Set<IpPrefix> ips,
54 Map<String, String>... annotations) {
55 super(annotations);
Ayaka Koshibe74a23922014-09-09 16:45:39 -070056 this.mac = mac;
57 this.vlan = vlan;
tom27ae0e62014-10-01 20:35:01 -070058 this.location = location;
59 this.ips = new HashSet<>(ips);
Ayaka Koshibe74a23922014-09-09 16:45:39 -070060 }
61
62 @Override
Ayaka Koshibea9c199f2014-09-16 16:21:40 -070063 public MacAddress hwAddress() {
Ayaka Koshibe74a23922014-09-09 16:45:39 -070064 return mac;
65 }
66
67 @Override
Ayaka Koshibea9c199f2014-09-16 16:21:40 -070068 public VlanId vlan() {
Ayaka Koshibe74a23922014-09-09 16:45:39 -070069 return vlan;
70 }
71
72 @Override
73 public HostLocation location() {
74 return location;
75 }
76
77 @Override
Ayaka Koshibe1d56fe42014-09-19 16:51:58 -070078 public Set<IpPrefix> ipAddresses() {
Ayaka Koshibee5652752014-09-10 23:27:34 -070079 return ImmutableSet.copyOf(ips);
Ayaka Koshibe74a23922014-09-09 16:45:39 -070080 }
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}