#! /pkg/bin/ksh
# ---------------------------------------------------------------------
# eigrp_show_tech - show tech-support routing eigrp script
#
# May 2011, Baalajee Surendran
#
# Copyright (c) 2011-2015, 2017 by cisco Systems, Inc.
# All rights reserved.
#--------------------------------------------------------------------

. /pkg/bin/show_tech_main_fragment

__cardtype="unspecified"

# Variable initialization

vrf_in_exec=''
vrf_in_ksh='default'
af_in_exec='ipv4'
af_in_ksh='0x1'
standby_in_exec=''
standby_in_ksh=''
eigrp_running=0
ipv4_rib_running=0
ipv6_rib_running=0
standby=0
local_node=''
local_nodeid=''
eigrp_jid=''
eigrp_pid=''

while [ $# -gt 0 ]; do
  case "$1" in
     -t) __cardtype="$2"; shift 2;;
      *) default_parser_function "$@"; shift $# ;;
  esac
done

if [ "$__filename" == "unspecified" ]; then
    echo "show_tech_eigrp: output file not specified"
    exit
fi

if [ "$__cardtype" == "unspecified" ]; then
    __cardtype=`node_type`
fi

# ***********************************************************
#  Show commands to be run by the show tech-support commands
# ***********************************************************

# Commands that run on once per system

if [ "$platform" == "panini" ]; then

    sys_exec[1]='show version'
    sys__ksh[1]='ng_show_version'

    sys_exec[3]='show instal active'
    sys__ksh[3]='sdr_instcmd show install active'

    sys_exec[2]='show_platform'
    sys__ksh[2]='show_platform_sysdb'
else
    sys_exec[1]='show version'
    sys__ksh[1]='show_version'

    sys_exec[2]='show platform'
    sys__ksh[2]='show_platform'

    sys_exec[3]='show install active'
    sys__ksh[3]='instcmd show install active'
fi    

sys_exec[4]='show redundancy detail'
sys__ksh[4]='redcon_show'

sys_exec[5]='show running router eigrp'
sys__ksh[5]='nvgen -c -q gl/eigrp/proc/'

sys_exec[6]='show ipv4 vrf all interface brief'
sys__ksh[6]='show_ip_interface -b -v all'

sys_exec[7]='show ipv6 vrf all interface brief'
sys__ksh[7]='show_ipv6_interface -b -v all'

sys_exec[8]='show lpts bindings brief client-id raw'
sys__ksh[8]='show_lpts_pa -B -j 0x3'

sys_exec[9]='sh lpts ifib entry brief'
sys__ksh[9]='show_lpts_ifib -m entries -b'

sys_exec[10]='sh lpts ifib statistics'
sys__ksh[10]='show_lpts_ifib -m statistics'

sys_exec[11]='show logging' 
sys__ksh[11]='show_logging'

sys__ksh[12]=''


# EIGRP Commands that run on all RP/DRP where EIGRP is running

rp_set1_exec[1]='show eigrp $standby_in_exec $vrf_in_exec $af_in_exec accounting'
rp_set1__ksh[1]='eigrp_show $standby_in_ksh -n '________' -a 0x0 -v $vrf_in_ksh -x $af_in_ksh -A'

rp_set1_exec[2]='show eigrp $standby_in_exec $vrf_in_exec $af_in_exec events'
rp_set1__ksh[2]='eigrp_show $standby_in_ksh -n '________' -a 0x0 -v $vrf_in_ksh -x $af_in_ksh -E'

rp_set1_exec[3]='show eigrp $standby_in_exec $vrf_in_exec $af_in_exec interfaces detail'
rp_set1__ksh[3]='eigrp_show $standby_in_ksh -n '________' -a 0x0 -v $vrf_in_ksh -x $af_in_ksh -f 0x0 -i none -d 0x1 -r 0x0 -I'

rp_set1_exec[4]='show eigrp $standby_in_exec $vrf_in_exec $af_in_exec neighbors detail'
rp_set1__ksh[4]='eigrp_show $standby_in_ksh -n '________' -a 0x0 -v $vrf_in_ksh -x $af_in_ksh -f 0x0 -i none -e 0x0 -d 0x1 -N'

