ONOS-197: Ignore Link with missing Device

- Catch, log, and skip Link edge creation failure.
- log topology error details

Change-Id: I3cd44a86ed6641c49923f6ed4d2dbaf1f97511d0
This commit is contained in:
Yuta HIGUCHI 2014-11-12 23:09:59 -08:00 committed by Yuta Higuchi
parent adac04a72d
commit 2210282957
4 changed files with 23 additions and 5 deletions

View File

@ -15,14 +15,18 @@
*/ */
package org.onlab.onos.net.topology; package org.onlab.onos.net.topology;
import static org.slf4j.LoggerFactory.getLogger;
import com.google.common.collect.ImmutableSet; import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Maps; import com.google.common.collect.Maps;
import org.onlab.onos.net.AbstractDescription; import org.onlab.onos.net.AbstractDescription;
import org.onlab.onos.net.ConnectPoint; import org.onlab.onos.net.ConnectPoint;
import org.onlab.onos.net.Device; import org.onlab.onos.net.Device;
import org.onlab.onos.net.DeviceId; import org.onlab.onos.net.DeviceId;
import org.onlab.onos.net.Link; import org.onlab.onos.net.Link;
import org.onlab.onos.net.SparseAnnotations; import org.onlab.onos.net.SparseAnnotations;
import org.slf4j.Logger;
import java.util.Map; import java.util.Map;
@ -32,6 +36,8 @@ import java.util.Map;
public class DefaultGraphDescription extends AbstractDescription public class DefaultGraphDescription extends AbstractDescription
implements GraphDescription { implements GraphDescription {
private static final Logger log = getLogger(DefaultGraphDescription.class);
private final long nanos; private final long nanos;
private final ImmutableSet<TopologyVertex> vertexes; private final ImmutableSet<TopologyVertex> vertexes;
private final ImmutableSet<TopologyEdge> edges; private final ImmutableSet<TopologyEdge> edges;
@ -87,8 +93,12 @@ public class DefaultGraphDescription extends AbstractDescription
private ImmutableSet<TopologyEdge> buildEdges(Iterable<Link> links) { private ImmutableSet<TopologyEdge> buildEdges(Iterable<Link> links) {
ImmutableSet.Builder<TopologyEdge> edges = ImmutableSet.builder(); ImmutableSet.Builder<TopologyEdge> edges = ImmutableSet.builder();
for (Link link : links) { for (Link link : links) {
edges.add(new DefaultTopologyEdge(vertexOf(link.src()), try {
vertexOf(link.dst()), link)); edges.add(new DefaultTopologyEdge(vertexOf(link.src()),
vertexOf(link.dst()), link));
} catch (IllegalArgumentException e) {
log.debug("Ignoring {}, missing vertex", link, e);
}
} }
return edges.build(); return edges.build();
} }

View File

@ -16,6 +16,7 @@
package org.onlab.onos.net.topology; package org.onlab.onos.net.topology;
import com.google.common.collect.ImmutableSet; import com.google.common.collect.ImmutableSet;
import org.junit.Test; import org.junit.Test;
import org.onlab.onos.net.DefaultDevice; import org.onlab.onos.net.DefaultDevice;
import org.onlab.onos.net.Device; import org.onlab.onos.net.Device;
@ -47,9 +48,13 @@ public class DefaultGraphDescriptionTest {
assertEquals("incorrect edge count", 2, desc.edges().size()); assertEquals("incorrect edge count", 2, desc.edges().size());
} }
@Test(expected = IllegalArgumentException.class) @Test
public void missingVertex() { public void missingVertex() {
new DefaultGraphDescription(4321L, ImmutableSet.of(DEV1, DEV3), GraphDescription desc = new DefaultGraphDescription(4321L,
ImmutableSet.of(L1, L2)); ImmutableSet.of(DEV1, DEV3),
ImmutableSet.of(L1, L2));
assertEquals("incorrect time", 4321L, desc.timestamp());
assertEquals("incorrect vertex count", 2, desc.vertexes().size());
assertEquals("incorrect edge count", 0, desc.edges().size());
} }
} }

View File

@ -48,7 +48,9 @@ public class DefaultTopologyEdgeTest {
static final ProviderId PID = new ProviderId("foo", "bar"); static final ProviderId PID = new ProviderId("foo", "bar");
/** D1:P1 -> D2:P1. */
static final Link L1 = new DefaultLink(PID, CP1, CP2, Link.Type.INDIRECT); static final Link L1 = new DefaultLink(PID, CP1, CP2, Link.Type.INDIRECT);
/** D2:P1 -> D1:P2. */
static final Link L2 = new DefaultLink(PID, CP3, CP4, Link.Type.INDIRECT); static final Link L2 = new DefaultLink(PID, CP3, CP4, Link.Type.INDIRECT);
@Test @Test

View File

@ -203,6 +203,7 @@ public class DefaultTopologyProvider extends AbstractProvider
buildTopology(reasons); buildTopology(reasons);
} catch (Exception e) { } catch (Exception e) {
log.warn("Unable to compute topology due to: {}", e.getMessage()); log.warn("Unable to compute topology due to: {}", e.getMessage());
log.debug("Unable to compute topology", e);
} }
} }
} }