[VOL-5291] On demand statistics for ONU and OLT

Change-Id: I4850bb0f0d2235122cb0c1bcf835b3672bb34436
Signed-off-by: Akash Reddy Kankanala <akash.kankanala@radisys.com>
diff --git a/protos/voltha_protos/common.proto b/protos/voltha_protos/common.proto
index d44611f..d2fe18b 100755
--- a/protos/voltha_protos/common.proto
+++ b/protos/voltha_protos/common.proto
@@ -121,3 +121,69 @@
     string additional_info = 2;
 }
 
+message PortStatistics {
+    fixed32 intf_id = 1;
+    fixed64 rx_bytes = 2;
+    fixed64 rx_packets = 3;
+    fixed64 rx_ucast_packets = 4;
+    fixed64 rx_mcast_packets = 5;
+    fixed64 rx_bcast_packets = 6;
+    fixed64 rx_error_packets = 7;
+    fixed64 rx_frames = 17;
+    fixed64 rx_frames_64 = 18;
+    fixed64 rx_frames_65_127 = 19;
+    fixed64 rx_frames_128_255 = 20;
+    fixed64 rx_frames_256_511 = 21;
+    fixed64 rx_frames_512_1023 = 22;
+    fixed64 rx_frames_1024_1518 = 23;
+    fixed64 rx_frames_1519_2047 = 24;
+    fixed64 rx_frames_2048_4095 = 25;
+    fixed64 rx_frames_4096_9216 = 26;
+    fixed64 rx_frames_9217_16383 = 27;
+    fixed64 rx_crc_errors = 14;
+    fixed64 rxUndersizePackets = 39;
+    fixed64 rxOversizePackets = 40;
+    fixed64 rxGem = 43;
+    fixed64 rxGemDropped = 44;
+    fixed64 rxGemIdle = 45;
+    fixed64 rxGemCorrected = 46;
+    fixed64 rxGemIllegal = 47;
+    fixed64 rxFragmentError = 48;
+    fixed64 rxPacketsDropped = 49;
+    fixed64 rxCpuOmciPacketsDropped = 50;
+    fixed64 rxCpu = 51;
+    fixed64 rxOmci = 52;
+    fixed64 rxOmciPacketsCrcError = 53;
+    fixed64 rxFcsErrorPackets = 62;
+
+    fixed64 tx_bytes = 8;
+    fixed64 tx_packets = 9;
+    fixed64 tx_ucast_packets = 10;
+    fixed64 tx_mcast_packets = 11;
+    fixed64 tx_bcast_packets = 12;
+    fixed64 tx_error_packets = 13;
+    fixed64 tx_frames = 28;
+    fixed64 tx_frames_64 = 29;
+    fixed64 tx_frames_65_127 = 30;
+    fixed64 tx_frames_128_255 = 31;
+    fixed64 tx_frames_256_511 = 32;
+    fixed64 tx_frames_512_1023 = 33;
+    fixed64 tx_frames_1024_1518 = 34;
+    fixed64 tx_frames_1519_2047 = 35;
+    fixed64 tx_frames_2048_4095 = 36;
+    fixed64 tx_frames_4096_9216 = 37;
+    fixed64 tx_frames_9217_16383 = 38;
+    fixed64 txUndersizePackets = 41;
+    fixed64 txOversizePackets = 42;
+    fixed64 txGem = 54;
+    fixed64 txCpu = 55;
+    fixed64 txOmci = 56;
+    fixed64 txDroppedIllegalLength = 57;
+    fixed64 txDroppedTpidMiss = 58;
+    fixed64 txDroppedVidMiss = 59;
+    fixed64 txDroppedTotal = 60;
+
+    fixed64 bip_errors = 15;
+    fixed64 bip_units = 61;
+    fixed32 timestamp = 16;
+}
\ No newline at end of file
diff --git a/protos/voltha_protos/extensions.proto b/protos/voltha_protos/extensions.proto
index d372f93..9ac58cf 100755
--- a/protos/voltha_protos/extensions.proto
+++ b/protos/voltha_protos/extensions.proto
@@ -21,6 +21,7 @@
 
 import "voltha_protos/ext_config.proto";
 import "google/protobuf/empty.proto";
+import "voltha_protos/common.proto";
 
 message ValueSet {
     string id = 1;
@@ -162,6 +163,34 @@
      uint32 packets1024To1518octets = 14;
 }
 
