Step 2: Move test folder to root
[integration/test.git] / csit / suites / l2switch / topologies / customtopo.py
1 # !/usr/bin/python
2
3 # usage: sudo mn --controller=remote,ip=<controller_ip> --switch=ovsk,protocols=OpenFlow13
4 #                --custom <path to customtopo.py> --topo ring ...
5
6 from mininet.topo import Topo
7
8
9 def add_hosts_to_switch(self, switch, hosts, start_host_suffix):
10     host_suffix = start_host_suffix
11     for _ in range(hosts):
12         host = self.addHost("h%s" % host_suffix)
13         self.addLink(switch, host)
14         host_suffix += 1
15
16
17 class RingTopo(Topo):
18     def __init__(self, switches=3, hosts_per_switch=1, **opts):
19         Topo.__init__(self, **opts)
20         host_suffix = 1
21         switch = self.addSwitch('s%s' % 1)
22         first_switch = switch
23         for i in range(1, switches):
24             # add hosts to switch
25             add_hosts_to_switch(self, switch, hosts_per_switch, host_suffix)
26             host_suffix += hosts_per_switch
27
28             new_switch = self.addSwitch('s%s' % (i + 1))
29             self.addLink(new_switch, switch)
30             switch = new_switch
31
32         add_hosts_to_switch(self, switch, hosts_per_switch, host_suffix)
33         self.addLink(switch, first_switch)
34
35
36 class MeshTopo(Topo):
37     def __init__(self, switches=3, hosts_per_switch=1, **opts):
38         Topo.__init__(self, **opts)
39         created_switches = []
40         host_suffix = 1
41         for i in range(switches):
42             new_switch = self.addSwitch('s%s' % (i + 1))
43
44             # add hosts to new switch
45             add_hosts_to_switch(self, new_switch, hosts_per_switch, host_suffix)
46             host_suffix += hosts_per_switch
47
48             for switch in created_switches:
49                 self.addLink(new_switch, switch)
50
51             created_switches.append(new_switch)
52
53
54 topos = {'ring': RingTopo,
55          'mesh': MeshTopo}