xref: /openbmc/openbmc-test-automation/lib/bmc_network_security_utils.robot (revision 1da8826c43ce3493d5426e7de8745ff4ff0ab186)
1e31542beSPrashanth Katti*** Settings ***
2e31542beSPrashanth Katti
3e31542beSPrashanth KattiDocumentation  Network security utility file.
4e31542beSPrashanth Katti
5e31542beSPrashanth KattiResource                ../lib/resource.robot
6e31542beSPrashanth KattiResource                ../lib/bmc_redfish_resource.robot
7e31542beSPrashanth Katti
8e31542beSPrashanth KattiSend Network Packets And Get Packet Loss
9*1da8826cSPrashanth Katti    [Documentation]  Send TCP, UDP or ICMP packets to any network device and return packet loss.
10e31542beSPrashanth Katti    [Arguments]  ${host}  ${num}=${count}  ${packet_type}=${ICMP_PACKETS}
11e31542beSPrashanth Katti    ...          ${port}=80  ${icmp_type}=${ICMP_ECHO_REQUEST}
12e31542beSPrashanth Katti
13e31542beSPrashanth Katti    # Description of argument(s):
14e31542beSPrashanth Katti    # host         The host name or IP address of the target system.
15e31542beSPrashanth Katti    # packet_type  The type of packets to be sent ("tcp, "udp", "icmp").
16e31542beSPrashanth Katti    # port         Network port.
17e31542beSPrashanth Katti    # icmp_type    Type of ICMP packets (e.g. 8, 13, 17, etc.).
18e31542beSPrashanth Katti    # num          Number of packets to be sent.
19e31542beSPrashanth Katti
20e31542beSPrashanth Katti    # This keyword expects host, port, type and number of packets to be sent
21e31542beSPrashanth Katti    # and rate at which packets to be sent, should be given in command line.
22e31542beSPrashanth Katti    # By default it sends 4 ICMP echo request  packets at 1 packets/second.
23e31542beSPrashanth Katti
24e31542beSPrashanth Katti    ${cmd_suffix}=  Set Variable If  '${packet_type}' == 'icmp'
25e31542beSPrashanth Katti    ...  --icmp-type ${icmp_type}
26e31542beSPrashanth Katti    ...  -p ${port}
27e31542beSPrashanth Katti    ${cmd_buf}=  Set Variable  --delay ${delay} ${host} -c ${num} --${packet_type} ${cmd_suffix}
28e31542beSPrashanth Katti
29e31542beSPrashanth Katti    ${nping_result}=  Nping  ${cmd_buf}
30e31542beSPrashanth Katti    [Return]   ${nping_result['percent_lost']}
31e31542beSPrashanth Katti
32e31542beSPrashanth Katti
33e31542beSPrashanth KattiSend Network Packets With Flags And Verify Stability
34e31542beSPrashanth Katti    [Documentation]  Send TCP with flags to the target.
35e31542beSPrashanth Katti    [Arguments]  ${host}  ${num}=${count}  ${port}=${REDFISH_INTERFACE}
36e31542beSPrashanth Katti    ...  ${flags}=${SYN_PACKETS}
37e31542beSPrashanth Katti    [Teardown]  Verify Interface Stability  ${port}
38e31542beSPrashanth Katti
39e31542beSPrashanth Katti    # Description of argument(s):
40e31542beSPrashanth Katti    # host         The host name or IP address of the target system.
41e31542beSPrashanth Katti    # packet_type  The type of packets to be sent ("tcp, "udp", "icmp").
42e31542beSPrashanth Katti    # port         Network port.
43e31542beSPrashanth Katti    # flags        Type of flag to be set (e.g. SYN, ACK, RST, FIN, ALL).
44e31542beSPrashanth Katti    # num          Number of packets to be sent.
45e31542beSPrashanth Katti
46e31542beSPrashanth Katti    # This keyword expects host, port, type and number of packets to be sent
47e31542beSPrashanth Katti    # and rate at which packets to be sent, should be given in command line.
48e31542beSPrashanth Katti    # By default it sends 4 ICMP echo request  packets at 1 packets/second.
49e31542beSPrashanth Katti
50e31542beSPrashanth Katti    ${cmd_suffix}=  Catenate  -p ${port} --flags ${flags}
51e31542beSPrashanth Katti    ${cmd_buf}=  Set Variable  --delay ${delay} ${host} -c ${num} --${packet_type} ${cmd_suffix}
52e31542beSPrashanth Katti
53e31542beSPrashanth Katti    ${nping_result}=  Nping  ${cmd_buf}
54e31542beSPrashanth Katti    Log To Console  Packets lost: ${nping_result['percent_lost']}
55