blob: c6ba53fe33c25e8b370afae29e8468f6c18dd8e7 [file] [log] [blame]
tom80c0e5e2014-09-08 18:08:58 -07001package org.onlab.onos.net;
2
tom7869ad92014-09-09 14:32:08 -07003import org.onlab.packet.MACAddress;
Ayaka Koshibe3a25aec2014-09-12 11:52:53 -07004import org.onlab.packet.VLANID;
tom7869ad92014-09-09 14:32:08 -07005
tom80c0e5e2014-09-08 18:08:58 -07006import java.net.URI;
7
8/**
9 * Immutable representation of a host identity.
10 */
11public final class HostId extends ElementId {
12
13 // Public construction is prohibited
14 private HostId(URI uri) {
15 super(uri);
16 }
17
18 /**
19 * Creates a device id using the supplied URI.
20 *
21 * @param uri device URI
tom7869ad92014-09-09 14:32:08 -070022 * @return host identifier
tom80c0e5e2014-09-08 18:08:58 -070023 */
24 public static HostId hostId(URI uri) {
25 return new HostId(uri);
26 }
27
28 /**
29 * Creates a device id using the supplied URI string.
30 *
31 * @param string device URI string
tom7869ad92014-09-09 14:32:08 -070032 * @return host identifier
tom80c0e5e2014-09-08 18:08:58 -070033 */
34 public static HostId hostId(String string) {
tom568581d2014-09-08 20:13:36 -070035 return hostId(URI.create(string));
tom80c0e5e2014-09-08 18:08:58 -070036 }
37
tom7869ad92014-09-09 14:32:08 -070038 /**
39 * Creates a device id using the supplied MAC & VLAN ID.
40 *
41 * @param mac mac address
42 * @param vlanId vlan identifier
43 * @return host identifier
44 */
Ayaka Koshibe3a25aec2014-09-12 11:52:53 -070045 public static HostId hostId(MACAddress mac, VLANID vlanId) {
tom7869ad92014-09-09 14:32:08 -070046 // FIXME: use more efficient means of encoding
tomcbefa232014-09-16 14:17:20 -070047 return hostId("nic" + ":" + mac + "-" + vlanId);
tom7869ad92014-09-09 14:32:08 -070048 }
49
tomc370ebd2014-09-16 01:25:21 -070050 /**
51 * Creates a device id using the supplied MAC and default VLAN.
52 *
53 * @param mac mac address
54 * @return host identifier
55 */
56 public static HostId hostId(MACAddress mac) {
57 return hostId(mac, VLANID.vlanId(VLANID.UNTAGGED));
58 }
59
tom80c0e5e2014-09-08 18:08:58 -070060}