Ayaka Koshibe

added default host constructs to API

Change-Id: I3ef3e08559c7c4d73d8e4aee693589ee0830ed85
package org.onlab.onos.net;
import static com.google.common.base.MoreObjects.toStringHelper;
import java.util.Collections;
import java.util.HashSet;
import java.util.Objects;
import java.util.Set;
import org.onlab.onos.net.provider.ProviderId;
import org.onlab.packet.IPv4;
import org.onlab.packet.MACAddress;
public class DefaultHost extends AbstractElement implements Host {
private final MACAddress mac;
private final short vlan;
private final HostLocation location;
private final Set<IPv4> ips;
protected DefaultHost(ProviderId providerId, ElementId id, MACAddress mac,
short vlan, HostLocation loc, Set<IPv4> ips) {
super(providerId, id);
this.mac = mac;
this.vlan = vlan;
this.location = loc;
this.ips = new HashSet<IPv4>(ips);
}
@Override
public HostId id() {
return (HostId) super.id();
}
@Override
public MACAddress mac() {
return mac;
}
@Override
public Set<IPv4> ipAddresses() {
return Collections.unmodifiableSet(ips);
}
@Override
public HostLocation location() {
return location;
}
@Override
public short vlan() {
return vlan;
}
@Override
public int hashCode() {
return Objects.hash(id, mac, vlan, location);
}
@Override
public boolean equals(Object obj) {
if (obj instanceof DefaultHost) {
final DefaultHost other = (DefaultHost) obj;
return Objects.equals(this.id, other.id) &&
Objects.equals(this.mac, other.mac) &&
Objects.equals(this.vlan, other.vlan) &&
Objects.equals(this.location, other.location);
}
return false;
}
@Override
public String toString() {
return toStringHelper(this)
.add("id", id)
.add("mac", mac)
.add("vlan", vlan)
.add("location", location)
.add("ipAddresses", ips)
.toString();
}
}
......@@ -25,6 +25,13 @@ public interface Host extends Element {
MACAddress mac();
/**
* Returns the VLAN ID tied to this host.
*
* @return VLAN ID value
*/
short 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
......
package org.onlab.onos.net.host;
import static com.google.common.base.MoreObjects.toStringHelper;
import java.util.Collections;
import java.util.HashSet;
import java.util.Set;
import org.onlab.onos.net.HostLocation;
import org.onlab.packet.IPv4;
import org.onlab.packet.MACAddress;
public class DefaultHostDescription implements HostDescription {
private final MACAddress mac;
private final short vlan;
private final HostLocation location;
private final Set<IPv4> ips;
public DefaultHostDescription(MACAddress mac, short vlan,
HostLocation loc, Set<IPv4> ips) {
this.mac = mac;
this.vlan = vlan;
this.location = loc;
this.ips = new HashSet<IPv4>(ips);
}
@Override
public MACAddress hwAddress() {
return mac;
}
@Override
public short vlan() {
return vlan;
}
@Override
public HostLocation location() {
return location;
}
@Override
public Set<IPv4> ipAddresses() {
return Collections.unmodifiableSet(ips);
}
@Override
public String toString() {
return toStringHelper(this)
.add("mac", mac)
.add("vlan", vlan)
.add("location", location)
.add("ipAddresses", ips)
.toString();
}
}
package org.onlab.onos.net.host;
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.MACAddress;
/**
* Information describing host and its location.
*/
public interface HostDescription {
public interface HostDescription extends Description {
// IP, MAC, VLAN-ID, HostLocation -> (ConnectionPoint + timestamp)
/**
* Returns the MAC address associated with this host (NIC).
*
* @return the MAC address of this host
*/
MACAddress hwAddress();
}
/**
* Returns the VLAN associated with this host.
*
* @return the VLAN ID value
*/
short vlan();
/**
* Returns the location of the host on the network edge.
*
* @return the network location
*/
HostLocation location();
/**
* Returns zero or more IP address(es) associated with this host's MAC.
*
* @return a set of IP addresses.
*/
Set<IPv4> ipAddresses();
}
......