mirror of
https://github.com/opennetworkinglab/onos.git
synced 2025-10-17 10:21:52 +02:00
Began implementation of the a host monitor
This commit is contained in:
parent
b79d641668
commit
fca736ce82
@ -6,7 +6,7 @@ import java.util.Collections;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
|
||||
import org.onlab.packet.IpAddress;
|
||||
import org.onlab.packet.IpPrefix;
|
||||
|
||||
/**
|
||||
* Default port implementation.
|
||||
@ -18,7 +18,7 @@ public class DefaultPort implements Port {
|
||||
private final boolean isEnabled;
|
||||
|
||||
// Attributes
|
||||
private final Set<IpAddress> ipAddresses;
|
||||
private final Set<IpPrefix> ipAddresses;
|
||||
|
||||
/**
|
||||
* Creates a network element attributed to the specified provider.
|
||||
@ -41,7 +41,7 @@ public class DefaultPort implements Port {
|
||||
* @param ipAddresses set of IP addresses assigned to the port
|
||||
*/
|
||||
public DefaultPort(Element element, PortNumber number,
|
||||
boolean isEnabled, Set<IpAddress> ipAddresses) {
|
||||
boolean isEnabled, Set<IpPrefix> ipAddresses) {
|
||||
this.element = element;
|
||||
this.number = number;
|
||||
this.isEnabled = isEnabled;
|
||||
@ -90,7 +90,7 @@ public class DefaultPort implements Port {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<IpAddress> ipAddresses() {
|
||||
public Set<IpPrefix> ipAddresses() {
|
||||
return ipAddresses;
|
||||
}
|
||||
|
||||
|
@ -2,7 +2,7 @@ package org.onlab.onos.net;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
import org.onlab.packet.IpAddress;
|
||||
import org.onlab.packet.IpPrefix;
|
||||
|
||||
/**
|
||||
* Abstraction of a network port.
|
||||
@ -39,5 +39,5 @@ public interface Port {
|
||||
* @return the set of IP addresses configured on the port. The set is empty
|
||||
* if no addresses are configured.
|
||||
*/
|
||||
Set<IpAddress> ipAddresses();
|
||||
Set<IpPrefix> ipAddresses();
|
||||
}
|
||||
|
@ -1,5 +1,7 @@
|
||||
package org.onlab.onos.net.host;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
import org.onlab.onos.net.ConnectPoint;
|
||||
import org.onlab.onos.net.DeviceId;
|
||||
import org.onlab.onos.net.Host;
|
||||
@ -8,8 +10,6 @@ import org.onlab.packet.IpPrefix;
|
||||
import org.onlab.packet.MacAddress;
|
||||
import org.onlab.packet.VlanId;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* Service for interacting with the inventory of end-station hosts.
|
||||
*/
|
||||
@ -81,6 +81,22 @@ public interface HostService {
|
||||
*/
|
||||
Set<Host> getConnectedHosts(DeviceId deviceId);
|
||||
|
||||
/**
|
||||
* Requests the host service to monitor hosts with the given IP address and
|
||||
* notify listeners of changes.
|
||||
*
|
||||
* @param ip IP address of the host to monitor
|
||||
*/
|
||||
void monitorIp(IpPrefix ip);
|
||||
|
||||
/**
|
||||
* Stops the host service from monitoring an IP address.
|
||||
*
|
||||
* @param ip IP address to stop monitoring
|
||||
*/
|
||||
// TODO clients can cancel other client's requests
|
||||
void stopMonitoringIp(IpPrefix ip);
|
||||
|
||||
/**
|
||||
* Adds the specified host listener.
|
||||
*
|
||||
|
@ -1,5 +1,7 @@
|
||||
package org.onlab.onos.net.host;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
import org.onlab.onos.net.ConnectPoint;
|
||||
import org.onlab.onos.net.DeviceId;
|
||||
import org.onlab.onos.net.Host;
|
||||
@ -8,8 +10,6 @@ import org.onlab.packet.IpPrefix;
|
||||
import org.onlab.packet.MacAddress;
|
||||
import org.onlab.packet.VlanId;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* Test adapter for host service.
|
||||
*/
|
||||
@ -54,6 +54,14 @@ public class HostServiceAdapter implements HostService {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void monitorIp(IpPrefix ip) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void stopMonitoringIp(IpPrefix ip) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addListener(HostListener listener) {
|
||||
}
|
||||
|
@ -1,5 +1,10 @@
|
||||
package org.onlab.onos.net.trivial.host.impl;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
import static org.slf4j.LoggerFactory.getLogger;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
import org.apache.felix.scr.annotations.Activate;
|
||||
import org.apache.felix.scr.annotations.Component;
|
||||
import org.apache.felix.scr.annotations.Deactivate;
|
||||
@ -28,11 +33,6 @@ import org.onlab.packet.MacAddress;
|
||||
import org.onlab.packet.VlanId;
|
||||
import org.slf4j.Logger;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
import static org.slf4j.LoggerFactory.getLogger;
|
||||
|
||||
/**
|
||||
* Provides basic implementation of the host SB & NB APIs.
|
||||
*/
|
||||
@ -117,6 +117,16 @@ public class SimpleHostManager
|
||||
return store.getConnectedHosts(deviceId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void monitorIp(IpPrefix ip) {
|
||||
// TODO pass through to SimpleHostMonitor
|
||||
}
|
||||
|
||||
@Override
|
||||
public void stopMonitoringIp(IpPrefix ip) {
|
||||
// TODO pass through to SimpleHostMonitor
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addListener(HostListener listener) {
|
||||
listenerRegistry.addListener(listener);
|
||||
|
@ -0,0 +1,108 @@
|
||||
package org.onlab.onos.net.trivial.host.impl;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import org.jboss.netty.util.Timeout;
|
||||
import org.jboss.netty.util.TimerTask;
|
||||
import org.onlab.onos.net.Device;
|
||||
import org.onlab.onos.net.Host;
|
||||
import org.onlab.onos.net.Port;
|
||||
import org.onlab.onos.net.device.DeviceService;
|
||||
import org.onlab.onos.net.host.HostProvider;
|
||||
import org.onlab.onos.net.host.HostService;
|
||||
import org.onlab.onos.net.packet.PacketProvider;
|
||||
import org.onlab.onos.net.topology.TopologyService;
|
||||
import org.onlab.packet.IpPrefix;
|
||||
import org.onlab.util.Timer;
|
||||
|
||||
public class SimpleHostMonitor implements TimerTask {
|
||||
|
||||
private final HostService hostService;
|
||||
private final TopologyService topologyService;
|
||||
private final DeviceService deviceService;
|
||||
private final HostProvider hostProvider;
|
||||
private final PacketProvider packetProvider;
|
||||
|
||||
private final Set<IpPrefix> monitoredAddresses;
|
||||
|
||||
private final long probeRate;
|
||||
|
||||
private Timeout timeout;
|
||||
|
||||
public SimpleHostMonitor(HostService hostService, TopologyService topologyService,
|
||||
DeviceService deviceService,
|
||||
HostProvider hostProvider, PacketProvider packetProvider) {
|
||||
this.hostService = hostService;
|
||||
this.topologyService = topologyService;
|
||||
this.deviceService = deviceService;
|
||||
this.hostProvider = hostProvider;
|
||||
this.packetProvider = packetProvider;
|
||||
|
||||
monitoredAddresses = new HashSet<>();
|
||||
|
||||
probeRate = 30000; // milliseconds
|
||||
|
||||
timeout = Timer.getTimer().newTimeout(this, 0, TimeUnit.MILLISECONDS);
|
||||
}
|
||||
|
||||
public void addMonitoringFor(IpPrefix ip) {
|
||||
monitoredAddresses.add(ip);
|
||||
}
|
||||
|
||||
public void stopMonitoring(IpPrefix ip) {
|
||||
monitoredAddresses.remove(ip);
|
||||
}
|
||||
|
||||
public void shutdown() {
|
||||
timeout.cancel();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run(Timeout timeout) throws Exception {
|
||||
for (IpPrefix ip : monitoredAddresses) {
|
||||
Set<Host> hosts = hostService.getHostsByIp(ip);
|
||||
|
||||
if (hosts.isEmpty()) {
|
||||
sendArpRequest(ip);
|
||||
} else {
|
||||
for (Host host : hosts) {
|
||||
hostProvider.triggerProbe(host);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
timeout = Timer.getTimer().newTimeout(this, probeRate, TimeUnit.MILLISECONDS);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sends an ARP request for the given IP address.
|
||||
*
|
||||
* @param targetIp IP address to ARP for
|
||||
*/
|
||||
private void sendArpRequest(IpPrefix targetIp) {
|
||||
// emit ARP packet out appropriate ports
|
||||
|
||||
// if ip in one of the configured (external) subnets
|
||||
// sent out that port
|
||||
// else (ip isn't in any configured subnet)
|
||||
// send out all non-external edge ports
|
||||
|
||||
for (Device device : deviceService.getDevices()) {
|
||||
for (Port port : deviceService.getPorts(device.id())) {
|
||||
for (IpPrefix ip : port.ipAddresses()) {
|
||||
if (ip.contains(targetIp)) {
|
||||
sendProbe(port, targetIp);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void sendProbe(Port port, IpPrefix targetIp) {
|
||||
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user