1*** Settings ***
2Documentation  Network stack stress tests using "nping" tool.
3
4Resource  ../lib/resource.robot
5
6Library  OperatingSystem
7Library  String
8
9Suite Setup  Suite Setup Execution
10
11Force Tags  Network_Nping
12
13*** Variables ***
14
15${delay}             200ms
16${count}             100
17${bmc_packet_loss}   ${EMPTY}
18
19*** Test Cases ***
20
21Verify Zero Network Packet Loss On BMC
22    [Documentation]  Pump network packets to target.
23    [Tags]  Verify_Zero_Network_Packet_Loss_On_BMC
24
25    # Send packets to BMC and check packet loss.
26    ${bmc_packet_loss}=  Send Network Packets
27    ...  ${OPENBMC_HOST}  ${PACKET_TYPE}  ${NETWORK_PORT}
28    Should Contain
29    ...  ${bmc_packet_loss}  Lost: 0 (0.00%)  msg=Fail, Packet loss on BMC.
30
31*** Keywords ***
32
33Suite Setup Execution
34    [Documentation]  Validate the setup.
35
36    Should Not Be Empty  ${OPENBMC_HOST}  msg=BMC IP address not provided.
37    ${output}=  Run  which nping
38    Should Not Be Empty  ${output}  msg="nping" tool not installed.
39
40Send Network Packets
41    [Documentation]  Send TCP, UDP or ICMP packets to the target.
42    [Arguments]  ${host}  ${packet_type}=tcp  ${port}=80
43
44    # Description of arguments:
45    # ${host}- Target system to which network packets to be sent.
46    # ${packet_type}- type of packets to be sent viz tcp, udp or icmp.
47    # ${port}- Network port.
48
49    # This program expects host, port, type and number of packets to be sent
50    # and rate at which packets to be sent, should be given in command line
51    # by default it sends 100 TCP packets at 5 packets/second.
52
53    ${cmd_buff}=  Run Keyword If  '${packet_type}' == 'icmp'
54    ...  Set Variable  nping --delay ${delay} ${host} -c ${count} --${packet_type}
55    ...  ELSE
56    ...  Set variable
57    ...  nping --delay ${delay} ${host} -c ${count} -p ${port} --${packet_type}
58    ${rc}  ${output}  Run And Return RC And Output  ${cmd_buff}
59    Should Be Equal As Integers  ${rc}  0  msg=Command execution failed.
60    ${packet_loss}  Get Packet Loss  ${host}  ${output}
61    [Return]  ${packet_loss}
62
63Get Packet Loss
64    [Documentation]  Check packet loss percentage.
65
66    # Sample Output from "nping" command:
67    # Starting Nping 0.6.47 ( http://nmap.org/nping ) at 2017-02-21 22:05 IST
68    # SENT (0.0181s) TCP Source IP:37577 >
69    #   Destination IP:80 S ttl=64 id=39113 iplen=40  seq=629782493 win=1480
70    # SENT (0.2189s) TCP Source IP:37577 >
71    #   Destination IP:80 S ttl=64 id=39113 iplen=40  seq=629782493 win=1480
72    # RCVD (0.4120s) TCP Destination IP:80 >
73    #   Source IP:37577 SA ttl=49 id=0 iplen=44  seq=1078301364 win=5840 <mss 1380>
74    # Max rtt: 193.010ms | Min rtt: 193.010ms | Avg rtt: 193.010ms
75    # Raw packets sent: 2 (80B) | Rcvd: 1 (46B) | Lost: 1 (50.00%)
76    # Nping done: 1 IP address pinged in 0.43 seconds
77
78    [Arguments]  ${host}  ${traffic_details}
79
80    # Description of arguments:
81    # ${host}- System on which packet loss to be checked.
82    # ${traffic_details}- Details of the network traffic sent.
83
84    ${summary}=  Get Lines Containing String  ${traffic_details}  Rcvd:
85    Log To Console  \nPacket loss summary on ${host}\n*********************
86    [Return]  ${summary}
87