Pi classes to support P4Runtime action profiles

+ modified default.p4 with ECMP capabilities (via action profiles)
+ sketched translation logic of ONOS groups (in Bmv2GroupProgrammable)
+ replaced existing instances of default.json/p4info with symlinks to
	p4src build directory (to avoid inconsistencies)

Change-Id: If82f0b8ce296c9b616415d99864d216b77645a87
diff --git a/core/api/src/main/java/org/onosproject/net/pi/runtime/PiActionGroup.java b/core/api/src/main/java/org/onosproject/net/pi/runtime/PiActionGroup.java
new file mode 100644
index 0000000..57fab9d
--- /dev/null
+++ b/core/api/src/main/java/org/onosproject/net/pi/runtime/PiActionGroup.java
@@ -0,0 +1,190 @@
+/*
+ * Copyright 2017-present 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.pi.runtime;
+
+import com.google.common.annotations.Beta;
+import com.google.common.base.MoreObjects;
+import com.google.common.base.Objects;
+import com.google.common.collect.ImmutableSet;
+import com.google.common.collect.Maps;
+
+import java.util.Collection;
+import java.util.Map;
+
+import static com.google.common.base.Preconditions.checkArgument;
+import static com.google.common.base.Preconditions.checkNotNull;
+
+/**
+ * Action group of a protocol-independent pipeline.
+ */
+@Beta
+public final class PiActionGroup {
+
+    /**
+     * Type of action group.
+     */
+    public enum Type {
+        /**
+         * Load-balancing among different members in a group.
+         */
+        SELECT
+    }
+
+    private final PiActionGroupId id;
+    private final Type type;
+    private final ImmutableSet<PiActionGroupMember> members;
+
+    private PiActionGroup(PiActionGroupId id, Type type, ImmutableSet<PiActionGroupMember> members) {
+        this.id = id;
+        this.type = type;
+        this.members = members;
+    }
+
+    /**
+     * Returns the identifier of this action group.
+     *
+     * @return action group identifier
+     */
+    public PiActionGroupId id() {
+        return id;
+    }
+
+    /**
+     * Returns the type of this action group.
+     *
+     * @return action group type
+     */
+    public Type type() {
+        return type;
+    }
+
+    /**
+     * Returns the members of this action group.
+     *
+     * @return collection of action members.
+     */
+    public Collection<PiActionGroupMember> members() {
+        return members;
+    }
+
+    @Override
+    public boolean equals(Object o) {
+        if (this == o) {
+            return true;
+        }
+        if (o == null || getClass() != o.getClass()) {
+            return false;
+        }
+        PiActionGroup that = (PiActionGroup) o;
+        return id == that.id &&
+                Objects.equal(type, that.type) &&
+                Objects.equal(members, that.members);
+    }
+
+    @Override
+    public int hashCode() {
+        return Objects.hashCode(id, type, members);
+    }
+
+    @Override
+    public String toString() {
+        return MoreObjects.toStringHelper(this)
+                .add("groupId", id)
+                .add("type", type)
+                .add("members", members)
+                .toString();
+    }
+
+    /**
+     * Returns a new builder of action groups.
+     *
+     * @return action group builder
+     */
+    public static Builder builder() {
+        return new Builder();
+    }
+
+    /**
+     * Builder of action groups.
+     */
+    public static final class Builder {
+
+        private PiActionGroupId id;
+        private Type type;
+        private Map<PiActionGroupMemberId, PiActionGroupMember> members = Maps.newHashMap();
+
+        private Builder() {
+            // hides constructor.
+        }
+
+        /**
+         * Sets the identifier of this action group.
+         *
+         * @param id action group identifier
+         * @return this
+         */
+        public Builder withId(PiActionGroupId id) {
+            this.id = id;
+            return this;
+        }
+
+        /**
+         * Sets the type of this action group.
+         *
+         * @param type action group type
+         * @return this
+         */
+        public Builder withType(Type type) {
+            this.type = type;
+            return this;
+        }
+
+        /**
+         * Adds one member to this action group.
+         *
+         * @param member action group member
+         * @return this
+         */
+        public Builder addMember(PiActionGroupMember member) {
+            members.put(member.id(), member);
+            return this;
+        }
+
+        /**
+         * Adds many members to this action group.
+         *
+         * @param members action group members
+         * @return this
+         */
+        public Builder addMembers(Collection<PiActionGroupMember> members) {
+            members.forEach(this::addMember);
+            return this;
+        }
+
+        /**
+         * Creates a new action group.
+         *
+         * @return action group
+         */
+        public PiActionGroup build() {
+            checkNotNull(id);
+            checkNotNull(type);
+            checkArgument(members.size() > 0, "Members cannot be empty");
+            return new PiActionGroup(id, type, ImmutableSet.copyOf(members.values()));
+        }
+    }
+}
diff --git a/core/api/src/main/java/org/onosproject/net/pi/runtime/PiActionGroupId.java b/core/api/src/main/java/org/onosproject/net/pi/runtime/PiActionGroupId.java
new file mode 100644
index 0000000..675ef59
--- /dev/null
+++ b/core/api/src/main/java/org/onosproject/net/pi/runtime/PiActionGroupId.java
@@ -0,0 +1,51 @@
+/*
+ * Copyright 2017-present 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.pi.runtime;
+
+import com.google.common.annotations.Beta;
+import org.onlab.util.Identifier;
+
+/**
+ * Identifier of an action group in a protocol-independent pipeline.
+ */
+@Beta
+public final class PiActionGroupId extends Identifier<Integer> implements PiTableAction {
+
+    private PiActionGroupId(int id) {
+        super(id);
+    }
+
+    /**
+     * Returns an action group identifier for the given integer value.
+     *
+     * @param id identifier
+     * @return action group
+     */
+    public static PiActionGroupId of(int id) {
+        return new PiActionGroupId(id);
+    }
+
+    /*
+    In P4Runtime, groups can be referenced directly as table actions (i.e. without invoking the selector).
+    In future we should consider having a more appropriate wrapper class for group IDs, instead of implementing
+    the PiTableAction interface.
+     */
+    @Override
+    public Type type() {
+        return Type.ACTION_GROUP_ID;
+    }
+}
diff --git a/core/api/src/main/java/org/onosproject/net/pi/runtime/PiActionGroupMember.java b/core/api/src/main/java/org/onosproject/net/pi/runtime/PiActionGroupMember.java
new file mode 100644
index 0000000..67566d6
--- /dev/null
+++ b/core/api/src/main/java/org/onosproject/net/pi/runtime/PiActionGroupMember.java
@@ -0,0 +1,165 @@
+/*
+ * Copyright 2017-present 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.pi.runtime;
+
+import com.google.common.annotations.Beta;
+import com.google.common.base.MoreObjects;
+import com.google.common.base.Objects;
+
+import static com.google.common.base.Preconditions.checkNotNull;
+
+/**
+ * Member of an action group in a protocol-independent pipeline.
+ */
+@Beta
+public final class PiActionGroupMember {
+
+    private final PiActionGroupMemberId id;
+    private final PiAction action;
+    private final int weight;
+
+    private PiActionGroupMember(PiActionGroupMemberId id, PiAction action, int weight) {
+        this.id = id;
+        this.action = action;
+        this.weight = weight;
+    }
+
+    /**
+     * Returns the identifier of this member.
+     *
+     * @return member identifier
+     */
+    public PiActionGroupMemberId id() {
+        return id;
+    }
+
+    /**
+     * Returns the action associated to this member.
+     *
+     * @return action
+     */
+    public PiAction action() {
+        return action;
+    }
+
+    /**
+     * Returns the weight associated to this member. Valid if the action group is of type {@link
+     * PiActionGroup.Type#SELECT}.
+     *
+     * @return weight
+     */
+    public int weight() {
+        return weight;
+    }
+
+    @Override
+    public boolean equals(Object o) {
+        if (this == o) {
+            return true;
+        }
+        if (!(o instanceof PiActionGroupMember)) {
+            return false;
+        }
+        PiActionGroupMember that = (PiActionGroupMember) o;
+        return weight == that.weight &&
+                Objects.equal(id, that.id) &&
+                Objects.equal(action, that.action);
+    }
+
+    @Override
+    public int hashCode() {
+        return Objects.hashCode(id, action, weight);
+    }
+
+    @Override
+    public String toString() {
+        return MoreObjects.toStringHelper(this)
+                .add("id", id)
+                .add("action", action)
+                .add("weight", weight)
+                .toString();
+    }
+
+    /**
+     * Returns a new builder of action group members.
+     *
+     * @return member builder
+     */
+    public static Builder builder() {
+        return new Builder();
+    }
+
+    /**
+     * Builder of action group members.
+     */
+    public static final class Builder {
+
+        private PiActionGroupMemberId id;
+        private PiAction action;
+        private int weight;
+
+        private Builder() {
+            // Hides constructor.
+        }
+
+        /**
+         * Sets the identifier of this member.
+         *
+         * @param id member identifier
+         * @return this
+         */
+        public Builder withId(PiActionGroupMemberId id) {
+            this.id = id;
+            return this;
+        }
+
+        /**
+         * Sets the action of this member.
+         *
+         * @param action action
+         * @return this
+         */
+        public Builder withAction(PiAction action) {
+            this.action = action;
+            return this;
+        }
+
+        /**
+         * Sets the weight of this member. Valid if the action group is of type {@link PiActionGroup.Type#SELECT}.
+         * <p>
+         * Default value is 0.
+         *
+         * @param weight weight
+         * @return this
+         */
+        public Builder withWeight(int weight) {
+            this.weight = weight;
+            return this;
+        }
+
+        /**
+         * Creates a new action group member.
+         *
+         * @return action group member
+         */
+        public PiActionGroupMember build() {
+            checkNotNull(id);
+            checkNotNull(action);
+            return new PiActionGroupMember(id, action, weight);
+        }
+    }
+}
diff --git a/core/api/src/main/java/org/onosproject/net/pi/runtime/PiActionGroupMemberId.java b/core/api/src/main/java/org/onosproject/net/pi/runtime/PiActionGroupMemberId.java
new file mode 100644
index 0000000..8669388
--- /dev/null
+++ b/core/api/src/main/java/org/onosproject/net/pi/runtime/PiActionGroupMemberId.java
@@ -0,0 +1,51 @@
+/*
+ * Copyright 2017-present 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.pi.runtime;
+
+import com.google.common.annotations.Beta;
+import org.onlab.util.Identifier;
+
+/**
+ * Identifier of a member of an action group in a protocol-independent pipeline.
+ */
+@Beta
+public final class PiActionGroupMemberId extends Identifier<Integer> implements PiTableAction {
+
+    private PiActionGroupMemberId(int id) {
+        super(id);
+    }
+
+    /**
+     * Returns an action group identifier for the given integer value.
+     *
+     * @param id identifier
+     * @return action group
+     */
+    public static PiActionGroupMemberId of(int id) {
+        return new PiActionGroupMemberId(id);
+    }
+
+    /*
+    In P4Runtime, group members can be referenced directly as table actions.
+    In future we should consider having a more appropriate wrapper class for group member IDs, instead of implementing
+    the PiTableAction interface.
+     */
+    @Override
+    public Type type() {
+        return Type.GROUP_MEMBER_ID;
+    }
+}
diff --git a/core/api/src/main/java/org/onosproject/net/pi/runtime/PiTableAction.java b/core/api/src/main/java/org/onosproject/net/pi/runtime/PiTableAction.java
index a4d4038..eb842d4 100644
--- a/core/api/src/main/java/org/onosproject/net/pi/runtime/PiTableAction.java
+++ b/core/api/src/main/java/org/onosproject/net/pi/runtime/PiTableAction.java
@@ -38,15 +38,14 @@
          */
         ACTION,
 
-        // TODO: in P4Runtime a table action can be any of the following 3.
-        // How to represent action profiles?
-        /* message TableAction {
-              oneof type {
-                Action action = 1;
-                uint32 action_profile_member_id = 2;
-                uint32 action_profile_group_id = 3;
-              }
-            }
-        */
+        /**
+         * Executes the action group specified by the given identifier.
+         */
+        ACTION_GROUP_ID,
+
+        /**
+         * Executes the action member group specified by the given identifier.
+         */
+        GROUP_MEMBER_ID
     }
 }