Ayaka Koshibe

tiny modifications to VLANID

Change-Id: Ib5b1adc2c147e23ce40ee35282c1fadc82d78111
package org.onlab.onos.net;
import org.onlab.packet.MACAddress;
import org.onlab.packet.VLANID;
import java.net.URI;
......@@ -42,7 +43,7 @@ public final class HostId extends ElementId {
* @return host identifier
*/
// FIXME: replace vlanId long with a rich data-type, e.g. VLanId or something like that
public static HostId hostId(MACAddress mac, long vlanId) {
public static HostId hostId(MACAddress mac, VLANID vlanId) {
// FIXME: use more efficient means of encoding
return hostId("nic" + ":" + mac + "/" + vlanId);
}
......
......@@ -12,7 +12,7 @@ public class IPAddress {
//lengths of address, in bytes
public static final int INET_LEN = 4;
public static final int INET6_LEN = 6;
public static final int INET6_LEN = 16;
protected Version version;
//does it make more sense to have a integral address?
......
......@@ -4,13 +4,28 @@ package org.onlab.packet;
* Representation of a VLAN ID.
*/
public class VLANID {
// A VLAN ID is 12 bits, short is close
private final short value;
private static final short NONE = 0;
// A VLAN ID is actually 12 bits of a VLAN tag.
private static final short MAX_VLAN = 4095;
public VLANID(short value) {
protected VLANID(short value) {
this.value = value;
}
public static VLANID vlanId() {
return new VLANID(NONE);
}
public static VLANID vlanId(short value) {
if (value >= MAX_VLAN) {
throw new IllegalArgumentException(
"value exceeds allowed maximum VLAN ID value (4095)");
}
return new VLANID(value);
}
public short toShort() {
return this.value;
}
......@@ -37,5 +52,10 @@ public class VLANID {
public int hashCode() {
return this.value;
}
@Override
public String toString() {
return String.valueOf(this.value);
}
}
......