From 156481b8140d3916d7ec7417dd438ca4b38d8998 Mon Sep 17 00:00:00 2001 From: Alina Quereilhac Date: Wed, 31 Aug 2011 18:22:55 +0200 Subject: [PATCH] udp and gre are working. tcp_handshake is not working yet. --- .../testbeds/planetlab/scripts/tun_connect.py | 16 +++-- src/nepi/util/tunchannel.py | 64 ++++++++++++------- test/testbeds/ns3/integration.py | 14 ++-- test/testbeds/planetlab/integration_multi.py | 8 ++- 4 files changed, 61 insertions(+), 41 deletions(-) diff --git a/src/nepi/testbeds/planetlab/scripts/tun_connect.py b/src/nepi/testbeds/planetlab/scripts/tun_connect.py index 08d50502..cf55e0da 100644 --- a/src/nepi/testbeds/planetlab/scripts/tun_connect.py +++ b/src/nepi/testbeds/planetlab/scripts/tun_connect.py @@ -38,7 +38,7 @@ parser.add_option( default = "/dev/net/tun", help = "TUN/TAP device file path or file descriptor number") parser.add_option( - "-p", "--peer-port", dest="peer-port", metavar="PEER_PORT", type="int", + "-p", "--peer-port", dest="peer_port", metavar="PEER_PORT", type="int", default = 15000, help = "Remote TCP/UDP port to connect to.") parser.add_option( @@ -199,7 +199,7 @@ parser.add_option( help = "If specified, packets won't be logged to standard output, " "but dumped to a pcap-formatted trace in the specified file. " ) -(options,) = parser.parse_args(sys.argv[1:]) +(options,args) = parser.parse_args(sys.argv[1:]) options.cipher = { 'aes' : 'AES', @@ -518,7 +518,7 @@ def pl_vif_start(tun_path, tun_name): stdin.write("txqueuelen=%d\n" % (options.vif_txqueuelen,)) if options.mode.startswith('pl-gre'): stdin.write("gre=%d\n" % (options.gre_key,)) - stdin.write("remote=%s\n" % (remaining_args[0],)) + stdin.write("remote=%s\n" % (options.peer_addr,)) stdin.close() t.join() @@ -772,16 +772,18 @@ try: elif options.protocol == "udp": # connect to remote endpoint if options.peer_addr and options.peer_port: - remote = tunchannel.udp_establish(TERMINATE, hostaddr, - options.port, options.peer_addr, options.peer_port) + rsock = tunchannel.udp_establish(TERMINATE, hostaddr, options.port, + options.peer_addr, options.peer_port) + remote = os.fdopen(rsock.fileno(), 'r+b', 0) else: print >>sys.stderr, "Error: need a remote endpoint in UDP mode" raise AssertionError, "Error: need a remote endpoint in UDP mode" elif options.protocol == "tcp": # connect to remote endpoint if options.peer_addr and options.peer_port: - remote = tunchannel.tcp_establish(TERMINATE, hostaddr, - options.port, options.peer_addr, options.peer_port) + rsock = tunchannel.tcp_establish(TERMINATE, hostaddr, options.port, + options.peer_addr, options.peer_port) + remote = os.fdopen(rsock.fileno(), 'r+b', 0) else: print >>sys.stderr, "Error: need a remote endpoint in TCP mode" raise AssertionError, "Error: need a remote endpoint in TCP mode" diff --git a/src/nepi/util/tunchannel.py b/src/nepi/util/tunchannel.py index fc627df4..baf39276 100644 --- a/src/nepi/util/tunchannel.py +++ b/src/nepi/util/tunchannel.py @@ -576,7 +576,7 @@ def tcp_connect(TERMINATE, stop, rsock, peer_addr, peer_port): retrydelay = 1.0 # The peer has a firewall that prevents a response to the connect, we # will be forever blocked in the connect, so we put a reasonable timeout. - sock.settimeout(10) + rsock.settimeout(10) # We wait for for i in xrange(30): if stop: @@ -596,6 +596,7 @@ def tcp_connect(TERMINATE, stop, rsock, peer_addr, peer_port): rsock.connect((peer_addr, peer_port)) sock = rsock if sock: + print >>sys.stderr, "tcp_connect: TCP sock connected to remote %s:%s" % (peer_addr, peer_port) sock.settimeout(0) return sock @@ -620,6 +621,7 @@ def tcp_listen(TERMINATE, stop, lsock, local_addr, local_port): else: lsock.bind((local_addr, local_port)) + print >>sys.stderr, "tcp_listen: TCP sock listening in local sock %s:%s" % (local_addr, local_port) # Now we wait until the other side connects. # The other side might not be ready yet, so we also wait in a loop for timeouts. timeout = 1 @@ -632,30 +634,32 @@ def tcp_listen(TERMINATE, stop, lsock, local_addr, local_port): break if lsock in rlist: sock,raddr = lsock.accept() + print >>sys.stderr, "tcp_listen: TCP connection accepted in local sock %s:%s" % (local_addr, local_port) break timeout += 5 return sock -def tcp_handshake(TERMINATE, sock, listen, dice): +def tcp_handshake(TERMINATE, rsock, listen, dice): # we are going to use a barrier algorithm to decide wich side listen. # each side will "roll a dice" and send the resulting value to the other # side. - result = None - sock.settimeout(5) + sock = None + rsock.settimeout(5) for i in xrange(100): if TERMINATE: raise OSError, "Killed" try: hand = dice.read() - sock.send(hand) - peer_hand = sock.recv(1) + rsock.send(str(hand)) + peer_hand = rsock.recv(1) + print >>sys.stderr, "tcp_handshake: hand %s, peer_hand %s" % (hand, peer_hand) if hand < peer_hand: if listen: - result = sock + sock = rsock break elif hand > peer_hand: if not listen: - result = sock + sock = rsock break else: dice.release() @@ -663,26 +667,42 @@ def tcp_handshake(TERMINATE, sock, listen, dice): except socket.error: dice.release() break - if result: + if sock: sock.settimeout(0) - return result + return sock def tcp_establish(TERMINATE, local_addr, local_port, peer_addr, peer_port): def listen(stop, result, lsock, dice): - lsock = tcp_listen(TERMINATE, stop, lsock, local_addr, local_port) - if lsock: - lsock = tcp_handshake(TERMINATE, lsock, True, dice) - if lsock: - stop[0] = True - result[0] = lsock + rsock = tcp_listen(TERMINATE, stop, lsock, local_addr, local_port) + if rsock: + rsock = tcp_handshake(TERMINATE, rsock, True, dice) + if rsock: + stop.append(True) + result.append(rsock) + rsock.send("GATO") + rsock.settimeout(6) + try: + perro = rsock.recv(5) + except: + perro = "ERROR! TIMEOUT" + rsock.settimeout(0) + print >>sys.stderr, "tcp_establish: listen %s" % perro def connect(stop, result, rsock, dice): rsock = tcp_connect(TERMINATE, stop, rsock, peer_addr, peer_port) if rsock: rsock = tcp_handshake(TERMINATE, rsock, False, dice) - if sock: - stop[0] = True - result[0] = rsock + if rsock: + stop.append(True) + result.append(rsock) + rsock.send("PERRO") + rsock.settimeout(6) + try: + gato = rsock.recv(4) + except: + gato = "TIMEOUT!!" + rsock.settimeout(0) + print >>sys.stderr, "tcp_establish: connected %s" % gato dice = Dice() dice.throw() @@ -690,8 +710,8 @@ def tcp_establish(TERMINATE, local_addr, local_port, peer_addr, peer_port): result = [] lsock = socket.socket(socket.AF_INET, socket.SOCK_STREAM, 0) rsock = socket.socket(socket.AF_INET, socket.SOCK_STREAM, 0) - connect_thread = threading.Thread(target=connect, args=(stop, result, rsock, dice)) listen_thread = threading.Thread(target=listen, args=(stop, result, lsock, dice)) + connect_thread = threading.Thread(target=connect, args=(stop, result, rsock, dice)) connect_thread.start() listen_thread.start() connect_thread.join() @@ -699,10 +719,6 @@ def tcp_establish(TERMINATE, local_addr, local_port, peer_addr, peer_port): if not result: raise OSError, "Error: tcp_establish could not establish connection." sock = result[0] - if sock == lsock: - rsock.close() - else: - lsock.close() return sock class Dice(object): diff --git a/test/testbeds/ns3/integration.py b/test/testbeds/ns3/integration.py index 12a41af9..248b9ae4 100755 --- a/test/testbeds/ns3/integration.py +++ b/test/testbeds/ns3/integration.py @@ -78,13 +78,13 @@ class Ns3IntegrationTestCase(unittest.TestCase): inst_root_dir = os.path.join(root_dir1, "instance") os.makedirs(inst_root_dir) ns3_desc1.set_attribute_value(DC.ROOT_DIRECTORY, inst_root_dir) - ns3_desc1.set_attribute_value(DC.LOG_LEVEL, DC.DEBUG_LEVEL) + #ns3_desc1.set_attribute_value(DC.LOG_LEVEL, DC.DEBUG_LEVEL) ns3_desc2.set_attribute_value(DC.DEPLOYMENT_MODE, DC.MODE_DAEMON) inst_root_dir = os.path.join(root_dir2, "instance") os.makedirs(inst_root_dir) ns3_desc2.set_attribute_value(DC.ROOT_DIRECTORY, inst_root_dir) - ns3_desc2.set_attribute_value(DC.LOG_LEVEL, DC.DEBUG_LEVEL) + #ns3_desc2.set_attribute_value(DC.LOG_LEVEL, DC.DEBUG_LEVEL) xml = exp_desc.to_xml() @@ -163,7 +163,7 @@ r [-+0-9.e]+ /NodeList/0/DeviceList/0/\$ns3::FdNetDevice/Rx Payload \(size=98\) inst_root_dir = os.path.join(self.root_dir, "instance") os.mkdir(inst_root_dir) ns3_desc.set_attribute_value(DC.ROOT_DIRECTORY, inst_root_dir) - ns3_desc.set_attribute_value(DC.LOG_LEVEL, DC.DEBUG_LEVEL) + #ns3_desc.set_attribute_value(DC.LOG_LEVEL, DC.DEBUG_LEVEL) xml = exp_desc.to_xml() @@ -191,7 +191,7 @@ r [-+0-9.e]+ /NodeList/0/DeviceList/0/\$ns3::FdNetDevice/Rx Payload \(size=98\) access_config = proxy.AccessConfiguration() access_config.set_attribute_value(DC.DEPLOYMENT_MODE, DC.MODE_DAEMON) access_config.set_attribute_value(DC.ROOT_DIRECTORY, self.root_dir) - access_config.set_attribute_value(DC.LOG_LEVEL, DC.DEBUG_LEVEL) + #access_config.set_attribute_value(DC.LOG_LEVEL, DC.DEBUG_LEVEL) self._test_fd_net_device( daemonize_testbed = True, @@ -205,7 +205,7 @@ r [-+0-9.e]+ /NodeList/0/DeviceList/0/\$ns3::FdNetDevice/Rx Payload \(size=98\) access_config = proxy.AccessConfiguration() access_config.set_attribute_value(DC.DEPLOYMENT_MODE, DC.MODE_DAEMON) access_config.set_attribute_value(DC.ROOT_DIRECTORY, self.root_dir) - access_config.set_attribute_value(DC.LOG_LEVEL, DC.DEBUG_LEVEL) + #access_config.set_attribute_value(DC.LOG_LEVEL, DC.DEBUG_LEVEL) access_config.set_attribute_value(DC.DEPLOYMENT_COMMUNICATION, DC.ACCESS_SSH) access_config.set_attribute_value(DC.DEPLOYMENT_PORT, env.port) access_config.set_attribute_value(DC.USE_AGENT, True) @@ -227,7 +227,7 @@ r [-+0-9.e]+ /NodeList/0/DeviceList/0/\$ns3::FdNetDevice/Rx Payload \(size=98\) access_config = proxy.AccessConfiguration() access_config.set_attribute_value(DC.DEPLOYMENT_MODE, DC.MODE_DAEMON) access_config.set_attribute_value(DC.ROOT_DIRECTORY, self.root_dir) - access_config.set_attribute_value(DC.LOG_LEVEL, DC.DEBUG_LEVEL) + #access_config.set_attribute_value(DC.LOG_LEVEL, DC.DEBUG_LEVEL) self._test_if( daemonize_testbed = True, @@ -241,7 +241,7 @@ r [-+0-9.e]+ /NodeList/0/DeviceList/0/\$ns3::FdNetDevice/Rx Payload \(size=98\) access_config = proxy.AccessConfiguration() access_config.set_attribute_value(DC.DEPLOYMENT_MODE, DC.MODE_DAEMON) access_config.set_attribute_value(DC.ROOT_DIRECTORY, self.root_dir) - access_config.set_attribute_value(DC.LOG_LEVEL, DC.DEBUG_LEVEL) + #access_config.set_attribute_value(DC.LOG_LEVEL, DC.DEBUG_LEVEL) access_config.set_attribute_value(DC.DEPLOYMENT_COMMUNICATION, DC.ACCESS_SSH) access_config.set_attribute_value(DC.DEPLOYMENT_PORT, env.port) access_config.set_attribute_value(DC.USE_AGENT, True) diff --git a/test/testbeds/planetlab/integration_multi.py b/test/testbeds/planetlab/integration_multi.py index c3db7499..4be4f0ed 100755 --- a/test/testbeds/planetlab/integration_multi.py +++ b/test/testbeds/planetlab/integration_multi.py @@ -71,6 +71,7 @@ class PlanetLabMultiIntegrationTestCase(unittest.TestCase): pl_desc.set_attribute_value("tapPortBase", self.port_base) pl_desc.set_attribute_value("p2pDeployment", False) # it's interactive, we don't want it in tests pl_desc.set_attribute_value("dedicatedSlice", True) + pl_desc.set_attribute_value("plLogLevel", "DEBUG") pl_desc2 = exp_desc.add_testbed_description(pl_provider) pl_desc2.set_attribute_value("homeDirectory", self.root_dir+"v2") @@ -82,6 +83,7 @@ class PlanetLabMultiIntegrationTestCase(unittest.TestCase): pl_desc2.set_attribute_value("tapPortBase", self.port_base+500) pl_desc2.set_attribute_value("p2pDeployment", False) # it's interactive, we don't want it in tests pl_desc2.set_attribute_value("dedicatedSlice", True) + pl_desc2.set_attribute_value("plLogLevel", "DEBUG") return pl_desc, pl_desc2, exp_desc @@ -182,7 +184,7 @@ class PlanetLabMultiIntegrationTestCase(unittest.TestCase): @test_util.skipUnless(test_util.pl_auth() is not None, "Test requires PlanetLab authentication info (PL_USER and PL_PASS environment variables)") - def test_plpl_crossconnect_udp(self): + def ptest_plpl_crossconnect_udp(self): self._test_plpl_crossconnect("udp") @test_util.skipUnless(test_util.pl_auth() is not None, @@ -192,12 +194,12 @@ class PlanetLabMultiIntegrationTestCase(unittest.TestCase): @test_util.skipUnless(test_util.pl_auth() is not None, "Test requires PlanetLab authentication info (PL_USER and PL_PASS environment variables)") - def test_plpl_crossconnect_gre(self): + def ptest_plpl_crossconnect_gre(self): self._test_plpl_crossconnect("gre") @test_util.skipUnless(test_util.pl_auth() is not None, "Test requires PlanetLab authentication info (PL_USER and PL_PASS environment variables)") - def test_plpl_crossconnect_udp_recover(self): + def ptest_plpl_crossconnect_udp_recover(self): self._test_plpl_crossconnect("udp", recover = True) -- 2.47.0