Jonathan Hart

Changed PortAddress API to allow multiple IP addresses per port

......@@ -4,8 +4,6 @@ import java.util.Set;
import org.onlab.onos.net.ConnectPoint;
import org.onlab.onos.net.HostId;
import org.onlab.packet.IpAddress;
import org.onlab.packet.MacAddress;
/**
* Service for administering the inventory of end-station hosts.
......@@ -20,26 +18,34 @@ public interface HostAdminService {
void removeHost(HostId hostId);
/**
* Binds an IP address and optional MAC address to the given connection
* point.
* Binds IP and MAC addresses to the given connection point.
* <p/>
* This method will overwrite any previously held address information for
* the connection point.
* The addresses are added to the set of addresses already bound to the
* connection point. If any of the fields in addresses is null, no change
* is made to the corresponding addresses in the store.
* {@link #unbindAddressesFromPort(PortAddresses)} must be use to unbind
* addresses that have previously been bound.
*
* @param addresses address object containing addresses to add and the port
* to add them to
*/
void bindAddressesToPort(PortAddresses addresses);
/**
* Removes the addresses contained in the given PortAddresses object from
* the set of addresses bound to the port.
*
* @param ip the IP address to bind to the connection point. This parameter
* is mandatory and cannot be null.
* @param mac the optional MAC address to bind to the connection point. Can
* be set to null if no MAC address needs to be bound.
* @param connectPoint the connection point to bind the addresses to
* @param portAddresses set of addresses to remove and port to remove them
* from
*/
void bindAddressesToPort(IpAddress ip, MacAddress mac, ConnectPoint connectPoint);
void unbindAddressesFromPort(PortAddresses portAddresses);
/**
* Removes all address information for the given connection point.
*
* @param connectPoint the connection point to remove address information
*/
void unbindAddressesFromPort(ConnectPoint connectPoint);
void clearAddresses(ConnectPoint connectPoint);
/**
* Returns the addresses information for all connection points.
......
......@@ -99,19 +99,28 @@ public interface HostStore {
Set<Host> getConnectedHosts(DeviceId deviceId);
/**
* Updates the address information for a given port.
* Updates the address information for a given port. The given address
* information is added to any previously held information for the port.
*
* @param addresses the port and address information
*/
void updateAddressBindings(PortAddresses addresses);
/**
* Removes the given addresses from the set of address information held for
* a port.
*
* @param addresses the port and address information
*/
void removeAddressBindings(PortAddresses addresses);
/**
* Removes any previously stored address information for a given connection
* point.
*
* @param connectPoint the connection point
*/
void removeAddressBindings(ConnectPoint connectPoint);
void clearAddressBindings(ConnectPoint connectPoint);
/**
* Returns the address bindings stored for all connection points.
......
package org.onlab.onos.net.host;
import java.util.HashSet;
import java.util.Set;
import org.onlab.onos.net.ConnectPoint;
import org.onlab.packet.IpAddress;
import org.onlab.packet.IpPrefix;
import org.onlab.packet.MacAddress;
/**
* Represents address information bound to a port.
*/
public interface PortAddresses {
public class PortAddresses {
private final ConnectPoint connectPoint;
private final Set<IpPrefix> ipAddresses;
private final MacAddress macAddress;
/**
* Constructs a PortAddress object for the given connection point, with a
* set of IP addresses and a MAC address.
* <p/>
* Both address parameters are optional and can be set to null.
*
* @param connectPoint the connection point these addresses are for
* @param ips a set of IP addresses
* @param mac a MAC address
*/
public PortAddresses(ConnectPoint connectPoint,
Set<IpPrefix> ips, MacAddress mac) {
this.connectPoint = connectPoint;
this.ipAddresses = (ips == null) ? null : new HashSet<>(ips);
this.macAddress = mac;
}
/**
* Returns the connection point this address information is bound to.
*
* @return the connection point
*/
ConnectPoint connectPoint();
public ConnectPoint connectPoint() {
return connectPoint;
}
/**
* Returns the IP address bound to the port.
* Returns the set of IP addresses.
*
* @return the IP address
* @return the IP addresses
*/
IpAddress ip();
public Set<IpPrefix> ips() {
return ipAddresses;
}
/**
* Returns the MAC address bound to the port.
* Returns the MAC address.
*
* @return the MAC address if one is bound, otherwise null
* @return the MAC address
*/
MacAddress mac();
public MacAddress mac() {
return macAddress;
}
}
......
package org.onlab.onos.net.host.impl;
import org.onlab.onos.net.ConnectPoint;
import org.onlab.onos.net.host.PortAddresses;
import org.onlab.packet.IpAddress;
import org.onlab.packet.MacAddress;
public class DefaultPortAddresses implements PortAddresses {
private final ConnectPoint connectPoint;
private final IpAddress ipAddress;
private final MacAddress macAddress;
public DefaultPortAddresses(ConnectPoint connectPoint,
IpAddress ip, MacAddress mac) {
this.connectPoint = connectPoint;
this.ipAddress = ip;
this.macAddress = mac;
}
@Override
public ConnectPoint connectPoint() {
return connectPoint;
}
@Override
public IpAddress ip() {
return ipAddress;
}
@Override
public MacAddress mac() {
return macAddress;
}
}
......@@ -155,14 +155,18 @@ public class HostManager
}
@Override
public void bindAddressesToPort(IpAddress ip, MacAddress mac,
ConnectPoint connectPoint) {
store.updateAddressBindings(new DefaultPortAddresses(connectPoint, ip, mac));
public void bindAddressesToPort(PortAddresses addresses) {
store.updateAddressBindings(addresses);
}
@Override
public void unbindAddressesFromPort(ConnectPoint connectPoint) {
store.removeAddressBindings(connectPoint);
public void unbindAddressesFromPort(PortAddresses portAddresses) {
store.removeAddressBindings(portAddresses);
}
@Override
public void clearAddresses(ConnectPoint connectPoint) {
store.clearAddressBindings(connectPoint);
}
@Override
......
......@@ -128,9 +128,11 @@ public class HostMonitor implements TimerTask {
ConnectPoint cp = new ConnectPoint(device.id(), port.number());
PortAddresses addresses = hostStore.getAddressBindingsForPort(cp);
if (addresses.ip().contains(targetIp)) {
sendProbe(device.id(), port, addresses, targetIp);
}
/*for (IpPrefix prefix : addresses.ips()) {
if (prefix.contains(targetIp)) {
sendProbe(device.id(), port, addresses, targetIp);
}
}*/
}
}
......@@ -173,7 +175,7 @@ public class HostMonitor implements TimerTask {
}
arp.setSenderHardwareAddress(sourceMacAddress)
.setSenderProtocolAddress(portAddresses.ip().toOctets())
//TODO .setSenderProtocolAddress(portAddresses.ips().toOctets())
.setTargetHardwareAddress(ZERO_MAC_ADDRESS)
.setTargetProtocolAddress(targetIp.toOctets());
......
......@@ -198,12 +198,19 @@ public class SimpleHostStore implements HostStore {
@Override
public void updateAddressBindings(PortAddresses addresses) {
portAddresses.put(addresses.connectPoint(), addresses);
// TODO portAddresses.put(addresses.connectPoint(), addresses);
}
@Override
public void removeAddressBindings(ConnectPoint connectPoint) {
portAddresses.remove(connectPoint);
public void removeAddressBindings(PortAddresses addresses) {
// TODO Auto-generated method stub
}
@Override
public void clearAddressBindings(ConnectPoint connectPoint) {
// TODO Auto-generated method stub
}
@Override
......