[VOL-4902] Delivery OMCI counter statistics

Precondition is release of voltctl at least 1.8.1!!!

Change-Id: Ic1ee9f2cacb8fb8b00694208e6eb1531b18568cb
diff --git a/VERSION b/VERSION
index 9462efa..22ac5d0 100644
--- a/VERSION
+++ b/VERSION
@@ -1 +1 @@
-2.11.8
+2.11.9
diff --git a/libraries/voltctl.robot b/libraries/voltctl.robot
index c1fdc82..c027eef 100755
--- a/libraries/voltctl.robot
+++ b/libraries/voltctl.robot
@@ -1152,3 +1152,29 @@
         Set To Dictionary    ${groupmetric_dict}    ${name}=${subdict}
     END
     [return]    ${groupmetric_dict}
+
+# openonu-go-adapter OMCI counter statistics
+Get OMCI counter statistics
+    [Documentation]    Delivers the openonu-go-adapter OMCI counter statistics
+    [Arguments]    ${dev_id}
+    ${rc}    ${output}=    Run and Return Rc and Output
+    ...    voltctl -c ${VOLTCTL_CONFIG} device getextval onu_omci_stats ${dev_id}
+    [return]    ${rc}    ${output}
+
+Get OMCI counter statistics dictionary
+    [Documentation]    Delivers the openonu-go-adapter OMCI counter statistics as dictionary
+    [Arguments]    ${dev_id}
+    ${rc}    ${output}=    Get OMCI counter statistics    ${dev_id}
+    # check rc
+    &{output_dict}= 	Create Dictionary
+    Return From Keyword If    ${rc} != 0    ${rc}    ${output_dict}
+    @{Results}=    Split String    ${output}    \n
+    FOR    ${Line}    IN     @{Results}
+        ${matched}=    Set Variable    False
+        @{words}=    Split String    ${Line}
+        ${name}=    Set Variable    ${words[0]}
+        ${value}=    Set Variable    ${words[1]}
+        ${name}=    Remove String    ${name}    :
+        Set To Dictionary    ${output_dict}    ${name}    ${value}
+    END
+    [return]    ${rc}    ${output_dict}
diff --git a/tests/openonu-go-adapter/Voltha_ONUNegativeStateTests.robot b/tests/openonu-go-adapter/Voltha_ONUNegativeStateTests.robot
index 99d5a62..69fd82a 100755
--- a/tests/openonu-go-adapter/Voltha_ONUNegativeStateTests.robot
+++ b/tests/openonu-go-adapter/Voltha_ONUNegativeStateTests.robot
@@ -110,6 +110,18 @@
     Build ONU Device Id List    ${list_onu_device_id}
     Run Keyword If    ${print2console}    Log    Check for device events that indicate a failed OMCI communication.   console=yes
     Wait Until Keyword Succeeds    ${timeout}    5s    Validate Failed OMCI Communication All ONUs    ${list_onu_device_id}
+    # Validate OMCI counter statistics
+    Build ONU Device Id List    ${list_onu_device_id}
+    FOR    ${onu_device_id}     IN      @{list_onu_device_id}
+        # get ONU OMCI counter statistics per ONU
+        ${rc}    ${OMCI_counter_dict}=    Get OMCI counter statistics dictionary   ${onu_device_id}
+        ${onu_sn}=    Run Keyword If    ${rc} != 0    Get SN From Device ID    ${onu_device_id}
+        Run Keyword If    ${rc} != 0    FAIL    Could not get ONU OMCI counter statistic of ONU ${onu_sn}!
+        ${TxOmciCounterRetries}=    Get From Dictionary    ${OMCI_counter_dict}    TxOmciCounterRetries
+        ${TxOmciCounterTimeouts}=   Get From Dictionary    ${OMCI_counter_dict}    TxOmciCounterTimeouts
+        Should Be True   0 < ${TxOmciCounterRetries}       No TxOmciCounterRetries found in baseline OMCI!
+        Should Be True   0 < ${TxOmciCounterTimeouts}      No TxOmciCounterTimeouts found in baseline OMCI!
+    END
     [Teardown]    Run Keywords   Printout ONU Serial Number and Device Id    print2console=${print2console}
     ...    AND    Run Keyword If    ${logging}    Collect Logs
     ...    AND    Stop Logging    ONUStateTest
