Merge branch 'master' of ssh://gerrit.onlab.us:29418/onos-next
Showing
3 changed files
with
25 additions
and
4 deletions
1 | package org.onlab.onos.net; | 1 | package org.onlab.onos.net; |
2 | 2 | ||
3 | import org.onlab.packet.MACAddress; | 3 | import org.onlab.packet.MACAddress; |
4 | +import org.onlab.packet.VLANID; | ||
4 | 5 | ||
5 | import java.net.URI; | 6 | import java.net.URI; |
6 | 7 | ||
... | @@ -42,7 +43,7 @@ public final class HostId extends ElementId { | ... | @@ -42,7 +43,7 @@ public final class HostId extends ElementId { |
42 | * @return host identifier | 43 | * @return host identifier |
43 | */ | 44 | */ |
44 | // FIXME: replace vlanId long with a rich data-type, e.g. VLanId or something like that | 45 | // 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 | + public static HostId hostId(MACAddress mac, VLANID vlanId) { |
46 | // FIXME: use more efficient means of encoding | 47 | // FIXME: use more efficient means of encoding |
47 | return hostId("nic" + ":" + mac + "/" + vlanId); | 48 | return hostId("nic" + ":" + mac + "/" + vlanId); |
48 | } | 49 | } | ... | ... |
... | @@ -12,7 +12,7 @@ public class IPAddress { | ... | @@ -12,7 +12,7 @@ public class IPAddress { |
12 | 12 | ||
13 | //lengths of address, in bytes | 13 | //lengths of address, in bytes |
14 | public static final int INET_LEN = 4; | 14 | public static final int INET_LEN = 4; |
15 | - public static final int INET6_LEN = 6; | 15 | + public static final int INET6_LEN = 16; |
16 | 16 | ||
17 | protected Version version; | 17 | protected Version version; |
18 | //does it make more sense to have a integral address? | 18 | //does it make more sense to have a integral address? | ... | ... |
... | @@ -4,13 +4,28 @@ package org.onlab.packet; | ... | @@ -4,13 +4,28 @@ package org.onlab.packet; |
4 | * Representation of a VLAN ID. | 4 | * Representation of a VLAN ID. |
5 | */ | 5 | */ |
6 | public class VLANID { | 6 | public class VLANID { |
7 | - // A VLAN ID is 12 bits, short is close | 7 | + |
8 | private final short value; | 8 | private final short value; |
9 | + private static final short NONE = 0; | ||
10 | + // A VLAN ID is actually 12 bits of a VLAN tag. | ||
11 | + private static final short MAX_VLAN = 4095; | ||
9 | 12 | ||
10 | - public VLANID(short value) { | 13 | + protected VLANID(short value) { |
11 | this.value = value; | 14 | this.value = value; |
12 | } | 15 | } |
13 | 16 | ||
17 | + public static VLANID vlanId() { | ||
18 | + return new VLANID(NONE); | ||
19 | + } | ||
20 | + | ||
21 | + public static VLANID vlanId(short value) { | ||
22 | + if (value >= MAX_VLAN) { | ||
23 | + throw new IllegalArgumentException( | ||
24 | + "value exceeds allowed maximum VLAN ID value (4095)"); | ||
25 | + } | ||
26 | + return new VLANID(value); | ||
27 | + } | ||
28 | + | ||
14 | public short toShort() { | 29 | public short toShort() { |
15 | return this.value; | 30 | return this.value; |
16 | } | 31 | } |
... | @@ -37,5 +52,10 @@ public class VLANID { | ... | @@ -37,5 +52,10 @@ public class VLANID { |
37 | public int hashCode() { | 52 | public int hashCode() { |
38 | return this.value; | 53 | return this.value; |
39 | } | 54 | } |
55 | + | ||
56 | + @Override | ||
57 | + public String toString() { | ||
58 | + return String.valueOf(this.value); | ||
59 | + } | ||
40 | } | 60 | } |
41 | 61 | ... | ... |
-
Please register or login to post a comment