#!/pkg/bin/ksh
#----------------------------------------------------------------------
# Created by Danial Johari September 2018 
# Copyright (c) 2018-2019 by cisco Systems, Inc.
# All rights reserved.
### Processes: mpls_oam_dpm
#
#----------------------------------------------------------------------


# 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

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

# Common commands
i=1;
j=1;
commandCommon_exec[$((i++))]='show running-config'
commandCommon__ksh[$((j++))]='nvgen -c -l 1 -t 1 -o 1'
commandCommon_exec[$((i++))]='show clock'
commandCommon__ksh[$((j++))]='iosclock -d 0x0'
commandCommon_exec[$((i++))]='show running-config hostname'
commandCommon__ksh[$((j++))]='nvgen -c -q gl/a/hostname'
commandCommon_exec[$((i++))]='show process lspv_server'
commandCommon__ksh[$((j++))]='sysmgr_show -o -p lspv_server'
commandCommon_exec[$((i++))]='show process lspv_dpm'
commandCommon__ksh[$((j++))]='sysmgr_show -o -p lspv_dpm'
# OAM/DPM general commands
i=1;
j=1;
commandOAM_exec[$((i++))]='show mpls oam dpm summary'
commandOAM__ksh[$((j++))]='lspv_show_dpm -c 0x1'
commandOAM_exec[$((i++))]='show mpls oam dpm adjacency'
commandOAM__ksh[$((j++))]='lspv_show_dpm -c 0x4'
commandOAM_exec[$((i++))]='show mpls oam dpm adjacency summary'
commandOAM__ksh[$((j++))]='lspv_show_dpm -c 0x3'
commandOAM_exec[$((i++))]='show mpls oam dpm counters'
commandOAM__ksh[$((j++))]='lspv_show_dpm -c 0x2'
commandOAM_exec[$((i++))]='show mpls oam dpm prefix'
commandOAM__ksh[$((j++))]='lspv_show_dpm -c 0x6'
commandOAM_exec[$((i++))]='show mpls oam dpm prefix summary'
commandOAM__ksh[$((j++))]='lspv_show_dpm -c 0x5'
commandOAM_exec[$((i++))]='show mpls oam client'
commandOAM__ksh[$((j++))]='lspv_show -c 0x1'
commandOAM_exec[$((i++))]='show mpls oam counters global'
commandOAM__ksh[$((j++))]='lspv_show -c 0x5'
commandOAM_exec[$((i++))]='show mpls oam counter packet'
commandOAM__ksh[$((j++))]='lspv_show -c 0x8' 
commandOAM_exec[$((i++))]='show mpls oam database requests'
commandOAM__ksh[$((j++))]='lspv_show -c 0x2'
commandOAM_exec[$((i++))]='show mpls oam database requests detail'
commandOAM__ksh[$((j++))]='lspv_show -c 0x2 -d'
commandOAM_exec[$((i++))]='show mpls oam database tt-requests'
commandOAM__ksh[$((j++))]='lspv_show -c 0x4'
commandOAM_exec[$((i++))]='show mpls oam database tt-requests detail'
commandOAM__ksh[$((j++))]='lspv_show -c 0x4 -d'
commandOAM_exec[$((i++))]='show mpls oam interface all'
commandOAM__ksh[$((j++))]='lspv_show -c 0x6 -a'
commandOAM_exec[$((i++))]='show mpls oam interface all detail'
commandOAM__ksh[$((j++))]='lspv_show -c 0x6 -a -d'
commandOAM_exec[$((i++))]='show mpls oam trace location all'
commandOAM__ksh[$((j++))]='lspv_show_ltrace -i all -1 -0'
commandOAM_exec[$((i++))]='show mpls oam per-call'
commandOAM__ksh[$((j++))]='percall_show lspv_server /oper/mpls_lspv/gl/'
commandOAM_exec[$((i++))]='show mpls oam dpm trace config'
commandOAM__ksh[$((j++))]='lspv_dpm_show_ltrace -T 0x3'
commandOAM_exec[$((i++))]='show mpls oam dpm trace error'
commandOAM__ksh[$((j++))]='lspv_dpm_show_ltrace -T 0x2'
commandOAM_exec[$((i++))]='show mpls oam dpm trace event'
commandOAM__ksh[$((j++))]='lspv_dpm_show_ltrace -T 0x1'
commandOAM_exec[$((i++))]='show mpls oam dpm trace fib'
commandOAM__ksh[$((j++))]='lspv_dpm_show_ltrace -T 0x4'
commandOAM_exec[$((i++))]='show mpls oam dpm trace lspv'
commandOAM__ksh[$((j++))]='lspv_dpm_show_ltrace -T 0x6'
commandOAM_exec[$((i++))]='show mpls oam dpm trace rib'
commandOAM__ksh[$((j++))]='lspv_dpm_show_ltrace -T 0x5'


# Initialise any variables used. 
debug_level_nb="0x3"
debug_level_str=""

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

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


# 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 oam dpm"
 
    if [[ "$__cardtype" == "SYS" ]]; then
        # Any system commands will go here
        echo ""
    else
        # Run commands
        exec_commands commandCommon
        exec_commands commandOAM
    fi
     
    # Print the closing heading. 
    print_main_heading "show tech-support mpls oam dpm 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

