Adapted ns3 testbed to changes in FdNetDevice.
authorAlina Quereilhac <alina.quereilhac@inria.fr>
Mon, 1 Aug 2011 10:31:37 +0000 (12:31 +0200)
committerAlina Quereilhac <alina.quereilhac@inria.fr>
Mon, 1 Aug 2011 10:31:37 +0000 (12:31 +0200)
src/nepi/testbeds/ns3/attributes_metadata.py
src/nepi/testbeds/ns3/connection_metadata.py
src/nepi/testbeds/ns3/factories_metadata.py

index 170d018..0ef4e71 100644 (file)
@@ -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
index 6d14a26..a76a3b3 100644 (file)
@@ -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({
index f706f28..197c152 100644 (file)
@@ -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],