|
| 1 | +#!/usr/bin/python |
| 2 | +''' |
| 3 | +nctu_cs_wired_and_wireless_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 | +import mininet.ns3 |
| 14 | +from mininet.ns3 import WifiSegment |
| 15 | + |
| 16 | +CONTROLLER_IP = "192.168.59.100" |
| 17 | +CONTROLLER_PORT = 6633 |
| 18 | + |
| 19 | +SERVER_LIST = [ 'mininet1', 'mininet2' ] |
| 20 | + |
| 21 | +class NCTU_EC_Topology( Topo ): |
| 22 | + |
| 23 | + def __init__(self, core=1, agg=6, access=6, host=5, *args, **kwargs): |
| 24 | + Topo.__init__(self, *args, **kwargs) |
| 25 | + self.core_num = core |
| 26 | + self.agg_num = agg |
| 27 | + self.access_num = access |
| 28 | + self.host_num = host |
| 29 | + self.sw_id = 1 |
| 30 | + self.host_id = 1 |
| 31 | + |
| 32 | + # Init switch and host list |
| 33 | + self.core_sw_list = [] |
| 34 | + self.agg_sw_list = [] |
| 35 | + self.access_sw_list = [] |
| 36 | + self.host_list = [] |
| 37 | + |
| 38 | + self.create_top_switch( "core", self.core_num, self.core_sw_list ) |
| 39 | + |
| 40 | + self.handle_top_down( "agg", self.agg_num, self.core_sw_list, self.agg_sw_list ) |
| 41 | + self.handle_top_down( "access", self.access_num, self.agg_sw_list, self.access_sw_list ) |
| 42 | + |
| 43 | + self.handle_host( "h", self.host_num, self.host_list ) |
| 44 | + |
| 45 | + self.handle_mesh( self.agg_sw_list ) |
| 46 | + |
| 47 | + def create_top_switch( self, prefix_name, sw_num, sw_list): |
| 48 | + for i in xrange(1, sw_num+1): |
| 49 | + sw_list.append(self.addSwitch("{0}{1}".format(prefix_name, i), dpid='{0:x}'.format(self.sw_id))) |
| 50 | + self.sw_id += 1 |
| 51 | + |
| 52 | + def handle_top_down( self, prefix_name, num, top_list, down_list): |
| 53 | + temp = 0 |
| 54 | + for i in xrange(0, len(top_list)): |
| 55 | + for j in xrange(1, num+1): |
| 56 | + switch = self.addSwitch("{0}{1}".format(prefix_name, j + temp), dpid='{0:x}'.format(self.sw_id)) |
| 57 | + self.addLink(top_list[i], switch) |
| 58 | + down_list.append(switch) |
| 59 | + self.sw_id += 1 |
| 60 | + temp = j |
| 61 | + |
| 62 | + |
| 63 | + def handle_host( self, prefix_name, host_num, host_list ): |
| 64 | + for i in xrange(0, len(self.access_sw_list)): |
| 65 | + for j in xrange(0, host_num): |
| 66 | + host = self.addHost('{0}{1}'.format(prefix_name, self.host_id)) |
| 67 | + # Link to access sw |
| 68 | + self.addLink(self.access_sw_list[i], host) |
| 69 | + # Append host to list |
| 70 | + host_list.append(host) |
| 71 | + self.host_id += 1 |
| 72 | + |
| 73 | + def handle_mesh( self, sw_list ): |
| 74 | + for link in combinations(sw_list, 2): |
| 75 | + self.addLink(link[0], link[1]) |
| 76 | + |
| 77 | + |
| 78 | +def RunTestBed(): |
| 79 | + |
| 80 | + # NCTU_EC_Topology( Core Switch, Aggregate Switch, Access Switch, Host) |
| 81 | + topo = NCTU_EC_Topology(core=1, agg=3, access=3, host=2) |
| 82 | + |
| 83 | + net = MininetCluster( controller=RemoteController, topo=topo, servers=SERVER_LIST, placement=DFSPlacer, root_node="core1", tunneling="vxlan" ) |
| 84 | + net.addController( 'controller', controller=RemoteController, ip=CONTROLLER_IP, port=CONTROLLER_PORT ) |
| 85 | + |
| 86 | + wifi = WifiSegment() |
| 87 | + |
| 88 | + """ |
| 89 | + Create AP |
| 90 | + """ |
| 91 | + ap_to_access_sw = 0 |
| 92 | + for i in xrange(1): |
| 93 | + AP_NAME = "ap" + str(i) |
| 94 | + ap = net.addSwitch(AP_NAME, server=SERVER_LIST[0]) |
| 95 | + mininet.ns3.setMobilityModel(ap, None) |
| 96 | + mininet.ns3.setPosition(ap, 0, 0, 0) |
| 97 | + wifi.addAp(ap, channelNumber=6, ssid="opennet-ap", port=0) |
| 98 | + net.addLink(ap, topo.access_sw_list[ap_to_access_sw]) |
| 99 | + ap_to_access_sw += 1 |
| 100 | + |
| 101 | + """ |
| 102 | + Create Station |
| 103 | + """ |
| 104 | + STA_NAME = "sta" + str(0) |
| 105 | + sta = net.addHost(STA_NAME, server=SERVER_LIST[0]) |
| 106 | + mininet.ns3.setMobilityModel(sta, None) |
| 107 | + mininet.ns3.setPosition(sta, 0, 0, 0) |
| 108 | + wifi.addSta(sta, channelNumber=6, ssid="opennet-ap", port=0) |
| 109 | + |
| 110 | + net.start() |
| 111 | + mininet.ns3.start() |
| 112 | + |
| 113 | + """ |
| 114 | + Post Handle |
| 115 | + """ |
| 116 | + # XXX Need to fixed |
| 117 | + AP_NAME = "ap" + str(0) |
| 118 | + cmd = "ovs-vsctl add-port {0} {0}-eth0".format(AP_NAME) |
| 119 | + net.getNodeByName(AP_NAME).cmdPrint(cmd) |
| 120 | + |
| 121 | + STA_NAME = "sta" + str(0) |
| 122 | + cmd = "ip addr add 10.0.0.{0}/8 dev {1}-eth0".format(str(200+i), STA_NAME) |
| 123 | + net.getNodeByName(STA_NAME).cmdPrint(cmd) |
| 124 | + net.getNodeByName(STA_NAME).cmdPrint("ip addr show dev {0}-eth0".format(STA_NAME)) |
| 125 | + |
| 126 | + """ |
| 127 | + Show interface object in ns3 |
| 128 | + """ |
| 129 | + print("*** allTBintfs: {0}\n".format(mininet.ns3.allTBIntfs)) |
| 130 | + CLI( net ) |
| 131 | + mininet.ns3.stop() |
| 132 | + mininet.ns3.clear() |
| 133 | + net.stop() |
| 134 | + |
| 135 | +if __name__ == '__main__': |
| 136 | + setLogLevel('info') |
| 137 | + RunTestBed() |
0 commit comments