Showing
4 changed files
with
237 additions
and
9 deletions
... | @@ -105,14 +105,14 @@ public interface TopologyService { | ... | @@ -105,14 +105,14 @@ public interface TopologyService { |
105 | 105 | ||
106 | 106 | ||
107 | /** | 107 | /** |
108 | - * Indicates whether the specified connection point belong to the | 108 | + * Indicates whether broadcast is allowed for traffic received on the |
109 | - * broadcast tree. | 109 | + * specified connection point. |
110 | * | 110 | * |
111 | * @param topology topology descriptor | 111 | * @param topology topology descriptor |
112 | * @param connectPoint connection point | 112 | * @param connectPoint connection point |
113 | * @return true if broadcast is permissible | 113 | * @return true if broadcast is permissible |
114 | */ | 114 | */ |
115 | - boolean isInBroadcastTree(Topology topology, ConnectPoint connectPoint); | 115 | + boolean isBroadcastPoint(Topology topology, ConnectPoint connectPoint); |
116 | 116 | ||
117 | /** | 117 | /** |
118 | * Adds the specified topology listener. | 118 | * Adds the specified topology listener. | ... | ... |
... | @@ -58,7 +58,7 @@ public class SimpleTopologyManager | ... | @@ -58,7 +58,7 @@ public class SimpleTopologyManager |
58 | private final SimpleTopologyStore store = new SimpleTopologyStore(); | 58 | private final SimpleTopologyStore store = new SimpleTopologyStore(); |
59 | 59 | ||
60 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) | 60 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
61 | - private EventDeliveryService eventDispatcher; | 61 | + protected EventDeliveryService eventDispatcher; |
62 | 62 | ||
63 | 63 | ||
64 | @Activate | 64 | @Activate |
... | @@ -151,10 +151,10 @@ public class SimpleTopologyManager | ... | @@ -151,10 +151,10 @@ public class SimpleTopologyManager |
151 | } | 151 | } |
152 | 152 | ||
153 | @Override | 153 | @Override |
154 | - public boolean isInBroadcastTree(Topology topology, ConnectPoint connectPoint) { | 154 | + public boolean isBroadcastPoint(Topology topology, ConnectPoint connectPoint) { |
155 | checkNotNull(topology, TOPOLOGY_NULL); | 155 | checkNotNull(topology, TOPOLOGY_NULL); |
156 | checkNotNull(connectPoint, CONNECTION_POINT_NULL); | 156 | checkNotNull(connectPoint, CONNECTION_POINT_NULL); |
157 | - return store.isInBroadcastTree(defaultTopology(topology), connectPoint); | 157 | + return store.isBroadcastPoint(defaultTopology(topology), connectPoint); |
158 | } | 158 | } |
159 | 159 | ||
160 | @Override | 160 | @Override | ... | ... |
... | @@ -136,13 +136,14 @@ class SimpleTopologyStore { | ... | @@ -136,13 +136,14 @@ class SimpleTopologyStore { |
136 | } | 136 | } |
137 | 137 | ||
138 | /** | 138 | /** |
139 | - * Indicates whether the given connect point is part of the broadcast tree. | 139 | + * Indicates whether broadcast is allowed for traffic received on the |
140 | + * given connection point. | ||
140 | * | 141 | * |
141 | * @param topology topology descriptor | 142 | * @param topology topology descriptor |
142 | * @param connectPoint connection point | 143 | * @param connectPoint connection point |
143 | - * @return true if in broadcast tree; false otherwise | 144 | + * @return true if broadcast allowed; false otherwise |
144 | */ | 145 | */ |
145 | - boolean isInBroadcastTree(DefaultTopology topology, ConnectPoint connectPoint) { | 146 | + boolean isBroadcastPoint(DefaultTopology topology, ConnectPoint connectPoint) { |
146 | return topology.isInBroadcastTree(connectPoint); | 147 | return topology.isInBroadcastTree(connectPoint); |
147 | } | 148 | } |
148 | 149 | ... | ... |
core/trivial/src/test/java/org/onlab/onos/net/trivial/topology/impl/SimpleTopologyManagerTest.java
0 → 100644
1 | +package org.onlab.onos.net.trivial.topology.impl; | ||
2 | + | ||
3 | +import org.junit.After; | ||
4 | +import org.junit.Before; | ||
5 | +import org.junit.Test; | ||
6 | +import org.onlab.onos.event.Event; | ||
7 | +import org.onlab.onos.event.impl.TestEventDispatcher; | ||
8 | +import org.onlab.onos.net.ConnectPoint; | ||
9 | +import org.onlab.onos.net.DefaultDevice; | ||
10 | +import org.onlab.onos.net.DefaultLink; | ||
11 | +import org.onlab.onos.net.Device; | ||
12 | +import org.onlab.onos.net.DeviceId; | ||
13 | +import org.onlab.onos.net.Link; | ||
14 | +import org.onlab.onos.net.Path; | ||
15 | +import org.onlab.onos.net.provider.AbstractProvider; | ||
16 | +import org.onlab.onos.net.provider.ProviderId; | ||
17 | +import org.onlab.onos.net.topology.GraphDescription; | ||
18 | +import org.onlab.onos.net.topology.LinkWeight; | ||
19 | +import org.onlab.onos.net.topology.Topology; | ||
20 | +import org.onlab.onos.net.topology.TopologyCluster; | ||
21 | +import org.onlab.onos.net.topology.TopologyEdge; | ||
22 | +import org.onlab.onos.net.topology.TopologyEvent; | ||
23 | +import org.onlab.onos.net.topology.TopologyGraph; | ||
24 | +import org.onlab.onos.net.topology.TopologyListener; | ||
25 | +import org.onlab.onos.net.topology.TopologyProvider; | ||
26 | +import org.onlab.onos.net.topology.TopologyProviderRegistry; | ||
27 | +import org.onlab.onos.net.topology.TopologyProviderService; | ||
28 | +import org.onlab.onos.net.topology.TopologyService; | ||
29 | + | ||
30 | +import java.util.ArrayList; | ||
31 | +import java.util.List; | ||
32 | +import java.util.Set; | ||
33 | + | ||
34 | +import static com.google.common.collect.ImmutableSet.of; | ||
35 | +import static org.junit.Assert.*; | ||
36 | +import static org.onlab.onos.net.DeviceId.deviceId; | ||
37 | +import static org.onlab.onos.net.PortNumber.portNumber; | ||
38 | +import static org.onlab.onos.net.topology.ClusterId.clusterId; | ||
39 | +import static org.onlab.onos.net.topology.TopologyEvent.Type.TOPOLOGY_CHANGED; | ||
40 | + | ||
41 | +/** | ||
42 | + * Test of the topology subsystem. | ||
43 | + */ | ||
44 | +public class SimpleTopologyManagerTest { | ||
45 | + | ||
46 | + private static final ProviderId PID = new ProviderId("foo"); | ||
47 | + | ||
48 | + private SimpleTopologyManager mgr; | ||
49 | + | ||
50 | + protected TopologyService service; | ||
51 | + protected TopologyProviderRegistry registry; | ||
52 | + protected TopologyProviderService providerService; | ||
53 | + protected TestProvider provider; | ||
54 | + protected TestListener listener = new TestListener(); | ||
55 | + | ||
56 | + @Before | ||
57 | + public void setUp() { | ||
58 | + mgr = new SimpleTopologyManager(); | ||
59 | + service = mgr; | ||
60 | + registry = mgr; | ||
61 | + | ||
62 | + mgr.eventDispatcher = new TestEventDispatcher(); | ||
63 | + mgr.activate(); | ||
64 | + | ||
65 | + service.addListener(listener); | ||
66 | + | ||
67 | + provider = new TestProvider(); | ||
68 | + providerService = registry.register(provider); | ||
69 | + | ||
70 | + assertTrue("provider should be registered", | ||
71 | + registry.getProviders().contains(provider.id())); | ||
72 | + } | ||
73 | + | ||
74 | + @After | ||
75 | + public void tearDown() { | ||
76 | + mgr.deactivate(); | ||
77 | + service.removeListener(listener); | ||
78 | + } | ||
79 | + | ||
80 | + @Test | ||
81 | + public void basics() { | ||
82 | + Topology topology = service.currentTopology(); | ||
83 | + assertNull("no topo expected", topology); | ||
84 | + submitTopologyGraph(); | ||
85 | + validateEvents(TOPOLOGY_CHANGED); | ||
86 | + topology = service.currentTopology(); | ||
87 | + assertTrue("should be latest", service.isLatest(topology)); | ||
88 | + | ||
89 | + submitTopologyGraph(); | ||
90 | + validateEvents(TOPOLOGY_CHANGED); | ||
91 | + assertFalse("should be latest", service.isLatest(topology)); | ||
92 | + } | ||
93 | + | ||
94 | + private void submitTopologyGraph() { | ||
95 | + Set<Device> devices = of(device("a"), device("b"), | ||
96 | + device("c"), device("d"), | ||
97 | + device("e"), device("f")); | ||
98 | + Set<Link> links = of(link("a", 1, "b", 1), link("b", 1, "a", 1), | ||
99 | + link("b", 2, "c", 1), link("c", 1, "b", 2), | ||
100 | + link("c", 2, "d", 1), link("d", 1, "c", 2), | ||
101 | + link("d", 2, "a", 2), link("a", 2, "d", 2), | ||
102 | + link("e", 1, "f", 1), link("f", 1, "e", 1)); | ||
103 | + GraphDescription data = new DefaultGraphDescription(4321L, devices, links); | ||
104 | + providerService.topologyChanged(data, null); | ||
105 | + } | ||
106 | + | ||
107 | + @Test | ||
108 | + public void clusters() { | ||
109 | + submitTopologyGraph(); | ||
110 | + Topology topology = service.currentTopology(); | ||
111 | + assertNotNull("topo expected", topology); | ||
112 | + assertEquals("wrong cluster count", 2, topology.clusterCount()); | ||
113 | + assertEquals("wrong device count", 6, topology.deviceCount()); | ||
114 | + assertEquals("wrong link count", 10, topology.linkCount()); | ||
115 | + assertEquals("wrong path count", 18, topology.pathCount()); | ||
116 | + | ||
117 | + assertEquals("wrong cluster count", 2, service.getClusters(topology).size()); | ||
118 | + | ||
119 | + TopologyCluster cluster = service.getCluster(topology, clusterId(0)); | ||
120 | + assertEquals("wrong device count", 4, cluster.deviceCount()); | ||
121 | + assertEquals("wrong device count", 4, service.getClusterDevices(topology, cluster).size()); | ||
122 | + assertEquals("wrong link count", 8, cluster.linkCount()); | ||
123 | + assertEquals("wrong link count", 8, service.getClusterLinks(topology, cluster).size()); | ||
124 | + } | ||
125 | + | ||
126 | + @Test | ||
127 | + public void structure() { | ||
128 | + submitTopologyGraph(); | ||
129 | + Topology topology = service.currentTopology(); | ||
130 | + | ||
131 | + assertTrue("should be infrastructure point", | ||
132 | + service.isInfrastructure(topology, new ConnectPoint(did("a"), portNumber(1)))); | ||
133 | + assertFalse("should not be infrastructure point", | ||
134 | + service.isInfrastructure(topology, new ConnectPoint(did("a"), portNumber(3)))); | ||
135 | + | ||
136 | + // One of these cannot be a broadcast point... or we have a loop... | ||
137 | + assertFalse("should not be broadcast point", | ||
138 | + service.isBroadcastPoint(topology, new ConnectPoint(did("a"), portNumber(1))) && | ||
139 | + service.isBroadcastPoint(topology, new ConnectPoint(did("b"), portNumber(1))) && | ||
140 | + service.isBroadcastPoint(topology, new ConnectPoint(did("c"), portNumber(1))) && | ||
141 | + service.isBroadcastPoint(topology, new ConnectPoint(did("d"), portNumber(1)))); | ||
142 | + assertTrue("should be broadcast point", | ||
143 | + service.isBroadcastPoint(topology, new ConnectPoint(did("a"), portNumber(3)))); | ||
144 | + } | ||
145 | + | ||
146 | + @Test | ||
147 | + public void graph() { | ||
148 | + submitTopologyGraph(); | ||
149 | + Topology topology = service.currentTopology(); | ||
150 | + TopologyGraph graph = service.getGraph(topology); | ||
151 | + assertEquals("wrong vertex count", 6, graph.getVertexes().size()); | ||
152 | + assertEquals("wrong edge count", 10, graph.getEdges().size()); | ||
153 | + } | ||
154 | + | ||
155 | + @Test | ||
156 | + public void precomputedPath() { | ||
157 | + submitTopologyGraph(); | ||
158 | + Topology topology = service.currentTopology(); | ||
159 | + Set<Path> paths = service.getPaths(topology, did("a"), did("c")); | ||
160 | + assertEquals("wrong path count", 2, paths.size()); | ||
161 | + Path path = paths.iterator().next(); | ||
162 | + assertEquals("wrong path length", 2, path.links().size()); | ||
163 | + assertEquals("wrong path cost", 2, path.cost(), 0.01); | ||
164 | + } | ||
165 | + | ||
166 | + @Test | ||
167 | + public void onDemandPath() { | ||
168 | + submitTopologyGraph(); | ||
169 | + Topology topology = service.currentTopology(); | ||
170 | + LinkWeight weight = new LinkWeight() { | ||
171 | + @Override | ||
172 | + public double weight(TopologyEdge edge) { | ||
173 | + return 3.3; | ||
174 | + } | ||
175 | + }; | ||
176 | + | ||
177 | + Set<Path> paths = service.getPaths(topology, did("a"), did("c"), weight); | ||
178 | + assertEquals("wrong path count", 2, paths.size()); | ||
179 | + Path path = paths.iterator().next(); | ||
180 | + assertEquals("wrong path length", 2, path.links().size()); | ||
181 | + assertEquals("wrong path cost", 6.6, path.cost(), 0.01); | ||
182 | + } | ||
183 | + | ||
184 | + // Short-hand for creating a link. | ||
185 | + private Link link(String src, int sp, String dst, int dp) { | ||
186 | + return new DefaultLink(PID, new ConnectPoint(did(src), portNumber(sp)), | ||
187 | + new ConnectPoint(did(dst), portNumber(dp)), | ||
188 | + Link.Type.DIRECT); | ||
189 | + } | ||
190 | + | ||
191 | + // Crates a new device with the specified id | ||
192 | + private Device device(String id) { | ||
193 | + return new DefaultDevice(PID, did(id), Device.Type.SWITCH, | ||
194 | + "mfg", "1.0", "1.1", "1234"); | ||
195 | + } | ||
196 | + | ||
197 | + // Short-hand for producing a device id from a string | ||
198 | + private DeviceId did(String id) { | ||
199 | + return deviceId("of:" + id); | ||
200 | + } | ||
201 | + | ||
202 | + protected void validateEvents(Enum... types) { | ||
203 | + int i = 0; | ||
204 | + assertEquals("wrong events received", types.length, listener.events.size()); | ||
205 | + for (Event event : listener.events) { | ||
206 | + assertEquals("incorrect event type", types[i], event.type()); | ||
207 | + i++; | ||
208 | + } | ||
209 | + listener.events.clear(); | ||
210 | + } | ||
211 | + | ||
212 | + private class TestProvider extends AbstractProvider implements TopologyProvider { | ||
213 | + public TestProvider() { | ||
214 | + super(PID); | ||
215 | + } | ||
216 | + } | ||
217 | + | ||
218 | + private static class TestListener implements TopologyListener { | ||
219 | + final List<TopologyEvent> events = new ArrayList<>(); | ||
220 | + | ||
221 | + @Override | ||
222 | + public void event(TopologyEvent event) { | ||
223 | + events.add(event); | ||
224 | + } | ||
225 | + } | ||
226 | + | ||
227 | +} | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
-
Please register or login to post a comment