[ONOS-7596] Support reading table entries with counter data in P4Runtime

Change-Id: I85bacb1697a6c881dd69ba74a2162c73ec0b8aee
diff --git a/core/api/src/main/java/org/onosproject/net/pi/runtime/PiTableEntry.java b/core/api/src/main/java/org/onosproject/net/pi/runtime/PiTableEntry.java
index f8a1460..ac73bbe 100644
--- a/core/api/src/main/java/org/onosproject/net/pi/runtime/PiTableEntry.java
+++ b/core/api/src/main/java/org/onosproject/net/pi/runtime/PiTableEntry.java
@@ -42,10 +42,11 @@
     private final long cookie;
     private final int priority;
     private final double timeout;
+    private final PiCounterCellData counterData;
 
     private PiTableEntry(PiTableId tableId, PiMatchKey matchKey,
                          PiTableAction tableAction, boolean isDefaultAction,
-                         long cookie, int priority, double timeout) {
+                         long cookie, int priority, double timeout, PiCounterCellData data) {
         this.tableId = tableId;
         this.matchKey = matchKey;
         this.tableAction = tableAction;
@@ -53,6 +54,7 @@
         this.cookie = cookie;
         this.priority = priority;
         this.timeout = timeout;
+        this.counterData = data;
     }
 
     /**
@@ -125,6 +127,18 @@
         return timeout == NO_TIMEOUT ? Optional.empty() : Optional.of(timeout);
     }
 
+    /**
+     * Returns the data of the counter cell associated with this table entry.
+     * This method is meaningful only if the table entry was read from the
+     * infrastructure device and the table has direct counters, otherwise
+     * returns null.
+     *
+     * @return counter cell data
+     */
+    public PiCounterCellData counter() {
+        return counterData;
+    }
+
     @Override
     public boolean equals(Object o) {
         if (this == o) {
@@ -197,6 +211,7 @@
         private long cookie = 0;
         private int priority = NO_PRIORITY;
         private double timeout = NO_TIMEOUT;
+        private PiCounterCellData counterData;
 
         private Builder() {
             // Hides constructor.
@@ -272,6 +287,17 @@
         }
 
         /**
+         * Sets the counter cell data of this table entry.
+         *
+         * @param data counter cell data
+         * @return this
+         */
+        public Builder withCounterCellData(PiCounterCellData data) {
+            this.counterData = checkNotNull(data, "Counter cell data cannot be null");
+            return this;
+        }
+
+        /**
          * Builds the table entry.
          *
          * @return a new table entry
@@ -281,7 +307,7 @@
             checkNotNull(matchKey);
             final boolean isDefaultAction = matchKey.equals(PiMatchKey.EMPTY);
             return new PiTableEntry(tableId, matchKey, tableAction,
-                                    isDefaultAction, cookie, priority, timeout);
+                                    isDefaultAction, cookie, priority, timeout, counterData);
         }
     }
 }