api.ponstels12.php 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392
  1. <?php
  2. /**
  3. * OLT Stels FD12XX hardware abstraction layer
  4. */
  5. class PONStels12 extends PONProto {
  6. /**
  7. * Stels FD12XX devices polling
  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. $ponPrefixAdd = (empty($this->snmpTemplates[$oltModelId]['misc']['INTERFACEADDPONPREFIX'])
  20. ? '' : $this->snmpTemplates[$oltModelId]['misc']['INTERFACEADDPONPREFIX']);
  21. $distIndex = array();
  22. $ifaceIndex = array();
  23. $sigIndex = $this->walkCleared($oltIPPORT, $oltCommunity,
  24. $this->snmpTemplates[$oltModelId]['signal']['SIGINDEX'],
  25. '',
  26. '.0.0 ', self::SNMPCACHE);
  27. //ONU distance polling for stels12 devices
  28. if (isset($this->snmpTemplates[$oltModelId]['misc'])) {
  29. if (isset($this->snmpTemplates[$oltModelId]['misc']['DISTINDEX'])) {
  30. if (!empty($this->snmpTemplates[$oltModelId]['misc']['DISTINDEX'])) {
  31. $distIndex = $this->walkCleared($oltIPPORT, $oltCommunity,
  32. $this->snmpTemplates[$oltModelId]['misc']['DISTINDEX'],
  33. '',
  34. '', self::SNMPCACHE);
  35. $onuIndex = $this->walkCleared($oltIPPORT, $oltCommunity,
  36. $this->snmpTemplates[$oltModelId]['misc']['ONUINDEX'],
  37. '',
  38. '.0.0 ', self::SNMPCACHE);
  39. $ifaceIndex = $this->walkCleared($oltIPPORT, $oltCommunity,
  40. $this->snmpTemplates[$oltModelId]['misc']['INTERFACEINDEX'],
  41. '',
  42. '"', self::SNMPCACHE);
  43. }
  44. }
  45. if (isset($this->snmpTemplates[$oltModelId]['misc']['DEREGREASON'])) {
  46. if (!empty($this->snmpTemplates[$oltModelId]['misc']['DEREGREASON'])) {
  47. $lastDeregIndex = $this->walkCleared($oltIPPORT, $oltCommunity,
  48. $this->snmpTemplates[$oltModelId]['misc']['DEREGREASON'],
  49. '',
  50. '"', self::SNMPCACHE);
  51. }
  52. }
  53. }
  54. //getting MAC index.
  55. $macIndex = $this->walkCleared($oltIPPORT, $oltCommunity,
  56. $this->snmpTemplates[$oltModelId]['signal']['MACINDEX'],
  57. '',
  58. '', self::SNMPCACHE);
  59. $this->signalParse($oltid, $sigIndex, $macIndex, $this->snmpTemplates[$oltModelId]['signal']);
  60. if (isset($this->snmpTemplates[$oltModelId]['misc'])) {
  61. if (isset($this->snmpTemplates[$oltModelId]['misc']['DISTINDEX'])) {
  62. if (!empty($this->snmpTemplates[$oltModelId]['misc']['DISTINDEX'])) {
  63. // processing distance data
  64. $this->distanceParse($oltid, $distIndex, $macIndex);
  65. //processing interfaces data
  66. //$this->interfaceParseStels12($oltid, $ifaceIndex, $macIndex, $deviceType);
  67. $this->interfaceParseStels12($oltid, $ifaceIndex, $ponPrefixAdd);
  68. }
  69. }
  70. if (isset($this->snmpTemplates[$oltModelId]['misc']['DEREGREASON'])) {
  71. if (!empty($this->snmpTemplates[$oltModelId]['misc']['DEREGREASON'])) {
  72. $this->lastDeregParseStels12($oltid, $lastDeregIndex, $macIndex);
  73. }
  74. }
  75. }
  76. if (!$oltNoFDBQ) {
  77. $fdbMACIndex = $this->walkCleared($oltIPPORT, $oltCommunity,
  78. $this->snmpTemplates[$oltModelId]['misc']['FDBMACINDEX'],
  79. '',
  80. '', self::SNMPCACHE);
  81. $this->fdbParseStels12($fdbMACIndex);
  82. }
  83. }
  84. /**
  85. * Parses & stores in cache OLT ONU interfaces
  86. *
  87. * @param int $oltid
  88. * @param array $ifaceIndex
  89. * @param array $macIndex
  90. *
  91. * @return void
  92. */
  93. protected function interfaceParseStels12($oltid, $ifaceIndex, $ponPrefixAdd = '') {
  94. $macIndex = $this->olt->readMacIndex();
  95. $oltid = vf($oltid, 3);
  96. $ifaceTmp = array();
  97. $result = array();
  98. $i = 0;
  99. //iface index preprocessing
  100. if ((!empty($ifaceIndex)) and ( !empty($macIndex))) {
  101. // creating mapping of internal pon ifaces nums to sequential, like this:
  102. //bsPortIndex.1.0.13; Value (Integer): 13 => 1
  103. //bsPortIndex.1.0.14; Value (Integer): 14 => 2
  104. //bsPortIndex.1.0.15; Value (Integer): 15 => 3
  105. //bsPortIndex.1.0.16; Value (Integer): 16 => 4
  106. //bsPortIndex.1.0.17; Value (Integer): 17 => 5
  107. //bsPortIndex.1.0.18; Value (Integer): 18 => 6
  108. //bsPortIndex.1.0.19; Value (Integer): 19 => 7
  109. //bsPortIndex.1.0.20; Value (Integer): 20 => 8
  110. foreach ($ifaceIndex as $io => $eachIface) {
  111. $i++;
  112. $line = explode('=', $eachIface);
  113. if (isset($line[1])) {
  114. $ponIfaceNum = trim($line[1]); // pon interface number
  115. $ifaceTmp[$ponIfaceNum] = $i;
  116. }
  117. }
  118. // using "special" math to get pon port num + LLID from dev index
  119. // formula: dev index DEC to HEX
  120. // 16780033 => 1000B01, where
  121. // 0B => 11 - pon port num
  122. // 01 => 1 - LLID
  123. if (!empty($macIndex) and !empty($ifaceTmp)) {
  124. foreach ($macIndex as $eachMac => $devId) {
  125. $LLID = '';
  126. $hexDevId = dechex($devId);
  127. $portNum = hexdec(substr($hexDevId, -4, 2));
  128. $onuNum = hexdec(substr($hexDevId, -2, 2));
  129. if (!empty($ifaceTmp[$portNum])) {
  130. $portNum = $ifaceTmp[$portNum];
  131. $LLID = $portNum . ":" . $onuNum;
  132. } else {
  133. $LLID = __('On ho');
  134. }
  135. //storing results
  136. $result[$eachMac] = $ponPrefixAdd . $LLID;
  137. }
  138. }
  139. //saving ONUs interfaces
  140. $this->olt->writeInterfaces($result);
  141. }
  142. }
  143. /**
  144. * Parses & stores in cache ONU last dereg reasons
  145. *
  146. * @param int $oltid
  147. * @param array $deregIndex
  148. * @param array $macIndex
  149. *
  150. * @return void
  151. */
  152. protected function lastDeregParseStels12($oltid, $deregIndex, $macIndex) {
  153. $oltid = vf($oltid, 3);
  154. $deregTmp = array();
  155. $macTmp = array();
  156. $result = array();
  157. //dereg index preprocessing
  158. if ((!empty($deregIndex)) and ( !empty($macIndex))) {
  159. foreach ($deregIndex as $io => $eachdereg) {
  160. $line = explode('=', $eachdereg);
  161. //dereg is present
  162. if (isset($line[1])) {
  163. $lastDeregRaw = trim($line[1]); // last dereg reason
  164. $devIndex = trim($line[0]); // device index
  165. $deregTmp[$devIndex] = $lastDeregRaw;
  166. }
  167. }
  168. //mac index preprocessing
  169. foreach ($macIndex as $io => $eachmac) {
  170. $line = explode('=', $eachmac);
  171. //mac is present
  172. if (isset($line[1])) {
  173. $macRaw = trim($line[1]); //mac address
  174. $devIndex = trim($line[0]); //device index
  175. $macRaw = str_replace(' ', ':', $macRaw);
  176. $macRaw = strtolower($macRaw);
  177. $macTmp[$devIndex] = $macRaw;
  178. }
  179. }
  180. //storing results
  181. if (!empty($macTmp)) {
  182. foreach ($macTmp as $devId => $eachMac) {
  183. $currentInterface = '';
  184. if (!empty($deregTmp)) {
  185. foreach ($deregTmp as $intefaceOffset => $interfaceName) {
  186. // dirty hack for firmware > 1.4.0 - some shitty math used
  187. $recalcIfaceOffset = $intefaceOffset;
  188. if ($recalcIfaceOffset < 100) {
  189. $recalcIfaceOffset = (($recalcIfaceOffset - 10) * 256) + 16779776;
  190. }
  191. if ($devId >= $recalcIfaceOffset) {
  192. $currentInterface = $intefaceOffset;
  193. }
  194. }
  195. $result[$eachMac] = (isset($deregTmp[$currentInterface])) ? $deregTmp[$currentInterface] : __('On ho');
  196. }
  197. }
  198. //saving ONUs dereg reasons
  199. $this->olt->writeDeregs($result);
  200. }
  201. }
  202. }
  203. /**
  204. * Parses & stores in cache OLT ONU interfaces
  205. *
  206. * @param int $oltid
  207. * @param array $intIndex
  208. * @param array $macIndex
  209. *
  210. * @return void
  211. */
  212. protected function interfaceParseStels($oltid, $intIndex, $macIndex) {
  213. $oltid = vf($oltid, 3);
  214. $intTmp = array();
  215. $macTmp = array();
  216. $result = array();
  217. //distance index preprocessing
  218. if ((!empty($intIndex)) and ( !empty($macIndex))) {
  219. foreach ($intIndex as $io => $eachint) {
  220. $line = explode('=', $eachint);
  221. //distance is present
  222. if (isset($line[1])) {
  223. // distance
  224. $devIndex = trim($line[0]); // device index
  225. $devIndex = explode('.', $devIndex);
  226. $portIndex = trim($devIndex[0]);
  227. $interfaceRaw = $devIndex[0] . ':' . $devIndex[1];
  228. // $devIndex = ($devIndex[1] * 256) + 1;
  229. $intTmp[$portIndex . ':' . $devIndex] = $interfaceRaw;
  230. }
  231. }
  232. //mac index preprocessing
  233. foreach ($macIndex as $io => $eachmac) {
  234. $line = explode('=', $eachmac);
  235. //mac is present
  236. if (isset($line[1])) {
  237. $macRaw = trim($line[1]); //mac address
  238. $devIndex = trim($line[0]); //device index
  239. $devIndex = explode('.', $devIndex);
  240. $portIndex = trim($devIndex[0]);
  241. $devIndex = $devIndex[1];
  242. $macRaw = str_replace(' ', ':', $macRaw);
  243. $macRaw = strtolower($macRaw);
  244. $macTmp[$portIndex . ':' . $devIndex] = $macRaw;
  245. }
  246. }
  247. //storing results
  248. if (!empty($macTmp)) {
  249. foreach ($macTmp as $devId => $eachMac) {
  250. if (isset($intTmp[$devId])) {
  251. $interface = $intTmp[$devId];
  252. $result[$eachMac] = $interface;
  253. }
  254. }
  255. //saving ONUs interfaces
  256. $this->olt->writeInterfaces($result);
  257. }
  258. }
  259. }
  260. /**
  261. * Parses & stores in cache OLT ONU interfaces
  262. *
  263. * @param int $oltid
  264. * @param array $deregIndex
  265. * @param array $macIndex
  266. *
  267. * @return void
  268. */
  269. protected function lastDeregParseStels($oltid, $deregIndex, $macIndex) {
  270. $oltid = vf($oltid, 3);
  271. $deregTmp = array();
  272. $onuTmp = array();
  273. $result = array();
  274. //dereg index preprocessing
  275. if ((!empty($deregIndex)) and ( !empty($macIndex))) {
  276. foreach ($deregIndex as $io => $eachdereg) {
  277. $line = explode('=', $eachdereg);
  278. //dereg is present
  279. if (isset($line[1])) {
  280. $deregRaw = trim(trim($line[1]), '"'); // dereg
  281. $devIndex = $line[0];
  282. $devIndex = explode('.', $devIndex);
  283. $portIndex = trim($devIndex[0]);
  284. $devIndex = trim($devIndex[1]);
  285. // $devIndex = (($devIndex * 256) + 1);
  286. $deregTmp[$portIndex . ':' . $devIndex] = $deregRaw;
  287. }
  288. }
  289. //mac index preprocessing
  290. foreach ($macIndex as $io => $eachmac) {
  291. $line = explode('=', $eachmac);
  292. //mac is present
  293. if (isset($line[1])) {
  294. $macRaw = trim($line[1]); //mac address
  295. $devIndex = trim($line[0]);
  296. $devIndex = explode('.', $devIndex);
  297. $portIndex = trim($devIndex[0]);
  298. $devIndex = $devIndex[1];
  299. $macRaw = str_replace(' ', ':', $macRaw);
  300. $macRaw = strtolower($macRaw);
  301. $onuTmp[$portIndex . ':' . $devIndex] = $macRaw;
  302. }
  303. }
  304. //storing results
  305. if (!empty($onuTmp)) {
  306. foreach ($onuTmp as $devId => $eachMac) {
  307. if (isset($deregTmp[$devId])) {
  308. $result[$eachMac] = $deregTmp[$devId];
  309. }
  310. }
  311. //saving ONUs dereg reasons
  312. $this->olt->writeDeregs($result);
  313. }
  314. }
  315. }
  316. /**
  317. * Parses & stores to cache ONUs FDB cache (MACs behind ONU)
  318. *
  319. * @param $fdbMACIndex
  320. *
  321. * @return void
  322. */
  323. protected function fdbParseStels12($fdbMACIndex) {
  324. $onuMACIndex = $this->olt->readMacIndex();
  325. $i = 0;
  326. $fdbCahce = array();
  327. if (!empty($onuMACIndex) and !empty($fdbMACIndex)) {
  328. // processing $fdbMACIndex array to get a FDB record at once
  329. foreach ($fdbMACIndex as $eachIdx => $eachONUMAC) {
  330. $i++;
  331. $line = explode('=', $eachONUMAC);
  332. // MAC is present
  333. if (isset($line[1])) {
  334. $onuMAC = trim($line[1]);
  335. if (ispos($onuMAC, 'STRING:')) continue;
  336. $onuMAC = strtolower(str_replace(' ', ':', $onuMAC)); // ONU MAC
  337. $tmpIndex = trim($line[0]); // pon port number + device index
  338. $fdbVLAN = substr($tmpIndex, strripos($tmpIndex, '.') + 1); // fdb VLAN
  339. $fdbMAC = convertMACDec2Hex(substr($tmpIndex, 0, strripos($tmpIndex, '.'))); // fdb MAC;
  340. $fdbCahce[$onuMAC][$i] = array('mac' => $fdbMAC, 'vlan' => $fdbVLAN);
  341. }
  342. }
  343. }
  344. //saving OLT FDB
  345. $this->olt->writeFdb($fdbCahce);
  346. }
  347. }