Sho SHIMIZU
Committed by Ray Milkey

Merge IntentInstaller's role into IntentCompiler

It resolves naming mismatch in naming of IntentProcessPhases and states
handled in the phases. It is described in ONOS-1064.

- Define FlowRuleIntent that enables flow rule level operation
  as an intent.
- Remove IntentInstaller interface
- Existing installable intents such as PathIntent, LinkCollectionIntent,
  OpticalPathIntent and MplsPathIntent now become non installable intents.
  Only FlowRuleIntent is categorized as installable intent now.
- Implement intent compilers for PathIntent, LinkCollectionIntent,
  OpticalPathIntent and MplsPathIntent. They generates FlowRuleIntents.
- Write unit tests for the newly created intent compilers according to
  the intent installers' unit tests
- Remove all intent installers and their unit tests

Change-Id: I22d6c7acb65a4c066145de0018bd0727f44bd54a
Showing 47 changed files with 1243 additions and 2299 deletions
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 +package org.onosproject.net.intent;
17 +
18 +import com.google.common.base.MoreObjects;
19 +import com.google.common.collect.ImmutableList;
20 +import org.onosproject.core.ApplicationId;
21 +import org.onosproject.net.NetworkResource;
22 +import org.onosproject.net.flow.FlowRule;
23 +
24 +import java.util.Collection;
25 +import java.util.Collections;
26 +import java.util.List;
27 +
28 +import static com.google.common.base.Preconditions.checkNotNull;
29 +
30 +/**
31 + * An intent that enables to tell flow level operation.
32 + * This instance holds a collection of flow rules that may be executed in parallel.
33 + */
34 +public class FlowRuleIntent extends Intent {
35 +
36 + private final Collection<FlowRule> flowRules;
37 +
38 + /**
39 + * Creates an flow rule intent with the specified flow rules to be set.
40 + *
41 + * @param appId application id
42 + * @param flowRules flow rules to be set.
43 + */
44 + public FlowRuleIntent(ApplicationId appId, List<FlowRule> flowRules) {
45 + this(appId, null, flowRules, Collections.emptyList());
46 + }
47 +
48 + /**
49 + * Creates an flow rule intent with the specified key, flow rules to be set, and
50 + * required network resources.
51 + *
52 + * @param appId application id
53 + * @param key key
54 + * @param flowRules flow rules
55 + * @param resources network resources
56 + */
57 + public FlowRuleIntent(ApplicationId appId, Key key, Collection<FlowRule> flowRules,
58 + Collection<NetworkResource> resources) {
59 + super(appId, key, resources, DEFAULT_INTENT_PRIORITY);
60 + this.flowRules = ImmutableList.copyOf(checkNotNull(flowRules));
61 + }
62 +
63 + /**
64 + * Returns a collection of flow rules to be set.
65 + *
66 + * @return a collection of flow rules
67 + */
68 + public Collection<FlowRule> flowRules() {
69 + return flowRules;
70 + }
71 +
72 + @Override
73 + public boolean isInstallable() {
74 + return true;
75 + }
76 +
77 + @Override
78 + public String toString() {
79 + return MoreObjects.toStringHelper(this)
80 + .add("id", id())
81 + .add("key", key())
82 + .add("appId", appId())
83 + .add("resources", resources())
84 + .add("flowRule", flowRules)
85 + .toString();
86 + }
87 +}
...@@ -45,28 +45,4 @@ public interface IntentExtensionService { ...@@ -45,28 +45,4 @@ public interface IntentExtensionService {
45 * @return the set of compiler bindings 45 * @return the set of compiler bindings
46 */ 46 */
47 Map<Class<? extends Intent>, IntentCompiler<? extends Intent>> getCompilers(); 47 Map<Class<? extends Intent>, IntentCompiler<? extends Intent>> getCompilers();
48 -
49 - /**
50 - * Registers the specified installer for the given installable intent class.
51 - *
52 - * @param cls installable intent class
53 - * @param installer intent installer
54 - * @param <T> the type of installable intent
55 - */
56 - <T extends Intent> void registerInstaller(Class<T> cls, IntentInstaller<T> installer);
57 -
58 - /**
59 - * Unregisters the installer for the given installable intent class.
60 - *
61 - * @param cls installable intent class
62 - * @param <T> the type of installable intent
63 - */
64 - <T extends Intent> void unregisterInstaller(Class<T> cls);
65 -
66 - /**
67 - * Returns immutable set of bindings of currently registered intent installers.
68 - *
69 - * @return the set of installer bindings
70 - */
71 - Map<Class<? extends Intent>, IntentInstaller<? extends Intent>> getInstallers();
72 } 48 }
......
...@@ -222,11 +222,6 @@ public final class LinkCollectionIntent extends ConnectivityIntent { ...@@ -222,11 +222,6 @@ public final class LinkCollectionIntent extends ConnectivityIntent {
222 } 222 }
223 223
224 @Override 224 @Override
225 - public boolean isInstallable() {
226 - return true;
227 - }
228 -
229 - @Override
230 public String toString() { 225 public String toString() {
231 return MoreObjects.toStringHelper(getClass()) 226 return MoreObjects.toStringHelper(getClass())
232 .add("id", id()) 227 .add("id", id())
......
...@@ -154,11 +154,6 @@ public final class OpticalPathIntent extends Intent { ...@@ -154,11 +154,6 @@ public final class OpticalPathIntent extends Intent {
154 } 154 }
155 155
156 @Override 156 @Override
157 - public boolean isInstallable() {
158 - return true;
159 - }
160 -
161 - @Override
162 public String toString() { 157 public String toString() {
163 return MoreObjects.toStringHelper(getClass()) 158 return MoreObjects.toStringHelper(getClass())
164 .add("id", id()) 159 .add("id", id())
......
...@@ -184,12 +184,6 @@ public class PathIntent extends ConnectivityIntent { ...@@ -184,12 +184,6 @@ public class PathIntent extends ConnectivityIntent {
184 } 184 }
185 185
186 @Override 186 @Override
187 - public boolean isInstallable() {
188 - return true;
189 - }
190 -
191 -
192 - @Override
193 public String toString() { 187 public String toString() {
194 return MoreObjects.toStringHelper(getClass()) 188 return MoreObjects.toStringHelper(getClass())
195 .add("id", id()) 189 .add("id", id())
......
...@@ -37,8 +37,6 @@ public class FakeIntentManager implements TestableIntentService { ...@@ -37,8 +37,6 @@ public class FakeIntentManager implements TestableIntentService {
37 private final Set<IntentListener> listeners = new HashSet<>(); 37 private final Set<IntentListener> listeners = new HashSet<>();
38 38
39 private final Map<Class<? extends Intent>, IntentCompiler<? extends Intent>> compilers = new HashMap<>(); 39 private final Map<Class<? extends Intent>, IntentCompiler<? extends Intent>> compilers = new HashMap<>();
40 - private final Map<Class<? extends Intent>, IntentInstaller<? extends Intent>> installers
41 - = new HashMap<>();
42 40
43 private final ExecutorService executor = Executors.newSingleThreadExecutor(); 41 private final ExecutorService executor = Executors.newSingleThreadExecutor();
44 private final List<IntentException> exceptions = new ArrayList<>(); 42 private final List<IntentException> exceptions = new ArrayList<>();
...@@ -88,16 +86,6 @@ public class FakeIntentManager implements TestableIntentService { ...@@ -88,16 +86,6 @@ public class FakeIntentManager implements TestableIntentService {
88 return compiler; 86 return compiler;
89 } 87 }
90 88
91 - private <T extends Intent> IntentInstaller<T> getInstaller(T intent) {
92 - @SuppressWarnings("unchecked")
93 - IntentInstaller<T> installer = (IntentInstaller<T>) installers.get(intent
94 - .getClass());
95 - if (installer == null) {
96 - throw new IntentException("no installer for class " + intent.getClass());
97 - }
98 - return installer;
99 - }
100 -
101 private <T extends Intent> void executeCompilingPhase(T intent) { 89 private <T extends Intent> void executeCompilingPhase(T intent) {
102 setState(intent, IntentState.COMPILING); 90 setState(intent, IntentState.COMPILING);
103 try { 91 try {
...@@ -118,10 +106,6 @@ public class FakeIntentManager implements TestableIntentService { ...@@ -118,10 +106,6 @@ public class FakeIntentManager implements TestableIntentService {
118 List<Intent> installable) { 106 List<Intent> installable) {
119 setState(intent, IntentState.INSTALLING); 107 setState(intent, IntentState.INSTALLING);
120 try { 108 try {
121 - for (Intent ii : installable) {
122 - registerSubclassInstallerIfNeeded(ii);
123 - getInstaller(ii).install(ii);
124 - }
125 setState(intent, IntentState.INSTALLED); 109 setState(intent, IntentState.INSTALLED);
126 putInstallable(intent.key(), installable); 110 putInstallable(intent.key(), installable);
127 dispatch(new IntentEvent(IntentEvent.Type.INSTALLED, intent)); 111 dispatch(new IntentEvent(IntentEvent.Type.INSTALLED, intent));
...@@ -136,9 +120,6 @@ public class FakeIntentManager implements TestableIntentService { ...@@ -136,9 +120,6 @@ public class FakeIntentManager implements TestableIntentService {
136 List<Intent> installable) { 120 List<Intent> installable) {
137 setState(intent, IntentState.WITHDRAWING); 121 setState(intent, IntentState.WITHDRAWING);
138 try { 122 try {
139 - for (Intent ii : installable) {
140 - getInstaller(ii).uninstall(ii);
141 - }
142 removeInstallable(intent.key()); 123 removeInstallable(intent.key());
143 setState(intent, IntentState.WITHDRAWN); 124 setState(intent, IntentState.WITHDRAWN);
144 dispatch(new IntentEvent(IntentEvent.Type.WITHDRAWN, intent)); 125 dispatch(new IntentEvent(IntentEvent.Type.WITHDRAWN, intent));
...@@ -263,23 +244,6 @@ public class FakeIntentManager implements TestableIntentService { ...@@ -263,23 +244,6 @@ public class FakeIntentManager implements TestableIntentService {
263 return Collections.unmodifiableMap(compilers); 244 return Collections.unmodifiableMap(compilers);
264 } 245 }
265 246
266 - @Override
267 - public <T extends Intent> void registerInstaller(Class<T> cls,
268 - IntentInstaller<T> installer) {
269 - installers.put(cls, installer);
270 - }
271 -
272 - @Override
273 - public <T extends Intent> void unregisterInstaller(Class<T> cls) {
274 - installers.remove(cls);
275 - }
276 -
277 - @Override
278 - public Map<Class<? extends Intent>,
279 - IntentInstaller<? extends Intent>> getInstallers() {
280 - return Collections.unmodifiableMap(installers);
281 - }
282 -
283 private void registerSubclassCompilerIfNeeded(Intent intent) { 247 private void registerSubclassCompilerIfNeeded(Intent intent) {
284 if (!compilers.containsKey(intent.getClass())) { 248 if (!compilers.containsKey(intent.getClass())) {
285 Class<?> cls = intent.getClass(); 249 Class<?> cls = intent.getClass();
...@@ -296,23 +260,4 @@ public class FakeIntentManager implements TestableIntentService { ...@@ -296,23 +260,4 @@ public class FakeIntentManager implements TestableIntentService {
296 } 260 }
297 } 261 }
298 } 262 }
299 -
300 - private void registerSubclassInstallerIfNeeded(Intent intent) {
301 - if (!installers.containsKey(intent.getClass())) {
302 - Class<?> cls = intent.getClass();
303 - while (cls != Object.class) {
304 - // As long as we're within the Intent class
305 - // descendants
306 - if (Intent.class.isAssignableFrom(cls)) {
307 - IntentInstaller<?> installer = installers.get(cls);
308 - if (installer != null) {
309 - installers.put(intent.getClass(), installer);
310 - return;
311 - }
312 - }
313 - cls = cls.getSuperclass();
314 - }
315 - }
316 - }
317 -
318 } 263 }
......
...@@ -19,12 +19,10 @@ import org.junit.After; ...@@ -19,12 +19,10 @@ import org.junit.After;
19 import org.junit.Before; 19 import org.junit.Before;
20 import org.junit.Test; 20 import org.junit.Test;
21 import org.onosproject.core.IdGenerator; 21 import org.onosproject.core.IdGenerator;
22 -import org.onosproject.net.flow.FlowRuleOperation;
23 import org.onosproject.net.resource.LinkResourceAllocations; 22 import org.onosproject.net.resource.LinkResourceAllocations;
24 23
25 import java.util.ArrayList; 24 import java.util.ArrayList;
26 import java.util.Arrays; 25 import java.util.Arrays;
27 -import java.util.Collection;
28 import java.util.Collections; 26 import java.util.Collections;
29 import java.util.Iterator; 27 import java.util.Iterator;
30 import java.util.List; 28 import java.util.List;
...@@ -76,7 +74,6 @@ public class IntentServiceTest { ...@@ -76,7 +74,6 @@ public class IntentServiceTest {
76 74
77 // Register a compiler and an installer both setup for success. 75 // Register a compiler and an installer both setup for success.
78 service.registerCompiler(TestIntent.class, new TestCompiler(new TestInstallableIntent(INSTALLABLE_IID))); 76 service.registerCompiler(TestIntent.class, new TestCompiler(new TestInstallableIntent(INSTALLABLE_IID)));
79 - service.registerInstaller(TestInstallableIntent.class, new TestInstaller(false));
80 77
81 final Intent intent = new TestIntent(IID); 78 final Intent intent = new TestIntent(IID);
82 service.submit(intent); 79 service.submit(intent);
...@@ -143,29 +140,6 @@ public class IntentServiceTest { ...@@ -143,29 +140,6 @@ public class IntentServiceTest {
143 validateEvents(intent, INSTALL_REQ, FAILED); 140 validateEvents(intent, INSTALL_REQ, FAILED);
144 } 141 }
145 142
146 - @Test
147 - public void failedInstallation() {
148 - // Register a compiler programmed for success and installer for failure
149 - service.registerCompiler(TestIntent.class, new TestCompiler(new TestInstallableIntent(INSTALLABLE_IID)));
150 - service.registerInstaller(TestInstallableIntent.class, new TestInstaller(true));
151 -
152 - // Submit an intent
153 - final Intent intent = new TestIntent(IID);
154 - service.submit(intent);
155 -
156 - // Allow a small window of time until the intent is in the expected state
157 - TestTools.assertAfter(GRACE_MS, new Runnable() {
158 - @Override
159 - public void run() {
160 - assertEquals("incorrect intent state", IntentState.FAILED,
161 - service.getIntentState(intent.key()));
162 - }
163 - });
164 -
165 - // Make sure that all expected events have been emitted
166 - validateEvents(intent, INSTALL_REQ, FAILED);
167 - }
168 -
169 /** 143 /**
170 * Validates that the test event listener has received the following events 144 * Validates that the test event listener has received the following events
171 * for the specified intent. Events received for other intents will not be 145 * for the specified intent. Events received for other intents will not be
...@@ -210,23 +184,6 @@ public class IntentServiceTest { ...@@ -210,23 +184,6 @@ public class IntentServiceTest {
210 } 184 }
211 185
212 @Test 186 @Test
213 - public void installerBasics() {
214 - // Make sure there are no installers
215 - assertEquals("incorrect installer count", 0, service.getInstallers().size());
216 -
217 - // Add an installer and make sure that it appears in the map
218 - IntentInstaller<TestInstallableIntent> installer = new TestInstaller(false);
219 - service.registerInstaller(TestInstallableIntent.class, installer);
220 - assertEquals("incorrect installer", installer,
221 - service.getInstallers().get(TestInstallableIntent.class));
222 -
223 - // Remove the same and make sure that it no longer appears in the map
224 - service.unregisterInstaller(TestInstallableIntent.class);
225 - assertNull("installer should not be registered",
226 - service.getInstallers().get(TestInstallableIntent.class));
227 - }
228 -
229 - @Test
230 public void implicitRegistration() { 187 public void implicitRegistration() {
231 // Add a compiler and make sure that it appears in the map 188 // Add a compiler and make sure that it appears in the map
232 IntentCompiler<TestIntent> compiler = new TestCompiler(new TestSubclassInstallableIntent(INSTALLABLE_IID)); 189 IntentCompiler<TestIntent> compiler = new TestCompiler(new TestSubclassInstallableIntent(INSTALLABLE_IID));
...@@ -234,13 +191,6 @@ public class IntentServiceTest { ...@@ -234,13 +191,6 @@ public class IntentServiceTest {
234 assertEquals("incorrect compiler", compiler, 191 assertEquals("incorrect compiler", compiler,
235 service.getCompilers().get(TestIntent.class)); 192 service.getCompilers().get(TestIntent.class));
236 193
237 - // Add a installer and make sure that it appears in the map
238 - IntentInstaller<TestInstallableIntent> installer = new TestInstaller(false);
239 - service.registerInstaller(TestInstallableIntent.class, installer);
240 - assertEquals("incorrect installer", installer,
241 - service.getInstallers().get(TestInstallableIntent.class));
242 -
243 -
244 // Submit an intent which is a subclass of the one we registered 194 // Submit an intent which is a subclass of the one we registered
245 final Intent intent = new TestSubclassIntent(IID); 195 final Intent intent = new TestSubclassIntent(IID);
246 service.submit(intent); 196 service.submit(intent);
...@@ -259,11 +209,6 @@ public class IntentServiceTest { ...@@ -259,11 +209,6 @@ public class IntentServiceTest {
259 assertEquals("incorrect compiler", compiler, 209 assertEquals("incorrect compiler", compiler,
260 service.getCompilers().get(TestSubclassIntent.class)); 210 service.getCompilers().get(TestSubclassIntent.class));
261 211
262 - // Make sure that now we have an implicit registration of the installer
263 - // under the intent subclass
264 - assertEquals("incorrect installer", installer,
265 - service.getInstallers().get(TestSubclassInstallableIntent.class));
266 -
267 // TODO: discuss whether or if implicit registration should require implicit unregistration 212 // TODO: discuss whether or if implicit registration should require implicit unregistration
268 // perhaps unregister by compiler or installer itself, rather than by class would be better 213 // perhaps unregister by compiler or installer itself, rather than by class would be better
269 } 214 }
...@@ -304,36 +249,4 @@ public class IntentServiceTest { ...@@ -304,36 +249,4 @@ public class IntentServiceTest {
304 return compiled; 249 return compiled;
305 } 250 }
306 } 251 }
307 -
308 - // Controllable installer
309 - private class TestInstaller implements IntentInstaller<TestInstallableIntent> {
310 - private final boolean fail;
311 -
312 - TestInstaller(boolean fail) {
313 - this.fail = fail;
314 - }
315 -
316 - @Override
317 - public List<Collection<FlowRuleOperation>> install(TestInstallableIntent intent) {
318 - if (fail) {
319 - throw new IntentException("install failed by design");
320 - }
321 - return null;
322 - }
323 -
324 - @Override
325 - public List<Collection<FlowRuleOperation>> uninstall(TestInstallableIntent intent) {
326 - if (fail) {
327 - throw new IntentException("remove failed by design");
328 - }
329 - return null;
330 - }
331 -
332 - @Override
333 - public List<Collection<FlowRuleOperation>> replace(TestInstallableIntent intent,
334 - TestInstallableIntent newIntent) {
335 - return null;
336 - }
337 - }
338 -
339 } 252 }
......
...@@ -113,7 +113,7 @@ public class LinkCollectionIntentTest extends IntentTest { ...@@ -113,7 +113,7 @@ public class LinkCollectionIntentTest extends IntentTest {
113 113
114 final Set<Link> createdLinks = collectionIntent.links(); 114 final Set<Link> createdLinks = collectionIntent.links();
115 assertThat(createdLinks, hasSize(1)); 115 assertThat(createdLinks, hasSize(1));
116 - assertThat(collectionIntent.isInstallable(), is(true)); 116 + assertThat(collectionIntent.isInstallable(), is(false));
117 assertThat(collectionIntent.treatment(), is(treatment)); 117 assertThat(collectionIntent.treatment(), is(treatment));
118 assertThat(collectionIntent.selector(), is(selector)); 118 assertThat(collectionIntent.selector(), is(selector));
119 assertThat(collectionIntent.ingressPoints(), is(ImmutableSet.of(ingress))); 119 assertThat(collectionIntent.ingressPoints(), is(ImmutableSet.of(ingress)));
...@@ -147,7 +147,7 @@ public class LinkCollectionIntentTest extends IntentTest { ...@@ -147,7 +147,7 @@ public class LinkCollectionIntentTest extends IntentTest {
147 147
148 final Set<Link> createdLinks = collectionIntent.links(); 148 final Set<Link> createdLinks = collectionIntent.links();
149 assertThat(createdLinks, hasSize(1)); 149 assertThat(createdLinks, hasSize(1));
150 - assertThat(collectionIntent.isInstallable(), is(true)); 150 + assertThat(collectionIntent.isInstallable(), is(false));
151 assertThat(collectionIntent.treatment(), is(treatment)); 151 assertThat(collectionIntent.treatment(), is(treatment));
152 assertThat(collectionIntent.selector(), is(selector)); 152 assertThat(collectionIntent.selector(), is(selector));
153 assertThat(collectionIntent.ingressPoints(), is(ImmutableSet.of(ingress))); 153 assertThat(collectionIntent.ingressPoints(), is(ImmutableSet.of(ingress)));
...@@ -169,7 +169,7 @@ public class LinkCollectionIntentTest extends IntentTest { ...@@ -169,7 +169,7 @@ public class LinkCollectionIntentTest extends IntentTest {
169 169
170 final Set<Link> createdLinks = collectionIntent.links(); 170 final Set<Link> createdLinks = collectionIntent.links();
171 assertThat(createdLinks, nullValue()); 171 assertThat(createdLinks, nullValue());
172 - assertThat(collectionIntent.isInstallable(), is(true)); 172 + assertThat(collectionIntent.isInstallable(), is(false));
173 assertThat(collectionIntent.treatment(), nullValue()); 173 assertThat(collectionIntent.treatment(), nullValue());
174 assertThat(collectionIntent.selector(), nullValue()); 174 assertThat(collectionIntent.selector(), nullValue());
175 assertThat(collectionIntent.ingressPoints(), nullValue()); 175 assertThat(collectionIntent.ingressPoints(), nullValue());
......
...@@ -26,15 +26,17 @@ import org.onosproject.core.CoreService; ...@@ -26,15 +26,17 @@ import org.onosproject.core.CoreService;
26 import org.onosproject.core.IdGenerator; 26 import org.onosproject.core.IdGenerator;
27 import org.onosproject.event.AbstractListenerRegistry; 27 import org.onosproject.event.AbstractListenerRegistry;
28 import org.onosproject.event.EventDeliveryService; 28 import org.onosproject.event.EventDeliveryService;
29 +import org.onosproject.net.flow.FlowRule;
29 import org.onosproject.net.flow.FlowRuleOperations; 30 import org.onosproject.net.flow.FlowRuleOperations;
31 +import org.onosproject.net.flow.FlowRuleOperationsContext;
30 import org.onosproject.net.flow.FlowRuleService; 32 import org.onosproject.net.flow.FlowRuleService;
33 +import org.onosproject.net.intent.FlowRuleIntent;
31 import org.onosproject.net.intent.Intent; 34 import org.onosproject.net.intent.Intent;
32 import org.onosproject.net.intent.IntentBatchDelegate; 35 import org.onosproject.net.intent.IntentBatchDelegate;
33 import org.onosproject.net.intent.IntentCompiler; 36 import org.onosproject.net.intent.IntentCompiler;
34 import org.onosproject.net.intent.IntentData; 37 import org.onosproject.net.intent.IntentData;
35 import org.onosproject.net.intent.IntentEvent; 38 import org.onosproject.net.intent.IntentEvent;
36 import org.onosproject.net.intent.IntentExtensionService; 39 import org.onosproject.net.intent.IntentExtensionService;
37 -import org.onosproject.net.intent.IntentInstaller;
38 import org.onosproject.net.intent.IntentListener; 40 import org.onosproject.net.intent.IntentListener;
39 import org.onosproject.net.intent.IntentService; 41 import org.onosproject.net.intent.IntentService;
40 import org.onosproject.net.intent.IntentState; 42 import org.onosproject.net.intent.IntentState;
...@@ -47,6 +49,7 @@ import org.onosproject.net.intent.impl.phase.IntentWorker; ...@@ -47,6 +49,7 @@ import org.onosproject.net.intent.impl.phase.IntentWorker;
47 import org.slf4j.Logger; 49 import org.slf4j.Logger;
48 50
49 import java.util.Collection; 51 import java.util.Collection;
52 +import java.util.Collections;
50 import java.util.EnumSet; 53 import java.util.EnumSet;
51 import java.util.List; 54 import java.util.List;
52 import java.util.Map; 55 import java.util.Map;
...@@ -60,7 +63,9 @@ import static java.util.concurrent.Executors.newFixedThreadPool; ...@@ -60,7 +63,9 @@ import static java.util.concurrent.Executors.newFixedThreadPool;
60 import static java.util.concurrent.Executors.newSingleThreadExecutor; 63 import static java.util.concurrent.Executors.newSingleThreadExecutor;
61 import static org.onlab.util.Tools.groupedThreads; 64 import static org.onlab.util.Tools.groupedThreads;
62 import static org.onosproject.net.intent.IntentState.FAILED; 65 import static org.onosproject.net.intent.IntentState.FAILED;
66 +import static org.onosproject.net.intent.IntentState.INSTALLED;
63 import static org.onosproject.net.intent.IntentState.INSTALL_REQ; 67 import static org.onosproject.net.intent.IntentState.INSTALL_REQ;
68 +import static org.onosproject.net.intent.IntentState.WITHDRAWN;
64 import static org.onosproject.net.intent.IntentState.WITHDRAW_REQ; 69 import static org.onosproject.net.intent.IntentState.WITHDRAW_REQ;
65 import static org.onosproject.net.intent.impl.phase.IntentProcessPhase.newInitialPhase; 70 import static org.onosproject.net.intent.impl.phase.IntentProcessPhase.newInitialPhase;
66 import static org.slf4j.LoggerFactory.getLogger; 71 import static org.slf4j.LoggerFactory.getLogger;
...@@ -105,7 +110,6 @@ public class IntentManager ...@@ -105,7 +110,6 @@ public class IntentManager
105 private ExecutorService workerExecutor; 110 private ExecutorService workerExecutor;
106 111
107 private final CompilerRegistry compilerRegistry = new CompilerRegistry(); 112 private final CompilerRegistry compilerRegistry = new CompilerRegistry();
108 - private final InstallerRegistry installerRegistry = new InstallerRegistry();
109 private final InternalIntentProcessor processor = new InternalIntentProcessor(); 113 private final InternalIntentProcessor processor = new InternalIntentProcessor();
110 private final IntentStoreDelegate delegate = new InternalStoreDelegate(); 114 private final IntentStoreDelegate delegate = new InternalStoreDelegate();
111 private final TopologyChangeDelegate topoDelegate = new InternalTopoChangeDelegate(); 115 private final TopologyChangeDelegate topoDelegate = new InternalTopoChangeDelegate();
...@@ -215,21 +219,6 @@ public class IntentManager ...@@ -215,21 +219,6 @@ public class IntentManager
215 } 219 }
216 220
217 @Override 221 @Override
218 - public <T extends Intent> void registerInstaller(Class<T> cls, IntentInstaller<T> installer) {
219 - installerRegistry.registerInstaller(cls, installer);
220 - }
221 -
222 - @Override
223 - public <T extends Intent> void unregisterInstaller(Class<T> cls) {
224 - installerRegistry.unregisterInstaller(cls);
225 - }
226 -
227 - @Override
228 - public Map<Class<? extends Intent>, IntentInstaller<? extends Intent>> getInstallers() {
229 - return installerRegistry.getInstallers();
230 - }
231 -
232 - @Override
233 public Iterable<Intent> getPending() { 222 public Iterable<Intent> getPending() {
234 return store.getPending(); 223 return store.getPending();
235 } 224 }
...@@ -370,18 +359,92 @@ public class IntentManager ...@@ -370,18 +359,92 @@ public class IntentManager
370 } 359 }
371 360
372 @Override 361 @Override
373 - public FlowRuleOperations coordinate(IntentData current, IntentData pending) { 362 + public void install(IntentData data) {
374 - return installerRegistry.coordinate(current, pending, store, trackerService); 363 + IntentManager.this.install(data);
375 } 364 }
376 365
377 @Override 366 @Override
378 - public FlowRuleOperations uninstallCoordinate(IntentData current, IntentData pending) { 367 + public void uninstall(IntentData data) {
379 - return installerRegistry.uninstallCoordinate(current, pending, store, trackerService); 368 + IntentManager.this.uninstall(data);
380 } 369 }
381 370
371 + }
372 +
373 + private void install(IntentData data) {
374 + // need to consider if FlowRuleIntent is only one as installable intent or not
375 + List<Intent> installables = data.installables();
376 + if (!installables.stream().allMatch(x -> x instanceof FlowRuleIntent)) {
377 + throw new IllegalStateException("installable intents must be FlowRuleIntent");
378 + }
379 +
380 + installables.forEach(x -> trackerService.addTrackedResources(data.key(), x.resources()));
381 +
382 + List<Collection<FlowRule>> stages = installables.stream()
383 + .map(x -> (FlowRuleIntent) x)
384 + .map(FlowRuleIntent::flowRules)
385 + .collect(Collectors.toList());
386 +
387 + FlowRuleOperations.Builder builder = FlowRuleOperations.builder();
388 + for (Collection<FlowRule> rules : stages) {
389 + rules.forEach(builder::add);
390 + builder.newStage();
391 + }
392 +
393 + FlowRuleOperations operations = builder.build(new FlowRuleOperationsContext() {
382 @Override 394 @Override
383 - public void applyFlowRules(FlowRuleOperations flowRules) { 395 + public void onSuccess(FlowRuleOperations ops) {
384 - flowRuleService.apply(flowRules); 396 + log.debug("Completed installing: {}", data.key());
397 + data.setState(INSTALLED);
398 + store.write(data);
385 } 399 }
400 +
401 + @Override
402 + public void onError(FlowRuleOperations ops) {
403 + log.warn("Failed installation: {} {} on {}", data.key(), data.intent(), ops);
404 + data.setState(FAILED);
405 + store.write(data);
406 + }
407 + });
408 +
409 + flowRuleService.apply(operations);
410 + }
411 +
412 + private void uninstall(IntentData data) {
413 + List<Intent> installables = data.installables();
414 + if (!installables.stream().allMatch(x -> x instanceof FlowRuleIntent)) {
415 + throw new IllegalStateException("installable intents must be FlowRuleIntent");
416 + }
417 +
418 + installables.forEach(x -> trackerService.removeTrackedResources(data.intent().key(), x.resources()));
419 +
420 + List<Collection<FlowRule>> stages = installables.stream()
421 + .map(x -> (FlowRuleIntent) x)
422 + .map(FlowRuleIntent::flowRules)
423 + .collect(Collectors.toList());
424 +
425 + FlowRuleOperations.Builder builder = FlowRuleOperations.builder();
426 + for (Collection<FlowRule> rules : stages) {
427 + rules.forEach(builder::remove);
428 + builder.newStage();
429 + }
430 +
431 + FlowRuleOperations operations = builder.build(new FlowRuleOperationsContext() {
432 + @Override
433 + public void onSuccess(FlowRuleOperations ops) {
434 + log.debug("Completed withdrawing: {}", data.key());
435 + data.setState(WITHDRAWN);
436 + data.setInstallables(Collections.emptyList());
437 + store.write(data);
438 + }
439 +
440 + @Override
441 + public void onError(FlowRuleOperations ops) {
442 + log.warn("Failed withdraw: {}", data.key());
443 + data.setState(FAILED);
444 + store.write(data);
445 + }
446 + });
447 +
448 + flowRuleService.apply(operations);
386 } 449 }
387 } 450 }
......
...@@ -15,7 +15,6 @@ ...@@ -15,7 +15,6 @@
15 */ 15 */
16 package org.onosproject.net.intent.impl; 16 package org.onosproject.net.intent.impl;
17 17
18 -import org.onosproject.net.flow.FlowRuleOperations;
19 import org.onosproject.net.intent.Intent; 18 import org.onosproject.net.intent.Intent;
20 import org.onosproject.net.intent.IntentData; 19 import org.onosproject.net.intent.IntentData;
21 20
...@@ -39,30 +38,16 @@ public interface IntentProcessor { ...@@ -39,30 +38,16 @@ public interface IntentProcessor {
39 List<Intent> compile(Intent intent, List<Intent> previousInstallables); 38 List<Intent> compile(Intent intent, List<Intent> previousInstallables);
40 39
41 /** 40 /**
42 - * Generate a {@link FlowRuleOperations} instance from the specified intent data. 41 + * Installs an intent included in the specified intent data.
43 * 42 *
44 - * @param current intent data stored in the store 43 + * @param data intent data containing an intent to be installed
45 - * @param pending intent data being processed
46 - * @return flow rule operations
47 */ 44 */
48 - FlowRuleOperations coordinate(IntentData current, IntentData pending); 45 + void install(IntentData data);
49 46
50 /** 47 /**
51 - * Generate a {@link FlowRuleOperations} instance from the specified intent data. 48 + * Uninstalls an intent included in the specified intent data.
52 * 49 *
53 - * @param current intent data stored in the store 50 + * @param data intent data containing an intent to be uninstalled
54 - * @param pending intent data being processed
55 - * @return flow rule operations
56 */ 51 */
57 - FlowRuleOperations uninstallCoordinate(IntentData current, IntentData pending); 52 + void uninstall(IntentData data);
58 -
59 - /**
60 - * Applies a batch operation of FlowRules.
61 - *
62 - * @param flowRules batch operation to apply
63 - */
64 - // TODO: consider a better name
65 - // This methods gives strangeness a bit because
66 - // it doesn't receive/return intent related information
67 - void applyFlowRules(FlowRuleOperations flowRules);
68 } 53 }
......
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 +package org.onosproject.net.intent.impl.compiler;
17 +
18 +import com.google.common.collect.HashMultimap;
19 +import com.google.common.collect.SetMultimap;
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;
25 +import org.onosproject.core.ApplicationId;
26 +import org.onosproject.core.CoreService;
27 +import org.onosproject.core.DefaultGroupId;
28 +import org.onosproject.net.ConnectPoint;
29 +import org.onosproject.net.DeviceId;
30 +import org.onosproject.net.Link;
31 +import org.onosproject.net.PortNumber;
32 +import org.onosproject.net.flow.DefaultFlowRule;
33 +import org.onosproject.net.flow.DefaultTrafficSelector;
34 +import org.onosproject.net.flow.DefaultTrafficTreatment;
35 +import org.onosproject.net.flow.FlowRule;
36 +import org.onosproject.net.flow.TrafficSelector;
37 +import org.onosproject.net.flow.TrafficTreatment;
38 +import org.onosproject.net.intent.FlowRuleIntent;
39 +import org.onosproject.net.intent.Intent;
40 +import org.onosproject.net.intent.IntentCompiler;
41 +import org.onosproject.net.intent.IntentExtensionService;
42 +import org.onosproject.net.intent.LinkCollectionIntent;
43 +import org.onosproject.net.resource.LinkResourceAllocations;
44 +
45 +import java.util.ArrayList;
46 +import java.util.Arrays;
47 +import java.util.List;
48 +import java.util.Set;
49 +import java.util.stream.Collectors;
50 +
51 +@Component(immediate = true)
52 +public class LinkCollectionIntentCompiler implements IntentCompiler<LinkCollectionIntent> {
53 +
54 + @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
55 + protected IntentExtensionService intentManager;
56 +
57 + @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
58 + protected CoreService coreService;
59 +
60 + private ApplicationId appId;
61 +
62 + @Activate
63 + public void activate() {
64 + appId = coreService.registerApplication("org.onosproject.net.intent");
65 + intentManager.registerCompiler(LinkCollectionIntent.class, this);
66 + }
67 +
68 + @Deactivate
69 + public void deactivate() {
70 + intentManager.unregisterCompiler(LinkCollectionIntent.class);
71 + }
72 +
73 + @Override
74 + public List<Intent> compile(LinkCollectionIntent intent, List<Intent> installable,
75 + Set<LinkResourceAllocations> resources) {
76 + SetMultimap<DeviceId, PortNumber> inputPorts = HashMultimap.create();
77 + SetMultimap<DeviceId, PortNumber> outputPorts = HashMultimap.create();
78 +
79 + for (Link link : intent.links()) {
80 + inputPorts.put(link.dst().deviceId(), link.dst().port());
81 + outputPorts.put(link.src().deviceId(), link.src().port());
82 + }
83 +
84 + for (ConnectPoint ingressPoint : intent.ingressPoints()) {
85 + inputPorts.put(ingressPoint.deviceId(), ingressPoint.port());
86 + }
87 +
88 + for (ConnectPoint egressPoint : intent.egressPoints()) {
89 + outputPorts.put(egressPoint.deviceId(), egressPoint.port());
90 + }
91 +
92 + List<FlowRule> rules = new ArrayList<>();
93 + for (DeviceId deviceId: outputPorts.keys()) {
94 + rules.addAll(createRules(intent, deviceId, inputPorts.get(deviceId), outputPorts.get(deviceId)));
95 + }
96 + return Arrays.asList(new FlowRuleIntent(appId, rules));
97 + }
98 +
99 + private List<FlowRule> createRules(LinkCollectionIntent intent, DeviceId deviceId,
100 + Set<PortNumber> inPorts, Set<PortNumber> outPorts) {
101 + Set<PortNumber> ingressPorts = intent.ingressPoints().stream()
102 + .filter(point -> point.deviceId().equals(deviceId))
103 + .map(ConnectPoint::port)
104 + .collect(Collectors.toSet());
105 +
106 + TrafficTreatment.Builder defaultTreatmentBuilder = DefaultTrafficTreatment.builder();
107 + outPorts.stream()
108 + .forEach(defaultTreatmentBuilder::setOutput);
109 + TrafficTreatment defaultTreatment = defaultTreatmentBuilder.build();
110 +
111 + TrafficTreatment.Builder ingressTreatmentBuilder = DefaultTrafficTreatment.builder(intent.treatment());
112 + outPorts.stream()
113 + .forEach(ingressTreatmentBuilder::setOutput);
114 + TrafficTreatment ingressTreatment = ingressTreatmentBuilder.build();
115 +
116 + List<FlowRule> rules = new ArrayList<>(inPorts.size());
117 + for (PortNumber inPort: inPorts) {
118 + TrafficSelector selector = DefaultTrafficSelector.builder(intent.selector()).matchInPort(inPort).build();
119 + TrafficTreatment treatment;
120 + if (ingressPorts.contains(inPort)) {
121 + treatment = ingressTreatment;
122 + } else {
123 + treatment = defaultTreatment;
124 + }
125 +
126 + DefaultFlowRule rule = new DefaultFlowRule(deviceId, selector, treatment, 123, appId,
127 + new DefaultGroupId((short) (intent.id().fingerprint() & 0xffff)), 0, true);
128 +
129 + rules.add(rule);
130 + }
131 +
132 + return rules;
133 + }
134 +}
1 /* 1 /*
2 - * Copyright 2014 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,10 +13,8 @@ ...@@ -13,10 +13,8 @@
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 -package org.onosproject.net.intent.impl.installer; 16 +package org.onosproject.net.intent.impl.compiler;
17 17
18 -import com.google.common.collect.ImmutableSet;
19 -import com.google.common.collect.Lists;
20 import org.apache.felix.scr.annotations.Activate; 18 import org.apache.felix.scr.annotations.Activate;
21 import org.apache.felix.scr.annotations.Component; 19 import org.apache.felix.scr.annotations.Component;
22 import org.apache.felix.scr.annotations.Deactivate; 20 import org.apache.felix.scr.annotations.Deactivate;
...@@ -30,13 +28,14 @@ import org.onosproject.net.flow.DefaultFlowRule; ...@@ -30,13 +28,14 @@ import org.onosproject.net.flow.DefaultFlowRule;
30 import org.onosproject.net.flow.DefaultTrafficSelector; 28 import org.onosproject.net.flow.DefaultTrafficSelector;
31 import org.onosproject.net.flow.DefaultTrafficTreatment; 29 import org.onosproject.net.flow.DefaultTrafficTreatment;
32 import org.onosproject.net.flow.FlowRule; 30 import org.onosproject.net.flow.FlowRule;
33 -import org.onosproject.net.flow.FlowRuleOperation;
34 -import org.onosproject.net.flow.FlowRuleService;
35 import org.onosproject.net.flow.TrafficSelector; 31 import org.onosproject.net.flow.TrafficSelector;
36 import org.onosproject.net.flow.TrafficTreatment; 32 import org.onosproject.net.flow.TrafficTreatment;
33 +import org.onosproject.net.intent.FlowRuleIntent;
34 +import org.onosproject.net.intent.Intent;
35 +import org.onosproject.net.intent.IntentCompiler;
37 import org.onosproject.net.intent.IntentExtensionService; 36 import org.onosproject.net.intent.IntentExtensionService;
38 -import org.onosproject.net.intent.IntentInstaller;
39 import org.onosproject.net.intent.OpticalPathIntent; 37 import org.onosproject.net.intent.OpticalPathIntent;
38 +import org.onosproject.net.intent.impl.IntentCompilationException;
40 import org.onosproject.net.resource.DefaultLinkResourceRequest; 39 import org.onosproject.net.resource.DefaultLinkResourceRequest;
41 import org.onosproject.net.resource.Lambda; 40 import org.onosproject.net.resource.Lambda;
42 import org.onosproject.net.resource.LambdaResourceAllocation; 41 import org.onosproject.net.resource.LambdaResourceAllocation;
...@@ -46,28 +45,21 @@ import org.onosproject.net.resource.LinkResourceService; ...@@ -46,28 +45,21 @@ import org.onosproject.net.resource.LinkResourceService;
46 import org.onosproject.net.resource.ResourceAllocation; 45 import org.onosproject.net.resource.ResourceAllocation;
47 import org.onosproject.net.resource.ResourceType; 46 import org.onosproject.net.resource.ResourceType;
48 import org.onosproject.net.topology.TopologyService; 47 import org.onosproject.net.topology.TopologyService;
49 -import org.slf4j.Logger;
50 48
51 -import java.util.Collection; 49 +import java.util.Arrays;
50 +import java.util.LinkedList;
52 import java.util.List; 51 import java.util.List;
52 +import java.util.Set;
53 53
54 import static org.onosproject.net.flow.DefaultTrafficTreatment.builder; 54 import static org.onosproject.net.flow.DefaultTrafficTreatment.builder;
55 -import static org.slf4j.LoggerFactory.getLogger;
56 55
57 -/**
58 - * Installer for {@link org.onosproject.net.intent.OpticalPathIntent optical path connectivity intents}.
59 - */
60 @Component(immediate = true) 56 @Component(immediate = true)
61 -public class OpticalPathIntentInstaller implements IntentInstaller<OpticalPathIntent> { 57 +public class OpticalPathIntentCompiler implements IntentCompiler<OpticalPathIntent> {
62 - private final Logger log = getLogger(getClass());
63 58
64 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) 59 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
65 protected IntentExtensionService intentManager; 60 protected IntentExtensionService intentManager;
66 61
67 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) 62 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
68 - protected FlowRuleService flowRuleService;
69 -
70 - @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
71 protected CoreService coreService; 63 protected CoreService coreService;
72 64
73 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) 65 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
...@@ -83,70 +75,42 @@ public class OpticalPathIntentInstaller implements IntentInstaller<OpticalPathIn ...@@ -83,70 +75,42 @@ public class OpticalPathIntentInstaller implements IntentInstaller<OpticalPathIn
83 @Activate 75 @Activate
84 public void activate() { 76 public void activate() {
85 appId = coreService.registerApplication("org.onosproject.net.intent"); 77 appId = coreService.registerApplication("org.onosproject.net.intent");
86 - intentManager.registerInstaller(OpticalPathIntent.class, this); 78 + intentManager.registerCompiler(OpticalPathIntent.class, this);
87 } 79 }
88 80
89 @Deactivate 81 @Deactivate
90 public void deactivate() { 82 public void deactivate() {
91 - intentManager.unregisterInstaller(OpticalPathIntent.class); 83 + intentManager.unregisterCompiler(OpticalPathIntent.class);
92 } 84 }
93 85
94 @Override 86 @Override
95 - public List<Collection<FlowRuleOperation>> install(OpticalPathIntent intent) { 87 + public List<Intent> compile(OpticalPathIntent intent, List<Intent> installable,
88 + Set<LinkResourceAllocations> resources) {
96 LinkResourceAllocations allocations = assignWavelength(intent); 89 LinkResourceAllocations allocations = assignWavelength(intent);
97 - return generateRules(intent, allocations, FlowRuleOperation.Type.ADD);
98 - }
99 -
100 - @Override
101 - public List<Collection<FlowRuleOperation>> uninstall(OpticalPathIntent intent) {
102 - LinkResourceAllocations allocations = resourceService.getAllocations(intent.id());
103 - List<Collection<FlowRuleOperation>> rules = generateRules(intent, allocations, FlowRuleOperation.Type.REMOVE);
104 - log.info("uninstall rules: {}", rules);
105 - return rules;
106 - }
107 90
108 - @Override 91 + return Arrays.asList(new FlowRuleIntent(appId, createRules(intent, allocations)));
109 - public List<Collection<FlowRuleOperation>> replace(OpticalPathIntent oldIntent,
110 - OpticalPathIntent newIntent) {
111 - // FIXME: implement this
112 - List<Collection<FlowRuleOperation>> batches = Lists.newArrayList();
113 - batches.addAll(uninstall(oldIntent));
114 - batches.addAll(install(newIntent));
115 - return batches;
116 } 92 }
117 93
118 private LinkResourceAllocations assignWavelength(OpticalPathIntent intent) { 94 private LinkResourceAllocations assignWavelength(OpticalPathIntent intent) {
119 - LinkResourceRequest.Builder request = DefaultLinkResourceRequest.builder(intent.id(), 95 + LinkResourceRequest.Builder request = DefaultLinkResourceRequest
120 - intent.path().links()) 96 + .builder(intent.id(), intent.path().links())
121 .addLambdaRequest(); 97 .addLambdaRequest();
122 - LinkResourceAllocations retLambda = resourceService.requestResources(request.build()); 98 + return resourceService.requestResources(request.build());
123 - return retLambda;
124 } 99 }
125 100
126 - private List<Collection<FlowRuleOperation>> generateRules(OpticalPathIntent intent, 101 + private List<FlowRule> createRules(OpticalPathIntent intent, LinkResourceAllocations allocations) {
127 - LinkResourceAllocations allocations,
128 - FlowRuleOperation.Type operation) {
129 TrafficSelector.Builder selectorBuilder = DefaultTrafficSelector.builder(); 102 TrafficSelector.Builder selectorBuilder = DefaultTrafficSelector.builder();
130 selectorBuilder.matchInPort(intent.src().port()); 103 selectorBuilder.matchInPort(intent.src().port());
131 104
132 - List<FlowRuleOperation> rules = Lists.newLinkedList(); 105 + List<FlowRule> rules = new LinkedList<>();
133 ConnectPoint prev = intent.src(); 106 ConnectPoint prev = intent.src();
134 107
135 - //FIXME check for null allocations
136 - //TODO throw exception if the lambda was not assigned successfully
137 for (Link link : intent.path().links()) { 108 for (Link link : intent.path().links()) {
138 - Lambda la = null; 109 + ResourceAllocation allocation = allocations.getResourceAllocation(link).stream()
139 - for (ResourceAllocation allocation : allocations.getResourceAllocation(link)) { 110 + .filter(x -> x.type() == ResourceType.LAMBDA)
140 - if (allocation.type() == ResourceType.LAMBDA) { 111 + .findFirst()
141 - la = ((LambdaResourceAllocation) allocation).lambda(); 112 + .orElseThrow(() -> new IntentCompilationException("Lambda was not assigned successfully"));
142 - break; 113 + Lambda la = ((LambdaResourceAllocation) allocation).lambda();
143 - }
144 - }
145 -
146 - if (la == null) {
147 - log.info("Lambda was not assigned successfully");
148 - return null;
149 - }
150 114
151 TrafficTreatment.Builder treatmentBuilder = DefaultTrafficTreatment.builder(); 115 TrafficTreatment.Builder treatmentBuilder = DefaultTrafficTreatment.builder();
152 treatmentBuilder.setLambda((short) la.toInt()); 116 treatmentBuilder.setLambda((short) la.toInt());
...@@ -160,11 +124,11 @@ public class OpticalPathIntentInstaller implements IntentInstaller<OpticalPathIn ...@@ -160,11 +124,11 @@ public class OpticalPathIntentInstaller implements IntentInstaller<OpticalPathIn
160 100, 124 100,
161 true); 125 true);
162 126
163 - rules.add(new FlowRuleOperation(rule, operation)); 127 + rules.add(rule);
164 128
165 prev = link.dst(); 129 prev = link.dst();
166 selectorBuilder.matchInPort(link.dst().port()); 130 selectorBuilder.matchInPort(link.dst().port());
167 - selectorBuilder.matchOpticalSignalType(SIGNAL_TYPE); //todo 131 + selectorBuilder.matchOpticalSignalType(SIGNAL_TYPE);
168 selectorBuilder.matchLambda((short) la.toInt()); 132 selectorBuilder.matchLambda((short) la.toInt());
169 133
170 } 134 }
...@@ -179,9 +143,8 @@ public class OpticalPathIntentInstaller implements IntentInstaller<OpticalPathIn ...@@ -179,9 +143,8 @@ public class OpticalPathIntentInstaller implements IntentInstaller<OpticalPathIn
179 appId, 143 appId,
180 100, 144 100,
181 true); 145 true);
182 - rules.add(new FlowRuleOperation(rule, operation)); 146 + rules.add(rule);
183 147
184 - //FIXME change to new api 148 + return rules;
185 - return Lists.newArrayList(ImmutableSet.of(rules));
186 } 149 }
187 } 150 }
......
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 +package org.onosproject.net.intent.impl.compiler;
17 +
18 +import org.apache.felix.scr.annotations.Activate;
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.onosproject.core.ApplicationId;
24 +import org.onosproject.core.CoreService;
25 +import org.onosproject.net.ConnectPoint;
26 +import org.onosproject.net.Link;
27 +import org.onosproject.net.flow.DefaultFlowRule;
28 +import org.onosproject.net.flow.DefaultTrafficSelector;
29 +import org.onosproject.net.flow.DefaultTrafficTreatment;
30 +import org.onosproject.net.flow.FlowRule;
31 +import org.onosproject.net.flow.TrafficSelector;
32 +import org.onosproject.net.flow.TrafficTreatment;
33 +import org.onosproject.net.intent.FlowRuleIntent;
34 +import org.onosproject.net.intent.Intent;
35 +import org.onosproject.net.intent.IntentCompiler;
36 +import org.onosproject.net.intent.IntentExtensionService;
37 +import org.onosproject.net.intent.PathIntent;
38 +import org.onosproject.net.resource.LinkResourceAllocations;
39 +
40 +import java.util.ArrayList;
41 +import java.util.Arrays;
42 +import java.util.List;
43 +import java.util.Set;
44 +
45 +@Component(immediate = true)
46 +public class PathIntentCompiler implements IntentCompiler<PathIntent> {
47 +
48 + @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
49 + protected CoreService coreService;
50 +
51 + @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
52 + protected IntentExtensionService intentManager;
53 +
54 + private ApplicationId appId;
55 +
56 + @Activate
57 + public void activate() {
58 + appId = coreService.registerApplication("org.onosproject.net.intent");
59 + intentManager.registerCompiler(PathIntent.class, this);
60 + }
61 +
62 + @Deactivate
63 + public void deactivate() {
64 + intentManager.unregisterCompiler(PathIntent.class);
65 + }
66 +
67 + @Override
68 + public List<Intent> compile(PathIntent intent, List<Intent> installable,
69 + Set<LinkResourceAllocations> resources) {
70 + // Note: right now recompile is not considered
71 + // TODO: implement recompile behavior
72 +
73 + List<Link> links = intent.path().links();
74 + List<FlowRule> rules = new ArrayList<>(links.size() - 1);
75 +
76 + for (int i = 0; i < links.size() - 1; i++) {
77 + ConnectPoint ingress = links.get(i).dst();
78 + ConnectPoint egress = links.get(i + 1).src();
79 + FlowRule rule = createFlowRule(intent.selector(), intent.treatment(), ingress, egress, isLast(links, i));
80 + rules.add(rule);
81 + }
82 +
83 + return Arrays.asList(new FlowRuleIntent(appId, rules));
84 + }
85 +
86 + private FlowRule createFlowRule(TrafficSelector originalSelector, TrafficTreatment originalTreatment,
87 + ConnectPoint ingress, ConnectPoint egress, boolean last) {
88 + TrafficSelector selector = DefaultTrafficSelector.builder(originalSelector)
89 + .matchInPort(ingress.port())
90 + .build();
91 +
92 + TrafficTreatment.Builder treatmentBuilder;
93 + if (last) {
94 + treatmentBuilder = DefaultTrafficTreatment.builder(originalTreatment);
95 + } else {
96 + treatmentBuilder = DefaultTrafficTreatment.builder();
97 + }
98 + TrafficTreatment treatment = treatmentBuilder.setOutput(egress.port()).build();
99 +
100 + return new DefaultFlowRule(ingress.deviceId(), selector, treatment, 123, appId, 0, true);
101 + }
102 +
103 + private boolean isLast(List<Link> links, int i) {
104 + return i == links.size() - 2;
105 + }
106 +}
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.onosproject.net.intent.impl.installer;
17 -
18 -import com.google.common.collect.HashMultimap;
19 -import com.google.common.collect.ImmutableSet;
20 -import com.google.common.collect.Lists;
21 -import com.google.common.collect.SetMultimap;
22 -import org.apache.felix.scr.annotations.Activate;
23 -import org.apache.felix.scr.annotations.Component;
24 -import org.apache.felix.scr.annotations.Deactivate;
25 -import org.apache.felix.scr.annotations.Reference;
26 -import org.apache.felix.scr.annotations.ReferenceCardinality;
27 -import org.onosproject.core.ApplicationId;
28 -import org.onosproject.core.CoreService;
29 -import org.onosproject.core.DefaultGroupId;
30 -import org.onosproject.net.ConnectPoint;
31 -import org.onosproject.net.DeviceId;
32 -import org.onosproject.net.Link;
33 -import org.onosproject.net.PortNumber;
34 -import org.onosproject.net.flow.DefaultFlowRule;
35 -import org.onosproject.net.flow.DefaultTrafficSelector;
36 -import org.onosproject.net.flow.DefaultTrafficTreatment;
37 -import org.onosproject.net.flow.FlowRule;
38 -import org.onosproject.net.flow.FlowRuleOperation;
39 -import org.onosproject.net.flow.TrafficSelector;
40 -import org.onosproject.net.flow.TrafficTreatment;
41 -import org.onosproject.net.intent.IntentExtensionService;
42 -import org.onosproject.net.intent.IntentInstaller;
43 -import org.onosproject.net.intent.LinkCollectionIntent;
44 -
45 -import java.util.Collection;
46 -import java.util.HashSet;
47 -import java.util.List;
48 -import java.util.Set;
49 -
50 -/**
51 - * Installer for {@link org.onosproject.net.intent.LinkCollectionIntent} path
52 - * segment intents.
53 - */
54 -@Component(immediate = true)
55 -public class LinkCollectionIntentInstaller
56 - implements IntentInstaller<LinkCollectionIntent> {
57 -
58 - @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
59 - protected IntentExtensionService intentManager;
60 -
61 - @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
62 - protected CoreService coreService;
63 -
64 - private ApplicationId appId;
65 -
66 - @Activate
67 - public void activate() {
68 - appId = coreService.registerApplication("org.onosproject.net.intent");
69 - intentManager.registerInstaller(LinkCollectionIntent.class, this);
70 - }
71 -
72 - @Deactivate
73 - public void deactivate() {
74 - intentManager.unregisterInstaller(LinkCollectionIntent.class);
75 - }
76 -
77 - @Override
78 - public List<Collection<FlowRuleOperation>> install(LinkCollectionIntent intent) {
79 - return generateBatchOperations(intent, FlowRuleOperation.Type.ADD);
80 - }
81 -
82 - @Override
83 - public List<Collection<FlowRuleOperation>> uninstall(LinkCollectionIntent intent) {
84 - return generateBatchOperations(intent, FlowRuleOperation.Type.REMOVE);
85 - }
86 -
87 - private List<Collection<FlowRuleOperation>> generateBatchOperations(
88 - LinkCollectionIntent intent, FlowRuleOperation.Type operation) {
89 -
90 - //TODO do we need a set here?
91 - SetMultimap<DeviceId, PortNumber> inputPorts = HashMultimap.create();
92 - SetMultimap<DeviceId, PortNumber> outputPorts = HashMultimap.create();
93 -
94 - for (Link link : intent.links()) {
95 - inputPorts.put(link.dst().deviceId(), link.dst().port());
96 - outputPorts.put(link.src().deviceId(), link.src().port());
97 - }
98 -
99 - for (ConnectPoint ingressPoint : intent.ingressPoints()) {
100 - inputPorts.put(ingressPoint.deviceId(), ingressPoint.port());
101 - }
102 -
103 - for (ConnectPoint egressPoint : intent.egressPoints()) {
104 - outputPorts.put(egressPoint.deviceId(), egressPoint.port());
105 - }
106 -
107 - List<FlowRuleOperation> rules = Lists.newArrayList();
108 - outputPorts.keys().stream()
109 - .map(deviceId -> createBatchEntries(operation,
110 - intent, deviceId,
111 - inputPorts.get(deviceId),
112 - outputPorts.get(deviceId)))
113 - .forEach(rules::addAll);
114 -
115 - return Lists.newArrayList(ImmutableSet.of(rules));
116 - }
117 -
118 - @Override
119 - public List<Collection<FlowRuleOperation>> replace(LinkCollectionIntent oldIntent,
120 - LinkCollectionIntent newIntent) {
121 - // FIXME: implement this in a more intelligent/less brute force way
122 - List<Collection<FlowRuleOperation>> batches = Lists.newArrayList();
123 - batches.addAll(uninstall(oldIntent));
124 - batches.addAll(install(newIntent));
125 - return batches;
126 - }
127 -
128 - /**
129 - * Creates a collection of FlowRuleOperation based on the provided
130 - * parameters.
131 - *
132 - * @param operation the FlowRuleOperation type to use
133 - * @param intent the link collection intent
134 - * @param deviceId the device ID for the flow rule
135 - * @param inPorts the logical input ports of the flow rule
136 - * @param outPorts the set of output ports for the flow rule
137 - * @return a collection with the new flow rule batch entries
138 - */
139 - private Collection<FlowRuleOperation> createBatchEntries(
140 - FlowRuleOperation.Type operation,
141 - LinkCollectionIntent intent,
142 - DeviceId deviceId,
143 - Set<PortNumber> inPorts,
144 - Set<PortNumber> outPorts) {
145 - Collection<FlowRuleOperation> result = Lists.newLinkedList();
146 - Set<PortNumber> ingressPorts = new HashSet<PortNumber>();
147 -
148 - //
149 - // Collect all ingress ports for this device.
150 - // The intent treatment is applied only on those ports.
151 - //
152 - for (ConnectPoint cp : intent.ingressPoints()) {
153 - if (cp.deviceId().equals(deviceId)) {
154 - ingressPorts.add(cp.port());
155 - }
156 - }
157 -
158 - //
159 - // Create two treatments: one for setting the output ports,
160 - // and a second one that applies the intent treatment and sets the
161 - // output ports.
162 - // NOTE: The second one is created only if there are ingress ports.
163 - //
164 - TrafficTreatment.Builder defaultTreatmentBuilder =
165 - DefaultTrafficTreatment.builder();
166 - for (PortNumber outPort : outPorts) {
167 - defaultTreatmentBuilder.setOutput(outPort);
168 - }
169 - TrafficTreatment defaultTreatment = defaultTreatmentBuilder.build();
170 - TrafficTreatment intentTreatment = null;
171 - if (!ingressPorts.isEmpty()) {
172 - TrafficTreatment.Builder intentTreatmentBuilder =
173 - DefaultTrafficTreatment.builder(intent.treatment());
174 - for (PortNumber outPort : outPorts) {
175 - intentTreatmentBuilder.setOutput(outPort);
176 - }
177 - intentTreatment = intentTreatmentBuilder.build();
178 - }
179 -
180 - for (PortNumber inPort : inPorts) {
181 - TrafficSelector selector = DefaultTrafficSelector
182 - .builder(intent.selector()).matchInPort(inPort).build();
183 - TrafficTreatment treatment = defaultTreatment;
184 - if (ingressPorts.contains(inPort)) {
185 - // Use the intent treatment if this is ingress port
186 - treatment = intentTreatment;
187 - }
188 - FlowRule rule = new DefaultFlowRule(deviceId,
189 - selector, treatment, intent.priority(), appId,
190 - new DefaultGroupId((short) (intent.id().fingerprint() & 0xffff)),
191 - 0, true);
192 - result.add(new FlowRuleOperation(rule, operation));
193 - }
194 -
195 - return result;
196 - }
197 -}
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.onosproject.net.intent.impl.installer;
17 -
18 -import com.google.common.collect.ImmutableSet;
19 -import com.google.common.collect.Lists;
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;
25 -import org.onosproject.core.ApplicationId;
26 -import org.onosproject.core.CoreService;
27 -import org.onosproject.core.DefaultGroupId;
28 -import org.onosproject.net.ConnectPoint;
29 -import org.onosproject.net.Link;
30 -import org.onosproject.net.flow.DefaultFlowRule;
31 -import org.onosproject.net.flow.DefaultTrafficSelector;
32 -import org.onosproject.net.flow.FlowRule;
33 -import org.onosproject.net.flow.FlowRuleOperation;
34 -import org.onosproject.net.flow.TrafficSelector;
35 -import org.onosproject.net.flow.TrafficTreatment;
36 -import org.onosproject.net.intent.Constraint;
37 -import org.onosproject.net.intent.IntentExtensionService;
38 -import org.onosproject.net.intent.IntentInstaller;
39 -import org.onosproject.net.intent.PathIntent;
40 -import org.onosproject.net.resource.DefaultLinkResourceRequest;
41 -import org.onosproject.net.resource.LinkResourceAllocations;
42 -import org.onosproject.net.resource.LinkResourceRequest;
43 -import org.onosproject.net.resource.LinkResourceService;
44 -import org.slf4j.Logger;
45 -
46 -import java.util.Collection;
47 -import java.util.Iterator;
48 -import java.util.List;
49 -
50 -import static org.onosproject.net.flow.DefaultTrafficTreatment.builder;
51 -import static org.slf4j.LoggerFactory.getLogger;
52 -
53 -/**
54 - * Installer for {@link PathIntent packet path connectivity intents}.
55 - */
56 -@Component(immediate = true)
57 -public class PathIntentInstaller implements IntentInstaller<PathIntent> {
58 -
59 - private final Logger log = getLogger(getClass());
60 -
61 - @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
62 - protected IntentExtensionService intentManager;
63 -
64 - @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
65 - protected CoreService coreService;
66 -
67 - @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
68 - protected LinkResourceService resourceService;
69 -
70 - protected ApplicationId appId;
71 -
72 - @Activate
73 - public void activate() {
74 - appId = coreService.registerApplication("org.onosproject.net.intent");
75 - intentManager.registerInstaller(PathIntent.class, this);
76 - }
77 -
78 - @Deactivate
79 - public void deactivate() {
80 - intentManager.unregisterInstaller(PathIntent.class);
81 - }
82 -
83 - @Override
84 - public List<Collection<FlowRuleOperation>> install(PathIntent intent) {
85 - LinkResourceAllocations allocations = allocateResources(intent);
86 -
87 - TrafficSelector.Builder builder =
88 - DefaultTrafficSelector.builder(intent.selector());
89 - Iterator<Link> links = intent.path().links().iterator();
90 - ConnectPoint prev = links.next().dst();
91 - List<FlowRuleOperation> rules = Lists.newLinkedList();
92 - // TODO Generate multiple batches
93 - while (links.hasNext()) {
94 - builder.matchInPort(prev.port());
95 - Link link = links.next();
96 - // if this is the last flow rule, apply the intent's treatments
97 - TrafficTreatment treatment =
98 - (links.hasNext() ? builder() : builder(intent.treatment()))
99 - .setOutput(link.src().port()).build();
100 -
101 - FlowRule rule = new DefaultFlowRule(link.src().deviceId(),
102 - builder.build(), treatment, intent.priority(),
103 - appId,
104 - new DefaultGroupId((short) (intent.id().fingerprint() & 0xffff)),
105 - 0, true);
106 - rules.add(new FlowRuleOperation(rule, FlowRuleOperation.Type.ADD));
107 - prev = link.dst();
108 - }
109 -
110 - return Lists.newArrayList(ImmutableSet.of(rules));
111 - }
112 -
113 - @Override
114 - public List<Collection<FlowRuleOperation>> uninstall(PathIntent intent) {
115 - deallocateResources(intent);
116 - TrafficSelector.Builder builder =
117 - DefaultTrafficSelector.builder(intent.selector());
118 - Iterator<Link> links = intent.path().links().iterator();
119 - ConnectPoint prev = links.next().dst();
120 - List<FlowRuleOperation> rules = Lists.newLinkedList();
121 - // TODO Generate multiple batches
122 - while (links.hasNext()) {
123 - builder.matchInPort(prev.port());
124 - Link link = links.next();
125 - // if this is the last flow rule, apply the intent's treatments
126 - TrafficTreatment treatment =
127 - (links.hasNext() ? builder() : builder(intent.treatment()))
128 - .setOutput(link.src().port()).build();
129 - FlowRule rule = new DefaultFlowRule(link.src().deviceId(),
130 - builder.build(), treatment, intent.priority(), appId,
131 - new DefaultGroupId((short) (intent.id().fingerprint() & 0xffff)),
132 - 0, true);
133 - rules.add(new FlowRuleOperation(rule, FlowRuleOperation.Type.REMOVE));
134 - prev = link.dst();
135 - }
136 - // FIXME this should change to new api
137 - return Lists.newArrayList(ImmutableSet.of(rules));
138 - }
139 -
140 - @Override
141 - public List<Collection<FlowRuleOperation>> replace(PathIntent oldIntent, PathIntent newIntent) {
142 - // FIXME: implement this
143 - List<Collection<FlowRuleOperation>> batches = Lists.newArrayList();
144 - batches.addAll(uninstall(oldIntent));
145 - batches.addAll(install(newIntent));
146 - return batches;
147 - }
148 -
149 - /**
150 - * Allocate resources required for an intent.
151 - *
152 - * @param intent intent to allocate resource for
153 - * @return allocated resources if any are required, null otherwise
154 - */
155 - private LinkResourceAllocations allocateResources(PathIntent intent) {
156 - LinkResourceRequest.Builder builder =
157 - DefaultLinkResourceRequest.builder(intent.id(), intent.path().links());
158 - for (Constraint constraint : intent.constraints()) {
159 - builder.addConstraint(constraint);
160 - }
161 - LinkResourceRequest request = builder.build();
162 - return request.resources().isEmpty() ? null : resourceService.requestResources(request);
163 - }
164 -
165 - /**
166 - * Deallocate resources held by an intent.
167 - *
168 - * @param intent intent to deallocate resources for
169 - */
170 - private void deallocateResources(PathIntent intent) {
171 - if (intent.constraints().isEmpty()) {
172 - return;
173 - }
174 -
175 - LinkResourceAllocations allocatedResources = resourceService.getAllocations(intent.id());
176 - if (allocatedResources != null) {
177 - resourceService.releaseResources(allocatedResources);
178 - }
179 - }
180 -}
...@@ -20,14 +20,14 @@ import org.onosproject.net.intent.IntentData; ...@@ -20,14 +20,14 @@ import org.onosproject.net.intent.IntentData;
20 /** 20 /**
21 * Represents a phase where the compile has failed. 21 * Represents a phase where the compile has failed.
22 */ 22 */
23 -public class CompilingFailed extends AbstractFailed { 23 +public class CompileFailed extends AbstractFailed {
24 24
25 /** 25 /**
26 * Create an instance with the specified data. 26 * Create an instance with the specified data.
27 * 27 *
28 * @param intentData intentData 28 * @param intentData intentData
29 */ 29 */
30 - public CompilingFailed(IntentData intentData) { 30 + public CompileFailed(IntentData intentData) {
31 super(intentData); 31 super(intentData);
32 } 32 }
33 } 33 }
......
...@@ -15,14 +15,12 @@ ...@@ -15,14 +15,12 @@
15 */ 15 */
16 package org.onosproject.net.intent.impl.phase; 16 package org.onosproject.net.intent.impl.phase;
17 17
18 -import org.onosproject.net.intent.Intent;
19 import org.onosproject.net.intent.IntentData; 18 import org.onosproject.net.intent.IntentData;
20 import org.onosproject.net.intent.IntentException; 19 import org.onosproject.net.intent.IntentException;
21 import org.onosproject.net.intent.impl.IntentProcessor; 20 import org.onosproject.net.intent.impl.IntentProcessor;
22 import org.slf4j.Logger; 21 import org.slf4j.Logger;
23 import org.slf4j.LoggerFactory; 22 import org.slf4j.LoggerFactory;
24 23
25 -import java.util.List;
26 import java.util.Optional; 24 import java.util.Optional;
27 25
28 import static com.google.common.base.Preconditions.checkNotNull; 26 import static com.google.common.base.Preconditions.checkNotNull;
...@@ -35,24 +33,27 @@ final class Compiling implements IntentProcessPhase { ...@@ -35,24 +33,27 @@ final class Compiling implements IntentProcessPhase {
35 private static final Logger log = LoggerFactory.getLogger(Compiling.class); 33 private static final Logger log = LoggerFactory.getLogger(Compiling.class);
36 34
37 private final IntentProcessor processor; 35 private final IntentProcessor processor;
38 - private final IntentData pending; 36 + private final IntentData data;
39 - private final IntentData current;
40 37
41 - Compiling(IntentProcessor processor, IntentData pending, IntentData current) { 38 + /**
39 + * Creates an compiling phase.
40 + *
41 + * @param processor intent processor that does work for compiling
42 + * @param data intent data containing an intent to be compiled
43 + */
44 + Compiling(IntentProcessor processor, IntentData data) {
42 this.processor = checkNotNull(processor); 45 this.processor = checkNotNull(processor);
43 - this.pending = checkNotNull(pending); 46 + this.data = checkNotNull(data);
44 - this.current = current;
45 } 47 }
46 48
47 @Override 49 @Override
48 public Optional<IntentProcessPhase> execute() { 50 public Optional<IntentProcessPhase> execute() {
49 try { 51 try {
50 - List<Intent> installables = (current != null) ? current.installables() : null; 52 + data.setInstallables(processor.compile(data.intent(), null));
51 - pending.setInstallables(processor.compile(pending.intent(), installables)); 53 + return Optional.of(new Installing(processor, data));
52 - return Optional.of(new InstallCoordinating(processor, pending, current));
53 } catch (IntentException e) { 54 } catch (IntentException e) {
54 - log.debug("Unable to compile intent {} due to: {}", pending.intent(), e); 55 + log.debug("Unable to compile intent {} due to: {}", data.intent(), e);
55 - return Optional.of(new CompilingFailed(pending)); 56 + return Optional.of(new CompileFailed(data));
56 } 57 }
57 } 58 }
58 59
......
...@@ -26,8 +26,19 @@ public abstract class FinalIntentProcessPhase implements IntentProcessPhase { ...@@ -26,8 +26,19 @@ public abstract class FinalIntentProcessPhase implements IntentProcessPhase {
26 26
27 @Override 27 @Override
28 public final Optional<IntentProcessPhase> execute() { 28 public final Optional<IntentProcessPhase> execute() {
29 + preExecute();
29 return Optional.empty(); 30 return Optional.empty();
30 } 31 }
31 32
33 + /**
34 + * Executes operations that must take place before the phase starts.
35 + */
36 + protected void preExecute() {}
37 +
38 + /**
39 + * Returns the IntentData object being acted on by this phase.
40 + *
41 + * @return intent data object for the phase
42 + */
32 public abstract IntentData data(); 43 public abstract IntentData data();
33 } 44 }
......
...@@ -27,18 +27,30 @@ import static com.google.common.base.Preconditions.checkNotNull; ...@@ -27,18 +27,30 @@ import static com.google.common.base.Preconditions.checkNotNull;
27 */ 27 */
28 final class InstallRequest implements IntentProcessPhase { 28 final class InstallRequest implements IntentProcessPhase {
29 29
30 - private final IntentProcessor intentManager; 30 + private final IntentProcessor processor;
31 - private final IntentData pending; 31 + private final IntentData data;
32 - private final Optional<IntentData> current; 32 + private final Optional<IntentData> stored;
33 33
34 - InstallRequest(IntentProcessor processor, IntentData intentData, Optional<IntentData> current) { 34 + /**
35 - this.intentManager = checkNotNull(processor); 35 + * Creates an install request phase.
36 - this.pending = checkNotNull(intentData); 36 + *
37 - this.current = checkNotNull(current); 37 + * @param processor intent processor to be passed to intent process phases
38 + * generated after this phase
39 + * @param intentData intent data to be processed
40 + * @param stored intent data stored in the store
41 + */
42 + InstallRequest(IntentProcessor processor, IntentData intentData, Optional<IntentData> stored) {
43 + this.processor = checkNotNull(processor);
44 + this.data = checkNotNull(intentData);
45 + this.stored = checkNotNull(stored);
38 } 46 }
39 47
40 @Override 48 @Override
41 public Optional<IntentProcessPhase> execute() { 49 public Optional<IntentProcessPhase> execute() {
42 - return Optional.of(new Compiling(intentManager, pending, current.orElse(null))); 50 + if (!stored.isPresent() || stored.get().installables() == null || stored.get().installables().isEmpty()) {
51 + return Optional.of(new Compiling(processor, data));
52 + } else {
53 + return Optional.of(new Recompiling(processor, data, stored.get()));
54 + }
43 } 55 }
44 } 56 }
......
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 -package org.onosproject.net.intent.impl.phase;
17 -
18 -import org.onosproject.net.intent.IntentData;
19 -
20 -import static com.google.common.base.Preconditions.checkNotNull;
21 -import static org.onosproject.net.intent.IntentState.INSTALLING;
22 -
23 -/**
24 - * Represent a phase where an intent has been installed.
25 - */
26 -class Installed extends FinalIntentProcessPhase {
27 -
28 - private final IntentData intentData;
29 -
30 - Installed(IntentData intentData) {
31 - this.intentData = checkNotNull(intentData);
32 - this.intentData.setState(INSTALLING);
33 - }
34 -
35 - @Override
36 - public IntentData data() {
37 - return intentData;
38 - }
39 -}
...@@ -15,45 +15,39 @@ ...@@ -15,45 +15,39 @@
15 */ 15 */
16 package org.onosproject.net.intent.impl.phase; 16 package org.onosproject.net.intent.impl.phase;
17 17
18 -import org.onosproject.net.flow.FlowRuleOperations;
19 import org.onosproject.net.intent.IntentData; 18 import org.onosproject.net.intent.IntentData;
20 -import org.onosproject.net.intent.IntentException;
21 import org.onosproject.net.intent.impl.IntentProcessor; 19 import org.onosproject.net.intent.impl.IntentProcessor;
22 -import org.slf4j.Logger;
23 -import org.slf4j.LoggerFactory;
24 -
25 -import java.util.Optional;
26 20
27 import static com.google.common.base.Preconditions.checkNotNull; 21 import static com.google.common.base.Preconditions.checkNotNull;
22 +import static org.onosproject.net.intent.IntentState.INSTALLING;
28 23
29 /** 24 /**
30 - * Represents a phase of installing an intent with calling 25 + * Represents a phase where an intent is being installed.
31 - * {@link org.onosproject.net.flow.FlowRuleService}.
32 */ 26 */
33 -final class Installing implements IntentProcessPhase { 27 +class Installing extends FinalIntentProcessPhase {
34 -
35 - private static final Logger log = LoggerFactory.getLogger(Installing.class);
36 28
37 private final IntentProcessor processor; 29 private final IntentProcessor processor;
38 - private final IntentData pending; 30 + private final IntentData data;
39 - private final FlowRuleOperations flowRules;
40 31
41 - Installing(IntentProcessor processor, IntentData pending, FlowRuleOperations flowRules) { 32 + /**
33 + * Create an installing phase.
34 + *
35 + * @param processor intent processor that does work for installing
36 + * @param data intent data containing an intent to be installed
37 + */
38 + Installing(IntentProcessor processor, IntentData data) {
42 this.processor = checkNotNull(processor); 39 this.processor = checkNotNull(processor);
43 - this.pending = checkNotNull(pending); 40 + this.data = checkNotNull(data);
44 - this.flowRules = flowRules; 41 + this.data.setState(INSTALLING);
45 } 42 }
46 43
47 @Override 44 @Override
48 - public Optional<IntentProcessPhase> execute() { 45 + public void preExecute() {
49 - try { 46 + processor.install(data);
50 - processor.applyFlowRules(flowRules);
51 - return Optional.of(new Installed(pending));
52 - // What kinds of exceptions are thrown by FlowRuleService.apply()?
53 - // Is IntentException a correct exception abstraction?
54 - } catch (IntentException e) {
55 - log.warn("Unable to install intent {} due to: {}", pending.intent().id(), e);
56 - return Optional.of(new InstallingFailed(pending));
57 } 47 }
48 +
49 + @Override
50 + public IntentData data() {
51 + return data;
58 } 52 }
59 } 53 }
......
...@@ -21,7 +21,6 @@ import org.onosproject.net.intent.impl.IntentProcessor; ...@@ -21,7 +21,6 @@ import org.onosproject.net.intent.impl.IntentProcessor;
21 import java.util.Optional; 21 import java.util.Optional;
22 22
23 import static org.onlab.util.Tools.isNullOrEmpty; 23 import static org.onlab.util.Tools.isNullOrEmpty;
24 -import static org.onosproject.net.intent.IntentState.WITHDRAWN;
25 24
26 /** 25 /**
27 * Represents a phase of processing an intent. 26 * Represents a phase of processing an intent.
...@@ -52,7 +51,7 @@ public interface IntentProcessPhase { ...@@ -52,7 +51,7 @@ public interface IntentProcessPhase {
52 return new InstallRequest(processor, data, Optional.ofNullable(current)); 51 return new InstallRequest(processor, data, Optional.ofNullable(current));
53 case WITHDRAW_REQ: 52 case WITHDRAW_REQ:
54 if (current == null || isNullOrEmpty(current.installables())) { 53 if (current == null || isNullOrEmpty(current.installables())) {
55 - return new Withdrawn(data, WITHDRAWN); 54 + return new Withdrawn(data);
56 } else { 55 } else {
57 return new WithdrawRequest(processor, data, current); 56 return new WithdrawRequest(processor, data, current);
58 } 57 }
...@@ -60,7 +59,7 @@ public interface IntentProcessPhase { ...@@ -60,7 +59,7 @@ public interface IntentProcessPhase {
60 return new PurgeRequest(data, current); 59 return new PurgeRequest(data, current);
61 default: 60 default:
62 // illegal state 61 // illegal state
63 - return new CompilingFailed(data); 62 + return new CompileFailed(data);
64 } 63 }
65 } 64 }
66 65
......
...@@ -15,19 +15,41 @@ ...@@ -15,19 +15,41 @@
15 */ 15 */
16 package org.onosproject.net.intent.impl.phase; 16 package org.onosproject.net.intent.impl.phase;
17 17
18 +import org.onosproject.net.intent.Intent;
18 import org.onosproject.net.intent.IntentData; 19 import org.onosproject.net.intent.IntentData;
20 +import org.onosproject.net.intent.impl.IntentProcessor;
21 +
22 +import java.util.List;
23 +import java.util.Optional;
24 +
25 +import static com.google.common.base.Preconditions.checkNotNull;
19 26
20 /** 27 /**
21 - * Represents a phase where the withdraw has failed. 28 + * Represents a phase where an intent is being recompiled.
22 */ 29 */
23 -final class WithdrawingFailed extends AbstractFailed { 30 +class Recompiling implements IntentProcessPhase {
31 +
32 + private final IntentProcessor processor;
33 + private final IntentData data;
34 + private final IntentData stored;
24 35
25 /** 36 /**
26 - * Create an instance with the specified data. 37 + * Creates a intent recompiling phase.
27 * 38 *
28 - * @param intentData intentData 39 + * @param processor intent processor that does work for recompiling
40 + * @param data intent data containing an intent to be recompiled
41 + * @param stored intent data stored in the store
29 */ 42 */
30 - WithdrawingFailed(IntentData intentData) { 43 + Recompiling(IntentProcessor processor, IntentData data, IntentData stored) {
31 - super(intentData); 44 + this.processor = checkNotNull(processor);
45 + this.data = checkNotNull(data);
46 + this.stored = checkNotNull(stored);
47 + }
48 +
49 + @Override
50 + public Optional<IntentProcessPhase> execute() {
51 + List<Intent> compiled = processor.compile(data.intent(), stored.installables());
52 + data.setInstallables(compiled);
53 + return Optional.of(new Replacing(processor, data, stored));
32 } 54 }
33 } 55 }
......
...@@ -20,14 +20,14 @@ import org.onosproject.net.intent.IntentData; ...@@ -20,14 +20,14 @@ import org.onosproject.net.intent.IntentData;
20 /** 20 /**
21 * Represent a phase where the install has failed. 21 * Represent a phase where the install has failed.
22 */ 22 */
23 -class InstallingFailed extends AbstractFailed { 23 +class ReplaceFailed extends AbstractFailed {
24 24
25 /** 25 /**
26 * Create an instance with the specified data. 26 * Create an instance with the specified data.
27 * 27 *
28 * @param intentData intentData 28 * @param intentData intentData
29 */ 29 */
30 - InstallingFailed(IntentData intentData) { 30 + ReplaceFailed(IntentData intentData) {
31 super(intentData); 31 super(intentData);
32 } 32 }
33 } 33 }
......
...@@ -15,7 +15,6 @@ ...@@ -15,7 +15,6 @@
15 */ 15 */
16 package org.onosproject.net.intent.impl.phase; 16 package org.onosproject.net.intent.impl.phase;
17 17
18 -import org.onosproject.net.flow.FlowRuleOperations;
19 import org.onosproject.net.intent.IntentData; 18 import org.onosproject.net.intent.IntentData;
20 import org.onosproject.net.intent.IntentException; 19 import org.onosproject.net.intent.IntentException;
21 import org.onosproject.net.intent.impl.IntentProcessor; 20 import org.onosproject.net.intent.impl.IntentProcessor;
...@@ -27,33 +26,37 @@ import java.util.Optional; ...@@ -27,33 +26,37 @@ import java.util.Optional;
27 import static com.google.common.base.Preconditions.checkNotNull; 26 import static com.google.common.base.Preconditions.checkNotNull;
28 27
29 /** 28 /**
30 - * Represents a phase to create a {@link FlowRuleOperations} instance 29 + * Represents a phase to replace an intent.
31 - * with using registered intent installers.
32 */ 30 */
33 -final class InstallCoordinating implements IntentProcessPhase { 31 +final class Replacing implements IntentProcessPhase {
34 32
35 - private static final Logger log = LoggerFactory.getLogger(InstallCoordinating.class); 33 + private static final Logger log = LoggerFactory.getLogger(Replacing.class);
36 34
37 private final IntentProcessor processor; 35 private final IntentProcessor processor;
38 - private final IntentData pending; 36 + private final IntentData data;
39 - private final IntentData current; 37 + private final IntentData stored;
40 38
41 - InstallCoordinating(IntentProcessor processor, IntentData pending, IntentData current) { 39 + /**
40 + * Creates a replacing phase.
41 + *
42 + * @param processor intent processor that does work for replacing
43 + * @param data intent data containing an intent to be replaced
44 + * @param stored intent data stored in the store
45 + */
46 + Replacing(IntentProcessor processor, IntentData data, IntentData stored) {
42 this.processor = checkNotNull(processor); 47 this.processor = checkNotNull(processor);
43 - this.pending = checkNotNull(pending); 48 + this.data = checkNotNull(data);
44 - this.current = current; 49 + this.stored = checkNotNull(stored);
45 } 50 }
46 51
47 @Override 52 @Override
48 public Optional<IntentProcessPhase> execute() { 53 public Optional<IntentProcessPhase> execute() {
49 try { 54 try {
50 - //FIXME we orphan flow rules that are currently on the data plane 55 + processor.uninstall(stored);
51 - // ... should either reuse them or remove them 56 + return Optional.of(new Installing(processor, data));
52 - FlowRuleOperations flowRules = processor.coordinate(current, pending);
53 - return Optional.of(new Installing(processor, pending, flowRules));
54 } catch (IntentException e) { 57 } catch (IntentException e) {
55 - log.warn("Unable to generate a FlowRuleOperations from intent {} due to:", pending.intent().id(), e); 58 + log.warn("Unable to generate a FlowRuleOperations from intent {} due to:", data.intent().id(), e);
56 - return Optional.of(new InstallingFailed(pending)); 59 + return Optional.of(new ReplaceFailed(data));
57 } 60 }
58 } 61 }
59 } 62 }
......
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 -package org.onosproject.net.intent.impl.phase;
17 -
18 -import org.onosproject.net.flow.FlowRuleOperations;
19 -import org.onosproject.net.intent.IntentData;
20 -import org.onosproject.net.intent.IntentException;
21 -import org.onosproject.net.intent.impl.IntentProcessor;
22 -import org.slf4j.Logger;
23 -import org.slf4j.LoggerFactory;
24 -
25 -import java.util.Optional;
26 -
27 -import static com.google.common.base.Preconditions.checkNotNull;
28 -
29 -/**
30 - * Represents a phase to create a {@link FlowRuleOperations} instance
31 - * with using registered intent installers.
32 - */
33 -final class WithdrawCoordinating implements IntentProcessPhase {
34 -
35 - private static final Logger log = LoggerFactory.getLogger(WithdrawCoordinating.class);
36 -
37 - private final IntentProcessor processor;
38 - private final IntentData pending;
39 - private final IntentData current;
40 -
41 - WithdrawCoordinating(IntentProcessor processor, IntentData pending, IntentData current) {
42 - this.processor = checkNotNull(processor);
43 - this.pending = checkNotNull(pending);
44 - this.current = checkNotNull(current);
45 - }
46 -
47 - @Override
48 - public Optional<IntentProcessPhase> execute() {
49 - try {
50 - // Note: current.installables() are not null or empty due to createIntentUpdate check
51 - FlowRuleOperations flowRules = processor.uninstallCoordinate(current, pending);
52 - pending.setInstallables(current.installables());
53 - return Optional.of(new Withdrawing(processor, pending, flowRules));
54 - } catch (IntentException e) {
55 - log.warn("Unable to generate generate a FlowRuleOperations from intent {} due to:", pending.intent(), e);
56 - return Optional.of(new WithdrawingFailed(pending));
57 - }
58 - }
59 -}
...@@ -28,13 +28,21 @@ import static com.google.common.base.Preconditions.checkNotNull; ...@@ -28,13 +28,21 @@ import static com.google.common.base.Preconditions.checkNotNull;
28 final class WithdrawRequest implements IntentProcessPhase { 28 final class WithdrawRequest implements IntentProcessPhase {
29 29
30 private final IntentProcessor processor; 30 private final IntentProcessor processor;
31 - private final IntentData pending; 31 + private final IntentData data;
32 - private final IntentData current; 32 + private final IntentData stored;
33 33
34 - WithdrawRequest(IntentProcessor processor, IntentData intentData, IntentData current) { 34 + /**
35 + * Creates a withdraw request phase.
36 + *
37 + * @param processor intent processor to be passed to intent process phases
38 + * generated after this phase
39 + * @param intentData intent data to be processed
40 + * @param stored intent data stored in the store
41 + */
42 + WithdrawRequest(IntentProcessor processor, IntentData intentData, IntentData stored) {
35 this.processor = checkNotNull(processor); 43 this.processor = checkNotNull(processor);
36 - this.pending = checkNotNull(intentData); 44 + this.data = checkNotNull(intentData);
37 - this.current = checkNotNull(current); 45 + this.stored = checkNotNull(stored);
38 } 46 }
39 47
40 @Override 48 @Override
...@@ -42,6 +50,7 @@ final class WithdrawRequest implements IntentProcessPhase { ...@@ -42,6 +50,7 @@ final class WithdrawRequest implements IntentProcessPhase {
42 //TODO perhaps we want to validate that the pending and current are the 50 //TODO perhaps we want to validate that the pending and current are the
43 // same version i.e. they are the same 51 // same version i.e. they are the same
44 // Note: this call is not just the symmetric version of submit 52 // Note: this call is not just the symmetric version of submit
45 - return Optional.of(new WithdrawCoordinating(processor, pending, current)); 53 + data.setInstallables(stored.installables());
54 + return Optional.of(new Withdrawing(processor, data));
46 } 55 }
47 } 56 }
......
...@@ -15,33 +15,40 @@ ...@@ -15,33 +15,40 @@
15 */ 15 */
16 package org.onosproject.net.intent.impl.phase; 16 package org.onosproject.net.intent.impl.phase;
17 17
18 -import org.onosproject.net.flow.FlowRuleOperations;
19 import org.onosproject.net.intent.IntentData; 18 import org.onosproject.net.intent.IntentData;
20 import org.onosproject.net.intent.impl.IntentProcessor; 19 import org.onosproject.net.intent.impl.IntentProcessor;
21 20
22 -import java.util.Optional;
23 -
24 import static com.google.common.base.Preconditions.checkNotNull; 21 import static com.google.common.base.Preconditions.checkNotNull;
22 +import static org.onosproject.net.intent.IntentState.WITHDRAWING;
25 23
26 /** 24 /**
27 - * Represents a phase of withdrawing an intent with calling 25 + * Represents a phase where an intent is withdrawing.
28 - * {@link org.onosproject.net.flow.FlowRuleService}.
29 */ 26 */
30 -class Withdrawing implements IntentProcessPhase { 27 +class Withdrawing extends FinalIntentProcessPhase {
31 28
32 private final IntentProcessor processor; 29 private final IntentProcessor processor;
33 - private final IntentData pending; 30 + private final IntentData data;
34 - private final FlowRuleOperations flowRules;
35 31
36 - Withdrawing(IntentProcessor processor, IntentData pending, FlowRuleOperations flowRules) { 32 + /**
33 + * Creates a withdrawing phase.
34 + *
35 + * @param processor intent processor that does work for withdrawing
36 + * @param data intent data containing an intent to be withdrawn
37 + */
38 + Withdrawing(IntentProcessor processor, IntentData data) {
37 this.processor = checkNotNull(processor); 39 this.processor = checkNotNull(processor);
38 - this.pending = checkNotNull(pending); 40 + this.data = checkNotNull(data);
39 - this.flowRules = checkNotNull(flowRules); 41 +
42 + this.data.setState(WITHDRAWING);
43 + }
44 +
45 + @Override
46 + protected void preExecute() {
47 + processor.uninstall(data);
40 } 48 }
41 49
42 @Override 50 @Override
43 - public Optional<IntentProcessPhase> execute() { 51 + public IntentData data() {
44 - processor.applyFlowRules(flowRules); 52 + return data;
45 - return Optional.of(new Withdrawn(pending));
46 } 53 }
47 } 54 }
......
...@@ -16,29 +16,29 @@ ...@@ -16,29 +16,29 @@
16 package org.onosproject.net.intent.impl.phase; 16 package org.onosproject.net.intent.impl.phase;
17 17
18 import org.onosproject.net.intent.IntentData; 18 import org.onosproject.net.intent.IntentData;
19 -import org.onosproject.net.intent.IntentState;
20 19
21 import static com.google.common.base.Preconditions.checkNotNull; 20 import static com.google.common.base.Preconditions.checkNotNull;
22 -import static org.onosproject.net.intent.IntentState.WITHDRAWING; 21 +import static org.onosproject.net.intent.IntentState.WITHDRAWN;
23 22
24 /** 23 /**
25 * Represents a phase where an intent has been withdrawn. 24 * Represents a phase where an intent has been withdrawn.
26 */ 25 */
27 final class Withdrawn extends FinalIntentProcessPhase { 26 final class Withdrawn extends FinalIntentProcessPhase {
28 27
29 - private final IntentData intentData; 28 + private final IntentData data;
30 29
31 - Withdrawn(IntentData intentData) { 30 + /**
32 - this(intentData, WITHDRAWING); 31 + * Create a withdrawn phase.
33 - } 32 + *
34 - 33 + * @param data intent data containing an intent to be withdrawn
35 - Withdrawn(IntentData intentData, IntentState newState) { 34 + */
36 - this.intentData = checkNotNull(intentData); 35 + Withdrawn(IntentData data) {
37 - this.intentData.setState(newState); 36 + this.data = checkNotNull(data);
37 + this.data.setState(WITHDRAWN);
38 } 38 }
39 39
40 @Override 40 @Override
41 public IntentData data() { 41 public IntentData data() {
42 - return intentData; 42 + return data;
43 } 43 }
44 } 44 }
......
...@@ -15,6 +15,7 @@ ...@@ -15,6 +15,7 @@
15 */ 15 */
16 package org.onosproject.net.intent.impl; 16 package org.onosproject.net.intent.impl;
17 17
18 +import java.util.Arrays;
18 import java.util.Collection; 19 import java.util.Collection;
19 import java.util.Collections; 20 import java.util.Collections;
20 import java.util.List; 21 import java.util.List;
...@@ -34,15 +35,13 @@ import org.onosproject.core.ApplicationId; ...@@ -34,15 +35,13 @@ import org.onosproject.core.ApplicationId;
34 import org.onosproject.core.impl.TestCoreManager; 35 import org.onosproject.core.impl.TestCoreManager;
35 import org.onosproject.event.impl.TestEventDispatcher; 36 import org.onosproject.event.impl.TestEventDispatcher;
36 import org.onosproject.net.NetworkResource; 37 import org.onosproject.net.NetworkResource;
37 -import org.onosproject.net.flow.FlowRule; 38 +import org.onosproject.net.intent.FlowRuleIntent;
38 -import org.onosproject.net.flow.FlowRuleOperation;
39 import org.onosproject.net.intent.Intent; 39 import org.onosproject.net.intent.Intent;
40 import org.onosproject.net.intent.IntentCompiler; 40 import org.onosproject.net.intent.IntentCompiler;
41 import org.onosproject.net.intent.IntentEvent; 41 import org.onosproject.net.intent.IntentEvent;
42 import org.onosproject.net.intent.IntentEvent.Type; 42 import org.onosproject.net.intent.IntentEvent.Type;
43 import org.onosproject.net.intent.IntentExtensionService; 43 import org.onosproject.net.intent.IntentExtensionService;
44 import org.onosproject.net.intent.IntentId; 44 import org.onosproject.net.intent.IntentId;
45 -import org.onosproject.net.intent.IntentInstaller;
46 import org.onosproject.net.intent.IntentListener; 45 import org.onosproject.net.intent.IntentListener;
47 import org.onosproject.net.intent.IntentService; 46 import org.onosproject.net.intent.IntentService;
48 import org.onosproject.net.intent.IntentState; 47 import org.onosproject.net.intent.IntentState;
...@@ -51,7 +50,6 @@ import org.onosproject.net.resource.LinkResourceAllocations; ...@@ -51,7 +50,6 @@ import org.onosproject.net.resource.LinkResourceAllocations;
51 import org.onosproject.store.trivial.impl.SimpleIntentStore; 50 import org.onosproject.store.trivial.impl.SimpleIntentStore;
52 51
53 import com.google.common.collect.HashMultimap; 52 import com.google.common.collect.HashMultimap;
54 -import com.google.common.collect.ImmutableSet;
55 import com.google.common.collect.Lists; 53 import com.google.common.collect.Lists;
56 import com.google.common.collect.Maps; 54 import com.google.common.collect.Maps;
57 import com.google.common.collect.Multimap; 55 import com.google.common.collect.Multimap;
...@@ -95,7 +93,6 @@ public class IntentManagerTest { ...@@ -95,7 +93,6 @@ public class IntentManagerTest {
95 protected IntentExtensionService extensionService; 93 protected IntentExtensionService extensionService;
96 protected TestListener listener = new TestListener(); 94 protected TestListener listener = new TestListener();
97 protected TestIntentCompiler compiler = new TestIntentCompiler(); 95 protected TestIntentCompiler compiler = new TestIntentCompiler();
98 - protected TestIntentInstaller installer = new TestIntentInstaller();
99 96
100 private static class TestListener implements IntentListener { 97 private static class TestListener implements IntentListener {
101 final Multimap<IntentEvent.Type, IntentEvent> events = HashMultimap.create(); 98 final Multimap<IntentEvent.Type, IntentEvent> events = HashMultimap.create();
...@@ -152,14 +149,10 @@ public class IntentManagerTest { ...@@ -152,14 +149,10 @@ public class IntentManagerTest {
152 } 149 }
153 } 150 }
154 151
155 - private static class MockInstallableIntent extends MockIntent { 152 + private static class MockInstallableIntent extends FlowRuleIntent {
156 - public MockInstallableIntent(Long number) {
157 - super(number);
158 - }
159 153
160 - @Override 154 + public MockInstallableIntent() {
161 - public boolean isInstallable() { 155 + super(APPID, Arrays.asList(new MockFlowRule(100)));
162 - return true;
163 } 156 }
164 } 157 }
165 158
...@@ -167,7 +160,7 @@ public class IntentManagerTest { ...@@ -167,7 +160,7 @@ public class IntentManagerTest {
167 @Override 160 @Override
168 public List<Intent> compile(MockIntent intent, List<Intent> installable, 161 public List<Intent> compile(MockIntent intent, List<Intent> installable,
169 Set<LinkResourceAllocations> resources) { 162 Set<LinkResourceAllocations> resources) {
170 - return Lists.newArrayList(new MockInstallableIntent(intent.number())); 163 + return Lists.newArrayList(new MockInstallableIntent());
171 } 164 }
172 } 165 }
173 166
...@@ -179,53 +172,6 @@ public class IntentManagerTest { ...@@ -179,53 +172,6 @@ public class IntentManagerTest {
179 } 172 }
180 } 173 }
181 174
182 - private static class TestIntentInstaller implements IntentInstaller<MockInstallableIntent> {
183 - @Override
184 - public List<Collection<org.onosproject.net.flow.FlowRuleOperation>> install(MockInstallableIntent intent) {
185 - FlowRule fr = new MockFlowRule(intent.number().intValue());
186 - Set<FlowRuleOperation> rules = ImmutableSet.of(
187 - new FlowRuleOperation(fr, FlowRuleOperation.Type.ADD));
188 - return Lists.newArrayList(ImmutableSet.of(rules));
189 - }
190 -
191 - @Override
192 - public List<Collection<FlowRuleOperation>> uninstall(MockInstallableIntent intent) {
193 - FlowRule fr = new MockFlowRule(intent.number().intValue());
194 - Set<FlowRuleOperation> rules = ImmutableSet.of(
195 - new FlowRuleOperation(fr, FlowRuleOperation.Type.REMOVE));
196 - return Lists.newArrayList(ImmutableSet.of(rules));
197 - }
198 -
199 - @Override
200 - public List<Collection<FlowRuleOperation>> replace(MockInstallableIntent oldIntent,
201 - MockInstallableIntent newIntent) {
202 - FlowRule fr = new MockFlowRule(oldIntent.number().intValue());
203 - FlowRule fr2 = new MockFlowRule(newIntent.number().intValue());
204 - Set<FlowRuleOperation> rules = ImmutableSet.of(
205 - new FlowRuleOperation(fr, FlowRuleOperation.Type.REMOVE),
206 - new FlowRuleOperation(fr2, FlowRuleOperation.Type.ADD));
207 - return Lists.newArrayList(ImmutableSet.of(rules));
208 - }
209 - }
210 -
211 - private static class TestIntentErrorInstaller implements IntentInstaller<MockInstallableIntent> {
212 - @Override
213 - public List<Collection<FlowRuleOperation>> install(MockInstallableIntent intent) {
214 - throw new IntentInstallationException("install() always fails");
215 - }
216 -
217 - @Override
218 - public List<Collection<FlowRuleOperation>> uninstall(MockInstallableIntent intent) {
219 - throw new IntentRemovalException("uninstall() always fails");
220 - }
221 -
222 - @Override
223 - public List<Collection<FlowRuleOperation>> replace(MockInstallableIntent oldIntent,
224 - MockInstallableIntent newIntent) {
225 - throw new IntentInstallationException("replace() always fails");
226 - }
227 - }
228 -
229 /** 175 /**
230 * Hamcrest matcher to check that a conllection of Intents contains an 176 * Hamcrest matcher to check that a conllection of Intents contains an
231 * Intent with the specified Intent Id. 177 * Intent with the specified Intent Id.
...@@ -274,7 +220,6 @@ public class IntentManagerTest { ...@@ -274,7 +220,6 @@ public class IntentManagerTest {
274 manager.activate(); 220 manager.activate();
275 service.addListener(listener); 221 service.addListener(listener);
276 extensionService.registerCompiler(MockIntent.class, compiler); 222 extensionService.registerCompiler(MockIntent.class, compiler);
277 - extensionService.registerInstaller(MockInstallableIntent.class, installer);
278 223
279 assertTrue("store should be empty", 224 assertTrue("store should be empty",
280 Sets.newHashSet(service.getIntents()).isEmpty()); 225 Sets.newHashSet(service.getIntents()).isEmpty());
...@@ -307,7 +252,6 @@ public class IntentManagerTest { ...@@ -307,7 +252,6 @@ public class IntentManagerTest {
307 @After 252 @After
308 public void tearDown() { 253 public void tearDown() {
309 extensionService.unregisterCompiler(MockIntent.class); 254 extensionService.unregisterCompiler(MockIntent.class);
310 - extensionService.unregisterInstaller(MockInstallableIntent.class);
311 service.removeListener(listener); 255 service.removeListener(listener);
312 manager.deactivate(); 256 manager.deactivate();
313 // TODO null the other refs? 257 // TODO null the other refs?
...@@ -428,22 +372,6 @@ public class IntentManagerTest { ...@@ -428,22 +372,6 @@ public class IntentManagerTest {
428 } 372 }
429 373
430 /** 374 /**
431 - * Tests handling of an error that is generated by the intent installer.
432 - */
433 - @Test
434 - public void errorIntentInstallFromInstaller() {
435 - final TestIntentErrorInstaller errorInstaller = new TestIntentErrorInstaller();
436 - extensionService.registerInstaller(MockInstallableIntent.class, errorInstaller);
437 - MockIntent intent = new MockIntent(MockIntent.nextId());
438 - listener.setLatch(1, Type.INSTALL_REQ);
439 - listener.setLatch(1, Type.FAILED);
440 - service.submit(intent);
441 - listener.await(Type.INSTALL_REQ);
442 - listener.await(Type.FAILED);
443 - verifyState();
444 - }
445 -
446 - /**
447 * Tests handling a future that contains an unresolvable error as a result of 375 * Tests handling a future that contains an unresolvable error as a result of
448 * installing an intent. 376 * installing an intent.
449 */ 377 */
...@@ -521,9 +449,6 @@ public class IntentManagerTest { ...@@ -521,9 +449,6 @@ public class IntentManagerTest {
521 */ 449 */
522 @Test 450 @Test
523 public void intentWithoutInstaller() { 451 public void intentWithoutInstaller() {
524 -
525 - extensionService.unregisterInstaller(MockInstallableIntent.class);
526 -
527 MockIntent intent = new MockIntent(MockIntent.nextId()); 452 MockIntent intent = new MockIntent(MockIntent.nextId());
528 listener.setLatch(1, Type.INSTALL_REQ); 453 listener.setLatch(1, Type.INSTALL_REQ);
529 listener.setLatch(1, Type.FAILED); 454 listener.setLatch(1, Type.FAILED);
......
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 +package org.onosproject.net.intent.impl.compiler;
17 +
18 +import com.google.common.collect.ImmutableSet;
19 +import org.junit.After;
20 +import org.junit.Before;
21 +import org.junit.Test;
22 +import org.onosproject.TestApplicationId;
23 +import org.onosproject.core.ApplicationId;
24 +import org.onosproject.core.CoreService;
25 +import org.onosproject.core.IdGenerator;
26 +import org.onosproject.net.ConnectPoint;
27 +import org.onosproject.net.DefaultLink;
28 +import org.onosproject.net.Link;
29 +import org.onosproject.net.flow.DefaultTrafficSelector;
30 +import org.onosproject.net.flow.DefaultTrafficTreatment;
31 +import org.onosproject.net.flow.FlowRule;
32 +import org.onosproject.net.flow.TrafficSelector;
33 +import org.onosproject.net.flow.TrafficTreatment;
34 +import org.onosproject.net.intent.FlowRuleIntent;
35 +import org.onosproject.net.intent.Intent;
36 +import org.onosproject.net.intent.IntentExtensionService;
37 +import org.onosproject.net.intent.LinkCollectionIntent;
38 +import org.onosproject.net.intent.MockIdGenerator;
39 +
40 +import java.util.Collection;
41 +import java.util.Collections;
42 +import java.util.List;
43 +import java.util.Set;
44 +
45 +import static org.easymock.EasyMock.createMock;
46 +import static org.easymock.EasyMock.expect;
47 +import static org.easymock.EasyMock.replay;
48 +import static org.hamcrest.MatcherAssert.assertThat;
49 +import static org.hamcrest.Matchers.hasSize;
50 +import static org.hamcrest.Matchers.is;
51 +import static org.onosproject.net.Link.Type.DIRECT;
52 +import static org.onosproject.net.NetTestTools.APP_ID;
53 +import static org.onosproject.net.NetTestTools.PID;
54 +import static org.onosproject.net.NetTestTools.connectPoint;
55 +
56 +public class LinkCollectionIntentCompilerTest {
57 +
58 + private final ApplicationId appId = new TestApplicationId("test");
59 +
60 + private final ConnectPoint d1p1 = connectPoint("s1", 0);
61 + private final ConnectPoint d2p0 = connectPoint("s2", 0);
62 + private final ConnectPoint d2p1 = connectPoint("s2", 1);
63 + private final ConnectPoint d3p1 = connectPoint("s3", 1);
64 + private final ConnectPoint d3p0 = connectPoint("s3", 10);
65 + private final ConnectPoint d1p0 = connectPoint("s1", 10);
66 +
67 + private final Set<Link> links = ImmutableSet.of(
68 + new DefaultLink(PID, d1p1, d2p0, DIRECT),
69 + new DefaultLink(PID, d2p1, d3p1, DIRECT),
70 + new DefaultLink(PID, d1p1, d3p1, DIRECT));
71 +
72 + private final TrafficSelector selector = DefaultTrafficSelector.builder().build();
73 + private final TrafficTreatment treatment = DefaultTrafficTreatment.builder().build();
74 +
75 + private CoreService coreService;
76 + private IntentExtensionService intentExtensionService;
77 + private IdGenerator idGenerator = new MockIdGenerator();
78 +
79 + private LinkCollectionIntent intent;
80 +
81 + private LinkCollectionIntentCompiler sut;
82 +
83 + @Before
84 + public void setUP() {
85 + sut = new LinkCollectionIntentCompiler();
86 + coreService = createMock(CoreService.class);
87 + expect(coreService.registerApplication("org.onosproject.net.intent"))
88 + .andReturn(appId);
89 + sut.coreService = coreService;
90 +
91 + Intent.bindIdGenerator(idGenerator);
92 +
93 + intent = LinkCollectionIntent.builder()
94 + .appId(APP_ID)
95 + .selector(selector)
96 + .treatment(treatment)
97 + .links(links)
98 + .ingressPoints(ImmutableSet.of(d1p1))
99 + .egressPoints(ImmutableSet.of(d3p1))
100 + .build();
101 + intentExtensionService = createMock(IntentExtensionService.class);
102 + intentExtensionService.registerCompiler(LinkCollectionIntent.class, sut);
103 + intentExtensionService.unregisterCompiler(LinkCollectionIntent.class);
104 + sut.intentManager = intentExtensionService;
105 +
106 + replay(coreService, intentExtensionService);
107 + }
108 +
109 + @After
110 + public void tearDown() {
111 + Intent.unbindIdGenerator(idGenerator);
112 + }
113 +
114 + @Test
115 + public void testCompile() {
116 + sut.activate();
117 +
118 + List<Intent> compiled = sut.compile(intent, Collections.emptyList(), Collections.emptySet());
119 + assertThat(compiled, hasSize(1));
120 +
121 + Collection<FlowRule> rules = ((FlowRuleIntent) compiled.get(0)).flowRules();
122 + assertThat(rules, hasSize(links.size()));
123 +
124 + // if not found, get() raises an exception
125 + FlowRule rule1 = rules.stream()
126 + .filter(rule -> rule.deviceId().equals(d1p0.deviceId()))
127 + .findFirst()
128 + .get();
129 + assertThat(rule1.selector(), is(
130 + DefaultTrafficSelector.builder(intent.selector()).matchInPort(d1p1.port()).build()
131 + ));
132 + assertThat(rule1.treatment(), is(
133 + DefaultTrafficTreatment.builder(intent.treatment()).setOutput(d1p1.port()).build()
134 + ));
135 +
136 + FlowRule rule2 = rules.stream()
137 + .filter(rule -> rule.deviceId().equals(d2p0.deviceId()))
138 + .findFirst()
139 + .get();
140 + assertThat(rule2.selector(), is(
141 + DefaultTrafficSelector.builder(intent.selector()).matchInPort(d2p0.port()).build()
142 + ));
143 + assertThat(rule2.treatment(), is(
144 + DefaultTrafficTreatment.builder().setOutput(d2p1.port()).build()
145 + ));
146 +
147 + FlowRule rule3 = rules.stream()
148 + .filter(rule -> rule.deviceId().equals(d3p0.deviceId()))
149 + .findFirst()
150 + .get();
151 + assertThat(rule3.selector(), is(
152 + DefaultTrafficSelector.builder(intent.selector()).matchInPort(d3p1.port()).build()
153 + ));
154 + assertThat(rule3.treatment(), is(
155 + DefaultTrafficTreatment.builder().setOutput(d3p1.port()).build()
156 + ));
157 +
158 + sut.deactivate();
159 + }
160 +}
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 +package org.onosproject.net.intent.impl.compiler;
17 +
18 +import java.util.Arrays;
19 +import java.util.Collection;
20 +import java.util.Collections;
21 +import java.util.List;
22 +import java.util.Optional;
23 +
24 +import org.junit.After;
25 +import org.junit.Before;
26 +import org.junit.Test;
27 +import org.onlab.packet.MplsLabel;
28 +import org.onosproject.TestApplicationId;
29 +import org.onosproject.core.ApplicationId;
30 +import org.onosproject.core.CoreService;
31 +import org.onosproject.core.IdGenerator;
32 +import org.onosproject.net.ConnectPoint;
33 +import org.onosproject.net.DefaultLink;
34 +import org.onosproject.net.DefaultPath;
35 +import org.onosproject.net.Link;
36 +import org.onosproject.net.flow.DefaultTrafficSelector;
37 +import org.onosproject.net.flow.DefaultTrafficTreatment;
38 +import org.onosproject.net.flow.FlowRule;
39 +import org.onosproject.net.flow.TrafficSelector;
40 +import org.onosproject.net.flow.TrafficTreatment;
41 +import org.onosproject.net.intent.FlowRuleIntent;
42 +import org.onosproject.net.intent.Intent;
43 +import org.onosproject.net.intent.IntentExtensionService;
44 +import org.onosproject.net.intent.IntentTestsMocks;
45 +import org.onosproject.net.intent.MockIdGenerator;
46 +import org.onosproject.net.intent.MplsPathIntent;
47 +import org.onosproject.store.trivial.impl.SimpleLinkStore;
48 +
49 +import static org.easymock.EasyMock.createMock;
50 +import static org.easymock.EasyMock.expect;
51 +import static org.easymock.EasyMock.replay;
52 +import static org.hamcrest.MatcherAssert.assertThat;
53 +import static org.hamcrest.Matchers.hasSize;
54 +import static org.hamcrest.Matchers.is;
55 +import static org.onosproject.net.Link.Type.DIRECT;
56 +import static org.onosproject.net.NetTestTools.APP_ID;
57 +import static org.onosproject.net.NetTestTools.PID;
58 +import static org.onosproject.net.NetTestTools.connectPoint;
59 +
60 +public class MplsPathIntentCompilerTest {
61 +
62 + private final ApplicationId appId = new TestApplicationId("test");
63 +
64 + private final ConnectPoint d1p1 = connectPoint("s1", 0);
65 + private final ConnectPoint d2p0 = connectPoint("s2", 0);
66 + private final ConnectPoint d2p1 = connectPoint("s2", 1);
67 + private final ConnectPoint d3p1 = connectPoint("s3", 1);
68 +
69 + private final TrafficSelector selector = DefaultTrafficSelector.builder().build();
70 + private final TrafficTreatment treatment = DefaultTrafficTreatment.builder().build();
71 +
72 + private final Optional<MplsLabel> ingressLabel =
73 + Optional.of(MplsLabel.mplsLabel(10));
74 + private final Optional<MplsLabel> egressLabel =
75 + Optional.of(MplsLabel.mplsLabel(20));
76 +
77 + private final List<Link> links = Arrays.asList(
78 + new DefaultLink(PID, d1p1, d2p0, DIRECT),
79 + new DefaultLink(PID, d2p1, d3p1, DIRECT)
80 + );
81 +
82 + private IdGenerator idGenerator = new MockIdGenerator();
83 +
84 + private final int hops = links.size() - 1;
85 + private MplsPathIntent intent;
86 + private MplsPathIntentCompiler sut;
87 +
88 + @Before
89 + public void setUp() {
90 + sut = new MplsPathIntentCompiler();
91 + CoreService coreService = createMock(CoreService.class);
92 + expect(coreService.registerApplication("org.onosproject.net.intent"))
93 + .andReturn(appId);
94 + sut.coreService = coreService;
95 + sut.linkStore = new SimpleLinkStore();
96 + sut.resourceService = new IntentTestsMocks.MockResourceService();
97 +
98 + Intent.bindIdGenerator(idGenerator);
99 +
100 + intent = MplsPathIntent.builder()
101 + .appId(APP_ID)
102 + .selector(selector)
103 + .treatment(treatment)
104 + .path(new DefaultPath(PID, links, hops))
105 + .ingressLabel(ingressLabel)
106 + .egressLabel(egressLabel)
107 + .priority(55)
108 + .build();
109 +
110 + IntentExtensionService intentExtensionService = createMock(IntentExtensionService.class);
111 + intentExtensionService.registerCompiler(MplsPathIntent.class, sut);
112 + intentExtensionService.unregisterCompiler(MplsPathIntent.class);
113 + sut.intentExtensionService = intentExtensionService;
114 +
115 + replay(coreService, intentExtensionService);
116 + }
117 +
118 + @After
119 + public void tearDown() {
120 + Intent.unbindIdGenerator(idGenerator);
121 + }
122 +
123 + @Test
124 + public void testCompile() {
125 + sut.activate();
126 +
127 + List<Intent> compiled = sut.compile(intent, Collections.emptyList(), Collections.emptySet());
128 + assertThat(compiled, hasSize(1));
129 +
130 + Collection<FlowRule> rules = ((FlowRuleIntent) compiled.get(0)).flowRules();
131 + assertThat(rules, hasSize(1));
132 +
133 + FlowRule rule = rules.stream()
134 + .filter(x -> x.deviceId().equals(d2p0.deviceId()))
135 + .findFirst()
136 + .get();
137 + assertThat(rule.deviceId(), is(d2p0.deviceId()));
138 +
139 + sut.deactivate();
140 +
141 + }
142 +}
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 +package org.onosproject.net.intent.impl.compiler;
17 +
18 +import org.junit.After;
19 +import org.junit.Before;
20 +import org.junit.Test;
21 +import org.onosproject.TestApplicationId;
22 +import org.onosproject.core.ApplicationId;
23 +import org.onosproject.core.CoreService;
24 +import org.onosproject.core.IdGenerator;
25 +import org.onosproject.net.ConnectPoint;
26 +import org.onosproject.net.DefaultLink;
27 +import org.onosproject.net.DefaultPath;
28 +import org.onosproject.net.Link;
29 +import org.onosproject.net.flow.DefaultTrafficSelector;
30 +import org.onosproject.net.flow.DefaultTrafficTreatment;
31 +import org.onosproject.net.flow.FlowRule;
32 +import org.onosproject.net.flow.TrafficSelector;
33 +import org.onosproject.net.flow.TrafficTreatment;
34 +import org.onosproject.net.intent.FlowRuleIntent;
35 +import org.onosproject.net.intent.Intent;
36 +import org.onosproject.net.intent.IntentExtensionService;
37 +import org.onosproject.net.intent.IntentTestsMocks;
38 +import org.onosproject.net.intent.MockIdGenerator;
39 +import org.onosproject.net.intent.OpticalPathIntent;
40 +import org.onosproject.net.provider.ProviderId;
41 +
42 +import java.util.Arrays;
43 +import java.util.Collection;
44 +import java.util.Collections;
45 +import java.util.List;
46 +
47 +import static org.easymock.EasyMock.createMock;
48 +import static org.easymock.EasyMock.expect;
49 +import static org.easymock.EasyMock.replay;
50 +import static org.hamcrest.MatcherAssert.assertThat;
51 +import static org.hamcrest.Matchers.hasSize;
52 +import static org.onosproject.net.Link.Type.DIRECT;
53 +import static org.onosproject.net.NetTestTools.PID;
54 +import static org.onosproject.net.NetTestTools.connectPoint;
55 +
56 +public class OpticalPathIntentCompilerTest {
57 +
58 + private CoreService coreService;
59 + private IntentExtensionService intentExtensionService;
60 + private final IdGenerator idGenerator = new MockIdGenerator();
61 + private OpticalPathIntentCompiler sut;
62 +
63 + private final TrafficSelector selector = DefaultTrafficSelector.builder().build();
64 + private final TrafficTreatment treatment = DefaultTrafficTreatment.builder().build();
65 + private final ApplicationId appId = new TestApplicationId("test");
66 + private final ProviderId pid = new ProviderId("of", "test");
67 + private final ConnectPoint d1p1 = connectPoint("s1", 0);
68 + private final ConnectPoint d2p0 = connectPoint("s2", 0);
69 + private final ConnectPoint d2p1 = connectPoint("s2", 1);
70 + private final ConnectPoint d3p1 = connectPoint("s3", 1);
71 + private final ConnectPoint d3p0 = connectPoint("s3", 10);
72 + private final ConnectPoint d1p0 = connectPoint("s1", 10);
73 +
74 + private final List<Link> links = Arrays.asList(
75 + new DefaultLink(PID, d1p1, d2p0, DIRECT),
76 + new DefaultLink(PID, d2p1, d3p1, DIRECT)
77 + );
78 + private final int hops = links.size() + 1;
79 + private OpticalPathIntent intent;
80 +
81 + @Before
82 + public void setUp() {
83 + sut = new OpticalPathIntentCompiler();
84 + coreService = createMock(CoreService.class);
85 + expect(coreService.registerApplication("org.onosproject.net.intent"))
86 + .andReturn(appId);
87 + sut.coreService = coreService;
88 +
89 + Intent.bindIdGenerator(idGenerator);
90 +
91 + intent = OpticalPathIntent.builder()
92 + .appId(appId)
93 + .src(d1p1)
94 + .dst(d3p1)
95 + .path(new DefaultPath(PID, links, hops))
96 + .build();
97 + intentExtensionService = createMock(IntentExtensionService.class);
98 + intentExtensionService.registerCompiler(OpticalPathIntent.class, sut);
99 + intentExtensionService.unregisterCompiler(OpticalPathIntent.class);
100 + sut.intentManager = intentExtensionService;
101 + sut.resourceService = new IntentTestsMocks.MockResourceService();
102 +
103 + replay(coreService, intentExtensionService);
104 + }
105 +
106 + @After
107 + public void tearDown() {
108 + Intent.unbindIdGenerator(idGenerator);
109 + }
110 +
111 + @Test
112 + public void testCompiler() {
113 + sut.activate();
114 +
115 + List<Intent> compiled = sut.compile(intent, Collections.emptyList(), Collections.emptySet());
116 + assertThat(compiled, hasSize(1));
117 +
118 + Collection<FlowRule> rules = ((FlowRuleIntent) compiled.get(0)).flowRules();
119 + rules.stream()
120 + .filter(x -> x.deviceId().equals(d1p1.deviceId()))
121 + .findFirst()
122 + .get();
123 +
124 + rules.stream()
125 + .filter(x -> x.deviceId().equals(d2p1.deviceId()))
126 + .findFirst()
127 + .get();
128 +
129 + rules.stream()
130 + .filter(x -> x.deviceId().equals(d3p1.deviceId()))
131 + .findFirst()
132 + .get();
133 +
134 + sut.deactivate();
135 + }
136 +
137 +}
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 +package org.onosproject.net.intent.impl.compiler;
17 +
18 +import java.util.Arrays;
19 +import java.util.Collection;
20 +import java.util.Collections;
21 +import java.util.List;
22 +
23 +import org.junit.After;
24 +import org.junit.Before;
25 +import org.junit.Test;
26 +import org.onosproject.TestApplicationId;
27 +import org.onosproject.core.ApplicationId;
28 +import org.onosproject.core.CoreService;
29 +import org.onosproject.core.IdGenerator;
30 +import org.onosproject.net.ConnectPoint;
31 +import org.onosproject.net.DefaultLink;
32 +import org.onosproject.net.DefaultPath;
33 +import org.onosproject.net.Link;
34 +import org.onosproject.net.flow.DefaultTrafficSelector;
35 +import org.onosproject.net.flow.DefaultTrafficTreatment;
36 +import org.onosproject.net.flow.FlowRule;
37 +import org.onosproject.net.flow.TrafficSelector;
38 +import org.onosproject.net.flow.TrafficTreatment;
39 +import org.onosproject.net.intent.FlowRuleIntent;
40 +import org.onosproject.net.intent.Intent;
41 +import org.onosproject.net.intent.IntentExtensionService;
42 +import org.onosproject.net.intent.MockIdGenerator;
43 +import org.onosproject.net.intent.PathIntent;
44 +import org.onosproject.net.provider.ProviderId;
45 +
46 +import static org.easymock.EasyMock.createMock;
47 +import static org.easymock.EasyMock.expect;
48 +import static org.easymock.EasyMock.replay;
49 +import static org.hamcrest.MatcherAssert.assertThat;
50 +import static org.hamcrest.Matchers.hasSize;
51 +import static org.hamcrest.Matchers.is;
52 +import static org.onosproject.net.DefaultEdgeLink.createEdgeLink;
53 +import static org.onosproject.net.Link.Type.DIRECT;
54 +import static org.onosproject.net.NetTestTools.APP_ID;
55 +import static org.onosproject.net.NetTestTools.PID;
56 +import static org.onosproject.net.NetTestTools.connectPoint;
57 +
58 +/**
59 + * Unit tests for PathIntentCompiler.
60 + */
61 +public class PathIntentCompilerTest {
62 +
63 + private CoreService coreService;
64 + private IntentExtensionService intentExtensionService;
65 + private IdGenerator idGenerator = new MockIdGenerator();
66 + private PathIntentCompiler sut;
67 +
68 + private final TrafficSelector selector = DefaultTrafficSelector.builder().build();
69 + private final TrafficTreatment treatment = DefaultTrafficTreatment.builder().build();
70 + private final ApplicationId appId = new TestApplicationId("test");
71 + private final ProviderId pid = new ProviderId("of", "test");
72 + private final ConnectPoint d1p1 = connectPoint("s1", 0);
73 + private final ConnectPoint d2p0 = connectPoint("s2", 0);
74 + private final ConnectPoint d2p1 = connectPoint("s2", 1);
75 + private final ConnectPoint d3p1 = connectPoint("s3", 1);
76 + private final ConnectPoint d3p0 = connectPoint("s3", 10);
77 + private final ConnectPoint d1p0 = connectPoint("s1", 10);
78 +
79 + private final List<Link> links = Arrays.asList(
80 + createEdgeLink(d1p0, true),
81 + new DefaultLink(PID, d1p1, d2p0, DIRECT),
82 + new DefaultLink(PID, d2p1, d3p1, DIRECT),
83 + createEdgeLink(d3p0, false)
84 + );
85 + private final int hops = links.size() - 1;
86 + private PathIntent intent;
87 +
88 + /**
89 + * Configures objects used in all the test cases.
90 + */
91 + @Before
92 + public void setUp() {
93 + sut = new PathIntentCompiler();
94 + coreService = createMock(CoreService.class);
95 + expect(coreService.registerApplication("org.onosproject.net.intent"))
96 + .andReturn(appId);
97 + sut.coreService = coreService;
98 +
99 + Intent.bindIdGenerator(idGenerator);
100 +
101 + intent = PathIntent.builder()
102 + .appId(APP_ID)
103 + .selector(selector)
104 + .treatment(treatment)
105 + .path(new DefaultPath(pid, links, hops))
106 + .build();
107 + intentExtensionService = createMock(IntentExtensionService.class);
108 + intentExtensionService.registerCompiler(PathIntent.class, sut);
109 + intentExtensionService.unregisterCompiler(PathIntent.class);
110 + sut.intentManager = intentExtensionService;
111 +
112 + replay(coreService, intentExtensionService);
113 + }
114 +
115 + /**
116 + * Tears down objects used in all the test cases.
117 + */
118 + @After
119 + public void tearDown() {
120 + Intent.unbindIdGenerator(idGenerator);
121 + }
122 +
123 + /**
124 + * Tests the compilation behavior of the path intent compiler.
125 + */
126 + @Test
127 + public void testCompile() {
128 + sut.activate();
129 +
130 + List<Intent> compiled = sut.compile(intent, Collections.emptyList(), Collections.emptySet());
131 + assertThat(compiled, hasSize(1));
132 +
133 + Collection<FlowRule> rules = ((FlowRuleIntent) compiled.get(0)).flowRules();
134 +
135 + FlowRule rule1 = rules.stream()
136 + .filter(x -> x.deviceId().equals(d1p0.deviceId()))
137 + .findFirst()
138 + .get();
139 + assertThat(rule1.deviceId(), is(d1p0.deviceId()));
140 + assertThat(rule1.selector(),
141 + is(DefaultTrafficSelector.builder(selector).matchInPort(d1p0.port()).build()));
142 + assertThat(rule1.treatment(),
143 + is(DefaultTrafficTreatment.builder().setOutput(d1p1.port()).build()));
144 +
145 + FlowRule rule2 = rules.stream()
146 + .filter(x -> x.deviceId().equals(d2p0.deviceId()))
147 + .findFirst()
148 + .get();
149 + assertThat(rule2.deviceId(), is(d2p0.deviceId()));
150 + assertThat(rule2.selector(),
151 + is(DefaultTrafficSelector.builder(selector).matchInPort(d2p0.port()).build()));
152 + assertThat(rule2.treatment(),
153 + is(DefaultTrafficTreatment.builder().setOutput(d2p1.port()).build()));
154 +
155 + FlowRule rule3 = rules.stream()
156 + .filter(x -> x.deviceId().equals(d3p0.deviceId()))
157 + .findFirst()
158 + .get();
159 + assertThat(rule3.deviceId(), is(d3p1.deviceId()));
160 + assertThat(rule3.selector(),
161 + is(DefaultTrafficSelector.builder(selector).matchInPort(d3p1.port()).build()));
162 + assertThat(rule3.treatment(),
163 + is(DefaultTrafficTreatment.builder(treatment).setOutput(d3p0.port()).build()));
164 +
165 + sut.deactivate();
166 + }
167 +}
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 -package org.onosproject.net.intent.impl.installer;
17 -
18 -import org.junit.After;
19 -import org.junit.Before;
20 -import org.onosproject.core.ApplicationId;
21 -import org.onosproject.core.CoreService;
22 -import org.onosproject.core.CoreServiceAdapter;
23 -import org.onosproject.core.IdGenerator;
24 -import org.onosproject.net.ConnectPoint;
25 -import org.onosproject.net.DeviceId;
26 -import org.onosproject.net.flow.FlowRuleOperation;
27 -import org.onosproject.net.intent.FakeIntentManager;
28 -import org.onosproject.net.intent.Intent;
29 -import org.onosproject.net.intent.IntentInstaller;
30 -import org.onosproject.net.intent.IntentTestsMocks;
31 -import org.onosproject.net.intent.MockIdGenerator;
32 -
33 -import static org.hamcrest.MatcherAssert.assertThat;
34 -import static org.hamcrest.Matchers.equalTo;
35 -import static org.hamcrest.Matchers.is;
36 -import static org.onosproject.net.NetTestTools.APP_ID;
37 -import static org.onosproject.net.NetTestTools.connectPoint;
38 -
39 -/**
40 - * Base class for intent installer tests.
41 - */
42 -public class IntentInstallerTest {
43 -
44 - /**
45 - * Mock for core service.
46 - */
47 - static class TestCoreService extends CoreServiceAdapter {
48 -
49 - String registeredId = "";
50 -
51 - @Override
52 - public ApplicationId registerApplication(String identifier) {
53 - registeredId = identifier;
54 - return APP_ID;
55 - }
56 - }
57 -
58 - /**
59 - * Mock for intent manager service. Checks that the PathIntent
60 - * installer installs and uninstalls properly.
61 - */
62 - static class MockIntentManager extends FakeIntentManager {
63 -
64 - boolean installerRegistered = false;
65 - final Class expectedClass;
66 -
67 - private MockIntentManager() {
68 - expectedClass = null;
69 - }
70 -
71 - MockIntentManager(Class expectedInstaller) {
72 - this.expectedClass = expectedInstaller;
73 - }
74 -
75 - @Override
76 - public <T extends Intent> void registerInstaller(
77 - Class<T> cls,
78 - IntentInstaller<T> installer) {
79 - assertThat(cls, equalTo(expectedClass));
80 - installerRegistered = true;
81 - }
82 -
83 - @Override
84 - public <T extends Intent> void unregisterInstaller(Class<T> cls) {
85 - assertThat(cls, equalTo(expectedClass));
86 - assertThat(installerRegistered, is(true));
87 - }
88 -
89 - }
90 -
91 - CoreService testCoreService;
92 - IdGenerator idGenerator = new MockIdGenerator();
93 - IntentInstaller installer;
94 -
95 - final IntentTestsMocks.MockSelector selector = new IntentTestsMocks.MockSelector();
96 - final IntentTestsMocks.MockTreatment treatment = new IntentTestsMocks.MockTreatment();
97 - final ConnectPoint d1p1 = connectPoint("s1", 0);
98 - final ConnectPoint d2p0 = connectPoint("s2", 0);
99 - final ConnectPoint d2p1 = connectPoint("s2", 1);
100 - final ConnectPoint d3p1 = connectPoint("s3", 1);
101 - final ConnectPoint d3p0 = connectPoint("s3", 10);
102 - final ConnectPoint d1p0 = connectPoint("s1", 10);
103 -
104 - /**
105 - * Configures objects used in all the test cases.
106 - */
107 - @Before
108 - public void setUp() {
109 - testCoreService = new TestCoreService();
110 - Intent.bindIdGenerator(idGenerator);
111 - }
112 -
113 - /**
114 - * Tears down objects used in all the test cases.
115 - */
116 - @After
117 - public void tearDown() {
118 - Intent.unbindIdGenerator(idGenerator);
119 - }
120 -
121 - /**
122 - * Checks that a flow operation contains the correct values.
123 - *
124 - * @param op flow rule operation to check
125 - * @param type type the flow rule operation should have
126 - * @param deviceId device id the flow rule operation should have
127 - */
128 - void checkFlowOperation(FlowRuleOperation op,
129 - FlowRuleOperation.Type type,
130 - DeviceId deviceId) {
131 - assertThat(op.type(), is(type));
132 - assertThat(op.rule().deviceId(), equalTo(deviceId));
133 - }
134 -
135 -}
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 -package org.onosproject.net.intent.impl.installer;
17 -
18 -import java.util.Collection;
19 -import java.util.List;
20 -import java.util.Set;
21 -
22 -import org.junit.Before;
23 -import org.junit.Test;
24 -import org.onosproject.net.DefaultLink;
25 -import org.onosproject.net.DeviceId;
26 -import org.onosproject.net.Link;
27 -import org.onosproject.net.flow.FlowRuleOperation;
28 -import org.onosproject.net.intent.LinkCollectionIntent;
29 -
30 -import com.google.common.collect.ImmutableSet;
31 -
32 -import static org.hamcrest.MatcherAssert.assertThat;
33 -import static org.hamcrest.Matchers.hasSize;
34 -import static org.hamcrest.Matchers.notNullValue;
35 -import static org.onosproject.net.Link.Type.DIRECT;
36 -import static org.onosproject.net.NetTestTools.APP_ID;
37 -import static org.onosproject.net.NetTestTools.PID;
38 -
39 -public class LinkCollectionIntentInstallerTest extends IntentInstallerTest {
40 -
41 - LinkCollectionIntentInstaller installer;
42 -
43 - private final Set<Link> links = ImmutableSet.of(
44 - new DefaultLink(PID, d1p1, d2p0, DIRECT),
45 - new DefaultLink(PID, d2p1, d3p1, DIRECT),
46 - new DefaultLink(PID, d1p1, d3p1, DIRECT));
47 -
48 - private LinkCollectionIntent intent;
49 -
50 - /**
51 - * Configures objects used in all the test cases.
52 - */
53 - @Before
54 - public void localSetUp() {
55 - installer = new LinkCollectionIntentInstaller();
56 - installer.coreService = testCoreService;
57 - installer.intentManager =
58 - new IntentInstallerTest.MockIntentManager(LinkCollectionIntent.class);
59 - intent = LinkCollectionIntent.builder()
60 - .appId(APP_ID)
61 - .selector(selector)
62 - .treatment(treatment)
63 - .links(links)
64 - .ingressPoints(ImmutableSet.of(d1p1))
65 - .egressPoints(ImmutableSet.of(d3p1))
66 - .build();
67 - }
68 -
69 - private FlowRuleOperation findOperation(Collection<FlowRuleOperation> ops,
70 - DeviceId deviceId) {
71 - for (FlowRuleOperation op : ops) {
72 - if (op.rule().deviceId().equals(deviceId)) {
73 - return op;
74 - }
75 - }
76 - return null;
77 - }
78 -
79 - /**
80 - * Tests activation and deactivation of the installer.
81 - */
82 - @Test
83 - public void activateDeactivate() {
84 - installer.activate();
85 - installer.deactivate();
86 - }
87 -
88 - /**
89 - * Tests installation operation of the path intent installer.
90 - */
91 - @Test
92 - public void install() {
93 - installer.activate();
94 -
95 - List<Collection<FlowRuleOperation>> operations =
96 - installer.install(intent);
97 - assertThat(operations, notNullValue());
98 - assertThat(operations, hasSize(1));
99 -
100 - Collection<FlowRuleOperation> flowRuleOpsCollection = operations.get(0);
101 - assertThat(flowRuleOpsCollection, hasSize(links.size()));
102 -
103 - FlowRuleOperation op0 = findOperation(flowRuleOpsCollection,
104 - d1p0.deviceId());
105 - checkFlowOperation(op0, FlowRuleOperation.Type.ADD, d1p0.deviceId());
106 -
107 - FlowRuleOperation op1 = findOperation(flowRuleOpsCollection,
108 - d2p0.deviceId());
109 - checkFlowOperation(op1, FlowRuleOperation.Type.ADD, d2p0.deviceId());
110 -
111 - FlowRuleOperation op2 = findOperation(flowRuleOpsCollection,
112 - d3p0.deviceId());
113 - checkFlowOperation(op2, FlowRuleOperation.Type.ADD, d3p0.deviceId());
114 -
115 - installer.deactivate();
116 - }
117 -
118 - /**
119 - * Checks the uninstall operation of the path intent installer.
120 - */
121 - @Test
122 - public void uninstall() {
123 - installer.activate();
124 -
125 - List<Collection<FlowRuleOperation>> operations =
126 - installer.uninstall(intent);
127 - assertThat(operations, notNullValue());
128 - assertThat(operations, hasSize(1));
129 -
130 - Collection<FlowRuleOperation> flowRuleOpsCollection = operations.get(0);
131 - assertThat(flowRuleOpsCollection, hasSize(links.size()));
132 -
133 - FlowRuleOperation op0 = findOperation(flowRuleOpsCollection,
134 - d1p0.deviceId());
135 - checkFlowOperation(op0, FlowRuleOperation.Type.REMOVE, d1p0.deviceId());
136 -
137 - FlowRuleOperation op1 = findOperation(flowRuleOpsCollection,
138 - d2p0.deviceId());
139 - checkFlowOperation(op1, FlowRuleOperation.Type.REMOVE, d2p0.deviceId());
140 -
141 - FlowRuleOperation op2 = findOperation(flowRuleOpsCollection,
142 - d3p0.deviceId());
143 - checkFlowOperation(op2, FlowRuleOperation.Type.REMOVE, d3p0.deviceId());
144 -
145 - installer.deactivate();
146 - }
147 -}
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 -package org.onosproject.net.intent.impl.installer;
17 -
18 -import java.util.Arrays;
19 -import java.util.Collection;
20 -import java.util.List;
21 -import java.util.Optional;
22 -
23 -import org.junit.Before;
24 -import org.junit.Test;
25 -import org.onlab.packet.MplsLabel;
26 -import org.onosproject.net.DefaultLink;
27 -import org.onosproject.net.DefaultPath;
28 -import org.onosproject.net.Link;
29 -import org.onosproject.net.flow.FlowRuleOperation;
30 -import org.onosproject.net.intent.IntentTestsMocks;
31 -import org.onosproject.net.intent.MplsPathIntent;
32 -import org.onosproject.store.trivial.impl.SimpleLinkStore;
33 -
34 -import static org.hamcrest.MatcherAssert.assertThat;
35 -import static org.hamcrest.Matchers.hasSize;
36 -import static org.hamcrest.Matchers.notNullValue;
37 -import static org.onosproject.net.Link.Type.DIRECT;
38 -import static org.onosproject.net.NetTestTools.APP_ID;
39 -import static org.onosproject.net.NetTestTools.PID;
40 -
41 -/**
42 - * Unit tests for path intent installer.
43 - */
44 -public class MplsPathIntentInstallerTest extends IntentInstallerTest {
45 -
46 - MplsPathIntentInstaller installer;
47 -
48 - private final Optional<MplsLabel> ingressLabel =
49 - Optional.of(MplsLabel.mplsLabel(10));
50 - private final Optional<MplsLabel> egressLabel =
51 - Optional.of(MplsLabel.mplsLabel(20));
52 -
53 - private final List<Link> links = Arrays.asList(
54 - new DefaultLink(PID, d1p1, d2p0, DIRECT),
55 - new DefaultLink(PID, d2p1, d3p1, DIRECT)
56 - );
57 - private final int hops = links.size() - 1;
58 - private MplsPathIntent intent;
59 -
60 - /**
61 - * Configures objects used in all the test cases.
62 - */
63 - @Before
64 - public void localSetUp() {
65 - installer = new MplsPathIntentInstaller();
66 - installer.coreService = testCoreService;
67 - installer.intentManager = new MockIntentManager(MplsPathIntent.class);
68 - installer.linkStore = new SimpleLinkStore();
69 - installer.resourceService = new IntentTestsMocks.MockResourceService();
70 -
71 - intent = MplsPathIntent.builder()
72 - .appId(APP_ID)
73 - .selector(selector)
74 - .treatment(treatment)
75 - .path(new DefaultPath(PID, links, hops))
76 - .ingressLabel(ingressLabel)
77 - .egressLabel(egressLabel)
78 - .priority(55)
79 - .build();
80 - }
81 -
82 - /**
83 - * Tests activation and deactivation of the installer.
84 - */
85 - @Test
86 - public void activateDeactivate() {
87 - installer.activate();
88 - installer.deactivate();
89 - }
90 -
91 - /**
92 - * Tests installation operation of the MPLS path intent installer.
93 - */
94 - @Test
95 - public void install() {
96 - installer.activate();
97 -
98 - List<Collection<FlowRuleOperation>> operations =
99 - installer.install(intent);
100 - assertThat(operations, notNullValue());
101 - assertThat(operations, hasSize(1));
102 -
103 - Collection<FlowRuleOperation> flowRuleOpsCollection = operations.get(0);
104 - assertThat(flowRuleOpsCollection, hasSize(hops));
105 - FlowRuleOperation[] flowRuleOps =
106 - flowRuleOpsCollection.toArray(new FlowRuleOperation[hops]);
107 -
108 - FlowRuleOperation op0 = flowRuleOps[0];
109 - checkFlowOperation(op0, FlowRuleOperation.Type.ADD, d2p0.deviceId());
110 -
111 - installer.deactivate();
112 - }
113 -
114 - /**
115 - * Checks the uninstall operation of the path intent installer.
116 - */
117 - @Test
118 - public void uninstall() {
119 - installer.activate();
120 -
121 - List<Collection<FlowRuleOperation>> operations =
122 - installer.uninstall(intent);
123 - assertThat(operations, notNullValue());
124 - assertThat(operations, hasSize(1));
125 -
126 - Collection<FlowRuleOperation> flowRuleOpsCollection = operations.get(0);
127 - assertThat(flowRuleOpsCollection, hasSize(hops));
128 - FlowRuleOperation[] flowRuleOps =
129 - flowRuleOpsCollection.toArray(new FlowRuleOperation[hops]);
130 -
131 - FlowRuleOperation op0 = flowRuleOps[0];
132 - checkFlowOperation(op0, FlowRuleOperation.Type.REMOVE, d2p0.deviceId());
133 -
134 - installer.deactivate();
135 - }
136 -}
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 -package org.onosproject.net.intent.impl.installer;
17 -
18 -import java.util.Arrays;
19 -import java.util.Collection;
20 -import java.util.List;
21 -
22 -import org.junit.Before;
23 -import org.junit.Test;
24 -import org.onosproject.net.DefaultLink;
25 -import org.onosproject.net.DefaultPath;
26 -import org.onosproject.net.Link;
27 -import org.onosproject.net.flow.FlowRuleOperation;
28 -import org.onosproject.net.intent.IntentTestsMocks;
29 -import org.onosproject.net.intent.OpticalPathIntent;
30 -
31 -import static org.hamcrest.MatcherAssert.assertThat;
32 -import static org.hamcrest.Matchers.hasSize;
33 -import static org.hamcrest.Matchers.notNullValue;
34 -import static org.onosproject.net.Link.Type.DIRECT;
35 -import static org.onosproject.net.NetTestTools.APP_ID;
36 -import static org.onosproject.net.NetTestTools.PID;
37 -
38 -public class OpticalPathIntentInstallerTest extends IntentInstallerTest {
39 -
40 - OpticalPathIntentInstaller installer;
41 -
42 - private final List<Link> links = Arrays.asList(
43 - new DefaultLink(PID, d1p1, d2p0, DIRECT),
44 - new DefaultLink(PID, d2p1, d3p1, DIRECT)
45 - );
46 - private final int hops = links.size() + 1;
47 - private OpticalPathIntent intent;
48 -
49 - /**
50 - * Configures objects used in all the test cases.
51 - */
52 - @Before
53 - public void localSetUp() {
54 - installer = new OpticalPathIntentInstaller();
55 - installer.coreService = testCoreService;
56 - installer.intentManager =
57 - new IntentInstallerTest.MockIntentManager(OpticalPathIntent.class);
58 - installer.resourceService = new IntentTestsMocks.MockResourceService();
59 -
60 - intent = OpticalPathIntent.builder().appId(APP_ID)
61 - .src(d1p1)
62 - .dst(d3p1)
63 - .path(new DefaultPath(PID, links, hops))
64 - .build();
65 - }
66 -
67 - /**
68 - * Tests activation and deactivation of the installer.
69 - */
70 - @Test
71 - public void activateDeactivate() {
72 - installer.activate();
73 - installer.deactivate();
74 - }
75 -
76 - /**
77 - * Tests installation operation of the optical path intent installer.
78 - */
79 - @Test
80 - public void install() {
81 - installer.activate();
82 -
83 - List<Collection<FlowRuleOperation>> operations =
84 - installer.install(intent);
85 - assertThat(operations, notNullValue());
86 - assertThat(operations, hasSize(1));
87 -
88 - Collection<FlowRuleOperation> flowRuleOpsCollection = operations.get(0);
89 - assertThat(flowRuleOpsCollection, hasSize(hops));
90 - FlowRuleOperation[] flowRuleOps =
91 - flowRuleOpsCollection.toArray(new FlowRuleOperation[hops]);
92 -
93 - FlowRuleOperation op0 = flowRuleOps[0];
94 - checkFlowOperation(op0, FlowRuleOperation.Type.ADD, d1p1.deviceId());
95 -
96 - FlowRuleOperation op1 = flowRuleOps[1];
97 - checkFlowOperation(op1, FlowRuleOperation.Type.ADD, d2p1.deviceId());
98 -
99 - FlowRuleOperation op2 = flowRuleOps[2];
100 - checkFlowOperation(op2, FlowRuleOperation.Type.ADD, d3p1.deviceId());
101 -
102 - installer.deactivate();
103 - }
104 -
105 - /**
106 - * Checks the uninstall operation of the optical path intent installer.
107 - */
108 - @Test
109 - public void uninstall() {
110 - installer.activate();
111 -
112 - List<Collection<FlowRuleOperation>> operations =
113 - installer.uninstall(intent);
114 - assertThat(operations, notNullValue());
115 - assertThat(operations, hasSize(1));
116 -
117 - Collection<FlowRuleOperation> flowRuleOpsCollection = operations.get(0);
118 - assertThat(flowRuleOpsCollection, hasSize(hops));
119 - FlowRuleOperation[] flowRuleOps =
120 - flowRuleOpsCollection.toArray(new FlowRuleOperation[hops]);
121 -
122 - FlowRuleOperation op0 = flowRuleOps[0];
123 - checkFlowOperation(op0, FlowRuleOperation.Type.REMOVE, d1p1.deviceId());
124 -
125 - FlowRuleOperation op1 = flowRuleOps[1];
126 - checkFlowOperation(op1, FlowRuleOperation.Type.REMOVE, d2p1.deviceId());
127 -
128 - FlowRuleOperation op2 = flowRuleOps[2];
129 - checkFlowOperation(op2, FlowRuleOperation.Type.REMOVE, d3p1.deviceId());
130 -
131 - installer.deactivate();
132 - }
133 -
134 -}
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.onosproject.net.intent.impl.installer;
17 -
18 -import org.junit.Before;
19 -import org.junit.Test;
20 -import org.onosproject.net.ConnectPoint;
21 -import org.onosproject.net.DefaultLink;
22 -import org.onosproject.net.DefaultPath;
23 -import org.onosproject.net.Link;
24 -import org.onosproject.net.flow.FlowRuleOperation;
25 -import org.onosproject.net.intent.AbstractIntentTest;
26 -import org.onosproject.net.intent.Constraint;
27 -import org.onosproject.net.intent.IntentTestsMocks;
28 -import org.onosproject.net.intent.PathIntent;
29 -import org.onosproject.net.intent.constraint.BandwidthConstraint;
30 -import org.onosproject.net.intent.constraint.LambdaConstraint;
31 -import org.onosproject.net.resource.Bandwidth;
32 -import org.onosproject.net.resource.Lambda;
33 -
34 -import java.util.Arrays;
35 -import java.util.Collection;
36 -import java.util.List;
37 -
38 -import static org.hamcrest.MatcherAssert.assertThat;
39 -import static org.hamcrest.Matchers.hasSize;
40 -import static org.hamcrest.Matchers.instanceOf;
41 -import static org.hamcrest.Matchers.notNullValue;
42 -import static org.junit.Assert.fail;
43 -import static org.onosproject.net.DefaultEdgeLink.createEdgeLink;
44 -import static org.onosproject.net.Link.Type.DIRECT;
45 -import static org.onosproject.net.NetTestTools.APP_ID;
46 -import static org.onosproject.net.NetTestTools.PID;
47 -import static org.onosproject.net.NetTestTools.connectPoint;
48 -import static org.onosproject.net.intent.IntentTestsMocks.MockResourceService.makeBandwidthResourceService;
49 -import static org.onosproject.net.intent.IntentTestsMocks.MockResourceService.makeLambdaResourceService;
50 -
51 -/**
52 - * Unit tests for calculating paths for intents with constraints.
53 - */
54 -
55 -public class PathConstraintCalculationTest extends AbstractIntentTest {
56 -
57 - private final IntentTestsMocks.MockSelector selector = new IntentTestsMocks.MockSelector();
58 - private final IntentTestsMocks.MockTreatment treatment = new IntentTestsMocks.MockTreatment();
59 - private final ConnectPoint d1p1 = connectPoint("s1", 0);
60 - private final ConnectPoint d2p0 = connectPoint("s2", 0);
61 - private final ConnectPoint d2p1 = connectPoint("s2", 1);
62 - private final ConnectPoint d3p1 = connectPoint("s3", 1);
63 - private final ConnectPoint d3p0 = connectPoint("s3", 10);
64 - private final ConnectPoint d1p0 = connectPoint("s1", 10);
65 -
66 - private PathIntentInstaller sut;
67 -
68 - @Before
69 - public void setUpIntentInstaller() {
70 - sut = new PathIntentInstaller();
71 - sut.appId = APP_ID;
72 - }
73 -
74 - private PathIntent createPathIntent(List<Link> links, List<Constraint> constraints) {
75 - int hops = links.size() - 1;
76 - return PathIntent.builder()
77 - .appId(APP_ID)
78 - .selector(selector)
79 - .treatment(treatment)
80 - .path(new DefaultPath(PID, links, hops))
81 - .constraints(constraints)
82 - .priority(333)
83 - .build();
84 - }
85 -
86 - /**
87 - * Tests that installation of bandwidth constrained path intents are
88 - * successful.
89 - */
90 - @Test
91 - public void testInstallBandwidthConstrainedIntentSuccess() {
92 -
93 - final Constraint constraint = new BandwidthConstraint(Bandwidth.bps(100.0));
94 -
95 - List<Link> links = Arrays.asList(
96 - createEdgeLink(d1p0, true),
97 - new DefaultLink(PID, d1p1, d2p0, DIRECT),
98 - new DefaultLink(PID, d2p1, d3p1, DIRECT),
99 - createEdgeLink(d3p0, false)
100 - );
101 - PathIntent installable = createPathIntent(links, Arrays.asList(constraint));
102 -
103 - sut.resourceService = makeBandwidthResourceService(1000.0);
104 -
105 - final List<Collection<FlowRuleOperation>> flowOperations = sut.install(installable);
106 -
107 - assertThat(flowOperations, notNullValue());
108 - assertThat(flowOperations, hasSize(1));
109 - }
110 -
111 - /**
112 - * Tests that installation of bandwidth constrained path intents fail
113 - * if there are no available resources.
114 - */
115 - @Test
116 - public void testInstallBandwidthConstrainedIntentFailure() {
117 -
118 - final Constraint constraint = new BandwidthConstraint(Bandwidth.bps(100.0));
119 -
120 - List<Link> links = Arrays.asList(
121 - createEdgeLink(d1p0, true),
122 - new DefaultLink(PID, d1p1, d2p0, DIRECT),
123 - new DefaultLink(PID, d2p1, d3p1, DIRECT),
124 - createEdgeLink(d3p0, false)
125 - );
126 - PathIntent installable = createPathIntent(links, Arrays.asList(constraint));
127 -
128 - // Make it look like the available bandwidth was consumed
129 - final IntentTestsMocks.MockResourceService resourceService = makeBandwidthResourceService(1000.0);
130 - resourceService.setAvailableBandwidth(1.0);
131 - sut.resourceService = resourceService;
132 -
133 - try {
134 - sut.install(installable);
135 - fail("Bandwidth request with no available bandwidth did not fail.");
136 - } catch (IntentTestsMocks.MockedAllocationFailure failure) {
137 - assertThat(failure,
138 - instanceOf(IntentTestsMocks.MockedAllocationFailure.class));
139 - }
140 - }
141 -
142 - /**
143 - * Tests that installation of lambda constrained path intents are
144 - * successful.
145 - */
146 - @Test
147 - public void testInstallLambdaConstrainedIntentSuccess() {
148 -
149 - final Constraint constraint = new LambdaConstraint(Lambda.valueOf(1));
150 -
151 - List<Link> links = Arrays.asList(
152 - createEdgeLink(d1p0, true),
153 - new DefaultLink(PID, d1p1, d2p0, DIRECT),
154 - new DefaultLink(PID, d2p1, d3p1, DIRECT),
155 - createEdgeLink(d3p0, false)
156 - );
157 - PathIntent installable = createPathIntent(links, Arrays.asList(constraint));
158 -
159 - sut.resourceService = makeLambdaResourceService(1);
160 -
161 - final List<Collection<FlowRuleOperation>> flowOperations = sut.install(installable);
162 -
163 - assertThat(flowOperations, notNullValue());
164 - assertThat(flowOperations, hasSize(1));
165 - }
166 -
167 - /**
168 - * Tests that installation of lambda constrained path intents fail
169 - * if there are no available resources.
170 - */
171 - @Test
172 - public void testInstallLambdaConstrainedIntentFailure() {
173 -
174 - final Constraint constraint = new LambdaConstraint(Lambda.valueOf(1));
175 -
176 - List<Link> links = Arrays.asList(
177 - createEdgeLink(d1p0, true),
178 - new DefaultLink(PID, d1p1, d2p0, DIRECT),
179 - new DefaultLink(PID, d2p1, d3p1, DIRECT),
180 - createEdgeLink(d3p0, false)
181 - );
182 - PathIntent installable = createPathIntent(links, Arrays.asList(constraint));
183 -
184 - // Make it look like the available lambda was consumed
185 - final IntentTestsMocks.MockResourceService resourceService = makeLambdaResourceService(1);
186 - resourceService.setAvailableLambda(0);
187 - sut.resourceService = resourceService;
188 -
189 - try {
190 - sut.install(installable);
191 - fail("Lambda request with no available lambda did not fail.");
192 - } catch (IntentTestsMocks.MockedAllocationFailure failure) {
193 - assertThat(failure,
194 - instanceOf(IntentTestsMocks.MockedAllocationFailure.class));
195 - }
196 - }
197 -
198 -}
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 -package org.onosproject.net.intent.impl.installer;
17 -
18 -import java.util.Arrays;
19 -import java.util.Collection;
20 -import java.util.List;
21 -
22 -import org.junit.Before;
23 -import org.junit.Test;
24 -import org.onosproject.net.DefaultLink;
25 -import org.onosproject.net.DefaultPath;
26 -import org.onosproject.net.Link;
27 -import org.onosproject.net.flow.FlowRuleOperation;
28 -import org.onosproject.net.intent.PathIntent;
29 -
30 -import static org.hamcrest.MatcherAssert.assertThat;
31 -import static org.hamcrest.Matchers.hasSize;
32 -import static org.hamcrest.Matchers.notNullValue;
33 -import static org.onosproject.net.DefaultEdgeLink.createEdgeLink;
34 -import static org.onosproject.net.Link.Type.DIRECT;
35 -import static org.onosproject.net.NetTestTools.APP_ID;
36 -import static org.onosproject.net.NetTestTools.PID;
37 -
38 -/**
39 - * Unit tests for path intent installer.
40 - */
41 -public class PathIntentInstallerTest extends IntentInstallerTest {
42 -
43 - PathIntentInstaller installer;
44 -
45 - private final List<Link> links = Arrays.asList(
46 - createEdgeLink(d1p0, true),
47 - new DefaultLink(PID, d1p1, d2p0, DIRECT),
48 - new DefaultLink(PID, d2p1, d3p1, DIRECT),
49 - createEdgeLink(d3p0, false)
50 - );
51 - private final int hops = links.size() - 1;
52 - private PathIntent intent;
53 -
54 - /**
55 - * Configures objects used in all the test cases.
56 - */
57 - @Before
58 - public void localSetUp() {
59 - installer = new PathIntentInstaller();
60 - installer.coreService = testCoreService;
61 - installer.intentManager = new MockIntentManager(PathIntent.class);
62 - intent = PathIntent.builder()
63 - .appId(APP_ID)
64 - .selector(selector)
65 - .treatment(treatment)
66 - .path(new DefaultPath(PID, links, hops))
67 - .priority(77)
68 - .build();
69 - }
70 -
71 - /**
72 - * Tests activation and deactivation of the installer.
73 - */
74 - @Test
75 - public void activateDeactivate() {
76 - installer.activate();
77 - installer.deactivate();
78 - }
79 -
80 - /**
81 - * Tests installation operation of the path intent installer.
82 - */
83 - @Test
84 - public void install() {
85 - installer.activate();
86 -
87 - List<Collection<FlowRuleOperation>> operations =
88 - installer.install(intent);
89 - assertThat(operations, notNullValue());
90 - assertThat(operations, hasSize(1));
91 -
92 - Collection<FlowRuleOperation> flowRuleOpsCollection = operations.get(0);
93 - assertThat(flowRuleOpsCollection, hasSize(hops));
94 - FlowRuleOperation[] flowRuleOps =
95 - flowRuleOpsCollection.toArray(new FlowRuleOperation[hops]);
96 -
97 - FlowRuleOperation op0 = flowRuleOps[0];
98 - checkFlowOperation(op0, FlowRuleOperation.Type.ADD, d1p0.deviceId());
99 -
100 - FlowRuleOperation op1 = flowRuleOps[1];
101 - checkFlowOperation(op1, FlowRuleOperation.Type.ADD, d2p0.deviceId());
102 -
103 - FlowRuleOperation op2 = flowRuleOps[2];
104 - checkFlowOperation(op2, FlowRuleOperation.Type.ADD, d3p0.deviceId());
105 -
106 - installer.deactivate();
107 - }
108 -
109 - /**
110 - * Checks the uninstall operation of the path intent installer.
111 - */
112 - @Test
113 - public void uninstall() {
114 - installer.activate();
115 -
116 - List<Collection<FlowRuleOperation>> operations =
117 - installer.uninstall(intent);
118 - assertThat(operations, notNullValue());
119 - assertThat(operations, hasSize(1));
120 -
121 - Collection<FlowRuleOperation> flowRuleOpsCollection = operations.get(0);
122 - assertThat(flowRuleOpsCollection, hasSize(hops));
123 - FlowRuleOperation[] flowRuleOps =
124 - flowRuleOpsCollection.toArray(new FlowRuleOperation[hops]);
125 -
126 - FlowRuleOperation op0 = flowRuleOps[0];
127 - checkFlowOperation(op0, FlowRuleOperation.Type.REMOVE, d1p0.deviceId());
128 -
129 - FlowRuleOperation op1 = flowRuleOps[1];
130 - checkFlowOperation(op1, FlowRuleOperation.Type.REMOVE, d2p0.deviceId());
131 -
132 - FlowRuleOperation op2 = flowRuleOps[2];
133 - checkFlowOperation(op2, FlowRuleOperation.Type.REMOVE, d3p0.deviceId());
134 -
135 - installer.deactivate();
136 - }
137 -}
...@@ -121,12 +121,12 @@ public class CompilingTest { ...@@ -121,12 +121,12 @@ public class CompilingTest {
121 expect(processor.compile(input, null)).andReturn(Arrays.asList(compiled)); 121 expect(processor.compile(input, null)).andReturn(Arrays.asList(compiled));
122 replay(processor); 122 replay(processor);
123 123
124 - Compiling sut = new Compiling(processor, pending, null); 124 + Compiling sut = new Compiling(processor, pending);
125 125
126 Optional<IntentProcessPhase> output = sut.execute(); 126 Optional<IntentProcessPhase> output = sut.execute();
127 127
128 verify(processor); 128 verify(processor);
129 - assertThat(output.get(), is(instanceOf(InstallCoordinating.class))); 129 + assertThat(output.get(), is(instanceOf(Installing.class)));
130 } 130 }
131 131
132 /** 132 /**
...@@ -139,11 +139,11 @@ public class CompilingTest { ...@@ -139,11 +139,11 @@ public class CompilingTest {
139 expect(processor.compile(input, null)).andThrow(new IntentCompilationException()); 139 expect(processor.compile(input, null)).andThrow(new IntentCompilationException());
140 replay(processor); 140 replay(processor);
141 141
142 - Compiling sut = new Compiling(processor, pending, null); 142 + Compiling sut = new Compiling(processor, pending);
143 143
144 Optional<IntentProcessPhase> output = sut.execute(); 144 Optional<IntentProcessPhase> output = sut.execute();
145 145
146 verify(processor); 146 verify(processor);
147 - assertThat(output.get(), is(instanceOf(CompilingFailed.class))); 147 + assertThat(output.get(), is(instanceOf(CompileFailed.class)));
148 } 148 }
149 } 149 }
......
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 -package org.onosproject.net.intent.impl.phase;
17 -
18 -import org.junit.After;
19 -import org.junit.Before;
20 -import org.junit.Test;
21 -import org.onosproject.TestApplicationId;
22 -import org.onosproject.core.ApplicationId;
23 -import org.onosproject.core.IdGenerator;
24 -import org.onosproject.net.ConnectPoint;
25 -import org.onosproject.net.DefaultLink;
26 -import org.onosproject.net.DefaultPath;
27 -import org.onosproject.net.Link;
28 -import org.onosproject.net.Path;
29 -import org.onosproject.net.flow.DefaultTrafficSelector;
30 -import org.onosproject.net.flow.DefaultTrafficTreatment;
31 -import org.onosproject.net.flow.FlowRuleOperations;
32 -import org.onosproject.net.flow.TrafficSelector;
33 -import org.onosproject.net.flow.TrafficTreatment;
34 -import org.onosproject.net.intent.Intent;
35 -import org.onosproject.net.intent.IntentData;
36 -import org.onosproject.net.intent.MockIdGenerator;
37 -import org.onosproject.net.intent.PathIntent;
38 -import org.onosproject.net.intent.PointToPointIntent;
39 -import org.onosproject.net.intent.impl.IntentInstallationException;
40 -import org.onosproject.net.intent.impl.IntentProcessor;
41 -import org.onosproject.net.provider.ProviderId;
42 -import org.onosproject.store.Timestamp;
43 -
44 -import java.util.Arrays;
45 -import java.util.List;
46 -import java.util.Optional;
47 -
48 -import static org.easymock.EasyMock.createMock;
49 -import static org.easymock.EasyMock.expectLastCall;
50 -import static org.easymock.EasyMock.replay;
51 -import static org.easymock.EasyMock.verify;
52 -import static org.hamcrest.Matchers.instanceOf;
53 -import static org.hamcrest.Matchers.is;
54 -import static org.junit.Assert.assertThat;
55 -import static org.onosproject.net.DeviceId.deviceId;
56 -import static org.onosproject.net.Link.Type.DIRECT;
57 -import static org.onosproject.net.PortNumber.portNumber;
58 -import static org.onosproject.net.intent.IntentState.INSTALL_REQ;
59 -
60 -/**
61 - * Unit tests for Installing phase.
62 - */
63 -public class InstallingTest {
64 -
65 - private final ApplicationId appId = new TestApplicationId("test");
66 - private final ProviderId pid = new ProviderId("of", "test");
67 - private final TrafficSelector selector = DefaultTrafficSelector.emptySelector();
68 - private final TrafficTreatment treatment = DefaultTrafficTreatment.emptyTreatment();
69 - private final ConnectPoint cp1 = new ConnectPoint(deviceId("1"), portNumber(1));
70 - private final ConnectPoint cp2 = new ConnectPoint(deviceId("1"), portNumber(2));
71 - private final ConnectPoint cp3 = new ConnectPoint(deviceId("2"), portNumber(1));
72 - private final ConnectPoint cp4 = new ConnectPoint(deviceId("2"), portNumber(2));
73 -
74 - private final List<Link> links = Arrays.asList(new DefaultLink(pid, cp2, cp4, DIRECT));
75 - private final Path path = new DefaultPath(pid, links, 10);
76 -
77 - private PointToPointIntent input;
78 - private PathIntent compiled;
79 -
80 - private IdGenerator idGenerator;
81 - private IntentProcessor processor;
82 - private Timestamp version;
83 -
84 - @Before
85 - public void setUp() {
86 - processor = createMock(IntentProcessor.class);
87 - version = createMock(Timestamp.class);
88 -
89 - idGenerator = new MockIdGenerator();
90 -
91 - Intent.bindIdGenerator(idGenerator);
92 -
93 - // Intent creation should be placed after binding an ID generator
94 - input = PointToPointIntent.builder()
95 - .appId(appId)
96 - .selector(selector)
97 - .treatment(treatment)
98 - .ingressPoint(cp1)
99 - .egressPoint(cp3)
100 - .build();
101 - compiled = PathIntent.builder()
102 - .appId(appId)
103 - .selector(selector)
104 - .treatment(treatment)
105 - .path(path)
106 - .build();
107 - }
108 -
109 -
110 - @After
111 - public void tearDown() {
112 - Intent.unbindIdGenerator(idGenerator);
113 - }
114 -
115 - /**
116 - * Tests a next phase when no exception occurs.
117 - */
118 - @Test
119 - public void testMoveToNextPhaseWithoutError() {
120 - IntentData pending = new IntentData(input, INSTALL_REQ, version);
121 - pending.setInstallables(Arrays.asList(compiled));
122 -
123 - FlowRuleOperations operations = createMock(FlowRuleOperations.class);
124 -
125 - processor.applyFlowRules(operations);
126 - replay(processor);
127 -
128 - Installing sut = new Installing(processor, pending, operations);
129 -
130 - Optional<IntentProcessPhase> executed = sut.execute();
131 - verify(processor);
132 - assertThat(executed.get(), is(instanceOf(Installed.class)));
133 - }
134 -
135 - /**
136 - * Test a next phase when IntentInstallationException occurs.
137 - */
138 - @Test
139 - public void testWhenIntentInstallationExceptionOccurs() {
140 - IntentData pending = new IntentData(input, INSTALL_REQ, version);
141 - pending.setInstallables(Arrays.asList(compiled));
142 -
143 - FlowRuleOperations operations = createMock(FlowRuleOperations.class);
144 -
145 - processor.applyFlowRules(operations);
146 - expectLastCall().andThrow(new IntentInstallationException());
147 - replay(processor);
148 -
149 - Installing sut = new Installing(processor, pending, operations);
150 -
151 - Optional<IntentProcessPhase> executed = sut.execute();
152 - verify(processor);
153 - assertThat(executed.get(), is(instanceOf(InstallingFailed.class)));
154 - }
155 -}
...@@ -28,7 +28,6 @@ import org.onosproject.net.Link; ...@@ -28,7 +28,6 @@ import org.onosproject.net.Link;
28 import org.onosproject.net.Path; 28 import org.onosproject.net.Path;
29 import org.onosproject.net.flow.DefaultTrafficSelector; 29 import org.onosproject.net.flow.DefaultTrafficSelector;
30 import org.onosproject.net.flow.DefaultTrafficTreatment; 30 import org.onosproject.net.flow.DefaultTrafficTreatment;
31 -import org.onosproject.net.flow.FlowRuleOperations;
32 import org.onosproject.net.flow.TrafficSelector; 31 import org.onosproject.net.flow.TrafficSelector;
33 import org.onosproject.net.flow.TrafficTreatment; 32 import org.onosproject.net.flow.TrafficTreatment;
34 import org.onosproject.net.intent.Intent; 33 import org.onosproject.net.intent.Intent;
...@@ -46,7 +45,7 @@ import java.util.List; ...@@ -46,7 +45,7 @@ import java.util.List;
46 import java.util.Optional; 45 import java.util.Optional;
47 46
48 import static org.easymock.EasyMock.createMock; 47 import static org.easymock.EasyMock.createMock;
49 -import static org.easymock.EasyMock.expect; 48 +import static org.easymock.EasyMock.expectLastCall;
50 import static org.easymock.EasyMock.replay; 49 import static org.easymock.EasyMock.replay;
51 import static org.easymock.EasyMock.verify; 50 import static org.easymock.EasyMock.verify;
52 import static org.hamcrest.Matchers.instanceOf; 51 import static org.hamcrest.Matchers.instanceOf;
...@@ -55,12 +54,13 @@ import static org.junit.Assert.assertThat; ...@@ -55,12 +54,13 @@ import static org.junit.Assert.assertThat;
55 import static org.onosproject.net.DeviceId.deviceId; 54 import static org.onosproject.net.DeviceId.deviceId;
56 import static org.onosproject.net.Link.Type.DIRECT; 55 import static org.onosproject.net.Link.Type.DIRECT;
57 import static org.onosproject.net.PortNumber.portNumber; 56 import static org.onosproject.net.PortNumber.portNumber;
57 +import static org.onosproject.net.intent.IntentState.INSTALLED;
58 import static org.onosproject.net.intent.IntentState.INSTALL_REQ; 58 import static org.onosproject.net.intent.IntentState.INSTALL_REQ;
59 59
60 /** 60 /**
61 * Unit tests for InstallingCoordinating phase. 61 * Unit tests for InstallingCoordinating phase.
62 */ 62 */
63 -public class InstallCoordinatingTest { 63 +public class ReplacingTest {
64 64
65 private final ApplicationId appId = new TestApplicationId("test"); 65 private final ApplicationId appId = new TestApplicationId("test");
66 private final ProviderId pid = new ProviderId("of", "test"); 66 private final ProviderId pid = new ProviderId("of", "test");
...@@ -120,12 +120,13 @@ public class InstallCoordinatingTest { ...@@ -120,12 +120,13 @@ public class InstallCoordinatingTest {
120 IntentData pending = new IntentData(input, INSTALL_REQ, version); 120 IntentData pending = new IntentData(input, INSTALL_REQ, version);
121 pending.setInstallables(Arrays.asList(compiled)); 121 pending.setInstallables(Arrays.asList(compiled));
122 122
123 - FlowRuleOperations operations = createMock(FlowRuleOperations.class); 123 + IntentData current = new IntentData(input, INSTALLED, version);
124 + current.setInstallables(Arrays.asList(compiled));
124 125
125 - expect(processor.coordinate(null, pending)).andReturn(operations); 126 + processor.uninstall(current);
126 replay(processor); 127 replay(processor);
127 128
128 - InstallCoordinating sut = new InstallCoordinating(processor, pending, null); 129 + Replacing sut = new Replacing(processor, pending, current);
129 130
130 Optional<IntentProcessPhase> executed = sut.execute(); 131 Optional<IntentProcessPhase> executed = sut.execute();
131 132
...@@ -141,14 +142,17 @@ public class InstallCoordinatingTest { ...@@ -141,14 +142,17 @@ public class InstallCoordinatingTest {
141 IntentData pending = new IntentData(input, INSTALL_REQ, version); 142 IntentData pending = new IntentData(input, INSTALL_REQ, version);
142 pending.setInstallables(Arrays.asList(compiled)); 143 pending.setInstallables(Arrays.asList(compiled));
143 144
144 - expect(processor.coordinate(null, pending)).andThrow(new IntentInstallationException()); 145 + IntentData current = new IntentData(input, INSTALLED, version);
146 +
147 + processor.uninstall(current);
148 + expectLastCall().andThrow(new IntentInstallationException());
145 replay(processor); 149 replay(processor);
146 150
147 - InstallCoordinating sut = new InstallCoordinating(processor, pending, null); 151 + Replacing sut = new Replacing(processor, pending, current);
148 152
149 Optional<IntentProcessPhase> executed = sut.execute(); 153 Optional<IntentProcessPhase> executed = sut.execute();
150 154
151 verify(processor); 155 verify(processor);
152 - assertThat(executed.get(), is(instanceOf(InstallingFailed.class))); 156 + assertThat(executed.get(), is(instanceOf(ReplaceFailed.class)));
153 } 157 }
154 } 158 }
......
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 -package org.onosproject.net.intent.impl.phase;
17 -
18 -import org.junit.After;
19 -import org.junit.Before;
20 -import org.junit.Test;
21 -import org.onosproject.TestApplicationId;
22 -import org.onosproject.core.ApplicationId;
23 -import org.onosproject.core.IdGenerator;
24 -import org.onosproject.net.ConnectPoint;
25 -import org.onosproject.net.DefaultLink;
26 -import org.onosproject.net.DefaultPath;
27 -import org.onosproject.net.Link;
28 -import org.onosproject.net.Path;
29 -import org.onosproject.net.flow.DefaultTrafficSelector;
30 -import org.onosproject.net.flow.DefaultTrafficTreatment;
31 -import org.onosproject.net.flow.FlowRuleOperations;
32 -import org.onosproject.net.flow.TrafficSelector;
33 -import org.onosproject.net.flow.TrafficTreatment;
34 -import org.onosproject.net.intent.Intent;
35 -import org.onosproject.net.intent.IntentData;
36 -import org.onosproject.net.intent.MockIdGenerator;
37 -import org.onosproject.net.intent.PathIntent;
38 -import org.onosproject.net.intent.PointToPointIntent;
39 -import org.onosproject.net.intent.impl.IntentProcessor;
40 -import org.onosproject.net.intent.impl.IntentRemovalException;
41 -import org.onosproject.net.provider.ProviderId;
42 -import org.onosproject.store.Timestamp;
43 -
44 -import java.util.Arrays;
45 -import java.util.List;
46 -import java.util.Optional;
47 -
48 -import static org.easymock.EasyMock.createMock;
49 -import static org.easymock.EasyMock.expect;
50 -import static org.easymock.EasyMock.replay;
51 -import static org.easymock.EasyMock.verify;
52 -import static org.hamcrest.Matchers.instanceOf;
53 -import static org.hamcrest.Matchers.is;
54 -import static org.junit.Assert.assertThat;
55 -import static org.onosproject.net.DeviceId.deviceId;
56 -import static org.onosproject.net.Link.Type.DIRECT;
57 -import static org.onosproject.net.PortNumber.portNumber;
58 -import static org.onosproject.net.intent.IntentState.INSTALLED;
59 -import static org.onosproject.net.intent.IntentState.WITHDRAW_REQ;
60 -
61 -/**
62 - * Unit tests for WithdrawCoordinating phase.
63 - */
64 -public class WithdrawCoordinatingTest {
65 -
66 - private final ApplicationId appId = new TestApplicationId("test");
67 - private final ProviderId pid = new ProviderId("of", "test");
68 - private final TrafficSelector selector = DefaultTrafficSelector.emptySelector();
69 - private final TrafficTreatment treatment = DefaultTrafficTreatment.emptyTreatment();
70 - private final ConnectPoint cp1 = new ConnectPoint(deviceId("1"), portNumber(1));
71 - private final ConnectPoint cp2 = new ConnectPoint(deviceId("1"), portNumber(2));
72 - private final ConnectPoint cp3 = new ConnectPoint(deviceId("2"), portNumber(1));
73 - private final ConnectPoint cp4 = new ConnectPoint(deviceId("2"), portNumber(2));
74 -
75 - private final List<Link> links = Arrays.asList(new DefaultLink(pid, cp2, cp4, DIRECT));
76 - private final Path path = new DefaultPath(pid, links, 10);
77 -
78 - private PointToPointIntent input;
79 - private PathIntent compiled;
80 -
81 - private IdGenerator idGenerator;
82 - private IntentProcessor processor;
83 - private Timestamp version;
84 -
85 - @Before
86 - public void setUp() {
87 - processor = createMock(IntentProcessor.class);
88 - version = createMock(Timestamp.class);
89 -
90 - idGenerator = new MockIdGenerator();
91 -
92 - Intent.bindIdGenerator(idGenerator);
93 -
94 - // Intent creation should be placed after binding an ID generator
95 - input = PointToPointIntent.builder()
96 - .appId(appId)
97 - .selector(selector)
98 - .treatment(treatment)
99 - .ingressPoint(cp1)
100 - .egressPoint(cp3)
101 - .build();
102 - compiled = PathIntent.builder()
103 - .appId(appId)
104 - .selector(selector)
105 - .treatment(treatment)
106 - .path(path)
107 - .build();
108 - }
109 -
110 -
111 - @After
112 - public void tearDown() {
113 - Intent.unbindIdGenerator(idGenerator);
114 - }
115 -
116 - /**
117 - * Tests a next phase when no exception occurs.
118 - */
119 - @Test
120 - public void testMoveToNextPhaseWithoutError() {
121 - IntentData pending = new IntentData(input, WITHDRAW_REQ, version);
122 - IntentData current = new IntentData(input, INSTALLED, version);
123 - current.setInstallables(Arrays.asList(compiled));
124 -
125 - FlowRuleOperations operations = createMock(FlowRuleOperations.class);
126 - expect(processor.uninstallCoordinate(current, pending)).andReturn(operations);
127 - replay(processor);
128 -
129 - WithdrawCoordinating sut = new WithdrawCoordinating(processor, pending, current);
130 -
131 - Optional<IntentProcessPhase> executed = sut.execute();
132 - verify(processor);
133 - assertThat(executed.get(), is(instanceOf(Withdrawing.class)));
134 - }
135 -
136 - /**
137 - * Tests a next phase when IntentRemovalExceptionOccurs.
138 - */
139 - @Test
140 - public void testWhenIntentRemovalExceptionOccurs() {
141 - IntentData pending = new IntentData(input, WITHDRAW_REQ, version);
142 - IntentData current = new IntentData(input, INSTALLED, version);
143 - current.setInstallables(Arrays.asList(compiled));
144 -
145 - expect(processor.uninstallCoordinate(current, pending)).andThrow(new IntentRemovalException());
146 - replay(processor);
147 -
148 - WithdrawCoordinating sut = new WithdrawCoordinating(processor, pending, current);
149 -
150 - Optional<IntentProcessPhase> executed = sut.execute();
151 - verify(processor);
152 - assertThat(executed.get(), is(instanceOf(WithdrawingFailed.class)));
153 - }
154 -
155 -}
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 -package org.onosproject.net.intent.impl.phase;
17 -
18 -import org.junit.After;
19 -import org.junit.Before;
20 -import org.junit.Test;
21 -import org.onosproject.TestApplicationId;
22 -import org.onosproject.core.ApplicationId;
23 -import org.onosproject.core.IdGenerator;
24 -import org.onosproject.net.ConnectPoint;
25 -import org.onosproject.net.DefaultLink;
26 -import org.onosproject.net.DefaultPath;
27 -import org.onosproject.net.Link;
28 -import org.onosproject.net.Path;
29 -import org.onosproject.net.flow.DefaultTrafficSelector;
30 -import org.onosproject.net.flow.DefaultTrafficTreatment;
31 -import org.onosproject.net.flow.FlowRuleOperations;
32 -import org.onosproject.net.flow.TrafficSelector;
33 -import org.onosproject.net.flow.TrafficTreatment;
34 -import org.onosproject.net.intent.Intent;
35 -import org.onosproject.net.intent.IntentData;
36 -import org.onosproject.net.intent.MockIdGenerator;
37 -import org.onosproject.net.intent.PathIntent;
38 -import org.onosproject.net.intent.PointToPointIntent;
39 -import org.onosproject.net.intent.impl.IntentProcessor;
40 -import org.onosproject.net.provider.ProviderId;
41 -import org.onosproject.store.Timestamp;
42 -
43 -import java.util.Arrays;
44 -import java.util.List;
45 -import java.util.Optional;
46 -
47 -import static org.easymock.EasyMock.createMock;
48 -import static org.easymock.EasyMock.replay;
49 -import static org.easymock.EasyMock.verify;
50 -import static org.hamcrest.Matchers.instanceOf;
51 -import static org.hamcrest.Matchers.is;
52 -import static org.junit.Assert.assertThat;
53 -import static org.onosproject.net.DeviceId.deviceId;
54 -import static org.onosproject.net.Link.Type.DIRECT;
55 -import static org.onosproject.net.PortNumber.portNumber;
56 -import static org.onosproject.net.intent.IntentState.INSTALLED;
57 -import static org.onosproject.net.intent.IntentState.WITHDRAW_REQ;
58 -
59 -/**
60 - * Unit tests for Withdrawing phase.
61 - */
62 -public class WithdrawingTest {
63 -
64 - private final ApplicationId appId = new TestApplicationId("test");
65 - private final ProviderId pid = new ProviderId("of", "test");
66 - private final TrafficSelector selector = DefaultTrafficSelector.emptySelector();
67 - private final TrafficTreatment treatment = DefaultTrafficTreatment.emptyTreatment();
68 - private final ConnectPoint cp1 = new ConnectPoint(deviceId("1"), portNumber(1));
69 - private final ConnectPoint cp2 = new ConnectPoint(deviceId("1"), portNumber(2));
70 - private final ConnectPoint cp3 = new ConnectPoint(deviceId("2"), portNumber(1));
71 - private final ConnectPoint cp4 = new ConnectPoint(deviceId("2"), portNumber(2));
72 -
73 - private final List<Link> links = Arrays.asList(new DefaultLink(pid, cp2, cp4, DIRECT));
74 - private final Path path = new DefaultPath(pid, links, 10);
75 -
76 - private PointToPointIntent input;
77 - private PathIntent compiled;
78 -
79 - private IdGenerator idGenerator;
80 - private IntentProcessor processor;
81 - private Timestamp version;
82 -
83 - @Before
84 - public void setUp() {
85 - processor = createMock(IntentProcessor.class);
86 - version = createMock(Timestamp.class);
87 -
88 - idGenerator = new MockIdGenerator();
89 -
90 - Intent.bindIdGenerator(idGenerator);
91 -
92 - // Intent creation should be placed after binding an ID generator
93 - input = PointToPointIntent.builder()
94 - .appId(appId)
95 - .selector(selector)
96 - .treatment(treatment)
97 - .ingressPoint(cp1)
98 - .egressPoint(cp3)
99 - .build();
100 - compiled = PathIntent.builder()
101 - .appId(appId)
102 - .selector(selector)
103 - .treatment(treatment)
104 - .path(path)
105 - .build();
106 - }
107 -
108 -
109 - @After
110 - public void tearDown() {
111 - Intent.unbindIdGenerator(idGenerator);
112 - }
113 -
114 - /**
115 - * Tests a next phase when no exception occurs.
116 - */
117 - @Test
118 - public void testMoveToNextPhaseWithoutError() {
119 - IntentData pending = new IntentData(input, WITHDRAW_REQ, version);
120 - IntentData current = new IntentData(input, INSTALLED, version);
121 - current.setInstallables(Arrays.asList(compiled));
122 -
123 - FlowRuleOperations operations = createMock(FlowRuleOperations.class);
124 - processor.applyFlowRules(operations);
125 - replay(processor);
126 -
127 - Withdrawing sut = new Withdrawing(processor, pending, operations);
128 -
129 - Optional<IntentProcessPhase> executed = sut.execute();
130 - verify(processor);
131 - assertThat(executed.get(), is(instanceOf(Withdrawn.class)));
132 - }
133 -}