/** * Initializes this singleton * * @throws java.io.IOException if any. */ public synchronized void initialize() throws IOException { if (s_pingTracker != null) return; s_pingTracker = new RequestTracker<PingRequest<IcmpSocket>, PingReply>("ICMP", new IcmpMessenger(), new IDBasedRequestLocator<PingRequestId, PingRequest<IcmpSocket>, PingReply>()); s_pingTracker.start(); }
/** * <p>ping</p> * * @param host a {@link java.net.InetAddress} object. * @param timeout a long. * @param retries a int. * @param packetsize The size in byte of the ICMP packet. * @param sequenceId a short. * @param cb a {@link org.opennms.netmgt.ping.PingResponseCallback} object. * @throws java.lang.Exception if any. */ @Override public void ping(final InetAddress host, final long timeout, final int retries, final int packetsize, final int sequenceId, final PingResponseCallback cb) throws Exception { initialize(); m_pingTracker.sendRequest(new JnaPingRequest(host, m_pingerId, sequenceId, timeout, retries, packetsize, cb)); }
/** {@inheritDoc} */ @Override public synchronized void start() { LOG.debug("Calling start()"); super.start(); LOG.debug("Called start()"); }
@Override public RequestTracker<Jni6PingRequest, Jni6PingResponse> call() throws Exception { return new RequestTracker<Jni6PingRequest, Jni6PingResponse>(name, m_jni6messenger, requestLocator); } });
/** * Initializes this singleton * @throws Exception */ private synchronized void initialize() throws Exception { if (m_pingTracker != null) return; try { m_messenger = new JnaIcmpMessenger(m_pingerId); m_pingTracker = Logging.withPrefix("icmp", new Callable<RequestTracker<JnaPingRequest,JnaPingReply>>() { @Override public RequestTracker<JnaPingRequest, JnaPingReply> call() throws Exception { return new RequestTracker<JnaPingRequest, JnaPingReply>("JNA-ICMP-"+m_pingerId, m_messenger, new IDBasedRequestLocator<JnaPingRequestId, JnaPingRequest, JnaPingReply>()); } }); m_pingTracker.start(); } catch (final IOException e) { final String errorMessage = e.getMessage().toLowerCase(); if (errorMessage.contains("permission denied") || errorMessage.contains("operation not permitted")) { LOG.error("Permission error received while attempting to open ICMP socket. See https://wiki.opennms.org/wiki/ICMP for information on configuring ICMP for non-root."); } throw e; } }
@Override public RequestTracker<Jni6PingRequest, Jni6PingResponse> call() throws Exception { return new RequestTracker<Jni6PingRequest, Jni6PingResponse>(name, m_jni6messenger, requestLocator); } });
/** * <p>ping</p> * * @param host a {@link java.net.InetAddress} object. * @param timeout a long. * @param retries a int. * @param sequenceId a short. * @param cb a {@link org.opennms.netmgt.ping.PingResponseCallback} object. * @throws java.lang.Exception if any. */ public void ping(InetAddress host, long timeout, int retries, short sequenceId, PingResponseCallback cb) throws Exception { initialize(); s_pingTracker.sendRequest(new org.opennms.netmgt.ping.PingRequest(host, sequenceId, timeout, retries, cb)); }
/** * Initializes this singleton * * @throws java.io.IOException if any. */ private synchronized void initialize() throws Exception { if (s_pingTracker != null) return; try { m_messenger = new JniIcmpMessenger(m_pingerId); s_pingTracker = Logging.withPrefix("icmp", new Callable<RequestTracker<JniPingRequest, JniPingResponse>>() { @Override public RequestTracker<JniPingRequest, JniPingResponse> call() throws Exception { return new RequestTracker<JniPingRequest, JniPingResponse>("JNI-ICMP-"+m_pingerId, m_messenger, new IDBasedRequestLocator<JniPingRequestId, JniPingRequest, JniPingResponse>()); } }); s_pingTracker.start(); } catch (final IOException ioe) { m_error = ioe; final String errorMessage = m_error.getMessage().toLowerCase(); if (errorMessage.contains("permission denied") || errorMessage.contains("operation not permitted")) { LOG.error("Permission error received while attempting to open ICMP socket. See https://wiki.opennms.org/wiki/ICMP for information on configuring ICMP for non-root."); } s_pingTracker = null; throw ioe; } catch (final RuntimeException rte) { m_error = rte; s_pingTracker = null; throw rte; } }
@Override public RequestTracker<JnaPingRequest, JnaPingReply> call() throws Exception { return new RequestTracker<JnaPingRequest, JnaPingReply>("JNA-ICMP-"+m_pingerId, m_messenger, new IDBasedRequestLocator<JnaPingRequestId, JnaPingRequest, JnaPingReply>()); } });
/** * <p>ping</p> * * @param host a {@link java.net.InetAddress} object. * @param timeout a long. * @param retries a int. * @param sequenceId a short. * @param cb a {@link org.opennms.netmgt.ping.PingResponseCallback} object. * @throws java.lang.Exception if any. */ @Override public void ping(final InetAddress host, final long timeout, final int retries, final int sequenceId, final PingResponseCallback cb) throws Exception { initialize(); m_pingTracker.sendRequest(new JnaPingRequest(host, m_pingerId, sequenceId, timeout, retries, DEFAULT_PACKET_SIZE, cb)); }
@Override public synchronized void initialize6() throws Exception { if (s_pingTracker != null) return; final String name = "JNI-ICMPv6-"+m_pingerId; final IDBasedRequestLocator<Jni6PingRequestId, Jni6PingRequest, Jni6PingResponse> requestLocator = new IDBasedRequestLocator<Jni6PingRequestId, Jni6PingRequest, Jni6PingResponse>(); try { m_jni6messenger = new Jni6IcmpMessenger(m_pingerId); s_pingTracker = Logging.withPrefix("icmp", new Callable<RequestTracker<Jni6PingRequest, Jni6PingResponse>>() { @Override public RequestTracker<Jni6PingRequest, Jni6PingResponse> call() throws Exception { return new RequestTracker<Jni6PingRequest, Jni6PingResponse>(name, m_jni6messenger, requestLocator); } }); s_pingTracker.start(); } catch (final IOException ioe) { m_v6Error = ioe; final String errorMessage = m_v6Error.getMessage().toLowerCase(); if (errorMessage.contains("permission denied") || errorMessage.contains("operation not permitted")) { LOG.error("Permission error received while attempting to open ICMP socket. See https://wiki.opennms.org/wiki/ICMP for information on configuring ICMP for non-root."); } throw ioe; } catch (final RuntimeException rte) { m_v6Error = rte; throw rte; } }
@Override public RequestTracker<JniPingRequest, JniPingResponse> call() throws Exception { return new RequestTracker<JniPingRequest, JniPingResponse>("JNI-ICMP-"+m_pingerId, m_messenger, new IDBasedRequestLocator<JniPingRequestId, JniPingRequest, JniPingResponse>()); } });
/** * <p>ping</p> * * @param host a {@link java.net.InetAddress} object. * @param timeout a long. * @param retries a int. * @param packetsize The size in byte of the ICMP packet. * @param sequenceId a short. * @param cb a {@link org.opennms.netmgt.icmp.jni.PingResponseCallback} object. * @throws java.lang.Exception if any. */ @Override public void ping(final InetAddress host, final long timeout, final int retries, final int packetsize, final int sequenceId, final PingResponseCallback cb) throws Exception { initialize(); s_pingTracker.sendRequest(new JniPingRequest(host, m_pingerId, sequenceId, timeout, retries, packetsize, new LogPrefixPreservingPingResponseCallback(cb))); }
@Override public synchronized void initialize6() throws Exception { if (s_pingTracker != null) return; final String name = "JNI-ICMPv6-"+m_pingerId; final IDBasedRequestLocator<Jni6PingRequestId, Jni6PingRequest, Jni6PingResponse> requestLocator = new IDBasedRequestLocator<Jni6PingRequestId, Jni6PingRequest, Jni6PingResponse>(); try { m_jni6messenger = new Jni6IcmpMessenger(m_pingerId); s_pingTracker = Logging.withPrefix("icmp", new Callable<RequestTracker<Jni6PingRequest, Jni6PingResponse>>() { @Override public RequestTracker<Jni6PingRequest, Jni6PingResponse> call() throws Exception { return new RequestTracker<Jni6PingRequest, Jni6PingResponse>(name, m_jni6messenger, requestLocator); } }); s_pingTracker.start(); } catch (final IOException ioe) { m_v6Error = ioe; final String errorMessage = m_v6Error.getMessage().toLowerCase(); if (errorMessage.contains("permission denied") || errorMessage.contains("operation not permitted")) { LOG.error("Permission error received while attempting to open ICMP socket. See https://wiki.opennms.org/wiki/ICMP for information on configuring ICMP for non-root."); } throw ioe; } catch (final RuntimeException rte) { m_v6Error = rte; throw rte; } }
/** * <p>ping</p> * * @param host a {@link java.net.InetAddress} object. * @param timeout a long. * @param retries a int. * @param packetsize The size in byte of the ICMP packet. * @param sequenceId a short. * @param cb a {@link org.opennms.netmgt.icmp.jni.PingResponseCallback} object. * @throws java.lang.Exception if any. */ @Override public void ping(final InetAddress host, final long timeout, final int retries, final int sequenceId, final PingResponseCallback cb) throws Exception { initialize(); s_pingTracker.sendRequest(new JniPingRequest(host, m_pingerId, sequenceId, timeout, retries, DEFAULT_PACKET_SIZE, new LogPrefixPreservingPingResponseCallback(cb))); }
/** * <p>parallelPing</p> * * @param host a {@link java.net.InetAddress} object. * @param count a int. * @param timeout a long. * @param pingInterval a long. * @return a {@link java.util.List} object. * @throws java.lang.Exception if any. */ public List<Number> parallelPing(InetAddress host, int count, long timeout, long pingInterval) throws Exception { initialize(); ParallelPingResponseCallback cb = new ParallelPingResponseCallback(count); if (timeout == 0) { timeout = DEFAULT_TIMEOUT; } for (int i = 0; i < count; i++) { PingRequest<IcmpSocket> request = new org.opennms.netmgt.ping.PingRequest(host, (short) i, timeout, 0, cb); s_pingTracker.sendRequest(request); Thread.sleep(pingInterval); } cb.waitFor(); return cb.getResponseTimes(); }
/** * Ping a remote host, sending 1 or more packets at the given interval, and then * return the response times as a list. * * @param host The {@link java.net.InetAddress} address to poll. * @param count The number of packets to send. * @param timeout The time to wait between each retry. * @param pingInterval The interval at which packets will be sent. * @param size The size of the packet to send. * @return a {@link java.util.List} of response times in microseconds. * If, for a given ping request, the host is reachable and has responded with an * echo reply, it will contain a number, otherwise a null value. */ @Override public List<Number> parallelPing(final InetAddress host, final int count, final long timeout, final long pingInterval, final int size) throws Exception { initialize(); final ParallelPingResponseCallback cb = new ParallelPingResponseCallback(count); final long threadId = JniPingRequest.getNextTID(); for (int seqNum = 0; seqNum < count; seqNum++) { final JniPingRequest request = new JniPingRequest(host, m_pingerId, seqNum, threadId, timeout == 0? DEFAULT_TIMEOUT : timeout, 0, size, cb); s_pingTracker.sendRequest(request); Thread.sleep(pingInterval); } cb.waitFor(); return cb.getResponseTimes(); }
/** * Ping a remote host, sending 1 or more packets at the given interval, and then * return the response times as a list. * * @param host The {@link java.net.InetAddress} address to poll. * @param count The number of packets to send. * @param timeout The time to wait between each retry. * @param pingInterval The interval at which packets will be sent. * @param size The size of the packet to send. * @return a {@link java.util.List} of response times in microseconds. * If, for a given ping request, the host is reachable and has responded with an * echo reply, it will contain a number, otherwise a null value. */ @Override public List<Number> parallelPing(final InetAddress host, final int count, final long timeout, final long pingInterval, final int size) throws Exception { initialize(); final ParallelPingResponseCallback cb = new ParallelPingResponseCallback(count); final long threadId = JnaPingRequest.getNextTID(); for (int seqNum = 0; seqNum < count; seqNum++) { final JnaPingRequest request = new JnaPingRequest(host, m_pingerId, seqNum, threadId, timeout == 0? DEFAULT_TIMEOUT : timeout, 0, size, cb); m_pingTracker.sendRequest(request); Thread.sleep(pingInterval); } cb.waitFor(); return cb.getResponseTimes(); }
/** * <p>ping</p> * * @param host a {@link java.net.InetAddress} object. * @param timeout a long. * @param retries a int. * @param packetsize The size in byte of the ICMP packet. * @param sequenceId a short. * @param cb a {@link org.opennms.netmgt.icmp.jni.PingResponseCallback} object. * @throws java.lang.Exception if any. */ @Override public void ping(final InetAddress host, final long timeout, final int retries, final int sequenceId, final PingResponseCallback cb) throws Exception { if (host instanceof Inet4Address) { initialize4(); m_jniPinger.ping(host, timeout, retries, DEFAULT_PACKET_SIZE, sequenceId, cb); } else { initialize6(); s_pingTracker.sendRequest(new Jni6PingRequest((Inet6Address)host, m_pingerId, sequenceId, timeout, retries, DEFAULT_PACKET_SIZE, new LogPrefixPreservingPingResponseCallback(cb))); } }
/** * <p>ping</p> * * @param host a {@link java.net.InetAddress} object. * @param timeout a long. * @param retries a int. * @param packetsize The size in byte of the ICMP packet. * @param sequenceId a short. * @param cb a {@link org.opennms.netmgt.icmp.jni.PingResponseCallback} object. * @throws java.lang.Exception if any. */ @Override public void ping(final InetAddress host, final long timeout, final int retries, final int packetsize, final int sequenceId, final PingResponseCallback cb) throws Exception { if (host instanceof Inet4Address) { initialize4(); m_jniPinger.ping(host, timeout, retries, packetsize, sequenceId, cb); } else { initialize6(); s_pingTracker.sendRequest(new Jni6PingRequest((Inet6Address)host, m_pingerId, sequenceId, timeout, retries, packetsize, new LogPrefixPreservingPingResponseCallback(cb))); } }