Source of file api.ponbdcom.php
Size: 20,716 Bytes - Last Modified: 2026-08-12T15:26:42+03:00
/tmp/current_snapshot/api/libs/api.ponbdcom.php
| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460 | <?php/** * OLT BDCOM 36xx/33xx or Eltex and Extralink hardware abstraction layer */class PONBdcom extends PONProto { /** * Contains system UbillingConfig object instance * * @var object */protected $ubConfig = ''; /** * Contains flag that enables UNI port oper status polling * * @var bool */protected $onuUniStatusEnabled = false; /** * Receives, preprocess and stores all required data from BDCOM 36xx/33xx or Eltex OLT device * * @return void */public function collect() { global $ubillingConfig; $this->ubConfig = $ubillingConfig; $this->onuUniStatusEnabled = $this->ubConfig->getAlterParam('PON_ONU_UNI_STATUS_ENABLED', false); $oltModelId = $this->oltParameters['MODELID']; $oltid = $this->oltParameters['ID']; $oltIp = $this->oltParameters['IP']; $oltCommunity = $this->oltParameters['COMMUNITY']; $oltNoFDBQ = $this->oltParameters['NOFDB']; $sigIndexOID = $this->snmpTemplates[$oltModelId]['signal']['SIGINDEX']; $sigIndex = $this->snmp->walk($oltIp . ':' . self::SNMPPORT, $oltCommunity, $sigIndexOID, self::SNMPCACHE); $sigIndex = str_replace($sigIndexOID . '.', '', $sigIndex); $sigIndex = str_replace($this->snmpTemplates[$oltModelId]['signal']['SIGVALUE'], '', $sigIndex); $sigIndex = explodeRows($sigIndex); $ifaceCustDescrIndex = array(); // ONU distance polling for bdcom devices if (isset($this->snmpTemplates[$oltModelId]['misc'])) { if (isset($this->snmpTemplates[$oltModelId]['misc']['DISTINDEX'])) { if (!empty($this->snmpTemplates[$oltModelId]['misc']['DISTINDEX'])) { $distIndexOid = $this->snmpTemplates[$oltModelId]['misc']['DISTINDEX']; $distIndex = $this->snmp->walk($oltIp . ':' . self::SNMPPORT, $oltCommunity, $distIndexOid, self::SNMPCACHE); $distIndex = str_replace($distIndexOid . '.', '', $distIndex); $distIndex = str_replace($this->snmpTemplates[$oltModelId]['misc']['DISTVALUE'], '', $distIndex); $distIndex = explodeRows($distIndex); $onuIndexOid = $this->snmpTemplates[$oltModelId]['misc']['ONUINDEX']; $onuIndex = $this->snmp->walk($oltIp . ':' . self::SNMPPORT, $oltCommunity, $onuIndexOid, self::SNMPCACHE); $onuIndex = str_replace($onuIndexOid . '.', '', $onuIndex); $onuIndex = str_replace($this->snmpTemplates[$oltModelId]['misc']['ONUVALUE'], '', $onuIndex); $onuIndex = explodeRows($onuIndex); if (isset($this->snmpTemplates[$oltModelId]['misc']['DEREGREASON'])) { $deregIndexOid = $this->snmpTemplates[$oltModelId]['misc']['DEREGREASON']; $deregIndex = $this->snmp->walk($oltIp . ':' . self::SNMPPORT, $oltCommunity, $deregIndexOid, self::SNMPCACHE); $deregIndex = str_replace($deregIndexOid . '.', '', $deregIndex); $deregIndex = str_replace($this->snmpTemplates[$oltModelId]['misc']['DEREGVALUE'], '', $deregIndex); $deregIndex = explodeRows($deregIndex); } $intIndexOid = $this->snmpTemplates[$oltModelId]['misc']['INTERFACEINDEX']; $intIndex = $this->snmp->walk($oltIp . ':' . self::SNMPPORT, $oltCommunity, $intIndexOid, self::SNMPCACHE); $intIndex = str_replace($intIndexOid . '.', '', $intIndex); $intIndex = str_replace($this->snmpTemplates[$oltModelId]['misc']['INTERFACEVALUE'], '', $intIndex); $intIndex = explodeRows($intIndex); if (!$oltNoFDBQ) { $FDBIndexOid = $this->snmpTemplates[$oltModelId]['misc']['FDBINDEX']; $FDBIndex = $this->snmp->walk($oltIp . ':' . self::SNMPPORT, $oltCommunity, $FDBIndexOid, self::SNMPCACHE); $FDBIndex = str_replace($FDBIndexOid . '.', '', $FDBIndex); $FDBIndex = explodeRows($FDBIndex); } } } if (isset($this->snmpTemplates[$oltModelId]['misc']['IFACECUSTOMDESCR'])) { $ifaceCustDescrIndexOID = $this->snmpTemplates[$oltModelId]['misc']['IFACECUSTOMDESCR']; $ifaceCustDescrIndex = $this->snmp->walk($oltIp . ':' . self::SNMPPORT, $oltCommunity, $ifaceCustDescrIndexOID, self::SNMPCACHE); $ifaceCustDescrIndex = str_replace($ifaceCustDescrIndexOID . '.', '', $ifaceCustDescrIndex); $ifaceCustDescrIndex = str_replace(array($this->snmpTemplates[$oltModelId]['misc']['INTERFACEVALUE'], '"'), '', $ifaceCustDescrIndex); $ifaceCustDescrIndex = explodeRows($ifaceCustDescrIndex); } // Get UniOperStatusIndex if (isset($this->snmpTemplates[$oltModelId]['misc']['UNIOPERSTATUS']) and $this->onuUniStatusEnabled) { $uniOperStatusIndexOID = $this->snmpTemplates[$oltModelId]['misc']['UNIOPERSTATUS']; $uniOperStatusIndex = $this->snmp->walk($oltIp . ':' . self::SNMPPORT, $oltCommunity, $uniOperStatusIndexOID, self::SNMPCACHE); $uniOperStatusIndex = str_replace($uniOperStatusIndexOID . '.', '', $uniOperStatusIndex); $uniOperStatusIndex = str_replace(array($this->snmpTemplates[$oltModelId]['misc']['UNIOPERSTATUSVALUE'], '"'), '', $uniOperStatusIndex); $uniOperStatusIndex = explodeRows($uniOperStatusIndex); } } // getting other system data from OLT if (isset($this->snmpTemplates[$oltModelId]['system'])) { //OLT uptime if (isset($this->snmpTemplates[$oltModelId]['system']['UPTIME'])) { $uptimeIndexOid = $this->snmpTemplates[$oltModelId]['system']['UPTIME']; $oltSystemUptimeRaw = $this->snmp->walk($oltIp . ':' . self::SNMPPORT, $oltCommunity, $uptimeIndexOid, self::SNMPCACHE); $this->uptimeParse($oltid, $oltSystemUptimeRaw); } //OLT temperature if (isset($this->snmpTemplates[$oltModelId]['system']['TEMPERATURE'])) { $temperatureIndexOid = $this->snmpTemplates[$oltModelId]['system']['TEMPERATURE']; $oltTemperatureRaw = $this->snmp->walk($oltIp . ':' . self::SNMPPORT, $oltCommunity, $temperatureIndexOid, self::SNMPCACHE); $this->temperatureParse($oltid, $oltTemperatureRaw); } } // getting MAC index. $macIndexOID = $this->snmpTemplates[$oltModelId]['signal']['MACINDEX']; $macIndex = $this->snmp->walk($oltIp . ':' . self::SNMPPORT, $oltCommunity, $macIndexOID, self::SNMPCACHE); $macIndex = str_replace($macIndexOID . '.', '', $macIndex); $macIndex = str_replace($this->snmpTemplates[$oltModelId]['signal']['MACVALUE'], '', $macIndex); $macIndex = explodeRows($macIndex); $this->signalParse($oltid, $sigIndex, $macIndex, $this->snmpTemplates[$oltModelId]['signal']); // Start proccesing for get ONU id and MAC $this->onuMacProcessing($macIndex); $this->onuDevIndexProcessing($onuIndex); /** * This is here because BDCOM is BDCOM and another SNMP queries cant be processed after MACINDEX query in some cases. */if (isset($this->snmpTemplates[$oltModelId]['misc'])) { if (isset($this->snmpTemplates[$oltModelId]['misc']['DISTINDEX'])) { if (!empty($this->snmpTemplates[$oltModelId]['misc']['DISTINDEX'])) { // processing distance data $this->distanceParse($oltid, $distIndex, $onuIndex); // processing interfaces data and interface description data $this->interfaceParseBd($intIndex, $ifaceCustDescrIndex); // processing FDB data if (!$oltNoFDBQ) { if (isset($this->snmpTemplates[$oltModelId]['misc']['FDBMODE']) and $this->snmpTemplates[$oltModelId]['misc']['FDBMODE'] == 'FIRMWARE-F') { $this->FDBParseBdFirmwareF($FDBIndex, $oltModelId); } else { $this->FDBParseBd($FDBIndex, $oltModelId); } } // processing last dereg reason data if (isset($this->snmpTemplates[$oltModelId]['misc']['DEREGREASON'])) { $this->lastDeregParseBd($deregIndex); } // processing UniOperStauts if (isset($this->snmpTemplates[$oltModelId]['misc']['UNIOPERSTATUS']) and $this->onuUniStatusEnabled) { $this->uniParseBd($uniOperStatusIndex); } } } } } /** * Parses & stores in cache OLT ONU interfaces * * @param array $intIndex * @param array $ifaceCustDescrRaw * * @return void */protected function interfaceParseBd($intIndex, $ifaceCustDescrRaw = array()) { $intTmp = array(); $result = array(); $processIfaceCustDescr = ! empty($ifaceCustDescrRaw); $ifaceCustDescrIdx = array(); $ifaceCustDescrArr = array(); // olt iface descr extraction if ($processIfaceCustDescr) { foreach ($ifaceCustDescrRaw as $io => $each) { if (empty($each)) { continue; } $ifDescr = explode('=', str_replace(array(" ", "\t", "\n", "\r", "\0", "\x0B"), '', $each)); if ((empty($ifDescr[0]) && empty($ifDescr[1])) || intval($ifDescr[0]) < 7) { continue; } if ($ifDescr[0] > 10) { break; } $ifaceCustDescrIdx[$ifDescr[0] - 6] = $ifDescr[1]; } } // interface index preprocessing if ((! empty($intIndex)) and ( ! empty($this->macIndexProcessed))) { foreach ($intIndex as $io => $eachint) { $line = explode('=', $eachint); // interface is present if (isset($line[1])) { $interfaceRaw = trim($line[1]); // interface $devIndex = trim($line[0]); // device index $intTmp[$devIndex] = $interfaceRaw; } } // storing results foreach ($this->macIndexProcessed as $devId => $eachMac) { if (isset($intTmp[$devId])) { $interface = $intTmp[$devId]; $result[$eachMac] = $interface; $cleanIface = strstr($interface, ':', true); $tPONIfaceNum = substr($cleanIface, -1, 1); if ($processIfaceCustDescr && !isset($ifaceCustDescrArr[$cleanIface]) && array_key_exists($tPONIfaceNum, $ifaceCustDescrIdx)) { $ifaceCustDescrArr[$cleanIface] = $ifaceCustDescrIdx[$tPONIfaceNum]; } } } //saving interfaces cache as mac=>interface name $this->olt->writeInterfaces($result); //saving interfaces custom descriptions as interface=>desctription $this->olt->writeInterfacesDescriptions($ifaceCustDescrArr); } } /** * Parses & stores in cache OLT ONU interfaces * * @param array $FDBIndex * @param array $oltModelId * * @return void */protected function FDBParseBd($FDBIndex, $oltModelId) { $FDBTmp = array(); $result = array(); // fdb index preprocessing if ((! empty($FDBIndex)) and ( ! empty($this->macIndexProcessed))) { foreach ($FDBIndex as $io => $eachfdb) { if (preg_match('/' . $this->snmpTemplates[$oltModelId]['misc']['FDBVALUE'] . '/', $eachfdb)) { $eachfdb = str_replace($this->snmpTemplates[$oltModelId]['misc']['FDBVALUE'], '', $eachfdb); $line = explode('=', $eachfdb); // fdb is present if (isset($line[1])) { $FDBRaw = trim($line[1]); // FDB $devOID = trim($line[0]); // FDB last OID $devline = explode('.', $devOID); $devIndex = trim($devline[0]); // FDB index $FDBvlan = trim($devline[1]); // Vlan $FDBnum = trim($devline[7]); // Count number of MAC $FDBRaw = str_replace(' ', ':', $FDBRaw); $FDBRaw = strtolower($FDBRaw); $FDBTmp[$devIndex][$FDBnum]['mac'] = $FDBRaw; $FDBTmp[$devIndex][$FDBnum]['vlan'] = $FDBvlan; } } } // storing results foreach ($this->macIndexProcessed as $devId => $eachMac) { if (isset($FDBTmp[$devId])) { $fdb = $FDBTmp[$devId]; $result[$eachMac] = $fdb; } } //saving FDB cache $this->olt->writeFdb($result); } } /** * Parses & stores in cache OLT FDB * * @param array $FDBIndex * @param array $oltModelId * * @return void */protected function FDBParseBdFirmwareF($FDBIndex, $oltModelId) { $TmpArr = array(); $FDBTmp = array(); $result = array(); //fdb index preprocessing if ((! empty($FDBIndex)) and ( ! empty($this->macIndexProcessed))) { foreach ($FDBIndex as $io => $eachfdbRaw) { if (preg_match('/' . $this->snmpTemplates[$oltModelId]['misc']['FDBVALUE'] . '|INTEGER:/', $eachfdbRaw)) { $eachfdbRaw = str_replace(array($this->snmpTemplates[$oltModelId]['misc']['FDBVALUE'], 'INTEGER:'), '', $eachfdbRaw); $line = explode('=', $eachfdbRaw); //fdb is present if (isset($line[1])) { $devOID = trim($line[0]); // FDB last OID $lineRaw = trim($line[1]); // FDB $devline = explode('.', $devOID); $FDBvlan = trim($devline[1]); // Vlan $FDBnum = trim($devline[7]); // Count number of MAC if (preg_match('/^1/', $devOID)) { $FDBRaw = str_replace(' ', ':', $lineRaw); $FDBRaw = strtolower($FDBRaw); $TmpArr[$devOID]['mac'] = $FDBRaw; $TmpArr[$devOID]['vlan'] = $FDBvlan; $TmpArr[$devOID]['FDBnum'] = $FDBnum; } elseif (preg_match('/^2/', $devOID)) { $devIndexOid = substr_replace($devOID, '1', 0, 1); $TmpArr[$devIndexOid]['index'] = $lineRaw; } else { continue; } } } } if (!empty($TmpArr)) { // Crete tmp Ubilling PON FDB array foreach ($TmpArr as $io => $each) { if (count($each) == 4) { $FDBTmp[$each['index']][$each['FDBnum']]['mac'] = $each['mac']; $FDBTmp[$each['index']][$each['FDBnum']]['vlan'] = $each['vlan']; } } } //storing results foreach ($this->macIndexProcessed as $devId => $eachMac) { if (isset($FDBTmp[$devId])) { $fdb = $FDBTmp[$devId]; $result[$eachMac] = $fdb; } } //saving FDB cache $this->olt->writeFDB($result); } } /** * Parses & stores in cache OLT ONU dereg reaesons * * @param array $distIndex * * @return void */protected function lastDeregParseBd($deregIndex) { $result = array(); //dereg index preprocessing if ((!empty($deregIndex)) and ( !empty($this->onuDevIndexProcessed))) { foreach ($deregIndex as $io => $eachdereg) { $line = explode('=', $eachdereg); //dereg is present if (isset($line[1])) { $deregRaw = trim($line[1]); // dereg $devIndex = trim($line[0]); // device index switch ($deregRaw) { case 2: $TxtColor = '"#00B20E"'; $tmpONULastDeregReasonStr = 'Normal'; break; case 3: $TxtColor = '"#F80000"'; $tmpONULastDeregReasonStr = 'MPCP down'; break; case 4: $TxtColor = '"#F80000"'; $tmpONULastDeregReasonStr = 'OAM down'; break; case 5: $TxtColor = '"#6500FF"'; $tmpONULastDeregReasonStr = 'Firmware download'; break; case 6: $TxtColor = '"#F80000"'; $tmpONULastDeregReasonStr = 'Illegal MAC'; break; case 7: $TxtColor = '"#FF4400"'; $tmpONULastDeregReasonStr = 'LLID admin down'; break; case 8: $TxtColor = '"#F80000"'; $tmpONULastDeregReasonStr = 'Wire down'; break; case 9: $TxtColor = '"#6500FF"'; $tmpONULastDeregReasonStr = 'Power off'; break; default: $TxtColor = '"#000000"'; $tmpONULastDeregReasonStr = 'Unknown'; break; } $tmpONULastDeregReasonStr = wf_tag('font', false, '', 'color=' . $TxtColor . '') . $tmpONULastDeregReasonStr . wf_tag('font', true); if (isset($this->onuDevIndexProcessed[$devIndex])) { $result[$this->onuDevIndexProcessed[$devIndex]] = $tmpONULastDeregReasonStr; } } } //saving dereg reasons cache $this->olt->writeDeregs($result); } } /** * Performs UNI port oper status preprocessing for index array and stores it into cache * * @param $uniOperStatusIndex * * @return void */protected function uniParseBd($uniOperStatusIndex) { $result = array(); if (! empty($this->macIndexProcessed) and ! empty($uniOperStatusIndex)) { foreach ($uniOperStatusIndex as $io => $eachRow) { $line = explode('=', $eachRow); if (empty($line[0]) || empty($line[1])) { continue; } // LLID + ether port index $tmpLLIDEtherIdx = trim($line[0]); $tmpLLIDEtherIdx = ltrim($tmpLLIDEtherIdx, '.'); $tmpLLIDEtherIdxLen = strlen($tmpLLIDEtherIdx); // ehter port index $tmpEtherIdx = strrchr($tmpLLIDEtherIdx, '.'); $tmpEtherIdxLen = strlen($tmpEtherIdx); $tmpEtherIdx = 'eth' . trim($tmpEtherIdx, '.'); //LLID $tmpONUPortLLID = substr($tmpLLIDEtherIdx, 0, $tmpLLIDEtherIdxLen - $tmpEtherIdxLen); $tmpUniStatus = trim($line[1]); $tmpUniStatus = ($tmpUniStatus == 1) ? 1 : 0; if (isset($this->macIndexProcessed[$tmpONUPortLLID])) { $result[$this->macIndexProcessed[$tmpONUPortLLID]][$tmpEtherIdx] = $tmpUniStatus; } } //saving UniOperStats $this->olt->writeUniOperStats($result); } } } |