Fix PiGroupTranslatorImpl producing action profile members with ID 0

which is invalid in P4Runtime. This was observed when using action
profile group IDs with the last 2 bytes set to zeros, e.g. 0xec3b0000.
Now we generate the member ID as the hash of the group ID and the bucket
index, also adding a check for member IDs to be different than 0.

Change-Id: Id9fdf21d9704930703c3020b049cb19dafb1e590
diff --git a/core/net/src/main/java/org/onosproject/net/pi/impl/PiGroupTranslatorImpl.java b/core/net/src/main/java/org/onosproject/net/pi/impl/PiGroupTranslatorImpl.java
index 14e2b5c..42a29a8 100644
--- a/core/net/src/main/java/org/onosproject/net/pi/impl/PiGroupTranslatorImpl.java
+++ b/core/net/src/main/java/org/onosproject/net/pi/impl/PiGroupTranslatorImpl.java
@@ -34,7 +34,7 @@
 import org.onosproject.net.pi.runtime.PiTableAction;
 import org.onosproject.net.pi.service.PiTranslationException;
 
-import java.nio.ByteBuffer;
+import java.util.Objects;
 import java.util.Set;
 
 import static java.lang.String.format;
@@ -133,11 +133,12 @@
             Hack: Statically derive member ID by combining groupId and position
             of the bucket in the list.
              */
-            final ByteBuffer bb = ByteBuffer.allocate(4)
-                    .putShort((short) (group.id().id() & 0xffff))
-                    .putShort(bucketIdx);
-            bb.rewind();
-            final int memberId = bb.getInt();
+            final int memberId = Objects.hash(group.id(), bucketIdx);
+            if (memberId == 0) {
+                throw new PiTranslationException(
+                        "GroupBucket produces PiActionProfileMember " +
+                                "with invalid ID 0");
+            }
             bucketIdx++;
 
             final PiTableAction tableAction = translateTreatment(
diff --git a/core/net/src/test/java/org/onosproject/net/pi/impl/PiGroupTranslatorImplTest.java b/core/net/src/test/java/org/onosproject/net/pi/impl/PiGroupTranslatorImplTest.java
index fd445d7..ac9817d 100644
--- a/core/net/src/test/java/org/onosproject/net/pi/impl/PiGroupTranslatorImplTest.java
+++ b/core/net/src/test/java/org/onosproject/net/pi/impl/PiGroupTranslatorImplTest.java
@@ -81,7 +81,7 @@
             DEVICE_ID, SELECT, BUCKETS, GROUP_KEY, GROUP_ID.id(), APP_ID);
     private static final Group SELECT_GROUP = new DefaultGroup(GROUP_ID, SELECT_GROUP_DESC);
     private static final int DEFAULT_MEMBER_WEIGHT = 1;
-    private static final int BASE_MEM_ID = 65535;
+    private static final int BASE_MEM_ID = 991;
     private static final int PORT_BITWIDTH = 9;
     private Collection<PiActionProfileMember> expectedMemberInstances;
     private Collection<PiActionProfileGroup.WeightedMember> expectedWeightedMembers;