#!/pkg/bin/ksh
# Created by Hassan Hosseini July 2003
# Copyright (c) 2003-2017, 2021 by cisco Systems, Inc.
# All rights reserved.
#
# This scripts expects 1 to 4 arguments
#
# -L <level> where level is 0x1, 0x2, 0x3, or 0x4
#
# -f <device> <filename> These two arguments are used to redirect
#                        output to a file system, ex: disk, 
#                        tftp, ftp etc..
# -N 0/1/cpu0   Some (optional) location
#
# -v <vrf>   vrf name; "default" if not specified
#----------------------------------------------------------------------

#
# TODO-SKRAZA-CSC/V6: VRF-ize/AF-ize the script/cmds
#

# This script fragment contains the code for the following functions
# - print_main_heading
# - print_command_heading
# - run_single_command
# - run_commands
# - run_single_command_on_all_nodes
# - run_commands_on_all_nodes
# - default_parser_function
. /pkg/bin/show_tech_main_fragment

# Initialise any variables used. 
debug_level_nb="0x3"
debug_level_str=""
afi="ipv4"
vrf_i=""
location=""

# Fetch the list of vrfs through show run mpls ldp
vrf_list=`nvgen -c -q gl/mpls_ldp/ | grep -E vrf | grep -v default | cut -c 6-`

# Parse the arguments to the script.
# Usage: 
# 
#    mpls_ldp_show_tech [-L <level>] [-f <file>] [-l 0/1/CPU0]
#                       [-V <vrf>]
while [ "$#" -gt "0" ]; do
  case "$1" in
     -L) debug_level_nb="$2"; shift 2;;
     -V) vrf_i="$2"; shift 2;;
     -l) location="$2"; shift 2;;
     *)  default_parser_function "$@"; shift $#;;
  esac
done

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

# Set debug_level_str
case "$debug_level_nb" in
    "0x1") debug_level_str="Brief Summary";;
    "0x2") debug_level_str="Regular";;
    "0x3") debug_level_str="Detail with Event traces";;
    "0x4") debug_level_str="Extended";;
    *) echo "Invalid Debug level entered: $debug_level_nb"; exit;;
esac

#Set VRF options
if [[ $vrf_i = "all" ]];then
   #prints out all vrf
   vrf_i=""
   vrf_i_ksh="default"
elif [[ $vrf_i = "default" ]];then
   #prints out default vrf only
   vrf_i=""
   vrf_i_ksh="default"
   vrf_list=""
else
   valid_vrf=0
   for vrf in $vrf_list;do
      if [[ $vrf_i = $vrf ]]; then
           #prints out selected vrf
          vrf_list=""
          vrf_i_ksh=$vrf_i
          vrf_i="vrf $vrf_i"
          valid_vrf=1
          break
      fi
   done

   if [[ $valid_vrf = 0 ]]; then
     echo "Invalid LDP VRF name entered: $vrf_i.  Collecting DFLT"
     vrf_i=""
     vrf_i_ksh="default"
     vrf_list=""
   fi
fi

#Platform specific commands
# find a media to store showtech output
uname -a | grep hfr > /dev/null 2>&1;  RC=$?
uname -a | grep prp > /dev/null 2>&1;  RC1=$?
uname -a | grep enxr > /dev/null 2>&1; RC2=$?
uname -a | grep asr9k > /dev/null 2>&1; RC3=$?  
uname -a | grep xrvr > /dev/null 2>&1; RC4=$?

if [[ "$RC" -eq "0" ]]; then
    platform="hfr"
elif [[ "$RC1" -eq "0" ]]; then
    platform="prp"
elif [[ "$RC2" -eq "0" ]]; then
    platform="enxr"
elif [[ "$RC3" -eq "0" ]]; then 
    platform="viking"
elif [[ "$RC4" -eq "0" ]]; then 
    platform="xrvr"
else
    platform="panini"
fi 

# List each set of show commands to be run. Each set must finish with an empty
# string. Note that it is important to use single quotes rather than double 
# quotes for the strings containing your commands; showtech infra expects the command
# exactly the way it was entered.
# Use "\" ahead of any special character (eg. |) used in the command line.

# System commands
i=1
j=1
System_exec[$((i++))]='show clock'
System__ksh[$((j++))]='iosclock -d 0x0'
System_exec[$((i++))]='show running-config hostname'
System__ksh[$((j++))]='nvgen -c -q gl/a/hostname'
System_exec[$((i++))]='show platform'
if [[ "$platform" = "viking" ]]; then 
     System__ksh[$((j++))]='show_platform_vkg -e'
