VTP.php 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299
  1. <?php
  2. /*
  3. Copyright (c) 2012, Open Source Solutions Limited, Dublin, Ireland
  4. All rights reserved.
  5. Contact: Barry O'Donovan - barry (at) opensolutions (dot) ie
  6. http://www.opensolutions.ie/
  7. This file is part of the OSS_SNMP package.
  8. Redistribution and use in source and binary forms, with or without
  9. modification, are permitted provided that the following conditions are met:
  10. * Redistributions of source code must retain the above copyright
  11. notice, this list of conditions and the following disclaimer.
  12. * Redistributions in binary form must reproduce the above copyright
  13. notice, this list of conditions and the following disclaimer in the
  14. documentation and/or other materials provided with the distribution.
  15. * Neither the name of Open Source Solutions Limited nor the
  16. names of its contributors may be used to endorse or promote products
  17. derived from this software without specific prior written permission.
  18. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
  19. ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  20. WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  21. DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
  22. DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  23. (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  24. LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  25. ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  26. (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  27. SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  28. */
  29. namespace OSS\SNMP\MIBS\Cisco;
  30. /**
  31. * A class for performing SNMP V2 queries on Cisco devices
  32. *
  33. * @copyright Copyright (c) 2012, Open Source Solutions Limited, Dublin, Ireland
  34. * @author Barry O'Donovan <barry@opensolutions.ie>
  35. */
  36. class VTP extends \OSS\SNMP\MIBS\Cisco
  37. {
  38. const OID_VTP_VLAN_STATUS = '.1.3.6.1.4.1.9.9.46.1.3.1.1.2.1';
  39. const OID_VTP_VLAN_TYPE = '.1.3.6.1.4.1.9.9.46.1.3.1.1.3.1';
  40. const OID_VTP_VLAN_NAME = '.1.3.6.1.4.1.9.9.46.1.3.1.1.4.1';
  41. const OID_STP_X_RSTP_PORT_ROLE = '.1.3.6.1.4.1.9.9.82.1.12.2.1.3'; // add '.$VID'; integer
  42. /**
  43. * Constant for possible value of VTP VLAN status.
  44. * @see vlanStates()
  45. */
  46. const VTP_VLAN_STATE_OPERATIONAL = 1;
  47. /**
  48. * Constant for possible value of VTP VLAN status.
  49. * @see vlanStates()
  50. */
  51. const VTP_VLAN_STATE_SUSPENDED = 2;
  52. /**
  53. * Constant for possible value of VTP VLAN status.
  54. * @see vlanStates()
  55. */
  56. const VTP_VLAN_STATE_MTU_TOO_BIG_FOR_DEVICE = 3;
  57. /**
  58. * Constant for possible value of VTP VLAN status.
  59. * @see vlanStates()
  60. */
  61. const VTP_VLAN_STATE_MTU_TOO_BIG_FOR_TRUNK = 4;
  62. /**
  63. * Text representation of VTP VLAN status.
  64. *
  65. * @see vlanStates()
  66. * @var array Text representations of VTP VLAN status.
  67. */
  68. public static $VTP_VLAN_STATES = array(
  69. self::VTP_VLAN_STATE_OPERATIONAL => 'operational',
  70. self::VTP_VLAN_STATE_SUSPENDED => 'suspended',
  71. self::VTP_VLAN_STATE_MTU_TOO_BIG_FOR_DEVICE => 'mtuTooBigForDevice',
  72. self::VTP_VLAN_STATE_MTU_TOO_BIG_FOR_TRUNK => 'mtuTooBigForTrunk'
  73. );
  74. /**
  75. * Get the device's VTP VLAN States (indexed by VLAN ID)
  76. *
  77. * @see $VTP_VLAN_STATES
  78. * @see VTP_VLAN_STATE_OPERATIONAL and others
  79. *
  80. * @param boolean $translate If true, return the string representation via self::$VTP_VLAN_TYPES
  81. * @return array The device's VTP VLAN States (indexed by VLAN ID)
  82. */
  83. public function vlanStates( $translate = false )
  84. {
  85. $states = $this->getSNMP()->walk1d( self::OID_VTP_VLAN_STATUS );
  86. if( !$translate )
  87. return $states;
  88. return $this->getSNMP()->translate( $states, self::$VTP_VLAN_STATES );
  89. }
  90. /**
  91. * Constant for possible value of VTP VLAN type.
  92. * @see vlanTypes()
  93. */
  94. const VTP_VLAN_TYPE_ETHERNET = 1;
  95. /**
  96. * Constant for possible value of VTP VLAN type.
  97. * @see vlanTypes()
  98. */
  99. const VTP_VLAN_TYPE_FDDI = 2;
  100. /**
  101. * Constant for possible value of VTP VLAN type.
  102. * @see vlanTypes()
  103. */
  104. const VTP_VLAN_TYPE_TOKEN_RING = 3;
  105. /**
  106. * Constant for possible value of VTP VLAN type.
  107. * @see vlanTypes()
  108. */
  109. const VTP_VLAN_TYPE_FDDI_NET = 4;
  110. /**
  111. * Constant for possible value of VTP VLAN type.
  112. * @see vlanTypes()
  113. */
  114. const VTP_VLAN_TYPE_TR_NET = 5;
  115. /**
  116. * Constant for possible value of VTP VLAN type.
  117. * @see vlanTypes()
  118. */
  119. const VTP_VLAN_TYPE_DEPRECATED = 6;
  120. /**
  121. * Text representation of VTP VLAN types.
  122. *
  123. * @see vlanTypes()
  124. * @var array Text representations of VTP VLAN types.
  125. */
  126. public static $VTP_VLAN_TYPES = array(
  127. self::VTP_VLAN_TYPE_ETHERNET => 'ethernet',
  128. self::VTP_VLAN_TYPE_FDDI => 'fddi',
  129. self::VTP_VLAN_TYPE_TOKEN_RING => 'tokenRing',
  130. self::VTP_VLAN_TYPE_FDDI_NET => 'fddiNet',
  131. self::VTP_VLAN_TYPE_TR_NET => 'trNet',
  132. self::VTP_VLAN_TYPE_DEPRECATED => 'deprecated'
  133. );
  134. /**
  135. * Get the device's VTP VLAN Types (indexed by VLAN ID)
  136. *
  137. * @see $VTP_VLAN_TYPES
  138. * @see VTP_VLAN_TYPE_ETHERNET and others
  139. *
  140. * @param boolean $translate If true, return the string representation via self::$VTP_VLAN_TYPES
  141. * @return array The device's VTP VLAN types (indexed by VLAN ID)
  142. */
  143. public function vlanTypes( $translate = false )
  144. {
  145. $types = $this->getSNMP()->walk1d( self::OID_VTP_VLAN_TYPE );
  146. if( !$translate )
  147. return $types;
  148. return $this->getSNMP()->translate( $types, self::$VTP_VLAN_TYPES );
  149. }
  150. /**
  151. * Get the device's VTP VLAN names (indexed by VLAN ID)
  152. *
  153. * @return array The device's VTP VLAN names (indexed by VLAN ID)
  154. */
  155. public function vlanNames()
  156. {
  157. return $this->getSNMP()->walk1d( self::OID_VTP_VLAN_NAME );
  158. }
  159. /**
  160. * Constant for possible value of STP extensions RSTP Port Role
  161. * @see stpxRstpPortRole()
  162. */
  163. const STP_X_RSTP_PORT_ROLE_DISABLED = 1;
  164. /**
  165. * Constant for possible value of STP extensions RSTP Port Role
  166. * @see stpxRstpPortRole()
  167. */
  168. const STP_X_RSTP_PORT_ROLE_ROOT = 2;
  169. /**
  170. * Constant for possible value of STP extensions RSTP Port Role
  171. * @see stpxRstpPortRole()
  172. */
  173. const STP_X_RSTP_PORT_ROLE_DESIGNATED = 3;
  174. /**
  175. * Constant for possible value of STP extensions RSTP Port Role
  176. * @see stpxRstpPortRole()
  177. */
  178. const STP_X_RSTP_PORT_ROLE_ALTERNATE = 4;
  179. /**
  180. * Constant for possible value of STP extensions RSTP Port Role
  181. * @see stpxRstpPortRole()
  182. */
  183. const STP_X_RSTP_PORT_ROLE_BACKUP = 5;
  184. /**
  185. * Constant for possible value of STP extensions RSTP Port Role
  186. * @see stpxRstpPortRole()
  187. */
  188. const STP_X_RSTP_PORT_ROLE_BOUNDARY = 6;
  189. /**
  190. * Constant for possible value of STP extensions RSTP Port Role
  191. * @see stpxRstpPortRole()
  192. */
  193. const STP_X_RSTP_PORT_ROLE_MASTER = 6;
  194. /**
  195. * Text representation of STP extensions RSTP Port Roles
  196. *
  197. * @see stpxRstpPortRole()
  198. * @var array Text representations of STP extensions RSTP Port Role.
  199. */
  200. public static $STP_X_RSTP_PORT_ROLES = array(
  201. self::STP_X_RSTP_PORT_ROLE_DISABLED => 'disabled',
  202. self::STP_X_RSTP_PORT_ROLE_ROOT => 'root',
  203. self::STP_X_RSTP_PORT_ROLE_DESIGNATED => 'designated',
  204. self::STP_X_RSTP_PORT_ROLE_ALTERNATE => 'alternate',
  205. self::STP_X_RSTP_PORT_ROLE_BACKUP => 'backUp',
  206. self::STP_X_RSTP_PORT_ROLE_BOUNDARY => 'boundary',
  207. self::STP_X_RSTP_PORT_ROLE_MASTER => 'master'
  208. );
  209. /**
  210. * Get the device's RSTP port roles (by given vlan id)
  211. *
  212. * Only ports participating in RSTP for the given VLAN id are returned.
  213. *
  214. * This function will also convert STP port IDs to the device proper port IDs.
  215. * E.g. sample output:
  216. *
  217. * Array
  218. * (
  219. * [10101] => 3
  220. * [10103] => 3
  221. * [10105] => 3
  222. * [5048] => 2
  223. * )
  224. *
  225. *
  226. * @see $STP_X_RSTP_PORT_ROLES
  227. * @see STP_X_RSTP_PORT_ROLE_ROOT and others
  228. *
  229. * @param int $vid The RSTP VLAN ID to query port roles for
  230. * @param boolean $translate If true, return the string representation via self::$STP_X_RSTP_PORT_ROLES
  231. * @return array The device's RSTP port roles (by given vlan id)
  232. */
  233. public function rstpPortRole( $vid, $translate = false )
  234. {
  235. $roles = $this->getSNMP()->walk1d( self::OID_STP_X_RSTP_PORT_ROLE . ".{$vid}" );
  236. // convert STP port IDs to switch port IDs
  237. $croles = array();
  238. foreach( $roles as $k => $v )
  239. $croles[ $this->bridgeBasePortIfIndexes()[$k] ] = $v;
  240. if( !$translate )
  241. return $croles;
  242. return self::translate( $croles, self::$STP_X_RSTP_PORT_ROLES );
  243. }
  244. }