rp_set1_exec[5]='show eigrp $standby_in_exec $vrf_in_exec $af_in_exec statistics'
rp_set1__ksh[5]='eigrp_show $standby_in_ksh -n '________' -a 0x0 -v $vrf_in_ksh -x $af_in_ksh -C'

rp_set1_exec[6]='show eigrp $standby_in_exec $vrf_in_exec $af_in_exec traffic'
rp_set1__ksh[6]='eigrp_show $standby_in_ksh -n '________' -a 0x0 -v $vrf_in_ksh -x $af_in_ksh -S'

rp_set1_exec[7]='show eigrp $standby_in_exec $vrf_in_exec $af_in_exec topology detail'
rp_set1__ksh[7]='eigrp_show $standby_in_ksh -n '________' -a 0x0 -v $vrf_in_ksh -x $af_in_ksh -f 0x0 -p 0x0 -m 0x0 -e 0x5 -r 0x0 -T'

rp_set1_exec[8]='show eigrp $standby_in_exec $vrf_in_exec $af_in_exec topology all'
rp_set1__ksh[8]='eigrp_show $standby_in_ksh -n '________' -a 0x0 -v $vrf_in_ksh -x $af_in_ksh -f 0x0 -p 0x0 -m 0x0 -e 0x4 -r 0x0 -T'

rp_set1__ksh[9]=''

# EIGRP process related commands that run on RP/DRP where EIGRP is running 

rp_set11_exec[1]='show eigrp $standby_in_exec ha'
rp_set11__ksh[1]='eigrp_show $standby_in_ksh -n '________' -x 0x0 -H'

rp_set11_exec[2]='show eigrp $standby_in_exec process statistics'
rp_set11__ksh[2]='eigrp_show $standby_in_ksh -n '________' -x 0x0 -B'

rp_set11_exec[3]='show eigrp $standby_in_exec process ipv4 statistics'
rp_set11__ksh[3]='eigrp_show $standby_in_ksh -n '________' -x 0x1 -B'

rp_set11_exec[4]='show eigrp $standby_in_exec process ipv6 statistics'
rp_set11__ksh[4]='eigrp_show $standby_in_ksh -n '________' -x 0x2 -B'

rp_set11__ksh[5]=''

# EIGRP process related commands that run on RP/DRP where EIGRP is running 

rp_set2_exec[1]='show process eigrp'
rp_set2__ksh[1]='sysmgr_show -o -p eigrp'

rp_set2_exec[2]='show process blocked'
if [ "$platform" == "panini" ]; then
    rp_set2__ksh[2]='sh_proc_ng_blocked'
else    
    rp_set2__ksh[2]='show_processes -b'
fi 

rp_set2_exec[3]='follow process 1 stackonly delay 2'
rp_set2__ksh[3]='attach_process -p $eigrp_pid -d 2 -S'

rp_set2__ksh[4]=''

# ITAL commands that run on RP/DRP where EIGRP is running

rp_set3_exec[1]='show ital registrations vrf process eigrp location $local_node'
rp_set3__ksh[1]='ital_show -x 0x1 -y eigrp -z 0x1 -l $local_nodeid'

rp_set3_exec[2]='show ital registrations interface process eigrp location $local_node'
rp_set3__ksh[2]='ital_show -x 0x1 -y eigrp -z 0x0 -l $local_nodeid'

rp_set3_exec[3]='show ital dbase vrf-dbase all process eigrp location $local_node'
rp_set3__ksh[3]='ital_show -x 0x1 -y eigrp -z 0x3 -a all-vrf -e 0x0 -f none -l $local_nodeid'

rp_set3_exec[4]='show ital dbase if-dbase all process eigrp location $local_node'
rp_set3__ksh[4]='ital_show -x 0x1 -y eigrp -z 0x2 -a none -e 0x1 -f all-if -l $local_nodeid'

rp_set3__ksh[5]=''

