api.oltattractor.php 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853
  1. <?php
  2. /**
  3. * OLT local data manipultaion abstraction layer
  4. */
  5. class OLTAttractor {
  6. /**
  7. * Contains current instance OLT device ID
  8. *
  9. * @var int
  10. */
  11. protected $oltId = '';
  12. /**
  13. * Some basic paths and data parameters here
  14. */
  15. const CACHE_ROOT_PATH = 'exports/pondata/';
  16. const SIGCACHE_PATH = 'exports/pondata/signals/';
  17. const SIGCACHE_EXT = 'OLTSIGNALS';
  18. const DISTCACHE_PATH = 'exports/pondata/dist/';
  19. const DISTCACHE_EXT = 'OLTDISTANCE';
  20. const ONUCACHE_PATH = 'exports/pondata/onucache/';
  21. const ONUCACHE_EXT = 'ONUINDEX';
  22. const INTCACHE_PATH = 'exports/pondata/iface/';
  23. const INTCACHE_EXT = 'ONUINTERFACE';
  24. const INTDESCRCACHE_EXT = 'OLTINTERFACEDESCR';
  25. const FDBCACHE_PATH = 'exports/pondata/fdb/';
  26. const FDBCACHE_EXT = 'OLTFDB';
  27. const DEREGCACHE_PATH = 'exports/pondata/dereg/';
  28. const DEREGCACHE_EXT = 'ONUDEREGS';
  29. const UPTIME_PATH = 'exports/pondata/uptime/';
  30. const UPTIME_EXT = 'OLTUPTIME';
  31. const TEMPERATURE_PATH = 'exports/pondata/temp/';
  32. const TEMPERATURE_EXT = 'OLTTEMPERATURE';
  33. const MACDEVIDCACHE_PATH = 'exports/pondata/macdev/';
  34. const MACDEVIDCACHE_EXT = 'ONUMACDEVINDEX';
  35. const UNIOPERSTATS_PATH = 'exports/pondata/unioperstats/';
  36. const UNIOPERSTATS_EXT = 'UNIOPERSTATS';
  37. /**
  38. * ONUs signal history path
  39. */
  40. const ONUSIG_PATH = 'content/documents/onusig/';
  41. /**
  42. * Creates new OLT data manipulation instance
  43. *
  44. * @param int $oltId Existing OLT device ID
  45. */
  46. public function __construct($oltId = '') {
  47. if (!empty($oltId)) {
  48. $this->oltId = $oltId;
  49. }
  50. }
  51. /**
  52. * Sets current instance OLT device ID
  53. *
  54. * @param int $oltId
  55. *
  56. * @return void
  57. */
  58. public function setOltId($oltId) {
  59. $this->oltId = $oltId;
  60. // __ _
  61. // _wr"" "-q__
  62. // _dP 9m_
  63. // _#P 9#_
  64. // d#@ 9#m
  65. // d## ###
  66. // J### ###L
  67. // {###K J###K
  68. // ]####K ___aaa___ J####F
  69. // __gmM######_ w#P"" ""9#m _d#####Mmw__
  70. // _g##############mZ_ __g##############m_
  71. // _d####M@PPPP@@M#######Mmp gm#########@@PPP9@M####m_
  72. // a###"" ,Z"#####@" '######"\g ""M##m
  73. // J#@" 0L "*## ##@" J# *#K
  74. // #" `# "_gmwgm_~ dF `#_
  75. // 7F "#_ ]#####F _dK JE
  76. // ] *m__ ##### __g@" F
  77. // "PJ#####LP"
  78. // ` 0######_ '
  79. // _0########_
  80. // . _d#####^#####m__ ,
  81. // "*w_________am#####P" ~9#####mw_________w*"
  82. // ""9@#####@M"" ""P@#####@M""
  83. }
  84. /**
  85. * Returns some data container unpacked content
  86. *
  87. * @param string $dataContainer Path to data container
  88. * @param bool $isArray is container data an serialized array?
  89. *
  90. * @return array/string
  91. */
  92. protected function getData($dataContainer, $isArray = true) {
  93. $result = ($isArray) ? array() : '';
  94. if (!empty($this->oltId)) {
  95. if (file_exists($dataContainer)) {
  96. $result = file_get_contents($dataContainer);
  97. if ($isArray) {
  98. $result = unserialize($result);
  99. }
  100. }
  101. } else {
  102. throw new Exception('EX_OLTID_EMPTY');
  103. }
  104. return ($result);
  105. }
  106. /**
  107. * Saves some data in container
  108. *
  109. * @param string $dataContainer
  110. * @param array/string $dataToSave data to save
  111. *
  112. * @return void
  113. */
  114. protected function saveData($dataContainer, $dataToSave) {
  115. if (!empty($this->oltId)) {
  116. if (is_array($dataToSave)) {
  117. $dataToSave = serialize($dataToSave);
  118. }
  119. file_put_contents($dataContainer, $dataToSave);
  120. } else {
  121. throw new Exception('EX_OLTID_EMPTY');
  122. }
  123. }
  124. /**
  125. * Returns full content of data container
  126. *
  127. * @param string $dataContainer
  128. *
  129. * @return array
  130. */
  131. public function loadContainerData($dataContainer) {
  132. return ($this->getData($dataContainer));
  133. }
  134. /**
  135. * Extracts OLT ID from data container name
  136. *
  137. * @param string $dataContainerName
  138. *
  139. * @return int/bool on error
  140. */
  141. protected function extractOltID($dataContainerName) {
  142. $result = false;
  143. if (!empty($dataContainerName)) {
  144. $anyDigits = preg_replace("#[^0-9]#Uis", '', $dataContainerName);
  145. if (!empty($anyDigits)) {
  146. $result = $anyDigits;
  147. }
  148. }
  149. return ($result);
  150. }
  151. /**
  152. * Return list of available OLT data containers as oltId=>containerName
  153. *
  154. * @param string $containerPath
  155. * @param string $containerMark
  156. *
  157. * @return array
  158. */
  159. protected function getContainers($containerPath, $containerMark) {
  160. $result = array();
  161. $availContainers = rcms_scandir($containerPath, '*_' . $containerMark);
  162. if (!empty($availContainers)) {
  163. foreach ($availContainers as $io => $eachContainer) {
  164. $oltId = $this->extractOltID($eachContainer);
  165. if ($oltId !== false) {
  166. $result[$oltId] = $containerPath . $eachContainer;
  167. }
  168. }
  169. }
  170. return ($result);
  171. }
  172. /**
  173. * Returns content of all OLT data containers with some path and mark
  174. *
  175. * @param string $containerPath
  176. * @param string $containerPath
  177. *
  178. * @return array
  179. */
  180. protected function getContainersContent($containerPath, $containerMark) {
  181. $result = array();
  182. $oltData = new OLTAttractor();
  183. $availDataContainers = $this->getContainers($containerPath, $containerMark);
  184. if (!empty($availDataContainers)) {
  185. foreach ($availDataContainers as $eachContainerKey => $eachContainerName) {
  186. $oltData->setOltId($eachContainerKey);
  187. $containerData = $oltData->loadContainerData($eachContainerName);
  188. if (!empty($containerData)) {
  189. $result += $containerData;
  190. }
  191. }
  192. }
  193. return ($result);
  194. }
  195. /**
  196. * Checks is any data containers available for some path/mark?
  197. *
  198. * @param string $containerPath
  199. * @param string $containerMark
  200. *
  201. * @return bool
  202. */
  203. protected function checkContainersAvailable($containerPath, $containerMark) {
  204. $result = false;
  205. $availContainers = rcms_scandir($containerPath, '*_' . $containerMark);
  206. if (!empty($availContainers)) {
  207. $result = true;
  208. }
  209. return ($result);
  210. }
  211. /**
  212. * OLT data manipulation subroutines
  213. */
  214. /**
  215. * Saves current OLT temperature
  216. *
  217. * @param float $tempRaw current OLT temperature in celsius
  218. *
  219. * @return void
  220. */
  221. public function writeTemperature($tempRaw) {
  222. $dataToSave = trim($tempRaw);
  223. if (!empty($dataToSave)) {
  224. $dataContainer = self::TEMPERATURE_PATH . $this->oltId . '_' . self::TEMPERATURE_EXT;
  225. $this->saveData($dataContainer, $dataToSave);
  226. }
  227. }
  228. /**
  229. * Returns current OLT temperature in celsius
  230. *
  231. * @return float
  232. */
  233. public function readTemperature() {
  234. $dataContainer = self::TEMPERATURE_PATH . $this->oltId . '_' . self::TEMPERATURE_EXT;
  235. $result = $this->getData($dataContainer, false);
  236. return ($result);
  237. }
  238. /**
  239. * Saves last OLT uptime
  240. *
  241. * @param string $uptimeRaw readable string like "666 days"
  242. *
  243. * @return void
  244. */
  245. public function writeUptime($uptimeRaw) {
  246. $dataToSave = trim($uptimeRaw);
  247. if (!empty($dataToSave)) {
  248. $dataContainer = self::UPTIME_PATH . $this->oltId . '_' . self::UPTIME_EXT;
  249. $this->saveData($dataContainer, $dataToSave);
  250. }
  251. }
  252. /**
  253. * Returns last OLT uptime just as readable string
  254. *
  255. * @return string
  256. */
  257. public function readUptime() {
  258. $dataContainer = self::UPTIME_PATH . $this->oltId . '_' . self::UPTIME_EXT;
  259. $result = $this->getData($dataContainer, false);
  260. return ($result);
  261. }
  262. /**
  263. * Saves latest OLT all ONUs signals
  264. *
  265. * @param array $signalsArr array of [onuMac or onuSerial] => signalString
  266. *
  267. * @return void
  268. */
  269. public function writeSignals($signalsArr) {
  270. $dataToSave = $signalsArr;
  271. $dataContainer = self::SIGCACHE_PATH . $this->oltId . '_' . self::SIGCACHE_EXT;
  272. $this->saveData($dataContainer, $dataToSave);
  273. }
  274. /**
  275. * Returns latest OLT all ONUs signals
  276. *
  277. * @return array as [onuMac or onuSerial] => signalString
  278. */
  279. public function readSignals() {
  280. $dataContainer = self::SIGCACHE_PATH . $this->oltId . '_' . self::SIGCACHE_EXT;
  281. $result = $this->getData($dataContainer);
  282. return ($result);
  283. }
  284. /**
  285. * Saves latest OLT all ONUs MAC index
  286. *
  287. * @param array $macIndexArr array of [onuMac]=>deviceId
  288. *
  289. * @return void
  290. */
  291. public function writeMacIndex($macIndexArr) {
  292. $dataToSave = $macIndexArr;
  293. $dataContainer = self::MACDEVIDCACHE_PATH . $this->oltId . '_' . self::MACDEVIDCACHE_EXT;
  294. $this->saveData($dataContainer, $dataToSave);
  295. }
  296. /**
  297. * Returns latest OLT all ONUs MAC index
  298. *
  299. * @return array as [onuMac]=>deviceId
  300. */
  301. public function readMacIndex() {
  302. $dataContainer = self::MACDEVIDCACHE_PATH . $this->oltId . '_' . self::MACDEVIDCACHE_EXT;
  303. $result = $this->getData($dataContainer);
  304. return ($result);
  305. }
  306. /**
  307. * Creates single ONU signal history record
  308. *
  309. * @param string $onuIdent onuMac or OnuSerial
  310. * @param float $signalLevel latest ONU signal in dB
  311. *
  312. * @return void
  313. */
  314. public function writeSignalHistory($onuIdent, $signalLevel) {
  315. if (!empty($onuIdent)) {
  316. $dataContainer = self::ONUSIG_PATH . md5($onuIdent);
  317. file_put_contents($dataContainer, curdatetime() . ',' . $signalLevel . PHP_EOL, FILE_APPEND);
  318. }
  319. }
  320. /**
  321. * Saves latest OLT all ONUs distances
  322. *
  323. * @param array $distsArr array of [onuMac or onuSerial] => onuDistance in meters
  324. *
  325. * @return void
  326. */
  327. public function writeDistances($distsArr) {
  328. $dataToSave = $distsArr;
  329. $dataContainer = self::DISTCACHE_PATH . $this->oltId . '_' . self::DISTCACHE_EXT;
  330. $this->saveData($dataContainer, $dataToSave);
  331. }
  332. /**
  333. * Returns latest OLT all ONUs distances
  334. *
  335. * @return array as [onuMac or onuSerial] => onuDistance in meters
  336. */
  337. public function readDistances() {
  338. $dataContainer = self::DISTCACHE_PATH . $this->oltId . '_' . self::DISTCACHE_EXT;
  339. $result = $this->getData($dataContainer);
  340. return ($result);
  341. }
  342. /**
  343. * Saves latest OLT all ONUs devices cache
  344. *
  345. * @param array $onusArr array of [onuIdx]=>onuMac or onuSerial
  346. *
  347. * @return void
  348. */
  349. public function writeOnuCache($onusArr) {
  350. $dataToSave = $onusArr;
  351. $dataContainer = self::ONUCACHE_PATH . $this->oltId . '_' . self::ONUCACHE_EXT;
  352. $this->saveData($dataContainer, $dataToSave);
  353. }
  354. /**
  355. * Returns latest OLT all ONUs devices cache
  356. *
  357. * @return array as [onuIdx]=>onuMac or onuSerial
  358. */
  359. public function readOnuCache() {
  360. $dataContainer = self::ONUCACHE_PATH . $this->oltId . '_' . self::ONUCACHE_EXT;
  361. $result = $this->getData($dataContainer);
  362. return ($result);
  363. }
  364. /**
  365. * Saves latest OLT all ONUs interfaces cache
  366. *
  367. * @param array $ifacesArr array of [onuMac or onuSerial]=>InterfaceName like EPON0/5:1
  368. *
  369. * @return void
  370. */
  371. public function writeInterfaces($ifacesArr) {
  372. $dataToSave = $ifacesArr;
  373. $dataContainer = self::INTCACHE_PATH . $this->oltId . '_' . self::INTCACHE_EXT;
  374. $this->saveData($dataContainer, $dataToSave);
  375. }
  376. /**
  377. * Returns latest OLT all ONUs interfaces cache
  378. *
  379. * @return array as array [onuMac or onuSerial]=>interfaceName like EPON0/5:1
  380. */
  381. public function readInterfaces() {
  382. $dataContainer = self::INTCACHE_PATH . $this->oltId . '_' . self::INTCACHE_EXT;
  383. $result = $this->getData($dataContainer);
  384. return ($result);
  385. }
  386. /**
  387. * Saves latest OLT all interfaces description cache
  388. *
  389. * @param array $ifdescrsArr array of [interfaceName]=>description
  390. *
  391. * @return void
  392. */
  393. public function writeInterfacesDescriptions($ifdescrsArr) {
  394. $dataToSave = $ifdescrsArr;
  395. $dataContainer = self::INTCACHE_PATH . $this->oltId . '_' . self::INTDESCRCACHE_EXT;
  396. $this->saveData($dataContainer, $dataToSave);
  397. }
  398. /**
  399. * Returns latest OLT all interfaces description cache
  400. *
  401. * @return array as [interfaceName]=>description
  402. */
  403. public function readInterfacesDescriptions() {
  404. $dataContainer = self::INTCACHE_PATH . $this->oltId . '_' . self::INTDESCRCACHE_EXT;
  405. $result = $this->getData($dataContainer);
  406. return ($result);
  407. }
  408. /**
  409. * Saves OLT full FDB table into cache
  410. *
  411. * @param array $fdbStruct array of [onuMac/onuSerial][id]=>mac+vlan
  412. *
  413. * @return void
  414. */
  415. public function writeFdb($fdbStruct) {
  416. /**
  417. * Expected input data structure:
  418. *
  419. * [onuMac/onuSerial] => Array
  420. * (
  421. * [someId] => Array
  422. * (
  423. * [mac] => e8:ba:70:c6:49:aa
  424. * [vlan] => 1
  425. * )
  426. *
  427. * [anotherId] => Array
  428. * (
  429. * [mac] => e8:ba:70:c6:49:bb
  430. * [vlan] => 1
  431. * )
  432. * */
  433. $dataToSave = $fdbStruct;
  434. $dataContainer = self::FDBCACHE_PATH . $this->oltId . '_' . self::FDBCACHE_EXT;
  435. $this->saveData($dataContainer, $dataToSave);
  436. }
  437. /**
  438. * Returns OLT full FDB table from cache
  439. *
  440. * @return array as array of [onuMac/onuSerial][id]=>mac+vlan
  441. */
  442. public function readFdb() {
  443. $dataContainer = self::FDBCACHE_PATH . $this->oltId . '_' . self::FDBCACHE_EXT;
  444. $result = $this->getData($dataContainer);
  445. /**
  446. * Expected return data struct:
  447. *
  448. * [onuMac/onuSerial] => Array
  449. * (
  450. * [someId] => Array
  451. * (
  452. * [mac] => e8:ba:70:c6:49:aa
  453. * [vlan] => 1
  454. * )
  455. *
  456. * [anotherId] => Array
  457. * (
  458. * [mac] => e8:ba:70:c6:49:bb
  459. * [vlan] => 1
  460. * )
  461. * */
  462. return ($result);
  463. }
  464. /**
  465. * Saves OLT all ONUs deregistrations reasons
  466. *
  467. * @param array $onuDeregsArr array of [onuMac/onuSerial]=>deregReason like "wire down"
  468. *
  469. * @return void
  470. */
  471. public function writeDeregs($onuDeregsArr) {
  472. $dataToSave = $onuDeregsArr;
  473. $dataContainer = self::DEREGCACHE_PATH . $this->oltId . '_' . self::DEREGCACHE_EXT;
  474. $this->saveData($dataContainer, $dataToSave);
  475. }
  476. /**
  477. * Returns OLT all ONUs deregistrations reasons
  478. *
  479. * @return array as array of [onuMac/onuSerial]=>deregReason like "wire down"
  480. */
  481. public function readDeregs() {
  482. $dataContainer = self::DEREGCACHE_PATH . $this->oltId . '_' . self::DEREGCACHE_EXT;
  483. $result = $this->getData($dataContainer);
  484. return ($result);
  485. }
  486. /**
  487. * Saves OLT all ONUs UNI-ports operational statuses
  488. *
  489. * @param array $uniStatsArr array of [onuMac/onuSerial] => (ethPort => Status) like 1(up) or 0(down)
  490. *
  491. * @return void
  492. *
  493. * @throws Exception
  494. */
  495. public function writeUniOperStats($uniStatsArr) {
  496. $dataToSave = $uniStatsArr;
  497. $dataContainer = self::UNIOPERSTATS_PATH . $this->oltId . '_' . self::UNIOPERSTATS_EXT;
  498. $this->saveData($dataContainer, $dataToSave);
  499. }
  500. /**
  501. * Returns OLT all ONUs UNI-ports operational statuses
  502. *
  503. * @return array as array of [onuMac/onuSerial] => (ethPort => Status) like 1(up) or 0(down)
  504. *
  505. * @throws Exception
  506. */
  507. public function readUniOperStats() {
  508. $dataContainer = self::UNIOPERSTATS_PATH . $this->oltId . '_' . self::UNIOPERSTATS_EXT;
  509. $result = $this->getData($dataContainer);
  510. return ($result);
  511. }
  512. /**
  513. * Public data getters here
  514. */
  515. /**
  516. * Returns list of all OLTs available ONUs distances as [onuMac/onuSerial]=>distance in meters
  517. *
  518. * @return array
  519. */
  520. public function getDistancesAll() {
  521. $containerPath = self::DISTCACHE_PATH;
  522. $containerMark = self::DISTCACHE_EXT;
  523. return ($this->getContainersContent($containerPath, $containerMark));
  524. }
  525. /**
  526. * Returns list of all OLTs available ONUs dereg reasons as [onuMac/onuSerial]=>reason
  527. *
  528. * @return array
  529. */
  530. public function getDeregsAll() {
  531. $containerPath = self::DEREGCACHE_PATH;
  532. $containerMark = self::DEREGCACHE_EXT;
  533. return ($this->getContainersContent($containerPath, $containerMark));
  534. }
  535. /**
  536. * Returns list of all OLTs available ONUs signals as [onuMac/onuSerial]=>signal in db
  537. *
  538. * @return array
  539. */
  540. public function getSignalsAll() {
  541. $containerPath = self::SIGCACHE_PATH;
  542. $containerMark = self::SIGCACHE_EXT;
  543. return ($this->getContainersContent($containerPath, $containerMark));
  544. }
  545. /**
  546. * Returns list of all OLTs available ONUs interfaces as [onuMac/onuSerial]=>interfaceName
  547. *
  548. * @return array
  549. */
  550. public function getInterfacesAll() {
  551. $containerPath = self::INTCACHE_PATH;
  552. $containerMark = self::INTCACHE_EXT;
  553. return ($this->getContainersContent($containerPath, $containerMark));
  554. }
  555. /**
  556. * Returns list of all ONUs FDB data as [onuMac/onuSerial]=>fdbStruct
  557. *
  558. * @return array
  559. */
  560. public function getFdbAll() {
  561. $containerPath = self::FDBCACHE_PATH;
  562. $containerMark = self::FDBCACHE_EXT;
  563. return ($this->getContainersContent($containerPath, $containerMark));
  564. }
  565. /**
  566. * Returns list of all OLTs available ONUs UNI-ports operational statuses [onuMac/onuSerial] => (ethPort => Status) like 1(up) or 0(down)
  567. *
  568. * @return array
  569. */
  570. public function getUniOperStatsAll() {
  571. $containerPath = self::UNIOPERSTATS_PATH;
  572. $containerMark = self::UNIOPERSTATS_EXT;
  573. return ($this->getContainersContent($containerPath, $containerMark));
  574. }
  575. /**
  576. * Returns list of all OLTs available ONUs interfaces as [oltId][interfaceName]=>interfaceDescr
  577. *
  578. * @return array
  579. */
  580. public function getInterfacesDescriptions() {
  581. $containerPath = self::INTCACHE_PATH;
  582. $containerMark = self::INTDESCRCACHE_EXT;
  583. $oltData = new OLTAttractor();
  584. $result = array();
  585. $allContainers = $this->getContainers($containerPath, $containerMark);
  586. if (!empty($allContainers)) {
  587. foreach ($allContainers as $eachOltId => $eachContainer) {
  588. $oltData->setOltId($eachOltId);
  589. $result[$eachOltId] = $oltData->readInterfacesDescriptions();
  590. }
  591. }
  592. return ($result);
  593. }
  594. /**
  595. * Returns list of all ONUs MAC index as [onuMac]=>deviceId
  596. *
  597. * @return array
  598. */
  599. public function getMacIndexAll() {
  600. $containerPath = self::MACDEVIDCACHE_PATH;
  601. $containerMark = self::MACDEVIDCACHE_EXT;
  602. return ($this->getContainersContent($containerPath, $containerMark));
  603. }
  604. /**
  605. * Returns list of all ONUs MACs on OLTs as [onuMac]=>oltId
  606. *
  607. * @return array
  608. */
  609. public function getONUonOLTAll() {
  610. $containerPath = self::ONUCACHE_PATH;
  611. $containerMark = self::ONUCACHE_EXT;
  612. $oltData = new OLTAttractor();
  613. $result = array();
  614. $allContainers = $this->getContainers($containerPath, $containerMark);
  615. if (!empty($allContainers)) {
  616. foreach ($allContainers as $eachOltId => $eachContainer) {
  617. $oltData->setOltId($eachOltId);
  618. $allOltOnus = $oltData->readOnuCache();
  619. if (!empty($allOltOnus)) {
  620. foreach ($allOltOnus as $eachDevId => $eachOnuMac) {
  621. $result[$eachOnuMac] = $eachOltId;
  622. }
  623. }
  624. }
  625. }
  626. return ($result);
  627. }
  628. /**
  629. * Returns list of all ONUs signals on OLTS as [oltId][onuMac/onuSerial]=>signal in db
  630. *
  631. * @return array
  632. */
  633. public function getSignalsOLTAll() {
  634. $containerPath = self::SIGCACHE_PATH;
  635. $containerMark = self::SIGCACHE_EXT;
  636. $oltData = new OLTAttractor();
  637. $result = array();
  638. $allContainers = $this->getContainers($containerPath, $containerMark);
  639. if (!empty($allContainers)) {
  640. foreach ($allContainers as $eachOltId => $eachContainer) {
  641. $oltData->setOltId($eachOltId);
  642. $eachOltSignals = $oltData->readSignals();
  643. $result[$eachOltId] = $eachOltSignals;
  644. }
  645. }
  646. return ($result);
  647. }
  648. /**
  649. * Returns per-OLT ONUs FDB cache as [oltId]=>fdbStruct (see readFdb)
  650. *
  651. * @return array
  652. */
  653. public function getFdbOLTAll() {
  654. $containerPath = self::FDBCACHE_PATH;
  655. $containerMark = self::FDBCACHE_EXT;
  656. $oltData = new OLTAttractor();
  657. $result = array();
  658. $allContainers = $this->getContainers($containerPath, $containerMark);
  659. if (!empty($allContainers)) {
  660. foreach ($allContainers as $eachOltId => $eachContainer) {
  661. $oltData->setOltId($eachOltId);
  662. $eachOltFdb = $oltData->readFdb();
  663. $result[$eachOltId] = $eachOltFdb;
  664. }
  665. }
  666. return ($result);
  667. }
  668. /**
  669. * Public methods to perform fast data availability checks without containers reading
  670. */
  671. /**
  672. * Checks is any distances data available?
  673. *
  674. * @return bool
  675. */
  676. public function isDistancesAvailable() {
  677. $containerPath = self::DISTCACHE_PATH;
  678. $containerMark = self::DISTCACHE_EXT;
  679. return ($this->checkContainersAvailable($containerPath, $containerMark));
  680. }
  681. /**
  682. * Checks is any interfaces data available?
  683. *
  684. * @return bool
  685. */
  686. public function isInterfacesAvailable() {
  687. $containerPath = self::INTCACHE_PATH;
  688. $containerMark = self::INTCACHE_EXT;
  689. return ($this->checkContainersAvailable($containerPath, $containerMark));
  690. }
  691. /**
  692. * Checks is any deregs data available?
  693. *
  694. * @return bool
  695. */
  696. public function isDeregsAvailable() {
  697. $containerPath = self::DEREGCACHE_PATH;
  698. $containerMark = self::DEREGCACHE_EXT;
  699. return ($this->checkContainersAvailable($containerPath, $containerMark));
  700. }
  701. /**
  702. * Checks is any interface descriptions data available?
  703. *
  704. * @return bool
  705. */
  706. public function isInterfacesDescriptionsAvailable() {
  707. $containerPath = self::INTCACHE_PATH;
  708. $containerMark = self::INTDESCRCACHE_EXT;
  709. return ($this->checkContainersAvailable($containerPath, $containerMark));
  710. }
  711. /**
  712. * Checks is any ONU FDB data available?
  713. *
  714. * @return bool
  715. */
  716. public function isFdbAvailable() {
  717. $containerPath = self::FDBCACHE_PATH;
  718. $containerMark = self::FDBCACHE_EXT;
  719. return ($this->checkContainersAvailable($containerPath, $containerMark));
  720. }
  721. /**
  722. * Checks is any ONU cache data available?
  723. *
  724. * @return bool
  725. */
  726. public function isOnusAvailable() {
  727. $containerPath = self::ONUCACHE_PATH;
  728. $containerMark = self::ONUCACHE_EXT;
  729. return ($this->checkContainersAvailable($containerPath, $containerMark));
  730. }
  731. /**
  732. * Checks is any ONU signals cache data available?
  733. *
  734. * @return bool
  735. */
  736. public function isSignalsAvailable() {
  737. $containerPath = self::SIGCACHE_PATH;
  738. $containerMark = self::SIGCACHE_EXT;
  739. return ($this->checkContainersAvailable($containerPath, $containerMark));
  740. }
  741. /**
  742. * Performs cleanup of all available cached data
  743. *
  744. * @return int
  745. */
  746. public function flushAllCacheData() {
  747. $allContainers = rcms_scandir(self::CACHE_ROOT_PATH, '*', 'dir');
  748. $result = 0;
  749. if (!empty($allContainers)) {
  750. foreach ($allContainers as $io => $each) {
  751. $containerPath = self::CACHE_ROOT_PATH . $each . '/';
  752. $containersList = rcms_scandir($containerPath);
  753. if (!empty($containersList)) {
  754. foreach ($containersList as $index => $eachContainer)
  755. if ($eachContainer != 'placeholder') {
  756. rcms_delete_files($containerPath . $eachContainer);
  757. $result++;
  758. }
  759. }
  760. }
  761. }
  762. return ($result);
  763. }
  764. /**
  765. * Performs idx lookup in container data array by ONU MAC or Serial and returns value if its exist
  766. *
  767. * @param array $onuData ONU data array with mac/serial keys
  768. * @param array $containerArr Container content array like with signals or dereg reasons
  769. *
  770. * @return mixed
  771. */
  772. public function lookupOnuIdxValue($onuData, $containerArr) {
  773. $result = false;
  774. if (is_array($onuData)) {
  775. if (isset($onuData['mac']) and isset($onuData['serial'])) {
  776. if (!empty($containerArr)) {
  777. if (!empty($onuData['mac'])) {
  778. if (isset($containerArr[$onuData['mac']])) {
  779. $result = $containerArr[$onuData['mac']];
  780. }
  781. }
  782. if (!empty($onuData['serial'])) {
  783. if (isset($containerArr[$onuData['serial']])) {
  784. $result = $containerArr[$onuData['serial']];
  785. }
  786. }
  787. }
  788. }
  789. }
  790. return ($result);
  791. }
  792. }