# # $Id: LinkStateUpdate.pm,v 1.4 2007/03/13 18:18:45 gomor Exp $ # package Net::Frame::Layer::OSPF::LinkStateUpdate; use strict; use warnings; use Net::Frame::Layer qw(:consts :subs); our @ISA = qw(Net::Frame::Layer); our @AS = qw( lsaNumber ); our @AA = qw( lsaList ); __PACKAGE__->cgBuildIndices; __PACKAGE__->cgBuildAccessorsScalar(\@AS); __PACKAGE__->cgBuildAccessorsArray (\@AA); use Net::Frame::Layer::OSPF qw(:consts); require Net::Frame::Layer::OSPF::Lsa; sub new { shift->SUPER::new( lsaNumber => 0, lsaList => [], @_, ); } sub getLength { my $self = shift; my $len = 4; for ($self->lsaList) { $len += $_->getLength; } $len; } sub pack { my $self = shift; my $raw = $self->SUPER::pack('N', $self->lsaNumber) or return undef; for ($self->lsaList) { $raw .= $_->pack; } $self->raw($raw); } sub unpack { my $self = shift; my ($lsaNumber, $payload) = $self->SUPER::unpack('N a*', $self->raw) or return undef; $self->lsaNumber($lsaNumber); my @lsaList = (); while ($payload && length($payload) > 0) { my $lsa = Net::Frame::Layer::OSPF::Lsa->new(raw => $payload); $lsa->unpack; push @lsaList, $lsa; $payload = $lsa->payload; } $self->lsaList(\@lsaList); $self->payload($payload); $self; } sub print { my $self = shift; my $l = $self->layer; my $buf = sprintf "$l: lsaNumber:%d", $self->lsaNumber, ; for ($self->lsaList) { $buf .= "\n".$_->print; } $buf; } 1; __END__ =head1 NAME Net::Frame::Layer::OSPF::LinkStateUpdate - OSPF LinkStateUpdate type object =head1 SYNOPSIS use Net::Frame::Layer::OSPF::LinkStateUpdate; my $layer = Net::Frame::Layer::OSPF::LinkStateUpdate->new( lsaNumber => 0, lsaList => [], ); $layer->pack; print 'RAW: '.$layer->dump."\n"; # Read a raw layer my $layer = Net::Frame::Layer::OSPF::LinkStateUpdate->new(raw => $raw); print $layer->print."\n"; print 'PAYLOAD: '.unpack('H*', $layer->payload)."\n" if $layer->payload; =head1 DESCRIPTION This modules implements the encoding and decoding of the OSPF LinkStateUpdate object. See also B for other attributes and methods. =head1 ATTRIBUTES =over 4 =item B =item B ( [ B, ... ] ) This attribute takes an array ref of B objects. =back The following are inherited attributes. See B for more information. =over 4 =item B =item B =item B =back =head1 METHODS =over 4 =item B =item B (hash) Object constructor. You can pass attributes that will overwrite default ones. See B for default values. =back The following are inherited methods. Some of them may be overriden in this layer, and some others may not be meaningful in this layer. See B for more information. =over 4 =item B =item B =item B =item B =item B =item B =item B =item B =item B =item B =back =head1 CONSTANTS No constants here. =head1 SEE ALSO L, L =head1 AUTHOR Patrice EGomoRE Auffret =head1 COPYRIGHT AND LICENSE Copyright (c) 2006-2007, Patrice EGomoRE Auffret You may distribute this module under the terms of the Artistic license. See LICENSE.Artistic file in the source distribution archive. =cut