Added new testcases for Cipher suite IPMI cmd.

Testcases covered in this script:
    1) Verify cipher suite IPMI raw cmd for all available channels
including channel 14(current channel).

    2) Verify cipher suite IPMI raw cmd for invalid channels and expects
response code 0xcc.

    3) Verify cipher suite IPMI raw cmd with one byte more and less for
valid channel and expects response code as 0xc7.

Added keyword on lib/ipmi_client.robot to check invalid ipmi cmd.

Added keyword to get invalid channel list in lib/bmc_network_utils.robot.

Tested: Run robot ipmi/test_ipmi_cipher.robot

Signed-off-by: Nagarjun B  <nagarjunb@ami.com>
Change-Id: Id510a6a7bb4c58770fdd04b32bf5ae9f276e2f39
diff --git a/data/ipmi_raw_cmd_table.py b/data/ipmi_raw_cmd_table.py
index 8a9abec..690fba0 100644
--- a/data/ipmi_raw_cmd_table.py
+++ b/data/ipmi_raw_cmd_table.py
@@ -594,4 +594,16 @@
             "0x06 0x38",
         ]
     },
+    'Cipher Suite':
+    {
+        'get':
+        [
+            # raw command, supported algorithm
+            "0x06 0x54",
+            "03 44 81",
+            # 03 - HMAC-SHA256
+            # 44 - sha256_128
+            # 81 - aes_cbc_128
+        ]
+    },
 }
diff --git a/ipmi/test_ipmi_cipher.robot b/ipmi/test_ipmi_cipher.robot
index 6f1eb7d..2962e8f 100644
--- a/ipmi/test_ipmi_cipher.robot
+++ b/ipmi/test_ipmi_cipher.robot
@@ -2,14 +2,24 @@
 Documentation    Module to test IPMI chipher functionality.
 Resource         ../lib/ipmi_client.robot
 Resource         ../lib/openbmc_ffdc.robot
+Resource         ../lib/bmc_network_utils.robot
 Library          ../lib/ipmi_utils.py
 Library          ../lib/var_funcs.py
 Variables        ../data/ipmi_raw_cmd_table.py
 Library          String
 
+
+Suite Setup      IPMI Cipher Suite Setup
 Test Setup       Printn
 Test Teardown    FFDC On Test Case Fail
 
+
+*** Variables  ***
+${cipher_suite}      standard
+&{payload_type}      ipmi=0  sol=1
+@{list_index_value}  0x80  0x00
+
+
 *** Test Cases ***
 
 Verify Supported Ciphers
@@ -41,7 +51,7 @@
 
 
 Verify Supported Cipher Via Getciphers
-    [Documentation]  Verify supported ciphers via IPMI getciphers command.
+    [Documentation]  Verify supported chipers via IPMI getciphers command.
     [Tags]  Verify_Supported_Cipher_Via_Getciphers
 
     # Example output from 'Channel Getciphers IPMI':
@@ -65,3 +75,153 @@
     ${ipmi_channel_cipher_ids}=  Nested Get  id  ${ipmi_channel_ciphers}
     Rpvars  ipmi_channel_cipher_ids
     Valid List  ipmi_channel_cipher_ids  valid_values=${valid_ciphers}
