From 2f963800e8ac8b1b3865f1ff7c64b8e6f9a83fd0 Mon Sep 17 00:00:00 2001 From: Casandra Qiu Date: Wed, 28 Jun 2017 16:55:15 -0400 Subject: [PATCH 1/3] Add Vlan and MTU to switch_macmap output --- perl-xCAT/xCAT/MacMap.pm | 22 +++++++++++++++++++++ xCAT-server/lib/xcat/plugins/switch.pm | 27 +++++++++++++++++++++----- 2 files changed, 44 insertions(+), 5 deletions(-) diff --git a/perl-xCAT/xCAT/MacMap.pm b/perl-xCAT/xCAT/MacMap.pm index 54edb1824..f95d01091 100644 --- a/perl-xCAT/xCAT/MacMap.pm +++ b/perl-xCAT/xCAT/MacMap.pm @@ -356,6 +356,8 @@ sub dump_mac_info { } } @{ $ret{$switch}->{$snmpportname}->{MACaddress} } = @{ $self->{macinfo}->{$switch}->{$snmpportname} }; + @{ $ret{$switch}->{$snmpportname}->{Vlanid} } = @{ $self->{vlaninfo}->{$switch}->{$snmpportname} }; + @{ $ret{$switch}->{$snmpportname}->{Mtu} } = @{ $self->{mtuinfo}->{$switch}->{$snmpportname} }; } } } @@ -720,6 +722,12 @@ sub refresh_switch { return; } + # get mtu + my $iftomtumap = walkoid($session, '.1.3.6.1.2.1.2.2.1.4', silentfail => 1, verbose => $self->{show_verbose_info}, switch => $switch, callback => $self->{callback}); + unless (defined($iftomtumap)) { + xCAT::MsgUtils->message("I", "MTU information is not availabe for this switch $switch"); + } + #Above is valid without community string indexing, on cisco, we need it on the next one and onward my $iftovlanmap = walkoid($session, '.1.3.6.1.4.1.9.9.68.1.2.2.1.2', silentfail => 1, verbose => $self->{show_verbose_info}, switch => $switch, callback => $self->{callback}); #use cisco vlan membership mib to ascertain vlan my $trunktovlanmap = walkoid($session, '.1.3.6.1.4.1.9.9.46.1.6.1.1.5', silentfail => 1, verbose => $self->{show_verbose_info}, switch => $switch, callback => $self->{callback}); #for trunk ports, we are interested in the native vlan, so we need cisco vtp mib too @@ -783,24 +791,38 @@ sub refresh_switch { xCAT::MsgUtils->message("S", "Error communicating with " . $session->{DestHost} . ": Unable to get MAC entries via either BRIDGE or Q-BRIDE MIB"); return; } + if (defined($self->{collect_mac_info})) { my %index_to_mac = (); + my %index_to_vlan = (); foreach (keys %$mactoindexmap) { my $index = $mactoindexmap->{$_}; my @tmp = split /\./, $_; + my $vlan = @tmp[0]; my @mac = @tmp[ -6 .. -1 ]; my $macstring = sprintf("%02x:%02x:%02x:%02x:%02x:%02x", @mac); push @{ $index_to_mac{$index} }, $macstring; + push @{ $index_to_vlan{$index} }, $vlan; } foreach my $boid (keys %$bridgetoifmap) { my $port_index = $boid; my $port_name = $namemap->{ $bridgetoifmap->{$port_index} }; + my $mtu = $iftomtumap->{ $bridgetoifmap->{$port_index} }; if (defined($index_to_mac{$port_index})) { push @{ $self->{macinfo}->{$switch}->{$port_name} }, @{ $index_to_mac{$port_index} }; } else { $self->{macinfo}->{$switch}->{$port_name}->[0] = ''; } + + if (defined($index_to_vlan{$port_index})) { + push @{ $self->{vlaninfo}->{$switch}->{$port_name} }, @{ $index_to_vlan{$port_index} }; + } + else { + $self->{vlaninfo}->{$switch}->{$port_name}->[0] = ''; + } + push @{ $self->{mtuinfo}->{$switch}->{$port_name} } , $mtu; + } return; } diff --git a/xCAT-server/lib/xcat/plugins/switch.pm b/xCAT-server/lib/xcat/plugins/switch.pm index 61dbce696..f4330a883 100644 --- a/xCAT-server/lib/xcat/plugins/switch.pm +++ b/xCAT-server/lib/xcat/plugins/switch.pm @@ -230,12 +230,12 @@ sub process_request { } } } - my $format = "%-" . $switch_name_length . "s %-" . $port_name_length . "s %-18s %s"; + my $format = "%-" . $switch_name_length . "s %-" . $port_name_length . "s %-18s %-20s %-7s %s"; my %failed_switches = (); - my $header = sprintf($format, "Switch", "Port", "MAC address", "Node"); + my $header = sprintf($format, "Switch", "Port", "MAC address", "Node", "Vlan", "MTU"); if (!defined($req->{opt}->{check}) and $port_name_length) { $cb->({ data => $header }); - $cb->({ data => "------------------------------------------------------------------" }) + $cb->({ data => "--------------------------------------------------------------------------------------" }) } foreach my $switch (keys %$macinfo) { if (defined($macinfo->{$switch}->{ErrorStr})) { @@ -251,17 +251,34 @@ sub process_request { $cb->({ node => [ { name => $switch, data => ["PASS"] } ] }); next; } + foreach my $port (sort keys %{ $macinfo->{$switch} }) { my $node = ''; if (defined($macinfo->{$switch}->{$port}->{Node})) { $node = $macinfo->{$switch}->{$port}->{Node}; } + + my $mtu = ''; + my @mtuarray = (); + if (defined($macinfo->{$switch}->{$port}->{Mtu})) { + @mtuarray = @{ $macinfo->{$switch}->{$port}->{Mtu} }; + } + my $vlanid = ''; + my @vlans = (); + if (defined($macinfo->{$switch}->{$port}->{Vlanid})) { + @vlans = @{ $macinfo->{$switch}->{$port}->{Vlanid} }; + } + my @macarrary = (); if (defined($macinfo->{$switch}->{$port}->{MACaddress})) { @macarray = @{ $macinfo->{$switch}->{$port}->{MACaddress} }; + my $ind = 0; foreach (@macarray) { - my $data = sprintf($format, $switch, $port, ($_ ne '') ? $_ : ' N/A', $node); + $vlanid = $vlans[$ind]; + $mtu = $mtuarray[$ind]; + my $data = sprintf($format, $switch, $port, ($_ ne '') ? $_ : ' N/A', $node,$vlanid,$mtu); $cb->({ data => $data }); + $ind++; #$cb->({node=>[{name=>$switch,data=>$data}]}); } @@ -269,7 +286,7 @@ sub process_request { } } if (!defined($req->{opt}->{check}) and $port_name_length) { - $cb->({ data => "------------------------------------------------------------------" }) + $cb->({ data => "--------------------------------------------------------------------------------------" }) } foreach (keys %failed_switches) { $cb->({ node => [ { name => $_, error => [ $failed_switches{$_} ], errorcode => 1 } ] }); From e55e5e14dc98a9b4cdee4e354b2f34516c9d74e7 Mon Sep 17 00:00:00 2001 From: Casandra Qiu Date: Mon, 10 Jul 2017 12:17:29 -0400 Subject: [PATCH 2/3] change the format --- xCAT-server/lib/xcat/plugins/switch.pm | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/xCAT-server/lib/xcat/plugins/switch.pm b/xCAT-server/lib/xcat/plugins/switch.pm index f4330a883..07a18bcfe 100644 --- a/xCAT-server/lib/xcat/plugins/switch.pm +++ b/xCAT-server/lib/xcat/plugins/switch.pm @@ -226,13 +226,13 @@ sub process_request { } foreach my $portname (keys %{ $macinfo->{$switch} }) { if (length($portname) > $port_name_length) { - $port_name_length = length($portname); + $port_name_length = length($portname) + 8; } } } - my $format = "%-" . $switch_name_length . "s %-" . $port_name_length . "s %-18s %-20s %-7s %s"; + my $format = "%-" . $switch_name_length . "s %-" . $port_name_length . "s %-26s %s"; my %failed_switches = (); - my $header = sprintf($format, "Switch", "Port", "MAC address", "Node", "Vlan", "MTU"); + my $header = sprintf($format, "Switch", "Port(MTU)", "MAC address(VLAN)", "Node"); if (!defined($req->{opt}->{check}) and $port_name_length) { $cb->({ data => $header }); $cb->({ data => "--------------------------------------------------------------------------------------" }) @@ -251,7 +251,6 @@ sub process_request { $cb->({ node => [ { name => $switch, data => ["PASS"] } ] }); next; } - foreach my $port (sort keys %{ $macinfo->{$switch} }) { my $node = ''; if (defined($macinfo->{$switch}->{$port}->{Node})) { @@ -274,9 +273,22 @@ sub process_request { @macarray = @{ $macinfo->{$switch}->{$port}->{MACaddress} }; my $ind = 0; foreach (@macarray) { + my $mac = $_; $vlanid = $vlans[$ind]; + my $mac_vlan; + if (!$mac) { + $mac_vlan="N/A"; + } elsif ($vlanid) { + $mac_vlan = "$mac($vlanid)"; + } else { + $mac_vlan = $mac; + } $mtu = $mtuarray[$ind]; - my $data = sprintf($format, $switch, $port, ($_ ne '') ? $_ : ' N/A', $node,$vlanid,$mtu); + my $port_mtu = $port; + if ($mtu) { + $port_mtu = "$port($mtu)"; + } + my $data = sprintf($format, $switch, $port_mtu, $mac_vlan, $node); $cb->({ data => $data }); $ind++; From 8efbf20e6950797527b65714a766d54bb11578b6 Mon Sep 17 00:00:00 2001 From: Casandra Qiu Date: Tue, 11 Jul 2017 13:50:51 -0400 Subject: [PATCH 3/3] Append MTU for every switch port --- xCAT-server/lib/xcat/plugins/switch.pm | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/xCAT-server/lib/xcat/plugins/switch.pm b/xCAT-server/lib/xcat/plugins/switch.pm index 07a18bcfe..09e4052d9 100644 --- a/xCAT-server/lib/xcat/plugins/switch.pm +++ b/xCAT-server/lib/xcat/plugins/switch.pm @@ -226,7 +226,7 @@ sub process_request { } foreach my $portname (keys %{ $macinfo->{$switch} }) { if (length($portname) > $port_name_length) { - $port_name_length = length($portname) + 8; + $port_name_length = length($portname) + 10; } } } @@ -258,10 +258,6 @@ sub process_request { } my $mtu = ''; - my @mtuarray = (); - if (defined($macinfo->{$switch}->{$port}->{Mtu})) { - @mtuarray = @{ $macinfo->{$switch}->{$port}->{Mtu} }; - } my $vlanid = ''; my @vlans = (); if (defined($macinfo->{$switch}->{$port}->{Vlanid})) { @@ -283,9 +279,9 @@ sub process_request { } else { $mac_vlan = $mac; } - $mtu = $mtuarray[$ind]; my $port_mtu = $port; - if ($mtu) { + if (defined($macinfo->{$switch}->{$port}->{Mtu})) { + $mtu = $macinfo->{$switch}->{$port}->{Mtu}->[0]; $port_mtu = "$port($mtu)"; } my $data = sprintf($format, $switch, $port_mtu, $mac_vlan, $node);