BGP/Notification.pm

filter: Statementstmt 65.2% 45 / 69 Branchbran 83.3% 10 / 12 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 36.1% 13 / 36 Podpod 0.0% 0 / 32 totaltotal 45.6% 68 / 149 CC 7 SCAR 9.4
CC
7
Cov
68%
new
7.1
BGP_ERROR_CODE_MESSAGE_HEADER
2.0
BGP_ERROR_CODE_OPEN_MESSAGE
2.0
CRAP 2.6
« BGP/Refresh.pm ↑ Summary BGP/ASPath/AS_SET.pm »
1 #!/usr/bin/perl
2  
3 package Net::BGP::Notification;
4  
5 8 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 8 ▶use vars qw( $VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS @ERRORS );
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 ## Inheritance and Versioning ##
9  
10 8 @ISA = qw( Exporter );
11 8 $VERSION = '0.18';
12  
13 ## Module Imports ##
14  
15 8 ▶use Exporter;
Subroutine BEGIN: called CC=1 SCAR=0.0
16 8 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
17  
18 ## BGP Protocol Error Code and Subcode Enumerations ##
19  
20 0 ▶sub BGP_ERROR_CODE_MESSAGE_HEADER { 1 }
Subroutine BGP_ERROR_CODE_MESSAGE_HEADER: not called CC=1 SCAR=6.9
Pod undocumented
21 0 ▶sub BGP_ERROR_CODE_OPEN_MESSAGE { 2 }
Subroutine BGP_ERROR_CODE_OPEN_MESSAGE: not called CC=1 SCAR=6.9
Pod undocumented
22 1 ▶sub BGP_ERROR_CODE_UPDATE_MESSAGE { 3 }
Subroutine BGP_ERROR_CODE_UPDATE_MESSAGE: called CC=1 SCAR=0.0
Pod undocumented
23 0 ▶sub BGP_ERROR_CODE_HOLD_TIMER_EXPIRED { 4 }
Subroutine BGP_ERROR_CODE_HOLD_TIMER_EXPIRED: not called CC=1 SCAR=6.9
Pod undocumented
24 0 ▶sub BGP_ERROR_CODE_FINITE_STATE_MACHINE { 5 }
Subroutine BGP_ERROR_CODE_FINITE_STATE_MACHINE: not called CC=1 SCAR=6.9
Pod undocumented
25 6 ▶sub BGP_ERROR_CODE_CEASE { 6 }
Subroutine BGP_ERROR_CODE_CEASE: called CC=1 SCAR=0.0
Pod undocumented
26  
27 6 ▶sub BGP_ERROR_SUBCODE_NULL { 0 }
Subroutine BGP_ERROR_SUBCODE_NULL: called CC=1 SCAR=0.0
Pod undocumented
28  
29 0 ▶sub BGP_ERROR_SUBCODE_CONN_NOT_SYNC { 1 }
Subroutine BGP_ERROR_SUBCODE_CONN_NOT_SYNC: not called CC=1 SCAR=6.9
Pod undocumented
30 0 ▶sub BGP_ERROR_SUBCODE_BAD_MSG_LENGTH { 2 }
Subroutine BGP_ERROR_SUBCODE_BAD_MSG_LENGTH: not called CC=1 SCAR=6.9
Pod undocumented
31 0 ▶sub BGP_ERROR_SUBCODE_BAD_MSG_TYPE { 3 }
Subroutine BGP_ERROR_SUBCODE_BAD_MSG_TYPE: not called CC=1 SCAR=6.9
Pod undocumented
32  
33 0 ▶sub BGP_ERROR_SUBCODE_BAD_VERSION_NUM { 1 }
Subroutine BGP_ERROR_SUBCODE_BAD_VERSION_NUM: not called CC=1 SCAR=6.9
Pod undocumented
34 0 ▶sub BGP_ERROR_SUBCODE_BAD_PEER_AS { 2 }
Subroutine BGP_ERROR_SUBCODE_BAD_PEER_AS: not called CC=1 SCAR=6.9
Pod undocumented
35 0 ▶sub BGP_ERROR_SUBCODE_BAD_BGP_ID { 3 }
Subroutine BGP_ERROR_SUBCODE_BAD_BGP_ID: not called CC=1 SCAR=6.9
Pod undocumented
36 0 ▶sub BGP_ERROR_SUBCODE_BAD_OPT_PARAMETER { 4 }
Subroutine BGP_ERROR_SUBCODE_BAD_OPT_PARAMETER: not called CC=1 SCAR=6.9
Pod undocumented
37 0 ▶sub BGP_ERROR_SUBCODE_AUTH_FAILURE { 5 }
Subroutine BGP_ERROR_SUBCODE_AUTH_FAILURE: not called CC=1 SCAR=6.9
Pod undocumented
38 0 ▶sub BGP_ERROR_SUBCODE_BAD_HOLD_TIME { 6 }
Subroutine BGP_ERROR_SUBCODE_BAD_HOLD_TIME: not called CC=1 SCAR=6.9
Pod undocumented
39  
40 0 ▶sub BGP_ERROR_SUBCODE_MALFORMED_ATTR_LIST { 1 }
Subroutine BGP_ERROR_SUBCODE_MALFORMED_ATTR_LIST: not called CC=1 SCAR=6.9
Pod undocumented
41 0 ▶sub BGP_ERROR_SUBCODE_BAD_WELL_KNOWN_ATTR { 2 }
Subroutine BGP_ERROR_SUBCODE_BAD_WELL_KNOWN_ATTR: not called CC=1 SCAR=6.9
Pod undocumented
42 0 ▶sub BGP_ERROR_SUBCODE_MISSING_WELL_KNOWN_ATTR { 3 }
Subroutine BGP_ERROR_SUBCODE_MISSING_WELL_KNOWN_ATTR: not called CC=1 SCAR=6.9
Pod undocumented
43 1 ▶sub BGP_ERROR_SUBCODE_BAD_ATTR_FLAGS { 4 }
Subroutine BGP_ERROR_SUBCODE_BAD_ATTR_FLAGS: called CC=1 SCAR=0.0
Pod undocumented
44 0 ▶sub BGP_ERROR_SUBCODE_BAD_ATTR_LENGTH { 5 }
Subroutine BGP_ERROR_SUBCODE_BAD_ATTR_LENGTH: not called CC=1 SCAR=6.9
Pod undocumented
45 0 ▶sub BGP_ERROR_SUBCODE_BAD_ORIGIN_ATTR { 6 }
Subroutine BGP_ERROR_SUBCODE_BAD_ORIGIN_ATTR: not called CC=1 SCAR=6.9
Pod undocumented
46 0 ▶sub BGP_ERROR_SUBCODE_AS_ROUTING_LOOP { 7 }
Subroutine BGP_ERROR_SUBCODE_AS_ROUTING_LOOP: not called CC=1 SCAR=6.9
Pod undocumented
47 0 ▶sub BGP_ERROR_SUBCODE_BAD_NEXT_HOP_ATTR { 8 }
Subroutine BGP_ERROR_SUBCODE_BAD_NEXT_HOP_ATTR: not called CC=1 SCAR=6.9
Pod undocumented
48 0 ▶sub BGP_ERROR_SUBCODE_BAD_OPT_ATTR { 9 }
Subroutine BGP_ERROR_SUBCODE_BAD_OPT_ATTR: not called CC=1 SCAR=6.9
Pod undocumented
49 0 ▶sub BGP_ERROR_SUBCODE_BAD_NLRI { 10 }
Subroutine BGP_ERROR_SUBCODE_BAD_NLRI: not called CC=1 SCAR=6.9
Pod undocumented
50 0 ▶sub BGP_ERROR_SUBCODE_BAD_AS_PATH { 11 }
Subroutine BGP_ERROR_SUBCODE_BAD_AS_PATH: not called CC=1 SCAR=6.9
Pod undocumented
51  
52 ## Export Tag Definitions ##
53  
54 8 @ERRORS = qw(
55 BGP_ERROR_CODE_MESSAGE_HEADER
56 BGP_ERROR_CODE_OPEN_MESSAGE
57 BGP_ERROR_CODE_UPDATE_MESSAGE
58 BGP_ERROR_CODE_HOLD_TIMER_EXPIRED
59 BGP_ERROR_CODE_FINITE_STATE_MACHINE
60 BGP_ERROR_CODE_CEASE
61 BGP_ERROR_SUBCODE_NULL
62 BGP_ERROR_SUBCODE_CONN_NOT_SYNC
63 BGP_ERROR_SUBCODE_BAD_MSG_LENGTH
64 BGP_ERROR_SUBCODE_BAD_MSG_TYPE
65 BGP_ERROR_SUBCODE_BAD_VERSION_NUM
66 BGP_ERROR_SUBCODE_BAD_PEER_AS
67 BGP_ERROR_SUBCODE_BAD_BGP_ID
68 BGP_ERROR_SUBCODE_BAD_OPT_PARAMETER
69 BGP_ERROR_SUBCODE_AUTH_FAILURE
70 BGP_ERROR_SUBCODE_BAD_HOLD_TIME
71 BGP_ERROR_SUBCODE_MALFORMED_ATTR_LIST
72 BGP_ERROR_SUBCODE_BAD_WELL_KNOWN_ATTR
73 BGP_ERROR_SUBCODE_MISSING_WELL_KNOWN_ATTR
74 BGP_ERROR_SUBCODE_BAD_ATTR_FLAGS
75 BGP_ERROR_SUBCODE_BAD_ATTR_LENGTH
76 BGP_ERROR_SUBCODE_BAD_ORIGIN_ATTR
77 BGP_ERROR_SUBCODE_AS_ROUTING_LOOP
78 BGP_ERROR_SUBCODE_BAD_NEXT_HOP_ATTR
79 BGP_ERROR_SUBCODE_BAD_OPT_ATTR
80 BGP_ERROR_SUBCODE_BAD_NLRI
81 BGP_ERROR_SUBCODE_BAD_AS_PATH
82 );
83  
84 8 @EXPORT = ();
85 8 @EXPORT_OK = ( @ERRORS );
86 8 %EXPORT_TAGS = (
87 errors => [ @ERRORS ],
88 ALL => [ @EXPORT, @EXPORT_OK ]
89 );
90  
91 ## Public Methods ##
92  
93 sub new
94 9 ▶{
Subroutine new: called CC=7 SCAR=19.6
Pod undocumented
95 9 my $class = shift();
96 9 my ($arg, $value);
97  
98 9 my $this = {
99 _error_code => undef,
100 _error_subcode => undef,
101 _error_data => undef
102 };
103  
104 9 bless($this, $class);
105  
106 9 ▶ while ( defined($arg = shift()) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($arg = shift())) 15 9 24
107 15 $value = shift();
108  
109 15 ▶ if ( $arg =~ /errorcode/i ) {
Branch: 3 branches
BranchTrueFalseTotal
if ($arg =~ /errorcode/i) { } 9 6 15
elsif ($arg =~ /errorsubcode/i) { } 3 3 6
elsif ($arg =~ /errordata/i) { } 3 0 3
110 9 $this->{_error_code} = $value;
111 }
112 elsif ( $arg =~ /errorsubcode/i ) {
113 3 $this->{_error_subcode} = $value;
114 }
115 elsif ( $arg =~ /errordata/i ) {
116 3 $this->{_error_data} = $value;
117 }
118 else {
119 0 die("unrecognized argument $arg\n");
120 }
121 }
122  
123 9 ▶ defined $this->{_error_code} or croak "ErrorCode not defined";
Branch: 1 branch
BranchTrueFalseTotal
defined $this->{"_error_code"} or croak("ErrorCode not defined") 9 0 9
124 defined $this->{_error_subcode}
125 9 ▶ or $this->{_error_subcode} = BGP_ERROR_SUBCODE_NULL;
Branch: 1 branch
BranchTrueFalseTotal
defined $this->{"_error_subcode"} or $this->{"_error_subcode"} = BGP_ERROR_SUBCODE_NULL() 3 6 9
126  
127 9 return ( $this );
128 }
129  
130 1 ▶sub throw {
Subroutine throw: called CC=1 SCAR=0.0
Pod undocumented
131 1 my $class = shift;
132 1 my $notif = $class->new(@_);
133 1 die $notif;
134 }
135  
136 sub error_code
137 8 ▶{
Subroutine error_code: called CC=1 SCAR=0.0
Pod undocumented
138 8 my $this = shift();
139 8 return ( $this->{_error_code} );
140 }
141  
142 sub error_subcode
143 8 ▶{
Subroutine error_subcode: called CC=1 SCAR=0.0
Pod undocumented
144 8 my $this = shift();
145 8 return ( $this->{_error_subcode} );
146 }
147  
148 sub error_data
149 2 ▶{
Subroutine error_data: called CC=1 SCAR=0.0
Pod undocumented
150 2 my $this = shift();
151 2 return ( $this->{_error_data} );
152 }
153  
154 ## Private Methods ##
155  
156 ## POD ##
157  
158 =pod
159  
160 =head1 NAME
161  
162 C<Net::BGP::Notification> - Class encapsulating BGP-4 NOTIFICATION message
163  
164 =head1 SYNOPSIS
165  
166 use Net::BGP::Notification;
167  
168 $error = Net::BGP::Notification->new(
169 ErrorCode => $error_code,
170 ErrorSubCode => $error_subcode,
171 ErrorData => $error_data
172 );
173  
174 $error_code = $error->error_code();
175 $error_subcode = $error->error_subcode();
176 $error_data = $error->error_data();
177  
178 =head1 DESCRIPTION
179  
180 This module encapsulates the data contained in a BGP-4 NOTIFICATION message.
181 It provides a constructor, and accessor methods for each of the Error Code,
182 Error Subcode, and Error Data fields of a NOTIFICATION. It is unlikely that
183 user programs will need to instantiate C<Net::BGP::Notification> objects
184 directly. However, when an error occurs and a NOTIFICATION message is sent
185 or received by a BGP peering session established with the L<Net::BGP>
186 module, a reference to a C<Net::BGP::Notification> object will be passed
187 to the corresponding user callback subroutine. The subroutine can then use
188 the accessor methods provided by this module to examine the details of the
189 NOTIFICATION message.
190  
191 =head1 METHODS
192  
193 I<new()> - create a new C<Net::BGP::Notification> object
194  
195 $error = Net::BGP::Notification->new(
196 ErrorCode => $error_code,
197 ErrorSubCode => $error_subcode,
198 ErrorData => $error_data
199 );
200  
201 This is the constructor for C<Net::BGP::Notification> objects. It returns a
202 reference to the newly created object. The following named parameters may
203 be passed to the constructor.
204  
205 =head2 ErrorCode
206  
207 This parameter corresponds to the Error Code field of a NOTIFICATION
208 message. It must be provided to the constructor.
209  
210 =head2 ErrorSubCode
211  
212 This parameter corresponds to the Error Subcode field of a NOTIFICATION
213 message. It may be omitted, in which case the field defaults to the null
214 (0) subcode value.
215  
216 =head2 ErrorData
217  
218 This parameter corresponds to the Error Data field of a NOTIFICATION
219 message. It may be omitted, in which case the field defaults to a null
220 (zero-length) value.
221  
222 I<throw()> - create a Notification object and throw an exception
223  
224 Net::BGP::Notification->throw( same args as new );
225  
226 I<error_code()> - retrieve the value of the Error Code field
227  
228 $error_code = $error->error_code();
229  
230 I<error_subcode()> - retrieve the value of the Error Subcode field
231  
232 $error_subcode = $error->error_subcode();
233  
234 I<error_data()> - retrieve the value of the Error Data field
235  
236 $error_data = $error->error_data();
237  
238 =head1 SEE ALSO
239  
240 =over
241  
242 =item L<Net::BGP>
243  
244 =item L<Net::BGP::Process>
245  
246 =item L<Net::BGP::Peer>
247  
248 =item L<Net::BGP::Update>
249  
250 =item L<Net::BGP::Refresh>
251  
252 =item L<Net::BGP::ASPath>
253  
254 =item L<Net::BGP::NLRI>
255  
256 =back
257  
258 =head1 AUTHOR
259  
260 Stephen J. Scheck <sscheck@cpan.org>
261  
262 =cut
263  
264 ## End Package Net::BGP::Notification ##
265  
266 8 1;
« BGP/Refresh.pm ↑ Summary BGP/ASPath/AS_SET.pm »