tom

Doh! Forgot to ignite SimpleFlowRuleStore as a component. Pingall now works again!

1 +package org.onlab.onos.cluster;
2 +
3 +/**
4 + * Service responsible for determining the controller instance mastership of
5 + * a device in a clustered environment. This is the central authority for
6 + * determining mastership, but is not responsible for actually applying it
7 + * to the devices; this falls on the device service.
8 + */
9 +public interface MastershipService {
10 +
11 + // InstanceId getMasterFor(DeviceId deviceId)
12 + // Set<DeviceId> getDevicesOf(InstanceId instanceId);
13 +
14 + // MastershipRole requestRoleFor(DeviceId deviceId);
15 +
16 + // addListener/removeLister(MastershipListener listener);
17 + // types of events would be MASTER_CHANGED (subject ==> deviceId; master ==> instanceId)
18 +
19 +}
1 +package org.onlab.onos.net;
2 +
3 +import org.onlab.onos.net.provider.ProviderId;
4 +import org.onlab.packet.IpPrefix;
5 +
6 +import java.util.ArrayList;
7 +import java.util.HashSet;
8 +import java.util.List;
9 +
10 +import static org.onlab.onos.net.DeviceId.deviceId;
11 +import static org.onlab.onos.net.HostId.hostId;
12 +import static org.onlab.onos.net.PortNumber.portNumber;
13 +import static org.onlab.packet.MacAddress.valueOf;
14 +import static org.onlab.packet.VlanId.vlanId;
15 +
16 +/**
17 + * Miscellaneous tools for testing core related to the network model.
18 + */
19 +public final class NetTestTools {
20 +
21 + private NetTestTools() {
22 + }
23 +
24 + public static final ProviderId PID = new ProviderId("of", "foo");
25 +
26 + // Short-hand for producing a device id from a string
27 + public static DeviceId did(String id) {
28 + return deviceId("of:" + id);
29 + }
30 +
31 +
32 + // Short-hand for producing a host id from a string
33 + public static HostId hid(String id) {
34 + return hostId("nic:" + id);
35 + }
36 +
37 + // Crates a new device with the specified id
38 + public static Device device(String id) {
39 + return new DefaultDevice(PID, did(id), Device.Type.SWITCH,
40 + "mfg", "1.0", "1.1", "1234");
41 + }
42 +
43 + // Crates a new host with the specified id
44 + public static Host host(String id, String did) {
45 + return new DefaultHost(PID, hid(id), valueOf(1234), vlanId((short) 2),
46 + new HostLocation(did(did), portNumber(1), 321),
47 + new HashSet<IpPrefix>());
48 + }
49 +
50 + // Short-hand for creating a link.
51 + public static Link link(String src, int sp, String dst, int dp) {
52 + return new DefaultLink(PID, new ConnectPoint(did(src), portNumber(sp)),
53 + new ConnectPoint(did(dst), portNumber(dp)),
54 + Link.Type.DIRECT);
55 + }
56 +
57 + // Creates a path that leads through the given devices.
58 + public static Path createPath(String... ids) {
59 + List<Link> links = new ArrayList<>();
60 + for (int i = 0; i < ids.length - 1; i++) {
61 + links.add(link(ids[i], i, ids[i + 1], i));
62 + }
63 + return new DefaultPath(PID, links, ids.length);
64 + }
65 +
66 +}
...@@ -24,23 +24,30 @@ ...@@ -24,23 +24,30 @@
24 24
25 <dependency> 25 <dependency>
26 <groupId>org.onlab.onos</groupId> 26 <groupId>org.onlab.onos</groupId>
27 - <artifactId>onos-core-trivial</artifactId> 27 + <artifactId>onos-api</artifactId>
28 - <version>${project.version}</version> 28 + <classifier>tests</classifier>
29 <scope>test</scope> 29 <scope>test</scope>
30 </dependency> 30 </dependency>
31 31
32 <dependency> 32 <dependency>
33 - <groupId>org.apache.felix</groupId> 33 + <groupId>org.onlab.onos</groupId>
34 - <artifactId>org.apache.felix.scr.annotations</artifactId> 34 + <artifactId>onos-core-trivial</artifactId>
35 + <version>${project.version}</version>
36 + <scope>test</scope>
35 </dependency> 37 </dependency>
36 38
37 <!-- TODO Consider removing store dependency. 39 <!-- TODO Consider removing store dependency.
38 Currently required for DistributedDeviceManagerTest. --> 40 Currently required for DistributedDeviceManagerTest. -->
39 <dependency> 41 <dependency>
40 - <groupId>org.onlab.onos</groupId> 42 + <groupId>org.onlab.onos</groupId>
41 - <artifactId>onos-core-store</artifactId> 43 + <artifactId>onos-core-store</artifactId>
42 <version>${project.version}</version> 44 <version>${project.version}</version>
43 - <scope>test</scope> 45 + <scope>test</scope>
46 + </dependency>
47 +
48 + <dependency>
49 + <groupId>org.apache.felix</groupId>
50 + <artifactId>org.apache.felix.scr.annotations</artifactId>
44 </dependency> 51 </dependency>
45 </dependencies> 52 </dependencies>
46 53
......
1 package org.onlab.onos.net.topology.impl; 1 package org.onlab.onos.net.topology.impl;
2 2
3 +import com.google.common.collect.ImmutableSet;
3 import com.google.common.collect.Lists; 4 import com.google.common.collect.Lists;
4 import com.google.common.collect.Sets; 5 import com.google.common.collect.Sets;
5 import org.apache.felix.scr.annotations.Activate; 6 import org.apache.felix.scr.annotations.Activate;
...@@ -59,12 +60,12 @@ public class PathManager implements PathService { ...@@ -59,12 +60,12 @@ public class PathManager implements PathService {
59 protected HostService hostService; 60 protected HostService hostService;
60 61
61 @Activate 62 @Activate
62 - public void setUp() { 63 + public void activate() {
63 log.info("Started"); 64 log.info("Started");
64 } 65 }
65 66
66 @Deactivate 67 @Deactivate
67 - public void tearDown() { 68 + public void deactivate() {
68 log.info("Stopped"); 69 log.info("Stopped");
69 } 70 }
70 71
...@@ -82,6 +83,11 @@ public class PathManager implements PathService { ...@@ -82,6 +83,11 @@ public class PathManager implements PathService {
82 EdgeLink srcEdge = getEdgeLink(src, true); 83 EdgeLink srcEdge = getEdgeLink(src, true);
83 EdgeLink dstEdge = getEdgeLink(dst, false); 84 EdgeLink dstEdge = getEdgeLink(dst, false);
84 85
86 + // If either edge is null, bail with no paths.
87 + if (srcEdge == null || dstEdge == null) {
88 + return ImmutableSet.of();
89 + }
90 +
85 DeviceId srcDevice = srcEdge != NOT_HOST ? srcEdge.dst().deviceId() : (DeviceId) src; 91 DeviceId srcDevice = srcEdge != NOT_HOST ? srcEdge.dst().deviceId() : (DeviceId) src;
86 DeviceId dstDevice = dstEdge != NOT_HOST ? dstEdge.src().deviceId() : (DeviceId) dst; 92 DeviceId dstDevice = dstEdge != NOT_HOST ? dstEdge.src().deviceId() : (DeviceId) dst;
87 93
...@@ -117,28 +123,14 @@ public class PathManager implements PathService { ...@@ -117,28 +123,14 @@ public class PathManager implements PathService {
117 return NOT_HOST; 123 return NOT_HOST;
118 } 124 }
119 125
120 - // Produces a set of direct edge-to-edge paths. 126 + // Produces a set of edge-to-edge paths using the set of infrastructure
127 + // paths and the given edge links.
121 private Set<Path> edgeToEdgePaths(EdgeLink srcLink, EdgeLink dstLink) { 128 private Set<Path> edgeToEdgePaths(EdgeLink srcLink, EdgeLink dstLink) {
122 Set<Path> endToEndPaths = Sets.newHashSetWithExpectedSize(1); 129 Set<Path> endToEndPaths = Sets.newHashSetWithExpectedSize(1);
123 - if (srcLink != NOT_HOST || dstLink != NOT_HOST) { 130 + endToEndPaths.add(edgeToEdgePath(srcLink, dstLink, null));
124 - endToEndPaths.add(edgeToEdgePath(srcLink, dstLink));
125 - }
126 return endToEndPaths; 131 return endToEndPaths;
127 } 132 }
128 133
129 - // Produces a direct edge-to-edge path.
130 - private Path edgeToEdgePath(EdgeLink srcLink, EdgeLink dstLink) {
131 - List<Link> links = Lists.newArrayListWithCapacity(2);
132 - // Add source and destination edge links only if they are real.
133 - if (srcLink != NOT_HOST) {
134 - links.add(srcLink);
135 - }
136 - if (dstLink != NOT_HOST) {
137 - links.add(dstLink);
138 - }
139 - return new DefaultPath(PID, links, 2);
140 - }
141 -
142 // Produces a set of edge-to-edge paths using the set of infrastructure 134 // Produces a set of edge-to-edge paths using the set of infrastructure
143 // paths and the given edge links. 135 // paths and the given edge links.
144 private Set<Path> edgeToEdgePaths(EdgeLink srcLink, EdgeLink dstLink, Set<Path> paths) { 136 private Set<Path> edgeToEdgePaths(EdgeLink srcLink, EdgeLink dstLink, Set<Path> paths) {
...@@ -149,14 +141,21 @@ public class PathManager implements PathService { ...@@ -149,14 +141,21 @@ public class PathManager implements PathService {
149 return endToEndPaths; 141 return endToEndPaths;
150 } 142 }
151 143
152 - // Produces an edge-to-edge path using the specified infrastructure path 144 + // Produces a direct edge-to-edge path.
153 - // and edge links.
154 private Path edgeToEdgePath(EdgeLink srcLink, EdgeLink dstLink, Path path) { 145 private Path edgeToEdgePath(EdgeLink srcLink, EdgeLink dstLink, Path path) {
155 - List<Link> links = Lists.newArrayListWithCapacity(path.links().size() + 2); 146 + List<Link> links = Lists.newArrayListWithCapacity(2);
156 - links.add(srcLink); 147 + // Add source and destination edge links only if they are real and
157 - links.addAll(path.links()); 148 + // add the infrastructure path only if it is not null.
158 - links.add(dstLink); 149 + if (srcLink != NOT_HOST) {
159 - return new DefaultPath(path.providerId(), links, path.cost() + 2); 150 + links.add(srcLink);
151 + }
152 + if (path != null) {
153 + links.addAll(path.links());
154 + }
155 + if (dstLink != NOT_HOST) {
156 + links.add(dstLink);
157 + }
158 + return new DefaultPath(PID, links, 2);
160 } 159 }
161 160
162 // Special value for edge link to represent that this is really not an 161 // Special value for edge link to represent that this is really not an
......
...@@ -25,6 +25,8 @@ import java.util.Set; ...@@ -25,6 +25,8 @@ import java.util.Set;
25 import static org.junit.Assert.assertEquals; 25 import static org.junit.Assert.assertEquals;
26 import static org.junit.Assert.assertNotNull; 26 import static org.junit.Assert.assertNotNull;
27 import static org.onlab.junit.TestTools.assertAfter; 27 import static org.onlab.junit.TestTools.assertAfter;
28 +import static org.onlab.onos.net.NetTestTools.device;
29 +import static org.onlab.onos.net.NetTestTools.link;
28 import static org.onlab.onos.net.device.DeviceEvent.Type.DEVICE_ADDED; 30 import static org.onlab.onos.net.device.DeviceEvent.Type.DEVICE_ADDED;
29 import static org.onlab.onos.net.link.LinkEvent.Type.LINK_ADDED; 31 import static org.onlab.onos.net.link.LinkEvent.Type.LINK_ADDED;
30 32
...@@ -79,8 +81,8 @@ public class DefaultTopologyProviderTest { ...@@ -79,8 +81,8 @@ public class DefaultTopologyProviderTest {
79 @Override 81 @Override
80 public void run() { 82 public void run() {
81 validateSubmission(); 83 validateSubmission();
82 - deviceService.post(new DeviceEvent(DEVICE_ADDED, TopologyManagerTest.device("z"), null)); 84 + deviceService.post(new DeviceEvent(DEVICE_ADDED, device("z"), null));
83 - linkService.post(new LinkEvent(LINK_ADDED, TopologyManagerTest.link("z", 1, "a", 4))); 85 + linkService.post(new LinkEvent(LINK_ADDED, link("z", 1, "a", 4)));
84 validateSubmission(); 86 validateSubmission();
85 } 87 }
86 }); 88 });
...@@ -128,9 +130,9 @@ public class DefaultTopologyProviderTest { ...@@ -128,9 +130,9 @@ public class DefaultTopologyProviderTest {
128 130
129 @Override 131 @Override
130 public Iterable<Device> getDevices() { 132 public Iterable<Device> getDevices() {
131 - return ImmutableSet.of(TopologyManagerTest.device("a"), TopologyManagerTest.device("b"), 133 + return ImmutableSet.of(device("a"), device("b"),
132 - TopologyManagerTest.device("c"), TopologyManagerTest.device("d"), 134 + device("c"), device("d"),
133 - TopologyManagerTest.device("e"), TopologyManagerTest.device("f")); 135 + device("e"), device("f"));
134 } 136 }
135 137
136 void post(DeviceEvent event) { 138 void post(DeviceEvent event) {
...@@ -146,11 +148,11 @@ public class DefaultTopologyProviderTest { ...@@ -146,11 +148,11 @@ public class DefaultTopologyProviderTest {
146 148
147 @Override 149 @Override
148 public Iterable<Link> getLinks() { 150 public Iterable<Link> getLinks() {
149 - return ImmutableSet.of(TopologyManagerTest.link("a", 1, "b", 1), TopologyManagerTest.link("b", 1, "a", 1), 151 + return ImmutableSet.of(link("a", 1, "b", 1), link("b", 1, "a", 1),
150 - TopologyManagerTest.link("b", 2, "c", 1), TopologyManagerTest.link("c", 1, "b", 2), 152 + link("b", 2, "c", 1), link("c", 1, "b", 2),
151 - TopologyManagerTest.link("c", 2, "d", 1), TopologyManagerTest.link("d", 1, "c", 2), 153 + link("c", 2, "d", 1), link("d", 1, "c", 2),
152 - TopologyManagerTest.link("d", 2, "a", 2), TopologyManagerTest.link("a", 2, "d", 2), 154 + link("d", 2, "a", 2), link("a", 2, "d", 2),
153 - TopologyManagerTest.link("e", 1, "f", 1), TopologyManagerTest.link("f", 1, "e", 1)); 155 + link("e", 1, "f", 1), link("f", 1, "e", 1));
154 } 156 }
155 157
156 void post(LinkEvent event) { 158 void post(LinkEvent event) {
......
1 +package org.onlab.onos.net.topology.impl;
2 +
3 +import org.junit.After;
4 +import org.junit.Before;
5 +import org.junit.Test;
6 +import org.onlab.onos.net.DeviceId;
7 +import org.onlab.onos.net.ElementId;
8 +import org.onlab.onos.net.Host;
9 +import org.onlab.onos.net.HostId;
10 +import org.onlab.onos.net.Path;
11 +import org.onlab.onos.net.host.HostService;
12 +import org.onlab.onos.net.host.HostServiceAdapter;
13 +import org.onlab.onos.net.provider.ProviderId;
14 +import org.onlab.onos.net.topology.LinkWeight;
15 +import org.onlab.onos.net.topology.PathService;
16 +import org.onlab.onos.net.topology.Topology;
17 +import org.onlab.onos.net.topology.TopologyService;
18 +import org.onlab.onos.net.topology.TopologyServiceAdapter;
19 +
20 +import java.util.HashMap;
21 +import java.util.HashSet;
22 +import java.util.Map;
23 +import java.util.Set;
24 +
25 +import static org.junit.Assert.assertEquals;
26 +import static org.junit.Assert.assertTrue;
27 +import static org.onlab.onos.net.NetTestTools.*;
28 +
29 +/**
30 + * Test of the path selection subsystem.
31 + */
32 +public class PathManagerTest {
33 +
34 + private static final ProviderId PID = new ProviderId("of", "foo");
35 +
36 + private PathManager mgr;
37 + private PathService service;
38 +
39 + private FakeTopoMgr fakeTopoMgr = new FakeTopoMgr();
40 + private FakeHostMgr fakeHostMgr = new FakeHostMgr();
41 +
42 + @Before
43 + public void setUp() {
44 + mgr = new PathManager();
45 + service = mgr;
46 + mgr.topologyService = fakeTopoMgr;
47 + mgr.hostService = fakeHostMgr;
48 + mgr.activate();
49 + }
50 +
51 + @After
52 + public void tearDown() {
53 + mgr.deactivate();
54 + }
55 +
56 + @Test
57 + public void infraToInfra() {
58 + DeviceId src = did("src");
59 + DeviceId dst = did("dst");
60 + fakeTopoMgr.paths.add(createPath("src", "middle", "dst"));
61 + Set<Path> paths = service.getPaths(src, dst);
62 + validatePaths(paths, 1, 2, src, dst);
63 + }
64 +
65 + @Test
66 + public void infraToEdge() {
67 + DeviceId src = did("src");
68 + HostId dst = hid("dst");
69 + fakeTopoMgr.paths.add(createPath("src", "middle", "edge"));
70 + fakeHostMgr.hosts.put(dst, host("dst", "edge"));
71 + Set<Path> paths = service.getPaths(src, dst);
72 + validatePaths(paths, 1, 3, src, dst);
73 + }
74 +
75 + @Test
76 + public void edgeToInfra() {
77 + HostId src = hid("src");
78 + DeviceId dst = did("dst");
79 + fakeTopoMgr.paths.add(createPath("edge", "middle", "dst"));
80 + fakeHostMgr.hosts.put(src, host("src", "edge"));
81 + Set<Path> paths = service.getPaths(src, dst);
82 + validatePaths(paths, 1, 3, src, dst);
83 + }
84 +
85 + @Test
86 + public void edgeToEdge() {
87 + HostId src = hid("src");
88 + HostId dst = hid("dst");
89 + fakeTopoMgr.paths.add(createPath("srcEdge", "middle", "dstEdge"));
90 + fakeHostMgr.hosts.put(src, host("src", "srcEdge"));
91 + fakeHostMgr.hosts.put(dst, host("dst", "dstEdge"));
92 + Set<Path> paths = service.getPaths(src, dst);
93 + validatePaths(paths, 1, 4, src, dst);
94 + }
95 +
96 + @Test
97 + public void edgeToEdgeDirect() {
98 + HostId src = hid("src");
99 + HostId dst = hid("dst");
100 + fakeHostMgr.hosts.put(src, host("src", "edge"));
101 + fakeHostMgr.hosts.put(dst, host("dst", "edge"));
102 + Set<Path> paths = service.getPaths(src, dst);
103 + validatePaths(paths, 1, 2, src, dst);
104 + }
105 +
106 + @Test
107 + public void noEdge() {
108 + Set<Path> paths = service.getPaths(hid("src"), hid("dst"));
109 + assertTrue("there should be no paths", paths.isEmpty());
110 + }
111 +
112 + // Makes sure the set of paths meets basic expectations.
113 + private void validatePaths(Set<Path> paths, int count, int length,
114 + ElementId src, ElementId dst) {
115 + assertEquals("incorrect path count", count, paths.size());
116 + for (Path path : paths) {
117 + assertEquals("incorrect length", length, path.links().size());
118 + assertEquals("incorrect source", src, path.src().elementId());
119 + assertEquals("incorrect destination", dst, path.dst().elementId());
120 + }
121 + }
122 +
123 + // Fake entity to give out paths.
124 + private class FakeTopoMgr extends TopologyServiceAdapter implements TopologyService {
125 + Set<Path> paths = new HashSet<>();
126 +
127 + @Override
128 + public Set<Path> getPaths(Topology topology, DeviceId src, DeviceId dst) {
129 + return paths;
130 + }
131 +
132 + @Override
133 + public Set<Path> getPaths(Topology topology, DeviceId src, DeviceId dst, LinkWeight weight) {
134 + return paths;
135 + }
136 + }
137 +
138 + // Fake entity to give out hosts.
139 + private class FakeHostMgr extends HostServiceAdapter implements HostService {
140 + private Map<HostId, Host> hosts = new HashMap<>();
141 +
142 + @Override
143 + public Host getHost(HostId hostId) {
144 + return hosts.get(hostId);
145 + }
146 + }
147 +
148 +}
...@@ -6,10 +6,7 @@ import org.junit.Test; ...@@ -6,10 +6,7 @@ import org.junit.Test;
6 import org.onlab.onos.event.Event; 6 import org.onlab.onos.event.Event;
7 import org.onlab.onos.event.impl.TestEventDispatcher; 7 import org.onlab.onos.event.impl.TestEventDispatcher;
8 import org.onlab.onos.net.ConnectPoint; 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; 9 import org.onlab.onos.net.Device;
12 -import org.onlab.onos.net.DeviceId;
13 import org.onlab.onos.net.Link; 10 import org.onlab.onos.net.Link;
14 import org.onlab.onos.net.Path; 11 import org.onlab.onos.net.Path;
15 import org.onlab.onos.net.provider.AbstractProvider; 12 import org.onlab.onos.net.provider.AbstractProvider;
...@@ -35,7 +32,7 @@ import java.util.Set; ...@@ -35,7 +32,7 @@ import java.util.Set;
35 32
36 import static com.google.common.collect.ImmutableSet.of; 33 import static com.google.common.collect.ImmutableSet.of;
37 import static org.junit.Assert.*; 34 import static org.junit.Assert.*;
38 -import static org.onlab.onos.net.DeviceId.deviceId; 35 +import static org.onlab.onos.net.NetTestTools.*;
39 import static org.onlab.onos.net.PortNumber.portNumber; 36 import static org.onlab.onos.net.PortNumber.portNumber;
40 import static org.onlab.onos.net.topology.ClusterId.clusterId; 37 import static org.onlab.onos.net.topology.ClusterId.clusterId;
41 import static org.onlab.onos.net.topology.TopologyEvent.Type.TOPOLOGY_CHANGED; 38 import static org.onlab.onos.net.topology.TopologyEvent.Type.TOPOLOGY_CHANGED;
...@@ -184,24 +181,6 @@ public class TopologyManagerTest { ...@@ -184,24 +181,6 @@ public class TopologyManagerTest {
184 assertEquals("wrong path cost", 6.6, path.cost(), 0.01); 181 assertEquals("wrong path cost", 6.6, path.cost(), 0.01);
185 } 182 }
186 183
187 - // Short-hand for creating a link.
188 - public static Link link(String src, int sp, String dst, int dp) {
189 - return new DefaultLink(PID, new ConnectPoint(did(src), portNumber(sp)),
190 - new ConnectPoint(did(dst), portNumber(dp)),
191 - Link.Type.DIRECT);
192 - }
193 -
194 - // Crates a new device with the specified id
195 - public static Device device(String id) {
196 - return new DefaultDevice(PID, did(id), Device.Type.SWITCH,
197 - "mfg", "1.0", "1.1", "1234");
198 - }
199 -
200 - // Short-hand for producing a device id from a string
201 - public static DeviceId did(String id) {
202 - return deviceId("of:" + id);
203 - }
204 -
205 protected void validateEvents(Enum... types) { 184 protected void validateEvents(Enum... types) {
206 int i = 0; 185 int i = 0;
207 assertEquals("wrong events received", types.length, listener.events.size()); 186 assertEquals("wrong events received", types.length, listener.events.size());
......
...@@ -8,6 +8,8 @@ ...@@ -8,6 +8,8 @@
8 <bundle>mvn:commons-lang/commons-lang/2.6</bundle> 8 <bundle>mvn:commons-lang/commons-lang/2.6</bundle>
9 <bundle>mvn:com.google.guava/guava/18.0</bundle> 9 <bundle>mvn:com.google.guava/guava/18.0</bundle>
10 <bundle>mvn:io.netty/netty/3.9.2.Final</bundle> 10 <bundle>mvn:io.netty/netty/3.9.2.Final</bundle>
11 + <bundle>mvn:com.esotericsoftware.kryo/kryo/2.24.0</bundle>
12 + <bundle>mvn:com.esotericsoftware.minlog/minlog/1.3</bundle>
11 </feature> 13 </feature>
12 14
13 <feature name="onos-thirdparty-web" version="1.0.0" 15 <feature name="onos-thirdparty-web" version="1.0.0"
......