# RAW commands that run on RP/DRP where EIGRP is running

rp_set4_exec[1]='show raw brief'
rp_set4__ksh[1]='raw_show show brief'

rp_set4__ksh[2]=''

# SYSDB commands that run on RP/DRP where EIGRP is running

rp_set5_exec[1]='show sysdb statistics clients $eigrp_jid location $local_node'
rp_set5__ksh[1]='sysdbshow -l $local_nodeid -c stats client $eigrp_jid'

rp_set5__ksh[2]=''

# IPv4 RIB commands that run on RP/DRP where ipv4_rib is running

rp_set6_exec[1]='show rib $vrf_in_exec ipv4 protocols $standby_in_exec'
rp_set6__ksh[1]='show_ipv4_rib -X 0x1 -Y 0x1 -Z $vrf_in_ksh -V ________ $standby_in_ksh -z 0x0'

rp_set6_exec[2]='show route $vrf_in_exec ipv4 eigrp $standby_in_exec'
rp_set6__ksh[2]='show_ipv4_rib -X 0x1 -Y 0x1 -Z $vrf_in_ksh -V ________ $standby_in_ksh -P eigrp ipv4 $vrf_in_ksh'

rp_set6_exec[3]='show route $vrf_in_exec ipv4 summary $standby_in_exec'
rp_set6__ksh[3]='show_ipv4_rib -X 0x1 -Y 0x1 -Z $vrf_in_ksh -V ________ -S $standby_in_ksh ipv4 $vrf_in_ksh'

rp_set6__ksh[4]=''

# IPv6 RIB commands that run on RP/DRP where ipv6_rib is running

rp_set7_exec[1]='show rib $vrf_in_exec ipv6 protocols $standby_in_exec'
rp_set7__ksh[1]='show_ipv6_rib -X 0x2 -Y 0x1 -Z $vrf_in_ksh -V ________ $standby_in_ksh -z 0x0'

rp_set7_exec[2]='show route $vrf_in_exec ipv6 eigrp $standby_in_exec'
rp_set7__ksh[2]='show_ipv6_rib -X 0x2 -Y 0x1 -Z $vrf_in_ksh -V ________ $standby_in_ksh -P eigrp ipv6 $vrf_in_ksh'

rp_set7_exec[3]='show route $vrf_in_exec ipv6 summary $standby_in_exec'
rp_set7__ksh[3]='show_ipv6_rib -X 0x2 -Y 0x1 -Z $vrf_in_ksh -V ________ -S $standby_in_ksh ipv6 $vrf_in_ksh'

rp_set7__ksh[4]=''

# EIGRP trace command that runs on all RP/DRP where EIGRP is running

rp_set8_exec[1]='show eigrp trace'
rp_set8__ksh[1]='eigrp_show_ltrace -N ________ -O 0x1000000'

rp_set8__ksh[2]=''

# Non-EIGRP commands that run on all LC's

if [ $platform == 'panini' ] || [ $platform == 'hfr' ]; then
    lc_set1_exec[1]='sh lpts pifib hardware entry brief location $local_node'
    lc_set1__ksh[1]='show_platform_pifib -z 0x2 -i $local_nodeid'

    lc_set1_exec[2]='sh lpts pifib hardware entry statistics location $local_node'
    lc_set1__ksh[2]='show_platform_pifib -z 0x3 -i $local_nodeid'
else
    lc_set1_exec[1]='sh lpts pifib hardware entry brief location $local_node'
    lc_set1__ksh[1]='platform_show_pifib -z 0x2 -i $local_nodeid'

    lc_set1_exec[2]='sh lpts pifib hardware entry statistics location $local_node'
    lc_set1__ksh[2]='platform_show_pifib -z 0x3 -i $local_nodeid'
fi

lc_set1__ksh[3]=''

