class Bgp
The Bgp
class provides a class implementation and methods for managing BGP on the node. This class presents an abstraction
Public Class Methods
This API creates a new BGP neighbor on the switch.
Request URL: IP-ADDR:REST-PORT/api/bgps/neighbors/cfgs/10.10.10.10
payload format of key-value pairs { "local_addr": local_ip, "neighbor_addr": neighbor_ip, "admin_status": status, "asn": asn, "holdtime": 180, "keepalive": 60 }
@param conn [Class] Connect
object to the node @param neighbor_ip [String] BGP Neighbor IPv4 or IPv6 address @param local_addr [String] Local IPv4 or IPv6 address @param admin_status [String] admin status of the neighbor. Valid Values: “up” or “down” @param asn [Integer] BGP autonomous system number @param holdtime [Integer] holdtime timer @param keepalive [Integer] keep-alive timer
@return [RestClient::Request] Rest
output from SONIC in JSON format
# File lib/sonic-rbapi/bgp.rb, line 105 def self.create_bgp_neighbor(conn, neighbor_ip, local_addr, admin_status='up', asn=0, holdtime=180, keepalive=60) url = form_url(conn, @bgp_cfg + '/' + neighbor_ip) hdr = form_hdr(conn) params = {"local_addr": local_addr, "neighbor_addr": neighbor_ip, "admin_status": admin_status, "asn": asn, "holdtime": holdtime, "keepalive": keepalive} params = params.to_json Rest.put(conn, url, hdr, params) end
This API delete BGP neighbor on the switch.
Request URL: IP-ADDR:REST-PORT/api/bgps/neighbors/cfgs/10.10.10.10
@param conn [Class] Connect
object to the node @param neighbor_ip [String] Neighbor peer address (IPv4 or IPv6)
@return [RestClient::Request] Rest
output from SONIC in JSON format
# File lib/sonic-rbapi/bgp.rb, line 121 def self.delete_bgp_neighbor(conn, neighbor_ip) url = form_url(conn, @bgp_cfg + '/' + neighbor_ip) hdr = form_hdr(conn) Rest.delete(conn, url, hdr) end
This API gets all BGP neighbors
Request URL: IP-ADDR:REST-PORT/api/bgps/neighbors/cfgs
@param conn [Class] Connect
object to the node
@return [RestClient::Request] Rest
output from SONIC in JSON format as below
{ "10.0.0.19": { "asn": "65200", "keepalive": "60", "rrclient": "0", "holdtime": "180", "name": "AVI10T2", "local_addr": "10.0.0.18", "nhopself": "0" }, ... }
# File lib/sonic-rbapi/bgp.rb, line 146 def self.get_all_bgp_neighbors(conn) url = form_url(conn, @bgp_cfg) hdr = form_hdr(conn) Rest.get(conn, url, hdr) end
This API gets BGP information from the switch.
Request URL: IP-ADDR:REST-PORT/api/bgps/neighbors/info/summary
http://IP-ADDR:REST-PORT/api/bgps/neighbors/info
@param conn [Class] Connect
object to the node @param filter [String] BGP info filter which holds the value “summary” or None
@return [RestClient::Request] Rest
output from SONIC in JSON format as below
{ "192.168.10.2": { "rxMsg": "6036", "bgp_version": "4", "txMsg": "6042", "up_down_time": "01:57:08", "outQ": "0", "state_prefix": "Active", "tblVer": "0", "inQ": "0", "peer_asn": "63100" }, }
# File lib/sonic-rbapi/bgp.rb, line 49 def self.get_bgp_info(conn, filter=nil) summary_filter = "summary" if filter == summary_filter url = form_url(conn, @bgp_info + '/' + summary_filter) elsif filter == nil url = form_url(conn, @bgp_info) end hdr = form_hdr(conn) Rest.get(conn, url, hdr) end
This API updates the BGP global configuration on the switch.
Request URL: IP-ADDR:REST-PORT/api/bgps/globals
payload format of key-value pairs { "default_bgp_status": "up", "bgp_asn": 5000 }
@param conn [Class] Connect
object to the node @param bgp_status [String] Default BGP neighbor status. Valid Values: “up” or “down” @param bgp_asn [Integer] Default BGP AS number
@return [RestClient::Request] Rest
output from SONIC in JSON format
# File lib/sonic-rbapi/bgp.rb, line 75 def self.update_bgp_global_config(conn, bgp_status='up', bgp_asn) url = form_url(conn, @bgp_global) hdr = form_hdr(conn) params = {"default_bgp_status": bgp_status, "bgp_asn": bgp_asn} params = params.to_json Rest.put(conn, url, hdr, params) end