diff options
Diffstat (limited to 'tools/grpc')
-rw-r--r-- | tools/grpc/nodejs/get_neighbors.js | 40 |
1 files changed, 20 insertions, 20 deletions
diff --git a/tools/grpc/nodejs/get_neighbors.js b/tools/grpc/nodejs/get_neighbors.js index ba2296fa..6cc6b082 100644 --- a/tools/grpc/nodejs/get_neighbors.js +++ b/tools/grpc/nodejs/get_neighbors.js @@ -1,24 +1,24 @@ var grpc = require('grpc'); var api = grpc.load('gobgp.proto').gobgpapi; -var stub = new api.GobgpApi('localhost:50051', grpc.Credentials.createInsecure()); +var stub = new api.GobgpApi('localhost:50051', grpc.credentials.createInsecure()); -var call = stub.getNeighbors({}); -call.on('data', function(neighbor) { - console.log('BGP neighbor is', neighbor.conf.remote_ip, - ', remote AS', neighbor.conf.remote_as); - console.log("\tBGP version 4, remote route ID", neighbor.conf.id); - console.log("\tBGP state =", neighbor.info.bgp_state, - ', up for', neighbor.info.uptime); - console.log("\tBGP OutQ =", neighbor.info.out_q, - ', Flops =', neighbor.info.flops); - console.log("\tHold time is", neighbor.info.negotiated_holdtime, - ', keepalive interval is', neighbor.info.keepalive_interval, 'seconds'); - console.log("\tConfigured hold time is", neighbor.conf.holdtime); -}); -call.on('end', function() { - // do something when the server has finished sending -}); -call.on('status', function(status) { - // do something with the status -}); +stub.getNeighbor({}, function(err, neighbor) { + neighbor.peers.forEach(function(peer) { + if(peer.info.bgp_state == 'BGP_FSM_ESTABLISHED') { + var date = new Date(Number(peer.timers.state.uptime)*1000); + var holdtime = peer.timers.state.negotiated_hold_time; + var keepalive = peer.timers.state.keepalive_interval; + } + console.log('BGP neighbor:', peer.conf.neighbor_address, + ', remote AS:', peer.conf.peer_as); + console.log("\tBGP version 4, remote router ID:", peer.conf.id); + console.log("\tBGP state:", peer.info.bgp_state, + ', uptime:', date); + console.log("\tBGP OutQ:", peer.info.out_q, + ', Flops:', peer.info.flops); + console.log("\tHold time:", holdtime, + ', keepalive interval:', keepalive, 'seconds'); + console.log("\tConfigured hold time:", peer.timers.config.hold_time); + }); +}); |