LAG.php 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  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;
  30. /**
  31. * A class for performing SNMP V2 queries on generic devices
  32. *
  33. * @copyright Copyright (c) 2012, Open Source Solutions Limited, Dublin, Ireland
  34. * @author Barry O'Donovan <barry@opensolutions.ie>
  35. */
  36. class LAG extends \OSS_SNMP\MIB
  37. {
  38. /**
  39. * The identifier value (port ID) of the Aggregator that this Aggregation Port is currently attached
  40. * to. Zero indicates that the Aggregation Port is not currently attached to an Aggregator.
  41. */
  42. const OID_LAG_PORT_ATTACHED_ID = '.1.2.840.10006.300.43.1.2.1.1.13';
  43. /**
  44. * Boolean value indicating whether the Aggregator represents an Aggregate (`TRUE') or an Individual link (`FALSE')
  45. */
  46. const OID_LAG_AGGREGATE_OR_INDIVIDUAL = '.1.2.840.10006.300.43.1.2.1.1.24';
  47. /**
  48. * Returns an associate array of port IDs with a boolean value to indicate if it's an aggregate port (true)
  49. * or an individual port (false).
  50. *
  51. * @return array Associate array of port IDs with a boolean value to indicate if it's an aggregate port (true) or not
  52. */
  53. public function isAggregatePorts()
  54. {
  55. return $this->getSNMP()->ppTruthValue( $this->getSNMP()->walk1d( self::OID_LAG_AGGREGATE_OR_INDIVIDUAL ) );
  56. }
  57. /**
  58. * Returns an associate array of port IDs with the ID of the aggregate port that
  59. * they are a member of (else 0 if not a LAG port)
  60. *
  61. *
  62. * @return array Associate array of port IDs with the ID of the aggregate port that they are a member of
  63. */
  64. public function portAttachedIds()
  65. {
  66. return $this->getSNMP()->walk1d( self::OID_LAG_PORT_ATTACHED_ID );
  67. }
  68. /**
  69. * Gets an associate array of LAG ports with the [id] => name of it's constituent ports
  70. *
  71. * E.g.:
  72. * [5048] => Array
  73. * (
  74. * [10111] => GigabitEthernet1/0/11
  75. * [10112] => GigabitEthernet1/0/12
  76. * )
  77. *
  78. * @return array Associate array of LAG ports with the [id] => name of it's constituent ports
  79. */
  80. public function getLAGPorts()
  81. {
  82. $ports = array();
  83. foreach( $this->portAttachedIds() as $portId => $aggPortId )
  84. if( $aggPortId != 0 )
  85. $ports[ $aggPortId ][$portId] = $this->getSNMP()->useIface()->names()[$portId];
  86. return $ports;
  87. }
  88. /**
  89. * Utility function to identify configured but unattached LAG ports
  90. *
  91. * @return array Array of indexed port ids (array index, not value) of configured but unattached LAG ports
  92. */
  93. public function findFailedLAGPorts()
  94. {
  95. // find all configured LAG ports
  96. $lagPorts = $this->isAggregatePorts();
  97. // find all attached ports
  98. $attachedPorts = $this->portAttachedIds();
  99. foreach( $lagPorts as $portId => $isLAG )
  100. {
  101. if( !$isLAG )
  102. {
  103. unset( $lagPorts[ $portId ] );
  104. continue;
  105. }
  106. if( $attachedPorts[ $portId ] != 0 )
  107. unset( $lagPorts[ $portId ] );
  108. }
  109. // we should be left with configured but unattached LAG ports
  110. return( $lagPorts );
  111. }
  112. }