tom | 80c0e5e | 2014-09-08 18:08:58 -0700 | [diff] [blame] | 1 | package org.onlab.onos.net; |
| 2 | |
tom | 7869ad9 | 2014-09-09 14:32:08 -0700 | [diff] [blame] | 3 | import org.onlab.packet.MACAddress; |
| 4 | |
tom | 80c0e5e | 2014-09-08 18:08:58 -0700 | [diff] [blame] | 5 | import java.net.URI; |
| 6 | |
| 7 | /** |
| 8 | * Immutable representation of a host identity. |
| 9 | */ |
| 10 | public final class HostId extends ElementId { |
| 11 | |
| 12 | // Public construction is prohibited |
| 13 | private HostId(URI uri) { |
| 14 | super(uri); |
| 15 | } |
| 16 | |
| 17 | /** |
| 18 | * Creates a device id using the supplied URI. |
| 19 | * |
| 20 | * @param uri device URI |
tom | 7869ad9 | 2014-09-09 14:32:08 -0700 | [diff] [blame] | 21 | * @return host identifier |
tom | 80c0e5e | 2014-09-08 18:08:58 -0700 | [diff] [blame] | 22 | */ |
| 23 | public static HostId hostId(URI uri) { |
| 24 | return new HostId(uri); |
| 25 | } |
| 26 | |
| 27 | /** |
| 28 | * Creates a device id using the supplied URI string. |
| 29 | * |
| 30 | * @param string device URI string |
tom | 7869ad9 | 2014-09-09 14:32:08 -0700 | [diff] [blame] | 31 | * @return host identifier |
tom | 80c0e5e | 2014-09-08 18:08:58 -0700 | [diff] [blame] | 32 | */ |
| 33 | public static HostId hostId(String string) { |
tom | 568581d | 2014-09-08 20:13:36 -0700 | [diff] [blame] | 34 | return hostId(URI.create(string)); |
tom | 80c0e5e | 2014-09-08 18:08:58 -0700 | [diff] [blame] | 35 | } |
| 36 | |
tom | 7869ad9 | 2014-09-09 14:32:08 -0700 | [diff] [blame] | 37 | /** |
| 38 | * Creates a device id using the supplied MAC & VLAN ID. |
| 39 | * |
| 40 | * @param mac mac address |
| 41 | * @param vlanId vlan identifier |
| 42 | * @return host identifier |
| 43 | */ |
| 44 | // FIXME: replace vlanId long with a rich data-type, e.g. VLanId or something like that |
| 45 | public static HostId hostId(MACAddress mac, long vlanId) { |
| 46 | // FIXME: use more efficient means of encoding |
| 47 | return hostId("nic" + ":" + mac + "/" + vlanId); |
| 48 | } |
| 49 | |
tom | 80c0e5e | 2014-09-08 18:08:58 -0700 | [diff] [blame] | 50 | } |