Merge TCP handshake stuff
[nepi.git] / src / nepi / testbeds / planetlab / metadata.py
index 0123ce6..b388707 100644 (file)
@@ -31,6 +31,9 @@ NETPIPE = "NetPipe"
 TUNFILTER = "TunFilter"
 CLASSQUEUEFILTER = "ClassQueueFilter"
 TOSQUEUEFILTER = "TosQueueFilter"
+MULTICASTFORWARDER = "MulticastForwarder"
+MULTICASTANNOUNCER = "MulticastAnnouncer"
+MULTICASTROUTER = "MulticastRouter"
 
 TUNFILTERS = (TUNFILTER, CLASSQUEUEFILTER, TOSQUEUEFILTER)
 TAPFILTERS = (TUNFILTER, )
@@ -121,9 +124,14 @@ def connect_tun_iface_peer(proto, testbed_instance, iface_guid, peer_iface_guid)
 def connect_tun_iface_filter(testbed_instance, iface_guid, filter_guid):
     iface = testbed_instance._elements[iface_guid]
     filt = testbed_instance._elements[filter_guid]
+    traces = testbed_instance._get_traces(filter_guid)
+    if 'dropped_stats' in traces: 
+        args = filt.args if filt.args else ""
+        filt.args = ','.join(filt.args.split(',') + ["logdropped=true",])
     iface.filter_module = filt
     filt.iface_guid = iface_guid
     filt.iface = weakref.ref(iface)
+
     if filt.peer_guid:
         connect_tun_iface_peer(filt.peer_proto, testbed_instance, filt.iface_guid, filt.peer_guid)
 
