conf-bbr_vs_cubic.py~ 4.03 KB
Newer Older
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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
import unittest 
import sys 
import time
import os
import random
import subprocess
sys.path.append('.')
from time import sleep
from mininet.net import Mininet
from mininet.node import Ryu, OVSSwitch
from mininet.node import Host
from mininet.clean import cleanup
from mininet.link import TCLink
from mininet.cli import CLI
from datacenter_mptcp import MyTopo
from mininet.term import cleanUpScreens, makeTerms


class testSwitchTopo(object):
	"Test ping with the specified topology"
	topoClass = None # Override with topology
	ryuParams = ['ryu.app.simple_switch_13']
	mayDrop = 0
	top=MyTopo(2, 2, 4, 2)


	# This is to enable the RYU controller, which enables loop-free routes that the standard SDN controller doesn't enable	
	def controller(self, name, **params):
		return Ryu(name, *self.ryuParams, **params)

	@staticmethod
	def tearDown():
		"Clean up the network"
		if sys.exc_info != (None, None, None):
			cleanup()

	

	def testPing(self):
		"Create the network and run a ping test"
		# 
		net = Mininet(topo=self.topoClass(2, 4, 8, 2), controller=self.controller, host=Host,
			switch=OVSSwitch, link=TCLink, waitConnected=True)
		#net.link.bw=10000
		net.addNAT().configDefault()
		net.addLink(net.hosts[-1],net.switches[1])
		net.hosts[0].cmd('sysctl net.ipv4.ip_forward=1')
		print net.hosts[-1]
		
		for i in range (len(net.hosts)-2):
			print(net.hosts[i+1])
			net.hosts[1+i].cmd('sudo ip route add 10.16.0.0/12 via 10.0.0.1')
			
			
		#net.hosts[-1].cmd('iptables -t nat -A POSTROUTING -j MASQUERADE')	
		net.hosts[0].cmd('iptables -t nat -A POSTROUTING -j MASQUERADE')
		
		net.start()
		CLI(net) 
		# set path manager
    		#os.system('sysctl -w net.mptcp.mptcp_path_manager=fullmesh')
    		# set scheduler
    		#os.system('sysctl -w net.mptcp.mptcp_scheduler=default')
		
		client=[]
		server=[]
		for i in range ((len(net.hosts)-2)/2):
			client.append(net.hosts[2*(i+1)])
			server.append(net.hosts[2*(i)+1])

		
		b= server[:]
		random.shuffle(b)
		
		for i in range (len(net.hosts)-1):
			net.hosts[i].cmd('wireshark &')
		
		

		# This open the mininet terminal and it allows to launch Mininet's commands
		CLI(net) 
		
		puerto = 3000
		n=0
		m=0
		n1=0
		u=0
		v=0
		r=0
		t_trafico=time.time()
		t_UE=time.time()
		t_ciclo=0

		for i in range(5250):
			r+=1
			t_ciclo=time.time()
			trafico1=random.randint(0, len(client)-1)
			trafico2=random.randint(0, len(net.hosts)-1)
			x1= random.random()
			x2= random.random()
			random.shuffle(b)
			tempo_trafico=random.expovariate(0.01)/1000
			tempo_UE=random.expovariate(0.01)/1000
			
			b[trafico1].cmd('iperf -s -p ' + str(puerto) + ' & ')
			ip= str(b[trafico1].IP).split('-eth0:')
			aux= ip[1].find(',')
			ip=ip[1][0:aux]

			if(time.time()-t_UE>=tempo_UE and m<100 and u>20):
				m=m+1
				v=v+1
				if (x2<0.8 and n1<80):
					y= random.randint(100, 10000)
					net.hosts[trafico2].cmd('iperf -c 10.16.0.2' + ' -n'+ str(y)+ ' -M 1400 &')
					n1+=1
					t_UE=time.time()
				
				else:
					y=random.randint(10000, 10000000)
					net.hosts[trafico2].cmd('iperf -c 10.16.0.2'+ ' -n '+ str(y)+ '-M 1400 &')
					t=UE=time.time()

			if (time.time()-t_trafico>=tempo_trafico):
				u=u+1
				if (x1<0.8 and n<900):
					y= random.randint(100, 10000)
					client[trafico1].cmd('iperf -c '+ str(ip) + ' -n '+ str(y)+ ' -p '+ str(puerto)+ ' &')
					puerto+=1
					n+=1
					t_trafico=time.time()
				else:
					y=random.randint(10000, 10000000)
					client[trafico1].cmd('iperf -c '+ str(ip) + ' -n '+ str(y)+ ' -p '+ str(puerto)+ ' &')
					puerto+=1
					t_trafico=time.time()
			time.sleep(0.003)
			print('u ' +str(u)+ ' v ' + str(v)+ 'r' +str(r))

		print(n1)
		print(n)	
		print(u)
		print(v)		
		
		CLI(net) 
		net.stop()
		
		

		

		

class TestDatacenter_tier3(testSwitchTopo, unittest.TestCase):
	"Test the HA Root datacenter topolog"
	topoClass= MyTopo
	ryuParams= ['ryu.app.simple_switch_stp']
	mayDrop = 15
	# enable MPTCP
	#os.system('sysctl -w net.mptcp.mptcp_enabled=0')
    	#enable debug output, execute "dmesg" to read output
    	#os.system('sysctl -w net.mptcp.mptcp_debug=0')
if __name__ == '__main__':
	unittest.main()