Class: Bgp

Inherits:
Object
  • Object
show all
Defined in:
lib/sonic-rbapi/bgp.rb

Overview

The Bgp class provides a class implementation and methods for managing BGP on the node. This class presents an abstraction

Class Method Summary collapse

Class Method Details

.create_bgp_neighbor(conn, neighbor_ip, local_addr, admin_status = 'up', asn = 0, holdtime = 180, keepalive = 60) ⇒ RestClient::Request

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
     }

Parameters:

  • conn (Class)

    Connect object to the node

  • neighbor_ip (String)

    BGP Neighbor IPv4 or IPv6 address

  • local_addr (String)

    Local IPv4 or IPv6 address

  • admin_status (String) (defaults to: 'up')

    admin status of the neighbor. Valid Values: “up” or “down”

  • asn (Integer) (defaults to: 0)

    BGP autonomous system number

  • holdtime (Integer) (defaults to: 180)

    holdtime timer

  • keepalive (Integer) (defaults to: 60)

    keep-alive timer

Returns:

  • (RestClient::Request)

    Rest output from SONIC in JSON format



105
106
107
108
109
110
111
# 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

.delete_bgp_neighbor(conn, neighbor_ip) ⇒ RestClient::Request

This API delete BGP neighbor on the switch.

Request URL: IP-ADDR:REST-PORT/api/bgps/neighbors/cfgs/10.10.10.10

Parameters:

  • conn (Class)

    Connect object to the node

  • neighbor_ip (String)

    Neighbor peer address (IPv4 or IPv6)

Returns:

  • (RestClient::Request)

    Rest output from SONIC in JSON format



121
122
123
124
125
# 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

.get_all_bgp_neighbors(conn) ⇒ RestClient::Request

This API gets all BGP neighbors

Request URL: IP-ADDR:REST-PORT/api/bgps/neighbors/cfgs

Parameters:

  • conn (Class)

    Connect object to the node

Returns:

  • (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"
      },
    ...
    

    }



146
147
148
149
150
# 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

.get_bgp_info(conn, filter = nil) ⇒ RestClient::Request

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

Parameters:

  • conn (Class)

    Connect object to the node

  • filter (String) (defaults to: nil)

    BGP info filter which holds the value “summary” or None

Returns:

  • (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"
     },
    

    }



49
50
51
52
53
54
55
56
57
58
59
# 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

.update_bgp_global_config(conn, bgp_status = 'up', bgp_asn) ⇒ RestClient::Request

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
     }

Parameters:

  • conn (Class)

    Connect object to the node

  • bgp_status (String) (defaults to: 'up')

    Default BGP neighbor status. Valid Values: “up” or “down”

  • bgp_asn (Integer)

    Default BGP AS number

Returns:

  • (RestClient::Request)

    Rest output from SONIC in JSON format



75
76
77
78
79
80
81
# 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