f5941f1ffb4278d474cdee34a19e5de327e78d31
[nepi.git] / examples / openvswitch / ping_over_udpTapTunnel_performance_test_triangleTopo.py
1 #!/usr/bin/env python
2 #
3 #    NEPI, a framework to manage network experiments
4 #    Copyright (C) 2013 INRIA
5 #
6 #    This program is free software: you can redistribute it and/or modify
7 #    it under the terms of the GNU General Public License as published by
8 #    the Free Software Foundation, either version 3 of the License, or
9 #    (at your option) any later version.
10 #
11 #    This program is distributed in the hope that it will be useful,
12 #    but WITHOUT ANY WARRANTY; without even the implied warranty of
13 #    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 #    GNU General Public License for more details.
15 #
16 #    You should have received a copy of the GNU General Public License
17 #    along with this program.  If not, see <http://www.gnu.org/licenses/>.
18 #
19 # Authors :  Julien Tribino <julien.tribino@inria.fr>
20 #          Alina Quereilhac <alina.quereilhac@inria.fr>
21 #
22 # Topology :
23 #
24 #                  Host3
25 #                    |
26 #                    |
27 #                    |   
28 #                 Switch3                         
29 #                 /    \          
30 #                /      \                
31 #               /        \              
32 #              /          \             
33 #         Switch1 ----- Switch2         
34 #            /              \           
35 #           /                \          
36 #          /                  \         
37 #       Host1                Host2   
38
39 from nepi.execution.ec import ExperimentController 
40
41 import os
42 import time
43
44 ### Useful Method to Create RM ##
45 def add_node(ec, host, user):
46     node = ec.register_resource("PlanetlabNode")
47     ec.set(node, "hostname", host)
48     ec.set(node, "username", user)
49     ec.set(node, "cleanHome", True)
50     ec.set(node, "cleanProcesses", True)
51     return node
52
53 def add_tap(ec, endpoint_ip, endpoint_prefix, pointopoint, node):
54     tap = ec.register_resource("PlanetlabTap")
55     ec.set(tap, "endpoint_ip", endpoint_ip)
56     ec.set(tap, "endpoint_prefix", endpoint_prefix)
57     ec.set(tap, "pointopoint", pointopoint)
58     ec.set(tap, "up", True)
59     ec.register_connection(tap, node)
60     return tap
61
62 def add_udptun(ec, tap1, tap2):
63     udptun = ec.register_resource("UdpTunnel")
64     ec.register_connection(tap1, udptun)
65     ec.register_connection(tap2, udptun)
66     return udptun
67
68 def add_vroute(ec, network, tap):
69     vroute = ec.register_resource("PlanetlabVroute")
70     ec.set(vroute, "action", "add")
71     ec.set(vroute, "network", network)
72     ec.register_connection(vroute, tap)
73     return vroute
74
75 def add_app(ec, command, node):
76     app = ec.register_resource("LinuxApplication")
77     ec.set(app, "command", command)
78     ec.register_connection(app, node)
79     return app
80
81 ### Data that can be changed ###
82 user = "inria_nepi"
83
84 hostname_switch1 = "planetlab2.virtues.fi"
85 hostname_switch2 = "planetlab2.upc.es"
86 hostname_switch3 = "planetlab2.cs.aueb.gr"
87 hostname_host1 = "planetlab2.ionio.gr"
88 hostname_host2 = "iraplab2.iralab.uni-karlsruhe.de"
89 hostname_host3 = "planetlab2.diku.dk"
90
91
92 ### Start Experiment ###
93 ec = ExperimentController(exp_id = "test-tap-tunnel")
94      
95 ## Create The topology ##   
96 host1 = add_node(ec, hostname_host1, user)
97 tap1 = add_tap(ec, "192.168.3.1", 24, "192.168.3.2", host1)
98
99 switch1 = add_node(ec, hostname_switch1, user)
100 tap2 = add_tap(ec, "192.168.3.2", 24, "192.168.3.1", switch1)
101 tap102 = add_tap(ec, "192.168.3.102", 29, "192.168.3.104", switch1)
102 tap152 = add_tap(ec, "192.168.3.152", 29, "192.168.3.156", switch1)
103
104 host2 = add_node(ec, hostname_host2, user)
105 tap13 = add_tap(ec, "192.168.3.13", 24, "192.168.3.14", host2)
106
107 switch2 = add_node(ec, hostname_switch2, user)
108 tap14 = add_tap(ec, "192.168.3.14", 24, "192.168.3.13", switch2)
109 tap104 = add_tap(ec, "192.168.3.104", 29, "192.168.3.102", switch2)
110 tap204 = add_tap(ec, "192.168.3.204", 29, "192.168.3.206", switch2)
111
112 host3 = add_node(ec, hostname_host3, user)
113 tap25 = add_tap(ec, "192.168.3.25", 24, "192.168.3.26", host3)
114
115 switch3 = add_node(ec, hostname_switch3, user)
116 tap26 = add_tap(ec, "192.168.3.26", 24, "192.168.3.25", switch3)
117 tap156 = add_tap(ec, "192.168.3.156", 29, "192.168.3.152", switch3)
118 tap206 = add_tap(ec, "192.168.3.206", 29, "192.168.3.204", switch3)
119
120 ## Create the UDP Tunnel ## 
121 udptun1 = add_udptun(ec, tap1, tap2)
122 udptun2 = add_udptun(ec, tap13, tap14)
123 udptun3 = add_udptun(ec, tap25, tap26)
124
125 udptun4 = add_udptun(ec, tap102, tap104)
126 udptun5 = add_udptun(ec, tap152, tap156)
127 udptun6 = add_udptun(ec, tap204, tap206)
128
129 ## Create the PlanetLab Route ## 
130 vroute1 = add_vroute(ec, "192.168.3.0", tap1)
131 vroute2 = add_vroute(ec, "192.168.3.0", tap13)
132 vroute3 = add_vroute(ec, "192.168.3.0", tap25)
133
134 vroute7 = add_vroute(ec, "192.168.3.8", tap102)
135 vroute8 = add_vroute(ec, "192.168.3.0", tap104)
136 vroute9 = add_vroute(ec, "192.168.3.24", tap152)
137 vroute10 = add_vroute(ec, "192.168.3.0", tap156)
138 vroute11 = add_vroute(ec, "192.168.3.24", tap204)
139 vroute12 = add_vroute(ec, "192.168.3.8", tap206)
140
141 ## Create all the Ping ## 
142
143 app1 = add_app(ec, "ping -c8 192.168.3.13", host1)
144 app2 = add_app(ec, "ping -c8 192.168.3.25", host1)
145 app3 = add_app(ec, "ping -c8 192.168.3.104", host1)
146 app4 = add_app(ec, "ping -c8 192.168.3.156", host1)
147 app5 = add_app(ec, "ping -c8 192.168.3.2", host1)
148
149 app11 = add_app(ec, "ping -c8 192.168.3.1", host2)
150 app12 = add_app(ec, "ping -c8 192.168.3.25", host2)
151 app13 = add_app(ec, "ping -c8 192.168.3.102", host2)
152 app14 = add_app(ec, "ping -c8 192.168.3.206", host2)
153 app15 = add_app(ec, "ping -c8 192.168.3.14", host2)
154
155 app21 = add_app(ec, "ping -c8 192.168.3.1", host3)
156 app22 = add_app(ec, "ping -c8 192.168.3.13", host3)
157 app23 = add_app(ec, "ping -c8 192.168.3.152", host3)
158 app24 = add_app(ec, "ping -c8 192.168.3.204", host3)
159 app25 = add_app(ec, "ping -c8 192.168.3.26", host3)
160
161 ec.deploy()
162
163 ec.wait_finished([app1 ,app2, app3, app4, app5, app11 ,app12, app13, app14, app15, app21 ,app22, app23, app24, app25])
164
165 # Retreive ping results and save
166 # them in a file
167 ping1 = ec.trace(app1, 'stdout')
168 ping2 = ec.trace(app2, 'stdout')
169 ping3 = ec.trace(app3, 'stdout')
170 ping4 = ec.trace(app4, 'stdout')
171 ping5 = ec.trace(app5, 'stdout')
172 ping11 = ec.trace(app11, 'stdout')
173 ping12 = ec.trace(app12, 'stdout')
174 ping13 = ec.trace(app13, 'stdout')
175 ping14 = ec.trace(app14, 'stdout')
176 ping15 = ec.trace(app15, 'stdout')
177 ping21 = ec.trace(app21, 'stdout')
178 ping22 = ec.trace(app22, 'stdout')
179 ping23 = ec.trace(app23, 'stdout')
180 ping24 = ec.trace(app24, 'stdout')
181 ping25 = ec.trace(app25, 'stdout')
182
183 f = open("examples/openvswitch/ping_over_udpTapTunnel_performance_test.txt", 'w')
184
185 if not ping25:
186   ec.shutdown()
187   
188
189 f.write("************ Ping From Host 1 : 192.168.3.1 ********************\n\n")
190 f.write(ping1)
191 f.write("----------------------------------------\n\n")
192 f.write(ping2)
193 f.write("----------------------------------------\n\n")
194 f.write(ping3)
195 f.write("----------------------------------------\n\n")
196 f.write(ping4)
197 f.write("----------------------------------------\n\n")
198 f.write(ping5)
199 f.write("************ Ping From Host 2 : 192.168.3.13 ********************\n\n")
200 f.write(ping11)
201 f.write("----------------------------------------\n\n")
202 f.write(ping12)
203 f.write("----------------------------------------\n\n")
204 f.write(ping13)
205 f.write("----------------------------------------\n\n")
206 f.write(ping14)
207 f.write("----------------------------------------\n\n")
208 f.write(ping15)
209 f.write("************ Ping From Host 3 : 192.168.3.25 ********************\n\n")
210 f.write(ping21)
211 f.write("----------------------------------------\n\n")
212 f.write(ping22)
213 f.write("----------------------------------------\n\n")
214 f.write(ping23)
215 f.write("----------------------------------------\n\n")
216 f.write(ping24)
217 f.write("----------------------------------------\n\n")
218 f.write(ping25)
219
220 f.close()
221
222 # Delete the overlay network
223 ec.shutdown()
224
225
226
227
228