Merge branch 'master' of ssh://gerrit.onlab.us:29418/onos-next
Showing
4 changed files
with
183 additions
and
3 deletions
1 | +package org.onlab.onos.net; | ||
2 | + | ||
3 | +import static com.google.common.base.MoreObjects.toStringHelper; | ||
4 | + | ||
5 | +import java.util.Collections; | ||
6 | +import java.util.HashSet; | ||
7 | +import java.util.Objects; | ||
8 | +import java.util.Set; | ||
9 | + | ||
10 | +import org.onlab.onos.net.provider.ProviderId; | ||
11 | +import org.onlab.packet.IPv4; | ||
12 | +import org.onlab.packet.MACAddress; | ||
13 | + | ||
14 | +public class DefaultHost extends AbstractElement implements Host { | ||
15 | + | ||
16 | + private final MACAddress mac; | ||
17 | + private final short vlan; | ||
18 | + private final HostLocation location; | ||
19 | + private final Set<IPv4> ips; | ||
20 | + | ||
21 | + protected DefaultHost(ProviderId providerId, ElementId id, MACAddress mac, | ||
22 | + short vlan, HostLocation loc, Set<IPv4> ips) { | ||
23 | + super(providerId, id); | ||
24 | + this.mac = mac; | ||
25 | + this.vlan = vlan; | ||
26 | + this.location = loc; | ||
27 | + this.ips = new HashSet<IPv4>(ips); | ||
28 | + } | ||
29 | + | ||
30 | + @Override | ||
31 | + public HostId id() { | ||
32 | + return (HostId) super.id(); | ||
33 | + } | ||
34 | + | ||
35 | + @Override | ||
36 | + public MACAddress mac() { | ||
37 | + return mac; | ||
38 | + } | ||
39 | + | ||
40 | + @Override | ||
41 | + public Set<IPv4> ipAddresses() { | ||
42 | + return Collections.unmodifiableSet(ips); | ||
43 | + } | ||
44 | + | ||
45 | + @Override | ||
46 | + public HostLocation location() { | ||
47 | + return location; | ||
48 | + } | ||
49 | + | ||
50 | + @Override | ||
51 | + public short vlan() { | ||
52 | + return vlan; | ||
53 | + } | ||
54 | + | ||
55 | + @Override | ||
56 | + public int hashCode() { | ||
57 | + return Objects.hash(id, mac, vlan, location); | ||
58 | + } | ||
59 | + | ||
60 | + @Override | ||
61 | + public boolean equals(Object obj) { | ||
62 | + if (obj instanceof DefaultHost) { | ||
63 | + final DefaultHost other = (DefaultHost) obj; | ||
64 | + return Objects.equals(this.id, other.id) && | ||
65 | + Objects.equals(this.mac, other.mac) && | ||
66 | + Objects.equals(this.vlan, other.vlan) && | ||
67 | + Objects.equals(this.location, other.location); | ||
68 | + } | ||
69 | + return false; | ||
70 | + } | ||
71 | + | ||
72 | + @Override | ||
73 | + public String toString() { | ||
74 | + return toStringHelper(this) | ||
75 | + .add("id", id) | ||
76 | + .add("mac", mac) | ||
77 | + .add("vlan", vlan) | ||
78 | + .add("location", location) | ||
79 | + .add("ipAddresses", ips) | ||
80 | + .toString(); | ||
81 | + } | ||
82 | + | ||
83 | +} |
... | @@ -25,6 +25,13 @@ public interface Host extends Element { | ... | @@ -25,6 +25,13 @@ public interface Host extends Element { |
25 | MACAddress mac(); | 25 | MACAddress mac(); |
26 | 26 | ||
27 | /** | 27 | /** |
28 | + * Returns the VLAN ID tied to this host. | ||
29 | + * | ||
30 | + * @return VLAN ID value | ||
31 | + */ | ||
32 | + short vlan(); | ||
33 | + | ||
34 | + /** | ||
28 | * Returns set of IP addresses currently bound to the host MAC address. | 35 | * Returns set of IP addresses currently bound to the host MAC address. |
29 | * | 36 | * |
30 | * @return set of IP addresses; empty if no IP address is bound | 37 | * @return set of IP addresses; empty if no IP address is bound | ... | ... |
1 | +package org.onlab.onos.net.host; | ||
2 | + | ||
3 | +import static com.google.common.base.MoreObjects.toStringHelper; | ||
4 | + | ||
5 | +import java.util.Collections; | ||
6 | +import java.util.HashSet; | ||
7 | +import java.util.Set; | ||
8 | + | ||
9 | +import org.onlab.onos.net.HostLocation; | ||
10 | +import org.onlab.packet.IPv4; | ||
11 | +import org.onlab.packet.MACAddress; | ||
12 | + | ||
13 | +public class DefaultHostDescription implements HostDescription { | ||
14 | + | ||
15 | + private final MACAddress mac; | ||
16 | + private final short vlan; | ||
17 | + private final HostLocation location; | ||
18 | + private final Set<IPv4> ips; | ||
19 | + | ||
20 | + public DefaultHostDescription(MACAddress mac, short vlan, | ||
21 | + HostLocation loc, Set<IPv4> ips) { | ||
22 | + this.mac = mac; | ||
23 | + this.vlan = vlan; | ||
24 | + this.location = loc; | ||
25 | + this.ips = new HashSet<IPv4>(ips); | ||
26 | + } | ||
27 | + | ||
28 | + @Override | ||
29 | + public MACAddress hwAddress() { | ||
30 | + return mac; | ||
31 | + } | ||
32 | + | ||
33 | + @Override | ||
34 | + public short vlan() { | ||
35 | + return vlan; | ||
36 | + } | ||
37 | + | ||
38 | + @Override | ||
39 | + public HostLocation location() { | ||
40 | + return location; | ||
41 | + } | ||
42 | + | ||
43 | + @Override | ||
44 | + public Set<IPv4> ipAddresses() { | ||
45 | + return Collections.unmodifiableSet(ips); | ||
46 | + } | ||
47 | + | ||
48 | + @Override | ||
49 | + public String toString() { | ||
50 | + return toStringHelper(this) | ||
51 | + .add("mac", mac) | ||
52 | + .add("vlan", vlan) | ||
53 | + .add("location", location) | ||
54 | + .add("ipAddresses", ips) | ||
55 | + .toString(); | ||
56 | + } | ||
57 | + | ||
58 | +} |
1 | package org.onlab.onos.net.host; | 1 | package org.onlab.onos.net.host; |
2 | 2 | ||
3 | +import java.util.Set; | ||
4 | + | ||
5 | +import org.onlab.onos.net.Description; | ||
6 | +import org.onlab.onos.net.HostLocation; | ||
7 | +import org.onlab.packet.IPv4; | ||
8 | +import org.onlab.packet.MACAddress; | ||
9 | + | ||
3 | /** | 10 | /** |
4 | * Information describing host and its location. | 11 | * Information describing host and its location. |
5 | */ | 12 | */ |
6 | -public interface HostDescription { | 13 | +public interface HostDescription extends Description { |
7 | 14 | ||
8 | - // IP, MAC, VLAN-ID, HostLocation -> (ConnectionPoint + timestamp) | 15 | + /** |
16 | + * Returns the MAC address associated with this host (NIC). | ||
17 | + * | ||
18 | + * @return the MAC address of this host | ||
19 | + */ | ||
20 | + MACAddress hwAddress(); | ||
9 | 21 | ||
10 | -} | 22 | + /** |
23 | + * Returns the VLAN associated with this host. | ||
24 | + * | ||
25 | + * @return the VLAN ID value | ||
26 | + */ | ||
27 | + short vlan(); | ||
11 | 28 | ||
29 | + /** | ||
30 | + * Returns the location of the host on the network edge. | ||
31 | + * | ||
32 | + * @return the network location | ||
33 | + */ | ||
34 | + HostLocation location(); | ||
35 | + | ||
36 | + /** | ||
37 | + * Returns zero or more IP address(es) associated with this host's MAC. | ||
38 | + * | ||
39 | + * @return a set of IP addresses. | ||
40 | + */ | ||
41 | + Set<IPv4> ipAddresses(); | ||
42 | + | ||
43 | +} | ... | ... |
-
Please register or login to post a comment