RSTP.php 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  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 RSTP extends \OSS\SNMP\MIBS\Cisco
  37. {
  38. const OID_STP_X_RSTP_PORT_ROLE = '.1.3.6.1.4.1.9.9.82.1.12.2.1.3'; // add '.$VID'; integer
  39. /**
  40. * Constant for possible value of STP extensions RSTP Port Role
  41. * @see rstpPortRole()
  42. */
  43. const STP_X_RSTP_PORT_ROLE_DISABLED = 1;
  44. /**
  45. * Constant for possible value of STP extensions RSTP Port Role
  46. * @see rstpPortRole()
  47. */
  48. const STP_X_RSTP_PORT_ROLE_ROOT = 2;
  49. /**
  50. * Constant for possible value of STP extensions RSTP Port Role
  51. * @see rstpPortRole()
  52. */
  53. const STP_X_RSTP_PORT_ROLE_DESIGNATED = 3;
  54. /**
  55. * Constant for possible value of STP extensions RSTP Port Role
  56. * @see rstpPortRole()
  57. */
  58. const STP_X_RSTP_PORT_ROLE_ALTERNATE = 4;
  59. /**
  60. * Constant for possible value of STP extensions RSTP Port Role
  61. * @see rstpPortRole()
  62. */
  63. const STP_X_RSTP_PORT_ROLE_BACKUP = 5;
  64. /**
  65. * Constant for possible value of STP extensions RSTP Port Role
  66. * @see rstpPortRole()
  67. */
  68. const STP_X_RSTP_PORT_ROLE_BOUNDARY = 6;
  69. /**
  70. * Constant for possible value of STP extensions RSTP Port Role
  71. * @see rstpPortRole()
  72. */
  73. const STP_X_RSTP_PORT_ROLE_MASTER = 6;
  74. /**
  75. * Text representation of STP extensions RSTP Port Roles
  76. *
  77. * @see rstpPortRole()
  78. * @var array Text representations of STP extensions RSTP Port Role.
  79. */
  80. public static $STP_X_RSTP_PORT_ROLES = array(
  81. self::STP_X_RSTP_PORT_ROLE_DISABLED => 'disabled',
  82. self::STP_X_RSTP_PORT_ROLE_ROOT => 'root',
  83. self::STP_X_RSTP_PORT_ROLE_DESIGNATED => 'designated',
  84. self::STP_X_RSTP_PORT_ROLE_ALTERNATE => 'alternate',
  85. self::STP_X_RSTP_PORT_ROLE_BACKUP => 'backUp',
  86. self::STP_X_RSTP_PORT_ROLE_BOUNDARY => 'boundary',
  87. self::STP_X_RSTP_PORT_ROLE_MASTER => 'master'
  88. );
  89. /**
  90. * Array of port states that indicate traffic is/can pass
  91. * @var Array of port states that indicate traffic is/can pass
  92. */
  93. public static $STP_X_RSTP_PASSING_PORT_ROLES = array(
  94. self::STP_X_RSTP_PORT_ROLE_ROOT => 'root',
  95. self::STP_X_RSTP_PORT_ROLE_DESIGNATED => 'designated'
  96. );
  97. /**
  98. * Get the device's RSTP port roles (by given vlan id)
  99. *
  100. * Only ports participating in RSTP for the given VLAN id are returned.
  101. *
  102. * This function will also convert STP port IDs to the device proper port IDs.
  103. * E.g. sample output:
  104. *
  105. * Array
  106. * (
  107. * [10101] => 3
  108. * [10103] => 3
  109. * [10105] => 3
  110. * [5048] => 2
  111. * )
  112. *
  113. *
  114. * @see $STP_X_RSTP_PORT_ROLES
  115. * @see STP_X_RSTP_PORT_ROLE_ROOT and others
  116. *
  117. * @param int $vid The RSTP VLAN ID to query port roles for
  118. * @param boolean $translate If true, return the string representation via self::$STP_X_RSTP_PORT_ROLES
  119. * @return array The device's RSTP port roles (by given vlan id)
  120. */
  121. public function rstpPortRole( $vid, $translate = false )
  122. {
  123. $roles = $this->getSNMP()->walk1d( self::OID_STP_X_RSTP_PORT_ROLE . ".{$vid}" );
  124. // convert STP port IDs to switch port IDs
  125. $croles = array();
  126. foreach( $roles as $k => $v )
  127. {
  128. $base = $this->getSNMP()->useBridge()->basePortIfIndexes()[$k];
  129. if( $base )
  130. $croles[ $base ] = $v;
  131. else
  132. {
  133. // and and get port ID from MIBS\Entity
  134. // TODO Find a better way to translate these?
  135. $croles[ $this->getSNMP()->useEntity()->relPosToAlias()[$k] ] = $v;
  136. }
  137. }
  138. if( !$translate )
  139. return $croles;
  140. return $this->getSNMP()->translate( $croles, self::$STP_X_RSTP_PORT_ROLES );
  141. }
  142. }