#!/bin/sh

# -------------------------------------------------------
# file   : draw8k.sh
# purpose: Create a pictorial layout of 8k nw setup.
# author : Vittal.S
#
# usage  : draw8k.sh [ -sys ]
#
# modifications:
# 04-01-07  Initial Creation .
# -------------------------------------------------------

#Check if osv_version is available
OSV_VERSION=$(whereis -b osv_version.sh | awk '{ print $2 }')
if [ ! -f "$OSV_VERSION" ]; then
   logger --id $$ --priority user.warning "$0: osv_version.sh not found in \$PATH ($PATH), exiting!" >/dev/null 2>&1
   exit 1
fi

fcfgread( )
{
    cfgvarkey=$1
    cfgvarvalue=""
    cfgvarln="`cat $CFGFILE|  grep -e \"^[ \t]*${cfgvarkey}:\"`"
    cfgvarvalue="`echo ${cfgvarln} | sed -e 's/'${cfgvarkey}:'//g' | sed -e 's/^[ ]*//g'`"
}

# ----------------------------------------------------------------
# function: mapnafodev
# args    : none
# description:
#   In V6 or higher we have a new mapping( BO3621 ).
# ----------------------------------------------------------------

mapnafodev( ) {
   case $2 in
      bond0)
         eval ${1}=bonding_dev0
         ;;
      bond1)
         eval ${1}=bonding_dev1
         ;;
      bond2)
         eval ${1}=bonding_dev2
         ;;
      bond3)
         eval ${1}=cluster_dev
         ;;
      *)
         eval ${1}=$2
         ;;
   esac
}

# ----------------------------------------------------------------
# function: setmeup
# args    : none
# description:
#   given any string it will format it to required length.
# ----------------------------------------------------------------

