Laurent Bendavid
and 1 contributors


Net::Brcd - Perl libraries to contact Brocade switch


    #use Net::<Proto>::Brcd;
    use Net::Telnet::Brcd;
    #my $sw = new Net::<Proto>::Brcd;
    #Example :
    my $sw = new Net::Telnet::Brcd;
    $sw->connect($sw_name,$user,$pass) or die "\n";
    %wwn_port = $sw->switchShow(-bywwn=>1);
    my @lines = $sw->cmd("configShow");


Perl libraries to contact Brocade switch. You could set this environment variable to simplify coding:


login name


login password


switch name or IP address

This module should not be call directly. You have to choose <Proto> for your communication.



    my $brcd = new Net::<Proto>::Brcd;
    # For instance <Proto> = Telnet

Initialize Brocade object. No arguments needed.



Connect to a Brocade switch. The command exit if an error occured.

Do it before any switch command.

One object is required for each connection. If you want simultaneous connection you need several objects.


    my @results = $brcd->cmd("configShow");
    my $ok      = $brcd->cmd("cfgsave");

This function is used to send command to a brocade switch. And implement differents features:

  • The command tracks the continue question and answer 'yes'. The goal of this module is to be used in silent mode.

  • The Brocade command answer is returned without carriage return (no \r \n).

  • Two methods is used to give parameters.

    scalar: The string command is sent as is.

    array: The command thinks that the first element is a command, the second the principal arguments and other members. It is very useful for ali* command.

Examples :

    my @results=$brcd->cmd("aliAdd","toto",":00:00:0:5:4:54:4:5");
    aliAdd "toto", "00:00:0:5:4:54:4:5"

The command does not decide that the command answer is an error or not. It just store the stdout of the brocade command and return it in a array.


    my $rc = $brcd->sendcmd("portperfshow");

This function execute command without trap standard output. It's useful for command that needs to be interrupted.

You have to use the readline function to read each line generated by the command.


    my $rc = $brcd->sendeof();

Send Ctrl-D command to interrupt command (useful for portperfshow).


    while (my ($str) = $brcd->readline()) {
        # Do what you want with $str

Read output as piped command. You have a to decided when to stop (If the line content a prompt, I return undef).

    $brcd->readline({Timeout => 60});

You have to set argument with a hash ref.


    my %alias_to_wwn = $brcd->aliShow();

Send command aliShow "*" and return a hash. Some option, change the content of the returned hash :


Without option : return key = alias, value = WWN.

Be carefull !! If one alias contains multiple WWN, value is a ref array of all the WWN member.


With option -onlywwn => 1 (default option) : does not return alias with port naming. Disable this option (-onlywwn => 0), if you want both.


By default, -filter is set to '*'. You could use an other filter to select specific alias. Recall of rbash regular expression, you could use in filter :

  • Any character.

  • ?

    One character.

  • [..]

    Character class. For instance a or b => [ab]

  • Examples

        -filter => '*sv*'
        -filter => 'w_??[ed]*'

With option -bywwwn => 1, return key = WWN, value = alias

    my %wwn_to_alias = $brcd->aliShow(-bywwn => 1);

With option -byport => 1, return key = port, value = alias


    my %zone = $brcd->zoneShow();

Return a hash with one key is a zone and value an array of alias member or WWN or ports.

    my %zone = $brcd->zoneShow();

    foreach my $zone (%zone) {
        print "$zone:\n\t";
        print join("; ", keys %{$zone{$zone}} ),"\n";
-bymember => 1

If you set option -bymember => 1, you have a hash with key a member and value an array of zones where member exists.

-filter => '*'

By default, select all zone but you could set a POSIX filter for your zone.

It's important to run this command before using the followings functions.


    my @member = $brcd->zoneMember("z_sctxp004_0");

Return an array of member of one zone. Need to execute $brcd->zoneShow before.


    my @zones = $brcd->memberZone("w_sctxp004_0");

Return an array of zones where member exist. Need to execute $brcd->zoneShow before.


    my %port = $brcd->switchShow();

This function send the switchShow command on the connected switch (see only one switch not all the fabric). It returns the following structure:

    $port{port number}->{SPEED}  = <2G|1G|...>
                      ->{STATUS} = <OnLine|NoLight|...>
                      ->{SLOT}   = blade number
                      ->{NUMBER} = port number on blade
                      ->{TYPE}   = <E-Port|F-Port|...>
                      ->{WWN}    if connected

If you set -bywwn=1, it's return only a hash of WWN as key and port number as value.

    my %wwn_to_port = $brcd->switchShow(-bywwn => 1);

If you set -withportname=1, the portName command is execute on each port of the switch to get the portname.

If you set -byslot=1, it's return only a hash of slot/number as key and portname and port number as value.


    my ($slot,$slot_number) = $brcd->toSlot(36);
    my $slot_address        = $brcd->toSlot(36);

The function need to have an execution of $brcd->switchShow. It's usefull for a Director Switch to have the translation between absolute port number and slot/port number value.

If you use it in scalar context, the command return the string slot/slot_number (portShow format).


    my %port     = $brcd->portShow($port_number);
    my $portname = $brcd->portShow($port_number);

Need to have running the $brcd->switchShow command. The function use the toSlot function before sending the portShow command.

In array context, function return a hash with key as the portName. In scalar context returns the portname.


    print $brcd->output();

Return the last function output.


    my $wwn_re = $brcd->wwn_re();

    if (m/($wwn_re)/) {

Return the WWN re.


    my %fabric = $brcd->fabricShow();

Return a hash with all the switch in the fabric. Return the result byswitch name -byswitch or -bydomain=1.


    my $dns_fabric = $brcd->currentFabric();

Return the current fabric NAME.


    if ($brcd->isWwn($str)) {

Test a string to check if it is a WWN.


    my ($domain, $port_number) = $brcd->portAlias("199,6");

Split a string whith zoning format in domain and port number in the switch.


    my $boolean = $brcd->cfgSave();

The function execute cfgSave command an return true if ok or exit. You can trap this exception whith eval {}; block. Error message always begin with Error - .


    my @rc = $brcd->zone(
        -add     => 1,
        -name    => 'z_toto1',
        -members => '10:00:00:00:C9:3D:F3:04',
    my @rc = $brcd->zone(
        -add     => 1,
        -name    => 'z_toto2',
        -members => [

Supported sub commmand are -add, -create, -delete, -remove.


    my @rc = $brcd->ali(
        -create  => 1,
        -name    => 'w_toto1',
        -members => '10:00:00:00:C9:51:FB:29',
    my @rc = $brcd->ali(
        -add     => 1,
        -name    => 'w_toto2',
        -members => [
    my @rc = $brcd->ali(
        -add     => 1,
        -name    => 'w_toto3',
        -members => [

Supported sub commmand are -add, -create, -delete, -remove.


Brocade Documentation, BrcdAPI, Net::Telnet::Brcd(3).




Laurent Bendavid, <>


Copyright (C) 2005 by Laurent Bendavid

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.8.3 or, at your option, any later version of Perl 5 you may have available.




Created 6/27/2005, Modified 7/3/10 22:13:07

4 POD Errors

The following errors were encountered while parsing the POD:

Around line 740:

Expected '=item *'

Around line 744:

Expected '=item *'

Around line 748:

Expected '=item *'

Around line 780:

=over should be: '=over' or '=over positive_number'