From ca15e05f2da03ce5fef9fed04a4d6917447e71d3 Mon Sep 17 00:00:00 2001 From: yinle Date: Sat, 11 Aug 2012 07:05:28 +0000 Subject: [PATCH] Add print information to lsslp. Put in the prm modification. git-svn-id: https://svn.code.sf.net/p/xcat/code/xcat-core/trunk@13489 8638fb3e-16cb-4fca-ae20-7b5d299a9bcd --- perl-xCAT/xCAT/SLP.pm | 203 ++++++++++++++++++++++++++---------------- 1 file changed, 126 insertions(+), 77 deletions(-) diff --git a/perl-xCAT/xCAT/SLP.pm b/perl-xCAT/xCAT/SLP.pm index a4edfd468..a54724d68 100644 --- a/perl-xCAT/xCAT/SLP.pm +++ b/perl-xCAT/xCAT/SLP.pm @@ -41,6 +41,8 @@ sub getmulticasthash { sub dodiscover { my %args = @_; my $rspcount = 0; + my $rspcount1 = 0; + my $sendcount = 1; $xid = int(rand(16384))+1; unless ($args{'socket'}) { if ($ip6support) { @@ -79,6 +81,16 @@ sub dodiscover { } } } + my @printip; + foreach my $iface (keys %{$interfaces}) { + foreach my $sip (@{$interfaces->{$iface}->{ipv4addrs}}) { + my $ip = $sip; + $ip =~ s/\/(.*)//; + push @printip, $ip; + } + } + my $printinfo = join(",", @printip); + send_message($args{reqcallback}, 0, "Sending SLP request on interfaces: $printinfo ...") if ($args{reqcallback}); foreach my $srvtype (@srvtypes) { send_service_request_single(%args,ifacemap=>$interfaces,SrvType=>$srvtype); } @@ -87,87 +99,115 @@ sub dodiscover { #by default, report all respondants within 3 seconds: my $waitforsocket = IO::Select->new(); $waitforsocket->add($args{'socket'}); - my $retrytime = ($args{Retry}>0)?$args{Retry}+1:1; + my $retrytime = ($args{Retry}>0)?$args{Retry}+1:3; + my $retryinterval = ($args{Retry}>0)?$args{Retry}:REQ_INTERVAL; + my $waittime = ($args{Time}>0)?$args{Time}:20; my @peerarray; - my @pkgarray; - for(my $i = 0; $i < $retrytime; $i++){ - my $sendcount = 0; - my $startinterval = time(); - my $interval; - my $retryinterval = ($args{Retry}>0)?$args{Retry}:REQ_INTERVAL; - my $waittime = ($args{Time}>0)?$args{Time}:20; - my $deadline=time()+$waittime; - my( $port,$flow,$ip6n,$ip4n,$scope); - my $slppacket; - my $peername; - while ($deadline > time()) { - while ($waitforsocket->can_read(0)) { + my @pkgarray; - my $peer = $args{'socket'}->recv($slppacket,1400,0); - - push @peerarray, $peer; - push @pkgarray, $slppacket; + my $startinterval = time(); + my $interval; + my $deadline=time()+$waittime; + my( $port,$flow,$ip6n,$ip4n,$scope); + my $slppacket; + my $peername; + while ($deadline > time()) { + ######################################## + # receive untill there is none + ######################################## + while ($waitforsocket->can_read(0)) { + my $peer = $args{'socket'}->recv($slppacket,1400,0); + push @peerarray, $peer; + push @pkgarray, $slppacket; + } + ####################################### + # process the packets + ####################################### + for(my $j = 0; $j< scalar(@peerarray); $j++) { + my $pkg = $peerarray[$j]; + my $slpkg = $pkgarray[$j]; + if ($ip6support) { + ( $port,$flow,$ip6n,$scope) = Socket6::unpack_sockaddr_in6_all($pkg); + $peername = Socket6::inet_ntop(Socket6::AF_INET6(),$ip6n); + } else { + ($port,$ip4n) = sockaddr_in($pkg); + $peername = inet_ntoa($ip4n); } - for(my $j = 0; $j< scalar(@peerarray); $j++) { - my $pkg = $peerarray[$j]; - my $slpkg = $pkgarray[$j]; - if ($ip6support) { - ( $port,$flow,$ip6n,$scope) = Socket6::unpack_sockaddr_in6_all($pkg); - $peername = Socket6::inet_ntop(Socket6::AF_INET6(),$ip6n); - } else { - ($port,$ip4n) = sockaddr_in($pkg); - $peername = inet_ntoa($ip4n); - } - if ($rethash{$peername}) { - next; #got a dupe, discard - } - my $result = process_slp_packet(packet=>$slpkg,sockaddr=>$pkg,'socket'=>$args{'socket'}); - if ($result) { - if ($peername =~ /\./) { #ipv4 - $peername =~ s/::ffff://; - } - $result->{peername} = $peername; - if ($gprlist) { - $gprlist .= ','.$peername if(length($gprlist) < 1250); - } else { - $gprlist = $peername; - } - $result->{scopeid} = $scope; - $result->{sockaddr} = $pkg; - my $hashkey; - if ($peername =~ /fe80/) { - $peername .= '%'.$scope; - } - $rspcount++; - $rethash{$peername} = $result; - if ($args{Callback}) { - $args{Callback}->($result); - } - } - } - @peerarray = (); - @pkgarray = (); - $interval = time() - $startinterval; - if ($args{Time} and $args{Count}) { - if ($rspcount >= $args{Count} or $interval >= $args{Time}) { - last; + if ($rethash{$peername}) { + next; #got a dupe, discard + } + my $result = process_slp_packet(packet=>$slpkg,sockaddr=>$pkg,'socket'=>$args{'socket'}); + if ($result) { + if ($peername =~ /\./) { #ipv4 + $peername =~ s/::ffff://; + } + $result->{peername} = $peername; + if ($gprlist) { + $gprlist .= ','.$peername if(length($gprlist) < 1250); + } else { + $gprlist = $peername; + } + $result->{scopeid} = $scope; + $result->{sockaddr} = $pkg; + my $hashkey; + if ($peername =~ /fe80/) { + $peername .= '%'.$scope; + } + $rspcount++; + $rspcount1++; + $rethash{$peername} = $result; + + if ($args{Callback}) { + $args{Callback}->($result); } } - if ( $interval > $retryinterval){#* (2**$sendcount))) { #double time - $sendcount++; - $startinterval = time(); - foreach my $srvtype (@srvtypes) { - send_service_request_single(%args,ifacemap=>$interfaces,SrvType=>$srvtype); - } - } - } - } - } #end nowait - + } + ############################# + # check if need to return + ############################# + @peerarray = (); + @pkgarray = (); + $interval = time() - $startinterval; + if ($args{Time} and $args{Count}) { + if ($rspcount >= $args{Count} or $interval >= $args{Time}) { + send_message($args{reqcallback}, 0, "Received $rspcount1 responses.") if ($args{reqcallback}); + last; + } + } + if ($sendcount > $retrytime and $rspcount1 == 0) { + send_message($args{reqcallback}, 0, "Received $rspcount1 responses.") if ($args{reqcallback}); + last; + } + ######################### + # send request again + ######################### + if ( $interval > $retryinterval){#* (2**$sendcount))) { #double time + $sendcount++; + $startinterval = time(); + send_message($args{reqcallback}, 0, "Received $rspcount1 responses.") if ($args{reqcallback}); + send_message($args{reqcallback}, 0, "Sending SLP request on interfaces: $printinfo ...") if ($args{reqcallback}); + foreach my $srvtype (@srvtypes) { + send_service_request_single(%args,ifacemap=>$interfaces,SrvType=>$srvtype); + } + $rspcount1 = 0; + } + } + + } #end nowait foreach my $entry (keys %rethash) { handle_new_slp_entity($rethash{$entry}) - } - return \%searchmacs; + } + if (xCAT::Utils->isAIX()) { + foreach my $iface (keys %{$interfaces}) { + foreach my $sip (@{$interfaces->{$iface}->{ipv4addrs}}) { + my $ip = $sip; + $ip =~ s/\/(.*)//; + my $maskbits = $1; + my $runcmd = `route delete 239.255.255.253 $ip`; + } + } + } + return (\%searchmacs, $sendcount, $rspcount); } sub process_slp_packet { @@ -345,9 +385,9 @@ sub send_service_request_single { my $ip = $sip; $ip =~ s/\/(.*)//; my $maskbits = $1; - #if (xCAT::Utils->isAIX()) { - # my $runcmd = `route add 239.255.255.253 $ip`; - #} + if (xCAT::Utils->isAIX()) { + my $runcmd = `route add 239.255.255.253 $ip`; + } my $ipn = inet_aton($ip); #we are ipv4 only, this is ok my $ipnum=unpack("N",$ipn); $ipnum= $ipnum | (2**(32-$maskbits))-1; @@ -605,4 +645,13 @@ sub get_ipv6_neighbors { } } +sub send_message { + my $callback = shift; + my $ecode = shift; + my $msg = shift; + my %output; + $output{errorcode} = $ecode; + $output{data} = $msg; + $callback->( \%output ); +} 1;