7 .. _grpc-languages-bindings:
9 Programming Language Bindings
10 =============================
12 The gRPC supported programming language bindings can be found here:
13 https://grpc.io/docs/languages/
15 After picking a programming language that supports gRPC bindings, the
16 next step is to generate the FRR northbound bindings. To generate the
17 northbound bindings you'll need the programming language binding
18 generator tools and those are language specific.
20 Next sections will use Ruby as an example for writing scripts to use
24 .. _grpc-ruby-generate:
26 Generating Ruby FRR Bindings
27 ----------------------------
29 Generating FRR northbound bindings for Ruby example:
33 # Install the required gems:
34 # - grpc: the gem that will talk with FRR's gRPC plugin.
35 # - grpc-tools: the gem that provides the code generator.
37 gem install grpc-tools
39 # Create your project/scripts directory:
42 # Go to FRR's grpc directory:
45 # Generate the ruby bindings:
46 grpc_tools_ruby_protoc \
47 --ruby_out=/tmp/frr-ruby \
48 --grpc_out=/tmp/frr-ruby \
52 .. _grpc-ruby-if-sample:
54 Using Ruby To Get Interfaces State
55 ----------------------------------
57 Here is a sample script to print all interfaces FRR discovered:
61 require 'frr-northbound_services_pb'
63 # Create the connection with FRR's gRPC:
64 stub = Frr::Northbound::Stub.new('localhost:50051', :this_channel_is_insecure)
66 # Create a new state request to get interface state:
67 request = Frr::GetRequest.new
69 request.path.push('/frr-interface:lib')
72 response = stub.get(request)
75 response.each do |result|
76 result.data.data.each_line do |line|
84 The generated files will assume that they are in the search path (e.g.
85 inside gem) so you'll need to either edit it to use ``require_relative`` or
86 tell Ruby where to look for them. For simplicity we'll use ``-I .`` to tell
87 it is in the current directory.
90 The previous script will output something like this:
95 # Add `-I.` so ruby finds the FRR generated file locally.
96 $ ruby -I. interface.rb
98 "frr-interface:lib": {
109 "phy-address": "11:22:33:44:55:66"
127 "phy-address": "00:00:00:00:00:00"
141 .. _grpc-ruby-bfd-profile-sample:
143 Using Ruby To Create BFD Profiles
144 ---------------------------------
146 In this example you'll learn how to edit configuration using JSON
147 and programmatic (XPath) format.
151 require 'frr-northbound_services_pb'
153 # Create the connection with FRR's gRPC:
154 stub = Frr::Northbound::Stub.new('localhost:50051', :this_channel_is_insecure)
156 # Create a new candidate configuration change.
157 new_candidate = stub.create_candidate(Frr::CreateCandidateRequest.new)
159 # Use JSON to configure.
160 request = Frr::LoadToCandidateRequest.new
161 request.candidate_id = new_candidate.candidate_id
162 request.type = :MERGE
163 request.config = Frr::DataTree.new
164 request.config.encoding = :JSON
165 request.config.data = <<-EOJ
172 "detection-multiplier": 4,
173 "required-receive-interval": 800000
181 # Load configuration to candidate.
182 stub.load_to_candidate(request)
186 Frr::CommitRequest.new(
187 candidate_id: new_candidate.candidate_id,
189 comment: 'create test-prof'
194 # Now lets delete the previous profile and create a new one.
197 # Create a new candidate configuration change.
198 new_candidate = stub.create_candidate(Frr::CreateCandidateRequest.new)
200 # Edit the configuration candidate.
201 request = Frr::EditCandidateRequest.new
202 request.candidate_id = new_candidate.candidate_id
204 # Delete previously created profile.
207 path: "/frr-bfdd:bfdd/bfd/profile[name='test-prof']",
211 # Add new profile with two configurations.
214 path: "/frr-bfdd:bfdd/bfd/profile[name='test-prof-2']/detection-multiplier",
220 path: "/frr-bfdd:bfdd/bfd/profile[name='test-prof-2']/desired-transmission-interval",
225 # Modify the candidate.
226 stub.edit_candidate(request)
228 # Commit the candidate configuration.
230 Frr::CommitRequest.new(
231 candidate_id: new_candidate.candidate_id,
233 comment: 'replace test-prof with test-prof-2'
238 And here is the new FRR configuration:
242 $ sudo vtysh -c 'show running-config'
247 transmit-interval 900