api.ponstels11.php 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378
  1. <?php
  2. /**
  3. * OLT Stels FD11XX hardware abstraction layer
  4. */
  5. class PONStels11 extends PONStels12 {
  6. /**
  7. * Receives, preprocess and stores all required data from Stels FD11XX or 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. $ponPrefixAdd = (empty($this->snmpTemplates[$oltModelId]['misc']['INTERFACEADDPONPREFIX'])
  18. ? '' : $this->snmpTemplates[$oltModelId]['misc']['INTERFACEADDPONPREFIX']);
  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. $this->signalParseStels($oltid, $sigIndex, $macIndex, $this->snmpTemplates[$oltModelId]['signal'], $ponPrefixAdd);
  30. //ONU distance polling for stels devices
  31. if (isset($this->snmpTemplates[$oltModelId]['misc'])) {
  32. if (isset($this->snmpTemplates[$oltModelId]['misc']['DISTINDEX'])) {
  33. if (!empty($this->snmpTemplates[$oltModelId]['misc']['DISTINDEX'])) {
  34. $distIndexOid = $this->snmpTemplates[$oltModelId]['misc']['DISTINDEX'];
  35. $distIndex = $this->snmp->walk($oltIp . ':' . self::SNMPPORT, $oltCommunity, $distIndexOid, self::SNMPCACHE);
  36. $distIndex = str_replace($distIndexOid . '.', '', $distIndex);
  37. $distIndex = str_replace($this->snmpTemplates[$oltModelId]['misc']['DISTVALUE'], '', $distIndex);
  38. $distIndex = explodeRows($distIndex);
  39. $lastDeregIndexOID = $this->snmpTemplates[$oltModelId]['misc']['DEREGREASON'];
  40. $lastDeregIndex = $this->snmp->walk($oltIp . ':' . self::SNMPPORT, $oltCommunity, $lastDeregIndexOID, self::SNMPCACHE);
  41. $lastDeregIndex = str_replace($lastDeregIndexOID . '.', '', $lastDeregIndex);
  42. $lastDeregIndex = str_replace($this->snmpTemplates[$oltModelId]['misc']['DEREGVALUE'], '', $lastDeregIndex);
  43. $lastDeregIndex = explodeRows($lastDeregIndex);
  44. $this->distanceParseStels($oltid, $distIndex, $macIndex);
  45. $this->lastDeregParseStels($oltid, $lastDeregIndex, $macIndex);
  46. if (!$oltNoFDBQ) {
  47. $fdbIndexOID = $this->snmpTemplates[$oltModelId]['misc']['FDBINDEX'];
  48. $fdbIndex = $this->snmp->walk($oltIp . ':' . self::SNMPPORT, $oltCommunity, $fdbIndexOID, self::SNMPCACHE);
  49. $fdbIndex = str_replace($fdbIndexOID . '.', '', $fdbIndex);
  50. $fdbIndex = str_replace($this->snmpTemplates[$oltModelId]['misc']['FDBVALUE'], '', $fdbIndex);
  51. $fdbIndex = explodeRows($fdbIndex);
  52. $fdbMACIndexOID = $this->snmpTemplates[$oltModelId]['misc']['FDBMACINDEX'];
  53. $fdbMACIndex = $this->snmp->walk($oltIp . ':' . self::SNMPPORT, $oltCommunity, $fdbMACIndexOID, self::SNMPCACHE);
  54. $fdbMACIndex = str_replace($fdbMACIndexOID . '.', '', $fdbMACIndex);
  55. $fdbMACIndex = str_replace($this->snmpTemplates[$oltModelId]['misc']['FDBMACVALUE'], '', $fdbMACIndex);
  56. $fdbMACIndex = explodeRows($fdbMACIndex);
  57. $fdbVLANIndexOID = $this->snmpTemplates[$oltModelId]['misc']['FDBVLANINDEX'];
  58. $fdbVLANIndex = $this->snmp->walk($oltIp . ':' . self::SNMPPORT, $oltCommunity, $fdbVLANIndexOID, self::SNMPCACHE);
  59. $fdbVLANIndex = str_replace($fdbVLANIndexOID . '.', '', $fdbVLANIndex);
  60. $fdbVLANIndex = str_replace($this->snmpTemplates[$oltModelId]['misc']['FDBVLANVALUE'], '', $fdbVLANIndex);
  61. $fdbVLANIndex = explodeRows($fdbVLANIndex);
  62. $this->fdbParseStels($oltid, $macIndex, $fdbIndex, $fdbMACIndex, $fdbVLANIndex);
  63. }
  64. }
  65. }
  66. }
  67. //getting others system data from OLT
  68. if (isset($this->snmpTemplates[$oltModelId]['system'])) {
  69. //OLT uptime
  70. if (isset($this->snmpTemplates[$oltModelId]['system']['UPTIME'])) {
  71. $uptimeIndexOid = $this->snmpTemplates[$oltModelId]['system']['UPTIME'];
  72. $oltSystemUptimeRaw = $this->snmp->walk($oltIp . ':' . self::SNMPPORT, $oltCommunity, $uptimeIndexOid, self::SNMPCACHE);
  73. $this->uptimeParse($oltid, $oltSystemUptimeRaw);
  74. }
  75. //OLT temperature
  76. if (isset($this->snmpTemplates[$oltModelId]['system']['TEMPERATURE'])) {
  77. $temperatureIndexOid = $this->snmpTemplates[$oltModelId]['system']['TEMPERATURE'];
  78. $oltTemperatureRaw = $this->snmp->walk($oltIp . ':' . self::SNMPPORT, $oltCommunity, $temperatureIndexOid, self::SNMPCACHE);
  79. $this->temperatureParse($oltid, $oltTemperatureRaw);
  80. }
  81. }
  82. }
  83. /**
  84. * Performs signal preprocessing for sig/mac index arrays and stores it into cache
  85. *
  86. * @param int $oltid
  87. * @param array $sigIndex
  88. * @param array $macIndex
  89. * @param array $snmpTemplate
  90. *
  91. * @return void
  92. */
  93. public function signalParseStels($oltid, $sigIndex, $macIndex, $snmpTemplate, $ponPrefixAdd = '') {
  94. $oltid = vf($oltid, 3);
  95. $sigTmp = array();
  96. $macTmp = array();
  97. $macDevIdx = array();
  98. $ifacesIdx = array();
  99. $result = array();
  100. $curDate = curdatetime();
  101. $plasticIndexSig = 0;
  102. $plasticIndexMac = 0;
  103. //signal index preprocessing
  104. if ((!empty($sigIndex)) and ( !empty($macIndex))) {
  105. foreach ($sigIndex as $io => $eachsig) {
  106. $line = explode('=', $eachsig);
  107. //signal is present
  108. if (isset($line[1])) {
  109. $signalRaw = trim($line[1]); // signal level
  110. $signalOnuPort = str_replace($snmpTemplate['SIGINDEX'], '', $line[0]);
  111. $signalOnuPort = explode('.', $signalOnuPort);
  112. $plasticIndexSig = trim($signalOnuPort[1]);
  113. // $plasticIndexSig = ($plasticIndexSig * 256) + 1; // realy shitty index
  114. if ($signalRaw == $snmpTemplate['DOWNVALUE'] or empty($signalRaw)) {
  115. $signalRaw = 'Offline';
  116. } else {
  117. if ($snmpTemplate['OFFSETMODE'] == 'logm') {
  118. if ($snmpTemplate['OFFSET']) {
  119. $signalRaw = round(10 * log10($signalRaw) - $snmpTemplate['OFFSET'], 2);
  120. }
  121. }
  122. }
  123. $sigTmp[$signalOnuPort[0] . ':' . $plasticIndexSig] = $signalRaw;
  124. }
  125. }
  126. //mac index preprocessing
  127. foreach ($macIndex as $io => $eachmac) {
  128. $line = explode('=', $eachmac);
  129. //mac is present
  130. if (isset($line[1])) {
  131. $macRaw = trim($line[1]); //mac address
  132. $macOnuPort = str_replace($snmpTemplate['MACINDEX'], '', $line[0]);
  133. $macOnuPort = explode('.', $macOnuPort);
  134. $plasticIndexMac = trim($macOnuPort[1]);
  135. $macRaw = str_replace(' ', ':', $macRaw);
  136. $macRaw = strtolower($macRaw);
  137. $macTmp[$macOnuPort[0] . ':' . $plasticIndexMac] = $macRaw;
  138. $macDevIdx[$macRaw] = $macOnuPort[0] . ':' . $plasticIndexMac;
  139. $ifacesIdx[$macRaw] = $ponPrefixAdd . $macOnuPort[0] . ':' . $plasticIndexMac;
  140. // $macDevIdx[$macRaw] = $macOnuPort[0] . '.' . (($plasticIndexMac - 1) / 256);
  141. }
  142. }
  143. //storing results
  144. if (!empty($macTmp)) {
  145. foreach ($macTmp as $devId => $eachMac) {
  146. if (isset($sigTmp[$devId])) {
  147. $signal = $sigTmp[$devId];
  148. $result[$eachMac] = $signal;
  149. //signal history filling
  150. if ($signal == 'Offline') {
  151. $signal = $this->onuOfflineSignalLevel; //over 9000 offline signal level :P
  152. }
  153. //saving each ONU signal history
  154. $this->olt->writeSignalHistory($eachMac, $signal);
  155. }
  156. }
  157. //saving ONUs signals
  158. $this->olt->writeSignals($result);
  159. //saving ONUs cache
  160. $this->olt->writeOnuCache($macTmp);
  161. //saving ONUs interfaces
  162. $this->olt->writeInterfaces($ifacesIdx);
  163. //saving ONUs MAC index
  164. $this->olt->writeMacIndex($macDevIdx);
  165. }
  166. }
  167. }
  168. /**
  169. * Parses & stores in cache OLT ONU distances
  170. *
  171. * @param int $oltid
  172. * @param array $distIndex
  173. * @param array $macIndex
  174. *
  175. * @return void
  176. */
  177. protected function distanceParseStels($oltid, $distIndex, $macIndex) {
  178. $oltid = vf($oltid, 3);
  179. $distTmp = array();
  180. $onuTmp = array();
  181. $result = array();
  182. $curDate = curdatetime();
  183. //distance index preprocessing
  184. if ((!empty($distIndex)) and ( !empty($macIndex))) {
  185. foreach ($distIndex as $io => $eachdist) {
  186. $line = explode('=', $eachdist);
  187. //distance is present
  188. if (isset($line[1])) {
  189. $distanceRaw = trim($line[1]); // distance
  190. $devIndex = $line[0];
  191. $devIndex = explode('.', $devIndex);
  192. $portIndex = trim($devIndex[0]);
  193. $devIndex = trim($devIndex[1]);
  194. // $devIndex = (($devIndex * 256) + 1);
  195. $distTmp[$portIndex . ':' . $devIndex] = $distanceRaw;
  196. }
  197. }
  198. //mac index preprocessing
  199. foreach ($macIndex as $io => $eachmac) {
  200. $line = explode('=', $eachmac);
  201. //mac is present
  202. if (isset($line[1])) {
  203. $macRaw = trim($line[1]); //mac address
  204. $devIndex = trim($line[0]);
  205. $devIndex = explode('.', $devIndex);
  206. $portIndex = trim($devIndex[0]);
  207. $devIndex = $devIndex[1];
  208. $macRaw = str_replace(' ', ':', $macRaw);
  209. $macRaw = strtolower($macRaw);
  210. $onuTmp[$portIndex . ':' . $devIndex] = $macRaw;
  211. }
  212. }
  213. //storing results
  214. if (!empty($onuTmp)) {
  215. foreach ($onuTmp as $devId => $eachMac) {
  216. if (isset($distTmp[$devId])) {
  217. $distance = $distTmp[$devId];
  218. $result[$eachMac] = $distance;
  219. }
  220. }
  221. //saving distances
  222. $this->olt->writeDistances($result);
  223. }
  224. }
  225. }
  226. /**
  227. * Parses & stores to cache ONUs FDB cache (MACs behind ONU)
  228. *
  229. * @param $oltID
  230. * @param $onuMACIndex
  231. * @param $fdbIndex
  232. * @param $fdbMACIndex
  233. * @param $fdbVLANIndex
  234. */
  235. protected function fdbParseStels($oltID, $onuMACIndex, $fdbIndex, $fdbMACIndex, $fdbVLANIndex) {
  236. $macLLIDIndexes = array();
  237. $fdbLLIDIndexes = array();
  238. $fdbIdxMAC = array();
  239. $fdbIdxVLAN = array();
  240. $fdbCahce = array();
  241. // processing $onuMACIndex array to get pon port number + ONU LLID => ONU MAC mapping
  242. if (!empty($onuMACIndex) and ! empty($fdbIndex)) {
  243. foreach ($onuMACIndex as $eachIdx => $eachONUMAC) {
  244. $line = explode('=', $eachONUMAC);
  245. // MAC is present
  246. if (isset($line[1])) {
  247. $onuMAC = trim($line[1]);
  248. $tmpIndex = trim($line[0]); // pon port number + device index
  249. $tmpIndex = explode('.', $tmpIndex);
  250. $portIndex = trim($tmpIndex[0]); // pon port number
  251. $devIndexRaw = $tmpIndex[1];
  252. // seems next lines no needed no more
  253. // $devIndexLLID = ($devIndexRaw - 1) / 256; // ONU LLID
  254. // $macLLIDIndexes[$portIndex . ':' . $devIndexLLID] = $onuMAC; // pon port number + ONU LLID => ONU MAC
  255. $macLLIDIndexes[$portIndex . ':' . $devIndexRaw] = $onuMAC; // pon port number + ONU LLID => ONU MAC
  256. }
  257. }
  258. // processing FDBIndex array to get FDB index number => pon port number + ONU LLID mapping
  259. foreach ($fdbIndex as $each => $eachIdx) {
  260. $line = explode('=', $eachIdx);
  261. // ONU LLID is present
  262. if (isset($line[1])) {
  263. $devLLID = trim($line[1]); // ONU LLID
  264. $tmpIndex = trim($line[0]); // pon port number + FDB index
  265. $tmpIndex = explode('.', $tmpIndex);
  266. $portIndex = trim($tmpIndex[0]); // pon port number
  267. $fdbIdxRaw = $tmpIndex[1]; // FDB index number
  268. $fdbLLIDIndexes[$fdbIdxRaw] = $portIndex . ':' . $devLLID; // FDB index number => pon port number + ONU LLID
  269. }
  270. }
  271. // processing $fdbMACIndex array to get FDB index number => FDB MAC mapping
  272. foreach ($fdbMACIndex as $each => $eachIdx) {
  273. $line = explode('=', $eachIdx);
  274. // FDB MAC is present
  275. if (isset($line[1])) {
  276. $fdbMAC = trim($line[1]); // FDB MAC
  277. $tmpIndex = trim($line[0]); // pon port number + FDB index
  278. $tmpIndex = explode('.', $tmpIndex);
  279. $fdbIdxRaw = $tmpIndex[1]; // FDB index number
  280. $fdbIdxMAC[$fdbIdxRaw] = $fdbMAC; // FDB index number => FDB MAC
  281. }
  282. }
  283. // processing $fdbVLANIndex array to get FDB index number => FDB VLAN mapping
  284. foreach ($fdbVLANIndex as $each => $eachIdx) {
  285. $line = explode('=', $eachIdx);
  286. // FDB VLAN is present
  287. if (isset($line[1])) {
  288. $fdbVLAN = trim($line[1]); // FDB VLAN
  289. $tmpIndex = trim($line[0]); // pon port number + FDB index
  290. $tmpIndex = explode('.', $tmpIndex);
  291. $fdbIdxRaw = $tmpIndex[1]; // FDB index number
  292. $fdbIdxVLAN[$fdbIdxRaw] = $fdbVLAN; // FDB index number => FDB VLAN
  293. }
  294. }
  295. if (!empty($macLLIDIndexes) and ! empty($fdbLLIDIndexes)) {
  296. foreach ($macLLIDIndexes as $eachLLID => $eachONUMAC) {
  297. $onuFDBIdxs = array_keys($fdbLLIDIndexes, $eachLLID);
  298. if (!empty($onuFDBIdxs)) {
  299. $tmpFDBArr = array();
  300. $tmpONUMAC = strtolower(AddMacSeparator(RemoveMacAddressSeparator($eachONUMAC, array(':', '-', '.', ' '))));
  301. foreach ($onuFDBIdxs as $io => $eachIdx) {
  302. $tmpFDBMAC = empty($fdbIdxMAC[$eachIdx]) ? '' : $fdbIdxMAC[$eachIdx];
  303. if (empty($tmpFDBMAC) or $tmpFDBMAC == $eachONUMAC) {
  304. continue;
  305. } else {
  306. $tmpFDBMAC = strtolower(AddMacSeparator(RemoveMacAddressSeparator($tmpFDBMAC, array(':', '-', '.', ' '))));
  307. $tmpFDBVLAN = empty($fdbIdxVLAN[$eachIdx]) ? '' : $fdbIdxVLAN[$eachIdx];
  308. // not applicable with PON HAL now.
  309. // i dont know nahooya this was here
  310. //$tmpONUID = $this->getONUIDByMAC($tmpONUMAC);
  311. //$tmpONUID = (empty($tmpONUID)) ? $eachIdx : $tmpONUID;
  312. $tmpONUID=$eachIdx;
  313. $tmpFDBArr[$tmpONUID] = array('mac' => $tmpFDBMAC, 'vlan' => $tmpFDBVLAN);
  314. }
  315. }
  316. $fdbCahce[$tmpONUMAC] = $tmpFDBArr;
  317. }
  318. }
  319. }
  320. }
  321. //saving OLT FDB
  322. $this->olt->writeFdb($fdbCahce);
  323. }
  324. }