tom | 80c0e5e | 2014-09-08 18:08:58 -0700 | [diff] [blame] | 1 | package org.onlab.onos.net; |
| 2 | |
Ayaka Koshibe | a9c199f | 2014-09-16 16:21:40 -0700 | [diff] [blame] | 3 | import org.onlab.packet.MacAddress; |
| 4 | import org.onlab.packet.VlanId; |
tom | 7869ad9 | 2014-09-09 14:32:08 -0700 | [diff] [blame] | 5 | |
tom | 80c0e5e | 2014-09-08 18:08:58 -0700 | [diff] [blame] | 6 | import java.net.URI; |
| 7 | |
| 8 | /** |
| 9 | * Immutable representation of a host identity. |
| 10 | */ |
| 11 | public final class HostId extends ElementId { |
| 12 | |
tom | a1d16b6 | 2014-10-02 23:45:11 -0700 | [diff] [blame^] | 13 | 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 | |
tom | 80c0e5e | 2014-09-08 18:08:58 -0700 | [diff] [blame] | 21 | // 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 |
tom | 7869ad9 | 2014-09-09 14:32:08 -0700 | [diff] [blame] | 30 | * @return host identifier |
tom | 80c0e5e | 2014-09-08 18:08:58 -0700 | [diff] [blame] | 31 | */ |
| 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 |
tom | 7869ad9 | 2014-09-09 14:32:08 -0700 | [diff] [blame] | 40 | * @return host identifier |
tom | 80c0e5e | 2014-09-08 18:08:58 -0700 | [diff] [blame] | 41 | */ |
| 42 | public static HostId hostId(String string) { |
tom | 568581d | 2014-09-08 20:13:36 -0700 | [diff] [blame] | 43 | return hostId(URI.create(string)); |
tom | 80c0e5e | 2014-09-08 18:08:58 -0700 | [diff] [blame] | 44 | } |
| 45 | |
tom | 7869ad9 | 2014-09-09 14:32:08 -0700 | [diff] [blame] | 46 | /** |
| 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 Koshibe | a9c199f | 2014-09-16 16:21:40 -0700 | [diff] [blame] | 53 | public static HostId hostId(MacAddress mac, VlanId vlanId) { |
tom | a1d16b6 | 2014-10-02 23:45:11 -0700 | [diff] [blame^] | 54 | return hostId(NIC + ":" + mac + "-" + vlanId); |
tom | 7869ad9 | 2014-09-09 14:32:08 -0700 | [diff] [blame] | 55 | } |
| 56 | |
tom | c370ebd | 2014-09-16 01:25:21 -0700 | [diff] [blame] | 57 | /** |
| 58 | * Creates a device id using the supplied MAC and default VLAN. |
| 59 | * |
| 60 | * @param mac mac address |
| 61 | * @return host identifier |
| 62 | */ |
Ayaka Koshibe | a9c199f | 2014-09-16 16:21:40 -0700 | [diff] [blame] | 63 | public static HostId hostId(MacAddress mac) { |
| 64 | return hostId(mac, VlanId.vlanId(VlanId.UNTAGGED)); |
tom | c370ebd | 2014-09-16 01:25:21 -0700 | [diff] [blame] | 65 | } |
| 66 | |
tom | 80c0e5e | 2014-09-08 18:08:58 -0700 | [diff] [blame] | 67 | } |