Calculate secondary 1 and secondary 2 mac address based on the primary MAC for HFI devices

git-svn-id: https://svn.code.sf.net/p/xcat/code/xcat-core/trunk@6312 8638fb3e-16cb-4fca-ae20-7b5d299a9bcd
This commit is contained in:
wanghuaz 2010-06-02 09:57:06 +00:00
parent 0118e0ff31
commit 76653dff61

View File

@ -713,6 +713,32 @@ sub getmacs {
}
}
##########################################################################
# Calculate secondary 1 and secondary 2 MAC address based on primary MAC
# for HFI devices
##########################################################################
sub cal_mac {
my $mac = shift;
$mac =~ s/://g;
$mac =~ /(.........)(.)(..)/;
my ($basemac, $mac_h, $mac_l) = ($1,$2, $3);
my $macnum_l = hex($mac_l);
my $macnum_h = hex($mac_h);
$macnum_l += 1;
if ($macnum_l > 0xFF) {
$macnum_h += 1;
}
my $newmac_l = sprintf("%02X", $macnum_l);
$newmac_l =~ /(..)$/;
$newmac_l = $1;
my $newmac_h = sprintf("%01X", $macnum_h);
my $newmac = $basemac.$newmac_h.$newmac_l;
return( $newmac );
}
##########################################################################
# Insert colons in MAC addresses for Linux only
##########################################################################
@ -720,20 +746,42 @@ sub format_mac {
my $data = shift;
if ( !xCAT::Utils->isAIX() ) {
#####################################
# Get adapter mac
#####################################
$data =~ /^(\S+\s+\S+\s+)(\S+)(\s+.*)$/;
my $mac = $2;
my $save = $mac;
#################################
# Delineate MAC with colons
#################################
$mac = lc($mac);
$mac =~ s/(\w{2})/$1:/g;
$mac =~ s/:$//;
$data =~ s/$save/$mac/;
#####################################
# Get adapter mac
#####################################
$data =~ /^(\S+\s+\S+\s+)(\S+)(\s+.*)$/;
my $mac = $2;
my $save = $mac;
if ( $data =~ /^hfi-ent\s+/ ) {
my @macs;
my $newmac;
my $newmac0 = cal_mac( $mac );
my $newmac1 = cal_mac( $newmac0 );
push @macs, $mac;
push @macs, $newmac0;
push @macs, $newmac1;
foreach my $mac_a ( @macs ) {
if ( !xCAT::Utils->isAIX() ) {
$mac_a = lc($mac_a);
$mac_a =~ s/(\w{2})/$1:/g;
$mac_a =~ s/:$//;
$newmac = $newmac.",".$mac_a;
} else {
$newmac = $newmac.",".$mac_a;
}
$newmac =~ s/^,//;
}
$data =~ s/$save/$newmac/;
} else {
if ( !xCAT::Utils->isAIX() ) {
#################################
# Delineate MAC with colons
#################################
$mac = lc($mac);
$mac =~ s/(\w{2})/$1:/g;
$mac =~ s/:$//;
$data =~ s/$save/$mac/;
}
}
return( "$data\n" );
}