#!/usr/bin/perl
#prune-nodebase.pl
# remove nodes not mentioned in an NDT file from an Anemone nodebase file
# USage: prune-nodebase.pl old-nodebase < xxx.ndt > nodebase.xxx

#( "srchost=arnet.gw.ualberta.ca","acked=1.0000","srcip=198.73.177.4","color=1.000000 0.300000 0.200000","samples=10","variation=12.1514","timestamp=853188143","dsthost=meb.gw.ualberta.ca","dstip=129.128.1.8")
while (<STDIN>) {
  chop ;
  s/^\(\s*"// ; s/"\s*\)$// ;
  @f = split(/","/) ;
  undef(%name) ;
  foreach $_ (@f) {
    ($name,$value)  = split(/=/) ;
    $name{$name} = $value ;
  }
  $src = $name{'srchost'} ; if (!$src) { $src = $name{'srcip'} ; } 
  $dst = $name{'dsthost'} ; if (!$dst) { $dst = $name{'dstip'} ; }
  $srchost{$src} = 1 ; 
  $dsthost{$dst} = 1 ;
}


open (IN,@ARGV[0]) || die "Can't open nodebase file \"@ARGV[0]\"" ;
#node_hint portal-rtr.hc.BC.net 200.000000 50.000000 oval 75.000000 50.000000
while (<IN>){ 
  chop ;
  ($hint,$node,$x,$y,$shape,$width,$height) = split (/ /) ;
  if ( !$srchost{$node} && !$dsthost{$node}) { next ; }
  print "$_\n";
}
close(IN) ;
