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 { ...@@ -44,6 +44,14 @@ public interface DeviceService {
44 Iterable<Device> getDevices(); 44 Iterable<Device> getDevices();
45 45
46 /** 46 /**
47 + * Returns an iterable collection of all devices
48 + * currently available to the system.
49 + *
50 + * @return device collection
51 + */
52 + Iterable<Device> getAvailableDevices();
53 +
54 + /**
47 * Returns the device with the specified identifier. 55 * Returns the device with the specified identifier.
48 * 56 *
49 * @param deviceId device identifier 57 * @param deviceId device identifier
......
...@@ -44,6 +44,15 @@ public interface DeviceStore extends Store<DeviceEvent, DeviceStoreDelegate> { ...@@ -44,6 +44,15 @@ public interface DeviceStore extends Store<DeviceEvent, DeviceStoreDelegate> {
44 Iterable<Device> getDevices(); 44 Iterable<Device> getDevices();
45 45
46 /** 46 /**
47 + * Returns an iterable collection of all devices currently available to the system.
48 + *
49 + * @return device collection
50 + */
51 + Iterable<Device> getAvailableDevices();
52 +
53 +
54 +
55 + /**
47 * Returns the device with the specified identifier. 56 * Returns the device with the specified identifier.
48 * 57 *
49 * @param deviceId device identifier 58 * @param deviceId device identifier
......
...@@ -41,6 +41,13 @@ public interface LinkService { ...@@ -41,6 +41,13 @@ public interface LinkService {
41 Iterable<Link> getLinks(); 41 Iterable<Link> getLinks();
42 42
43 /** 43 /**
44 + * Returns a collection of all active infrastructure links.
45 + *
46 + * @return all infrastructure links
47 + */
48 + Iterable<Link> getActiveLinks();
49 +
50 + /**
44 * Returns set of all infrastructure links leading to and from the 51 * Returns set of all infrastructure links leading to and from the
45 * specified device. 52 * specified device.
46 * 53 *
......
...@@ -21,6 +21,9 @@ import org.onlab.onos.net.MastershipRole; ...@@ -21,6 +21,9 @@ import org.onlab.onos.net.MastershipRole;
21 import org.onlab.onos.net.Port; 21 import org.onlab.onos.net.Port;
22 import org.onlab.onos.net.PortNumber; 22 import org.onlab.onos.net.PortNumber;
23 23
24 +import com.google.common.base.Predicate;
25 +import com.google.common.collect.FluentIterable;
26 +
24 import java.util.List; 27 import java.util.List;
25 28
26 /** 29 /**
...@@ -38,6 +41,18 @@ public class DeviceServiceAdapter implements DeviceService { ...@@ -38,6 +41,18 @@ public class DeviceServiceAdapter implements DeviceService {
38 } 41 }
39 42
40 @Override 43 @Override
44 + public Iterable<Device> getAvailableDevices() {
45 + return FluentIterable.from(getDevices())
46 + .filter(new Predicate<Device>() {
47 +
48 + @Override
49 + public boolean apply(Device input) {
50 + return isAvailable(input.id());
51 + }
52 + });
53 + }
54 +
55 + @Override
41 public Device getDevice(DeviceId deviceId) { 56 public Device getDevice(DeviceId deviceId) {
42 return null; 57 return null;
43 } 58 }
......
...@@ -20,6 +20,10 @@ import java.util.Set; ...@@ -20,6 +20,10 @@ import java.util.Set;
20 import org.onlab.onos.net.ConnectPoint; 20 import org.onlab.onos.net.ConnectPoint;
21 import org.onlab.onos.net.DeviceId; 21 import org.onlab.onos.net.DeviceId;
22 import org.onlab.onos.net.Link; 22 import org.onlab.onos.net.Link;
23 +import org.onlab.onos.net.Link.State;
24 +
25 +import com.google.common.base.Predicate;
26 +import com.google.common.collect.FluentIterable;
23 27
24 /** 28 /**
25 * Test adapter for link service. 29 * Test adapter for link service.
...@@ -36,6 +40,18 @@ public class LinkServiceAdapter implements LinkService { ...@@ -36,6 +40,18 @@ public class LinkServiceAdapter implements LinkService {
36 } 40 }
37 41
38 @Override 42 @Override
43 + public Iterable<Link> getActiveLinks() {
44 + return FluentIterable.from(getLinks())
45 + .filter(new Predicate<Link>() {
46 +
47 + @Override
48 + public boolean apply(Link input) {
49 + return input.state() == State.ACTIVE;
50 + }
51 + });
52 + }
53 +
54 + @Override
39 public Set<Link> getDeviceLinks(DeviceId deviceId) { 55 public Set<Link> getDeviceLinks(DeviceId deviceId) {
40 return null; 56 return null;
41 } 57 }
......
...@@ -149,6 +149,11 @@ public class DeviceManager ...@@ -149,6 +149,11 @@ public class DeviceManager
149 } 149 }
150 150
151 @Override 151 @Override
152 + public Iterable<Device> getAvailableDevices() {
153 + return store.getAvailableDevices();
154 + }
155 +
156 + @Override
152 public Device getDevice(DeviceId deviceId) { 157 public Device getDevice(DeviceId deviceId) {
153 checkNotNull(deviceId, DEVICE_ID_NULL); 158 checkNotNull(deviceId, DEVICE_ID_NULL);
154 return store.getDevice(deviceId); 159 return store.getDevice(deviceId);
......
...@@ -31,6 +31,7 @@ import org.onlab.onos.event.EventDeliveryService; ...@@ -31,6 +31,7 @@ import org.onlab.onos.event.EventDeliveryService;
31 import org.onlab.onos.net.ConnectPoint; 31 import org.onlab.onos.net.ConnectPoint;
32 import org.onlab.onos.net.DeviceId; 32 import org.onlab.onos.net.DeviceId;
33 import org.onlab.onos.net.Link; 33 import org.onlab.onos.net.Link;
34 +import org.onlab.onos.net.Link.State;
34 import org.onlab.onos.net.MastershipRole; 35 import org.onlab.onos.net.MastershipRole;
35 import org.onlab.onos.net.device.DeviceEvent; 36 import org.onlab.onos.net.device.DeviceEvent;
36 import org.onlab.onos.net.device.DeviceListener; 37 import org.onlab.onos.net.device.DeviceListener;
...@@ -49,6 +50,8 @@ import org.onlab.onos.net.provider.AbstractProviderRegistry; ...@@ -49,6 +50,8 @@ import org.onlab.onos.net.provider.AbstractProviderRegistry;
49 import org.onlab.onos.net.provider.AbstractProviderService; 50 import org.onlab.onos.net.provider.AbstractProviderService;
50 import org.slf4j.Logger; 51 import org.slf4j.Logger;
51 52
53 +import com.google.common.base.Predicate;
54 +import com.google.common.collect.FluentIterable;
52 import com.google.common.collect.Sets; 55 import com.google.common.collect.Sets;
53 56
54 /** 57 /**
...@@ -109,6 +112,18 @@ public class LinkManager ...@@ -109,6 +112,18 @@ public class LinkManager
109 } 112 }
110 113
111 @Override 114 @Override
115 + public Iterable<Link> getActiveLinks() {
116 + return FluentIterable.from(getLinks())
117 + .filter(new Predicate<Link>() {
118 +
119 + @Override
120 + public boolean apply(Link input) {
121 + return input.state() == State.ACTIVE;
122 + }
123 + });
124 + }
125 +
126 + @Override
112 public Set<Link> getDeviceLinks(DeviceId deviceId) { 127 public Set<Link> getDeviceLinks(DeviceId deviceId) {
113 checkNotNull(deviceId, DEVICE_ID_NULL); 128 checkNotNull(deviceId, DEVICE_ID_NULL);
114 return Sets.union(store.getDeviceEgressLinks(deviceId), 129 return Sets.union(store.getDeviceEgressLinks(deviceId),
......
...@@ -16,6 +16,7 @@ ...@@ -16,6 +16,7 @@
16 package org.onlab.onos.net.topology.impl; 16 package org.onlab.onos.net.topology.impl;
17 17
18 import com.google.common.collect.ImmutableList; 18 import com.google.common.collect.ImmutableList;
19 +
19 import org.apache.felix.scr.annotations.Activate; 20 import org.apache.felix.scr.annotations.Activate;
20 import org.apache.felix.scr.annotations.Component; 21 import org.apache.felix.scr.annotations.Component;
21 import org.apache.felix.scr.annotations.Deactivate; 22 import org.apache.felix.scr.annotations.Deactivate;
...@@ -209,8 +210,8 @@ public class DefaultTopologyProvider extends AbstractProvider ...@@ -209,8 +210,8 @@ public class DefaultTopologyProvider extends AbstractProvider
209 if (isStarted) { 210 if (isStarted) {
210 GraphDescription desc = 211 GraphDescription desc =
211 new DefaultGraphDescription(System.nanoTime(), 212 new DefaultGraphDescription(System.nanoTime(),
212 - deviceService.getDevices(), 213 + deviceService.getAvailableDevices(),
213 - linkService.getLinks()); 214 + linkService.getActiveLinks());
214 providerService.topologyChanged(desc, reasons); 215 providerService.topologyChanged(desc, reasons);
215 } 216 }
216 } 217 }
......
...@@ -20,6 +20,7 @@ import com.google.common.collect.ImmutableMap; ...@@ -20,6 +20,7 @@ import com.google.common.collect.ImmutableMap;
20 import com.google.common.collect.Lists; 20 import com.google.common.collect.Lists;
21 import com.google.common.collect.Sets; 21 import com.google.common.collect.Sets;
22 import com.google.common.util.concurrent.ListenableFuture; 22 import com.google.common.util.concurrent.ListenableFuture;
23 +
23 import org.junit.After; 24 import org.junit.After;
24 import org.junit.Before; 25 import org.junit.Before;
25 import org.junit.Test; 26 import org.junit.Test;
...@@ -34,7 +35,7 @@ import org.onlab.onos.net.MastershipRole; ...@@ -34,7 +35,7 @@ import org.onlab.onos.net.MastershipRole;
34 import org.onlab.onos.net.Port; 35 import org.onlab.onos.net.Port;
35 import org.onlab.onos.net.PortNumber; 36 import org.onlab.onos.net.PortNumber;
36 import org.onlab.onos.net.device.DeviceListener; 37 import org.onlab.onos.net.device.DeviceListener;
37 -import org.onlab.onos.net.device.DeviceService; 38 +import org.onlab.onos.net.device.DeviceServiceAdapter;
38 import org.onlab.onos.net.flow.BatchOperation; 39 import org.onlab.onos.net.flow.BatchOperation;
39 import org.onlab.onos.net.flow.CompletedBatchOperation; 40 import org.onlab.onos.net.flow.CompletedBatchOperation;
40 import org.onlab.onos.net.flow.DefaultFlowEntry; 41 import org.onlab.onos.net.flow.DefaultFlowEntry;
...@@ -461,7 +462,7 @@ public class FlowRuleManagerTest { ...@@ -461,7 +462,7 @@ public class FlowRuleManagerTest {
461 } 462 }
462 } 463 }
463 464
464 - private static class TestDeviceService implements DeviceService { 465 + private static class TestDeviceService extends DeviceServiceAdapter {
465 466
466 @Override 467 @Override
467 public int getDeviceCount() { 468 public int getDeviceCount() {
......
...@@ -39,7 +39,7 @@ import org.onlab.onos.net.MastershipRole; ...@@ -39,7 +39,7 @@ import org.onlab.onos.net.MastershipRole;
39 import org.onlab.onos.net.Port; 39 import org.onlab.onos.net.Port;
40 import org.onlab.onos.net.PortNumber; 40 import org.onlab.onos.net.PortNumber;
41 import org.onlab.onos.net.device.DeviceListener; 41 import org.onlab.onos.net.device.DeviceListener;
42 -import org.onlab.onos.net.device.DeviceService; 42 +import org.onlab.onos.net.device.DeviceServiceAdapter;
43 import org.onlab.onos.net.flow.instructions.Instruction; 43 import org.onlab.onos.net.flow.instructions.Instruction;
44 import org.onlab.onos.net.flow.instructions.Instructions.OutputInstruction; 44 import org.onlab.onos.net.flow.instructions.Instructions.OutputInstruction;
45 import org.onlab.onos.net.host.HostProvider; 45 import org.onlab.onos.net.host.HostProvider;
...@@ -189,7 +189,7 @@ public class HostMonitorTest { ...@@ -189,7 +189,7 @@ public class HostMonitorTest {
189 } 189 }
190 } 190 }
191 191
192 - class TestDeviceService implements DeviceService { 192 + class TestDeviceService extends DeviceServiceAdapter {
193 193
194 List<Device> devices = Lists.newArrayList(); 194 List<Device> devices = Lists.newArrayList();
195 Multimap<DeviceId, Port> devicePorts = HashMultimap.create(); 195 Multimap<DeviceId, Port> devicePorts = HashMultimap.create();
......
...@@ -154,6 +154,11 @@ public class DefaultTopologyProviderTest { ...@@ -154,6 +154,11 @@ public class DefaultTopologyProviderTest {
154 device("e"), device("f")); 154 device("e"), device("f"));
155 } 155 }
156 156
157 + @Override
158 + public Iterable<Device> getAvailableDevices() {
159 + return getDevices();
160 + }
161 +
157 void post(DeviceEvent event) { 162 void post(DeviceEvent event) {
158 eventDispatcher.post(event); 163 eventDispatcher.post(event);
159 } 164 }
...@@ -174,6 +179,11 @@ public class DefaultTopologyProviderTest { ...@@ -174,6 +179,11 @@ public class DefaultTopologyProviderTest {
174 link("e", 1, "f", 1), link("f", 1, "e", 1)); 179 link("e", 1, "f", 1), link("f", 1, "e", 1));
175 } 180 }
176 181
182 + @Override
183 + public Iterable<Link> getActiveLinks() {
184 + return getLinks();
185 + }
186 +
177 void post(LinkEvent event) { 187 void post(LinkEvent event) {
178 eventDispatcher.post(event); 188 eventDispatcher.post(event);
179 } 189 }
......
...@@ -16,6 +16,7 @@ ...@@ -16,6 +16,7 @@
16 package org.onlab.onos.store.device.impl; 16 package org.onlab.onos.store.device.impl;
17 17
18 import com.google.common.base.Function; 18 import com.google.common.base.Function;
19 +import com.google.common.base.Predicate;
19 import com.google.common.collect.FluentIterable; 20 import com.google.common.collect.FluentIterable;
20 import com.google.common.collect.ImmutableList; 21 import com.google.common.collect.ImmutableList;
21 import com.google.common.collect.Maps; 22 import com.google.common.collect.Maps;
...@@ -231,6 +232,18 @@ public class GossipDeviceStore ...@@ -231,6 +232,18 @@ public class GossipDeviceStore
231 } 232 }
232 233
233 @Override 234 @Override
235 + public Iterable<Device> getAvailableDevices() {
236 + return FluentIterable.from(getDevices())
237 + .filter(new Predicate<Device>() {
238 +
239 + @Override
240 + public boolean apply(Device input) {
241 + return isAvailable(input.id());
242 + }
243 + });
244 + }
245 +
246 + @Override
234 public Device getDevice(DeviceId deviceId) { 247 public Device getDevice(DeviceId deviceId) {
235 return devices.get(deviceId); 248 return devices.get(deviceId);
236 } 249 }
......
...@@ -15,6 +15,7 @@ ...@@ -15,6 +15,7 @@
15 */ 15 */
16 package org.onlab.onos.store.trivial.impl; 16 package org.onlab.onos.store.trivial.impl;
17 17
18 +import com.google.common.base.Predicate;
18 import com.google.common.collect.FluentIterable; 19 import com.google.common.collect.FluentIterable;
19 import com.google.common.collect.ImmutableList; 20 import com.google.common.collect.ImmutableList;
20 import com.google.common.collect.Maps; 21 import com.google.common.collect.Maps;
...@@ -123,6 +124,18 @@ public class SimpleDeviceStore ...@@ -123,6 +124,18 @@ public class SimpleDeviceStore
123 } 124 }
124 125
125 @Override 126 @Override
127 + public Iterable<Device> getAvailableDevices() {
128 + return FluentIterable.from(getDevices())
129 + .filter(new Predicate<Device>() {
130 +
131 + @Override
132 + public boolean apply(Device input) {
133 + return isAvailable(input.id());
134 + }
135 + });
136 + }
137 +
138 + @Override
126 public Device getDevice(DeviceId deviceId) { 139 public Device getDevice(DeviceId deviceId) {
127 return devices.get(deviceId); 140 return devices.get(deviceId);
128 } 141 }
......
...@@ -32,4 +32,12 @@ ...@@ -32,4 +32,12 @@
32 32
33 <description>ONOS LLDP Link Discovery</description> 33 <description>ONOS LLDP Link Discovery</description>
34 34
35 + <dependencies>
36 + <dependency>
37 + <groupId>org.onlab.onos</groupId>
38 + <artifactId>onos-api</artifactId>
39 + <classifier>tests</classifier>
40 + <scope>test</scope>
41 + </dependency>
42 + </dependencies>
35 </project> 43 </project>
......
...@@ -37,7 +37,7 @@ import org.onlab.onos.net.Port; ...@@ -37,7 +37,7 @@ import org.onlab.onos.net.Port;
37 import org.onlab.onos.net.PortNumber; 37 import org.onlab.onos.net.PortNumber;
38 import org.onlab.onos.net.device.DeviceEvent; 38 import org.onlab.onos.net.device.DeviceEvent;
39 import org.onlab.onos.net.device.DeviceListener; 39 import org.onlab.onos.net.device.DeviceListener;
40 -import org.onlab.onos.net.device.DeviceService; 40 +import org.onlab.onos.net.device.DeviceServiceAdapter;
41 import org.onlab.onos.net.flow.TrafficTreatment; 41 import org.onlab.onos.net.flow.TrafficTreatment;
42 import org.onlab.onos.net.link.LinkDescription; 42 import org.onlab.onos.net.link.LinkDescription;
43 import org.onlab.onos.net.link.LinkProvider; 43 import org.onlab.onos.net.link.LinkProvider;
...@@ -376,7 +376,7 @@ public class LLDPLinkProviderTest { ...@@ -376,7 +376,7 @@ public class LLDPLinkProviderTest {
376 } 376 }
377 } 377 }
378 378
379 - private class TestDeviceService implements DeviceService { 379 + private class TestDeviceService extends DeviceServiceAdapter {
380 380
381 private Map<DeviceId, Device> devices = new HashMap<>(); 381 private Map<DeviceId, Device> devices = new HashMap<>();
382 private final ArrayListMultimap<DeviceId, Port> ports = 382 private final ArrayListMultimap<DeviceId, Port> ports =
...@@ -408,7 +408,7 @@ public class LLDPLinkProviderTest { ...@@ -408,7 +408,7 @@ public class LLDPLinkProviderTest {
408 408
409 @Override 409 @Override
410 public Iterable<Device> getDevices() { 410 public Iterable<Device> getDevices() {
411 - return Collections.EMPTY_LIST; 411 + return Collections.emptyList();
412 } 412 }
413 413
414 @Override 414 @Override
......