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
11Test 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
55    ...  echo ${CLIENT_PASSWORD} | sudo -S nping --delay ${delay} ${host} -c ${count} --${packet_type}
56    ...  ELSE
57    ...  Set variable
58    ...  echo ${CLIENT_PASSWORD} | sudo -S nping --delay ${delay} ${host} -c ${count} -p ${port} --${packet_type}
59    ${rc}  ${output}  Run And Return RC And Output  ${cmd_buff}
60    Should Be Equal As Integers  ${rc}  0  msg=Command execution failed.
61    ${packet_loss}  Get Packet Loss  ${host}  ${output}
62    RETURN  ${packet_loss}
63
64Get Packet Loss
65    [Documentation]  Check packet loss percentage.
66
67    # Sample Output from "nping" command:
68    # Starting Nping 0.6.47 ( http://nmap.org/nping ) at 2017-02-21 22:05 IST
69    # SENT (0.0181s) TCP Source IP:37577 >
70    #   Destination IP:80 S ttl=64 id=39113 iplen=40  seq=629782493 win=1480
71    # SENT (0.2189s) TCP Source IP:37577 >
72    #   Destination IP:80 S ttl=64 id=39113 iplen=40  seq=629782493 win=1480
73    # RCVD (0.4120s) TCP Destination IP:80 >
74    #   Source IP:37577 SA ttl=49 id=0 iplen=44  seq=1078301364 win=5840 <mss 1380>
75    # Max rtt: 193.010ms | Min rtt: 193.010ms | Avg rtt: 193.010ms
76    # Raw packets sent: 2 (80B) | Rcvd: 1 (46B) | Lost: 1 (50.00%)
77    # Nping done: 1 IP address pinged in 0.43 seconds
78
79    [Arguments]  ${host}  ${traffic_details}
80
81    # Description of arguments:
82    # ${host}- System on which packet loss to be checked.
83    # ${traffic_details}- Details of the network traffic sent.
84
85    ${summary}=  Get Lines Containing String  ${traffic_details}  Rcvd:
86    Log To Console  \nPacket loss summary on ${host}\n*********************
87    RETURN  ${summary}
88