name: ping
description: An example ping module from ODL
license: MIT
schema: !yang ping.yang
keywords:
  - yangforge
  - ping
  - example
rpc:
  send-echo: !coffee/function |
    (input, output, done) ->
      sys = @parent.require 'child_process'
      unless sys?.exec?
        return done "cannot issue ping without sys.exec capability"
      destination = input.get 'destination'
      unless destination?
        console.error "cannot issue ping without destination address"
        output.set 'echo-result', 2
        return done()
      child = sys.exec "ping -c 1 #{destination}", timeout: 2500
      child.on 'error', (err)  -> output.set 'echo-result', 2; done()
      child.on 'close', (code) -> output.set 'echo-result', code ? 1; done()
