DocsIfCmts.php 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320
  1. <?php
  2. namespace OSS_SNMP\MIBS;
  3. class DocsIfCmts extends \OSS_SNMP\MIB {
  4. const OID_docsIfCmtsCmStatusMacAddress = "1.3.6.1.2.1.10.127.1.3.3.1.2";
  5. //const OID_docsIfCmtsCmStatusTable = "1.3.6.1.2.1.10.127.1.3.3";
  6. const OID_docsIfCmtsCmStatusUpChannelIfIndex = "1.3.6.1.2.1.10.127.1.3.3.1.5";
  7. const OID_docsIfCmtsCmStatusDownChannelIfIndex = "1.3.6.1.2.1.10.127.1.3.3.1.4";
  8. const OID_docsIfCmtsCmStatusIpAddress = "1.3.6.1.2.1.10.127.1.3.3.1.3";
  9. const OID_docsQosCmtsIfIndex = "1.3.6.1.2.1.10.127.7.1.11.1.3";
  10. const OID_docsQos3CmtsIfIndex = "1.3.6.1.4.1.4491.2.1.21.1.11.1.3";
  11. const OID_docsIfCmtsCmStatusIndex = "1.3.6.1.2.1.10.127.1.3.3.1.1";
  12. const OID_docsQosServiceFlowOctets = "1.3.6.1.2.1.10.127.7.1.4.1.2";
  13. const OID_docsQosServiceFlowDirection = "1.3.6.1.2.1.10.127.7.1.3.1.7";
  14. const OID_docsQos3ServiceFlowDirection = "1.3.6.1.4.1.4491.2.1.21.1.3.1.7";
  15. const OID_docsIfCmtsCmStatusRxPower = "1.3.6.1.2.1.10.127.1.3.3.1.6";
  16. const OID_docsIfCmtsCmStatusValue = "1.3.6.1.2.1.10.127.1.3.3.1.9";
  17. const OID_docsQos3ServiceFlowOctets = "1.3.6.1.4.1.4491.2.1.21.1.4.1.2";
  18. const OID_docsIfSigQSignalNoise = "1.3.6.1.2.1.10.127.1.1.4.1.5";
  19. const OID_docsIfSigQMicroreflections = "1.3.6.1.2.1.10.127.1.1.4.1.6";
  20. const docsIfCmtsChannelUtilization = "1.3.6.1.2.1.10.127.1.3.9.1.3";
  21. const OID_ipNetToMediaPhysAddress = "1.3.6.1.2.1.4.22.1.2";
  22. const OID_docsIfCmtsCmPtr = "1.3.6.1.2.1.10.127.1.3.7.1.2";
  23. const OID_docsIfCmStatusTxPower = "1.3.6.1.2.1.10.127.1.2.2.1.3";
  24. public function docsIfCmtsCmPtr(){
  25. $ptr = array();
  26. foreach($this->getSNMP()->realWalk(self::OID_docsIfCmtsCmPtr) as $key => $val){
  27. $mac =implode('',array_map(function($x) { return sprintf("%02x", $x);}, array_slice(explode(".",$key),14,6)));
  28. $ptr[$mac] = $this->getSNMP()->parseSnmpValue($val);
  29. }
  30. return $ptr;
  31. }
  32. public function ipNetToMediaPhysAddress(){
  33. $rtr = array();
  34. foreach($this->getSNMP()->realWalk(self::OID_ipNetToMediaPhysAddress) as $k => $m){
  35. ////tring(40) ".1.3.6.1.2.1.4.22.1.2.2000001.10.14.8.69"
  36. //string(23) "STRING: 0:c:e5:7d:93:d0"
  37. ////
  38. $karray = preg_split("|\.|",$k);
  39. $mac = preg_split("|:|", trim(substr($m,8)));
  40. $mac = sprintf("%02x:%02x:%02x:%02x:%02x:%02x",$mac[0], $mac[1], $mac[2], $mac[3], $mac[4], $mac[5]);
  41. $l_ke = count($karray);
  42. $rtr[$mac] = sprintf("%d.%d.%d.%d",$karray[$l_ke - 4],$karray[$l_ke - 3], $karray[$l_ke - 2], $karray[$l_ke-1]);
  43. }
  44. return $rtr;
  45. }
  46. public function docsQos3ServiceFlowDirection($translate=false){
  47. $rtr = array();
  48. $oid = self::OID_docsQos3ServiceFlowDirection;
  49. $stats = $this->getSNMP()->realWalk($oid);
  50. foreach((array)$stats as $k => $v){
  51. $k_prim = preg_split("|\.|",$k);
  52. //$dds = strpos($v, ':');
  53. if(!isset($k_prim[15])){
  54. continue;
  55. }
  56. $rtr[$k_prim[15].".".$k_prim[16]] = $this->getSNMP()->parseSnmpValue($v);
  57. }
  58. if( !$translate )
  59. return $rtr;
  60. return $this->getSNMP()->translate( $rtr, self::$FLOW_DIRECTIONS);
  61. }
  62. public function docsQos3ServiceFlowDirectionX($translate=false, $id=null){
  63. $rtr = array();
  64. if(is_null($id)) $oid = self::OID_docsQos3ServiceFlowDirection;
  65. else $oid = self::OID_docsQos3ServiceFlowDirection. "." .$id;
  66. $stats = $this->getSNMP()->realWalk($oid);
  67. foreach((array)$stats as $k => $v){
  68. $k_prim = preg_split("|\.|",$k);
  69. //$dds = strpos($v, ':');
  70. if(!isset($k_prim[15])){
  71. break;
  72. }
  73. $rtr[$k_prim[15].".".$k_prim[16]] = $this->getSNMP()->parseSnmpValue($v);
  74. }
  75. if( !$translate )
  76. return $rtr;
  77. return $this->getSNMP()->translate( $rtr, self::$FLOW_DIRECTIONS);
  78. }
  79. private function getDecMac($mac){
  80. preg_match('/^([a-f0-9]{1,2})[-:]*([a-f0-9]{1,2})[-:]*([a-f0-9]{1,2})[-:]*([a-f0-9]{1,2})[-:]*([a-f0-9]{1,2})[-:]*([a-f0-9]{1,2})$/i', $mac, $matches);
  81. unset($matches[0]);
  82. return implode('.', array_map('hexdec', $matches));
  83. }
  84. public function docsQos3CmtsIfIndex($mac=null){
  85. $rtr = array();
  86. if(!is_null($mac)){
  87. $oid = self::OID_docsQos3CmtsIfIndex .'.'.$this->getDecMac($mac);
  88. }else{
  89. $oid = self::OID_docsQos3CmtsIfIndex;
  90. }
  91. foreach((array)$this->getSNMP()->realWalk($oid) as $k => $v){
  92. $k_prim = preg_split("|\.|",$k);
  93. if(count($k_prim) < 20){
  94. continue;
  95. }
  96. $k_mac = sprintf("%02x:%02x:%02x:%02x:%02x:%02x",
  97. $k_prim[15], $k_prim[16], $k_prim[17], $k_prim[18], $k_prim[19], $k_prim[20]);
  98. $rtr[$k_mac][] = $this->getSNMP()->parseSnmpValue($v). ".".$k_prim[21];
  99. }
  100. return $rtr;
  101. }
  102. public function docsQos3ServiceFlowOctets($ifId=null){
  103. try{
  104. $rtr = array();
  105. if(!is_null($ifId)){
  106. $oid = self::OID_docsQos3ServiceFlowOctets ."." .$ifId;
  107. }else{
  108. $oid = self::OID_docsQos3ServiceFlowOctets;
  109. }
  110. foreach($this->getSNMP()->realWalk($oid) as $k => $v){
  111. $k_prim = preg_split("|\.|",$k);
  112. $rtr[$k_prim[15].".".$k_prim[16]] = $this->getSNMP()->parseSnmpValue($v);
  113. }
  114. return $rtr;
  115. }catch (\Exception $e){
  116. echo "ouch! ".$e->getMessage()."\n";
  117. return array();
  118. }
  119. }
  120. public static $FLOW_DIRECTIONS = array(1 => "downstream", 2 => 'upstream');
  121. public function docsQosServiceFlowDirection($translate=false){
  122. $oid = self::OID_docsQosServiceFlowDirection;
  123. $states = $this->getSNMP()->walk1d($oid);
  124. $rtr = array();
  125. if( !$translate )
  126. return $states;
  127. return $this->getSNMP()->translate( $states, self::$FLOW_DIRECTIONS);
  128. }
  129. public function docsQosServiceFlowDirectionX($translate=false, $id=null){
  130. if(is_null($id)) $oid = self::OID_docsQosServiceFlowDirection;
  131. else $oid = self::OID_docsQosServiceFlowDirection. "." .$id;
  132. $rtr = array();
  133. if( !$translate ){
  134. return $states = $this->getSNMP()->walk1d($oid);
  135. }
  136. $states = $this->getSNMP()->realWalk($oid);
  137. foreach($states as $k => $v){
  138. $k_p= preg_split("|\.|",$k);
  139. $rtr[$k_p[14].".".$k_p[15]] = self::$FLOW_DIRECTIONS[$this->getSNMP()->parseSnmpValue($v)];
  140. }
  141. return $rtr;
  142. }
  143. public function docsQosCmtsIfIndex($translate = false, $mac=null){
  144. $rtr = array();
  145. if(!is_null($mac)){
  146. $oid = self::OID_docsQosCmtsIfIndex .'.'.$this->getDecMac($mac);
  147. }else{
  148. $oid = self::OID_docsQosCmtsIfIndex;
  149. }
  150. $ifIndex = $this->getSNMP()->realWalk($oid);
  151. foreach((array)$ifIndex as $k => $v){
  152. $k_prim = preg_split("|\.|",$k);
  153. if(!isset($k_prim[14]) OR !isset($k_prim[15]) OR !isset($k_prim[16]) OR !isset($k_prim[17]) OR !isset($k_prim[18]) OR !isset($k_prim[19])){
  154. continue;
  155. }
  156. $k_mac = sprintf("%02x:%02x:%02x:%02x:%02x:%02x",
  157. $k_prim[14], $k_prim[15], $k_prim[16], $k_prim[17], $k_prim[18], $k_prim[19]);
  158. if(!$translate)
  159. $rtr[$k_mac][] = $k_prim[20]; //$this->getSNMP()->parseSnmpValue($v);
  160. else
  161. $rtr[$k_mac][] =$this->getSNMP()->parseSnmpValue($v).".". $k_prim[20];
  162. }
  163. return $rtr;
  164. }
  165. public function docsQosServiceFlowOctets($translate = false, $ifId=null){
  166. if(!is_null($ifId)){
  167. $oid = self::OID_docsQosServiceFlowOctets ."." .$ifId;
  168. }else{
  169. $oid = self::OID_docsQosServiceFlowOctets;
  170. }
  171. $rtr = array();
  172. if($translate) foreach($this->getSNMP()->realWalk($oid) as $k => $v){
  173. $k_prim = preg_split("|\.|",$k);
  174. $rtr[$k_prim[14].".".$k_prim[15]] = $this->getSNMP()->parseSnmpValue($v);
  175. }
  176. else
  177. $rtr = $this->getSNMP()->walk1d($oid);
  178. return $rtr;
  179. }
  180. /**
  181. other(1)   Any state other than below.
  182. ranging(2)   The CMTS has received an Initial Ranging Request   message from the CM, and the ranging process is not  yet   complete.
  183. rangingAborted(3)   The CMTS has sent a Ranging Abort message to the CM.
  184. rangingComplete(4)   The CMTS has sent a Ranging Complete message to the CM.
  185. ipComplete(5)   The CMTS has received a DHCP reply message and forwarded   it to the CM.
  186. registrationComplete(6)   The CMTS has sent a Registration Response message to the CM.
  187. accessDenied(7)   The CMTS has sent a Registration Aborted message   to the CM.
  188. **/
  189. public function docsIfCmtsCmStatusMacAddress()
  190. {
  191. $rtr = $this->getSNMP()->walk1d(self::OID_docsIfCmtsCmStatusMacAddress);
  192. return $rtr;
  193. }
  194. //public function docsIfCmtsCmStatusIndex(){
  195. // return $this->getSNMP()->walk1d(self::OID_docsIfCmtsCmStatusDownChannelIfIndex);
  196. //}
  197. public function docsIfCmtsCmStatusUpChannelIfIndex(){
  198. return $this->getSNMP()->walk1d(self::OID_docsIfCmtsCmStatusUpChannelIfIndex);
  199. }
  200. public function docsIfCmtsCmStatusDownChannelIfIndex(){
  201. return $this->getSNMP()->walk1d(self::OID_docsIfCmtsCmStatusDownChannelIfIndex);
  202. }
  203. public function docsIfCmtsCmStatusIpAddress(){
  204. return $this->getSNMP()->walk1d(self::OID_docsIfCmtsCmStatusIpAddress);
  205. }
  206. public function docsIfCmtsCmStatusValue(){
  207. $rtr = $this->getSNMP()->walk1d(self::OID_docsIfCmtsCmStatusValue);
  208. $replace = array(1 => 'other' , 2 => 'ranging', 3 => 'rangingAborted', 4 => 'rangingComplete', 5 => 'ipComplete',
  209. 6 => 'registrationComplete', 7 => 'accessDenied');
  210. foreach($rtr as $k => $v){ $rtr[$k] = $replace[$v]; }
  211. return $rtr;
  212. }
  213. public function docsIfCmtsCmStatusRxPower(){
  214. $rtr = $this->getSNMP()->walk1d(self::OID_docsIfCmtsCmStatusRxPower);
  215. return $rtr;
  216. }
  217. public function docsIfSigQSignalNoise(){
  218. $rtr = array();
  219. $data = $this->getSNMP()->realWalk(self::OID_docsIfSigQSignalNoise);
  220. foreach($data as $oid => $val){
  221. sscanf($val,"INTEGER: %f TenthdB", $readval);
  222. $rtr[substr($oid,strlen(self::OID_docsIfSigQSignalNoise)+2)] = $readval;
  223. }
  224. return $rtr;
  225. }
  226. public function docsIfSigQMicroreflections($trans = false){
  227. $oid = self::OID_docsIfSigQMicroreflections;
  228. $rtr = array();
  229. if($trans){
  230. foreach($this->getSNMP()->realWalk($oid) as $oid => $val){
  231. sscanf($val,"INTEGER: %f -dBc", $readval);
  232. $rtr[substr($oid,strlen(self::OID_docsIfSigQSignalNoise)+2)] = $readval;
  233. }
  234. return $rtr;
  235. }else{
  236. return $this->getSNMP()->walk1d(self::OID_docsIfSigQMicroreflections);
  237. }
  238. }
  239. public function docsIfCmtsChannelUtilization(){
  240. return $this->getSNMP()->realWalk(self::docsIfCmtsChannelUtilization);
  241. }
  242. public function docsIfCmStatusTxPower($decode=false){
  243. if(!$decode) return $this->getSNMP()->walk1d(self::OID_docsIfCmStatusTxPower);
  244. else{
  245. $rtr = array();
  246. foreach($this->getSNMP()->realWalk(self::OID_docsIfCmStatusTxPower) as $_oid => $val){
  247. $k = substr($_oid, strlen(self::OID_docsIfCmStatusTxPower)+2);
  248. $rtr[$k] = $this->getSNMP()->parseSnmpValue($val);
  249. }
  250. return $rtr;
  251. }
  252. }
  253. public function getCmStatus($index){
  254. $mibs = array(
  255. 'docsIfCmtsCmStatusMacAddress' => 'docsIfCmtsCmStatusMacAddress',
  256. 'docsIfCmtsCmStatusIpAddress' => 'docsIfCmtsCmStatusIpAddress',
  257. 'docsIfCmtsCmStatusDownChannelIfIndex' => 'docsIfCmtsCmStatusDownChannelIfIndex',
  258. 'docsIfCmtsCmStatusUpChannelIfIndex' => 'docsIfCmtsCmStatusUpChannelIfIndex',
  259. 'docsIfCmtsCmStatusRxPower' => 'docsIfCmtsCmStatusRxPower',
  260. 'docsIfCmtsCmStatusValue' => 'docsIfCmtsCmStatusValue',
  261. 'docsIfCmtsCmStatusUnerroreds' => 'docsIfCmtsCmStatusUnerroreds',
  262. 'docsIfCmtsCmStatusCorrecteds' => 'docsIfCmtsCmStatusCorrecteds',
  263. 'docsIfCmtsCmStatusUncorrectables' => 'docsIfCmtsCmStatusUncorrectables',
  264. 'docsIfCmtsCmStatusSignalNoise' => 'docsIfCmtsCmStatusSignalNoise',
  265. 'docsIfCmtsCmStatusMicroreflections' => 'docsIfCmtsCmStatusMicroreflections',
  266. 'docsIfCmtsCmStatusDocsisRegMode' => 'docsIfCmtsCmStatusDocsisRegMode',
  267. 'docsIfCmtsCmStatusModulationType' => 'docsIfCmtsCmStatusModulationType',
  268. );
  269. foreach($mibs as $k=> $m){
  270. $m .= ".".$index;
  271. $rta = $this->getSNMP()->realWalk($m);
  272. if(!$rta) continue;
  273. $v = current($rta);
  274. $dds = strpos($v, ':');
  275. $v = substr($v, $dds+2);
  276. $rtr[$k] = $v;
  277. }
  278. return $rtr;
  279. }
  280. }