summaryrefslogtreecommitdiffhomepage
path: root/tools/grpc
diff options
context:
space:
mode:
authorSatoshi Fujimoto <satoshi.fujimoto7@gmail.com>2017-06-29 14:28:44 +0900
committerSatoshi Fujimoto <satoshi.fujimoto7@gmail.com>2017-06-30 13:26:14 +0900
commitb81e2fd806055400307098af5fc426d7ae4b6515 (patch)
tree779834742f6c03088045430d718ef8d51277f372 /tools/grpc
parentd18ddd4ecaf53d7728ba542ca55a0a536e4d08ce (diff)
docs: Separate sample codes from gRPC document
This patch separate sample codes from grpc-client.md and adds references to samples in tools/grpc/. Signed-off-by: Satoshi Fujimoto <satoshi.fujimoto7@gmail.com>
Diffstat (limited to 'tools/grpc')
-rw-r--r--tools/grpc/java/src/gobgp/example/GobgpSampleClient.java45
1 files changed, 45 insertions, 0 deletions
diff --git a/tools/grpc/java/src/gobgp/example/GobgpSampleClient.java b/tools/grpc/java/src/gobgp/example/GobgpSampleClient.java
new file mode 100644
index 00000000..eb991f88
--- /dev/null
+++ b/tools/grpc/java/src/gobgp/example/GobgpSampleClient.java
@@ -0,0 +1,45 @@
+package gobgp.example;
+
+import gobgpapi.Gobgp;
+import gobgpapi.GobgpApiGrpc;
+import io.grpc.ManagedChannel;
+import io.grpc.ManagedChannelBuilder;
+
+import java.util.Iterator;
+
+public class GobgpSampleClient {
+
+ private final GobgpApiGrpc.GobgpApiBlockingStub blockingStub;
+
+ public GobgpSampleClient(String host, int port) {
+ ManagedChannel channel = ManagedChannelBuilder.forAddress(host, port).usePlaintext(true).build();
+ this.blockingStub = GobgpApiGrpc.newBlockingStub(channel);
+ }
+
+ public void getNeighbors(){
+
+ Gobgp.Arguments request = Gobgp.Arguments.newBuilder().build();
+
+ for(Iterator<Gobgp.Peer> iterator = this.blockingStub.getNeighbors(request); iterator.hasNext(); ) {
+ Gobgp.Peer p = iterator.next();
+ Gobgp.PeerConf conf = p.getConf();
+ Gobgp.PeerState state = p.getInfo();
+ Gobgp.Timers timer = p.getTimers();
+
+ System.out.printf("BGP neighbor is %s, remote AS %d\n", conf.getNeighborAddress(), conf.getPeerAs());
+ System.out.printf("\tBGP version 4, remote router ID %s\n", conf.getId());
+ System.out.printf("\tBGP state = %s, up for %d\n", state.getBgpState(), timer.getState().getUptime());
+ System.out.printf("\tBGP OutQ = %d, Flops = %d\n", state.getOutQ(), state.getFlops());
+ System.out.printf("\tHold time is %d, keepalive interval is %d seconds\n",
+ timer.getState().getHoldTime(), timer.getState().getKeepaliveInterval());
+ System.out.printf("\tConfigured hold time is %d\n", timer.getConfig().getHoldTime());
+
+ }
+ }
+
+ public static void main(String args[]){
+ new GobgpSampleClient(args[0], 8080).getNeighbors();
+ }
+
+}
+