elif [[ "$platform" = "panini" ]]; then
     System__ksh[$((j++))]='show_platform_sysdb -v'
elif [[ "$platform" = "hfr" ]]; then
     System__ksh[$((j++))]='shelfmgr_show_hfr -e'
else 
     System__ksh[$((j++))]='show_platform -a'
fi
System_exec[$((i++))]='show version'
if [[ "$platform" = "panini" ]]; then 
     System__ksh[$((j++))]='ng_show_version'
else
     System__ksh[$((j++))]='show_version'
fi
if [[ "$platform" = "panini" ]]; then 
     System_exec[$((i++))]='show install active'
     System__ksh[$((j++))]='sdr_instcmd show install active'
else
     System_exec[$((i++))]='show install active summary'
     System__ksh[$((j++))]='instcmd show install active summary'
fi
System_exec[$((i++))]='show redundancy location $location'
System__ksh[$((j++))]='redcon_show -n $fq_nodeid'
System_exec[$((i++))]='show redundancy summary'
System__ksh[$((j++))]='redcon_show -s'

# Common commands
i=1
j=1
Common_exec[$((i++))]='show clock'
Common__ksh[$((j++))]='iosclock -d 0x0'
Common_exec[$((i++))]='show running-config hostname'
Common__ksh[$((j++))]='nvgen -c -q gl/a/hostname'
Common_exec[$((i++))]='show platform'
if [[ "$platform" = "viking" ]]; then 
     Common__ksh[$((j++))]='show_platform_vkg -e'
elif [[ "$platform" = "panini" ]]; then
     Common__ksh[$((j++))]='show_platform_sysdb -v'
elif [[ "$platform" = "hfr" ]]; then
     Common__ksh[$((j++))]='shelfmgr_show_hfr -e'
else 
     Common__ksh[$((j++))]='show_platform -a'
fi
Common_exec[$((i++))]='show version'
if [[ "$platform" = "panini" ]]; then 
     Common__ksh[$((j++))]='ng_show_version'
else
     Common__ksh[$((j++))]='show_version'
fi
if [[ "$platform" = "panini" ]]; then 
     Common_exec[$((i++))]='show install active'
     Common__ksh[$((j++))]='sdr_instcmd show install active'
else
     Common_exec[$((i++))]='show install active summary'
     Common__ksh[$((j++))]='instcmd show install active summary'
fi
Common_exec[$((i++))]='show redundancy location $location'
Common__ksh[$((j++))]='redcon_show -n $fq_nodeid'
Common_exec[$((i++))]='show redundancy summary'
Common__ksh[$((j++))]='redcon_show -s'
Common_exec[$((i++))]='show ntp status'
Common__ksh[$((j++))]='ntp_command show -s'
Common_exec[$((i++))]='show placement program mpls_ldp'
Common__ksh[$((j++))]='placed_show -p mpls_ldp'
Common_exec[$((i++))]='show placement program ipv4_rib'
Common__ksh[$((j++))]='placed_show -p ipv4_rib'
Common_exec[$((i++))]='show placement program l2vpn_mgr'
Common__ksh[$((j++))]='placed_show -p l2vpn_mgr'
Common_exec[$((i++))]='show running-config'
Common__ksh[$((j++))]='nvgen -c -l 1 -t 1 -o 1'
Common_exec[$((i++))]='show running-config mpls ldp'
Common__ksh[$((j++))]='nvgen -c -q gl/mpls_ldp/'
Common_exec[$((i++))]='show run formal mpls ldp'
Common__ksh[$((j++))]='nvgen -e -q gl/mpls_ldp/'
Common_exec[$((i++))]='show proc mpls_ldp location $location'
Common__ksh[$((j++))]='sysmgr_show -o -p mpls_ldp -n $fq_nodeid'
Common_exec[$((i++))]='show iccp group location $location'
Common__ksh[$((j++))]='iccp_show -t 0x1 -h $fq_nodeid'
Common_exec[$((i++))]='show arm ipv4 router-ids'
Common__ksh[$((j++))]='ip_arm_show -v 4 -f default -l -1 -k'
Common_exec[$((i++))]='show mpls ldp summary all location $location'
Common__ksh[$((j++))]='mpls_ldp_show -t 0x18 0x1 -N $fq_nodeid'
Common_exec[$((i++))]='show mpls ldp bindings summary all location $location'
Common__ksh[$((j++))]='mpls_ldp_show -t 0x2 -v default 0x1 -N $fq_nodeid -V'
Common_exec[$((i++))]='show mpls ldp discovery summary all location $location'
Common__ksh[$((j++))]='mpls_ldp_show -t 0x3 0x1 -N $fq_nodeid -S'
Common_exec[$((i++))]='show mpls ldp forwarding summary all location $location'
Common__ksh[$((j++))]='mpls_ldp_show -t 0x8 -v default 0x1 -N $fq_nodeid -S'
Common_exec[$((i++))]='show mpls ldp nsr summary all location $location'
Common__ksh[$((j++))]='mpls_ldp_show -t 0x13 -v default 0x1 -N $fq_nodeid -V'
Common_exec[$((i++))]='show mpls ldp ipv4 interface summary location $location'
Common__ksh[$((j++))]='mpls_ldp_show -t 0xf -v default 0x1 -N $fq_nodeid -s'
Common_exec[$((i++))]='show mpls ldp vrf all summary location $location'
Common__ksh[$((j++))]='mpls_ldp_show -t 0x7 -v all 0x1 -N $fq_nodeid'
Common_exec[$((i++))]='show mpls ldp vrf all $afi discovery summary location $location'
Common__ksh[$((j++))]='mpls_ldp_show -t 0x3 -v all 0x1 -N $fq_nodeid -s'
Common_exec[$((i++))]='show mpls ldp vrf all $afi bindings summary location $location'
Common__ksh[$((j++))]='mpls_ldp_show -t 0x2 -v all 0x1 -N $fq_nodeid -s'
Common_exec[$((i++))]='show mpls ldp vrf all $afi forwarding summary location $location'
Common__ksh[$((j++))]='mpls_ldp_show -t 0x8 -v all 0x1 -N $fq_nodeid -s'
Common_exec[$((i++))]='show mpls ldp vrf all nsr summary location $location'
Common__ksh[$((j++))]='mpls_ldp_show -t 0x13 -v all 0x1 -N $fq_nodeid'
Common_exec[$((i++))]=''
Common__ksh[$((j++))]=''

