|
| 1 | +#!/usr/bin/python |
| 2 | +''' |
| 3 | +nctu_cs_wired_topo.gy |
| 4 | +''' |
| 5 | + |
| 6 | +from mininet.cluster.net import MininetCluster |
| 7 | +from mininet.cluster.placer import DFSPlacer |
| 8 | +from mininet.log import setLogLevel |
| 9 | +from mininet.cluster.cli import ClusterCLI as CLI |
| 10 | +from mininet.node import Controller, RemoteController |
| 11 | +from mininet.topo import Topo |
| 12 | +from itertools import combinations |
| 13 | + |
| 14 | +CONTROLLER_IP = "192.168.59.100" |
| 15 | +CONTROLLER_PORT = 6633 |
| 16 | +SERVER_LIST = [ 'mininet1', 'mininet2' ] |
| 17 | + |
| 18 | +class NCTU_EC_Topology( Topo ): |
| 19 | + |
| 20 | + def __init__(self, core=1, agg=6, access=6, host=5, *args, **kwargs): |
| 21 | + Topo.__init__(self, *args, **kwargs) |
| 22 | + self.core_num = core |
| 23 | + self.agg_num = agg |
| 24 | + self.access_num = access |
| 25 | + self.host_num = host |
| 26 | + self.sw_id = 1 |
| 27 | + self.host_id = 1 |
| 28 | + |
| 29 | + # Init switch and host list |
| 30 | + self.core_sw_list = [] |
| 31 | + self.agg_sw_list = [] |
| 32 | + self.access_sw_list = [] |
| 33 | + self.host_list = [] |
| 34 | + |
| 35 | + self.create_top_switch( "core", self.core_num, self.core_sw_list ) |
| 36 | + |
| 37 | + self.handle_top_down( "agg", self.agg_num, self.core_sw_list, self.agg_sw_list ) |
| 38 | + self.handle_top_down( "access", self.access_num, self.agg_sw_list, self.access_sw_list ) |
| 39 | + |
| 40 | + self.handle_host( "h", self.host_num, self.host_list ) |
| 41 | + |
| 42 | + self.handle_mesh( self.agg_sw_list ) |
| 43 | + |
| 44 | + def create_top_switch( self, prefix_name, sw_num, sw_list): |
| 45 | + for i in xrange(1, sw_num+1): |
| 46 | + sw_list.append(self.addSwitch("{0}{1}".format(prefix_name, i), dpid='{0:x}'.format(self.sw_id))) |
| 47 | + self.sw_id += 1 |
| 48 | + |
| 49 | + def handle_top_down( self, prefix_name, num, top_list, down_list): |
| 50 | + temp = 0 |
| 51 | + for i in xrange(0, len(top_list)): |
| 52 | + for j in xrange(1, num+1): |
| 53 | + switch = self.addSwitch("{0}{1}".format(prefix_name, j + temp), dpid='{0:x}'.format(self.sw_id)) |
| 54 | + self.addLink(top_list[i], switch) |
| 55 | + down_list.append(switch) |
| 56 | + self.sw_id += 1 |
| 57 | + temp = j |
| 58 | + |
| 59 | + |
| 60 | + def handle_host( self, prefix_name, host_num, host_list ): |
| 61 | + for i in xrange(0, len(self.access_sw_list)): |
| 62 | + for j in xrange(0, host_num): |
| 63 | + host = self.addHost('{0}{1}'.format(prefix_name, self.host_id)) |
| 64 | + # Link to access sw |
| 65 | + self.addLink(self.access_sw_list[i], host) |
| 66 | + # Append host to list |
| 67 | + host_list.append(host) |
| 68 | + self.host_id += 1 |
| 69 | + |
| 70 | + def handle_mesh( self, sw_list ): |
| 71 | + for link in combinations(sw_list, 2): |
| 72 | + self.addLink(link[0], link[1]) |
| 73 | + |
| 74 | +def RunTestBed(): |
| 75 | + |
| 76 | + # NCTU_EC_Topology( Core Switch, Aggregate Switch, Access Switch, Host) |
| 77 | + topo = NCTU_EC_Topology(core=1, agg=6, access=6, host=20) |
| 78 | + |
| 79 | + net = MininetCluster( controller=RemoteController, topo=topo, servers=SERVER_LIST, placement=DFSPlacer, root_node="core1", tunneling="vxlan" ) |
| 80 | + net.addController( 'controller', controller=RemoteController, ip=CONTROLLER_IP, port=CONTROLLER_PORT ) |
| 81 | + net.start() |
| 82 | + CLI( net ) |
| 83 | + net.stop() |
| 84 | + |
| 85 | + |
| 86 | +if __name__ == '__main__': |
| 87 | + setLogLevel('info') |
| 88 | + RunTestBed() |
0 commit comments