api.pongcomel5610.php 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508
  1. <?php
  2. /**
  3. * OLT GCOM EL5610 EPON hardware abstraction layer
  4. */
  5. class PONGCOMEL5610 extends PONProto {
  6. /**
  7. * Receives, preprocess and stores all required data from OLT
  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. $sigIndex = $this->walkCleared($oltIPPORT, $oltCommunity,
  19. $this->snmpTemplates[$oltModelId]['signal']['SIGINDEX'],
  20. '',
  21. array($this->snmpTemplates[$oltModelId]['signal']['SIGVALUE'], '"'), self::SNMPCACHE);
  22. $macIndex = $this->walkCleared($oltIPPORT, $oltCommunity,
  23. $this->snmpTemplates[$oltModelId]['signal']['MACINDEX'],
  24. '',
  25. $this->snmpTemplates[$oltModelId]['signal']['MACVALUE'], self::SNMPCACHE);
  26. $gcomeMACsProcessed = $this->macParseGCOME($macIndex);
  27. if (!empty($gcomeMACsProcessed)) {
  28. $this->signalParseGCOME($sigIndex, $gcomeMACsProcessed);
  29. $distIndex = $this->walkCleared($oltIPPORT, $oltCommunity,
  30. $this->snmpTemplates[$oltModelId]['misc']['DISTINDEX'],
  31. '',
  32. $this->snmpTemplates[$oltModelId]['misc']['DISTVALUE'], self::SNMPCACHE);
  33. $this->distanceParseGCOME($distIndex, $gcomeMACsProcessed);
  34. $ifaceIndex = $this->walkCleared($oltIPPORT, $oltCommunity,
  35. $this->snmpTemplates[$oltModelId]['misc']['IFACEDESCR'],
  36. '',
  37. array($this->snmpTemplates[$oltModelId]['misc']['IFACEVALUE'], '"'), self::SNMPCACHE);
  38. $ifaceCustDescrIndex = array();
  39. if (isset($this->snmpTemplates[$oltModelId]['misc']['IFACECUSTOMDESCR'])) {
  40. $ifaceCustDescrIndex = $this->walkCleared($oltIPPORT, $oltCommunity,
  41. $this->snmpTemplates[$oltModelId]['misc']['IFACECUSTOMDESCR'],
  42. '',
  43. array($this->snmpTemplates[$oltModelId]['misc']['IFACEVALUE'], '"'), self::SNMPCACHE);
  44. }
  45. $this->interfaceParseGCOME($ifaceIndex, $gcomeMACsProcessed, $ifaceCustDescrIndex);
  46. $lastDeregIndex = $this->walkCleared($oltIPPORT, $oltCommunity,
  47. $this->snmpTemplates[$oltModelId]['misc']['DEREGREASON'],
  48. '',
  49. $this->snmpTemplates[$oltModelId]['misc']['DEREGVALUE'], self::SNMPCACHE);
  50. $this->lastDeregParseGCOME($lastDeregIndex, $gcomeMACsProcessed);
  51. if (!$oltNoFDBQ) {
  52. // for some reason fdbVLANIndex for this OLT should be queried first
  53. // to prevent losing of the very first record from fdbVLANIndex
  54. $fdbVLANIndex = $this->walkCleared($oltIPPORT, $oltCommunity,
  55. $this->snmpTemplates[$oltModelId]['misc']['FDBVLANINDEX'],
  56. '',
  57. $this->snmpTemplates[$oltModelId]['misc']['FDBVLANVALUE'], self::SNMPCACHE);
  58. $fdbIndex = $this->walkCleared($oltIPPORT, $oltCommunity,
  59. $this->snmpTemplates[$oltModelId]['misc']['FDBMACINDEX'],
  60. '',
  61. $this->snmpTemplates[$oltModelId]['misc']['FDBMACVALUE'], self::SNMPCACHE);
  62. $this->fdbParseGCOME($gcomeMACsProcessed, $fdbIndex, $fdbVLANIndex);
  63. }
  64. $uniOperStatusIndex = array();
  65. if (isset($this->snmpTemplates[$oltModelId]['misc']['UNIOPERSTATUS'])) {
  66. $uniOperStatusIndex = $this->walkCleared($oltIPPORT, $oltCommunity,
  67. $this->snmpTemplates[$oltModelId]['misc']['UNIOPERSTATUS'],
  68. '',
  69. array($this->snmpTemplates[$oltModelId]['misc']['UNIOPERSTATUSVALUE'], '"'), self::SNMPCACHE);
  70. $this->uniParseGCOME($uniOperStatusIndex, $gcomeMACsProcessed);
  71. }
  72. }
  73. //getting others system data from OLT
  74. if (isset($this->snmpTemplates[$oltModelId]['system'])) {
  75. //OLT uptime
  76. if (isset($this->snmpTemplates[$oltModelId]['system']['UPTIME'])) {
  77. $uptimeIndexOid = $this->snmpTemplates[$oltModelId]['system']['UPTIME'];
  78. $oltSystemUptimeRaw = $this->snmp->walk($oltIPPORT, $oltCommunity, $uptimeIndexOid, self::SNMPCACHE);
  79. $this->uptimeParse($oltid, $oltSystemUptimeRaw);
  80. }
  81. //OLT temperature
  82. if (isset($this->snmpTemplates[$oltModelId]['system']['TEMPERATURE'])) {
  83. $temperatureIndexOid = $this->snmpTemplates[$oltModelId]['system']['TEMPERATURE'];
  84. $oltTemperatureRaw = $this->snmp->walk($oltIPPORT, $oltCommunity, $temperatureIndexOid, self::SNMPCACHE);
  85. $this->temperatureParse($oltid, $oltTemperatureRaw);
  86. }
  87. }
  88. }
  89. /**
  90. * Processes OLT MAC adresses and returns them in array: LLID=>MAC
  91. *
  92. * @param $macIndex
  93. *
  94. * @return array
  95. */
  96. protected function macParseGCOME($macIndex) {
  97. $ONUsMACs = array();
  98. if (!empty($macIndex)) {
  99. //mac index preprocessing
  100. foreach ($macIndex as $io => $eachmac) {
  101. $line = explode('=', $eachmac);
  102. if (empty($line[0]) || empty($line[1])) {
  103. continue;
  104. }
  105. $tmpONUPortLLID = trim($line[0]);
  106. $tmpONUMAC = strtolower(AddMacSeparator(RemoveMacAddressSeparator(trim($line[1]), array(':', '-', '.', ' ')))); //mac address
  107. //mac is present
  108. if (!empty($tmpONUPortLLID) and ! empty($tmpONUMAC)) {
  109. $ONUsMACs[$tmpONUPortLLID] = $tmpONUMAC;
  110. }
  111. }
  112. }
  113. return ($ONUsMACs);
  114. }
  115. /**
  116. * Performs signal preprocessing for sig/mac index arrays and stores it into cache
  117. *
  118. * @param array $sigIndex
  119. * @param array $macIndexProcessed
  120. *
  121. * @return void
  122. */
  123. protected function signalParseGCOME($sigIndex, $macIndexProcessed) {
  124. $ONUsModulesTemps = array();
  125. $ONUsModulesVoltages = array();
  126. $ONUsModulesCurrents = array();
  127. $ONUsSignals = array();
  128. $result = array();
  129. $macDevID = array();
  130. $curDate = curdatetime();
  131. //signal index preprocessing
  132. if ((!empty($sigIndex)) and ( !empty($macIndexProcessed))) {
  133. foreach ($sigIndex as $io => $eachsig) {
  134. if (empty($eachsig) or !ispos($eachsig, '=')) { continue; }
  135. $line = explode('=', $eachsig);
  136. //signal is present
  137. if (isset($line[0])) {
  138. $tmpONUPortLLID = trim($line[0]);
  139. $SignalRaw = trim($line[1]);
  140. // $ONUsSignals[$tmpONUPortLLID]['SignalRXRaw'] = trim($SignalRaw, '"');
  141. // $ONUsSignals[$tmpONUPortLLID]['SignalRXdBm'] = trim(substr(stristr(stristr(stristr($SignalRaw, '('), ')', true), 'dBm', true), 1));
  142. $ONUsSignals[$tmpONUPortLLID]['SignalRXdBm'] = trim($SignalRaw);
  143. }
  144. }
  145. //storing results
  146. foreach ($macIndexProcessed as $devId => $eachMac) {
  147. if (isset($ONUsSignals[$devId])) {
  148. //signal history filling
  149. $signal = $ONUsSignals[$devId]['SignalRXdBm'];
  150. if (!empty($signal)) {
  151. $signal = round($signal, 2);
  152. $result[$eachMac] = $signal;
  153. }
  154. if (empty($signal) or $signal == 'Offline') {
  155. $signal = $this->onuOfflineSignalLevel; //over 9000 offline signal level :P
  156. }
  157. //saving each ONU signal history
  158. $this->olt->writeSignalHistory($eachMac, $signal);
  159. }
  160. }
  161. $macDevID = array_flip($macIndexProcessed);
  162. //writing signals cache
  163. $this->olt->writeSignals($result);
  164. //saving ONU cache
  165. $this->olt->writeOnuCache($macIndexProcessed);
  166. // saving macindex as MAC => devID
  167. $this->olt->writeMacIndex($macDevID);
  168. }
  169. }
  170. /**
  171. * Performs distance preprocessing for distance/mac index arrays and stores it into cache
  172. *
  173. * @param $DistIndex
  174. * @param $macIndexProcessed
  175. */
  176. protected function distanceParseGCOME($DistIndex, $macIndexProcessed) {
  177. $ONUDistances = array();
  178. $result = array();
  179. if (!empty($macIndexProcessed) and ! empty($DistIndex)) {
  180. //last dereg index preprocessing
  181. foreach ($DistIndex as $io => $eachRow) {
  182. $line = explode('=', $eachRow);
  183. if (empty($line[0]) || empty($line[1])) {
  184. continue;
  185. }
  186. $tmpONUPortLLID = trim($line[0]);
  187. $tmpONUDistance = trim($line[1]);
  188. $ONUDistances[$tmpONUPortLLID] = $tmpONUDistance;
  189. }
  190. //storing results
  191. foreach ($macIndexProcessed as $devId => $eachMac) {
  192. if (isset($ONUDistances[$devId])) {
  193. $result[$eachMac] = $ONUDistances[$devId];
  194. }
  195. }
  196. //saving distances
  197. $this->olt->writeDistances($result);
  198. }
  199. }
  200. /**
  201. * Performs interface preprocessing for interface/mac index arrays and stores it into cache
  202. *
  203. * @param $IfaceIndex
  204. * @param $macIndexProcessed
  205. * @param $ifaceCustDescrRaw
  206. *
  207. * @return void
  208. */
  209. protected function interfaceParseGCOME($IfaceIndex, $macIndexProcessed, $ifaceCustDescrRaw = array()) {
  210. $ONUIfaces = array();
  211. $result = array();
  212. $processIfaceCustDescr = !empty($ifaceCustDescrRaw);
  213. $ifaceCustDescrIdx = array();
  214. $ifaceCustDescrArr = array();
  215. // olt iface descr extraction
  216. if ($processIfaceCustDescr) {
  217. foreach ($ifaceCustDescrRaw as $io => $each) {
  218. if (empty($each)) {
  219. continue;
  220. }
  221. $ifDescr = explode('=', str_replace(array(" ", "\t", "\n", "\r", "\0", "\x0B"), '', $each));
  222. if (empty($ifDescr[0]) && empty($ifDescr[1])) {
  223. continue;
  224. }
  225. $ifaceCustDescrIdx[$ifDescr[0]] = $ifDescr[1];
  226. }
  227. }
  228. if (!empty($macIndexProcessed) and ! empty($IfaceIndex)) {
  229. //OLT iface index preprocessing
  230. foreach ($IfaceIndex as $io => $eachRow) {
  231. if (empty($eachRow)) {
  232. continue;
  233. }
  234. $line = explode('=', str_replace(array(" ", "\t", "\n", "\r", "\0", "\x0B"), '', $eachRow));
  235. if (empty($line[0]) || empty($line[1]) || trim($line[0]) < 9) {
  236. continue;
  237. }
  238. $tmpONUPortLLID = trim($line[0]) - 8; // some shitty math
  239. $tmpONUIface = trim($line[1]);
  240. $ONUIfaces[$tmpONUPortLLID] = $tmpONUIface;
  241. }
  242. //storing results
  243. foreach ($macIndexProcessed as $devId => $eachMac) {
  244. $tPONIfaceNum = substr($devId, 0, 1);
  245. if (array_key_exists($tPONIfaceNum, $ONUIfaces)) {
  246. $tPONIfaceName = $ONUIfaces[$tPONIfaceNum];
  247. $tPONIfaceStr = $tPONIfaceName . ' / ' . str_replace('.', ':', $devId);
  248. $cleanIface = strstr($tPONIfaceStr, ':', true);
  249. if ($processIfaceCustDescr && !isset($ifaceCustDescrArr[$cleanIface]) && array_key_exists($tPONIfaceNum, $ifaceCustDescrIdx)) {
  250. $ifaceCustDescrArr[$cleanIface] = $ifaceCustDescrIdx[$tPONIfaceNum];
  251. }
  252. } else {
  253. $tPONIfaceStr = str_replace('.', ':', $devId);
  254. }
  255. $result[$eachMac] = $tPONIfaceStr;
  256. }
  257. //saving ONU interfaces and interfaces descriptions
  258. $this->olt->writeInterfaces($result);
  259. $this->olt->writeInterfacesDescriptions($ifaceCustDescrArr);
  260. }
  261. }
  262. /**
  263. * Parses & stores to cache ONUs FDB cache (MACs behind ONU)
  264. *
  265. * @param $onuMACIndex
  266. * @param $fdbIndex
  267. * @param $fdbVLANIndex
  268. *
  269. * @return void
  270. */
  271. protected function fdbParseGCOME($onuMACIndex, $fdbIndex, $fdbVLANIndex) {
  272. if (!empty($onuMACIndex)) {
  273. $fdbDevIdxMAC = array();
  274. $fdbIdxVLAN = array();
  275. $fdbCahce = array();
  276. if (!empty($fdbIndex)) {
  277. // processing FDBIndex array to get pon [port number + ONU LLID + dev idx => FDB MAC] mapping
  278. foreach ($fdbIndex as $each => $eachIdx) {
  279. $line = explode('=', $eachIdx);
  280. // FDB MAC is present
  281. if (isset($line[1])) {
  282. $fdbMAC = trim(str_replace(array('"', 'STRING:', 'dev/ro'), '', $line[1]));
  283. if (empty($fdbMAC)) continue;
  284. $fdbMAC = strtolower(AddMacSeparator(RemoveMacAddressSeparator($fdbMAC, array(':', '-', '.', ' ')))); // FDB MAC in space-separated format
  285. $portLLIDDevIdx = trim($line[0]); // pon port number + ONU LLID + dev idx
  286. //$portLLID = substr($portLLIDDevIdx, 0, 3); // pon port number + ONU LLID
  287. $fdbDevIdxMAC[$portLLIDDevIdx] = $fdbMAC; // pon port number + ONU LLID + dev idx => FDB MAC
  288. //$fdbIdxMAC[$fdbMAC] = $portLLID; // FDB MAC => pon port number + ONU LLID
  289. }
  290. }
  291. }
  292. if (!empty($fdbVLANIndex)) {
  293. // processing $fdbVLANIndex array to get [pon port number + ONU LLID + dev idx mapping => FDB VLAN] mapping
  294. foreach ($fdbVLANIndex as $each => $eachIdx) {
  295. $line = explode('=', $eachIdx);
  296. // FDB VLAN is present
  297. if (isset($line[1])) {
  298. $fdbVLAN = trim($line[1]); // FDB VLAN
  299. $portLLIDDevIdx = trim($line[0]); // pon port number + ONU LLID + dev idx
  300. $fdbIdxVLAN[$portLLIDDevIdx] = $fdbVLAN; // pon port number + ONU LLID + dev idx => FDB MAC
  301. }
  302. }
  303. }
  304. if (!empty($fdbDevIdxMAC)) {
  305. // processing $fdbIdxMAC and $fdbIdxVLAN to prepare [pon port number + ONU LLID => ['mac' => $eachFDBMAC, 'vlan' => $tmpFDBVLAN]] array
  306. foreach ($fdbDevIdxMAC as $eachPortLLIDDevIdx => $eachFDBMAC) {
  307. $portLLID = substr($eachPortLLIDDevIdx, 0, 3);
  308. $devIdx = substr($eachPortLLIDDevIdx, -1, 1);
  309. $tmpFDBVLAN = empty($fdbIdxVLAN[$eachPortLLIDDevIdx]) ? '' : $fdbIdxVLAN[$eachPortLLIDDevIdx];
  310. $fdbMACVLAN[$portLLID][$devIdx] = array('mac' => $eachFDBMAC, 'vlan' => $tmpFDBVLAN);
  311. }
  312. if (!empty($fdbMACVLAN)) {
  313. foreach ($onuMACIndex as $eachLLID => $eachONUMAC) {
  314. if (!empty($fdbMACVLAN[$eachLLID])) {
  315. $fdbCahce[$eachONUMAC] = $fdbMACVLAN[$eachLLID];
  316. }
  317. }
  318. }
  319. }
  320. //saving OLT FDB
  321. $this->olt->writeFdb($fdbCahce);
  322. }
  323. }
  324. /**
  325. * Performs last dereg reason preprocessing for dereg reason/mac index arrays and stores it into cache
  326. *
  327. * @param $LastDeregIndex
  328. * @param $macIndexProcessed
  329. *
  330. * @return void
  331. */
  332. protected function lastDeregParseGCOME($LastDeregIndex, $macIndexProcessed) {
  333. $ONUDeRegs = array();
  334. $result = array();
  335. if (!empty($macIndexProcessed) and ! empty($LastDeregIndex)) {
  336. //last dereg index preprocessing
  337. foreach ($LastDeregIndex as $io => $eachRow) {
  338. $line = explode('=', $eachRow);
  339. if (empty($line[0]) || empty($line[1])) {
  340. continue;
  341. }
  342. $tmpONUPortLLID = trim($line[0]);
  343. $tmpONULastDeregReason = intval(trim($line[1]));
  344. switch ($tmpONULastDeregReason) {
  345. case 1:
  346. $TxtColor = '"#F80000"';
  347. $tmpONULastDeregReasonStr = 'Wire down';
  348. break;
  349. case 3:
  350. $TxtColor = '"#FF4400"';
  351. $tmpONULastDeregReasonStr = 'Power off';
  352. break;
  353. default:
  354. $TxtColor = '"#000000"';
  355. $tmpONULastDeregReasonStr = 'Unknown';
  356. break;
  357. }
  358. if (!empty($tmpONUPortLLID)) {
  359. $tmpONULastDeregReasonStr = wf_tag('font', false, '', 'color=' . $TxtColor . '') .
  360. $tmpONULastDeregReasonStr .
  361. wf_tag('font', true);
  362. $ONUDeRegs[$tmpONUPortLLID] = $tmpONULastDeregReasonStr;
  363. }
  364. }
  365. //storing results
  366. foreach ($macIndexProcessed as $devId => $eachMac) {
  367. if (isset($ONUDeRegs[$devId])) {
  368. $result[$eachMac] = $ONUDeRegs[$devId];
  369. }
  370. }
  371. //saving ONUs deregs reasons
  372. $this->olt->writeDeregs($result);
  373. }
  374. }
  375. /**
  376. * Performs UNI port oper status preprocessing for index array and stores it into cache
  377. *
  378. * @param $uniOperStatusIndex
  379. * @param $macIndexProcessed
  380. *
  381. * @return void
  382. */
  383. protected function uniParseGCOME($uniOperStatusIndex, $macIndexProcessed) {
  384. $uniStats = array();
  385. $result = array();
  386. if (!empty($macIndexProcessed) and !empty($uniOperStatusIndex)) {
  387. //UniOperStats index preprocessing
  388. foreach ($uniOperStatusIndex as $io => $eachRow) {
  389. $line = explode('=', $eachRow);
  390. if (empty($line[0]) || empty($line[1])) {
  391. continue;
  392. }
  393. // LLID + ether port index
  394. $tmpLLIDEtherIdx = trim($line[0]);
  395. $tmpLLIDEtherIdxLen = strlen($tmpLLIDEtherIdx);
  396. // ehter port index
  397. $tmpEtherIdx = strrchr($tmpLLIDEtherIdx, '.');
  398. $tmpEtherIdxLen = strlen($tmpEtherIdx);
  399. $tmpEtherIdx = 'eth' . trim($tmpEtherIdx, '.');
  400. //LLID
  401. $tmpONUPortLLID = substr($tmpLLIDEtherIdx, 0, $tmpLLIDEtherIdxLen - $tmpEtherIdxLen);
  402. $tmpUniStatus = trim($line[1]);
  403. $uniStats[$tmpONUPortLLID] = array($tmpEtherIdx => $tmpUniStatus);
  404. }
  405. //storing results
  406. foreach ($macIndexProcessed as $devId => $eachMac) {
  407. if (isset($uniStats[$devId])) {
  408. $result[$eachMac] = $uniStats[$devId];
  409. }
  410. }
  411. //saving UniOperStats
  412. $this->olt->writeUniOperStats($result);
  413. }
  414. }
  415. }