Using jicmp from the command line
Subscribe

From OpenNMS

Jump to: navigation, search

Contents

Why

One of the bits of C code in OpenNMS is the code that we use to "ping" machines with ICMP echoes. Java doesn't have the ability for us to send and receive ICMP packets, so we have a little bit of C code that we call from Java to do the twiddling with the ICMP packets for us.

We run on a handful of different instruction set architectures (ISA), including x86, x64, SPARC 32 & 64 bit, and PowerPC 32 & 64 bit. Now, if you are running an Intel 32 bit Java virtual machine, but our C code gets compiled for a 64 bit ISA, then the C code won't work from Java, and you'll get errors whenever we try to use it. The same problem can happen if the ISAs match, but there might be linking problems or other oddities.

I got sick of debugging problems like this from within the OpenNMS daemon one day, and decided to make a command-line "ping" program in Java using our jicmp C code.

How

Don't forgot to run these commands as root. Also note that libjicmp.so might be named something slightly different on your operating system. It's libjicmp.jnilib on Mac OS X, for example. Lastly, if you are on SPARC, and you want to use the 64 bit JVM, put "-d64" before any of the other command-line options. The "`pwd`/libjicmp.so" is in there instead of just "libjicmp.so" because the opennms.library.jicmp option requires are an absolute pathname.

Modern Instructions (OpenNMS >= ~1.3.6 / 1.5.90 / 1.7.0 timeframe)

  1. Find out where your JICMP JNI library is. The easiest way to find this information is to look in OPENNMS_HOME/etc/libraries.properties for the value of opennms.library.jicmp.
  2. cd $OPENNMS_HOME/lib
  3. sudo java -Dopennms.library.jicmp=/sw/lib/libjicmp.jnilib -classpath opennms-icmp-api-1.5.91-SNAPSHOT.jar:log4j-1.2.9.jar:jicmp-api-1.0.jar org.opennms.netmgt.ping.Ping localhost

You will need to adjust the location and name of your JICMP JNI library and the specific versions of the various JAR files in the classpath argument according to your operating system and OpenNMS version. You should see output like the following; type your shell's break character to stop the pinging.

[DEBUG] System property 'opennms.library.jicmp' set to '/sw/lib/libjicmp.jnilib.  Attempting to load jicmp library from this location.
[INFO] Successfully loaded jicmp library.
PING localhost (127.0.0.1): 56 data bytes
56 bytes from 127.0.0.1: icmp_seq=0. time=0.097 ms
56 bytes from 127.0.0.1: icmp_seq=1. time=0.212 ms
56 bytes from 127.0.0.1: icmp_seq=2. time=0.208 ms

Archived Instructions (obsolete)

Pre-Maven (OpenNMS < ~1.3.2)

cd $OPENNMS_HOME/lib
java -Dopennms.library.jicmp=`pwd`/libjicmp.so -cp opennms_services.jar  org.opennms.protocols.icmp.IcmpSocket localhost

Post-Maven (OpenNMS < ~1.3.6)

cd $OPENNMS_HOME/lib
java -Dopennms.library.jicmp=`pwd`/libjicmp.so -cp opennms-icmp-api-1.3.2-SNAPSHOT.jar org.opennms.protocols.icmp.IcmpSocket localhost