Net::Packet::STP - Spanning Tree Protocol layer 4 object


Net-Packet documentation Contained in the Net-Packet distribution.

Index


Code Index:

NAME

Top

Net::Packet::STP - Spanning Tree Protocol layer 4 object

SYNOPSIS

Top

   use Net::Packet::Consts qw(:stp);
   require Net::Packet::STP;

   # Build a layer
   my $layer = Net::Packet::STP->new(
      protocolIdentifier        => NP_STP_PROTOCOL_IDENTIFIER_STP,
      protocolVersionIdentifier => 0,
      bpduType                  => 0x00,
      bpduFlags                 => 0x00,
      rootIdentifier            => '1/00:11:22:33:44:55',
      rootPathCost              => 1,
      bridgeIdentifier          => '2/11:22:33:44:55:66',
      portIdentifier            => 0x0001,
      messageAge                => 1,
      maxAge                    => 10,
      helloTime                 => 1,
      forwardDelay              => 10,
   );
   $layer->pack;

   print 'RAW: '.unpack('H*', $layer->raw)."\n";

   # Read a raw layer
   my $layer = Net::Packet::STP->new(raw => $raw);

   print $layer->print."\n";
   print 'PAYLOAD: '.unpack('H*', $layer->payload)."\n"
      if $layer->payload;

DESCRIPTION

Top

This modules implements the encoding and decoding of the Spanning Tree Protocol layer.

See also Net::Packet::Layer and Net::Packet::Layer4 for other attributes and methods.

ATTRIBUTES

Top

protocolIdentifier - 16 bits
protocolVersionIdentifier - 8 bits
bpduType - 8 bits
bpduFlags - 8 bits
rootIdentifier - 64 bits (16 + 56)
rootPathCost - 32 bits
bridgeIdentifier - 64 bits (16 + 56)
portIdentifier - 16 bits
messageAge - 16 bits
maxAge - 16 bits
helloTime - 16 bits
forwardDelay - 16 bits

METHODS

Top

new

Object constructor. You can pass attributes that will overwrite default ones. Default values:

protocolIdentifier: NP_STP_PROTOCOL_IDENTIFIER_STP

protocolVersionIdentifier: 0

bpduType: 0x00

bpduFlags: 0x00

rootIdentifier: '1/00:11:22:33:44:55'

rootPathCost: 1

bridgeIdentifier: '2/11:22:33:44:55:66'

portIdentifier: 0x0001

messageAge: 1

maxAge: 10

helloTime: 1

forwardDelay: 10

pack

Packs all attributes into a raw format, in order to inject to network. Returns 1 on success, undef otherwise.

unpack

Unpacks raw data from network and stores attributes into the object. Returns 1 on success, undef otherwise.

CONSTANTS

Top

Load them: use Net::Packet::Consts qw(:stp);

NP_STP_HDR_LEN

STP header length.

NP_STP_PROTOCOL_IDENTIFIER_STP

Various supported STP protocol identifiers.

AUTHOR

Top

Patrice <GomoR> Auffret

COPYRIGHT AND LICENSE

Top

RELATED MODULES

Top


Net-Packet documentation Contained in the Net-Packet distribution.

#
# $Id: STP.pm 1640 2009-11-09 17:58:27Z gomor $
#
package Net::Packet::STP;
use strict;
use warnings;

require Net::Packet::Layer4;
our @ISA = qw(Net::Packet::Layer4);

use Net::Packet::Consts qw(:stp :layer);
use Net::Packet::Utils qw(convertMac);

our @AS = qw(
   protocolIdentifier
   protocolVersionIdentifier
   bpduType
   bpduFlags
   rootIdentifier
   rootPathCost
   bridgeIdentifier
   portIdentifier
   messageAge
   maxAge
   helloTime
   forwardDelay
);
__PACKAGE__->cgBuildIndices;
__PACKAGE__->cgBuildAccessorsScalar(\@AS);

#no strict 'vars';

sub new {
   shift->SUPER::new(
      protocolIdentifier        => NP_STP_PROTOCOL_IDENTIFIER_STP,
      protocolVersionIdentifier => 0,
      bpduType                  => 0x00,
      bpduFlags                 => 0x00,
      rootIdentifier            => '1/00:11:22:33:44:55',
      rootPathCost              => 1,
      bridgeIdentifier          => '2/11:22:33:44:55:66',
      portIdentifier            => 0x0001,
      messageAge                => 1,
      maxAge                    => 10,
      helloTime                 => 1,
      forwardDelay              => 10,
      @_,
   );
}

sub getLength { NP_STP_HDR_LEN }

sub pack {
   my $self = shift;

   my ($root, $id1)   = split('\s*/\s*', $self->rootIdentifier);
   my ($bridge, $id2) = split('\s*/\s*', $self->bridgeIdentifier);

   $id1 =~ s/://g;
   $id2 =~ s/://g;

   $self->raw($self->SUPER::pack('nCCCnH12NnH12nvvvv',
      $self->protocolIdentifier, $self->protocolVersionIdentifier,
      $self->bpduType, $self->bpduFlags, $root, $id1, $self->rootPathCost,
      $bridge, $id2, $self->portIdentifier, $self->messageAge, $self->maxAge,
      $self->helloTime, $self->forwardDelay)
   ) or return undef;

   1;
}

sub unpack {
   my $self = shift;

   my ($protocolIdentifier, $protocolVersionIdentifier, $bpduType, $bpduFlags,
      $root, $identifier1, $rootPathCost, $bridge, $identifier2,
      $portIdentifier, $messageAge, $maxAge, $helloTime, $forwardDelay,
      $payload) = $self->SUPER::unpack('nCCCnH12NnH12nvvvv a*', $self->raw)
         or return undef;

   my $id1 = $root.'/'.convertMac($identifier1);
   my $id2 = $bridge.'/'.convertMac($identifier2);
   $self->rootIdentifier($id1);
   $self->bridgeIdentifier($id2);

   $self->protocolIdentifier($protocolIdentifier);
   $self->protocolVersionIdentifier($protocolVersionIdentifier);
   $self->bpduType($bpduType);
   $self->bpduFlags($bpduFlags);
   $self->rootPathCost($rootPathCost);
   $self->portIdentifier($portIdentifier);
   $self->messageAge($messageAge);
   $self->maxAge($maxAge);
   $self->helloTime($helloTime);
   $self->forwardDelay($forwardDelay);

   $self->payload($payload);

   1;
}

sub encapsulate {
   my $types = {
      NP_LAYER_NONE() => NP_LAYER_NONE(),
   };

   $types->{NP_LAYER_NONE()} || NP_LAYER_UNKNOWN();
}

sub print {
   my $self = shift;

   my $l = $self->layer;
   my $i = $self->is;
   sprintf "$l:+$i: protocolIdentifier:0x%04x  protocolVersionIdentifier:%d\n".
           "$l: $i: bpduType:0x%02x  bpduFlags:0x%02x\n".
           "$l: $i: rootIdentifier:%s  rootPathCost:%d\n".
           "$l: $i: bridgeIdentifier:%s  portIdentifier:0x%04x\n".
           "$l: $i: messageAge:%d  maxAge:%d  helloTime:%d  forwardDelay:%d",
              $self->protocolIdentifier, $self->protocolVersionIdentifier,
              $self->bpduType, $self->bpduFlags, $self->rootIdentifier,
              $self->rootPathCost, $self->bridgeIdentifier,
              $self->portIdentifier, $self->messageAge, $self->maxAge,
              $self->helloTime, $self->forwardDelay;
}

1;

__END__