Tunnel between 2 ns-3s in remote PL hosts
[nepi.git] / src / nepi / resources / linux / scripts / fd-udp-connect.py
@@ -43,15 +43,20 @@ def _resume(sig,frame):
 signal.signal(signal.SIGUSR2, _resume)
 
 def get_options():
-    usage = ("usage: %prog -a <address> -b <bwlimit> -c <cipher> "
-            "- k <cipher-key> -q <txqueuelen> -p <local-port-file> "
-            "-P <remote-port-file> -o <local-ip> -O <remote-ip> "
-            "-r <ret-file> ")
+    usage = ("usage: %prog -a <address> -t <vif-type> -n "
+            "-b <bwlimit> -c <cipher> -k <cipher-key> "
+            "-q <txqueuelen> -p <local-port-file> -P <remote-port-file> "
+            "-o <local-ip> -O <remote-ip> -r <ret-file> ")
     
     parser = OptionParser(usage = usage)
 
     parser.add_option("-a", "--address", dest="address",
         help="Socket address to send file descriptor to", type="str")
+    parser.add_option("-t", "--vif-type", dest="vif_type",
+        help="Virtual interface type. Either IFF_TAP or IFF_TUN. "
+            "Defaults to IFF_TAP. ", default=IFF_TAP, type="str")
+    parser.add_option("-n", "--pi", dest="pi", action="store_true", 
+            default=False, help="Enable PI header")
 
     parser.add_option("-b", "--bwlimit", dest="bwlimit",
         help="Specifies the interface's emulated bandwidth in bytes ",
@@ -84,18 +89,24 @@ def get_options():
         default = "ret_file", type="str")
 
     (options, args) = parser.parse_args()
-       
+            
+    vif_type = IFF_TAP
+    if options.vif_type and options.vif_type == "IFF_TUN":
+        vif_type = IFF_TUN
+  
     address = base64.b64decode(options.address)
 
-    return (address, options.local_port_file, options.remote_port_file, 
+    return (address,  vif_type, options.pi, 
+            options.local_port_file, options.remote_port_file, 
             options.local_ip, options.remote_ip, options.ret_file, 
             options.bwlimit, options.cipher, options.cipher_key, 
             options.txqueuelen)
 
 if __name__ == '__main__':
 
-    (address, local_port_file, remote_port_file, local_ip, remote_ip, 
-            ret_file, bwlimit, cipher, cipher_key, txqueuelen) = get_options()
+    (address, vif_type, pi, local_port_file, remote_port_file, 
+            local_ip, remote_ip, ret_file, bwlimit, cipher, cipher_key, 
+            txqueuelen) = get_options()
 
     # Create a local socket to stablish the tunnel connection
     rsock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM, 0)
@@ -154,8 +165,8 @@ if __name__ == '__main__':
 
     # Establish tunnel
     tunchannel.tun_fwd(tun, remote,
-        with_pi = True, # No PI headers 
-        ether_mode = IFF_TAP, # Ns-3 generates ethernet pkts
+        with_pi = pi, 
+        ether_mode = (vif_type == IFF_TAP),
         udp = True,
         cipher_key = cipher_key,
         cipher = cipher,