| 1 | package TL1::Toolkit; | ||
| 2 | |||
| 3 | |||
| 4 | use 5.008; | ||
| 5 | use strict; | ||
| 6 | use warnings; | ||
| 7 | |||
| 8 | our $VERSION = "0.02"; | ||
| 9 | |||
| 10 | # Module import | ||
| 11 | use threads; | ||
| 12 | use threads::shared; | ||
| 13 | use Thread::Queue::Any; | ||
| 14 | use Net::Telnet; | ||
| 15 | |||
| 16 | # $Revision: 602 $ | ||
| 17 | # +--------------------------------------------------------------------------+ | ||
| 18 | # | Licensed under the Apache License, Version 2.0 (the "License"); | | ||
| 19 | # | you may not use this file except in compliance with the License. | | ||
| 20 | # | You may obtain a copy of the License at | | ||
| 21 | # | | | ||
| 22 | # | http://www.apache.org/licenses/LICENSE-2.0 | | ||
| 23 | # | | | ||
| 24 | # | Unless required by applicable law or agreed to in writing, software | | ||
| 25 | # | distributed under the License is distributed on an "AS IS" BASIS, | | ||
| 26 | # | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | | ||
| 27 | # | See the License for the specific language governing permissions and | | ||
| 28 | # | limitations under the License. | | ||
| 29 | # +--------------------------------------------------------------------------+ | ||
| 30 | |||
| 31 | =pod | ||
| 32 | |||
| 33 | =head1 NAME | ||
| 34 | |||
| 35 | TL1::Toolkit - Utility functions for interacting with TL1 equipment | ||
| 36 | |||
| 37 | =head1 VERSION | ||
| 38 | |||
| 39 | 0.02 | ||
| 40 | |||
| 41 | =head1 DESCRIPTION | ||
| 42 | |||
| 43 | This Perl module is intended to hide the difficult TL1 syntax from | ||
| 44 | the user. It executes TL1 commands and returns the results in Perl | ||
| 45 | data structures. For example, if you work with different types and/or | ||
| 46 | vendors of devices the TL1 syntax might be different as well as the | ||
| 47 | output. This TL1 module retrieves information from different types | ||
| 48 | and/or vendors of devices without having to know the exact details. | ||
| 49 | There is also a cmd() function to execute any TL1 function. In this | ||
| 50 | case the user has to parse the returned results. This module is known | ||
| 51 | to work on Nortel OME6500, Nortel DWDM CPL, Nortel HDXc, Nortel OM5200, | ||
| 52 | Cisco ONS15454 and Adva FSP3000; but it should work on any TL1 capable | ||
| 53 | device. | ||
| 54 | |||
| 55 | =head1 SYNOPSIS | ||
| 56 | |||
| 57 | =head2 my $tl1 = TL1::Toolkit->new("node", "name", "secret"); | ||
| 58 | |||
| 59 | Create a TL1::Toolkit object that holds information about a TL1 session. | ||
| 60 | Its arguments are: | ||
| 61 | |||
| 62 | =over | ||
| 63 | |||
| 64 | =item * | ||
| 65 | |||
| 66 | hostname: network element to connect to | ||
| 67 | |||
| 68 | =item * | ||
| 69 | |||
| 70 | username: login name | ||
| 71 | |||
| 72 | =item * | ||
| 73 | |||
| 74 | password: password | ||
| 75 | |||
| 76 | =item * | ||
| 77 | |||
| 78 | type (optional): device type (OME6500, HDXc) | ||
| 79 | |||
| 80 | =item * | ||
| 81 | |||
| 82 | verbose (optional): debug level (0..9) | ||
| 83 | |||
| 84 | =back | ||
| 85 | |||
| 86 | =cut | ||
| 87 | |||
| 88 | my $keep_reading : shared = 1; | ||
| 89 | |||
| 90 | ########################################################################### | ||
| 91 | # Constructor method | ||
| 92 | ########################################################################### | ||
| 93 | sub new { | ||
| 94 | my $invocant = shift; | ||
| 95 | my $class = ref($invocant) || $invocant; | ||
| 96 | $keep_reading = 1; | ||
| 97 | my $self = { | ||
| 98 | username => 'xxxx', | ||
| 99 | password => 'xxxx', | ||
| 100 | type => 'OME6500', | ||
| 101 | ctag => '1', | ||
| 102 | timeout => 10, | ||
| 103 | retries => 3, | ||
| 104 | verbose => 0, | ||
| 105 | @_, | ||
| 106 | }; | ||
| 107 | |||
| 108 | bless( $self, $class ); | ||
| 109 | # 3 threads started | ||
| 110 | #resp_queue has responses | ||
| 111 | $self->{'resp_queue'} = Thread::Queue->new(); | ||
| 112 | #auto_queue has autonomous messages | ||
| 113 | $self->{'auto_queue'} = Thread::Queue->new(); | ||
| 114 | # | ||
| 115 | $self->{'acmd_queue'} = Thread::Queue->new(); | ||
| 116 | |||
| 117 | $self->_verbose( 2, | ||
| 118 | "Created tl1 object for: $self->{'hostname'}.\n" ); | ||
| 119 | return $self; | ||
| 120 | } | ||
| 121 | |||
| 122 | sub _verbose { | ||
| 123 | my ( $self, $level, $info ) = @_; | ||
| 124 | print( STDERR "debug$level: $info" ) | ||
| 125 | if ( $level <= $self->{'verbose'} ); | ||
| 126 | } | ||
| 127 | |||
| 128 | sub _receiver_thread { | ||
| 129 | my ($self) = @_; # Object this method is part of | ||
| 130 | my $state = 'noop'; # State of FSM | ||
| 131 | my $n = 0; # Counter variable | ||
| 132 | my @response; # Local copy of return array | ||
| 133 | my $socket = $self->{'socket'}; # Socket | ||
| 134 | |||
| 135 | # Debug message | ||
| 136 | $self->_verbose( 3, "Starting receiver thread.\n" ); | ||
| 137 | |||
| 138 | my $buf; | ||
| 139 | while ($keep_reading) { | ||
| 140 | # The OM5200 does not end its response with a newline. | ||
| 141 | # Therefore, the last line is a single ';' character. | ||
| 142 | # Look ahead in the buffer to detect this situation. | ||
| 143 | my $bufref = $socket->buffer(); | ||
| 144 | if (!defined($$bufref)) { | ||
| 145 | $self->_verbose(1, "bufref not defined\n"); | ||
| 146 | } | ||
| 147 | if ((length($$bufref) == 1) && ($$bufref eq ";") && | ||
| 148 | (($state eq 'response') || $state eq 'auto')) { | ||
| 149 | $self->_verbose( 9, "; read, state == response\n" ); | ||
| 150 | $buf = $socket->get(); | ||
| 151 | } else { | ||
| 152 | $self->_verbose( 9, "state = $state\n" ); | ||
| 153 | $buf = $socket->getline(); | ||
| 154 | } | ||
| 155 | if (!defined($buf)) { | ||
| 156 | $n++; | ||
| 157 | if (!$socket->eof()) { | ||
| 158 | my $msg = $socket->errmsg; | ||
| 159 | if ($msg ne "") { | ||
| 160 | $self->_verbose(1, "_receiver_thread $self->{'hostname'} (state=$state, retries=$n): $msg\n"); | ||
| 161 | } | ||
| 162 | } | ||
| 163 | # not sure if @resp needs to be shared | ||
| 164 | #my @resp : shared = undef; | ||
| 165 | if ($n >= $self->{'retries'}) { | ||
| 166 | $self->{'resp_queue'}->enqueue(undef); | ||
| 167 | $n = 0; | ||
| 168 | } | ||
| 169 | next; | ||
| 170 | } | ||
| 171 | # Debug message | ||
| 172 | $self->_verbose( 3, "$buf\n" ); | ||
| 173 | $n = 0; | ||
| 174 | SWITCH: { | ||
| 175 | # a line with a ; only means the end of a response | ||
| 176 | $buf =~ /^;/ && ( $state =~ /auto|response/ ) && do { | ||
| 177 | if ( $state eq 'auto' | ||
| 178 | && defined( $self->{'auto_code'} ) ) | ||
| 179 | { | ||
| 180 | |||
| 181 | # Return autonomous data | ||
| 182 | my @resp : shared = @response; | ||
| 183 | $self->{'auto_queue'}->enqueue( \@resp ); | ||
| 184 | } | ||
| 185 | elsif ( $state eq 'response' ) { | ||
| 186 | # this is what we do at the end of a response | ||
| 187 | # Return response data in @response | ||
| 188 | # it returns a reference to @response called @resp | ||
| 189 | |||
| 190 | my @resp : shared = @response; | ||
| 191 | $self->{'resp_queue'}->enqueue( \@resp ); | ||
| 192 | } | ||
| 193 | @response = (); | ||
| 194 | $socket->buffer_empty(); | ||
| 195 | |||
| 196 | $state = 'noop'; | ||
| 197 | last SWITCH; | ||
| 198 | }; | ||
| 199 | |||
| 200 | $buf =~ /^[;\r\n\<\>]/ && do { | ||
| 201 | $state = 'noop'; | ||
| 202 | last SWITCH; | ||
| 203 | }; | ||
| 204 | |||
| 205 | # start of an autonomonous message (alarm) | ||
| 206 | $buf =~ /^(\*C|\*\*|\* |A ) (\d{1,10}) (.*)/ && do { | ||
| 207 | $state = 'auto'; | ||
| 208 | last SWITCH; | ||
| 209 | }; | ||
| 210 | |||
| 211 | # start of a response | ||
| 212 | $buf =~ /^M (.*) (COMPLD|PRTL|DENY)/ && do { | ||
| 213 | $state = 'response'; | ||
| 214 | last SWITCH; | ||
| 215 | }; | ||
| 216 | |||
| 217 | # line with host date and time | ||
| 218 | $buf =~ /( (.*) (\d{2}-\d{2}-\d{2}) (\d{2}:\d{2}:\d{2}))/ | ||
| 219 | && do { | ||
| 220 | $state = 'log'; | ||
| 221 | last SWITCH; | ||
| 222 | }; | ||
| 223 | } | ||
| 224 | if ($state ne 'noop') { | ||
| 225 | chomp($buf); | ||
| 226 | # lines are pushed in @response until a line with | ||
| 227 | # a ; only ($state equals 'noop') is read | ||
| 228 | push( @response, $buf ); | ||
| 229 | } | ||
| 230 | } | ||
| 231 | $self->{'resp_queue'}->enqueue(undef); | ||
| 232 | $self->_verbose( 3, "Receiver thread ended.\n" ); | ||
| 233 | } | ||
| 234 | |||
| 235 | sub _auto_thread { | ||
| 236 | my ($self) = @_; | ||
| 237 | |||
| 238 | $self->_verbose( 3, "Autonomous messages thread started.\n" ); | ||
| 239 | while ( my $msg_ref = $self->{'auto_queue'}->dequeue() ) { | ||
| 240 | $self->{'auto_code'}->($self, $msg_ref, | ||
| 241 | $self->{'auto_arg_ref'} ); | ||
| 242 | } | ||
| 243 | $self->_verbose( 3, "Autonomous messages thread ended.\n" ); | ||
| 244 | } | ||
| 245 | |||
| 246 | sub _set_auto_code { | ||
| 247 | my ( $self, $func_ref, $arg_ref ) = @_; | ||
| 248 | $self->{'auto_code'} = $func_ref; | ||
| 249 | $self->{'auto_arg_ref'} = $arg_ref; | ||
| 250 | } | ||
| 251 | |||
| 252 | sub _async_cmd_thread { | ||
| 253 | my ($self) = @_; | ||
| 254 | |||
| 255 | $self->_verbose( 3, "Starting async command thread.\n" ); | ||
| 256 | while ( my $cmd = $self->{'acmd_queue'}->dequeue() ) { | ||
| 257 | my $resp_ref = $self->cmd($cmd); | ||
| 258 | $self->{'async_code'}->( $resp_ref, $self->{'async_arg_ref'} ) | ||
| 259 | if defined( $self->{'async_code'} ); | ||
| 260 | } | ||
| 261 | $self->_verbose( 3, "Async command thread ended.\n" ); | ||
| 262 | } | ||
| 263 | |||
| 264 | sub _set_async_code { | ||
| 265 | my ( $self, $func_ref, $arg_ref ) = @_; | ||
| 266 | $self->{'async_code'} = $func_ref; | ||
| 267 | $self->{'async_arg_ref'} = $arg_ref; | ||
| 268 | } | ||
| 269 | |||
| 270 | ########################################################################### | ||
| 271 | =pod | ||
| 272 | |||
| 273 | =head2 $tl1->open() | ||
| 274 | |||
| 275 | Connect to the TL1 device and login. Returns 1 on success, 0 on failure. | ||
| 276 | |||
| 277 | =cut | ||
| 278 | |||
| 279 | ########################################################################### | ||
| 280 | # Connect and login to TL1 device. | ||
| 281 | ########################################################################### | ||
| 282 | sub open { | ||
| 283 | my ($self) = @_; | ||
| 284 | $self->_verbose( 3, | ||
| 285 | "Starting threads for tl1 device: $self->{'hostname'}.\n" ); | ||
| 286 | |||
| 287 | # open socket connection | ||
| 288 | my $con = 1; | ||
| 289 | $self->{'socket'} = new Net::Telnet( | ||
| 290 | Timeout => $self->{'timeout'}, | ||
| 291 | Errmode => 'return' | ||
| 292 | ); | ||
| 293 | $self->{'socket'}->port($self->{'peerport'}); | ||
| 294 | $self->{'socket'}->open($self->{'hostname'}); | ||
| 295 | |||
| 296 | if ( $con != 1 ) { | ||
| 297 | $self->_verbose(1, "Can't connect to $self->{'hostname'}\n"); | ||
| 298 | return 0; | ||
| 299 | } | ||
| 300 | |||
| 301 | # Handle alarms | ||
| 302 | if ( defined( $self->{'auto_code'} ) ) { | ||
| 303 | $self->{'auto_thread'} = async { | ||
| 304 | $self->_auto_thread(); | ||
| 305 | } | ||
| 306 | } | ||
| 307 | |||
| 308 | # Start receiver | ||
| 309 | $self->{'receiver_thread'} = async { | ||
| 310 | $self->_receiver_thread(); | ||
| 311 | }; | ||
| 312 | |||
| 313 | # Async commands | ||
| 314 | $self->{'async_cmd_thread'} = async { | ||
| 315 | $self->_async_cmd_thread(); | ||
| 316 | }; | ||
| 317 | |||
| 318 | # login | ||
| 319 | my $result = $self->_login(); | ||
| 320 | if ($result ne "COMPLD") { | ||
| 321 | $self->_verbose(1, "login failed for $self->{'hostname'} $self->{'username'}\n"); | ||
| 322 | $self->{'socket'}->close(); | ||
| 323 | if ( defined( $self->{'auto_code'} ) ) { | ||
| 324 | $self->{'auto_queue'}->enqueue(undef); | ||
| 325 | $self->{'auto_thread'}->join(); | ||
| 326 | } | ||
| 327 | $self->{'acmd_queue'}->enqueue(undef); | ||
| 328 | $self->{'async_cmd_thread'}->join(); | ||
| 329 | $keep_reading = 0; | ||
| 330 | $self->{'receiver_thread'}->join(); | ||
| 331 | return 0; | ||
| 332 | } else { | ||
| 333 | $self->_verbose( 2, "login succeeded $self->{'username'}.\n" ); | ||
| 334 | } | ||
| 335 | return 1; | ||
| 336 | |||
| 337 | } | ||
| 338 | |||
| 339 | ########################################################################### | ||
| 340 | =pod | ||
| 341 | |||
| 342 | =head2 $tl1->close() | ||
| 343 | |||
| 344 | Logout and disconnect from the TL1 device. | ||
| 345 | |||
| 346 | =cut | ||
| 347 | |||
| 348 | ########################################################################### | ||
| 349 | # Logout and disconnect from TL1 device. | ||
| 350 | ########################################################################### | ||
| 351 | sub close { | ||
| 352 | my ($self) = @_; | ||
| 353 | $self->_verbose( 2, "Closing connection to $self->{'hostname'}.\n" ); | ||
| 354 | my $socket = $self->{'socket'}; | ||
| 355 | $socket->print("canc-user::$self->{'username'}:$self->{'ctag'};\n"); | ||
| 356 | $keep_reading = 0; | ||
| 357 | my $out = $self->{'resp_queue'}->dequeue(); | ||
| 358 | my $check = check_resp($out); | ||
| 359 | $self->{'socket'}->close(); | ||
| 360 | if ( defined( $self->{'auto_code'} ) ) { | ||
| 361 | $self->{'auto_queue'}->enqueue(undef); | ||
| 362 | $self->{'auto_thread'}->join(); | ||
| 363 | } | ||
| 364 | $self->{'acmd_queue'}->enqueue(undef); | ||
| 365 | $self->{'async_cmd_thread'}->join(); | ||
| 366 | $self->{'receiver_thread'}->join(); | ||
| 367 | return $check; | ||
| 368 | } | ||
| 369 | |||
| 370 | sub _login() { | ||
| 371 | my ($self) = @_; | ||
| 372 | $self->_verbose( 3, "starting login to $self->{'hostname'}.\n" ); | ||
| 373 | my $out = $self->cmd("ACT-USER::$self->{'username'}:$self->{'ctag'}::$self->{'password'};\n"); | ||
| 374 | my $check = check_resp ($out); | ||
| 375 | return $check; | ||
| 376 | } | ||
| 377 | |||
| 378 | ########################################################################### | ||
| 379 | =pod | ||
| 380 | |||
| 381 | =head2 my $output = $tl1->cmd($command); | ||
| 382 | |||
| 383 | The string variable $command contains a TL1 command string that will be | ||
| 384 | sent to the TL1 device as is. It returns the results as ASCII text to | ||
| 385 | the string variable $output. | ||
| 386 | |||
| 387 | =cut | ||
| 388 | |||
| 389 | ########################################################################### | ||
| 390 | # Send TL1 command and return response | ||
| 391 | ########################################################################### | ||
| 392 | sub cmd { | ||
| 393 | my ( $self, $cmd ) = @_; | ||
| 394 | my $socket = $self->{'socket'}; | ||
| 395 | $socket->print($cmd); | ||
| 396 | my $resp_ref = $self->{'resp_queue'}->dequeue(); | ||
| 397 | return $resp_ref; | ||
| 398 | } | ||
| 399 | |||
| 400 | ########################################################################### | ||
| 401 | =pod | ||
| 402 | |||
| 403 | =head2 my $type = $tl1->get_cardtype(1, 12); | ||
| 404 | |||
| 405 | Return the type of card in the shelf given as first argument and the | ||
| 406 | slot given as second argument. Returns a string. | ||
| 407 | |||
| 408 | =cut | ||
| 409 | |||
| 410 | ########################################################################### | ||
| 411 | # Return card type (CTYPE) string present in $shelf/$slot. | ||
| 412 | ########################################################################### | ||
| 413 | sub get_cardtype { | ||
| 414 | my ($self, $shelf, $slot) = @_; | ||
| 415 | |||
| 416 | my $socket = $self->{'socket'}; | ||
| 417 | $socket->print("RTRV-INVENTORY::SLOT-$shelf-$slot:$self->{'ctag'};\n"); | ||
| 418 | my $resp = $self->{'resp_queue'}->dequeue(); | ||
| 419 | my $n = 0; | ||
| 420 | while (defined($resp->[$n])) { | ||
| 421 | if ($resp->[$n] =~ /"AP-\d+-\d+::CTYPE/) { | ||
| 422 | # skip Access Panel line | ||
| 423 | } elsif ($resp->[$n] =~ /"\S+-\d+-\d+::CTYPE=\\"(.*?)\\",/) { | ||
| 424 | return $1; | ||
| 425 | } | ||
| 426 | $n++; | ||
| 427 | } | ||
| 428 | return undef(); | ||
| 429 | } | ||
| 430 | |||
| 431 | ########################################################################### | ||
| 432 | =pod | ||
| 433 | |||
| 434 | =head2 my $version = $tl1->get_swversion(); | ||
| 435 | |||
| 436 | Returns the currently active firmware version on the TL1 device. Returns | ||
| 437 | a string. | ||
| 438 | |||
| 439 | =cut | ||
| 440 | |||
| 441 | ########################################################################### | ||
| 442 | # Returns the currently active firmware version of the TL1 device. | ||
| 443 | ########################################################################### | ||
| 444 | sub get_swversion { | ||
| 445 | my ( $self ) = @_; | ||
| 446 | my $swversion; | ||
| 447 | $self->_verbose(1, "Retrieve software vesion\n"); | ||
| 448 | my $socket = $self->{'socket'}; | ||
| 449 | if ($self->{'type'} eq "OME6500") { | ||
| 450 | $socket->print("RTRV-SW-VER:::$self->{'ctag'};\n"); | ||
| 451 | my $resp = $self->{'resp_queue'}->dequeue(); | ||
| 452 | my $n = 0; | ||
| 453 | while (defined($resp->[$n])) { | ||
| 454 | # SHELF-1:REL0200Z.HQ | ||
| 455 | if ($resp->[$n] =~ /"SHELF-1:(\w+).*"/) { | ||
| 456 | $swversion = $1; | ||
| 457 | } | ||
| 458 | $n++; | ||
| 459 | } | ||
| 460 | } elsif ($self->{'type'} eq "HDXc") { | ||
| 461 | $socket->print("RTRV-UPGRD-STATUS:::$self->{'ctag'};\n"); | ||
| 462 | my $resp = $self->{'resp_queue'}->dequeue(); | ||
| 463 | my $n = 0; | ||
| 464 | while (defined($resp->[$n])) { | ||
| 465 | # "RELEASE=HDX_Rel_03.30_fo09,... | ||
| 466 | if ($resp->[$n] =~ /"RELEASE=([^,]+),/) { | ||
| 467 | $swversion = $1; | ||
| 468 | } | ||
| 469 | $n++; | ||
| 470 | } | ||
| 471 | } | ||
| 472 | return $swversion; | ||
| 473 | } | ||
| 474 | |||
| 475 | ########################################################################### | ||
| 476 | =pod | ||
| 477 | |||
| 478 | =head2 my $octets = $tl1->get_inoctets(1, 3); | ||
| 479 | |||
| 480 | Returns the Ethernet input octets on the slot given as first argument | ||
| 481 | and the port given as second argument. Returns an integer. | ||
| 482 | |||
| 483 | =cut | ||
| 484 | |||
| 485 | ########################################################################### | ||
| 486 | # Returns the Ethernet input octets on slot/port. | ||
| 487 | ########################################################################### | ||
| 488 | sub get_inoctets { | ||
| 489 | my ( $self ) = @_; | ||
| 490 | my $inoctets = 0; | ||
| 491 | $self->_verbose( 1, "Retrieve input octets\n" ); | ||
| 492 | my $socket = $self->{'socket'}; | ||
| 493 | my $slot= $self->{'slot'}; | ||
| 494 | my $port = $self->{'port'}; | ||
| 495 | my $swver = $self->get_swversion; | ||
| 496 | if (!defined($swver)) { | ||
| 497 | return undef; | ||
| 498 | } | ||
| 499 | # if ($swver eq 'REL0200Z') { | ||
| 500 | # $self->_verbose( 1, "sw version is REL0200Z command RTRV-OM-ETH::ETH-1-$slot-$port:45::;\n" ); | ||
| 501 | # $socket->print("RTRV-OM-ETH::ETH-1-$slot-$port:$self->{'ctag'}::;\n"); | ||
| 502 | # } else { | ||
| 503 | # $socket->print("RTRV-OM-if::ETH-1-$slot-$port:$self->{'ctag'}::;\n"); | ||
| 504 | # } | ||
| 505 | $socket->print("RTRV-OM-ETH::ETH-1-$slot-$port:$self->{'ctag'}::;\n"); | ||
| 506 | my $resp = $self->{'resp_queue'}->dequeue(); | ||
| 507 | my $n = 0; | ||
| 508 | while (defined($resp->[$n])) { | ||
| 509 | #match ETH-1-4-1::INFRAMES=343136315745,INFRAMESERR=0,INOCTETS=21960686905538,INDFR=1023574,INFRAMESDISCDS=0,INCFR=0,FRTOOSHORTS=0,FCSERR=0,FRTOOLONGS=0,OUTFRAMES=948548260,OUTOCTETS=68296800619,OUTPAUSEFR=0,OUTDFR=0,INTERNALMACRXERR=0,INTERNALMACTXERR=0,DEFERTRANS=77813222 | ||
| 510 | if ($resp->[$n] =~ /".*,INOCTETS=(\d+).*"/) { | ||
| 511 | $inoctets = $1; | ||
| 512 | } | ||
| 513 | $n++; | ||
| 514 | } | ||
| 515 | return $inoctets; | ||
| 516 | } | ||
| 517 | |||
| 518 | ########################################################################### | ||
| 519 | =pod | ||
| 520 | |||
| 521 | =head2 my $octets = $tl1->get_outoctets(7, 2); | ||
| 522 | |||
| 523 | Returns the Ethernet output octets on the slot given as first argument | ||
| 524 | and the port given as second argument. Returns an integer. | ||
| 525 | |||
| 526 | =cut | ||
| 527 | |||
| 528 | ########################################################################### | ||
| 529 | # Returns the Ethernet output octets on slot/port. | ||
| 530 | ########################################################################### | ||
| 531 | sub get_outoctets { | ||
| 532 | my ( $self ) = @_; | ||
| 533 | my $outoctets = 0; | ||
| 534 | $self->_verbose( 1, "Retrieve output octets\n" ); | ||
| 535 | my $socket = $self->{'socket'}; | ||
| 536 | my $slot= $self->{'slot'}; | ||
| 537 | my $port = $self->{'port'}; | ||
| 538 | my $swver = $self->get_swversion; | ||
| 539 | if (!defined($swver)) { | ||
| 540 | return undef; | ||
| 541 | } | ||
| 542 | # if ($swver eq 'REL0200Z') { | ||
| 543 | # $self->_verbose( 1, "sw version is REL0200Z command RTRV-OM-ETH::ETH-1-$slot-$port:45::;\n" ); | ||
| 544 | # $socket->print("RTRV-OM-ETH::ETH-1-$slot-$port:$self->{'ctag'}::;\n"); | ||
| 545 | # } else { | ||
| 546 | # $socket->print("RTRV-OM-if::ETH-1-$slot-$port:$self->{'ctag'}::;\n"); | ||
| 547 | # } | ||
| 548 | $socket->print("RTRV-OM-ETH::ETH-1-$slot-$port:$self->{'ctag'}::;\n"); | ||
| 549 | my $resp = $self->{'resp_queue'}->dequeue(); | ||
| 550 | my $n = 0; | ||
| 551 | while (defined($resp->[$n])) { | ||
| 552 | #matchETH-1-4-1::INFRAMES=343136315745,INFRAMESERR=0,INOCTETS=21960686905538,INDFR=1023574,INFRAMESDISCDS=0,INCFR=0,FRTOOSHORTS=0,FC SERR=0,FRTOOLONGS=0,OUTFRAMES=948548260,OUTOCTETS=68296800619,OUTPAUSEFR=0,OUTDFR=0,INTERNALMACRXERR=0,INTERNALMACTXERR=0,DEFERTRANS=77813222 | ||
| 553 | if ($resp->[$n] =~ /".*,OUTOCTETS=(\d+).*"/) { | ||
| 554 | $outoctets = $1; | ||
| 555 | } | ||
| 556 | $n++; | ||
| 557 | } | ||
| 558 | return $outoctets; | ||
| 559 | } | ||
| 560 | |||
| 561 | ########################################################################### | ||
| 562 | =pod | ||
| 563 | |||
| 564 | =head2 my @alarms = $tl1->get_alarms(); | ||
| 565 | |||
| 566 | Returns an array of hashes containing information about active alarms | ||
| 567 | on the TL1 device. Each entry in the array conatains information about | ||
| 568 | one alarm. The keys of each alarm are: | ||
| 569 | |||
| 570 | =over | ||
| 571 | |||
| 572 | =item * | ||
| 573 | |||
| 574 | interface | ||
| 575 | |||
| 576 | =item * | ||
| 577 | |||
| 578 | severity | ||
| 579 | |||
| 580 | =item * | ||
| 581 | |||
| 582 | impact | ||
| 583 | |||
| 584 | =item * | ||
| 585 | |||
| 586 | day | ||
| 587 | |||
| 588 | =item * | ||
| 589 | |||
| 590 | time | ||
| 591 | |||
| 592 | =item * | ||
| 593 | |||
| 594 | alarm | ||
| 595 | |||
| 596 | =item * | ||
| 597 | |||
| 598 | year | ||
| 599 | |||
| 600 | =item * | ||
| 601 | |||
| 602 | date | ||
| 603 | |||
| 604 | =item * | ||
| 605 | |||
| 606 | slot | ||
| 607 | |||
| 608 | =item * | ||
| 609 | |||
| 610 | subslot | ||
| 611 | |||
| 612 | =item * | ||
| 613 | |||
| 614 | port | ||
| 615 | |||
| 616 | =item * | ||
| 617 | |||
| 618 | fromfirststs | ||
| 619 | |||
| 620 | =back | ||
| 621 | |||
| 622 | Some of the keys can have an "undef" value. | ||
| 623 | |||
| 624 | =cut | ||
| 625 | |||
| 626 | ########################################################################### | ||
| 627 | # Returns the active alarms on the TL1 device as an array of hashes. | ||
| 628 | ########################################################################### | ||
| 629 | sub get_alarms { | ||
| 630 | my ($self) = @_; | ||
| 631 | my $key; | ||
| 632 | my @result; | ||
| 633 | my $ainfo; | ||
| 634 | my $val; | ||
| 635 | my $socket = $self->{'socket'}; | ||
| 636 | $self->_verbose( 1, "retrieving alarms for $self->{'type'}\n" ); | ||
| 637 | if ($self->{'type'} eq "OME6500") { | ||
| 638 | $socket->print("RTRV-ALM-ALL:::$self->{'ctag'}:::;\n"); | ||
| 639 | my $resp = $self->{'resp_queue'}->dequeue(); | ||
| 640 | my $n = 0; | ||
| 641 | while (defined($resp->[$n])) { | ||
| 642 | # match "LAN-1-15,COM:MN,NET,NSA,11-01,15-44-31,NEND,NA:\"LAN-15 Port Failure\":0100000002-5003-0536,:YEAR=2005,MODE=NONE" | ||
| 643 | if ($resp->[$n] =~ /"([^,]+),\w+:(\w+),\w+,(\w+),(\d+-\d+),(\d{1,2}-\d{1,2}-\d{1,2}),.*:\\"(.*)\\".*YEAR=(\d\d\d\d),.*"/) { | ||
| 644 | #print "$1 $2 $3 $4 $5 $6 $7\n"; | ||
| 645 | my $interface = $1; | ||
| 646 | my $severity = $2; | ||
| 647 | my $impact = $3; | ||
| 648 | my $day = $4; | ||
| 649 | my $time = $5; | ||
| 650 | my $alarm = $6; | ||
| 651 | my $year = $7; | ||
| 652 | my $date = "$7-$4"; | ||
| 653 | my $slot = undef; | ||
| 654 | my $subslot = undef; | ||
| 655 | my $port = undef; | ||
| 656 | my $fromfirststs = undef; | ||
| 657 | # interface can have diferent forms: | ||
| 658 | # STS3C-1-5-1-88 | ||
| 659 | # WAN-1-2-4 | ||
| 660 | # ETH-1-1-2 | ||
| 661 | # 10G-1-10 | ||
| 662 | # FILLER-1-9 | ||
| 663 | if ($interface =~ /\w+-\d+-(\d+)-?(\d+)?-?(\d+)?/) { | ||
| 664 | $slot = $1; | ||
| 665 | if (defined $2){ | ||
| 666 | #print "port is $2\n"; | ||
| 667 | $port = $2; | ||
| 668 | } | ||
| 669 | if (defined $3){ | ||
| 670 | #print "beginsts is $3\n"; | ||
| 671 | $fromfirststs = $3; | ||
| 672 | } | ||
| 673 | } | ||
| 674 | |||
| 675 | $ainfo = { | ||
| 676 | interface => $interface, | ||
| 677 | slot => $slot, | ||
| 678 | subslot => $subslot, | ||
| 679 | port => $port, | ||
| 680 | fromfirststs => $fromfirststs, | ||
| 681 | severity => $severity, | ||
| 682 | impact => $impact, | ||
| 683 | date => $date, | ||
| 684 | time => $time, | ||
| 685 | alarm => $alarm | ||
| 686 | }; | ||
| 687 | push @result, $ainfo; | ||
| 688 | } | ||
| 689 | $n++; | ||
| 690 | } | ||
| 691 | return @result; | ||
| 692 | |||
| 693 | } elsif ($self->{'type'} eq "HDXc") { | ||
| 694 | $socket->print("RTRV-ALM-ALL:::$self->{'ctag'}:::;\n"); | ||
| 695 | my $resp = $self->{'resp_queue'}->dequeue(); | ||
| 696 | my $n = 0; | ||
| 697 | #print_resp($resp); | ||
| 698 | while (defined($resp->[$n])) { | ||
| 699 | # match "ESI-2-SATT-1,TMG:MN,SYNCLOS,NSA,09-13,04-18-28,NEND,RCV:\"Loss of signal\",,\"TYP-SH-SATT-PRT\",:000006-6040-0066,:YEAR=2005" | ||
| 700 | if ($resp->[$n] =~ /"([^,]+),\w+:(\w+),\w+,(\w+),(\d+-\d+),(\d{1,2}-\d{1,2}-\d{1,2}),.*:\\"(.*)\\",.*,.*,.*:YEAR=(\d\d\d\d).*"/) { | ||
| 701 | #print "$1 $2 $3 $4 $5 $6 $7\n"; | ||
| 702 | my $interface = $1; | ||
| 703 | my $severity = $2; | ||
| 704 | my $impact = $3; | ||
| 705 | my $day = $4; | ||
| 706 | my $time = $5; | ||
| 707 | my $alarm = $6; | ||
| 708 | my $year = $7; | ||
| 709 | my $date = "$7-$4"; | ||
| 710 | my $slot = undef; | ||
| 711 | my $subslot = undef; | ||
| 712 | my $port = undef; | ||
| 713 | my $fromfirststs = undef; | ||
| 714 | |||
| 715 | # Interface format HDXc is: | ||
| 716 | # Payload AID: | ||
| 717 | # <type> <shelf> <slot> <subslot> <port> <signal> <offset> | ||
| 718 | # signal seems to be always 1, not sure what this means. | ||
| 719 | # offset is STS channel | ||
| 720 | |||
| 721 | if ($interface =~ | ||
| 722 | /^\w+-\d+-(\d+)-(\d+)-(\d+)-(\d+)-(\d+)/) { | ||
| 723 | $slot = $1; | ||
| 724 | $subslot = $2; | ||
| 725 | $port = $3; | ||
| 726 | $fromfirststs = $5; | ||
| 727 | } elsif ($interface =~ | ||
| 728 | /^\w+-\d+-(\d+)-(\d+)-(\d+)-(\d+)/) { | ||
| 729 | $slot = $1; | ||
| 730 | $subslot = $2; | ||
| 731 | $port = $3; | ||
| 732 | } elsif ($interface =~ | ||
| 733 | /^\w+-\d+-(\d+)-(\d+)/) { | ||
| 734 | $slot = $1; | ||
| 735 | $port = $2; | ||
| 736 | } elsif ($interface =~ /^\w+-\d+-(\d+)/) { | ||
| 737 | $slot = $1; | ||
| 738 | } | ||
| 739 | $ainfo = { | ||
| 740 | interface => $interface, | ||
| 741 | slot => $slot, | ||
| 742 | subslot => $subslot, | ||
| 743 | port => $port, | ||
| 744 | fromfirststs => $fromfirststs, | ||
| 745 | severity => $severity, | ||
| 746 | impact => $impact, | ||
| 747 | date => $date, | ||
| 748 | time => $time, | ||
| 749 | alarm => $alarm | ||
| 750 | }; | ||
| 751 | push @result, $ainfo; | ||
| 752 | } | ||
| 753 | $n++; | ||
| 754 | } | ||
| 755 | return @result; | ||
| 756 | } elsif ($self->{'type'} eq "ONS15454") { | ||
| 757 | $socket->print("RTRV-ALM-ALL:::$self->{'ctag'};\n"); | ||
| 758 | my $resp = $self->{'resp_queue'}->dequeue(); | ||
| 759 | my $n = 0; | ||
| 760 | #print_resp($resp); | ||
| 761 | while (defined($resp->[$n])) { | ||
| 762 | # match FAC-3-1,G1000:MN,CARLOSS,NSA,11-23,16-43-47,,:\"Carrier Loss On The LAN\",G1000-4" | ||
| 763 | # FAC-12-1,OC19:MN,LO-RXPO,NSA,11-01,06-49-20,,:\"Equipment Low Rx power\",OC192" | ||
| 764 | if ($resp->[$n] =~ /"([^,]+),.*:(\w+),.*,(\w+),(\d+-\d+),(\d{1,2}-\d{1,2}-\d{1,2}),[^:]:\\"(.*)\\"/) { | ||
| 765 | # print "$1 $2 $3 $4 $5 $6 $7\n"; | ||
| 766 | my $interface = $1; | ||
| 767 | my $severity = $2; | ||
| 768 | my $impact = $3; | ||
| 769 | my $day = $4; | ||
| 770 | my $time = $5; | ||
| 771 | my $alarm = $6; | ||
| 772 | my $slot = undef; | ||
| 773 | my $subslot = undef; | ||
| 774 | my $port = undef; | ||
| 775 | my $fromfirststs = undef; | ||
| 776 | |||
| 777 | # ONS does not report the year so we have to create this by ourselfs | ||
| 778 | use Time::localtime; | ||
| 779 | use Date::Manip; | ||
| 780 | my $year = localtime->year() + 1900; | ||
| 781 | my $date = "$year-$day"; | ||
| 782 | # now we need to test if the date is not a day in the future | ||
| 783 | my $testdate = ParseDate("$date"); | ||
| 784 | my $todaydate = ParseDate("today"); | ||
| 785 | my $flag = Date_Cmp($testdate,$todaydate); | ||
| 786 | if ($flag<0) { | ||
| 787 | #print " date1 is earlier\n"; | ||
| 788 | } elsif ($flag==0) { | ||
| 789 | #print " the two dates are identical\n"; | ||
| 790 | } else { | ||
| 791 | #print " testdate is earlier, so adjust to last year\n"; | ||
| 792 | my $newdate = DateCalc("$testdate","-1 Year",\my $err); | ||
| 793 | $date = UnixDate("$newdate","%Y-%m-%d"); | ||
| 794 | #print "$testdate\n"; | ||
| 795 | } | ||
| 796 | |||
| 797 | # FAC-6-1 FAC-12-1 | ||
| 798 | if ($interface =~ /\w+-(\d+)-?(\d+)?-?(\d+)?/) { | ||
| 799 | $slot = $1; | ||
| 800 | if (defined $2){ | ||
| 801 | #print "port is $2\n"; | ||
| 802 | $port = $2; | ||
| 803 | } | ||
| 804 | if (defined $3){ | ||
| 805 | #print "beginsts is $3\n"; | ||
| 806 | $fromfirststs = $3; | ||
| 807 | } | ||
| 808 | } | ||
| 809 | $ainfo = { | ||
| 810 | interface => $interface, | ||
| 811 | slot => $slot, | ||
| 812 | subslot => $subslot, | ||
| 813 | port => $port, | ||
| 814 | fromfirststs => $fromfirststs, | ||
| 815 | severity => $severity, | ||
| 816 | impact => $impact, | ||
| 817 | date => $date, | ||
| 818 | time => $time, | ||
| 819 | alarm => $alarm | ||
| 820 | }; | ||
| 821 | push @result, $ainfo; | ||
| 822 | } | ||
| 823 | $n++; | ||
| 824 | } | ||
| 825 | return @result; | ||
| 826 | } | ||
| 827 | } | ||
| 828 | |||
| 829 | ########################################################################### | ||
| 830 | =pod | ||
| 831 | |||
| 832 | =head2 my @crossconnects = $tl1->get_crossconnects(); | ||
| 833 | |||
| 834 | Retrieve information about crossconnects on the TL1 device. The | ||
| 835 | information is returned as an array of hashes. Each entry in the | ||
| 836 | array is information about one crossconnect. The crossconnect | ||
| 837 | information consists of a hash with these keys: | ||
| 838 | |||
| 839 | =over | ||
| 840 | |||
| 841 | =item * | ||
| 842 | |||
| 843 | ckid: crossconnect ID | ||
| 844 | |||
| 845 | =item * | ||
| 846 | |||
| 847 | nr_timeslots: total amount of timeslots | ||
| 848 | |||
| 849 | =item * | ||
| 850 | |||
| 851 | from_slot: slot of "from" interface | ||
| 852 | |||
| 853 | =item * | ||
| 854 | |||
| 855 | from_subslot: subslot of "from" interface | ||
| 856 | |||
| 857 | =item * | ||
| 858 | |||
| 859 | from_port: port of "from" interface | ||
| 860 | |||
| 861 | =item * | ||
| 862 | |||
| 863 | from_first_ts: first timeslot on "from" interface | ||
| 864 | |||
| 865 | =item * | ||
| 866 | |||
| 867 | from_last_ts: last timeslot on "from" interface | ||
| 868 | |||
| 869 | =item * | ||
| 870 | |||
| 871 | to_slot: slot of "to" interface | ||
| 872 | |||
| 873 | =item * | ||
| 874 | |||
| 875 | to_subslot: subslot of "to" interface | ||
| 876 | |||
| 877 | =item * | ||
| 878 | |||
| 879 | to_port: port of "to" interface | ||
| 880 | |||
| 881 | =item * | ||
| 882 | |||
| 883 | to_first_ts: first timeslot on "to" interface | ||
| 884 | |||
| 885 | =item * | ||
| 886 | |||
| 887 | to_last_ts: last timeslot on "to" interface | ||
| 888 | |||
| 889 | =item * | ||
| 890 | |||
| 891 | swmate_slot: slot of "switchmate" interface | ||
| 892 | |||
| 893 | =item * | ||
| 894 | |||
| 895 | swmate_subslot: subslot of "switchmate" interface | ||
| 896 | |||
| 897 | =item * | ||
| 898 | |||
| 899 | swmate_port: port of "switchmate" interface | ||
| 900 | |||
| 901 | =item * | ||
| 902 | |||
| 903 | swmate_first_ts: first timeslot on "switchmate" interface | ||
| 904 | |||
| 905 | =item * | ||
| 906 | |||
| 907 | swmate_last_ts: last timeslot on "switchmate" interface | ||
| 908 | |||
| 909 | =back | ||
| 910 | |||
| 911 | |||
| 912 | =cut | ||
| 913 | |||
| 914 | ########################################################################### | ||
| 915 | # Retrieve information about crossconnects on the TL1 device. | ||
| 916 | ########################################################################### | ||
| 917 | sub get_crossconnects { | ||
| 918 | my ($self) = @_; | ||
| 919 | my %sts; | ||
| 920 | my $key; | ||
| 921 | my @result; | ||
| 922 | my $val; | ||
| 923 | my $socket = $self->{'socket'}; | ||
| 924 | $self->_verbose( 1, "retrieving circuits for $self->{'type'}\n" ); | ||
| 925 | if ($self->{'type'} eq "OME6500") { | ||
| 926 | $socket->print("RTRV-CRS-COUNT:::$self->{'ctag'}::;\n"); | ||
| 927 | my $resp = $self->{'resp_queue'}->dequeue(); | ||
| 928 | my $n = 0; | ||
| 929 | while (defined($resp->[$n])) { | ||
| 930 | # match "SHELF-1:STS3C,8" | ||
| 931 | # first we need to determine which crossconnects are there (sts3, sts24, sts192 etc..) | ||
| 932 | if ($resp->[$n] =~ /SHELF-\d+:(STS\w+),\d+/) { | ||
| 933 | $sts{$1} = 1; | ||
| 934 | } | ||
| 935 | $n++; | ||
| 936 | } | ||
| 937 | # now for each type of crossconnect retrieve the info | ||
| 938 | foreach $key (keys %sts) { | ||
| 939 | $socket->print("RTRV-CRS-".$key."::ALL:$self->{'ctag'}:::DISPLAY=PROV,CKTID=ALL;\n"); | ||
| 940 | my $resp = $self->{'resp_queue'}->dequeue(); | ||
| 941 | my $n = 0; | ||
| 942 | while (defined($resp->[$n])) { | ||
| 943 | # match "STS3C-1-9-1-1,STS3C-1-4-101-1:2WAY:CKTID=\"test\":" | ||
| 944 | # match "STS3C-1-9-1-19,STS3C-1-2-1-19:2WAYPR:SWMATE=STS3C-1-6-1-40,CKTID=\"Ah001A-Es001A_GE1(Artez) \":" | ||
| 945 | if ($resp->[$n] =~ /(STS\w+)-(\d+)-(\d+)-(\d+)-(\d+),STS\w+-(\d+)-(\d+)-(\d+)-(\d+):(2WAY:|2WAYPR:SWMATE=STS\w+)?-?(\d+)?-?(\d+)?-?(\d+)?-?(\d+)?.*CKTID=\\"([^:]+)\\":"/) { | ||
| 946 | |||
| 947 | my $xinfo = {}; | ||
| 948 | my $ckid = $15; | ||
| 949 | my $bandwidth = $1; | ||
| 950 | my $nr_timeslots = $bandwidth; | ||
| 951 | my $shelf = $2; | ||
| 952 | my $from_slot = $3; | ||
| 953 | my $from_subslot = ''; | ||
| 954 | my $from_port = $4; | ||
| 955 | my $from_first_ts; | ||
| 956 | my $from_last_ts; | ||
| 957 | my $to_slot = $7; | ||
| 958 | my $to_subslot = ''; | ||
| 959 | my $to_port = $8; | ||
| 960 | my $to_first_ts; | ||
| 961 | my $to_last_ts; | ||
| 962 | my $swmate_slot = $12; | ||
| 963 | my $swmate_subslot = ''; | ||
| 964 | my $swmate_port = $13; | ||
| 965 | my $swmate_first_ts; | ||
| 966 | my $swmate_last_ts; | ||
| 967 | |||
| 968 | $from_first_ts = $5; | ||
| 969 | |||
| 970 | $to_first_ts = $9; | ||
| 971 | |||
| 972 | if (defined $swmate_slot) { | ||
| 973 | $swmate_first_ts = $14; | ||
| 974 | $nr_timeslots =~ s/\D//g; | ||
| 975 | $swmate_last_ts = $swmate_first_ts + $nr_timeslots - 1; | ||
| 976 | } | ||
| 977 | |||
| 978 | $nr_timeslots =~ s/\D//g; | ||
| 979 | $from_last_ts = $from_first_ts + $nr_timeslots - 1; | ||
| 980 | $to_last_ts = $to_first_ts + $nr_timeslots - 1; | ||
| 981 | |||
| 982 | # catch undefined values | ||
| 983 | if (not defined $swmate_slot) { | ||
| 984 | $swmate_slot = ''; | ||
| 985 | } | ||
| 986 | if (not defined $swmate_port) { | ||
| 987 | $swmate_port = ''; | ||
| 988 | } | ||
| 989 | if (not defined $swmate_first_ts) { | ||
| 990 | $swmate_first_ts = ''; | ||
| 991 | } | ||
| 992 | if (not defined $swmate_last_ts) { | ||
| 993 | $swmate_last_ts = ''; | ||
| 994 | } | ||
| 995 | $xinfo = { | ||
| 996 | ckid => $ckid, | ||
| 997 | nr_timeslots => $nr_timeslots, | ||
| 998 | from_slot => $from_slot, | ||
| 999 | from_subslot => $from_subslot, | ||
| 1000 | from_port => $from_port, | ||
| 1001 | from_first_ts => $from_first_ts, | ||
| 1002 | from_last_ts => $from_last_ts, | ||
| 1003 | to_slot => $to_slot, | ||
| 1004 | to_subslot => $to_subslot, | ||
| 1005 | to_port => $to_port, | ||
| 1006 | to_first_ts => $to_first_ts, | ||
| 1007 | to_last_ts => $to_last_ts, | ||
| 1008 | swmate_slot => $swmate_slot, | ||
| 1009 | swmate_subslot => $swmate_subslot, | ||
| 1010 | swmate_port => $swmate_port, | ||
| 1011 | swmate_first_ts => $swmate_first_ts, | ||
| 1012 | swmate_last_ts => $swmate_last_ts | ||
| 1013 | }; | ||
| 1014 | push @result, $xinfo; | ||
| 1015 | } | ||
| 1016 | $n++; | ||
| 1017 | } | ||
| 1018 | } | ||
| 1019 | } elsif ($self->{'type'} eq "HDXc") { | ||
| 1020 | # Voor de HDXc | ||
| 1021 | $socket->print("RTRV-CRS-ALL:::$self->{'ctag'};\n"); | ||
| 1022 | my $resp = $self->{'resp_queue'}->dequeue(); | ||
| 1023 | my $n = 0; | ||
| 1024 | #print_resp($resp); | ||
| 1025 | while (defined($resp->[$n])) { | ||
| 1026 | # match "OC192-1-503-0-1-1-49,OC192-1-505-0-3-1-49:2WAY,STS-48C:PRIME=OSS,DISOWN=IDLE,CONNID=881,LABEL=\"SC05-Prague-Chicago-1\",AST=LOCKED:ACT" | ||
| 1027 | if ($resp->[$n] =~ /[^-]+-(\d+)-(\d\d\d)-(\d)-(\d)-\d{1,3}-(\d{1,3}),[^-]+-\d+-(\d\d\d)-(\d)-(\d)-\d{1,3}-(\d{1,3}):[^,]+,([^:]+):.*LABEL=\\\"(.*)\\\",/) { | ||
| 1028 | my $xinfo = {}; | ||
| 1029 | my $ckid = $11; | ||
| 1030 | my $bandwidth = $10; | ||
| 1031 | my $shelf = $1; | ||
| 1032 | my $from_slot = $2; | ||
| 1033 | my $from_subslot = $3; | ||
| 1034 | my $from_port = $4; | ||
| 1035 | my $from_first_ts = $5; | ||
| 1036 | my $to_slot = $6; | ||
| 1037 | my $to_subslot = $7; | ||
| 1038 | my $to_port = $8; | ||
| 1039 | my $to_first_ts = $9; | ||
| 1040 | my $nr_timeslots = $bandwidth; | ||
| 1041 | # \D remove all non digits | ||
| 1042 | $nr_timeslots =~ s/\D//g; | ||
| 1043 | my $from_last_ts = $from_first_ts + $nr_timeslots - 1; | ||
| 1044 | my $to_last_ts = $to_first_ts + $nr_timeslots - 1; | ||
| 1045 | |||
| 1046 | $xinfo = { | ||
| 1047 | ckid => $ckid, | ||
| 1048 | nr_timeslots => $nr_timeslots, | ||
| 1049 | from_slot => $from_slot, | ||
| 1050 | from_subslot => $from_subslot, | ||
| 1051 | from_port => $from_port, | ||
| 1052 | from_first_ts => $from_first_ts, | ||
| 1053 | from_last_ts => $from_last_ts, | ||
| 1054 | to_slot => $to_slot, | ||
| 1055 | to_subslot => $to_subslot, | ||
| 1056 | to_port => $to_port, | ||
| 1057 | to_first_ts => $to_first_ts, | ||
| 1058 | to_last_ts => $to_last_ts | ||
| 1059 | }; | ||
| 1060 | push @result, $xinfo; | ||
| 1061 | } | ||
| 1062 | $n++; | ||
| 1063 | } | ||
| 1064 | #print "$val\n" while defined($val = pop(@result)); | ||
| 1065 | } elsif ($self->{'type'} eq "ONS15454") { | ||
| 1066 | $socket->print("RTRV-CRS:::$self->{'ctag'};\n"); | ||
| 1067 | my $resp = $self->{'resp_queue'}->dequeue(); | ||
| 1068 | my $n = 0; | ||
| 1069 | #print_resp($resp); | ||
| 1070 | while (defined($resp->[$n])) { | ||
| 1071 | # match "STS-6-1-73,STS-12-1-97:2WAY,STS24C:CKTID=\"CERN-Vancouver 2 - TST\":IS-NR," | ||
| 1072 | if ($resp->[$n] =~ /"\w+-(\d+)-(\d+)-?(\d+)?,\w+-(\d+)-(\d+)-?(\d+)?:[^,]+,([^:]+):CKTID=\\\"(.*)\\\":/) { | ||
| 1073 | my $xinfo = {}; | ||
| 1074 | my $ckid = $8; | ||
| 1075 | my $bandwidth = $7; | ||
| 1076 | my $from_slot = $1; | ||
| 1077 | my $from_subslot = ''; | ||
| 1078 | my $from_port = $2; | ||
| 1079 | my $from_first_ts = $3; | ||
| 1080 | my $to_slot = $4; | ||
| 1081 | my $to_subslot = ''; | ||
| 1082 | my $to_port = $5; | ||
| 1083 | my $to_first_ts = $6; | ||
| 1084 | my $nr_timeslots; | ||
| 1085 | my $from_last_ts; | ||
| 1086 | my $to_last_ts; | ||
| 1087 | #calculate end sts, bandwidth is $7 from sts is $3 and $6 | ||
| 1088 | if (defined $3){ | ||
| 1089 | $nr_timeslots = $bandwidth; | ||
| 1090 | $nr_timeslots =~ s/\D//g; | ||
| 1091 | $from_last_ts = $from_first_ts + $nr_timeslots - 1; | ||
| 1092 | } | ||
| 1093 | if (defined $6){ | ||
| 1094 | $nr_timeslots = $bandwidth; | ||
| 1095 | $nr_timeslots =~ s/\D//g; | ||
| 1096 | $to_last_ts = $to_first_ts + $nr_timeslots - 1; | ||
| 1097 | } | ||
| 1098 | # catch undefined values | ||
| 1099 | if (not defined $from_first_ts) { | ||
| 1100 | $from_first_ts = ''; | ||
| 1101 | } | ||
| 1102 | if (not defined $from_last_ts) { | ||
| 1103 | $from_last_ts = ''; | ||
| 1104 | } | ||
| 1105 | if (not defined $to_first_ts) { | ||
| 1106 | $to_first_ts = ''; | ||
| 1107 | } | ||
| 1108 | if (not defined $to_last_ts) { | ||
| 1109 | $to_last_ts = ''; | ||
| 1110 | } | ||
| 1111 | |||
| 1112 | $xinfo = { | ||
| 1113 | ckid => $ckid, | ||
| 1114 | nr_timeslots => $nr_timeslots, | ||
| 1115 | from_slot => $from_slot, | ||
| 1116 | from_subslot => $from_subslot, | ||
| 1117 | from_port => $from_port, | ||
| 1118 | from_first_ts => $from_first_ts, | ||
| 1119 | from_last_ts => $from_last_ts, | ||
| 1120 | to_slot => $to_slot, | ||
| 1121 | to_subslot => $to_subslot, | ||
| 1122 | to_port => $to_port, | ||
| 1123 | to_first_ts => $to_first_ts, | ||
| 1124 | to_last_ts => $to_last_ts | ||
| 1125 | }; | ||
| 1126 | push @result, $xinfo; | ||
| 1127 | } | ||
| 1128 | $n++; | ||
| 1129 | } | ||
| 1130 | |||
| 1131 | } | ||
| 1132 | return @result; | ||
| 1133 | } | ||
| 1134 | |||
| 1135 | ########################################################################### | ||
| 1136 | =pod | ||
| 1137 | |||
| 1138 | =head2 my $trace = $tl1->get_section_trace(1, 12, 1); | ||
| 1139 | |||
| 1140 | Return the received section trace on the port given as arguments. | ||
| 1141 | The first argument is the shelf number, the second argument is | ||
| 1142 | the slot number and the third argument is the port number. This | ||
| 1143 | function returns a string. | ||
| 1144 | |||
| 1145 | =cut | ||
| 1146 | |||
| 1147 | ########################################################################### | ||
| 1148 | # Return the "section trace" string received on $shelf/$slot/$port | ||
| 1149 | ########################################################################### | ||
| 1150 | sub get_section_trace { | ||
| 1151 | my ($self, $shelf, $slot, $port) = @_; | ||
| 1152 | |||
| 1153 | my $speed; | ||
| 1154 | my $socket = $self->{'socket'}; | ||
| 1155 | my $cardtype = get_cardtype($self, $shelf, $slot); | ||
| 1156 | if (!defined($cardtype)) { | ||
| 1157 | return undef(); | ||
| 1158 | } | ||
| 1159 | if ($cardtype =~ /\d+xOC-(\d+)/) { | ||
| 1160 | $speed = $1; | ||
| 1161 | } else { | ||
| 1162 | return undef(); | ||
| 1163 | } | ||
| 1164 | $socket->print("RTRV-TRC-OC${speed}::" . | ||
| 1165 | "OC$speed-$shelf-$slot-${port}:$self->{'ctag'}::INCSTRC;\n"); | ||
| 1166 | my $resp = $self->{'resp_queue'}->dequeue(); | ||
| 1167 | my $n = 0; | ||
| 1168 | while (defined($resp->[$n])) { | ||
| 1169 | if ($resp->[$n] =~ /"OC\d+-\d+-\d+-\d+:\\"(.*?)\\"/) { | ||
| 1170 | my $trace = $1; | ||
| 1171 | return $trace; | ||
| 1172 | } | ||
| 1173 | $n++; | ||
| 1174 | } | ||
| 1175 | return(undef()); | ||
| 1176 | } | ||
| 1177 | |||
| 1178 | |||
| 1179 | sub check_resp { | ||
| 1180 | my $resp = shift; | ||
| 1181 | my $n = 0; | ||
| 1182 | while (defined($resp->[$n])) { | ||
| 1183 | if ($resp->[$n] =~ /M\s+\w+\s+(\w+)/) { | ||
| 1184 | return $1; | ||
| 1185 | } | ||
| 1186 | $n++; | ||
| 1187 | } | ||
| 1188 | } | ||
| 1189 | |||
| 1190 | ########################################################################### | ||
| 1191 | =pod | ||
| 1192 | |||
| 1193 | =head2 $tl1->print_resp($output); | ||
| 1194 | |||
| 1195 | This function prints the output returned by the cmd() function | ||
| 1196 | on STDOUT. | ||
| 1197 | |||
| 1198 | =cut | ||
| 1199 | |||
| 1200 | ########################################################################### | ||
| 1201 | # Prints the output returned by the cmd() function. | ||
| 1202 | ########################################################################### | ||
| 1203 | sub print_resp { | ||
| 1204 | my ( $self, $resp ) = @_; | ||
| 1205 | my $n = 0; | ||
| 1206 | while (defined($resp->[$n])) { | ||
| 1207 | print $n, " ", $resp->[$n], "\n"; | ||
| 1208 | $n++; | ||
| 1209 | } | ||
| 1210 | } | ||
| 1211 | |||
| 1212 | |||
| 1213 | ########################################################################### | ||
| 1214 | # Send TL1 command and forget response or use code referent to process response | ||
| 1215 | ########################################################################### | ||
| 1216 | sub async_cmd { | ||
| 1217 | my ( $self, $cmd ) = @_; | ||
| 1218 | $self->{'acmd_queue'}->enqueue($cmd); | ||
| 1219 | } | ||
| 1220 | |||
| 1221 | 1; | ||
| 1222 | |||
| 1223 | ########################################################################### | ||
| 1224 | =pod | ||
| 1225 | |||
| 1226 | =head1 AUTHORS | ||
| 1227 | |||
| 1228 | Ronald van der Pol, SARA High Performance Networking, Amsterdam, 2005 - 2008. | ||
| 1229 | |||
| 1230 | Andree Toonk, SARA High Performance Networking, Amsterdam, 2005 - 2007. | ||
| 1231 | |||
| 1232 | =head1 ACKNOWLEDGEMENTS | ||
| 1233 | |||
| 1234 | This work is funded by SURFnet and GigaPort: | ||
| 1235 | |||
| 1236 | http://www.surfnet.nl/ | ||
| 1237 | |||
| 1238 | http://www.gigaport.nl/ | ||
| 1239 | |||
| 1240 | This module is based on a module by Arien Vijn, AMS-IX B.V. (2005). | ||
| 1241 | |||
| 1242 | =head1 COPYRIGHT | ||
| 1243 | |||
| 1244 | +------------------------------------------------------------------+ | ||
| 1245 | | Licensed under the Apache License, Version 2.0 (the "License"); | | ||
| 1246 | | you may not use this file except in compliance with the License. | | ||
| 1247 | | You may obtain a copy of the License at | | ||
| 1248 | | | | ||
| 1249 | | http://www.apache.org/licenses/LICENSE-2.0 | | ||
| 1250 | | | | ||
| 1251 | | Unless required by applicable law or agreed to in writing, | | ||
| 1252 | | software distributed under the License is distributed on an | | ||
| 1253 | | "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, | | ||
| 1254 | | either express or implied. See the License for the specific | | ||
| 1255 | | language governing permissions and limitations under the | | ||
| 1256 | | License. | | ||
| 1257 | +------------------------------------------------------------------+ | ||
| 1258 | |||
| 1259 | =head1 REQUIRES | ||
| 1260 | |||
| 1261 | threads; | ||
| 1262 | |||
| 1263 | threads::shared; | ||
| 1264 | |||
| 1265 | Thread::Queue::Any; | ||
| 1266 | |||
| 1267 | Net::Telnet; | ||
| 1268 | |||
| 1269 | Time::localtime; | ||
| 1270 | |||
| 1271 | Date::Manip; | ||
| 1272 | |||
| 1273 | =head1 RELEASED | ||
| 1274 | |||
| 1275 | December 2008 | ||
| 1276 | |||
| 1277 | =cut |