setName('furukawa:onu:scan') ->setDescription('Escanear OLT para obtener ONUs') ->setHelp('Se requieren parámetros para poder realizar la correcta consulta. El comando requiere Redis.') ->setDefinition(array( new InputOption('olt-device-id', null, InputOption::VALUE_OPTIONAL, "DeviceId de la OLT",1), new InputOption('olt-server-id', null, InputOption::VALUE_OPTIONAL, "ServerDevice de la OLT",1), new InputOption('olt-ip', false, InputOption::VALUE_OPTIONAL, "IP de la OLT"), new InputOption('olt-community', false, InputOption::VALUE_OPTIONAL, "COMMUNITY de la OLT"), new InputOption('olt-snmp-library', false, InputOption::VALUE_OPTIONAL, "Versión de librería SNMP") )) ; } /** * @param InputInterface $input * @param OutputInterface $output */ protected function execute(InputInterface $input, OutputInterface $output) { parent::execute($input, $output); $key_olt_scan = "olt_scan_{$this->d_s}"; $key_olt_pons = "olt_scan_pons_{$this->d_s}"; $inicio = microtime(true); $SNMP = new SNMP($this->oltIp, $this->oltCommunity); $library = "use".$this->oltSnmpLibrary; $this->apiSNMP = $SNMP->$library(); $portCached = $this->getData($key_olt_pons, true); if(empty($portCached)) { $this->output->writeln("Se requiere {$key_olt_pons}."); $this->removeLock($this->flag); return true; } $dataCached = array(); $serialNumbers = $this->getSNMP("onuSerialNumber","onuScan"); // array [4194312192.1] => 485754430011D168 // portIndex.onuIndex => serialNumber Hexa [48 57 54 43] 0011D168 => HWTC0011D168 (parecido al PonSerialNumber) $countOnus = 0; $current_charset = "ISO-8859-15//IGNORE"; foreach($serialNumbers as $index => $hexSerialNumber) { $vendoId = $this->hex2str(substr($hexSerialNumber,0,8)); $rest = substr($hexSerialNumber,8); $sn = strtolower($vendoId.$rest); $portOnu = explode(".",$index); if(count($portOnu) != 2) continue; $portIndex = $portOnu[0]; $onuId = $portOnu[1]; $countOnus++; if(isset($portCached[$portIndex])) { $p = $portCached[$portIndex]; $data = $p; $data['onuId'] = $onuId; $data['serialNumber'] = iconv("UTF-8",$current_charset,$sn); $data['hexaSerialNumber'] = iconv("UTF-8",$current_charset,$hexSerialNumber); $data['ponport'] = "{$p['ponPort']}/{$onuId}"; $dataCached[$index] = $data; } } $this->setData($key_olt_scan, $dataCached, true); /* Fin de bloqueo */ $this->removeLock($this->flag); $fin = microtime(true); $time = $fin - $inicio; $this->output->writeln("Tiempo: $time segundos / Cantidad ONUs: {$countOnus}"); } }