+
+
+Verify Cipher Suite And Supported Algorithms Via IPMI Raw Command
+    [Documentation]  Verify cipher ID and Supported Algorithms for all Available Channels.
+    [Tags]  Verify_Cipher_Suite_And_Supported_Algorithms_Via_IPMI_Raw_Command
+    [Template]  Verify Cipher ID and Supported Algorithm For Channel
+
+    FOR  ${channel}  IN  @{active_channel_list}
+        FOR  ${name}  ${type}  IN  &{payload_type}
+            FOR  ${index_value}  IN  @{list_index_value}
+                # Input Channel   Payload type    Index value 0x80 or 0x00
+                ${channel}        ${type}         ${index_value}
+            END
+        END
+    END
+
+
+Verify Get Cipher Suite Command For Invalid Channels
+    [Documentation]  Verify Get Cipher Suite Command For all Invalid Channels.
+    [Tags]  Verify_Get_Cipher_Suite_Command_For_Invalid_Channels
+    [Template]  Verify Cipher Suite For Invalid Channel
+
+    FOR  ${channel}  IN  @{inactive_channel_list}
+        # Input Channel
+        ${channel}
+    END
+
+
+Verify Get Cipher Suite Raw Command With Invalid Data Length
+    [Documentation]  Verify Get Cipher Suite Raw Command With One Extra and Less Byte.
+    [Tags]  Verify_Get_Cipher_Suite_Raw_Command_With_Invalid_Data_Length
+    [Template]  Verify Cipher Suite Command for Invalid Request Data
+
+    # Byte
+    less
+    extra
+
+
+*** Keywords ***
+
+IPMI Cipher Suite Setup
+    [Documentation]  Get active and inactive/invalid channels from channel_config.json file
+    ...              in list type and set it as suite variable.
+
+    # Get active channel list and set as a suite variable.
+    @{active_channel_list}=  Get Active Ethernet Channel List  current_channel=1
+    Set Suite Variable  @{active_channel_list}
+
+    # Get Inactive/Invalid channel list and set as a suite variable.
+    @{inactive_channel_list}=  Get Invalid Channel Number List
+    Set Suite Variable  @{inactive_channel_list}
+
+Verify Standard Cipher Suite For Channel
+    [Documentation]  Get the supported algorithms from data/ipmi_raw_cmd_table.py and
+    ...              split into list and compare it with the given data list.
+    [Arguments]  ${data_list}  ${channel_number}
+
+    # Description of argument(s):
+    # data_list   cipher suite records in list
+    #  e.g  [01, c0, 11, 03, 44, 81]
+
+    ${supported_algorithms}=  Split String  ${IPMI_RAW_CMD['Cipher Suite']['get'][1]}
+    ${cipher_suite_id}=  Convert To Integer  ${data_list}[2]  base=16
+
+    Should Be Equal  ${data_list}[0]  ${channel_number}
+    Should Be Equal  ${data_list}[1]  c0
+    Should Be Equal As Integers  ${cipher_suite_id}  ${valid_ciphers}[0]
+    List Should Contain Value  ${supported_algorithms}  ${data_list}[3]
+    List Should Contain Value  ${supported_algorithms}  ${data_list}[4]
+    List Should Contain Value  ${supported_algorithms}  ${data_list}[5]
+
+Verify Algorithm by Cipher Suite For Channel
+    [Documentation]  Spilt the given response data, store it in a list.
+    [Arguments]  ${response_data}  ${channel_number}
+
+    # Description of argument(s):
+    # response_data   response data of get channel cipher suite ipmi raw command
+    #   e.g  01 c0 11 03 44 81   ---> list of algorithms by cipher suite (0x80 in request data 3rd byte)
+    # ${channel_number}  Interface channel number
+
+    @{expected_data_list}=  Split String  ${response_data}
+
+    Run Keyword If  '${cipher_suite}' == 'standard'
+    ...  Verify Standard Cipher Suite For Channel  ${expected_data_list}  ${channel_number}
+
+Verify Supported Algorithm For Channel
+    [Documentation]  Compare the supported algorithms got from ipmi_raw_cmd_table with
+    ...              given repsonse.
+    [Arguments]  ${response_data}  ${channel_number}
+
+    # Description of argument(s):
+    # response_data    response data of get channel cipher suite ipmi raw command.
+    # channel_number   Interface Channel Number.
+
+    # expected data will be like " 01 03 44 81 ".
+    ${expected_data}=  Catenate  ${channel_number}  ${IPMI_RAW_CMD['Cipher Suite']['get'][1]}
+
+    Should Be Equal  ${expected_data}  ${response_data}
+
+Verify Cipher ID and Supported Algorithm For Channel
+    [Documentation]  Verify Cipher ID and Supported Algorithm on given channel.
+    [Arguments]  ${channel_num}  ${payload_type}  ${index_value}
+
+    # Description of argument(s):
+    # channel_num   Interface channel number.
+    # payload_type   IPMI(0x00) or Sol(0x01).
+    # index_value    0x80 for list algorithm by cipher suite.
+    #                0x00 for supported algorithms.
+
+    ${cmd}=  Catenate  ${IPMI_RAW_CMD['Cipher Suite']['get'][0]}
+    ...  ${channel_num} ${payload_type} ${index_value}
+
+    ${resp}=  Run External IPMI Raw Command  ${cmd}
+    ${resp}=  Strip String  ${resp}
+
+    # channel 14 represents current channel in which we send request.
+    ${channel_num}=  Run Keyword If  '${channel_num}' == '14'
+    ...  Convert To Hex  ${CHANNEL_NUMBER}  length=2
+    ...  ELSE
+    ...  Convert To Hex  ${channel_num}  length=2
+
+    Run Keyword If  '${index_value}' == '0x80'
+    ...  Verify Algorithm by Cipher Suite For Channel  ${resp}  ${channel_num}
+    ...  ELSE
+    ...  Verify Supported Algorithm For Channel  ${resp}  ${channel_num}
+
+Verify Cipher Suite For Invalid Channel
+   [Documentation]  Execute cipher suite ipmi cmd for invalid channel and verify Error code.
+   [Arguments]  ${channel_number}
+
+   # Description of argument(s):
+   # channel_number   Interface channel number.
+
+   ${cmd}=  Catenate  ${IPMI_RAW_CMD['Cipher Suite']['get'][0]} ${channel_number} 00 00
+
+   Verify Invalid IPMI Command  ${cmd}  0xcc
+
+Verify Cipher Suite Command for Invalid Request Data
+   [Documentation]  Verify Cipher Suite Command with Invalid data Length.
+   [Arguments]  ${byte_length}
+
+   # Description of argument(s):
+   # byte_length   extra or less.
+
+   ${req_cmd}=  Run Keyword If  '${byte_length}' == 'less'
+   ...  Catenate  ${IPMI_RAW_CMD['Cipher Suite']['get'][0]} ${CHANNEL_NUMBER} 00
+   ...  ELSE
+   ...  Catenate  ${IPMI_RAW_CMD['Cipher Suite']['get'][0]} ${CHANNEL_NUMBER} 00 00 01
+
+   Verify Invalid IPMI Command  ${req_cmd}  0xc7
diff --git a/lib/bmc_network_utils.robot b/lib/bmc_network_utils.robot
index dfa09d1..9ac2af1 100644
--- a/lib/bmc_network_utils.robot
+++ b/lib/bmc_network_utils.robot
@@ -688,6 +688,21 @@
 
     [Return]  ${valid_channel_number_interface_name}
 
