blob: cb2e292e08051d0a523588cb4fec591c29693839 [file] [log] [blame]
Ayaka Koshibe74a23922014-09-09 16:45:39 -07001package org.onlab.onos.net;
2
tomf5d85d42014-10-02 05:27:56 -07003import org.onlab.onos.net.provider.ProviderId;
4import org.onlab.packet.IpPrefix;
5import org.onlab.packet.MacAddress;
6import org.onlab.packet.VlanId;
Ayaka Koshibe74a23922014-09-09 16:45:39 -07007
8import java.util.Collections;
9import java.util.HashSet;
10import java.util.Objects;
11import java.util.Set;
12
tomf5d85d42014-10-02 05:27:56 -070013import static com.google.common.base.MoreObjects.toStringHelper;
Ayaka Koshibe74a23922014-09-09 16:45:39 -070014
Ayaka Koshibe1c7b38e2014-09-11 13:09:51 -070015/**
16 * A basic implementation of a Host.
17 */
Ayaka Koshibe74a23922014-09-09 16:45:39 -070018public class DefaultHost extends AbstractElement implements Host {
19
Ayaka Koshibea9c199f2014-09-16 16:21:40 -070020 private final MacAddress mac;
21 private final VlanId vlan;
Ayaka Koshibe74a23922014-09-09 16:45:39 -070022 private final HostLocation location;
Yuta HIGUCHIa2639152014-10-14 15:08:10 -070023 // FIXME: should be IpAddress
Ayaka Koshibe1d56fe42014-09-19 16:51:58 -070024 private final Set<IpPrefix> ips;
Ayaka Koshibe74a23922014-09-09 16:45:39 -070025
tomf5d85d42014-10-02 05:27:56 -070026 /**
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 Koshibea9c199f2014-09-16 16:21:40 -070037 public DefaultHost(ProviderId providerId, HostId id, MacAddress mac,
tomf5d85d42014-10-02 05:27:56 -070038 VlanId vlan, HostLocation location, Set<IpPrefix> ips,
39 Annotations... annotations) {
40 super(providerId, id, annotations);
Ayaka Koshibe74a23922014-09-09 16:45:39 -070041 this.mac = mac;
42 this.vlan = vlan;
tomf5d85d42014-10-02 05:27:56 -070043 this.location = location;
Ayaka Koshibe1d56fe42014-09-19 16:51:58 -070044 this.ips = new HashSet<IpPrefix>(ips);
Ayaka Koshibe74a23922014-09-09 16:45:39 -070045 }
46
47 @Override
48 public HostId id() {
tom5a9383a2014-10-02 07:33:52 -070049 return (HostId) id;
Ayaka Koshibe74a23922014-09-09 16:45:39 -070050 }
51
52 @Override
Ayaka Koshibea9c199f2014-09-16 16:21:40 -070053 public MacAddress mac() {
Ayaka Koshibe74a23922014-09-09 16:45:39 -070054 return mac;
55 }
56
57 @Override
Ayaka Koshibe1d56fe42014-09-19 16:51:58 -070058 public Set<IpPrefix> ipAddresses() {
Ayaka Koshibe74a23922014-09-09 16:45:39 -070059 return Collections.unmodifiableSet(ips);
60 }
61
62 @Override
63 public HostLocation location() {
64 return location;
65 }
66
67 @Override
Ayaka Koshibea9c199f2014-09-16 16:21:40 -070068 public VlanId vlan() {
Ayaka Koshibe74a23922014-09-09 16:45:39 -070069 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) {
tomfc9a4ff2014-09-22 18:22:47 -070079 if (this == obj) {
80 return true;
81 }
Ayaka Koshibe74a23922014-09-09 16:45:39 -070082 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}