Changeset 83


Ignore:
Timestamp:
Mar 30, 2011, 11:22:07 AM (13 years ago)
Author:
g7moreau
Message:
  • Change some variable name
  • New verbose
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/klask

    r82 r83  
    2828my $KLASK_DB_FILE  = "$KLASK_VAR/klaskdb";
    2929my $KLASK_SW_FILE  = "$KLASK_VAR/switchdb";
     30
     31#my $DEBUG = 0;
     32#GetOptionsFromArray(\@ARGV,
     33#   'debug|d=i'   => \$DEBUG,
     34#   );
    3035
    3136test_running_environnement();
     
    428433
    429434   for my $sw (@SWITCH) {
    430       $SWITCH_PORT_COUNT{$sw->{hostname}} = {} if not exists $SWITCH_PORT_COUNT{$sw->{hostname}};
     435      next if exists $SWITCH_PORT_COUNT{$sw->{hostname}};
     436
     437      $SWITCH_PORT_COUNT{$sw->{hostname}} = {};
     438#      print "DEBUG: SWITCH_PORT_COUNT defined for $sw->{hostname}\n" if $DEBUG xor 2;
    431439      }
    432440
     
    14331441   my %where = ();
    14341442   my %db_switch_output_port = ();
    1435    my %db_switch_ip_hostname = ();
     1443   my %db_switch_ip_hostnamefq = ();
    14361444
    14371445   DETECT_ALL_ROUTER:
     
    14391447   for my $one_router ( get_list_main_router(get_list_network()) ) {
    14401448      my %resol_arp = resolve_ip_arp_host($one_router, q{*}, q{low}); # resolution arp
     1449
    14411450      next DETECT_ALL_ROUTER if $resol_arp{mac_address} eq 'unknow';
     1451      print "VERBOSE_1: Router detected $resol_arp{ipv4_address} - $resol_arp{mac_address}\n" if $verbose;
     1452
    14421453      $where{$resol_arp{ipv4_address}} = find_all_switch_port($resol_arp{mac_address}); # retrouve les emplacements des routeurs
    1443       print "VERBOSE_1: Router detected $resol_arp{ipv4_address} - $resol_arp{mac_address}\n" if $verbose;
    14441454      }
    14451455
    14461456   ALL_ROUTER_IP_ADDRESS:
    1447    for my $ip (Net::Netmask::sort_by_ip_address(keys %where)) { # '194.254.66.254')) {
    1448 
    1449       next ALL_ROUTER_IP_ADDRESS if not exists $where{$ip}; # /a priori/ idiot car ne sers à rien...
     1457   for my $ip_router (Net::Netmask::sort_by_ip_address(keys %where)) { # '194.254.66.254')) {
     1458
     1459      next ALL_ROUTER_IP_ADDRESS if not exists $where{$ip_router}; # /a priori/ idiot car ne sers à rien...
    14501460
    14511461      ALL_SWITCH_CONNECTED:
    1452       for my $switch_detected ( keys %{$where{$ip}} ) {
    1453 
    1454          my $switch = $where{$ip}->{$switch_detected};
     1462      for my $switch_detected ( keys %{$where{$ip_router}} ) {
     1463
     1464         my $switch = $where{$ip_router}->{$switch_detected};
    14551465
    14561466         next ALL_SWITCH_CONNECTED if $switch->{port} eq '0';
     
    14631473   my %db_switch_link_with = ();
    14641474
    1465    my @list_switch_ip = ();
     1475   my @list_all_switch = ();
    14661476   my @list_switch_ipv4 = ();
    14671477   for my $sw (@SWITCH){
    1468       push @list_switch_ip, $sw->{hostname};
     1478      push @list_all_switch, $sw->{hostname};
    14691479      }
    14701480
     
    14721482
    14731483   ALL_SWITCH:
    1474    for my $one_computer (@list_switch_ip) {
     1484   for my $one_computer (@list_all_switch) {
    14751485      my %resol_arp = resolve_ip_arp_host($one_computer, q{*}, q{low}); # arp resolution
    14761486      next ALL_SWITCH if $resol_arp{mac_address} eq 'unknow';
     
    14811491
    14821492      if ($verbose) {
    1483 #         my @l = ();
    1484 #         for my $c  ( keys %{$where{$resol_arp{ipv4_address}}} ) {
    1485 #            push @l, "$c -+ "; #$where{$resol_arp{ipv4_address}}->{$c}{hostname};
    1486 #            }
    1487          print "VERBOSE_3 $one_computer $resol_arp{ipv4_address} $resol_arp{mac_address}\n";
    1488          print "VERBOSE_3 $one_computer --- ",
     1493         print "VERBOSE_3: $one_computer $resol_arp{ipv4_address} $resol_arp{mac_address}\n";
     1494         print "VERBOSE_3: $one_computer --- ",
    14891495            join(' + ', keys %{$where{$resol_arp{ipv4_address}}}),
    14901496            "\n";
    14911497         }
    14921498
    1493       $db_switch_ip_hostname{$resol_arp{ipv4_address}} = $resol_arp{hostname_fq};
     1499      $db_switch_ip_hostnamefq{$resol_arp{ipv4_address}} = $resol_arp{hostname_fq};
     1500      print "VERBOSE_4: db_switch_ip_hostnamefq $resol_arp{ipv4_address} -> $resol_arp{hostname_fq}\n" if $verbose;
    14941501
    14951502      $SWITCH_DB{$one_computer}->{ipv4_address} = $resol_arp{ipv4_address};
     
    15011508   for my $ip (Net::Netmask::sort_by_ip_address(@list_switch_ipv4)) {
    15021509
     1510      print "VERBOSE_5: loop on $db_switch_ip_hostnamefq{$ip}\n" if $verbose;
     1511
    15031512      next ALL_SWITCH_IP_ADDRESS if not exists $where{$ip};
     1513      next ALL_SWITCH_IP_ADDRESS if not exists $SWITCH_PORT_COUNT{ $db_switch_ip_hostnamefq{$ip} };
    15041514
    15051515      DETECTED_SWITCH:
    15061516      for my $switch_detected ( keys %{$where{$ip}} ) {
    15071517
    1508          next DETECTED_SWITCH if not exists $SWITCH_PORT_COUNT{ $db_switch_ip_hostname{$ip} };
    1509 
    15101518         my $switch = $where{$ip}->{$switch_detected};
    1511          print "VERBOSE_4: $db_switch_ip_hostname{$ip} -> $switch->{hostname} : $switch->{port}\n" if $verbose;
     1519         print "VERBOSE_6: $db_switch_ip_hostnamefq{$ip} -> $switch->{hostname} : $switch->{port}\n" if $verbose;
    15121520
    15131521         next if $switch->{port}     eq '0';
    15141522         next if $switch->{port}     eq $db_switch_output_port{$switch->{hostname}};
    1515          next if $switch->{hostname} eq $db_switch_ip_hostname{$ip}; # $computerdb->{$ip}{hostname};
    1516 
    1517          $db_switch_link_with{ $db_switch_ip_hostname{$ip} } ||= {};
    1518          $db_switch_link_with{ $db_switch_ip_hostname{$ip} }->{ $switch->{hostname} } = $switch->{port};
    1519          print "VERBOSE_5: $db_switch_ip_hostname{$ip} -> $switch->{hostname} : $switch->{port}\n" if $verbose;
     1523         next if $switch->{hostname} eq $db_switch_ip_hostnamefq{$ip}; # $computerdb->{$ip}{hostname};
     1524
     1525         $db_switch_link_with{ $db_switch_ip_hostnamefq{$ip} } ||= {};
     1526         $db_switch_link_with{ $db_switch_ip_hostnamefq{$ip} }->{ $switch->{hostname} } = $switch->{port};
     1527         print "VERBOSE_7: +++++\n" if $verbose;
    15201528         }
    15211529
Note: See TracChangeset for help on using the changeset viewer.