NAME

App::Netsync::Network - methods for manipulating network structures

DESCRIPTION

This module is responsible for for manipulating an internal view of a network.

SYNOPSIS

use App::Netsync 'devices_interfaces';
use App::Netsync::Network;
use feature 'say';

my %node;
$node{'ip'}       = '10.0.0.1';
$node{'hostname'} = 'host1';
$node{'session'}  = App::Netsync::SNMP::Session $node{'ip'};
$node{'info'}     = App::Netsync::SNMP::Info $session;

my $serial2if2ifName = device_interfaces ($node{'info'}->vendor,$node{'session'});

node_initialize (\%node,$serial2if2ifName);
say node_string \%node;
node_dump \%node;

# or

device_initialize (\%node,$_,$serial2if2ifName->{$_}) foreach keys $serial2if2ifName;
foreach my $serial (keys %{$node{'devices'}}) {
   my $device = $node{'devices'}{$serial};
   say device_string $device;
   device_dump $device;
}

# or

foreach my $serial (keys %serial2if2ifName) {
   $node->{'devices'}{$serial} = \%device;
   my $device = $node{'devices'}{$serial};
   $device->{'node'} = $node;

   my $if2ifName = $serial2if2ifName{$serial};
   interface_initialize ($device,$if2ifName->{$_},$_) foreach keys %$if2ifName;
}

foreach my $serial (keys %{$node{'devices'}}) {
   my $device = $node{'devices'}{$serial};
   foreach my $ifName (keys %{$device->{'interfaces'}}) {
      my interface = device->{'interfaces'}{$ifName};
      say interface_string $interface;
      interface_dump $interface;
   }
}


my %nodes;
$nodes{'10.0.0.1'} = \%node;
$nodes{'10.0.0.2'}{'ip'} = '10.0.0.2';
$nodes{'10.0.0.3'}{'ip'} = '10.0.0.3';
$nodes{'10.0.0.4'}{'ip'} = '10.0.0.4';
$nodes{'10.0.0.5'}{'ip'} = '10.0.0.5';

my $n = node_find (\%nodes,'10.0.0.5');
$n->{'ip'} == '10.0.0.5';

$n->{'devices'}{'1A2B3C4D5E6F'}{'serial'} = '1A2B3C4D5E6F';

my $d = device_find (\%nodes,'1A2B3C4D5E6F');
$d->{'serial'} == '1A2B3C4D5E6F';

$d->{'interfaces'}{'ethernet1/1/1'}{'ifName'} = ethernet1/1/1;

my $i = interface_find ($n->{'devices'},'ethernet1/1/1');
$i->{'ifName'} = 'ethernet1/1/1';

METHODS

node_initialize

initialize a new network node

Arguments

( $node , \%serial2if2ifName )

node

the node to initialize

$node

{
  'devices'  => {
                  $serial => $device,
                },
  'hostname' => SCALAR,
  'info'     => SNMP::Info,
  'ip'       => SCALAR,
  'session'  => SNMP::Session,
}
serial2if2ifName

a mapping of interfaces to devices (see App::Netsync::device_interfaces)

device_initialize

initialize a new network device

$device

{
  'interfaces' => {
                    $ifName => $interface,
                  },
  'node'       => $node,
  'identified' => SCALAR,
  'serial'     => $serial,
}

Arguments

( $node , $serial , \%if2ifName )

node

the node to add a new device to

serial

the serial number (unique identifier) of the new device (see node_initialize)

if2ifName

a mapping of SNMP interface IIDs to interface names (see device_interfaces)

interface_initialize

initialize a new network interface

$interface

{
  'device'     => $device,
  'ifName'     => $ifName,
  'IID'        => SCALAR,
  'info'       => {
                    $field => SCALAR,
                  },
  'identified' => SCALAR,
}

Arguments

( $device , $ifName , $IID [, \%fields ] )

device

the device to add a new interface to

ifName

the name of the new interface

IID

the IID of the new interface

fields

interface-specific key-value pairs

node_string

converts $node structure(s) to strings

Arguments

( @nodes )

nodes

an array of nodes to stringify

device_string

converts $device structures to strings

Arguments

( @devices )

devices

an array of devices to stringify

interface_string

converts $interface structures to strings

Arguments

( @interfaces )

interfaces

an array of devices to stringify

node_dump

prints a node structure

Arguments

( @nodes )

nodes

an array of nodes to print

device_dump

prints a device structure

Arguments

( @devices )

devices

an array of devices to print

interface_dump

prints an interface structure

Arguments

( @interfaces )

interfaces

an array of interfaces to print

node_find

check for a node in a set of nodes

Arguments

( \%nodes , $ip )

nodes

an array of nodes to search

ip

the IP address of the node

device_find

check for a device in a set of nodes

Arguments

( \%nodes , $serial )

nodes

an array of nodes to search

serial

a unique device identifier

interface_find

check for a interface in a set of devices

Arguments

( $devices , $ifName )

devices

an array of devices to search

ifName

a unique interface identifier

AUTHOR

David Tucker, <dmtucker at ucsc.edu>

BUGS

This module should be changed to use object-orientation. Until then, all of the included functions are exported!

Please report any bugs or feature requests to bug-netsync at rt.cpan.org, or through the web interface at http://rt.cpan.org/NoAuth/ReportBug.html?Queue=App-Netsync. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.

SUPPORT

You can find documentation for this module with the perldoc command.

perldoc App::Netsync

You can also look for information at:

LICENSE

Copyright 2013 David Tucker.

This program is free software; you can redistribute it and/or modify it under the terms of either: the GNU General Public License as published by the Free Software Foundation; or the Artistic License.

See http://dev.perl.org/licenses/ for more information.