Adding ICN PlanetLab large experiment scenarios
[nepi.git] / examples / omf-nitos-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", "tribino")
30 omf_desc.set_attribute_value("xmppHost", "nitlab.inf.uth.gr")
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.nitos.node019")
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.19")
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.nitos.node020")
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.20")
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("arguments", "/opt/10-by-p0d.avi --sout '#rtp{dst=192.168.0.20,port=1234,mux=ts}' vlc://quit")
88 app1.set_attribute_value("path", "/opt/vlc-1.1.13/cvlc")
89 app1.set_attribute_value("env", "DISPLAY=localhost:10.0 XAUTHORITY=/root/.Xauthority")
90 app1.connector("node").connect(node1.connector("apps"))
91
92 # Add a vlc client to receive the video stream
93 app2 = omf_desc.create("OmfApplication")
94 app2.set_attribute_value("appId", "Vlc#2")
95 #app2.set_attribute_value("arguments", "rtp://239.255.0.1:1234")
96 app2.set_attribute_value("arguments", "rtp://192.168.0.20:1234")
97 app2.set_attribute_value("path", "/opt/vlc-1.1.13/cvlc")
98 # To see the stream to a ssh -X connection, the DISPLAY variable must be set to the value of the node.
99 # Also don't forget to execute in 'xhost + localhost' in the node
100 app2.set_attribute_value("env", "DISPLAY=localhost:10.0 XAUTHORITY=/root/.Xauthority")
101 app2.connector("node").connect(node2.connector("apps"))
102
103 xml = exp_desc.to_xml()
104
105 controller = ExperimentController(xml, root_dir)
106 controller.start()
107 #while not (controller.is_finished(app1.guid) and \
108 #        controller.is_finished(app2.guid)):
109 #    time.sleep(0.5)
110
111 time.sleep(10)
112
113 #controller.set(iface2.guid, "channel", "1")
114
115 #time.sleep(5)
116
117 controller.stop()
118 controller.shutdown()
119