blob: f2c03032b455c1ae9419a210573137f2489920d6 [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
toma1d16b62014-10-02 23:45:11 -070013 private static final String NIC = "nic";
14
15 /**
16 * Represents either no host, or an unspecified host; used for creating
17 * open ingress/egress edge links.
18 */
19 public static final HostId NONE = hostId(NIC + ":none-0");
20
tom80c0e5e2014-09-08 18:08:58 -070021 // Public construction is prohibited
22 private HostId(URI uri) {
23 super(uri);
24 }
25
26 /**
27 * Creates a device id using the supplied URI.
28 *
29 * @param uri device URI
tom7869ad92014-09-09 14:32:08 -070030 * @return host identifier
tom80c0e5e2014-09-08 18:08:58 -070031 */
32 public static HostId hostId(URI uri) {
33 return new HostId(uri);
34 }
35
36 /**
37 * Creates a device id using the supplied URI string.
38 *
39 * @param string device URI string
tom7869ad92014-09-09 14:32:08 -070040 * @return host identifier
tom80c0e5e2014-09-08 18:08:58 -070041 */
42 public static HostId hostId(String string) {
tom568581d2014-09-08 20:13:36 -070043 return hostId(URI.create(string));
tom80c0e5e2014-09-08 18:08:58 -070044 }
45
tom7869ad92014-09-09 14:32:08 -070046 /**
47 * Creates a device id using the supplied MAC & VLAN ID.
48 *
49 * @param mac mac address
50 * @param vlanId vlan identifier
51 * @return host identifier
52 */
Ayaka Koshibea9c199f2014-09-16 16:21:40 -070053 public static HostId hostId(MacAddress mac, VlanId vlanId) {
toma1d16b62014-10-02 23:45:11 -070054 return hostId(NIC + ":" + mac + "-" + vlanId);
tom7869ad92014-09-09 14:32:08 -070055 }
56
tomc370ebd2014-09-16 01:25:21 -070057 /**
58 * Creates a device id using the supplied MAC and default VLAN.
59 *
60 * @param mac mac address
61 * @return host identifier
62 */
Ayaka Koshibea9c199f2014-09-16 16:21:40 -070063 public static HostId hostId(MacAddress mac) {
64 return hostId(mac, VlanId.vlanId(VlanId.UNTAGGED));
tomc370ebd2014-09-16 01:25:21 -070065 }
66
tom80c0e5e2014-09-08 18:08:58 -070067}