+// GetOnuAllocGemHistoryRequest collects GEM and AllocId stats from ONU 
+message GetOnuAllocGemHistoryRequest {
+    google.protobuf.Empty empty = 1;
+}
+
+message OnuGemPortHistoryData {
+    uint32 gemId = 1;
+    uint32 transmittedGEMFrames= 2;
+    uint32 receivedGEMFrames = 3;
+    uint32 receivedPayloadBytes= 4;
+    uint32 transmittedPayloadBytes = 5;
+    uint32 encryptionKeyErrors = 6;
+}
+
+message OnuAllocHistoryData {
+    uint32 allocId = 1;
+    uint32 rxBytes = 2;
+}
+
+message OnuAllocGemHistoryData {
+    OnuAllocHistoryData onuAllocIdInfo = 1;
+    repeated OnuGemPortHistoryData gemPortInfo = 2;
+}
+
+message GetOnuAllocGemHistoryResponse {
+    repeated OnuAllocGemHistoryData onuAllocGemHistoryData = 1;
+}
+
 message GetOnuFecHistory {
     google.protobuf.Empty empty = 1;
 }
@@ -202,6 +231,58 @@
     string onu_sn = 2;
 }
 
+message GetPonStatsRequest {
+    oneof portInfo {
+        string portLabel = 1;
+        fixed32 portId = 2;
+    }
+}
+
+message GetPonStatsResponse {
+    uint32 ponPort = 1;
+    common.PortStatistics portStatistics = 2;
+}
+
+message GetNNIStatsRequest {
+    oneof portInfo {
+        string portLabel = 1;
+        fixed32 portId = 2;
+    }
+}
+
+message GetNNIStatsResponse {
+    uint32 nniPort = 1;
+    common.PortStatistics portStatistics = 2;
+}
+
+// GetOnuStatsFromOltRequest collects GEM and AllocId stats from the OLT for a particular ONU.
+message GetOnuStatsFromOltRequest {
+    fixed32 intfId = 1;
+    fixed32 onuId = 2;
+}
+
+message OnuGemPortInfoFromOlt {
+    uint32 gemId = 1;
+    uint64 rxPackets = 2;
+    uint64 rxBytes = 3;
+    uint64 txPackets = 4;
+    uint64 txBytes = 5;
+}
+
+message OnuAllocIdInfoFromOlt {
+    uint32 allocId = 1;
+    uint64 rxBytes = 2;
+}
+
+message OnuAllocGemStatsFromOltResponse {
+    OnuAllocIdInfoFromOlt allocIdInfo = 1;
+    repeated OnuGemPortInfoFromOlt gemPortInfo = 2;
+}
+
+message GetOnuStatsFromOltResponse {
+    repeated OnuAllocGemStatsFromOltResponse allocGemStatsInfo = 1;
+}
+
 message GetOnuCountersResponse {
     oneof is_intf_id {
         fixed32 intf_id = 1;
@@ -464,6 +545,10 @@
         GetOltRxPowerRequest oltRxPower = 11;
         GetOnuOmciActiveAlarmsRequest onuActiveAlarms  = 12;
         GetOffloadedAppsStatisticsRequest offloadedAppsStats = 13;
+        GetOnuAllocGemHistoryRequest onuAllocGemStats = 14;
+        GetOnuStatsFromOltRequest onuStatsFromOlt = 15;
+        GetPonStatsRequest oltPonStats = 16;
+        GetNNIStatsRequest oltNniStats = 17;
     }
 }
 
@@ -501,6 +586,10 @@
         GetOltRxPowerResponse oltRxPower = 13;
         GetOnuOmciActiveAlarmsResponse onuActiveAlarms = 14;
         GetOffloadedAppsStatisticsResponse offloadedAppsStats = 15;
+        GetOnuAllocGemHistoryResponse onuAllocGemStatsResponse = 16;
+        GetOnuStatsFromOltResponse onuStatsFromOltResponse = 17;
+        GetPonStatsResponse oltPonStatsResponse = 18;
+        GetNNIStatsResponse oltNniStatsResponse = 19;
     }
 }
 
diff --git a/protos/voltha_protos/openolt.proto b/protos/voltha_protos/openolt.proto
index c26be7a..67a09f9 100755
--- a/protos/voltha_protos/openolt.proto
+++ b/protos/voltha_protos/openolt.proto
@@ -23,6 +23,7 @@
 import "voltha_protos/tech_profile.proto";
 import "voltha_protos/ext_config.proto";
 import "voltha_protos/extensions.proto";
+import "voltha_protos/common.proto";
 
 service Openolt {
 
@@ -252,6 +253,41 @@
           body: "*"
         };
     }
