BGP.php 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649
  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;
  30. /**
  31. * A class for performing SNMP V2 BGP queries
  32. *
  33. * @see http://tools.cisco.com/Support/SNMP/do/BrowseOID.do?local=en&translate=Translate&objectInput=1.3.6.1.2.1.15
  34. * @copyright Copyright (c) 2012, Open Source Solutions Limited, Dublin, Ireland
  35. * @author Barry O'Donovan <barry@opensolutions.ie>
  36. */
  37. class BGP extends \OSS_SNMP\MIB
  38. {
  39. const OID_BGP_VERSION = '.1.3.6.1.2.1.15.1.0';
  40. const OID_BGP_LOCAL_ASN = '.1.3.6.1.2.1.15.2.0';
  41. const OID_BGP_PEER_IDENTIFIER = '.1.3.6.1.2.1.15.3.1.1';
  42. const OID_BGP_PEER_CONNECTION_STATE = '.1.3.6.1.2.1.15.3.1.2';
  43. const OID_BGP_PEER_ADMIN_STATE = '.1.3.6.1.2.1.15.3.1.3';
  44. const OID_BGP_PEER_NEGOTIATED_VERSION = '.1.3.6.1.2.1.15.3.1.4';
  45. const OID_BGP_PEER_LOCAL_ADDRESS = '.1.3.6.1.2.1.15.3.1.5';
  46. const OID_BGP_PEER_LOCAL_PORT = '.1.3.6.1.2.1.15.3.1.6';
  47. const OID_BGP_PEER_REMOTE_ADDR = '.1.3.6.1.2.1.15.3.1.7';
  48. const OID_BGP_PEER_REMOTE_PORT = '.1.3.6.1.2.1.15.3.1.8';
  49. const OID_BGP_PEER_REMOTE_ASN = '.1.3.6.1.2.1.15.3.1.9';
  50. const OID_BGP_PEER_IN_UPDATES = '.1.3.6.1.2.1.15.3.1.10';
  51. const OID_BGP_PEER_OUT_UPDATES = '.1.3.6.1.2.1.15.3.1.11';
  52. const OID_BGP_PEER_IN_TOTAL_MESSAGES = '.1.3.6.1.2.1.15.3.1.12';
  53. const OID_BGP_PEER_OUT_TOTAL_MESSAGES = '.1.3.6.1.2.1.15.3.1.13';
  54. const OID_BGP_PEER_LAST_ERROR = '.1.3.6.1.2.1.15.3.1.14';
  55. const OID_BGP_PEER_FSM_ESTABLISHED_TRANSITIONS = '.1.3.6.1.2.1.15.3.1.15';
  56. const OID_BGP_PEER_FSM_ESTABLISHED_TIME = '.1.3.6.1.2.1.15.3.1.16';
  57. const OID_BGP_PEER_CONNECT_RETRY_INTERVAL = '.1.3.6.1.2.1.15.3.1.17';
  58. const OID_BGP_PEER_HOLD_TIME = '.1.3.6.1.2.1.15.3.1.18';
  59. const OID_BGP_PEER_KEEP_ALIVE = '.1.3.6.1.2.1.15.3.1.19';
  60. const OID_BGP_PEER_HOLD_TIME_CONFIGURED = '.1.3.6.1.2.1.15.3.1.20';
  61. const OID_BGP_PEER_KEEP_ALIVE_CONFIGURED = '.1.3.6.1.2.1.15.3.1.21';
  62. const OID_BGP_PEER_MIN_AS_ORIGINATION_INTERVAL = '.1.3.6.1.2.1.15.3.1.22';
  63. const OID_BGP_PEER_MIN_ROUTE_ADVERTISEMENT_INTERVAL = '.1.3.6.1.2.1.15.3.1.23';
  64. const OID_BGP_PEER_IN_UPDATE_ELAPSED_TIME = '.1.3.6.1.2.1.15.3.1.24';
  65. const OID_BGP_IDENTIFIER = '.1.3.6.1.2.1.15.4.0';
  66. const OID_BGP_PATH_ATTR_PEER = '.1.3.6.1.2.1.15.6.1.1';
  67. const OID_BGP_PATH_ATTR_ADDR_PREFIX_LENGTH = '.1.3.6.1.2.1.15.6.1.2';
  68. const OID_BGP_PATH_ATTR_ADDR_PREFIX = '.1.3.6.1.2.1.15.6.1.3';
  69. const OID_BGP_PATH_ATTR_ORIGIN = '.1.3.6.1.2.1.15.6.1.4';
  70. const OID_BGP_PATH_ATTR_AS_PATH_SEGMENT = '.1.3.6.1.2.1.15.6.1.5';
  71. const OID_BGP_PATH_ATTR_NEXT_HOP = '.1.3.6.1.2.1.15.6.1.6';
  72. const OID_BGP_PATH_ATTR_MED = '.1.3.6.1.2.1.15.6.1.7';
  73. const OID_BGP_PATH_ATTR_LOCAL_PREF = '.1.3.6.1.2.1.15.6.1.8';
  74. const OID_BGP_PATH_ATTR_ATOMIC_AGGREGATE = '.1.3.6.1.2.1.15.6.1.9';
  75. const OID_BGP_PATH_ATTR_AGGREGATOR_AS = '.1.3.6.1.2.1.15.6.1.10';
  76. const OID_BGP_PATH_ATTR_AGGREGATOR_ADDR = '.1.3.6.1.2.1.15.6.1.11';
  77. const OID_BGP_PATH_ATTR_CALC_LOCAL_PREF = '.1.3.6.1.2.1.15.6.1.12';
  78. const OID_BGP_PATH_ATTR_BEST = '.1.3.6.1.2.1.15.6.1.13';
  79. const OID_BGP_PATH_ATTR_UNKNOWN = '.1.3.6.1.2.1.15.6.1.14';
  80. /**
  81. * Returns the BGP version
  82. *
  83. * > "Vector of supported BGP protocol version numbers. Each peer negotiates the version
  84. * > from this vector. Versions are identified via the string of bits contained within this
  85. * > object. The first octet contains bits 0 to 7, the second octet contains bits 8 to 15,
  86. * > and so on, with the most significant bit referring to the lowest bit number in the
  87. * > octet (e.g., the MSB of the first octet refers to bit 0). If a bit, i, is present
  88. * > and set, then the version (i+1) of the BGP is supported."
  89. *
  90. * @return string Returns the BGP version
  91. */
  92. public function version()
  93. {
  94. return $this->getSNMP()->get( self::OID_BGP_VERSION );
  95. }
  96. /**
  97. * Returns the local BGP AS number
  98. *
  99. * > "The local autonomous system number."
  100. *
  101. * @return int The local autonomous system number.
  102. */
  103. public function localASN()
  104. {
  105. return $this->getSNMP()->get( self::OID_BGP_LOCAL_ASN );
  106. }
  107. /**
  108. * Returns the BGP identifier of all peers indexed by neighbour IPv4 address
  109. *
  110. * > "The BGP Identifier of this entry's BGP peer."
  111. *
  112. * @return array Returns the BGP identifier of all peers indexed by neighbour IPv4 address
  113. */
  114. public function peerIdentifiers()
  115. {
  116. return $this->getSNMP()->walkIPv4( self::OID_BGP_PEER_IDENTIFIER );
  117. }
  118. /**
  119. * Possible value for peer connection state
  120. * @var int Possible value for peer connection state
  121. */
  122. const BGP_PEER_CONNECTION_STATE_IDLE = 1;
  123. /**
  124. * Possible value for peer connection state
  125. * @var int Possible value for peer connection state
  126. */
  127. const BGP_PEER_CONNECTION_STATE_CONNECT = 2;
  128. /**
  129. * Possible value for peer connection state
  130. * @var int Possible value for peer connection state
  131. */
  132. const BGP_PEER_CONNECTION_STATE_ACTIVE = 3;
  133. /**
  134. * Possible value for peer connection state
  135. * @var int Possible value for peer connection state
  136. */
  137. const BGP_PEER_CONNECTION_STATE_OPENSENT = 4;
  138. /**
  139. * Possible value for peer connection state
  140. * @var int Possible value for peer connection state
  141. */
  142. const BGP_PEER_CONNECTION_STATE_OPENCONFIRM = 5;
  143. /**
  144. * Possible value for peer connection state
  145. * @var int Possible value for peer connection state
  146. */
  147. const BGP_PEER_CONNECTION_STATE_ESTABLISHED = 6;
  148. /**
  149. * Look up for text representation of BGP peer connection states
  150. * @var array Look up for text representation of BGP peer connection states
  151. */
  152. public static $BGP_PEER_CONNECTION_STATES = [
  153. self::BGP_PEER_CONNECTION_STATE_IDLE => 'idle',
  154. self::BGP_PEER_CONNECTION_STATE_CONNECT => 'connect',
  155. self::BGP_PEER_CONNECTION_STATE_ACTIVE => 'active',
  156. self::BGP_PEER_CONNECTION_STATE_OPENSENT => 'opensent',
  157. self::BGP_PEER_CONNECTION_STATE_OPENCONFIRM => 'openconfirm',
  158. self::BGP_PEER_CONNECTION_STATE_ESTABLISHED => 'established'
  159. ];
  160. /**
  161. * Returns the BGP peer connection state (see `self::$BGP_PEER_CONNECTION_STATES`)
  162. *
  163. * > "The BGP peer connection state."
  164. *
  165. * @param bool $translate If true, use the `$BGP_PEER_CONNECTION_STATES` array to return textual representation
  166. * @return array The BGP peer connection state (see `self::$BGP_PEER_CONNECTION_STATES`)
  167. */
  168. public function peerConnectionStates( $translate = false )
  169. {
  170. $s = $this->getSNMP()->walkIPv4( self::OID_BGP_PEER_CONNECTION_STATE );
  171. if( !$translate )
  172. return $s;
  173. return $this->getSNMP()->translate( $s, self::$BGP_PEER_CONNECTION_STATES );
  174. }
  175. /**
  176. * Possible value for peer admin state
  177. * @var int Possible value for peer admin state
  178. */
  179. const BGP_PEER_ADMIN_STATE_STOP = 1;
  180. /**
  181. * Possible value for peer admin state
  182. * @var int Possible value for peer admin state
  183. */
  184. const BGP_PEER_ADMIN_STATE_START = 2;
  185. /**
  186. * Look up for text representation of BGP peer admin states
  187. * @var array Look up for text representation of BGP peer admin states
  188. */
  189. public static $BGP_PEER_ADMIN_STATES = [
  190. self::BGP_PEER_ADMIN_STATE_STOP => 'stop',
  191. self::BGP_PEER_ADMIN_STATE_START => 'start'
  192. ];
  193. /**
  194. * Returns the BGP peer admin states (see `self::$BGP_PEER_ADMIN_STATES`)
  195. *
  196. * > "The desired state of the BGP connection. A transition from 'stop' to 'start' will
  197. * > cause the BGP Start Event to be generated. A transition from 'start' to 'stop' will
  198. * > cause the BGP Stop Event to be generated. This parameter can be used to restart BGP
  199. * > peer connections. Care should be used in providing write access to this object
  200. * > without adequate authentication."
  201. *
  202. * @param bool $translate If true, use the `$BGP_PEER_ADMIN_STATES` array to return textual representation
  203. * @return array The BGP peer admin states (see `self::$BGP_PEER_ADMIN_STATES`)
  204. */
  205. public function peerAdminStates( $translate = false )
  206. {
  207. $s = $this->getSNMP()->walkIPv4( self::OID_BGP_PEER_ADMIN_STATE );
  208. if( !$translate )
  209. return $s;
  210. return $this->getSNMP()->translate( $s, self::$BGP_PEER_ADMIN_STATES );
  211. }
  212. /**
  213. * Returns the negotiated version of BGP running between the two peers
  214. *
  215. * > "The negotiated version of BGP running between the two peers"
  216. *
  217. * @return array The negotiated version of BGP running between the two peers
  218. */
  219. public function peerNegotiatedVersions()
  220. {
  221. return $this->getSNMP()->walkIPv4( self::OID_BGP_PEER_NEGOTIATED_VERSION );
  222. }
  223. /**
  224. * Returns the local IP address of this entry's BGP connection.
  225. *
  226. * > "The local IP address of this entry's BGP connection."
  227. *
  228. * @return array The local IP address of this entry's BGP connection.
  229. */
  230. public function peerLocalAddresses()
  231. {
  232. return $this->getSNMP()->walkIPv4( self::OID_BGP_PEER_LOCAL_ADDRESS );
  233. }
  234. /**
  235. * Returns the local ports for the TCP connections between the BGP peers.
  236. *
  237. * > "The local port for the TCP connection between the BGP peers."
  238. *
  239. * @return array The local ports for the TCP connections between the BGP peers.
  240. */
  241. public function peerLocalPorts()
  242. {
  243. return $this->getSNMP()->walkIPv4( self::OID_BGP_PEER_LOCAL_PORT );
  244. }
  245. /**
  246. * Returns the local IP address of this entry's BGP peer.
  247. *
  248. * > "The remote IP address of this entry's BGP peer."
  249. *
  250. * @return array The remote IP address of this entry's BGP peer.
  251. */
  252. public function peerRemoteAddresses()
  253. {
  254. return $this->getSNMP()->walkIPv4( self::OID_BGP_PEER_REMOTE_ADDR );
  255. }
  256. /**
  257. * Returns the remote ports for the TCP connections between the BGP peers.
  258. *
  259. * > "The remote port for the TCP connection between the BGP peers."
  260. *
  261. * @return array The remote ports for the TCP connections between the BGP peers.
  262. */
  263. public function peerRemotePorts()
  264. {
  265. return $this->getSNMP()->walkIPv4( self::OID_BGP_PEER_REMOTE_PORT );
  266. }
  267. /**
  268. * Returns The remote autonomous system number.
  269. *
  270. * > "The remote autonomous system number."
  271. *
  272. * @return array The remote autonomous system number.
  273. */
  274. public function peerRemoteASNs()
  275. {
  276. return $this->getSNMP()->walkIPv4( self::OID_BGP_PEER_REMOTE_ASN );
  277. }
  278. /**
  279. * Returns The number of BGP UPDATE messages received on this connection.
  280. *
  281. * > "The number of BGP UPDATE messages received on this connection. This object
  282. * > should be initialized to zero (0) when the connection is established."
  283. *
  284. * @return array The number of BGP UPDATE messages received on this connection.
  285. */
  286. public function peerInUpdates()
  287. {
  288. return $this->getSNMP()->walkIPv4( self::OID_BGP_PEER_IN_UPDATES );
  289. }
  290. /**
  291. * Returns The number of BGP UPDATE messages transmitted on this connection.
  292. *
  293. * > "The number of BGP UPDATE messages transmitted on this connection. This
  294. * > object should be initialized to zero (0) when the connection is established."
  295. *
  296. * @return array The number of BGP UPDATE messages transmitted on this connection.
  297. */
  298. public function peerOutUpdates()
  299. {
  300. return $this->getSNMP()->walkIPv4( self::OID_BGP_PEER_OUT_UPDATES );
  301. }
  302. /**
  303. * Returns The total number of messages received from the remote peer on this connection.
  304. *
  305. * > "The total number of messages received from the remote peer on this connection.
  306. * > This object should be initialized to zero when the connection is established."
  307. *
  308. * @return array The total number of messages received from the remote peer on this connection.
  309. */
  310. public function peerInTotalMessages()
  311. {
  312. return $this->getSNMP()->walkIPv4( self::OID_BGP_PEER_IN_TOTAL_MESSAGES );
  313. }
  314. /**
  315. * Returns The total number of messages transmitted to the remote peer on this connection.
  316. *
  317. * > "The total number of messages transmitted to the remote peer on this connection. This
  318. * > object should be initialized to zero when the connection is established."
  319. *
  320. * @return array The total number of messages transmitted to the remote peer on this connection.
  321. */
  322. public function peerOutTotalMessages()
  323. {
  324. return $this->getSNMP()->walkIPv4( self::OID_BGP_PEER_OUT_TOTAL_MESSAGES );
  325. }
  326. /**
  327. * Returns The last error code and subcode seen by this peer on this connection.
  328. *
  329. * > "The last error code and subcode seen by this peer on this connection. If no error has
  330. * > occurred, this field is zero. Otherwise, the first byte of this two byte OCTET STRING
  331. * > contains the error code, and the second byte contains the subcode."
  332. *
  333. * @return array The last error code and subcode seen by this peer on this connection.
  334. */
  335. public function peerLastErrors()
  336. {
  337. return $this->getSNMP()->walkIPv4( self::OID_BGP_PEER_LAST_ERROR );
  338. }
  339. /**
  340. * Returns The total number of times the BGP FSM transitioned into the established state.
  341. *
  342. * > "The total number of times the BGP FSM transitioned into the established state."
  343. *
  344. * @return array The total number of times the BGP FSM transitioned into the established state.
  345. */
  346. public function peerEstabledTransitions()
  347. {
  348. return $this->getSNMP()->walkIPv4( self::OID_BGP_PEER_FSM_ESTABLISHED_TRANSITIONS );
  349. }
  350. /**
  351. * Returns how long (in seconds) this peer has been in the Established state or
  352. * how long since this peer was last in the Established state
  353. *
  354. * > "This timer indicates how long (in seconds) this peer has been in the
  355. * > Established state or how long since this peer was last in the
  356. * > Established state. It is set to zero when a new peer is configured or the router is
  357. * > booted"
  358. *
  359. * @return array How long (secs) this peer has been in (or since it was last in) the Established state
  360. */
  361. public function peerEstablishedTimes()
  362. {
  363. return $this->getSNMP()->walkIPv4( self::OID_BGP_PEER_FSM_ESTABLISHED_TIME );
  364. }
  365. /**
  366. * Returns Time interval in seconds for the ConnectRetry timer.
  367. *
  368. * > "Time interval in seconds for the ConnectRetry timer. The suggested value
  369. * > for this timer is 120 seconds."
  370. *
  371. * @return array Time interval in seconds for the ConnectRetry timer.
  372. */
  373. public function peerConnectRetryIntervals()
  374. {
  375. return $this->getSNMP()->walkIPv4( self::OID_BGP_PEER_CONNECT_RETRY_INTERVAL );
  376. }
  377. /**
  378. * Returns Time interval in seconds for the Hold Timer established with the peer.
  379. *
  380. * > "Time interval in seconds for the Hold Timer established with the peer. The
  381. * > value of this object is calculated by this BGP speaker by using the smaller of the
  382. * > value in bgpPeerHoldTimeConfigured and the Hold Time received in the OPEN message.
  383. * > This value must be at lease three seconds if it is not zero (0) in which case the
  384. * > Hold Timer has not been established with the peer, or, the value of
  385. * > bgpPeerHoldTimeConfigured is zero (0)."
  386. *
  387. * @return array Time interval in seconds for the Hold Timer established with the peer.
  388. */
  389. public function peerHoldTimes()
  390. {
  391. return $this->getSNMP()->walkIPv4( self::OID_BGP_PEER_HOLD_TIME );
  392. }
  393. /**
  394. * Returns Time interval in seconds for the KeepAlive timer established with the peer.
  395. *
  396. * > "Time interval in seconds for the KeepAlive timer established with the peer. The value
  397. * > of this object is calculated by this BGP speaker such that, when compared with
  398. * > bgpPeerHoldTime, it has the same proportion as what bgpPeerKeepAliveConfigured has when
  399. * > compared with bgpPeerHoldTimeConfigured. If the value of this object is zero (0),
  400. * > it indicates that the KeepAlive timer has not been established with the peer, or,
  401. * > the value of bgpPeerKeepAliveConfigured is zero (0)."
  402. *
  403. * @return array Time interval in seconds for the KeepAlive timer established with the peer.
  404. */
  405. public function peerKeepAlives()
  406. {
  407. return $this->getSNMP()->walkIPv4( self::OID_BGP_PEER_KEEP_ALIVE );
  408. }
  409. /**
  410. * Returns Time interval in seconds for the Hold Time configured for this BGP speaker with this peer.
  411. *
  412. * > "Time interval in seconds for the Hold Time configured for this BGP speaker with this
  413. * > peer. This value is placed in an OPEN message sent to this peer by this BGP
  414. * > speaker, and is compared with the Hold Time field in an OPEN message received
  415. * > from the peer when determining the Hold Time (bgpPeerHoldTime) with the peer.
  416. * > This value must not be less than three seconds if it is not zero (0) in which
  417. * > case the Hold Time is NOT to be established with the peer. The suggested
  418. * > value for this timer is 90 seconds."
  419. *
  420. * @return array Time interval in seconds for the Hold Time configured for this BGP speaker with this peer.
  421. */
  422. public function peerHoleTimesConfigured()
  423. {
  424. return $this->getSNMP()->walkIPv4( self::OID_BGP_PEER_HOLD_TIME_CONFIGURED );
  425. }
  426. /**
  427. * Returns Time interval in seconds for the KeepAlive timer configured for this BGP speaker with this peer.
  428. *
  429. * > "Time interval in seconds for the KeepAlive timer configured for this BGP
  430. * > speaker with this peer. The value of this object will only determine the
  431. * > KEEPALIVE messages' frequency relative to the value specified in
  432. * > bgpPeerHoldTimeConfigured; the actual time interval for the KEEPALIVE messages
  433. * > is indicated by bgpPeerKeepAlive. A reasonable maximum value for this timer
  434. * > would be configured to be one third of that of bgpPeerHoldTimeConfigured.
  435. * > If the value of this object is zero (0), no periodical KEEPALIVE messages are sent
  436. * > to the peer after the BGP connection has been established. The suggested value for
  437. * > this timer is 30 seconds"
  438. *
  439. * @return array Time interval in seconds for the KeepAlive timer configured for this BGP speaker with this peer.
  440. */
  441. public function peerKeepAlivesConfigured()
  442. {
  443. return $this->getSNMP()->walkIPv4( self::OID_BGP_PEER_KEEP_ALIVE_CONFIGURED );
  444. }
  445. /**
  446. * Returns Time interval in seconds for the MinASOriginationInterval timer.
  447. *
  448. * > "Time interval in seconds for the MinASOriginationInterval timer.
  449. * > The suggested value for this timer is 15 seconds."
  450. *
  451. * @return array Time interval in seconds for the MinASOriginationInterval timer.
  452. */
  453. public function peerMinASOriginationIntervals()
  454. {
  455. return $this->getSNMP()->walkIPv4( self::OID_BGP_PEER_MIN_AS_ORIGINATION_INTERVAL );
  456. }
  457. /**
  458. * Returns Time interval in seconds for the MinRouteAdvertisementInterval timer.
  459. *
  460. * > "Time interval in seconds for the MinRouteAdvertisementInterval timer.
  461. * > The suggested value for this timer is 30 seconds"
  462. *
  463. * @return array Time interval in seconds for the MinRouteAdvertisementInterval timer.
  464. */
  465. public function peerMinRouteAdvertisementIntervals()
  466. {
  467. return $this->getSNMP()->walkIPv4( self::OID_BGP_PEER_MIN_ROUTE_ADVERTISEMENT_INTERVAL );
  468. }
  469. /**
  470. * Returns Elapsed time in seconds since the last BGP UPDATE message was received from the peer.
  471. *
  472. * > "Elapsed time in seconds since the last BGP UPDATE message was received from the peer.
  473. * > Each time bgpPeerInUpdates is incremented, the value of this object is set to zero (0)."
  474. *
  475. * @return array Elapsed time in seconds since the last BGP UPDATE message was received from the peer.
  476. */
  477. public function peerInUpdateElapsedTimes()
  478. {
  479. return $this->getSNMP()->walkIPv4( self::OID_BGP_PEER_IN_UPDATE_ELAPSED_TIME );
  480. }
  481. /**
  482. * Utility function to gather all peer information into a single array.
  483. *
  484. * For example, this would return something like:
  485. *
  486. * Array
  487. * (
  488. * ....
  489. * [192.0.2.126] => Array
  490. * (
  491. * [identity] => 192.0.2.45
  492. * [connectionState] => established
  493. * [adminState] => start
  494. * [negotiatedVersion] => 4
  495. * [localAddress] => 193.242.111.74
  496. * [localPort] => 26789
  497. * [remoteAddress] => 192.0.2.126
  498. * [remotePort] => 179
  499. * [remoteASN] => 65505
  500. * [inUpdates] => 4
  501. * [outUpdates] => 2
  502. * [inTotalMessages] => 180988
  503. * [outTotalMessages] => 181012
  504. * [lastError] => 0000
  505. * [establishedTransitions] => 1
  506. * [establishedTime] => 9867469
  507. * [connectRetryInterval] => 60
  508. * [holdTime] => 180
  509. * [keepAlive] => 60
  510. * [holdTimeConfigured] => 180
  511. * [keepAliveConfigured] => 60
  512. * [minASOriginationInterval] => 30
  513. * [minRouteAdvertisementInterval] => 30
  514. * [inUpdateElapsedTime] => 0
  515. * )
  516. * ....
  517. * )
  518. *
  519. * @param bool $translate Where a called function supports translation, if true then translate
  520. * @return array Array of peer details - see example above.
  521. */
  522. public function peerDetails( $translate = false )
  523. {
  524. $fetchList = [
  525. 'peerIdentifiers' => 'identity',
  526. 'peerConnectionStates' => 'connectionState',
  527. 'peerAdminStates' => 'adminState',
  528. 'peerNegotiatedVersions' => 'negotiatedVersion',
  529. 'peerLocalAddresses' => 'localAddress',
  530. 'peerLocalPorts' => 'localPort',
  531. 'peerRemoteAddresses' => 'remoteAddress',
  532. 'peerRemotePorts' => 'remotePort',
  533. 'peerRemoteASNs' => 'remoteASN',
  534. 'peerInUpdates' => 'inUpdates',
  535. 'peerOutUpdates' => 'outUpdates',
  536. 'peerInTotalMessages' => 'inTotalMessages',
  537. 'peerOutTotalMessages' => 'outTotalMessages',
  538. 'peerLastErrors' => 'lastError',
  539. 'peerEstabledTransitions' => 'establishedTransitions',
  540. 'peerEstablishedTimes' => 'establishedTime',
  541. 'peerConnectRetryIntervals' => 'connectRetryInterval',
  542. 'peerHoldTimes' => 'holdTime',
  543. 'peerKeepAlives' => 'keepAlive',
  544. 'peerHoleTimesConfigured' => 'holdTimeConfigured',
  545. 'peerKeepAlivesConfigured' => 'keepAliveConfigured',
  546. 'peerMinASOriginationIntervals' => 'minASOriginationInterval',
  547. 'peerMinRouteAdvertisementIntervals' => 'minRouteAdvertisementInterval',
  548. 'peerInUpdateElapsedTimes' => 'inUpdateElapsedTime'
  549. ];
  550. $canTranslate = [ 'peerConnectionStates', 'peerAdminStates' ];
  551. $details = [];
  552. foreach( $fetchList as $fn => $idx )
  553. {
  554. if( in_array( $fn, $canTranslate ) )
  555. $values = $this->$fn( $translate );
  556. else
  557. $values = $this->$fn();
  558. foreach( $values as $ip => $value )
  559. $details[ $ip ][ $idx ] = $value;
  560. }
  561. return $details;
  562. }
  563. /**
  564. * Returns the local BGP identifier
  565. *
  566. * > "The BGP Identifier of local system."
  567. *
  568. * @return string The BGP Identifier of local system.
  569. */
  570. public function identifier()
  571. {
  572. return $this->getSNMP()->get( self::OID_BGP_IDENTIFIER );
  573. }
  574. }