Committed by
Gerrit Code Review
[Falcon] Componentize IntentSynchronizer and SdnIpFib.
Change-Id: Ic384ce00572ae1e4bbf94b4de814cea3499d3828
Showing
11 changed files
with
324 additions
and
225 deletions
... | @@ -47,9 +47,9 @@ import org.onosproject.net.packet.PacketContext; | ... | @@ -47,9 +47,9 @@ import org.onosproject.net.packet.PacketContext; |
47 | import org.onosproject.net.packet.PacketProcessor; | 47 | import org.onosproject.net.packet.PacketProcessor; |
48 | import org.onosproject.net.packet.PacketService; | 48 | import org.onosproject.net.packet.PacketService; |
49 | import org.onosproject.routing.IntentRequestListener; | 49 | import org.onosproject.routing.IntentRequestListener; |
50 | +import org.onosproject.routing.IntentSynchronizationService; | ||
50 | import org.onosproject.routing.RouteEntry; | 51 | import org.onosproject.routing.RouteEntry; |
51 | import org.onosproject.routing.RoutingService; | 52 | import org.onosproject.routing.RoutingService; |
52 | -import org.onosproject.routing.SdnIpService; | ||
53 | import org.onosproject.routing.config.RoutingConfigurationService; | 53 | import org.onosproject.routing.config.RoutingConfigurationService; |
54 | import org.slf4j.Logger; | 54 | import org.slf4j.Logger; |
55 | 55 | ||
... | @@ -86,7 +86,7 @@ public class SdnIpReactiveRouting { | ... | @@ -86,7 +86,7 @@ public class SdnIpReactiveRouting { |
86 | protected RoutingService routingService; | 86 | protected RoutingService routingService; |
87 | 87 | ||
88 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) | 88 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
89 | - protected SdnIpService sdnIpService; | 89 | + protected IntentSynchronizationService intentSynchronizer; |
90 | 90 | ||
91 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) | 91 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
92 | protected RoutingConfigurationService config; | 92 | protected RoutingConfigurationService config; |
... | @@ -109,8 +109,7 @@ public class SdnIpReactiveRouting { | ... | @@ -109,8 +109,7 @@ public class SdnIpReactiveRouting { |
109 | appId = coreService.registerApplication(APP_NAME); | 109 | appId = coreService.registerApplication(APP_NAME); |
110 | 110 | ||
111 | intentRequestListener = new ReactiveRoutingFib(appId, hostService, | 111 | intentRequestListener = new ReactiveRoutingFib(appId, hostService, |
112 | - config, interfaceService, | 112 | + config, interfaceService, intentSynchronizer); |
113 | - sdnIpService.getIntentSynchronizationService()); | ||
114 | 113 | ||
115 | packetService.addProcessor(processor, PacketProcessor.director(2)); | 114 | packetService.addProcessor(processor, PacketProcessor.director(2)); |
116 | requestIntercepts(); | 115 | requestIntercepts(); | ... | ... |
1 | /* | 1 | /* |
2 | - * Copyright 2014-2015 Open Networking Laboratory | 2 | + * Copyright 2015 Open Networking Laboratory |
3 | * | 3 | * |
4 | * Licensed under the Apache License, Version 2.0 (the "License"); | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
5 | * you may not use this file except in compliance with the License. | 5 | * you may not use this file except in compliance with the License. |
... | @@ -13,12 +13,13 @@ | ... | @@ -13,12 +13,13 @@ |
13 | * See the License for the specific language governing permissions and | 13 | * See the License for the specific language governing permissions and |
14 | * limitations under the License. | 14 | * limitations under the License. |
15 | */ | 15 | */ |
16 | + | ||
16 | package org.onosproject.routing; | 17 | package org.onosproject.routing; |
17 | 18 | ||
18 | /** | 19 | /** |
19 | - * Service interface exported by SDN-IP. | 20 | + * Administrative APIs for managing intent synchronization. |
20 | */ | 21 | */ |
21 | -public interface SdnIpService { | 22 | +public interface IntentSynchronizationAdminService { |
22 | 23 | ||
23 | /** | 24 | /** |
24 | * Changes whether this SDN-IP instance is the primary or not based on the | 25 | * Changes whether this SDN-IP instance is the primary or not based on the |
... | @@ -29,11 +30,7 @@ public interface SdnIpService { | ... | @@ -29,11 +30,7 @@ public interface SdnIpService { |
29 | void modifyPrimary(boolean isPrimary); | 30 | void modifyPrimary(boolean isPrimary); |
30 | 31 | ||
31 | /** | 32 | /** |
32 | - * Gets the intent synchronization service. | 33 | + * Withdraws all intents. |
33 | - * | ||
34 | - * @return intent synchronization service | ||
35 | */ | 34 | */ |
36 | - // TODO fix service resolution in SDN-IP | 35 | + void removeIntents(); |
37 | - IntentSynchronizationService getIntentSynchronizationService(); | ||
38 | - | ||
39 | } | 36 | } | ... | ... |
1 | +/* | ||
2 | + * Copyright 2015 Open Networking Laboratory | ||
3 | + * | ||
4 | + * Licensed under the Apache License, Version 2.0 (the "License"); | ||
5 | + * you may not use this file except in compliance with the License. | ||
6 | + * You may obtain a copy of the License at | ||
7 | + * | ||
8 | + * http://www.apache.org/licenses/LICENSE-2.0 | ||
9 | + * | ||
10 | + * Unless required by applicable law or agreed to in writing, software | ||
11 | + * distributed under the License is distributed on an "AS IS" BASIS, | ||
12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
13 | + * See the License for the specific language governing permissions and | ||
14 | + * limitations under the License. | ||
15 | + */ | ||
16 | + | ||
17 | +package org.onosproject.routing; | ||
18 | + | ||
19 | +import org.onlab.packet.IpAddress; | ||
20 | + | ||
21 | +import java.util.Collection; | ||
22 | + | ||
23 | +/** | ||
24 | + * Routing service adapter. | ||
25 | + */ | ||
26 | +public class RoutingServiceAdapter implements RoutingService { | ||
27 | + | ||
28 | + @Override | ||
29 | + public void start() { | ||
30 | + | ||
31 | + } | ||
32 | + | ||
33 | + @Override | ||
34 | + public void addFibListener(FibListener fibListener) { | ||
35 | + | ||
36 | + } | ||
37 | + | ||
38 | + @Override | ||
39 | + public void stop() { | ||
40 | + | ||
41 | + } | ||
42 | + | ||
43 | + @Override | ||
44 | + public Collection<RouteEntry> getRoutes4() { | ||
45 | + return null; | ||
46 | + } | ||
47 | + | ||
48 | + @Override | ||
49 | + public Collection<RouteEntry> getRoutes6() { | ||
50 | + return null; | ||
51 | + } | ||
52 | + | ||
53 | + @Override | ||
54 | + public RouteEntry getLongestMatchableRouteEntry(IpAddress ipAddress) { | ||
55 | + return null; | ||
56 | + } | ||
57 | +} |
... | @@ -35,7 +35,6 @@ import org.onlab.packet.IpAddress; | ... | @@ -35,7 +35,6 @@ import org.onlab.packet.IpAddress; |
35 | import org.onlab.packet.IpPrefix; | 35 | import org.onlab.packet.IpPrefix; |
36 | import org.onlab.packet.MacAddress; | 36 | import org.onlab.packet.MacAddress; |
37 | import org.onosproject.core.CoreService; | 37 | import org.onosproject.core.CoreService; |
38 | -import org.onosproject.incubator.net.intf.InterfaceService; | ||
39 | import org.onosproject.net.Host; | 38 | import org.onosproject.net.Host; |
40 | import org.onosproject.net.host.HostEvent; | 39 | import org.onosproject.net.host.HostEvent; |
41 | import org.onosproject.net.host.HostListener; | 40 | import org.onosproject.net.host.HostListener; |
... | @@ -107,9 +106,6 @@ public class Router implements RoutingService { | ... | @@ -107,9 +106,6 @@ public class Router implements RoutingService { |
107 | protected BgpService bgpService; | 106 | protected BgpService bgpService; |
108 | 107 | ||
109 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) | 108 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
110 | - protected InterfaceService interfaceService; | ||
111 | - | ||
112 | - @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) | ||
113 | protected RoutingConfigurationService routingConfigurationService; | 109 | protected RoutingConfigurationService routingConfigurationService; |
114 | 110 | ||
115 | private ExecutorService bgpUpdatesExecutor; | 111 | private ExecutorService bgpUpdatesExecutor; |
... | @@ -123,7 +119,7 @@ public class Router implements RoutingService { | ... | @@ -123,7 +119,7 @@ public class Router implements RoutingService { |
123 | new DefaultByteArrayNodeFactory()); | 119 | new DefaultByteArrayNodeFactory()); |
124 | 120 | ||
125 | routesWaitingOnArp = Multimaps.synchronizedSetMultimap( | 121 | routesWaitingOnArp = Multimaps.synchronizedSetMultimap( |
126 | - HashMultimap.<IpAddress, RouteEntry>create()); | 122 | + HashMultimap.create()); |
127 | 123 | ||
128 | coreService.registerApplication(ROUTER_APP_ID); | 124 | coreService.registerApplication(ROUTER_APP_ID); |
129 | 125 | ... | ... |
... | @@ -58,7 +58,15 @@ | ... | @@ -58,7 +58,15 @@ |
58 | 58 | ||
59 | <dependency> | 59 | <dependency> |
60 | <groupId>org.onosproject</groupId> | 60 | <groupId>org.onosproject</groupId> |
61 | - <artifactId>onos-app-routing</artifactId> | 61 | + <artifactId>onos-app-routing-api</artifactId> |
62 | + <version>${project.version}</version> | ||
63 | + </dependency> | ||
64 | + | ||
65 | + <dependency> | ||
66 | + <groupId>org.onosproject</groupId> | ||
67 | + <artifactId>onos-app-routing-api</artifactId> | ||
68 | + <scope>test</scope> | ||
69 | + <classifier>tests</classifier> | ||
62 | <version>${project.version}</version> | 70 | <version>${project.version}</version> |
63 | </dependency> | 71 | </dependency> |
64 | 72 | ... | ... |
... | @@ -15,101 +15,117 @@ | ... | @@ -15,101 +15,117 @@ |
15 | */ | 15 | */ |
16 | package org.onosproject.sdnip; | 16 | package org.onosproject.sdnip; |
17 | 17 | ||
18 | -import static java.util.concurrent.Executors.newSingleThreadExecutor; | 18 | +import org.apache.felix.scr.annotations.Activate; |
19 | -import static org.onlab.util.Tools.groupedThreads; | 19 | +import org.apache.felix.scr.annotations.Component; |
20 | +import org.apache.felix.scr.annotations.Deactivate; | ||
21 | +import org.apache.felix.scr.annotations.Reference; | ||
22 | +import org.apache.felix.scr.annotations.ReferenceCardinality; | ||
23 | +import org.apache.felix.scr.annotations.Service; | ||
24 | +import org.onosproject.cluster.ClusterService; | ||
25 | +import org.onosproject.cluster.LeadershipEvent; | ||
26 | +import org.onosproject.cluster.LeadershipEventListener; | ||
27 | +import org.onosproject.cluster.LeadershipService; | ||
28 | +import org.onosproject.core.ApplicationId; | ||
29 | +import org.onosproject.core.CoreService; | ||
30 | +import org.onosproject.net.intent.Intent; | ||
31 | +import org.onosproject.net.intent.IntentService; | ||
32 | +import org.onosproject.net.intent.IntentState; | ||
33 | +import org.onosproject.net.intent.Key; | ||
34 | +import org.onosproject.routing.IntentSynchronizationAdminService; | ||
35 | +import org.onosproject.routing.IntentSynchronizationService; | ||
36 | +import org.slf4j.Logger; | ||
37 | +import org.slf4j.LoggerFactory; | ||
20 | 38 | ||
21 | import java.util.HashMap; | 39 | import java.util.HashMap; |
22 | import java.util.LinkedList; | 40 | import java.util.LinkedList; |
23 | import java.util.List; | 41 | import java.util.List; |
24 | import java.util.Map; | 42 | import java.util.Map; |
25 | import java.util.Map.Entry; | 43 | import java.util.Map.Entry; |
44 | +import java.util.Objects; | ||
26 | import java.util.concurrent.ConcurrentHashMap; | 45 | import java.util.concurrent.ConcurrentHashMap; |
27 | import java.util.concurrent.ExecutorService; | 46 | import java.util.concurrent.ExecutorService; |
28 | 47 | ||
29 | -import org.onosproject.core.ApplicationId; | ||
30 | -import org.onosproject.net.intent.Intent; | ||
31 | -import org.onosproject.net.intent.IntentService; | ||
32 | -import org.onosproject.net.intent.IntentState; | ||
33 | import org.onosproject.net.intent.IntentUtils; | 48 | import org.onosproject.net.intent.IntentUtils; |
34 | -import org.onosproject.net.intent.Key; | 49 | + |
35 | -import org.onosproject.routing.IntentSynchronizationService; | 50 | +import static java.util.concurrent.Executors.newSingleThreadExecutor; |
36 | -import org.slf4j.Logger; | 51 | +import static org.onlab.util.Tools.groupedThreads; |
37 | -import org.slf4j.LoggerFactory; | ||
38 | 52 | ||
39 | /** | 53 | /** |
40 | - * Synchronizes intents between the in-memory intent store and the | 54 | + * Synchronizes intents between an in-memory intent store and the IntentService. |
41 | - * IntentService. | ||
42 | */ | 55 | */ |
43 | -public class IntentSynchronizer implements IntentSynchronizationService { | 56 | +@Service |
57 | +@Component(immediate = true) | ||
58 | +public class IntentSynchronizer implements IntentSynchronizationService, | ||
59 | + IntentSynchronizationAdminService { | ||
60 | + | ||
61 | + private static final Logger log = LoggerFactory.getLogger(IntentSynchronizer.class); | ||
62 | + | ||
63 | + private static final String APP_NAME = "org.onosproject.intentsynchronizer"; | ||
64 | + | ||
65 | + @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) | ||
66 | + protected CoreService coreService; | ||
44 | 67 | ||
45 | - private static final Logger log = | 68 | + @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
46 | - LoggerFactory.getLogger(IntentSynchronizer.class); | 69 | + protected LeadershipService leadershipService; |
47 | 70 | ||
48 | - private final ApplicationId appId; | 71 | + @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
49 | - private final IntentService intentService; | 72 | + protected ClusterService clusterService; |
50 | 73 | ||
51 | - private final Map<Key, Intent> intents; | 74 | + @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
75 | + protected IntentService intentService; | ||
76 | + | ||
77 | + private ApplicationId appId; | ||
78 | + | ||
79 | + private final InternalLeadershipListener leadershipEventListener = | ||
80 | + new InternalLeadershipListener(); | ||
81 | + | ||
82 | + private final Map<Key, Intent> intents = new ConcurrentHashMap<>(); | ||
83 | + | ||
84 | + private ExecutorService intentsSynchronizerExecutor; | ||
52 | 85 | ||
53 | - // | ||
54 | - // State to deal with the Leader election and pushing Intents | ||
55 | - // | ||
56 | - private final ExecutorService intentsSynchronizerExecutor; | ||
57 | private volatile boolean isElectedLeader = false; | 86 | private volatile boolean isElectedLeader = false; |
58 | private volatile boolean isActivatedLeader = false; | 87 | private volatile boolean isActivatedLeader = false; |
59 | 88 | ||
60 | - /** | 89 | + @Activate |
61 | - * Class constructor. | 90 | + public void activate() { |
62 | - * | 91 | + intentsSynchronizerExecutor = createExecutor(); |
63 | - * @param appId the Application ID | ||
64 | - * @param intentService the intent service | ||
65 | - */ | ||
66 | - public IntentSynchronizer(ApplicationId appId, IntentService intentService) { | ||
67 | - this(appId, intentService, | ||
68 | - newSingleThreadExecutor(groupedThreads("onos/" + appId, "sync"))); | ||
69 | - } | ||
70 | 92 | ||
71 | - /** | 93 | + this.appId = coreService.registerApplication(APP_NAME); |
72 | - * Class constructor. | ||
73 | - * | ||
74 | - * @param appId the Application ID | ||
75 | - * @param intentService the intent service | ||
76 | - * @param executorService executor service for synchronization thread | ||
77 | - */ | ||
78 | - public IntentSynchronizer(ApplicationId appId, IntentService intentService, | ||
79 | - ExecutorService executorService) { | ||
80 | - this.appId = appId; | ||
81 | - this.intentService = intentService; | ||
82 | 94 | ||
83 | - intents = new ConcurrentHashMap<>(); | 95 | + leadershipService.addListener(leadershipEventListener); |
96 | + leadershipService.runForLeadership(appId.name()); | ||
84 | 97 | ||
85 | - intentsSynchronizerExecutor = executorService; | 98 | + log.info("Started"); |
86 | } | 99 | } |
87 | 100 | ||
88 | - /** | 101 | + @Deactivate |
89 | - * Starts the synchronizer. | 102 | + public void deactivate() { |
90 | - */ | 103 | + leadershipService.withdraw(appId.name()); |
91 | - public void start() { | 104 | + leadershipService.removeListener(leadershipEventListener); |
92 | - | ||
93 | - } | ||
94 | 105 | ||
95 | - /** | ||
96 | - * Stops the synchronizer. | ||
97 | - */ | ||
98 | - public void stop() { | ||
99 | synchronized (this) { | 106 | synchronized (this) { |
100 | - // Stop the thread(s) | ||
101 | intentsSynchronizerExecutor.shutdownNow(); | 107 | intentsSynchronizerExecutor.shutdownNow(); |
102 | - log.info("Intents Synchronizer Executor shutdown completed"); | ||
103 | - | ||
104 | } | 108 | } |
109 | + | ||
110 | + log.info("Stopped"); | ||
105 | } | 111 | } |
106 | 112 | ||
107 | /** | 113 | /** |
108 | - * Withdraws all intents. | 114 | + * Creates an executor that will be used for synchronization tasks. |
115 | + * <p> | ||
116 | + * Can be overridden to change the type of executor used. | ||
117 | + * </p> | ||
118 | + * | ||
119 | + * @return executor service | ||
109 | */ | 120 | */ |
121 | + protected ExecutorService createExecutor() { | ||
122 | + return newSingleThreadExecutor(groupedThreads("onos/" + appId, "sync")); | ||
123 | + } | ||
124 | + | ||
125 | + @Override | ||
110 | public void removeIntents() { | 126 | public void removeIntents() { |
111 | if (!isElectedLeader) { | 127 | if (!isElectedLeader) { |
112 | - // only leader will withdraw intents | 128 | + // Only leader will withdraw intents |
113 | return; | 129 | return; |
114 | } | 130 | } |
115 | 131 | ||
... | @@ -152,18 +168,19 @@ public class IntentSynchronizer implements IntentSynchronizationService { | ... | @@ -152,18 +168,19 @@ public class IntentSynchronizer implements IntentSynchronizationService { |
152 | * | 168 | * |
153 | * @param isLeader true if this instance is now the leader, otherwise false | 169 | * @param isLeader true if this instance is now the leader, otherwise false |
154 | */ | 170 | */ |
155 | - public void leaderChanged(boolean isLeader) { | 171 | + private void leaderChanged(boolean isLeader) { |
156 | log.debug("Leader changed: {}", isLeader); | 172 | log.debug("Leader changed: {}", isLeader); |
157 | 173 | ||
158 | if (!isLeader) { | 174 | if (!isLeader) { |
159 | this.isElectedLeader = false; | 175 | this.isElectedLeader = false; |
160 | this.isActivatedLeader = false; | 176 | this.isActivatedLeader = false; |
161 | - return; // Nothing to do | 177 | + // Nothing to do |
178 | + return; | ||
162 | } | 179 | } |
163 | this.isActivatedLeader = false; | 180 | this.isActivatedLeader = false; |
164 | this.isElectedLeader = true; | 181 | this.isElectedLeader = true; |
165 | 182 | ||
166 | - // Run the synchronization method off-thread | 183 | + // Run the synchronization task |
167 | intentsSynchronizerExecutor.execute(this::synchronizeIntents); | 184 | intentsSynchronizerExecutor.execute(this::synchronizeIntents); |
168 | } | 185 | } |
169 | 186 | ||
... | @@ -232,10 +249,49 @@ public class IntentSynchronizer implements IntentSynchronizationService { | ... | @@ -232,10 +249,49 @@ public class IntentSynchronizer implements IntentSynchronizationService { |
232 | } | 249 | } |
233 | 250 | ||
234 | if (isElectedLeader) { | 251 | if (isElectedLeader) { |
235 | - isActivatedLeader = true; // Allow push of Intents | 252 | + // Allow push of Intents |
253 | + isActivatedLeader = true; | ||
236 | } else { | 254 | } else { |
237 | isActivatedLeader = false; | 255 | isActivatedLeader = false; |
238 | } | 256 | } |
239 | log.debug("Intent synchronization completed"); | 257 | log.debug("Intent synchronization completed"); |
240 | } | 258 | } |
259 | + | ||
260 | + @Override | ||
261 | + public void modifyPrimary(boolean isPrimary) { | ||
262 | + leaderChanged(isPrimary); | ||
263 | + } | ||
264 | + | ||
265 | + /** | ||
266 | + * A listener for leadership events. | ||
267 | + */ | ||
268 | + private class InternalLeadershipListener implements LeadershipEventListener { | ||
269 | + | ||
270 | + @Override | ||
271 | + public void event(LeadershipEvent event) { | ||
272 | + if (!event.subject().topic().equals(appId.name())) { | ||
273 | + // Not our topic: ignore | ||
274 | + return; | ||
275 | + } | ||
276 | + if (!Objects.equals(event.subject().leader(), | ||
277 | + clusterService.getLocalNode().id())) { | ||
278 | + // The event is not about this instance: ignore | ||
279 | + return; | ||
280 | + } | ||
281 | + | ||
282 | + switch (event.type()) { | ||
283 | + case LEADER_ELECTED: | ||
284 | + log.info("IntentSynchronizer gained leadership"); | ||
285 | + leaderChanged(true); | ||
286 | + break; | ||
287 | + case LEADER_BOOTED: | ||
288 | + log.info("IntentSynchronizer lost leadership"); | ||
289 | + leaderChanged(false); | ||
290 | + break; | ||
291 | + case LEADER_REELECTED: | ||
292 | + default: | ||
293 | + break; | ||
294 | + } | ||
295 | + } | ||
296 | + } | ||
241 | } | 297 | } | ... | ... |
... | @@ -15,136 +15,79 @@ | ... | @@ -15,136 +15,79 @@ |
15 | */ | 15 | */ |
16 | package org.onosproject.sdnip; | 16 | package org.onosproject.sdnip; |
17 | 17 | ||
18 | -import static org.slf4j.LoggerFactory.getLogger; | ||
19 | - | ||
20 | -import java.util.Objects; | ||
21 | - | ||
22 | import org.apache.felix.scr.annotations.Activate; | 18 | import org.apache.felix.scr.annotations.Activate; |
23 | import org.apache.felix.scr.annotations.Component; | 19 | import org.apache.felix.scr.annotations.Component; |
24 | import org.apache.felix.scr.annotations.Deactivate; | 20 | import org.apache.felix.scr.annotations.Deactivate; |
25 | import org.apache.felix.scr.annotations.Reference; | 21 | import org.apache.felix.scr.annotations.Reference; |
26 | import org.apache.felix.scr.annotations.ReferenceCardinality; | 22 | import org.apache.felix.scr.annotations.ReferenceCardinality; |
27 | -import org.apache.felix.scr.annotations.Service; | ||
28 | import org.onosproject.app.ApplicationService; | 23 | import org.onosproject.app.ApplicationService; |
29 | -import org.onosproject.cluster.ClusterService; | ||
30 | -import org.onosproject.cluster.ControllerNode; | ||
31 | -import org.onosproject.cluster.LeadershipEvent; | ||
32 | -import org.onosproject.cluster.LeadershipEventListener; | ||
33 | -import org.onosproject.cluster.LeadershipService; | ||
34 | import org.onosproject.core.ApplicationId; | 24 | import org.onosproject.core.ApplicationId; |
35 | import org.onosproject.core.CoreService; | 25 | import org.onosproject.core.CoreService; |
36 | import org.onosproject.incubator.net.intf.InterfaceService; | 26 | import org.onosproject.incubator.net.intf.InterfaceService; |
37 | import org.onosproject.net.config.NetworkConfigService; | 27 | import org.onosproject.net.config.NetworkConfigService; |
38 | -import org.onosproject.net.host.HostService; | 28 | +import org.onosproject.routing.IntentSynchronizationAdminService; |
39 | -import org.onosproject.net.intent.IntentService; | ||
40 | import org.onosproject.routing.IntentSynchronizationService; | 29 | import org.onosproject.routing.IntentSynchronizationService; |
41 | import org.onosproject.routing.RoutingService; | 30 | import org.onosproject.routing.RoutingService; |
42 | -import org.onosproject.routing.SdnIpService; | ||
43 | -import org.onosproject.routing.config.RoutingConfigurationService; | ||
44 | import org.slf4j.Logger; | 31 | import org.slf4j.Logger; |
45 | 32 | ||
33 | +import static org.slf4j.LoggerFactory.getLogger; | ||
34 | + | ||
46 | /** | 35 | /** |
47 | * Component for the SDN-IP peering application. | 36 | * Component for the SDN-IP peering application. |
48 | */ | 37 | */ |
49 | @Component(immediate = true) | 38 | @Component(immediate = true) |
50 | -@Service | 39 | +public class SdnIp { |
51 | -public class SdnIp implements SdnIpService { | ||
52 | 40 | ||
53 | - private static final String SDN_IP_APP = "org.onosproject.sdnip"; | 41 | + public static final String SDN_IP_APP = "org.onosproject.sdnip"; |
54 | private final Logger log = getLogger(getClass()); | 42 | private final Logger log = getLogger(getClass()); |
55 | 43 | ||
56 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) | 44 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
57 | protected CoreService coreService; | 45 | protected CoreService coreService; |
58 | 46 | ||
59 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) | 47 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
60 | - protected IntentService intentService; | ||
61 | - | ||
62 | - @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) | ||
63 | protected ApplicationService applicationService; | 48 | protected ApplicationService applicationService; |
64 | 49 | ||
65 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) | 50 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
66 | - protected HostService hostService; | 51 | + protected NetworkConfigService networkConfigService; |
67 | - | ||
68 | - @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) | ||
69 | - protected ClusterService clusterService; | ||
70 | - | ||
71 | - @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) | ||
72 | - protected LeadershipService leadershipService; | ||
73 | - | ||
74 | - @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) | ||
75 | - protected RoutingService routingService; | ||
76 | 52 | ||
77 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) | 53 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
78 | - protected RoutingConfigurationService config; | 54 | + protected InterfaceService interfaceService; |
79 | 55 | ||
80 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) | 56 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
81 | - protected NetworkConfigService networkConfigService; | 57 | + protected IntentSynchronizationService intentSynchronizer; |
82 | 58 | ||
83 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) | 59 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
84 | - protected InterfaceService interfaceService; | 60 | + protected IntentSynchronizationAdminService intentSynchronizerAdmin; |
85 | 61 | ||
86 | - private IntentSynchronizer intentSynchronizer; | ||
87 | private PeerConnectivityManager peerConnectivity; | 62 | private PeerConnectivityManager peerConnectivity; |
88 | - private SdnIpFib fib; | ||
89 | 63 | ||
90 | - private LeadershipEventListener leadershipEventListener = | ||
91 | - new InnerLeadershipEventListener(); | ||
92 | private ApplicationId appId; | 64 | private ApplicationId appId; |
93 | - private ControllerNode localControllerNode; | ||
94 | 65 | ||
95 | @Activate | 66 | @Activate |
96 | protected void activate() { | 67 | protected void activate() { |
97 | - log.info("SDN-IP started"); | ||
98 | - | ||
99 | appId = coreService.registerApplication(SDN_IP_APP); | 68 | appId = coreService.registerApplication(SDN_IP_APP); |
100 | 69 | ||
101 | - localControllerNode = clusterService.getLocalNode(); | ||
102 | - | ||
103 | - intentSynchronizer = new IntentSynchronizer(appId, intentService); | ||
104 | - intentSynchronizer.start(); | ||
105 | - | ||
106 | peerConnectivity = new PeerConnectivityManager(appId, | 70 | peerConnectivity = new PeerConnectivityManager(appId, |
107 | intentSynchronizer, | 71 | intentSynchronizer, |
108 | networkConfigService, | 72 | networkConfigService, |
109 | - coreService.getAppId(RoutingService.ROUTER_APP_ID), | 73 | + coreService.registerApplication(RoutingService.ROUTER_APP_ID), |
110 | interfaceService); | 74 | interfaceService); |
111 | peerConnectivity.start(); | 75 | peerConnectivity.start(); |
112 | 76 | ||
113 | - fib = new SdnIpFib(appId, interfaceService, intentSynchronizer); | 77 | + // TODO fix removing intents |
114 | - | ||
115 | - routingService.addFibListener(fib); | ||
116 | - routingService.start(); | ||
117 | - | ||
118 | - leadershipService.addListener(leadershipEventListener); | ||
119 | - leadershipService.runForLeadership(appId.name()); | ||
120 | - | ||
121 | applicationService.registerDeactivateHook(appId, | 78 | applicationService.registerDeactivateHook(appId, |
122 | - intentSynchronizer::removeIntents); | 79 | + intentSynchronizerAdmin::removeIntents); |
123 | 80 | ||
81 | + log.info("SDN-IP started"); | ||
124 | } | 82 | } |
125 | 83 | ||
126 | @Deactivate | 84 | @Deactivate |
127 | protected void deactivate() { | 85 | protected void deactivate() { |
128 | - routingService.stop(); | ||
129 | peerConnectivity.stop(); | 86 | peerConnectivity.stop(); |
130 | - intentSynchronizer.stop(); | ||
131 | - | ||
132 | - leadershipService.withdraw(appId.name()); | ||
133 | - leadershipService.removeListener(leadershipEventListener); | ||
134 | 87 | ||
135 | log.info("SDN-IP Stopped"); | 88 | log.info("SDN-IP Stopped"); |
136 | } | 89 | } |
137 | 90 | ||
138 | - @Override | ||
139 | - public void modifyPrimary(boolean isPrimary) { | ||
140 | - intentSynchronizer.leaderChanged(isPrimary); | ||
141 | - } | ||
142 | - | ||
143 | - @Override | ||
144 | - public IntentSynchronizationService getIntentSynchronizationService() { | ||
145 | - return intentSynchronizer; | ||
146 | - } | ||
147 | - | ||
148 | /** | 91 | /** |
149 | * Converts DPIDs of the form xx:xx:xx:xx:xx:xx:xx to OpenFlow provider | 92 | * Converts DPIDs of the form xx:xx:xx:xx:xx:xx:xx to OpenFlow provider |
150 | * device URIs. | 93 | * device URIs. |
... | @@ -156,38 +99,5 @@ public class SdnIp implements SdnIpService { | ... | @@ -156,38 +99,5 @@ public class SdnIp implements SdnIpService { |
156 | return "of:" + dpid.replace(":", ""); | 99 | return "of:" + dpid.replace(":", ""); |
157 | } | 100 | } |
158 | 101 | ||
159 | - /** | 102 | + |
160 | - * A listener for Leadership Events. | ||
161 | - */ | ||
162 | - private class InnerLeadershipEventListener | ||
163 | - implements LeadershipEventListener { | ||
164 | - | ||
165 | - @Override | ||
166 | - public void event(LeadershipEvent event) { | ||
167 | - log.debug("Leadership Event: time = {} type = {} event = {}", | ||
168 | - event.time(), event.type(), event); | ||
169 | - | ||
170 | - if (!event.subject().topic().equals(appId.name())) { | ||
171 | - return; // Not our topic: ignore | ||
172 | - } | ||
173 | - if (!Objects.equals(event.subject().leader(), localControllerNode.id())) { | ||
174 | - return; // The event is not about this instance: ignore | ||
175 | - } | ||
176 | - | ||
177 | - switch (event.type()) { | ||
178 | - case LEADER_ELECTED: | ||
179 | - log.info("SDN-IP Leader Elected"); | ||
180 | - intentSynchronizer.leaderChanged(true); | ||
181 | - break; | ||
182 | - case LEADER_BOOTED: | ||
183 | - log.info("SDN-IP Leader Lost Election"); | ||
184 | - intentSynchronizer.leaderChanged(false); | ||
185 | - break; | ||
186 | - case LEADER_REELECTED: | ||
187 | - break; | ||
188 | - default: | ||
189 | - break; | ||
190 | - } | ||
191 | - } | ||
192 | - } | ||
193 | } | 103 | } | ... | ... |
... | @@ -17,12 +17,18 @@ | ... | @@ -17,12 +17,18 @@ |
17 | package org.onosproject.sdnip; | 17 | package org.onosproject.sdnip; |
18 | 18 | ||
19 | import com.google.common.collect.ImmutableList; | 19 | import com.google.common.collect.ImmutableList; |
20 | +import org.apache.felix.scr.annotations.Activate; | ||
21 | +import org.apache.felix.scr.annotations.Component; | ||
22 | +import org.apache.felix.scr.annotations.Deactivate; | ||
23 | +import org.apache.felix.scr.annotations.Reference; | ||
24 | +import org.apache.felix.scr.annotations.ReferenceCardinality; | ||
20 | import org.onlab.packet.Ethernet; | 25 | import org.onlab.packet.Ethernet; |
21 | import org.onlab.packet.IpAddress; | 26 | import org.onlab.packet.IpAddress; |
22 | import org.onlab.packet.IpPrefix; | 27 | import org.onlab.packet.IpPrefix; |
23 | import org.onlab.packet.MacAddress; | 28 | import org.onlab.packet.MacAddress; |
24 | import org.onlab.packet.VlanId; | 29 | import org.onlab.packet.VlanId; |
25 | import org.onosproject.core.ApplicationId; | 30 | import org.onosproject.core.ApplicationId; |
31 | +import org.onosproject.core.CoreService; | ||
26 | import org.onosproject.incubator.net.intf.Interface; | 32 | import org.onosproject.incubator.net.intf.Interface; |
27 | import org.onosproject.incubator.net.intf.InterfaceService; | 33 | import org.onosproject.incubator.net.intf.InterfaceService; |
28 | import org.onosproject.net.ConnectPoint; | 34 | import org.onosproject.net.ConnectPoint; |
... | @@ -37,6 +43,7 @@ import org.onosproject.net.intent.constraint.PartialFailureConstraint; | ... | @@ -37,6 +43,7 @@ import org.onosproject.net.intent.constraint.PartialFailureConstraint; |
37 | import org.onosproject.routing.FibListener; | 43 | import org.onosproject.routing.FibListener; |
38 | import org.onosproject.routing.FibUpdate; | 44 | import org.onosproject.routing.FibUpdate; |
39 | import org.onosproject.routing.IntentSynchronizationService; | 45 | import org.onosproject.routing.IntentSynchronizationService; |
46 | +import org.onosproject.routing.RoutingService; | ||
40 | import org.slf4j.Logger; | 47 | import org.slf4j.Logger; |
41 | import org.slf4j.LoggerFactory; | 48 | import org.slf4j.LoggerFactory; |
42 | 49 | ||
... | @@ -51,40 +58,49 @@ import static com.google.common.base.Preconditions.checkArgument; | ... | @@ -51,40 +58,49 @@ import static com.google.common.base.Preconditions.checkArgument; |
51 | /** | 58 | /** |
52 | * FIB component of SDN-IP. | 59 | * FIB component of SDN-IP. |
53 | */ | 60 | */ |
54 | -public class SdnIpFib implements FibListener { | 61 | +@Component(immediate = true) |
62 | +public class SdnIpFib { | ||
55 | private Logger log = LoggerFactory.getLogger(getClass()); | 63 | private Logger log = LoggerFactory.getLogger(getClass()); |
56 | 64 | ||
65 | + @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) | ||
66 | + protected InterfaceService interfaceService; | ||
67 | + | ||
68 | + @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) | ||
69 | + protected IntentSynchronizationService intentSynchronizer; | ||
70 | + | ||
71 | + @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) | ||
72 | + protected CoreService coreService; | ||
73 | + | ||
74 | + @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) | ||
75 | + protected RoutingService routingService; | ||
76 | + | ||
77 | + private final InternalFibListener fibListener = new InternalFibListener(); | ||
78 | + | ||
57 | private static final int PRIORITY_OFFSET = 100; | 79 | private static final int PRIORITY_OFFSET = 100; |
58 | private static final int PRIORITY_MULTIPLIER = 5; | 80 | private static final int PRIORITY_MULTIPLIER = 5; |
59 | protected static final ImmutableList<Constraint> CONSTRAINTS | 81 | protected static final ImmutableList<Constraint> CONSTRAINTS |
60 | = ImmutableList.of(new PartialFailureConstraint()); | 82 | = ImmutableList.of(new PartialFailureConstraint()); |
61 | 83 | ||
62 | - private final Map<IpPrefix, MultiPointToSinglePointIntent> routeIntents; | 84 | + private final Map<IpPrefix, MultiPointToSinglePointIntent> routeIntents |
85 | + = new ConcurrentHashMap<>(); | ||
63 | 86 | ||
64 | - private final ApplicationId appId; | 87 | + private ApplicationId appId; |
65 | - private final InterfaceService interfaceService; | ||
66 | - private final IntentSynchronizationService intentSynchronizer; | ||
67 | 88 | ||
68 | - /** | 89 | + @Activate |
69 | - * Class constructor. | 90 | + public void activate() { |
70 | - * | 91 | + appId = coreService.getAppId(SdnIp.SDN_IP_APP); |
71 | - * @param appId application ID to use when generating intents | ||
72 | - * @param interfaceService interface service | ||
73 | - * @param intentSynchronizer intent synchronizer | ||
74 | - */ | ||
75 | - public SdnIpFib(ApplicationId appId, InterfaceService interfaceService, | ||
76 | - IntentSynchronizationService intentSynchronizer) { | ||
77 | - routeIntents = new ConcurrentHashMap<>(); | ||
78 | 92 | ||
79 | - this.appId = appId; | 93 | + routingService.addFibListener(fibListener); |
80 | - this.interfaceService = interfaceService; | 94 | + routingService.start(); |
81 | - this.intentSynchronizer = intentSynchronizer; | ||
82 | } | 95 | } |
83 | 96 | ||
97 | + @Deactivate | ||
98 | + public void deactivate() { | ||
99 | + // TODO remove listener | ||
100 | + routingService.stop(); | ||
101 | + } | ||
84 | 102 | ||
85 | - @Override | 103 | + private void update(Collection<FibUpdate> updates, Collection<FibUpdate> withdraws) { |
86 | - public void update(Collection<FibUpdate> updates, | ||
87 | - Collection<FibUpdate> withdraws) { | ||
88 | int submitCount = 0, withdrawCount = 0; | 104 | int submitCount = 0, withdrawCount = 0; |
89 | // | 105 | // |
90 | // NOTE: Semantically, we MUST withdraw existing intents before | 106 | // NOTE: Semantically, we MUST withdraw existing intents before |
... | @@ -224,4 +240,11 @@ public class SdnIpFib implements FibListener { | ... | @@ -224,4 +240,11 @@ public class SdnIpFib implements FibListener { |
224 | .build(); | 240 | .build(); |
225 | } | 241 | } |
226 | 242 | ||
243 | + private class InternalFibListener implements FibListener { | ||
244 | + @Override | ||
245 | + public void update(Collection<FibUpdate> updates, Collection<FibUpdate> withdraws) { | ||
246 | + SdnIpFib.this.update(updates, withdraws); | ||
247 | + } | ||
248 | + } | ||
249 | + | ||
227 | } | 250 | } | ... | ... |
... | @@ -18,10 +18,10 @@ package org.onosproject.sdnip.cli; | ... | @@ -18,10 +18,10 @@ package org.onosproject.sdnip.cli; |
18 | import org.apache.karaf.shell.commands.Argument; | 18 | import org.apache.karaf.shell.commands.Argument; |
19 | import org.apache.karaf.shell.commands.Command; | 19 | import org.apache.karaf.shell.commands.Command; |
20 | import org.onosproject.cli.AbstractShellCommand; | 20 | import org.onosproject.cli.AbstractShellCommand; |
21 | -import org.onosproject.routing.SdnIpService; | 21 | +import org.onosproject.routing.IntentSynchronizationAdminService; |
22 | 22 | ||
23 | /** | 23 | /** |
24 | - * Command to change whether this SDNIP instance is primary or not. | 24 | + * Command to change whether this instance's intent synchronizer is primary. |
25 | */ | 25 | */ |
26 | @Command(scope = "onos", name = "sdnip-set-primary", | 26 | @Command(scope = "onos", name = "sdnip-set-primary", |
27 | description = "Changes the primary status of this SDN-IP instance") | 27 | description = "Changes the primary status of this SDN-IP instance") |
... | @@ -34,7 +34,7 @@ public class PrimaryChangeCommand extends AbstractShellCommand { | ... | @@ -34,7 +34,7 @@ public class PrimaryChangeCommand extends AbstractShellCommand { |
34 | 34 | ||
35 | @Override | 35 | @Override |
36 | protected void execute() { | 36 | protected void execute() { |
37 | - get(SdnIpService.class).modifyPrimary(isPrimary); | 37 | + get(IntentSynchronizationAdminService.class).modifyPrimary(isPrimary); |
38 | } | 38 | } |
39 | 39 | ||
40 | } | 40 | } | ... | ... |
... | @@ -29,7 +29,9 @@ import org.onlab.packet.IpPrefix; | ... | @@ -29,7 +29,9 @@ import org.onlab.packet.IpPrefix; |
29 | import org.onlab.packet.MacAddress; | 29 | import org.onlab.packet.MacAddress; |
30 | import org.onlab.packet.VlanId; | 30 | import org.onlab.packet.VlanId; |
31 | import org.onosproject.TestApplicationId; | 31 | import org.onosproject.TestApplicationId; |
32 | +import org.onosproject.cluster.LeadershipServiceAdapter; | ||
32 | import org.onosproject.core.ApplicationId; | 33 | import org.onosproject.core.ApplicationId; |
34 | +import org.onosproject.core.CoreServiceAdapter; | ||
33 | import org.onosproject.incubator.net.intf.Interface; | 35 | import org.onosproject.incubator.net.intf.Interface; |
34 | import org.onosproject.net.ConnectPoint; | 36 | import org.onosproject.net.ConnectPoint; |
35 | import org.onosproject.net.DeviceId; | 37 | import org.onosproject.net.DeviceId; |
... | @@ -43,14 +45,15 @@ import org.onosproject.net.intent.AbstractIntentTest; | ... | @@ -43,14 +45,15 @@ import org.onosproject.net.intent.AbstractIntentTest; |
43 | import org.onosproject.net.intent.Intent; | 45 | import org.onosproject.net.intent.Intent; |
44 | import org.onosproject.net.intent.IntentService; | 46 | import org.onosproject.net.intent.IntentService; |
45 | import org.onosproject.net.intent.IntentState; | 47 | import org.onosproject.net.intent.IntentState; |
48 | +import org.onosproject.net.intent.IntentUtils; | ||
46 | import org.onosproject.net.intent.Key; | 49 | import org.onosproject.net.intent.Key; |
47 | import org.onosproject.net.intent.MultiPointToSinglePointIntent; | 50 | import org.onosproject.net.intent.MultiPointToSinglePointIntent; |
48 | -import org.onosproject.net.intent.IntentUtils; | ||
49 | import org.onosproject.routing.RouteEntry; | 51 | import org.onosproject.routing.RouteEntry; |
50 | 52 | ||
51 | import java.util.Collections; | 53 | import java.util.Collections; |
52 | import java.util.HashSet; | 54 | import java.util.HashSet; |
53 | import java.util.Set; | 55 | import java.util.Set; |
56 | +import java.util.concurrent.ExecutorService; | ||
54 | 57 | ||
55 | import static org.easymock.EasyMock.createMock; | 58 | import static org.easymock.EasyMock.createMock; |
56 | import static org.easymock.EasyMock.expect; | 59 | import static org.easymock.EasyMock.expect; |
... | @@ -88,7 +91,8 @@ public class IntentSyncTest extends AbstractIntentTest { | ... | @@ -88,7 +91,8 @@ public class IntentSyncTest extends AbstractIntentTest { |
88 | private IntentSynchronizer intentSynchronizer; | 91 | private IntentSynchronizer intentSynchronizer; |
89 | private final Set<Interface> interfaces = Sets.newHashSet(); | 92 | private final Set<Interface> interfaces = Sets.newHashSet(); |
90 | 93 | ||
91 | - private static final ApplicationId APPID = TestApplicationId.create("SDNIP"); | 94 | + private static final ApplicationId APPID = |
95 | + TestApplicationId.create("intent-sync-test"); | ||
92 | 96 | ||
93 | @Before | 97 | @Before |
94 | public void setUp() throws Exception { | 98 | public void setUp() throws Exception { |
... | @@ -98,8 +102,13 @@ public class IntentSyncTest extends AbstractIntentTest { | ... | @@ -98,8 +102,13 @@ public class IntentSyncTest extends AbstractIntentTest { |
98 | 102 | ||
99 | intentService = createMock(IntentService.class); | 103 | intentService = createMock(IntentService.class); |
100 | 104 | ||
101 | - intentSynchronizer = new IntentSynchronizer(APPID, intentService, | 105 | + intentSynchronizer = new TestIntentSynchronizer(); |
102 | - MoreExecutors.newDirectExecutorService()); | 106 | + |
107 | + intentSynchronizer.coreService = new TestCoreService(); | ||
108 | + intentSynchronizer.leadershipService = new TestLeadershipService(); | ||
109 | + intentSynchronizer.intentService = intentService; | ||
110 | + | ||
111 | + intentSynchronizer.activate(); | ||
103 | } | 112 | } |
104 | 113 | ||
105 | /** | 114 | /** |
... | @@ -268,7 +277,7 @@ public class IntentSyncTest extends AbstractIntentTest { | ... | @@ -268,7 +277,7 @@ public class IntentSyncTest extends AbstractIntentTest { |
268 | // Give the leadership to the intent synchronizer. It will now attempt | 277 | // Give the leadership to the intent synchronizer. It will now attempt |
269 | // to synchronize the intents in the store with the intents it has | 278 | // to synchronize the intents in the store with the intents it has |
270 | // recorded based on the earlier user input. | 279 | // recorded based on the earlier user input. |
271 | - intentSynchronizer.leaderChanged(true); | 280 | + intentSynchronizer.modifyPrimary(true); |
272 | 281 | ||
273 | verify(intentService); | 282 | verify(intentService); |
274 | } | 283 | } |
... | @@ -290,7 +299,7 @@ public class IntentSyncTest extends AbstractIntentTest { | ... | @@ -290,7 +299,7 @@ public class IntentSyncTest extends AbstractIntentTest { |
290 | 299 | ||
291 | // Give the intent synchronizer leadership so it will submit intents | 300 | // Give the intent synchronizer leadership so it will submit intents |
292 | // to the intent service | 301 | // to the intent service |
293 | - intentSynchronizer.leaderChanged(true); | 302 | + intentSynchronizer.modifyPrimary(true); |
294 | 303 | ||
295 | // Test the submit | 304 | // Test the submit |
296 | intentSynchronizer.submit(intent); | 305 | intentSynchronizer.submit(intent); |
... | @@ -303,7 +312,7 @@ public class IntentSyncTest extends AbstractIntentTest { | ... | @@ -303,7 +312,7 @@ public class IntentSyncTest extends AbstractIntentTest { |
303 | reset(intentService); | 312 | reset(intentService); |
304 | replay(intentService); | 313 | replay(intentService); |
305 | 314 | ||
306 | - intentSynchronizer.leaderChanged(false); | 315 | + intentSynchronizer.modifyPrimary(false); |
307 | 316 | ||
308 | intentSynchronizer.submit(intent); | 317 | intentSynchronizer.submit(intent); |
309 | 318 | ||
... | @@ -328,7 +337,7 @@ public class IntentSyncTest extends AbstractIntentTest { | ... | @@ -328,7 +337,7 @@ public class IntentSyncTest extends AbstractIntentTest { |
328 | 337 | ||
329 | // Give the intent synchronizer leadership so it will submit intents | 338 | // Give the intent synchronizer leadership so it will submit intents |
330 | // to the intent service | 339 | // to the intent service |
331 | - intentSynchronizer.leaderChanged(true); | 340 | + intentSynchronizer.modifyPrimary(true); |
332 | 341 | ||
333 | // Test the submit then withdraw | 342 | // Test the submit then withdraw |
334 | intentSynchronizer.submit(intent); | 343 | intentSynchronizer.submit(intent); |
... | @@ -342,7 +351,7 @@ public class IntentSyncTest extends AbstractIntentTest { | ... | @@ -342,7 +351,7 @@ public class IntentSyncTest extends AbstractIntentTest { |
342 | reset(intentService); | 351 | reset(intentService); |
343 | replay(intentService); | 352 | replay(intentService); |
344 | 353 | ||
345 | - intentSynchronizer.leaderChanged(false); | 354 | + intentSynchronizer.modifyPrimary(false); |
346 | 355 | ||
347 | intentSynchronizer.submit(intent); | 356 | intentSynchronizer.submit(intent); |
348 | intentSynchronizer.withdraw(intent); | 357 | intentSynchronizer.withdraw(intent); |
... | @@ -418,4 +427,22 @@ public class IntentSyncTest extends AbstractIntentTest { | ... | @@ -418,4 +427,22 @@ public class IntentSyncTest extends AbstractIntentTest { |
418 | "ingressPoints", intent.ingressPoints()); | 427 | "ingressPoints", intent.ingressPoints()); |
419 | return intentNew; | 428 | return intentNew; |
420 | } | 429 | } |
430 | + | ||
431 | + private class TestIntentSynchronizer extends IntentSynchronizer { | ||
432 | + @Override | ||
433 | + protected ExecutorService createExecutor() { | ||
434 | + return MoreExecutors.newDirectExecutorService(); | ||
435 | + } | ||
436 | + } | ||
437 | + | ||
438 | + private class TestCoreService extends CoreServiceAdapter { | ||
439 | + @Override | ||
440 | + public ApplicationId registerApplication(String name) { | ||
441 | + return APPID; | ||
442 | + } | ||
443 | + } | ||
444 | + | ||
445 | + private class TestLeadershipService extends LeadershipServiceAdapter { | ||
446 | + | ||
447 | + } | ||
421 | } | 448 | } | ... | ... |
... | @@ -28,6 +28,7 @@ import org.onlab.packet.MacAddress; | ... | @@ -28,6 +28,7 @@ import org.onlab.packet.MacAddress; |
28 | import org.onlab.packet.VlanId; | 28 | import org.onlab.packet.VlanId; |
29 | import org.onosproject.TestApplicationId; | 29 | import org.onosproject.TestApplicationId; |
30 | import org.onosproject.core.ApplicationId; | 30 | import org.onosproject.core.ApplicationId; |
31 | +import org.onosproject.core.CoreServiceAdapter; | ||
31 | import org.onosproject.incubator.net.intf.Interface; | 32 | import org.onosproject.incubator.net.intf.Interface; |
32 | import org.onosproject.incubator.net.intf.InterfaceService; | 33 | import org.onosproject.incubator.net.intf.InterfaceService; |
33 | import org.onosproject.net.ConnectPoint; | 34 | import org.onosproject.net.ConnectPoint; |
... | @@ -42,8 +43,10 @@ import org.onosproject.net.intent.AbstractIntentTest; | ... | @@ -42,8 +43,10 @@ import org.onosproject.net.intent.AbstractIntentTest; |
42 | import org.onosproject.net.intent.Key; | 43 | import org.onosproject.net.intent.Key; |
43 | import org.onosproject.net.intent.MultiPointToSinglePointIntent; | 44 | import org.onosproject.net.intent.MultiPointToSinglePointIntent; |
44 | import org.onosproject.routing.FibEntry; | 45 | import org.onosproject.routing.FibEntry; |
46 | +import org.onosproject.routing.FibListener; | ||
45 | import org.onosproject.routing.FibUpdate; | 47 | import org.onosproject.routing.FibUpdate; |
46 | import org.onosproject.routing.IntentSynchronizationService; | 48 | import org.onosproject.routing.IntentSynchronizationService; |
49 | +import org.onosproject.routing.RoutingServiceAdapter; | ||
47 | import org.onosproject.routing.config.BgpPeer; | 50 | import org.onosproject.routing.config.BgpPeer; |
48 | import org.onosproject.routing.config.RoutingConfigurationService; | 51 | import org.onosproject.routing.config.RoutingConfigurationService; |
49 | 52 | ||
... | @@ -90,6 +93,8 @@ public class SdnIpFibTest extends AbstractIntentTest { | ... | @@ -90,6 +93,8 @@ public class SdnIpFibTest extends AbstractIntentTest { |
90 | 93 | ||
91 | private static final ApplicationId APPID = TestApplicationId.create("SDNIP"); | 94 | private static final ApplicationId APPID = TestApplicationId.create("SDNIP"); |
92 | 95 | ||
96 | + private FibListener fibListener; | ||
97 | + | ||
93 | @Before | 98 | @Before |
94 | public void setUp() throws Exception { | 99 | public void setUp() throws Exception { |
95 | super.setUp(); | 100 | super.setUp(); |
... | @@ -106,7 +111,13 @@ public class SdnIpFibTest extends AbstractIntentTest { | ... | @@ -106,7 +111,13 @@ public class SdnIpFibTest extends AbstractIntentTest { |
106 | 111 | ||
107 | intentSynchronizer = createMock(IntentSynchronizationService.class); | 112 | intentSynchronizer = createMock(IntentSynchronizationService.class); |
108 | 113 | ||
109 | - sdnipFib = new SdnIpFib(APPID, interfaceService, intentSynchronizer); | 114 | + sdnipFib = new SdnIpFib(); |
115 | + sdnipFib.routingService = new TestRoutingService(); | ||
116 | + sdnipFib.coreService = new TestCoreService(); | ||
117 | + sdnipFib.interfaceService = interfaceService; | ||
118 | + sdnipFib.intentSynchronizer = intentSynchronizer; | ||
119 | + | ||
120 | + sdnipFib.activate(); | ||
110 | } | 121 | } |
111 | 122 | ||
112 | /** | 123 | /** |
... | @@ -242,7 +253,7 @@ public class SdnIpFibTest extends AbstractIntentTest { | ... | @@ -242,7 +253,7 @@ public class SdnIpFibTest extends AbstractIntentTest { |
242 | 253 | ||
243 | // Send in the UPDATE FibUpdate | 254 | // Send in the UPDATE FibUpdate |
244 | FibUpdate fibUpdate = new FibUpdate(FibUpdate.Type.UPDATE, fibEntry); | 255 | FibUpdate fibUpdate = new FibUpdate(FibUpdate.Type.UPDATE, fibEntry); |
245 | - sdnipFib.update(Collections.singleton(fibUpdate), Collections.emptyList()); | 256 | + fibListener.update(Collections.singleton(fibUpdate), Collections.emptyList()); |
246 | 257 | ||
247 | verify(intentSynchronizer); | 258 | verify(intentSynchronizer); |
248 | } | 259 | } |
... | @@ -295,7 +306,7 @@ public class SdnIpFibTest extends AbstractIntentTest { | ... | @@ -295,7 +306,7 @@ public class SdnIpFibTest extends AbstractIntentTest { |
295 | 306 | ||
296 | // Send in the UPDATE FibUpdate | 307 | // Send in the UPDATE FibUpdate |
297 | FibUpdate fibUpdate = new FibUpdate(FibUpdate.Type.UPDATE, fibEntry); | 308 | FibUpdate fibUpdate = new FibUpdate(FibUpdate.Type.UPDATE, fibEntry); |
298 | - sdnipFib.update(Collections.singleton(fibUpdate), Collections.emptyList()); | 309 | + fibListener.update(Collections.singleton(fibUpdate), Collections.emptyList()); |
299 | 310 | ||
300 | verify(intentSynchronizer); | 311 | verify(intentSynchronizer); |
301 | } | 312 | } |
... | @@ -354,7 +365,7 @@ public class SdnIpFibTest extends AbstractIntentTest { | ... | @@ -354,7 +365,7 @@ public class SdnIpFibTest extends AbstractIntentTest { |
354 | // Send in the UPDATE FibUpdate | 365 | // Send in the UPDATE FibUpdate |
355 | FibUpdate fibUpdate = new FibUpdate(FibUpdate.Type.UPDATE, | 366 | FibUpdate fibUpdate = new FibUpdate(FibUpdate.Type.UPDATE, |
356 | fibEntryUpdate); | 367 | fibEntryUpdate); |
357 | - sdnipFib.update(Collections.singletonList(fibUpdate), | 368 | + fibListener.update(Collections.singletonList(fibUpdate), |
358 | Collections.emptyList()); | 369 | Collections.emptyList()); |
359 | 370 | ||
360 | verify(intentSynchronizer); | 371 | verify(intentSynchronizer); |
... | @@ -410,8 +421,23 @@ public class SdnIpFibTest extends AbstractIntentTest { | ... | @@ -410,8 +421,23 @@ public class SdnIpFibTest extends AbstractIntentTest { |
410 | 421 | ||
411 | // Send in the DELETE FibUpdate | 422 | // Send in the DELETE FibUpdate |
412 | FibUpdate fibUpdate = new FibUpdate(FibUpdate.Type.DELETE, fibEntry); | 423 | FibUpdate fibUpdate = new FibUpdate(FibUpdate.Type.DELETE, fibEntry); |
413 | - sdnipFib.update(Collections.emptyList(), Collections.singletonList(fibUpdate)); | 424 | + fibListener.update(Collections.emptyList(), Collections.singletonList(fibUpdate)); |
414 | 425 | ||
415 | verify(intentSynchronizer); | 426 | verify(intentSynchronizer); |
416 | } | 427 | } |
428 | + | ||
429 | + private class TestCoreService extends CoreServiceAdapter { | ||
430 | + @Override | ||
431 | + public ApplicationId getAppId(String name) { | ||
432 | + return APPID; | ||
433 | + } | ||
434 | + } | ||
435 | + | ||
436 | + private class TestRoutingService extends RoutingServiceAdapter { | ||
437 | + | ||
438 | + @Override | ||
439 | + public void addFibListener(FibListener fibListener) { | ||
440 | + SdnIpFibTest.this.fibListener = fibListener; | ||
441 | + } | ||
442 | + } | ||
417 | } | 443 | } | ... | ... |
-
Please register or login to post a comment