# LDP commands at Debug level 0x1
i=1
j=1
Level1_exec[$((i++))]='show mpls ldp ipv4 interface brief location $location'
Level1__ksh[$((j++))]='mpls_ldp_show -t 0xf -v default 0x1 -N $fq_nodeid -b'
Level1_exec[$((i++))]='show mpls ldp ipv6 interface brief location $location'
Level1__ksh[$((j++))]='mpls_ldp_show -t 0xf -v default 0x2 -N $fq_nodeid -b'
Level1_exec[$((i++))]='show mpls ldp vrf all $afi discovery brief location $location'
Level1__ksh[$((j++))]='mpls_ldp_show -t 0x3 -v all 0x1 -N $fq_nodeid -b'
Level1_exec[$((i++))]='show mpls ldp ipv6 discovery brief location $location'
Level1__ksh[$((j++))]='mpls_ldp_show -t 0x3 -v default 0x2 -N $fq_nodeid -b'
Level1_exec[$((i++))]='show mpls ldp vrf all $afi igp sync brief location $location'
Level1__ksh[$((j++))]='mpls_ldp_show -t 0xe -v all 0x1 -N $fq_nodeid -b'
Level1_exec[$((i++))]='show mpls ldp ipv6 igp sync brief location $location'
Level1__ksh[$((j++))]='mpls_ldp_show -t 0xe -v default 0x2 -N $fq_nodeid -b'
Level1_exec[$((i++))]='show mpls ldp vrf all neighbor brief location $location'
Level1__ksh[$((j++))]='mpls_ldp_show -t 0x4 -v all 0x1 -N $fq_nodeid -b'
Level1_exec[$((i++))]='show mpls ldp vrf all $afi bindings brief location $location'
Level1__ksh[$((j++))]='mpls_ldp_show -t 0x2 -v all 0x1 -N $fq_nodeid -B'
Level1_exec[$((i++))]='show mpls ldp ipv6 bindings brief location $location'
Level1__ksh[$((j++))]='mpls_ldp_show -t 0x2 -v default 0x2 -N $fq_nodeid -B'
Level1_exec[$((i++))]='show clock'
Level1__ksh[$((j++))]='iosclock -d 0x0'
Level1_exec[$((i++))]=''
Level1__ksh[$((j++))]=''