setmeup( )
{
   varvaluetmp=$1
   length=$2
   varlength=$3
   length=${#varvaluetmp}
   if [ $length -ge 0 -a $length -lt $varlength ];
   then
      spaces=`expr $varlength - $length`
      while [ $spaces -gt 0 ];
      do
         varvaluetmp="${varvaluetmp}!"
         spaces=`expr $spaces - 1`
      done
   fi
   eval cfgvarres="$varvaluetmp"
}

# ----------------------------------------------------------------
# function: getnreplacenw
# args    : none
# description:
#   creates network info for a admin/sig/billing nw.
# ----------------------------------------------------------------

getnreplacenw( )
{
   varname=$1
   varone=$2
   varonelength=$3
   vartwo=$4
   vartwolength=$5

   fcfgread $varone
   cfgvaronetmp=${cfgvarvalue}
   fcfgread $vartwo
   cfgvartwotmp=${cfgvarvalue}
   cfgvarone=${cfgvaronetmp:0:$varonelength}
   cfgvartwo=${cfgvartwotmp:0:$vartwolength} 
   varnametmp="${cfgvarone}?${cfgvartwo}" 
   varlength=`expr $varonelength + $vartwolength`
   length=${#varnametmp}
   setmeup "$varnametmp" $length $varlength
   eval $varname="${cfgvarres:0:32}"
  
}

# ----------------------------------------------------------------
# function: getnrepvar
# args    : none
# description:
#   formats any variable in node.cfg for specified length
# ----------------------------------------------------------------

getnrepvar( )
{
   varname=$1
   varone=$2
   varonelength=$3
   fcfgread $varone
   cfgvaronetmp=${cfgvarvalue}
   cfgvarone=${cfgvaronetmp:0:$varonelength}
   length=${#cfgvarone}
   setmeup "$cfgvarone" $length $varonelength
   eval $varname="${cfgvarres:0:$varonelength}"
}

getnrepdefvar( )
{
   varname=$1
   varone=$2
   varonelength=$3
   cfgvarone=${varone:0:$varonelength}
   length=${#cfgvarone}
   setmeup "$cfgvarone" $length $varonelength
   eval $varname="${cfgvarres:0:$varonelength}"
}


# ----------------------------------------------------------------
# function: pluginvars
# args    : none
# description:
#   substitute's all the template with computed values
# ----------------------------------------------------------------

pluginvars( )
{

   cat $TEMPLATEFILE | sed -e 's/<16a>.*$/'${sipsm1}'/'  \
                      -e 's/<16b>.*$/'${sipsm2}'/'  \
                      -e 's/<16c>.*$/'${sipsm3}'/'  \
                      -e 's/<16d>.*$/'${sipsm4}'/'  \
                      -e 's/<17a>.*$/'${cstasm1}'/' \
                      -e 's/<17b>.*$/'${cstasm2}'/' \
                      -e 's/<17c>.*$/'${cstasm3}'/' \
                      -e 's/<17d>.*$/'${cstasm4}'/' \
                      -e 's/<18a>.*$/'${ccm1}'/'    \
                      -e 's/<18b>.*$/'${ccm2}'/'    \
                      -e 's/<18c>.*$/'${ccm3}'/'    \
                      -e 's/<18d>.*$/'${ccm4}'/'    \
                      -e 's/<19a>.*$/'${dns1}'/'    \
                      -e 's/<19b>.*$/'${dns2}'/'    \
                      -e 's/<20a>.*$/'${ntp1}'/'    \
                      -e 's/<21a>.*$/'${remote1}'/' \
                      -e 's/<21b>.*$/'${remote2}'/' \
                      -e 's/<22a>.*$/'${sauth1}'/'  \
                      -e 's/<23a>.*$/'${bser1}'/'   \
                      -e 's/<23b>.*$/'${bser2}'/'   \
                      -e 's/<3>[ ]*\$/'${node1}'/'  \
                      -e 's/<2>[ ]*\$/'${node2}'/'  \
                      -e 's/<24a>[ ]*\$/'${node1ip}'/' \
                      -e 's/<24b>[ ]*\$/'${node2ip}'/' \
                      -e 's/<1a> \$/'${cdev1}'  /'  \
                      -e 's/<1b> \$/'${cdev2}'  /'  \
                      -e 's/<1c> \$/'${cdev1}'  /'  \
                      -e 's/<1d> \$/'${cdev2}'  /'  \
                      -e 's/<6a> \$/'${sdev1}'  /'  \
                      -e 's/<7a> \$/'${sdev2}'  /'  \
                      -e 's/<10b> \$/'${sdev1}'   /'\
                      -e 's/<11b> \$/'${sdev2}'   /'\
                      -e 's/<8a> \$/'${bdev1}'  /'  \
                      -e 's/<9a> \$/'${bdev2}'  /'  \
                      -e 's/<8b> \$/'${bdev1}'  /'  \
                      -e 's/<9b> \$/'${bdev2}'  /'  \
                      -e 's/<10a> \$/'${adev1}'   /'\
                      -e 's/<11a> \$/'${adev2}'   /'\
                      -e 's/<6b> \$/'${adev1}'  /'  \
                      -e 's/<7b> \$/'${adev2}'  /'  \
                      -e 's/<4a>[ ]*\$/'${ciplg1}'  /' \
                      -e 's/<4b>[ ]*\$/'${cipnm1}'  /' \
                      -e 's/<4c>[ ]*\$/'${cipnw1}'  /' \
                      -e 's/<4d>[ ]*\$/'${cipgw1}'  /' \
                      -e 's/<5a>[ ]*\$/'${ciplg2}'  /' \
                      -e 's/<5b>[ ]*\$/'${cipnm2}'  /' \
                      -e 's/<5c>[ ]*\$/'${cipnw2}'  /' \
                      -e 's/<5d>[ ]*\$/'${cipgw2}'  /' \
                      -e 's/<12a>[ ]*\$/'${nafo0a}'/'  \
                      -e 's/<14a>[ ]*\$/'${nafo1a}'/'  \
                      -e 's/<13a>[ ]*\$/'${nafo2a}'/'  \
                      -e 's/<12b>[ ]*\$/'${nafo0b}'/'  \
                      -e 's/<14b>[ ]*\$/'${nafo1b}'/'  \
                      -e 's/<13b>[ ]*\$/'${nafo2b}'/'  \
                      -e 's/<0a>[ ]*\$/'$buildid'/'    \
                      -e 's/<0b>[ ]*\$/'$hwtype?$testbed?$profile'/' \
                      -e 's/<0c>[ ]*\$/'${sauth1}'/'   \
                      -e 's/<0d>[ ]*\$/'${sauth2}'/'   \
                      -e 's/<0e>[ ]*\$/'${comstr1}'/'  \
                      -e 's/<0f>[ ]*\$/'${comstr1}'/'  \
                      -e 's/<0g>[ ]*\$/'${primipmiweight}'/'  \
                      -e 's/<0h>[ ]*\$/'${primipmitimeout}'/' \
                      -e 's/<0i>[ ]*\$/'${primdieweight}'/'   \
                      -e 's/<0j>[ ]*\$/'${primdietimeout}'/'  \
                      -e 's/<0k>[ ]*\$/'${secipmiweight}'/'   \
                      -e 's/<0l>[ ]*\$/'${secipmitimeout}'/'  \
                      -e 's/<0m>[ ]*\$/'${secdieweight}'/'    \
                      -e 's/<0n>[ ]*\$/'${secdietimeout}'/'   \
                      -e 's/\!/ /g'                    \
                      -e 's/?/\//g'  
                      
}


# ----------------------------------------------------------------
# function: getsipnw
# args    : none
# description:
#   computes sipsm vip's/netmasks
# ----------------------------------------------------------------

getsipnw( )
{
   getnreplacenw sipsm1 sipsm1_vip 16 sipsm1_netmask 16
   getnreplacenw sipsm2 sipsm2_vip 16 sipsm2_netmask 16
   getnreplacenw sipsm3 sipsm3_vip 16 sipsm3_netmask 16
   getnreplacenw sipsm4 sipsm4_vip 16 sipsm4_netmask 16
}

getbilling( )
{
   getnrepvar bser1 billing_server1 16
   getnrepvar bser2 billing_server2 16
}

# ----------------------------------------------------------------
# function: getcstanw
# args    : none
# description:
#   computes csta vip's and nemasks
# ----------------------------------------------------------------

getcstanw( )
{
   getnreplacenw cstasm1 cstasm1_vip 16 cstasm1_netmask 16
   getnreplacenw cstasm2 cstasm2_vip 16 cstasm1_netmask 16
   getnreplacenw cstasm3 cstasm1_vip_2 16 cstasm1_netmask 16
   getnreplacenw cstasm4 cstasm2_vip_2 16 cstasm1_netmask 16
}


# ----------------------------------------------------------------
# function: getccmnw
# args    : none
# description:
#   computes ccm vip's and nemasks
# ----------------------------------------------------------------

getccmnw( )
{
   getnreplacenw  ccm1 ccm10_1_vip 16 ccm_netmask 16
   getnreplacenw  ccm2 ccm10_2_vip 16 ccm_netmask 16
   getnreplacenw  ccm3 ccm05_1_vip 16 ccm_netmask 16
   getnreplacenw  ccm4 ccm05_2_vip 16 ccm_netmask 16
}

# ----------------------------------------------------------------
# function: getdns
# args    : none
# description:
#   computes dns servers
# ----------------------------------------------------------------

getdns( )
{
   getnrepvar dns1 name_server_ip_1 16
   getnrepvar dns2 name_server_ip_2 16
}

# ----------------------------------------------------------------
# function: getntp
# args    : none
# description:
#   computes ntp server
# ----------------------------------------------------------------

getntp( )
{
   getnrepvar ntp1 ntp_server_1 16
}

# ----------------------------------------------------------------
# function: getremote
# args    : none
# description:
#   computes remote admin ip's/netmasks
# ----------------------------------------------------------------

getremote( )
{
   getnreplacenw  remote1 rsa_1_ip 16 rsa_1_netmask 16
   getnreplacenw  remote2 rsa_2_ip 16 rsa_2_netmask 16
}

# ----------------------------------------------------------------
# function: getsurv
# args    : none
# description:
#   computes survival authority
# ----------------------------------------------------------------

getsurv( )
{
   getnrepvar sauth1 survival_authority  16
}

# ----------------------------------------------------------------
# function: getvar
# args    : none
# description:
#   get's sa settings.
# ----------------------------------------------------------------

getvar( )
{
   varnode=$1
   vartype=$2
   varpos=$3
   varsubpos=$4
   rcsdvar=`cat $RCSDCFG 2>/dev/null | grep  -v '^#' | grep $varnode                                \
                       | grep $vartype | head -1 | awk  -v awkpos=$varpos -F',' '{ print $awkpos }' \
                       | sed -e 's/:.*//g' | awk -v awkpos=$varsubpos -F'=' '{ print $awkpos }'`
   length=${#rcsdvar}
   setmeup "$rcsdvar" $length 8
   echo "${cfgvarres:0:8}"
}


# ----------------------------------------------------------------
# function: getconfsurv
# args    : none
# description:
#   computes survival authority
# ----------------------------------------------------------------

getconfsurv( )
{
   CFGFILE=/etc/hiq8000/node.cfg
   fcfgread node_1_name
   firstnode=${cfgvarvalue}
   fcfgread node_2_name
   secondnode=${cfgvarvalue}
   fcfgread node_1_ip
   firstnodeip=${cfgvarvalue}
   fcfgread node_2_ip
   secondnodeip=${cfgvarvalue}
   fcfgread cluster_name
   clustername=${cfgvarvalue}
   fcfgread survival_authority
   survauth=${cfgvarvalue}

   if "$OSV_VERSION" --major compare sys lt V5;
   then
      SACFG=/etc/opt/SMAW/SMAWsf/SaQuery.cfg
   else
      SACFG=/tmp/expected.cfg
      { 
         echo "survival-authority ${survauth}"
         echo "community-string dynamic"
         echo "cluster-name ${clustername}"
         echo "${firstnode}#${firstnodeip}"
         echo "${secondnode}#${secondnodeip}"
      } > $SACFG
   fi

   #<CheckNode>
      nodename=`uname -n`
      if [ "$nodename" = "$firstnode" ];
      then
         mynode=$firstnode
         othernode=$secondnode
      else
         mynode=$secondnode
         othernode=$firstnode
      fi
   #</CheckNode>

   if "$OSV_VERSION" --major compare sys lt V5;
   then
      primipmiweight="`getvar  $firstnode  SA_ipmi 2 2`"
      secipmiweight="`getvar   $secondnode SA_ipmi 2 2`"
      primdieweight="`getvar   $firstnode  SA_down 2 2`"
      secdieweight="`getvar    $secondnode SA_down 2 2`"
      primipmitimeout="`getvar $firstnode  SA_ipmi 3 2`"
      secipmitimeout="`getvar  $secondnode SA_ipmi 3 2`"
      primdietimeout="`getvar  $firstnode  SA_down 3 2`"
      secdietimeout="`getvar   $secondnode SA_down 3 2`"
   else
      primipmiweight=na
      secipmiweight=na
      primdieweight=na
      secdieweight=na
      primipmitimeout=20
      secipmitimeout=20
      primdietimeout=15
      secdietimeout=15
   fi

   sacfg="`cat $SACFG 2>/dev/null | grep -v '^#' | grep "survival-authority"              \
                                               | awk '{ print $2 }' | sed -e 's/[ \t]*//g'`"
   comstrcfg="`cat $SACFG 2>/dev/null | grep -v '^#' | grep "community-string"            \
                                               | awk '{ print $2 }' | sed -e 's/[ \t]*//g'`"
   if [ "$testbed" = "cluster" ];
   then
      ssh -b $mynode $othernode "cat $SACFG 2>/dev/null | grep -v '^#' | grep \"survival-authority\""   \
                                          1>/tmp/remotesares 2>/dev/null
      ssh -b $mynode $othernode "cat $SACFG 2>/dev/null | grep -v '^#' | grep \"community-string\""     \
                                          1>/tmp/remotecomstrres 2>/dev/null
      remotesacfg=`cat /tmp/remotesares 2>/dev/null | awk '{ print $2 }' | sed -e 's/[ \t]*//g'`
      remotecomstrcfg=`cat /tmp/remotecomstrres 2>/dev/null | awk '{ print $2 }' | sed -e 's/[ \t]*//g'`
   fi
   sacfg=${sacfg:-"not-configured"}
   comstrcfg=${comstrcfg:-"not-configured"}
   remotesacfg=${remotesacfg:-"not-configured"}
   remotecomstrcfg=${remotecomstrcfg:-"not-configured"}
   rm -f /tmp/remotesares /tmp/remotecomstrres
   getnrepdefvar sauth1  "$sacfg"           16
   getnrepdefvar sauth2  "$remotesacfg"     16
   getnrepdefvar comstr1 "$comstrcfg"       16
   getnrepdefvar comstr2 "$remotecomstrcfg" 16
}


# ----------------------------------------------------------------
# function: getbondingdev
# args    : none
# description:
#   comoutes bonding dev association
# ----------------------------------------------------------------

getbondingdev( )
{
   devname=$1
   devtype=$2
   devlength=$3
   fcfgread $devtype
   dev=${cfgvarvalue}
   dev1tmp="`echo $dev | awk '{ print $1 }'`"
   dev2tmp="`echo $dev | awk '{ print $2 }'`"
   eval ${devname}1=${dev1tmp:0:4}
   eval ${devname}2=${dev2tmp:0:4}
   if [ "${dev1tmp:0:4}" = "" ];
   then
      eval ${devname}1="!!!!"
   fi
   if [ "${dev2tmp:0:4}" = "" ];
   then
      eval ${devname}2="!!!!"
   fi
   
}

# ----------------------------------------------------------------
# function: getnafodev
# args    : none
# description:
#   computes devices used for admin,billing,signalling in simplex
# ----------------------------------------------------------------

getnafodev( ) {
   fcfgread $3
   if [ "$mynode" = "$firstnode" ];
   then
      eval ${1}1="`echo ${cfgvarvalue} | awk '{ print $2 }'`"
      eval ${1}2="!!!!"
   else
      eval ${1}1="`echo ${cfgvarvalue} | awk '{ print $3 }'`"
      eval ${1}2="!!!!"
   fi
}

# ----------------------------------------------------------------
# function: getbonding
# args    : none
# description:
#   computes bonding dev association for all networks.
# ----------------------------------------------------------------


getbonding( )
{
   if [ "$testbed" = "cluster" ];
   then
      if [ "$mynode" = "$firstnode" ];
      then
         fcfgread nafo0
         mapnafodev nafo0Bond "`echo ${cfgvarvalue} | awk '{ print $2 }'`"
         fcfgread nafo1
         mapnafodev nafo1Bond "`echo ${cfgvarvalue} | awk '{ print $2 }'`"
         fcfgread nafo2
         mapnafodev nafo2Bond "`echo ${cfgvarvalue} | awk '{ print $2 }'`"
         if "$OSV_VERSION" --major compare sys lt V5;
         then
            mapnafodev nafo3Bond bond3
         else
            fcfgread nafo3
            mapnafodev nafo3Bond "`echo ${cfgvarvalue} | awk '{ print $2 }'`"
         fi
      else
         fcfgread nafo0
         mapnafodev nafo0Bond "`echo ${cfgvarvalue} | awk '{ print $3 }'`"
         fcfgread nafo1
         mapnafodev nafo1Bond "`echo ${cfgvarvalue} | awk '{ print $3 }'`"
         fcfgread nafo2
         mapnafodev nafo2Bond "`echo ${cfgvarvalue} | awk '{ print $3 }'`"
         if "$OSV_VERSION" --major compare sys lt V5;
         then
            mapnafodev nafo3Bond bond3
         else
            fcfgread nafo3
            mapnafodev nafo3Bond "`echo ${cfgvarvalue} | awk '{ print $3 }'`"
         fi
      fi
      getbondingdev adev $nafo0Bond  16
      getbondingdev sdev $nafo1Bond  16
      getbondingdev bdev $nafo2Bond  16
      getbondingdev cdev $nafo3Bond  16
   else
      getnafodev adev $CFGFILE nafo0
      getnafodev sdev $CFGFILE nafo1
      getnafodev bdev $CFGFILE nafo2
      cdev1=ethx
      cdev2=ethx
   fi
}

# ----------------------------------------------------------------
# function: getnodename
# args    : none
# description:
#   get's node#1, node#2 name.
# ----------------------------------------------------------------

getnodename( )
{
   getnrepvar node1 node_1_name 18
   getnrepvar node2 node_2_name 18
}

# ----------------------------------------------------------------
# function: getnodeip
# args    : none
# description:
#   get's node#1, node#2 ip.
# ----------------------------------------------------------------

getnodeip( )
{
   getnrepvar node1ip node_1_ip 18
   getnrepvar node2ip node_2_ip 18
}

# ----------------------------------------------------------------
# function: getcluster
# args    : none
# description:
#   computes cluster interconnect network.
# ----------------------------------------------------------------

getcluster( )
{
   if "$OSV_VERSION" --major compare sys lt V5;
   then
      getnrepvar ciplg1 node_1_cip_logical 16
      getnrepvar cipnw1 cip_network 16
      getnrepvar cipnm1 cip_netmask 16
      getnrepvar cipgw1 cip_gateway 16

      getnrepvar ciplg2 node_2_cip_logical 16
      getnrepvar cipnw2 cip2_network 16
      getnrepvar cipnm2 cip2_netmask 16
      getnrepvar cipgw2 cip2_gateway 16
   else
      fcfgread nafo3
      cfgvartmp="`echo ${cfgvarvalue} |  awk '{ print $4 }'`"
      setmeup "$cfgvartmp" 16 16
      ciplg1="${cfgvarres:0:16}"

      cfgvartmp="`echo ${cfgvarvalue} |  awk '{ print $7 }'`"
      setmeup "$cfgvartmp" 16 16
      cipnw1="${cfgvarres:0:16}"

      cfgvartmp="`echo ${cfgvarvalue} |  awk '{ print $6 }'`"
      setmeup "$cfgvartmp" 16 16 
      cipnm1="${cfgvarres:0:16}"

      cfgvartmp="`echo ${cfgvarvalue} |  awk '{ print $5 }'`"
      setmeup "$cfgvartmp" 16 16
      ciplg2="${cfgvarres:0:16}"

      cfgvartmp="`echo ${cfgvarvalue} |  awk '{ print $10 }'`"
      setmeup "$cfgvartmp" 16 16
      cipnw2="${cfgvarres:0:16}"

      cfgvartmp="`echo ${cfgvarvalue} |  awk '{ print $9 }'`"
      setmeup "$cfgvartmp" 16 16
      cipnm2="${cfgvarres:0:16}"

      getnrepvar cipgw1 xch_1_gateway 16
      getnrepvar cipgw2 xch_2_gateway 16
   fi
}

# ----------------------------------------------------------------
# function: getsubnets
# args    : none
# description:
#   computes various subnets.
# ----------------------------------------------------------------

getsubnets( )
{
   varname=$1
   vartype=$2
   varlength=$3

   fcfgread $vartype 
   cfgvaronetmp="`echo ${cfgvarvalue} |  awk '{ print $7 }'`"
   fcfgread $vartype 
   cfgvartwotmp="`echo ${cfgvarvalue} |  awk '{ print $6 }'`"
   cfgvarone=${cfgvaronetmp:0:$varlength}
   cfgvartwo=${cfgvartwotmp:0:$varlength} 
   cfgvartmp="${cfgvarone}?${cfgvartwo}" 
   length=${#cfgvartmp}
   setmeup "$cfgvartmp" 32 32
   eval ${varname}a="${cfgvarres:0:32}"

   fcfgread $vartype
   cfgvaronetmp="`echo ${cfgvarvalue} |  awk '{ print $10 }'`"
   fcfgread $vartype 
   cfgvartwotmp="`echo ${cfgvarvalue} |  awk '{ print $9 }'`"
   cfgvarone=${cfgvaronetmp:0:$varlength}
   cfgvartwo=${cfgvartwotmp:0:$varlength} 
   cfgvartmp="${cfgvarone}?${cfgvartwo}" 
   length=${#cfgvartmp}
   setmeup "$cfgvartmp" 32 32
   eval ${varname}b="${cfgvarres:0:32}"
}

# ----------------------------------------------------------------
# function: getnw
# args    : none
# description:
#   computes subnets for simplex.
# ----------------------------------------------------------------

getnw( )
{
   getsubnets nafo0 nafo0 16
   getsubnets nafo1 nafo1 16
   getsubnets nafo2 nafo2 16
   if "$OSV_VERSION" --major compare sys ge V5;
   then
      getsubnets nafo3 nafo3 16
   fi
}

# ------------------------------------------------------------
# function: mapprofile
# args    :
#	$1 solution type string, concatenated by hardware_platform_id
#	and solution. If this option is empty or not set then these
#	configuration directives are read from current system node.cfg
#	with cfgread program.
# description:
#   Maps the node.cfg hardware_platform_id and solution to a
#	system profile. System profiles possible values:
#	standard, integrated, unknown
# -------------------------------------------------------------
mapprofile( ) {
	solutiontype=$1
	#<MapRunningSolution>
	if [ "X${solutiontype}X" = "XX" ];
	then
		curhwid="`cfgread hardware_platform_id`"
		cursolution="`cfgread solution`"
		solutiontype=${curhwid}${cursolution}
	fi
	#</MapRunningSolution>

	unset syssolution
	case $solutiontype in
	'L8') profile="standard";;
	
	'M8') profile="standard" ;;
	
	'M9') profile="integrated" ;;

	'M10') profile="integrated" ;;

	'S8') profile="standard" ;;

	'S9') profile="integrated" ;;

	'S10') profile="integrated" ;;

	'T8'|'TM38'|'TM48') profile="standard" ;;

	'T9'|'TM39'|'TM49') profile="integrated" ;;

	'T10'|'TM310'|'TM410') profile="integrated" ;;

	'V8'|'V11'|'V12') profile="standard" ;;

	'V9') profile="integrated" ;;

	'V25')
		profile="integrated"
		syssolution="lowcost"
	;;

	'W8') profile="standard" ;;

	'W9') profile="integrated" ;;

	'W10') profile="integrated" ;;

	'WS68'|'WS78') profile="standard" ;;

	'WS69'|'WS79') profile="integrated" ;;

	'WS610'|'WS710') profile="integrated" ;;

	'X25'|'XM325')
		profile="integrated"
		syssolution="lowcost"
	;;

	'TM326' | 'TM426' | 'WS626' | 'WS726' | 'V26') # CQ00331659, FRN9989
		profile="standard"
	;;

	'PM19') # FSC RX 2530 M1 simplex
		profile="integrated"
	;;

	'PM126' | 'PM18') # FSC RX 2530 M1 duplex
		profile="standard"
	;;

	'TM59') # Lenovo X3550 M5 simplex
		profile="integrated"
	;;

	'TM526' | 'TM58') # Lenovo X3550 M5 duplex
		profile="standard"
	;;

	'SR59') # Lenovo SR530 simplex
		profile="integrated"
	;;

	'SR526' | 'SR58') # Lenovo SR530 duplex
		profile="standard"
	;;

	'SR69') # Lenovo SR630 simplex
		profile="integrated"
	;;

	'SR626' | 'SR68') # Lenovo SR630 duplex
		profile="standard"
	;;

	'SR6V39') # Lenovo SR630V3 simplex
		profile="integrated"
	;;

	'SR6V326' | 'SRV368') # Lenovo SR630V3 duplex
		profile="standard"
	;;

   'Generic9') # Generic simplex
		profile="integrated"
	;;

	'Generic26' | 'Generic8') # Generic duplex
		profile="standard"
	;;
   
	*) profile="unknown" ;;

	esac

	syssolution=${syssolution:-$profile}
}