do_find_node_details() {
    OS_STRING=`uname`
    if [ $platform == 'panini' ]; then
	local_node_name=$(uname -n | cut -d "_" -f 2,3,4)
    else
	local_node_name=$(uname -n)
    fi
    
    local_node=$(node_conversion -E $local_node_name)
    local_nodeid=$(node_conversion -i "/net/$local_node_name")

    if [ "$__cardtype" == "RP" -o "$__cardtype" == "DRP" ]; then
        standby=$(redcon_show | grep -c -E "\($local_node\) is in STANDBY role")
    fi
}

do_find_eigrp_details() {
    eigrp_running=$(sysmgr_show -o -p eigrp | grep -c -E "Process state: Run")
    if [ $eigrp_running == 1 ]; then
        jid=$(sysmgr_show -o -p eigrp -D | grep -E "Job Id")
        eigrp_jid=$(echo $jid | cut -f 3 -d " ")
        pid=$(sysmgr_show -o -p eigrp -D | grep -E "PID")
        eigrp_pid=$(echo $pid | cut -f 2 -d " ")
    fi
}

do_find_rib_details() {
    ipv4_rib_running=$(sysmgr_show -o -p ipv4_rib | grep -c -E "Process state: Run")
    ipv6_rib_running=$(sysmgr_show -o -p ipv6_rib | grep -c -E "Process state: Run")
}

display() {
    print_main_heading "show tech-support routing eigrp"
    
    if [ "$__cardtype" == "SYS" ]; then
        exec_commands sys
    else
        case "$__cardtype" in
        "LC")
             do_find_node_details

             # Print output of Non-EIGRP commands
             exec_commands lc_set1
            ;;
        "RP" | "DRP")
             do_find_node_details
             do_find_eigrp_details
             do_find_rib_details

             if [ $eigrp_running == 1 ]; then
                 if [ $standby == 1 ]; then
                     standby_in_exec='standby'
                     standby_in_ksh='-Y'
                 fi

                 # Print output of EIGRP commands (default-v4)
                 exec_commands rp_set1

                 # Print output of EIGRP commands (default-v6)
                 af_in_exec='ipv6'
                 af_in_ksh='0x2'
                 exec_commands rp_set1

                 # Print output of EIGRP commands (allother-v4)
                 vrf_in_exec='vrf all'
                 vrf_in_ksh='all'
                 af_in_exec='ipv4'
                 af_in_ksh='0x1'
                 exec_commands rp_set1

                 # Print output of EIGRP commands (allother-v6)
                 af_in_exec='ipv6'
                 af_in_ksh='0x2'
                 exec_commands rp_set1

                 # Print output of EIGRP commands
                 exec_commands rp_set11

                 # Print output of EIGRP process related commands
                 exec_commands rp_set2

                 # Print output of ITAL commands
                 exec_commands rp_set3

                 # Print output of RAW commands
                 exec_commands rp_set4

                 # Print output of SYSDB commands
                 exec_commands rp_set5
             fi

             if [ $ipv4_rib_running == 1 ]; then
                 if [ $standby == 1 ]; then
                     standby_in_exec='standby'
                     standby_in_ksh='-t'
                 fi

                 # Print output of RIB commands (default VRF)
                 vrf_in_exec='vrf default'
                 vrf_in_ksh='default'
                 exec_commands rp_set6

                 # Print output of RIB commands (all other VRF's)
                 vrf_in_exec='vrf all'
                 vrf_in_ksh='all'
                 exec_commands rp_set6
             fi

             if [ $ipv6_rib_running == 1 ]; then
                 if [ $standby == 1 ]; then
                     standby_in_exec='standby'
                     standby_in_ksh='-t'
                 fi

                 # Print output of RIB commands (default VRF)
                 vrf_in_exec='vrf default'
                 vrf_in_ksh='default'
                 exec_commands rp_set7

                 # Print output of RIB commands (all other VRF's)
                 vrf_in_exec='vrf all'
                 vrf_in_ksh='all'
                 exec_commands rp_set7
             fi

             if [ $eigrp_running == 1 ]; then
                # Print EIGRP traces
                exec_commands rp_set8
             fi
            ;;
        esac
    fi
 
    print_main_heading "show tech-support routing eigrp complete"
}

. /pkg/bin/show_tech_file_fragment

