Committed by
Gerrit Code Review
Refactored intent framework to deal with batches.
There is still work to be done, but for now, submit, withdraw and reroute are working. Change-Id: Ib94cf8c4be03786cc070f402d1f296f5dfa6588b
Showing
27 changed files
with
380 additions
and
55 deletions
... | @@ -29,6 +29,7 @@ import org.onlab.onos.net.intent.Intent; | ... | @@ -29,6 +29,7 @@ import org.onlab.onos.net.intent.Intent; |
29 | import org.onlab.onos.net.intent.IntentEvent; | 29 | import org.onlab.onos.net.intent.IntentEvent; |
30 | import org.onlab.onos.net.intent.IntentEvent.Type; | 30 | import org.onlab.onos.net.intent.IntentEvent.Type; |
31 | import org.onlab.onos.net.intent.IntentListener; | 31 | import org.onlab.onos.net.intent.IntentListener; |
32 | +import org.onlab.onos.net.intent.IntentOperations; | ||
32 | import org.onlab.onos.net.intent.IntentService; | 33 | import org.onlab.onos.net.intent.IntentService; |
33 | import org.onlab.onos.net.intent.PointToPointIntent; | 34 | import org.onlab.onos.net.intent.PointToPointIntent; |
34 | import org.onlab.packet.Ethernet; | 35 | import org.onlab.packet.Ethernet; |
... | @@ -63,9 +64,6 @@ public class IntentPushTestCommand extends AbstractShellCommand | ... | @@ -63,9 +64,6 @@ public class IntentPushTestCommand extends AbstractShellCommand |
63 | required = true, multiValued = false) | 64 | required = true, multiValued = false) |
64 | String countString = null; | 65 | String countString = null; |
65 | 66 | ||
66 | - | ||
67 | - private static long id = 0x7870001; | ||
68 | - | ||
69 | private IntentService service; | 67 | private IntentService service; |
70 | private CountDownLatch latch; | 68 | private CountDownLatch latch; |
71 | private long start, end; | 69 | private long start, end; |
... | @@ -91,15 +89,18 @@ public class IntentPushTestCommand extends AbstractShellCommand | ... | @@ -91,15 +89,18 @@ public class IntentPushTestCommand extends AbstractShellCommand |
91 | service.addListener(this); | 89 | service.addListener(this); |
92 | latch = new CountDownLatch(count); | 90 | latch = new CountDownLatch(count); |
93 | 91 | ||
94 | - start = System.currentTimeMillis(); | 92 | + IntentOperations.Builder ops = IntentOperations.builder(); |
95 | - for (int i = 0; i < count; i++) { | 93 | + for (int i = 1; i <= count; i++) { |
96 | TrafficSelector s = selector | 94 | TrafficSelector s = selector |
97 | .matchEthSrc(MacAddress.valueOf(i)) | 95 | .matchEthSrc(MacAddress.valueOf(i)) |
98 | .build(); | 96 | .build(); |
99 | Intent intent = new PointToPointIntent(appId(), s, treatment, | 97 | Intent intent = new PointToPointIntent(appId(), s, treatment, |
100 | ingress, egress); | 98 | ingress, egress); |
101 | - service.submit(intent); | 99 | + ops.addSubmitOperation(intent); |
102 | } | 100 | } |
101 | + IntentOperations operations = ops.build(); | ||
102 | + start = System.currentTimeMillis(); | ||
103 | + service.execute(operations); | ||
103 | try { | 104 | try { |
104 | if (latch.await(10, TimeUnit.SECONDS)) { | 105 | if (latch.await(10, TimeUnit.SECONDS)) { |
105 | printResults(count); | 106 | printResults(count); | ... | ... |
... | @@ -15,13 +15,13 @@ | ... | @@ -15,13 +15,13 @@ |
15 | */ | 15 | */ |
16 | package org.onlab.onos.net.flow; | 16 | package org.onlab.onos.net.flow; |
17 | 17 | ||
18 | -import static com.google.common.base.Preconditions.checkNotNull; | ||
19 | - | ||
20 | import java.util.Collection; | 18 | import java.util.Collection; |
21 | import java.util.Collections; | 19 | import java.util.Collections; |
22 | import java.util.LinkedList; | 20 | import java.util.LinkedList; |
23 | import java.util.List; | 21 | import java.util.List; |
24 | 22 | ||
23 | +import static com.google.common.base.Preconditions.checkNotNull; | ||
24 | + | ||
25 | /** | 25 | /** |
26 | * A list of BatchOperationEntry. | 26 | * A list of BatchOperationEntry. |
27 | * | 27 | * |
... | @@ -88,6 +88,16 @@ public abstract class BatchOperation<T extends BatchOperationEntry<?, ?>> { | ... | @@ -88,6 +88,16 @@ public abstract class BatchOperation<T extends BatchOperationEntry<?, ?>> { |
88 | return ops.add(entry) ? this : null; | 88 | return ops.add(entry) ? this : null; |
89 | } | 89 | } |
90 | 90 | ||
91 | + /** | ||
92 | + * Add all operations from another batch to this batch. | ||
93 | + * | ||
94 | + * @param another another batch | ||
95 | + * @return true if success | ||
96 | + */ | ||
97 | + public boolean addAll(BatchOperation<T> another) { | ||
98 | + return ops.addAll(another.getOperations()); | ||
99 | + } | ||
100 | + | ||
91 | @Override | 101 | @Override |
92 | public boolean equals(Object o) { | 102 | public boolean equals(Object o) { |
93 | if (this == o) { | 103 | if (this == o) { | ... | ... |
... | @@ -19,12 +19,20 @@ import java.util.Set; | ... | @@ -19,12 +19,20 @@ import java.util.Set; |
19 | 19 | ||
20 | import com.google.common.collect.ImmutableSet; | 20 | import com.google.common.collect.ImmutableSet; |
21 | 21 | ||
22 | +/** | ||
23 | + * Representation of a completed flow rule batch operation. | ||
24 | + */ | ||
22 | public class CompletedBatchOperation implements BatchOperationResult<FlowRule> { | 25 | public class CompletedBatchOperation implements BatchOperationResult<FlowRule> { |
23 | 26 | ||
24 | - | ||
25 | private final boolean success; | 27 | private final boolean success; |
26 | private final Set<FlowRule> failures; | 28 | private final Set<FlowRule> failures; |
27 | 29 | ||
30 | + /** | ||
31 | + * Creates a new batch completion result. | ||
32 | + * | ||
33 | + * @param success indicates whether the completion is successful. | ||
34 | + * @param failures set of any failures encountered | ||
35 | + */ | ||
28 | public CompletedBatchOperation(boolean success, Set<? extends FlowRule> failures) { | 36 | public CompletedBatchOperation(boolean success, Set<? extends FlowRule> failures) { |
29 | this.success = success; | 37 | this.success = success; |
30 | this.failures = ImmutableSet.copyOf(failures); | 38 | this.failures = ImmutableSet.copyOf(failures); |
... | @@ -40,5 +48,4 @@ public class CompletedBatchOperation implements BatchOperationResult<FlowRule> { | ... | @@ -40,5 +48,4 @@ public class CompletedBatchOperation implements BatchOperationResult<FlowRule> { |
40 | return failures; | 48 | return failures; |
41 | } | 49 | } |
42 | 50 | ||
43 | - | ||
44 | } | 51 | } | ... | ... |
1 | +/* | ||
2 | + * Copyright 2014 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 | +package org.onlab.onos.net.intent; | ||
17 | + | ||
18 | +/** | ||
19 | + * Facade for receiving notifications from the intent batch service. | ||
20 | + */ | ||
21 | +public interface IntentBatchDelegate { | ||
22 | + | ||
23 | + /** | ||
24 | + * Submits the specified batch of intent operations for processing. | ||
25 | + * | ||
26 | + * @param operations batch of operations | ||
27 | + */ | ||
28 | + void execute(IntentOperations operations); | ||
29 | + | ||
30 | + /** | ||
31 | + * Cancesl the specified batch of intent operations. | ||
32 | + * | ||
33 | + * @param operations batch of operations to be cancelled | ||
34 | + */ | ||
35 | + void cancel(IntentOperations operations); | ||
36 | +} |
1 | +/* | ||
2 | + * Copyright 2014 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 | +package org.onlab.onos.net.intent; | ||
17 | + | ||
18 | +import java.util.Set; | ||
19 | + | ||
20 | +/** | ||
21 | + * Service for tracking and delegating batches of intent operations. | ||
22 | + */ | ||
23 | +public interface IntentBatchService { | ||
24 | + | ||
25 | + /** | ||
26 | + * Submits a batch of intent operations. | ||
27 | + * | ||
28 | + * @param operations batch of operations | ||
29 | + */ | ||
30 | + void addIntentOperations(IntentOperations operations); | ||
31 | + | ||
32 | + /** | ||
33 | + * Removes the specified batch of intent operations after completion. | ||
34 | + * | ||
35 | + * @param operations batch of operations | ||
36 | + */ | ||
37 | + void removeIntentOperations(IntentOperations operations); | ||
38 | + | ||
39 | + /** | ||
40 | + * Returns the set of intent batches currently being tracked. | ||
41 | + * @return set of batches | ||
42 | + */ | ||
43 | + Set<IntentOperations> getIntentOperations(); | ||
44 | + | ||
45 | + /** | ||
46 | + * Sets the batch service delegate. | ||
47 | + * | ||
48 | + * @param delegate delegate to apply | ||
49 | + */ | ||
50 | + void setDelegate(IntentBatchDelegate delegate); | ||
51 | + | ||
52 | + /** | ||
53 | + * Unsets the batch service delegate. | ||
54 | + * | ||
55 | + * @param delegate delegate to unset | ||
56 | + */ | ||
57 | + void unsetDelegate(IntentBatchDelegate delegate); | ||
58 | + | ||
59 | +} |
... | @@ -15,7 +15,10 @@ | ... | @@ -15,7 +15,10 @@ |
15 | */ | 15 | */ |
16 | package org.onlab.onos.net.intent; | 16 | package org.onlab.onos.net.intent; |
17 | 17 | ||
18 | +import org.onlab.onos.net.resource.LinkResourceAllocations; | ||
19 | + | ||
18 | import java.util.List; | 20 | import java.util.List; |
21 | +import java.util.Set; | ||
19 | 22 | ||
20 | /** | 23 | /** |
21 | * Abstraction of a compiler which is capable of taking an intent | 24 | * Abstraction of a compiler which is capable of taking an intent |
... | @@ -27,9 +30,13 @@ public interface IntentCompiler<T extends Intent> { | ... | @@ -27,9 +30,13 @@ public interface IntentCompiler<T extends Intent> { |
27 | /** | 30 | /** |
28 | * Compiles the specified intent into other intents. | 31 | * Compiles the specified intent into other intents. |
29 | * | 32 | * |
30 | - * @param intent intent to be compiled | 33 | + * @param intent intent to be compiled |
34 | + * @param installable previously compilation result; optional | ||
35 | + * @param resources previously allocated resources; optional | ||
31 | * @return list of resulting intents | 36 | * @return list of resulting intents |
32 | * @throws IntentException if issues are encountered while compiling the intent | 37 | * @throws IntentException if issues are encountered while compiling the intent |
33 | */ | 38 | */ |
34 | - List<Intent> compile(T intent); | 39 | + List<Intent> compile(T intent, List<Intent> installable, |
40 | + Set<LinkResourceAllocations> resources); | ||
41 | + | ||
35 | } | 42 | } | ... | ... |
... | @@ -15,10 +15,10 @@ | ... | @@ -15,10 +15,10 @@ |
15 | */ | 15 | */ |
16 | package org.onlab.onos.net.intent; | 16 | package org.onlab.onos.net.intent; |
17 | 17 | ||
18 | -import java.util.List; | ||
19 | - | ||
20 | import org.onlab.onos.net.flow.FlowRuleBatchOperation; | 18 | import org.onlab.onos.net.flow.FlowRuleBatchOperation; |
21 | 19 | ||
20 | +import java.util.List; | ||
21 | + | ||
22 | /** | 22 | /** |
23 | * Abstraction of entity capable of installing intents to the environment. | 23 | * Abstraction of entity capable of installing intents to the environment. |
24 | */ | 24 | */ |
... | @@ -26,8 +26,8 @@ public interface IntentInstaller<T extends Intent> { | ... | @@ -26,8 +26,8 @@ public interface IntentInstaller<T extends Intent> { |
26 | /** | 26 | /** |
27 | * Installs the specified intent to the environment. | 27 | * Installs the specified intent to the environment. |
28 | * | 28 | * |
29 | - * @param intent intent to be installed | 29 | + * @param intent intent to be installed |
30 | - * @return FlowRule operations to install | 30 | + * @return flow rule operations to complete install |
31 | * @throws IntentException if issues are encountered while installing the intent | 31 | * @throws IntentException if issues are encountered while installing the intent |
32 | */ | 32 | */ |
33 | List<FlowRuleBatchOperation> install(T intent); | 33 | List<FlowRuleBatchOperation> install(T intent); |
... | @@ -35,9 +35,20 @@ public interface IntentInstaller<T extends Intent> { | ... | @@ -35,9 +35,20 @@ public interface IntentInstaller<T extends Intent> { |
35 | /** | 35 | /** |
36 | * Uninstalls the specified intent from the environment. | 36 | * Uninstalls the specified intent from the environment. |
37 | * | 37 | * |
38 | - * @param intent intent to be uninstalled | 38 | + * @param intent intent to be uninstalled |
39 | - * @return FlowRule operations to uninstall | 39 | + * @return flow rule operations to complete uninstall |
40 | * @throws IntentException if issues are encountered while uninstalling the intent | 40 | * @throws IntentException if issues are encountered while uninstalling the intent |
41 | */ | 41 | */ |
42 | List<FlowRuleBatchOperation> uninstall(T intent); | 42 | List<FlowRuleBatchOperation> uninstall(T intent); |
43 | + | ||
44 | + /** | ||
45 | + * Replaces the specified intent with a new one in the environment. | ||
46 | + * | ||
47 | + * @param oldIntent intent to be removed | ||
48 | + * @param newIntent intent to be installed | ||
49 | + * @return flow rule operations to complete the replace | ||
50 | + * @throws IntentException if issues are encountered while uninstalling the intent | ||
51 | + */ | ||
52 | + List<FlowRuleBatchOperation> replace(T oldIntent, T newIntent); | ||
53 | + | ||
43 | } | 54 | } | ... | ... |
... | @@ -15,6 +15,11 @@ | ... | @@ -15,6 +15,11 @@ |
15 | */ | 15 | */ |
16 | package org.onlab.onos.net.intent; | 16 | package org.onlab.onos.net.intent; |
17 | 17 | ||
18 | + | ||
19 | +import java.util.Objects; | ||
20 | + | ||
21 | +import static com.google.common.base.MoreObjects.toStringHelper; | ||
22 | + | ||
18 | /** | 23 | /** |
19 | * Abstraction of an intent-related operation, e.g. add, remove, replace. | 24 | * Abstraction of an intent-related operation, e.g. add, remove, replace. |
20 | */ | 25 | */ |
... | @@ -27,7 +32,7 @@ public class IntentOperation { | ... | @@ -27,7 +32,7 @@ public class IntentOperation { |
27 | /** | 32 | /** |
28 | * Operation type. | 33 | * Operation type. |
29 | */ | 34 | */ |
30 | - enum Type { | 35 | + public enum Type { |
31 | /** | 36 | /** |
32 | * Indicates that an intent should be added. | 37 | * Indicates that an intent should be added. |
33 | */ | 38 | */ |
... | @@ -41,15 +46,20 @@ public class IntentOperation { | ... | @@ -41,15 +46,20 @@ public class IntentOperation { |
41 | /** | 46 | /** |
42 | * Indicates that an intent should be replaced with another. | 47 | * Indicates that an intent should be replaced with another. |
43 | */ | 48 | */ |
44 | - REPLACE | 49 | + REPLACE, |
50 | + | ||
51 | + /** | ||
52 | + * Indicates that an intent should be updated (i.e. recompiled/reinstalled). | ||
53 | + */ | ||
54 | + UPDATE, | ||
45 | } | 55 | } |
46 | 56 | ||
47 | /** | 57 | /** |
48 | * Creates an intent operation. | 58 | * Creates an intent operation. |
49 | * | 59 | * |
50 | - * @param type operation type | 60 | + * @param type operation type |
51 | * @param intentId identifier of the intent subject to the operation | 61 | * @param intentId identifier of the intent subject to the operation |
52 | - * @param intent intent subject | 62 | + * @param intent intent subject |
53 | */ | 63 | */ |
54 | IntentOperation(Type type, IntentId intentId, Intent intent) { | 64 | IntentOperation(Type type, IntentId intentId, Intent intent) { |
55 | this.type = type; | 65 | this.type = type; |
... | @@ -85,4 +95,32 @@ public class IntentOperation { | ... | @@ -85,4 +95,32 @@ public class IntentOperation { |
85 | return intent; | 95 | return intent; |
86 | } | 96 | } |
87 | 97 | ||
98 | + @Override | ||
99 | + public int hashCode() { | ||
100 | + return Objects.hash(type, intentId, intent); | ||
101 | + } | ||
102 | + | ||
103 | + @Override | ||
104 | + public boolean equals(Object obj) { | ||
105 | + if (this == obj) { | ||
106 | + return true; | ||
107 | + } | ||
108 | + if (obj == null || getClass() != obj.getClass()) { | ||
109 | + return false; | ||
110 | + } | ||
111 | + final IntentOperation other = (IntentOperation) obj; | ||
112 | + return Objects.equals(this.type, other.type) && | ||
113 | + Objects.equals(this.intentId, other.intentId) && | ||
114 | + Objects.equals(this.intent, other.intent); | ||
115 | + } | ||
116 | + | ||
117 | + | ||
118 | + @Override | ||
119 | + public String toString() { | ||
120 | + return toStringHelper(this) | ||
121 | + .add("type", type) | ||
122 | + .add("intentId", intentId) | ||
123 | + .add("intent", intent) | ||
124 | + .toString(); | ||
125 | + } | ||
88 | } | 126 | } | ... | ... |
... | @@ -18,11 +18,11 @@ package org.onlab.onos.net.intent; | ... | @@ -18,11 +18,11 @@ package org.onlab.onos.net.intent; |
18 | import com.google.common.collect.ImmutableList; | 18 | import com.google.common.collect.ImmutableList; |
19 | 19 | ||
20 | import java.util.List; | 20 | import java.util.List; |
21 | +import java.util.Objects; | ||
21 | 22 | ||
23 | +import static com.google.common.base.MoreObjects.toStringHelper; | ||
22 | import static com.google.common.base.Preconditions.checkNotNull; | 24 | import static com.google.common.base.Preconditions.checkNotNull; |
23 | -import static org.onlab.onos.net.intent.IntentOperation.Type.REPLACE; | 25 | +import static org.onlab.onos.net.intent.IntentOperation.Type.*; |
24 | -import static org.onlab.onos.net.intent.IntentOperation.Type.SUBMIT; | ||
25 | -import static org.onlab.onos.net.intent.IntentOperation.Type.WITHDRAW; | ||
26 | 26 | ||
27 | /** | 27 | /** |
28 | * Batch of intent submit/withdraw/replace operations. | 28 | * Batch of intent submit/withdraw/replace operations. |
... | @@ -58,6 +58,31 @@ public final class IntentOperations { | ... | @@ -58,6 +58,31 @@ public final class IntentOperations { |
58 | return new Builder(); | 58 | return new Builder(); |
59 | } | 59 | } |
60 | 60 | ||
61 | + | ||
62 | + @Override | ||
63 | + public int hashCode() { | ||
64 | + return Objects.hash(operations); | ||
65 | + } | ||
66 | + | ||
67 | + @Override | ||
68 | + public boolean equals(Object obj) { | ||
69 | + if (this == obj) { | ||
70 | + return true; | ||
71 | + } | ||
72 | + if (obj == null || getClass() != obj.getClass()) { | ||
73 | + return false; | ||
74 | + } | ||
75 | + final IntentOperations other = (IntentOperations) obj; | ||
76 | + return Objects.equals(this.operations, other.operations); | ||
77 | + } | ||
78 | + | ||
79 | + @Override | ||
80 | + public String toString() { | ||
81 | + return toStringHelper(this) | ||
82 | + .add("operations", operations) | ||
83 | + .toString(); | ||
84 | + } | ||
85 | + | ||
61 | /** | 86 | /** |
62 | * Builder for batches of intent operations. | 87 | * Builder for batches of intent operations. |
63 | */ | 88 | */ |
... | @@ -108,6 +133,18 @@ public final class IntentOperations { | ... | @@ -108,6 +133,18 @@ public final class IntentOperations { |
108 | } | 133 | } |
109 | 134 | ||
110 | /** | 135 | /** |
136 | + * Adds an intent update operation. | ||
137 | + * | ||
138 | + * @param intentId identifier of the intent to be updated | ||
139 | + * @return self | ||
140 | + */ | ||
141 | + public Builder addUpdateOperation(IntentId intentId) { | ||
142 | + checkNotNull(intentId, "Intent ID cannot be null"); | ||
143 | + builder.add(new IntentOperation(UPDATE, intentId, null)); | ||
144 | + return this; | ||
145 | + } | ||
146 | + | ||
147 | + /** | ||
111 | * Builds a batch of intent operations. | 148 | * Builds a batch of intent operations. |
112 | * | 149 | * |
113 | * @return immutable batch of intent operations | 150 | * @return immutable batch of intent operations | ... | ... |
... | @@ -17,7 +17,6 @@ package org.onlab.onos.net.intent; | ... | @@ -17,7 +17,6 @@ package org.onlab.onos.net.intent; |
17 | 17 | ||
18 | 18 | ||
19 | import java.util.List; | 19 | import java.util.List; |
20 | -import java.util.concurrent.Future; | ||
21 | 20 | ||
22 | /** | 21 | /** |
23 | * Service for application submitting or withdrawing their intents. | 22 | * Service for application submitting or withdrawing their intents. |
... | @@ -59,9 +58,8 @@ public interface IntentService { | ... | @@ -59,9 +58,8 @@ public interface IntentService { |
59 | * affected at later time. | 58 | * affected at later time. |
60 | * </p> | 59 | * </p> |
61 | * @param operations batch of intent operations | 60 | * @param operations batch of intent operations |
62 | - * @return Future to get execution result | ||
63 | */ | 61 | */ |
64 | - Future<IntentOperations> execute(IntentOperations operations); | 62 | + void execute(IntentOperations operations); |
65 | 63 | ||
66 | /** | 64 | /** |
67 | * Returns an iterable of intents currently in the system. | 65 | * Returns an iterable of intents currently in the system. | ... | ... |
... | @@ -24,7 +24,6 @@ import java.util.Map; | ... | @@ -24,7 +24,6 @@ import java.util.Map; |
24 | import java.util.Set; | 24 | import java.util.Set; |
25 | import java.util.concurrent.ExecutorService; | 25 | import java.util.concurrent.ExecutorService; |
26 | import java.util.concurrent.Executors; | 26 | import java.util.concurrent.Executors; |
27 | -import java.util.concurrent.Future; | ||
28 | 27 | ||
29 | /** | 28 | /** |
30 | * Fake implementation of the intent service to assist in developing tests of | 29 | * Fake implementation of the intent service to assist in developing tests of |
... | @@ -104,7 +103,7 @@ public class FakeIntentManager implements TestableIntentService { | ... | @@ -104,7 +103,7 @@ public class FakeIntentManager implements TestableIntentService { |
104 | try { | 103 | try { |
105 | // For the fake, we compile using a single level pass | 104 | // For the fake, we compile using a single level pass |
106 | List<Intent> installable = new ArrayList<>(); | 105 | List<Intent> installable = new ArrayList<>(); |
107 | - for (Intent compiled : getCompiler(intent).compile(intent)) { | 106 | + for (Intent compiled : getCompiler(intent).compile(intent, null, null)) { |
108 | installable.add((Intent) compiled); | 107 | installable.add((Intent) compiled); |
109 | } | 108 | } |
110 | executeInstallingPhase(intent, installable); | 109 | executeInstallingPhase(intent, installable); |
... | @@ -192,9 +191,8 @@ public class FakeIntentManager implements TestableIntentService { | ... | @@ -192,9 +191,8 @@ public class FakeIntentManager implements TestableIntentService { |
192 | } | 191 | } |
193 | 192 | ||
194 | @Override | 193 | @Override |
195 | - public Future<IntentOperations> execute(IntentOperations operations) { | 194 | + public void execute(IntentOperations operations) { |
196 | // TODO: implement later | 195 | // TODO: implement later |
197 | - return null; | ||
198 | } | 196 | } |
199 | 197 | ||
200 | @Override | 198 | @Override | ... | ... |
... | @@ -29,11 +29,13 @@ import java.util.Arrays; | ... | @@ -29,11 +29,13 @@ import java.util.Arrays; |
29 | import java.util.Collections; | 29 | import java.util.Collections; |
30 | import java.util.Iterator; | 30 | import java.util.Iterator; |
31 | import java.util.List; | 31 | import java.util.List; |
32 | +import java.util.Set; | ||
32 | 33 | ||
33 | import org.junit.After; | 34 | import org.junit.After; |
34 | import org.junit.Before; | 35 | import org.junit.Before; |
35 | import org.junit.Test; | 36 | import org.junit.Test; |
36 | import org.onlab.onos.net.flow.FlowRuleBatchOperation; | 37 | import org.onlab.onos.net.flow.FlowRuleBatchOperation; |
38 | +import org.onlab.onos.net.resource.LinkResourceAllocations; | ||
37 | 39 | ||
38 | /** | 40 | /** |
39 | * Suite of tests for the intent service contract. | 41 | * Suite of tests for the intent service contract. |
... | @@ -294,7 +296,8 @@ public class IntentServiceTest { | ... | @@ -294,7 +296,8 @@ public class IntentServiceTest { |
294 | } | 296 | } |
295 | 297 | ||
296 | @Override | 298 | @Override |
297 | - public List<Intent> compile(TestIntent intent) { | 299 | + public List<Intent> compile(TestIntent intent, List<Intent> installable, |
300 | + Set<LinkResourceAllocations> resources) { | ||
298 | if (fail) { | 301 | if (fail) { |
299 | throw new IntentException("compile failed by design"); | 302 | throw new IntentException("compile failed by design"); |
300 | } | 303 | } |
... | @@ -326,6 +329,12 @@ public class IntentServiceTest { | ... | @@ -326,6 +329,12 @@ public class IntentServiceTest { |
326 | } | 329 | } |
327 | return null; | 330 | return null; |
328 | } | 331 | } |
332 | + | ||
333 | + @Override | ||
334 | + public List<FlowRuleBatchOperation> replace(TestInstallableIntent intent, | ||
335 | + TestInstallableIntent newIntent) { | ||
336 | + return null; | ||
337 | + } | ||
329 | } | 338 | } |
330 | 339 | ||
331 | } | 340 | } | ... | ... |
... | @@ -509,13 +509,8 @@ public class FlowRuleManager | ... | @@ -509,13 +509,8 @@ public class FlowRuleManager |
509 | boolean success = true; | 509 | boolean success = true; |
510 | Set<FlowRule> failed = Sets.newHashSet(); | 510 | Set<FlowRule> failed = Sets.newHashSet(); |
511 | CompletedBatchOperation completed; | 511 | CompletedBatchOperation completed; |
512 | - long start = System.nanoTime(); | ||
513 | - long end = start + unit.toNanos(timeout); | ||
514 | - | ||
515 | for (Future<CompletedBatchOperation> future : futures) { | 512 | for (Future<CompletedBatchOperation> future : futures) { |
516 | - long now = System.nanoTime(); | 513 | + completed = future.get(timeout, unit); |
517 | - long thisTimeout = end - now; | ||
518 | - completed = future.get(thisTimeout, TimeUnit.NANOSECONDS); | ||
519 | success = validateBatchOperation(failed, completed); | 514 | success = validateBatchOperation(failed, completed); |
520 | } | 515 | } |
521 | return finalizeBatchOperation(success, failed); | 516 | return finalizeBatchOperation(success, failed); | ... | ... |
... | @@ -27,9 +27,11 @@ import org.onlab.onos.net.host.HostService; | ... | @@ -27,9 +27,11 @@ import org.onlab.onos.net.host.HostService; |
27 | import org.onlab.onos.net.intent.HostToHostIntent; | 27 | import org.onlab.onos.net.intent.HostToHostIntent; |
28 | import org.onlab.onos.net.intent.Intent; | 28 | import org.onlab.onos.net.intent.Intent; |
29 | import org.onlab.onos.net.intent.PathIntent; | 29 | import org.onlab.onos.net.intent.PathIntent; |
30 | +import org.onlab.onos.net.resource.LinkResourceAllocations; | ||
30 | 31 | ||
31 | import java.util.Arrays; | 32 | import java.util.Arrays; |
32 | import java.util.List; | 33 | import java.util.List; |
34 | +import java.util.Set; | ||
33 | 35 | ||
34 | import static org.onlab.onos.net.flow.DefaultTrafficSelector.builder; | 36 | import static org.onlab.onos.net.flow.DefaultTrafficSelector.builder; |
35 | 37 | ||
... | @@ -54,7 +56,8 @@ public class HostToHostIntentCompiler | ... | @@ -54,7 +56,8 @@ public class HostToHostIntentCompiler |
54 | } | 56 | } |
55 | 57 | ||
56 | @Override | 58 | @Override |
57 | - public List<Intent> compile(HostToHostIntent intent) { | 59 | + public List<Intent> compile(HostToHostIntent intent, List<Intent> installable, |
60 | + Set<LinkResourceAllocations> resources) { | ||
58 | Path pathOne = getPath(intent, intent.one(), intent.two()); | 61 | Path pathOne = getPath(intent, intent.one(), intent.two()); |
59 | Path pathTwo = getPath(intent, intent.two(), intent.one()); | 62 | Path pathTwo = getPath(intent, intent.two(), intent.one()); |
60 | 63 | ... | ... |
This diff is collapsed. Click to expand it.
... | @@ -111,6 +111,13 @@ public class LinkCollectionIntentInstaller implements IntentInstaller<LinkCollec | ... | @@ -111,6 +111,13 @@ public class LinkCollectionIntentInstaller implements IntentInstaller<LinkCollec |
111 | return Lists.newArrayList(new FlowRuleBatchOperation(rules)); | 111 | return Lists.newArrayList(new FlowRuleBatchOperation(rules)); |
112 | } | 112 | } |
113 | 113 | ||
114 | + @Override | ||
115 | + public List<FlowRuleBatchOperation> replace(LinkCollectionIntent intent, | ||
116 | + LinkCollectionIntent newIntent) { | ||
117 | + // FIXME: implement | ||
118 | + return null; | ||
119 | + } | ||
120 | + | ||
114 | /** | 121 | /** |
115 | * Creates a FlowRuleBatchEntry based on the provided parameters. | 122 | * Creates a FlowRuleBatchEntry based on the provided parameters. |
116 | * | 123 | * | ... | ... |
... | @@ -29,6 +29,7 @@ import org.onlab.onos.net.intent.IntentExtensionService; | ... | @@ -29,6 +29,7 @@ import org.onlab.onos.net.intent.IntentExtensionService; |
29 | import org.onlab.onos.net.intent.LinkCollectionIntent; | 29 | import org.onlab.onos.net.intent.LinkCollectionIntent; |
30 | import org.onlab.onos.net.intent.MultiPointToSinglePointIntent; | 30 | import org.onlab.onos.net.intent.MultiPointToSinglePointIntent; |
31 | import org.onlab.onos.net.intent.PointToPointIntent; | 31 | import org.onlab.onos.net.intent.PointToPointIntent; |
32 | +import org.onlab.onos.net.resource.LinkResourceAllocations; | ||
32 | import org.onlab.onos.net.topology.PathService; | 33 | import org.onlab.onos.net.topology.PathService; |
33 | 34 | ||
34 | import java.util.Arrays; | 35 | import java.util.Arrays; |
... | @@ -61,7 +62,8 @@ public class MultiPointToSinglePointIntentCompiler | ... | @@ -61,7 +62,8 @@ public class MultiPointToSinglePointIntentCompiler |
61 | } | 62 | } |
62 | 63 | ||
63 | @Override | 64 | @Override |
64 | - public List<Intent> compile(MultiPointToSinglePointIntent intent) { | 65 | + public List<Intent> compile(MultiPointToSinglePointIntent intent, List<Intent> installable, |
66 | + Set<LinkResourceAllocations> resources) { | ||
65 | Set<Link> links = new HashSet<>(); | 67 | Set<Link> links = new HashSet<>(); |
66 | 68 | ||
67 | for (ConnectPoint ingressPoint : intent.ingressPoints()) { | 69 | for (ConnectPoint ingressPoint : intent.ingressPoints()) { | ... | ... |
... | @@ -29,6 +29,7 @@ import org.onlab.onos.net.intent.IntentCompiler; | ... | @@ -29,6 +29,7 @@ import org.onlab.onos.net.intent.IntentCompiler; |
29 | import org.onlab.onos.net.intent.IntentExtensionService; | 29 | import org.onlab.onos.net.intent.IntentExtensionService; |
30 | import org.onlab.onos.net.intent.OpticalConnectivityIntent; | 30 | import org.onlab.onos.net.intent.OpticalConnectivityIntent; |
31 | import org.onlab.onos.net.intent.OpticalPathIntent; | 31 | import org.onlab.onos.net.intent.OpticalPathIntent; |
32 | +import org.onlab.onos.net.resource.LinkResourceAllocations; | ||
32 | import org.onlab.onos.net.topology.LinkWeight; | 33 | import org.onlab.onos.net.topology.LinkWeight; |
33 | import org.onlab.onos.net.topology.Topology; | 34 | import org.onlab.onos.net.topology.Topology; |
34 | import org.onlab.onos.net.topology.TopologyEdge; | 35 | import org.onlab.onos.net.topology.TopologyEdge; |
... | @@ -60,7 +61,9 @@ public class OpticalConnectivityIntentCompiler implements IntentCompiler<Optical | ... | @@ -60,7 +61,9 @@ public class OpticalConnectivityIntentCompiler implements IntentCompiler<Optical |
60 | } | 61 | } |
61 | 62 | ||
62 | @Override | 63 | @Override |
63 | - public List<Intent> compile(OpticalConnectivityIntent intent) { | 64 | + public List<Intent> compile(OpticalConnectivityIntent intent, |
65 | + List<Intent> installable, | ||
66 | + Set<LinkResourceAllocations> resources) { | ||
64 | // TODO: compute multiple paths using the K-shortest path algorithm | 67 | // TODO: compute multiple paths using the K-shortest path algorithm |
65 | Path path = calculateOpticalPath(intent.getSrcConnectPoint(), intent.getDst()); | 68 | Path path = calculateOpticalPath(intent.getSrcConnectPoint(), intent.getDst()); |
66 | Intent newIntent = new OpticalPathIntent(intent.appId(), | 69 | Intent newIntent = new OpticalPathIntent(intent.appId(), | ... | ... |
... | @@ -104,6 +104,13 @@ public class OpticalPathIntentInstaller implements IntentInstaller<OpticalPathIn | ... | @@ -104,6 +104,13 @@ public class OpticalPathIntentInstaller implements IntentInstaller<OpticalPathIn |
104 | return generateRules(intent, allocations, FlowRuleOperation.REMOVE); | 104 | return generateRules(intent, allocations, FlowRuleOperation.REMOVE); |
105 | } | 105 | } |
106 | 106 | ||
107 | + @Override | ||
108 | + public List<FlowRuleBatchOperation> replace(OpticalPathIntent intent, | ||
109 | + OpticalPathIntent newIntent) { | ||
110 | + // FIXME: implement this | ||
111 | + return null; | ||
112 | + } | ||
113 | + | ||
107 | private LinkResourceAllocations assignWavelength(OpticalPathIntent intent) { | 114 | private LinkResourceAllocations assignWavelength(OpticalPathIntent intent) { |
108 | LinkResourceRequest.Builder request = DefaultLinkResourceRequest.builder(intent.id(), | 115 | LinkResourceRequest.Builder request = DefaultLinkResourceRequest.builder(intent.id(), |
109 | intent.path().links()) | 116 | intent.path().links()) | ... | ... |
... | @@ -131,6 +131,15 @@ public class PathIntentInstaller implements IntentInstaller<PathIntent> { | ... | @@ -131,6 +131,15 @@ public class PathIntentInstaller implements IntentInstaller<PathIntent> { |
131 | return Lists.newArrayList(new FlowRuleBatchOperation(rules)); | 131 | return Lists.newArrayList(new FlowRuleBatchOperation(rules)); |
132 | } | 132 | } |
133 | 133 | ||
134 | + @Override | ||
135 | + public List<FlowRuleBatchOperation> replace(PathIntent oldIntent, PathIntent newIntent) { | ||
136 | + // FIXME: implement this | ||
137 | + List<FlowRuleBatchOperation> batches = Lists.newArrayList(); | ||
138 | + batches.addAll(uninstall(oldIntent)); | ||
139 | + batches.addAll(install(newIntent)); | ||
140 | + return batches; | ||
141 | + } | ||
142 | + | ||
134 | /** | 143 | /** |
135 | * Allocate resources required for an intent. | 144 | * Allocate resources required for an intent. |
136 | * | 145 | * |
... | @@ -147,7 +156,7 @@ public class PathIntentInstaller implements IntentInstaller<PathIntent> { | ... | @@ -147,7 +156,7 @@ public class PathIntentInstaller implements IntentInstaller<PathIntent> { |
147 | return request.resources().isEmpty() ? null : resourceService.requestResources(request); | 156 | return request.resources().isEmpty() ? null : resourceService.requestResources(request); |
148 | } | 157 | } |
149 | 158 | ||
150 | - // TODO refactor below this line... ---------------------------- | 159 | + // FIXME refactor below this line... ---------------------------- |
151 | 160 | ||
152 | /** | 161 | /** |
153 | * Generates the series of MatchActionOperations from the | 162 | * Generates the series of MatchActionOperations from the | ... | ... |
... | @@ -28,9 +28,11 @@ import org.onlab.onos.net.intent.Intent; | ... | @@ -28,9 +28,11 @@ import org.onlab.onos.net.intent.Intent; |
28 | import org.onlab.onos.net.intent.PathIntent; | 28 | import org.onlab.onos.net.intent.PathIntent; |
29 | import org.onlab.onos.net.intent.PointToPointIntent; | 29 | import org.onlab.onos.net.intent.PointToPointIntent; |
30 | import org.onlab.onos.net.provider.ProviderId; | 30 | import org.onlab.onos.net.provider.ProviderId; |
31 | +import org.onlab.onos.net.resource.LinkResourceAllocations; | ||
31 | 32 | ||
32 | import java.util.ArrayList; | 33 | import java.util.ArrayList; |
33 | import java.util.List; | 34 | import java.util.List; |
35 | +import java.util.Set; | ||
34 | 36 | ||
35 | import static java.util.Arrays.asList; | 37 | import static java.util.Arrays.asList; |
36 | import static org.onlab.onos.net.Link.Type.DIRECT; | 38 | import static org.onlab.onos.net.Link.Type.DIRECT; |
... | @@ -57,7 +59,9 @@ public class PointToPointIntentCompiler | ... | @@ -57,7 +59,9 @@ public class PointToPointIntentCompiler |
57 | } | 59 | } |
58 | 60 | ||
59 | @Override | 61 | @Override |
60 | - public List<Intent> compile(PointToPointIntent intent) { | 62 | + public List<Intent> compile(PointToPointIntent intent, List<Intent> installable, |
63 | + Set<LinkResourceAllocations> resources) { | ||
64 | + | ||
61 | ConnectPoint ingressPoint = intent.ingressPoint(); | 65 | ConnectPoint ingressPoint = intent.ingressPoint(); |
62 | ConnectPoint egressPoint = intent.egressPoint(); | 66 | ConnectPoint egressPoint = intent.egressPoint(); |
63 | 67 | ... | ... |
... | @@ -87,7 +87,7 @@ public class PathConstraintCalculationTest { | ... | @@ -87,7 +87,7 @@ public class PathConstraintCalculationTest { |
87 | constraints); | 87 | constraints); |
88 | final PointToPointIntentCompiler compiler = makeCompiler(resourceService); | 88 | final PointToPointIntentCompiler compiler = makeCompiler(resourceService); |
89 | 89 | ||
90 | - return compiler.compile(intent); | 90 | + return compiler.compile(intent, null, null); |
91 | } | 91 | } |
92 | 92 | ||
93 | /** | 93 | /** | ... | ... |
... | @@ -121,7 +121,7 @@ public class TestHostToHostIntentCompiler { | ... | @@ -121,7 +121,7 @@ public class TestHostToHostIntentCompiler { |
121 | HostToHostIntentCompiler compiler = makeCompiler(hops); | 121 | HostToHostIntentCompiler compiler = makeCompiler(hops); |
122 | assertThat(compiler, is(notNullValue())); | 122 | assertThat(compiler, is(notNullValue())); |
123 | 123 | ||
124 | - List<Intent> result = compiler.compile(intent); | 124 | + List<Intent> result = compiler.compile(intent, null, null); |
125 | assertThat(result, is(Matchers.notNullValue())); | 125 | assertThat(result, is(Matchers.notNullValue())); |
126 | assertThat(result, hasSize(2)); | 126 | assertThat(result, hasSize(2)); |
127 | Intent forwardResultIntent = result.get(0); | 127 | Intent forwardResultIntent = result.get(0); | ... | ... |
core/net/src/test/java/org/onlab/onos/net/intent/impl/TestMultiPointToSinglePointIntentCompiler.java
... | @@ -137,7 +137,7 @@ public class TestMultiPointToSinglePointIntentCompiler { | ... | @@ -137,7 +137,7 @@ public class TestMultiPointToSinglePointIntentCompiler { |
137 | MultiPointToSinglePointIntentCompiler compiler = makeCompiler(hops); | 137 | MultiPointToSinglePointIntentCompiler compiler = makeCompiler(hops); |
138 | assertThat(compiler, is(notNullValue())); | 138 | assertThat(compiler, is(notNullValue())); |
139 | 139 | ||
140 | - List<Intent> result = compiler.compile(intent); | 140 | + List<Intent> result = compiler.compile(intent, null, null); |
141 | assertThat(result, is(Matchers.notNullValue())); | 141 | assertThat(result, is(Matchers.notNullValue())); |
142 | assertThat(result, hasSize(1)); | 142 | assertThat(result, hasSize(1)); |
143 | Intent resultIntent = result.get(0); | 143 | Intent resultIntent = result.get(0); |
... | @@ -172,7 +172,7 @@ public class TestMultiPointToSinglePointIntentCompiler { | ... | @@ -172,7 +172,7 @@ public class TestMultiPointToSinglePointIntentCompiler { |
172 | MultiPointToSinglePointIntentCompiler compiler = makeCompiler(hops); | 172 | MultiPointToSinglePointIntentCompiler compiler = makeCompiler(hops); |
173 | assertThat(compiler, is(notNullValue())); | 173 | assertThat(compiler, is(notNullValue())); |
174 | 174 | ||
175 | - List<Intent> result = compiler.compile(intent); | 175 | + List<Intent> result = compiler.compile(intent, null, null); |
176 | assertThat(result, is(notNullValue())); | 176 | assertThat(result, is(notNullValue())); |
177 | assertThat(result, hasSize(1)); | 177 | assertThat(result, hasSize(1)); |
178 | Intent resultIntent = result.get(0); | 178 | Intent resultIntent = result.get(0); |
... | @@ -205,7 +205,7 @@ public class TestMultiPointToSinglePointIntentCompiler { | ... | @@ -205,7 +205,7 @@ public class TestMultiPointToSinglePointIntentCompiler { |
205 | MultiPointToSinglePointIntentCompiler compiler = makeCompiler(hops); | 205 | MultiPointToSinglePointIntentCompiler compiler = makeCompiler(hops); |
206 | assertThat(compiler, is(notNullValue())); | 206 | assertThat(compiler, is(notNullValue())); |
207 | 207 | ||
208 | - List<Intent> result = compiler.compile(intent); | 208 | + List<Intent> result = compiler.compile(intent, null, null); |
209 | assertThat(result, is(notNullValue())); | 209 | assertThat(result, is(notNullValue())); |
210 | assertThat(result, hasSize(1)); | 210 | assertThat(result, hasSize(1)); |
211 | Intent resultIntent = result.get(0); | 211 | Intent resultIntent = result.get(0); | ... | ... |
... | @@ -93,7 +93,7 @@ public class TestPointToPointIntentCompiler { | ... | @@ -93,7 +93,7 @@ public class TestPointToPointIntentCompiler { |
93 | PointToPointIntentCompiler compiler = makeCompiler(hops); | 93 | PointToPointIntentCompiler compiler = makeCompiler(hops); |
94 | assertThat(compiler, is(notNullValue())); | 94 | assertThat(compiler, is(notNullValue())); |
95 | 95 | ||
96 | - List<Intent> result = compiler.compile(intent); | 96 | + List<Intent> result = compiler.compile(intent, null, null); |
97 | assertThat(result, is(Matchers.notNullValue())); | 97 | assertThat(result, is(Matchers.notNullValue())); |
98 | assertThat(result, hasSize(1)); | 98 | assertThat(result, hasSize(1)); |
99 | Intent forwardResultIntent = result.get(0); | 99 | Intent forwardResultIntent = result.get(0); |
... | @@ -126,7 +126,7 @@ public class TestPointToPointIntentCompiler { | ... | @@ -126,7 +126,7 @@ public class TestPointToPointIntentCompiler { |
126 | PointToPointIntentCompiler compiler = makeCompiler(hops); | 126 | PointToPointIntentCompiler compiler = makeCompiler(hops); |
127 | assertThat(compiler, is(notNullValue())); | 127 | assertThat(compiler, is(notNullValue())); |
128 | 128 | ||
129 | - List<Intent> result = compiler.compile(intent); | 129 | + List<Intent> result = compiler.compile(intent, null, null); |
130 | assertThat(result, is(Matchers.notNullValue())); | 130 | assertThat(result, is(Matchers.notNullValue())); |
131 | assertThat(result, hasSize(1)); | 131 | assertThat(result, hasSize(1)); |
132 | Intent reverseResultIntent = result.get(0); | 132 | Intent reverseResultIntent = result.get(0); |
... | @@ -157,7 +157,7 @@ public class TestPointToPointIntentCompiler { | ... | @@ -157,7 +157,7 @@ public class TestPointToPointIntentCompiler { |
157 | String[] hops = {"1"}; | 157 | String[] hops = {"1"}; |
158 | PointToPointIntentCompiler sut = makeCompiler(hops); | 158 | PointToPointIntentCompiler sut = makeCompiler(hops); |
159 | 159 | ||
160 | - List<Intent> compiled = sut.compile(intent); | 160 | + List<Intent> compiled = sut.compile(intent, null, null); |
161 | 161 | ||
162 | assertThat(compiled, hasSize(1)); | 162 | assertThat(compiled, hasSize(1)); |
163 | assertThat(compiled.get(0), is(instanceOf(PathIntent.class))); | 163 | assertThat(compiled.get(0), is(instanceOf(PathIntent.class))); | ... | ... |
core/store/trivial/src/main/java/org/onlab/onos/store/trivial/impl/SimpleIntentBatchQueue.java
0 → 100644
1 | +/* | ||
2 | + * Copyright 2014 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 | +package org.onlab.onos.store.trivial.impl; | ||
17 | + | ||
18 | +import com.google.common.collect.ImmutableSet; | ||
19 | +import org.apache.felix.scr.annotations.Activate; | ||
20 | +import org.apache.felix.scr.annotations.Component; | ||
21 | +import org.apache.felix.scr.annotations.Deactivate; | ||
22 | +import org.apache.felix.scr.annotations.Service; | ||
23 | +import org.onlab.onos.net.intent.IntentBatchDelegate; | ||
24 | +import org.onlab.onos.net.intent.IntentBatchService; | ||
25 | +import org.onlab.onos.net.intent.IntentOperations; | ||
26 | +import org.slf4j.Logger; | ||
27 | + | ||
28 | +import java.util.HashSet; | ||
29 | +import java.util.Set; | ||
30 | + | ||
31 | +import static com.google.common.base.Preconditions.checkNotNull; | ||
32 | +import static com.google.common.base.Preconditions.checkState; | ||
33 | +import static org.slf4j.LoggerFactory.getLogger; | ||
34 | + | ||
35 | +@Component(immediate = true) | ||
36 | +@Service | ||
37 | +public class SimpleIntentBatchQueue implements IntentBatchService { | ||
38 | + | ||
39 | + private final Logger log = getLogger(getClass()); | ||
40 | + private final Set<IntentOperations> pendingBatches = new HashSet<>(); | ||
41 | + private IntentBatchDelegate delegate; | ||
42 | + | ||
43 | + @Activate | ||
44 | + public void activate() { | ||
45 | + log.info("Started"); | ||
46 | + } | ||
47 | + | ||
48 | + @Deactivate | ||
49 | + public void deactivate() { | ||
50 | + log.info("Stopped"); | ||
51 | + } | ||
52 | + | ||
53 | + @Override | ||
54 | + public void addIntentOperations(IntentOperations operations) { | ||
55 | + checkState(delegate != null, "No delegate set"); | ||
56 | + pendingBatches.add(operations); | ||
57 | + delegate.execute(operations); | ||
58 | + } | ||
59 | + | ||
60 | + @Override | ||
61 | + public void removeIntentOperations(IntentOperations operations) { | ||
62 | + pendingBatches.remove(operations); | ||
63 | + } | ||
64 | + | ||
65 | + @Override | ||
66 | + public Set<IntentOperations> getIntentOperations() { | ||
67 | + return ImmutableSet.copyOf(pendingBatches); | ||
68 | + } | ||
69 | + | ||
70 | + @Override | ||
71 | + public void setDelegate(IntentBatchDelegate delegate) { | ||
72 | + this.delegate = checkNotNull(delegate, "Delegate cannot be null"); | ||
73 | + } | ||
74 | + | ||
75 | + @Override | ||
76 | + public void unsetDelegate(IntentBatchDelegate delegate) { | ||
77 | + if (this.delegate != null && this.delegate.equals(delegate)) { | ||
78 | + this.delegate = null; | ||
79 | + } | ||
80 | + } | ||
81 | +} |
... | @@ -33,7 +33,7 @@ import java.util.List; | ... | @@ -33,7 +33,7 @@ import java.util.List; |
33 | import java.util.Map; | 33 | import java.util.Map; |
34 | import java.util.concurrent.ConcurrentHashMap; | 34 | import java.util.concurrent.ConcurrentHashMap; |
35 | 35 | ||
36 | -import static org.onlab.onos.net.intent.IntentState.*; | 36 | +import static org.onlab.onos.net.intent.IntentState.WITHDRAWN; |
37 | import static org.slf4j.LoggerFactory.getLogger; | 37 | import static org.slf4j.LoggerFactory.getLogger; |
38 | 38 | ||
39 | @Component(immediate = true) | 39 | @Component(immediate = true) |
... | @@ -45,8 +45,8 @@ public class SimpleIntentStore | ... | @@ -45,8 +45,8 @@ public class SimpleIntentStore |
45 | private final Logger log = getLogger(getClass()); | 45 | private final Logger log = getLogger(getClass()); |
46 | private final Map<IntentId, Intent> intents = new ConcurrentHashMap<>(); | 46 | private final Map<IntentId, Intent> intents = new ConcurrentHashMap<>(); |
47 | private final Map<IntentId, IntentState> states = new ConcurrentHashMap<>(); | 47 | private final Map<IntentId, IntentState> states = new ConcurrentHashMap<>(); |
48 | - private final Map<IntentId, List<Intent>> installable = | 48 | + private final Map<IntentId, List<Intent>> installable = new ConcurrentHashMap<>(); |
49 | - new ConcurrentHashMap<>(); | 49 | + |
50 | 50 | ||
51 | @Activate | 51 | @Activate |
52 | public void activate() { | 52 | public void activate() { |
... | @@ -60,6 +60,9 @@ public class SimpleIntentStore | ... | @@ -60,6 +60,9 @@ public class SimpleIntentStore |
60 | 60 | ||
61 | @Override | 61 | @Override |
62 | public IntentEvent createIntent(Intent intent) { | 62 | public IntentEvent createIntent(Intent intent) { |
63 | + if (intents.containsKey(intent.id())) { | ||
64 | + return null; | ||
65 | + } | ||
63 | intents.put(intent.id(), intent); | 66 | intents.put(intent.id(), intent); |
64 | return this.setState(intent, IntentState.SUBMITTED); | 67 | return this.setState(intent, IntentState.SUBMITTED); |
65 | } | 68 | } | ... | ... |
-
Please register or login to post a comment