Source of file api.ponzte.php
Size: 41,835 Bytes - Last Modified: 2024-04-27T15:26:05+03:00
/tmp/current_snapshot/api/libs/api.ponzte.php
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269 | <?php /** * ZTE-like PON devices management */ class PonZte { CONST DESC_PONTYPE = 1; CONST DESC_SHELF = 2; CONST DESC_SLOT = 3; CONST DESC_OLT = 4; CONST DESC_ONU = 5; /** * Contains current HAL instance OLT parameters * * @var array */ protected $oltParameters = array(); /** * Array for checking ports count for EPON cards * * @var array */ protected $eponCards = array(); /** * Array for checking ports count for GPON cards * * @var array */ protected $gponCards = array(); /** * Contains snmp helper object * * @var object */ protected $snmp; /** * Contains OLTData * * @var object */ protected $olt = ''; /** * Contains all OLTs snmp tmplates * * @var array */ protected $snmpTemplates = array(); /** * Contains all OLTs devices with proper snmp config * * @var array */ protected $allOltSnmp = array(); /** * Contains all olt models * * @var array */ protected $allOltModels = array(); /** * Contains all OLTs devices * * @var array */ protected $allOltDevices = array(); /** * Current OLT switch id * * @var int */ protected $oltid = 0; /** * Current OLT IP with SNMP port * * @var string */ protected $oltIp = ''; /** * Current OLT IP with SNMP port * * @var string */ protected $oltFullAddress = ''; /** * Current OLT snmp community * * @var string */ protected $oltCommunity = ''; /** * Take only needed SNMP template for current OLT. * * @var array */ protected $currentSnmpTemplate; /** * Contains all ONUs MAC addresses. * * @var array */ protected $macIndex = array(); /** * Contains all signals * * @var array */ protected $sigIndex = array(); /** * Contains all interface names => ONU ID * * @var array */ protected $intIndex = array(); /** * Contains FDB * * @var array */ protected $fdbIndex = array(); /** * Contains type EPON or GPON. * * @var string */ public $ponType = ''; /** * Contains all serial numbers => index * * @var array */ protected $snIndex = array(); /** * Contains distances for ONTs * * @var array */ protected $distanceIndex = array(); /** * Creates new PON poller/parser proto * * @param array $oltParameters * @param array $snmpTemplates */ public function __construct($oltParameters, $snmpTemplates) { $this->oltParameters = $oltParameters; //unpacking OLT settings $oltModelId = $this->oltParameters['MODELID']; $oltid = $this->oltParameters['ID']; $oltIp = $this->oltParameters['IP']; $oltCommunity = $this->oltParameters['COMMUNITY']; $oltNoFDBQ = $this->oltParameters['NOFDB']; $ponType = $this->oltParameters['TYPE']; //setting some object properties $this->oltid = $oltid; $this->oltCommunity = $oltCommunity; $this->oltIp = $oltIp; $this->oltFullAddress = $oltIp . ':' . PONizer::SNMPPORT; $this->ponType = $ponType; $this->initSNMP(); $this->initOltAttractor(); $this->loadOltDevices(); $this->loadOltModels(); $this->snmpTemplates = $snmpTemplates; $this->currentSnmpTemplate = $this->snmpTemplates[$oltModelId]; $this->eponCards = OnuRegister::allEponCards(); $this->gponCards = OnuRegister::allGponCards(); if (!isset($this->currentSnmpTemplate['signal']['POLLTYPE'])) { $this->currentSnmpTemplate['signal']['POLLTYPE'] = 'default'; } if (!isset($this->currentSnmpTemplate['signal']['SIGNALTYPE'])) { $this->currentSnmpTemplate['signal']['SIGNALTYPE'] = 'OLTRX'; } } /** * Creates single instance of SNMPHelper object * * @return void */ protected function initSNMP() { $this->snmp = new SNMPHelper(); } /** * Inits current OLT data abstraction layer for further usage */ protected function initOltAttractor() { $this->olt = new OLTAttractor($this->oltParameters['ID']); } /** * Loads all available snmp models data into private data property * * @return void */ protected function loadOltModels() { $rawModels = zb_SwitchModelsGetAll(); if (!empty($rawModels)) { foreach ($rawModels as $io => $each) { $this->allOltModels[$each['id']]['modelname'] = $each['modelname']; $this->allOltModels[$each['id']]['snmptemplate'] = $each['snmptemplate']; $this->allOltModels[$each['id']]['ports'] = $each['ports']; } } } /** * Loads all available devices set as OLT * * @return void */ protected function loadOltDevices() { $query = "SELECT `id`,`ip`,`location`,`snmp`,`modelid` from `switches` WHERE `desc` LIKE '%OLT%';"; $raw = simple_queryall($query); if (!empty($raw)) { foreach ($raw as $io => $each) { $this->allOltDevices[$each['id']] = $each['ip'] . ' - ' . $each['location']; if (!empty($each['snmp'])) { $this->allOltSnmp[$each['id']]['community'] = $each['snmp']; $this->allOltSnmp[$each['id']]['modelid'] = $each['modelid']; $this->allOltSnmp[$each['id']]['ip'] = $each['ip']; } } } } //wrappers /** * Wrapper around $this->snmp->walk method and explodeRows function to get less string length. * * @param string $oid * * @return array */ protected function snmpwalk($oid) { $data = $this->snmp->walk($this->oltFullAddress, $this->oltCommunity, $oid, PONizer::SNMPCACHE); return(explodeRows(trim($data))); } /** * Converts hex to string value * * @param string $hex * @return string */ protected function hexToString($hex) { return pack('H*', $hex); } /** * Remove oid + dot from string * * @param string $oid * @param string $str * * @return string */ protected function strRemoveOidWithDot($oid, $str) { return(trim(str_replace($oid . ".", '', $str))); } /** * Wrapper around str_replace to make code more pretty * * @param string $search * @param string $str * * @return string */ protected function strRemove($search, $str) { return(trim(str_replace($search, '', $str))); } //processing functions /** * Epon signals preprocessing * * @return array */ protected function signalIndexProcessing() { foreach ($this->sigIndex as $devIndex => &$eachsig) { if ($eachsig == $this->currentSnmpTemplate['signal']['DOWNVALUE']) { $eachsig = 'Offline'; } if (isset($this->currentSnmpTemplate['signal']['DOWNVALUE2'])) { if ($eachsig == $this->currentSnmpTemplate['signal']['DOWNVALUE2']) { $eachsig = 'Offline'; } } if (isset($this->currentSnmpTemplate['signal']['DOWNVALUE3'])) { if ($eachsig == $this->currentSnmpTemplate['signal']['DOWNVALUE3']) { $eachsig = 'Offline'; } } if ($eachsig != 'Offline') { $eachsig = str_replace('"', '', $eachsig); if ($this->currentSnmpTemplate['signal']['OFFSETMODE'] == 'div') { if ($this->currentSnmpTemplate['signal']['OFFSET']) { $div = $this->currentSnmpTemplate['signal']['OFFSET']; if ($this->currentSnmpTemplate['signal']['SIGNALTYPE'] == 'ONURX') { $div = $this->currentSnmpTemplate['signal']['ONURXOFFSET']; $exploDevIndex = explode('.', $devIndex); $devIndex = $exploDevIndex[0] . "." . $exploDevIndex[1]; $this->sigIndex[$devIndex] = $eachsig / $div; } $eachsig = $eachsig / $div; } } } } } /** * Epon mac indexes preprocessing * * @return array */ protected function macIndexEponProcessing() { foreach ($this->macIndex as $devIndex => &$eachmac) { $eachmac = str_replace(' ', ':', $eachmac); $eachmac = strtolower($eachmac); } } /** * Serial number indexes preprocessing. * * @return void */ protected function serialIndexGponProcessing() { foreach ($this->snIndex as $devIndex => &$eachSn) { $eachSn = str_replace(' ', ':', $eachSn); $eachSn = strtoupper($eachSn); } } /** * Coverts dec value to binary with byte offset. * * @param int $binary * * @return array() */ protected function getDecodeType($binary) { $match = array(); $match2 = array(); switch (strlen($binary)) { case 30: preg_match("/(\d{4})(\d{3})(\d{4})(\d{3})(\d{8})(\d{8})/", $binary, $match); break; case 31: preg_match("/(\d{4})(\d{4})(\d{4})(\d{3})(\d{8})(\d{8})/", $binary, $match); break; case 32: preg_match("/(\d{4})(\d{4})(\d{5})(\d{3})(\d{8})(\d{8})/", $binary, $match); break; } foreach ($match as &$each) { $each = bindec($each); } if (!empty($match)) { $match[self::DESC_OLT] += 1; switch ($match[self::DESC_PONTYPE]) { case 9: preg_match("/(\d{4})(\d{4})(\d{4})(\d{4})(\d{8})(\d{8})/", $binary, $match2); break; case 10: preg_match("/(\d{4})(\d{4})(\d{4})(\d{4})(\d{8})(\d{8})/", $binary, $match2); break; } if (isset($match2[self::DESC_PONTYPE])) { foreach ($match2 as &$each) { $each = bindec($each); } $match2[self::DESC_OLT] += 1; $match = $match2; } } return($match); } /** * Coverts dec value to binary with byte offset. For ZTE C6XX/ * * @param int $binary * * @return array() */ protected function getDecodeTypeC6XX($binary) { $match = array(); switch (strlen($binary)) { case 29: preg_match("/(\d{4})(\d{9})(\d{8})(\d{8})/", $binary, $match); break; } foreach ($match as &$each) { $each = bindec($each); } return($match); } /** * Converts binary string to human readable format like epon-olt_1/1/10:16 * * @param array $match * @param boolg $default * * @return string */ protected function stdDecodeOutput($match, $default = true) { $typeName = array( 1 => 'type_olt_virtualIfBER', 3 => 'type-onu', 8 => 'type-onu', 9 => 'type-onu', 10 => 'type-onu', 12 => 'type-onu' ); //rename interface to epon (or gpon if needed) foreach ($typeName as &$name) { if ($this->ponType == 'EPON') { $name = str_replace('type', 'epon', $name); } else { $name = str_replace('type', 'gpon', $name); } } if ($default) { return($typeName[$match[self::DESC_PONTYPE]] . '_' . $match[self::DESC_SHELF] . '/' . $match[self::DESC_SLOT] . '/' . $match[self::DESC_OLT] . ':' . $match[self::DESC_ONU] ); } else { return($typeName[$match[self::DESC_PONTYPE]] . '_' . $match[self::DESC_SHELF] . '/' . $match[self::DESC_SLOT] . '/' . $match[self::DESC_OLT] ); } } /** * Converts dec number to gpon interface name. Looks dirty but seems working. * * @param int $dec * * @return string */ protected function gponOltInterfaceDecode($dec) { $result = ''; $match = array(); $binary = decbin($dec); if (strlen($binary) == 29) { preg_match("/(\d{4})(\d{6})(\d{3})(\d{8})(\d{8})/", $binary, $match); foreach ($match as &$each) { $each = bindec($each); } if ($match[self::DESC_ONU] == 0) { $result = 'gpon-onu_' . $match[self::DESC_SHELF] . '/' . $match[self::DESC_SLOT] . '/' . $match[self::DESC_OLT] . ':'; } else { $result = 'gpon-onu_' . $match[self::DESC_SHELF + 1] . '/' . $match[self::DESC_SLOT + 1] . '/' . $match[self::DESC_OLT + 1] . ':'; } } return($result); } /** * Calculation ZTE epon interfaces indexes. * * @return void */ protected function intIndexCalcEpon() { $cards = $this->cardsEponCalc(); $onu_id_start = 805830912; foreach ($cards as $card) { $onu_id = $onu_id_start + (524288 * ($card - 1)); for ($port = 1; $port <= 16; $port++) { $tmp_id = $onu_id; for ($onu_num = 1; $onu_num <= 64; $onu_num++) { $this->intIndex[$tmp_id] = 'epon-onu_' . $card . "/" . $port . ':' . $onu_num; $tmp_id += 256; } $onu_id += 65536; } } } /** * Check out which cards are installed * * @return array */ protected function cardsEponCalc() { $cards = array(); if (isset($this->currentSnmpTemplate['misc']['ALLCARDS'])) { $allCards = $this->snmpwalk($this->currentSnmpTemplate['misc']['ALLCARDS']); foreach ($allCards as $io => $value) { $split = explode("=", $value); if (isset($split[1])) { $oid = $this->strRemoveOidWithDot($this->currentSnmpTemplate['misc']['ALLCARDS'], $split[0]); $oidParts = explode(".", $oid); $cardNumber = end($oidParts); $card = trim(str_replace("STRING:", '', $split[1])); $card = str_replace('"', '', $card); if (isset($this->eponCards[$card])) { $cards[] = $cardNumber; } } } } if (empty($cards)) { if (isset($this->currentSnmpTemplate['misc']['CARDOFFSET'])) { $start = $this->currentSnmpTemplate['misc']['CARDOFFSET']; } else { $start = 1; } for ($card = $start; $card <= 20; $card++) { $cards[] = $card; } } return($cards); } /** * Getting raw snmp interface index => mac onu * * @return array */ protected function macIndexRawCalc() { $macIndex = array(); $macIndexTmp = $this->snmpwalk($this->currentSnmpTemplate['signal']['MACINDEX']); foreach ($macIndexTmp as $io => $value) { $value = $this->strRemoveOidWithDot($this->currentSnmpTemplate['signal']['MACINDEX'], $value); $value = $this->strRemove($this->currentSnmpTemplate['signal']['MACVALUE'], $value); $macIndex[$io] = $value; } return($macIndex); } /** * Prettyfying result of macIndexRawCalc * * @return void */ protected function macIndexCalc() { $macIndexRaw = $this->macIndexRawCalc(); if (!empty($macIndexRaw)) { foreach ($macIndexRaw as $rawIo => $rawEach) { $explodeIndex = explode('=', $rawEach); if (isset($explodeIndex[1])) { $naturalIndex = trim($explodeIndex[0]); $naturalMac = trim($explodeIndex[1]); $this->macIndex[$naturalIndex] = $naturalMac; } } } } /** * Getting signals => snmp interface id. * * @return array */ protected function sigIndexCalc($data) { $sigIndexTmp = array(); if ($this->currentSnmpTemplate['signal']['SIGNALTYPE'] == 'ONURX') { $oid = $this->currentSnmpTemplate['signal']['ONURXINDEX']; } else { $oid = $this->currentSnmpTemplate['signal']['SIGINDEX']; } if (!empty($data)) { if ($this->currentSnmpTemplate['signal']['POLLTYPE'] == 'default') { foreach ($data as $ioIndex => $eachVal) { $tmpSig = $this->snmpwalk($oid . $ioIndex); $sigIndex = $this->strRemove($this->currentSnmpTemplate['signal']['SIGVALUE'], $tmpSig[0]); $sigIndex = $this->strRemove($oid, $sigIndex); $explodeSig = explode('=', $sigIndex); $naturalIndex = trim($explodeSig[0]); if (isset($explodeSig[1])) { $naturalSig = trim($explodeSig[1]); $trueIndex = $naturalIndex; if ($this->currentSnmpTemplate['signal']['SIGNALTYPE'] == 'ONURX') { $splitIndex = explode(".", $naturalIndex); $trueIndex = $splitIndex[0] . "." . $splitIndex[1]; if ($naturalSig <= 30000) { $naturalSig = $naturalSig * 0.002 - 30; } if ($naturalSig > 30000) { $naturalSig = ($naturalSig - 65535) * 0.002 - 30; } } $sigIndexTmp[$trueIndex] = $naturalSig; } } } if ($this->currentSnmpTemplate['signal']['POLLTYPE'] == 'fast') { $oid = substr($oid, 0, -1); $tmpSig = $this->snmpwalk($oid); foreach ($tmpSig as $eachSig) { $sigIndex = $this->strRemove($this->currentSnmpTemplate['signal']['SIGVALUE'], $eachSig); $sigIndex = $this->strRemoveOidWithDot($oid, $sigIndex); $explodeSig = explode('=', $sigIndex); $naturalIndex = trim($explodeSig[0]); if (isset($explodeSig[1])) { $naturalSig = trim($explodeSig[1]); $trueIndex = $naturalIndex; if ($this->currentSnmpTemplate['signal']['SIGNALTYPE'] == 'ONURX') { $splitIndex = explode(".", $naturalIndex); $trueIndex = $splitIndex[0] . "." . $splitIndex[1]; if ($naturalSig <= 30000) { $naturalSig = $naturalSig * 0.002 - 30; } if ($naturalSig > 30000) { $naturalSig = ($naturalSig - 65535) * 0.002 - 30; } } $sigIndexTmp[$trueIndex] = $naturalSig; } } } } unset($this->sigIndex); $this->sigIndex = $sigIndexTmp; } /** * Getting FDB * * @return void */ protected function fdbCalc() { $this->fdbIndex = $this->snmpwalk($this->currentSnmpTemplate['misc']['FDBINDEX']); foreach ($this->fdbIndex as $id => &$value) { $value = $this->strRemoveOidWithDot($this->currentSnmpTemplate['misc']['FDBINDEX'], $value); } } /** * * Function for fixing fucking zte interfaces snmp id. * * @param int $uuid * * @return string */ protected function interfaceDecode($uuid) { $binary = decbin($uuid); $match = $this->getDecodeType($binary); if (!empty($match) and isset($match[self::DESC_PONTYPE])) { switch ($match[self::DESC_PONTYPE]) { case 1: return($this->stdDecodeOutput($match, false)); case 3: return($this->stdDecodeOutput($match)); case 6: return($match[self::DESC_SHELF] . '/' . $match[self::DESC_SLOT] . '/'); case 8: $match[self::DESC_SLOT] += $this->currentSnmpTemplate['misc']['CARDOFFSET']; $match[self::DESC_ONU] += 1; return($this->stdDecodeOutput($match)); case 9: return($this->stdDecodeOutput($match)); case 10: $match[self::DESC_SLOT] += 1; $match[self::DESC_ONU] += 1; return($this->stdDecodeOutput($match)); case 12: return($this->stdDecodeOutput($match)); } } return FALSE; } /** * Preprocessing serial index array with removing unneded substrings. * * @return void */ protected function snIndexProcess() { $this->snIndex = $this->snmpwalk($this->currentSnmpTemplate['signal']['SNINDEX']); foreach ($this->snIndex as $io => &$value) { $value = $this->strRemove($this->currentSnmpTemplate['signal']['SNVALUE'], $value); $value = $this->strRemoveOidWithDot($this->currentSnmpTemplate['signal']['SNINDEX'], $value); $value = trim($value); } } /** * Preproccess distances indexes. * * @return void */ protected function distanceIndexProcess() { if ($this->currentSnmpTemplate['signal']['POLLTYPE'] == 'default') { foreach ($this->snIndex as $ioIndex => $eachSn) { $tmpDist = $this->snmpwalk($this->currentSnmpTemplate['signal']['DISTANCE'] . '.' . $ioIndex); $distIndex = $this->strRemoveOidWithDot($this->currentSnmpTemplate['signal']['DISTANCE'], $tmpDist[0]); $distIndex = $this->strRemove($this->currentSnmpTemplate['signal']['DISTVALUE'], $distIndex); $explodeDist = explode('=', $distIndex); $naturalIndex = trim($explodeDist[0]); if (isset($explodeDist[1])) { $naturalDist = trim($explodeDist[1]); $this->distanceIndex[$naturalIndex] = $naturalDist; } } } if ($this->currentSnmpTemplate['signal']['POLLTYPE'] == 'fast') { $tmpDist = $this->snmpwalk($this->currentSnmpTemplate['signal']['DISTANCE']); foreach ($tmpDist as $eachDist) { $distIndex = $this->strRemoveOidWithDot($this->currentSnmpTemplate['signal']['DISTANCE'], $eachDist); $distIndex = $this->strRemove($this->currentSnmpTemplate['signal']['DISTVALUE'], $distIndex); $explodeDist = explode('=', $distIndex); $naturalIndex = trim($explodeDist[0]); if (isset($explodeDist[1])) { $naturalDist = trim($explodeDist[1]); $this->distanceIndex[$naturalIndex] = $naturalDist; } } } } //parser functions /** * Parses & stores in cache ZTE OLT ONU ID * * @return void */ protected function onuidParseEpon() { $macTmp = array(); foreach ($this->macIndex as $ioIndex => $eachMac) { $eachMac = strtolower($eachMac); $eachMac = str_replace(" ", ":", $eachMac); $macTmp[$ioIndex] = $eachMac; } $this->olt->writeOnuCache($macTmp); } /** * Parsing and validating input array. Getting hex from dec values. * * @param array $decParts * * @return array */ protected function macPartParse($decParts) { $macPart = array(); if (isset($decParts[1])) { for ($i = 2; $i <= 7; $i++) { $macPart[] = dechex($decParts[$i]); } foreach ($macPart as &$eachPart) { if (strlen($eachPart) < 2) { $eachPart = '0' . $eachPart; } } } return($macPart); } /** * Parses & stores in cache OLT ONU interfaces * * @return void */ protected function fdbParseEpon() { $counter = 1; $fdbTmp = array(); $macTmp = array(); $result = array(); //fdb index preprocessing if ((!empty($this->fdbIndex)) AND (!empty($this->macIndex))) { foreach ($this->fdbIndex as $io => $eachfdb) { $line = explode('=', $eachfdb); $devOid = trim($line[0]); $decParts = explode('.', $devOid); $devIndex = trim($decParts[0]); $interfaceName = $this->interfaceDecode($devIndex); if ($interfaceName) { if (isset($decParts[1])) { $fdbVlan = trim($decParts[1]); $fdbMac = implode(':', $this->macPartParse($decParts)); $fdbTmp[$interfaceName][$counter]['mac'] = $fdbMac; $fdbTmp[$interfaceName][$counter]['vlan'] = $fdbVlan; $counter++; } } } //mac index preprocessing foreach ($this->macIndex as $devIndex => $eachMac) { if ($this->interfaceDecode($devIndex)) { $macTmp[$this->interfaceDecode($devIndex)] = $eachMac; } } $realData = array_intersect_key($macTmp, $fdbTmp); //storing results foreach ($realData as $devId => $eachMac) { $result[$macTmp[$devId]] = $fdbTmp[$devId]; } } $this->olt->writeFdb($result); } /** * Parses & stores in cache ZTE OLT ONU interfaces * * @return void */ protected function interfaceParseEpon() { $result = array(); foreach ($this->macIndex as $ioIndex => $eachMac) { if (isset($this->intIndex[$ioIndex])) { $eachMac = strtolower($eachMac); $eachMac = str_replace(" ", ":", $eachMac); $interface = $this->intIndex[$ioIndex]; $result[$eachMac] = $interface; } elseif ($this->interfaceDecode($ioIndex)) { $eachMac = strtolower($eachMac); $eachMac = str_replace(" ", ":", $eachMac); $result[$eachMac] = $this->interfaceDecode($ioIndex); } } $this->olt->writeInterfaces($result); } /** * Performs signal preprocessing for sig/mac index arrays and stores it into cache for ZTE OLT * * @return void */ protected function signalParseEpon() { $result = array(); if ((!empty($this->sigIndex)) AND (!empty($this->macIndex))) { $this->signalIndexProcessing(); $this->macIndexEponProcessing(); $realData = array_intersect_key($this->macIndex, $this->sigIndex); foreach ($realData as $devId => $io) { $result[$this->macIndex[$devId]] = $this->sigIndex[$devId]; $tmpSig = $this->sigIndex[$devId]; if ($this->sigIndex[$devId] == 'Offline') { $tmpSig = -9000; } $this->olt->writeSignalHistory($this->macIndex[$devId], $tmpSig); } } $this->olt->writeSignals($result); } /** * Performs signal preprocessing for sig/sn index arrays and stores it into cache for ZTE OLT * * @return void */ protected function signalParseGpon() { $result = array(); $curDate = curdatetime(); //signal index preprocessing if ((!empty($this->sigIndex)) AND (!empty($this->snIndex))) { $this->signalIndexProcessing(); $this->serialIndexGponProcessing(); $realData = array_intersect_key($this->snIndex, $this->sigIndex); //storing results foreach ($realData as $devId => $eachSn) { $result[$this->snIndex[$devId]] = $this->sigIndex[$devId]; $tmpSig = $this->sigIndex[$devId]; if ($tmpSig == 'Offline') { $tmpSig = -9000; } //signal history filling $this->olt->writeSignalHistory($this->snIndex[$devId], $tmpSig); } } $this->olt->writeSignals($result); } /** * Parsing distance for ZTE/Huawei GPON * * @param array $distIndex * * @return void */ protected function distanceParseGpon() { $result = array(); //distance index preprocessing if (!empty($this->distanceIndex) AND!empty($this->snIndex)) { $realData = array_intersect_key($this->snIndex, $this->distanceIndex); foreach ($realData as $io => $eachsn) { $result[$this->snIndex[$io]] = $this->distanceIndex[$io]; } } $this->olt->writeDistances($result); } /** * Parses & stores in cache OLT ONU interfaces * * @return void */ protected function fdbParseGpon() { $counter = 1; $fdbTmp = array(); $snTmp = array(); $result = array(); //fdb index preprocessing if ((!empty($this->fdbIndex)) AND (!empty($this->snIndex))) { foreach ($this->fdbIndex as $io => $eachfdb) { $line = explode('=', $eachfdb); $devOid = trim($line[0]); $decParts = explode('.', $devOid); if ($this->currentSnmpTemplate['onu_reg']['VERSION'] == 'C6XX') { if (trim($decParts[2]) != 0) { $vportIndex = trim($decParts[1]); $devIndex = trim($decParts[2]); $interfaceVport = $this->gponOltInterfaceDecode($vportIndex); /* // It's real data from OLT // c025.2fac.ff3c 3701 Dynamic vport-1/3/1.5:1 $interfaceVport = str_replace('gpon-onu_', 'vport-', $this->gponOltInterfaceDecode($vportIndex)); $interfaceVport = str_replace(':', '.', $interfaceVport); $interfaceVportDecode = $this->getDecodeTypeC6XX(decbin($devIndex)); $interfaceName = $interfaceVport . $interfaceVportDecode[3] . ':' . $interfaceVportDecode[4]; $interfaceVportDecode = $this->getDecodeTypeC6XX(decbin($devIndex)); $interfaceName = $interfaceVport . $interfaceVportDecode[3] . ':' . $interfaceVportDecode[4]; */ $interfaceVportDecode = $this->getDecodeTypeC6XX(decbin($devIndex)); $interfaceName = $interfaceVport . $interfaceVportDecode[2]; if ($interfaceName) { if (isset($decParts[0])) { $fdbVlan = trim($decParts[0]); $fdbMac = trim(str_replace('Hex-STRING:', '', $line[1])); $fdbMac = strtolower(str_replace(' ', ':', $fdbMac)); $fdbTmp[$interfaceName][$counter]['mac'] = $fdbMac; $fdbTmp[$interfaceName][$counter]['vlan'] = $fdbVlan; $counter++; } } } } else { $devIndex = trim($decParts[0]); $interfaceName = $this->interfaceDecode($devIndex); if ($interfaceName) { if (isset($decParts[1])) { $fdbVlan = trim($decParts[1]); $fdbMac = implode(':', $this->macPartParse($decParts)); $fdbTmp[$interfaceName][$counter]['mac'] = $fdbMac; $fdbTmp[$interfaceName][$counter]['vlan'] = $fdbVlan; $counter++; } } } } //mac index preprocessing foreach ($this->snIndex as $devIndex => $eachSn) { $devIndexParts = explode(".", $devIndex); $onuNumber = $devIndexParts[1]; $interfaceName = $this->gponOltInterfaceDecode($devIndexParts[0]) . $onuNumber; if ($interfaceName) { $snTmp[$interfaceName] = $eachSn; } } $realData = array_intersect_key($snTmp, $fdbTmp); //storing results foreach ($realData as $devId => $eachSn) { $result[$snTmp[$devId]] = $fdbTmp[$devId]; } } $this->olt->writeFdb($result); } /** * Parses & stores in cache ZTE OLT ONU interfaces * * @return void */ protected function interfaceParseGpon() { $result = array(); //storing results foreach ($this->snIndex as $ioIndex => $eachSn) { $ioIndexSplit = explode(".", $ioIndex); $result[$eachSn] = $this->gponOltInterfaceDecode($ioIndexSplit[0]) . $ioIndexSplit[1]; } $this->olt->writeInterfaces($result); } /** * Parses & stores in cache ZTE OLT ONU ID * * @return void */ protected function onuidParseGpon() { $snTmp = array(); if ($this->currentSnmpTemplate['onu_reg']['VERSION'] == 'C6XX') { $snTmp = $this->snIndex; } else { foreach ($this->snIndex as $ioIndex => $eachSn) { $snTmp[$this->interfaceDecode($ioIndex)] = $eachSn; } } $this->olt->writeOnuCache($snTmp); } /** * Parsing serial numbers; * * @return void */ protected function serialNumberParse() { $result = array(); foreach ($this->snIndex as $rawIo => $rawEach) { $split = explode("=", $rawEach); if (isset($split[1])) { $naturalIndex = trim($split[0]); $rawSn = trim($split[1]); $tmpSn = explode(" ", $rawSn); $check = trim($tmpSn[0]); if ($check == 'STRING:') { $naturalSn = $this->serialNumberBinaryParse($tmpSn[1]); } else { $naturalSn = $this->serialNumberHexParse($tmpSn); } $result[$naturalIndex] = $naturalSn; } } unset($this->snIndex); $this->snIndex = $result; } /** * Parsing serial number in binary format and coverting it to needed format. * * @param array $rawSn * * @return string */ protected function serialNumberBinaryParse($rawSn) { $parts = array(); $hexSn = bin2hex($rawSn); if (strlen($hexSn) == 20) { $parts[0] = $this->serialNumberPartsTranslate($hexSn[2] . $hexSn[3]); $parts[1] = $this->serialNumberPartsTranslate($hexSn[4] . $hexSn[5]); $parts[2] = $this->serialNumberPartsTranslate($hexSn[6] . $hexSn[7]); $parts[3] = $this->serialNumberPartsTranslate($hexSn[8] . $hexSn[9]); $parts[4] = ''; for ($i = 10; $i <= 17; $i++) { $parts[4] .= $hexSn[$i]; } } else { $parts[0] = $this->serialNumberPartsTranslate($hexSn[0] . $hexSn[1]); $parts[1] = $this->serialNumberPartsTranslate($hexSn[2] . $hexSn[3]); $parts[2] = $this->serialNumberPartsTranslate($hexSn[4] . $hexSn[5]); $parts[3] = $this->serialNumberPartsTranslate($hexSn[6] . $hexSn[7]); $parts[4] = ''; for ($i = 8; $i <= 15; $i++) { $parts[4] .= $hexSn[$i]; } } $result = implode("", $parts); return($result); } /** * Parsing serial number in hex format and coverting it to needed format. * * @param array $rawSn * * @return string */ protected function serialNumberHexParse($rawSn) { $parts[0] = $this->serialNumberPartsTranslate($rawSn[0]); $parts[1] = $this->serialNumberPartsTranslate($rawSn[1]); $parts[2] = $this->serialNumberPartsTranslate($rawSn[2]); $parts[3] = $this->serialNumberPartsTranslate($rawSn[3]); $parts[4] = $rawSn[4] . $rawSn[5] . $rawSn[6] . $rawSn[7]; $result = implode("", $parts); return($result); } /** * Check mode to convert serial number string vs raw. * * @param string $part * * @return string */ protected function serialNumberPartsTranslate($part) { if ($this->currentSnmpTemplate['signal']['SNMODE'] == 'STRING') { return($this->hexToString($part)); } if ($this->currentSnmpTemplate['signal']['SNMODE'] == 'PURE') { return($part); } } /** * Parses uptime data and saves it into uptime cache * * @param int $oltid * @param string $uptimeRaw * * @return void */ protected function uptimeParse() { $uptimeIndexOid = $this->currentSnmpTemplate['system']['UPTIME']; $uptimeRaw = $this->snmp->walk($this->oltFullAddress, $this->oltCommunity, $uptimeIndexOid, PONizer::SNMPCACHE); if (!empty($this->oltid) and!empty($uptimeRaw)) { $uptimeRaw = explode(')', $uptimeRaw); $uptimeRaw = $uptimeRaw[1]; $uptimeRaw = trim($uptimeRaw); $this->olt->writeUptime($uptimeRaw); } } /** * Parses temperature data and saves it into uptime cache * * @param int $oltid * @param string $uptimeRaw * * @return void */ protected function temperatureParse() { $temperatureIndexOid = $this->currentSnmpTemplate['system']['TEMPERATURE']; $tempRaw = $this->snmp->walk($this->oltFullAddress, $this->oltCommunity, $temperatureIndexOid, PONizer::SNMPCACHE); if (!empty($this->oltid) and!empty($tempRaw)) { $tempRaw = explode(':', $tempRaw); $tempRaw = $tempRaw[1]; $tempRaw = trim($tempRaw); $this->olt->writeTemperature($tempRaw); } } //Main section /** * Polling EPON device * * @return void */ public function pollEpon() { $this->macIndexCalc(); $this->sigIndexCalc($this->macIndex); $this->signalParseEpon(); if (isset($this->currentSnmpTemplate['misc'])) { if (isset($this->currentSnmpTemplate['misc']['CARDOFFSET'])) { $this->intIndexCalcEpon(); $this->fdbCalc(); $this->fdbParseEpon(); $this->interfaceParseEpon(); $this->onuidParseEpon(); } } } /** * Polling GPON device * * @return void */ public function pollGpon() { $this->snIndexProcess(); $this->serialNumberParse(); $this->sigIndexCalc($this->snIndex); $this->signalParseGpon(); if (isset($this->currentSnmpTemplate['signal']['DISTANCE'])) { $this->distanceIndexProcess(); $this->distanceParseGpon(); } if (isset($this->currentSnmpTemplate['misc'])) { if (isset($this->currentSnmpTemplate['misc']['CARDOFFSET'])) { $this->fdbCalc(); $this->fdbParseGpon(); $this->interfaceParseGpon(); $this->onuidParseGpon(); } } //getting others system data from OLT if (isset($this->currentSnmpTemplate['system'])) { //OLT uptime if (isset($this->currentSnmpTemplate['system']['UPTIME'])) { $this->uptimeParse(); } //OLT temperature if (isset($this->currentSnmpTemplate['system']['TEMPERATURE'])) { $this->temperatureParse(); } } } /** * Polling Huawei GPON device * * @return void */ public function huaweiPollGpon() { $this->snIndexProcess(); $this->serialNumberParse(); $this->sigIndexCalc($this->snIndex); $this->signalParseGpon(); if (isset($this->currentSnmpTemplate['signal']['DISTANCE'])) { $this->distanceIndexProcess(); $this->distanceParseGpon(); } } } |