diff --git a/tests/openonu-go-adapter/Voltha_ONUTemplateTests.robot b/tests/openonu-go-adapter/Voltha_ONUTemplateTests.robot
index f021982..3e90bd0 100755
--- a/tests/openonu-go-adapter/Voltha_ONUTemplateTests.robot
+++ b/tests/openonu-go-adapter/Voltha_ONUTemplateTests.robot
@@ -270,6 +270,26 @@
     Run Keyword And Continue On Failure    Wait Until Keyword Succeeds    ${timeout}    3s
     ...    Verify MIB Template Data Available    ${INFRA_NAMESPACE}
     ${MibTemplateDataBaseline}=    Get ONU MIB Template Data    ${INFRA_NAMESPACE}
+    # get ONU OMCI counter statistics
+    ${onu_device_id}=    Get Device ID From SN    ${src['onu']}
+    ${rc}    ${OMCI_counter_dict}=    Get OMCI counter statistics dictionary   ${onu_device_id}
+    Run Keyword If    ${rc} != 0    FAIL    Could not get baseline ONU OMCI counter statistic of ONU ${src['onu']}!
+    ${BaseTxArFrames}=    Get From Dictionary    ${OMCI_counter_dict}     BaseTxArFrames
+    ${BaseRxAkFrames}=    Get From Dictionary    ${OMCI_counter_dict}     BaseRxAkFrames
+    Should Be Equal As Integers   ${BaseTxArFrames}   ${BaseRxAkFrames}   Number of baseline Rx and Tx frames do not match!
+    # some additional checks
+    ${ExtRxAkFrames}=           Get From Dictionary   ${OMCI_counter_dict}   ExtRxAkFrames
+    ${ExtRxNoAkFrames}=         Get From Dictionary   ${OMCI_counter_dict}   ExtRxNoAkFrames
+    ${ExtTxArFrames}=           Get From Dictionary   ${OMCI_counter_dict}   ExtTxArFrames
+    ${ExtTxNoArFrames}=         Get From Dictionary   ${OMCI_counter_dict}   ExtTxNoArFrames
+    ${TxOmciCounterRetries}=    Get From Dictionary   ${OMCI_counter_dict}   TxOmciCounterRetries
+    ${TxOmciCounterTimeouts}=   Get From Dictionary   ${OMCI_counter_dict}   TxOmciCounterTimeouts
+    Should Be Equal   0   ${ExtRxAkFrames}          ExtRxAkFrames found in baseline OMCI!
+    Should Be Equal   0   ${ExtRxNoAkFrames}        ExtRxNoAkFrames found in baseline OMCI!
+    Should Be Equal   0   ${ExtTxArFrames}          ExtTxArFrames found in baseline OMCI!
+    Should Be Equal   0   ${ExtTxNoArFrames}        ExtTxNoArFrames found in baseline OMCI!
+    Should Be Equal   0   ${TxOmciCounterRetries}   TxOmciCounterRetries found in baseline OMCI!
+    Should Be Equal   0   ${TxOmciCounterTimeouts}  TxOmciCounterTimeouts found in baseline OMCI!
     Delete All Devices and Verify
     Delete MIB Template Data    ${INFRA_NAMESPACE}
     # Restart BBSIM with OMCI Extended Message
@@ -307,6 +327,23 @@
     ${MibTemplateDataExtended}=    Remove String Using Regexp    ${MibTemplateDataExtended}    ${remove_regexp}
     # end of handling for VOL-4721
     Should Be Equal As Strings    ${MibTemplateDataBaseline}    ${MibTemplateDataExtended}    MIB Templates not equal!
