tom | dc95b8a | 2014-09-17 08:07:26 -0700 | [diff] [blame^] | 1 | package org.onlab.onos.net.trivial.topology.impl; |
| 2 | |
| 3 | import org.junit.Before; |
| 4 | import org.junit.Test; |
| 5 | import org.onlab.onos.net.ConnectPoint; |
| 6 | import org.onlab.onos.net.Device; |
| 7 | import org.onlab.onos.net.DeviceId; |
| 8 | import org.onlab.onos.net.Link; |
| 9 | import org.onlab.onos.net.Path; |
| 10 | import org.onlab.onos.net.PortNumber; |
| 11 | import org.onlab.onos.net.provider.ProviderId; |
| 12 | import org.onlab.onos.net.topology.ClusterId; |
| 13 | import org.onlab.onos.net.topology.GraphDescription; |
| 14 | import org.onlab.onos.net.topology.LinkWeight; |
| 15 | import org.onlab.onos.net.topology.TopologyCluster; |
| 16 | import org.onlab.onos.net.topology.TopologyEdge; |
| 17 | |
| 18 | import java.util.Set; |
| 19 | |
| 20 | import static com.google.common.collect.ImmutableSet.of; |
| 21 | import static org.junit.Assert.*; |
| 22 | import static org.onlab.onos.net.DeviceId.deviceId; |
| 23 | import static org.onlab.onos.net.PortNumber.portNumber; |
| 24 | import static org.onlab.onos.net.trivial.topology.impl.SimpleTopologyManagerTest.device; |
| 25 | import static org.onlab.onos.net.trivial.topology.impl.SimpleTopologyManagerTest.link; |
| 26 | |
| 27 | /** |
| 28 | * Test of the default topology implementation. |
| 29 | */ |
| 30 | public class DefaultTopologyTest { |
| 31 | |
| 32 | public static final ProviderId PID = new ProviderId("foo.bar"); |
| 33 | |
| 34 | public static final DeviceId D1 = deviceId("of:1"); |
| 35 | public static final DeviceId D2 = deviceId("of:2"); |
| 36 | public static final DeviceId D3 = deviceId("of:3"); |
| 37 | public static final DeviceId D4 = deviceId("of:4"); |
| 38 | public static final DeviceId D5 = deviceId("of:5"); |
| 39 | |
| 40 | public static final PortNumber P1 = portNumber(1); |
| 41 | public static final PortNumber P2 = portNumber(2); |
| 42 | |
| 43 | public static final LinkWeight WEIGHT = new LinkWeight() { |
| 44 | @Override |
| 45 | public double weight(TopologyEdge edge) { |
| 46 | return edge.src().deviceId().equals(D4) || |
| 47 | edge.dst().deviceId().equals(D4) ? 2.0 : 1.0; |
| 48 | } |
| 49 | }; |
| 50 | |
| 51 | private DefaultTopology dt; |
| 52 | |
| 53 | @Before |
| 54 | public void setUp() { |
| 55 | long now = System.currentTimeMillis(); |
| 56 | Set<Device> devices = of(device("1"), device("2"), |
| 57 | device("3"), device("4"), |
| 58 | device("5")); |
| 59 | Set<Link> links = of(link("1", 1, "2", 1), link("2", 1, "1", 1), |
| 60 | link("3", 2, "2", 2), link("2", 2, "3", 2), |
| 61 | link("1", 3, "4", 3), link("4", 3, "1", 3), |
| 62 | link("3", 4, "4", 4), link("4", 4, "3", 4)); |
| 63 | GraphDescription graphDescription = |
| 64 | new DefaultGraphDescription(now, devices, links); |
| 65 | |
| 66 | dt = new DefaultTopology(PID, graphDescription); |
| 67 | assertEquals("incorrect supplier", PID, dt.providerId()); |
| 68 | assertEquals("incorrect time", now, dt.time()); |
| 69 | assertEquals("incorrect device count", 5, dt.deviceCount()); |
| 70 | assertEquals("incorrect link count", 8, dt.linkCount()); |
| 71 | assertEquals("incorrect cluster count", 2, dt.clusterCount()); |
| 72 | assertEquals("incorrect broadcast set size", 6, |
| 73 | dt.broadcastSetSize(ClusterId.clusterId(0))); |
| 74 | } |
| 75 | |
| 76 | @Test |
| 77 | public void pathRelated() { |
| 78 | Set<Path> paths = dt.getPaths(D1, D2); |
| 79 | assertEquals("incorrect path count", 1, paths.size()); |
| 80 | |
| 81 | paths = dt.getPaths(D1, D3); |
| 82 | assertEquals("incorrect path count", 2, paths.size()); |
| 83 | |
| 84 | paths = dt.getPaths(D1, D5); |
| 85 | assertTrue("no paths expected", paths.isEmpty()); |
| 86 | |
| 87 | paths = dt.getPaths(D1, D3, WEIGHT); |
| 88 | assertEquals("incorrect path count", 1, paths.size()); |
| 89 | } |
| 90 | |
| 91 | @Test |
| 92 | public void pointRelated() { |
| 93 | assertTrue("should be infrastructure point", |
| 94 | dt.isInfrastructure(new ConnectPoint(D1, P1))); |
| 95 | assertFalse("should not be infrastructure point", |
| 96 | dt.isInfrastructure(new ConnectPoint(D1, P2))); |
| 97 | } |
| 98 | |
| 99 | @Test |
| 100 | public void clusterRelated() { |
| 101 | Set<TopologyCluster> clusters = dt.getClusters(); |
| 102 | assertEquals("incorrect cluster count", 2, clusters.size()); |
| 103 | |
| 104 | TopologyCluster c = dt.getCluster(D1); |
| 105 | Set<DeviceId> devs = dt.getClusterDevices(c); |
| 106 | assertEquals("incorrect cluster device count", 4, devs.size()); |
| 107 | assertTrue("cluster should contain D2", devs.contains(D2)); |
| 108 | assertFalse("cluster should not contain D5", devs.contains(D5)); |
| 109 | } |
| 110 | |
| 111 | } |