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
diff --git a/core/net/src/test/java/org/onosproject/net/intent/impl/IntentManagerTest.java b/core/net/src/test/java/org/onosproject/net/intent/impl/IntentManagerTest.java
index 64c963b..87ca8c7 100644
--- a/core/net/src/test/java/org/onosproject/net/intent/impl/IntentManagerTest.java
+++ b/core/net/src/test/java/org/onosproject/net/intent/impl/IntentManagerTest.java
@@ -15,6 +15,7 @@
*/
package org.onosproject.net.intent.impl;
+import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
@@ -34,15 +35,13 @@
import org.onosproject.core.impl.TestCoreManager;
import org.onosproject.event.impl.TestEventDispatcher;
import org.onosproject.net.NetworkResource;
-import org.onosproject.net.flow.FlowRule;
-import org.onosproject.net.flow.FlowRuleOperation;
+import org.onosproject.net.intent.FlowRuleIntent;
import org.onosproject.net.intent.Intent;
import org.onosproject.net.intent.IntentCompiler;
import org.onosproject.net.intent.IntentEvent;
import org.onosproject.net.intent.IntentEvent.Type;
import org.onosproject.net.intent.IntentExtensionService;
import org.onosproject.net.intent.IntentId;
-import org.onosproject.net.intent.IntentInstaller;
import org.onosproject.net.intent.IntentListener;
import org.onosproject.net.intent.IntentService;
import org.onosproject.net.intent.IntentState;
@@ -51,7 +50,6 @@
import org.onosproject.store.trivial.impl.SimpleIntentStore;
import com.google.common.collect.HashMultimap;
-import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.google.common.collect.Multimap;
@@ -95,7 +93,6 @@
protected IntentExtensionService extensionService;
protected TestListener listener = new TestListener();
protected TestIntentCompiler compiler = new TestIntentCompiler();
- protected TestIntentInstaller installer = new TestIntentInstaller();
private static class TestListener implements IntentListener {
final Multimap<IntentEvent.Type, IntentEvent> events = HashMultimap.create();
@@ -152,14 +149,10 @@
}
}
- private static class MockInstallableIntent extends MockIntent {
- public MockInstallableIntent(Long number) {
- super(number);
- }
+ private static class MockInstallableIntent extends FlowRuleIntent {
- @Override
- public boolean isInstallable() {
- return true;
+ public MockInstallableIntent() {
+ super(APPID, Arrays.asList(new MockFlowRule(100)));
}
}
@@ -167,7 +160,7 @@
@Override
public List<Intent> compile(MockIntent intent, List<Intent> installable,
Set<LinkResourceAllocations> resources) {
- return Lists.newArrayList(new MockInstallableIntent(intent.number()));
+ return Lists.newArrayList(new MockInstallableIntent());
}
}
@@ -179,53 +172,6 @@
}
}
- private static class TestIntentInstaller implements IntentInstaller<MockInstallableIntent> {
- @Override
- public List<Collection<org.onosproject.net.flow.FlowRuleOperation>> install(MockInstallableIntent intent) {
- FlowRule fr = new MockFlowRule(intent.number().intValue());
- Set<FlowRuleOperation> rules = ImmutableSet.of(
- new FlowRuleOperation(fr, FlowRuleOperation.Type.ADD));
- return Lists.newArrayList(ImmutableSet.of(rules));
- }
-
- @Override
- public List<Collection<FlowRuleOperation>> uninstall(MockInstallableIntent intent) {
- FlowRule fr = new MockFlowRule(intent.number().intValue());
- Set<FlowRuleOperation> rules = ImmutableSet.of(
- new FlowRuleOperation(fr, FlowRuleOperation.Type.REMOVE));
- return Lists.newArrayList(ImmutableSet.of(rules));
- }
-
- @Override
- public List<Collection<FlowRuleOperation>> replace(MockInstallableIntent oldIntent,
- MockInstallableIntent newIntent) {
- FlowRule fr = new MockFlowRule(oldIntent.number().intValue());
- FlowRule fr2 = new MockFlowRule(newIntent.number().intValue());
- Set<FlowRuleOperation> rules = ImmutableSet.of(
- new FlowRuleOperation(fr, FlowRuleOperation.Type.REMOVE),
- new FlowRuleOperation(fr2, FlowRuleOperation.Type.ADD));
- return Lists.newArrayList(ImmutableSet.of(rules));
- }
- }
-
- private static class TestIntentErrorInstaller implements IntentInstaller<MockInstallableIntent> {
- @Override
- public List<Collection<FlowRuleOperation>> install(MockInstallableIntent intent) {
- throw new IntentInstallationException("install() always fails");
- }
-
- @Override
- public List<Collection<FlowRuleOperation>> uninstall(MockInstallableIntent intent) {
- throw new IntentRemovalException("uninstall() always fails");
- }
-
- @Override
- public List<Collection<FlowRuleOperation>> replace(MockInstallableIntent oldIntent,
- MockInstallableIntent newIntent) {
- throw new IntentInstallationException("replace() always fails");
- }
- }
-
/**
* Hamcrest matcher to check that a conllection of Intents contains an
* Intent with the specified Intent Id.
@@ -274,7 +220,6 @@
manager.activate();
service.addListener(listener);
extensionService.registerCompiler(MockIntent.class, compiler);
- extensionService.registerInstaller(MockInstallableIntent.class, installer);
assertTrue("store should be empty",
Sets.newHashSet(service.getIntents()).isEmpty());
@@ -307,7 +252,6 @@
@After
public void tearDown() {
extensionService.unregisterCompiler(MockIntent.class);
- extensionService.unregisterInstaller(MockInstallableIntent.class);
service.removeListener(listener);
manager.deactivate();
// TODO null the other refs?
@@ -428,22 +372,6 @@
}
/**
- * Tests handling of an error that is generated by the intent installer.
- */
- @Test
- public void errorIntentInstallFromInstaller() {
- final TestIntentErrorInstaller errorInstaller = new TestIntentErrorInstaller();
- extensionService.registerInstaller(MockInstallableIntent.class, errorInstaller);
- MockIntent intent = new MockIntent(MockIntent.nextId());
- listener.setLatch(1, Type.INSTALL_REQ);
- listener.setLatch(1, Type.FAILED);
- service.submit(intent);
- listener.await(Type.INSTALL_REQ);
- listener.await(Type.FAILED);
- verifyState();
- }
-
- /**
* Tests handling a future that contains an unresolvable error as a result of
* installing an intent.
*/
@@ -521,9 +449,6 @@
*/
@Test
public void intentWithoutInstaller() {
-
- extensionService.unregisterInstaller(MockInstallableIntent.class);
-
MockIntent intent = new MockIntent(MockIntent.nextId());
listener.setLatch(1, Type.INSTALL_REQ);
listener.setLatch(1, Type.FAILED);
diff --git a/core/net/src/test/java/org/onosproject/net/intent/impl/compiler/LinkCollectionIntentCompilerTest.java b/core/net/src/test/java/org/onosproject/net/intent/impl/compiler/LinkCollectionIntentCompilerTest.java
new file mode 100644
index 0000000..f314fe9
--- /dev/null
+++ b/core/net/src/test/java/org/onosproject/net/intent/impl/compiler/LinkCollectionIntentCompilerTest.java
@@ -0,0 +1,160 @@
+/*
+ * Copyright 2015 Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.onosproject.net.intent.impl.compiler;
+
+import com.google.common.collect.ImmutableSet;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.onosproject.TestApplicationId;
+import org.onosproject.core.ApplicationId;
+import org.onosproject.core.CoreService;
+import org.onosproject.core.IdGenerator;
+import org.onosproject.net.ConnectPoint;
+import org.onosproject.net.DefaultLink;
+import org.onosproject.net.Link;
+import org.onosproject.net.flow.DefaultTrafficSelector;
+import org.onosproject.net.flow.DefaultTrafficTreatment;
+import org.onosproject.net.flow.FlowRule;
+import org.onosproject.net.flow.TrafficSelector;
+import org.onosproject.net.flow.TrafficTreatment;
+import org.onosproject.net.intent.FlowRuleIntent;
+import org.onosproject.net.intent.Intent;
+import org.onosproject.net.intent.IntentExtensionService;
+import org.onosproject.net.intent.LinkCollectionIntent;
+import org.onosproject.net.intent.MockIdGenerator;
+
+import java.util.Collection;
+import java.util.Collections;
+import java.util.List;
+import java.util.Set;
+
+import static org.easymock.EasyMock.createMock;
+import static org.easymock.EasyMock.expect;
+import static org.easymock.EasyMock.replay;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.hasSize;
+import static org.hamcrest.Matchers.is;
+import static org.onosproject.net.Link.Type.DIRECT;
+import static org.onosproject.net.NetTestTools.APP_ID;
+import static org.onosproject.net.NetTestTools.PID;
+import static org.onosproject.net.NetTestTools.connectPoint;
+
+public class LinkCollectionIntentCompilerTest {
+
+ private final ApplicationId appId = new TestApplicationId("test");
+
+ private final ConnectPoint d1p1 = connectPoint("s1", 0);
+ private final ConnectPoint d2p0 = connectPoint("s2", 0);
+ private final ConnectPoint d2p1 = connectPoint("s2", 1);
+ private final ConnectPoint d3p1 = connectPoint("s3", 1);
+ private final ConnectPoint d3p0 = connectPoint("s3", 10);
+ private final ConnectPoint d1p0 = connectPoint("s1", 10);
+
+ private final Set<Link> links = ImmutableSet.of(
+ new DefaultLink(PID, d1p1, d2p0, DIRECT),
+ new DefaultLink(PID, d2p1, d3p1, DIRECT),
+ new DefaultLink(PID, d1p1, d3p1, DIRECT));
+
+ private final TrafficSelector selector = DefaultTrafficSelector.builder().build();
+ private final TrafficTreatment treatment = DefaultTrafficTreatment.builder().build();
+
+ private CoreService coreService;
+ private IntentExtensionService intentExtensionService;
+ private IdGenerator idGenerator = new MockIdGenerator();
+
+ private LinkCollectionIntent intent;
+
+ private LinkCollectionIntentCompiler sut;
+
+ @Before
+ public void setUP() {
+ sut = new LinkCollectionIntentCompiler();
+ coreService = createMock(CoreService.class);
+ expect(coreService.registerApplication("org.onosproject.net.intent"))
+ .andReturn(appId);
+ sut.coreService = coreService;
+
+ Intent.bindIdGenerator(idGenerator);
+
+ intent = LinkCollectionIntent.builder()
+ .appId(APP_ID)
+ .selector(selector)
+ .treatment(treatment)
+ .links(links)
+ .ingressPoints(ImmutableSet.of(d1p1))
+ .egressPoints(ImmutableSet.of(d3p1))
+ .build();
+ intentExtensionService = createMock(IntentExtensionService.class);
+ intentExtensionService.registerCompiler(LinkCollectionIntent.class, sut);
+ intentExtensionService.unregisterCompiler(LinkCollectionIntent.class);
+ sut.intentManager = intentExtensionService;
+
+ replay(coreService, intentExtensionService);
+ }
+
+ @After
+ public void tearDown() {
+ Intent.unbindIdGenerator(idGenerator);
+ }
+
+ @Test
+ public void testCompile() {
+ sut.activate();
+
+ List<Intent> compiled = sut.compile(intent, Collections.emptyList(), Collections.emptySet());
+ assertThat(compiled, hasSize(1));
+
+ Collection<FlowRule> rules = ((FlowRuleIntent) compiled.get(0)).flowRules();
+ assertThat(rules, hasSize(links.size()));
+
+ // if not found, get() raises an exception
+ FlowRule rule1 = rules.stream()
+ .filter(rule -> rule.deviceId().equals(d1p0.deviceId()))
+ .findFirst()
+ .get();
+ assertThat(rule1.selector(), is(
+ DefaultTrafficSelector.builder(intent.selector()).matchInPort(d1p1.port()).build()
+ ));
+ assertThat(rule1.treatment(), is(
+ DefaultTrafficTreatment.builder(intent.treatment()).setOutput(d1p1.port()).build()
+ ));
+
+ FlowRule rule2 = rules.stream()
+ .filter(rule -> rule.deviceId().equals(d2p0.deviceId()))
+ .findFirst()
+ .get();
+ assertThat(rule2.selector(), is(
+ DefaultTrafficSelector.builder(intent.selector()).matchInPort(d2p0.port()).build()
+ ));
+ assertThat(rule2.treatment(), is(
+ DefaultTrafficTreatment.builder().setOutput(d2p1.port()).build()
+ ));
+
+ FlowRule rule3 = rules.stream()
+ .filter(rule -> rule.deviceId().equals(d3p0.deviceId()))
+ .findFirst()
+ .get();
+ assertThat(rule3.selector(), is(
+ DefaultTrafficSelector.builder(intent.selector()).matchInPort(d3p1.port()).build()
+ ));
+ assertThat(rule3.treatment(), is(
+ DefaultTrafficTreatment.builder().setOutput(d3p1.port()).build()
+ ));
+
+ sut.deactivate();
+ }
+}
diff --git a/core/net/src/test/java/org/onosproject/net/intent/impl/compiler/MplsPathIntentCompilerTest.java b/core/net/src/test/java/org/onosproject/net/intent/impl/compiler/MplsPathIntentCompilerTest.java
new file mode 100644
index 0000000..574bc05
--- /dev/null
+++ b/core/net/src/test/java/org/onosproject/net/intent/impl/compiler/MplsPathIntentCompilerTest.java
@@ -0,0 +1,142 @@
+/*
+ * Copyright 2015 Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.onosproject.net.intent.impl.compiler;
+
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.List;
+import java.util.Optional;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.onlab.packet.MplsLabel;
+import org.onosproject.TestApplicationId;
+import org.onosproject.core.ApplicationId;
+import org.onosproject.core.CoreService;
+import org.onosproject.core.IdGenerator;
+import org.onosproject.net.ConnectPoint;
+import org.onosproject.net.DefaultLink;
+import org.onosproject.net.DefaultPath;
+import org.onosproject.net.Link;
+import org.onosproject.net.flow.DefaultTrafficSelector;
+import org.onosproject.net.flow.DefaultTrafficTreatment;
+import org.onosproject.net.flow.FlowRule;
+import org.onosproject.net.flow.TrafficSelector;
+import org.onosproject.net.flow.TrafficTreatment;
+import org.onosproject.net.intent.FlowRuleIntent;
+import org.onosproject.net.intent.Intent;
+import org.onosproject.net.intent.IntentExtensionService;
+import org.onosproject.net.intent.IntentTestsMocks;
+import org.onosproject.net.intent.MockIdGenerator;
+import org.onosproject.net.intent.MplsPathIntent;
+import org.onosproject.store.trivial.impl.SimpleLinkStore;
+
+import static org.easymock.EasyMock.createMock;
+import static org.easymock.EasyMock.expect;
+import static org.easymock.EasyMock.replay;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.hasSize;
+import static org.hamcrest.Matchers.is;
+import static org.onosproject.net.Link.Type.DIRECT;
+import static org.onosproject.net.NetTestTools.APP_ID;
+import static org.onosproject.net.NetTestTools.PID;
+import static org.onosproject.net.NetTestTools.connectPoint;
+
+public class MplsPathIntentCompilerTest {
+
+ private final ApplicationId appId = new TestApplicationId("test");
+
+ private final ConnectPoint d1p1 = connectPoint("s1", 0);
+ private final ConnectPoint d2p0 = connectPoint("s2", 0);
+ private final ConnectPoint d2p1 = connectPoint("s2", 1);
+ private final ConnectPoint d3p1 = connectPoint("s3", 1);
+
+ private final TrafficSelector selector = DefaultTrafficSelector.builder().build();
+ private final TrafficTreatment treatment = DefaultTrafficTreatment.builder().build();
+
+ private final Optional<MplsLabel> ingressLabel =
+ Optional.of(MplsLabel.mplsLabel(10));
+ private final Optional<MplsLabel> egressLabel =
+ Optional.of(MplsLabel.mplsLabel(20));
+
+ private final List<Link> links = Arrays.asList(
+ new DefaultLink(PID, d1p1, d2p0, DIRECT),
+ new DefaultLink(PID, d2p1, d3p1, DIRECT)
+ );
+
+ private IdGenerator idGenerator = new MockIdGenerator();
+
+ private final int hops = links.size() - 1;
+ private MplsPathIntent intent;
+ private MplsPathIntentCompiler sut;
+
+ @Before
+ public void setUp() {
+ sut = new MplsPathIntentCompiler();
+ CoreService coreService = createMock(CoreService.class);
+ expect(coreService.registerApplication("org.onosproject.net.intent"))
+ .andReturn(appId);
+ sut.coreService = coreService;
+ sut.linkStore = new SimpleLinkStore();
+ sut.resourceService = new IntentTestsMocks.MockResourceService();
+
+ Intent.bindIdGenerator(idGenerator);
+
+ intent = MplsPathIntent.builder()
+ .appId(APP_ID)
+ .selector(selector)
+ .treatment(treatment)
+ .path(new DefaultPath(PID, links, hops))
+ .ingressLabel(ingressLabel)
+ .egressLabel(egressLabel)
+ .priority(55)
+ .build();
+
+ IntentExtensionService intentExtensionService = createMock(IntentExtensionService.class);
+ intentExtensionService.registerCompiler(MplsPathIntent.class, sut);
+ intentExtensionService.unregisterCompiler(MplsPathIntent.class);
+ sut.intentExtensionService = intentExtensionService;
+
+ replay(coreService, intentExtensionService);
+ }
+
+ @After
+ public void tearDown() {
+ Intent.unbindIdGenerator(idGenerator);
+ }
+
+ @Test
+ public void testCompile() {
+ sut.activate();
+
+ List<Intent> compiled = sut.compile(intent, Collections.emptyList(), Collections.emptySet());
+ assertThat(compiled, hasSize(1));
+
+ Collection<FlowRule> rules = ((FlowRuleIntent) compiled.get(0)).flowRules();
+ assertThat(rules, hasSize(1));
+
+ FlowRule rule = rules.stream()
+ .filter(x -> x.deviceId().equals(d2p0.deviceId()))
+ .findFirst()
+ .get();
+ assertThat(rule.deviceId(), is(d2p0.deviceId()));
+
+ sut.deactivate();
+
+ }
+}
diff --git a/core/net/src/test/java/org/onosproject/net/intent/impl/compiler/OpticalPathIntentCompilerTest.java b/core/net/src/test/java/org/onosproject/net/intent/impl/compiler/OpticalPathIntentCompilerTest.java
new file mode 100644
index 0000000..08e8e4f
--- /dev/null
+++ b/core/net/src/test/java/org/onosproject/net/intent/impl/compiler/OpticalPathIntentCompilerTest.java
@@ -0,0 +1,137 @@
+/*
+ * Copyright 2015 Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.onosproject.net.intent.impl.compiler;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.onosproject.TestApplicationId;
+import org.onosproject.core.ApplicationId;
+import org.onosproject.core.CoreService;
+import org.onosproject.core.IdGenerator;
+import org.onosproject.net.ConnectPoint;
+import org.onosproject.net.DefaultLink;
+import org.onosproject.net.DefaultPath;
+import org.onosproject.net.Link;
+import org.onosproject.net.flow.DefaultTrafficSelector;
+import org.onosproject.net.flow.DefaultTrafficTreatment;
+import org.onosproject.net.flow.FlowRule;
+import org.onosproject.net.flow.TrafficSelector;
+import org.onosproject.net.flow.TrafficTreatment;
+import org.onosproject.net.intent.FlowRuleIntent;
+import org.onosproject.net.intent.Intent;
+import org.onosproject.net.intent.IntentExtensionService;
+import org.onosproject.net.intent.IntentTestsMocks;
+import org.onosproject.net.intent.MockIdGenerator;
+import org.onosproject.net.intent.OpticalPathIntent;
+import org.onosproject.net.provider.ProviderId;
+
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.List;
+
+import static org.easymock.EasyMock.createMock;
+import static org.easymock.EasyMock.expect;
+import static org.easymock.EasyMock.replay;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.hasSize;
+import static org.onosproject.net.Link.Type.DIRECT;
+import static org.onosproject.net.NetTestTools.PID;
+import static org.onosproject.net.NetTestTools.connectPoint;
+
+public class OpticalPathIntentCompilerTest {
+
+ private CoreService coreService;
+ private IntentExtensionService intentExtensionService;
+ private final IdGenerator idGenerator = new MockIdGenerator();
+ private OpticalPathIntentCompiler sut;
+
+ private final TrafficSelector selector = DefaultTrafficSelector.builder().build();
+ private final TrafficTreatment treatment = DefaultTrafficTreatment.builder().build();
+ private final ApplicationId appId = new TestApplicationId("test");
+ private final ProviderId pid = new ProviderId("of", "test");
+ private final ConnectPoint d1p1 = connectPoint("s1", 0);
+ private final ConnectPoint d2p0 = connectPoint("s2", 0);
+ private final ConnectPoint d2p1 = connectPoint("s2", 1);
+ private final ConnectPoint d3p1 = connectPoint("s3", 1);
+ private final ConnectPoint d3p0 = connectPoint("s3", 10);
+ private final ConnectPoint d1p0 = connectPoint("s1", 10);
+
+ private final List<Link> links = Arrays.asList(
+ new DefaultLink(PID, d1p1, d2p0, DIRECT),
+ new DefaultLink(PID, d2p1, d3p1, DIRECT)
+ );
+ private final int hops = links.size() + 1;
+ private OpticalPathIntent intent;
+
+ @Before
+ public void setUp() {
+ sut = new OpticalPathIntentCompiler();
+ coreService = createMock(CoreService.class);
+ expect(coreService.registerApplication("org.onosproject.net.intent"))
+ .andReturn(appId);
+ sut.coreService = coreService;
+
+ Intent.bindIdGenerator(idGenerator);
+
+ intent = OpticalPathIntent.builder()
+ .appId(appId)
+ .src(d1p1)
+ .dst(d3p1)
+ .path(new DefaultPath(PID, links, hops))
+ .build();
+ intentExtensionService = createMock(IntentExtensionService.class);
+ intentExtensionService.registerCompiler(OpticalPathIntent.class, sut);
+ intentExtensionService.unregisterCompiler(OpticalPathIntent.class);
+ sut.intentManager = intentExtensionService;
+ sut.resourceService = new IntentTestsMocks.MockResourceService();
+
+ replay(coreService, intentExtensionService);
+ }
+
+ @After
+ public void tearDown() {
+ Intent.unbindIdGenerator(idGenerator);
+ }
+
+ @Test
+ public void testCompiler() {
+ sut.activate();
+
+ List<Intent> compiled = sut.compile(intent, Collections.emptyList(), Collections.emptySet());
+ assertThat(compiled, hasSize(1));
+
+ Collection<FlowRule> rules = ((FlowRuleIntent) compiled.get(0)).flowRules();
+ rules.stream()
+ .filter(x -> x.deviceId().equals(d1p1.deviceId()))
+ .findFirst()
+ .get();
+
+ rules.stream()
+ .filter(x -> x.deviceId().equals(d2p1.deviceId()))
+ .findFirst()
+ .get();
+
+ rules.stream()
+ .filter(x -> x.deviceId().equals(d3p1.deviceId()))
+ .findFirst()
+ .get();
+
+ sut.deactivate();
+ }
+
+}
diff --git a/core/net/src/test/java/org/onosproject/net/intent/impl/compiler/PathIntentCompilerTest.java b/core/net/src/test/java/org/onosproject/net/intent/impl/compiler/PathIntentCompilerTest.java
new file mode 100644
index 0000000..058b607
--- /dev/null
+++ b/core/net/src/test/java/org/onosproject/net/intent/impl/compiler/PathIntentCompilerTest.java
@@ -0,0 +1,167 @@
+/*
+ * Copyright 2015 Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.onosproject.net.intent.impl.compiler;
+
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.List;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.onosproject.TestApplicationId;
+import org.onosproject.core.ApplicationId;
+import org.onosproject.core.CoreService;
+import org.onosproject.core.IdGenerator;
+import org.onosproject.net.ConnectPoint;
+import org.onosproject.net.DefaultLink;
+import org.onosproject.net.DefaultPath;
+import org.onosproject.net.Link;
+import org.onosproject.net.flow.DefaultTrafficSelector;
+import org.onosproject.net.flow.DefaultTrafficTreatment;
+import org.onosproject.net.flow.FlowRule;
+import org.onosproject.net.flow.TrafficSelector;
+import org.onosproject.net.flow.TrafficTreatment;
+import org.onosproject.net.intent.FlowRuleIntent;
+import org.onosproject.net.intent.Intent;
+import org.onosproject.net.intent.IntentExtensionService;
+import org.onosproject.net.intent.MockIdGenerator;
+import org.onosproject.net.intent.PathIntent;
+import org.onosproject.net.provider.ProviderId;
+
+import static org.easymock.EasyMock.createMock;
+import static org.easymock.EasyMock.expect;
+import static org.easymock.EasyMock.replay;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.hasSize;
+import static org.hamcrest.Matchers.is;
+import static org.onosproject.net.DefaultEdgeLink.createEdgeLink;
+import static org.onosproject.net.Link.Type.DIRECT;
+import static org.onosproject.net.NetTestTools.APP_ID;
+import static org.onosproject.net.NetTestTools.PID;
+import static org.onosproject.net.NetTestTools.connectPoint;
+
+/**
+ * Unit tests for PathIntentCompiler.
+ */
+public class PathIntentCompilerTest {
+
+ private CoreService coreService;
+ private IntentExtensionService intentExtensionService;
+ private IdGenerator idGenerator = new MockIdGenerator();
+ private PathIntentCompiler sut;
+
+ private final TrafficSelector selector = DefaultTrafficSelector.builder().build();
+ private final TrafficTreatment treatment = DefaultTrafficTreatment.builder().build();
+ private final ApplicationId appId = new TestApplicationId("test");
+ private final ProviderId pid = new ProviderId("of", "test");
+ private final ConnectPoint d1p1 = connectPoint("s1", 0);
+ private final ConnectPoint d2p0 = connectPoint("s2", 0);
+ private final ConnectPoint d2p1 = connectPoint("s2", 1);
+ private final ConnectPoint d3p1 = connectPoint("s3", 1);
+ private final ConnectPoint d3p0 = connectPoint("s3", 10);
+ private final ConnectPoint d1p0 = connectPoint("s1", 10);
+
+ private final List<Link> links = Arrays.asList(
+ createEdgeLink(d1p0, true),
+ new DefaultLink(PID, d1p1, d2p0, DIRECT),
+ new DefaultLink(PID, d2p1, d3p1, DIRECT),
+ createEdgeLink(d3p0, false)
+ );
+ private final int hops = links.size() - 1;
+ private PathIntent intent;
+
+ /**
+ * Configures objects used in all the test cases.
+ */
+ @Before
+ public void setUp() {
+ sut = new PathIntentCompiler();
+ coreService = createMock(CoreService.class);
+ expect(coreService.registerApplication("org.onosproject.net.intent"))
+ .andReturn(appId);
+ sut.coreService = coreService;
+
+ Intent.bindIdGenerator(idGenerator);
+
+ intent = PathIntent.builder()
+ .appId(APP_ID)
+ .selector(selector)
+ .treatment(treatment)
+ .path(new DefaultPath(pid, links, hops))
+ .build();
+ intentExtensionService = createMock(IntentExtensionService.class);
+ intentExtensionService.registerCompiler(PathIntent.class, sut);
+ intentExtensionService.unregisterCompiler(PathIntent.class);
+ sut.intentManager = intentExtensionService;
+
+ replay(coreService, intentExtensionService);
+ }
+
+ /**
+ * Tears down objects used in all the test cases.
+ */
+ @After
+ public void tearDown() {
+ Intent.unbindIdGenerator(idGenerator);
+ }
+
+ /**
+ * Tests the compilation behavior of the path intent compiler.
+ */
+ @Test
+ public void testCompile() {
+ sut.activate();
+
+ List<Intent> compiled = sut.compile(intent, Collections.emptyList(), Collections.emptySet());
+ assertThat(compiled, hasSize(1));
+
+ Collection<FlowRule> rules = ((FlowRuleIntent) compiled.get(0)).flowRules();
+
+ FlowRule rule1 = rules.stream()
+ .filter(x -> x.deviceId().equals(d1p0.deviceId()))
+ .findFirst()
+ .get();
+ assertThat(rule1.deviceId(), is(d1p0.deviceId()));
+ assertThat(rule1.selector(),
+ is(DefaultTrafficSelector.builder(selector).matchInPort(d1p0.port()).build()));
+ assertThat(rule1.treatment(),
+ is(DefaultTrafficTreatment.builder().setOutput(d1p1.port()).build()));
+
+ FlowRule rule2 = rules.stream()
+ .filter(x -> x.deviceId().equals(d2p0.deviceId()))
+ .findFirst()
+ .get();
+ assertThat(rule2.deviceId(), is(d2p0.deviceId()));
+ assertThat(rule2.selector(),
+ is(DefaultTrafficSelector.builder(selector).matchInPort(d2p0.port()).build()));
+ assertThat(rule2.treatment(),
+ is(DefaultTrafficTreatment.builder().setOutput(d2p1.port()).build()));
+
+ FlowRule rule3 = rules.stream()
+ .filter(x -> x.deviceId().equals(d3p0.deviceId()))
+ .findFirst()
+ .get();
+ assertThat(rule3.deviceId(), is(d3p1.deviceId()));
+ assertThat(rule3.selector(),
+ is(DefaultTrafficSelector.builder(selector).matchInPort(d3p1.port()).build()));
+ assertThat(rule3.treatment(),
+ is(DefaultTrafficTreatment.builder(treatment).setOutput(d3p0.port()).build()));
+
+ sut.deactivate();
+ }
+}
diff --git a/core/net/src/test/java/org/onosproject/net/intent/impl/installer/IntentInstallerTest.java b/core/net/src/test/java/org/onosproject/net/intent/impl/installer/IntentInstallerTest.java
deleted file mode 100644
index e6c723c..0000000
--- a/core/net/src/test/java/org/onosproject/net/intent/impl/installer/IntentInstallerTest.java
+++ /dev/null
@@ -1,135 +0,0 @@
-/*
- * Copyright 2015 Open Networking Laboratory
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.onosproject.net.intent.impl.installer;
-
-import org.junit.After;
-import org.junit.Before;
-import org.onosproject.core.ApplicationId;
-import org.onosproject.core.CoreService;
-import org.onosproject.core.CoreServiceAdapter;
-import org.onosproject.core.IdGenerator;
-import org.onosproject.net.ConnectPoint;
-import org.onosproject.net.DeviceId;
-import org.onosproject.net.flow.FlowRuleOperation;
-import org.onosproject.net.intent.FakeIntentManager;
-import org.onosproject.net.intent.Intent;
-import org.onosproject.net.intent.IntentInstaller;
-import org.onosproject.net.intent.IntentTestsMocks;
-import org.onosproject.net.intent.MockIdGenerator;
-
-import static org.hamcrest.MatcherAssert.assertThat;
-import static org.hamcrest.Matchers.equalTo;
-import static org.hamcrest.Matchers.is;
-import static org.onosproject.net.NetTestTools.APP_ID;
-import static org.onosproject.net.NetTestTools.connectPoint;
-
-/**
- * Base class for intent installer tests.
- */
-public class IntentInstallerTest {
-
- /**
- * Mock for core service.
- */
- static class TestCoreService extends CoreServiceAdapter {
-
- String registeredId = "";
-
- @Override
- public ApplicationId registerApplication(String identifier) {
- registeredId = identifier;
- return APP_ID;
- }
- }
-
- /**
- * Mock for intent manager service. Checks that the PathIntent
- * installer installs and uninstalls properly.
- */
- static class MockIntentManager extends FakeIntentManager {
-
- boolean installerRegistered = false;
- final Class expectedClass;
-
- private MockIntentManager() {
- expectedClass = null;
- }
-
- MockIntentManager(Class expectedInstaller) {
- this.expectedClass = expectedInstaller;
- }
-
- @Override
- public <T extends Intent> void registerInstaller(
- Class<T> cls,
- IntentInstaller<T> installer) {
- assertThat(cls, equalTo(expectedClass));
- installerRegistered = true;
- }
-
- @Override
- public <T extends Intent> void unregisterInstaller(Class<T> cls) {
- assertThat(cls, equalTo(expectedClass));
- assertThat(installerRegistered, is(true));
- }
-
- }
-
- CoreService testCoreService;
- IdGenerator idGenerator = new MockIdGenerator();
- IntentInstaller installer;
-
- final IntentTestsMocks.MockSelector selector = new IntentTestsMocks.MockSelector();
- final IntentTestsMocks.MockTreatment treatment = new IntentTestsMocks.MockTreatment();
- final ConnectPoint d1p1 = connectPoint("s1", 0);
- final ConnectPoint d2p0 = connectPoint("s2", 0);
- final ConnectPoint d2p1 = connectPoint("s2", 1);
- final ConnectPoint d3p1 = connectPoint("s3", 1);
- final ConnectPoint d3p0 = connectPoint("s3", 10);
- final ConnectPoint d1p0 = connectPoint("s1", 10);
-
- /**
- * Configures objects used in all the test cases.
- */
- @Before
- public void setUp() {
- testCoreService = new TestCoreService();
- Intent.bindIdGenerator(idGenerator);
- }
-
- /**
- * Tears down objects used in all the test cases.
- */
- @After
- public void tearDown() {
- Intent.unbindIdGenerator(idGenerator);
- }
-
- /**
- * Checks that a flow operation contains the correct values.
- *
- * @param op flow rule operation to check
- * @param type type the flow rule operation should have
- * @param deviceId device id the flow rule operation should have
- */
- void checkFlowOperation(FlowRuleOperation op,
- FlowRuleOperation.Type type,
- DeviceId deviceId) {
- assertThat(op.type(), is(type));
- assertThat(op.rule().deviceId(), equalTo(deviceId));
- }
-
-}
diff --git a/core/net/src/test/java/org/onosproject/net/intent/impl/installer/LinkCollectionIntentInstallerTest.java b/core/net/src/test/java/org/onosproject/net/intent/impl/installer/LinkCollectionIntentInstallerTest.java
deleted file mode 100644
index 00ebedf..0000000
--- a/core/net/src/test/java/org/onosproject/net/intent/impl/installer/LinkCollectionIntentInstallerTest.java
+++ /dev/null
@@ -1,147 +0,0 @@
-/*
- * Copyright 2015 Open Networking Laboratory
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.onosproject.net.intent.impl.installer;
-
-import java.util.Collection;
-import java.util.List;
-import java.util.Set;
-
-import org.junit.Before;
-import org.junit.Test;
-import org.onosproject.net.DefaultLink;
-import org.onosproject.net.DeviceId;
-import org.onosproject.net.Link;
-import org.onosproject.net.flow.FlowRuleOperation;
-import org.onosproject.net.intent.LinkCollectionIntent;
-
-import com.google.common.collect.ImmutableSet;
-
-import static org.hamcrest.MatcherAssert.assertThat;
-import static org.hamcrest.Matchers.hasSize;
-import static org.hamcrest.Matchers.notNullValue;
-import static org.onosproject.net.Link.Type.DIRECT;
-import static org.onosproject.net.NetTestTools.APP_ID;
-import static org.onosproject.net.NetTestTools.PID;
-
-public class LinkCollectionIntentInstallerTest extends IntentInstallerTest {
-
- LinkCollectionIntentInstaller installer;
-
- private final Set<Link> links = ImmutableSet.of(
- new DefaultLink(PID, d1p1, d2p0, DIRECT),
- new DefaultLink(PID, d2p1, d3p1, DIRECT),
- new DefaultLink(PID, d1p1, d3p1, DIRECT));
-
- private LinkCollectionIntent intent;
-
- /**
- * Configures objects used in all the test cases.
- */
- @Before
- public void localSetUp() {
- installer = new LinkCollectionIntentInstaller();
- installer.coreService = testCoreService;
- installer.intentManager =
- new IntentInstallerTest.MockIntentManager(LinkCollectionIntent.class);
- intent = LinkCollectionIntent.builder()
- .appId(APP_ID)
- .selector(selector)
- .treatment(treatment)
- .links(links)
- .ingressPoints(ImmutableSet.of(d1p1))
- .egressPoints(ImmutableSet.of(d3p1))
- .build();
- }
-
- private FlowRuleOperation findOperation(Collection<FlowRuleOperation> ops,
- DeviceId deviceId) {
- for (FlowRuleOperation op : ops) {
- if (op.rule().deviceId().equals(deviceId)) {
- return op;
- }
- }
- return null;
- }
-
- /**
- * Tests activation and deactivation of the installer.
- */
- @Test
- public void activateDeactivate() {
- installer.activate();
- installer.deactivate();
- }
-
- /**
- * Tests installation operation of the path intent installer.
- */
- @Test
- public void install() {
- installer.activate();
-
- List<Collection<FlowRuleOperation>> operations =
- installer.install(intent);
- assertThat(operations, notNullValue());
- assertThat(operations, hasSize(1));
-
- Collection<FlowRuleOperation> flowRuleOpsCollection = operations.get(0);
- assertThat(flowRuleOpsCollection, hasSize(links.size()));
-
- FlowRuleOperation op0 = findOperation(flowRuleOpsCollection,
- d1p0.deviceId());
- checkFlowOperation(op0, FlowRuleOperation.Type.ADD, d1p0.deviceId());
-
- FlowRuleOperation op1 = findOperation(flowRuleOpsCollection,
- d2p0.deviceId());
- checkFlowOperation(op1, FlowRuleOperation.Type.ADD, d2p0.deviceId());
-
- FlowRuleOperation op2 = findOperation(flowRuleOpsCollection,
- d3p0.deviceId());
- checkFlowOperation(op2, FlowRuleOperation.Type.ADD, d3p0.deviceId());
-
- installer.deactivate();
- }
-
- /**
- * Checks the uninstall operation of the path intent installer.
- */
- @Test
- public void uninstall() {
- installer.activate();
-
- List<Collection<FlowRuleOperation>> operations =
- installer.uninstall(intent);
- assertThat(operations, notNullValue());
- assertThat(operations, hasSize(1));
-
- Collection<FlowRuleOperation> flowRuleOpsCollection = operations.get(0);
- assertThat(flowRuleOpsCollection, hasSize(links.size()));
-
- FlowRuleOperation op0 = findOperation(flowRuleOpsCollection,
- d1p0.deviceId());
- checkFlowOperation(op0, FlowRuleOperation.Type.REMOVE, d1p0.deviceId());
-
- FlowRuleOperation op1 = findOperation(flowRuleOpsCollection,
- d2p0.deviceId());
- checkFlowOperation(op1, FlowRuleOperation.Type.REMOVE, d2p0.deviceId());
-
- FlowRuleOperation op2 = findOperation(flowRuleOpsCollection,
- d3p0.deviceId());
- checkFlowOperation(op2, FlowRuleOperation.Type.REMOVE, d3p0.deviceId());
-
- installer.deactivate();
- }
-}
diff --git a/core/net/src/test/java/org/onosproject/net/intent/impl/installer/MplsPathIntentInstallerTest.java b/core/net/src/test/java/org/onosproject/net/intent/impl/installer/MplsPathIntentInstallerTest.java
deleted file mode 100644
index e88947c..0000000
--- a/core/net/src/test/java/org/onosproject/net/intent/impl/installer/MplsPathIntentInstallerTest.java
+++ /dev/null
@@ -1,136 +0,0 @@
-/*
- * Copyright 2015 Open Networking Laboratory
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.onosproject.net.intent.impl.installer;
-
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.List;
-import java.util.Optional;
-
-import org.junit.Before;
-import org.junit.Test;
-import org.onlab.packet.MplsLabel;
-import org.onosproject.net.DefaultLink;
-import org.onosproject.net.DefaultPath;
-import org.onosproject.net.Link;
-import org.onosproject.net.flow.FlowRuleOperation;
-import org.onosproject.net.intent.IntentTestsMocks;
-import org.onosproject.net.intent.MplsPathIntent;
-import org.onosproject.store.trivial.impl.SimpleLinkStore;
-
-import static org.hamcrest.MatcherAssert.assertThat;
-import static org.hamcrest.Matchers.hasSize;
-import static org.hamcrest.Matchers.notNullValue;
-import static org.onosproject.net.Link.Type.DIRECT;
-import static org.onosproject.net.NetTestTools.APP_ID;
-import static org.onosproject.net.NetTestTools.PID;
-
-/**
- * Unit tests for path intent installer.
- */
-public class MplsPathIntentInstallerTest extends IntentInstallerTest {
-
- MplsPathIntentInstaller installer;
-
- private final Optional<MplsLabel> ingressLabel =
- Optional.of(MplsLabel.mplsLabel(10));
- private final Optional<MplsLabel> egressLabel =
- Optional.of(MplsLabel.mplsLabel(20));
-
- private final List<Link> links = Arrays.asList(
- new DefaultLink(PID, d1p1, d2p0, DIRECT),
- new DefaultLink(PID, d2p1, d3p1, DIRECT)
- );
- private final int hops = links.size() - 1;
- private MplsPathIntent intent;
-
- /**
- * Configures objects used in all the test cases.
- */
- @Before
- public void localSetUp() {
- installer = new MplsPathIntentInstaller();
- installer.coreService = testCoreService;
- installer.intentManager = new MockIntentManager(MplsPathIntent.class);
- installer.linkStore = new SimpleLinkStore();
- installer.resourceService = new IntentTestsMocks.MockResourceService();
-
- intent = MplsPathIntent.builder()
- .appId(APP_ID)
- .selector(selector)
- .treatment(treatment)
- .path(new DefaultPath(PID, links, hops))
- .ingressLabel(ingressLabel)
- .egressLabel(egressLabel)
- .priority(55)
- .build();
- }
-
- /**
- * Tests activation and deactivation of the installer.
- */
- @Test
- public void activateDeactivate() {
- installer.activate();
- installer.deactivate();
- }
-
- /**
- * Tests installation operation of the MPLS path intent installer.
- */
- @Test
- public void install() {
- installer.activate();
-
- List<Collection<FlowRuleOperation>> operations =
- installer.install(intent);
- assertThat(operations, notNullValue());
- assertThat(operations, hasSize(1));
-
- Collection<FlowRuleOperation> flowRuleOpsCollection = operations.get(0);
- assertThat(flowRuleOpsCollection, hasSize(hops));
- FlowRuleOperation[] flowRuleOps =
- flowRuleOpsCollection.toArray(new FlowRuleOperation[hops]);
-
- FlowRuleOperation op0 = flowRuleOps[0];
- checkFlowOperation(op0, FlowRuleOperation.Type.ADD, d2p0.deviceId());
-
- installer.deactivate();
- }
-
- /**
- * Checks the uninstall operation of the path intent installer.
- */
- @Test
- public void uninstall() {
- installer.activate();
-
- List<Collection<FlowRuleOperation>> operations =
- installer.uninstall(intent);
- assertThat(operations, notNullValue());
- assertThat(operations, hasSize(1));
-
- Collection<FlowRuleOperation> flowRuleOpsCollection = operations.get(0);
- assertThat(flowRuleOpsCollection, hasSize(hops));
- FlowRuleOperation[] flowRuleOps =
- flowRuleOpsCollection.toArray(new FlowRuleOperation[hops]);
-
- FlowRuleOperation op0 = flowRuleOps[0];
- checkFlowOperation(op0, FlowRuleOperation.Type.REMOVE, d2p0.deviceId());
-
- installer.deactivate();
- }
-}
diff --git a/core/net/src/test/java/org/onosproject/net/intent/impl/installer/OpticalPathIntentInstallerTest.java b/core/net/src/test/java/org/onosproject/net/intent/impl/installer/OpticalPathIntentInstallerTest.java
deleted file mode 100644
index 4aad8a5..0000000
--- a/core/net/src/test/java/org/onosproject/net/intent/impl/installer/OpticalPathIntentInstallerTest.java
+++ /dev/null
@@ -1,134 +0,0 @@
-/*
- * Copyright 2015 Open Networking Laboratory
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.onosproject.net.intent.impl.installer;
-
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.List;
-
-import org.junit.Before;
-import org.junit.Test;
-import org.onosproject.net.DefaultLink;
-import org.onosproject.net.DefaultPath;
-import org.onosproject.net.Link;
-import org.onosproject.net.flow.FlowRuleOperation;
-import org.onosproject.net.intent.IntentTestsMocks;
-import org.onosproject.net.intent.OpticalPathIntent;
-
-import static org.hamcrest.MatcherAssert.assertThat;
-import static org.hamcrest.Matchers.hasSize;
-import static org.hamcrest.Matchers.notNullValue;
-import static org.onosproject.net.Link.Type.DIRECT;
-import static org.onosproject.net.NetTestTools.APP_ID;
-import static org.onosproject.net.NetTestTools.PID;
-
-public class OpticalPathIntentInstallerTest extends IntentInstallerTest {
-
- OpticalPathIntentInstaller installer;
-
- private final List<Link> links = Arrays.asList(
- new DefaultLink(PID, d1p1, d2p0, DIRECT),
- new DefaultLink(PID, d2p1, d3p1, DIRECT)
- );
- private final int hops = links.size() + 1;
- private OpticalPathIntent intent;
-
- /**
- * Configures objects used in all the test cases.
- */
- @Before
- public void localSetUp() {
- installer = new OpticalPathIntentInstaller();
- installer.coreService = testCoreService;
- installer.intentManager =
- new IntentInstallerTest.MockIntentManager(OpticalPathIntent.class);
- installer.resourceService = new IntentTestsMocks.MockResourceService();
-
- intent = OpticalPathIntent.builder().appId(APP_ID)
- .src(d1p1)
- .dst(d3p1)
- .path(new DefaultPath(PID, links, hops))
- .build();
- }
-
- /**
- * Tests activation and deactivation of the installer.
- */
- @Test
- public void activateDeactivate() {
- installer.activate();
- installer.deactivate();
- }
-
- /**
- * Tests installation operation of the optical path intent installer.
- */
- @Test
- public void install() {
- installer.activate();
-
- List<Collection<FlowRuleOperation>> operations =
- installer.install(intent);
- assertThat(operations, notNullValue());
- assertThat(operations, hasSize(1));
-
- Collection<FlowRuleOperation> flowRuleOpsCollection = operations.get(0);
- assertThat(flowRuleOpsCollection, hasSize(hops));
- FlowRuleOperation[] flowRuleOps =
- flowRuleOpsCollection.toArray(new FlowRuleOperation[hops]);
-
- FlowRuleOperation op0 = flowRuleOps[0];
- checkFlowOperation(op0, FlowRuleOperation.Type.ADD, d1p1.deviceId());
-
- FlowRuleOperation op1 = flowRuleOps[1];
- checkFlowOperation(op1, FlowRuleOperation.Type.ADD, d2p1.deviceId());
-
- FlowRuleOperation op2 = flowRuleOps[2];
- checkFlowOperation(op2, FlowRuleOperation.Type.ADD, d3p1.deviceId());
-
- installer.deactivate();
- }
-
- /**
- * Checks the uninstall operation of the optical path intent installer.
- */
- @Test
- public void uninstall() {
- installer.activate();
-
- List<Collection<FlowRuleOperation>> operations =
- installer.uninstall(intent);
- assertThat(operations, notNullValue());
- assertThat(operations, hasSize(1));
-
- Collection<FlowRuleOperation> flowRuleOpsCollection = operations.get(0);
- assertThat(flowRuleOpsCollection, hasSize(hops));
- FlowRuleOperation[] flowRuleOps =
- flowRuleOpsCollection.toArray(new FlowRuleOperation[hops]);
-
- FlowRuleOperation op0 = flowRuleOps[0];
- checkFlowOperation(op0, FlowRuleOperation.Type.REMOVE, d1p1.deviceId());
-
- FlowRuleOperation op1 = flowRuleOps[1];
- checkFlowOperation(op1, FlowRuleOperation.Type.REMOVE, d2p1.deviceId());
-
- FlowRuleOperation op2 = flowRuleOps[2];
- checkFlowOperation(op2, FlowRuleOperation.Type.REMOVE, d3p1.deviceId());
-
- installer.deactivate();
- }
-
-}
diff --git a/core/net/src/test/java/org/onosproject/net/intent/impl/installer/PathConstraintCalculationTest.java b/core/net/src/test/java/org/onosproject/net/intent/impl/installer/PathConstraintCalculationTest.java
deleted file mode 100644
index 6e7606d..0000000
--- a/core/net/src/test/java/org/onosproject/net/intent/impl/installer/PathConstraintCalculationTest.java
+++ /dev/null
@@ -1,198 +0,0 @@
-/*
- * Copyright 2014 Open Networking Laboratory
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.onosproject.net.intent.impl.installer;
-
-import org.junit.Before;
-import org.junit.Test;
-import org.onosproject.net.ConnectPoint;
-import org.onosproject.net.DefaultLink;
-import org.onosproject.net.DefaultPath;
-import org.onosproject.net.Link;
-import org.onosproject.net.flow.FlowRuleOperation;
-import org.onosproject.net.intent.AbstractIntentTest;
-import org.onosproject.net.intent.Constraint;
-import org.onosproject.net.intent.IntentTestsMocks;
-import org.onosproject.net.intent.PathIntent;
-import org.onosproject.net.intent.constraint.BandwidthConstraint;
-import org.onosproject.net.intent.constraint.LambdaConstraint;
-import org.onosproject.net.resource.Bandwidth;
-import org.onosproject.net.resource.Lambda;
-
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.List;
-
-import static org.hamcrest.MatcherAssert.assertThat;
-import static org.hamcrest.Matchers.hasSize;
-import static org.hamcrest.Matchers.instanceOf;
-import static org.hamcrest.Matchers.notNullValue;
-import static org.junit.Assert.fail;
-import static org.onosproject.net.DefaultEdgeLink.createEdgeLink;
-import static org.onosproject.net.Link.Type.DIRECT;
-import static org.onosproject.net.NetTestTools.APP_ID;
-import static org.onosproject.net.NetTestTools.PID;
-import static org.onosproject.net.NetTestTools.connectPoint;
-import static org.onosproject.net.intent.IntentTestsMocks.MockResourceService.makeBandwidthResourceService;
-import static org.onosproject.net.intent.IntentTestsMocks.MockResourceService.makeLambdaResourceService;
-
-/**
- * Unit tests for calculating paths for intents with constraints.
- */
-
-public class PathConstraintCalculationTest extends AbstractIntentTest {
-
- private final IntentTestsMocks.MockSelector selector = new IntentTestsMocks.MockSelector();
- private final IntentTestsMocks.MockTreatment treatment = new IntentTestsMocks.MockTreatment();
- private final ConnectPoint d1p1 = connectPoint("s1", 0);
- private final ConnectPoint d2p0 = connectPoint("s2", 0);
- private final ConnectPoint d2p1 = connectPoint("s2", 1);
- private final ConnectPoint d3p1 = connectPoint("s3", 1);
- private final ConnectPoint d3p0 = connectPoint("s3", 10);
- private final ConnectPoint d1p0 = connectPoint("s1", 10);
-
- private PathIntentInstaller sut;
-
- @Before
- public void setUpIntentInstaller() {
- sut = new PathIntentInstaller();
- sut.appId = APP_ID;
- }
-
- private PathIntent createPathIntent(List<Link> links, List<Constraint> constraints) {
- int hops = links.size() - 1;
- return PathIntent.builder()
- .appId(APP_ID)
- .selector(selector)
- .treatment(treatment)
- .path(new DefaultPath(PID, links, hops))
- .constraints(constraints)
- .priority(333)
- .build();
- }
-
- /**
- * Tests that installation of bandwidth constrained path intents are
- * successful.
- */
- @Test
- public void testInstallBandwidthConstrainedIntentSuccess() {
-
- final Constraint constraint = new BandwidthConstraint(Bandwidth.bps(100.0));
-
- List<Link> links = Arrays.asList(
- createEdgeLink(d1p0, true),
- new DefaultLink(PID, d1p1, d2p0, DIRECT),
- new DefaultLink(PID, d2p1, d3p1, DIRECT),
- createEdgeLink(d3p0, false)
- );
- PathIntent installable = createPathIntent(links, Arrays.asList(constraint));
-
- sut.resourceService = makeBandwidthResourceService(1000.0);
-
- final List<Collection<FlowRuleOperation>> flowOperations = sut.install(installable);
-
- assertThat(flowOperations, notNullValue());
- assertThat(flowOperations, hasSize(1));
- }
-
- /**
- * Tests that installation of bandwidth constrained path intents fail
- * if there are no available resources.
- */
- @Test
- public void testInstallBandwidthConstrainedIntentFailure() {
-
- final Constraint constraint = new BandwidthConstraint(Bandwidth.bps(100.0));
-
- List<Link> links = Arrays.asList(
- createEdgeLink(d1p0, true),
- new DefaultLink(PID, d1p1, d2p0, DIRECT),
- new DefaultLink(PID, d2p1, d3p1, DIRECT),
- createEdgeLink(d3p0, false)
- );
- PathIntent installable = createPathIntent(links, Arrays.asList(constraint));
-
- // Make it look like the available bandwidth was consumed
- final IntentTestsMocks.MockResourceService resourceService = makeBandwidthResourceService(1000.0);
- resourceService.setAvailableBandwidth(1.0);
- sut.resourceService = resourceService;
-
- try {
- sut.install(installable);
- fail("Bandwidth request with no available bandwidth did not fail.");
- } catch (IntentTestsMocks.MockedAllocationFailure failure) {
- assertThat(failure,
- instanceOf(IntentTestsMocks.MockedAllocationFailure.class));
- }
- }
-
- /**
- * Tests that installation of lambda constrained path intents are
- * successful.
- */
- @Test
- public void testInstallLambdaConstrainedIntentSuccess() {
-
- final Constraint constraint = new LambdaConstraint(Lambda.valueOf(1));
-
- List<Link> links = Arrays.asList(
- createEdgeLink(d1p0, true),
- new DefaultLink(PID, d1p1, d2p0, DIRECT),
- new DefaultLink(PID, d2p1, d3p1, DIRECT),
- createEdgeLink(d3p0, false)
- );
- PathIntent installable = createPathIntent(links, Arrays.asList(constraint));
-
- sut.resourceService = makeLambdaResourceService(1);
-
- final List<Collection<FlowRuleOperation>> flowOperations = sut.install(installable);
-
- assertThat(flowOperations, notNullValue());
- assertThat(flowOperations, hasSize(1));
- }
-
- /**
- * Tests that installation of lambda constrained path intents fail
- * if there are no available resources.
- */
- @Test
- public void testInstallLambdaConstrainedIntentFailure() {
-
- final Constraint constraint = new LambdaConstraint(Lambda.valueOf(1));
-
- List<Link> links = Arrays.asList(
- createEdgeLink(d1p0, true),
- new DefaultLink(PID, d1p1, d2p0, DIRECT),
- new DefaultLink(PID, d2p1, d3p1, DIRECT),
- createEdgeLink(d3p0, false)
- );
- PathIntent installable = createPathIntent(links, Arrays.asList(constraint));
-
- // Make it look like the available lambda was consumed
- final IntentTestsMocks.MockResourceService resourceService = makeLambdaResourceService(1);
- resourceService.setAvailableLambda(0);
- sut.resourceService = resourceService;
-
- try {
- sut.install(installable);
- fail("Lambda request with no available lambda did not fail.");
- } catch (IntentTestsMocks.MockedAllocationFailure failure) {
- assertThat(failure,
- instanceOf(IntentTestsMocks.MockedAllocationFailure.class));
- }
- }
-
-}
diff --git a/core/net/src/test/java/org/onosproject/net/intent/impl/installer/PathIntentInstallerTest.java b/core/net/src/test/java/org/onosproject/net/intent/impl/installer/PathIntentInstallerTest.java
deleted file mode 100644
index 9bbd16c..0000000
--- a/core/net/src/test/java/org/onosproject/net/intent/impl/installer/PathIntentInstallerTest.java
+++ /dev/null
@@ -1,137 +0,0 @@
-/*
- * Copyright 2015 Open Networking Laboratory
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.onosproject.net.intent.impl.installer;
-
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.List;
-
-import org.junit.Before;
-import org.junit.Test;
-import org.onosproject.net.DefaultLink;
-import org.onosproject.net.DefaultPath;
-import org.onosproject.net.Link;
-import org.onosproject.net.flow.FlowRuleOperation;
-import org.onosproject.net.intent.PathIntent;
-
-import static org.hamcrest.MatcherAssert.assertThat;
-import static org.hamcrest.Matchers.hasSize;
-import static org.hamcrest.Matchers.notNullValue;
-import static org.onosproject.net.DefaultEdgeLink.createEdgeLink;
-import static org.onosproject.net.Link.Type.DIRECT;
-import static org.onosproject.net.NetTestTools.APP_ID;
-import static org.onosproject.net.NetTestTools.PID;
-
-/**
- * Unit tests for path intent installer.
- */
-public class PathIntentInstallerTest extends IntentInstallerTest {
-
- PathIntentInstaller installer;
-
- private final List<Link> links = Arrays.asList(
- createEdgeLink(d1p0, true),
- new DefaultLink(PID, d1p1, d2p0, DIRECT),
- new DefaultLink(PID, d2p1, d3p1, DIRECT),
- createEdgeLink(d3p0, false)
- );
- private final int hops = links.size() - 1;
- private PathIntent intent;
-
- /**
- * Configures objects used in all the test cases.
- */
- @Before
- public void localSetUp() {
- installer = new PathIntentInstaller();
- installer.coreService = testCoreService;
- installer.intentManager = new MockIntentManager(PathIntent.class);
- intent = PathIntent.builder()
- .appId(APP_ID)
- .selector(selector)
- .treatment(treatment)
- .path(new DefaultPath(PID, links, hops))
- .priority(77)
- .build();
- }
-
- /**
- * Tests activation and deactivation of the installer.
- */
- @Test
- public void activateDeactivate() {
- installer.activate();
- installer.deactivate();
- }
-
- /**
- * Tests installation operation of the path intent installer.
- */
- @Test
- public void install() {
- installer.activate();
-
- List<Collection<FlowRuleOperation>> operations =
- installer.install(intent);
- assertThat(operations, notNullValue());
- assertThat(operations, hasSize(1));
-
- Collection<FlowRuleOperation> flowRuleOpsCollection = operations.get(0);
- assertThat(flowRuleOpsCollection, hasSize(hops));
- FlowRuleOperation[] flowRuleOps =
- flowRuleOpsCollection.toArray(new FlowRuleOperation[hops]);
-
- FlowRuleOperation op0 = flowRuleOps[0];
- checkFlowOperation(op0, FlowRuleOperation.Type.ADD, d1p0.deviceId());
-
- FlowRuleOperation op1 = flowRuleOps[1];
- checkFlowOperation(op1, FlowRuleOperation.Type.ADD, d2p0.deviceId());
-
- FlowRuleOperation op2 = flowRuleOps[2];
- checkFlowOperation(op2, FlowRuleOperation.Type.ADD, d3p0.deviceId());
-
- installer.deactivate();
- }
-
- /**
- * Checks the uninstall operation of the path intent installer.
- */
- @Test
- public void uninstall() {
- installer.activate();
-
- List<Collection<FlowRuleOperation>> operations =
- installer.uninstall(intent);
- assertThat(operations, notNullValue());
- assertThat(operations, hasSize(1));
-
- Collection<FlowRuleOperation> flowRuleOpsCollection = operations.get(0);
- assertThat(flowRuleOpsCollection, hasSize(hops));
- FlowRuleOperation[] flowRuleOps =
- flowRuleOpsCollection.toArray(new FlowRuleOperation[hops]);
-
- FlowRuleOperation op0 = flowRuleOps[0];
- checkFlowOperation(op0, FlowRuleOperation.Type.REMOVE, d1p0.deviceId());
-
- FlowRuleOperation op1 = flowRuleOps[1];
- checkFlowOperation(op1, FlowRuleOperation.Type.REMOVE, d2p0.deviceId());
-
- FlowRuleOperation op2 = flowRuleOps[2];
- checkFlowOperation(op2, FlowRuleOperation.Type.REMOVE, d3p0.deviceId());
-
- installer.deactivate();
- }
-}
diff --git a/core/net/src/test/java/org/onosproject/net/intent/impl/phase/CompilingTest.java b/core/net/src/test/java/org/onosproject/net/intent/impl/phase/CompilingTest.java
index a968e4e..f3e91a4 100644
--- a/core/net/src/test/java/org/onosproject/net/intent/impl/phase/CompilingTest.java
+++ b/core/net/src/test/java/org/onosproject/net/intent/impl/phase/CompilingTest.java
@@ -121,12 +121,12 @@
expect(processor.compile(input, null)).andReturn(Arrays.asList(compiled));
replay(processor);
- Compiling sut = new Compiling(processor, pending, null);
+ Compiling sut = new Compiling(processor, pending);
Optional<IntentProcessPhase> output = sut.execute();
verify(processor);
- assertThat(output.get(), is(instanceOf(InstallCoordinating.class)));
+ assertThat(output.get(), is(instanceOf(Installing.class)));
}
/**
@@ -139,11 +139,11 @@
expect(processor.compile(input, null)).andThrow(new IntentCompilationException());
replay(processor);
- Compiling sut = new Compiling(processor, pending, null);
+ Compiling sut = new Compiling(processor, pending);
Optional<IntentProcessPhase> output = sut.execute();
verify(processor);
- assertThat(output.get(), is(instanceOf(CompilingFailed.class)));
+ assertThat(output.get(), is(instanceOf(CompileFailed.class)));
}
}
diff --git a/core/net/src/test/java/org/onosproject/net/intent/impl/phase/InstallingTest.java b/core/net/src/test/java/org/onosproject/net/intent/impl/phase/InstallingTest.java
deleted file mode 100644
index 8d4b334..0000000
--- a/core/net/src/test/java/org/onosproject/net/intent/impl/phase/InstallingTest.java
+++ /dev/null
@@ -1,155 +0,0 @@
-/*
- * Copyright 2015 Open Networking Laboratory
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.onosproject.net.intent.impl.phase;
-
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Test;
-import org.onosproject.TestApplicationId;
-import org.onosproject.core.ApplicationId;
-import org.onosproject.core.IdGenerator;
-import org.onosproject.net.ConnectPoint;
-import org.onosproject.net.DefaultLink;
-import org.onosproject.net.DefaultPath;
-import org.onosproject.net.Link;
-import org.onosproject.net.Path;
-import org.onosproject.net.flow.DefaultTrafficSelector;
-import org.onosproject.net.flow.DefaultTrafficTreatment;
-import org.onosproject.net.flow.FlowRuleOperations;
-import org.onosproject.net.flow.TrafficSelector;
-import org.onosproject.net.flow.TrafficTreatment;
-import org.onosproject.net.intent.Intent;
-import org.onosproject.net.intent.IntentData;
-import org.onosproject.net.intent.MockIdGenerator;
-import org.onosproject.net.intent.PathIntent;
-import org.onosproject.net.intent.PointToPointIntent;
-import org.onosproject.net.intent.impl.IntentInstallationException;
-import org.onosproject.net.intent.impl.IntentProcessor;
-import org.onosproject.net.provider.ProviderId;
-import org.onosproject.store.Timestamp;
-
-import java.util.Arrays;
-import java.util.List;
-import java.util.Optional;
-
-import static org.easymock.EasyMock.createMock;
-import static org.easymock.EasyMock.expectLastCall;
-import static org.easymock.EasyMock.replay;
-import static org.easymock.EasyMock.verify;
-import static org.hamcrest.Matchers.instanceOf;
-import static org.hamcrest.Matchers.is;
-import static org.junit.Assert.assertThat;
-import static org.onosproject.net.DeviceId.deviceId;
-import static org.onosproject.net.Link.Type.DIRECT;
-import static org.onosproject.net.PortNumber.portNumber;
-import static org.onosproject.net.intent.IntentState.INSTALL_REQ;
-
-/**
- * Unit tests for Installing phase.
- */
-public class InstallingTest {
-
- private final ApplicationId appId = new TestApplicationId("test");
- private final ProviderId pid = new ProviderId("of", "test");
- private final TrafficSelector selector = DefaultTrafficSelector.emptySelector();
- private final TrafficTreatment treatment = DefaultTrafficTreatment.emptyTreatment();
- private final ConnectPoint cp1 = new ConnectPoint(deviceId("1"), portNumber(1));
- private final ConnectPoint cp2 = new ConnectPoint(deviceId("1"), portNumber(2));
- private final ConnectPoint cp3 = new ConnectPoint(deviceId("2"), portNumber(1));
- private final ConnectPoint cp4 = new ConnectPoint(deviceId("2"), portNumber(2));
-
- private final List<Link> links = Arrays.asList(new DefaultLink(pid, cp2, cp4, DIRECT));
- private final Path path = new DefaultPath(pid, links, 10);
-
- private PointToPointIntent input;
- private PathIntent compiled;
-
- private IdGenerator idGenerator;
- private IntentProcessor processor;
- private Timestamp version;
-
- @Before
- public void setUp() {
- processor = createMock(IntentProcessor.class);
- version = createMock(Timestamp.class);
-
- idGenerator = new MockIdGenerator();
-
- Intent.bindIdGenerator(idGenerator);
-
- // Intent creation should be placed after binding an ID generator
- input = PointToPointIntent.builder()
- .appId(appId)
- .selector(selector)
- .treatment(treatment)
- .ingressPoint(cp1)
- .egressPoint(cp3)
- .build();
- compiled = PathIntent.builder()
- .appId(appId)
- .selector(selector)
- .treatment(treatment)
- .path(path)
- .build();
- }
-
-
- @After
- public void tearDown() {
- Intent.unbindIdGenerator(idGenerator);
- }
-
- /**
- * Tests a next phase when no exception occurs.
- */
- @Test
- public void testMoveToNextPhaseWithoutError() {
- IntentData pending = new IntentData(input, INSTALL_REQ, version);
- pending.setInstallables(Arrays.asList(compiled));
-
- FlowRuleOperations operations = createMock(FlowRuleOperations.class);
-
- processor.applyFlowRules(operations);
- replay(processor);
-
- Installing sut = new Installing(processor, pending, operations);
-
- Optional<IntentProcessPhase> executed = sut.execute();
- verify(processor);
- assertThat(executed.get(), is(instanceOf(Installed.class)));
- }
-
- /**
- * Test a next phase when IntentInstallationException occurs.
- */
- @Test
- public void testWhenIntentInstallationExceptionOccurs() {
- IntentData pending = new IntentData(input, INSTALL_REQ, version);
- pending.setInstallables(Arrays.asList(compiled));
-
- FlowRuleOperations operations = createMock(FlowRuleOperations.class);
-
- processor.applyFlowRules(operations);
- expectLastCall().andThrow(new IntentInstallationException());
- replay(processor);
-
- Installing sut = new Installing(processor, pending, operations);
-
- Optional<IntentProcessPhase> executed = sut.execute();
- verify(processor);
- assertThat(executed.get(), is(instanceOf(InstallingFailed.class)));
- }
-}
diff --git a/core/net/src/test/java/org/onosproject/net/intent/impl/phase/InstallCoordinatingTest.java b/core/net/src/test/java/org/onosproject/net/intent/impl/phase/ReplacingTest.java
similarity index 87%
rename from core/net/src/test/java/org/onosproject/net/intent/impl/phase/InstallCoordinatingTest.java
rename to core/net/src/test/java/org/onosproject/net/intent/impl/phase/ReplacingTest.java
index 1938425..e646a3f 100644
--- a/core/net/src/test/java/org/onosproject/net/intent/impl/phase/InstallCoordinatingTest.java
+++ b/core/net/src/test/java/org/onosproject/net/intent/impl/phase/ReplacingTest.java
@@ -28,7 +28,6 @@
import org.onosproject.net.Path;
import org.onosproject.net.flow.DefaultTrafficSelector;
import org.onosproject.net.flow.DefaultTrafficTreatment;
-import org.onosproject.net.flow.FlowRuleOperations;
import org.onosproject.net.flow.TrafficSelector;
import org.onosproject.net.flow.TrafficTreatment;
import org.onosproject.net.intent.Intent;
@@ -46,7 +45,7 @@
import java.util.Optional;
import static org.easymock.EasyMock.createMock;
-import static org.easymock.EasyMock.expect;
+import static org.easymock.EasyMock.expectLastCall;
import static org.easymock.EasyMock.replay;
import static org.easymock.EasyMock.verify;
import static org.hamcrest.Matchers.instanceOf;
@@ -55,12 +54,13 @@
import static org.onosproject.net.DeviceId.deviceId;
import static org.onosproject.net.Link.Type.DIRECT;
import static org.onosproject.net.PortNumber.portNumber;
+import static org.onosproject.net.intent.IntentState.INSTALLED;
import static org.onosproject.net.intent.IntentState.INSTALL_REQ;
/**
* Unit tests for InstallingCoordinating phase.
*/
-public class InstallCoordinatingTest {
+public class ReplacingTest {
private final ApplicationId appId = new TestApplicationId("test");
private final ProviderId pid = new ProviderId("of", "test");
@@ -120,12 +120,13 @@
IntentData pending = new IntentData(input, INSTALL_REQ, version);
pending.setInstallables(Arrays.asList(compiled));
- FlowRuleOperations operations = createMock(FlowRuleOperations.class);
+ IntentData current = new IntentData(input, INSTALLED, version);
+ current.setInstallables(Arrays.asList(compiled));
- expect(processor.coordinate(null, pending)).andReturn(operations);
+ processor.uninstall(current);
replay(processor);
- InstallCoordinating sut = new InstallCoordinating(processor, pending, null);
+ Replacing sut = new Replacing(processor, pending, current);
Optional<IntentProcessPhase> executed = sut.execute();
@@ -141,14 +142,17 @@
IntentData pending = new IntentData(input, INSTALL_REQ, version);
pending.setInstallables(Arrays.asList(compiled));
- expect(processor.coordinate(null, pending)).andThrow(new IntentInstallationException());
+ IntentData current = new IntentData(input, INSTALLED, version);
+
+ processor.uninstall(current);
+ expectLastCall().andThrow(new IntentInstallationException());
replay(processor);
- InstallCoordinating sut = new InstallCoordinating(processor, pending, null);
+ Replacing sut = new Replacing(processor, pending, current);
Optional<IntentProcessPhase> executed = sut.execute();
verify(processor);
- assertThat(executed.get(), is(instanceOf(InstallingFailed.class)));
+ assertThat(executed.get(), is(instanceOf(ReplaceFailed.class)));
}
}
diff --git a/core/net/src/test/java/org/onosproject/net/intent/impl/phase/WithdrawCoordinatingTest.java b/core/net/src/test/java/org/onosproject/net/intent/impl/phase/WithdrawCoordinatingTest.java
deleted file mode 100644
index 5d40516..0000000
--- a/core/net/src/test/java/org/onosproject/net/intent/impl/phase/WithdrawCoordinatingTest.java
+++ /dev/null
@@ -1,155 +0,0 @@
-/*
- * Copyright 2015 Open Networking Laboratory
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.onosproject.net.intent.impl.phase;
-
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Test;
-import org.onosproject.TestApplicationId;
-import org.onosproject.core.ApplicationId;
-import org.onosproject.core.IdGenerator;
-import org.onosproject.net.ConnectPoint;
-import org.onosproject.net.DefaultLink;
-import org.onosproject.net.DefaultPath;
-import org.onosproject.net.Link;
-import org.onosproject.net.Path;
-import org.onosproject.net.flow.DefaultTrafficSelector;
-import org.onosproject.net.flow.DefaultTrafficTreatment;
-import org.onosproject.net.flow.FlowRuleOperations;
-import org.onosproject.net.flow.TrafficSelector;
-import org.onosproject.net.flow.TrafficTreatment;
-import org.onosproject.net.intent.Intent;
-import org.onosproject.net.intent.IntentData;
-import org.onosproject.net.intent.MockIdGenerator;
-import org.onosproject.net.intent.PathIntent;
-import org.onosproject.net.intent.PointToPointIntent;
-import org.onosproject.net.intent.impl.IntentProcessor;
-import org.onosproject.net.intent.impl.IntentRemovalException;
-import org.onosproject.net.provider.ProviderId;
-import org.onosproject.store.Timestamp;
-
-import java.util.Arrays;
-import java.util.List;
-import java.util.Optional;
-
-import static org.easymock.EasyMock.createMock;
-import static org.easymock.EasyMock.expect;
-import static org.easymock.EasyMock.replay;
-import static org.easymock.EasyMock.verify;
-import static org.hamcrest.Matchers.instanceOf;
-import static org.hamcrest.Matchers.is;
-import static org.junit.Assert.assertThat;
-import static org.onosproject.net.DeviceId.deviceId;
-import static org.onosproject.net.Link.Type.DIRECT;
-import static org.onosproject.net.PortNumber.portNumber;
-import static org.onosproject.net.intent.IntentState.INSTALLED;
-import static org.onosproject.net.intent.IntentState.WITHDRAW_REQ;
-
-/**
- * Unit tests for WithdrawCoordinating phase.
- */
-public class WithdrawCoordinatingTest {
-
- private final ApplicationId appId = new TestApplicationId("test");
- private final ProviderId pid = new ProviderId("of", "test");
- private final TrafficSelector selector = DefaultTrafficSelector.emptySelector();
- private final TrafficTreatment treatment = DefaultTrafficTreatment.emptyTreatment();
- private final ConnectPoint cp1 = new ConnectPoint(deviceId("1"), portNumber(1));
- private final ConnectPoint cp2 = new ConnectPoint(deviceId("1"), portNumber(2));
- private final ConnectPoint cp3 = new ConnectPoint(deviceId("2"), portNumber(1));
- private final ConnectPoint cp4 = new ConnectPoint(deviceId("2"), portNumber(2));
-
- private final List<Link> links = Arrays.asList(new DefaultLink(pid, cp2, cp4, DIRECT));
- private final Path path = new DefaultPath(pid, links, 10);
-
- private PointToPointIntent input;
- private PathIntent compiled;
-
- private IdGenerator idGenerator;
- private IntentProcessor processor;
- private Timestamp version;
-
- @Before
- public void setUp() {
- processor = createMock(IntentProcessor.class);
- version = createMock(Timestamp.class);
-
- idGenerator = new MockIdGenerator();
-
- Intent.bindIdGenerator(idGenerator);
-
- // Intent creation should be placed after binding an ID generator
- input = PointToPointIntent.builder()
- .appId(appId)
- .selector(selector)
- .treatment(treatment)
- .ingressPoint(cp1)
- .egressPoint(cp3)
- .build();
- compiled = PathIntent.builder()
- .appId(appId)
- .selector(selector)
- .treatment(treatment)
- .path(path)
- .build();
- }
-
-
- @After
- public void tearDown() {
- Intent.unbindIdGenerator(idGenerator);
- }
-
- /**
- * Tests a next phase when no exception occurs.
- */
- @Test
- public void testMoveToNextPhaseWithoutError() {
- IntentData pending = new IntentData(input, WITHDRAW_REQ, version);
- IntentData current = new IntentData(input, INSTALLED, version);
- current.setInstallables(Arrays.asList(compiled));
-
- FlowRuleOperations operations = createMock(FlowRuleOperations.class);
- expect(processor.uninstallCoordinate(current, pending)).andReturn(operations);
- replay(processor);
-
- WithdrawCoordinating sut = new WithdrawCoordinating(processor, pending, current);
-
- Optional<IntentProcessPhase> executed = sut.execute();
- verify(processor);
- assertThat(executed.get(), is(instanceOf(Withdrawing.class)));
- }
-
- /**
- * Tests a next phase when IntentRemovalExceptionOccurs.
- */
- @Test
- public void testWhenIntentRemovalExceptionOccurs() {
- IntentData pending = new IntentData(input, WITHDRAW_REQ, version);
- IntentData current = new IntentData(input, INSTALLED, version);
- current.setInstallables(Arrays.asList(compiled));
-
- expect(processor.uninstallCoordinate(current, pending)).andThrow(new IntentRemovalException());
- replay(processor);
-
- WithdrawCoordinating sut = new WithdrawCoordinating(processor, pending, current);
-
- Optional<IntentProcessPhase> executed = sut.execute();
- verify(processor);
- assertThat(executed.get(), is(instanceOf(WithdrawingFailed.class)));
- }
-
-}
diff --git a/core/net/src/test/java/org/onosproject/net/intent/impl/phase/WithdrawingTest.java b/core/net/src/test/java/org/onosproject/net/intent/impl/phase/WithdrawingTest.java
deleted file mode 100644
index 6f7f267..0000000
--- a/core/net/src/test/java/org/onosproject/net/intent/impl/phase/WithdrawingTest.java
+++ /dev/null
@@ -1,133 +0,0 @@
-/*
- * Copyright 2015 Open Networking Laboratory
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.onosproject.net.intent.impl.phase;
-
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Test;
-import org.onosproject.TestApplicationId;
-import org.onosproject.core.ApplicationId;
-import org.onosproject.core.IdGenerator;
-import org.onosproject.net.ConnectPoint;
-import org.onosproject.net.DefaultLink;
-import org.onosproject.net.DefaultPath;
-import org.onosproject.net.Link;
-import org.onosproject.net.Path;
-import org.onosproject.net.flow.DefaultTrafficSelector;
-import org.onosproject.net.flow.DefaultTrafficTreatment;
-import org.onosproject.net.flow.FlowRuleOperations;
-import org.onosproject.net.flow.TrafficSelector;
-import org.onosproject.net.flow.TrafficTreatment;
-import org.onosproject.net.intent.Intent;
-import org.onosproject.net.intent.IntentData;
-import org.onosproject.net.intent.MockIdGenerator;
-import org.onosproject.net.intent.PathIntent;
-import org.onosproject.net.intent.PointToPointIntent;
-import org.onosproject.net.intent.impl.IntentProcessor;
-import org.onosproject.net.provider.ProviderId;
-import org.onosproject.store.Timestamp;
-
-import java.util.Arrays;
-import java.util.List;
-import java.util.Optional;
-
-import static org.easymock.EasyMock.createMock;
-import static org.easymock.EasyMock.replay;
-import static org.easymock.EasyMock.verify;
-import static org.hamcrest.Matchers.instanceOf;
-import static org.hamcrest.Matchers.is;
-import static org.junit.Assert.assertThat;
-import static org.onosproject.net.DeviceId.deviceId;
-import static org.onosproject.net.Link.Type.DIRECT;
-import static org.onosproject.net.PortNumber.portNumber;
-import static org.onosproject.net.intent.IntentState.INSTALLED;
-import static org.onosproject.net.intent.IntentState.WITHDRAW_REQ;
-
-/**
- * Unit tests for Withdrawing phase.
- */
-public class WithdrawingTest {
-
- private final ApplicationId appId = new TestApplicationId("test");
- private final ProviderId pid = new ProviderId("of", "test");
- private final TrafficSelector selector = DefaultTrafficSelector.emptySelector();
- private final TrafficTreatment treatment = DefaultTrafficTreatment.emptyTreatment();
- private final ConnectPoint cp1 = new ConnectPoint(deviceId("1"), portNumber(1));
- private final ConnectPoint cp2 = new ConnectPoint(deviceId("1"), portNumber(2));
- private final ConnectPoint cp3 = new ConnectPoint(deviceId("2"), portNumber(1));
- private final ConnectPoint cp4 = new ConnectPoint(deviceId("2"), portNumber(2));
-
- private final List<Link> links = Arrays.asList(new DefaultLink(pid, cp2, cp4, DIRECT));
- private final Path path = new DefaultPath(pid, links, 10);
-
- private PointToPointIntent input;
- private PathIntent compiled;
-
- private IdGenerator idGenerator;
- private IntentProcessor processor;
- private Timestamp version;
-
- @Before
- public void setUp() {
- processor = createMock(IntentProcessor.class);
- version = createMock(Timestamp.class);
-
- idGenerator = new MockIdGenerator();
-
- Intent.bindIdGenerator(idGenerator);
-
- // Intent creation should be placed after binding an ID generator
- input = PointToPointIntent.builder()
- .appId(appId)
- .selector(selector)
- .treatment(treatment)
- .ingressPoint(cp1)
- .egressPoint(cp3)
- .build();
- compiled = PathIntent.builder()
- .appId(appId)
- .selector(selector)
- .treatment(treatment)
- .path(path)
- .build();
- }
-
-
- @After
- public void tearDown() {
- Intent.unbindIdGenerator(idGenerator);
- }
-
- /**
- * Tests a next phase when no exception occurs.
- */
- @Test
- public void testMoveToNextPhaseWithoutError() {
- IntentData pending = new IntentData(input, WITHDRAW_REQ, version);
- IntentData current = new IntentData(input, INSTALLED, version);
- current.setInstallables(Arrays.asList(compiled));
-
- FlowRuleOperations operations = createMock(FlowRuleOperations.class);
- processor.applyFlowRules(operations);
- replay(processor);
-
- Withdrawing sut = new Withdrawing(processor, pending, operations);
-
- Optional<IntentProcessPhase> executed = sut.execute();
- verify(processor);
- assertThat(executed.get(), is(instanceOf(Withdrawn.class)));
- }
-}