VOL-3419: Replicate voltha flows in openolt agent
- Use the flow_id, symmetric_flow_id, replication_flag and pbit_to_gemport_map
  coming in Flow proto messge to replicate the flow as needed
- Use the CreateQueues and RemoveQueues messages to setup and remove gem_ports
- Use latest gRPC version 1.31.1 which allows fine tuning of gRPC threadpools
  which allows for greating performance.
- Performance numbers when tested with openolt-scale-tester has been better with
  using latest gRPC and threadpool tuning when compared to earlier. It is to be
  noted that the performance is better even with openolt-agent replicating the flow
  now.
- Scale tests with 512 subscribers have been successfull with BAL3.4.7.5 version
- Use openolt proto version 4.0.0
- Use openolt-test (for unit test) image version 2.0.1 (which bundles latest gRPC version 1.31.1)
- These changes are NOT backward compatible and openolt-agent will have a major
  version bump to 3.0.0

Change-Id: I715c804bdf342e60d08cab6c59e1c21b8c5ac1f4
diff --git a/agent/src/core_data.h b/agent/src/core_data.h
index d0761c5..322c834 100644
--- a/agent/src/core_data.h
+++ b/agent/src/core_data.h
@@ -20,6 +20,7 @@
 
 #include "core.h"
 #include "Queue.h"
+#include "device.h"
 
 extern "C"
 {
@@ -43,8 +44,6 @@
 
 #define ONU_DEACTIVATE_COMPLETE_WAIT_TIMEOUT 5000 // in milli-seconds
 
-#define MIN_ALLOC_ID_GPON 256
-#define MIN_ALLOC_ID_XGSPON 1024
 
 #define MAX_ACL_ID 33
 
@@ -132,6 +131,23 @@
     // above elements.
 } acl_classifier_key;
 
+typedef struct device_flow_params {
+    uint8_t pbit; // If pbit classifier is not present in flow, use 0xff to invalidate
+    uint32_t gemport_id;
+    uint16_t flow_id;
+} device_flow_params;
+
+typedef struct device_flow {
+    bool is_flow_replicated; // If true number of replicated flows is to the NUMBER_OF_PBITS, else 1
+    device_flow_params params[NUMBER_OF_REPLICATED_FLOWS]; // A voltha-flow cannot be replicated more than the number of pbits
+    uint64_t voltha_flow_id; // This is corresponding voltha flow-id.
+    uint64_t symmetric_voltha_flow_id; // Is not applicable for trap-to-controller voltha flows.
+                                       // 0 value means invalid or not-applicable
+                                       // Applicable for bi-directional data path flows (one flow per direction)
+                                       // Symmetric flows should share the same device_flow_id.
+
+} device_flow;
+
 // *******************************************************//
 // Extern Variable/Constant declarations used by the core //
 // *******************************************************//
@@ -215,9 +231,9 @@
 extern std::map<acl_classifier_key, uint16_t> acl_classifier_to_acl_id_map;
 extern bool operator<(const acl_classifier_key& a1, const acl_classifier_key& a2);
 
-typedef std::tuple<uint16_t, std::string> flow_id_flow_direction;
-typedef std::tuple<int16_t, uint16_t, int32_t> acl_id_gem_id_intf_id;
-extern std::map<flow_id_flow_direction, acl_id_gem_id_intf_id> flow_to_acl_map;
+typedef std::tuple<uint64_t, std::string> flow_id_flow_direction;
+typedef std::tuple<int16_t, int32_t> acl_id_intf_id;
+extern std::map<flow_id_flow_direction, acl_id_intf_id> flow_to_acl_map;
 
 // Keeps a reference count of how many flows are referencing a given ACL ID.
 // Key represents the ACL-ID and value is number of flows referencing the given ACL-ID.
@@ -225,12 +241,6 @@
 // When there are no flows referencing the ACL-ID, the ACL should be removed.
 extern std::map<uint16_t, uint16_t> acl_ref_cnt;
 
-typedef std::tuple<uint16_t, uint16_t> gem_id_intf_id; // key to gem_ref_cnt
-// Keeps a reference count of how many ACL related flows are referencing a given (gem-id, pon_intf_id).
-// When there is at least on flow, we should install the gem. When there are no flows
-// the gem should be removed.
-extern std::map<gem_id_intf_id, uint16_t> gem_ref_cnt;
-
 // Needed to keep track of how many flows for a given acl_id, intf_id and intf_type are
 // installed. When there is at least on flow for this key, we should have interface registered
 // for the given ACL-ID. When there are no flows, the intf should unregister itself from
@@ -239,14 +249,26 @@
 extern std::map<acl_id_intf_id_intf_type, uint16_t> intf_acl_registration_ref_cnt;
 
 extern std::bitset<MAX_ACL_ID> acl_id_bitset;
+extern bcmos_fastlock acl_id_bitset_lock;
 
 /*** ACL Handling related data end ***/
 
 extern std::bitset<MAX_TM_SCHED_ID> tm_sched_bitset;
+extern bcmos_fastlock tm_sched_bitset_lock;
+
 extern std::bitset<MAX_TM_QMP_ID> tm_qmp_bitset;
+extern bcmos_fastlock tm_qmp_bitset_lock;
+
+extern std::bitset<MAX_FLOW_ID> flow_id_bitset;
+extern bcmos_fastlock flow_id_bitset_lock;
+
+extern std::map<uint64_t, device_flow> voltha_flow_to_device_flow;
+extern bcmos_fastlock voltha_flow_to_device_flow_lock;
 
 extern Queue<openolt::Indication> oltIndQ;
 
+/*** ACL Handling related data end ***/
+
 extern bcmos_fastlock data_lock;
 
 // Interface name on which grpc server is running on