Keyword and test case to send network packets with flags

Changes:
    Added code to flood SYN packets and verify Redfish port stability to SYN flood attack
    Added code to flood FIN packets and verify Redfish port stability to FIN flood attack
    Added code to flood RST packets and verify Redfish port stability to RST flood attack

Signed-off-by: Prashanth Katti <prkatti1@in.ibm.com>
Change-Id: I34223ace3a68d289831e6a8b147b22251465b791
diff --git a/lib/resource.robot b/lib/resource.robot
index 3113fa9..a758074 100755
--- a/lib/resource.robot
+++ b/lib/resource.robot
@@ -82,6 +82,11 @@
 ${TCP_PACKETS}             tcp
 ${ICMP_NETMASK_REQUEST}    17
 ${REDFISH_INTERFACE}       443
+${SYN_PACKETS}             SYN
+${RESET_PACKETS}           RST
+${FIN_PACKETS}             FIN
+${SYN_ACK_RESET}           SAR
+${ALL_FLAGS}               ALL
 
 # BMC debug tarball parameter
 ${DEBUG_TARBALL_PATH}  ${EMPTY}
diff --git a/security/test_bmc_network_security.robot b/security/test_bmc_network_security.robot
index e6becb8..5b9d08d 100644
--- a/security/test_bmc_network_security.robot
+++ b/security/test_bmc_network_security.robot
@@ -51,7 +51,7 @@
     # Send large number of packets to Redfish interface.
     ${packet_loss}=  Send Network Packets And Get Packet Loss
     ...  ${OPENBMC_HOST}  ${iterations}  ${TCP_PACKETS}  ${REDFISH_INTERFACE}
-    Should Be Equal  ${packet_loss}  0.0
+    Should Be Equal As Numbers  ${packet_loss}  0.0
     ...  msg=FAILURE: BMC is dropping some packets.
 
     # Check if Redfish interface is functional.
@@ -66,7 +66,7 @@
     # Send large number of packets to IPMI port.
     ${packet_loss}=  Send Network Packets And Get Packet Loss
     ...  ${OPENBMC_HOST}  ${iterations}  ${TCP_PACKETS}  ${IPMI_PORT}
-    Should Be Equal  ${packet_loss}  0.0
+    Should Be Equal As Numbers  ${packet_loss}  0.0
     ...  msg=FAILURE: BMC is dropping some packets.
 
     # Check if IPMI interface is functional.
@@ -80,7 +80,7 @@
     # Send large number of packets to SSH port.
     ${packet_loss}=  Send Network Packets And Get Packet Loss
     ...  ${OPENBMC_HOST}  ${iterations}  ${TCP_PACKETS}  ${SSH_PORT}
-    Should Be Equal  ${packet_loss}  0.0
+    Should Be Equal As Numbers  ${packet_loss}  0.0
     ...  msg=FAILURE: BMC is dropping some packets.
 
     # Check if SSH interface is functional.
@@ -89,6 +89,30 @@
     Open Connection And Log In  ${OPENBMC_USERNAME}  ${OPENBMC_PASSWORD}
 
 
+Flood Redfish Interface With Packets With Flags And Check Stability
+    [Documentation]  Send large number of packets with flags to Redfish interface
+    ... and check stability.
+    [Tags]  Flood_Redfish_Interface_With_Packets_With_Flags_And_Check_Stability
+    [Template]  Send Network Packets With Flags And Verify Stability
+
+    # Target         No. Of packets  Interface              Flags
+
+    # Flood syn packets and check BMC behavior.
+    ${OPENBMC_HOST}  ${iterations}   ${REDFISH_INTERFACE}   ${SYN_PACKETS}
+
+    # Flood reset packets and check BMC behavior.
+    ${OPENBMC_HOST}  ${iterations}   ${REDFISH_INTERFACE}   ${RESET_PACKETS}
+
+    # Flood fin packets and check BMC behavior.
+    ${OPENBMC_HOST}  ${iterations}   ${REDFISH_INTERFACE}   ${FIN_PACKETS}
+
+    # Flood syn ack reset packets and check BMC behavior.
+    ${OPENBMC_HOST}  ${iterations}   ${REDFISH_INTERFACE}   ${SYN_ACK_RESET}
+
+    # Flood packets with all flags and check BMC behavior.
+    ${OPENBMC_HOST}  ${iterations}   ${REDFISH_INTERFACE}   ${ALL_FLAGS}
+
+
 *** Keywords ***
 
 Suite Setup Execution
@@ -120,3 +144,46 @@
 
     ${nping_result}=  Nping  ${cmd_buf}
     [Return]   ${nping_result['percent_lost']}
+
+
+Send Network Packets With Flags And Verify Stability
+    [Documentation]  Send TCP with flags to the target.
+    [Arguments]  ${host}  ${num}=${count}  ${port}=${REDFISH_INTERFACE}
+    ...  ${flags}=${SYN_PACKETS}
+    [Teardown]  Verify Interface Stability  ${port}
+
+    # Description of argument(s):
+    # host         The host name or IP address of the target system.
+    # packet_type  The type of packets to be sent ("tcp, "udp", "icmp").
+    # port         Network port.
+    # flags        Type of flag to be set (e.g. SYN, ACK, RST, FIN, ALL).
+    # num          Number of packets to be sent.
+
+    # This keyword expects host, port, type and number of packets to be sent
+    # and rate at which packets to be sent, should be given in command line.
+    # By default it sends 4 ICMP echo request  packets at 1 packets/second.
+
+    ${cmd_suffix}=  Catenate  -p ${port} --flags ${flags}
+    ${cmd_buf}=  Set Variable  --delay ${delay} ${host} -c ${num} --${packet_type} ${cmd_suffix}
+
+    ${nping_result}=  Nping  ${cmd_buf}
+    Log To Console  Packets lost: ${nping_result['percent_lost']}
+
+
+Verify Interface Stability
+    [Documentation]  Verify interface is up and active.
+    [Arguments]  ${port}
+
+    # Description of argument(s):
+    # port  Network port.
+
+    Run Keyword If  ${port} == ${REDFISH_INTERFACE}
+    ...  Redfish.Login
+    ...  ELSE IF  ${port} == ${SSH_PORT}
+    ...  Open Connection And Log In  ${OPENBMC_USERNAME}  ${OPENBMC_PASSWORD}
+    ...  ELSE IF  ${port} == ${IPMI_PORT}
+    ...  Run External IPMI Standard Command lan print
+    ...  ELSE IF  ${port} == ${HOST_SOL_PORT}
+    ...  Open Connection And Log In  ${OPENBMC_USERNAME}  ${OPENBMC_PASSWORD}  port=${HOST_SOL_PORT}
+    ...  ELSE
+    ...  Redfish.Login