mirror of
				https://github.com/Telecominfraproject/wlan-lanforge-scripts.git
				synced 2025-10-31 18:58:01 +00:00 
			
		
		
		
	Utils: added get_eid_map() and ports_on_radio()
This commit is contained in:
		| @@ -421,6 +421,91 @@ sub sleep_sec { | ||||
|   } | ||||
| } | ||||
|  | ||||
| ## | ||||
| ##  Returns ref to map of all stations maching a parent device | ||||
| ##  EG: $rh_eid_map = $u->get_eid_map($::resource) | ||||
| ## | ||||
|  | ||||
| sub get_eid_map { | ||||
|   my ($self, $resource) = @_; | ||||
|   my %eid_map = (); | ||||
|   my @ports_lines = split("\n", $self->doAsyncCmd("nc_show_ports 1 $resource ALL")); | ||||
|   chomp(@ports_lines); | ||||
|  | ||||
|   my ($eid, $card, $port, $type, $mac, $dev, $parent, $ip); | ||||
|   foreach my $line (@ports_lines) { | ||||
|     # collect all stations on that radio add them to @interfaces | ||||
|     if ($line =~ /^Shelf: /) { | ||||
|       $card = undef; $port = undef; | ||||
|       $type = undef; $parent = undef; | ||||
|       $eid = undef; $mac = undef; | ||||
|       $dev = undef; | ||||
|       $ip = undef; | ||||
|     } | ||||
|  | ||||
|     # careful about that comma after card! | ||||
|     # NO EID for Shelf: 1, Card: 1, Port: 2  Type: WIFI-Radio  Alias: | ||||
|     ($card, $port, $type) = $line =~ m/^Shelf: 1, Card: (\d+),\s+Port: (\d+)\s+Type: (\w+)/; | ||||
|     if ((defined $card) && ($card ne "") && (defined $port) && ($port ne "")) { | ||||
|       $eid = "1.${card}.${port}"; | ||||
|       my $rh_eid = { | ||||
|         eid => $eid, | ||||
|         type => $type, | ||||
|         parent => undef, | ||||
|         dev => undef, | ||||
|       }; | ||||
|       $eid_map{$eid} = $rh_eid; | ||||
|       #print "\nfound eid $eid\n"; | ||||
|     } | ||||
|     #elsif ($line =~ /^Shelf/) { | ||||
|     #  #print "NO EID for $line\n"; | ||||
|     #} | ||||
|  | ||||
|     if (!(defined $eid) || ($eid eq "")) { | ||||
|       #print "NO EID for $line\n"; | ||||
|       next; | ||||
|     } | ||||
|     ($mac, $dev) = $line =~ / MAC: ([0-9:a-fA-F]+)\s+DEV: (\S+)/; | ||||
|     if ((defined $mac) && ($mac ne "")) { | ||||
|      #print "$eid MAC: $line\n"; | ||||
|       $eid_map{$eid}->{mac} = $mac; | ||||
|       $eid_map{$eid}->{dev} = $dev; | ||||
|     } | ||||
|  | ||||
|     ($parent) = $line =~ / Parent.Peer: (\S+) /; | ||||
|     if ((defined $parent) && ($parent ne "")) { | ||||
|       #print "$eid PARENT: $line\n"; | ||||
|       $eid_map{$eid}->{parent} = $parent; | ||||
|     } | ||||
|  | ||||
|     ($ip) = $line =~ m/ IP: *([^ ]+) */; | ||||
|     if ((defined $ip) && ($ip ne "")) { | ||||
|       #print "$eid IP: $line\n"; | ||||
|       $eid_map{$eid}->{ip} = $ip; | ||||
|     } | ||||
|   } # foreach | ||||
|  | ||||
|   #foreach $eid (keys %eid_map) { | ||||
|   #  print "eid $eid "; | ||||
|   #} | ||||
|   return \%eid_map; | ||||
| } | ||||
|  | ||||
| ## | ||||
| ## retrieve ports on radio from EID map | ||||
| ## EG: $ra_interfaces = $u->ports_on_radio($rh_eid_map, $radio_name); | ||||
| ## | ||||
| sub ports_on_radio { | ||||
|   my ($self, $rh_eid_map, $radio) = @_; | ||||
|   my @interfaces = (); | ||||
|   while (my ($eid, $rh_eid) = each %$rh_eid_map) { | ||||
|     if ((defined $rh_eid->{parent}) && ($rh_eid->{parent} eq $radio)) { | ||||
|       push(@interfaces, $rh_eid->{dev}); | ||||
|     } | ||||
|   } | ||||
|  | ||||
|   return \@interfaces; | ||||
| } | ||||
|  | ||||
| 1; # So the require or use succeeds (perl stuff) | ||||
| __END__ | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 Jed Reynolds
					Jed Reynolds