Ayaka Koshibe | 74a2392 | 2014-09-09 16:45:39 -0700 | [diff] [blame] | 1 | package org.onlab.onos.net.host; |
| 2 | |
tom | f5d85d4 | 2014-10-02 05:27:56 -0700 | [diff] [blame] | 3 | import org.onlab.onos.net.AbstractDescription; |
Ayaka Koshibe | 74a2392 | 2014-09-09 16:45:39 -0700 | [diff] [blame] | 4 | import org.onlab.onos.net.HostLocation; |
tom | f5d85d4 | 2014-10-02 05:27:56 -0700 | [diff] [blame] | 5 | import org.onlab.onos.net.SparseAnnotations; |
Ayaka Koshibe | 1d56fe4 | 2014-09-19 16:51:58 -0700 | [diff] [blame] | 6 | import org.onlab.packet.IpPrefix; |
Ayaka Koshibe | a9c199f | 2014-09-16 16:21:40 -0700 | [diff] [blame] | 7 | import org.onlab.packet.MacAddress; |
| 8 | import org.onlab.packet.VlanId; |
Ayaka Koshibe | 74a2392 | 2014-09-09 16:45:39 -0700 | [diff] [blame] | 9 | |
tom | 27ae0e6 | 2014-10-01 20:35:01 -0700 | [diff] [blame] | 10 | import static com.google.common.base.MoreObjects.toStringHelper; |
| 11 | |
| 12 | /** |
| 13 | * Default implementation of an immutable host description. |
| 14 | */ |
tom | f5d85d4 | 2014-10-02 05:27:56 -0700 | [diff] [blame] | 15 | public class DefaultHostDescription extends AbstractDescription |
tom | 27ae0e6 | 2014-10-01 20:35:01 -0700 | [diff] [blame] | 16 | implements HostDescription { |
Ayaka Koshibe | 74a2392 | 2014-09-09 16:45:39 -0700 | [diff] [blame] | 17 | |
Ayaka Koshibe | a9c199f | 2014-09-16 16:21:40 -0700 | [diff] [blame] | 18 | private final MacAddress mac; |
| 19 | private final VlanId vlan; |
Ayaka Koshibe | 74a2392 | 2014-09-09 16:45:39 -0700 | [diff] [blame] | 20 | private final HostLocation location; |
tom | 093340b | 2014-10-10 00:15:36 -0700 | [diff] [blame] | 21 | private final IpPrefix ip; |
Ayaka Koshibe | 74a2392 | 2014-09-09 16:45:39 -0700 | [diff] [blame] | 22 | |
tom | 27ae0e6 | 2014-10-01 20:35:01 -0700 | [diff] [blame] | 23 | /** |
| 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 Koshibe | a9c199f | 2014-09-16 16:21:40 -0700 | [diff] [blame] | 31 | public DefaultHostDescription(MacAddress mac, VlanId vlan, |
tom | 27ae0e6 | 2014-10-01 20:35:01 -0700 | [diff] [blame] | 32 | HostLocation location, |
tom | f5d85d4 | 2014-10-02 05:27:56 -0700 | [diff] [blame] | 33 | SparseAnnotations... annotations) { |
tom | 093340b | 2014-10-10 00:15:36 -0700 | [diff] [blame] | 34 | this(mac, vlan, location, null, annotations); |
Ayaka Koshibe | 1a10098 | 2014-09-13 19:32:19 -0700 | [diff] [blame] | 35 | } |
| 36 | |
tom | 27ae0e6 | 2014-10-01 20:35:01 -0700 | [diff] [blame] | 37 | /** |
| 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 |
tom | 093340b | 2014-10-10 00:15:36 -0700 | [diff] [blame] | 43 | * @param ip host IP address |
tom | 27ae0e6 | 2014-10-01 20:35:01 -0700 | [diff] [blame] | 44 | * @param annotations optional key/value annotations map |
| 45 | */ |
Ayaka Koshibe | a9c199f | 2014-09-16 16:21:40 -0700 | [diff] [blame] | 46 | public DefaultHostDescription(MacAddress mac, VlanId vlan, |
tom | 093340b | 2014-10-10 00:15:36 -0700 | [diff] [blame] | 47 | HostLocation location, IpPrefix ip, |
tom | f5d85d4 | 2014-10-02 05:27:56 -0700 | [diff] [blame] | 48 | SparseAnnotations... annotations) { |
tom | 27ae0e6 | 2014-10-01 20:35:01 -0700 | [diff] [blame] | 49 | super(annotations); |
Ayaka Koshibe | 74a2392 | 2014-09-09 16:45:39 -0700 | [diff] [blame] | 50 | this.mac = mac; |
| 51 | this.vlan = vlan; |
tom | 27ae0e6 | 2014-10-01 20:35:01 -0700 | [diff] [blame] | 52 | this.location = location; |
tom | 093340b | 2014-10-10 00:15:36 -0700 | [diff] [blame] | 53 | this.ip = ip; |
Ayaka Koshibe | 74a2392 | 2014-09-09 16:45:39 -0700 | [diff] [blame] | 54 | } |
| 55 | |
| 56 | @Override |
Ayaka Koshibe | a9c199f | 2014-09-16 16:21:40 -0700 | [diff] [blame] | 57 | public MacAddress hwAddress() { |
Ayaka Koshibe | 74a2392 | 2014-09-09 16:45:39 -0700 | [diff] [blame] | 58 | return mac; |
| 59 | } |
| 60 | |
| 61 | @Override |
Ayaka Koshibe | a9c199f | 2014-09-16 16:21:40 -0700 | [diff] [blame] | 62 | public VlanId vlan() { |
Ayaka Koshibe | 74a2392 | 2014-09-09 16:45:39 -0700 | [diff] [blame] | 63 | return vlan; |
| 64 | } |
| 65 | |
| 66 | @Override |
| 67 | public HostLocation location() { |
| 68 | return location; |
| 69 | } |
| 70 | |
| 71 | @Override |
tom | 093340b | 2014-10-10 00:15:36 -0700 | [diff] [blame] | 72 | public IpPrefix ipAddress() { |
| 73 | return ip; |
Ayaka Koshibe | 74a2392 | 2014-09-09 16:45:39 -0700 | [diff] [blame] | 74 | } |
| 75 | |
| 76 | @Override |
| 77 | public String toString() { |
| 78 | return toStringHelper(this) |
| 79 | .add("mac", mac) |
| 80 | .add("vlan", vlan) |
| 81 | .add("location", location) |
tom | 093340b | 2014-10-10 00:15:36 -0700 | [diff] [blame] | 82 | .add("ipAddress", ip) |
Ayaka Koshibe | 74a2392 | 2014-09-09 16:45:39 -0700 | [diff] [blame] | 83 | .toString(); |
| 84 | } |
| 85 | |
| 86 | } |