ZteOnuScanCommand.php 3.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. <?php
  2. namespace ZteBundle\Command;
  3. use BaseStatsBundle\Command\BaseCommand;
  4. use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
  5. use Symfony\Component\Console\Input\InputOption;
  6. use Symfony\Component\Console\Input\InputInterface;
  7. use Symfony\Component\Console\Output\OutputInterface;
  8. use ZteBundle\SNMP\SNMP as SNMP;
  9. //use RedisBundle\Services\RedisService;
  10. class ZteOnuScanCommand extends BaseCommand
  11. {
  12. protected function configure()
  13. {
  14. $this
  15. ->setName('zte:onu:scan')
  16. ->setDescription('Escanear OLT para obtener ONUs')
  17. ->setHelp('Se requieren parámetros para poder realizar la correcta consulta. El comando requiere Redis.')
  18. ->setDefinition(array(
  19. new InputOption('olt-device-id', null, InputOption::VALUE_OPTIONAL, "DeviceId de la OLT",1),
  20. new InputOption('olt-server-id', null, InputOption::VALUE_OPTIONAL, "ServerDevice de la OLT",1),
  21. new InputOption('olt-ip', false, InputOption::VALUE_OPTIONAL, "IP de la OLT"),
  22. new InputOption('olt-community', false, InputOption::VALUE_OPTIONAL, "COMMUNITY de la OLT"),
  23. new InputOption('olt-snmp-library', false, InputOption::VALUE_OPTIONAL, "Versión de librería SNMP")
  24. ))
  25. ;
  26. }
  27. /**
  28. * @param InputInterface $input
  29. * @param OutputInterface $output
  30. */
  31. protected function execute(InputInterface $input, OutputInterface $output)
  32. {
  33. parent::execute($input, $output);
  34. $key_olt_scan = "olt_scan_{$this->d_s}";
  35. $key_olt_pons = "olt_scan_pons_{$this->d_s}";
  36. $inicio = microtime(true);
  37. $SNMP = new SNMP($this->oltIp, $this->oltCommunity);
  38. $library = "use".$this->oltSnmpLibrary;
  39. $this->apiSNMP = $SNMP->$library();
  40. $portCached = $this->getData($key_olt_pons, true);
  41. if(empty($portCached)) {
  42. $this->output->writeln("Se requiere {$key_olt_pons}.");
  43. $this->removeLock($this->flag);
  44. return true;
  45. }
  46. $dataCached = array();
  47. $serialNumbers = $this->getSNMP("onuSerialNumber","onuScan");
  48. // array [4194312192.1] => 485754430011D168
  49. // portIndex.onuIndex => serialNumber Hexa [48 57 54 43] 0011D168 => HWTC0011D168 (parecido al PonSerialNumber)
  50. $countOnus = 0;
  51. foreach($serialNumbers as $index => $hexSerialNumber) {
  52. $vendoId = $this->hex2str(substr($hexSerialNumber,0,8));
  53. $rest = substr($hexSerialNumber,8);
  54. $sn = strtolower($vendoId.$rest);
  55. $portOnu = explode(".",$index);
  56. if(count($portOnu) != 2) continue;
  57. $portIndex = $portOnu[0];
  58. $onuId = $portOnu[1];
  59. $countOnus++;
  60. if(isset($portCached[$portIndex])) {
  61. $p = $portCached[$portIndex];
  62. $data = $p;
  63. $data['onuId'] = $onuId;
  64. $data['serialNumber'] = $sn;
  65. $data['hexaSerialNumber'] = $hexSerialNumber;
  66. $data['ponport'] = "{$p['ponPort']}/{$onuId}";
  67. $dataCached[$index] = $data;
  68. }
  69. }
  70. $this->setData($key_olt_scan, $dataCached, true);
  71. /* Fin de bloqueo */
  72. $this->removeLock($this->flag);
  73. $fin = microtime(true);
  74. $time = $fin - $inicio;
  75. $this->output->writeln("Tiempo: $time segundos / Cantidad ONUs: {$countOnus}");
  76. }
  77. }