Home | History | Annotate | Download | only in arp
      1 #!/bin/sh
      2 #******************************************************************************
      3 #
      4 #   Copyright (c) International Business Machines  Corp., 2000
      5 #
      6 #   This program is free software;  you can redistribute it and/or modify
      7 #   it under the terms of the GNU General Public License as published by
      8 #   the Free Software Foundation; either version 2 of the License, or
      9 #   (at your option) any later version.
     10 #
     11 #   This program is distributed in the hope that it will be useful,
     12 #   but WITHOUT ANY WARRANTY;  without even the implied warranty of
     13 #   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
     14 #   the GNU General Public License for more details.
     15 #
     16 #   You should have received a copy of the GNU General Public License
     17 #   along with this program;  if not, write to the Free Software
     18 #   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
     19 #
     20 #
     21 #
     22 #  FILE   : arp
     23 #
     24 #  PURPOSE: To test the basic functionality of `arp`.
     25 #
     26 #  SETUP: The "RHOST" setting should be exported to be the hostname of
     27 #         another machine on the same subnet.  Otherwise, the hostname
     28 #         of the tested machine will be used.
     29 #
     30 #  HISTORY:
     31 #    06/05/03 Manoj Iyer - manjo (at] mail.utexas.edu
     32 #      - Ported to use LTP test harness API
     33 #    03/01 Robbie Williamson (robbiew (at] us.ibm.com)
     34 #      -Ported
     35 #
     36 #-----------------------------------------------------------------------
     37 
     38 #-----------------------------------------------------------------------
     39 #
     40 # FUNCTION:  do_setup
     41 #
     42 #-----------------------------------------------------------------------
     43 
     44 do_setup()
     45 {
     46 
     47     NUMLOOPS=${NUMLOOPS:-20}
     48     TST_TOTAL=$(( $NUMLOOPS * 2 ))
     49 
     50     tst_setup
     51     exists arp grep hostname ping sleep whoami
     52 
     53     RHOST=${RHOST:-$(hostname)}
     54     SLEEPTIME=${SLEEPTIME:-1}
     55     LUSER=$(whoami)
     56 
     57     [ "$LUSER" = "root" ] || end_testcase "Must be root to run this test!"
     58 
     59 }
     60 
     61 #-----------------------------------------------------------------------
     62 #
     63 # FUNCTION:  do_test
     64 #
     65 #-----------------------------------------------------------------------
     66 
     67 do_test()
     68 {
     69     while [ $TST_COUNT -le $NUMLOOPS ]; do
     70         arp -a 2>&1 1>/dev/null || end_testcase "arp -a failed"
     71         incr_tst_count
     72     done
     73 
     74     sleep $SLEEPTIME
     75 
     76     # PURPOSE:  stress the automatic creation of arp entries by pinging a host
     77     #           and deleting the arp entry again.
     78 
     79     while [ $TST_COUNT -le $TST_TOTAL ]; do
     80 
     81         ping -c1 $RHOST 2>&1 1>/dev/null || end_testcase "ping $RHOST failed"
     82 
     83         if ! arp -a | grep "$RHOST\>" 2>&1 1>/dev/null; then
     84             end_testcase "arp -a failed"
     85         fi
     86 
     87         if ! arp -d $RHOST 2>&1 1>/dev/null; then
     88             end_testcase "arp -d $RHOST failed"
     89         fi
     90 
     91         incr_tst_count
     92 
     93         sleep $SLEEPTIME
     94 
     95     done
     96 
     97 }
     98 
     99 #-----------------------------------------------------------------------
    100 # FUNCTION: MAIN
    101 # PURPOSE:  To invoke the functions to perform the tasks outlined in the
    102 #           prologue.
    103 # INPUT:    None.
    104 # OUTPUT:   None.
    105 #-----------------------------------------------------------------------
    106 
    107 . net_cmdlib.sh
    108 
    109 read_opts $*
    110 do_setup
    111 do_test
    112 end_testcase
    113