#!/bin/sh
# extract topology info from the hardware graph /hw/ .

if [ -d /hw/module ] 
then

cpus=`find /hw -name "?" -print | grep cpu\/ | wc -l`
nodes=`find /hw -name node -print | wc -l`
routers=`find /hw -name router -print | wc -l`
links=`find /hw -name link | wc -l`
ab=`find /hw -name "[ab]" -print | wc -l`

echo -n "\nMachine" `hostname` "has "
echo -n $cpus "cpu's, "
echo -n $nodes "memory nodes, "
echo and $routers routers.

echo "\nThe cpus are:"

hinv -t cpu -v | grep Module | awk '{print $2,$5,$6,$7}' |	sed -e 's/\/S...[e]*//g' -e 's/://' | tr A-Z a-z | awk '{printf "cpu %3d is /hw/module/%d/slot/n%d/node/cpu/%s\n",$1,$2,$3,$4}' | sort -n

echo "\nThe nodes are:"
find /hw -name node -print | sort

if [ 0 != $routers ]
then echo "\nThe routers are:"
     find /hw -name router -print | sort 
fi

echo "\nThe topology is defined by:"
if [ 0 != $links ]
then ls -l `find /hw -name link` | cut -c"56-"
fi
echo ""
if [ 0 != $routers ]
then find /hw -name "?" -print | grep router | xargs ls -l | cut -c"56-" | sort
fi

else
hinv 

fi
