api.ponbdcomgp.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237
  1. <?php
  2. /**
  3. * OLT BDCOM GPXXXX hardware abstraction layer
  4. */
  5. class PONBdcomGP extends PONBdcom {
  6. /**
  7. * Receives, preprocess and stores all required data from BDCOM GPXXXX OLT device
  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. $this->onuSerialCaseMode = (isset($this->snmpTemplates[$oltModelId]['misc']['SERIAL_CASE_MODE'])
  18. ? $this->snmpTemplates[$oltModelId]['misc']['SERIAL_CASE_MODE'] : 1);
  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. // ONU distance polling for bdcom devices
  25. if (isset($this->snmpTemplates[$oltModelId]['misc'])) {
  26. if (isset($this->snmpTemplates[$oltModelId]['misc']['DISTINDEX'])) {
  27. if (!empty($this->snmpTemplates[$oltModelId]['misc']['DISTINDEX'])) {
  28. $distIndexOid = $this->snmpTemplates[$oltModelId]['misc']['DISTINDEX'];
  29. $distIndex = $this->snmp->walk($oltIp . ':' . self::SNMPPORT, $oltCommunity, $distIndexOid, self::SNMPCACHE);
  30. $distIndex = str_replace($distIndexOid . '.', '', $distIndex);
  31. $distIndex = str_replace($this->snmpTemplates[$oltModelId]['misc']['DISTVALUE'], '', $distIndex);
  32. $distIndex = explodeRows($distIndex);
  33. $onuIndexOid = $this->snmpTemplates[$oltModelId]['misc']['ONUINDEX'];
  34. $onuIndex = $this->snmp->walk($oltIp . ':' . self::SNMPPORT, $oltCommunity, $onuIndexOid, self::SNMPCACHE);
  35. $onuIndex = str_replace($onuIndexOid . '.', '', $onuIndex);
  36. $onuIndex = str_replace($this->snmpTemplates[$oltModelId]['misc']['ONUVALUE'], '', $onuIndex);
  37. $onuIndex = str_replace('"', '', $onuIndex);
  38. $onuIndex = explodeRows($onuIndex);
  39. $intIndexOid = $this->snmpTemplates[$oltModelId]['misc']['INTERFACEINDEX'];
  40. $intIndex = $this->snmp->walk($oltIp . ':' . self::SNMPPORT, $oltCommunity, $intIndexOid, self::SNMPCACHE);
  41. $intIndex = str_replace($intIndexOid . '.', '', $intIndex);
  42. $intIndex = str_replace($this->snmpTemplates[$oltModelId]['misc']['INTERFACEVALUE'], '', $intIndex);
  43. $intIndex = explodeRows($intIndex);
  44. if (!$oltNoFDBQ) {
  45. $FDBIndexOid = $this->snmpTemplates[$oltModelId]['misc']['FDBINDEX'];
  46. $FDBIndex = $this->snmp->walk($oltIp . ':' . self::SNMPPORT, $oltCommunity, $FDBIndexOid, self::SNMPCACHE);
  47. $FDBIndex = str_replace($FDBIndexOid . '.', '', $FDBIndex);
  48. $FDBIndex = explodeRows($FDBIndex);
  49. }
  50. }
  51. }
  52. }
  53. // getting others system data from OLT
  54. if (isset($this->snmpTemplates[$oltModelId]['system'])) {
  55. // OLT uptime
  56. if (isset($this->snmpTemplates[$oltModelId]['system']['UPTIME'])) {
  57. $uptimeIndexOid = $this->snmpTemplates[$oltModelId]['system']['UPTIME'];
  58. $oltSystemUptimeRaw = $this->snmp->walk($oltIp . ':' . self::SNMPPORT, $oltCommunity, $uptimeIndexOid, self::SNMPCACHE);
  59. $this->uptimeParse($oltid, $oltSystemUptimeRaw);
  60. }
  61. // OLT temperature
  62. if (isset($this->snmpTemplates[$oltModelId]['system']['TEMPERATURE'])) {
  63. $temperatureIndexOid = $this->snmpTemplates[$oltModelId]['system']['TEMPERATURE'];
  64. $oltTemperatureRaw = $this->snmp->walk($oltIp . ':' . self::SNMPPORT, $oltCommunity, $temperatureIndexOid, self::SNMPCACHE);
  65. $this->temperatureParse($oltid, $oltTemperatureRaw);
  66. }
  67. }
  68. // getting MAC index.
  69. $macIndexOID = $this->snmpTemplates[$oltModelId]['signal']['MACINDEX'];
  70. $macIndex = $this->snmp->walk($oltIp . ':' . self::SNMPPORT, $oltCommunity, $macIndexOID, self::SNMPCACHE);
  71. $macIndex = str_replace($macIndexOID . '.', '', $macIndex);
  72. $macIndex = str_replace($this->snmpTemplates[$oltModelId]['signal']['MACVALUE'], '', $macIndex);
  73. $macIndex = str_replace('"', '', $macIndex);
  74. $macIndex = explodeRows($macIndex);
  75. // Start proccesing for get ONU id and MAC
  76. $this->onuMacProcessing($macIndex);
  77. $this->onuDevIndexProcessing($onuIndex);
  78. $this->signalParse($oltid, $sigIndex, $macIndex, $this->snmpTemplates[$oltModelId]['signal']);
  79. // This is here because BDCOM is BDCOM and another snmp queries cant be processed after MACINDEX query in some cases.
  80. if (isset($this->snmpTemplates[$oltModelId]['misc'])) {
  81. if (isset($this->snmpTemplates[$oltModelId]['misc']['DISTINDEX'])) {
  82. if (!empty($this->snmpTemplates[$oltModelId]['misc']['DISTINDEX'])) {
  83. // processing distance data
  84. $this->distanceParseGPBd($distIndex, $onuIndex);
  85. // processing interfaces data
  86. $this->interfaceParseBd($intIndex);
  87. // processing FDB data
  88. if (!$oltNoFDBQ) {
  89. $this->FDBParseGPBd($FDBIndex, $oltModelId);
  90. }
  91. if (isset($this->snmpTemplates[$oltModelId]['misc']['DEREGREASON'])) {
  92. // processing last dereg reason data
  93. $this->lastDeregParseBd($deregIndex);
  94. }
  95. }
  96. }
  97. }
  98. }
  99. /**
  100. * Parses & stores in cache OLT ONU interfaces
  101. *
  102. * @param array $FDBIndex
  103. * @param array $oltModelId
  104. *
  105. * @return void
  106. */
  107. protected function FDBParseGPBd($FDBIndex, $oltModelId) {
  108. $TmpArr = array();
  109. $FDBTmp = array();
  110. $result = array();
  111. // fdb index preprocessing
  112. if ((!empty($FDBIndex)) and ( ! empty($this->macIndexProcessed))) {
  113. foreach ($FDBIndex as $io => $eachfdbRaw) {
  114. if (preg_match('/' . $this->snmpTemplates[$oltModelId]['misc']['FDBVALUE'] . '|INTEGER:/', $eachfdbRaw)) {
  115. $eachfdbRaw = str_replace(array($this->snmpTemplates[$oltModelId]['misc']['FDBVALUE'], 'INTEGER:'), '', $eachfdbRaw);
  116. $line = explode('=', $eachfdbRaw);
  117. // fdb is present
  118. if (isset($line[1])) {
  119. $devOID = trim($line[0]); // FDB last OID
  120. $lineRaw = trim($line[1]); // FDB
  121. $devline = explode('.', $devOID);
  122. $FDBvlan = trim($devline[1]); // Vlan
  123. $FDBnum = trim($devline[7]); // Count number of MAC
  124. if (preg_match('/^1/', $devOID)) {
  125. $FDBRaw = str_replace(' ', ':', $lineRaw);
  126. $FDBRaw = strtolower($FDBRaw);
  127. $TmpArr[$devOID]['mac'] = $FDBRaw;
  128. $TmpArr[$devOID]['vlan'] = $FDBvlan;
  129. $TmpArr[$devOID]['FDBnum'] = $FDBnum;
  130. } elseif (preg_match('/^2/', $devOID)) {
  131. $devIndexOid = substr_replace($devOID, '1', 0, 1);
  132. $TmpArr[$devIndexOid]['index'] = $lineRaw;
  133. } else {
  134. continue;
  135. }
  136. }
  137. }
  138. }
  139. if (!empty($TmpArr)) {
  140. // Crete tmp Ubilling PON FDB array
  141. foreach ($TmpArr as $io => $each) {
  142. if (count($each) == 4) {
  143. $FDBTmp[$each['index']][$each['FDBnum']]['mac'] = $each['mac'];
  144. $FDBTmp[$each['index']][$each['FDBnum']]['vlan'] = $each['vlan'];
  145. }
  146. }
  147. }
  148. // storing results
  149. foreach ($this->macIndexProcessed as $devId => $eachMac) {
  150. if (isset($FDBTmp[$devId])) {
  151. $fdb = $FDBTmp[$devId];
  152. $result[$eachMac] = $fdb;
  153. }
  154. }
  155. //saving FDB data
  156. $this->olt->writeFdb($result);
  157. }
  158. }
  159. /**
  160. * Parses & stores in cache OLT ONU distances
  161. *
  162. * @param array $distIndex
  163. * @param array $onuIndex
  164. *
  165. * @return void
  166. */
  167. protected function distanceParseGPBd($distIndex, $onuIndex) {
  168. $distTmp = array();
  169. $onuTmp = array();
  170. $result = array();
  171. // distance index preprocessing
  172. if ((!empty($distIndex)) and ( !empty($onuIndex))) {
  173. foreach ($distIndex as $io => $eachdist) {
  174. $line = explode('=', $eachdist);
  175. // distance is present
  176. if (isset($line[1])) {
  177. $distanceRaw = trim($line[1]); // distance
  178. $devIndex = trim($line[0]); // device index
  179. $distTmp[$devIndex] = $distanceRaw;
  180. }
  181. }
  182. // mac index preprocessing
  183. foreach ($onuIndex as $io => $eachmac) {
  184. $line = explode('=', $eachmac);
  185. // mac is present
  186. if (isset($line[1])) {
  187. $macRaw = trim($line[1]); //mac address
  188. $devIndex = trim($line[0]); //device index
  189. $macRaw = str_replace(' ', ':', $macRaw);
  190. $macRaw = strtolower($macRaw);
  191. $onuTmp[$devIndex] = $macRaw;
  192. }
  193. }
  194. // storing results
  195. if (!empty($onuTmp)) {
  196. foreach ($onuTmp as $devId => $eachMac) {
  197. if (isset($distTmp[$devId])) {
  198. $distance = $distTmp[$devId];
  199. if (!empty($distance)) {
  200. $distance_m = substr($distance, 0, -1);
  201. $distance_dm = substr($distance, -1);
  202. $result[$eachMac] = $distance_m . '.' . $distance_dm;
  203. } else {
  204. $result[$eachMac] = 0;
  205. }
  206. }
  207. }
  208. // saving ONUs distances
  209. $this->olt->writeDistances($result);
  210. // saving ONUs cache
  211. $this->olt->writeOnuCache($onuTmp);
  212. }
  213. }
  214. }
  215. }