Merge branch 'master' of ssh://gerrit.onlab.us:29418/onos-next
Showing
9 changed files
with
210 additions
and
7 deletions
... | @@ -25,10 +25,10 @@ import org.slf4j.LoggerFactory; | ... | @@ -25,10 +25,10 @@ import org.slf4j.LoggerFactory; |
25 | /** | 25 | /** |
26 | * Manages the connectivity requirements between peers. | 26 | * Manages the connectivity requirements between peers. |
27 | */ | 27 | */ |
28 | -public class PeerConnectivity { | 28 | +public class PeerConnectivityManager { |
29 | 29 | ||
30 | private static final Logger log = LoggerFactory.getLogger( | 30 | private static final Logger log = LoggerFactory.getLogger( |
31 | - PeerConnectivity.class); | 31 | + PeerConnectivityManager.class); |
32 | 32 | ||
33 | // TODO these shouldn't be defined here | 33 | // TODO these shouldn't be defined here |
34 | private static final short BGP_PORT = 179; | 34 | private static final short BGP_PORT = 179; |
... | @@ -41,7 +41,7 @@ public class PeerConnectivity { | ... | @@ -41,7 +41,7 @@ public class PeerConnectivity { |
41 | // TODO this sucks. | 41 | // TODO this sucks. |
42 | private int intentId = 0; | 42 | private int intentId = 0; |
43 | 43 | ||
44 | - public PeerConnectivity(SdnIpConfigService configInfoService, | 44 | + public PeerConnectivityManager(SdnIpConfigService configInfoService, |
45 | InterfaceService interfaceService, IntentService intentService) { | 45 | InterfaceService interfaceService, IntentService intentService) { |
46 | this.configInfoService = configInfoService; | 46 | this.configInfoService = configInfoService; |
47 | this.interfaceService = interfaceService; | 47 | this.interfaceService = interfaceService; | ... | ... |
... | @@ -36,7 +36,7 @@ public class SdnIp implements SdnIpService { | ... | @@ -36,7 +36,7 @@ public class SdnIp implements SdnIpService { |
36 | protected HostService hostService; | 36 | protected HostService hostService; |
37 | 37 | ||
38 | private SdnIpConfigReader config; | 38 | private SdnIpConfigReader config; |
39 | - private PeerConnectivity peerConnectivity; | 39 | + private PeerConnectivityManager peerConnectivity; |
40 | private Router router; | 40 | private Router router; |
41 | private BgpSessionManager bgpSessionManager; | 41 | private BgpSessionManager bgpSessionManager; |
42 | 42 | ||
... | @@ -49,7 +49,7 @@ public class SdnIp implements SdnIpService { | ... | @@ -49,7 +49,7 @@ public class SdnIp implements SdnIpService { |
49 | 49 | ||
50 | InterfaceService interfaceService = new HostServiceBasedInterfaceService(hostService); | 50 | InterfaceService interfaceService = new HostServiceBasedInterfaceService(hostService); |
51 | 51 | ||
52 | - peerConnectivity = new PeerConnectivity(config, interfaceService, intentService); | 52 | + peerConnectivity = new PeerConnectivityManager(config, interfaceService, intentService); |
53 | peerConnectivity.start(); | 53 | peerConnectivity.start(); |
54 | 54 | ||
55 | router = new Router(intentService, hostService, config, interfaceService); | 55 | router = new Router(intentService, hostService, config, interfaceService); |
... | @@ -79,4 +79,8 @@ public class SdnIp implements SdnIpService { | ... | @@ -79,4 +79,8 @@ public class SdnIp implements SdnIpService { |
79 | public Collection<RouteEntry> getRoutes() { | 79 | public Collection<RouteEntry> getRoutes() { |
80 | return router.getRoutes(); | 80 | return router.getRoutes(); |
81 | } | 81 | } |
82 | + | ||
83 | + static String dpidToUri(String dpid) { | ||
84 | + return "of:" + dpid.replace(":", ""); | ||
85 | + } | ||
82 | } | 86 | } | ... | ... |
This diff is collapsed. Click to expand it.
... | @@ -7,6 +7,8 @@ import org.onlab.onos.net.Provided; | ... | @@ -7,6 +7,8 @@ import org.onlab.onos.net.Provided; |
7 | */ | 7 | */ |
8 | public interface Topology extends Provided { | 8 | public interface Topology extends Provided { |
9 | 9 | ||
10 | + // FIXME: Following is not true right now. It is actually System.nanoTime(), | ||
11 | + // which has no relation to epoch time, wall clock, etc. | ||
10 | /** | 12 | /** |
11 | * Returns the time, specified in milliseconds since start of epoch, | 13 | * Returns the time, specified in milliseconds since start of epoch, |
12 | * when the topology became active and made available. | 14 | * when the topology became active and made available. | ... | ... |
... | @@ -52,6 +52,12 @@ | ... | @@ -52,6 +52,12 @@ |
52 | <artifactId>easymock</artifactId> | 52 | <artifactId>easymock</artifactId> |
53 | <scope>test</scope> | 53 | <scope>test</scope> |
54 | </dependency> | 54 | </dependency> |
55 | + <dependency> | ||
56 | + <groupId>org.onlab.onos</groupId> | ||
57 | + <artifactId>onos-api</artifactId> | ||
58 | + <classifier>tests</classifier> | ||
59 | + <scope>test</scope> | ||
60 | + </dependency> | ||
55 | </dependencies> | 61 | </dependencies> |
56 | 62 | ||
57 | </project> | 63 | </project> | ... | ... |
... | @@ -3,7 +3,7 @@ package org.onlab.onos.store.flow; | ... | @@ -3,7 +3,7 @@ package org.onlab.onos.store.flow; |
3 | import org.onlab.onos.net.DeviceId; | 3 | import org.onlab.onos.net.DeviceId; |
4 | 4 | ||
5 | /** | 5 | /** |
6 | - * Service to return where the Replica should be placed. | 6 | + * Service to return where the replica should be placed. |
7 | */ | 7 | */ |
8 | public interface ReplicaInfoService { | 8 | public interface ReplicaInfoService { |
9 | 9 | ||
... | @@ -15,4 +15,19 @@ public interface ReplicaInfoService { | ... | @@ -15,4 +15,19 @@ public interface ReplicaInfoService { |
15 | * @return placement information | 15 | * @return placement information |
16 | */ | 16 | */ |
17 | ReplicaInfo getReplicaInfoFor(DeviceId deviceId); | 17 | ReplicaInfo getReplicaInfoFor(DeviceId deviceId); |
18 | + | ||
19 | + /** | ||
20 | + * Adds the specified replica placement info change listener. | ||
21 | + * | ||
22 | + * @param listener the replica placement info change listener | ||
23 | + */ | ||
24 | + void addListener(ReplicaInfoEventListener listener); | ||
25 | + | ||
26 | + /** | ||
27 | + * Removes the specified replica placement info change listener. | ||
28 | + * | ||
29 | + * @param listener the replica placement info change listener | ||
30 | + */ | ||
31 | + void removeListener(ReplicaInfoEventListener listener); | ||
32 | + | ||
18 | } | 33 | } | ... | ... |
1 | package org.onlab.onos.store.flow.impl; | 1 | package org.onlab.onos.store.flow.impl; |
2 | 2 | ||
3 | +import static com.google.common.base.Preconditions.checkNotNull; | ||
3 | import static org.slf4j.LoggerFactory.getLogger; | 4 | import static org.slf4j.LoggerFactory.getLogger; |
4 | import static org.onlab.onos.store.flow.ReplicaInfoEvent.Type.MASTER_CHANGED; | 5 | import static org.onlab.onos.store.flow.ReplicaInfoEvent.Type.MASTER_CHANGED; |
5 | 6 | ||
... | @@ -66,6 +67,16 @@ public class ReplicaInfoManager implements ReplicaInfoService { | ... | @@ -66,6 +67,16 @@ public class ReplicaInfoManager implements ReplicaInfoService { |
66 | Collections.<NodeId>emptyList()); | 67 | Collections.<NodeId>emptyList()); |
67 | } | 68 | } |
68 | 69 | ||
70 | + @Override | ||
71 | + public void addListener(ReplicaInfoEventListener listener) { | ||
72 | + listenerRegistry.addListener(checkNotNull(listener)); | ||
73 | + } | ||
74 | + | ||
75 | + @Override | ||
76 | + public void removeListener(ReplicaInfoEventListener listener) { | ||
77 | + listenerRegistry.removeListener(checkNotNull(listener)); | ||
78 | + } | ||
79 | + | ||
69 | final class InternalMastershipListener implements MastershipListener { | 80 | final class InternalMastershipListener implements MastershipListener { |
70 | 81 | ||
71 | @Override | 82 | @Override | ... | ... |
1 | +package org.onlab.onos.store.flow.impl; | ||
2 | + | ||
3 | +import static com.google.common.base.Preconditions.checkState; | ||
4 | +import static org.junit.Assert.*; | ||
5 | + | ||
6 | +import java.util.Collections; | ||
7 | +import java.util.Map; | ||
8 | +import java.util.concurrent.CountDownLatch; | ||
9 | +import java.util.concurrent.TimeUnit; | ||
10 | + | ||
11 | +import org.junit.After; | ||
12 | +import org.junit.Before; | ||
13 | +import org.junit.Test; | ||
14 | +import org.onlab.onos.cluster.NodeId; | ||
15 | +import org.onlab.onos.event.AbstractListenerRegistry; | ||
16 | +import org.onlab.onos.event.DefaultEventSinkRegistry; | ||
17 | +import org.onlab.onos.event.Event; | ||
18 | +import org.onlab.onos.event.EventDeliveryService; | ||
19 | +import org.onlab.onos.event.EventSink; | ||
20 | +import org.onlab.onos.mastership.MastershipEvent; | ||
21 | +import org.onlab.onos.mastership.MastershipEvent.Type; | ||
22 | +import org.onlab.onos.mastership.MastershipListener; | ||
23 | +import org.onlab.onos.mastership.MastershipService; | ||
24 | +import org.onlab.onos.mastership.MastershipServiceAdapter; | ||
25 | +import org.onlab.onos.net.DeviceId; | ||
26 | +import org.onlab.onos.store.flow.ReplicaInfo; | ||
27 | +import org.onlab.onos.store.flow.ReplicaInfoEvent; | ||
28 | +import org.onlab.onos.store.flow.ReplicaInfoEventListener; | ||
29 | +import org.onlab.onos.store.flow.ReplicaInfoService; | ||
30 | + | ||
31 | +import com.google.common.base.Optional; | ||
32 | +import com.google.common.collect.Maps; | ||
33 | + | ||
34 | +public class ReplicaInfoManagerTest { | ||
35 | + | ||
36 | + | ||
37 | + private static final DeviceId DID1 = DeviceId.deviceId("of:1"); | ||
38 | + private static final DeviceId DID2 = DeviceId.deviceId("of:2"); | ||
39 | + private static final NodeId NID1 = new NodeId("foo"); | ||
40 | + | ||
41 | + private ReplicaInfoManager mgr; | ||
42 | + private ReplicaInfoService service; | ||
43 | + | ||
44 | + private AbstractListenerRegistry<MastershipEvent, MastershipListener> | ||
45 | + mastershipListenerRegistry; | ||
46 | + private TestEventDispatcher eventDispatcher; | ||
47 | + | ||
48 | + | ||
49 | + @Before | ||
50 | + public void setUp() throws Exception { | ||
51 | + mastershipListenerRegistry = new AbstractListenerRegistry<>(); | ||
52 | + | ||
53 | + mgr = new ReplicaInfoManager(); | ||
54 | + service = mgr; | ||
55 | + | ||
56 | + eventDispatcher = new TestEventDispatcher(); | ||
57 | + mgr.eventDispatcher = eventDispatcher; | ||
58 | + mgr.mastershipService = new TestMastershipService(); | ||
59 | + | ||
60 | + // register dummy mastership event source | ||
61 | + mgr.eventDispatcher.addSink(MastershipEvent.class, mastershipListenerRegistry); | ||
62 | + | ||
63 | + mgr.activate(); | ||
64 | + } | ||
65 | + | ||
66 | + @After | ||
67 | + public void tearDown() throws Exception { | ||
68 | + mgr.deactivate(); | ||
69 | + } | ||
70 | + | ||
71 | + @Test | ||
72 | + public void testGetReplicaInfoFor() { | ||
73 | + ReplicaInfo info1 = service.getReplicaInfoFor(DID1); | ||
74 | + assertEquals(Optional.of(NID1), info1.master()); | ||
75 | + // backups are always empty for now | ||
76 | + assertEquals(Collections.emptyList(), info1.backups()); | ||
77 | + | ||
78 | + ReplicaInfo info2 = service.getReplicaInfoFor(DID2); | ||
79 | + assertEquals("There's no master", Optional.absent(), info2.master()); | ||
80 | + // backups are always empty for now | ||
81 | + assertEquals(Collections.emptyList(), info2.backups()); | ||
82 | + } | ||
83 | + | ||
84 | + @Test | ||
85 | + public void testReplicaInfoEvent() throws InterruptedException { | ||
86 | + final CountDownLatch latch = new CountDownLatch(1); | ||
87 | + service.addListener(new MasterNodeCheck(latch, DID1, NID1)); | ||
88 | + | ||
89 | + // fake MastershipEvent | ||
90 | + eventDispatcher.post(new MastershipEvent(Type.MASTER_CHANGED, DID1, NID1)); | ||
91 | + | ||
92 | + assertTrue(latch.await(1, TimeUnit.SECONDS)); | ||
93 | + } | ||
94 | + | ||
95 | + | ||
96 | + private final class MasterNodeCheck implements ReplicaInfoEventListener { | ||
97 | + private final CountDownLatch latch; | ||
98 | + private Optional<NodeId> expectedMaster; | ||
99 | + private DeviceId expectedDevice; | ||
100 | + | ||
101 | + | ||
102 | + MasterNodeCheck(CountDownLatch latch, DeviceId did, | ||
103 | + NodeId nid) { | ||
104 | + this.latch = latch; | ||
105 | + this.expectedMaster = Optional.fromNullable(nid); | ||
106 | + this.expectedDevice = did; | ||
107 | + } | ||
108 | + | ||
109 | + @Override | ||
110 | + public void event(ReplicaInfoEvent event) { | ||
111 | + assertEquals(expectedDevice, event.subject()); | ||
112 | + assertEquals(expectedMaster, event.replicaInfo().master()); | ||
113 | + // backups are always empty for now | ||
114 | + assertEquals(Collections.emptyList(), event.replicaInfo().backups()); | ||
115 | + latch.countDown(); | ||
116 | + } | ||
117 | + } | ||
118 | + | ||
119 | + | ||
120 | + private final class TestMastershipService | ||
121 | + extends MastershipServiceAdapter | ||
122 | + implements MastershipService { | ||
123 | + | ||
124 | + private Map<DeviceId, NodeId> masters; | ||
125 | + | ||
126 | + TestMastershipService() { | ||
127 | + masters = Maps.newHashMap(); | ||
128 | + masters.put(DID1, NID1); | ||
129 | + // DID2 has no master | ||
130 | + } | ||
131 | + | ||
132 | + @Override | ||
133 | + public NodeId getMasterFor(DeviceId deviceId) { | ||
134 | + return masters.get(deviceId); | ||
135 | + } | ||
136 | + | ||
137 | + @Override | ||
138 | + public void addListener(MastershipListener listener) { | ||
139 | + mastershipListenerRegistry.addListener(listener); | ||
140 | + } | ||
141 | + | ||
142 | + @Override | ||
143 | + public void removeListener(MastershipListener listener) { | ||
144 | + mastershipListenerRegistry.removeListener(listener); | ||
145 | + } | ||
146 | + } | ||
147 | + | ||
148 | + | ||
149 | + // code clone | ||
150 | + /** | ||
151 | + * Implements event delivery system that delivers events synchronously, or | ||
152 | + * in-line with the post method invocation. | ||
153 | + */ | ||
154 | + private static class TestEventDispatcher extends DefaultEventSinkRegistry | ||
155 | + implements EventDeliveryService { | ||
156 | + | ||
157 | + @SuppressWarnings({ "rawtypes", "unchecked" }) | ||
158 | + @Override | ||
159 | + public void post(Event event) { | ||
160 | + EventSink sink = getSink(event.getClass()); | ||
161 | + checkState(sink != null, "No sink for event %s", event); | ||
162 | + sink.process(event); | ||
163 | + } | ||
164 | + } | ||
165 | +} |
... | @@ -172,7 +172,7 @@ public class OpenFlowDeviceProvider extends AbstractProvider implements DevicePr | ... | @@ -172,7 +172,7 @@ public class OpenFlowDeviceProvider extends AbstractProvider implements DevicePr |
172 | */ | 172 | */ |
173 | private List<PortDescription> buildPortDescriptions( | 173 | private List<PortDescription> buildPortDescriptions( |
174 | List<OFPortDesc> ports) { | 174 | List<OFPortDesc> ports) { |
175 | - final List<PortDescription> portDescs = new ArrayList<>(); | 175 | + final List<PortDescription> portDescs = new ArrayList<>(ports.size()); |
176 | for (OFPortDesc port : ports) { | 176 | for (OFPortDesc port : ports) { |
177 | portDescs.add(buildPortDescription(port)); | 177 | portDescs.add(buildPortDescription(port)); |
178 | } | 178 | } | ... | ... |
-
Please register or login to post a comment