Implement IntentCompilers
For the following Intent types
- PointToPointIntent
- PathIntent
- MultiPointToSinglePointIntent
This resolves ONOS-1657, ONOS-1659, and ONOS-1660.
Change-Id: I7c68cec4b025a59f9c97bae4488801bea2716baf
diff --git a/src/main/java/net/onrc/onos/core/newintent/AbstractIntentCompiler.java b/src/main/java/net/onrc/onos/core/newintent/AbstractIntentCompiler.java
new file mode 100644
index 0000000..0b16f10
--- /dev/null
+++ b/src/main/java/net/onrc/onos/core/newintent/AbstractIntentCompiler.java
@@ -0,0 +1,54 @@
+package net.onrc.onos.core.newintent;
+
+import net.onrc.onos.api.newintent.ConnectivityIntent;
+import net.onrc.onos.api.newintent.Intent;
+import net.onrc.onos.api.newintent.IntentCompiler;
+import net.onrc.onos.api.newintent.IntentId;
+import net.onrc.onos.api.newintent.IntentIdGenerator;
+import net.onrc.onos.core.matchaction.action.Action;
+import net.onrc.onos.core.matchaction.action.Actions;
+import net.onrc.onos.core.matchaction.action.OutputAction;
+import net.onrc.onos.core.util.SwitchPort;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import static com.google.common.base.Preconditions.checkNotNull;
+
+/**
+ * A base IntentCompiler implementation.
+ * @param <T> the type of intent
+ */
+public abstract class AbstractIntentCompiler<T extends Intent> implements IntentCompiler<T> {
+ private final IntentIdGenerator idGenerator;
+
+ /**
+ * Constructs an instance with the specified Intent ID generator.
+ * <p>
+ * Intent compiler generates intents from an input intent.
+ * To make sure to use unique IDs for generated intents, intent
+ * ID generator is given as the argument of a constructor in normal
+ * cases.
+ * </p>
+ * @param idGenerator intent ID generator
+ */
+ protected AbstractIntentCompiler(IntentIdGenerator idGenerator) {
+ this.idGenerator = checkNotNull(idGenerator);
+ }
+
+ protected IntentId getNextId() {
+ return idGenerator.getNewId();
+ }
+
+ protected List<Action> packActions(ConnectivityIntent intent, SwitchPort egress) {
+ List<Action> actions = new ArrayList<>();
+ Action intentAction = intent.getAction();
+ if (!intentAction.equals(Actions.nullAction())) {
+ actions.add(intentAction);
+ }
+
+ OutputAction output = new OutputAction(egress.getPortNumber());
+ actions.add(output);
+ return actions;
+ }
+}