blob: bc6e3e5ab046a99b7a45a00ea63ad47db710ed68 [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;
tomf5d85d42014-10-02 05:27:56 -07004import org.onlab.onos.net.AbstractDescription;
Ayaka Koshibe74a23922014-09-09 16:45:39 -07005import org.onlab.onos.net.HostLocation;
tomf5d85d42014-10-02 05:27:56 -07006import org.onlab.onos.net.SparseAnnotations;
Ayaka Koshibe1d56fe42014-09-19 16:51:58 -07007import org.onlab.packet.IpPrefix;
Ayaka Koshibea9c199f2014-09-16 16:21:40 -07008import org.onlab.packet.MacAddress;
9import org.onlab.packet.VlanId;
Ayaka Koshibe74a23922014-09-09 16:45:39 -070010
tom27ae0e62014-10-01 20:35:01 -070011import java.util.HashSet;
tom27ae0e62014-10-01 20:35:01 -070012import 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 */
tomf5d85d42014-10-02 05:27:56 -070019public class DefaultHostDescription extends AbstractDescription
tom27ae0e62014-10-01 20:35:01 -070020 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 */
Ayaka Koshibea9c199f2014-09-16 16:21:40 -070035 public DefaultHostDescription(MacAddress mac, VlanId vlan,
tom27ae0e62014-10-01 20:35:01 -070036 HostLocation location,
tomf5d85d42014-10-02 05:27:56 -070037 SparseAnnotations... annotations) {
tom27ae0e62014-10-01 20:35:01 -070038 this(mac, vlan, location, new HashSet<IpPrefix>(), annotations);
Ayaka Koshibe1a100982014-09-13 19:32:19 -070039 }
40
tom27ae0e62014-10-01 20:35:01 -070041 /**
42 * Creates a host description using the supplied information.
43 *
44 * @param mac host MAC address
45 * @param vlan host VLAN identifier
46 * @param location host location
47 * @param ips of host IP addresses
48 * @param annotations optional key/value annotations map
49 */
Ayaka Koshibea9c199f2014-09-16 16:21:40 -070050 public DefaultHostDescription(MacAddress mac, VlanId vlan,
tom27ae0e62014-10-01 20:35:01 -070051 HostLocation location, Set<IpPrefix> ips,
tomf5d85d42014-10-02 05:27:56 -070052 SparseAnnotations... annotations) {
tom27ae0e62014-10-01 20:35:01 -070053 super(annotations);
Ayaka Koshibe74a23922014-09-09 16:45:39 -070054 this.mac = mac;
55 this.vlan = vlan;
tom27ae0e62014-10-01 20:35:01 -070056 this.location = location;
57 this.ips = new HashSet<>(ips);
Ayaka Koshibe74a23922014-09-09 16:45:39 -070058 }
59
60 @Override
Ayaka Koshibea9c199f2014-09-16 16:21:40 -070061 public MacAddress hwAddress() {
Ayaka Koshibe74a23922014-09-09 16:45:39 -070062 return mac;
63 }
64
65 @Override
Ayaka Koshibea9c199f2014-09-16 16:21:40 -070066 public VlanId vlan() {
Ayaka Koshibe74a23922014-09-09 16:45:39 -070067 return vlan;
68 }
69
70 @Override
71 public HostLocation location() {
72 return location;
73 }
74
75 @Override
Ayaka Koshibe1d56fe42014-09-19 16:51:58 -070076 public Set<IpPrefix> ipAddresses() {
Ayaka Koshibee5652752014-09-10 23:27:34 -070077 return ImmutableSet.copyOf(ips);
Ayaka Koshibe74a23922014-09-09 16:45:39 -070078 }
79
80 @Override
81 public String toString() {
82 return toStringHelper(this)
83 .add("mac", mac)
84 .add("vlan", vlan)
85 .add("location", location)
86 .add("ipAddresses", ips)
87 .toString();
88 }
89
90}