tom

Merge branch 'master' of ssh://gerrit.onlab.us:29418/onos-next

......@@ -8,23 +8,27 @@ import java.util.Objects;
import java.util.Set;
import org.onlab.onos.net.provider.ProviderId;
import org.onlab.packet.IPv4;
import org.onlab.packet.IPAddress;
import org.onlab.packet.MACAddress;
import org.onlab.packet.VLANID;
/**
* A basic implementation of a Host.
*/
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<IPv4> ips;
private final Set<IPAddress> ips;
public DefaultHost(ProviderId providerId, ElementId id, MACAddress mac,
short vlan, HostLocation loc, Set<IPv4> 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;
this.location = loc;
this.ips = new HashSet<IPv4>(ips);
this.ips = new HashSet<IPAddress>(ips);
}
@Override
......@@ -38,7 +42,7 @@ public class DefaultHost extends AbstractElement implements Host {
}
@Override
public Set<IPv4> ipAddresses() {
public Set<IPAddress> ipAddresses() {
return Collections.unmodifiableSet(ips);
}
......@@ -48,7 +52,7 @@ public class DefaultHost extends AbstractElement implements Host {
}
@Override
public short vlan() {
public VLANID vlan() {
return vlan;
}
......
package org.onlab.onos.net;
import org.onlab.packet.IPv4;
import org.onlab.packet.IPAddress;
import org.onlab.packet.MACAddress;
import org.onlab.packet.VLANID;
import java.util.Set;
......@@ -15,6 +16,7 @@ public interface Host extends Element {
*
* @return host id
*/
@Override
HostId id();
/**
......@@ -29,14 +31,14 @@ 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.
*
* @return set of IP addresses; empty if no IP address is bound
*/
Set<IPv4> ipAddresses();
Set<IPAddress> ipAddresses();
/**
* Returns the most recent host location where the host attaches to the
......
......@@ -6,24 +6,25 @@ import java.util.HashSet;
import java.util.Set;
import org.onlab.onos.net.HostLocation;
import org.onlab.packet.IPv4;
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<IPv4> ips;
private final Set<IPAddress> ips;
public DefaultHostDescription(MACAddress mac, short vlan,
HostLocation loc, Set<IPv4> ips) {
public DefaultHostDescription(MACAddress mac, VLANID vlan,
HostLocation loc, Set<IPAddress> ips) {
this.mac = mac;
this.vlan = vlan;
this.location = loc;
this.ips = new HashSet<IPv4>(ips);
this.ips = new HashSet<IPAddress>(ips);
}
@Override
......@@ -32,7 +33,7 @@ public class DefaultHostDescription implements HostDescription {
}
@Override
public short vlan() {
public VLANID vlan() {
return vlan;
}
......@@ -42,7 +43,7 @@ public class DefaultHostDescription implements HostDescription {
}
@Override
public Set<IPv4> ipAddresses() {
public Set<IPAddress> ipAddresses() {
return ImmutableSet.copyOf(ips);
}
......
......@@ -4,8 +4,9 @@ import java.util.Set;
import org.onlab.onos.net.Description;
import org.onlab.onos.net.HostLocation;
import org.onlab.packet.IPv4;
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.
......@@ -38,6 +39,6 @@ public interface HostDescription extends Description {
*
* @return a set of IP addresses.
*/
Set<IPv4> ipAddresses();
Set<IPAddress> ipAddresses();
}
......
......@@ -4,8 +4,9 @@ import org.onlab.onos.net.ConnectPoint;
import org.onlab.onos.net.DeviceId;
import org.onlab.onos.net.Host;
import org.onlab.onos.net.HostId;
import org.onlab.packet.IPv4;
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.
......@@ -59,7 +60,7 @@ public interface HostService {
* @param ip ip address
* @return set of hosts with the given IP
*/
Set<Host> getHostsByIp(IPv4 ip);
Set<Host> getHostsByIp(IPAddress ip);
/**
* Returns the set of hosts whose most recent location is the specified
......
......@@ -21,8 +21,9 @@ import org.onlab.onos.net.host.HostProviderService;
import org.onlab.onos.net.host.HostService;
import org.onlab.onos.net.provider.AbstractProviderRegistry;
import org.onlab.onos.net.provider.AbstractProviderService;
import org.onlab.packet.IPv4;
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);
}
......@@ -96,7 +97,7 @@ public class SimpleHostManager
}
@Override
public Set<Host> getHostsByIp(IPv4 ip) {
public Set<Host> getHostsByIp(IPAddress ip) {
checkNotNull(ip, "IP address cannot be null");
return store.getHosts(ip);
}
......
......@@ -19,8 +19,9 @@ import org.onlab.onos.net.HostId;
import org.onlab.onos.net.host.HostDescription;
import org.onlab.onos.net.host.HostEvent;
import org.onlab.onos.net.provider.ProviderId;
import org.onlab.packet.IPv4;
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);
}
}
......@@ -181,7 +182,7 @@ public class SimpleHostStore {
* @param ip ip address
* @return set of hosts with the given IP
*/
Set<Host> getHosts(IPv4 ip) {
Set<Host> getHosts(IPAddress ip) {
Set<Host> ipset = new HashSet<>();
for (Host h : hosts.values()) {
if (h.ipAddresses().contains(ip)) {
......
package org.onlab.packet;
import java.util.Arrays;
/**
* A class representing an IPv4 address.
*/
public class IPAddress {
//IP Versions
public enum Version { INET, INET6 };
//lengths of address, in bytes
public static final int INET_LEN = 4;
public static final int INET6_LEN = 6;
protected Version version;
//does it make more sense to have a integral address?
protected byte[] octets;
protected IPAddress(Version ver, byte[] octets) {
this.version = ver;
this.octets = Arrays.copyOf(octets, INET_LEN);
}
/**
* Converts a byte array into an IP address.
*
* @param address a byte array
* @return an IP address
*/
public static IPAddress valueOf(byte [] address) {
return new IPAddress(Version.INET, address);
}
/**
* Converts an integer into an IPv4 address.
*
* @param address an integer representing an IP value
* @return an IP address
*/
public static IPAddress valueOf(int address) {
byte [] bytes = new byte [] {
(byte) ((address >> 24) & 0xff),
(byte) ((address >> 16) & 0xff),
(byte) ((address >> 8) & 0xff),
(byte) ((address >> 0) & 0xff)
};
return new IPAddress(Version.INET, bytes);
}
/**
* Converts a string in dotted-decimal notation (x.x.x.x) into
* an IPv4 address.
*
* @param address a string representing an IP address, e.g. "10.0.0.1"
* @return an IP address
*/
public static IPAddress valueOf(String address) {
final String [] parts = address.split(".");
if (parts.length != INET_LEN) {
throw new IllegalArgumentException("Malformed IP address string; "
+ "Addres must have four decimal values separated by dots (.)");
}
final byte [] bytes = new byte[INET_LEN];
for (int i = 0; i < INET_LEN; i++) {
bytes[i] = Byte.parseByte(parts[i], 10);
}
return new IPAddress(Version.INET, bytes);
}
/**
* Returns the IP version of this address.
*
* @return the version
*/
public Version version() {
return this.version;
}
/**
* Returns the IP address as a byte array.
*
* @return a byte array
*/
public byte [] toOctets() {
return Arrays.copyOf(this.octets, INET_LEN);
}
public int toInt() {
int address =
((octets[0] << 24) |
(octets[1] << 16) |
(octets[2] << 8) |
(octets[3] << 0));
return address;
}
@Override
public String toString() {
final StringBuilder builder = new StringBuilder();
for (final byte b : this.octets) {
if (builder.length() > 0) {
builder.append(".");
}
builder.append(String.format("%02d", b));
}
return builder.toString();
}
@Override
public int hashCode() {
return octets.hashCode();
}
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj instanceof IPAddress) {
IPAddress other = (IPAddress) obj;
if (!(this.version.equals(other.version))) {
return false;
}
if (!(Arrays.equals(this.octets, other.octets))) {
return false;
}
}
return true;
}
}
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;
}
}