blob: 2e92daddd4870f64b9700425dd684abd8df22430 [file] [log] [blame]
Ayaka Koshibe74a23922014-09-09 16:45:39 -07001package org.onlab.onos.net.host;
2
tomf5d85d42014-10-02 05:27:56 -07003import org.onlab.onos.net.AbstractDescription;
Ayaka Koshibe74a23922014-09-09 16:45:39 -07004import org.onlab.onos.net.HostLocation;
tomf5d85d42014-10-02 05:27:56 -07005import org.onlab.onos.net.SparseAnnotations;
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 static com.google.common.base.MoreObjects.toStringHelper;
11
12/**
13 * Default implementation of an immutable host description.
14 */
tomf5d85d42014-10-02 05:27:56 -070015public class DefaultHostDescription extends AbstractDescription
tom27ae0e62014-10-01 20:35:01 -070016 implements HostDescription {
Ayaka Koshibe74a23922014-09-09 16:45:39 -070017
Ayaka Koshibea9c199f2014-09-16 16:21:40 -070018 private final MacAddress mac;
19 private final VlanId vlan;
Ayaka Koshibe74a23922014-09-09 16:45:39 -070020 private final HostLocation location;
tom093340b2014-10-10 00:15:36 -070021 private final IpPrefix ip;
Ayaka Koshibe74a23922014-09-09 16:45:39 -070022
tom27ae0e62014-10-01 20:35:01 -070023 /**
24 * Creates a host description using the supplied information.
25 *
26 * @param mac host MAC address
27 * @param vlan host VLAN identifier
28 * @param location host location
29 * @param annotations optional key/value annotations map
30 */
Ayaka Koshibea9c199f2014-09-16 16:21:40 -070031 public DefaultHostDescription(MacAddress mac, VlanId vlan,
tom27ae0e62014-10-01 20:35:01 -070032 HostLocation location,
tomf5d85d42014-10-02 05:27:56 -070033 SparseAnnotations... annotations) {
tom093340b2014-10-10 00:15:36 -070034 this(mac, vlan, location, null, annotations);
Ayaka Koshibe1a100982014-09-13 19:32:19 -070035 }
36
tom27ae0e62014-10-01 20:35:01 -070037 /**
38 * Creates a host description using the supplied information.
39 *
40 * @param mac host MAC address
41 * @param vlan host VLAN identifier
42 * @param location host location
tom093340b2014-10-10 00:15:36 -070043 * @param ip host IP address
tom27ae0e62014-10-01 20:35:01 -070044 * @param annotations optional key/value annotations map
45 */
Ayaka Koshibea9c199f2014-09-16 16:21:40 -070046 public DefaultHostDescription(MacAddress mac, VlanId vlan,
tom093340b2014-10-10 00:15:36 -070047 HostLocation location, IpPrefix ip,
tomf5d85d42014-10-02 05:27:56 -070048 SparseAnnotations... annotations) {
tom27ae0e62014-10-01 20:35:01 -070049 super(annotations);
Ayaka Koshibe74a23922014-09-09 16:45:39 -070050 this.mac = mac;
51 this.vlan = vlan;
tom27ae0e62014-10-01 20:35:01 -070052 this.location = location;
tom093340b2014-10-10 00:15:36 -070053 this.ip = ip;
Ayaka Koshibe74a23922014-09-09 16:45:39 -070054 }
55
56 @Override
Ayaka Koshibea9c199f2014-09-16 16:21:40 -070057 public MacAddress hwAddress() {
Ayaka Koshibe74a23922014-09-09 16:45:39 -070058 return mac;
59 }
60
61 @Override
Ayaka Koshibea9c199f2014-09-16 16:21:40 -070062 public VlanId vlan() {
Ayaka Koshibe74a23922014-09-09 16:45:39 -070063 return vlan;
64 }
65
66 @Override
67 public HostLocation location() {
68 return location;
69 }
70
71 @Override
tom093340b2014-10-10 00:15:36 -070072 public IpPrefix ipAddress() {
73 return ip;
Ayaka Koshibe74a23922014-09-09 16:45:39 -070074 }
75
76 @Override
77 public String toString() {
78 return toStringHelper(this)
79 .add("mac", mac)
80 .add("vlan", vlan)
81 .add("location", location)
tom093340b2014-10-10 00:15:36 -070082 .add("ipAddress", ip)
Ayaka Koshibe74a23922014-09-09 16:45:39 -070083 .toString();
84 }
85
86}