Ayaka Koshibe

added VLANID construct

Change-Id: Ia58abb268d52639215f289052bbf8802992f98a6
......@@ -10,6 +10,7 @@ import java.util.Set;
import org.onlab.onos.net.provider.ProviderId;
import org.onlab.packet.IPAddress;
import org.onlab.packet.MACAddress;
import org.onlab.packet.VLANID;
/**
* A basic implementation of a Host.
......@@ -17,12 +18,12 @@ import org.onlab.packet.MACAddress;
public class DefaultHost extends AbstractElement implements Host {
private final MACAddress mac;
private final short vlan;
private final VLANID vlan;
private final HostLocation location;
private final Set<IPAddress> ips;
public DefaultHost(ProviderId providerId, ElementId id, MACAddress mac,
short vlan, HostLocation loc, Set<IPAddress> ips) {
public DefaultHost(ProviderId providerId, HostId id, MACAddress mac,
VLANID vlan, HostLocation loc, Set<IPAddress> ips) {
super(providerId, id);
this.mac = mac;
this.vlan = vlan;
......@@ -51,7 +52,7 @@ public class DefaultHost extends AbstractElement implements Host {
}
@Override
public short vlan() {
public VLANID vlan() {
return vlan;
}
......
......@@ -2,6 +2,7 @@ package org.onlab.onos.net;
import org.onlab.packet.IPAddress;
import org.onlab.packet.MACAddress;
import org.onlab.packet.VLANID;
import java.util.Set;
......@@ -30,7 +31,7 @@ public interface Host extends Element {
*
* @return VLAN ID value
*/
short vlan();
VLANID vlan();
/**
* Returns set of IP addresses currently bound to the host MAC address.
......
......@@ -8,17 +8,18 @@ import java.util.Set;
import org.onlab.onos.net.HostLocation;
import org.onlab.packet.IPAddress;
import org.onlab.packet.MACAddress;
import org.onlab.packet.VLANID;
import com.google.common.collect.ImmutableSet;
public class DefaultHostDescription implements HostDescription {
private final MACAddress mac;
private final short vlan;
private final VLANID vlan;
private final HostLocation location;
private final Set<IPAddress> ips;
public DefaultHostDescription(MACAddress mac, short vlan,
public DefaultHostDescription(MACAddress mac, VLANID vlan,
HostLocation loc, Set<IPAddress> ips) {
this.mac = mac;
this.vlan = vlan;
......@@ -32,7 +33,7 @@ public class DefaultHostDescription implements HostDescription {
}
@Override
public short vlan() {
public VLANID vlan() {
return vlan;
}
......
......@@ -6,6 +6,7 @@ import org.onlab.onos.net.Description;
import org.onlab.onos.net.HostLocation;
import org.onlab.packet.IPAddress;
import org.onlab.packet.MACAddress;
import org.onlab.packet.VLANID;
/**
* Information describing host and its location.
......@@ -24,7 +25,7 @@ public interface HostDescription extends Description {
*
* @return the VLAN ID value
*/
short vlan();
VLANID vlan();
/**
* Returns the location of the host on the network edge.
......
......@@ -6,6 +6,7 @@ import org.onlab.onos.net.Host;
import org.onlab.onos.net.HostId;
import org.onlab.packet.IPAddress;
import org.onlab.packet.MACAddress;
import org.onlab.packet.VLANID;
import java.util.Set;
......@@ -43,7 +44,7 @@ public interface HostService {
* @return set of hosts in the given vlan id
*/
// FIXME: change long to VLanId
Set<Host> getHostsByVlan(long vlanId);
Set<Host> getHostsByVlan(VLANID vlanId);
/**
* Returns the set of hosts that have the specified MAC address.
......
......@@ -23,6 +23,7 @@ import org.onlab.onos.net.provider.AbstractProviderRegistry;
import org.onlab.onos.net.provider.AbstractProviderService;
import org.onlab.packet.IPAddress;
import org.onlab.packet.MACAddress;
import org.onlab.packet.VLANID;
import org.slf4j.Logger;
import java.util.Set;
......@@ -85,7 +86,7 @@ public class SimpleHostManager
}
@Override
public Set<Host> getHostsByVlan(long vlanId) {
public Set<Host> getHostsByVlan(VLANID vlanId) {
return store.getHosts(vlanId);
}
......
......@@ -21,6 +21,7 @@ import org.onlab.onos.net.host.HostEvent;
import org.onlab.onos.net.provider.ProviderId;
import org.onlab.packet.IPAddress;
import org.onlab.packet.MACAddress;
import org.onlab.packet.VLANID;
import com.google.common.collect.HashMultimap;
import com.google.common.collect.ImmutableSet;
......@@ -149,10 +150,10 @@ public class SimpleHostStore {
* @param vlanId vlan id
* @return set of hosts in the vlan
*/
Set<Host> getHosts(long vlanId) {
Set<Host> getHosts(VLANID vlanId) {
Set<Host> vlanset = new HashSet<Host>();
for (Host h : hosts.values()) {
if (h.vlan() == vlanId) {
if (h.vlan().equals(vlanId)) {
vlanset.add(h);
}
}
......
......@@ -10,7 +10,7 @@ public class IPAddress {
//IP Versions
public enum Version { INET, INET6 };
//lengths of addresses, in bytes
//lengths of address, in bytes
public static final int INET_LEN = 4;
public static final int INET6_LEN = 6;
......
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;
public VLANID(short value) {
this.value = value;
}
public short toShort() {
return this.value;
}
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj instanceof VLANID) {
return true;
}
VLANID other = (VLANID) obj;
if (this.value == other.value) {
return true;
}
return false;
}
@Override
public int hashCode() {
return this.value;
}
}