From: Alina Quereilhac Date: Mon, 1 Aug 2011 10:31:37 +0000 (+0200) Subject: Adapted ns3 testbed to changes in FdNetDevice. X-Git-Tag: nepi-3.0.0~320^2~2 X-Git-Url: http://git.onelab.eu/?a=commitdiff_plain;h=899ce3800c804da3f039ddbc9dda7c5eda84ff7d;p=nepi.git Adapted ns3 testbed to changes in FdNetDevice. --- diff --git a/src/nepi/testbeds/ns3/attributes_metadata.py b/src/nepi/testbeds/ns3/attributes_metadata.py index 170d0186..0ef4e719 100644 --- a/src/nepi/testbeds/ns3/attributes_metadata.py +++ b/src/nepi/testbeds/ns3/attributes_metadata.py @@ -2437,18 +2437,6 @@ attributes = dict({ "allowed": wifi_standards.keys(), "help": "Wifi PHY standard" }), - "LinuxSocketAddress": dict({ - "name": "LinuxSocketAddress", - "validation_function": None, - "value": "", - "flags": Attribute.DesignInvisible | \ - Attribute.ExecInvisible | \ - Attribute.ExecReadOnly | \ - Attribute.ExecImmutable | \ - Attribute.Metadata, - "type": Attribute.STRING, - "help": "Socket address assigned to the Linux socket created to recive file descriptor" - }), "ClassifierSrcAddress": dict({ "name": "SrcAddress", "validation_function": validation.is_string, # TODO:! Address + Netref diff --git a/src/nepi/testbeds/ns3/connection_metadata.py b/src/nepi/testbeds/ns3/connection_metadata.py index 6d14a266..a76a3b3a 100644 --- a/src/nepi/testbeds/ns3/connection_metadata.py +++ b/src/nepi/testbeds/ns3/connection_metadata.py @@ -113,47 +113,38 @@ def connect_classifier_sflow(testbed_instance, classifier_guid, sflow_guid): sflow.SetConvergenceSublayerParam (csparam); def connect_fd(testbed_instance, fdnd_guid, cross_data): - fdnd = testbed_instance._elements[fdnd_guid] - endpoint = fdnd.GetEndpoint() - # XXX: check the method StringToBuffer of ns3::FdNetDevice - # to see how the address should be decoded - address = endpoint.replace(":", "").decode('hex')[2:] - testbed_instance.set(fdnd_guid, "LinuxSocketAddress", address) - - # If it's a non-abstract socket, add the path - if not address.startswith('\x00'): - address = os.path.join( testbed_instance.root_directory, address ) + def recvfd(sock, fdnd): + (fd, msg) = passfd.recvfd(sock) + # Store a reference to the endpoint to keep the socket alive + fdnd.SetFileDescriptor(fd) + import threading + import passfd + import socket + sock = socket.socket(socket.AF_UNIX, socket.SOCK_DGRAM) + sock.bind("") + address = sock.getsockname() # Set tun standard contract attributes - testbed_instance.set(fdnd_guid, "tun_addr", address ) + testbed_instance.set(fdnd_guid, "tun_addr", address) testbed_instance.set(fdnd_guid, "tun_proto", "fd") testbed_instance.set(fdnd_guid, "tun_port", 0) testbed_instance.set(fdnd_guid, "tun_key", ("\xfa"*32).encode("base64")) # unimportant, fds aren't encrypted + fdnd = testbed_instance._elements[fdnd_guid] + t = threading.Thread(target=recvfd, args=(sock,fdnd)) + t.start() def connect_tunchannel_fd(testbed_instance, tun_guid, fdnd_guid): fdnd = testbed_instance._elements[fdnd_guid] tun = testbed_instance._elements[tun_guid] - # XXX: check the method StringToBuffer of ns3::FdNetDevice - # to see how the address should be decoded - endpoint = fdnd.GetEndpoint() - address = endpoint.replace(":", "").decode('hex')[2:] - testbed_instance.set(fdnd_guid, "LinuxSocketAddress", address) - # Create socket pair to connect the FDND and the TunChannel with it import socket sock1, sock2 = socket.socketpair( socket.AF_UNIX, socket.SOCK_SEQPACKET) - # Send one endpoint to the FDND - import passfd - import socket - sock = socket.socket(socket.AF_UNIX, socket.SOCK_DGRAM) - sock.connect(address) - passfd.sendfd(sock, sock1.fileno(), '0') - # Store a reference to the endpoint to keep the socket alive fdnd._endpoint_socket = sock1 + fdnd.SetFileDescriptor(sock1.fileno()) # Send the other endpoint to the TUN channel tun.tun_socket = sock2 @@ -163,7 +154,6 @@ def connect_tunchannel_fd(testbed_instance, tun_guid, fdnd_guid): # the default presence of PI headers) tun.with_pi = True - ### Connector information ### connector_types = dict({ diff --git a/src/nepi/testbeds/ns3/factories_metadata.py b/src/nepi/testbeds/ns3/factories_metadata.py index f706f285..197c152e 100644 --- a/src/nepi/testbeds/ns3/factories_metadata.py +++ b/src/nepi/testbeds/ns3/factories_metadata.py @@ -1036,7 +1036,6 @@ factories_info = dict({ "help": "Network interface associated to a file descriptor", "connector_types": ["node", "->fd"], "box_attributes": ["Address", - "LinuxSocketAddress", "tun_proto", "tun_addr", "tun_port", "tun_key"], "traces": ["fdpcap"], "tags": [tags.INTERFACE, tags.ALLOW_ADDRESSES],