# LDP commands at Debug level 0x2
i=1
j=1
Level2_exec[$((i++))]='show mpls ldp ipv4 interface location $location'
Level2__ksh[$((j++))]='mpls_ldp_show -t 0xf -v default 0x1 -N $fq_nodeid'
Level2_exec[$((i++))]='show mpls ldp statistic im location $location'
Level2__ksh[$((j++))]='mpls_ldp_show -t 0xb 0x1 -N $fq_nodeid -i'
Level2_exec[$((i++))]='show mpls ldp statistics fwd-setup location $location'
Level2__ksh[$((j++))]='mpls_ldp_show -t 0xb -v default 0x1 -N $fq_nodeid -f'
Level2_exec[$((i++))]='show tcp nsr client brief location $location' 
Level2__ksh[$((j++))]='tss_show -t b -c 0 -l $fq_nodeid'
Level2_exec[$((i++))]='show tcp nsr brief location $location'
Level2__ksh[$((j++))]='tss_show -t b -p 0 -l $fq_nodeid'
Level2_exec[$((i++))]='show tcp nsr session-set brief location $location' 
Level2__ksh[$((j++))]='tss_show -t b -s 0 -l $fq_nodeid'
Level2_exec[$((i++))]='show tcp nsr statistics summary location $location'
Level2__ksh[$((j++))]='tss_show -t s -l $fq_nodeid'
Level2_exec[$((i++))]='show tcp nsr statistics session-set all location $location'
Level2__ksh[$((j++))]='tss_show -t s -s 0 -l $fq_nodeid'
Level2_exec[$((i++))]='show isis neighbors'
Level2__ksh[$((j++))]='isis_show -x'
Level2_exec[$((i++))]='show route vrf all ipv4 summary'
Level2__ksh[$((j++))]='show_ipv4_rib -X 0x1 -Y 0x1 -Z all -V ________ -S ipv4 all'
Level2_exec[$((i++))]='show route vrf all ipv6 summary'
Level2__ksh[$((j++))]='show_ipv6_rib -X 0x2 -Y 0x1 -Z all -V ________ -S ipv6 all'
Level2_exec[$((i++))]='show rib vrf all ipv4 protocols'
Level2__ksh[$((j++))]='show_ipv4_rib -X 0x1 -Y 0x1 -Z all -V ________ -z 0x0'
Level2_exec[$((i++))]='show rib vrf all ipv6 protocols'
Level2__ksh[$((j++))]='show_ipv6_rib -X 0x2 -Y 0x1 -Z all -V ________ -z 0x0'
Level2_exec[$((i++))]='show rib ipv4 protocols'
Level2__ksh[$((j++))]='show_ipv4_rib -X 0x1 -Y 0x1 -Z ________ -V ________ -z 0x0'
Level2_exec[$((i++))]='show rib ipv6 protocols'
Level2__ksh[$((j++))]='show_ipv6_rib -X 0x2 -Y 0x1 -Z ________ -V ________ -z 0x0'
Level2_exec[$((i++))]='show rib ipv4 clients redistribution'
Level2__ksh[$((j++))]='show_ipv4_rib -X 0x1 -v 0x0'
Level2_exec[$((i++))]='show rib ipv6 clients redistribution'
Level2__ksh[$((j++))]='show_ipv6_rib -X 0x2 -v 0x0'
Level2_exec[$((i++))]='show ospf neighbor'
Level2__ksh[$((j++))]='ospf_show -T + -v + -l active -N -X 0x0 -Y 0x0 -f 0x0 -i 0x0 -a 0x0 -d 0x0 -j 0x0'
Level2_exec[$((i++))]='show ospfv3 neighbor'
Level2__ksh[$((j++))]='ospfv3_show_nbr -T + -v + -L active -X 0x0 -Y 0x0 -f 0x0 -i 0x0 -a 0x0 -d 0x0'
Level2_exec[$((i++))]='show mpls traffic-eng tunnels brief'
Level2__ksh[$((j++))]='mpls_te_show 0x1 ipv4 unicast -z 0x1'
Level2_exec[$((i++))]='show proc ipv4_rib'
Level2__ksh[$((j++))]='sysmgr_show -o -p ipv4_rib'
Level2_exec[$((i++))]='show proc ipv6_rib'
Level2__ksh[$((j++))]='sysmgr_show -o -p ipv6_rib'
Level2_exec[$((i++))]='show proc rsi_agent'
Level2__ksh[$((j++))]='sysmgr_show -o -p rsi_agent'
Level2_exec[$((i++))]='show clock'
Level2__ksh[$((j++))]='iosclock -d 0x0'
Level2_exec[$((i++))]=''
Level2__ksh[$((j++))]=''

