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