Enhance CLI command 'tablestats' to support P4 switch

Change-Id: Icb7bae93840bac1ad8d49240f61a4f5bf08dac4c
diff --git a/providers/openflow/flow/src/main/java/org/onosproject/provider/of/flow/impl/OpenFlowRuleProvider.java b/providers/openflow/flow/src/main/java/org/onosproject/provider/of/flow/impl/OpenFlowRuleProvider.java
index a72c082..c6d0769 100644
--- a/providers/openflow/flow/src/main/java/org/onosproject/provider/of/flow/impl/OpenFlowRuleProvider.java
+++ b/providers/openflow/flow/src/main/java/org/onosproject/provider/of/flow/impl/OpenFlowRuleProvider.java
@@ -52,6 +52,7 @@
 import org.onosproject.net.flow.FlowRuleProviderRegistry;
 import org.onosproject.net.flow.FlowRuleProviderService;
 import org.onosproject.net.flow.TableStatisticsEntry;
+import org.onosproject.net.flow.IndexTableId;
 import org.onosproject.net.provider.AbstractProvider;
 import org.onosproject.net.provider.ProviderId;
 import org.onosproject.net.statistic.DefaultLoad;
@@ -709,11 +710,25 @@
                                                           OFTableStatsEntry ofEntry) {
             TableStatisticsEntry entry = null;
             if (ofEntry != null) {
-                entry = new DefaultTableStatisticsEntry(deviceId,
-                                                        ofEntry.getTableId().getValue(),
-                                                        ofEntry.getActiveCount(),
-                                                        ofEntry.getLookupCount().getValue(),
-                                                        ofEntry.getMatchedCount().getValue());
+                IndexTableId tid = IndexTableId.of(ofEntry.getTableId().getValue());
+
+                try {
+                    entry = DefaultTableStatisticsEntry.builder()
+                            .withDeviceId(deviceId)
+                            .withTableId(tid)
+                            .withActiveFlowEntries(ofEntry.getActiveCount())
+                            .withPacketsLookedUpCount(ofEntry.getLookupCount().getValue())
+                            .withPacketsMatchedCount(ofEntry.getMatchedCount().getValue())
+                            .withMaxSize(ofEntry.getMaxEntries()).build();
+                } catch (UnsupportedOperationException e) {
+                    // The exception "UnsupportedOperationException" is thrown by "getMaxEntries()".
+                    entry = DefaultTableStatisticsEntry.builder()
+                            .withDeviceId(deviceId)
+                            .withTableId(tid)
+                            .withActiveFlowEntries(ofEntry.getActiveCount())
+                            .withPacketsLookedUpCount(ofEntry.getLookupCount().getValue())
+                            .withPacketsMatchedCount(ofEntry.getMatchedCount().getValue()).build();
+                }
             }
 
             return entry;
@@ -775,4 +790,4 @@
         }
     }
 
-}
+}
\ No newline at end of file