# Per VRF
i=1
j=1
Level2V_exec[$((i++))]='show mpls ldp $vrf parameters location $location'
Level2V__ksh[$((j++))]='mpls_ldp_show -t 0x5 -v $vrf_i_ksh 0x1 -N $fq_nodeid'
Level2V_exec[$((i++))]='show mpls ldp $vrf capabilities location $location'
Level2V__ksh[$((j++))]='mpls_ldp_show -t 0x14 -v $vrf_i_ksh 0x1 -N $fq_nodeid -a'
Level2V_exec[$((i++))]='show mpls ldp $vrf $afi discovery location $location'
Level2V__ksh[$((j++))]='mpls_ldp_show -t 0x3 -v $vrf_i_ksh 0x1 -N $fq_nodeid'
Level2V_exec[$((i++))]='show mpls ldp $vrf $afi igp sync location $location'
Level2V__ksh[$((j++))]='mpls_ldp_show -t 0xe -v $vrf_i_ksh 0x1 -N $fq_nodeid'
Level2V_exec[$((i++))]='show mpls ldp $vrf neighbor location $location'
Level2V__ksh[$((j++))]='mpls_ldp_show -t 0x4 -v $vrf_i_ksh 0x1 -N $fq_nodeid -e'
Level2V_exec[$((i++))]='show mpls ldp $vrf graceful-restart location $location'
Level2V__ksh[$((j++))]='mpls_ldp_show -t 0xa -v $vrf_i_ksh 0x1 -N $fq_nodeid -g'
Level2V_exec[$((i++))]='show mpls ldp $vrf backoff location $location'
Level2V__ksh[$((j++))]='mpls_ldp_show -t 0x1 -v $vrf_i_ksh 0x1 -N $fq_nodeid'
Level2V_exec[$((i++))]='show mpls ldp $vrf statistics msg-counters location $location'
Level2V__ksh[$((j++))]='mpls_ldp_show -t 0xb -v $vrf_i_ksh 0x1 -N $fq_nodeid -e'
Level2V_exec[$((i++))]='show mpls ldp $vrf $afi bindings location $location'
Level2V__ksh[$((j++))]='mpls_ldp_show -t 0x2 -v $vrf_i_ksh 0x1 -N $fq_nodeid'
Level2V_exec[$((i++))]='show mpls ldp $vrf $afi forwarding location $location'
Level2V__ksh[$((j++))]='mpls_ldp_show -t 0x8 -v $vrf_i_ksh 0x1 -N $fq_nodeid'
Level2V_exec[$((i++))]='show mpls ldp $vrf nsr pending neighbor location $location'
Level2V__ksh[$((j++))]='mpls_ldp_show -t 0x12 -v $vrf_i_ksh 0x1 -N $fq_nodeid'
Level2V_exec[$((i++))]='show mpls ldp $vrf nsr statistics location $location'
Level2V__ksh[$((j++))]='mpls_ldp_show -t 0x10 -v $vrf_i_ksh 0x1 -N $fq_nodeid'
Level2V_exec[$((i++))]='show mpls ldp $vrf nsr statistic neighbor location $location'
Level2V__ksh[$((j++))]='mpls_ldp_show -t 0x11 -v $vrf_i_ksh 0x1 -N $fq_nodeid'
Level2V_exec[$((i++))]=''
Level2V__ksh[$((j++))]=''

#IPv6
i=1
j=1
Level2AF_exec[$((i++))]='show mpls ldp ipv6 discovery location $location'
Level2AF__ksh[$((j++))]='mpls_ldp_show -t 0x3 -v default 0x2 -N $fq_nodeid'
Level2AF_exec[$((i++))]='show mpls ldp ipv6 igp sync location $location'
Level2AF__ksh[$((j++))]='mpls_ldp_show -t 0xe -v default 0x2 -N $fq_nodeid'
Level2AF_exec[$((i++))]='show mpls ldp ipv6 bindings location $location'
Level2AF__ksh[$((j++))]='mpls_ldp_show -t 0x2 -v default 0x2 -N $fq_nodeid'
Level2AF_exec[$((i++))]='show mpls ldp ipv6 forwarding location $location'
Level2AF__ksh[$((j++))]='mpls_ldp_show -t 0x8 -v default 0x2 -N $fq_nodeid'
Level2AF_exec[$((i++))]=''
Level2AF__ksh[$((j++))]=''

