1*** Settings ***
2Documentation  Network stack stress tests using "nping" tool.
3
4Resource                ../lib/resource.robot
5Resource                ../lib/bmc_redfish_resource.robot
6Resource                ../lib/ipmi_client.robot
7
8Library                 OperatingSystem
9Library                 String
10Library                 ../lib/gen_robot_valid.py
11Library                 ../lib/bmc_network_utils.py
12Library                 ../lib/ipmi_utils.py
13
14Suite Setup             Suite Setup Execution
15
16Force Tags              Network_Nping
17
18*** Variables ***
19
20${delay}                1000ms
21${count}                4
22${program_name}         nping
23${iterations}           5000
24
25*** Test Cases ***
26
27Send ICMP Timestamp Request
28    [Documentation]  Send ICMP packet type 13 and check BMC drops such packets
29    [Tags]  Send_ICMP_Timestamp_Request
30
31    # Send ICMP packet type 13 to BMC and check packet loss.
32    ${packet_loss}=  Send Network Packets And Get Packet Loss
33    ...  ${OPENBMC_HOST}  ${count}  ${ICMP_PACKETS}  ${NETWORK_PORT}  ${ICMP_TIMESTAMP_REQUEST}
34    Should Be Equal As Numbers  ${packet_loss}  100.00
35    ...  msg=FAILURE: BMC is not dropping timestamp request messages.
36
37Send ICMP Netmask Request
38    [Documentation]  Send ICMP packet type 17 and check BMC drops such packets
39    [Tags]  Send_ICMP_Netmask_Request
40
41    # Send ICMP packet type 17 to BMC and check packet loss.
42    ${packet_loss}=  Send Network Packets And Get Packet Loss
43    ...  ${OPENBMC_HOST}  ${count}  ${ICMP_PACKETS}  ${NETWORK_PORT}  ${ICMP_NETMASK_REQUEST}
44    Should Be Equal As Numbers  ${packet_loss}  100.00
45    ...  msg=FAILURE: BMC is not dropping netmask request messages.
46
47Send Network Packets Continuously To Redfish Interface
48    [Documentation]  Send network packets continuously to Redfish interface and verify stability.
49    [Tags]  Send_Network_Packets_Continuously_To_Redfish_Interface
50
51    # Send large number of packets to Redfish interface.
52    ${packet_loss}=  Send Network Packets And Get Packet Loss
53    ...  ${OPENBMC_HOST}  ${iterations}  ${TCP_PACKETS}  ${REDFISH_INTERFACE}
54    Should Be Equal  ${packet_loss}  0.0
55    ...  msg=FAILURE: BMC is dropping some packets.
56
57    # Check if Redfish interface is functional.
58    Redfish.Login
59    Redfish.Logout
60
61
62Send Network Packets Continuously To IPMI Port
63    [Documentation]  Send network packets continuously to IPMI port and verify stability.
64    [Tags]  Send_Network_Packets_Continuously_To_IPMI_Port
65
66    # Send large number of packets to IPMI port.
67    ${packet_loss}=  Send Network Packets And Get Packet Loss
68    ...  ${OPENBMC_HOST}  ${iterations}  ${TCP_PACKETS}  ${IPMI_PORT}
69    Should Be Equal  ${packet_loss}  0.0
70    ...  msg=FAILURE: BMC is dropping some packets.
71
72    # Check if IPMI interface is functional.
73    Run IPMI Standard Command  chassis status
74
75
76Send Network Packets Continuously To SSH Port
77    [Documentation]  Send network packets continuously to SSH port and verify stability.
78    [Tags]  Send_Network_Packets_Continuously_To_SSH_Port
79
80    # Send large number of packets to SSH port.
81    ${packet_loss}=  Send Network Packets And Get Packet Loss
82    ...  ${OPENBMC_HOST}  ${iterations}  ${TCP_PACKETS}  ${SSH_PORT}
83    Should Be Equal  ${packet_loss}  0.0
84    ...  msg=FAILURE: BMC is dropping some packets.
85
86    # Check if SSH interface is functional.
87
88    SSHLibrary.Open Connection  ${OPENBMC_HOST}
89    Open Connection And Log In  ${OPENBMC_USERNAME}  ${OPENBMC_PASSWORD}
90
91
92*** Keywords ***
93
94Suite Setup Execution
95    [Documentation]  Validate the setup.
96
97    Valid Value  OPENBMC_HOST
98    Valid Program  program_name
99
100Send Network Packets And Get Packet Loss
101    [Documentation]  Send TCP, UDP or ICMP packets to the target.
102    [Arguments]  ${host}  ${num}=${count}  ${packet_type}=${ICMP_PACKETS}
103    ...          ${port}=80  ${icmp_type}=${ICMP_ECHO_REQUEST}
104
105    # Description of argument(s):
106    # host         The host name or IP address of the target system.
107    # packet_type  The type of packets to be sent ("tcp, "udp", "icmp").
108    # port         Network port.
109    # icmp_type    Type of ICMP packets (e.g. 8, 13, 17, etc.).
110    # num          Number of packets to be sent.
111
112    # This keyword expects host, port, type and number of packets to be sent
113    # and rate at which packets to be sent, should be given in command line.
114    # By default it sends 4 ICMP echo request  packets at 1 packets/second.
115
116    ${cmd_suffix}=  Set Variable If  '${packet_type}' == 'icmp'
117    ...  --icmp-type ${icmp_type}
118    ...  -p ${port}
119    ${cmd_buf}=  Set Variable  --delay ${delay} ${host} -c ${num} --${packet_type} ${cmd_suffix}
120
121    ${nping_result}=  Nping  ${cmd_buf}
122    [Return]   ${nping_result['percent_lost']}
123