2 # -*- coding: utf-8 -*-
6 from constants import TESTBED_ID, TESTBED_VERSION
7 from nepi.core import metadata
8 from nepi.core.metadata import Parallel
9 from nepi.core.attributes import Attribute
10 from nepi.util import tags, validation
11 from nepi.util.constants import ApplicationStatus as AS, \
12 FactoryCategories as FC, \
13 ATTR_NEPI_TESTBED_ENVIRONMENT_SETUP, \
14 DeploymentConfiguration as DC
22 NODEIFACE = "NodeInterface"
23 TUNIFACE = "TunInterface"
24 TAPIFACE = "TapInterface"
25 APPLICATION = "Application"
26 DEPENDENCY = "Dependency"
27 NEPIDEPENDENCY = "NepiDependency"
28 NS3DEPENDENCY = "NS3Dependency"
31 TUNFILTER = "TunFilter"
33 PL_TESTBED_ID = "planetlab"
36 ### Custom validation functions ###
37 def is_addrlist(attribute, value):
38 if not validation.is_string(attribute, value):
45 components = value.split(',')
47 for component in components:
49 addr, mask = component.split('/',1)
51 addr, mask = component, '32'
53 if mask is not None and not (mask and mask.isdigit()):
54 # No empty or nonnumeric masks
57 if not validation.is_ip4_address(attribute, addr):
58 # Address part must be ipv4
63 def is_portlist(attribute, value):
64 if not validation.is_string(attribute, value):
71 components = value.split(',')
73 for component in components:
75 pfrom, pto = component.split('-',1)
77 pfrom = pto = component
79 if not pfrom or not pto or not pfrom.isdigit() or not pto.isdigit():
80 # No empty or nonnumeric ports
86 ### Connection functions ####
88 def connect_node_iface_node(testbed_instance, node_guid, iface_guid):
89 node = testbed_instance._elements[node_guid]
90 iface = testbed_instance._elements[iface_guid]
93 def connect_node_iface_inet(testbed_instance, iface_guid, inet_guid):
94 iface = testbed_instance._elements[iface_guid]
95 iface.has_internet = True
97 def connect_tun_iface_node(testbed_instance, node_guid, iface_guid):
98 node = testbed_instance._elements[node_guid]
99 iface = testbed_instance._elements[iface_guid]
101 node.required_vsys.update(('fd_tuntap', 'vif_up', 'vif_down'))
102 node.required_packages.update(('python', 'python-crypto', 'python-setuptools', 'gcc'))
104 def connect_tun_iface_peer(proto, testbed_instance, iface_guid, peer_iface_guid):
105 iface = testbed_instance._elements[iface_guid]
106 peer_iface = testbed_instance._elements[peer_iface_guid]
107 iface.peer_iface = peer_iface
108 peer_iface.peer_iface = iface
111 peer_iface.peer_proto = \
112 peer_iface.tun_proto = proto
113 iface.tun_key = peer_iface.tun_key
115 def connect_tun_iface_filter(testbed_instance, iface_guid, filter_guid):
116 iface = testbed_instance._elements[iface_guid]
117 filt = testbed_instance._elements[filter_guid]
118 iface.filter_module = filt
119 filt.iface_guid = iface_guid
120 filt.iface = weakref.ref(iface)
122 connect_tun_iface_peer(filt.peer_proto, testbed_instance, filt.iface_guid, filt.peer_guid)
124 def connect_filter_peer(proto, testbed_instance, filter_guid, peer_guid):
125 peer = testbed_instance._elements[peer_guid]
126 filt = testbed_instance._elements[filter_guid]
127 filt.peer_proto = proto
128 filt.peer_guid = peer_guid
130 connect_tun_iface_peer(filt.peer_proto, testbed_instance, filt.iface_guid, filt.peer_guid)
132 def connect_filter_filter(proto, testbed_instance, filter_guid, peer_guid):
133 peer = testbed_instance._elements[peer_guid]
134 filt = testbed_instance._elements[filter_guid]
135 filt.peer_proto = proto
136 peer.peer_proto = proto
138 peer.peer_guid = filt.iface_guid
140 filt.peer_guid = peer.iface_guid
141 if filt.iface_guid and filt.peer_guid:
142 connect_tun_iface_peer(filt.peer_proto, testbed_instance, filt.iface_guid, filt.peer_guid)
144 def crossconnect_tun_iface_peer_init(proto, testbed_instance, iface_guid, peer_iface_data):
145 iface = testbed_instance._elements[iface_guid]
146 iface.peer_iface = None
147 iface.peer_addr = peer_iface_data.get("tun_addr")
148 iface.peer_proto = peer_iface_data.get("tun_proto") or proto
149 iface.peer_port = peer_iface_data.get("tun_port")
150 iface.peer_cipher = peer_iface_data.get("tun_cipher")
151 iface.tun_key = min(iface.tun_key, peer_iface_data.get("tun_key"))
152 iface.tun_proto = proto
154 preconfigure_tuniface(testbed_instance, iface_guid)
156 def crossconnect_tun_iface_peer_compl(proto, testbed_instance, iface_guid, peer_iface_data):
157 # refresh (refreshable) attributes for second-phase
158 iface = testbed_instance._elements[iface_guid]
159 iface.peer_addr = peer_iface_data.get("tun_addr")
160 iface.peer_proto = peer_iface_data.get("tun_proto") or proto
161 iface.peer_port = peer_iface_data.get("tun_port")
162 iface.peer_cipher = peer_iface_data.get("tun_cipher")
164 postconfigure_tuniface(testbed_instance, iface_guid)
166 def crossconnect_tun_iface_peer_both(proto, testbed_instance, iface_guid, peer_iface_data):
167 crossconnect_tun_iface_peer_init(proto, testbed_instance, iface_guid, peer_iface_data)
168 crossconnect_tun_iface_peer_compl(proto, testbed_instance, iface_guid, peer_iface_data)
170 def crossconnect_filter_peer_init(proto, testbed_instance, filter_guid, peer_data):
171 filt = testbed_instance._elements[filter_guid]
172 filt.peer_proto = proto
173 crossconnect_tun_iface_peer_init(filt.peer_proto, testbed_instance, filt.iface_guid, peer_data)
175 def crossconnect_filter_peer_compl(proto, testbed_instance, filter_guid, peer_data):
176 filt = testbed_instance._elements[filter_guid]
177 filt.peer_proto = proto
178 crossconnect_tun_iface_peer_compl(filt.peer_proto, testbed_instance, filt.iface_guid, peer_data)
180 def crossconnect_filter_peer_both(proto, testbed_instance, filter_guid, peer_data):
181 crossconnect_filter_peer_init(proto, testbed_instance, iface_guid, peer_iface_data)
182 crossconnect_filter_peer_compl(proto, testbed_instance, iface_guid, peer_iface_data)
185 def connect_dep(testbed_instance, node_guid, app_guid):
186 node = testbed_instance._elements[node_guid]
187 app = testbed_instance._elements[app_guid]
191 node.required_packages.update(set(
192 app.depends.split() ))
195 if app.home_path and app.home_path not in node.pythonpath:
196 node.pythonpath.append(app.home_path)
199 for envkey, envval in app.env.iteritems():
200 envval = app._replace_paths(envval)
201 node.env[envkey].append(envval)
204 node.rpmFusion = True
206 def connect_node_netpipe(testbed_instance, node_guid, netpipe_guid):
207 node = testbed_instance._elements[node_guid]
208 netpipe = testbed_instance._elements[netpipe_guid]
210 node.required_vsys.add('ipfw-be')
211 node.required_packages.add('ipfwslice')
214 ### Creation functions ###
216 def create_node(testbed_instance, guid):
217 parameters = testbed_instance._get_parameters(guid)
219 # create element with basic attributes
220 element = testbed_instance._make_node(parameters)
222 # add constraint on number of (real) interfaces
223 # by counting connected devices
224 dev_guids = testbed_instance.get_connected(guid, "devs", "node")
225 num_open_ifaces = sum( # count True values
226 NODEIFACE == testbed_instance._get_factory_id(guid)
227 for guid in dev_guids )
228 element.min_num_external_ifaces = num_open_ifaces
230 # require vroute vsys if we have routes to set up
231 routes = testbed_instance._add_route.get(guid)
233 vsys = element.routing_method(routes,
234 testbed_instance.vsys_vnet)
235 element.required_vsys.add(vsys)
237 testbed_instance.elements[guid] = element
239 def create_nodeiface(testbed_instance, guid):
240 parameters = testbed_instance._get_parameters(guid)
241 element = testbed_instance._make_node_iface(parameters)
242 testbed_instance.elements[guid] = element
244 def create_tuniface(testbed_instance, guid):
245 parameters = testbed_instance._get_parameters(guid)
246 element = testbed_instance._make_tun_iface(parameters)
248 # Set custom addresses, if there are any already
249 # Setting this early helps set up P2P links
250 if guid in testbed_instance._add_address and not (element.address or element.netmask or element.netprefix):
251 addresses = testbed_instance._add_address[guid]
252 for address in addresses:
253 (address, netprefix, broadcast) = address
254 element.add_address(address, netprefix, broadcast)
256 testbed_instance.elements[guid] = element
258 def create_tapiface(testbed_instance, guid):
259 parameters = testbed_instance._get_parameters(guid)
260 element = testbed_instance._make_tap_iface(parameters)
262 # Set custom addresses, if there are any already
263 # Setting this early helps set up P2P links
264 if guid in testbed_instance._add_address and not (element.address or element.netmask or element.netprefix):
265 addresses = testbed_instance._add_address[guid]
266 for address in addresses:
267 (address, netprefix, broadcast) = address
268 element.add_address(address, netprefix, broadcast)
270 testbed_instance.elements[guid] = element
272 def create_tunfilter(testbed_instance, guid):
273 parameters = testbed_instance._get_parameters(guid)
274 element = testbed_instance._make_tun_filter(parameters)
275 testbed_instance.elements[guid] = element
278 def create_application(testbed_instance, guid):
279 parameters = testbed_instance._get_parameters(guid)
280 element = testbed_instance._make_application(parameters)
282 # Just inject configuration stuff
283 element.home_path = "nepi-app-%s" % (guid,)
285 testbed_instance.elements[guid] = element
287 def create_dependency(testbed_instance, guid):
288 parameters = testbed_instance._get_parameters(guid)
289 element = testbed_instance._make_dependency(parameters)
291 # Just inject configuration stuff
292 element.home_path = "nepi-dep-%s" % (guid,)
294 testbed_instance.elements[guid] = element
296 def create_nepi_dependency(testbed_instance, guid):
297 parameters = testbed_instance._get_parameters(guid)
298 element = testbed_instance._make_nepi_dependency(parameters)
300 # Just inject configuration stuff
301 element.home_path = "nepi-nepi-%s" % (guid,)
303 testbed_instance.elements[guid] = element
305 def create_ns3_dependency(testbed_instance, guid):
306 parameters = testbed_instance._get_parameters(guid)
307 element = testbed_instance._make_ns3_dependency(parameters)
309 # Just inject configuration stuff
310 element.home_path = "nepi-ns3-%s" % (guid,)
312 testbed_instance.elements[guid] = element
314 def create_internet(testbed_instance, guid):
315 parameters = testbed_instance._get_parameters(guid)
316 element = testbed_instance._make_internet(parameters)
317 testbed_instance.elements[guid] = element
319 def create_netpipe(testbed_instance, guid):
320 parameters = testbed_instance._get_parameters(guid)
321 element = testbed_instance._make_netpipe(parameters)
322 testbed_instance.elements[guid] = element
324 ### Start/Stop functions ###
326 def start_application(testbed_instance, guid):
327 parameters = testbed_instance._get_parameters(guid)
328 traces = testbed_instance._get_traces(guid)
329 app = testbed_instance.elements[guid]
331 app.stdout = "stdout" in traces
332 app.stderr = "stderr" in traces
333 app.buildlog = "buildlog" in traces
337 def stop_application(testbed_instance, guid):
338 app = testbed_instance.elements[guid]
341 ### Status functions ###
343 def status_application(testbed_instance, guid):
344 if guid not in testbed_instance.elements.keys():
345 return AS.STATUS_NOT_STARTED
347 app = testbed_instance.elements[guid]
350 ### Configure functions ###
352 def configure_nodeiface(testbed_instance, guid):
353 element = testbed_instance._elements[guid]
355 # Cannot explicitly configure addresses
356 if guid in testbed_instance._add_address:
357 raise ValueError, "Cannot explicitly set address of public PlanetLab interface"
360 node_guid = testbed_instance.get_connected(guid, "node", "devs")[0]
361 dev_guids = testbed_instance.get_connected(node_guid, "node", "devs")
362 siblings = [ self._element[dev_guid]
363 for dev_guid in dev_guids
364 if dev_guid != guid ]
366 # Fetch address from PLC api
367 element.pick_iface(siblings)
369 # Do some validations
372 def preconfigure_tuniface(testbed_instance, guid):
373 element = testbed_instance._elements[guid]
375 # Set custom addresses if any, and if not set already
376 if guid in testbed_instance._add_address and not (element.address or element.netmask or element.netprefix):
377 addresses = testbed_instance._add_address[guid]
378 for address in addresses:
379 (address, netprefix, broadcast) = address
380 element.add_address(address, netprefix, broadcast)
382 # Link to external interface, if any
383 for iface in testbed_instance._elements.itervalues():
384 if isinstance(iface, testbed_instance._interfaces.NodeIface) and iface.node is element.node and iface.has_internet:
385 element.external_iface = iface
388 # Set standard TUN attributes
389 if (not element.tun_addr or not element.tun_port) and element.external_iface:
390 element.tun_addr = element.external_iface.address
391 element.tun_port = testbed_instance.tapPortBase + int(guid)
394 traces = testbed_instance._get_traces(guid)
395 for capmode in ('pcap', 'packets'):
396 if capmode in traces:
397 element.capture = capmode
400 element.capture = False
402 # Do some validations
406 if element.peer_proto:
407 if element.peer_iface and isinstance(element.peer_iface, testbed_instance._interfaces.TunIface):
409 listening = id(element) < id(element.peer_iface)
412 if not element.tun_addr or not element.tun_port:
414 elif not element.peer_addr or not element.peer_port:
417 # both have addresses...
418 # ...the one with the lesser address listens
419 listening = element.tun_addr < element.peer_addr
424 def postconfigure_tuniface(testbed_instance, guid):
425 element = testbed_instance._elements[guid]
430 def wait_tuniface(testbed_instance, guid):
431 element = testbed_instance._elements[guid]
434 element.async_launch_wait()
437 def configure_node(testbed_instance, guid):
438 node = testbed_instance._elements[guid]
440 # Just inject configuration stuff
441 node.home_path = "nepi-node-%s" % (guid,)
442 node.ident_path = testbed_instance.sliceSSHKey
443 node.slicename = testbed_instance.slicename
445 # Do some validations
448 # this will be done in parallel in all nodes
449 # this call only spawns the process
450 node.install_dependencies()
452 def configure_node_routes(testbed_instance, guid):
453 node = testbed_instance._elements[guid]
454 routes = testbed_instance._add_route.get(guid)
458 for dev_guid in testbed_instance.get_connected(guid, "devs", "node")
459 for dev in ( testbed_instance._elements.get(dev_guid) ,)
460 if dev and isinstance(dev, testbed_instance._interfaces.TunIface) ]
462 vsys = testbed_instance.vsys_vnet
464 node.configure_routes(routes, devs, vsys)
466 def configure_application(testbed_instance, guid):
467 app = testbed_instance._elements[guid]
469 # Do some validations
472 # Wait for dependencies
473 app.node.wait_dependencies()
478 def configure_dependency(testbed_instance, guid):
479 dep = testbed_instance._elements[guid]
481 # Do some validations
484 # Wait for dependencies
485 dep.node.wait_dependencies()
490 def configure_netpipe(testbed_instance, guid):
491 netpipe = testbed_instance._elements[guid]
493 # Do some validations
496 # Wait for dependencies
497 netpipe.node.wait_dependencies()
502 ### Factory information ###
504 connector_types = dict({
506 "help": "Connector from node to applications",
512 "help": "Connector from node to network interfaces",
518 "help": "Connector from node to application dependencies "
519 "(packages and applications that need to be installed)",
525 "help": "Connector from network interfaces to the internet",
531 "help": "Connector to a Node",
537 "help": "Connector to a NetPipe",
544 "help": "ip-ip tunneling over TCP link",
550 "help": "ip-ip tunneling over UDP datagrams",
556 "help": "IP or Ethernet tunneling using the GRE protocol",
562 "help": "TUN device file descriptor provider",
568 "help": "TUN device file descriptor slot",
577 "from": (TESTBED_ID, NODE, "devs"),
578 "to": (TESTBED_ID, NODEIFACE, "node"),
579 "init_code": connect_node_iface_node,
583 "from": (TESTBED_ID, NODE, "devs"),
584 "to": (TESTBED_ID, TUNIFACE, "node"),
585 "init_code": connect_tun_iface_node,
589 "from": (TESTBED_ID, NODE, "devs"),
590 "to": (TESTBED_ID, TAPIFACE, "node"),
591 "init_code": connect_tun_iface_node,
595 "from": (TESTBED_ID, NODEIFACE, "inet"),
596 "to": (TESTBED_ID, INTERNET, "devs"),
597 "init_code": connect_node_iface_inet,
601 "from": (TESTBED_ID, NODE, "apps"),
602 "to": (TESTBED_ID, APPLICATION, "node"),
603 "init_code": connect_dep,
607 "from": (TESTBED_ID, NODE, "deps"),
608 "to": (TESTBED_ID, DEPENDENCY, "node"),
609 "init_code": connect_dep,
613 "from": (TESTBED_ID, NODE, "deps"),
614 "to": (TESTBED_ID, NEPIDEPENDENCY, "node"),
615 "init_code": connect_dep,
619 "from": (TESTBED_ID, NODE, "deps"),
620 "to": (TESTBED_ID, NS3DEPENDENCY, "node"),
621 "init_code": connect_dep,
625 "from": (TESTBED_ID, NODE, "pipes"),
626 "to": (TESTBED_ID, NETPIPE, "node"),
627 "init_code": connect_node_netpipe,
631 "from": (TESTBED_ID, TUNIFACE, "tcp"),
632 "to": (TESTBED_ID, TUNIFACE, "tcp"),
633 "init_code": functools.partial(connect_tun_iface_peer,"tcp"),
637 "from": (TESTBED_ID, TUNIFACE, "udp"),
638 "to": (TESTBED_ID, TUNIFACE, "udp"),
639 "init_code": functools.partial(connect_tun_iface_peer,"udp"),
643 "from": (TESTBED_ID, TUNIFACE, "gre"),
644 "to": (TESTBED_ID, TUNIFACE, "gre"),
645 "init_code": functools.partial(connect_tun_iface_peer,"gre"),
649 "from": (TESTBED_ID, TUNIFACE, "fd->"),
650 "to": (TESTBED_ID, TUNFILTER, "->fd"),
651 "init_code": connect_tun_iface_filter,
655 "from": (TESTBED_ID, TUNFILTER, "tcp"),
656 "to": (TESTBED_ID, TUNIFACE, "tcp"),
657 "init_code": functools.partial(connect_filter_peer,"tcp"),
661 "from": (TESTBED_ID, TUNFILTER, "udp"),
662 "to": (TESTBED_ID, TUNIFACE, "udp"),
663 "init_code": functools.partial(connect_filter_peer,"udp"),
667 "from": (TESTBED_ID, TAPIFACE, "tcp"),
668 "to": (TESTBED_ID, TAPIFACE, "tcp"),
669 "init_code": functools.partial(connect_tun_iface_peer,"tcp"),
673 "from": (TESTBED_ID, TAPIFACE, "udp"),
674 "to": (TESTBED_ID, TAPIFACE, "udp"),
675 "init_code": functools.partial(connect_tun_iface_peer,"udp"),
679 "from": (TESTBED_ID, TAPIFACE, "gre"),
680 "to": (TESTBED_ID, TAPIFACE, "gre"),
681 "init_code": functools.partial(connect_tun_iface_peer,"gre"),
685 "from": (TESTBED_ID, TAPIFACE, "fd->"),
686 "to": (TESTBED_ID, TUNFILTER, "->fd"),
687 "init_code": connect_tun_iface_filter,
691 "from": (TESTBED_ID, TUNFILTER, "tcp"),
692 "to": (TESTBED_ID, TAPIFACE, "tcp"),
693 "init_code": functools.partial(connect_filter_peer,"tcp"),
697 "from": (TESTBED_ID, TUNFILTER, "udp"),
698 "to": (TESTBED_ID, TAPIFACE, "udp"),
699 "init_code": functools.partial(connect_filter_peer,"udp"),
703 "from": (TESTBED_ID, TUNFILTER, "tcp"),
704 "to": (TESTBED_ID, TUNFILTER, "tcp"),
705 "init_code": functools.partial(connect_filter_filter,"tcp"),
709 "from": (TESTBED_ID, TUNFILTER, "udp"),
710 "to": (TESTBED_ID, TUNFILTER, "udp"),
711 "init_code": functools.partial(connect_filter_filter,"udp"),
715 "from": (TESTBED_ID, TUNIFACE, "tcp"),
716 "to": (None, None, "tcp"),
717 "init_code": functools.partial(crossconnect_tun_iface_peer_init,"tcp"),
718 "compl_code": functools.partial(crossconnect_tun_iface_peer_compl,"tcp"),
722 "from": (TESTBED_ID, TUNIFACE, "udp"),
723 "to": (None, None, "udp"),
724 "init_code": functools.partial(crossconnect_tun_iface_peer_init,"udp"),
725 "compl_code": functools.partial(crossconnect_tun_iface_peer_compl,"udp"),
729 "from": (TESTBED_ID, TUNIFACE, "fd->"),
730 "to": (None, None, "->fd"),
731 "compl_code": functools.partial(crossconnect_tun_iface_peer_both,"fd"),
735 "from": (TESTBED_ID, TUNIFACE, "gre"),
736 "to": (None, None, "gre"),
737 "compl_code": functools.partial(crossconnect_tun_iface_peer_both,"gre"),
741 "from": (TESTBED_ID, TAPIFACE, "tcp"),
742 "to": (None, None, "tcp"),
743 "init_code": functools.partial(crossconnect_tun_iface_peer_init,"tcp"),
744 "compl_code": functools.partial(crossconnect_tun_iface_peer_compl,"tcp"),
748 "from": (TESTBED_ID, TAPIFACE, "udp"),
749 "to": (None, None, "udp"),
750 "init_code": functools.partial(crossconnect_tun_iface_peer_init,"udp"),
751 "compl_code": functools.partial(crossconnect_tun_iface_peer_compl,"udp"),
755 "from": (TESTBED_ID, TAPIFACE, "fd->"),
756 "to": (None, None, "->fd"),
757 "compl_code": functools.partial(crossconnect_tun_iface_peer_both,"fd"),
760 # EGRE is an extension of PlanetLab, so we can't connect externally
761 # if the other testbed isn't another PlanetLab
763 "from": (TESTBED_ID, TAPIFACE, "gre"),
764 "to": (TESTBED_ID, None, "gre"),
765 "compl_code": functools.partial(crossconnect_tun_iface_peer_both,"gre"),
769 "from": (TESTBED_ID, TUNFILTER, "tcp"),
770 "to": (None, None, "tcp"),
771 "init_code": functools.partial(crossconnect_filter_peer_init,"tcp"),
772 "compl_code": functools.partial(crossconnect_filter_peer_compl,"tcp"),
776 "from": (TESTBED_ID, TUNFILTER, "udp"),
777 "to": (None, None, "udp"),
778 "init_code": functools.partial(crossconnect_filter_peer_init,"udp"),
779 "compl_code": functools.partial(crossconnect_filter_peer_compl,"udp"),
785 "forward_X11": dict({
786 "name": "forward_X11",
787 "help": "Forward x11 from main namespace to the node",
788 "type": Attribute.BOOL,
790 "flags": Attribute.ExecReadOnly | Attribute.ExecImmutable,
791 "validation_function": validation.is_bool,
795 "help": "Constrain hostname during resource discovery. May use wildcards.",
796 "type": Attribute.STRING,
797 "flags": Attribute.ExecReadOnly | Attribute.ExecImmutable,
798 "validation_function": validation.is_string,
802 "help": "Constrain location (city) during resource discovery. May use wildcards.",
803 "type": Attribute.STRING,
804 "flags": Attribute.ExecReadOnly | Attribute.ExecImmutable,
805 "validation_function": validation.is_string,
809 "help": "Constrain location (country) during resource discovery. May use wildcards.",
810 "type": Attribute.STRING,
811 "flags": Attribute.ExecReadOnly | Attribute.ExecImmutable,
812 "validation_function": validation.is_string,
816 "help": "Constrain location (region) during resource discovery. May use wildcards.",
817 "type": Attribute.STRING,
818 "flags": Attribute.ExecReadOnly | Attribute.ExecImmutable,
819 "validation_function": validation.is_string,
821 "architecture": dict({
822 "name": "architecture",
823 "help": "Constrain architexture during resource discovery.",
824 "type": Attribute.ENUM,
825 "flags": Attribute.ExecReadOnly | Attribute.ExecImmutable,
826 "allowed": ["x86_64",
828 "validation_function": validation.is_enum,
830 "operating_system": dict({
831 "name": "operatingSystem",
832 "help": "Constrain operating system during resource discovery.",
833 "type": Attribute.ENUM,
834 "flags": Attribute.ExecReadOnly | Attribute.ExecImmutable,
840 "validation_function": validation.is_enum,
844 "help": "Constrain the PlanetLab site this node should reside on.",
845 "type": Attribute.ENUM,
846 "flags": Attribute.ExecReadOnly | Attribute.ExecImmutable,
850 "validation_function": validation.is_enum,
852 "min_reliability": dict({
853 "name": "minReliability",
854 "help": "Constrain reliability while picking PlanetLab nodes. Specifies a lower acceptable bound.",
855 "type": Attribute.DOUBLE,
857 "flags": Attribute.ExecReadOnly | Attribute.ExecImmutable,
858 "validation_function": validation.is_number,
860 "max_reliability": dict({
861 "name": "maxReliability",
862 "help": "Constrain reliability while picking PlanetLab nodes. Specifies an upper acceptable bound.",
863 "type": Attribute.DOUBLE,
865 "flags": Attribute.ExecReadOnly | Attribute.ExecImmutable,
866 "validation_function": validation.is_number,
868 "min_bandwidth": dict({
869 "name": "minBandwidth",
870 "help": "Constrain available bandwidth while picking PlanetLab nodes. Specifies a lower acceptable bound.",
871 "type": Attribute.DOUBLE,
873 "flags": Attribute.ExecReadOnly | Attribute.ExecImmutable,
874 "validation_function": validation.is_number,
876 "max_bandwidth": dict({
877 "name": "maxBandwidth",
878 "help": "Constrain available bandwidth while picking PlanetLab nodes. Specifies an upper acceptable bound.",
879 "type": Attribute.DOUBLE,
881 "flags": Attribute.ExecReadOnly | Attribute.ExecImmutable,
882 "validation_function": validation.is_number,
886 "help": "Constrain node load average while picking PlanetLab nodes. Specifies a lower acceptable bound.",
887 "type": Attribute.DOUBLE,
889 "flags": Attribute.ExecReadOnly | Attribute.ExecImmutable,
890 "validation_function": validation.is_number,
894 "help": "Constrain node load average while picking PlanetLab nodes. Specifies an upper acceptable bound.",
895 "type": Attribute.DOUBLE,
897 "flags": Attribute.ExecReadOnly | Attribute.ExecImmutable,
898 "validation_function": validation.is_number,
902 "help": "Constrain available cpu time while picking PlanetLab nodes. Specifies a lower acceptable bound.",
903 "type": Attribute.DOUBLE,
905 "flags": Attribute.ExecReadOnly | Attribute.ExecImmutable,
906 "validation_function": validation.is_number,
910 "help": "Constrain available cpu time while picking PlanetLab nodes. Specifies an upper acceptable bound.",
911 "type": Attribute.DOUBLE,
913 "flags": Attribute.ExecReadOnly | Attribute.ExecImmutable,
914 "validation_function": validation.is_number,
920 "type": Attribute.BOOL,
922 "validation_function": validation.is_bool
926 "help": "This is the primary interface for the attached node",
927 "type": Attribute.BOOL,
929 "validation_function": validation.is_bool
931 "device_name": dict({
933 "help": "Device name",
934 "type": Attribute.STRING,
935 "flags": Attribute.ExecReadOnly | Attribute.ExecImmutable,
936 "validation_function": validation.is_string
940 "help": "Maximum transmition unit for device",
941 "type": Attribute.INTEGER,
943 "validation_function": validation.is_integer_range(0,1500)
947 "help": "Network mask for the device (eg: 24 for /24 network)",
948 "type": Attribute.INTEGER,
949 "validation_function": validation.is_integer_range(8,24)
953 "help": "Enable SNAT (source NAT to the internet) no this device",
954 "type": Attribute.BOOL,
956 "validation_function": validation.is_bool
958 "pointopoint": dict({
959 "name": "pointopoint",
960 "help": "If the interface is a P2P link, the remote endpoint's IP "
961 "should be set on this attribute.",
962 "type": Attribute.STRING,
963 "flags": Attribute.ExecReadOnly | Attribute.ExecImmutable,
964 "validation_function": validation.is_string
967 "name": "txqueuelen",
968 "help": "Transmission queue length (in packets)",
969 "type": Attribute.INTEGER,
971 "flags": Attribute.ExecReadOnly | Attribute.ExecImmutable,
973 "validation_function": validation.is_integer
978 "help": "Command line string",
979 "type": Attribute.STRING,
980 "flags": Attribute.ExecReadOnly | Attribute.ExecImmutable,
981 "validation_function": validation.is_string
985 "help": "Run with root privileges",
986 "type": Attribute.BOOL,
987 "flags": Attribute.ExecReadOnly | Attribute.ExecImmutable,
989 "validation_function": validation.is_bool
993 "help": "Standard input",
994 "type": Attribute.STRING,
995 "flags": Attribute.ExecReadOnly | Attribute.ExecImmutable,
996 "validation_function": validation.is_string
1001 "help": "Space-separated list of packages required to run the application",
1002 "type": Attribute.STRING,
1003 "flags": Attribute.ExecReadOnly | Attribute.ExecImmutable,
1004 "validation_function": validation.is_string
1006 "build-depends": dict({
1007 "name": "buildDepends",
1008 "help": "Space-separated list of packages required to build the application",
1009 "type": Attribute.STRING,
1010 "flags": Attribute.ExecReadOnly | Attribute.ExecImmutable,
1011 "validation_function": validation.is_string
1013 "rpm-fusion": dict({
1014 "name": "rpmFusion",
1015 "help": "True if required packages can be found in the RpmFusion repository",
1016 "type": Attribute.BOOL,
1017 "flags": Attribute.ExecReadOnly | Attribute.ExecImmutable,
1019 "validation_function": validation.is_bool
1023 "help": "Space-separated list of regular files to be deployed in the working path prior to building. "
1024 "Archives won't be expanded automatically.",
1025 "type": Attribute.STRING,
1026 "flags": Attribute.ExecReadOnly | Attribute.ExecImmutable,
1027 "validation_function": validation.is_string
1031 "help": "Build commands to execute after deploying the sources. "
1032 "Sources will be in the ${SOURCES} folder. "
1033 "Example: tar xzf ${SOURCES}/my-app.tgz && cd my-app && ./configure && make && make clean.\n"
1034 "Try to make the commands return with a nonzero exit code on error.\n"
1035 "Also, do not install any programs here, use the 'install' attribute. This will "
1036 "help keep the built files constrained to the build folder (which may "
1037 "not be the home folder), and will result in faster deployment. Also, "
1038 "make sure to clean up temporary files, to reduce bandwidth usage between "
1039 "nodes when transferring built packages.",
1040 "type": Attribute.STRING,
1041 "flags": Attribute.ExecReadOnly | Attribute.ExecImmutable,
1042 "validation_function": validation.is_string
1046 "help": "Commands to transfer built files to their final destinations. "
1047 "Sources will be in the initial working folder, and a special "
1048 "tag ${SOURCES} can be used to reference the experiment's "
1049 "home folder (where the application commands will run).\n"
1050 "ALL sources and targets needed for execution must be copied there, "
1051 "if building has been enabled.\n"
1052 "That is, 'slave' nodes will not automatically get any source files. "
1053 "'slave' nodes don't get build dependencies either, so if you need "
1054 "make and other tools to install, be sure to provide them as "
1055 "actual dependencies instead.",
1056 "type": Attribute.STRING,
1057 "flags": Attribute.ExecReadOnly | Attribute.ExecImmutable,
1058 "validation_function": validation.is_string
1061 "netpipe_mode": dict({
1063 "help": "Link mode:\n"
1064 " * SERVER: applies to incoming connections\n"
1065 " * CLIENT: applies to outgoing connections\n"
1066 " * SERVICE: applies to both",
1067 "type": Attribute.ENUM,
1068 "flags": Attribute.ExecReadOnly | Attribute.ExecImmutable,
1069 "allowed": ["SERVER",
1072 "validation_function": validation.is_enum,
1076 "help": "Port list or range. Eg: '22', '22,23,27', '20-2000'",
1077 "type": Attribute.STRING,
1078 "validation_function": is_portlist,
1082 "help": "Address list or range. Eg: '127.0.0.1', '127.0.0.1,127.0.1.1', '127.0.0.1/8'",
1083 "type": Attribute.STRING,
1084 "validation_function": is_addrlist,
1088 "help": "Inbound bandwidth limit (in Mbit/s)",
1089 "type": Attribute.DOUBLE,
1090 "validation_function": validation.is_number,
1094 "help": "Outbound bandwidth limit (in Mbit/s)",
1095 "type": Attribute.DOUBLE,
1096 "validation_function": validation.is_number,
1100 "help": "Inbound packet loss rate (0 = no loss, 1 = 100% loss)",
1101 "type": Attribute.DOUBLE,
1102 "validation_function": validation.is_number,
1106 "help": "Outbound packet loss rate (0 = no loss, 1 = 100% loss)",
1107 "type": Attribute.DOUBLE,
1108 "validation_function": validation.is_number,
1112 "help": "Inbound packet delay (in milliseconds)",
1113 "type": Attribute.INTEGER,
1115 "validation_function": validation.is_integer,
1119 "help": "Outbound packet delay (in milliseconds)",
1120 "type": Attribute.INTEGER,
1122 "validation_function": validation.is_integer,
1126 "help": "Path to a .c or .py source for a filter module, or a binary .so",
1127 "type": Attribute.STRING,
1128 "flags": Attribute.ExecReadOnly | Attribute.ExecImmutable,
1129 "validation_function": validation.is_string
1133 "help": "Module arguments - comma-separated list of name=value pairs",
1134 "type": Attribute.STRING,
1135 "flags": Attribute.ExecReadOnly | Attribute.ExecImmutable,
1136 "validation_function": validation.is_string
1143 "help": "Standard output stream"
1147 "help": "Application standard error",
1151 "help": "Output of the build process",
1154 "netpipe_stats": dict({
1155 "name": "netpipeStats",
1156 "help": "Information about rule match counters, packets dropped, etc.",
1161 "help": "Detailled log of all packets going through the interface",
1165 "help": "PCAP trace of all packets going through the interface",
1169 create_order = [ INTERNET, NODE, NODEIFACE, TUNFILTER, TAPIFACE, TUNIFACE, NETPIPE, NEPIDEPENDENCY, NS3DEPENDENCY, DEPENDENCY, APPLICATION ]
1171 configure_order = [ INTERNET, Parallel(NODE), NODEIFACE, Parallel(TAPIFACE), Parallel(TUNIFACE), NETPIPE, Parallel(NEPIDEPENDENCY), Parallel(NS3DEPENDENCY), Parallel(DEPENDENCY), Parallel(APPLICATION) ]
1173 # Start (and prestart) node after ifaces, because the node needs the ifaces in order to set up routes
1174 start_order = [ INTERNET, NODEIFACE, Parallel(TAPIFACE), Parallel(TUNIFACE), Parallel(NODE), NETPIPE, Parallel(NEPIDEPENDENCY), Parallel(NS3DEPENDENCY), Parallel(DEPENDENCY), Parallel(APPLICATION) ]
1177 shutdown_order = [ Parallel(APPLICATION), Parallel(TAPIFACE), Parallel(TUNIFACE), Parallel(NETPIPE), Parallel(NEPIDEPENDENCY), Parallel(NS3DEPENDENCY), Parallel(DEPENDENCY), NODEIFACE, Parallel(NODE) ]
1179 factories_info = dict({
1181 "help": "Virtualized Node (V-Server style)",
1182 "category": FC.CATEGORY_NODES,
1183 "create_function": create_node,
1184 "preconfigure_function": configure_node,
1185 "prestart_function": configure_node_routes,
1197 # NEPI-in-NEPI attributes
1198 ATTR_NEPI_TESTBED_ENVIRONMENT_SETUP,
1200 "connector_types": ["devs", "apps", "pipes", "deps"],
1201 "tags": [tags.NODE, tags.ALLOW_ROUTES],
1204 "help": "External network interface - they cannot be brought up or down, and they MUST be connected to the internet.",
1205 "category": FC.CATEGORY_DEVICES,
1206 "create_function": create_nodeiface,
1207 "preconfigure_function": configure_nodeiface,
1208 "box_attributes": [ ],
1209 "connector_types": ["node", "inet"],
1210 "tags": [tags.INTERFACE, tags.HAS_ADDRESSES],
1213 "help": "Virtual TUN network interface (layer 3)",
1214 "category": FC.CATEGORY_DEVICES,
1215 "create_function": create_tuniface,
1216 "preconfigure_function": preconfigure_tuniface,
1217 "configure_function": postconfigure_tuniface,
1218 "prestart_function": wait_tuniface,
1220 "up", "device_name", "mtu", "snat", "pointopoint",
1222 "tun_proto", "tun_addr", "tun_port", "tun_key", "tun_cipher",
1224 "traces": ["packets", "pcap"],
1225 "connector_types": ["node","udp","tcp","fd->","gre"],
1226 "tags": [tags.INTERFACE, tags.ALLOW_ADDRESSES],
1229 "help": "Virtual TAP network interface (layer 2)",
1230 "category": FC.CATEGORY_DEVICES,
1231 "create_function": create_tapiface,
1232 "preconfigure_function": preconfigure_tuniface,
1233 "configure_function": postconfigure_tuniface,
1234 "prestart_function": wait_tuniface,
1236 "up", "device_name", "mtu", "snat", "pointopoint",
1238 "tun_proto", "tun_addr", "tun_port", "tun_key", "tun_cipher",
1240 "traces": ["packets", "pcap"],
1241 "connector_types": ["node","udp","tcp","fd->","gre"],
1242 "tags": [tags.INTERFACE, tags.ALLOW_ADDRESSES],
1245 "help": "TUN/TAP stream filter\n\n"
1246 "If specified, it should be either a .py or .so module. "
1247 "It will be loaded, and all incoming and outgoing packets "
1248 "will be routed through it. The filter will not be responsible "
1249 "for buffering, packet queueing is performed in tun_connect "
1250 "already, so it should not concern itself with it. It should "
1251 "not, however, block in one direction if the other is congested.\n"
1253 "Modules are expected to have the following methods:\n"
1255 "\t\tIf arguments are given, this method will be called with the\n"
1256 "\t\tgiven arguments (as keyword args in python modules, or a single\n"
1257 "\taccept_packet(packet, direction):\n"
1258 "\t\tDecide whether to drop the packet. Direction is 0 for packets "
1259 "coming from the local side to the remote, and 1 is for packets "
1260 "coming from the remote side to the local. Return a boolean, "
1261 "true if the packet is not to be dropped.\n"
1262 "\tfilter_init():\n"
1263 "\t\tInitializes a filtering pipe (filter_run). It should "
1264 "return two file descriptors to use as a bidirectional "
1265 "pipe: local and remote. 'local' is where packets from the "
1266 "local side will be written to. After filtering, those packets "
1267 "should be written to 'remote', where tun_connect will read "
1268 "from, and it will forward them to the remote peer. "
1269 "Packets from the remote peer will be written to 'remote', "
1270 "where the filter is expected to read from, and eventually "
1271 "forward them to the local side. If the file descriptors are "
1272 "not nonblocking, they will be set to nonblocking. So it's "
1273 "better to set them from the start like that.\n"
1274 "\tfilter_run(local, remote):\n"
1275 "\t\tIf filter_init is provided, it will be called repeatedly, "
1276 "in a separate thread until the process is killed. It should "
1277 "sleep at most for a second.\n"
1278 "\tfilter_close(local, remote):\n"
1279 "\t\tCalled then the process is killed, if filter_init was provided. "
1280 "It should, among other things, close the file descriptors.\n"
1282 "Python modules are expected to return a tuple in filter_init, "
1283 "either of file descriptors or file objects, while native ones "
1284 "will receive two int*.\n"
1286 "Python modules can additionally contain a custom queue class "
1287 "that will replace the FIFO used by default. The class should "
1288 "be named 'queueclass' and contain an interface compatible with "
1289 "collections.deque. That is, indexing (especiall for q[0]), "
1290 "bool(q), popleft, appendleft, pop (right), append (right), "
1291 "len(q) and clear.",
1292 "category": FC.CATEGORY_CHANNELS,
1293 "create_function": create_tunfilter,
1296 "tun_proto", "tun_addr", "tun_port", "tun_key", "tun_cipher",
1298 "connector_types": ["->fd","udp","tcp"],
1301 "help": "Generic executable command line application",
1302 "category": FC.CATEGORY_APPLICATIONS,
1303 "create_function": create_application,
1304 "start_function": start_application,
1305 "status_function": status_application,
1306 "stop_function": stop_application,
1307 "configure_function": configure_application,
1308 "box_attributes": ["command", "sudo", "stdin",
1309 "depends", "build-depends", "build", "install",
1310 "sources", "rpm-fusion" ],
1311 "connector_types": ["node"],
1312 "traces": ["stdout", "stderr", "buildlog"],
1313 "tags": [tags.APPLICATION],
1316 "help": "Requirement for package or application to be installed on some node",
1317 "category": FC.CATEGORY_APPLICATIONS,
1318 "create_function": create_dependency,
1319 "preconfigure_function": configure_dependency,
1320 "box_attributes": ["depends", "build-depends", "build", "install",
1321 "sources", "rpm-fusion" ],
1322 "connector_types": ["node"],
1323 "traces": ["buildlog"],
1325 NEPIDEPENDENCY: dict({
1326 "help": "Requirement for NEPI inside NEPI - required to run testbed instances inside a node",
1327 "category": FC.CATEGORY_APPLICATIONS,
1328 "create_function": create_nepi_dependency,
1329 "preconfigure_function": configure_dependency,
1330 "box_attributes": [],
1331 "connector_types": ["node"],
1332 "traces": ["buildlog"],
1334 NS3DEPENDENCY: dict({
1335 "help": "Requirement for NS3 inside NEPI - required to run NS3 testbed instances inside a node. It also needs NepiDependency.",
1336 "category": FC.CATEGORY_APPLICATIONS,
1337 "create_function": create_ns3_dependency,
1338 "preconfigure_function": configure_dependency,
1339 "box_attributes": [ ],
1340 "connector_types": ["node"],
1341 "traces": ["buildlog"],
1344 "help": "Internet routing",
1345 "category": FC.CATEGORY_CHANNELS,
1346 "create_function": create_internet,
1347 "connector_types": ["devs"],
1348 "tags": [tags.INTERNET],
1351 "help": "Link emulation",
1352 "category": FC.CATEGORY_CHANNELS,
1353 "create_function": create_netpipe,
1354 "configure_function": configure_netpipe,
1355 "box_attributes": ["netpipe_mode",
1356 "addr_list", "port_list",
1357 "bw_in","plr_in","delay_in",
1358 "bw_out","plr_out","delay_out"],
1359 "connector_types": ["node"],
1360 "traces": ["netpipe_stats"],
1364 testbed_attributes = dict({
1367 "help": "The name of the PlanetLab slice to use",
1368 "type": Attribute.STRING,
1369 "flags": Attribute.ExecReadOnly | Attribute.ExecImmutable | Attribute.NoDefaultValue,
1370 "validation_function": validation.is_string
1374 "help": "The name of the PlanetLab user to use for API calls - it must have at least a User role.",
1375 "type": Attribute.STRING,
1376 "flags": Attribute.ExecReadOnly | Attribute.ExecImmutable | Attribute.NoDefaultValue,
1377 "validation_function": validation.is_string
1381 "help": "The PlanetLab user's password.",
1382 "type": Attribute.STRING,
1383 "flags": Attribute.ExecReadOnly | Attribute.ExecImmutable | Attribute.NoDefaultValue,
1384 "validation_function": validation.is_string
1388 "help": "The PlanetLab PLC API host",
1389 "type": Attribute.STRING,
1390 "value": "www.planet-lab.eu",
1391 "flags": Attribute.ExecReadOnly | Attribute.ExecImmutable,
1392 "validation_function": validation.is_string
1396 "help": "The PlanetLab PLC API url pattern - %(hostname)s is replaced by plcHost.",
1397 "type": Attribute.STRING,
1398 "value": "https://%(hostname)s:443/PLCAPI/",
1399 "flags": Attribute.ExecReadOnly | Attribute.ExecImmutable,
1400 "validation_function": validation.is_string
1402 "p2p_deployment": dict({
1403 "name": "p2pDeployment",
1404 "help": "Enable peer-to-peer deployment of applications and dependencies. "
1405 "When enabled, dependency packages and applications are "
1406 "deployed in a P2P fashion, picking a single node to do "
1407 "the building or repo download, while all the others "
1408 "cooperatively exchange resulting binaries or rpms. "
1409 "When deploying to many nodes, this is a far more efficient "
1410 "use of resources. It does require re-encrypting and distributing "
1411 "the slice's private key. Though it is implemented in a secure "
1412 "fashion, if they key's sole purpose is not PlanetLab, then this "
1413 "feature should be disabled.",
1414 "type": Attribute.BOOL,
1416 "flags": Attribute.ExecReadOnly | Attribute.ExecImmutable,
1417 "validation_function": validation.is_bool
1419 "slice_ssh_key": dict({
1420 "name": "sliceSSHKey",
1421 "help": "The controller-local path to the slice user's ssh private key. "
1422 "It is the user's responsability to deploy this file where the controller "
1423 "will run, it won't be done automatically because it's sensitive information. "
1424 "It is recommended that a NEPI-specific user be created for this purpose and "
1425 "this purpose alone.",
1426 "type": Attribute.STRING,
1427 "flags": Attribute.ExecReadOnly | Attribute.ExecImmutable | Attribute.NoDefaultValue,
1428 "validation_function": validation.is_string
1430 "pl_log_level": dict({
1431 "name": "plLogLevel",
1432 "help": "Verbosity of logging of planetlab events.",
1434 "type": Attribute.ENUM,
1435 "allowed": ["DEBUG",
1440 "validation_function": validation.is_enum,
1442 "tap_port_base": dict({
1443 "name": "tapPortBase",
1444 "help": "Base port to use when connecting TUN/TAPs. Effective port will be BASE + GUID.",
1445 "type": Attribute.INTEGER,
1447 "range": (2000,30000),
1448 "validation_function": validation.is_integer_range(2000,30000)
1450 "dedicated_slice": dict({
1451 "name": "dedicatedSlice",
1452 "help": "Set to True if the slice will be dedicated to this experiment. "
1453 "NEPI will perform node and slice cleanup, making sure slices are "
1454 "in a clean, repeatable state before running the experiment.",
1455 "type": Attribute.BOOL,
1457 "flags": Attribute.ExecReadOnly | Attribute.ExecImmutable,
1458 "validation_function": validation.is_bool
1462 supported_recovery_policies = [
1468 class MetadataInfo(metadata.MetadataInfo):
1470 def connector_types(self):
1471 return connector_types
1474 def connections(self):
1478 def attributes(self):
1486 def create_order(self):
1490 def configure_order(self):
1491 return configure_order
1494 def prestart_order(self):
1498 def start_order(self):
1502 def factories_info(self):
1503 return factories_info
1506 def testbed_attributes(self):
1507 return testbed_attributes
1510 def testbed_id(self):
1514 def testbed_version(self):
1515 return TESTBED_VERSION
1518 def supported_recovery_policies(self):
1519 return supported_recovery_policies