+
+    /*
+     * GetAllocIdStatistics takes onuId and allocId as argument.
+     * This method includes a default wait period of 10 secs before collecting the stats.
+     * The caller has to be aware of this wait and handle it accordingly.
+     * Returns AllocId statistics in the form of OnuAllocStatistics structure
+     */
+    rpc GetAllocIdStatistics(OnuPacket) returns (OnuAllocIdStatistics) {
+        option (google.api.http) = {
+            post: "/v1/GetAllocIdStatistics"
+            body: "*"
+        };
+    }
+
+    /*
+     * GetPonPortStatistics takes interface id and type as argument from Interface structure.
+     * Returns Pon port statistics in the form of PonStatsData structure.
+     */
+     rpc GetPonPortStatistics(Interface) returns (common.PortStatistics) {
+        option (google.api.http) = {
+          post: "/v1/GetPonPortStatistics"
+          body: "*"
+        };
+    }
+
+    /*
+     * GetNniPortStatistics takes takes interface id and type as argument from Interface structure.
+     * Returns Nni port statistics in the form of NniStatsData structure
+     */
+     rpc GetNniPortStatistics(Interface) returns (common.PortStatistics) {
+        option (google.api.http) = {
+          post: "/v1/GetNniPortStatistics"
+          body: "*"
+        };
+    }
 }
 
 message Indication {
@@ -263,7 +299,7 @@
         OnuIndication onu_ind = 5;
         OmciIndication omci_ind = 6;
         PacketIndication pkt_ind = 7;
-        PortStatistics port_stats = 8;
+        common.PortStatistics port_stats = 8;
         FlowStatistics flow_stats = 9;
         AlarmIndication alarm_ind= 10;
     }
@@ -377,6 +413,7 @@
 
 message Interface {
     fixed32 intf_id = 1;
+    fixed32 intf_type = 2;
 }
 
 message Heartbeat {
@@ -409,6 +446,7 @@
     fixed32 onu_id = 2;
     fixed32 port_no = 4;
     fixed32 gemport_id = 5;
+    fixed32 alloc_id = 6;
     bytes pkt = 3;
 }
 
@@ -550,49 +588,6 @@
     bytes vendor_specific = 2;
 }
 
-message PortStatistics {
-    fixed32 intf_id = 1;
-    fixed64 rx_bytes = 2;
-    fixed64 rx_packets = 3;
-    fixed64 rx_ucast_packets = 4;
-    fixed64 rx_mcast_packets = 5;
-    fixed64 rx_bcast_packets = 6;
-    fixed64 rx_error_packets = 7;
-    fixed64 rx_frames = 17;
-    fixed64 rx_frames_64 = 18;
-    fixed64 rx_frames_65_127 = 19;
-    fixed64 rx_frames_128_255 = 20;
-    fixed64 rx_frames_256_511 = 21;
-    fixed64 rx_frames_512_1023 = 22;
-    fixed64 rx_frames_1024_1518 = 23;
-    fixed64 rx_frames_1519_2047 = 24;
-    fixed64 rx_frames_2048_4095 = 25;
-    fixed64 rx_frames_4096_9216 = 26;
-    fixed64 rx_frames_9217_16383 = 27;
-    fixed64 rx_crc_errors = 14;
-
-    fixed64 tx_bytes = 8;
-    fixed64 tx_packets = 9;
-    fixed64 tx_ucast_packets = 10;
-    fixed64 tx_mcast_packets = 11;
-    fixed64 tx_bcast_packets = 12;
-    fixed64 tx_error_packets = 13;
-    fixed64 tx_frames = 28;
-    fixed64 tx_frames_64 = 29;
-    fixed64 tx_frames_65_127 = 30;
-    fixed64 tx_frames_128_255 = 31;
-    fixed64 tx_frames_256_511 = 32;
-    fixed64 tx_frames_512_1023 = 33;
-    fixed64 tx_frames_1024_1518 = 34;
-    fixed64 tx_frames_1519_2047 = 35;
-    fixed64 tx_frames_2048_4095 = 36;
-    fixed64 tx_frames_4096_9216 = 37;
-    fixed64 tx_frames_9217_16383 = 38;
-
-    fixed64 bip_errors = 15;
-    fixed32 timestamp = 16;
-}
-
 message OnuStatistics {
     fixed32 intf_id = 1;
     fixed32 onu_id = 2;
@@ -818,6 +813,12 @@
     double rx_power_mean_dbm = 5;
 }
 
+message OnuAllocIdStatistics {
+    fixed32 intfId = 1;
+    fixed32 allocId = 2;
+    fixed64 rxBytes = 3;
+}
+
 enum AlarmState {
     OFF   = 0;
     ON    = 1;