Commit 826b5fa1 authored by Mac Newbold's avatar Mac Newbold

Takes an ir and makes appropriate ifc file, input to ifc_all or ifc_boot.

parent f7570c17
#!/usr/local/bin/perl -w
#
# Takes input IR file on STDIN, and dumps IFC file to STDOUT.
#
my $go=0;
my $ipsection=0;
my %ips = ();
my %nodes = ();
my %nodeips = ();
my %ifs = ();
while ( <> ) {
if ( /^start ip/i ) { $ipsection=1; }
elsif ( /^end ip/i ) { $ipsection=0; }
elsif ( /^start mac/i ) { $go=1; }
elsif ( /^end mac/i ) { $go=0; }
elsif ( $go ) {
my ($mac,$ip) = split();
$ips{$mac} = $ip;
}
}
my $path="";
if ( -x "/usr/testbed/bin/mac2if" ) { $path="/usr/testbed/bin/" }
elsif ( -x "mac2if" ) { $path=""; }
elsif ( -x "./mac2if" ) { $path="./"; }
elsif ( -x "/home/newbold/db/mac2if" ) { $path="/home/newbold/db/"; }
open(MAC2IF,"$path"."mac2if ".join(" ",keys %ips)." |");
while ( <MAC2IF> ) {
if (! /^\|/ ) {next;}
if ( /^\|node_id/ ) {next;}
s/ *|\t*//g;
s/^\|//;
my ($node,$ifc,$mac) = split(/\|/,$_);
$nodes{$mac} = $node;
$ifs{$mac} = $ifc;
}
if ( -x "/usr/testbed/bin/nodeip" ) { $path="/usr/testbed/bin/" }
elsif ( -x "nodeip" ) { $path=""; }
elsif ( -x "./nodeip" ) { $path="./"; }
elsif ( -x "/home/newbold/db/nodeip" ) { $path="/home/newbold/db/"; }
open(NODEIP,"$path"."nodeip ".join(" ",values %nodes)." |");
while ( <NODEIP> ) {
if (! /^\|/ ) {next;}
if ( /^\|node_id/ ) {next;}
s/ *|\t*//g;
s/^\|//;
my ($node,$ifc,$ip) = split(/\|/,$_);
if ($node =~ /^tbpc/) { if ($ifc==4) { $nodeip{$node} = $ip; } }
else { if ($ifc==1) { $nodeip{$node} = $ip; } }
}
print "# This ifc file generated by ir2ifc\n";
foreach my $mac ( keys %ips ) {
if (defined $nodeip{$nodes{$mac}} ) {
if (defined $ifs{$mac} ) {
print $nodeip{$nodes{$mac}}," ",$ifs{$mac}," ",$ips{$mac},"\n";
}
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment