package NWS::MCDATA;
#<copyright>
# ----------------------------------------------------------
# Sun Proprietary/Confidential Code
# Copyright 2001, Sun Microsystems, Inc. All rights reserved.
# ----------------------------------------------------------
#</copyright>

#  $Name:  $ 
#  $Id: MCDATA.pm,v 1.1 2002/08/01 16:32:17 mckenney Exp $

use Report;
use CIM::Instance;
use Data::Dumper;
use strict;
use Ilist;
use PDM;
use NWS;
sub revision {'$Revision: 1.1 $'}

sub newSystem {
  my ($class, $rep) = @_;
  my(@pil, $i, $dd, $a, $j, $k, $k1, $v);
  my($PORTS);
  my($wwn) = $rep->get('id.wwn');
  my($p1) = CIM::Instance->new('NWS_System',[
                    [Name 		=> $wwn               ],
                    [SystemName         => $rep->get('id.name')],
                    [OtherIdentifyingInfo  => "wwn=$wwn"      ],
                    [IP 		=> $rep->get('id.ip')],
                    [FruCount 		=> $rep->get('port.count')+1],
                    [Firmware           => $rep->get('id.productID')],
                    [Caption            => "MCDATA"],
                ]);

  my($p2) = CIM::Instance->new('CIM_PhysicalFrame', [
                  [Tag 			=> $rep->get("id.wwn")],
                  [Name			=> $rep->get("id.wwn")],
                  [Manufacturer 	=> "MCDATA" ],
                  [Model 		=> "MCDATA_". $rep->get('port.count')],
                  ]);

  my($a2) = CIM::Instance->new('CIM_ComputerSystemPackage', [
                  [Antecedent            => $p1],
                  [Dependent             => $p2],
                  ]);

  my($l1) = NWS->location($rep);
  
  my($al1) = CIM::Instance->new('NWS_PhysicalFrameLocation', [
                  [Element 		=> $p2],
                  [PhysicalLocation 	=> $l1],
                  ]);
               
  push (@pil, $p1, $p2, $a2, $l1, $al1);

  $PORTS =  $rep->get('port.count');


  for ($i = 1; $i <= $PORTS; $i++) {
    $dd = $class->newPort($rep,"port.$i" , $i);
    $a = CIM::Instance->new('CIM_Container', [
                   [GroupComponent  => $p2],
                   [PartComponent => $dd->[1]],
                   [LocationWithinContainer => "port$i"],
                   ]);
    push (@pil, @$dd);
    push (@pil, $a);
  }
  
  return Ilist->new(\@pil);
}


sub newPort {
  my($class, $rep, $cd, $no) = @_;
  my(@il, $p1, $c1, $a1);
  
  my($status) = $rep->get("${cd}.state.status");

  my($serial_no) = $rep->get("id.wwn") .  "." . $cd;

  my($map) = PDM->getDeviceStateMap("mcdata.availability");

  my($state) =  $map->get("state.status." . $rep->get("$cd.state.state") );

  $p1 = CIM::Instance->new('NWS_SwitchPort',  [
                    [Admin        => $rep->get("${cd}.state.AdmStatus")],
                    [Mode         => $rep->get("${cd}.state.state")],
                    [Operational  => $rep->get("${cd}.state.Status")],

             [SystemName          => "MCDATA" . $rep->get("port.count") ],
             [DeviceID            => $serial_no ],
             [Name                => $serial_no ],
             [StatusInfo          => $status    ],
             [Status              => $state     ],
             [LossOfSignalCounter => 0          ],
             [LossOfSyncCounter   => 0          ],
             [CRCErrors           => $rep->get("$cd.error.InvalidCrcs") ], 
                 
                    ]);

  push(@il,$p1);

  $c1 = CIM::Instance->new('CIM_Card', [
                [Removable 	=> "Yes"],
                [Replaceable 	=> "Yes"],
                [Tag 		=> $serial_no],
                [Name  		=> $serial_no],
                [SerialNumber 	=> $serial_no],
                    ]);

  push(@il, $c1);
  $a1 = CIM::Instance->new('CIM_Realizes', [
                [Antecedent => $c1],
                [Dependent => $p1],
                    ]);
                    
  push(@il,$a1);

  return Ilist->new(\@il);

}

1;
