1205e9f72150a987427075f81e6ad47ec041bb93
[nepi.git] / test / testbeds / planetlab / execute.py
1 #!/usr/bin/env python
2 # -*- coding: utf-8 -*-
3
4 import getpass
5 from nepi.util.constants import ApplicationStatus as AS
6 from nepi.testbeds import planetlab
7 import os
8 import shutil
9 import tempfile
10 import time
11 import unittest
12 import re
13 import test_util
14 import sys
15
16 class PlanetLabExecuteTestCase(unittest.TestCase):
17     testbed_id = "planetlab"
18     slicename = "inria_nepi"
19     plchost = "nepiplc.pl.sophia.inria.fr"
20     
21     host1 = "nepi1.pl.sophia.inria.fr"
22     host2 = "nepi2.pl.sophia.inria.fr"
23     
24     port_base = 2000 + (os.getpid() % 1000) * 13
25     
26     PLR50_PY = os.path.join(
27         os.path.dirname(planetlab.__file__), 
28         'scripts',
29         'plr50.py')
30     PLR50_C = os.path.join(
31         os.path.dirname(planetlab.__file__), 
32         'scripts',
33         'plr50.c')
34     TOS_PY = os.path.join(
35         os.path.dirname(planetlab.__file__), 
36         'scripts',
37         'tosqueue.py')
38     CLS_PY = os.path.join(
39         os.path.dirname(planetlab.__file__), 
40         'scripts',
41         'classqueue.py')
42     
43     def setUp(self):
44         self.root_dir = tempfile.mkdtemp()
45         self.__class__.port_base = self.port_base + 100
46         
47     def tearDown(self):
48         try:
49             shutil.rmtree(self.root_dir)
50         except:
51             # retry
52             time.sleep(0.1)
53             shutil.rmtree(self.root_dir)
54
55     def make_instance(self):
56         testbed_id = self.testbed_id
57         slicename = self.slicename
58         plchost = self.plchost
59         
60         instance = planetlab.TestbedController()
61         pl_ssh_key = os.environ.get(
62             "PL_SSH_KEY",
63             "%s/.ssh/id_rsa_planetlab" % (os.environ['HOME'],) )
64         slicename = os.environ.get(
65             "PL_SLICE",
66             slicename)
67         pl_user, pl_pwd = test_util.pl_auth()
68         
69         instance.defer_configure("homeDirectory", self.root_dir)
70         instance.defer_configure("slice", slicename)
71         instance.defer_configure("sliceSSHKey", pl_ssh_key)
72         instance.defer_configure("authUser", pl_user)
73         instance.defer_configure("authPass", pl_pwd)
74         instance.defer_configure("plcHost", plchost)
75         instance.defer_configure("tapPortBase", self.port_base)
76         instance.defer_configure("p2pDeployment", False) # it's interactive, we don't want it in tests
77         instance.defer_configure("dedicatedSlice", True)
78         
79         # Hack, but we need vsys_vnet
80         instance.do_setup()
81         vnet = instance.vsys_vnet
82         self.net_prefix = vnet.rsplit('.',1)[0]
83         
84         return instance
85
86     @test_util.skipUnless(test_util.pl_auth() is not None, "Test requires PlanetLab authentication info (PL_USER and PL_PASS environment variables)")
87     def test_simple(self):
88         instance = self.make_instance()
89         
90         instance.defer_create(2, "Node")
91         instance.defer_create_set(2, "hostname", self.host1)
92         instance.defer_create(3, "Node")
93         instance.defer_create_set(3, "hostname", self.host2)
94         instance.defer_create(4, "NodeInterface")
95         instance.defer_connect(2, "devs", 4, "node")
96         instance.defer_create(5, "NodeInterface")
97         instance.defer_connect(3, "devs", 5, "node")
98         instance.defer_create(6, "Internet")
99         instance.defer_connect(4, "inet", 6, "devs")
100         instance.defer_connect(5, "inet", 6, "devs")
101         instance.defer_create(7, "Application")
102         instance.defer_create_set(7, "command", "ping -qc1 {#[GUID-5].addr[0].[Address]#}")
103         instance.defer_add_trace(7, "stdout")
104         instance.defer_add_trace(7, "stderr")
105         instance.defer_connect(7, "node", 2, "apps")
106
107         comp_result = r"""PING .* \(.*\) \d*\(\d*\) bytes of data.
108
109 --- .* ping statistics ---
110 1 packets transmitted, 1 received, 0% packet loss, time \d*ms.*
111 """
112
113         try:
114             instance.do_setup()
115             instance.do_create()
116             instance.do_connect_init()
117             instance.do_connect_compl()
118             instance.do_preconfigure()
119             
120             # Manually replace netref
121             instance.set(7, "command",
122                 instance.get(7, "command")
123                     .replace("{#[GUID-5].addr[0].[Address]#}", 
124                         instance.get_address(5, 0, "Address") )
125             )
126
127             instance.do_configure()
128             
129             instance.do_prestart()
130             instance.start()
131             while instance.status(7) != AS.STATUS_FINISHED:
132                 time.sleep(0.5)
133             ping_result = instance.trace(7, "stdout") or ""
134             instance.stop()
135         finally:
136             try:
137                 instance.shutdown()
138             except:
139                 pass
140
141         # asserts at the end, to make sure there's proper cleanup
142         self.assertTrue(re.match(comp_result, ping_result, re.MULTILINE),
143             "Unexpected trace:\n" + ping_result)
144         
145     @test_util.skipUnless(test_util.pl_auth() is not None, "Test requires PlanetLab authentication info (PL_USER and PL_PASS environment variables)")
146     def test_depends(self):
147         instance = self.make_instance()
148         
149         instance.defer_create(2, "Node")
150         instance.defer_create_set(2, "hostname", self.host1)
151         instance.defer_create(3, "NodeInterface")
152         instance.defer_connect(2, "devs", 3, "node")
153         instance.defer_create(4, "Internet")
154         instance.defer_connect(3, "inet", 4, "devs")
155         instance.defer_create(5, "Application")
156         instance.defer_create_set(5, "command", "gfortran --version")
157         instance.defer_create_set(5, "depends", "gcc-gfortran")
158         instance.defer_add_trace(5, "stdout")
159         instance.defer_add_trace(5, "stderr")
160         instance.defer_connect(5, "node", 2, "apps")
161
162         try:
163             instance.do_setup()
164             instance.do_create()
165             instance.do_connect_init()
166             instance.do_connect_compl()
167             instance.do_preconfigure()
168             instance.do_configure()
169             
170             instance.do_prestart()
171             instance.start()
172             while instance.status(5) != AS.STATUS_FINISHED:
173                 time.sleep(0.5)
174             ping_result = instance.trace(5, "stdout") or ""
175             comp_result = r".*GNU Fortran \(GCC\).*"
176             instance.stop()
177         finally:
178             try:
179                 instance.shutdown()
180             except:
181                 pass
182
183         # asserts at the end, to make sure there's proper cleanup
184         self.assertTrue(re.match(comp_result, ping_result, re.MULTILINE),
185             "Unexpected trace:\n" + ping_result)
186         
187     @test_util.skipUnless(test_util.pl_auth() is not None, "Test requires PlanetLab authentication info (PL_USER and PL_PASS environment variables)")
188     def test_build(self):
189         instance = self.make_instance()
190         
191         instance.defer_create(2, "Node")
192         instance.defer_create_set(2, "hostname", self.host1)
193         instance.defer_create(3, "NodeInterface")
194         instance.defer_connect(2, "devs", 3, "node")
195         instance.defer_create(4, "Internet")
196         instance.defer_connect(3, "inet", 4, "devs")
197         instance.defer_create(10, "Application")
198         instance.defer_create_set(10, "command", "./consts")
199         instance.defer_create_set(10, "buildDepends", "gcc")
200         instance.defer_create_set(10, "build", "gcc ${SOURCES}/consts.c -o consts")
201         instance.defer_create_set(10, "install", "cp consts ${SOURCES}/consts")
202         instance.defer_create_set(10, "sources", os.path.join(os.path.dirname(planetlab.__file__),'scripts','consts.c'))
203         instance.defer_add_trace(10, "stdout")
204         instance.defer_add_trace(10, "stderr")
205         instance.defer_connect(10, "node", 2, "apps")
206
207         comp_result = \
208 r""".*ETH_P_ALL = 0x[0-9a-fA-F]{8}
209 ETH_P_IP = 0x[0-9a-fA-F]{8}
210 TUNGETIFF = 0x[0-9a-fA-F]{8}
211 TUNSETIFF = 0x[0-9a-fA-F]{8}
212 IFF_NO_PI = 0x[0-9a-fA-F]{8}
213 IFF_TAP = 0x[0-9a-fA-F]{8}
214 IFF_TUN = 0x[0-9a-fA-F]{8}
215 IFF_VNET_HDR = 0x[0-9a-fA-F]{8}
216 TUN_PKT_STRIP = 0x[0-9a-fA-F]{8}
217 IFHWADDRLEN = 0x[0-9a-fA-F]{8}
218 IFNAMSIZ = 0x[0-9a-fA-F]{8}
219 IFREQ_SZ = 0x[0-9a-fA-F]{8}
220 FIONREAD = 0x[0-9a-fA-F]{8}.*
221 """
222
223         try:
224             instance.do_setup()
225             instance.do_create()
226             instance.do_connect_init()
227             instance.do_connect_compl()
228             instance.do_preconfigure()
229             instance.do_configure()
230             
231             instance.do_prestart()
232             instance.start()
233             while instance.status(10) != AS.STATUS_FINISHED:
234                 time.sleep(0.5)
235             ping_result = instance.trace(10, "stdout") or ""
236             instance.stop()
237         finally:
238             try:
239                 instance.shutdown()
240             except:
241                 pass
242
243         # asserts at the end, to make sure there's proper cleanup
244         self.assertTrue(re.match(comp_result, ping_result, re.MULTILINE),
245             "Unexpected trace:\n" + ping_result)
246         
247     @test_util.skipUnless(test_util.pl_auth() is not None, "Test requires PlanetLab authentication info (PL_USER and PL_PASS environment variables)")
248     def test_simple_vsys(self):
249         instance = self.make_instance()
250         
251         instance.defer_create(2, "Node")
252         instance.defer_create_set(2, "hostname", self.host1)
253         instance.defer_create(3, "NodeInterface")
254         instance.defer_connect(2, "devs", 3, "node")
255         instance.defer_create(4, "Internet")
256         instance.defer_connect(3, "inet", 4, "devs")
257         instance.defer_create(5, "TunInterface")
258         instance.defer_add_address(5, self.net_prefix+".2", 24, False)
259         instance.defer_connect(2, "devs", 5, "node")
260         instance.defer_create(6, "Application")
261         instance.defer_create_set(6, "command", """
262 set -e
263 netconfig help > /dev/null
264 test -e /vsys/vif_up.in > /dev/null
265 test -e /vsys/vif_up.out > /dev/null
266 test -e /vsys/fd_tuntap.control > /dev/null
267 echo 'OKIDOKI'
268 """)
269         instance.defer_create_set(6, "sudo", True) # only sudo has access to /vsys
270         instance.defer_add_trace(6, "stdout")
271         instance.defer_add_trace(6, "stderr")
272         instance.defer_connect(6, "node", 2, "apps")
273
274         try:
275             instance.do_setup()
276             instance.do_create()
277             instance.do_connect_init()
278             instance.do_connect_compl()
279             instance.do_preconfigure()
280             instance.do_configure()
281             
282             instance.do_prestart()
283             instance.start()
284             while instance.status(6) != AS.STATUS_FINISHED:
285                 time.sleep(0.5)
286             test_result = (instance.trace(6, "stdout") or "").strip()
287             comp_result = "OKIDOKI"
288             instance.stop()
289         finally:
290             try:
291                 instance.shutdown()
292             except:
293                 pass
294
295         # asserts at the end, to make sure there's proper cleanup
296         self.assertEqual(comp_result, test_result)
297
298     @test_util.skipUnless(test_util.pl_auth() is not None, "Test requires PlanetLab authentication info (PL_USER and PL_PASS environment variables)")
299     def test_emulation(self):
300         instance = self.make_instance()
301         
302         instance.defer_create(2, "Node")
303         instance.defer_create_set(2, "hostname", self.host1)
304         instance.defer_create(3, "NodeInterface")
305         instance.defer_connect(2, "devs", 3, "node")
306         instance.defer_create(4, "Internet")
307         instance.defer_connect(3, "inet", 4, "devs")
308         instance.defer_create(7, "NetPipe")
309         instance.defer_create_set(7, "mode", "CLIENT")
310         instance.defer_create_set(7, "portList", "80")
311         instance.defer_create_set(7, "bwOut", 12.0/1024.0) # 12kbps
312         instance.defer_create_set(7, "bwIn", 64.0/1024.0) # 64kbps
313         instance.defer_create_set(7, "plrOut", 0.01) # 1% plr outbound - high loss
314         instance.defer_create_set(7, "plrIn", 0.001) # 0.1% plr inbound - regular loss
315         instance.defer_create_set(7, "delayOut", int(1500 * 8 / (12.0/1024.0) / 1000)) # tx delay at 12kbps in ms
316         instance.defer_create_set(7, "delayIn", int(1500 * 8 / (64.0/1024.0) / 1000)) # rx delay at 64kbps in ms
317         instance.defer_add_trace(7, "netpipeStats")
318         instance.defer_connect(2, "pipes", 7, "node")
319         instance.defer_create(8, "Application")
320         instance.defer_create_set(8, "command", "time wget -q -O /dev/null http://www.google.com/") # Fetch ~10kb
321         instance.defer_add_trace(8, "stdout")
322         instance.defer_add_trace(8, "stderr")
323         instance.defer_connect(8, "node", 2, "apps")
324
325         try:
326             instance.do_setup()
327             instance.do_create()
328             instance.do_connect_init()
329             instance.do_connect_compl()
330             instance.do_preconfigure()
331             instance.do_configure()
332             
333             instance.do_prestart()
334             instance.start()
335             while instance.status(8) != AS.STATUS_FINISHED:
336                 time.sleep(0.5)
337             test_result = (instance.trace(8, "stderr") or "").strip()
338             comp_result = r".*real\s*(?P<min>[0-9]+)m(?P<sec>[0-9]+[.][0-9]+)s.*"
339             netpipe_stats = instance.trace(7, "netpipeStats")
340             
341             instance.stop()
342         finally:
343             try:
344                 instance.shutdown()
345             except:
346                 pass
347
348         # asserts at the end, to make sure there's proper cleanup
349         match = re.match(comp_result, test_result, re.MULTILINE)
350         self.assertTrue(match, "Unexpected output: %s" % (test_result,))
351         
352         minutes = int(match.group("min"))
353         seconds = float(match.group("sec"))
354         self.assertTrue((minutes * 60 + seconds) > 1.0, "Emulation not effective: %s" % (test_result,))
355
356         self.assertTrue(netpipe_stats, "Unavailable netpipe stats")
357
358     @test_util.skipUnless(test_util.pl_auth() is not None, "Test requires PlanetLab authentication info (PL_USER and PL_PASS environment variables)")
359     def _pingtest(self, TunClass, ConnectionProto, Cipher, Filter1=None, Filter2=None, Filter1args=None, Filter2args=None, PLREX=None):
360         instance = self.make_instance()
361         
362         instance.defer_create(2, "Node")
363         instance.defer_create_set(2, "hostname", self.host1)
364         instance.defer_create(3, "Node")
365         instance.defer_create_set(3, "hostname", self.host2)
366         instance.defer_create(4, "NodeInterface")
367         instance.defer_connect(2, "devs", 4, "node")
368         instance.defer_create(5, "Internet")
369         instance.defer_connect(4, "inet", 5, "devs")
370         instance.defer_create(6, "NodeInterface")
371         instance.defer_connect(3, "devs", 6, "node")
372         instance.defer_connect(6, "inet", 5, "devs")
373         instance.defer_create(7, TunClass)
374         instance.defer_create_set(7, "tun_cipher", Cipher)
375         instance.defer_add_trace(7, "packets")
376         instance.defer_add_address(7, self.net_prefix+".2", 24, False)
377         instance.defer_connect(2, "devs", 7, "node")
378         instance.defer_create(8, TunClass)
379         instance.defer_create_set(8, "tun_cipher", Cipher)
380         instance.defer_add_trace(8, "packets")
381         instance.defer_add_address(8, self.net_prefix+".3", 24, False)
382         instance.defer_connect(3, "devs", 8, "node")
383         instance.defer_create(9, "Application")
384         instance.defer_create_set(9, "command", "ping -qc10 {#[GUID-8].addr[0].[Address]#}")
385         instance.defer_add_trace(9, "stdout")
386         instance.defer_add_trace(9, "stderr")
387         instance.defer_connect(9, "node", 2, "apps")
388         
389         if Filter1:
390             instance.defer_create(10, "TunFilter")
391             instance.defer_create_set(10, "module", Filter1)
392             if Filter1args:
393                 instance.defer_create_set(10, "args", Filter1args)
394             instance.defer_connect(7, "fd->", 10, "->fd")
395             
396         if Filter2:
397             instance.defer_create(11, "TunFilter")
398             instance.defer_create_set(11, "module", Filter2)
399             if Filter2args:
400                 instance.defer_create_set(11, "args", Filter2args)
401             instance.defer_connect(8, "fd->", 11, "->fd")
402
403         if PLREX is None:
404             if Filter1 and Filter2:
405                 plr = "[5-9][0-9]"
406             elif Filter1 or Filter2:
407                 plr = "[3-9][0-9]"
408             else:
409                 plr = "0"
410         else:
411             plr = PLREX
412        
413         instance.defer_connect(
414             (10 if Filter1 else 7), ConnectionProto, 
415             (11 if Filter2 else 8), ConnectionProto)
416
417         comp_result = r"""PING .* \(.*\) \d*\(\d*\) bytes of data.
418
419 --- .* ping statistics ---
420 10 packets transmitted, [0-9]+ received,.* %s%% packet loss, time \d*ms.*
421 """ % (plr,)
422
423         try:
424             instance.do_setup()
425             instance.do_create()
426             instance.do_connect_init()
427             instance.do_connect_compl()
428             instance.do_preconfigure()
429             
430             # Manually replace netref
431             instance.set(9, "command",
432                 instance.get(9, "command")
433                     .replace("{#[GUID-8].addr[0].[Address]#}", 
434                         instance.get_address(8, 0, "Address") )
435             )
436             
437             instance.do_configure()
438             
439             instance.do_prestart()
440             instance.start()
441             while instance.status(9) != AS.STATUS_FINISHED:
442                 time.sleep(0.5)
443             ping_result = instance.trace(9, "stdout") or ""
444             packets1 = instance.trace(7, "packets") or ""
445             packets2 = instance.trace(8, "packets") or ""
446             instance.stop()
447         finally:
448             try:
449                 instance.shutdown()
450             except:
451                 pass
452
453         # asserts at the end, to make sure there's proper cleanup
454         self.assertTrue(re.match(comp_result, ping_result, re.MULTILINE),
455             "Unexpected trace:\n%s\nPackets @ source:\n%s\nPackets @ target:\n%s" % (
456                 ping_result,
457                 packets1,
458                 packets2))
459
460     @test_util.skipUnless(test_util.pl_auth() is not None, "Test requires PlanetLab authentication info (PL_USER and PL_PASS environment variables)")
461     def test_tun_ping(self):
462         self._pingtest("TunInterface", "tcp", "AES")
463
464     @test_util.skipUnless(test_util.pl_auth() is not None, "Test requires PlanetLab authentication info (PL_USER and PL_PASS environment variables)")
465     def test_tun_ping_udp(self):
466         self._pingtest("TunInterface", "udp", "AES")
467
468     @test_util.skipUnless(test_util.pl_auth() is not None, "Test requires PlanetLab authentication info (PL_USER and PL_PASS environment variables)")
469     def test_tun_ping_gre(self):
470         self._pingtest("TunInterface", "gre", "PLAIN")
471
472     @test_util.skipUnless(test_util.pl_auth() is not None, "Test requires PlanetLab authentication info (PL_USER and PL_PASS environment variables)")
473     def test_tap_ping(self):
474         self._pingtest("TapInterface", "tcp", "AES")
475
476     @test_util.skipUnless(test_util.pl_auth() is not None, "Test requires PlanetLab authentication info (PL_USER and PL_PASS environment variables)")
477     def test_tap_ping_udp(self):
478         self._pingtest("TapInterface", "udp", "AES")
479
480     @test_util.skipUnless(test_util.pl_auth() is not None, "Test requires PlanetLab authentication info (PL_USER and PL_PASS environment variables)")
481     def test_tap_ping_gre(self):
482         self._pingtest("TapInterface", "gre", "PLAIN")
483
484     @test_util.skipUnless(test_util.pl_auth() is not None, "Test requires PlanetLab authentication info (PL_USER and PL_PASS environment variables)")
485     def test_tap_ping_udp_loss1_py(self):
486         self._pingtest("TapInterface", "udp", "AES", self.PLR50_PY, None, "plr=50")
487
488     @test_util.skipUnless(test_util.pl_auth() is not None, "Test requires PlanetLab authentication info (PL_USER and PL_PASS environment variables)")
489     def test_tap_ping_udp_loss2_py(self):
490         self._pingtest("TapInterface", "udp", "AES", self.PLR50_PY, self.PLR50_PY, "plr=40", "plr=40")
491
492     @test_util.skipUnless(test_util.pl_auth() is not None, "Test requires PlanetLab authentication info (PL_USER and PL_PASS environment variables)")
493     def test_tap_ping_udp_loss1_c(self):
494         self._pingtest("TapInterface", "udp", "AES", self.PLR50_C, None, "plr=50")
495
496     @test_util.skipUnless(test_util.pl_auth() is not None, "Test requires PlanetLab authentication info (PL_USER and PL_PASS environment variables)")
497     def test_tap_ping_udp_loss2_c(self):
498         self._pingtest("TapInterface", "udp", "AES", self.PLR50_C, self.PLR50_C, "plr=40", "plr=40")
499
500     @test_util.skipUnless(test_util.pl_auth() is not None, "Test requires PlanetLab authentication info (PL_USER and PL_PASS environment variables)")
501     def test_tun_ping_udp_tos(self):
502         self._pingtest("TunInterface", "udp", "AES", self.TOS_PY, self.TOS_PY, "size=1000", "size=1000", "0")
503
504     @test_util.skipUnless(test_util.pl_auth() is not None, "Test requires PlanetLab authentication info (PL_USER and PL_PASS environment variables)")
505     def test_tun_ping_udp_class(self):
506         self._pingtest("TunInterface", "udp", "AES", self.CLS_PY, self.CLS_PY, "size=10", "size=10", "0")
507
508     @test_util.skipUnless(test_util.pl_auth() is not None, "Test requires PlanetLab authentication info (PL_USER and PL_PASS environment variables)")
509     def test_nepi_depends(self):
510         instance = self.make_instance()
511         
512         instance.defer_create(2, "Node")
513         instance.defer_create_set(2, "hostname", self.host1)
514         instance.defer_create(3, "NodeInterface")
515         instance.defer_connect(2, "devs", 3, "node")
516         instance.defer_create(4, "Internet")
517         instance.defer_connect(3, "inet", 4, "devs")
518         instance.defer_create(5, "NepiDependency")
519         instance.defer_connect(5, "node", 2, "deps")
520         instance.defer_create(12, "Application")
521         instance.defer_connect(12, "node", 2, "apps")
522         instance.defer_create_set(12, "command", "python -c 'import nepi'")
523         instance.defer_add_trace(12, "stderr")
524
525         try:
526             instance.do_setup()
527             instance.do_create()
528             instance.do_connect_init()
529             instance.do_connect_compl()
530             instance.do_preconfigure()
531             instance.do_configure()
532             
533             instance.do_prestart()
534             instance.start()
535             while instance.status(12) != AS.STATUS_FINISHED:
536                 time.sleep(0.5)
537             ping_result = (instance.trace(12, "stderr") or "").strip()
538             instance.stop()
539         finally:
540             try:
541                 instance.shutdown()
542             except:
543                 pass
544         
545         # asserts at the end, to make sure there's proper cleanup
546         self.assertEqual(ping_result, "")
547
548     @test_util.skipUnless(test_util.pl_auth() is not None, 
549         "Test requires PlanetLab authentication info (PL_USER and PL_PASS environment variables)")
550     @test_util.skipUnless(os.environ.get('NEPI_FULL_TESTS','').lower() in ('1','yes','true','on'),
551         "Test is expensive, requires NEPI_FULL_TESTS=yes")
552     def test_ns3_depends(self):
553         instance = self.make_instance()
554         
555         instance.defer_create(2, "Node")
556         instance.defer_create_set(2, "hostname", self.host1)
557         instance.defer_create(3, "NodeInterface")
558         instance.defer_connect(2, "devs", 3, "node")
559         instance.defer_create(4, "Internet")
560         instance.defer_connect(3, "inet", 4, "devs")
561         instance.defer_create(5, "NepiDependency")
562         instance.defer_connect(5, "node", 2, "deps")
563         instance.defer_create(6, "NS3Dependency")
564         instance.defer_connect(6, "node", 2, "deps")
565         instance.defer_create(12, "Application")
566         instance.defer_connect(12, "node", 2, "apps")
567         instance.defer_create_set(12, "command", "python -c 'import nepi.testbeds.ns3.execute ; tb = nepi.testbeds.ns3.execute.TestbedController() ; mod = tb._configure_ns3_module()'")
568         instance.defer_add_trace(12, "stderr")
569
570         try:
571             instance.do_setup()
572             instance.do_create()
573             instance.do_connect_init()
574             instance.do_connect_compl()
575             instance.do_preconfigure()
576             instance.do_configure()
577             
578             instance.do_prestart()
579             instance.start()
580             while instance.status(12) != AS.STATUS_FINISHED:
581                 time.sleep(0.5)
582             ping_result = (instance.trace(12, "stderr") or "").strip()
583             instance.stop()
584         finally:
585             try:
586                 instance.shutdown()
587             except:
588                 pass
589         
590         # asserts at the end, to make sure there's proper cleanup
591         self.assertEqual(ping_result, "")
592
593     @test_util.skipUnless(test_util.pl_auth() is not None, "Test requires PlanetLab authentication info (PL_USER and PL_PASS environment variables)")
594     def test_discovery(self):
595         instance = self.make_instance()
596         
597         instance.defer_create(2, "Node")
598         instance.defer_create_set(2, "operatingSystem", "f12")
599         instance.defer_create(3, "Node")
600         instance.defer_create_set(3, "operatingSystem", "f12")
601         instance.defer_create(4, "NodeInterface")
602         instance.defer_connect(2, "devs", 4, "node")
603         instance.defer_create(5, "NodeInterface")
604         instance.defer_connect(3, "devs", 5, "node")
605         instance.defer_create(6, "Internet")
606         instance.defer_connect(4, "inet", 6, "devs")
607         instance.defer_connect(5, "inet", 6, "devs")
608         instance.defer_create(7, "Application")
609         instance.defer_create_set(7, "command", "ping -qc1 {#[GUID-5].addr[0].[Address]#}")
610         instance.defer_add_trace(7, "stdout")
611         instance.defer_add_trace(7, "stderr")
612         instance.defer_connect(7, "node", 2, "apps")
613
614         comp_result = r"""PING .* \(.*\) \d*\(\d*\) bytes of data.
615
616 --- .* ping statistics ---
617 1 packets transmitted, 1 received, 0% packet loss, time \d*ms.*
618 """
619
620         try:
621             instance.do_setup()
622             instance.do_create()
623             instance.do_connect_init()
624             instance.do_connect_compl()
625             instance.do_preconfigure()
626             
627             # Manually replace netref
628             instance.set(7, "command",
629                 instance.get(7, "command")
630                     .replace("{#[GUID-5].addr[0].[Address]#}", 
631                         instance.get_address(5, 0, "Address") )
632             )
633
634             instance.do_configure()
635             
636             instance.do_prestart()
637             instance.start()
638             while instance.status(7) != AS.STATUS_FINISHED:
639                 time.sleep(0.5)
640             ping_result = instance.trace(7, "stdout") or ""
641             instance.stop()
642         finally:
643             try:
644                 instance.shutdown()
645             except:
646                 pass
647
648         # asserts at the end, to make sure there's proper cleanup
649         self.assertTrue(re.match(comp_result, ping_result, re.MULTILINE),
650             "Unexpected trace:\n" + ping_result)
651         
652         
653
654 if __name__ == '__main__':
655     unittest.main()
656