Changeset 190 for trunk


Ignore:
Timestamp:
03/08/05 17:40:12 (19 years ago)
Author:
Kris Deugau
Message:

/trunk

consistency-check.pl:
Updated to be consistent with the new alloctypes and to check

the new container types for CIDR-level correctness.

Made output more consistent.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/cgi-bin/consistency-check.pl

    r167 r190  
    1919initIPDBGlobals($dbh);
    2020
    21 print "First check:  All blocks must be within one of the master blocks\n";
     21print "Checking master containment...\n";
    2222
    2323# First check - make sure ALL routes and allocated blocks are part
    2424# of one of the master blocks.
    25 print "Checking routed blocks: ";
     25print "  Checking routed blocks:";
    2626$sth = $dbh->prepare("select cidr from routed");
    27 # union select cidr from allocations union select cidr from freeblocks");
    28 $sth->execute;
     27$sth->execute;
     28$flag = '';
    2929ROUTED: while (@data = $sth->fetchrow_array) {
    3030  $cidr = new NetAddr::IP $data[0];
     
    3232    if ($master->contains($cidr)) { next ROUTED; }
    3333  }
    34   print "$cidr not mastered\n";
    35 }
    36 print " done.\n";
     34  print "\n    $cidr not mastered";
     35}
     36print "$flag done.\n";
    3737
    3838# Next test:  All allocations must be part of a master.
    39 print "Checking allocations: ";
     39print "  Checking allocations:";
    4040$sth = $dbh->prepare("select cidr from allocations");
    4141$sth->execute;
     42$flag = '';
    4243ALLOCATED: while (@data = $sth->fetchrow_array) {
    4344  $cidr = new NetAddr::IP $data[0];
     
    4546    if ($master->contains($cidr)) { next ALLOCATED; }
    4647  }
    47   print "$cidr not mastered\n";
    48 }
    49 print " done.\n";
     48  print "\n    $cidr not mastered";
     49  $flag = "\n ";
     50}
     51print "$flag done.\n";
    5052
    5153# Next:  free blocks
    52 print "Checking freeblocks: ";
     54print "  Checking freeblocks:";
    5355$sth = $dbh->prepare("select cidr from freeblocks order by cidr");
    5456$sth->execute;
     57$flag = '';
    5558FREEBLOCK: while (@data = $sth->fetchrow_array) {
    5659  $cidr = new NetAddr::IP $data[0];
     
    5861    if ($master->contains($cidr)) { next FREEBLOCK; }
    5962  }
    60   print "$cidr not mastered\n";
    61 }
    62 print " done.\n";
    63 
    64 print "Done checking master containment.\n\nChecking pool containment...\n";
     63  print "\n    $cidr not mastered";
     64  $flag = "\n ";
     65}
     66print "$flag done.\n";
     67
     68print "Done checking master containment.\n\n";
     69
     70print "Checking pool containment...\n";
    6571
    6672$sth = $dbh->prepare("select pool,ip from poolips order by ip");
     
    6975  $pool = new NetAddr::IP $data[0];
    7076  $ip = new NetAddr::IP $data[1];
    71   print "IP $ip listed with incorrect pool $pool\n"
     77  print "  IP $ip listed with incorrect pool $pool\n"
    7278    if !$pool->contains($ip);
    7379}
     
    7783  $sth2 = $dbh->prepare("select cidr from allocations where cidr='$data[0]'");
    7884  $sth2->execute;
    79   print "Pool $data[0] does not exist in allocations table\n"
     85  print "  Pool $data[0] does not exist in allocations table\n"
    8086    if (($sth2->fetchrow_array)[0] eq '');
    8187}
    8288
    83 print "Done checking pool containment.\n\nChecking block-alignment consistency:\n";
     89print "Done checking pool containment.\n\n";
     90
     91print "Checking block-alignment consistency...\n";
    8492
    8593# Block alignment consistency:  All allocated+free blocks within a master
     
    97105
    98106foreach $master (@masterblocks) {
    99   print "Master $master:\n";
     107  print "  Master $master:\n";
    100108  $prev = $master;
    101109  $sth = $dbh->prepare("(select network(cidr) as net, broadcast(cidr) as bcast ".
    102         " from allocations where cidr <<= '$master') union ".
    103         "(select network(cidr) as net, broadcast(cidr) as bcast ".
    104         "from freeblocks where cidr <<= '$master') order by net");
     110        "from allocations where cidr <<= '$master' and type not like '_c') ".
     111        "union (select network(cidr) as net, broadcast(cidr) as bcast ".
     112        "from freeblocks where cidr <<= '$master' and not (routed='c')) order by net");
    105113  $sth->execute;
    106114
     
    111119      # check if cur starts with master
    112120      if ($cur->numeric > $prev->numeric) {
    113         print " Gap from start of master $master to first block $cur\n";
     121        print "    Gap from start of master $master to first block $cur\n";
    114122      } elsif ($cur->numeric < $prev->numeric) {
    115         print " BIG problem!  Current block $cur begins before master $master!\n";
     123        print "    BIG problem!  Current block $cur begins before master $master!\n";
    116124      }
    117125    } else {
    118126      if ($cur->numeric < ($prev->numeric + 1)) {
    119         print " Block ".$prev->network." overlaps block $cur\n";
     127        print "    Block ".$prev->network." overlaps block $cur\n";
    120128      } elsif ($cur->numeric > ($prev->numeric + 1)) {
    121         print " Gap between end of block ".$prev->network." and block $cur\n";
     129        print "    Gap between end of block ".$prev->network." and block $cur\n";
    122130      }
    123131    }
     
    131139  $master--;
    132140  if ($cur->numeric ne $master->numeric) {
    133     print " Gap from $cur to end of master at $master\n";
    134   }
    135   print "done $master.\n";
    136 }
    137 
    138 print "Done checking block alignment.\n\nChecking for correctness on 'defined' CustIDs:\n";
     141    print "    Gap from $cur to end of master at $master\n";
     142  }
     143  print "  done $master.\n";
     144}
     145
     146print "Done checking block alignment.\n\n";
     147
     148print "Checking containment on container blocks...\n";
     149# First, we need a list of containers.
     150# Then, we check all of the contained blocks to see if they're within
     151# the proper container.
     152$sth = $dbh->prepare("select cidr from allocations where type like '_c' order by cidr");
     153$sth->execute;
     154$i=0;
     155while (@data = $sth->fetchrow_array) {
     156  $containers[$i++] = new NetAddr::IP $data[0];
     157}
     158print "  Checking general containment:";
     159$sth = $dbh->prepare("select cidr from allocations where type like '_r' order by cidr");
     160$sth->execute;
     161$flag = '';
     162CONTAINED: while (@data = $sth->fetchrow_array) {
     163  $cidr = new NetAddr::IP $data[0];
     164  foreach $container (@containers) {
     165    next CONTAINED if $container->contains($cidr);
     166  }
     167  print "\n    $cidr not contained";
     168  $flag = "\n ";
     169}
     170print "$flag done.\n";
     171print "  Checking alignment:\n";
     172foreach $container (@containers) {
     173  print "    Container $container:\n";
     174  $prev = $container;
     175  $sth = $dbh->prepare("(select network(cidr) as net, broadcast(cidr) as bcast ".
     176        "from allocations where cidr <<= '$container' and type like '_r') ".
     177        "union (select network(cidr) as net, broadcast(cidr) as bcast ".
     178        "from freeblocks where cidr <<= '$container' and routed='w') order by net");
     179    $sth->execute;
     180
     181  while (@data = $sth->fetchrow_array) {
     182    $cur = new NetAddr::IP $data[0];
     183
     184    if ($container->numeric == $prev->numeric) {
     185      # check if cur starts with master
     186      if ($cur->numeric > $prev->numeric) {
     187        print "      Gap from start of container $container to first block $cur\n";
     188      } elsif ($cur->numeric < $prev->numeric) {
     189        print "      BIG problem!  Current block $cur begins before container $container!\n";
     190      }
     191    } else {
     192      if ($cur->numeric < ($prev->numeric + 1)) {
     193        print "      Block ".$prev->network." overlaps block $cur\n";
     194      } elsif ($cur->numeric > ($prev->numeric + 1)) {
     195        print "      Gap between end of block ".$prev->network." and block $cur\n";
     196      }
     197    }
     198
     199    $prev = $cur;
     200    $prev--;
     201
     202  } # while (@data...)
     203
     204  $cur--;
     205  $container--;
     206  if ($cur->numeric ne $container->numeric) {
     207    print "      Gap from $cur to end of container at $container\n";
     208  }
     209  print "    done $container.\n";
     210
     211}
     212print "  done container alignment.\n";
     213print "Done checking container containment.\n\n";
     214
     215print "Checking for correctness on 'defined' CustIDs:\n";
    139216# New check:  Make sure "defined" CustIDs are correct.
    140217$sth = $dbh->prepare("select cidr,type,custid from allocations where not type='cn' order by cidr");
Note: See TracChangeset for help on using the changeset viewer.