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/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)));
- }
-}