+    # get ONU OMCI counter statistics
+    ${onu_device_id}=    Get Device ID From SN    ${src['onu']}
+    ${rc}    ${OMCI_counter_dict}=    Get OMCI counter statistics dictionary   ${onu_device_id}
+    Run Keyword If    ${rc} != 0    FAIL    Could not get extended ONU OMCI counter statistic of ONU ${src['onu']}!
+    ${ExtTxArFrames}=    Get From Dictionary    ${OMCI_counter_dict}    ExtTxArFrames
+    ${ExtRxAkFrames}=    Get From Dictionary    ${OMCI_counter_dict}    ExtRxAkFrames
+    Should Be Equal As Integers   ${ExtTxArFrames}   ${ExtRxAkFrames}   Number of extended Rx and Tx frames do not match!
+    # check baseline and extended OMCI frames counter
+    ${TxArFrames_compare}=    Evaluate    ${BaseTxArFrames}*0.05 > ${ExtTxArFrames}
+    Should Be True    ${TxArFrames_compare}   Comparison of TxArFrames failed (${BaseTxArFrames}:${ExtTxArFrames})!
+    ${RxAkFrames_compare}=    Evaluate    ${BaseRxAkFrames}*0.05 > ${ExtRxAkFrames}
+    Should Be True    ${RxAkFrames_compare}   Comparison of RxAkFrames failed (${BaseRxAkFrames}:${ExtRxAkFrames})!
+    # some additional checks
+    ${TxOmciCounterRetries}=    Get From Dictionary   ${OMCI_counter_dict}   TxOmciCounterRetries
+    ${TxOmciCounterTimeouts}=   Get From Dictionary   ${OMCI_counter_dict}   TxOmciCounterTimeouts
+    Should Be Equal   0   ${TxOmciCounterRetries}   TxOmciCounterRetries found in extended OMCI!
+    Should Be Equal   0   ${TxOmciCounterTimeouts}  TxOmciCounterTimeouts found in extended OMCI!
     # Restart BBSIM with OMCI Message Version read at begin of test
     ${extra_helm_flags}=    Catenate
     ...    --set onu=2,pon=2,controlledActivation=only-onu,injectOmciUnknownAttributes=true,injectOmciUnknownMe=true
diff --git a/tests/software-upgrades/ONU_Upgrade.robot b/tests/software-upgrades/ONU_Upgrade.robot
index 7d3930e..aa7beda 100755
--- a/tests/software-upgrades/ONU_Upgrade.robot
+++ b/tests/software-upgrades/ONU_Upgrade.robot
@@ -746,6 +746,25 @@
     Log    ONU ${src['onu']}: downloaded SW upgrade in ${baselineonu} sec for OMCI baseline message.    console=yes
     Append To File    ${outputfile}
     ...    \r\nONU ${src['onu']} downloaded SW upgrade in ${baselineonu} sec for OMCI baseline message.
