blob: ae548e18d6261666217e919602f30dd5a9d85a74 [file] [log] [blame]
Ayaka Koshibe74a23922014-09-09 16:45:39 -07001package org.onlab.onos.net.host;
2
Yuta HIGUCHI5fa3dc02014-10-15 17:08:13 -07003import java.util.Collections;
4import java.util.Set;
5
tomf5d85d42014-10-02 05:27:56 -07006import org.onlab.onos.net.AbstractDescription;
Ayaka Koshibe74a23922014-09-09 16:45:39 -07007import org.onlab.onos.net.HostLocation;
tomf5d85d42014-10-02 05:27:56 -07008import org.onlab.onos.net.SparseAnnotations;
Pavlin Radoslavov33f228a2014-10-27 19:33:16 -07009import org.onlab.packet.IpAddress;
Ayaka Koshibea9c199f2014-09-16 16:21:40 -070010import org.onlab.packet.MacAddress;
11import org.onlab.packet.VlanId;
Ayaka Koshibe74a23922014-09-09 16:45:39 -070012
Yuta HIGUCHI5fa3dc02014-10-15 17:08:13 -070013import com.google.common.collect.ImmutableSet;
14
tom27ae0e62014-10-01 20:35:01 -070015import static com.google.common.base.MoreObjects.toStringHelper;
16
17/**
18 * Default implementation of an immutable host description.
19 */
tomf5d85d42014-10-02 05:27:56 -070020public class DefaultHostDescription extends AbstractDescription
tom27ae0e62014-10-01 20:35:01 -070021 implements HostDescription {
Ayaka Koshibe74a23922014-09-09 16:45:39 -070022
Ayaka Koshibea9c199f2014-09-16 16:21:40 -070023 private final MacAddress mac;
24 private final VlanId vlan;
Ayaka Koshibe74a23922014-09-09 16:45:39 -070025 private final HostLocation location;
Pavlin Radoslavov33f228a2014-10-27 19:33:16 -070026 private final Set<IpAddress> ip;
Ayaka Koshibe74a23922014-09-09 16:45:39 -070027
tom27ae0e62014-10-01 20:35:01 -070028 /**
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 Koshibea9c199f2014-09-16 16:21:40 -070036 public DefaultHostDescription(MacAddress mac, VlanId vlan,
tom27ae0e62014-10-01 20:35:01 -070037 HostLocation location,
tomf5d85d42014-10-02 05:27:56 -070038 SparseAnnotations... annotations) {
Pavlin Radoslavov33f228a2014-10-27 19:33:16 -070039 this(mac, vlan, location, Collections.<IpAddress>emptySet(),
40 annotations);
Ayaka Koshibe1a100982014-09-13 19:32:19 -070041 }
42
tom27ae0e62014-10-01 20:35:01 -070043 /**
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
tom093340b2014-10-10 00:15:36 -070049 * @param ip host IP address
tom27ae0e62014-10-01 20:35:01 -070050 * @param annotations optional key/value annotations map
51 */
Ayaka Koshibea9c199f2014-09-16 16:21:40 -070052 public DefaultHostDescription(MacAddress mac, VlanId vlan,
Pavlin Radoslavov33f228a2014-10-27 19:33:16 -070053 HostLocation location, IpAddress ip,
tomf5d85d42014-10-02 05:27:56 -070054 SparseAnnotations... annotations) {
Yuta HIGUCHI5fa3dc02014-10-15 17:08:13 -070055 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 Radoslavov33f228a2014-10-27 19:33:16 -070068 HostLocation location, Set<IpAddress> ip,
Yuta HIGUCHI5fa3dc02014-10-15 17:08:13 -070069 SparseAnnotations... annotations) {
tom27ae0e62014-10-01 20:35:01 -070070 super(annotations);
Ayaka Koshibe74a23922014-09-09 16:45:39 -070071 this.mac = mac;
72 this.vlan = vlan;
tom27ae0e62014-10-01 20:35:01 -070073 this.location = location;
Yuta HIGUCHI5fa3dc02014-10-15 17:08:13 -070074 this.ip = ImmutableSet.copyOf(ip);
Ayaka Koshibe74a23922014-09-09 16:45:39 -070075 }
76
77 @Override
Ayaka Koshibea9c199f2014-09-16 16:21:40 -070078 public MacAddress hwAddress() {
Ayaka Koshibe74a23922014-09-09 16:45:39 -070079 return mac;
80 }
81
82 @Override
Ayaka Koshibea9c199f2014-09-16 16:21:40 -070083 public VlanId vlan() {
Ayaka Koshibe74a23922014-09-09 16:45:39 -070084 return vlan;
85 }
86
87 @Override
88 public HostLocation location() {
89 return location;
90 }
91
92 @Override
Pavlin Radoslavov33f228a2014-10-27 19:33:16 -070093 public Set<IpAddress> ipAddress() {
tom093340b2014-10-10 00:15:36 -070094 return ip;
Ayaka Koshibe74a23922014-09-09 16:45:39 -070095 }
96
97 @Override
98 public String toString() {
99 return toStringHelper(this)
100 .add("mac", mac)
101 .add("vlan", vlan)
102 .add("location", location)
tom093340b2014-10-10 00:15:36 -0700103 .add("ipAddress", ip)
Ayaka Koshibe74a23922014-09-09 16:45:39 -0700104 .toString();
105 }
106
107}