1*** Settings ***
2
3Documentation          Module to test IPMI network functionality.
4Resource               ../lib/ipmi_client.robot
5Resource               ../lib/openbmc_ffdc.robot
6Resource               ../lib/bmc_network_utils.robot
7Library                ../lib/ipmi_utils.py
8Library                ../lib/gen_robot_valid.py
9Library                ../lib/var_funcs.py
10Library                ../lib/bmc_network_utils.py
11Variables              ../data/ipmi_raw_cmd_table.py
12
13Suite Setup            Redfish.Login
14Test Setup             Printn
15Test Teardown          FFDC On Test Case Fail
16
17Force Tags             IPMI_Network_Verification
18
19*** Variables ***
20
21${set_mac_address}                      02:f4:43:24:e7:1a
22${Invalid_mac_address}                  11:f4:43:24:e7:1a
23
24
25*** Test Cases ***
26
27Retrieve IP Address Via IPMI And Verify Using Redfish
28    [Documentation]  Retrieve IP address using IPMI and verify using Redfish.
29    [Tags]  Retrieve_IP_Address_Via_IPMI_And_Verify_Using_Redfish
30
31    ${active_channel_config}=  Get Active Channel Config
32    FOR  ${channel_number}  IN  @{active_channel_config.keys()}
33      Verify Channel Info  ${channel_number}  IPv4StaticAddresses  ${active_channel_config}
34    END
35
36Retrieve Default Gateway Via IPMI And Verify
37    [Documentation]  Retrieve default gateway via IPMI and verify it's existence on the BMC.
38    [Tags]  Retrieve_Default_Gateway_Via_IPMI_And_Verify
39
40    ${lan_print_ipmi}=  Get LAN Print Dict
41
42    Verify Gateway On BMC  ${lan_print_ipmi['Default Gateway IP']}
43
44
45Retrieve MAC Address Via IPMI And Verify Using Redfish
46    [Documentation]  Retrieve MAC address via IPMI and verify using Redfish.
47    [Tags]  Retrieve_MAC_Address_Via_IPMI_And_Verify_Using_Redfish
48
49    ${active_channel_config}=  Get Active Channel Config
50    FOR  ${channel_number}  IN  @{active_channel_config.keys()}
51      Verify Channel Info  ${channel_number}  MACAddress  ${active_channel_config}
52    END
53
54
55Test Valid IPMI Channels Supported
56    [Documentation]  Verify IPMI channels supported on a given system.
57    [Tags]  Test_Valid_IPMI_Channels_Supported
58
59    ${channel_count}=  Get Physical Network Interface Count
60    Should Be True  ${channel_count} > 0
61    ...  msg=IPMI Lan channel support expected > 0 but found ${channel_count}
62    ${channel_count}=  Evaluate  ${channel_count} + 1
63
64    # Note: IPMI network channel logically starts from 1.
65    FOR  ${channel_number}  IN RANGE  1  ${channel_count}
66      Run IPMI Standard Command  lan print ${channel_number}
67    END
68
69
70Test Invalid IPMI Channel Response
71    [Documentation]  Verify invalid IPMI channels supported response.
72    [Tags]  Test_Invalid_IPMI_Channel_Response
73
74    # Example of invalid channel:
75    # $ ipmitool -I lanplus -H xx.xx.xx.xx -P password lan print 3
76    # Get Channel Info command failed: Parameter out of range
77    # Invalid channel: 3
78
79    @{inactive_channel_list}=  Get Invalid Channel Number List
80    FOR  ${channel_number}  IN  @{inactive_channel_list}
81        ${stdout}=  Run IPMI Standard Command
82        ...  lan print ${channel_number}  fail_on_err=${0}
83        Should Contain  ${stdout}  Invalid channel
84        ...  msg=IPMI channel ${channel_number} is invalid but seen working.
85    END
86
87
88Get IP Address Source And Verify Using Redfish
89    [Documentation]  Get IP address source and verify it using Redfish.
90    [Tags]  Get_IP_Address_Source_And_Verify_Using_Redfish
91
92    ${active_channel_config}=  Get Active Channel Config
93    ${lan_config}=  Get LAN Print Dict  ${CHANNEL_NUMBER}
94
95    ${ipv4_addresses}=  Redfish.Get Attribute
96    ...  /redfish/v1/Managers/${MANAGER_ID}/EthernetInterfaces/${active_channel_config['${CHANNEL_NUMBER}']['name']}
97    ...  IPv4Addresses
98
99    FOR  ${ipv4_address}  IN  @{ipv4_addresses}
100      ${ip_address_source}=
101      ...  Set Variable if  '${ipv4_address['Address']}' == '${lan_config['IP Address']}'
102      ...  ${ipv4_address['AddressOrigin']} Address
103      Exit For Loop IF  "${ip_address_source}" != 'None'
104    END
105
106    Valid Value  lan_config['IP Address Source']  ['${ip_address_source}']
107
108
109Verify Get Set In Progress
110    [Documentation]  Verify Get Set In Progress which belongs to LAN Configuration Parameters
111    ...              via IPMI raw Command.
112    [Tags]  Verify_Get_Set_In_Progress
113
114    ${ipmi_output}=  Run IPMI Command
115    ...  ${IPMI_RAW_CMD['LAN_Config_Params']['Get'][0]} ${CHANNEL_NUMBER} 0x00 0x00 0x00
116
117    ${ipmi_output}=  Split String  ${ipmi_output}
118    ${set_in_progress_value}=  Set Variable  ${ipmi_output[1]}
119
120    # 00b = set complete.
121    # 01b = set in progress.
122    Should Contain Any  ${set_in_progress_value}  00  01
123
124
125Verify Cipher Suite Entry Count
126    [Documentation]  Verify cipher suite entry count which belongs to LAN Configuration Parameters
127    ...              via IPMI raw Command.
128    [Tags]  Verify_Cipher_Suite_Entry_Count
129
130    ${ipmi_output}=  Run IPMI Command
131    ...  ${IPMI_RAW_CMD['LAN_Config_Params']['Get'][0]} ${CHANNEL_NUMBER} 0x16 0x00 0x00
132    ${cipher_suite_entry_count}=  Split String  ${ipmi_output}
133
134    # Convert minor cipher suite entry count from BCD format to integer. i.e. 01 to 1.
135    ${cipher_suite_entry_count[1]}=  Convert To Integer  ${cipher_suite_entry_count[1]}
136    ${cnt}=  Get length  ${valid_ciphers}
137
138    Should be Equal  ${cipher_suite_entry_count[1]}  ${cnt}
139
140
141Verify Authentication Type Support
142    [Documentation]  Verify authentication type support which belongs to LAN Configuration Parameters
143    ...              via IPMI raw Command.
144    [Tags]  Verify_Authentication_Type_Support
145
146    ${ipmi_output}=  Run IPMI Command
147    ...  ${IPMI_RAW_CMD['LAN_Config_Params']['Get'][0]} ${CHANNEL_NUMBER} 0x01 0x00 0x00
148
149    ${authentication_type_support}=  Split String  ${ipmi_output}
150    # All bits:
151    # 1b = supported
152    # 0b = authentication type not available for use
153    # [5] - OEM proprietary (per OEM identified by the IANA OEM ID in the RMCP Ping Response)
154    # [4] - straight password / key
155    # [3] - reserved
156    # [2] - MD5
157    # [1] - MD2
158    # [0] - none
159    Should Contain Any  ${authentication_type_support[1]}  00  01  02  03  04  05
160
161
162Verify Set In Progress
163    [Documentation]  Verify Set In Progress which belongs to LAN Configuration Parameters
164    ...              via IPMI raw Command.
165    [Tags]  Verify_Set_In_Progress
166
167   # Set the Set In Progress
168    ${output_msg}=  Run Inband IPMI Raw Command
169    ...  ${IPMI_RAW_CMD['LAN_Config_Params']['Set'][0]} ${CHANNEL_NUMBER} 0x00 0x01
170
171    # Get the Set In Progress
172    ${ipmi_output}=  Run Inband IPMI Raw Command
173    ...  ${IPMI_RAW_CMD['LAN_Config_Params']['Get'][0]} ${CHANNEL_NUMBER} 0x00 0x00 0x00
174
175    # Verify the response
176    ${ipmi_output}=  Split String  ${ipmi_output}
177    ${set_in_progress_value}=  Set Variable  ${ipmi_output[1]}
178
179    # 01b = set in progress.
180    Should be Equal  ${set_in_progress_value}  01
181
182    # set back to default.
183    Run IPMI Command  ${IPMI_RAW_CMD['LAN_Config_Params']['Set'][0]} ${CHANNEL_NUMBER} 0x00 0x00
184
185    # Get the Set In Progress.
186    ${ipmi_output}=  Run Inband IPMI Raw Command
187    ...  ${IPMI_RAW_CMD['LAN_Config_Params']['Get'][0]} ${CHANNEL_NUMBER} 0x00 0x00 0x00
188
189    # Verify the response.
190    ${ipmi_output}=  Split String  ${ipmi_output}
191    ${set_in_progress_value}=  Set Variable  ${ipmi_output[1]}
192
193    # 00b = set complete.
194    Should be Equal  ${set_in_progress_value}  00
195
196
197Verify Invalid Set MAC Address Via IPMI
198    [Documentation]  Verify Get and Set MAC address via IPMI.
199    [Tags]  Verify_Invalid_Set_MAC_Address_Via_IPMI
200
201    # MAC to hexa string.
202    ${Invalid_mac_address_hex}=  Mac Address To Hex String  ${Invalid_mac_address}
203
204    # Set MAC Address with invalid data.
205    ${cmd}=  Catenate  ${IPMI_RAW_CMD['LAN_Config_Params']['Set'][0]} ${CHANNEL_NUMBER}
206    ...  0x05 ${Invalid_mac_address_hex}
207    ${ipmi_set_output}=  Run Inband IPMI Raw Command  ${cmd}  fail_on_err=0
208
209    Should Contain  ${ipmi_set_output}  ${IPMI_RAW_CMD['LAN_Config_Params']['Set'][3]}
210
211
212Verify Get And Set MAC Address Via IPMI
213    [Documentation]  Verify Get and Set MAC address via IPMI.
214    [Tags]  Verify_Get_And_Set_MAC_Address_Via_IPMI
215    [Setup]  Fetch The Default Mac Address
216    [Teardown]  Set Default Mac And Verify  ${ipmi_default_mac_split}
217
218    # MAC to hexa string.
219    ${mac_address_hex}=  Mac Address To Hex String  ${set_mac_address}
220
221    # Set the MAC address.
222    ${cmd}=  Catenate  ${IPMI_RAW_CMD['LAN_Config_Params']['Set'][0]} ${CHANNEL_NUMBER}
223    ...  0x05 ${mac_address_hex}
224    ${ipmi_set_output}=  Run Inband IPMI Raw Command  ${cmd}  fail_on_err=0
225
226    # Get the MAC address and verify.
227    ${ipmi_output}=  Run Inband IPMI Raw Command
228    ...  ${IPMI_RAW_CMD['LAN_Config_Params']['Get'][0]} ${CHANNEL_NUMBER} 0x05 0x00 0x00
229    ${ipmi_output_split}=  Split String  ${ipmi_output}
230    ${get_mac}=   Evaluate  ":".join(${ipmi_output_split[1:]})
231
232    Should be Equal  ${get_mac}  ${set_mac_address}
233
234
235Verify Cipher Suite Privilege
236    [Documentation]  Verify cipher suite privilege which belongs to LAN Configuration Parameters
237    ...              via IPMI raw Command.
238    [Tags]  Verify_Cipher_Suite_Privilege
239
240    # Get the Cipher Suite privilege and verify the response.
241    ${ipmi_output}=  Run Inband IPMI Raw Command
242    ...  ${IPMI_RAW_CMD['LAN_Config_Params']['Get'][0]} ${CHANNEL_NUMBER} 0x18 0x00 0x00
243    ${cipher_suite_privilege}=  Split String  ${ipmi_output}
244
245    Should be Equal  '${${cipher_suite_privilege}[0]}'  '11'
246    # 00b = reserved.
247    Should Contain Any  '${cipher_suite_privilege[1]}'  '00'  '0'
248
249    ${cipher_suite_privilege_length}=  Get length  ${cipher_suite_privilege}
250    Should be Equal  '${cipher_suite_privilege_length}'  '10'
251
252    #44b = Maximum privilege for cipher suite.
253    FOR  ${channel_number}  IN RANGE  2  ${cipher_suite_privilege_length}
254      Should be Equal  '${cipher_suite_privilege[${channel_number}]}'  '44'
255    END
256
257
258Verify Set On Authentication Type
259    [Documentation]  Verify Set On Authentication Type which belongs to LAN Configuration Parameters
260    ...              via IPMI raw Command.
261    [Tags]  Verify_Set_On_Authentication_Type
262
263    # Set Authentication Type and expect error.
264    ${ipmi_output}=  Run Inband IPMI Raw Command
265    ...  ${IPMI_RAW_CMD['LAN_Config_Params']['Set'][0]} ${CHANNEL_NUMBER} 0x01 0x01  fail_on_err=0
266
267    Should Contain  ${ipmi_output}  ${IPMI_RAW_CMD['LAN_Config_Params']['Set'][2]}
268
269
270Verify IP Address Source Set To Address Loaded By BIOS
271    [Documentation]  Verify Set IP Address Source to address loaded by BIOS or system software via IPMI.
272    [Tags]  Verify_IP_Address_Source_Set_To_Address_Loaded_By_BIOS
273
274    # Set IP address source to address loaded by BIOS or system software.
275    ${ipmi_output}=  Run Keyword and Expect Error  *${IPMI_RAW_CMD['LAN_Config_Params']['Set'][3]}*
276    ...  Run Inband IPMI Raw Command
277    ...  ${IPMI_RAW_CMD['LAN_Config_Params']['Set'][0]} 0x0${CHANNEL_NUMBER} 0x04 0x03
278
279
280Verify IP Address Source Set To Address Obtained By BMC
281    [Documentation]  Verify Set IP Address Source to address obtained by,
282    ...              BMC running other address assignment protocol via IPMI.
283    [Tags]  Verify_IP_Address_Source_Set_To_Address_Obtained_By_BMC
284
285    # Set IP address source to address obtained by BMC running other address assignment protocol
286    ${ipmi_output}=  Run Keyword and Expect Error  *${IPMI_RAW_CMD['LAN_Config_Params']['Set'][3]}*
287    ...  Run Inband IPMI Raw Command
288    ...  ${IPMI_RAW_CMD['LAN_Config_Params']['Set'][0]} 0x0${CHANNEL_NUMBER} 0x04 0x04
289
290
291Verify IP Address Source Set To Unspecified Address Source
292    [Documentation]  Verify Set IP Address source to unspecified address source via IPMI.
293    [Tags]  Verify_IP_Address_Source_Set_To_Unspecified_Address_Source
294
295    # Set IP address source to unspecified address source.
296    ${ipmi_output}=  Run Keyword and Expect Error  *${IPMI_RAW_CMD['LAN_Config_Params']['Set'][3]}*
297    ...  Run Inband IPMI Raw Command
298    ...  ${IPMI_RAW_CMD['LAN_Config_Params']['Set'][0]} 0x0${CHANNEL_NUMBER} 0x04 0x00
299
300
301*** Keywords ***
302
303Get Physical Network Interface Count
304    [Documentation]  Return valid physical network interfaces count.
305    # Example:
306    # link/ether 22:3a:7f:70:92:cb brd ff:ff:ff:ff:ff:ff
307    # link/ether 0e:8e:0d:6b:e9:e4 brd ff:ff:ff:ff:ff:ff
308
309    ${mac_entry_list}=  Get BMC MAC Address List
310    ${mac_unique_list}=  Remove Duplicates  ${mac_entry_list}
311    ${physical_interface_count}=  Get Length  ${mac_unique_list}
312
313    [Return]  ${physical_interface_count}
314
315
316Verify Channel Info
317    [Documentation]  Verify the channel info.
318    [Arguments]  ${channel_number}  ${network_parameter}  ${active_channel_config}
319
320    Run Keyword If  '${network_parameter}' == 'IPv4StaticAddresses'
321    ...    Verify IPv4 Static Address  ${channel_number}  ${active_channel_config}
322    ...  ELSE IF  '${network_parameter}' == 'MACAddress'
323    ...    Verify MAC Address  ${channel_number}  ${active_channel_config}
324
325
326Verify IPv4 Static Address
327    [Documentation]  Verify the IPv4 Static Address.
328    [Arguments]  ${channel_number}  ${active_channel_config}
329
330    ${lan_print_ipmi}=  Get LAN Print Dict  ${channel_number}
331    ${ipv4_static_addresses}=  Redfish.Get Attribute
332    ...  ${REDFISH_NW_ETH_IFACE}${active_channel_config['${channel_number}']['name']}  IPv4StaticAddresses
333    ${redfish_ips}=  Nested Get  Address  ${ipv4_static_addresses}
334    Rprint Vars  lan_print_ipmi  ipv4_static_addresses  redfish_ips
335    Valid Value  lan_print_ipmi['IP Address']  ${redfish_ips}
336
337
338Verify MAC Address
339    [Documentation]  Verify the MAC Address.
340    [Arguments]  ${channel_number}  ${active_channel_config}
341
342    ${lan_print_ipmi}=  Get LAN Print Dict  ${channel_number}
343    ${redfish_mac_address}=  Redfish.Get Attribute
344    ...  ${REDFISH_NW_ETH_IFACE}${active_channel_config['${channel_number}']['name']}  MACAddress
345    Rprint Vars  lan_print_ipmi  redfish_mac_address
346    Valid Value  lan_print_ipmi['MAC Address']  ['${redfish_mac_address}']
347
348
349Fetch The Default Mac Address
350    [Documentation]  Fetch The Default MAC Address.
351
352     # Get Default MAC Address.
353    ${ipmi_get_default_mac}=  Run Inband IPMI Raw Command
354    ...  ${IPMI_RAW_CMD['LAN_Config_Params']['Get'][0]} ${CHANNEL_NUMBER} 0x05 0x00 0x00
355    Set Test Variable  ${ipmi_get_default_mac}
356
357    # After splitting, list will have each byte of MAC address.
358    ${ipmi_default_mac_split}=  Split String  ${ipmi_get_default_mac}
359    Set Test Variable  ${ipmi_default_mac_split}
360
361
362Set Default Mac And Verify
363    [Documentation]  Set Default Mac And Verify.
364    [Arguments]  ${default_mac}=${ipmi_default_mac_split}
365
366    ${set_default_mac}=   Evaluate  ":".join(${default_mac[1:]})
367    ${default_mac_address_hex}=  Mac Address To Hex String  ${set_default_mac}
368
369    # Set the Default MAC address.
370    ${cmd}=  Catenate  ${IPMI_RAW_CMD['LAN_Config_Params']['Set'][0]} ${CHANNEL_NUMBER}
371    ...  0x05 ${default_mac_address_hex}
372    ${ipmi_set_output}=  Run Inband IPMI Raw Command  ${cmd}  fail_on_err=0
373
374    # check whether the default MAC is set.
375    ${ipmi_get_mac}=  Run Inband IPMI Raw Command
376    ...  ${IPMI_RAW_CMD['LAN_Config_Params']['Get'][0]} ${CHANNEL_NUMBER} 0x05 0x00 0x00
377
378    ${ipmi_out}=  Split String  ${ipmi_get_mac}
379    Should be Equal  ${default_mac}  ${ipmi_out}
380