api.ponbdcom.php 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445
  1. <?php
  2. /**
  3. * OLT BDCOM 36xx/33xx or Eltex and Extralink hardware abstraction layer
  4. */
  5. class PONBdcom extends PONProto {
  6. /**
  7. * Receives, preprocess and stores all required data from BDCOM 36xx/33xx or Eltex OLT device
  8. *
  9. * @return void
  10. */
  11. public function collect() {
  12. global $ubillingConfig;
  13. $this->ubConfig = $ubillingConfig;
  14. $this->onuUniStatusEnabled = $this->ubConfig->getAlterParam('PON_ONU_UNI_STATUS_ENABLED', false);
  15. $oltModelId = $this->oltParameters['MODELID'];
  16. $oltid = $this->oltParameters['ID'];
  17. $oltIp = $this->oltParameters['IP'];
  18. $oltCommunity = $this->oltParameters['COMMUNITY'];
  19. $oltNoFDBQ = $this->oltParameters['NOFDB'];
  20. $sigIndexOID = $this->snmpTemplates[$oltModelId]['signal']['SIGINDEX'];
  21. $sigIndex = $this->snmp->walk($oltIp . ':' . self::SNMPPORT, $oltCommunity, $sigIndexOID, self::SNMPCACHE);
  22. $sigIndex = str_replace($sigIndexOID . '.', '', $sigIndex);
  23. $sigIndex = str_replace($this->snmpTemplates[$oltModelId]['signal']['SIGVALUE'], '', $sigIndex);
  24. $sigIndex = explodeRows($sigIndex);
  25. $ifaceCustDescrIndex = array();
  26. // ONU distance polling for bdcom devices
  27. if (isset($this->snmpTemplates[$oltModelId]['misc'])) {
  28. if (isset($this->snmpTemplates[$oltModelId]['misc']['DISTINDEX'])) {
  29. if (!empty($this->snmpTemplates[$oltModelId]['misc']['DISTINDEX'])) {
  30. $distIndexOid = $this->snmpTemplates[$oltModelId]['misc']['DISTINDEX'];
  31. $distIndex = $this->snmp->walk($oltIp . ':' . self::SNMPPORT, $oltCommunity, $distIndexOid, self::SNMPCACHE);
  32. $distIndex = str_replace($distIndexOid . '.', '', $distIndex);
  33. $distIndex = str_replace($this->snmpTemplates[$oltModelId]['misc']['DISTVALUE'], '', $distIndex);
  34. $distIndex = explodeRows($distIndex);
  35. $onuIndexOid = $this->snmpTemplates[$oltModelId]['misc']['ONUINDEX'];
  36. $onuIndex = $this->snmp->walk($oltIp . ':' . self::SNMPPORT, $oltCommunity, $onuIndexOid, self::SNMPCACHE);
  37. $onuIndex = str_replace($onuIndexOid . '.', '', $onuIndex);
  38. $onuIndex = str_replace($this->snmpTemplates[$oltModelId]['misc']['ONUVALUE'], '', $onuIndex);
  39. $onuIndex = explodeRows($onuIndex);
  40. if (isset($this->snmpTemplates[$oltModelId]['misc']['DEREGREASON'])) {
  41. $deregIndexOid = $this->snmpTemplates[$oltModelId]['misc']['DEREGREASON'];
  42. $deregIndex = $this->snmp->walk($oltIp . ':' . self::SNMPPORT, $oltCommunity, $deregIndexOid, self::SNMPCACHE);
  43. $deregIndex = str_replace($deregIndexOid . '.', '', $deregIndex);
  44. $deregIndex = str_replace($this->snmpTemplates[$oltModelId]['misc']['DEREGVALUE'], '', $deregIndex);
  45. $deregIndex = explodeRows($deregIndex);
  46. }
  47. $intIndexOid = $this->snmpTemplates[$oltModelId]['misc']['INTERFACEINDEX'];
  48. $intIndex = $this->snmp->walk($oltIp . ':' . self::SNMPPORT, $oltCommunity, $intIndexOid, self::SNMPCACHE);
  49. $intIndex = str_replace($intIndexOid . '.', '', $intIndex);
  50. $intIndex = str_replace($this->snmpTemplates[$oltModelId]['misc']['INTERFACEVALUE'], '', $intIndex);
  51. $intIndex = explodeRows($intIndex);
  52. if (!$oltNoFDBQ) {
  53. $FDBIndexOid = $this->snmpTemplates[$oltModelId]['misc']['FDBINDEX'];
  54. $FDBIndex = $this->snmp->walk($oltIp . ':' . self::SNMPPORT, $oltCommunity, $FDBIndexOid, self::SNMPCACHE);
  55. $FDBIndex = str_replace($FDBIndexOid . '.', '', $FDBIndex);
  56. $FDBIndex = explodeRows($FDBIndex);
  57. }
  58. }
  59. }
  60. if (isset($this->snmpTemplates[$oltModelId]['misc']['IFACECUSTOMDESCR'])) {
  61. $ifaceCustDescrIndexOID = $this->snmpTemplates[$oltModelId]['misc']['IFACECUSTOMDESCR'];
  62. $ifaceCustDescrIndex = $this->snmp->walk($oltIp . ':' . self::SNMPPORT, $oltCommunity, $ifaceCustDescrIndexOID, self::SNMPCACHE);
  63. $ifaceCustDescrIndex = str_replace($ifaceCustDescrIndexOID . '.', '', $ifaceCustDescrIndex);
  64. $ifaceCustDescrIndex = str_replace(array($this->snmpTemplates[$oltModelId]['misc']['INTERFACEVALUE'], '"'), '', $ifaceCustDescrIndex);
  65. $ifaceCustDescrIndex = explodeRows($ifaceCustDescrIndex);
  66. }
  67. // Get UniOperStatusIndex
  68. if (isset($this->snmpTemplates[$oltModelId]['misc']['UNIOPERSTATUS']) and $this->onuUniStatusEnabled) {
  69. $uniOperStatusIndexOID = $this->snmpTemplates[$oltModelId]['misc']['UNIOPERSTATUS'];
  70. $uniOperStatusIndex = $this->snmp->walk($oltIp . ':' . self::SNMPPORT, $oltCommunity, $uniOperStatusIndexOID, self::SNMPCACHE);
  71. $uniOperStatusIndex = str_replace($uniOperStatusIndexOID . '.', '', $uniOperStatusIndex);
  72. $uniOperStatusIndex = str_replace(array($this->snmpTemplates[$oltModelId]['misc']['UNIOPERSTATUSVALUE'], '"'), '', $uniOperStatusIndex);
  73. $uniOperStatusIndex = explodeRows($uniOperStatusIndex);
  74. }
  75. }
  76. // getting other system data from OLT
  77. if (isset($this->snmpTemplates[$oltModelId]['system'])) {
  78. //OLT uptime
  79. if (isset($this->snmpTemplates[$oltModelId]['system']['UPTIME'])) {
  80. $uptimeIndexOid = $this->snmpTemplates[$oltModelId]['system']['UPTIME'];
  81. $oltSystemUptimeRaw = $this->snmp->walk($oltIp . ':' . self::SNMPPORT, $oltCommunity, $uptimeIndexOid, self::SNMPCACHE);
  82. $this->uptimeParse($oltid, $oltSystemUptimeRaw);
  83. }
  84. //OLT temperature
  85. if (isset($this->snmpTemplates[$oltModelId]['system']['TEMPERATURE'])) {
  86. $temperatureIndexOid = $this->snmpTemplates[$oltModelId]['system']['TEMPERATURE'];
  87. $oltTemperatureRaw = $this->snmp->walk($oltIp . ':' . self::SNMPPORT, $oltCommunity, $temperatureIndexOid, self::SNMPCACHE);
  88. $this->temperatureParse($oltid, $oltTemperatureRaw);
  89. }
  90. }
  91. // getting MAC index.
  92. $macIndexOID = $this->snmpTemplates[$oltModelId]['signal']['MACINDEX'];
  93. $macIndex = $this->snmp->walk($oltIp . ':' . self::SNMPPORT, $oltCommunity, $macIndexOID, self::SNMPCACHE);
  94. $macIndex = str_replace($macIndexOID . '.', '', $macIndex);
  95. $macIndex = str_replace($this->snmpTemplates[$oltModelId]['signal']['MACVALUE'], '', $macIndex);
  96. $macIndex = explodeRows($macIndex);
  97. $this->signalParse($oltid, $sigIndex, $macIndex, $this->snmpTemplates[$oltModelId]['signal']);
  98. // Start proccesing for get ONU id and MAC
  99. $this->onuMacProcessing($macIndex);
  100. $this->onuDevIndexProcessing($onuIndex);
  101. /**
  102. * This is here because BDCOM is BDCOM and another SNMP queries cant be processed after MACINDEX query in some cases.
  103. */
  104. if (isset($this->snmpTemplates[$oltModelId]['misc'])) {
  105. if (isset($this->snmpTemplates[$oltModelId]['misc']['DISTINDEX'])) {
  106. if (!empty($this->snmpTemplates[$oltModelId]['misc']['DISTINDEX'])) {
  107. // processing distance data
  108. $this->distanceParse($oltid, $distIndex, $onuIndex);
  109. // processing interfaces data and interface description data
  110. $this->interfaceParseBd($intIndex, $ifaceCustDescrIndex);
  111. // processing FDB data
  112. if (!$oltNoFDBQ) {
  113. if (isset($this->snmpTemplates[$oltModelId]['misc']['FDBMODE']) and $this->snmpTemplates[$oltModelId]['misc']['FDBMODE'] == 'FIRMWARE-F') {
  114. $this->FDBParseBdFirmwareF($FDBIndex, $oltModelId);
  115. } else {
  116. $this->FDBParseBd($FDBIndex, $oltModelId);
  117. }
  118. }
  119. // processing last dereg reason data
  120. if (isset($this->snmpTemplates[$oltModelId]['misc']['DEREGREASON'])) {
  121. $this->lastDeregParseBd($deregIndex);
  122. }
  123. // processing UniOperStauts
  124. if (isset($this->snmpTemplates[$oltModelId]['misc']['UNIOPERSTATUS']) and $this->onuUniStatusEnabled) {
  125. $this->uniParseBd($uniOperStatusIndex);
  126. }
  127. }
  128. }
  129. }
  130. }
  131. /**
  132. * Parses & stores in cache OLT ONU interfaces
  133. *
  134. * @param array $intIndex
  135. * @param array $ifaceCustDescrRaw
  136. *
  137. * @return void
  138. */
  139. protected function interfaceParseBd($intIndex, $ifaceCustDescrRaw = array()) {
  140. $intTmp = array();
  141. $result = array();
  142. $processIfaceCustDescr = ! empty($ifaceCustDescrRaw);
  143. $ifaceCustDescrIdx = array();
  144. $ifaceCustDescrArr = array();
  145. // olt iface descr extraction
  146. if ($processIfaceCustDescr) {
  147. foreach ($ifaceCustDescrRaw as $io => $each) {
  148. if (empty($each)) {
  149. continue;
  150. }
  151. $ifDescr = explode('=', str_replace(array(" ", "\t", "\n", "\r", "\0", "\x0B"), '', $each));
  152. if ((empty($ifDescr[0]) && empty($ifDescr[1])) || intval($ifDescr[0]) < 7) {
  153. continue;
  154. }
  155. if ($ifDescr[0] > 10) {
  156. break;
  157. }
  158. $ifaceCustDescrIdx[$ifDescr[0] - 6] = $ifDescr[1];
  159. }
  160. }
  161. // interface index preprocessing
  162. if ((! empty($intIndex)) and ( ! empty($this->macIndexProcessed))) {
  163. foreach ($intIndex as $io => $eachint) {
  164. $line = explode('=', $eachint);
  165. // interface is present
  166. if (isset($line[1])) {
  167. $interfaceRaw = trim($line[1]); // interface
  168. $devIndex = trim($line[0]); // device index
  169. $intTmp[$devIndex] = $interfaceRaw;
  170. }
  171. }
  172. // storing results
  173. foreach ($this->macIndexProcessed as $devId => $eachMac) {
  174. if (isset($intTmp[$devId])) {
  175. $interface = $intTmp[$devId];
  176. $result[$eachMac] = $interface;
  177. $cleanIface = strstr($interface, ':', true);
  178. $tPONIfaceNum = substr($cleanIface, -1, 1);
  179. if ($processIfaceCustDescr && !isset($ifaceCustDescrArr[$cleanIface]) && array_key_exists($tPONIfaceNum, $ifaceCustDescrIdx)) {
  180. $ifaceCustDescrArr[$cleanIface] = $ifaceCustDescrIdx[$tPONIfaceNum];
  181. }
  182. }
  183. }
  184. //saving interfaces cache as mac=>interface name
  185. $this->olt->writeInterfaces($result);
  186. //saving interfaces custom descriptions as interface=>desctription
  187. $this->olt->writeInterfacesDescriptions($ifaceCustDescrArr);
  188. }
  189. }
  190. /**
  191. * Parses & stores in cache OLT ONU interfaces
  192. *
  193. * @param array $FDBIndex
  194. * @param array $oltModelId
  195. *
  196. * @return void
  197. */
  198. protected function FDBParseBd($FDBIndex, $oltModelId) {
  199. $FDBTmp = array();
  200. $result = array();
  201. // fdb index preprocessing
  202. if ((! empty($FDBIndex)) and ( ! empty($this->macIndexProcessed))) {
  203. foreach ($FDBIndex as $io => $eachfdb) {
  204. if (preg_match('/' . $this->snmpTemplates[$oltModelId]['misc']['FDBVALUE'] . '/', $eachfdb)) {
  205. $eachfdb = str_replace($this->snmpTemplates[$oltModelId]['misc']['FDBVALUE'], '', $eachfdb);
  206. $line = explode('=', $eachfdb);
  207. // fdb is present
  208. if (isset($line[1])) {
  209. $FDBRaw = trim($line[1]); // FDB
  210. $devOID = trim($line[0]); // FDB last OID
  211. $devline = explode('.', $devOID);
  212. $devIndex = trim($devline[0]); // FDB index
  213. $FDBvlan = trim($devline[1]); // Vlan
  214. $FDBnum = trim($devline[7]); // Count number of MAC
  215. $FDBRaw = str_replace(' ', ':', $FDBRaw);
  216. $FDBRaw = strtolower($FDBRaw);
  217. $FDBTmp[$devIndex][$FDBnum]['mac'] = $FDBRaw;
  218. $FDBTmp[$devIndex][$FDBnum]['vlan'] = $FDBvlan;
  219. }
  220. }
  221. }
  222. // storing results
  223. foreach ($this->macIndexProcessed as $devId => $eachMac) {
  224. if (isset($FDBTmp[$devId])) {
  225. $fdb = $FDBTmp[$devId];
  226. $result[$eachMac] = $fdb;
  227. }
  228. }
  229. //saving FDB cache
  230. $this->olt->writeFdb($result);
  231. }
  232. }
  233. /**
  234. * Parses & stores in cache OLT FDB
  235. *
  236. * @param array $FDBIndex
  237. * @param array $oltModelId
  238. *
  239. * @return void
  240. */
  241. protected function FDBParseBdFirmwareF($FDBIndex, $oltModelId) {
  242. $TmpArr = array();
  243. $FDBTmp = array();
  244. $result = array();
  245. //fdb index preprocessing
  246. if ((! empty($FDBIndex)) and ( ! empty($this->macIndexProcessed))) {
  247. foreach ($FDBIndex as $io => $eachfdbRaw) {
  248. if (preg_match('/' . $this->snmpTemplates[$oltModelId]['misc']['FDBVALUE'] . '|INTEGER:/', $eachfdbRaw)) {
  249. $eachfdbRaw = str_replace(array($this->snmpTemplates[$oltModelId]['misc']['FDBVALUE'], 'INTEGER:'), '', $eachfdbRaw);
  250. $line = explode('=', $eachfdbRaw);
  251. //fdb is present
  252. if (isset($line[1])) {
  253. $devOID = trim($line[0]); // FDB last OID
  254. $lineRaw = trim($line[1]); // FDB
  255. $devline = explode('.', $devOID);
  256. $FDBvlan = trim($devline[1]); // Vlan
  257. $FDBnum = trim($devline[7]); // Count number of MAC
  258. if (preg_match('/^1/', $devOID)) {
  259. $FDBRaw = str_replace(' ', ':', $lineRaw);
  260. $FDBRaw = strtolower($FDBRaw);
  261. $TmpArr[$devOID]['mac'] = $FDBRaw;
  262. $TmpArr[$devOID]['vlan'] = $FDBvlan;
  263. $TmpArr[$devOID]['FDBnum'] = $FDBnum;
  264. } elseif (preg_match('/^2/', $devOID)) {
  265. $devIndexOid = substr_replace($devOID, '1', 0, 1);
  266. $TmpArr[$devIndexOid]['index'] = $lineRaw;
  267. } else {
  268. continue;
  269. }
  270. }
  271. }
  272. }
  273. if (!empty($TmpArr)) {
  274. // Crete tmp Ubilling PON FDB array
  275. foreach ($TmpArr as $io => $each) {
  276. if (count($each) == 4) {
  277. $FDBTmp[$each['index']][$each['FDBnum']]['mac'] = $each['mac'];
  278. $FDBTmp[$each['index']][$each['FDBnum']]['vlan'] = $each['vlan'];
  279. }
  280. }
  281. }
  282. //storing results
  283. foreach ($this->macIndexProcessed as $devId => $eachMac) {
  284. if (isset($FDBTmp[$devId])) {
  285. $fdb = $FDBTmp[$devId];
  286. $result[$eachMac] = $fdb;
  287. }
  288. }
  289. //saving FDB cache
  290. $this->olt->writeFDB($result);
  291. }
  292. }
  293. /**
  294. * Parses & stores in cache OLT ONU dereg reaesons
  295. *
  296. * @param array $distIndex
  297. *
  298. * @return void
  299. */
  300. protected function lastDeregParseBd($deregIndex) {
  301. $result = array();
  302. //dereg index preprocessing
  303. if ((!empty($deregIndex)) and ( !empty($this->onuDevIndexProcessed))) {
  304. foreach ($deregIndex as $io => $eachdereg) {
  305. $line = explode('=', $eachdereg);
  306. //dereg is present
  307. if (isset($line[1])) {
  308. $deregRaw = trim($line[1]); // dereg
  309. $devIndex = trim($line[0]); // device index
  310. switch ($deregRaw) {
  311. case 2:
  312. $TxtColor = '"#00B20E"';
  313. $tmpONULastDeregReasonStr = 'Normal';
  314. break;
  315. case 3:
  316. $TxtColor = '"#F80000"';
  317. $tmpONULastDeregReasonStr = 'MPCP down';
  318. break;
  319. case 4:
  320. $TxtColor = '"#F80000"';
  321. $tmpONULastDeregReasonStr = 'OAM down';
  322. break;
  323. case 5:
  324. $TxtColor = '"#6500FF"';
  325. $tmpONULastDeregReasonStr = 'Firmware download';
  326. break;
  327. case 6:
  328. $TxtColor = '"#F80000"';
  329. $tmpONULastDeregReasonStr = 'Illegal MAC';
  330. break;
  331. case 7:
  332. $TxtColor = '"#FF4400"';
  333. $tmpONULastDeregReasonStr = 'LLID admin down';
  334. break;
  335. case 8:
  336. $TxtColor = '"#F80000"';
  337. $tmpONULastDeregReasonStr = 'Wire down';
  338. break;
  339. case 9:
  340. $TxtColor = '"#6500FF"';
  341. $tmpONULastDeregReasonStr = 'Power off';
  342. break;
  343. default:
  344. $TxtColor = '"#000000"';
  345. $tmpONULastDeregReasonStr = 'Unknown';
  346. break;
  347. }
  348. $tmpONULastDeregReasonStr = wf_tag('font', false, '', 'color=' . $TxtColor . '') .
  349. $tmpONULastDeregReasonStr .
  350. wf_tag('font', true);
  351. if (isset($this->onuDevIndexProcessed[$devIndex])) {
  352. $result[$this->onuDevIndexProcessed[$devIndex]] = $tmpONULastDeregReasonStr;
  353. }
  354. }
  355. }
  356. //saving dereg reasons cache
  357. $this->olt->writeDeregs($result);
  358. }
  359. }
  360. /**
  361. * Performs UNI port oper status preprocessing for index array and stores it into cache
  362. *
  363. * @param $uniOperStatusIndex
  364. *
  365. * @return void
  366. */
  367. protected function uniParseBd($uniOperStatusIndex) {
  368. $result = array();
  369. if (! empty($this->macIndexProcessed) and ! empty($uniOperStatusIndex)) {
  370. foreach ($uniOperStatusIndex as $io => $eachRow) {
  371. $line = explode('=', $eachRow);
  372. if (empty($line[0]) || empty($line[1])) {
  373. continue;
  374. }
  375. // LLID + ether port index
  376. $tmpLLIDEtherIdx = trim($line[0]);
  377. $tmpLLIDEtherIdx = ltrim($tmpLLIDEtherIdx, '.');
  378. $tmpLLIDEtherIdxLen = strlen($tmpLLIDEtherIdx);
  379. // ehter port index
  380. $tmpEtherIdx = strrchr($tmpLLIDEtherIdx, '.');
  381. $tmpEtherIdxLen = strlen($tmpEtherIdx);
  382. $tmpEtherIdx = 'eth' . trim($tmpEtherIdx, '.');
  383. //LLID
  384. $tmpONUPortLLID = substr($tmpLLIDEtherIdx, 0, $tmpLLIDEtherIdxLen - $tmpEtherIdxLen);
  385. $tmpUniStatus = trim($line[1]);
  386. $tmpUniStatus = ($tmpUniStatus == 1) ? 1 : 0;
  387. if (isset($this->macIndexProcessed[$tmpONUPortLLID])) {
  388. $result[$this->macIndexProcessed[$tmpONUPortLLID]][$tmpEtherIdx] = $tmpUniStatus;
  389. }
  390. }
  391. //saving UniOperStats
  392. $this->olt->writeUniOperStats($result);
  393. }
  394. }
  395. }