blob: 71a952e75dc04bc0d519a2cae770914e759ba8da [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;
Ayaka Koshibe1d56fe42014-09-19 16:51:58 -07009import org.onlab.packet.IpPrefix;
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;
Yuta HIGUCHI5fa3dc02014-10-15 17:08:13 -070026 private final Set<IpPrefix> 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) {
Yuta HIGUCHI5fa3dc02014-10-15 17:08:13 -070039 this(mac, vlan, location, Collections.<IpPrefix>emptySet(), 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
tom093340b2014-10-10 00:15:36 -070048 * @param ip host IP address
tom27ae0e62014-10-01 20:35:01 -070049 * @param annotations optional key/value annotations map
50 */
Ayaka Koshibea9c199f2014-09-16 16:21:40 -070051 public DefaultHostDescription(MacAddress mac, VlanId vlan,
tom093340b2014-10-10 00:15:36 -070052 HostLocation location, IpPrefix ip,
tomf5d85d42014-10-02 05:27:56 -070053 SparseAnnotations... annotations) {
Yuta HIGUCHI5fa3dc02014-10-15 17:08:13 -070054 this(mac, vlan, location, ImmutableSet.of(ip), annotations);
55 }
56
57 /**
58 * Creates a host description using the supplied information.
59 *
60 * @param mac host MAC address
61 * @param vlan host VLAN identifier
62 * @param location host location
63 * @param ip host IP addresses
64 * @param annotations optional key/value annotations map
65 */
66 public DefaultHostDescription(MacAddress mac, VlanId vlan,
67 HostLocation location, Set<IpPrefix> ip,
68 SparseAnnotations... annotations) {
tom27ae0e62014-10-01 20:35:01 -070069 super(annotations);
Ayaka Koshibe74a23922014-09-09 16:45:39 -070070 this.mac = mac;
71 this.vlan = vlan;
tom27ae0e62014-10-01 20:35:01 -070072 this.location = location;
Yuta HIGUCHI5fa3dc02014-10-15 17:08:13 -070073 this.ip = ImmutableSet.copyOf(ip);
Ayaka Koshibe74a23922014-09-09 16:45:39 -070074 }
75
76 @Override
Ayaka Koshibea9c199f2014-09-16 16:21:40 -070077 public MacAddress hwAddress() {
Ayaka Koshibe74a23922014-09-09 16:45:39 -070078 return mac;
79 }
80
81 @Override
Ayaka Koshibea9c199f2014-09-16 16:21:40 -070082 public VlanId vlan() {
Ayaka Koshibe74a23922014-09-09 16:45:39 -070083 return vlan;
84 }
85
86 @Override
87 public HostLocation location() {
88 return location;
89 }
90
91 @Override
Yuta HIGUCHI5fa3dc02014-10-15 17:08:13 -070092 public Set<IpPrefix> ipAddress() {
tom093340b2014-10-10 00:15:36 -070093 return ip;
Ayaka Koshibe74a23922014-09-09 16:45:39 -070094 }
95
96 @Override
97 public String toString() {
98 return toStringHelper(this)
99 .add("mac", mac)
100 .add("vlan", vlan)
101 .add("location", location)
tom093340b2014-10-10 00:15:36 -0700102 .add("ipAddress", ip)
Ayaka Koshibe74a23922014-09-09 16:45:39 -0700103 .toString();
104 }
105
106}