Skip to content

Commit bc87aac

Browse files
committed
bug workaround: the TCP stack does not retransmit unless it receives some more packets. Add a timer to check for any retransmits 2 seconds after receiving any packet.
1 parent 7922bce commit bc87aac

File tree

2 files changed

+24
-12
lines changed

2 files changed

+24
-12
lines changed

TCPStack.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ class TCPConnection():
6666
"""Manages the state of one half of a TCP connection."""
6767
def __init__(self, syn_seq, my_ip, my_port, other_ip, other_port,
6868
connection_over_callback, has_data_to_send_callback,
69-
assumed_rtt=0.5, mtu=1500, max_data=2048, max_wait_time_sec=5):
69+
assumed_rtt=0.5, mtu=1500, max_data=2048, max_wait_time_sec=30):
7070
# socket pair
7171
self.my_ip = my_ip
7272
self.my_port = my_port

Topology.py

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010

1111
from django.contrib.auth.models import User
1212

13+
from twisted.internet import reactor
14+
1315
from settings import ARP_CACHE_TIMEOUT, MAY_FORWARD_TO_PRIVATE_IPS, WEB_SERVER_ROOT_WWW
1416
from AddressAllocation import allocate_to_topology
1517
from DRRQueue import DRRQueue
@@ -256,7 +258,7 @@ def handle_packet_from_client(self, conn, pkt_msg):
256258

257259
# failed to find the specified interface
258260
fmt = 'bad packet request: invalid interface: %s'
259-
return fmt % (n.name, departure_intf_name)
261+
return fmt % ((n.name, departure_intf_name),)
260262

261263
def create_job_for_incoming_packet(self, packet, rewrite_dst_mac):
262264
"""Enqueues a job for handling this packet with handle_incoming_packet()."""
@@ -909,6 +911,8 @@ class WebServer(BasicNode):
909911
def __init__(self, topo, name, path_to_serve):
910912
BasicNode.__init__(self, topo, name)
911913
self.http_server = HTTPServer(TCPServer.ANY_PORT, path_to_serve)
914+
self.intf = None
915+
self.pkt = None
912916

913917
@staticmethod
914918
def get_type_str():
@@ -917,24 +921,32 @@ def get_type_str():
917921
def handle_non_icmp_ip_packet_to_self(self, intf, pkt):
918922
"""If pkt is to an HTTP_PORT, then the packet is handed off to the HTTP
919923
server. Otherwise, the default superclass implementation is called."""
924+
reactor.callLater(2, self.send_packets)
920925
if pkt.is_valid_tcp():
921926
if is_http_port(pkt.tcp_dst_port):
922927
self.handle_http_request(intf, pkt)
923928
return
924929
BasicNode.handle_non_icmp_ip_packet_to_self(self, intf, pkt)
925930

926931
def handle_http_request(self, intf, pkt):
927-
"""Forward the received packet from an HTTP client to the web server."""
932+
"""Forward the rceived packet from an HTTP client to the web server."""
933+
self.intf = intf
934+
self.pkt = pkt
928935
tcp_conn = self.http_server.handle_tcp(pkt)
929-
if tcp_conn:
930-
tcp_pts = tcp_conn.get_packets_to_send()
931-
if tcp_pts:
932-
for tcp, data in tcp_pts:
933-
eth = pkt.get_reversed_eth()
934-
ip = pkt.get_reversed_ip(new_ttl=64, new_tlen=pkt.ip_hlen+len(tcp)+len(data))
935-
pkt_out = eth + ip + Packet.cksum_tcp_hdr(ip, tcp, data) + data
936-
logging.debug('%s sending packet from HTTP server: %s' % (self, pktstr(pkt_out)))
937-
intf.link.send_to_other(intf, pkt_out)
936+
self.send_packets()
937+
938+
def send_packets(self):
939+
"""Send any waiting packets"""
940+
if self.intf and self.pkt:
941+
for (_, tcp_conn) in self.http_server.connections.iteritems():
942+
if tcp_conn and not tcp_conn.dead:
943+
tcp_pts = tcp_conn.get_packets_to_send()
944+
for tcp, data in tcp_pts:
945+
eth = self.pkt.get_reversed_eth()
946+
ip = self.pkt.get_reversed_ip(new_ttl=64, new_tlen=self.pkt.ip_hlen+len(tcp)+len(data))
947+
pkt_out = eth + ip + Packet.cksum_tcp_hdr(ip, tcp, data) + data
948+
logging.debug('%s sending packet from HTTP server: %s' % (self, pktstr(pkt_out)))
949+
self.intf.link.send_to_other(self.intf, pkt_out)
938950

939951
def __str__(self):
940952
ps = ' serving:%s' % self.http_server.get_path_being_served()

0 commit comments

Comments
 (0)