Add the robot based CSIT tool with the base edition
[integration/test.git] / test / 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 class MininetHandler(object):
9     '''
10     MininetHandler class will provide all operations about Mininet, such as config controller_ip, start or stop net.
11     '''
12     def __init__(self,controller_ip='127.0.0.1'):
13         self.controller_ip = controller_ip
14         self.net=None
15
16     def set_controller_ip(self,controller_ip):
17         self.controller_ip = controller_ip
18
19     def config_net(self):
20         net = Mininet(switch=OVSKernelSwitch,controller=RemoteController)
21
22         print '*** Adding controller'
23         net.addController('c0',ip=self.controller_ip)
24
25         print '*** Adding hosts'
26         h1 = net.addHost( 'h1', mac='00:00:00:00:00:01')
27         h2 = net.addHost( 'h2', mac='00:00:00:00:00:02')
28         h3 = net.addHost( 'h3', mac='00:00:00:00:00:03')
29         h4 = net.addHost( 'h4', mac='00:00:00:00:00:04')
30
31         print '*** Adding switch'
32         s1 = net.addSwitch( 's1' )
33         s2 = net.addSwitch( 's2' )
34         s3 = net.addSwitch( 's3' )
35
36         print '*** Creating links'
37         net.addLink(h1,s2)
38         net.addLink(h2,s2)
39         net.addLink(h3,s3)
40         net.addLink(h4,s3)
41         net.addLink(s1,s2)
42         net.addLink(s1,s3)
43
44         self.net = net
45
46     def start_net(self):
47         self.net.start()
48
49     def stop_net(self):
50         self.net.stop()