Initial work for adding flow-objective backed intents.
Split installation work from IntentManager into IntentInstaller helper class.
Change-Id: If926ce975d005abee4f22f2b05404de328d94203
diff --git a/core/api/src/main/java/org/onosproject/net/intent/FlowObjectiveIntent.java b/core/api/src/main/java/org/onosproject/net/intent/FlowObjectiveIntent.java
new file mode 100644
index 0000000..18dcb6e
--- /dev/null
+++ b/core/api/src/main/java/org/onosproject/net/intent/FlowObjectiveIntent.java
@@ -0,0 +1,97 @@
+/*
+ * Copyright 2016 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;
+
+import com.google.common.base.MoreObjects;
+import org.onosproject.core.ApplicationId;
+import org.onosproject.net.NetworkResource;
+import org.onosproject.net.flowobjective.Objective;
+
+import java.util.Collection;
+
+/**
+ * Intent expressed as (and backed by) a collection of flow objectives through
+ * which the intent is to be accomplished.
+ */
+public class FlowObjectiveIntent extends Intent {
+
+ private final Collection<Objective> objectives;
+
+ /**
+ * Constructor for serialization.
+ */
+ protected FlowObjectiveIntent() {
+ super();
+ this.objectives = null;
+ }
+
+ /**
+ * Creates a flow objective intent with the specified objectives and
+ * resources.
+ *
+ * @param appId application id
+ * @param objectives backing flow objectives
+ * @param resources backing network resources
+ */
+ public FlowObjectiveIntent(ApplicationId appId,
+ Collection<Objective> objectives,
+ Collection<NetworkResource> resources) {
+ this(appId, null, objectives, resources);
+ }
+
+ /**
+ * Creates a flow objective intent with the specified objectives and
+ * resources.
+ *
+ * @param appId application id
+ * @param key intent key
+ * @param objectives backing flow objectives
+ * @param resources backing network resources
+ */
+ public FlowObjectiveIntent(ApplicationId appId, Key key,
+ Collection<Objective> objectives,
+ Collection<NetworkResource> resources) {
+ super(appId, key, resources, DEFAULT_INTENT_PRIORITY);
+ this.objectives = objectives;
+ }
+
+ /**
+ * Returns the collection of backing flow objectives.
+ *
+ * @return flow objectives
+ */
+ Collection<Objective> objectives() {
+ return objectives;
+ }
+
+
+ @Override
+ public boolean isInstallable() {
+ return true;
+ }
+
+ @Override
+ public String toString() {
+ return MoreObjects.toStringHelper(this)
+ .add("id", id())
+ .add("key", key())
+ .add("appId", appId())
+ .add("resources", resources())
+ .add("objectives", objectives)
+ .toString();
+ }
+}
diff --git a/core/api/src/test/java/org/onosproject/net/intent/AbstractIntentTest.java b/core/api/src/test/java/org/onosproject/net/intent/AbstractIntentTest.java
index 6bb7e28..565bdf5 100644
--- a/core/api/src/test/java/org/onosproject/net/intent/AbstractIntentTest.java
+++ b/core/api/src/test/java/org/onosproject/net/intent/AbstractIntentTest.java
@@ -25,6 +25,7 @@
@Before
public void setUp() throws Exception {
+ Intent.unbindIdGenerator(idGenerator);
Intent.bindIdGenerator(idGenerator);
}
diff --git a/core/api/src/test/java/org/onosproject/net/intent/FlowObjectiveIntentTest.java b/core/api/src/test/java/org/onosproject/net/intent/FlowObjectiveIntentTest.java
new file mode 100644
index 0000000..ec3e334
--- /dev/null
+++ b/core/api/src/test/java/org/onosproject/net/intent/FlowObjectiveIntentTest.java
@@ -0,0 +1,99 @@
+/*
+ * Copyright 2016 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;
+
+import com.google.common.collect.ImmutableSet;
+import com.google.common.testing.EqualsTester;
+import org.junit.Test;
+import org.onosproject.core.ApplicationId;
+import org.onosproject.core.DefaultApplicationId;
+import org.onosproject.net.NetworkResource;
+import org.onosproject.net.flow.DefaultTrafficSelector;
+import org.onosproject.net.flow.DefaultTrafficTreatment;
+import org.onosproject.net.flow.criteria.Criteria;
+import org.onosproject.net.flowobjective.DefaultFilteringObjective;
+import org.onosproject.net.flowobjective.DefaultForwardingObjective;
+import org.onosproject.net.flowobjective.ForwardingObjective;
+import org.onosproject.net.flowobjective.Objective;
+
+import java.util.Collection;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+import static org.onlab.junit.ImmutableClassChecker.assertThatClassIsImmutable;
+
+/**
+ * Tests of the flow objective intent.
+ */
+public class FlowObjectiveIntentTest extends IntentTest {
+
+ private static final ApplicationId APP_ID = new DefaultApplicationId(1, "foo");
+ private static final Key KEY = Key.of("bar", APP_ID);
+
+ private static final Objective FO1 = DefaultFilteringObjective.builder()
+ .fromApp(APP_ID).addCondition(Criteria.matchEthType(123))
+ .permit().add();
+ private static final Objective FO2 = DefaultForwardingObjective.builder()
+ .fromApp(APP_ID)
+ .withSelector(DefaultTrafficSelector.builder().matchEthType((short) 123).build())
+ .withTreatment(DefaultTrafficTreatment.emptyTreatment())
+ .withFlag(ForwardingObjective.Flag.VERSATILE).add();
+ private static final Collection<Objective> OBJECTIVES = ImmutableSet.of(FO1, FO2);
+ private static final Collection<NetworkResource> RESOURCES = ImmutableSet.of();
+
+ /**
+ * Tests basics of construction and getters.
+ */
+ @Test
+ public void basics() {
+ FlowObjectiveIntent intent =
+ new FlowObjectiveIntent(APP_ID, KEY, OBJECTIVES, RESOURCES);
+ assertEquals("incorrect app id", APP_ID, intent.appId());
+ assertEquals("incorrect key", KEY, intent.key());
+ assertEquals("incorrect objectives", OBJECTIVES, intent.objectives());
+ assertEquals("incorrect resources", RESOURCES, intent.resources());
+ assertTrue("should be installable", intent.isInstallable());
+ }
+
+ /**
+ * Tests equality.
+ */
+ @Test
+ public void equality() {
+ Intent a = createOne();
+ Intent b = createAnother();
+ new EqualsTester().addEqualityGroup(a).addEqualityGroup(b).testEquals();
+ }
+
+ /**
+ * Tests that instance is immutable.
+ */
+ @Test
+ public void testImmutability() {
+ assertThatClassIsImmutable(HostToHostIntent.class);
+ }
+
+ @Override
+ protected Intent createOne() {
+ return new FlowObjectiveIntent(APP_ID, OBJECTIVES, RESOURCES);
+ }
+
+ @Override
+ protected Intent createAnother() {
+ return new FlowObjectiveIntent(APP_ID, OBJECTIVES, RESOURCES);
+ }
+}
\ No newline at end of file