-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathweb_mirror_replay.py
110 lines (96 loc) · 4.28 KB
/
web_mirror_replay.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
#!/usr/bin/python
from mininet.cli import CLI
from mininet.log import lg
from mininet.node import Node
from mininet.topolib import TreeNet
from mininet.topo import Topo
from mininet.net import Mininet
from mininet.node import Host
from mininet.link import Link
from mininet.node import OVSController
import os
import sys
sharded_servers = sys.argv[1]
ip_addr=[]
for server in open(sharded_servers):
ip_addr.append(server.strip())
site_to_fetch=sys.argv[2]
phantomjs=sys.argv[3]
quic_path=sys.argv[4]
cc=sys.argv[5]
browser=sys.argv[6]
#################################
class ProtoTester(Topo):
def __init__(self):
# Initialise topology
Topo.__init__(self)
# Create switch
s1 = self.addSwitch('s1')
# IP for client
client = self.addHost('client', ip='10.0.1.1', mac='00:00:00:00:00:01')
self.addLink(client, s1)
# IPs for sharded servers
server_list = []
for i in range(0,len(ip_addr)):
if i < 8:
server_list.append(self.addHost('server'+str(i), ip=ip_addr[i], mac='00:00:00:00:00:0'+str(i+2)))
if i > 7:
server_list.append(self.addHost('server'+str(i), ip=ip_addr[i], mac='00:00:00:00:00:'+str(i+2)))
# Add links
self.addLink(s1, server_list[i])
if __name__ == '__main__':
lg.setLogLevel( 'info')
# Configure and start NATted connectivity
os.system( "killall -q controller" )
os.system( "killall -q phantomjs" )
os.system( "/etc/init.d/apache2 stop" )
os.system( "killall -s9 apache2" )
os.system( "killall -s9 quic_server" )
os.system( "rm -rf /home/vagrant/prof" )
topo = ProtoTester()
net = Mininet(topo=topo, host=Host, link=Link, controller=OVSController)
net.start()
# Set /32 netmask and route for client
client = net.getNodeByName('client')
client.sendCmd('ifconfig client-eth0 10.0.1.1 netmask 0.0.0.0')
client.waitOutput()
client.sendCmd('route add default dev client-eth0')
client.waitOutput()
# Set /32 netmask and route for all serversi
server_names = ['']*len(ip_addr)
for i in range(0,len(ip_addr)):
server_names[i] = net.getNodeByName('server'+str(i))
server_names[i].sendCmd('ifconfig server'+str(i)+'-eth0 '+ip_addr[i]+' netmask 0.0.0.0');
server_names[i].waitOutput()
server_names[i].sendCmd('route add default dev server'+str(i)+'-eth0')
server_names[i].waitOutput()
print cc
if cc == 'cubic':
print 'here'
server_names[i].cmdPrint('apache2ctl -f /etc/apache2/apache2.conf ')
server_names[i].waitOutput()
elif cc == 'quic':
quic_folder = site_to_fetch.split('http://')[1]
server_names[i].cmdPrint('nohup ' + quic_path + '/quic_server --quic_in_memory_cache_dir0=' + quic_path + '/' + quic_folder + ' --port=80 --ip=' + ip_addr[i] + ' > /tmp/quic_server' + str(i)+'.stdout 2> /tmp/quic_server' + str(i) +'.stderr &')
else:
exit(5)
server_names[i].waitOutput()
print "*** Hosts are running and can talk to each other"
print "*** Type 'exit' or control-D to shut down network"
client.cmdPrint('/usr/sbin/dnsmasq -x /var/run/dnsmasq.pid -7 /etc/dnsmasq.d,.dpkg-dist,.dpkg-old,.dpkg-new -8 /var/dnsmasq.log -k --log-queries --except-interface eth1 &')
client.waitOutput()
if cc == 'cubic':
if browser == 'phantomjs':
client.cmdPrint(phantomjs+'/bin/phantomjs '+ phantomjs + "/examples/loadspeed.js " +site_to_fetch);
client.cmdPrint(phantomjs+'/bin/phantomjs '+ phantomjs + "/examples/loadspeed.js " +site_to_fetch);
elif browser == 'chrome':
client.cmdPrint('su vagrant -c"PATH=$PATH:/home/vagrant/chrome-checkout-clean/src/out/Release:/home/vagrant/depot_tools CHROME_DEVEL_SANDBOX=/usr/local/sbin/chrome-devel-sandbox python load_google.py '+ quic_path+'/chrome ' + site_to_fetch+ ' ' + cc+'"')
else:
exit(5)
client.waitOutput()
elif cc == 'quic':
client.cmdPrint('su vagrant -c"PATH=$PATH:/home/vagrant/chrome-checkout-clean/src/out/Release:/home/vagrant/depot_tools CHROME_DEVEL_SANDBOX=/usr/local/sbin/chrome-devel-sandbox python load_google.py '+ quic_path+'/chrome ' + site_to_fetch+ ' ' + cc+'"')
#client.cmdPrint('su vagrant -c"python load_google.py "')
else:
exit(5)
CLI( net )