# LDP commands at Debug level 0x3
i=1
j=1
Level3_exec[$((i++))]='show mpls ldp $afi interface detail location $location'
Level3__ksh[$((j++))]='mpls_ldp_show -t 0xf -v default 0x1 -N $fq_nodeid -d'
Level3_exec[$((i++))]='show mpls ldp ipv6 interface detail location $location'
Level3__ksh[$((j++))]='mpls_ldp_show -t 0xf -v default 0x2 -N $fq_nodeid -d'
Level3_exec[$((i++))]='show mpls ldp $afi struct'
Level3__ksh[$((j++))]='mpls_ldp_show -t 0x6 -v default 0x1 -Z false -a'
Level3_exec[$((i++))]='show mpls ldp ipv6 struct'
Level3__ksh[$((j++))]='mpls_ldp_show -t 0x6 -v default 0x2 -Z false -a'
Level3_exec[$((i++))]='show mpls ldp trace location $location'
Level3__ksh[$((j++))]='mpls_ldp_show_trace -i $fq_nodeid' 
Level3_exec[$((i++))]='show iccp counters location $location'
Level3__ksh[$((j++))]='iccp_show -t 0x2 -h $fq_nodeid'
Level3_exec[$((i++))]='show iccp trace location $location'
Level3__ksh[$((j++))]='iccp_show_trace -i $fq_nodeid'
Level3_exec[$((i++))]='show clock'
Level3__ksh[$((j++))]='iosclock -d 0x0'
Level3_exec[$((i++))]=''
Level3__ksh[$((j++))]=''

# Per VRF
i=1
j=1
#-1- Other show commands
Level3V_exec[$((i++))]='show running-config mpls ldp $vrf'
Level3V__ksh[$((j++))]='nvgen -c -q gl/mpls_ldp/ord_2_vrf/ord_2/$vrf_i_ksh/'
Level3V_exec[$((i++))]='show mpls ldp $vrf capabilities detail location $location'
Level3V__ksh[$((j++))]='mpls_ldp_show -t 0x14 -v $vrf_i_ksh 0x1 -N $fq_nodeid -a -d'
Level3V_exec[$((i++))]='show mpls ldp $vrf graceful-restart detail location $location'
Level3V__ksh[$((j++))]='mpls_ldp_show -t 0xa -v $vrf_i_ksh 0x1 -N $fq_nodeid -g -d'

Level3V_exec[$((i++))]='show mpls ldp $vrf $afi structs location $location'
Level3V__ksh[$((j++))]='mpls_ldp_show -t 0x6 -v $vrf_i_ksh 0x1 -N $fq_nodeid -a'
Level3V_exec[$((i++))]='show mpls ldp $vrf ipv6 structs location $location'
Level3V__ksh[$((j++))]='mpls_ldp_show -t 0x6 -v $vrf_i_ksh 0x2 -N $fq_nodeid -a'

Level3V_exec[$((i++))]='show mpls ldp $vrf $afi igp sync location $location'
Level3V__ksh[$((j++))]='mpls_ldp_show -t 0xe -v $vrf_i_ksh 0x1 -N $fq_nodeid'
Level3V_exec[$((i++))]='show mpls ldp $vrf ipv6 igp sync location $location'
Level3V__ksh[$((j++))]='mpls_ldp_show -t 0xe -v $vrf_i_ksh 0x2 -N $fq_nodeid'

Level3V_exec[$((i++))]='show mpls ldp $vrf neighbor gr location $location'
Level3V__ksh[$((j++))]='mpls_ldp_show -t 0x4 -v $vrf_i_ksh 0x1 -N $fq_nodeid -g'
Level3V_exec[$((i++))]='show mpls ldp $vrf neighbor private location $location'
Level3V__ksh[$((j++))]='mpls_ldp_show -t 0x4 -v $vrf_i_ksh 0x1 -N $fq_nodeid -e -p'
#-2- Permutation of [interface, discovery, bindings, neighbor] and [detail, brief, summary]
#-2.1- Show detail 
Level3V_exec[$((i++))]='show mpls ldp $vrf $afi interface detail location $location'
Level3V__ksh[$((j++))]='mpls_ldp_show -t 0xf -v $vrf_i_ksh 0x1 -N $fq_nodeid -d'
Level3V_exec[$((i++))]='show mpls ldp $vrf ipv6 interface detail location $location'
Level3V__ksh[$((j++))]='mpls_ldp_show -t 0xf -v $vrf_i_ksh 0x2 -N $fq_nodeid -d'

Level3V_exec[$((i++))]='show mpls ldp $vrf $afi discovery detail location $location'
Level3V__ksh[$((j++))]='mpls_ldp_show -t 0x3 -v $vrf_i_ksh 0x1 -N $fq_nodeid -d'
Level3V_exec[$((i++))]='show mpls ldp $vrf ipv6 discovery detail location $location'
Level3V__ksh[$((j++))]='mpls_ldp_show -t 0x3 -v $vrf_i_ksh 0x2 -N $fq_nodeid -d'

