Merge branch 'master' of ssh://gerrit.onlab.us:29418/onos-next
Showing
12 changed files
with
330 additions
and
78 deletions
1 | package org.onlab.onos.net.intent; | 1 | package org.onlab.onos.net.intent; |
2 | 2 | ||
3 | -import java.util.concurrent.Future; | 3 | +import java.util.List; |
4 | 4 | ||
5 | -import org.onlab.onos.net.flow.CompletedBatchOperation; | 5 | +import org.onlab.onos.net.flow.FlowRuleBatchOperation; |
6 | 6 | ||
7 | /** | 7 | /** |
8 | * Abstraction of entity capable of installing intents to the environment. | 8 | * Abstraction of entity capable of installing intents to the environment. |
... | @@ -14,7 +14,7 @@ public interface IntentInstaller<T extends InstallableIntent> { | ... | @@ -14,7 +14,7 @@ public interface IntentInstaller<T extends InstallableIntent> { |
14 | * @param intent intent to be installed | 14 | * @param intent intent to be installed |
15 | * @throws IntentException if issues are encountered while installing the intent | 15 | * @throws IntentException if issues are encountered while installing the intent |
16 | */ | 16 | */ |
17 | - Future<CompletedBatchOperation> install(T intent); | 17 | + List<FlowRuleBatchOperation> install(T intent); |
18 | 18 | ||
19 | /** | 19 | /** |
20 | * Uninstalls the specified intent from the environment. | 20 | * Uninstalls the specified intent from the environment. |
... | @@ -22,5 +22,5 @@ public interface IntentInstaller<T extends InstallableIntent> { | ... | @@ -22,5 +22,5 @@ public interface IntentInstaller<T extends InstallableIntent> { |
22 | * @param intent intent to be uninstalled | 22 | * @param intent intent to be uninstalled |
23 | * @throws IntentException if issues are encountered while uninstalling the intent | 23 | * @throws IntentException if issues are encountered while uninstalling the intent |
24 | */ | 24 | */ |
25 | - Future<CompletedBatchOperation> uninstall(T intent); | 25 | + List<FlowRuleBatchOperation> uninstall(T intent); |
26 | } | 26 | } | ... | ... |
1 | +package org.onlab.onos.net.resource; | ||
2 | + | ||
3 | +import java.util.Objects; | ||
4 | + | ||
5 | +/** | ||
6 | + * Representation of bandwidth resource. | ||
7 | + */ | ||
8 | +public final class Bandwidth extends LinkResource { | ||
9 | + | ||
10 | + private final double bandwidth; | ||
11 | + | ||
12 | + /** | ||
13 | + * Creates a new instance with given bandwidth. | ||
14 | + * | ||
15 | + * @param bandwidth bandwidth value to be assigned | ||
16 | + */ | ||
17 | + private Bandwidth(double bandwidth) { | ||
18 | + this.bandwidth = bandwidth; | ||
19 | + } | ||
20 | + | ||
21 | + /** | ||
22 | + * Creates a new instance with given bandwidth. | ||
23 | + * | ||
24 | + * @param bandwidth bandwidth value to be assigned | ||
25 | + * @return {@link Bandwidth} instance with given bandwidth | ||
26 | + */ | ||
27 | + public static Bandwidth valueOf(double bandwidth) { | ||
28 | + return new Bandwidth(bandwidth); | ||
29 | + } | ||
30 | + | ||
31 | + /** | ||
32 | + * Returns bandwidth as a double value. | ||
33 | + * | ||
34 | + * @return bandwidth as a double value | ||
35 | + */ | ||
36 | + public double toDouble() { | ||
37 | + return bandwidth; | ||
38 | + } | ||
39 | + | ||
40 | + @Override | ||
41 | + public boolean equals(Object obj) { | ||
42 | + if (obj instanceof Bandwidth) { | ||
43 | + Bandwidth that = (Bandwidth) obj; | ||
44 | + return Objects.equals(this.bandwidth, that.bandwidth); | ||
45 | + } | ||
46 | + return false; | ||
47 | + } | ||
48 | + | ||
49 | + @Override | ||
50 | + public int hashCode() { | ||
51 | + return Objects.hashCode(this.bandwidth); | ||
52 | + } | ||
53 | + | ||
54 | + @Override | ||
55 | + public String toString() { | ||
56 | + return String.valueOf(this.bandwidth); | ||
57 | + } | ||
58 | +} |
1 | +package org.onlab.onos.net.resource; | ||
2 | + | ||
3 | +import java.util.Objects; | ||
4 | + | ||
5 | +/** | ||
6 | + * Representation of lambda resource. | ||
7 | + */ | ||
8 | +public final class Lambda extends LinkResource { | ||
9 | + | ||
10 | + private final int lambda; | ||
11 | + | ||
12 | + /** | ||
13 | + * Creates a new instance with given lambda. | ||
14 | + * | ||
15 | + * @param lambda lambda value to be assigned | ||
16 | + */ | ||
17 | + private Lambda(int lambda) { | ||
18 | + this.lambda = lambda; | ||
19 | + } | ||
20 | + | ||
21 | + /** | ||
22 | + * Creates a new instance with given lambda. | ||
23 | + * | ||
24 | + * @param lambda lambda value to be assigned | ||
25 | + * @return {@link Lambda} instance with given lambda | ||
26 | + */ | ||
27 | + public static Lambda valueOf(int lambda) { | ||
28 | + return new Lambda(lambda); | ||
29 | + } | ||
30 | + | ||
31 | + /** | ||
32 | + * Returns lambda as an int value. | ||
33 | + * @return lambda as an int value | ||
34 | + */ | ||
35 | + public int toInt() { | ||
36 | + return lambda; | ||
37 | + } | ||
38 | + | ||
39 | + @Override | ||
40 | + public boolean equals(Object obj) { | ||
41 | + if (obj instanceof Lambda) { | ||
42 | + Lambda that = (Lambda) obj; | ||
43 | + return Objects.equals(this.lambda, that.lambda); | ||
44 | + } | ||
45 | + return false; | ||
46 | + } | ||
47 | + | ||
48 | + @Override | ||
49 | + public int hashCode() { | ||
50 | + return Objects.hashCode(this.lambda); | ||
51 | + } | ||
52 | + | ||
53 | + @Override | ||
54 | + public String toString() { | ||
55 | + return String.valueOf(this.lambda); | ||
56 | + } | ||
57 | + | ||
58 | +} |
1 | +package org.onlab.onos.net.resource; | ||
2 | + | ||
3 | +import java.util.Map; | ||
4 | + | ||
5 | +import org.onlab.onos.net.Link; | ||
6 | +import org.onlab.onos.net.intent.IntentId; | ||
7 | +import org.onlab.onos.net.intent.PathIntent; | ||
8 | + | ||
9 | +/** | ||
10 | + * Service for providing link resource allocation. | ||
11 | + */ | ||
12 | +public interface LinkResourceService { | ||
13 | + | ||
14 | + /** | ||
15 | + * Allocates resources along the path. | ||
16 | + * <p> | ||
17 | + * Tries to allocate given resources on the links along the path specified | ||
18 | + * by the given intent. | ||
19 | + * | ||
20 | + * @param res resources to be allocated | ||
21 | + * @param intent an intent to be used for specifying the path | ||
22 | + */ | ||
23 | + void allocateResource(LinkResources res, PathIntent intent); | ||
24 | + | ||
25 | + /** | ||
26 | + * Releases resources along the path. | ||
27 | + * | ||
28 | + * @param intentId an ID for the intent for specifying the path | ||
29 | + */ | ||
30 | + void releaseResource(IntentId intentId); | ||
31 | + | ||
32 | + /** | ||
33 | + * Returns all allocated resources to each link. | ||
34 | + * | ||
35 | + * @return allocated resources to each link with {@link IntentId} | ||
36 | + */ | ||
37 | + Map<Link, Map<IntentId, LinkResources>> allocatedResources(); | ||
38 | + | ||
39 | + /** | ||
40 | + * Returns all allocated resources to given link. | ||
41 | + * | ||
42 | + * @param link a target link | ||
43 | + * @return allocated resources to the target link with {@link IntentId} | ||
44 | + */ | ||
45 | + Map<IntentId, LinkResources> allocatedResources(Link link); | ||
46 | + | ||
47 | + /** | ||
48 | + * Returns available resources for each link. | ||
49 | + * | ||
50 | + * @return available resources for each link | ||
51 | + */ | ||
52 | + Map<Link, LinkResources> availableResources(); | ||
53 | + | ||
54 | + /** | ||
55 | + * Returns available resources for given link. | ||
56 | + * @param link a target link | ||
57 | + * @return available resources for the target link | ||
58 | + */ | ||
59 | + LinkResources availableResources(Link link); | ||
60 | +} |
1 | +package org.onlab.onos.net.resource; | ||
2 | + | ||
3 | +import java.util.Set; | ||
4 | + | ||
5 | +/** | ||
6 | + * Abstraction of a resources of a link. | ||
7 | + */ | ||
8 | +public interface LinkResources { | ||
9 | + | ||
10 | + /** | ||
11 | + * Returns resources as a set of {@link LinkResource}s. | ||
12 | + * | ||
13 | + * @return a set of {@link LinkResource}s | ||
14 | + */ | ||
15 | + Set<LinkResource> resources(); | ||
16 | + | ||
17 | + /** | ||
18 | + * Builder of {@link LinkResources}. | ||
19 | + */ | ||
20 | + public interface Builder { | ||
21 | + | ||
22 | + /** | ||
23 | + * Adds bandwidth resource. | ||
24 | + * <p> | ||
25 | + * This operation adds given bandwidth to previous bandwidth and | ||
26 | + * generates single bandwidth resource. | ||
27 | + * | ||
28 | + * @param bandwidth bandwidth value to be added | ||
29 | + * @return self | ||
30 | + */ | ||
31 | + public Builder addBandwidth(double bandwidth); | ||
32 | + | ||
33 | + /** | ||
34 | + * Adds lambda resource. | ||
35 | + * | ||
36 | + * @param lambda lambda value to be added | ||
37 | + * @return self | ||
38 | + */ | ||
39 | + public Builder addLambda(int lambda); | ||
40 | + | ||
41 | + /** | ||
42 | + * Builds an immutable link resources. | ||
43 | + * | ||
44 | + * @return link resources | ||
45 | + */ | ||
46 | + public LinkResources build(); | ||
47 | + } | ||
48 | +} |
... | @@ -14,12 +14,11 @@ import java.util.Arrays; | ... | @@ -14,12 +14,11 @@ import java.util.Arrays; |
14 | import java.util.Collections; | 14 | import java.util.Collections; |
15 | import java.util.Iterator; | 15 | import java.util.Iterator; |
16 | import java.util.List; | 16 | import java.util.List; |
17 | -import java.util.concurrent.Future; | ||
18 | 17 | ||
19 | import org.junit.After; | 18 | import org.junit.After; |
20 | import org.junit.Before; | 19 | import org.junit.Before; |
21 | import org.junit.Test; | 20 | import org.junit.Test; |
22 | -import org.onlab.onos.net.flow.CompletedBatchOperation; | 21 | +import org.onlab.onos.net.flow.FlowRuleBatchOperation; |
23 | 22 | ||
24 | /** | 23 | /** |
25 | * Suite of tests for the intent service contract. | 24 | * Suite of tests for the intent service contract. |
... | @@ -298,7 +297,7 @@ public class IntentServiceTest { | ... | @@ -298,7 +297,7 @@ public class IntentServiceTest { |
298 | } | 297 | } |
299 | 298 | ||
300 | @Override | 299 | @Override |
301 | - public Future<CompletedBatchOperation> install(TestInstallableIntent intent) { | 300 | + public List<FlowRuleBatchOperation> install(TestInstallableIntent intent) { |
302 | if (fail) { | 301 | if (fail) { |
303 | throw new IntentException("install failed by design"); | 302 | throw new IntentException("install failed by design"); |
304 | } | 303 | } |
... | @@ -306,7 +305,7 @@ public class IntentServiceTest { | ... | @@ -306,7 +305,7 @@ public class IntentServiceTest { |
306 | } | 305 | } |
307 | 306 | ||
308 | @Override | 307 | @Override |
309 | - public Future<CompletedBatchOperation> uninstall(TestInstallableIntent intent) { | 308 | + public List<FlowRuleBatchOperation> uninstall(TestInstallableIntent intent) { |
310 | if (fail) { | 309 | if (fail) { |
311 | throw new IntentException("remove failed by design"); | 310 | throw new IntentException("remove failed by design"); |
312 | } | 311 | } | ... | ... |
... | @@ -34,6 +34,8 @@ import org.apache.felix.scr.annotations.Service; | ... | @@ -34,6 +34,8 @@ import org.apache.felix.scr.annotations.Service; |
34 | import org.onlab.onos.event.AbstractListenerRegistry; | 34 | import org.onlab.onos.event.AbstractListenerRegistry; |
35 | import org.onlab.onos.event.EventDeliveryService; | 35 | import org.onlab.onos.event.EventDeliveryService; |
36 | import org.onlab.onos.net.flow.CompletedBatchOperation; | 36 | import org.onlab.onos.net.flow.CompletedBatchOperation; |
37 | +import org.onlab.onos.net.flow.FlowRuleBatchOperation; | ||
38 | +import org.onlab.onos.net.flow.FlowRuleService; | ||
37 | import org.onlab.onos.net.intent.InstallableIntent; | 39 | import org.onlab.onos.net.intent.InstallableIntent; |
38 | import org.onlab.onos.net.intent.Intent; | 40 | import org.onlab.onos.net.intent.Intent; |
39 | import org.onlab.onos.net.intent.IntentCompiler; | 41 | import org.onlab.onos.net.intent.IntentCompiler; |
... | @@ -90,6 +92,9 @@ public class IntentManager | ... | @@ -90,6 +92,9 @@ public class IntentManager |
90 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) | 92 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
91 | protected EventDeliveryService eventDispatcher; | 93 | protected EventDeliveryService eventDispatcher; |
92 | 94 | ||
95 | + @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) | ||
96 | + protected FlowRuleService flowRuleService; | ||
97 | + | ||
93 | @Activate | 98 | @Activate |
94 | public void activate() { | 99 | public void activate() { |
95 | store.setDelegate(delegate); | 100 | store.setDelegate(delegate); |
... | @@ -283,7 +288,7 @@ public class IntentManager | ... | @@ -283,7 +288,7 @@ public class IntentManager |
283 | // Indicate that the intent is entering the installing phase. | 288 | // Indicate that the intent is entering the installing phase. |
284 | store.setState(intent, INSTALLING); | 289 | store.setState(intent, INSTALLING); |
285 | 290 | ||
286 | - List<Future<CompletedBatchOperation>> installFutures = Lists.newArrayList(); | 291 | + List<FlowRuleBatchOperation> installWork = Lists.newArrayList(); |
287 | try { | 292 | try { |
288 | List<InstallableIntent> installables = store.getInstallableIntents(intent.id()); | 293 | List<InstallableIntent> installables = store.getInstallableIntents(intent.id()); |
289 | if (installables != null) { | 294 | if (installables != null) { |
... | @@ -291,13 +296,13 @@ public class IntentManager | ... | @@ -291,13 +296,13 @@ public class IntentManager |
291 | registerSubclassInstallerIfNeeded(installable); | 296 | registerSubclassInstallerIfNeeded(installable); |
292 | trackerService.addTrackedResources(intent.id(), | 297 | trackerService.addTrackedResources(intent.id(), |
293 | installable.requiredLinks()); | 298 | installable.requiredLinks()); |
294 | - Future<CompletedBatchOperation> future = getInstaller(installable).install(installable); | 299 | + List<FlowRuleBatchOperation> batch = getInstaller(installable).install(installable); |
295 | - installFutures.add(future); | 300 | + installWork.addAll(batch); |
296 | } | 301 | } |
297 | } | 302 | } |
298 | // FIXME we have to wait for the installable intents | 303 | // FIXME we have to wait for the installable intents |
299 | //eventDispatcher.post(store.setState(intent, INSTALLED)); | 304 | //eventDispatcher.post(store.setState(intent, INSTALLED)); |
300 | - monitorExecutor.execute(new IntentInstallMonitor(intent, installFutures, INSTALLED)); | 305 | + monitorExecutor.execute(new IntentInstallMonitor(intent, installWork, INSTALLED)); |
301 | } catch (Exception e) { | 306 | } catch (Exception e) { |
302 | log.warn("Unable to install intent {} due to: {}", intent.id(), e); | 307 | log.warn("Unable to install intent {} due to: {}", intent.id(), e); |
303 | uninstallIntent(intent, RECOMPILING); | 308 | uninstallIntent(intent, RECOMPILING); |
... | @@ -369,16 +374,16 @@ public class IntentManager | ... | @@ -369,16 +374,16 @@ public class IntentManager |
369 | * @param intent intent to be uninstalled | 374 | * @param intent intent to be uninstalled |
370 | */ | 375 | */ |
371 | private void uninstallIntent(Intent intent, IntentState nextState) { | 376 | private void uninstallIntent(Intent intent, IntentState nextState) { |
372 | - List<Future<CompletedBatchOperation>> uninstallFutures = Lists.newArrayList(); | 377 | + List<FlowRuleBatchOperation> uninstallWork = Lists.newArrayList(); |
373 | try { | 378 | try { |
374 | List<InstallableIntent> installables = store.getInstallableIntents(intent.id()); | 379 | List<InstallableIntent> installables = store.getInstallableIntents(intent.id()); |
375 | if (installables != null) { | 380 | if (installables != null) { |
376 | for (InstallableIntent installable : installables) { | 381 | for (InstallableIntent installable : installables) { |
377 | - Future<CompletedBatchOperation> future = getInstaller(installable).uninstall(installable); | 382 | + List<FlowRuleBatchOperation> batches = getInstaller(installable).uninstall(installable); |
378 | - uninstallFutures.add(future); | 383 | + uninstallWork.addAll(batches); |
379 | } | 384 | } |
380 | } | 385 | } |
381 | - monitorExecutor.execute(new IntentInstallMonitor(intent, uninstallFutures, nextState)); | 386 | + monitorExecutor.execute(new IntentInstallMonitor(intent, uninstallWork, nextState)); |
382 | } catch (IntentException e) { | 387 | } catch (IntentException e) { |
383 | log.warn("Unable to uninstall intent {} due to: {}", intent.id(), e); | 388 | log.warn("Unable to uninstall intent {} due to: {}", intent.id(), e); |
384 | } | 389 | } |
... | @@ -495,17 +500,27 @@ public class IntentManager | ... | @@ -495,17 +500,27 @@ public class IntentManager |
495 | private class IntentInstallMonitor implements Runnable { | 500 | private class IntentInstallMonitor implements Runnable { |
496 | 501 | ||
497 | private final Intent intent; | 502 | private final Intent intent; |
503 | + private final List<FlowRuleBatchOperation> work; | ||
498 | private final List<Future<CompletedBatchOperation>> futures; | 504 | private final List<Future<CompletedBatchOperation>> futures; |
499 | private final IntentState nextState; | 505 | private final IntentState nextState; |
500 | 506 | ||
501 | public IntentInstallMonitor(Intent intent, | 507 | public IntentInstallMonitor(Intent intent, |
502 | - List<Future<CompletedBatchOperation>> futures, IntentState nextState) { | 508 | + List<FlowRuleBatchOperation> work, |
509 | + IntentState nextState) { | ||
503 | this.intent = intent; | 510 | this.intent = intent; |
504 | - this.futures = futures; | 511 | + this.work = work; |
512 | + // TODO how many Futures can be outstanding? one? | ||
513 | + this.futures = Lists.newLinkedList(); | ||
505 | this.nextState = nextState; | 514 | this.nextState = nextState; |
515 | + | ||
516 | + // TODO need to kick off the first batch sometime, why not now? | ||
517 | + futures.add(applyNextBatch()); | ||
506 | } | 518 | } |
507 | 519 | ||
508 | - private void updateIntent(Intent intent) { | 520 | + /** |
521 | + * Update the intent store with the next status for this intent. | ||
522 | + */ | ||
523 | + private void updateIntent() { | ||
509 | if (nextState == RECOMPILING) { | 524 | if (nextState == RECOMPILING) { |
510 | executor.execute(new IntentTask(nextState, intent)); | 525 | executor.execute(new IntentTask(nextState, intent)); |
511 | } else if (nextState == INSTALLED || nextState == WITHDRAWN) { | 526 | } else if (nextState == INSTALLED || nextState == WITHDRAWN) { |
... | @@ -515,22 +530,55 @@ public class IntentManager | ... | @@ -515,22 +530,55 @@ public class IntentManager |
515 | } | 530 | } |
516 | } | 531 | } |
517 | 532 | ||
518 | - @Override | 533 | + /** |
519 | - public void run() { | 534 | + * Apply a list of FlowRules. |
535 | + * | ||
536 | + * @param rules rules to apply | ||
537 | + */ | ||
538 | + private Future<CompletedBatchOperation> applyNextBatch() { | ||
539 | + if (work.isEmpty()) { | ||
540 | + return null; | ||
541 | + } | ||
542 | + FlowRuleBatchOperation batch = work.remove(0); | ||
543 | + return flowRuleService.applyBatch(batch); | ||
544 | + } | ||
545 | + | ||
546 | + /** | ||
547 | + * Iterate through the pending futures, and remove them when they have completed. | ||
548 | + */ | ||
549 | + private void processFutures() { | ||
550 | + List<Future<CompletedBatchOperation>> newFutures = Lists.newArrayList(); | ||
520 | for (Iterator<Future<CompletedBatchOperation>> i = futures.iterator(); i.hasNext();) { | 551 | for (Iterator<Future<CompletedBatchOperation>> i = futures.iterator(); i.hasNext();) { |
521 | Future<CompletedBatchOperation> future = i.next(); | 552 | Future<CompletedBatchOperation> future = i.next(); |
522 | try { | 553 | try { |
523 | // TODO: we may want to get the future here and go back to the future. | 554 | // TODO: we may want to get the future here and go back to the future. |
524 | CompletedBatchOperation completed = future.get(100, TimeUnit.NANOSECONDS); | 555 | CompletedBatchOperation completed = future.get(100, TimeUnit.NANOSECONDS); |
525 | - // TODO check if future succeeded and if not report fail items | 556 | + if (completed.isSuccess()) { |
557 | + Future<CompletedBatchOperation> newFuture = applyNextBatch(); | ||
558 | + if (newFuture != null) { | ||
559 | + // we'll add this later so that we don't get a ConcurrentModException | ||
560 | + newFutures.add(newFuture); | ||
561 | + } | ||
562 | + } else { | ||
563 | + // TODO check if future succeeded and if not report fail items | ||
564 | + log.warn("Failed items: {}", completed.failedItems()); | ||
565 | + // TODO revert.... | ||
566 | + //uninstallIntent(intent, RECOMPILING); | ||
567 | + } | ||
526 | i.remove(); | 568 | i.remove(); |
527 | - | ||
528 | } catch (TimeoutException | InterruptedException | ExecutionException te) { | 569 | } catch (TimeoutException | InterruptedException | ExecutionException te) { |
529 | log.debug("Intallations of intent {} is still pending", intent); | 570 | log.debug("Intallations of intent {} is still pending", intent); |
530 | } | 571 | } |
531 | } | 572 | } |
573 | + futures.addAll(newFutures); | ||
574 | + } | ||
575 | + | ||
576 | + @Override | ||
577 | + public void run() { | ||
578 | + processFutures(); | ||
532 | if (futures.isEmpty()) { | 579 | if (futures.isEmpty()) { |
533 | - updateIntent(intent); | 580 | + // woohoo! we are done! |
581 | + updateIntent(); | ||
534 | } else { | 582 | } else { |
535 | // resubmit ourselves if we are not done yet | 583 | // resubmit ourselves if we are not done yet |
536 | monitorExecutor.submit(this); | 584 | monitorExecutor.submit(this); | ... | ... |
... | @@ -4,7 +4,6 @@ import static org.onlab.onos.net.flow.DefaultTrafficTreatment.builder; | ... | @@ -4,7 +4,6 @@ import static org.onlab.onos.net.flow.DefaultTrafficTreatment.builder; |
4 | import static org.slf4j.LoggerFactory.getLogger; | 4 | import static org.slf4j.LoggerFactory.getLogger; |
5 | 5 | ||
6 | import java.util.List; | 6 | import java.util.List; |
7 | -import java.util.concurrent.Future; | ||
8 | 7 | ||
9 | import org.apache.felix.scr.annotations.Activate; | 8 | import org.apache.felix.scr.annotations.Activate; |
10 | import org.apache.felix.scr.annotations.Component; | 9 | import org.apache.felix.scr.annotations.Component; |
... | @@ -16,14 +15,12 @@ import org.onlab.onos.CoreService; | ... | @@ -16,14 +15,12 @@ import org.onlab.onos.CoreService; |
16 | import org.onlab.onos.net.DeviceId; | 15 | import org.onlab.onos.net.DeviceId; |
17 | import org.onlab.onos.net.Link; | 16 | import org.onlab.onos.net.Link; |
18 | import org.onlab.onos.net.PortNumber; | 17 | import org.onlab.onos.net.PortNumber; |
19 | -import org.onlab.onos.net.flow.CompletedBatchOperation; | ||
20 | import org.onlab.onos.net.flow.DefaultFlowRule; | 18 | import org.onlab.onos.net.flow.DefaultFlowRule; |
21 | import org.onlab.onos.net.flow.DefaultTrafficSelector; | 19 | import org.onlab.onos.net.flow.DefaultTrafficSelector; |
22 | import org.onlab.onos.net.flow.FlowRule; | 20 | import org.onlab.onos.net.flow.FlowRule; |
23 | import org.onlab.onos.net.flow.FlowRuleBatchEntry; | 21 | import org.onlab.onos.net.flow.FlowRuleBatchEntry; |
24 | import org.onlab.onos.net.flow.FlowRuleBatchEntry.FlowRuleOperation; | 22 | import org.onlab.onos.net.flow.FlowRuleBatchEntry.FlowRuleOperation; |
25 | import org.onlab.onos.net.flow.FlowRuleBatchOperation; | 23 | import org.onlab.onos.net.flow.FlowRuleBatchOperation; |
26 | -import org.onlab.onos.net.flow.FlowRuleService; | ||
27 | import org.onlab.onos.net.flow.TrafficSelector; | 24 | import org.onlab.onos.net.flow.TrafficSelector; |
28 | import org.onlab.onos.net.flow.TrafficTreatment; | 25 | import org.onlab.onos.net.flow.TrafficTreatment; |
29 | import org.onlab.onos.net.intent.IntentExtensionService; | 26 | import org.onlab.onos.net.intent.IntentExtensionService; |
... | @@ -47,9 +44,6 @@ public class LinkCollectionIntentInstaller implements IntentInstaller<LinkCollec | ... | @@ -47,9 +44,6 @@ public class LinkCollectionIntentInstaller implements IntentInstaller<LinkCollec |
47 | protected IntentExtensionService intentManager; | 44 | protected IntentExtensionService intentManager; |
48 | 45 | ||
49 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) | 46 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
50 | - protected FlowRuleService flowRuleService; | ||
51 | - | ||
52 | - @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) | ||
53 | protected CoreService coreService; | 47 | protected CoreService coreService; |
54 | 48 | ||
55 | private ApplicationId appId; | 49 | private ApplicationId appId; |
... | @@ -65,18 +59,8 @@ public class LinkCollectionIntentInstaller implements IntentInstaller<LinkCollec | ... | @@ -65,18 +59,8 @@ public class LinkCollectionIntentInstaller implements IntentInstaller<LinkCollec |
65 | intentManager.unregisterInstaller(PathIntent.class); | 59 | intentManager.unregisterInstaller(PathIntent.class); |
66 | } | 60 | } |
67 | 61 | ||
68 | - /** | ||
69 | - * Apply a list of FlowRules. | ||
70 | - * | ||
71 | - * @param rules rules to apply | ||
72 | - */ | ||
73 | - private Future<CompletedBatchOperation> applyBatch(List<FlowRuleBatchEntry> rules) { | ||
74 | - FlowRuleBatchOperation batch = new FlowRuleBatchOperation(rules); | ||
75 | - return flowRuleService.applyBatch(batch); | ||
76 | - } | ||
77 | - | ||
78 | @Override | 62 | @Override |
79 | - public Future<CompletedBatchOperation> install(LinkCollectionIntent intent) { | 63 | + public List<FlowRuleBatchOperation> install(LinkCollectionIntent intent) { |
80 | TrafficSelector.Builder builder = | 64 | TrafficSelector.Builder builder = |
81 | DefaultTrafficSelector.builder(intent.selector()); | 65 | DefaultTrafficSelector.builder(intent.selector()); |
82 | List<FlowRuleBatchEntry> rules = Lists.newLinkedList(); | 66 | List<FlowRuleBatchEntry> rules = Lists.newLinkedList(); |
... | @@ -92,11 +76,11 @@ public class LinkCollectionIntentInstaller implements IntentInstaller<LinkCollec | ... | @@ -92,11 +76,11 @@ public class LinkCollectionIntentInstaller implements IntentInstaller<LinkCollec |
92 | intent.egressPoint().deviceId(), | 76 | intent.egressPoint().deviceId(), |
93 | intent.egressPoint().port())); | 77 | intent.egressPoint().port())); |
94 | 78 | ||
95 | - return applyBatch(rules); | 79 | + return Lists.newArrayList(new FlowRuleBatchOperation(rules)); |
96 | } | 80 | } |
97 | 81 | ||
98 | @Override | 82 | @Override |
99 | - public Future<CompletedBatchOperation> uninstall(LinkCollectionIntent intent) { | 83 | + public List<FlowRuleBatchOperation> uninstall(LinkCollectionIntent intent) { |
100 | TrafficSelector.Builder builder = | 84 | TrafficSelector.Builder builder = |
101 | DefaultTrafficSelector.builder(intent.selector()); | 85 | DefaultTrafficSelector.builder(intent.selector()); |
102 | List<FlowRuleBatchEntry> rules = Lists.newLinkedList(); | 86 | List<FlowRuleBatchEntry> rules = Lists.newLinkedList(); |
... | @@ -113,7 +97,7 @@ public class LinkCollectionIntentInstaller implements IntentInstaller<LinkCollec | ... | @@ -113,7 +97,7 @@ public class LinkCollectionIntentInstaller implements IntentInstaller<LinkCollec |
113 | intent.egressPoint().deviceId(), | 97 | intent.egressPoint().deviceId(), |
114 | intent.egressPoint().port())); | 98 | intent.egressPoint().port())); |
115 | 99 | ||
116 | - return applyBatch(rules); | 100 | + return Lists.newArrayList(new FlowRuleBatchOperation(rules)); |
117 | } | 101 | } |
118 | 102 | ||
119 | /** | 103 | /** | ... | ... |
... | @@ -5,7 +5,6 @@ import static org.slf4j.LoggerFactory.getLogger; | ... | @@ -5,7 +5,6 @@ import static org.slf4j.LoggerFactory.getLogger; |
5 | 5 | ||
6 | import java.util.Iterator; | 6 | import java.util.Iterator; |
7 | import java.util.List; | 7 | import java.util.List; |
8 | -import java.util.concurrent.Future; | ||
9 | 8 | ||
10 | import org.apache.felix.scr.annotations.Activate; | 9 | import org.apache.felix.scr.annotations.Activate; |
11 | import org.apache.felix.scr.annotations.Component; | 10 | import org.apache.felix.scr.annotations.Component; |
... | @@ -16,14 +15,12 @@ import org.onlab.onos.ApplicationId; | ... | @@ -16,14 +15,12 @@ import org.onlab.onos.ApplicationId; |
16 | import org.onlab.onos.CoreService; | 15 | import org.onlab.onos.CoreService; |
17 | import org.onlab.onos.net.ConnectPoint; | 16 | import org.onlab.onos.net.ConnectPoint; |
18 | import org.onlab.onos.net.Link; | 17 | import org.onlab.onos.net.Link; |
19 | -import org.onlab.onos.net.flow.CompletedBatchOperation; | ||
20 | import org.onlab.onos.net.flow.DefaultFlowRule; | 18 | import org.onlab.onos.net.flow.DefaultFlowRule; |
21 | import org.onlab.onos.net.flow.DefaultTrafficSelector; | 19 | import org.onlab.onos.net.flow.DefaultTrafficSelector; |
22 | import org.onlab.onos.net.flow.FlowRule; | 20 | import org.onlab.onos.net.flow.FlowRule; |
23 | import org.onlab.onos.net.flow.FlowRuleBatchEntry; | 21 | import org.onlab.onos.net.flow.FlowRuleBatchEntry; |
24 | import org.onlab.onos.net.flow.FlowRuleBatchEntry.FlowRuleOperation; | 22 | import org.onlab.onos.net.flow.FlowRuleBatchEntry.FlowRuleOperation; |
25 | import org.onlab.onos.net.flow.FlowRuleBatchOperation; | 23 | import org.onlab.onos.net.flow.FlowRuleBatchOperation; |
26 | -import org.onlab.onos.net.flow.FlowRuleService; | ||
27 | import org.onlab.onos.net.flow.TrafficSelector; | 24 | import org.onlab.onos.net.flow.TrafficSelector; |
28 | import org.onlab.onos.net.flow.TrafficTreatment; | 25 | import org.onlab.onos.net.flow.TrafficTreatment; |
29 | import org.onlab.onos.net.intent.IntentExtensionService; | 26 | import org.onlab.onos.net.intent.IntentExtensionService; |
... | @@ -45,9 +42,6 @@ public class PathIntentInstaller implements IntentInstaller<PathIntent> { | ... | @@ -45,9 +42,6 @@ public class PathIntentInstaller implements IntentInstaller<PathIntent> { |
45 | protected IntentExtensionService intentManager; | 42 | protected IntentExtensionService intentManager; |
46 | 43 | ||
47 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) | 44 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
48 | - protected FlowRuleService flowRuleService; | ||
49 | - | ||
50 | - @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) | ||
51 | protected CoreService coreService; | 45 | protected CoreService coreService; |
52 | 46 | ||
53 | private ApplicationId appId; | 47 | private ApplicationId appId; |
... | @@ -63,31 +57,14 @@ public class PathIntentInstaller implements IntentInstaller<PathIntent> { | ... | @@ -63,31 +57,14 @@ public class PathIntentInstaller implements IntentInstaller<PathIntent> { |
63 | intentManager.unregisterInstaller(PathIntent.class); | 57 | intentManager.unregisterInstaller(PathIntent.class); |
64 | } | 58 | } |
65 | 59 | ||
66 | - /** | ||
67 | - * Apply a list of FlowRules. | ||
68 | - * | ||
69 | - * @param rules rules to apply | ||
70 | - */ | ||
71 | - private Future<CompletedBatchOperation> applyBatch(List<FlowRuleBatchEntry> rules) { | ||
72 | - FlowRuleBatchOperation batch = new FlowRuleBatchOperation(rules); | ||
73 | - Future<CompletedBatchOperation> future = flowRuleService.applyBatch(batch); | ||
74 | - return future; | ||
75 | -// try { | ||
76 | -// //FIXME don't do this here | ||
77 | -// future.get(); | ||
78 | -// } catch (InterruptedException | ExecutionException e) { | ||
79 | -// // TODO Auto-generated catch block | ||
80 | -// e.printStackTrace(); | ||
81 | -// } | ||
82 | - } | ||
83 | - | ||
84 | @Override | 60 | @Override |
85 | - public Future<CompletedBatchOperation> install(PathIntent intent) { | 61 | + public List<FlowRuleBatchOperation> install(PathIntent intent) { |
86 | TrafficSelector.Builder builder = | 62 | TrafficSelector.Builder builder = |
87 | DefaultTrafficSelector.builder(intent.selector()); | 63 | DefaultTrafficSelector.builder(intent.selector()); |
88 | Iterator<Link> links = intent.path().links().iterator(); | 64 | Iterator<Link> links = intent.path().links().iterator(); |
89 | ConnectPoint prev = links.next().dst(); | 65 | ConnectPoint prev = links.next().dst(); |
90 | List<FlowRuleBatchEntry> rules = Lists.newLinkedList(); | 66 | List<FlowRuleBatchEntry> rules = Lists.newLinkedList(); |
67 | + // TODO Generate multiple batches | ||
91 | while (links.hasNext()) { | 68 | while (links.hasNext()) { |
92 | builder.matchInport(prev.port()); | 69 | builder.matchInport(prev.port()); |
93 | Link link = links.next(); | 70 | Link link = links.next(); |
... | @@ -100,18 +77,17 @@ public class PathIntentInstaller implements IntentInstaller<PathIntent> { | ... | @@ -100,18 +77,17 @@ public class PathIntentInstaller implements IntentInstaller<PathIntent> { |
100 | rules.add(new FlowRuleBatchEntry(FlowRuleOperation.ADD, rule)); | 77 | rules.add(new FlowRuleBatchEntry(FlowRuleOperation.ADD, rule)); |
101 | prev = link.dst(); | 78 | prev = link.dst(); |
102 | } | 79 | } |
103 | - | 80 | + return Lists.newArrayList(new FlowRuleBatchOperation(rules)); |
104 | - return applyBatch(rules); | ||
105 | } | 81 | } |
106 | 82 | ||
107 | @Override | 83 | @Override |
108 | - public Future<CompletedBatchOperation> uninstall(PathIntent intent) { | 84 | + public List<FlowRuleBatchOperation> uninstall(PathIntent intent) { |
109 | TrafficSelector.Builder builder = | 85 | TrafficSelector.Builder builder = |
110 | DefaultTrafficSelector.builder(intent.selector()); | 86 | DefaultTrafficSelector.builder(intent.selector()); |
111 | Iterator<Link> links = intent.path().links().iterator(); | 87 | Iterator<Link> links = intent.path().links().iterator(); |
112 | ConnectPoint prev = links.next().dst(); | 88 | ConnectPoint prev = links.next().dst(); |
113 | List<FlowRuleBatchEntry> rules = Lists.newLinkedList(); | 89 | List<FlowRuleBatchEntry> rules = Lists.newLinkedList(); |
114 | - | 90 | + // TODO Generate multiple batches |
115 | while (links.hasNext()) { | 91 | while (links.hasNext()) { |
116 | builder.matchInport(prev.port()); | 92 | builder.matchInport(prev.port()); |
117 | Link link = links.next(); | 93 | Link link = links.next(); |
... | @@ -123,7 +99,7 @@ public class PathIntentInstaller implements IntentInstaller<PathIntent> { | ... | @@ -123,7 +99,7 @@ public class PathIntentInstaller implements IntentInstaller<PathIntent> { |
123 | rules.add(new FlowRuleBatchEntry(FlowRuleOperation.REMOVE, rule)); | 99 | rules.add(new FlowRuleBatchEntry(FlowRuleOperation.REMOVE, rule)); |
124 | prev = link.dst(); | 100 | prev = link.dst(); |
125 | } | 101 | } |
126 | - return applyBatch(rules); | 102 | + return Lists.newArrayList(new FlowRuleBatchOperation(rules)); |
127 | } | 103 | } |
128 | 104 | ||
129 | // TODO refactor below this line... ---------------------------- | 105 | // TODO refactor below this line... ---------------------------- | ... | ... |
... | @@ -22,10 +22,8 @@ import org.onlab.onos.store.cluster.messaging.ClusterMessage; | ... | @@ -22,10 +22,8 @@ import org.onlab.onos.store.cluster.messaging.ClusterMessage; |
22 | import org.onlab.onos.store.cluster.messaging.ClusterMessageHandler; | 22 | import org.onlab.onos.store.cluster.messaging.ClusterMessageHandler; |
23 | import org.onlab.onos.store.cluster.messaging.ClusterMessageResponse; | 23 | import org.onlab.onos.store.cluster.messaging.ClusterMessageResponse; |
24 | import org.onlab.onos.store.cluster.messaging.MessageSubject; | 24 | import org.onlab.onos.store.cluster.messaging.MessageSubject; |
25 | -import org.onlab.onos.store.serializers.ClusterMessageSerializer; | ||
26 | import org.onlab.onos.store.serializers.KryoNamespaces; | 25 | import org.onlab.onos.store.serializers.KryoNamespaces; |
27 | import org.onlab.onos.store.serializers.KryoSerializer; | 26 | import org.onlab.onos.store.serializers.KryoSerializer; |
28 | -import org.onlab.onos.store.serializers.MessageSubjectSerializer; | ||
29 | import org.onlab.util.KryoNamespace; | 27 | import org.onlab.util.KryoNamespace; |
30 | import org.onlab.netty.Endpoint; | 28 | import org.onlab.netty.Endpoint; |
31 | import org.onlab.netty.Message; | 29 | import org.onlab.netty.Message; | ... | ... |
... | @@ -17,6 +17,8 @@ import io.netty.channel.ChannelInitializer; | ... | @@ -17,6 +17,8 @@ import io.netty.channel.ChannelInitializer; |
17 | import io.netty.channel.ChannelOption; | 17 | import io.netty.channel.ChannelOption; |
18 | import io.netty.channel.EventLoopGroup; | 18 | import io.netty.channel.EventLoopGroup; |
19 | import io.netty.channel.SimpleChannelInboundHandler; | 19 | import io.netty.channel.SimpleChannelInboundHandler; |
20 | +import io.netty.channel.epoll.EpollEventLoopGroup; | ||
21 | +import io.netty.channel.epoll.EpollSocketChannel; | ||
20 | import io.netty.channel.nio.NioEventLoopGroup; | 22 | import io.netty.channel.nio.NioEventLoopGroup; |
21 | import io.netty.channel.socket.SocketChannel; | 23 | import io.netty.channel.socket.SocketChannel; |
22 | import io.netty.channel.socket.nio.NioServerSocketChannel; | 24 | import io.netty.channel.socket.nio.NioServerSocketChannel; |
... | @@ -41,7 +43,8 @@ public class NettyMessagingService implements MessagingService { | ... | @@ -41,7 +43,8 @@ public class NettyMessagingService implements MessagingService { |
41 | private final int port; | 43 | private final int port; |
42 | private final Endpoint localEp; | 44 | private final Endpoint localEp; |
43 | private final EventLoopGroup bossGroup = new NioEventLoopGroup(); | 45 | private final EventLoopGroup bossGroup = new NioEventLoopGroup(); |
44 | - private final EventLoopGroup workerGroup = new NioEventLoopGroup(); | 46 | + private EventLoopGroup workerGroup; |
47 | + private Class<? extends Channel> channelClass; | ||
45 | private final ConcurrentMap<String, MessageHandler> handlers = new ConcurrentHashMap<>(); | 48 | private final ConcurrentMap<String, MessageHandler> handlers = new ConcurrentHashMap<>(); |
46 | private final Cache<Long, AsyncResponse> responseFutures = CacheBuilder.newBuilder() | 49 | private final Cache<Long, AsyncResponse> responseFutures = CacheBuilder.newBuilder() |
47 | .maximumSize(100000) | 50 | .maximumSize(100000) |
... | @@ -52,6 +55,17 @@ public class NettyMessagingService implements MessagingService { | ... | @@ -52,6 +55,17 @@ public class NettyMessagingService implements MessagingService { |
52 | private final GenericKeyedObjectPool<Endpoint, Channel> channels | 55 | private final GenericKeyedObjectPool<Endpoint, Channel> channels |
53 | = new GenericKeyedObjectPool<Endpoint, Channel>(new OnosCommunicationChannelFactory()); | 56 | = new GenericKeyedObjectPool<Endpoint, Channel>(new OnosCommunicationChannelFactory()); |
54 | 57 | ||
58 | + // TODO: make this configurable. | ||
59 | + private void initEventLoopGroup() { | ||
60 | + try { | ||
61 | + workerGroup = new EpollEventLoopGroup(); | ||
62 | + channelClass = EpollSocketChannel.class; | ||
63 | + } catch (Throwable t) { | ||
64 | + workerGroup = new NioEventLoopGroup(); | ||
65 | + channelClass = NioSocketChannel.class; | ||
66 | + } | ||
67 | + } | ||
68 | + | ||
55 | public NettyMessagingService() { | 69 | public NettyMessagingService() { |
56 | // TODO: Default port should be configurable. | 70 | // TODO: Default port should be configurable. |
57 | this(8080); | 71 | this(8080); |
... | @@ -71,6 +85,7 @@ public class NettyMessagingService implements MessagingService { | ... | @@ -71,6 +85,7 @@ public class NettyMessagingService implements MessagingService { |
71 | public void activate() throws Exception { | 85 | public void activate() throws Exception { |
72 | channels.setTestOnBorrow(true); | 86 | channels.setTestOnBorrow(true); |
73 | channels.setTestOnReturn(true); | 87 | channels.setTestOnReturn(true); |
88 | + initEventLoopGroup(); | ||
74 | startAcceptingConnections(); | 89 | startAcceptingConnections(); |
75 | } | 90 | } |
76 | 91 | ||
... | @@ -173,7 +188,7 @@ public class NettyMessagingService implements MessagingService { | ... | @@ -173,7 +188,7 @@ public class NettyMessagingService implements MessagingService { |
173 | bootstrap.group(workerGroup); | 188 | bootstrap.group(workerGroup); |
174 | // TODO: Make this faster: | 189 | // TODO: Make this faster: |
175 | // http://normanmaurer.me/presentations/2014-facebook-eng-netty/slides.html#37.0 | 190 | // http://normanmaurer.me/presentations/2014-facebook-eng-netty/slides.html#37.0 |
176 | - bootstrap.channel(NioSocketChannel.class); | 191 | + bootstrap.channel(channelClass); |
177 | bootstrap.option(ChannelOption.SO_KEEPALIVE, true); | 192 | bootstrap.option(ChannelOption.SO_KEEPALIVE, true); |
178 | bootstrap.handler(new OnosCommunicationChannelInitializer()); | 193 | bootstrap.handler(new OnosCommunicationChannelInitializer()); |
179 | // Start the client. | 194 | // Start the client. | ... | ... |
-
Please register or login to post a comment