Initial implementation of full-fledged nn_device()

This means allowing for uni-directional and loopback devices.

Signed-off-by: Martin Sustrik <sustrik@250bpm.com>