api.ponvsol.php 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596
  1. <?php
  2. /**
  3. * OLT V-Solution 1600D hardware abstraction layer
  4. */
  5. class PONVsol extends PONProto {
  6. /**
  7. * Receives, preprocess and stores all required data from V-Solution 1600D
  8. *
  9. * @return void
  10. */
  11. public function collect() {
  12. $oltModelId = $this->oltParameters['MODELID'];
  13. $oltid = $this->oltParameters['ID'];
  14. $oltIp = $this->oltParameters['IP'];
  15. $oltCommunity = $this->oltParameters['COMMUNITY'];
  16. $oltNoFDBQ = $this->oltParameters['NOFDB'];
  17. $oltIPPORT = $oltIp . ':' . self::SNMPPORT;
  18. $deviceType = $this->snmpTemplates[$oltModelId]['define']['DEVICE'];
  19. $sigIndexOID = $this->snmpTemplates[$oltModelId]['signal']['SIGINDEX'];
  20. $sigIndex = $this->snmp->walk($oltIp . ':' . self::SNMPPORT, $oltCommunity, $sigIndexOID, self::SNMPCACHE);
  21. $sigIndex = str_replace($sigIndexOID . '.', '', $sigIndex);
  22. $sigIndex = str_replace($this->snmpTemplates[$oltModelId]['signal']['SIGVALUE'], '', $sigIndex);
  23. $sigIndex = explodeRows($sigIndex);
  24. $macIndexOID = $this->snmpTemplates[$oltModelId]['signal']['MACINDEX'];
  25. $macIndex = $this->snmp->walk($oltIp . ':' . self::SNMPPORT, $oltCommunity, $macIndexOID, self::SNMPCACHE);
  26. $macIndex = str_replace($macIndexOID . '.', '', $macIndex);
  27. $macIndex = str_replace($this->snmpTemplates[$oltModelId]['signal']['MACVALUE'], '', $macIndex);
  28. $macIndex = explodeRows($macIndex);
  29. $VSOLMACsProcessed = $this->macParseVSOL($macIndex, $this->snmpTemplates[$oltModelId]);
  30. if (!empty($VSOLMACsProcessed)) {
  31. $this->signalParseVSOL($oltid, $sigIndex, $VSOLMACsProcessed);
  32. $distIndexOID = $this->snmpTemplates[$oltModelId]['misc']['DISTINDEX'];
  33. $distIndex = $this->snmp->walk($oltIp . ':' . self::SNMPPORT, $oltCommunity, $distIndexOID, self::SNMPCACHE);
  34. $distIndex = str_replace($distIndexOID . '.', '', $distIndex);
  35. $distIndex = str_replace($this->snmpTemplates[$oltModelId]['misc']['DISTVALUE'], '', $distIndex);
  36. $distIndex = explodeRows($distIndex);
  37. $this->distanceParseVSOL($oltid, $distIndex, $VSOLMACsProcessed);
  38. $ifaceIndexOID = $this->snmpTemplates[$oltModelId]['misc']['IFACEDESCR'];
  39. $ifaceIndex = $this->snmp->walk($oltIp . ':' . self::SNMPPORT, $oltCommunity, $ifaceIndexOID, self::SNMPCACHE);
  40. $ifaceIndex = str_replace($ifaceIndexOID . '.', '', $ifaceIndex);
  41. $ifaceIndex = str_replace(array($this->snmpTemplates[$oltModelId]['misc']['IFACEVALUE'], '"'), '', $ifaceIndex);
  42. $ifaceIndex = explodeRows($ifaceIndex);
  43. $ifaceCustDescrIndex = array();
  44. if (isset($this->snmpTemplates[$oltModelId]['misc']['IFACECUSTOMDESCR'])) {
  45. $ifaceCustDescrIndexOID = $this->snmpTemplates[$oltModelId]['misc']['IFACECUSTOMDESCR'];
  46. $ifaceCustDescrIndex = $this->snmp->walk($oltIp . ':' . self::SNMPPORT, $oltCommunity, $ifaceCustDescrIndexOID, self::SNMPCACHE);
  47. $ifaceCustDescrIndex = str_replace($ifaceCustDescrIndexOID . '.', '', $ifaceCustDescrIndex);
  48. $ifaceCustDescrIndex = str_replace(array($this->snmpTemplates[$oltModelId]['misc']['IFACEVALUE'], '"'), '', $ifaceCustDescrIndex);
  49. $ifaceCustDescrIndex = explodeRows($ifaceCustDescrIndex);
  50. }
  51. $this->interfaceParseVSOL($oltid, $ifaceIndex, $VSOLMACsProcessed, $ifaceCustDescrIndex);
  52. $lastDeregIndexOID = $this->snmpTemplates[$oltModelId]['misc']['DEREGREASON'];
  53. $lastDeregIndex = $this->snmp->walk($oltIp . ':' . self::SNMPPORT, $oltCommunity, $lastDeregIndexOID, self::SNMPCACHE);
  54. $lastDeregIndex = str_replace($lastDeregIndexOID . '.', '', $lastDeregIndex);
  55. $lastDeregIndex = str_replace($this->snmpTemplates[$oltModelId]['misc']['DEREGVALUE'], '', $lastDeregIndex);
  56. $lastDeregIndex = explodeRows($lastDeregIndex);
  57. $this->lastDeregParseVSOL($oltid, $lastDeregIndex, $VSOLMACsProcessed);
  58. if (!$oltNoFDBQ) {
  59. $fdbIndex = $this->walkCleared($oltIPPORT, $oltCommunity,
  60. $this->snmpTemplates[$oltModelId]['misc']['FDBINDEX'],
  61. '',
  62. $this->snmpTemplates[$oltModelId]['misc']['FDBVALUE'],
  63. self::SNMPCACHE);
  64. /* $fdbIndexOID = $this->snmpTemplates[$oltModelId]['misc']['FDBINDEX'];
  65. $fdbIndex = $this->snmp->walk($oltIp . ':' . self::SNMPPORT, $oltCommunity, $fdbIndexOID, self::SNMPCACHE);
  66. $fdbIndex = str_replace($fdbIndexOID . '.', '', $fdbIndex);
  67. $fdbIndex = str_replace($this->snmpTemplates[$oltModelId]['misc']['FDBVALUE'], '', $fdbIndex);
  68. $fdbIndex = explodeRows($fdbIndex);*/
  69. $fdbVLANIndex = $this->walkCleared($oltIPPORT, $oltCommunity,
  70. $this->snmpTemplates[$oltModelId]['misc']['FDBVLANINDEX'],
  71. '',
  72. $this->snmpTemplates[$oltModelId]['misc']['FDBVLANVALUE'],
  73. self::SNMPCACHE);
  74. /* $fdbMACVLANOID = $this->snmpTemplates[$oltModelId]['misc']['FDBVLANINDEX'];
  75. $fdbVLANIndex = $this->snmp->walk($oltIp . ':' . self::SNMPPORT, $oltCommunity, $fdbMACVLANOID, self::SNMPCACHE);
  76. $fdbVLANIndex = str_replace($fdbMACVLANOID . '.', '', $fdbVLANIndex);
  77. $fdbVLANIndex = str_replace($this->snmpTemplates[$oltModelId]['misc']['FDBVLANVALUE'], '', $fdbVLANIndex);
  78. $fdbVLANIndex = explodeRows($fdbVLANIndex);*/
  79. if ($deviceType == 'V-Solution OLT V1600D_L') {
  80. $fdbMACIndex = $this->walkCleared($oltIPPORT, $oltCommunity,
  81. $this->snmpTemplates[$oltModelId]['misc']['FDBMACINDEX'],
  82. '',
  83. array($this->snmpTemplates[$oltModelId]['misc']['FDBMACVALUE'], '"'),
  84. self::SNMPCACHE);
  85. $this->fdbParseVSOL_L($VSOLMACsProcessed, $fdbIndex, $fdbMACIndex, $fdbVLANIndex);
  86. } else {
  87. $this->fdbParseVSOL($oltid, $VSOLMACsProcessed, $fdbIndex, $fdbVLANIndex);
  88. }
  89. }
  90. }
  91. //getting others system data from OLT
  92. if (isset($this->snmpTemplates[$oltModelId]['system'])) {
  93. //OLT uptime
  94. if (isset($this->snmpTemplates[$oltModelId]['system']['UPTIME'])) {
  95. $uptimeIndexOid = $this->snmpTemplates[$oltModelId]['system']['UPTIME'];
  96. $oltSystemUptimeRaw = $this->snmp->walk($oltIp . ':' . self::SNMPPORT, $oltCommunity, $uptimeIndexOid, self::SNMPCACHE);
  97. $this->uptimeParse($oltid, $oltSystemUptimeRaw);
  98. }
  99. //OLT temperature
  100. if (isset($this->snmpTemplates[$oltModelId]['system']['TEMPERATURE'])) {
  101. $temperatureIndexOid = $this->snmpTemplates[$oltModelId]['system']['TEMPERATURE'];
  102. $oltTemperatureRaw = $this->snmp->walk($oltIp . ':' . self::SNMPPORT, $oltCommunity, $temperatureIndexOid, self::SNMPCACHE);
  103. $this->temperatureParse($oltid, $oltTemperatureRaw);
  104. }
  105. }
  106. }
  107. /**
  108. * Processes V-SOLUTION OLT MAC adresses and returns them in array: LLID=>MAC
  109. *
  110. * @param $macIndex
  111. * @param $snmpTemplate
  112. *
  113. * @return array
  114. */
  115. protected function macParseVSOL($macIndex, $snmpTemplate) {
  116. $ONUsMACs = array();
  117. if (!empty($macIndex)) {
  118. //mac index preprocessing
  119. foreach ($macIndex as $io => $eachmac) {
  120. $line = explode('=', $eachmac);
  121. if (empty($line[0]) || empty($line[1])) {
  122. continue;
  123. }
  124. $tmpONUPortLLID = trim($line[0]);
  125. if ($snmpTemplate['misc']['GETACTIVEONUMACONLY']) {
  126. $tmpONUMAC = rtrim(chunk_split(str_replace(array('"', "0x"), '', trim($line[1])), 2, ':'), ':'); //mac address
  127. } else {
  128. $tmpONUMAC = str_replace('"', '', trim($line[1])); //mac address
  129. }
  130. //mac is present
  131. if (!empty($tmpONUPortLLID) and ! empty($tmpONUMAC)) {
  132. $ONUsMACs[$tmpONUPortLLID] = $tmpONUMAC;
  133. }
  134. }
  135. }
  136. return ($ONUsMACs);
  137. }
  138. /**
  139. * Performs signal preprocessing for sig/mac index arrays and stores it into cache
  140. *
  141. * @param int $oltid
  142. * @param array $sigIndex
  143. * @param array $macIndexProcessed
  144. *
  145. * @return void
  146. */
  147. protected function signalParseVSOL($oltid, $sigIndex, $macIndexProcessed) {
  148. $ONUsModulesTemps = array();
  149. $ONUsModulesVoltages = array();
  150. $ONUsModulesCurrents = array();
  151. $ONUsSignals = array();
  152. $result = array();
  153. $macDevID = array();
  154. $curDate = curdatetime();
  155. $oltid = vf($oltid, 3);
  156. //signal index preprocessing
  157. if ((!empty($sigIndex)) and ( !empty($macIndexProcessed))) {
  158. foreach ($sigIndex as $io => $eachsig) {
  159. $line = explode('=', $eachsig);
  160. //signal is present
  161. if (isset($line[0])) {
  162. $tmpOIDParamaterPiece = substr(trim($line[0]), 0, 1);
  163. $tmpONUPortLLID = substr(trim($line[0]), 2);
  164. // just because we can't(I dunno why - honestly) just query the
  165. // .1.3.6.1.4.1.37950.1.1.5.12.2.1.8.1.6 and .1.3.6.1.4.1.37950.1.1.5.12.2.1.8.1.7 OIDs
  166. // cause it's simply returns NOTHING - we need to take a start from the higher tree point - .1.3.6.1.4.1.37950.1.1.5.12.2.1.8.1
  167. // and then we can extract all necessary values
  168. switch ($tmpOIDParamaterPiece) {
  169. case '3':
  170. $ONUsModulesTemps[$tmpONUPortLLID] = trim($line[1]); // may be we'll show this somewhere in future
  171. break;
  172. case '4':
  173. $ONUsModulesVoltages[$tmpONUPortLLID] = trim($line[1]); // may be we'll show this somewhere in future
  174. break;
  175. case '5':
  176. $ONUsModulesCurrents[$tmpONUPortLLID] = trim($line[1]); // may be we'll show this somewhere in future
  177. break;
  178. // may be we'll show this somewhere in future
  179. case '6':
  180. $SignalRaw = trim($line[1]);
  181. $ONUsSignals[$tmpONUPortLLID]['SignalTXRaw'] = $SignalRaw;
  182. $ONUsSignals[$tmpONUPortLLID]['SignalTXdBm'] = trim(substr(stristr(stristr(stristr($SignalRaw, '('), ')', true), 'dBm', true), 1));
  183. break;
  184. case '7':
  185. $SignalRaw = trim($line[1]);
  186. $ONUsSignals[$tmpONUPortLLID]['SignalRXRaw'] = $SignalRaw;
  187. $ONUsSignals[$tmpONUPortLLID]['SignalRXdBm'] = trim(substr(stristr(stristr(stristr($SignalRaw, '('), ')', true), 'dBm', true), 1));
  188. break;
  189. }
  190. }
  191. }
  192. //storing results
  193. foreach ($macIndexProcessed as $devId => $eachMac) {
  194. if (isset($ONUsSignals[$devId])) {
  195. //signal history filling
  196. $signal = (isset($ONUsSignals[$devId]['SignalRXdBm']) ? $ONUsSignals[$devId]['SignalRXdBm'] : '');
  197. if (!empty($signal)) {
  198. $result[$eachMac] = $signal;
  199. }
  200. if (empty($signal) or $signal == 'Offline') {
  201. $signal = $this->onuOfflineSignalLevel; //over 9000 offline signal level :P
  202. }
  203. //saving each ONU signal history
  204. $this->olt->writeSignalHistory($eachMac, $signal);
  205. }
  206. }
  207. $macDevID = array_flip($macIndexProcessed);
  208. //writing signals cache
  209. $this->olt->writeSignals($result);
  210. //saving ONU cache
  211. $this->olt->writeOnuCache($macIndexProcessed);
  212. // saving macindex as MAC => devID
  213. $this->olt->writeMacIndex($macDevID);
  214. }
  215. }
  216. /**
  217. * Performs distance preprocessing for distance/mac index arrays and stores it into cache
  218. *
  219. * @param $oltid
  220. * @param $DistIndex
  221. * @param $macIndexProcessed
  222. */
  223. protected function distanceParseVSOL($oltid, $DistIndex, $macIndexProcessed) {
  224. $ONUDistances = array();
  225. $result = array();
  226. if (!empty($macIndexProcessed) and ! empty($DistIndex)) {
  227. //last dereg index preprocessing
  228. foreach ($DistIndex as $io => $eachRow) {
  229. $line = explode('=', $eachRow);
  230. if (empty($line[0]) || empty($line[1])) {
  231. continue;
  232. }
  233. $tmpONUPortLLID = trim($line[0]);
  234. $tmpONUDistance = trim($line[1]);
  235. $ONUDistances[$tmpONUPortLLID] = $tmpONUDistance;
  236. }
  237. //storing results
  238. foreach ($macIndexProcessed as $devId => $eachMac) {
  239. if (isset($ONUDistances[$devId])) {
  240. $result[$eachMac] = $ONUDistances[$devId];
  241. }
  242. }
  243. //saving distances
  244. $this->olt->writeDistances($result);
  245. }
  246. }
  247. /**
  248. * Performs interface preprocessing for interface/mac index arrays and stores it into cache
  249. *
  250. * @param $oltid
  251. * @param $IfaceIndex
  252. * @param $macIndexProcessed
  253. * @param $ifaceCustDescrRaw
  254. */
  255. protected function interfaceParseVSOL($oltid, $IfaceIndex, $macIndexProcessed, $ifaceCustDescrRaw = array()) {
  256. $ONUIfaces = array();
  257. $result = array();
  258. $processIfaceCustDescr = !empty($ifaceCustDescrRaw);
  259. $ifaceCustDescrIdx = array();
  260. $ifaceCustDescrArr = array();
  261. // olt iface descr extraction
  262. if ($processIfaceCustDescr) {
  263. foreach ($ifaceCustDescrRaw as $io => $each) {
  264. if (empty($each)) {
  265. continue;
  266. }
  267. $ifDescr = explode('=', str_replace(array(" ", "\t", "\n", "\r", "\0", "\x0B"), '', $each));
  268. if (empty($ifDescr[0]) && empty($ifDescr[1])) {
  269. continue;
  270. }
  271. $ifaceCustDescrIdx[$ifDescr[0]] = $ifDescr[1];
  272. }
  273. }
  274. if (!empty($macIndexProcessed) and ! empty($IfaceIndex)) {
  275. //OLT iface index preprocessing
  276. foreach ($IfaceIndex as $io => $eachRow) {
  277. if (empty($eachRow)) {
  278. continue;
  279. }
  280. $line = explode('=', str_replace(array(" ", "\t", "\n", "\r", "\0", "\x0B"), '', $eachRow));
  281. if (empty($line[0]) || empty($line[1])) {
  282. continue;
  283. }
  284. $tmpONUPortLLID = trim($line[0]);
  285. $tmpONUIface = trim($line[1]);
  286. $ONUIfaces[$tmpONUPortLLID] = $tmpONUIface;
  287. }
  288. //storing results
  289. foreach ($macIndexProcessed as $devId => $eachMac) {
  290. $tPONIfaceNum = substr($devId, 0, 1);
  291. if (array_key_exists($tPONIfaceNum, $ONUIfaces)) {
  292. $tPONIfaceName = $ONUIfaces[$tPONIfaceNum];
  293. $tPONIfaceStr = $tPONIfaceName . ' / ' . str_replace('.', ':', $devId);
  294. $cleanIface = strstr($tPONIfaceStr, ':', true);
  295. if ($processIfaceCustDescr && !isset($ifaceCustDescrArr[$cleanIface]) && array_key_exists($tPONIfaceNum, $ifaceCustDescrIdx)) {
  296. $ifaceCustDescrArr[$cleanIface] = $ifaceCustDescrIdx[$tPONIfaceNum];
  297. }
  298. } else {
  299. $tPONIfaceStr = str_replace('.', ':', $devId);
  300. }
  301. $result[$eachMac] = $tPONIfaceStr;
  302. }
  303. //saving ONU interfaces and interfaces descriptions
  304. $this->olt->writeInterfaces($result);
  305. $this->olt->writeInterfacesDescriptions($ifaceCustDescrArr);
  306. }
  307. }
  308. /**
  309. * Parses & stores to cache ONUs FDB cache (MACs behind ONU)
  310. *
  311. * @param $oltID
  312. * @param $onuMACIndex
  313. * @param $fdbIndex
  314. * @param $fdbVLANIndex
  315. */
  316. protected function fdbParseVSOL($oltID, $onuMACIndex, $fdbIndex, $fdbVLANIndex) {
  317. $fdbIdxMAC = array();
  318. $fdbIdxVLAN = array();
  319. $fdbCahce = array();
  320. if (!empty($fdbIndex)) {
  321. // processing FDBIndex array to get FDB MAC => pon port number + ONU LLID mapping
  322. foreach ($fdbIndex as $each => $eachIdx) {
  323. $line = explode('=', $eachIdx);
  324. // ONU LLID is present
  325. if (isset($line[1])) {
  326. $portLLID = trim(str_replace(array('"', 'EPON0/'), '', $line[1])); // pon port number + ONU LLID
  327. $portLLID = str_replace(':', '.', $portLLID);
  328. $fdbMAC = trim(convertMACDec2Hex($line[0])); // FDB MAC in dotted DEC format
  329. $fdbIdxMAC[$fdbMAC] = $portLLID; // FDB MAC => pon port number + ONU LLID
  330. }
  331. }
  332. }
  333. if (!empty($fdbVLANIndex)) {
  334. // processing $fdbVLANIndex array to get FDB MAC => FDB VLAN mapping
  335. foreach ($fdbVLANIndex as $each => $eachIdx) {
  336. $line = explode('=', $eachIdx);
  337. // FDB VLAN is present
  338. if (isset($line[1])) {
  339. $fdbVLAN = trim($line[1]); // pon port number + ONU LLID
  340. $fdbMAC = trim(convertMACDec2Hex($line[0])); // FDB MAC in dotted DEC format
  341. $fdbIdxVLAN[$fdbMAC] = $fdbVLAN; // FDB MAC => FDB VLAN
  342. }
  343. }
  344. }
  345. if (!empty($onuMACIndex) and ! empty($fdbIdxMAC)) {
  346. foreach ($onuMACIndex as $eachLLID => $eachONUMAC) {
  347. $onuFDBIdxs = array_keys($fdbIdxMAC, $eachLLID);
  348. if (!empty($onuFDBIdxs)) {
  349. $tmpFDBArr = array();
  350. foreach ($onuFDBIdxs as $io => $eachFDBMAC) {
  351. if (empty($eachFDBMAC) or $eachFDBMAC == $eachONUMAC) {
  352. continue;
  353. } else {
  354. $tmpFDBVLAN = empty($fdbIdxVLAN[$eachFDBMAC]) ? '' : $fdbIdxVLAN[$eachFDBMAC];
  355. // not applicable with PON HAL now
  356. // i dont know nahooya this was here
  357. //$tmpONUID = $this->getONUIDByMAC($eachONUMAC);
  358. //$tmpONUID = (empty($tmpONUID)) ? $io : $tmpONUID;
  359. $tmpONUID = $io;
  360. $tmpFDBArr[$tmpONUID] = array('mac' => $eachFDBMAC, 'vlan' => $tmpFDBVLAN);
  361. }
  362. }
  363. $fdbCahce[$eachONUMAC] = $tmpFDBArr;
  364. }
  365. }
  366. }
  367. //saving OLT FDB
  368. $this->olt->writeFdb($fdbCahce);
  369. }
  370. /**
  371. * Parses & stores to cache ONUs FDB cache (MACs behind ONU) for "L" series VSOL OLTs
  372. *
  373. * @param $onuMACIndex
  374. * @param $fdbIndex
  375. * @param $fdbMACIndex
  376. * @param $fdbVLANIndex
  377. *
  378. * @return void
  379. */
  380. protected function fdbParseVSOL_L($onuMACIndex, $fdbIndex, $fdbMACIndex, $fdbVLANIndex) {
  381. $fdbIdxPosLLID = array();
  382. $fdbIdxMAC = array();
  383. $fdbIdxVLAN = array();
  384. $fdbCahce = array();
  385. if (!empty($fdbIndex)) {
  386. // processing FDBIndex array to get FDB MAC => pon port number + ONU LLID mapping
  387. foreach ($fdbIndex as $each => $eachIdx) {
  388. $line = explode('=', $eachIdx);
  389. // ONU LLID is present
  390. if (isset($line[1])) {
  391. $portLLID = trim(str_replace(array('"', 'EPON0/'), '', $line[1])); // pon port number + ONU LLID
  392. $portLLID = str_replace(':', '.', $portLLID);
  393. $fdbIdxPos = trim($line[0]); // FDB index position (integer) to look for in $fdbMACIndex & $fdbVLANIndex
  394. $fdbIdxPosLLID[$fdbIdxPos] = $portLLID; // FDB index position => pon port number + ONU LLID
  395. }
  396. }
  397. }
  398. if (!empty($fdbMACIndex)) {
  399. // processing $fdbVLANIndex array to get FDB MAC => FDB VLAN mapping
  400. foreach ($fdbMACIndex as $each => $eachIdx) {
  401. $line = explode('=', $eachIdx);
  402. // FDB VLAN is present
  403. if (isset($line[1])) {
  404. $fdbMAC = strtolower(str_replace(' ', ':', trim($line[1]))); // FDB MAC
  405. $fdbIdxPos = trim($line[0]); // FDB index position (integer)
  406. $fdbIdxMAC[$fdbIdxPos] = $fdbMAC; // FDB MAC => FDB VLAN
  407. }
  408. }
  409. }
  410. if (!empty($fdbVLANIndex)) {
  411. // processing $fdbVLANIndex array to get FDB MAC => FDB VLAN mapping
  412. foreach ($fdbVLANIndex as $each => $eachIdx) {
  413. $line = explode('=', $eachIdx);
  414. // FDB VLAN is present
  415. if (isset($line[1])) {
  416. $fdbVLAN = trim($line[1]); // FDB VLAN ID (integer)
  417. $fdbIdxPos = trim($line[0]); // FDB index position (integer)
  418. $fdbIdxVLAN[$fdbIdxPos] = $fdbVLAN; // FDB MAC => FDB VLAN
  419. }
  420. }
  421. }
  422. if (!empty($onuMACIndex) and !empty($fdbIdxPosLLID)) {
  423. foreach ($onuMACIndex as $eachLLID => $eachONUMAC) {
  424. $onuFDBIdxs = array_keys($fdbIdxPosLLID, $eachLLID);
  425. if (!empty($onuFDBIdxs)) {
  426. $tmpFDBArr = array();
  427. foreach ($onuFDBIdxs as $io => $eachFDBIdx) {
  428. if (empty($eachFDBIdx)) {
  429. continue;
  430. } else {
  431. $tmpFDBVLAN = (empty($fdbIdxVLAN[$eachFDBIdx]) ? '' : $fdbIdxVLAN[$eachFDBIdx]);
  432. $tmpFDBMAC = (empty($fdbIdxMAC[$eachFDBIdx]) ? '' : $fdbIdxMAC[$eachFDBIdx]);
  433. $tmpONUID = $io;
  434. $tmpFDBArr[$tmpONUID] = array('mac' => $tmpFDBMAC, 'vlan' => $tmpFDBVLAN);
  435. }
  436. }
  437. $fdbCahce[$eachONUMAC] = $tmpFDBArr;
  438. }
  439. }
  440. }
  441. //saving OLT FDB
  442. $this->olt->writeFdb($fdbCahce);
  443. }
  444. /**
  445. * Performs last dereg reason preprocessing for dereg reason/mac index arrays and stores it into cache
  446. *
  447. * @param $oltid
  448. * @param $LastDeregIndex
  449. * @param $macIndex
  450. * @param $snmpTemplate
  451. */
  452. protected function lastDeregParseVSOL($oltid, $LastDeregIndex, $macIndexProcessed) {
  453. $ONUDeRegs = array();
  454. $result = array();
  455. if (!empty($macIndexProcessed) and ! empty($LastDeregIndex)) {
  456. //last dereg index preprocessing
  457. foreach ($LastDeregIndex as $io => $eachRow) {
  458. $line = explode('=', $eachRow);
  459. if (empty($line[0]) || empty($line[1])) {
  460. continue;
  461. }
  462. $tmpONUPortLLID = trim($line[0]);
  463. $tmpONULastDeregReason = intval(trim($line[1]));
  464. switch ($tmpONULastDeregReason) {
  465. case 0:
  466. $TxtColor = '"#F80000"';
  467. $tmpONULastDeregReasonStr = 'Wire down';
  468. break;
  469. case 1:
  470. $TxtColor = '"#FF4400"';
  471. $tmpONULastDeregReasonStr = 'Power off';
  472. break;
  473. default:
  474. $TxtColor = '"#000000"';
  475. $tmpONULastDeregReasonStr = 'Unknown';
  476. break;
  477. }
  478. if (!empty($tmpONUPortLLID)) {
  479. $tmpONULastDeregReasonStr = wf_tag('font', false, '', 'color=' . $TxtColor . '') .
  480. $tmpONULastDeregReasonStr .
  481. wf_tag('font', true);
  482. $ONUDeRegs[$tmpONUPortLLID] = $tmpONULastDeregReasonStr;
  483. }
  484. }
  485. //storing results
  486. foreach ($macIndexProcessed as $devId => $eachMac) {
  487. if (isset($ONUDeRegs[$devId])) {
  488. $result[$eachMac] = $ONUDeRegs[$devId];
  489. }
  490. }
  491. //saving ONUs deregs reasons
  492. $this->olt->writeDeregs($result);
  493. }
  494. }
  495. }