+Get Invalid Channel Number List
+    [Documentation]  Get Invalid Channel and return as list.
+
+    ${available_channels}=  Get Channel Number For All Interface
+    # Get the channel which medium_type as 'reserved' and append it to a list.
+    @{invalid_channel_number_list}=  Create List
+
+    FOR  ${channel_number}  ${values}  IN  &{available_channels}
+       Run Keyword If  '${values['channel_info']['medium_type']}' == 'reserved'
+       ...  Append To List  ${invalid_channel_number_list}  ${channel_number}
+    END
+
+    [Return]  ${invalid_channel_number_list}
+
+
 Get Channel Number For Valid Ethernet Interface
     [Documentation]  Get channel number for all ethernet interface.
     [Arguments]  ${valid_channel_number_interface_name}
@@ -704,8 +719,26 @@
 
     [Return]  ${channel_number_list}
 
+
+Get Current Channel Name List
+    [Documentation]  Get Current Channel name and append it to active channel list.
+    [Arguments]  ${channel_list}  ${channel_config_json}
+
+    # Description of Arguments
+    # ${channel_list}  -  list Contains all availabe active channels.
+    # ${channel_config_json} - output of /usr/share/ipmi-providers/channel_config.json file.
+
+    FOR  ${channel_number}  ${values}  IN  &{channel_config_json}
+        Run Keyword If  '${values['name']}' == 'SELF'
+        ...  Run Keyword  Append To List  ${channel_list}  ${channel_number}
+    END
+
+    [Return]  ${channel_list}
+
+
 Get Active Ethernet Channel List
-    [Documentation]  Get Available Channel.
+    [Documentation]  Get Available channels from channel_config.json file and return as list.
+    [Arguments]  ${current_channel}=${0}
 
     ${valid_channel_number_interface_names}=  Get Channel Number For All Interface
 
@@ -714,4 +747,8 @@
     ${channel_number_list}=  Get Channel Number For Valid Ethernet Interface
     ...  ${valid_channel_number_interface_name}
 
+    Return From Keyword If  ${current_channel} == 0  ${channel_number_list}
+    ${channel_number_list}=  Get Current Channel Name List
+    ...  ${channel_number_list}  ${valid_channel_number_interface_names}
+
     [Return]  ${channel_number_list}
diff --git a/lib/ipmi_client.robot b/lib/ipmi_client.robot
index 8bee9da..52e46c7 100755
--- a/lib/ipmi_client.robot
+++ b/lib/ipmi_client.robot
@@ -560,3 +560,16 @@
     ${resp}=  Split String  ${resp}
 
     [Return]  ${resp}
+
+
+Verify Invalid IPMI Command
+    [Documentation]  Execute invalid IPMI command and verify with given response code.
+    [Arguments]  ${ipmi_cmd}  ${error_code}=0xc9
+
+    #  Description Of Arguments.
+    #  ${ipmi_cmd}   - IPMI raw cmd with invalid data length.
+    #  ${error_code} - Expected error code e.g 0xc7, 0xcc.
+
+    ${resp}=  Run External IPMI Raw Command  ${ipmi_cmd}  fail_on_err=0
+
+    Should Contain  ${resp}  rsp=${error_code}