# ----------------------------------------------------------------
# function: getsolution
# args    : none
# description:
#   computes solution(platform/<integ|simplex>
# ----------------------------------------------------------------

getsolution( )
{
   hwtype=`cat $CFGFILE| grep hw_platform | tr "A-Z" "a-z" |\
                               awk -F':' '{ print $2 }' | sed -e 's/[ \t]*//g'`
   testbed=`cat $CFGFILE| grep test_bed | awk -F':' '{ print $2 }' | sed -e 's/[ \t]*//g'`
   buildid=$("$OSV_VERSION" get)
   hwid="`cat $CFGFILE| grep hardware_platform_id | awk -F':' '{ print $2 }' | sed -e 's/[ \t]*//g'`"
   solution="`cat $CFGFILE| grep solution | awk -F':' '{ print $2 }' | sed -e 's/[ \t]*//g'`"
   solutionprofile="${hwid}${solution}"
   mapprofile $solutionprofile
}

# ----------------------------------------------------------------
# function: getstaticroute
# args    : none
# description:
#   get's all static routes.
# ----------------------------------------------------------------

getstaticroute( )
{
   idx=0
   routevar=""
   routevar=""
   routeprefix=$1
   nodeid=$2
   while [ $idx -lt 64 ];
   do
      if "$OSV_VERSION" --major compare sys lt V5;
      then
         staticexpr="static_route$idx"
         nextv4route="v4:`cat $CFGFILE|  grep \"^${staticexpr}:\" | cut -d':' -f2 | sed -e 's/[  ]\*/ /g' \
                          -e 's/-net //' -e 's/-host//' -e 's/netmask/%/' -e 's/dev /%/' -e 's/gw /%/'`"
         nextv6route="v6:"
      else
         staticv4expr="${routeprefix}_r$idx"
         staticbcexpr="${routeprefix}_bc$idx"
         staticv6expr="${routeprefix}_v$idx"
         nextv4route="v4:`cat $CFGFILE|  grep \"^${staticv4expr}:\" | cut -d':' -f2  | sed -e 's/[  ]\*/ /g'`"
         nextbcroute="bc:`cat $CFGFILE|  grep \"^${staticbcexpr}:\" | cut -d':' -f2  | sed -e 's/[  ]\*/ /g'`"
         nextv6route="v6:`cat $CFGFILE|  grep \"^${staticv6expr}:\" | cut -d':' -f2- | sed -e 's/[  ]\*/ /g'`"
      fi
      for nextrouteidx in "$nextv4route" "$nextbcroute" "$nextv6route"
      do
         nextroute=${nextrouteidx:3} 
         nextroutetype=${nextrouteidx:0:2}
         if [ "$nextroute" != "" ];
         then
            nextidx="[${idx}/${nextroutetype}]"
            if "$OSV_VERSION" --major compare sys lt V5;
            then
               result="`echo \"     $nextidx: $nextroute\" | sed -e 's/!/ /g'`"
               routenum="`echo $result | awk -F'%' '{ print $1 }' | sed -e 's/[ ]*//g'`"
               network="`echo $result  | awk -F'%' '{ print $2 }' | sed -e 's/[ ]*//g'`"
               netmask="`echo $result  | awk -F'%' '{ print $3 }' | sed -e 's/[ ]*//g'`"
               gateway="`echo $result  | awk -F'%' '{ print $4 }' | sed -e 's/[ ]*//g'`"
            else
               routenum="$nextidx"
               network="`echo  $nextroute | awk -F' ' '{ print $1 }' | sed -e 's/[ ]*//g'`"
               if [ "$nextroutetype" = "v4" -o "$nextroutetype" = "bc" ];
               then
                  netmask="`echo  $nextroute  | awk -F' ' '{ print $2 }' | sed -e 's/[ ]*//g'`"
                  gateway="`echo  $nextroute  | awk -F' ' '{ print $3"/"$4 }' | sed -e 's/[ ]*//g'`"
               else
                  netmask=""
                  gateway="`echo  $nextroute  | awk -F' ' '{ print $2"/"$3 }' | sed -e 's/[ ]*//g'`"
               fi
            fi
            routenumlen=${#routenum}
            networklen=${#network}
            netmasklen=${#netmask}
            gatewaylen=${#gateway}
            setmeup "$routenum" ${routenumlen} 8  
            routepad=$cfgvarres
            if [ "$nextroutetype" = "v4" -o "$nextroutetype" = "bc" ];
            then
               setmeup "$network" ${networklen} 16  
               networkpad=$cfgvarres
               setmeup "$netmask" ${netmasklen} 16  
               netmaskpad=$cfgvarres
               setmeup "$gateway" ${gatewaylen} 16  
               gatewaypad=$cfgvarres
            else
               setmeup "$network" ${networklen} 32
               networkpad=$cfgvarres
               setmeup "$netmask" ${netmasklen} 0
               netmaskpad=$cfgvarres
               setmeup "$gateway" ${gatewaylen} 16
               gatewaypad=$cfgvarres
            fi
            echo "      ${routepad} ${networkpad} ${netmaskpad} ${gatewaypad}" | sed -e 's/!/ /g'
         fi

      done
      idx=`expr $idx + 1`
      
   done
} 

# ----------------------------------------------------------------
# function: ipv6info
# args    : none
# description:
#   display ipv6 information, during imaging.
# ----------------------------------------------------------------

ipv6info( ) {
   if "$OSV_VERSION" --major compare sys ge V7;
   then
      echo "Default IPV6 routes:"
      echo "--------------------"
      fcfgread "default_router_1_ipv6"
      defaultv6rt1=${cfgvarvalue}
      defaultv6rt1=${defaultv6rt1:-"None"}
      fcfgread "default_router_1_ipv6"
      defaultv6rt=${cfgvarvalue}
      defaultv6rt2=${cfgvarvalue}
      defaultv6rt2=${defaultv6rt2:-"None"}
      echo "    [$firstnode]-$defaultv6rt1"
      echo "    [$secondnode]-$defaultv6rt2"
      echo "Signalling IPV6 info:"
      echo "---------------------"
      fcfgread "sipsm1_vipV6"
      sipsm1vipV6=${cfgvarvalue}
      sipsm1vipV6=${sipsm1vipV6:-"None"}
      fcfgread "sipsm3_vipV6"
      sipsm3vipV6=${cfgvarvalue}
      sipsm3vipV6=${sipsm3vipV6:-"None"}
      fcfgread "sipsm2_vipV6"
      sipsm2vipV6=${cfgvarvalue}
      sipsm2vipV6=${sipsm2vipV6:-"None"}
      fcfgread "sipsm4_vipV6"
      sipsm4vipV6=${cfgvarvalue}
      sipsm4vipV6=${sipsm4vipV6:-"None"}
      fcfgread "subnet_1_ipv6"
      subnet1vipV6=${cfgvarvalue}
      subnet1vipV6=${subnet1vipV6:-"None"}
      fcfgread "subnet_2_ipv6"
      subnet2vipV6=${cfgvarvalue}
      subnet2vipV6=${subnet2vipV6:-"None"}
      echo "$firstnode:-"
      echo "   $sipsm1vipV6[$subnet1vipV6]"
      echo "   $sipsm3vipV6[$subnet1vipV6]"
      echo "$secondnode:-"
      echo "   $sipsm2vipV6[$subnet2vipV6]"
      echo "   $sipsm4vipV6[$subnet2vipV6]"
   fi
}

# ----------------------------------------------------------------
# function: defaultroutes
# args    : none
# description:
#   computes the default routes,gateways.
# ----------------------------------------------------------------

defaultroutes( ) {

   echo "Default routes:"
   echo "---------------"
   fcfgread "default_router"
   defaultrt1=${cfgvarvalue}
   fcfgread "default_router_2"
   defaultrt2=${cfgvarvalue}
   if [ "${defaultrt1}" != "" ];
   then
      echo "    [$firstnode]-${defaultrt1}"
   fi
   if [ "${defaultrt2}" != "" ];
   then
      echo "    [$secondnode]-${defaultrt2}"
   fi
   if "$OSV_VERSION" --major compare sys ge V5;
   then
      echo "Gateways:"
      echo "---------"
      for gwtype in admin signaling billing xch
      do
         fcfgread "${gwtype}_${nodeid}_gateway"
         if [ "${cfgvarvalue}" != "" -a "${cfgvarvalue}" != "0.0.0.0" ];
         then
            getnrepdefvar nextgw "$gwtype" 16
            echo "$nextgw : ${cfgvarvalue}" | sed -e 's/!/ /g'
         fi
      done
   fi

}


# ----------------------------------------------------------------
# function: main
# args    : none
# description:
#   computes the logical entities and display's them.
# ----------------------------------------------------------------

source /etc/profile
CFGFILE=${1:-/etc/hiq8000/node.cfg}
RCSDCFG=/etc/opt/SMAW/SMAWsf/rcsd.cfg
TEMPLATEFILE=$2
stty intr undef
#<CheckNode>
   fcfgread node_1_name
   firstnode=${cfgvarvalue}
   fcfgread node_2_name
   secondnode=${cfgvarvalue}
   nodename=`uname -n`
   if [ "$nodename" = "$firstnode" ];
   then
      mynode=$firstnode
      othernode=$secondnode
   else
      mynode=$secondnode
      othernode=$firstnode
   fi
#</CheckNode>
if [ "$TEMPLATEFILE" = "" ];
then
   TEMPLATEFILE="/var/opt/image/hipath8k.template"
fi
BASETEMPLATEFILE=`basename $TEMPLATEFILE`
if [ "$CFGFILE" = "" -o ! -f "$CFGFILE" ];
then
   echo "Sorry cannot find node.cfg file."
   exit 0
else
   getsolution
   getsipnw
   getcstanw
   getccmnw
   getbilling
   getdns
   getntp
   getremote
   if [ "$BASETEMPLATEFILE" = "failover.template" ];
   then
      getconfsurv
   else
      getsurv
   fi
   getbonding
   getnodename
   getnodeip
   getcluster
   getnw
   pluginvars
   if "$OSV_VERSION" --major compare sys lt V5;
   then
      getstaticroute
      defaultroutes
   else
      echo "      Node:$firstnode"
      echo "      ------------------------------------------------------------"
      getstaticroute "first_node" 1
      echo "      ------------------------------------------------------------"
      if [ "$testbed" = "cluster" ];
      then
         echo ""
         echo "      Node:$secondnode"
         echo "      ------------------------------------------------------------"
         getstaticroute "second_node" 2
         echo "      ------------------------------------------------------------"
      fi
      defaultroutes
   fi
   ipv6info
fi

