Author: mrogers
Date: 2006-07-27 08:59:44 +0000 (Thu, 27 Jul 2006)
New Revision: 9790

Modified:
   trunk/apps/load-balancing-sims/phase5/Packet.java
   trunk/apps/load-balancing-sims/phase5/Peer.java
Log:
Don't send empty packets if txHeadSize > cwind - inflight - Packet.HEADER_SIZE

Modified: trunk/apps/load-balancing-sims/phase5/Packet.java
===================================================================
--- trunk/apps/load-balancing-sims/phase5/Packet.java   2006-07-26 23:14:46 UTC 
(rev 9789)
+++ trunk/apps/load-balancing-sims/phase5/Packet.java   2006-07-27 08:59:44 UTC 
(rev 9790)
@@ -4,17 +4,18 @@

 abstract class Packet
 {
-       public final static int HEADER_SIZE = 50;
+       public final static int HEADER_SIZE = 80; // Including IP & UDP headers
        public final static int MAX_PAYLOAD = 1400;
+       public final static int SENSIBLE_PAYLOAD = 1000; // Nagle's algorithm

        public int src, dest; // Network addresses
        public int size; // Packet size in bytes, including headers
-       public int seq; // Sequence number or explicit ack
        public double latency; // Link latency (stored here for convenience)
 }

 class DataPacket extends Packet
 {
+       public int seq; // Sequence number
        public ArrayList<Message> messages = null; // Payload   
        public double sent; // Time at which the packet was (re)transmitted

@@ -23,14 +24,7 @@
                size = dataSize + HEADER_SIZE;
        }

-       /*
-       In real life the payload would be an array of bytes, but here the 
-       payload is represented by an ArrayList of Messages. A large message can
-       be split across more than one packet, in which case the message only
-       appears in the payload of the *last* packet. This means it's possible
-       for a full packet to have an apparently empty payload.
-       */
-       
+       // In real life the payload would be an array of bytes
        public void addMessage (Message m)
        {
                if (messages == null) messages = new ArrayList<Message>();
@@ -40,9 +34,11 @@

 class Ack extends Packet
 {
-       public Ack (int seq)
+       public int ack; // Explicit ack of a DataPacket's sequence number
+       
+       public Ack (int ack)
        {
                size = HEADER_SIZE;
-               this.seq = seq;
+               this.ack = ack;
        }
 }

Modified: trunk/apps/load-balancing-sims/phase5/Peer.java
===================================================================
--- trunk/apps/load-balancing-sims/phase5/Peer.java     2006-07-26 23:14:46 UTC 
(rev 9789)
+++ trunk/apps/load-balancing-sims/phase5/Peer.java     2006-07-27 08:59:44 UTC 
(rev 9790)
@@ -9,9 +9,6 @@
        public double location; // The remote node's routing location
        private double latency; // The latency of the connection in seconds

-       // Nagle's algorithm
-       public final static int SENSIBLE_PAYLOAD = 1000; // Minimum packet size
-       
        // Retransmission parameters
        public final static double TIMER = 0.5; // Coarse-grained timer, seconds
        public final static double RTO = 4.0; // Retransmission timeout in RTTs
@@ -78,11 +75,23 @@
                        return false;
                }

-               if (cwind - inflight <= Packet.HEADER_SIZE) {
+               // Work out how large a packet we can send
+               int payload = Packet.MAX_PAYLOAD;
+               if (payload > txQueueSize) payload = txQueueSize;
+               if (payload > cwind - inflight - Packet.HEADER_SIZE)
+                       payload = (int) cwind - inflight - Packet.HEADER_SIZE;
+               
+               if (payload < txHeadSize) {
                        log ("no room in congestion window");
                        return false;
                }

+               // Nagle's algorithm - try to coalesce small packets
+               if (payload < Packet.SENSIBLE_PAYLOAD && inflight > 0) {
+                       log ("delaying transmission of " + payload + " bytes");
+                       return false;
+               }
+               
                // Return to slow start when the link is idle
                double now = Event.time();
                if (now - lastTransmission > RTO * rtt) {
@@ -92,18 +101,6 @@
                }
                lastTransmission = now;

-               // Work out how large a packet we can send
-               int payload = Packet.MAX_PAYLOAD;
-               if (payload > txQueueSize) payload = txQueueSize;
-               if (payload > cwind - inflight - Packet.HEADER_SIZE)
-                       payload = (int) cwind - inflight - Packet.HEADER_SIZE;
-               
-               // Nagle's algorithm - try to coalesce small packets
-               if (payload < SENSIBLE_PAYLOAD && inflight > 0) {
-                       log ("delaying transmission of " + payload + " bytes");
-                       return false;
-               }
-               
                // Put as many messages as possible in the packet
                DataPacket p = new DataPacket (payload);
                while (payload >= txHeadSize) {
@@ -208,14 +205,14 @@

        private void handleAck (Ack a)
        {
-               log ("received ack " + a.seq);
+               log ("received ack " + a.ack);
                double now = Event.time();
                Iterator<DataPacket> i = txBuffer.iterator();
                while (i.hasNext()) {
                        DataPacket p = i.next();
                        double age = now - p.sent;
                        // Explicit ack
-                       if (p.seq == a.seq) {
+                       if (p.seq == a.ack) {
                                log ("packet " + p.seq + " acknowledged");
                                i.remove();
                                inflight -= p.size;
@@ -232,7 +229,7 @@
                                break;
                        }
                        // Fast retransmission
-                       if (p.seq < a.seq && age > FRTO * rtt) {
+                       if (p.seq < a.ack && age > FRTO * rtt) {
                                p.sent = now;
                                log ("fast retransmitting packet " + p.seq);
                                log (inflight + " bytes in flight");
@@ -265,7 +262,7 @@

        private void log (String message)
        {
-               // Event.log (node.net.address + ":" + address + " " + message);
+               Event.log (node.net.address + ":" + address + " " + message);
        }

        // Event callback


Reply via email to