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