+    # get ONU OMCI counter statistics
+    ${onu_device_id}=    Get Device ID From SN    ${src['onu']}
+    ${rc}    ${OMCI_counter_dict}=    Get OMCI counter statistics dictionary   ${onu_device_id}
+    Run Keyword If    ${rc} != 0    FAIL    Could not get baseline ONU OMCI counter statistic of ONU ${src['onu']}!
+    ${BaseTxNoArFrames}=    Get From Dictionary   ${OMCI_counter_dict}   BaseTxNoArFrames
+    Should Be True   0 < ${BaseTxNoArFrames}    No BaseTxNoArFrames found in baseline OMCI!
+    # some additional checks
+    ${ExtRxAkFrames}=           Get From Dictionary   ${OMCI_counter_dict}   ExtRxAkFrames
+    ${ExtRxNoAkFrames}=         Get From Dictionary   ${OMCI_counter_dict}   ExtRxNoAkFrames
+    ${ExtTxArFrames}=           Get From Dictionary   ${OMCI_counter_dict}   ExtTxArFrames
+    ${ExtTxNoArFrames}=         Get From Dictionary   ${OMCI_counter_dict}   ExtTxNoArFrames
+    ${TxOmciCounterRetries}=    Get From Dictionary   ${OMCI_counter_dict}   TxOmciCounterRetries
+    ${TxOmciCounterTimeouts}=   Get From Dictionary   ${OMCI_counter_dict}   TxOmciCounterTimeouts
+    Should Be Equal   0   ${ExtRxAkFrames}          ExtRxAkFrames found in baseline OMCI!
+    Should Be Equal   0   ${ExtRxNoAkFrames}        ExtRxNoAkFrames found in baseline OMCI!
+    Should Be Equal   0   ${ExtTxArFrames}          ExtTxArFrames found in baseline OMCI!
+    Should Be Equal   0   ${ExtTxNoArFrames}        ExtTxNoArFrames found in baseline OMCI!
+    Should Be Equal   0   ${TxOmciCounterRetries}   TxOmciCounterRetries found in baseline OMCI!
+    Should Be Equal   0   ${TxOmciCounterTimeouts}  TxOmciCounterTimeouts found in baseline OMCI!
     Delete All Devices and Verify
     # Restart BBSIM with OMCI Extended Message
     ${extra_helm_flags}=    Run Keyword If    ${is_omcc_extended}     Catenate    --set omccVersion=${omcc_version}
@@ -763,6 +782,20 @@
     ...    \r\nONU ${src['onu']} downloaded SW upgrade in ${extendedonu} sec for OMCI extended message.
     ${duration_compare}=    Evaluate    ${baselineonu}*0.8 > ${extendedonu}
     Should Be True    ${duration_compare}   SW Upgrade too slow for OMCI extended message!
+    # get ONU OMCI counter statistics
+    ${onu_device_id}=    Get Device ID From SN    ${src['onu']}
+    ${rc}    ${OMCI_counter_dict}=    Get OMCI counter statistics dictionary   ${onu_device_id}
+    Run Keyword If    ${rc} != 0    FAIL    Could not get extended ONU OMCI counter statistic of ONU ${src['onu']}!
+    ${ExtTxNoArFrames}=    Get From Dictionary    ${OMCI_counter_dict}    ExtTxNoArFrames
+    Should Be True   0 < ${ExtTxNoArFrames}    No ExtTxNoArFrames found in extended OMCI!
+    # check baseline and extended OMCI frames counter
+    ${TxNoArFrames_compare}=   Evaluate   ${BaseTxNoArFrames}*0.05 > ${ExtTxNoArFrames}
+    Should Be True    ${TxNoArFrames_compare}   Comparison of TxNoArFrames failed (${BaseTxNoArFrames}:${ExtTxNoArFrames})!
+    # some additional checks
+    ${TxOmciCounterRetries}=    Get From Dictionary   ${OMCI_counter_dict}   TxOmciCounterRetries
+    ${TxOmciCounterTimeouts}=   Get From Dictionary   ${OMCI_counter_dict}   TxOmciCounterTimeouts
+    Should Be Equal   0   ${TxOmciCounterRetries}   TxOmciCounterRetries found in extended OMCI!
+    Should Be Equal   0   ${TxOmciCounterTimeouts}  TxOmciCounterTimeouts found in extended OMCI!
     # Restart BBSIM with OMCI Message Version read at begin of test
     ${extra_helm_flags}=    Catenate    --set omccVersion=${omcc_version}
     Run Keyword Unless   ${is_omcc_extended}   Restart BBSIM by Helm Charts   ${NAMESPACE}   extra_helm_flags=${extra_helm_flags}