Yuta HIGUCHI
Committed by Gerrit Code Review

Construct GraphDescription with online/active Device/Link only

Change-Id: I9312c0c8ae190bf0200bd040823b6f7a3e7a15e1
......@@ -44,6 +44,14 @@ public interface DeviceService {
Iterable<Device> getDevices();
/**
* Returns an iterable collection of all devices
* currently available to the system.
*
* @return device collection
*/
Iterable<Device> getAvailableDevices();
/**
* Returns the device with the specified identifier.
*
* @param deviceId device identifier
......
......@@ -44,6 +44,15 @@ public interface DeviceStore extends Store<DeviceEvent, DeviceStoreDelegate> {
Iterable<Device> getDevices();
/**
* Returns an iterable collection of all devices currently available to the system.
*
* @return device collection
*/
Iterable<Device> getAvailableDevices();
/**
* Returns the device with the specified identifier.
*
* @param deviceId device identifier
......
......@@ -41,6 +41,13 @@ public interface LinkService {
Iterable<Link> getLinks();
/**
* Returns a collection of all active infrastructure links.
*
* @return all infrastructure links
*/
Iterable<Link> getActiveLinks();
/**
* Returns set of all infrastructure links leading to and from the
* specified device.
*
......
......@@ -21,6 +21,9 @@ import org.onlab.onos.net.MastershipRole;
import org.onlab.onos.net.Port;
import org.onlab.onos.net.PortNumber;
import com.google.common.base.Predicate;
import com.google.common.collect.FluentIterable;
import java.util.List;
/**
......@@ -38,6 +41,18 @@ public class DeviceServiceAdapter implements DeviceService {
}
@Override
public Iterable<Device> getAvailableDevices() {
return FluentIterable.from(getDevices())
.filter(new Predicate<Device>() {
@Override
public boolean apply(Device input) {
return isAvailable(input.id());
}
});
}
@Override
public Device getDevice(DeviceId deviceId) {
return null;
}
......
......@@ -20,6 +20,10 @@ import java.util.Set;
import org.onlab.onos.net.ConnectPoint;
import org.onlab.onos.net.DeviceId;
import org.onlab.onos.net.Link;
import org.onlab.onos.net.Link.State;
import com.google.common.base.Predicate;
import com.google.common.collect.FluentIterable;
/**
* Test adapter for link service.
......@@ -36,6 +40,18 @@ public class LinkServiceAdapter implements LinkService {
}
@Override
public Iterable<Link> getActiveLinks() {
return FluentIterable.from(getLinks())
.filter(new Predicate<Link>() {
@Override
public boolean apply(Link input) {
return input.state() == State.ACTIVE;
}
});
}
@Override
public Set<Link> getDeviceLinks(DeviceId deviceId) {
return null;
}
......
......@@ -149,6 +149,11 @@ public class DeviceManager
}
@Override
public Iterable<Device> getAvailableDevices() {
return store.getAvailableDevices();
}
@Override
public Device getDevice(DeviceId deviceId) {
checkNotNull(deviceId, DEVICE_ID_NULL);
return store.getDevice(deviceId);
......
......@@ -31,6 +31,7 @@ import org.onlab.onos.event.EventDeliveryService;
import org.onlab.onos.net.ConnectPoint;
import org.onlab.onos.net.DeviceId;
import org.onlab.onos.net.Link;
import org.onlab.onos.net.Link.State;
import org.onlab.onos.net.MastershipRole;
import org.onlab.onos.net.device.DeviceEvent;
import org.onlab.onos.net.device.DeviceListener;
......@@ -49,6 +50,8 @@ import org.onlab.onos.net.provider.AbstractProviderRegistry;
import org.onlab.onos.net.provider.AbstractProviderService;
import org.slf4j.Logger;
import com.google.common.base.Predicate;
import com.google.common.collect.FluentIterable;
import com.google.common.collect.Sets;
/**
......@@ -109,6 +112,18 @@ public class LinkManager
}
@Override
public Iterable<Link> getActiveLinks() {
return FluentIterable.from(getLinks())
.filter(new Predicate<Link>() {
@Override
public boolean apply(Link input) {
return input.state() == State.ACTIVE;
}
});
}
@Override
public Set<Link> getDeviceLinks(DeviceId deviceId) {
checkNotNull(deviceId, DEVICE_ID_NULL);
return Sets.union(store.getDeviceEgressLinks(deviceId),
......
......@@ -16,6 +16,7 @@
package org.onlab.onos.net.topology.impl;
import com.google.common.collect.ImmutableList;
import org.apache.felix.scr.annotations.Activate;
import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Deactivate;
......@@ -209,8 +210,8 @@ public class DefaultTopologyProvider extends AbstractProvider
if (isStarted) {
GraphDescription desc =
new DefaultGraphDescription(System.nanoTime(),
deviceService.getDevices(),
linkService.getLinks());
deviceService.getAvailableDevices(),
linkService.getActiveLinks());
providerService.topologyChanged(desc, reasons);
}
}
......
......@@ -20,6 +20,7 @@ import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Lists;
import com.google.common.collect.Sets;
import com.google.common.util.concurrent.ListenableFuture;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
......@@ -34,7 +35,7 @@ import org.onlab.onos.net.MastershipRole;
import org.onlab.onos.net.Port;
import org.onlab.onos.net.PortNumber;
import org.onlab.onos.net.device.DeviceListener;
import org.onlab.onos.net.device.DeviceService;
import org.onlab.onos.net.device.DeviceServiceAdapter;
import org.onlab.onos.net.flow.BatchOperation;
import org.onlab.onos.net.flow.CompletedBatchOperation;
import org.onlab.onos.net.flow.DefaultFlowEntry;
......@@ -461,7 +462,7 @@ public class FlowRuleManagerTest {
}
}
private static class TestDeviceService implements DeviceService {
private static class TestDeviceService extends DeviceServiceAdapter {
@Override
public int getDeviceCount() {
......
......@@ -39,7 +39,7 @@ import org.onlab.onos.net.MastershipRole;
import org.onlab.onos.net.Port;
import org.onlab.onos.net.PortNumber;
import org.onlab.onos.net.device.DeviceListener;
import org.onlab.onos.net.device.DeviceService;
import org.onlab.onos.net.device.DeviceServiceAdapter;
import org.onlab.onos.net.flow.instructions.Instruction;
import org.onlab.onos.net.flow.instructions.Instructions.OutputInstruction;
import org.onlab.onos.net.host.HostProvider;
......@@ -189,7 +189,7 @@ public class HostMonitorTest {
}
}
class TestDeviceService implements DeviceService {
class TestDeviceService extends DeviceServiceAdapter {
List<Device> devices = Lists.newArrayList();
Multimap<DeviceId, Port> devicePorts = HashMultimap.create();
......
......@@ -154,6 +154,11 @@ public class DefaultTopologyProviderTest {
device("e"), device("f"));
}
@Override
public Iterable<Device> getAvailableDevices() {
return getDevices();
}
void post(DeviceEvent event) {
eventDispatcher.post(event);
}
......@@ -174,6 +179,11 @@ public class DefaultTopologyProviderTest {
link("e", 1, "f", 1), link("f", 1, "e", 1));
}
@Override
public Iterable<Link> getActiveLinks() {
return getLinks();
}
void post(LinkEvent event) {
eventDispatcher.post(event);
}
......
......@@ -16,6 +16,7 @@
package org.onlab.onos.store.device.impl;
import com.google.common.base.Function;
import com.google.common.base.Predicate;
import com.google.common.collect.FluentIterable;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.Maps;
......@@ -231,6 +232,18 @@ public class GossipDeviceStore
}
@Override
public Iterable<Device> getAvailableDevices() {
return FluentIterable.from(getDevices())
.filter(new Predicate<Device>() {
@Override
public boolean apply(Device input) {
return isAvailable(input.id());
}
});
}
@Override
public Device getDevice(DeviceId deviceId) {
return devices.get(deviceId);
}
......
......@@ -15,6 +15,7 @@
*/
package org.onlab.onos.store.trivial.impl;
import com.google.common.base.Predicate;
import com.google.common.collect.FluentIterable;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.Maps;
......@@ -123,6 +124,18 @@ public class SimpleDeviceStore
}
@Override
public Iterable<Device> getAvailableDevices() {
return FluentIterable.from(getDevices())
.filter(new Predicate<Device>() {
@Override
public boolean apply(Device input) {
return isAvailable(input.id());
}
});
}
@Override
public Device getDevice(DeviceId deviceId) {
return devices.get(deviceId);
}
......
......@@ -32,4 +32,12 @@
<description>ONOS LLDP Link Discovery</description>
<dependencies>
<dependency>
<groupId>org.onlab.onos</groupId>
<artifactId>onos-api</artifactId>
<classifier>tests</classifier>
<scope>test</scope>
</dependency>
</dependencies>
</project>
......
......@@ -37,7 +37,7 @@ import org.onlab.onos.net.Port;
import org.onlab.onos.net.PortNumber;
import org.onlab.onos.net.device.DeviceEvent;
import org.onlab.onos.net.device.DeviceListener;
import org.onlab.onos.net.device.DeviceService;
import org.onlab.onos.net.device.DeviceServiceAdapter;
import org.onlab.onos.net.flow.TrafficTreatment;
import org.onlab.onos.net.link.LinkDescription;
import org.onlab.onos.net.link.LinkProvider;
......@@ -376,7 +376,7 @@ public class LLDPLinkProviderTest {
}
}
private class TestDeviceService implements DeviceService {
private class TestDeviceService extends DeviceServiceAdapter {
private Map<DeviceId, Device> devices = new HashMap<>();
private final ArrayListMultimap<DeviceId, Port> ports =
......@@ -408,7 +408,7 @@ public class LLDPLinkProviderTest {
@Override
public Iterable<Device> getDevices() {
return Collections.EMPTY_LIST;
return Collections.emptyList();
}
@Override
......