1*** Settings ***
2Documentation  Network stack stress tests using "nping" tool.
3
4# This Suite has few testcases which uses nping with ICMP.
5# ICMP creates a raw socket, which requires root privilege/sudo to run tests.
6
7Resource                ../lib/resource.robot
8Resource                ../lib/bmc_redfish_resource.robot
9Resource                ../lib/ipmi_client.robot
10
11Library                 OperatingSystem
12Library                 String
13Library                 ../lib/gen_robot_valid.py
14Library                 ../lib/bmc_network_utils.py
15Library                 ../lib/ipmi_utils.py
16
17Suite Setup             Suite Setup Execution
18
19Force Tags              Network_Nping
20
21*** Variables ***
22
23${delay}                1000ms
24${count}                4
25${program_name}         nping
26${iterations}           5000
27
28*** Test Cases ***
29
30Send ICMP Timestamp Request
31    [Documentation]  Send ICMP packet type 13 and check BMC drops such packets
32    [Tags]  Send_ICMP_Timestamp_Request
33
34    # Send ICMP packet type 13 to BMC and check packet loss.
35    ${packet_loss}=  Send Network Packets And Get Packet Loss
36    ...  ${OPENBMC_HOST}  ${count}  ${ICMP_PACKETS}  ${NETWORK_PORT}  ${ICMP_TIMESTAMP_REQUEST}
37    Should Be Equal As Numbers  ${packet_loss}  100.00
38    ...  msg=FAILURE: BMC is not dropping timestamp request messages.
39
40Send ICMP Netmask Request
41    [Documentation]  Send ICMP packet type 17 and check BMC drops such packets
42    [Tags]  Send_ICMP_Netmask_Request
43
44    # Send ICMP packet type 17 to BMC and check packet loss.
45    ${packet_loss}=  Send Network Packets And Get Packet Loss
46    ...  ${OPENBMC_HOST}  ${count}  ${ICMP_PACKETS}  ${NETWORK_PORT}  ${ICMP_NETMASK_REQUEST}
47    Should Be Equal As Numbers  ${packet_loss}  100.00
48    ...  msg=FAILURE: BMC is not dropping netmask request messages.
49
50Send Continuous ICMP Echo Request To BMC And Verify No Packet Loss
51    [Documentation]  Send ICMP packet type 8 continuously and check no packets are dropped from BMC
52    [Tags]  Send_Continuous_ICMP_Echo_Request_To_BMC_And_Verify_No_Packet_Loss
53
54    # Send ICMP packet type 8 to BMC and check packet loss.
55    ${packet_loss}=  Send Network Packets And Get Packet Loss
56    ...  ${OPENBMC_HOST}  ${iterations}  ${ICMP_PACKETS}
57    Should Be Equal As Numbers  ${packet_loss}  0.0
58    ...  msg=FAILURE: BMC is dropping packets.
59
60Send Network Packets Continuously To Redfish Interface
61    [Documentation]  Send network packets continuously to Redfish interface and verify stability.
62    [Tags]  Send_Network_Packets_Continuously_To_Redfish_Interface
63
64    # Send large number of packets to Redfish interface.
65    ${packet_loss}=  Send Network Packets And Get Packet Loss
66    ...  ${OPENBMC_HOST}  ${iterations}  ${TCP_PACKETS}  ${REDFISH_INTERFACE}
67    Should Be Equal As Numbers  ${packet_loss}  0.0
68    ...  msg=FAILURE: BMC is dropping some packets.
69
70    # Check if Redfish interface is functional.
71    Redfish.Login
72    Redfish.Logout
73
74
75Send Network Packets Continuously To IPMI Port
76    [Documentation]  Send network packets continuously to IPMI port and verify stability.
77    [Tags]  Send_Network_Packets_Continuously_To_IPMI_Port
78
79    # Send large number of packets to IPMI port.
80    ${packet_loss}=  Send Network Packets And Get Packet Loss
81    ...  ${OPENBMC_HOST}  ${iterations}  ${TCP_PACKETS}  ${IPMI_PORT}
82    Should Be Equal As Numbers  ${packet_loss}  0.0
83    ...  msg=FAILURE: BMC is dropping some packets.
84
85    # Check if IPMI interface is functional.
86    Run IPMI Standard Command  chassis status
87
88
89Send Network Packets Continuously To SSH Port
90    [Documentation]  Send network packets continuously to SSH port and verify stability.
91    [Tags]  Send_Network_Packets_Continuously_To_SSH_Port
92
93    # Send large number of packets to SSH port.
94    ${packet_loss}=  Send Network Packets And Get Packet Loss
95    ...  ${OPENBMC_HOST}  ${iterations}  ${TCP_PACKETS}  ${SSH_PORT}
96    Should Be Equal As Numbers  ${packet_loss}  0.0
97    ...  msg=FAILURE: BMC is dropping some packets.
98
99    # Check if SSH interface is functional.
100
101    SSHLibrary.Open Connection  ${OPENBMC_HOST}
102    Open Connection And Log In  ${OPENBMC_USERNAME}  ${OPENBMC_PASSWORD}
103
104
105Flood Redfish Interface With Packets With Flags And Check Stability
106    [Documentation]  Send large number of packets with flags to Redfish interface
107    ... and check stability.
108    [Tags]  Flood_Redfish_Interface_With_Packets_With_Flags_And_Check_Stability
109    [Template]  Send Network Packets With Flags And Verify Stability
110
111    # Target         No. Of packets  Interface              Flags
112
113    # Flood syn packets and check BMC behavior.
114    ${OPENBMC_HOST}  ${iterations}   ${REDFISH_INTERFACE}   ${SYN_PACKETS}
115
116    # Flood reset packets and check BMC behavior.
117    ${OPENBMC_HOST}  ${iterations}   ${REDFISH_INTERFACE}   ${RESET_PACKETS}
118
119    # Flood fin packets and check BMC behavior.
120    ${OPENBMC_HOST}  ${iterations}   ${REDFISH_INTERFACE}   ${FIN_PACKETS}
121
122    # Flood syn ack reset packets and check BMC behavior.
123    ${OPENBMC_HOST}  ${iterations}   ${REDFISH_INTERFACE}   ${SYN_ACK_RESET}
124
125    # Flood packets with all flags and check BMC behavior.
126    ${OPENBMC_HOST}  ${iterations}   ${REDFISH_INTERFACE}   ${ALL_FLAGS}
127
128
129*** Keywords ***
130
131Suite Setup Execution
132    [Documentation]  Validate the setup.
133
134    Valid Value  OPENBMC_HOST
135    Valid Program  program_name
136
137Send Network Packets And Get Packet Loss
138    [Documentation]  Send TCP, UDP or ICMP packets to the target.
139    [Arguments]  ${host}  ${num}=${count}  ${packet_type}=${ICMP_PACKETS}
140    ...          ${port}=80  ${icmp_type}=${ICMP_ECHO_REQUEST}
141
142    # Description of argument(s):
143    # host         The host name or IP address of the target system.
144    # packet_type  The type of packets to be sent ("tcp, "udp", "icmp").
145    # port         Network port.
146    # icmp_type    Type of ICMP packets (e.g. 8, 13, 17, etc.).
147    # num          Number of packets to be sent.
148
149    # This keyword expects host, port, type and number of packets to be sent
150    # and rate at which packets to be sent, should be given in command line.
151    # By default it sends 4 ICMP echo request  packets at 1 packets/second.
152
153    ${cmd_suffix}=  Set Variable If  '${packet_type}' == 'icmp'
154    ...  --icmp-type ${icmp_type}
155    ...  -p ${port}
156    ${cmd_buf}=  Set Variable  --delay ${delay} ${host} -c ${num} --${packet_type} ${cmd_suffix}
157
158    ${nping_result}=  Nping  ${cmd_buf}
159    [Return]   ${nping_result['percent_lost']}
160
161
162Send Network Packets With Flags And Verify Stability
163    [Documentation]  Send TCP with flags to the target.
164    [Arguments]  ${host}  ${num}=${count}  ${port}=${REDFISH_INTERFACE}
165    ...  ${flags}=${SYN_PACKETS}
166    [Teardown]  Verify Interface Stability  ${port}
167
168    # Description of argument(s):
169    # host         The host name or IP address of the target system.
170    # packet_type  The type of packets to be sent ("tcp, "udp", "icmp").
171    # port         Network port.
172    # flags        Type of flag to be set (e.g. SYN, ACK, RST, FIN, ALL).
173    # num          Number of packets to be sent.
174
175    # This keyword expects host, port, type and number of packets to be sent
176    # and rate at which packets to be sent, should be given in command line.
177    # By default it sends 4 ICMP echo request  packets at 1 packets/second.
178
179    ${cmd_suffix}=  Catenate  -p ${port} --flags ${flags}
180    ${cmd_buf}=  Set Variable  --delay ${delay} ${host} -c ${num} --${packet_type} ${cmd_suffix}
181
182    ${nping_result}=  Nping  ${cmd_buf}
183    Log To Console  Packets lost: ${nping_result['percent_lost']}
184
185
186Verify Interface Stability
187    [Documentation]  Verify interface is up and active.
188    [Arguments]  ${port}
189
190    # Description of argument(s):
191    # port  Network port.
192
193    Run Keyword If  ${port} == ${REDFISH_INTERFACE}
194    ...  Redfish.Login
195    ...  ELSE IF  ${port} == ${SSH_PORT}
196    ...  Open Connection And Log In  ${OPENBMC_USERNAME}  ${OPENBMC_PASSWORD}
197    ...  ELSE IF  ${port} == ${IPMI_PORT}
198    ...  Run External IPMI Standard Command lan print
199    ...  ELSE IF  ${port} == ${HOST_SOL_PORT}
200    ...  Open Connection And Log In  ${OPENBMC_USERNAME}  ${OPENBMC_PASSWORD}  port=${HOST_SOL_PORT}
201    ...  ELSE
202    ...  Redfish.Login
203