#!/bin/bash
#
#  Copyright (c) 2015-2016 by cisco Systems, Inc.
#  All rights reserved.
#

#
# debug diag shell commands
#
# show the interface counts
count() 
{
        bcmd $1 "show Counters"
}
export -f count

bcmd () 
{ 
    if [ $1 = "all" ]; then
        for i in `seq 0 5`;
        do
            printf "===================================================\n";
            printf "Executing %s on NPU %d\n" "$2" "$i";
            printf "===================================================\n";
            fia_test diag_shell -c "$2" -u $i;
        done;
    else
        fia_test diag_shell -c "$2" -u $1;
    fi
}
export -f bcmd
       
# show the LEM lookup
# lem <unit> <core>
lem() {
      local core
      if [ -z "$2" ]; then
	  core=0
      else
	  core=$2
      fi
      bcmd $1 "diag pp DB_LEM_lkup_info core=$core"
}
export -f lem

# show the FEC table
fec() 
{
      bcmd $1 "diag alloc FEC direct=1"
}
export -f fec

# Show the graphical counters
dcount() 
{
      bcmd $1 "diag counters g cdsp"
}
export -f dcount

# Interface state
nif() 
{
      bcmd $1 "diag nif"
}
export -f nif

# show the trace of the forwarding,
# tfwd <unit> <core>
tfwd() {
      local core
      if [ -z "$2" ]; then
	  core=0
      else
	  core=$2
      fi
    
       bcmd $1 "diag pp Frwrd_Decision_Trace core=$core"
}
export -f tfwd

# show the tm lookup
# tmshow <unit> <core> <queue>
tmshow() {
      local core
      local queue
      if [ -z "$3" ]; then
	  core=0
	  queue=$2
      else
	  core=$2
	  queue=$3
      fi
      bcmd $1 "diag cos print_flow_and_up is_flow=1 dest_id=$queue  print_status=1 core=$core"
}
export -f tmshow

iph () 
{
    bcmd $1 "L3 route get vrf=0 ip=$1 mask=255.255.255.255"
}

cint() 
{
       bcmd 0 "cint $1"
}
export -f cint

dune() 
{
       bcmd 0 "dune"
}
export -f dune

# tmd <unit <core>
tmd() {
      local core
      if [ -z "$2" ]; then
	  core=0
      else
	  core=$2
      fi

      bcmd $1 "diag pp PKT_associated_TM_info core=$core"
}
export -f tmd

# ttrap unit core
ttrap () {
      local core
      if [ -z "$2" ]; then
	  core=0
      else
	  core=$2
      fi
      bcmd $1 "diag pp TRAPS_Info core=$core"
}
export -f ttrap
