Advertisement
Guest User

Untitled

a guest
Jun 23rd, 2014
471
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.66 KB | None | 0 0
  1. <?php
  2.  
  3.  
  4. class OltTelnetReq
  5. {
  6.     public $commands_olt = array(
  7.         'GET_ALL_ONU_INFO' => 'show epon onu-information',
  8.         'GET_MAC_INTERFACE' => 'show mac address-table dynamic interface ', // concat interface
  9.         'GET_ALL_OPT_PARAMS' => 'show epon optical-transceiver-diagnosis',
  10.         'GET_ALL_MAC_ON_INTERFACES' => 'show mac address-table',
  11.     );
  12.     public $telnet;
  13.     public $num_olt;
  14.  
  15.     /**
  16.      * Устанавливает телнет соединение с Олтом
  17.      * @param $olt_num
  18.      */
  19.     public function telnet_connected($IP)
  20.     {
  21.         $this->telnet = new Telnet($IP, '23', '60', 'User Access Verification');
  22.         $this->telnet->login('login', 'pass');
  23.         $this->telnet->setPrompt('#');
  24.         $this->telnet->exec('enable');
  25.     }
  26.  
  27.     /**
  28.      * 2 - EPON0/1:1 - port
  29.      * 3 - temp data - BDCM      3022
  30.      * 4 - BDCM - onu brand
  31.      * 5 - 3022 - onu type 3024/3023/3022 P1004/P1504/P1501
  32.      * 6 - fcfa.f79d.02ff - onu mac
  33.      * 7 - auto_conf - status onu - deregiste/auto_conf(online)/lost
  34.      * 8 - power off - reson dereg - power off/N/A(online)/wire down(lost link)
  35.      */
  36.     public function get_epon_onu_info()
  37.     {
  38.         $preg_epon_all_info = '/((EPON0\/[\d]{1,2}:[\d]{1,2})\s*(([A-Za-z]{3,4})\s*([0-9a-zA-Z]{3,4})){0,1}\s*([a-f0-9]{4}.[a-f0-9]{4}.[a-f0-9]{4})[\w\W]*(deregiste|auto_conf|lost)[\w\W]*(N\/A|power\soff|wire\sdown|unknow))+/iU';
  39.         preg_match_all($preg_epon_all_info, $this->telnet->exec($this->commands_olt['GET_ALL_ONU_INFO']), $match);
  40.         return $match;
  41.     }
  42.  
  43.     /**
  44.      * 2 - 11 - VLAN ID
  45.      * 3 - fcfa.f79d.02ff - onu mac
  46.      * 4 - DYNAMIC - address type
  47.      * 5 - epon0/1:1 - port
  48.      */
  49.     public function get_macs_on_interface($interface)
  50.     {
  51.         $preg_get_address_info = '/(([\d]{2})[\s]*([a-f0-9]{4}.[a-f0-9]{4}.[a-f0-9]{4})[\w\W]*(DYNAMIC)[\w\W]*(epon0\/[\d]{1,2}:[\d]{1,2})(?=\s|$))+/iU';
  52.         preg_match_all($preg_get_address_info, $this->telnet->exec($this->commands_olt['GET_MAC_INTERFACE'] . $interface), $match);
  53.         return $match;
  54.  
  55.  
  56.     }
  57.  
  58.     /**
  59.      * 2 - 11 - VLAN ID
  60.      * 3 - fcfa.f79d.02ff - onu mac
  61.      * 4 - DYNAMIC - address type
  62.      * 5 - epon0/1:1 - port
  63.      */
  64.     public function get_all_macs_on_interfaces()
  65.     {
  66.         $pairs_data = array();
  67.         $preg_get_address_info = '/(([\d]*)\s*([a-f0-9]{4}.[a-f0-9]{4}.[a-f0-9]{4})\s*(DYNAMIC)\s*(epon0\/[\d]{1,2}:[\d]{1,2})(?=\s|$))+/iU';
  68.         preg_match_all($preg_get_address_info, $this->telnet->exec($this->commands_olt['GET_ALL_MAC_ON_INTERFACES']), $match);
  69.         foreach ($match[3] as $k => $mac) {
  70.             if ($match[2][$k] == 1)
  71.                 $pairs_data[$match[5][$k]]['mac_onu'] = $mac;
  72.             else {
  73.                 $pairs_data[$match[5][$k]]['info_client'][] = array('mac' => $mac, 'vlan' => $match[2][$k]);
  74.             }
  75.         }
  76.         return $pairs_data;
  77.     }
  78.  
  79.     /**
  80.      * 2 - epon0/1:1 - port
  81.      * 3 - -27.1 - optical param
  82.      */
  83.     public function get_all_optical_params()
  84.     {
  85.         $preg_get_optical_params = '/((epon0\/[\d]{1,2}:[\d]{1,2})\s[\w\W]*(-[\d]{1,2}.[\d]))+/iU';
  86.         preg_match_all($preg_get_optical_params, $this->telnet->exec($this->commands_olt['GET_ALL_OPT_PARAMS']), $match);
  87.         return $match;
  88.     }
  89.  
  90.     /**
  91.      * 1 - -18 - signal level
  92.      */
  93.     public function get_optical_params($interface)
  94.     {
  95.         $preg_get_optical_params = '/received\spower\(DBm\):\s(-\d*.\d)/i';
  96.         preg_match($preg_get_optical_params, $this->telnet->exec('sh epon interface ' . $interface . ' onu ctc optical-transceiver-diagnosis'), $match);
  97.         return $match;
  98.     }
  99.  
  100. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement