Added routes to OMF nodes
[nepi.git] / src / nepi / testbeds / netns / metadata.py
index 8c04d99..36e914a 100644 (file)
@@ -1,4 +1,3 @@
-#!/usr/bin/env python
 # -*- coding: utf-8 -*-
 
 from constants import TESTBED_ID, TESTBED_VERSION
@@ -52,7 +51,10 @@ def connect_fd(testbed_instance, tap_guid, cross_data):
     passfd.sendfd(sock, tap.fd, '0')
     # TODO: after succesful transfer, the tap device should close the fd
 
-def connect_tunchannel_tap(testbed_instance, chan_guid, tap_guid):
+def connect_tunchannel_tun(testbed_instance, chan_guid, tap_guid):
+    connect_tunchannel_tap(testbed_instance, chan_guid, tap_guid, ethernet_mode=False)
+
+def connect_tunchannel_tap(testbed_instance, chan_guid, tap_guid, ethernet_mode=True):
     tap = testbed_instance._elements[tap_guid]
     chan = testbed_instance._elements[chan_guid]
 
@@ -63,7 +65,7 @@ def connect_tunchannel_tap(testbed_instance, chan_guid, tap_guid):
     chan.tun_socket = os.fdopen(tap.fd)
     
     # Set the channel to ethernet mode (it's a tap)
-    chan.ethernet_mode = True
+    chan.ethernet_mode = ethernet_mode
     
     # Check to see if the device uses PI headers
     # It's normally so
@@ -75,7 +77,7 @@ def connect_tunchannel_tap(testbed_instance, chan_guid, tap_guid):
         IFF_NO_PI = 0x00001000
         struct_ifreq = "x"*16+"H"+"x"*22
         flags = struct.unpack(struct_ifreq,
-            fcntl.ioctl(tap.fd, TUNGETIFF, struct.pack(struct_ifreq,0)) )
+            fcntl.ioctl(tap.fd, TUNGETIFF, struct.pack(struct_ifreq,0)) )[0]
         with_pi = (0 == (flags & IFF_NO_PI))
     except:
         # maybe the kernel doesn't support the IOCTL,
@@ -243,7 +245,7 @@ def configure_node(testbed_instance, guid):
         return
     routes = testbed_instance._add_route[guid]
     for route in routes:
-        (destination, netprefix, nexthop, metric) = route
+        (destination, netprefix, nexthop, metric, device) = route
         element.add_route(prefix = destination, prefix_len = netprefix,
             nexthop = nexthop, metric = metric)
 
@@ -364,7 +366,7 @@ connections = [
     dict({
         "from": (TESTBED_ID, TUNCHANNEL, "->fd" ),
         "to":   (TESTBED_ID, TUNIFACE, "fd->" ),
-        "init_code": connect_tunchannel_tap,
+        "init_code": connect_tunchannel_tun,
         "can_cross": False
     }),
     dict({
@@ -403,7 +405,8 @@ attributes = dict({
                 "name": "up",
                 "help": "Link up",
                 "type": Attribute.BOOL,
-                "value": False,
+                "value": True,
+                "flags": Attribute.NoDefaultValue, 
                 "validation_function": validation.is_bool
             }),
     "device_name": dict({