PlanetLab support toon-up: home_cleanup only nepi folders + make server support longe...
[nepi.git] / examples / omf-iminds-vlc.py
1 #!/usr/bin/env python
2 # -*- coding: utf-8 -*-
3
4 #
5 # Experiment Topology:
6 #
7 #  n1 --- n2
8 #  0.1   0.2 
9 #    
10
11 from nepi.core.design import ExperimentDescription, FactoriesProvider
12 from nepi.core.execute import ExperimentController
13 import getpass
14 import logging
15 import tempfile
16 import time
17
18 logging.basicConfig(level=logging.DEBUG)
19
20 root_dir = tempfile.mkdtemp()
21
22 exp_desc = ExperimentDescription()
23
24 testbed_id = "omf"
25 omf_provider = FactoriesProvider(testbed_id)
26 omf_desc = exp_desc.add_testbed_description(omf_provider)
27 omf_desc.set_attribute_value("homeDirectory", root_dir)
28 omf_desc.set_attribute_value("enableDebug", True)
29 omf_desc.set_attribute_value("xmppSlice", "default_slice_iMinds")
30 omf_desc.set_attribute_value("xmppHost", "xmpp.ilabt.iminds.be")
31 omf_desc.set_attribute_value("xmppPort", 5222)
32 omf_desc.set_attribute_value("xmppPassword", "1234")
33
34 # Add node1
35 node1 = omf_desc.create("Node")
36 node1.set_attribute_value("hostname", "omf.ibbt.open.node3")
37
38 # Add configuration for interface 1
39 iface1 = omf_desc.create("WifiInterface")
40 iface1.set_attribute_value("alias", "w0")
41 iface1.set_attribute_value("mode", "adhoc")
42 iface1.set_attribute_value("channel", "6")
43 iface1.set_attribute_value("type", "g")
44 iface1.set_attribute_value("essid", "cvlcmode")
45 iface1.set_attribute_value("ip", "192.168.0.3")
46 node1.connector("devs").connect(iface1.connector("node"))
47
48 # Add multicast route to node 1
49 route1 = node1.add_route()
50 route1.set_attribute_value("Destination", "224.0.0.0")
51 route1.set_attribute_value("NetPrefix", 4)
52 route1.set_attribute_value("Device", "wlan0")
53
54 # Add node2
55 node2 = omf_desc.create("Node")
56 node2.set_attribute_value("hostname", "omf.ibbt.open.node4")
57
58 # Add configuration for interface 2
59 iface2 = omf_desc.create("WifiInterface")
60 iface2.set_attribute_value("alias", "w0")
61 iface2.set_attribute_value("mode", "adhoc")
62 iface2.set_attribute_value("channel", "6")
63 iface2.set_attribute_value("type", "g")
64 iface2.set_attribute_value("essid", "cvlcmode")
65 iface2.set_attribute_value("ip", "192.168.0.4")
66 node2.connector("devs").connect(iface2.connector("node"))
67
68 # Add multicast route to node 2
69 route2 = node2.add_route()
70 route2.set_attribute_value("Destination", "224.0.0.0")
71 route2.set_attribute_value("NetPrefix", 4)
72 route2.set_attribute_value("Device", "wlan0")
73
74 # Add a channel
75 channel = omf_desc.create("Channel")
76 channel.set_attribute_value("mode", "adhoc")
77 channel.set_attribute_value("channel", "6")
78 channel.set_attribute_value("type", "g")
79 channel.set_attribute_value("essid", "cvlcmode")
80 channel.connector("devs").connect(iface1.connector("chan"))
81 channel.connector("devs").connect(iface2.connector("chan"))
82
83 # Add a vlc server to stream a video using multicast
84 app1 = omf_desc.create("OmfApplication")
85 app1.set_attribute_value("appId", "Vlc#1")
86 app1.set_attribute_value("arguments", "/opt/bbb_240p_mpeg4_lq.ts --sout '#rtp{dst=239.255.0.1,port=1234,mux=ts}' vlc://quit")
87 app1.set_attribute_value("path", "/opt/vlc-1.1.13/cvlc")
88 app1.set_attribute_value("env", "DISPLAY=localhost:10.0 XAUTHORITY=/root/.Xauthority")
89 app1.connector("node").connect(node1.connector("apps"))
90
91 # Add a vlc client to receive the video stream
92 app2 = omf_desc.create("OmfApplication")
93 app2.set_attribute_value("appId", "Vlc#2")
94 app2.set_attribute_value("arguments", "rtp://239.255.0.1:1234")
95 app2.set_attribute_value("path", "/opt/vlc-1.1.13/cvlc")
96 # To see the stream to a ssh -X connection, the DISPLAY variable must be set to the value of the node.
97 # Also don't forget to execute in 'xhost + localhost' in the node
98 app2.set_attribute_value("env", "DISPLAY=localhost:10.0 XAUTHORITY=/root/.Xauthority")
99 app2.connector("node").connect(node2.connector("apps"))
100
101 xml = exp_desc.to_xml()
102
103 controller = ExperimentController(xml, root_dir)
104 controller.start()
105 #while not (controller.is_finished(app1.guid) and \
106 #        controller.is_finished(app2.guid)):
107 #    time.sleep(0.5)
108
109 time.sleep(10)
110
111 #controller.set(iface2.guid, "channel", "1")
112
113 #time.sleep(5)
114
115 controller.stop()
116 controller.shutdown()
117