VTP.php 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  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 THE COPYRIGHT OWNER OR CONTRIBUTORS 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. }