NSO is capable of starting user provided Erlang
applications embedded in the same Erlang VM as NSO.
The Erlang code is packaged into applications which are
automatically started and stopped by NSO if they are
located at the proper place. NSO will search all packages
for top level directories called
erlang-lib
. The structure of such a
directory is the same as a standard lib
directory in Erlang. The directory may contain multiple Erlang
applications. Each one must have a valid
.app
file. See the Erlang documentation of
application
and app
for more info.
An Erlang package skeleton can be created by making use of the
ncs-make-package
command:
Multiple applications can be generated by using the
option --erlang-application-name NAME
multiple times
with different names.
All application code SHOULD use the prefix "ec_" for module
names, application names, registered processes (if any), and
named ets tables (if any), to avoid conflict with existing or
future names used by NSO itself.
The Erlang API to NSO is implemented as an Erlang/OTP
application called econfd
. This application comes in
two flavours. One is builtin into NSO in order to support
applications running in the same Erlang VM as NSO. The
other is a separate library which is included in source form in
the NSO release, in the
$NCS_DIR/erlang
directory. Building
econfd
as described in the
$NCS_DIR/erlang/econfd/README
file will
compile the Erlang code and generate the documentation.
This API can be used by applications written in Erlang in much
the same way as the C and Java APIs are used, i.e. code running
in an Erlang VM can use the econfd
API functions to
make socket connections to NSO for data provider, MAAPI, CDB,
etc access. However the API is also available internally in
NSO, which makes it possible to run Erlang application code
inside the NSO daemon, without the overhead imposed by the
socket communication.
When the application is started, one of its processes should
make initial connections to the NSO subsystems, register
callbacks etc. This is typically done in the init/1
function of a gen_server
or similar. While the
internal connections are made using the exact same API functions
(e.g. econfd_maapi:connect/2
) as for an
application running in an external Erlang VM, any
Address
and Port
arguments are ignored, and instead standard Erlang inter-process
communication is used.
There is little or no support for testing and debugging Erlang
code executing internally in NSO, since NSO provides
a very limited runtime environment for Erlang in order to
minimize disk and memory footprints. Thus the recommended method
is to develop Erlang code targeted for this by using
econfd
in a separate Erlang VM, where an
interactive Erlang shell and all the other development support
included in the standard Erlang/OTP releases are available. When
development and testing is completed, the code can be deployed
to run internally in NSO without changes.
For information about the Erlang programming language and
development tools, please refer to www.erlang.org and the
available books about Erlang (some are referenced on the web
site).
The --printlog
option to
ncs, which prints the contents of the NSO
error log, is normally only useful for Cisco support and
developers, but it may also be relevant for debugging problems
with application code running inside NSO. The error log
collects the events sent to the OTP error_logger, e.g. crash
reports as well as info generated by calls to functions in the
error_logger(3) module. Another possibility for primitive
debugging is to run ncs with the
--foreground
option, where calls to
io:format/2
etc will print to standard
output. Printouts may also be directed to the developer log
by using econfd:log/3
.
While Erlang application code running in an external Erlang VM
can use basically any version of Erlang/OTP, this is not the
case for code running inside NSO, since the Erlang VM is
evolving and provides limited backward/forward compatibility.
To avoid incompatibility issues when loading the
beam
files, the Erlang compiler erlc
should be of the same version as was used to build the NSO
distribution.
NSO provides the VM, erlc
and the
kernel
, stdlib
, and
crypto
OTP applications.
Note
Obviously application code running internally in the NSO
daemon can have an impact on the execution of the standard NSO
code. Thus it is critically important that the application code
is thoroughly tested and verified before being deployed for
production in a system using NSO.