| line | stmt | bran | cond | sub | pod | time | code | 
| 1 |  |  |  |  |  |  | #!/usr/bin/perl | 
| 2 |  |  |  |  |  |  |  | 
| 3 |  |  |  |  |  |  | package Net::BGP::Notification; | 
| 4 |  |  |  |  |  |  |  | 
| 5 | 8 |  |  | 8 |  | 56 | use strict; | 
|  | 8 |  |  |  |  | 17 |  | 
|  | 8 |  |  |  |  | 320 |  | 
| 6 | 8 |  |  | 8 |  | 41 | use vars qw( $VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS @ERRORS ); | 
|  | 8 |  |  |  |  | 16 |  | 
|  | 8 |  |  |  |  | 711 |  | 
| 7 |  |  |  |  |  |  |  | 
| 8 |  |  |  |  |  |  | ## Inheritance and Versioning ## | 
| 9 |  |  |  |  |  |  |  | 
| 10 |  |  |  |  |  |  | @ISA     = qw( Exporter ); | 
| 11 |  |  |  |  |  |  | $VERSION = '0.18'; | 
| 12 |  |  |  |  |  |  |  | 
| 13 |  |  |  |  |  |  | ## Module Imports ## | 
| 14 |  |  |  |  |  |  |  | 
| 15 | 8 |  |  | 8 |  | 57 | use Exporter; | 
|  | 8 |  |  |  |  | 15 |  | 
|  | 8 |  |  |  |  | 328 |  | 
| 16 | 8 |  |  | 8 |  | 47 | use Carp; | 
|  | 8 |  |  |  |  | 12 |  | 
|  | 8 |  |  |  |  | 6571 |  | 
| 17 |  |  |  |  |  |  |  | 
| 18 |  |  |  |  |  |  | ## BGP Protocol Error Code and Subcode Enumerations ## | 
| 19 |  |  |  |  |  |  |  | 
| 20 | 0 |  |  | 0 | 0 | 0 | sub BGP_ERROR_CODE_MESSAGE_HEADER             {  1 } | 
| 21 | 0 |  |  | 0 | 0 | 0 | sub BGP_ERROR_CODE_OPEN_MESSAGE               {  2 } | 
| 22 | 1 |  |  | 1 | 0 | 5 | sub BGP_ERROR_CODE_UPDATE_MESSAGE             {  3 } | 
| 23 | 0 |  |  | 0 | 0 | 0 | sub BGP_ERROR_CODE_HOLD_TIMER_EXPIRED         {  4 } | 
| 24 | 0 |  |  | 0 | 0 | 0 | sub BGP_ERROR_CODE_FINITE_STATE_MACHINE       {  5 } | 
| 25 | 6 |  |  | 6 | 0 | 31 | sub BGP_ERROR_CODE_CEASE                      {  6 } | 
| 26 |  |  |  |  |  |  |  | 
| 27 | 6 |  |  | 6 | 0 | 14 | sub BGP_ERROR_SUBCODE_NULL                    {  0 } | 
| 28 |  |  |  |  |  |  |  | 
| 29 | 0 |  |  | 0 | 0 | 0 | sub BGP_ERROR_SUBCODE_CONN_NOT_SYNC           {  1 } | 
| 30 | 0 |  |  | 0 | 0 | 0 | sub BGP_ERROR_SUBCODE_BAD_MSG_LENGTH          {  2 } | 
| 31 | 0 |  |  | 0 | 0 | 0 | sub BGP_ERROR_SUBCODE_BAD_MSG_TYPE            {  3 } | 
| 32 |  |  |  |  |  |  |  | 
| 33 | 0 |  |  | 0 | 0 | 0 | sub BGP_ERROR_SUBCODE_BAD_VERSION_NUM         {  1 } | 
| 34 | 0 |  |  | 0 | 0 | 0 | sub BGP_ERROR_SUBCODE_BAD_PEER_AS             {  2 } | 
| 35 | 0 |  |  | 0 | 0 | 0 | sub BGP_ERROR_SUBCODE_BAD_BGP_ID              {  3 } | 
| 36 | 0 |  |  | 0 | 0 | 0 | sub BGP_ERROR_SUBCODE_BAD_OPT_PARAMETER       {  4 } | 
| 37 | 0 |  |  | 0 | 0 | 0 | sub BGP_ERROR_SUBCODE_AUTH_FAILURE            {  5 } | 
| 38 | 0 |  |  | 0 | 0 | 0 | sub BGP_ERROR_SUBCODE_BAD_HOLD_TIME           {  6 } | 
| 39 |  |  |  |  |  |  |  | 
| 40 | 0 |  |  | 0 | 0 | 0 | sub BGP_ERROR_SUBCODE_MALFORMED_ATTR_LIST     {  1 } | 
| 41 | 0 |  |  | 0 | 0 | 0 | sub BGP_ERROR_SUBCODE_BAD_WELL_KNOWN_ATTR     {  2 } | 
| 42 | 0 |  |  | 0 | 0 | 0 | sub BGP_ERROR_SUBCODE_MISSING_WELL_KNOWN_ATTR {  3 } | 
| 43 | 1 |  |  | 1 | 0 | 7 | sub BGP_ERROR_SUBCODE_BAD_ATTR_FLAGS          {  4 } | 
| 44 | 0 |  |  | 0 | 0 | 0 | sub BGP_ERROR_SUBCODE_BAD_ATTR_LENGTH         {  5 } | 
| 45 | 0 |  |  | 0 | 0 | 0 | sub BGP_ERROR_SUBCODE_BAD_ORIGIN_ATTR         {  6 } | 
| 46 | 0 |  |  | 0 | 0 | 0 | sub BGP_ERROR_SUBCODE_AS_ROUTING_LOOP         {  7 } | 
| 47 | 0 |  |  | 0 | 0 | 0 | sub BGP_ERROR_SUBCODE_BAD_NEXT_HOP_ATTR       {  8 } | 
| 48 | 0 |  |  | 0 | 0 | 0 | sub BGP_ERROR_SUBCODE_BAD_OPT_ATTR            {  9 } | 
| 49 | 0 |  |  | 0 | 0 | 0 | sub BGP_ERROR_SUBCODE_BAD_NLRI                { 10 } | 
| 50 | 0 |  |  | 0 | 0 | 0 | sub BGP_ERROR_SUBCODE_BAD_AS_PATH             { 11 } | 
| 51 |  |  |  |  |  |  |  | 
| 52 |  |  |  |  |  |  | ## Export Tag Definitions ## | 
| 53 |  |  |  |  |  |  |  | 
| 54 |  |  |  |  |  |  | @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 |  |  |  |  |  |  | @EXPORT      = (); | 
| 85 |  |  |  |  |  |  | @EXPORT_OK   = ( @ERRORS ); | 
| 86 |  |  |  |  |  |  | %EXPORT_TAGS = ( | 
| 87 |  |  |  |  |  |  | errors => [ @ERRORS ], | 
| 88 |  |  |  |  |  |  | ALL    => [ @EXPORT, @EXPORT_OK ] | 
| 89 |  |  |  |  |  |  | ); | 
| 90 |  |  |  |  |  |  |  | 
| 91 |  |  |  |  |  |  | ## Public Methods ## | 
| 92 |  |  |  |  |  |  |  | 
| 93 |  |  |  |  |  |  | sub new | 
| 94 |  |  |  |  |  |  | { | 
| 95 | 9 |  |  | 9 | 0 | 33 | my $class = shift(); | 
| 96 | 9 |  |  |  |  | 19 | my ($arg, $value); | 
| 97 |  |  |  |  |  |  |  | 
| 98 | 9 |  |  |  |  | 43 | my $this = { | 
| 99 |  |  |  |  |  |  | _error_code    => undef, | 
| 100 |  |  |  |  |  |  | _error_subcode => undef, | 
| 101 |  |  |  |  |  |  | _error_data    => undef | 
| 102 |  |  |  |  |  |  | }; | 
| 103 |  |  |  |  |  |  |  | 
| 104 | 9 |  |  |  |  | 21 | bless($this, $class); | 
| 105 |  |  |  |  |  |  |  | 
| 106 | 9 |  |  |  |  | 31 | while ( defined($arg = shift()) ) { | 
| 107 | 15 |  |  |  |  | 25 | $value = shift(); | 
| 108 |  |  |  |  |  |  |  | 
| 109 | 15 | 100 |  |  |  | 116 | if ( $arg =~ /errorcode/i ) { | 
|  |  | 100 |  |  |  |  |  | 
|  |  | 50 |  |  |  |  |  | 
| 110 | 9 |  |  |  |  | 57 | $this->{_error_code} = $value; | 
| 111 |  |  |  |  |  |  | } | 
| 112 |  |  |  |  |  |  | elsif ( $arg =~ /errorsubcode/i ) { | 
| 113 | 3 |  |  |  |  | 10 | $this->{_error_subcode} = $value; | 
| 114 |  |  |  |  |  |  | } | 
| 115 |  |  |  |  |  |  | elsif ( $arg =~ /errordata/i ) { | 
| 116 | 3 |  |  |  |  | 22 | $this->{_error_data} = $value; | 
| 117 |  |  |  |  |  |  | } | 
| 118 |  |  |  |  |  |  | else { | 
| 119 | 0 |  |  |  |  | 0 | die("unrecognized argument $arg\n"); | 
| 120 |  |  |  |  |  |  | } | 
| 121 |  |  |  |  |  |  | } | 
| 122 |  |  |  |  |  |  |  | 
| 123 | 9 | 50 |  |  |  | 27 | defined $this->{_error_code} or croak "ErrorCode not defined"; | 
| 124 |  |  |  |  |  |  | defined $this->{_error_subcode} | 
| 125 | 9 | 100 |  |  |  | 28 | or $this->{_error_subcode} = BGP_ERROR_SUBCODE_NULL; | 
| 126 |  |  |  |  |  |  |  | 
| 127 | 9 |  |  |  |  | 28 | return ( $this ); | 
| 128 |  |  |  |  |  |  | } | 
| 129 |  |  |  |  |  |  |  | 
| 130 |  |  |  |  |  |  | sub throw { | 
| 131 | 1 |  |  | 1 | 0 | 3 | my $class = shift; | 
| 132 | 1 |  |  |  |  | 5 | my $notif = $class->new(@_); | 
| 133 | 1 |  |  |  |  | 13 | die $notif; | 
| 134 |  |  |  |  |  |  | } | 
| 135 |  |  |  |  |  |  |  | 
| 136 |  |  |  |  |  |  | sub error_code | 
| 137 |  |  |  |  |  |  | { | 
| 138 | 8 |  |  | 8 | 0 | 75 | my $this = shift(); | 
| 139 | 8 |  |  |  |  | 26 | return ( $this->{_error_code} ); | 
| 140 |  |  |  |  |  |  | } | 
| 141 |  |  |  |  |  |  |  | 
| 142 |  |  |  |  |  |  | sub error_subcode | 
| 143 |  |  |  |  |  |  | { | 
| 144 | 8 |  |  | 8 | 0 | 28 | my $this = shift(); | 
| 145 | 8 |  |  |  |  | 29 | return ( $this->{_error_subcode} ); | 
| 146 |  |  |  |  |  |  | } | 
| 147 |  |  |  |  |  |  |  | 
| 148 |  |  |  |  |  |  | sub error_data | 
| 149 |  |  |  |  |  |  | { | 
| 150 | 2 |  |  | 2 | 0 | 5 | my $this = shift(); | 
| 151 | 2 |  |  |  |  | 15 | return ( $this->{_error_data} ); | 
| 152 |  |  |  |  |  |  | } | 
| 153 |  |  |  |  |  |  |  | 
| 154 |  |  |  |  |  |  | ## Private Methods ## | 
| 155 |  |  |  |  |  |  |  | 
| 156 |  |  |  |  |  |  | ## POD ## | 
| 157 |  |  |  |  |  |  |  | 
| 158 |  |  |  |  |  |  | =pod | 
| 159 |  |  |  |  |  |  |  | 
| 160 |  |  |  |  |  |  | =head1 NAME | 
| 161 |  |  |  |  |  |  |  | 
| 162 |  |  |  |  |  |  | C - 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 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 | 
| 186 |  |  |  |  |  |  | module, a reference to a C 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 - create a new C 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 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 - create a Notification object and throw an exception | 
| 223 |  |  |  |  |  |  |  | 
| 224 |  |  |  |  |  |  | Net::BGP::Notification->throw( same args as new ); | 
| 225 |  |  |  |  |  |  |  | 
| 226 |  |  |  |  |  |  | I - retrieve the value of the Error Code field | 
| 227 |  |  |  |  |  |  |  | 
| 228 |  |  |  |  |  |  | $error_code = $error->error_code(); | 
| 229 |  |  |  |  |  |  |  | 
| 230 |  |  |  |  |  |  | I - retrieve the value of the Error Subcode field | 
| 231 |  |  |  |  |  |  |  | 
| 232 |  |  |  |  |  |  | $error_subcode = $error->error_subcode(); | 
| 233 |  |  |  |  |  |  |  | 
| 234 |  |  |  |  |  |  | I - 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 | 
| 243 |  |  |  |  |  |  |  | 
| 244 |  |  |  |  |  |  | =item L | 
| 245 |  |  |  |  |  |  |  | 
| 246 |  |  |  |  |  |  | =item L | 
| 247 |  |  |  |  |  |  |  | 
| 248 |  |  |  |  |  |  | =item L | 
| 249 |  |  |  |  |  |  |  | 
| 250 |  |  |  |  |  |  | =item L | 
| 251 |  |  |  |  |  |  |  | 
| 252 |  |  |  |  |  |  | =item L | 
| 253 |  |  |  |  |  |  |  | 
| 254 |  |  |  |  |  |  | =item L | 
| 255 |  |  |  |  |  |  |  | 
| 256 |  |  |  |  |  |  | =back | 
| 257 |  |  |  |  |  |  |  | 
| 258 |  |  |  |  |  |  | =head1 AUTHOR | 
| 259 |  |  |  |  |  |  |  | 
| 260 |  |  |  |  |  |  | Stephen J. Scheck | 
| 261 |  |  |  |  |  |  |  | 
| 262 |  |  |  |  |  |  | =cut | 
| 263 |  |  |  |  |  |  |  | 
| 264 |  |  |  |  |  |  | ## End Package Net::BGP::Notification ## | 
| 265 |  |  |  |  |  |  |  | 
| 266 |  |  |  |  |  |  | 1; |