File Coverage

blib/lib/Net/Frame/Layer/LLC.pm
Criterion Covered Total %
statement 73 81 90.1
branch 2 8 25.0
condition n/a
subroutine 21 24 87.5
pod 6 6 100.0
total 102 119 85.7


line stmt bran cond sub pod time code
1             #
2             # $Id: LLC.pm 16 2010-06-03 12:46:53Z gomor $
3             #
4             package Net::Frame::Layer::LLC;
5 3     3   32542 use strict;
  3         7  
  3         124  
6 3     3   88 use warnings;
  3         7  
  3         322  
7              
8             our $VERSION = '1.02';
9              
10 3     3   3260 use Net::Frame::Layer qw(:consts);
  3         240537  
  3         903  
11             require Exporter;
12             our @ISA = qw(Net::Frame::Layer Exporter);
13              
14             our %EXPORT_TAGS = (
15             consts => [qw(
16             NF_LLC_HDR_LEN
17             NF_LLC_DSAP_STP
18             NF_LLC_SSAP_STP
19             NF_LLC_DSAP_SNAP
20             NF_LLC_SSAP_SNAP
21             NF_LLC_DSAP_IPX
22             NF_LLC_SSAP_IPX
23             NF_LLC_DSAP_HPEXTLLC
24             NF_LLC_SSAP_HPEXTLLC
25             NF_LLC_SNAP_HDR_LEN
26             NF_LLC_SNAP_OUI_CISCO
27             NF_LLC_SNAP_PID_CDP
28             NF_LLC_SNAP_PID_STP
29             NF_LLC_SNAP_PID_IPX
30             )],
31             );
32             our @EXPORT_OK = (
33             @{$EXPORT_TAGS{consts}},
34             );
35              
36 3     3   28 use constant NF_LLC_HDR_LEN => 3;
  3         6  
  3         183  
37 3     3   17 use constant NF_LLC_DSAP_STP => 0x21;
  3         5  
  3         143  
38 3     3   17 use constant NF_LLC_SSAP_STP => 0x21;
  3         5  
  3         131  
39 3     3   17 use constant NF_LLC_DSAP_SNAP => 0x55;
  3         5  
  3         136  
40 3     3   16 use constant NF_LLC_SSAP_SNAP => 0x55;
  3         6  
  3         138  
41 3     3   15 use constant NF_LLC_DSAP_IPX => 0x70;
  3         6  
  3         126  
42 3     3   23 use constant NF_LLC_SSAP_IPX => 0x70;
  3         6  
  3         143  
43 3     3   18 use constant NF_LLC_DSAP_HPEXTLLC => 0x7c;
  3         6  
  3         846  
44 3     3   17 use constant NF_LLC_SSAP_HPEXTLLC => 0x7c;
  3         5  
  3         150  
45              
46 3     3   16 use constant NF_LLC_SNAP_HDR_LEN => 5;
  3         6  
  3         628  
47 3     3   38 use constant NF_LLC_SNAP_OUI_CISCO => 0x00000c;
  3         14  
  3         148  
48 3     3   15 use constant NF_LLC_SNAP_PID_CDP => 0x2000;
  3         5  
  3         136  
49 3     3   25 use constant NF_LLC_SNAP_PID_STP => 0x010b;
  3         11  
  3         136  
50 3     3   16 use constant NF_LLC_SNAP_PID_IPX => 0x8137;
  3         11  
  3         262  
51              
52             our @AS = qw(
53             dsap
54             ig
55             ssap
56             cr
57             control
58             );
59             __PACKAGE__->cgBuildIndices;
60             __PACKAGE__->cgBuildAccessorsScalar(\@AS);
61              
62 3     3   16 no strict 'vars';
  3         5  
  3         2469  
63              
64             require Bit::Vector;
65              
66             sub new {
67             shift->SUPER::new(
68 1     1 1 23 dsap => NF_LLC_DSAP_SNAP,
69             ig => 1,
70             ssap => NF_LLC_SSAP_SNAP,
71             cr => 1,
72             control => 0x03,
73             @_,
74             );
75             }
76              
77 0     0 1 0 sub getLength { NF_LLC_HDR_LEN }
78              
79             sub pack {
80 1     1 1 316 my $self = shift;
81              
82 1         43 my $dsap = Bit::Vector->new_Dec(7, $self->[$__dsap]);
83 1         9 my $ig = Bit::Vector->new_Dec(1, $self->[$__ig]);
84 1         7 my $ssap = Bit::Vector->new_Dec(7, $self->[$__ssap]);
85 1         7 my $cr = Bit::Vector->new_Dec(1, $self->[$__cr]);
86 1         14 my $v16 = $dsap->Concat_List($ig, $ssap, $cr);
87              
88 1 50       20 $self->[$__raw] = $self->SUPER::pack('nC',
89             $v16->to_Dec,
90             $self->[$__control],
91             ) or return undef;
92              
93 1         29 $self->[$__raw];
94             }
95              
96             sub unpack {
97 1     1 1 6 my $self = shift;
98              
99 1 50       9 my ($dsapIgSsapCr, $control, $payload) =
100             $self->SUPER::unpack('nC a*', $self->[$__raw])
101             or return undef;
102              
103 1         42 my $v16 = Bit::Vector->new_Dec(16, $dsapIgSsapCr);
104 1         11 $self->[$__dsap] = $v16->Chunk_Read(7, 9);
105 1         4 $self->[$__ig] = $v16->Chunk_Read(1, 8);
106 1         4 $self->[$__ssap] = $v16->Chunk_Read(7, 1);
107 1         5 $self->[$__cr] = $v16->Chunk_Read(1, 0);
108              
109 1         3 $self->[$__control] = $control;
110              
111 1         3 $self->[$__payload] = $payload;
112              
113 1         6 $self;
114             }
115              
116             sub encapsulate {
117 0     0 1   my $self = shift;
118              
119 0 0         return $self->[$__nextLayer] if $self->[$__nextLayer];
120              
121 0           my $types = {
122             NF_LLC_DSAP_STP() => 'STP',
123             NF_LLC_DSAP_IPX() => 'IPX',
124             NF_LLC_DSAP_SNAP() => 'LLC::SNAP',
125             NF_LLC_DSAP_HPEXTLLC() => 'HPEXTLLC',
126             };
127              
128 0 0         $types->{$self->[$__dsap]} || NF_LAYER_UNKNOWN;
129             }
130              
131             sub print {
132 0     0 1   my $self = shift;
133              
134 0           my $l = $self->layer;
135 0           sprintf "$l: dsap:0x%02x ig:%d ssap:0x%02x cr:%d control:0x%02x",
136             $self->[$__dsap], $self->[$__ig], $self->[$__ssap], $self->[$__cr],
137             $self->[$__control];
138             }
139              
140             1;
141              
142             __END__