Level3V_exec[$((i++))]='show mpls ldp $vrf $afi bindings detail location $location'
Level3V__ksh[$((j++))]='mpls_ldp_show -t 0x2 -v $vrf_i_ksh 0x1 -N $fq_nodeid -b'
Level3V_exec[$((i++))]='show mpls ldp $vrf ipv6 bindings detail location $location'
Level3V__ksh[$((j++))]='mpls_ldp_show -t 0x2 -v $vrf_i_ksh 0x2 -N $fq_nodeid -b'

Level3V_exec[$((i++))]='show mpls ldp $vrf $afi forwarding detail location $location'
Level3V__ksh[$((j++))]='mpls_ldp_show -t 0x8 -v $vrf_i_ksh 0x1 -N $fq_nodeid -d'
Level3V_exec[$((i++))]='show mpls ldp $vrf ipv6 forwarding detail location $location'
Level3V__ksh[$((j++))]='mpls_ldp_show -t 0x8 -v $vrf_i_ksh 0x2 -N $fq_nodeid -d'

Level3V_exec[$((i++))]='show mpls ldp $vrf neighbor detail location $location'
Level3V__ksh[$((j++))]='mpls_ldp_show -t 0x4 -v $vrf_i_ksh 0x1 -N $fq_nodeid -e -D'
#-2.2- Show brief
Level3V_exec[$((i++))]='show mpls ldp $vrf $afi interface brief location $location'
Level3V__ksh[$((j++))]='mpls_ldp_show -t 0xf -v $vrf_i_ksh 0x1 -N $fq_nodeid -b'
Level3V_exec[$((i++))]='show mpls ldp $vrf ipv6 interface brief location $location'
Level3V__ksh[$((j++))]='mpls_ldp_show -t 0xf -v $vrf_i_ksh 0x2 -N $fq_nodeid -b'

Level3V_exec[$((i++))]='show mpls ldp $vrf $afi discovery brief location $location'
Level3V__ksh[$((j++))]='mpls_ldp_show -t 0x3 -v $vrf_i_ksh 0x1 -N $fq_nodeid -b'
Level3V_exec[$((i++))]='show mpls ldp $vrf ipv6 discovery brief location $location'
Level3V__ksh[$((j++))]='mpls_ldp_show -t 0x3 -v $vrf_i_ksh 0x2 -N $fq_nodeid -b'

Level3V_exec[$((i++))]='show mpls ldp $vrf $afi bindings brief location $location'
Level3V__ksh[$((j++))]='mpls_ldp_show -t 0x2 -v $vrf_i_ksh 0x1 -N $fq_nodeid -B'
Level3V_exec[$((i++))]='show mpls ldp $vrf ipv6 bindings brief location $location'
Level3V__ksh[$((j++))]='mpls_ldp_show -t 0x2 -v $vrf_i_ksh 0x2 -N $fq_nodeid -B'

Level3V_exec[$((i++))]='show mpls ldp $vrf neighbor brief location $location'
Level3V__ksh[$((j++))]='mpls_ldp_show -t 0x4 -v $vrf_i_ksh 0x1 -N $fq_nodeid -e -b'
#-2.3- Show summary
Level3V_exec[$((i++))]='show mpls ldp $vrf $afi interface summary location $location'
Level3V__ksh[$((j++))]='mpls_ldp_show -t 0xf -v $vrf_i_ksh 0x1 -N $fq_nodeid -s'
Level3V_exec[$((i++))]='show mpls ldp $vrf ipv6 interface summary location $location'
Level3V__ksh[$((j++))]='mpls_ldp_show -t 0xf -v $vrf_i_ksh 0x2 -N $fq_nodeid -s'

Level3V_exec[$((i++))]='show mpls ldp $vrf $afi discovery summary location $location'
Level3V__ksh[$((j++))]='mpls_ldp_show -t 0x3 -v $vrf_i_ksh 0x1 -N $fq_nodeid -s'
Level3V_exec[$((i++))]='show mpls ldp $vrf ipv6 discovery summary location $location'
Level3V__ksh[$((j++))]='mpls_ldp_show -t 0x3 -v $vrf_i_ksh 0x2 -N $fq_nodeid -s'

