Network packet test automation with "nping" tool
This change addresses:
1. Send any number of network packets at any rate
2. Check packet loss
3. Checks whether issue is with system or network
Resolves openbmc/openbmc-test-automation#345
Change-Id: I66b07c8924d855ad47fa631914a1992830222f37
Signed-off-by: Prashanth Katti <prkatti1@in.ibm.com>
diff --git a/extended/test_network_nping.robot b/extended/test_network_nping.robot
new file mode 100644
index 0000000..b9a81c0
--- /dev/null
+++ b/extended/test_network_nping.robot
@@ -0,0 +1,81 @@
+*** Settings ***
+Documentation Network stack stress tests using "nping" tool.
+
+Resource ../lib/resource.txt
+
+Library OperatingSystem
+Library String
+
+Suite Setup Validate Setup
+
+*** Variables ***
+
+${delay} 200ms
+${count} 100
+${bmc_packet_loss} ${EMPTY}
+
+*** Test Cases ***
+
+Verify Zero Network Packet Loss On BMC
+ [Documentation] Pump network packets to target.
+ [Tags] Verify_Zero_Network_Packet_Loss_On_BMC
+
+ # Send packets to BMC and check packet loss.
+ ${bmc_packet_loss}= Send Network Packets
+ ... ${OPENBMC_HOST} ${PACKET_TYPE} ${NETWORK_PORT}
+ Should Contain
+ ... ${bmc_packet_loss} Lost: 0 (0.00%) msg=Fail, Packet loss on BMC.
+
+*** Keywords ***
+
+Validate Setup
+ [Documentation] Validate the setup.
+
+ Should Not Be Empty ${OPENBMC_HOST} msg=BMC IP address not provided.
+ ${output}= Run which nping
+ Should Not Be Empty ${output} msg="nping" tool not installed.
+
+Send Network Packets
+ [Documentation] Send TCP, UDP or ICMP packets to the target.
+ [Arguments] ${host} ${packet_type}=tcp ${port}=80
+
+ # Description of arguments:
+ # ${host}- Target system to which network packets to be sent.
+ # ${packet_type}- type of packets to be sent viz tcp, udp or icmp.
+ # ${port}- Network port.
+
+ # This program expects host, port, type and number of packets to be sent
+ # and rate at which packets to be sent, should be given in commad line
+ # by default it sends 100 TCP packets at 5 packets/second.
+
+ ${cmd_buff}= Run Keyword If '${packet_type}' == 'icmp'
+ ... Set Variable nping --delay ${delay} ${host} -c ${count} --${packet_type}
+ ... ELSE
+ ... Set variable
+ ... nping --delay ${delay} ${host} -c ${count} -p ${port} --${packet_type}
+ ${rc} ${output} Run And Return RC And Output ${cmd_buff}
+ Should Be Equal As Integers ${rc} 0 msg=Command execution failed.
+ ${packet_loss} Get Packet Loss ${host} ${output}
+ [Return] ${packet_loss}
+
+Get Packet Loss
+ [Documentation] Check packet loss percentage.
+
+ # Sample Output from "nping" command:
+ # Starting Nping 0.6.47 ( http://nmap.org/nping ) at 2017-02-21 22:05 IST
+ # SENT (0.0181s) TCP Source IP:37577 > Destination IP:80 S ttl=64 id=39113 iplen=40 seq=629782493 win=1480
+ # SENT (0.2189s) TCP Source IP:37577 > Destination IP:80 S ttl=64 id=39113 iplen=40 seq=629782493 win=1480
+ # RCVD (0.4120s) TCP Destination IP:80 > Source IP:37577 SA ttl=49 id=0 iplen=44 seq=1078301364 win=5840 <mss 1380>
+ # Max rtt: 193.010ms | Min rtt: 193.010ms | Avg rtt: 193.010ms
+ # Raw packets sent: 2 (80B) | Rcvd: 1 (46B) | Lost: 1 (50.00%)
+ # Nping done: 1 IP address pinged in 0.43 seconds
+
+ [Arguments] ${host} ${traffic_details}
+
+ # Description of arguments:
+ # ${host}- System on which packet loss to be checked.
+ # ${traffic_details}- Details of the network traffic sent.
+
+ ${summary}= Get Lines Containing String ${traffic_details} Rcvd:
+ Log To Console \nPacket loss summary on ${host}\n*********************
+ [Return] ${summary}
diff --git a/lib/resource.txt b/lib/resource.txt
index a90b9c8..74d9e5c 100755
--- a/lib/resource.txt
+++ b/lib/resource.txt
@@ -40,6 +40,10 @@
${OS_PASSWORD} ${EMPTY}
${OS_WAIT_TIMEOUT} ${15*60}
+# Networking related parameters
+${NETWORK_PORT} 80
+${PACKET_TYPE} tcp
+
*** Keywords ***
Get Inventory Schema
[Arguments] ${machine}