openleon-datacenter.py 3.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
# This is a test example

import unittest 
import sys 
import time
import os
import random
import subprocess
sys.path.append('.')
from time import sleep
from mininet.net import Containernet
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 openleon_datacenter_tier3 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"
		#
		print("*** Creating the datacenter topology")
		net = Containernet(topo=self.topoClass(2, 2, 4, 2), controller=self.controller, host=Host,	 
		#net = Containernet(topo=self.topoClass(2, 4, 8, 8), controller=self.controller, host=Host,
			switch=OVSSwitch, link=TCLink, waitConnected=True)

		"""Test with the dockers"""
		d1 = net.addDocker('d1', ip='10.0.0.112', dimage="ubuntu:trusty")
		d2 = net.addDocker('d2', ip='10.0.0.113', dimage="ubuntu:trusty")
		net.addLink('d1','s4')
		net.addLink('d2','s4')

		#net.link.bw=10000
		net.addNAT().configDefault()
		net.hosts[0].cmd('sysctl net.ipv4.ip_forward=1')
		print net.hosts[-1]
		print("*** End printing hosts")

		for i in range (len(net.hosts)-1):
			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('sudo ip route add 10.16.0.0/12 via 10.0.0.1')
			
		net.hosts[0].cmd('iptables -t nat -A POSTROUTING -j MASQUERADE')
		#net.hosts[-1].cmd('sudo ip route add 10.0.0.8 via 10.0.0.1')
		net.start()
		client=[]
		server=[]
		for i in range ((len(net.hosts)-1)/2):
			client.append(net.hosts[2*(i)])
			server.append(net.hosts[2*(i)+1])

		
		b= server[:]
		b_shuffle = [x for x in range(0, len(server))]
		random.shuffle(b)
		#print b
		#print b_shuffle
		
		CLI(net)
		# This open the mininet terminal and it allows to launch Mininet's commands
		
		
		

		"""for i in range (len(client)):
			b[i].cmd('iperf -s -u &')
			client[i].cmd('iperf -c ' + b[i].IP() + ' -t 10000 -i 1 -u -b 10M &')
		net.hosts[0].cmd('wireshark')"""
		
		
		"""sleep(10)	
		net.hosts[0].cmd('iperf -s &')
		net.hosts[1].cmd('iperf -c 10.0.0.1 -t 10000 -i 1 -u -b 50M &')
		net.hosts[2].cmd('iperf -s &')
		net.hosts[3].cmd('iperf -c 10.0.0.1 -t 10000 -i 1 -u -b 50M &')"""
		
		net.stop()
		#net.ping()
		
		#net.myiperf(net.hosts,10)		

class TestDatacenter_tier3(testSwitchTopo, unittest.TestCase):
	"Test the HA Root datacenter topolog"
	topoClass= MyTopo
	ryuParams= ['ryu.app.simple_switch_stp']
	mayDrop = 15

if __name__ == '__main__':
	unittest.main()