summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorISHIDA Wataru <ishida.wataru@lab.ntt.co.jp>2015-08-27 18:44:21 +0900
committerISHIDA Wataru <ishida.wataru@lab.ntt.co.jp>2015-08-27 18:47:01 +0900
commit8ef1f381b07d04a38597f1fd5587cc1d377433cf (patch)
tree7a44788f43ddb0d552ed8a4bdb5d8b7c511bffc5
parent7b1db76d135aadff9b8710dc52f953c30f2857b6 (diff)
doc/tools: add doc explains how to interact with gobgp using ruby
Signed-off-by: ISHIDA Wataru <ishida.wataru@lab.ntt.co.jp>
-rw-r--r--docs/sources/grpc-client.md64
-rw-r--r--tools/grpc/ruby/get_neighbors.rb16
2 files changed, 80 insertions, 0 deletions
diff --git a/docs/sources/grpc-client.md b/docs/sources/grpc-client.md
index df388b6c..a7c979e3 100644
--- a/docs/sources/grpc-client.md
+++ b/docs/sources/grpc-client.md
@@ -8,6 +8,7 @@ assumes that you use Ubuntu 14.04 (64bit).
## Contents
- [Python](#python)
+- [Ruby](#ruby)
## <a name="python"> Python
@@ -100,3 +101,66 @@ D0821 12:31:07.821508149 91029 iomgr.c:119] Waiting for 1 iomgr
We got neighbor information successfully.
+## <a name="ruby"> Ruby
+
+### Installing LinuxBrew
+
+See [python](#python).
+
+
+### Installing gRPC and Ruby Libraries
+
+```bash
+$ curl -fsSL https://goo.gl/getgrpc | bash -s ruby
+$ sudo ldconfig
+```
+
+### Generating Stub Code
+
+We need to generate stub code GoBGP at first.
+```bash
+$ cd $GOPATH/src/github.com/osrg/gobgp/tools/grpc/ruby
+$ GOBGP_API=$GOPATH/src/github.com/osrg/gobgp/api
+$ protoc -I $GOBGP_API --ruby_out=. --grpc_out=. --plugin=protoc-gen-grpc=`which grpc_ruby_plugin` $GOBGP_API/gobgp.proto
+```
+
+### Get Neighbor
+
+Here is an example for getting neighbor's information.
+```ruby
+require 'gobgp'
+require 'gobgp_services'
+
+host = 'localhost'
+host = ARGV[0] if ARGV.length > 0
+
+stub = Api::Grpc::Stub.new("#{host}:8080")
+arg = Api::Arguments.new()
+stub.get_neighbors(arg).each do |n|
+ puts "BGP neighbor is #{n.conf.remote_ip}, remote AS #{n.conf.remote_as}"
+ puts "\tBGP version 4, remote route ID #{n.conf.id}"
+ puts "\tBGP state = #{n.info.bgp_state}, up for #{n.info.uptime}"
+ puts "\tBGP OutQ = #{n.info.out_q}, Flops = #{n.info.flops}"
+ puts "\tHold time is #{n.info.negotiated_holdtime}, keepalive interval is #{n.info.keepalive_interval} seconds"
+ puts "\tConfigured hold time is #{n.conf.holdtime}"
+end
+```
+
+Let's run this script.
+
+```bash
+$ruby -I . ./get_neighbors.rb
+BGP neighbor is 192.168.10.2, remote AS 65001
+ BGP version 4, remote route ID <nil>
+ BGP state = BGP_FSM_ACTIVE, up for 0
+ BGP OutQ = 0, Flops = 0
+ Hold time is 0, keepalive interval is 0 seconds
+ Configured hold time is 90
+BGP neighbor is 192.168.10.3, remote AS 65001
+ BGP version 4, remote route ID <nil>
+ BGP state = BGP_FSM_ACTIVE, up for 0
+ BGP OutQ = 0, Flops = 0
+ Hold time is 0, keepalive interval is 0 seconds
+ Configured hold time is 90
+D0827 18:43:24.628846574 3379 iomgr.c:119] Waiting for 1 iomgr objects to be destroyed and executing final callbacks
+```
diff --git a/tools/grpc/ruby/get_neighbors.rb b/tools/grpc/ruby/get_neighbors.rb
new file mode 100644
index 00000000..d833802c
--- /dev/null
+++ b/tools/grpc/ruby/get_neighbors.rb
@@ -0,0 +1,16 @@
+require 'gobgp'
+require 'gobgp_services'
+
+host = 'localhost'
+host = ARGV[0] if ARGV.length > 0
+
+stub = Api::Grpc::Stub.new("#{host}:8080")
+arg = Api::Arguments.new()
+stub.get_neighbors(arg).each do |n|
+ puts "BGP neighbor is #{n.conf.remote_ip}, remote AS #{n.conf.remote_as}"
+ puts "\tBGP version 4, remote route ID #{n.conf.id}"
+ puts "\tBGP state = #{n.info.bgp_state}, up for #{n.info.uptime}"
+ puts "\tBGP OutQ = #{n.info.out_q}, Flops = #{n.info.flops}"
+ puts "\tHold time is #{n.info.negotiated_holdtime}, keepalive interval is #{n.info.keepalive_interval} seconds"
+ puts "\tConfigured hold time is #{n.conf.holdtime}"
+end