#! /pkg/bin/ksh
# ----------------------------------------------------------------------
# l2tp_show_tech -- L2TP show tech-support script
#
# December 2006, Sudhir Rustogi
#
# Copyright (c) 2015 by cisco Systems, Inc.
# All rights reserved.
#-----------------------------------------------------------------------

# 
# This script runs all the show commands required for the L2TP show 
# tech-support command. 
# 
# Options:
#          Currently only the standard tech-support options are supported. 
#          If more options are added, add description here.
# 

# ******************************************************************
#  Main heading required by show tech-support
# ******************************************************************
. /pkg/bin/show_tech_main_fragment

# ******************************************************************
#  Variable initialization
# ******************************************************************
cmd_level="0x1"
cmd_level_str=""
__cardtype="unspecified"

# ******************************************************************
# Parse the arguments to the script.
# Usage: 
#        l2tp_show_tech [-t <cardtype>] [-L <level>] [-f <file>]
# ******************************************************************
while [ "$#" -gt "0" ]; do
  case "$1" in
     -t) __cardtype="$2"; shift 2;;
     -L) cmd_level="$2"; shift 2;;
     *)  default_parser_function "$@"; shift $#;;
  esac
done

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

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

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=$?
  
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"
else
    platform="panini"
fi

# ******************************************************************
#  Command level
# ******************************************************************
case "$cmd_level" in
    "0x1") cmd_level_str="Detailed output with event traces";;
    "0x2") cmd_level_str="Detailed output without event traces";;
    "0x3") cmd_level_str="Brief output";;
    *) echo "Invalid command level: $cmd_level"; exit;;
esac

# 
# 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.
# 

# ******************************************************************
#  Command set for command level one: Detailed output w event traces
# ******************************************************************
# Commands that run on once per system
sys_show_exec[1]='show running-config'
sys_show__ksh[1]='nvgen -c -l 1 -t 1 -o 1'
sys_show_exec[2]='show version'
if [[ "$platform" = "panini" ]]; then
    sys_show__ksh[2]='ng_show_version'
else
    sys_show__ksh[2]='show_version'
fi
sys_show_exec[3]='show interfaces'
sys_show__ksh[3]='show_interface -a'
sys_show_exec[4]='show l2tp session detail'
sys_show__ksh[4]='l2tp_show_command -f 0x8 -V 0x2'
sys_show_exec[5]='show l2tp tunnel detail'
sys_show__ksh[5]='l2tp_show_command -e 0x5 -V 0x2'
sys_show_exec[6]='show l2tp internal'
sys_show__ksh[6]='l2tp_show_command -o -V 0x2'
sys_show_exec[7]='show l2tp counters control tunnel'
sys_show__ksh[7]='l2tp_show_command -c 0x3 -V 0x2'
sys_show_exec[8]='show l2tp counters control tunnel all'
sys_show__ksh[8]='l2tp_show_command -d 0x3 -V 0x2'
sys_show_exec[9]='show l2tp counters control tunnel authentication'
sys_show__ksh[9]='l2tp_show_command -a 0x3 -V 0x2'
sys_show_exec[10]='show l2tp counters control session fsm state current'
sys_show__ksh[10]='l2tp_show_command -p 0x1 -V 0x2'
sys_show_exec[11]='show l2tp counters control session fsm state transition'
sys_show__ksh[11]='l2tp_show_command -p 0x0 -V 0x2'
sys_show_exec[12]='show l2tp counters control session fsm event'
sys_show__ksh[12]='l2tp_show_command -p 0x2 -V 0x2'
sys_show_exec[13]='show processes l2tp_mgr location all'
sys_show__ksh[13]='sysmgr_show -o -p l2tp_mgr -n all'
sys_show_exec[14]='show l2tp trace location all'
sys_show__ksh[14]='show_l2tp_trace -V 0x2 -i all'
sys_show_exec[15]=''
sys_show__ksh[15]=''

#*******************************************************************
# Commands that run on RP or LC
#*******************************************************************
rplc_exec[1]=''
rplc__ksh[1]=''

#
# 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()
# ******************************************************************
display() {
    # Print the output heading 
    print_main_heading "show tech-support l2tp \($cmd_level_str\)"

    # Execute commands
    if [ "$__cardtype" == "SYS" ]; then
        exec_commands sys_show
    else
        case "$__cardtype" in
        "RP")
            exec_commands rplc
            ;;
        "DRP")
            exec_commands rplc
            ;;
        "LC")
            exec_commands rplc
            ;;
        esac
    fi

    # Print the closing heading
    print_main_heading "show tech-support l2tp 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
