Ayaka Koshibe | 74a2392 | 2014-09-09 16:45:39 -0700 | [diff] [blame] | 1 | package org.onlab.onos.net; |
| 2 | |
tom | f5d85d4 | 2014-10-02 05:27:56 -0700 | [diff] [blame] | 3 | import org.onlab.onos.net.provider.ProviderId; |
| 4 | import org.onlab.packet.IpPrefix; |
| 5 | import org.onlab.packet.MacAddress; |
| 6 | import org.onlab.packet.VlanId; |
Ayaka Koshibe | 74a2392 | 2014-09-09 16:45:39 -0700 | [diff] [blame] | 7 | |
| 8 | import java.util.Collections; |
| 9 | import java.util.HashSet; |
| 10 | import java.util.Objects; |
| 11 | import java.util.Set; |
| 12 | |
tom | f5d85d4 | 2014-10-02 05:27:56 -0700 | [diff] [blame] | 13 | import static com.google.common.base.MoreObjects.toStringHelper; |
Ayaka Koshibe | 74a2392 | 2014-09-09 16:45:39 -0700 | [diff] [blame] | 14 | |
Ayaka Koshibe | 1c7b38e | 2014-09-11 13:09:51 -0700 | [diff] [blame] | 15 | /** |
| 16 | * A basic implementation of a Host. |
| 17 | */ |
Ayaka Koshibe | 74a2392 | 2014-09-09 16:45:39 -0700 | [diff] [blame] | 18 | public class DefaultHost extends AbstractElement implements Host { |
| 19 | |
Ayaka Koshibe | a9c199f | 2014-09-16 16:21:40 -0700 | [diff] [blame] | 20 | private final MacAddress mac; |
| 21 | private final VlanId vlan; |
Ayaka Koshibe | 74a2392 | 2014-09-09 16:45:39 -0700 | [diff] [blame] | 22 | private final HostLocation location; |
Yuta HIGUCHI | a263915 | 2014-10-14 15:08:10 -0700 | [diff] [blame] | 23 | // FIXME: should be IpAddress |
Ayaka Koshibe | 1d56fe4 | 2014-09-19 16:51:58 -0700 | [diff] [blame] | 24 | private final Set<IpPrefix> ips; |
Ayaka Koshibe | 74a2392 | 2014-09-09 16:45:39 -0700 | [diff] [blame] | 25 | |
tom | f5d85d4 | 2014-10-02 05:27:56 -0700 | [diff] [blame] | 26 | /** |
| 27 | * Creates an end-station host using the supplied information. |
| 28 | * |
| 29 | * @param providerId provider identity |
| 30 | * @param id host identifier |
| 31 | * @param mac host MAC address |
| 32 | * @param vlan host VLAN identifier |
| 33 | * @param location host location |
| 34 | * @param ips host IP addresses |
| 35 | * @param annotations optional key/value annotations |
| 36 | */ |
Ayaka Koshibe | a9c199f | 2014-09-16 16:21:40 -0700 | [diff] [blame] | 37 | public DefaultHost(ProviderId providerId, HostId id, MacAddress mac, |
tom | f5d85d4 | 2014-10-02 05:27:56 -0700 | [diff] [blame] | 38 | VlanId vlan, HostLocation location, Set<IpPrefix> ips, |
| 39 | Annotations... annotations) { |
| 40 | super(providerId, id, annotations); |
Ayaka Koshibe | 74a2392 | 2014-09-09 16:45:39 -0700 | [diff] [blame] | 41 | this.mac = mac; |
| 42 | this.vlan = vlan; |
tom | f5d85d4 | 2014-10-02 05:27:56 -0700 | [diff] [blame] | 43 | this.location = location; |
Ayaka Koshibe | 1d56fe4 | 2014-09-19 16:51:58 -0700 | [diff] [blame] | 44 | this.ips = new HashSet<IpPrefix>(ips); |
Ayaka Koshibe | 74a2392 | 2014-09-09 16:45:39 -0700 | [diff] [blame] | 45 | } |
| 46 | |
| 47 | @Override |
| 48 | public HostId id() { |
tom | 5a9383a | 2014-10-02 07:33:52 -0700 | [diff] [blame] | 49 | return (HostId) id; |
Ayaka Koshibe | 74a2392 | 2014-09-09 16:45:39 -0700 | [diff] [blame] | 50 | } |
| 51 | |
| 52 | @Override |
Ayaka Koshibe | a9c199f | 2014-09-16 16:21:40 -0700 | [diff] [blame] | 53 | public MacAddress mac() { |
Ayaka Koshibe | 74a2392 | 2014-09-09 16:45:39 -0700 | [diff] [blame] | 54 | return mac; |
| 55 | } |
| 56 | |
| 57 | @Override |
Ayaka Koshibe | 1d56fe4 | 2014-09-19 16:51:58 -0700 | [diff] [blame] | 58 | public Set<IpPrefix> ipAddresses() { |
Ayaka Koshibe | 74a2392 | 2014-09-09 16:45:39 -0700 | [diff] [blame] | 59 | return Collections.unmodifiableSet(ips); |
| 60 | } |
| 61 | |
| 62 | @Override |
| 63 | public HostLocation location() { |
| 64 | return location; |
| 65 | } |
| 66 | |
| 67 | @Override |
Ayaka Koshibe | a9c199f | 2014-09-16 16:21:40 -0700 | [diff] [blame] | 68 | public VlanId vlan() { |
Ayaka Koshibe | 74a2392 | 2014-09-09 16:45:39 -0700 | [diff] [blame] | 69 | return vlan; |
| 70 | } |
| 71 | |
| 72 | @Override |
| 73 | public int hashCode() { |
| 74 | return Objects.hash(id, mac, vlan, location); |
| 75 | } |
| 76 | |
| 77 | @Override |
| 78 | public boolean equals(Object obj) { |
tom | fc9a4ff | 2014-09-22 18:22:47 -0700 | [diff] [blame] | 79 | if (this == obj) { |
| 80 | return true; |
| 81 | } |
Ayaka Koshibe | 74a2392 | 2014-09-09 16:45:39 -0700 | [diff] [blame] | 82 | if (obj instanceof DefaultHost) { |
| 83 | final DefaultHost other = (DefaultHost) obj; |
| 84 | return Objects.equals(this.id, other.id) && |
| 85 | Objects.equals(this.mac, other.mac) && |
| 86 | Objects.equals(this.vlan, other.vlan) && |
| 87 | Objects.equals(this.location, other.location); |
| 88 | } |
| 89 | return false; |
| 90 | } |
| 91 | |
| 92 | @Override |
| 93 | public String toString() { |
| 94 | return toStringHelper(this) |
| 95 | .add("id", id) |
| 96 | .add("mac", mac) |
| 97 | .add("vlan", vlan) |
| 98 | .add("location", location) |
| 99 | .add("ipAddresses", ips) |
| 100 | .toString(); |
| 101 | } |
| 102 | |
| 103 | } |