blob: 1768f24a74c941091add359718183eda65c116c6 [file] [log] [blame]
tom80c0e5e2014-09-08 18:08:58 -07001package org.onlab.onos.net;
2
Ayaka Koshibea9c199f2014-09-16 16:21:40 -07003import org.onlab.packet.MacAddress;
4import 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 Koshibea9c199f2014-09-16 16:21:40 -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 */
Ayaka Koshibea9c199f2014-09-16 16:21:40 -070056 public static HostId hostId(MacAddress mac) {
57 return hostId(mac, VlanId.vlanId(VlanId.UNTAGGED));
tomc370ebd2014-09-16 01:25:21 -070058 }
59
tom80c0e5e2014-09-08 18:08:58 -070060}