@@ -187,10 +195,9 @@ def crossconnect_filter_peer_both(proto, testbed_instance, filter_guid, peer_dat
     crossconnect_filter_peer_init(proto, testbed_instance, iface_guid, peer_iface_data)
     crossconnect_filter_peer_compl(proto, testbed_instance, iface_guid, peer_iface_data)
 
-
-def connect_dep(testbed_instance, node_guid, app_guid):
-    node = testbed_instance._elements[node_guid]
-    app = testbed_instance._elements[app_guid]
+def connect_dep(testbed_instance, node_guid, app_guid, node=None, app=None):
+    node = node or testbed_instance._elements[node_guid]
+    app = app or testbed_instance._elements[app_guid]
     app.node = node
     
     if app.depends:
@@ -209,6 +216,24 @@ def connect_dep(testbed_instance, node_guid, app_guid):
     if app.rpmFusion:
         node.rpmFusion = True
 
+def connect_forwarder(testbed_instance, node_guid, fwd_guid):
+    node = testbed_instance._elements[node_guid]
+    fwd = testbed_instance._elements[fwd_guid]
+    node.multicast_forwarder = fwd
+    
+    if fwd.router:
+        connect_dep(testbed_instance, node_guid, None, app=fwd.router)
+
+    connect_dep(testbed_instance, node_guid, fwd_guid)
+
+def connect_router(testbed_instance, fwd_guid, router_guid):
+    fwd = testbed_instance._elements[fwd_guid]
+    router = testbed_instance._elements[router_guid]
+    fwd.router = router
+    
+    if fwd.node:
+        connect_dep(testbed_instance, None, router_guid, node=fwd.node)
+
 def connect_node_netpipe(testbed_instance, node_guid, netpipe_guid):
     node = testbed_instance._elements[node_guid]
     netpipe = testbed_instance._elements[netpipe_guid]
@@ -281,13 +306,14 @@ def create_tunfilter(testbed_instance, guid):
     testbed_instance.elements[guid] = element
 
 def create_classqueuefilter(testbed_instance, guid):
-    element = create_tunfilter(testbed_instance, guid)
-    element.module = "classqueue.py"
+    parameters = testbed_instance._get_parameters(guid)
+    element = testbed_instance._make_class_queue_filter(parameters)
+    testbed_instance.elements[guid] = element
 
 def create_tosqueuefilter(testbed_instance, guid):
-    element = create_tunfilter(testbed_instance, guid)
-    element.module = "tosqueue.py"
-
+    parameters = testbed_instance._get_parameters(guid)
+    element = testbed_instance._make_tos_queue_filter(parameters)
+    testbed_instance.elements[guid] = element
 
 def create_application(testbed_instance, guid):
     parameters = testbed_instance._get_parameters(guid)
@@ -325,6 +351,33 @@ def create_ns3_dependency(testbed_instance, guid):
     
     testbed_instance.elements[guid] = element
 
+def create_multicast_forwarder(testbed_instance, guid):
+    parameters = testbed_instance._get_parameters(guid)
+    element = testbed_instance._make_multicast_forwarder(parameters)
+    
+    # Just inject configuration stuff
+    element.home_path = "nepi-mcfwd-%s" % (guid,)
+    
+    testbed_instance.elements[guid] = element
+
+def create_multicast_announcer(testbed_instance, guid):
+    parameters = testbed_instance._get_parameters(guid)
+    element = testbed_instance._make_multicast_announcer(parameters)
+    
+    # Just inject configuration stuff
+    element.home_path = "nepi-mcann-%s" % (guid,)
+    
+    testbed_instance.elements[guid] = element
+
+def create_multicast_router(testbed_instance, guid):
+    parameters = testbed_instance._get_parameters(guid)
+    element = testbed_instance._make_multicast_router(parameters)
+    
+    # Just inject configuration stuff
+    element.home_path = "nepi-mcrt-%s" % (guid,)
+    
+    testbed_instance.elements[guid] = element
+
 def create_internet(testbed_instance, guid):
     parameters = testbed_instance._get_parameters(guid)
     element = testbed_instance._make_internet(parameters)
@@ -418,36 +471,19 @@ def preconfigure_tuniface(testbed_instance, guid):
     element.validate()
     
     # First-phase setup
-    if element.peer_proto:
-        if element.peer_iface and isinstance(element.peer_iface, testbed_instance._interfaces.TunIface):
-            # intra tun
-            listening = id(element) < id(element.peer_iface)
-        else:
-            # cross tun
-            if not element.tun_addr or not element.tun_port:
-                listening = True
-            elif not element.peer_addr or not element.peer_port:
-                listening = True
-            else:
-                # both have addresses...
-                # ...the one with the lesser address listens
-                listening = element.tun_addr < element.peer_addr
-        element.prepare( 
-            'tun-%s' % (guid,),
-             listening)
+    element.prepare('tun-%s' % (guid,))
 
 def postconfigure_tuniface(testbed_instance, guid):
     element = testbed_instance._elements[guid]
     
     # Second-phase setup
-    element.setup()
+    element.launch()
     
-def wait_tuniface(testbed_instance, guid):
+def prestart_tuniface(testbed_instance, guid):
     element = testbed_instance._elements[guid]
     
     # Second-phase setup
-    element.async_launch_wait()
-    
+    element.wait()
 
 def configure_node(testbed_instance, guid):
     node = testbed_instance._elements[guid]
@@ -502,6 +538,41 @@ def configure_dependency(testbed_instance, guid):
     # Install stuff
     dep.async_setup()
 
+def configure_announcer(testbed_instance, guid):
+    # Link ifaces
+    fwd = testbed_instance._elements[guid]
+    fwd.ifaces = [ dev
+        for node_guid in testbed_instance.get_connected(guid, "node", "apps")
+        for dev_guid in testbed_instance.get_connected(node_guid, "devs", "node")
+        for dev in ( testbed_instance._elements.get(dev_guid) ,)
+        if dev and isinstance(dev, testbed_instance._interfaces.TunIface)
+            and dev.multicast ]
+    
+    # Install stuff
+    configure_dependency(testbed_instance, guid)
+
+def configure_forwarder(testbed_instance, guid):
+    configure_announcer(testbed_instance, guid)
+    
+    # Link ifaces to forwarder
+    fwd = testbed_instance._elements[guid]
+    for iface in fwd.ifaces:
+        iface.multicast_forwarder = '/var/run/mcastfwd'
+
+def configure_router(testbed_instance, guid):
+    # Link ifaces
+    rt = testbed_instance._elements[guid]
+    rt.nonifaces = [ dev
+        for fwd_guid in testbed_instance.get_connected(guid, "fwd", "router")
+        for node_guid in testbed_instance.get_connected(fwd_guid, "node", "apps")
+        for dev_guid in testbed_instance.get_connected(node_guid, "devs", "node")
+        for dev in ( testbed_instance._elements.get(dev_guid) ,)
+        if dev and isinstance(dev, testbed_instance._interfaces.TunIface)
+            and not dev.multicast ]
+    
+    # Install stuff
+    configure_dependency(testbed_instance, guid)
+
 def configure_netpipe(testbed_instance, guid):
     netpipe = testbed_instance._elements[guid]
     
@@ -548,6 +619,18 @@ connector_types = dict({
                 "max": 1, 
                 "min": 1
             }),
+    "router": dict({
+                "help": "Connector to a routing daemon", 
+                "name": "router",
+                "max": 1, 
+                "min": 1
+            }),
+    "fwd": dict({
+                "help": "Forwarder this routing daemon communicates with", 
+                "name": "fwd",
+                "max": 1, 
+                "min": 1
+            }),
     "pipes": dict({
                 "help": "Connector to a NetPipe", 
                 "name": "pipes",
@@ -614,32 +697,20 @@ connections = [
     }),
     dict({
         "from": (TESTBED_ID, NODE, "apps"),
-        "to":   (TESTBED_ID, APPLICATION, "node"),
-        "init_code": connect_dep,
-        "can_cross": False
-    }),
-    dict({
-        "from": (TESTBED_ID, NODE, "deps"),
-        "to":   (TESTBED_ID, DEPENDENCY, "node"),
-        "init_code": connect_dep,
-        "can_cross": False
-    }),
-    dict({
-        "from": (TESTBED_ID, NODE, "deps"),
-        "to":   (TESTBED_ID, NEPIDEPENDENCY, "node"),
+        "to":   (TESTBED_ID, (APPLICATION, DEPENDENCY, NEPIDEPENDENCY, NS3DEPENDENCY, MULTICASTANNOUNCER), "node"),
         "init_code": connect_dep,
         "can_cross": False
     }),
     dict({
-        "from": (TESTBED_ID, NODE, "deps"),
-        "to":   (TESTBED_ID, NS3DEPENDENCY, "node"),
-        "init_code": connect_dep,
+        "from": (TESTBED_ID, NODE, "apps"),
+        "to":   (TESTBED_ID, MULTICASTFORWARDER, "node"),
+        "init_code": connect_forwarder,
         "can_cross": False
     }),
     dict({
-        "from": (TESTBED_ID, NODE, "pipes"),
-        "to":   (TESTBED_ID, NETPIPE, "node"),
-        "init_code": connect_node_netpipe,
+        "from": (TESTBED_ID, MULTICASTFORWARDER, "router"),
+        "to":   (TESTBED_ID, MULTICASTROUTER, "fwd"),
+        "init_code": connect_router,
         "can_cross": False
     }),
     dict({
@@ -982,6 +1053,15 @@ attributes = dict({
                 "value": False,
                 "validation_function": validation.is_bool
             }),
+    "multicast":  dict({
+                "name": "multicast", 
+                "help": "Enable multicast forwarding on this device. "
+                        "Note that you still need a multicast routing daemon "
+                        "in the node.",
+                "type": Attribute.BOOL,
+                "value": False,
+                "validation_function": validation.is_bool
+            }),
     "pointopoint":  dict({
                 "name": "pointopoint", 
                 "help": "If the interface is a P2P link, the remote endpoint's IP "
@@ -990,6 +1070,14 @@ attributes = dict({
                 "flags": Attribute.ExecReadOnly | Attribute.ExecImmutable,
                 "validation_function": validation.is_string
             }),
+    "bwlimit":  dict({
+                "name": "bwlimit", 
+                "help": "Emulated transmission speed (in kbytes per second)",
+                "type": Attribute.INTEGER,
+                "range" : (1,10*2**20),
+                "flags": Attribute.ExecReadOnly | Attribute.ExecImmutable,
+                "validation_function": validation.is_integer
+            }),
     "txqueuelen":  dict({
                 "name": "txqueuelen", 
                 "help": "Transmission queue length (in packets)",
@@ -1162,6 +1250,15 @@ attributes = dict({
                 "flags": Attribute.ExecReadOnly | Attribute.ExecImmutable,
                 "validation_function": validation.is_string
             }),
+    "routing_algorithm": dict({      
+            "name": "algorithm",
+            "help": "Routing algorithm.",
+            "value": "dvmrp",
+            "type": Attribute.ENUM, 
+            "allowed": ["dvmrp"],
+            "flags": Attribute.ExecReadOnly | Attribute.ExecImmutable,
+            "validation_function": validation.is_enum,
+        }),
     })
 
 traces = dict({
@@ -1195,17 +1292,40 @@ traces = dict({
                 "name": "output",
                 "help": "Extra output trace for applications. When activated this trace can be referenced with wildcard a reference from an Application command line. Ex: command: 'tcpdump -w {#[elemet-label].trace[trace-id].[name|path]#}' ",
               }),
+    "dropped_stats": dict({
+                "name": "dropped_stats",
+                "help": "Information on dropped packets on a filer or queue associated to a network interface",
+            }),
     })
 
-create_order = [ INTERNET, NODE, NODEIFACE, TUNFILTER, TAPIFACE, TUNIFACE, NETPIPE, NEPIDEPENDENCY, NS3DEPENDENCY, DEPENDENCY, APPLICATION ]
+create_order = [ 
+    INTERNET, NODE, NODEIFACE, CLASSQUEUEFILTER, TOSQUEUEFILTER, 
+    MULTICASTANNOUNCER, MULTICASTFORWARDER, MULTICASTROUTER, 
+    TUNFILTER, TAPIFACE, TUNIFACE, NETPIPE, 
+    NEPIDEPENDENCY, NS3DEPENDENCY, DEPENDENCY, APPLICATION ]
 
-configure_order = [ INTERNET, Parallel(NODE), NODEIFACE, Parallel(TAPIFACE), Parallel(TUNIFACE), NETPIPE, Parallel(NEPIDEPENDENCY), Parallel(NS3DEPENDENCY), Parallel(DEPENDENCY), Parallel(APPLICATION) ]
+configure_order = [ 
+    INTERNET, Parallel(NODE), 
+    NODEIFACE, 
+    Parallel(MULTICASTANNOUNCER), Parallel(MULTICASTFORWARDER), Parallel(MULTICASTROUTER), 
+    Parallel(TAPIFACE), Parallel(TUNIFACE), NETPIPE, 
+    Parallel(NEPIDEPENDENCY), Parallel(NS3DEPENDENCY), Parallel(DEPENDENCY), Parallel(APPLICATION) ]
 
 # Start (and prestart) node after ifaces, because the node needs the ifaces in order to set up routes
-start_order = [ INTERNET, NODEIFACE, Parallel(TAPIFACE), Parallel(TUNIFACE), Parallel(NODE), NETPIPE, Parallel(NEPIDEPENDENCY), Parallel(NS3DEPENDENCY), Parallel(DEPENDENCY), Parallel(APPLICATION) ]
+start_order = [ INTERNET, 
+    NODEIFACE, 
+    Parallel(TAPIFACE), Parallel(TUNIFACE), 
+    Parallel(NODE), NETPIPE, 
+    Parallel(MULTICASTANNOUNCER), Parallel(MULTICASTFORWARDER), Parallel(MULTICASTROUTER), 
+    Parallel(NEPIDEPENDENCY), Parallel(NS3DEPENDENCY), Parallel(DEPENDENCY), Parallel(APPLICATION) ]
 
 # cleanup order
-shutdown_order = [ Parallel(APPLICATION), Parallel(TAPIFACE), Parallel(TUNIFACE), Parallel(NETPIPE), Parallel(NEPIDEPENDENCY), Parallel(NS3DEPENDENCY), Parallel(DEPENDENCY), NODEIFACE, Parallel(NODE) ]
+shutdown_order = [ 
+    Parallel(APPLICATION), 
+    Parallel(MULTICASTROUTER), Parallel(MULTICASTFORWARDER), Parallel(MULTICASTANNOUNCER), 
+    Parallel(TAPIFACE), Parallel(TUNIFACE), Parallel(NETPIPE), 
+    Parallel(NEPIDEPENDENCY), Parallel(NS3DEPENDENCY), Parallel(DEPENDENCY), 
+    NODEIFACE, Parallel(NODE) ]
 
 factories_info = dict({
     NODE: dict({
@@ -1246,9 +1366,9 @@ factories_info = dict({
             "create_function": create_tuniface,
             "preconfigure_function": preconfigure_tuniface,
             "configure_function": postconfigure_tuniface,
-            "prestart_function": wait_tuniface,
+            "prestart_function": prestart_tuniface,
             "box_attributes": [
-                "up", "if_name", "mtu", "snat", "pointopoint",
+                "up", "if_name", "mtu", "snat", "pointopoint", "multicast", "bwlimit",
                 "txqueuelen",
                 "tun_proto", "tun_addr", "tun_port", "tun_key", "tun_cipher",
             ],
@@ -1262,9 +1382,9 @@ factories_info = dict({
             "create_function": create_tapiface,
             "preconfigure_function": preconfigure_tuniface,
             "configure_function": postconfigure_tuniface,
-            "prestart_function": wait_tuniface,
+            "prestart_function": prestart_tuniface,
             "box_attributes": [
-                "up", "if_name", "mtu", "snat", "pointopoint",
+                "up", "if_name", "mtu", "snat", "pointopoint", "multicast", "bwlimit",
                 "txqueuelen",
                 "tun_proto", "tun_addr", "tun_port", "tun_key", "tun_cipher",
             ],
@@ -1361,6 +1481,7 @@ factories_info = dict({
                 "tun_proto", "tun_addr", "tun_port", "tun_key", "tun_cipher",
             ],
             "connector_types": ["->fd","udp","tcp"],
+            "traces": ["dropped_stats"],
         }),
     TOSQUEUEFILTER : dict({
             "help": "TUN classfull queue that classifies according to the TOS (RFC 791) IP field.\n\n"
@@ -1418,6 +1539,51 @@ factories_info = dict({
             "connector_types": ["node"],
             "traces": ["buildlog"],
         }),
+    MULTICASTFORWARDER: dict({
+            "help": "This application installs a userspace packet forwarder "
+                    "that, when connected to a node, filters all packets "
+                    "flowing through multicast-capable virtual interfaces "
+                    "and applies custom-specified routing policies.",
+            "category": FC.CATEGORY_APPLICATIONS,
+            "create_function": create_multicast_forwarder,
+            "preconfigure_function": configure_forwarder,
+            "start_function": start_application,
+            "status_function": status_application,
+            "stop_function": stop_application,
+            "box_attributes": [ ],
+            "connector_types": ["node","router"],
+            "traces": ["buildlog","stderr"],
+        }),
+    MULTICASTANNOUNCER: dict({
+            "help": "This application installs a userspace daemon that "
+                    "monitors multicast membership and announces it on all "
+                    "multicast-capable interfaces.\n"
+                    "This does not usually happen automatically on PlanetLab slivers.",
+            "category": FC.CATEGORY_APPLICATIONS,
+            "create_function": create_multicast_announcer,
+            "preconfigure_function": configure_announcer,
+            "start_function": start_application,
+            "status_function": status_application,
+            "stop_function": stop_application,
+            "box_attributes": [ ],
+            "connector_types": ["node"],
+            "traces": ["buildlog","stderr"],
+        }),
+    MULTICASTROUTER: dict({
+            "help": "This application installs a userspace daemon that "
+                    "monitors multicast membership and announces it on all "
+                    "multicast-capable interfaces.\n"
+                    "This does not usually happen automatically on PlanetLab slivers.",
+            "category": FC.CATEGORY_APPLICATIONS,
+            "create_function": create_multicast_router,
+            "preconfigure_function": configure_router,
+            "start_function": start_application,
+            "status_function": status_application,
+            "stop_function": stop_application,
+            "box_attributes": ["routing_algorithm"],
+            "connector_types": ["fwd"],
+            "traces": ["buildlog","stdout","stderr"],
+        }),
     INTERNET: dict({
             "help": "Internet routing",
             "category": FC.CATEGORY_CHANNELS,