95f33db2de8c9385155dc493559f0ddcb79c7f5f
[integration/test.git] / tools / Robot_Tool / libraries / MininetHandler.py
1 """
2 Library for the robot based system test tool of the OpenDaylight project.
3 Authors: Baohua Yang@IBM, Denghui Huang@IBM
4 Updated: 2013-11-18
5 """
6 from mininet.net import Mininet
7
8
9 class MininetHandler(object):
10     '''
11     MininetHandler class will provide all operations about Mininet, such as config controller_ip, start or stop net.
12     '''
13     def __init__(self, controller_ip='127.0.0.1'):
14         self.controller_ip = controller_ip
15         self.net = None
16
17     def set_controller_ip(self, controller_ip):
18         self.controller_ip = controller_ip
19
20     def config_net(self):
21         net = Mininet(switch=OVSKernelSwitch, controller=RemoteController)  # noqa
22
23         print '*** Adding controller'
24         net.addController('c0', ip=self.controller_ip)
25
26         print '*** Adding hosts'
27         h1 = net.addHost('h1', mac='00:00:00:00:00:01')
28         h2 = net.addHost('h2', mac='00:00:00:00:00:02')
29         h3 = net.addHost('h3', mac='00:00:00:00:00:03')
30         h4 = net.addHost('h4', mac='00:00:00:00:00:04')
31
32         print '*** Adding switch'
33         s1 = net.addSwitch('s1')
34         s2 = net.addSwitch('s2')
35         s3 = net.addSwitch('s3')
36
37         print '*** Creating links'
38         net.addLink(h1, s2)
39         net.addLink(h2, s2)
40         net.addLink(h3, s3)
41         net.addLink(h4, s3)
42         net.addLink(s1, s2)
43         net.addLink(s1, s3)
44
45         self.net = net
46
47     def start_net(self):
48         self.net.start()
49
50     def stop_net(self):
51         self.net.stop()