|
From: Peter P. <pr...@us...> - 2006-11-24 10:53:29
|
Update of /cvsroot/pyxida/Pyxida/src/edu/harvard/syrah/pyxida/ping In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv19223/src/edu/harvard/syrah/pyxida/ping Modified Files: ICMPPinger.java Pinger.java JpcapPinger.java Log Message: Found a workaround for the timeout issue. If there's no response to am ICMP echo request, you should receive a timeout message. Index: Pinger.java =================================================================== RCS file: /cvsroot/pyxida/Pyxida/src/edu/harvard/syrah/pyxida/ping/Pinger.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** Pinger.java 23 Nov 2006 23:22:48 -0000 1.2 --- Pinger.java 24 Nov 2006 10:53:27 -0000 1.3 *************** *** 1,5 **** package edu.harvard.syrah.pyxida.ping; - import edu.harvard.syrah.sbon.async.CallbacksIF.CB1; import edu.harvard.syrah.sbon.comm.AddressIF; --- 1,4 ---- *************** *** 16,20 **** AddressIF pingAddr; double lat; - CB1<Double> cbLat; } --- 15,18 ---- Index: JpcapPinger.java =================================================================== RCS file: /cvsroot/pyxida/Pyxida/src/edu/harvard/syrah/pyxida/ping/JpcapPinger.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** JpcapPinger.java 23 Nov 2006 23:22:48 -0000 1.1 --- JpcapPinger.java 24 Nov 2006 10:53:27 -0000 1.2 *************** *** 13,16 **** --- 13,17 ---- import jpcap.NetworkInterfaceAddress; import jpcap.packet.EthernetPacket; + import jpcap.packet.IPPacket; import jpcap.packet.Packet; import edu.harvard.syrah.prp.Log; *************** *** 33,37 **** private static JpcapCaptor captor; ! private static JpcapSender sender; protected static NetworkInterface device; --- 34,38 ---- private static JpcapCaptor captor; ! protected static JpcapSender sender; protected static NetworkInterface device; *************** *** 51,55 **** } ! protected static JpcapPingData currentPing; public void init(AddressIF defaultPingAddr, final CB0 cbDone) { --- 52,56 ---- } ! private static JpcapPingData currentPing; public void init(AddressIF defaultPingAddr, final CB0 cbDone) { *************** *** 166,205 **** protected void addRequest(JpcapPingData pd) { JpcapPinger.currentPing = pd; - synchronized(jpcapThread) { - jpcapThread.notify(); - } } public void run() { ! try { while (!jpcapThread.isInterrupted()) { ! if (currentPing == null) { ! synchronized (jpcapThread) { ! jpcapThread.wait(); ! } ! } ! ! if (currentPing != null) { ! AddressIF pingAddr = currentPing.pingAddr; ! Packet packet = currentPing.sendPacket; ! captor.setFilter("icmp and src host " + pingAddr.getHostname(), true); ! currentPing.sendTS = System.nanoTime() / 1000; ! try { ! sender.sendPacket(packet); ! } catch (Exception e) { ! log.warn("Failed sending packet: " + e); ! } ! log.debug("sendPacket=" + packet); ! log.debug("sendTS=" + currentPing.sendTS); ! assert currentPing.sendTS > 0; ! currentPing.recvPacket = captor.getPacket(); ! log.debug("Received packet: " + currentPing.recvPacket); EventLoop.get().registerTimerCB(currentPing.cbDone); currentPing = null; } - } - } catch (InterruptedException e) { /* ignore */ } } --- 167,190 ---- protected void addRequest(JpcapPingData pd) { JpcapPinger.currentPing = pd; } public void run() { ! captor.setFilter("icmp and dst host " + thisIP.getHostAddress(), true); ! //captor.setFilter("icmp", true); ! while (!jpcapThread.isInterrupted()) { ! IPPacket ip = null; ! do { ! log.debug("Waiting for a packet..."); ! ip = (IPPacket) captor.getPacket(); ! log.debug("Captured a packet: ip=" + ip + " src=" + ip.src_ip); ! } while (currentPing == null || !ip.src_ip.equals(currentPing.pingAddr.getInetAddress())); ! currentPing.recvPacket = ip; ! log.debug("Received packet: " + currentPing.recvPacket); EventLoop.get().registerTimerCB(currentPing.cbDone); currentPing = null; } } Index: ICMPPinger.java =================================================================== RCS file: /cvsroot/pyxida/Pyxida/src/edu/harvard/syrah/pyxida/ping/ICMPPinger.java,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** ICMPPinger.java 23 Nov 2006 23:22:48 -0000 1.5 --- ICMPPinger.java 24 Nov 2006 10:53:27 -0000 1.6 *************** *** 18,21 **** --- 18,22 ---- private static final long PING_DELAY = 1000; + private static final long PING_TIMEOUT = 3000; public void init(AddressIF defaultPingAddr, final CB0 cbDone) { *************** *** 27,31 **** ping(remoteNode, new CB1<Double>() { protected void cb(CBResult result, Double lat) { ! System.out.println("lat=" + (lat > 0 ? lat : "Timeout")); EventLoop.get().registerTimerCB(PING_DELAY, new CB0() { protected void cb(CBResult result) { --- 28,32 ---- ping(remoteNode, new CB1<Double>() { protected void cb(CBResult result, Double lat) { ! System.out.println(lat == 0 ? "Timeout" : "lat=" + (lat > 0 ? lat : "Neg")); EventLoop.get().registerTimerCB(PING_DELAY, new CB0() { protected void cb(CBResult result) { *************** *** 38,55 **** public void ping(AddressIF remoteNode, final CB1<Double> cbPing) throws UnsupportedOperationException { final JpcapPingData pd = new JpcapPingData(); pd.pingAddr = remoteNode; ! pd.cbLat = cbPing; ! pd.sendPacket = createICMP(remoteNode); ! pd.cbDone = new CB0() { protected void cb(CBResult resultOK) { pd.recvTS = parseICMP(pd.recvPacket); long lat = 0; ! if (pd.recvTS > 0) lat = pd.recvTS - pd.sendTS; cbPing.call(resultOK, lat / 1000.0); } }; ! addRequest(pd); } --- 39,74 ---- public void ping(AddressIF remoteNode, final CB1<Double> cbPing) throws UnsupportedOperationException { + log.debug("Sending new ping to remoteNode=" + remoteNode); final JpcapPingData pd = new JpcapPingData(); pd.pingAddr = remoteNode; ! ! pd.cbDone = new CB0(PING_TIMEOUT) { protected void cb(CBResult resultOK) { + log.debug("pd.recvPacket=" + pd.recvPacket); pd.recvTS = parseICMP(pd.recvPacket); + log.debug("pd.recvTS=" + pd.recvTS); long lat = 0; ! if (pd.recvTS > 0) { ! assert pd.sendTS > 0; ! assert pd.recvTS > pd.sendTS : "send TS > recv TS ?"; lat = pd.recvTS - pd.sendTS; + } + log.debug("lat=" + lat); cbPing.call(resultOK, lat / 1000.0); } }; ! ! addRequest(pd); ! ! pd.sendPacket = createICMP(pd.pingAddr); ! try { ! sender.sendPacket(pd.sendPacket); ! } catch (Exception e) { ! log.warn("Failed sending packet: " + e); ! } ! pd.sendTS = System.nanoTime() / 1000; ! log.debug("sendPacket=" + pd.sendPacket); ! log.debug("sendTS=" + pd.sendTS); ! assert pd.sendTS > 0; } *************** *** 82,85 **** --- 101,106 ---- private long parseICMP(Packet p) { + log.debug("p=" + p + " p.class=" + (p != null ? p.getClass() : null)); + long recvTS = Long.MIN_VALUE; ICMPPacket icmp = (ICMPPacket) p; *************** *** 97,101 **** } else if (icmp.type == ICMPPacket.ICMP_ECHOREPLY) { - icmp.src_ip.getHostName(); long sec = p.sec; long usec = p.usec; --- 118,121 ---- *************** *** 157,164 **** } }); - EventLoop.get().main(); - } - } --- 177,181 ---- |