Level3V_exec[$((i++))]='show mpls ldp $vrf $afi bindings summary location $location'
Level3V__ksh[$((j++))]='mpls_ldp_show -t 0x2 -v $vrf_i_ksh 0x1 -N $fq_nodeid -s'
Level3V_exec[$((i++))]='show mpls ldp $vrf ipv6 bindings summary location $location'
Level3V__ksh[$((j++))]='mpls_ldp_show -t 0x2 -v $vrf_i_ksh 0x2 -N $fq_nodeid -s'

Level3V_exec[$((i++))]='show mpls ldp $vrf $afi forwarding summary location $location'
Level3V__ksh[$((j++))]='mpls_ldp_show -t 0x8 -v $vrf_i_ksh 0x1 -N $fq_nodeid -s'
Level3V_exec[$((i++))]='show mpls ldp $vrf ipv6 forwarding summary location $location'
Level3V__ksh[$((j++))]='mpls_ldp_show -t 0x8 -v $vrf_i_ksh 0x2 -N $fq_nodeid -s'
Level3V_exec[$((i++))]=''
Level3V__ksh[$((j++))]=''

#IPv6
i=1
j=1
Level3AF_exec[$((i++))]='show mpls ldp ipv6 discovery detail location $location'
Level3AF__ksh[$((j++))]='mpls_ldp_show -t 0x3 -v default 0x2 -N $fq_nodeid -d'
Level3AF_exec[$((i++))]='show mpls ldp ipv6 bindings detail location $location'
Level3AF__ksh[$((j++))]='mpls_ldp_show -t 0x2 -v default 0x2 -N $fq_nodeid -b'
Level3AF_exec[$((i++))]='show mpls ldp ipv6 forwarding detail location $location'
Level3AF__ksh[$((j++))]='mpls_ldp_show -t 0x8 -v default 0x2 -N $fq_nodeid -d'
Level3AF_exec[$((i++))]=''
Level3AF__ksh[$((j++))]=''

# LDP extended tech commands level 0x4
i=1
j=1
Level4_exec[$((i++))]='show route ipv4 unicast'
Level4__ksh[$((j++))]='show_ipv4_rib -X 0x1 -Y 0x1 -Z ________ -V ________ -s ipv4 ________'
Level4_exec[$((i++))]='show route ipv6 unicast'
Level4__ksh[$((j++))]='show_ipv6_rib -X 0x2 -Y 0x1 -Z ________ -V ________ -s ipv6 ________'
Level4_exec[$((i++))]='show clock'
Level4__ksh[$((j++))]='iosclock -d 0x0'
Level4_exec[$((i++))]=''
Level4__ksh[$((j++))]=''

# A function called display() must be provided that calls the functions to 
# run the required show commands. The display() function is called in 
# /pkg/bin/show_tech_comp_file_frag

display() {
    # Print the output heading 
    print_main_heading "show tech-support mpls ldp start \(Verbosity: $debug_level_str\)" 
    
    if [ "$__cardtype" == "SYS" ]; then
	exec_commands System
    else
	# Run LDP specific commands
	exec_commands Common
	# Each level higher prints all the previous levels:
	while true; do
	    exec_commands Level1
	    if [ "$debug_level_nb" = "0x1" ] ; then
		break
            fi

	    exec_commands Level2
	    vrf=$vrf_i
            exec_commands Level2V
            exec_commands Level2AF
	    for vrf_i in $vrf_list;do
		vrf_i_ksh=$vrf_i
		vrf="vrf $vrf_i"
		exec_commands Level2V
            done
	    if [ "$debug_level_nb" = "0x2" ] ; then
     	        break
	    fi

	    vrf=$vrf_i
	    exec_commands Level3V
	    exec_commands Level3AF
	    for vrf_i in $vrf_list;do
		vrf_i_ksh=$vrf_i
		vrf="vrf $vrf_i"
		exec_commands Level3V
	    done
	    exec_commands Level3
	    if [ "$debug_level_nb" = "0x3" ] ; then
		break
	    fi

	    exec_commands Level4
	    break
        done
    fi

    # Add in additional tech-supports. These are on separate lines purely
    # from a readability perspective.

    # These tech-supports are always required (currently UDP is not supported)
    enable_techs "" udp tcp_nsr_fast lpts

    # These tech-supports are required for l2vpn related issues
    enable_techs "" /pkg/bin/l2vpn_show_tech_infra

    # These tech-supports are required for forwading related issues
    enable_techs "" /pkg/bin/rib_show_tech_script /pkg/bin/mpls_lsd_show_tech_fast cef

    # Print the closing heading. 
    print_main_heading "show tech-support mpls ldp complete"
}

# This function calls the display() function and sends the output to file if
# the file option has been set. 
. /pkg/bin/show_tech_file_fragment
