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 | |
| 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 |
tom | 7869ad9 | 2014-09-09 14:32:08 -0700 | [diff] [blame] | 22 | * @return host identifier |
tom | 80c0e5e | 2014-09-08 18:08:58 -0700 | [diff] [blame] | 23 | */ |
| 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 |
tom | 7869ad9 | 2014-09-09 14:32:08 -0700 | [diff] [blame] | 32 | * @return host identifier |
tom | 80c0e5e | 2014-09-08 18:08:58 -0700 | [diff] [blame] | 33 | */ |
| 34 | public static HostId hostId(String string) { |
tom | 568581d | 2014-09-08 20:13:36 -0700 | [diff] [blame] | 35 | return hostId(URI.create(string)); |
tom | 80c0e5e | 2014-09-08 18:08:58 -0700 | [diff] [blame] | 36 | } |
| 37 | |
tom | 7869ad9 | 2014-09-09 14:32:08 -0700 | [diff] [blame] | 38 | /** |
| 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 Koshibe | a9c199f | 2014-09-16 16:21:40 -0700 | [diff] [blame] | 45 | public static HostId hostId(MacAddress mac, VlanId vlanId) { |
tom | 7869ad9 | 2014-09-09 14:32:08 -0700 | [diff] [blame] | 46 | // FIXME: use more efficient means of encoding |
tom | cbefa23 | 2014-09-16 14:17:20 -0700 | [diff] [blame] | 47 | return hostId("nic" + ":" + mac + "-" + vlanId); |
tom | 7869ad9 | 2014-09-09 14:32:08 -0700 | [diff] [blame] | 48 | } |
| 49 | |
tom | c370ebd | 2014-09-16 01:25:21 -0700 | [diff] [blame] | 50 | /** |
| 51 | * Creates a device id using the supplied MAC and default VLAN. |
| 52 | * |
| 53 | * @param mac mac address |
| 54 | * @return host identifier |
| 55 | */ |
Ayaka Koshibe | a9c199f | 2014-09-16 16:21:40 -0700 | [diff] [blame] | 56 | public static HostId hostId(MacAddress mac) { |
| 57 | return hostId(mac, VlanId.vlanId(VlanId.UNTAGGED)); |
tom | c370ebd | 2014-09-16 01:25:21 -0700 | [diff] [blame] | 58 | } |
| 59 | |
tom | 80c0e5e | 2014-09-08 18:08:58 -0700 | [diff] [blame] | 60 | } |