@Override public RequestTracker<JniPingRequest, JniPingResponse> call() throws Exception { return new RequestTracker<JniPingRequest, JniPingResponse>("JNI-ICMP-"+m_pingerId, m_messenger, new IDBasedRequestLocator<JniPingRequestId, JniPingRequest, JniPingResponse>()); } });
@Override public RequestTracker<Jni6PingRequest, Jni6PingResponse> call() throws Exception { return new RequestTracker<Jni6PingRequest, Jni6PingResponse>(name, m_jni6messenger, requestLocator); } });
/** * 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(); }
@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.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)); }
/** * <p>Constructor for SmsPingTrackerImpl.</p> * * @param smsMessenger a {@link org.opennms.sms.ping.internal.SmsPingMessenger} object. * @throws java.io.IOException if any. */ public SmsPingTrackerImpl(SmsPingMessenger smsMessenger) throws IOException { super("SMS", smsMessenger, new IDBasedRequestLocator<PingRequestId, PingRequest, PingReply>()); LOG.debug("Created SmsPingTrackerImpl"); }
/** {@inheritDoc} */ @Override public synchronized void start() { LOG.debug("Calling start()"); super.start(); LOG.debug("Called start()"); }
@Override public void onPingReply(final InetAddress address, final EchoPacket packet) { m_callback.handleReply(new JnaPingReply(address, packet)); }
@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<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)); }
void processPackets(ReplyHandler<Jni6PingResponse> callback) { while (true) { try { DatagramPacket packet = m_socket.receive(); Jni6PingResponse reply = Jni6IcmpMessenger.createPingResponse(packet); if (reply != null && reply.getIdentifier() == m_pingerId) { callback.handleReply(reply); } } catch (IOException e) { LOG.error("I/O Error occurred reading from ICMP Socket", e); } catch (IllegalArgumentException e) { // this is not an EchoReply so ignore it } catch (IndexOutOfBoundsException e) { // this packet is not a valid EchoReply ignore it } catch (Throwable e) { LOG.error("Unexpected Exception processing reply packet!", 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)); }
void processPackets(ReplyHandler<Jni6PingResponse> callback) { while (true) { try { DatagramPacket packet = m_socket.receive(); Jni6PingResponse reply = Jni6IcmpMessenger.createPingResponse(packet); if (reply != null && reply.getIdentifier() == m_pingerId) { callback.handleReply(reply); } } catch (IOException e) { LOG.error("I/O Error occurred reading from ICMP Socket", e); } catch (IllegalArgumentException e) { // this is not an EchoReply so ignore it } catch (IndexOutOfBoundsException e) { // this packet is not a valid EchoReply ignore it } catch (Throwable e) { LOG.error("Unexpected Exception processing reply packet!", e); } } }
/** * <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))); }
void processPackets(ReplyHandler<JniPingResponse> callback) { final int pingerId = m_pingerId; while (true) { try { DatagramPacket packet = m_socket.receive(); JniPingResponse reply = JniIcmpMessenger.createPingResponse(packet); if (reply.isEchoReply() && reply.getIdentifier() == pingerId) { // Remove this so we don't send a lot of time in this method when we should be processing packets // LogUtils.debugf(this, "Found an echo packet addr = %s, port = %d, length = %d, created reply %s", packet.getAddress(), packet.getPort(), packet.getLength(), reply); callback.handleReply(reply); } } catch (IOException e) { LOG.error("I/O Error occurred reading from ICMP Socket", e); } catch (IllegalArgumentException e) { // this is not an EchoReply so ignore it } catch (IndexOutOfBoundsException e) { // this packet is not a valid EchoReply ignore it } catch (Throwable e) { LOG.error("Unexpected Exception processing reply packet!", e); } } }
/** * <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>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))); } }