Beispiel #1
0
def TreeNet(depth=1, fanout=2, **kwargs):
    "Convenience function for creating tree networks."
    topo = TreeTopo(depth, fanout)
    return Mininet(topo=topo,
                   controller=lambda name: None,
                   xterms=True,
                   **kwargs)
def create_net(controller_ip, controller_port, topo_type, switch_type,
               nodes_per_switch, switch_num, mac):
    """Bootstrap a Mininet network using the Minimal Topology"""

    # Create an instance of our topology
    if topo_type == 'tree':
        topology = TreeTopo(depth=switch_num, fanout=nodes_per_switch)
    else:
        topology = LinearTopo(k=switch_num, n=nodes_per_switch)

    if switch_type == 'OVSKernelSwitch':
        switch = partial(OVSKernelSwitch, protocols='OpenFlow13')
    else:
        switch = partial(OVSSwitch, protocols='OpenFlow13')

    if controller_port == 'default':
        controller = lambda name: RemoteController(name, ip=controller_ip)
    else:
        controller = lambda name: RemoteController(
            name, ip=controller_ip, port=int(controller_port))

    # Create a network based on the topology, using OVS and controlled by a remote controller.
    global global_net
    global_net = Mininet(topo=topology,
                         controller=controller,
                         switch=switch,
                         autoSetMacs=mac,
                         waitConnected=True)
Beispiel #3
0
def main(argv):

    Link = RemoteGRELink
    topo = TreeTopo(depth=2, fanout=3)
    plot = False

    try:
        opts, args = getopt.getopt(argv, "hpt:", ["tunnel="])
    except getopt.GetoptError:
        print './clustertest.py -t <tunnel> -p'
        sys.exit(2)
    for opt, arg in opts:
        if opt == '-h':
            print './clustertest.py -t <tunnel(ssh|gre)> -p'
            sys.exit()
        if opt in ("-t", "--tunnel"):
            if arg in ['ssh', 'SSH']:
                Link = RemoteSSHLink
            elif arg in ['gre', 'GRE']:
                Link = RemoteGRELink
        if opt == '-p':
            plot = True

    net = MininetCluster(topo=topo,
                         servers=servers,
                         link=Link,
                         placement=SwitchBinPlacer)
    net.start()
    net.pingAll()
    if plot:
        CLI(net).do_plot()
    else:
        CLI(net)
    net.stop()
Beispiel #4
0
def run():

#    topo = NetworkTopo()
    
#    net = Mininet( topo=topo, controller=lambda name: RemoteController( name, ip='127.0.0.1' ),switch=OVSSwitch, autoSetMacs=True)
    tree4 = TreeTopo(depth=3,fanout=2)
    net = Mininet( topo=tree4, controller=lambda name: RemoteController( name, ip='127.0.0.1' ),switch=OVSSwitch, autoSetMacs=True)
    net.start()
    #CLI( net )
    secflow = None
    #pusher.set(flow1, 1)
    #pusher.set(flow2, 1)
    pusher.put(secflow,3)
    #pusher.set(flow3, 2)
    #pusher.set(allowflow, 4)
    #pusher.set(denyflow, 4)
    #time.sleep(15)
    print("-------------")
    print("starting firewall part")
    with open('ipblocklist_aggressive.csv') as csvfile:
        csv_reader = csv.reader(csvfile, delimiter=',')
        line_count = 0
        for row in csv_reader:
            if line_count == 0:
                print(f'Column names are {", ".join(row)}')
                line_count += 1
            else:
                line_count += 1
                denyflow = flow3
                denyflow["dst-ip"]=row[1]
                pusher.set(denyflow,4) 
    
    CLI(net)
    net.stop()
def make_spanning_tree(broker_depth=2):
    '''
    Construct a pseudo-spanning tree.
    '''

    tree = TreeTopo(depth=broker_depth, fanout=3)

    # Add extra nodes for publishers and subscribers to each switch without
    # hosts
    bare_switches = set(tree.switches())
    for src, dest in tree.links():
        if tree.isSwitch(src) and not tree.isSwitch(dest):
            bare_switches.discard(src)
        if tree.isSwitch(dest) and not tree.isSwitch(src):
            bare_switches.discard(dest)

    print 'bare switches: ', bare_switches

    nHost = len(tree.hosts()) + 1
    for switch in bare_switches:
        for i in xrange(3):
            host = 'h%s' % nHost
            tree.addHost(host)
            nHost = nHost + 1
            tree.addLink(host, switch)

    return tree
Beispiel #6
0
def run():
    "Create control and data networks, and invoke the CLI"

    info('* Creating Control Network\n')
    ctopo = ControlNetwork(n=4, dataController=DataController)
    cnet = Mininet(topo=ctopo,
                   ipBase='192.168.123.0/24',
                   controller=None,
                   waitConnected=True)
    info('* Adding Control Network Controller\n')
    cnet.addController('cc0', controller=Controller)
    info('* Starting Control Network\n')
    cnet.start()

    info('* Creating Data Network\n')
    topo = TreeTopo(depth=2, fanout=2)
    # UserSwitch so we can easily test failover
    sw = partial(UserSwitch, opts='--inactivity-probe=1 --max-backoff=1')
    net = Mininet(topo=topo, switch=sw, controller=None, waitConnected=True)
    info('* Adding Controllers to Data Network\n')
    for host in cnet.hosts:
        if isinstance(host, Controller):
            net.addController(host)
    info('* Starting Data Network\n')
    net.start()

    mn = MininetFacade(net, cnet=cnet)

    CLI(mn)

    info('* Stopping Data Network\n')
    net.stop()

    info('* Stopping Control Network\n')
    cnet.stop()
Beispiel #7
0
def run():
    info('* Creating Control Network\n')
    ctopo = ControlNetwork(n=4, dataController=DataController)
    cnet = Mininet(topo=ctopo, ipBase='192.168.123.0/24', controller=None)
    info('* Adding Control Network Controller\n')
    cnet.addController('cc0', controller=Controller)
    info('* Starting Control Network\n')
    cnet.start()

    info('* Creating Data Network\n')
    topo = TreeTopo(depth=2, fanout=2)
    # UserSwitch so we can easily test failover
    net = Mininet(topo=topo, switch=UserSwitch, controller=None)
    info('* Adding Controllers to Data Network\n')
    for host in cnet.hosts:
        if isinstance(host, Controller):
            net.addController(host)
    info('* Starting Data Network\n')
    net.start()

    mn = MininetFacade(net, cnet=cnet)

    # run the function passed as an argument
    CLI(mn)

    info('* Stopping Data Network\n')
    net.stop()

    info('* Stopping Control Network\n')
    # dataControllers have already been stopped -- now terminate is idempotent
    #cnet.hosts = list( set( cnet.hosts ) - set( dataControllers ) )
    cnet.stop()
Beispiel #8
0
def bwtest( cpuLimits, period_us=100000, seconds=5 ):
    """Example/test of link and CPU bandwidth limits
       cpu: cpu limit as fraction of overall CPU time"""

    topo = TreeTopo( depth=1, fanout=2 )

    results = {}

    for sched in 'rt', 'cfs':
        print '*** Testing with', sched, 'bandwidth limiting'
        for cpu in cpuLimits:
            host = custom( CPULimitedHost, sched=sched,
                           period_us=period_us,
                           cpu=cpu )
            net = Mininet( topo=topo, host=host )
            net.start()
            net.pingAll()
            hosts = [ net.getNodeByName( h ) for h in topo.hosts() ]
            client, server = hosts[ 0 ], hosts[ -1 ]
            server.cmd( 'iperf -s -p 5001 &' )
            waitListening( client, server, 5001 )
            result = client.cmd( 'iperf -yc -t %s -c %s' % (
                seconds, server.IP() ) ).split( ',' )
            bps = float( result[ -1 ] )
            server.cmdPrint( 'kill %iperf' )
            net.stop()
            updated = results.get( sched, [] )
            updated += [ ( cpu, bps ) ]
            results[ sched ] = updated

    return results
Beispiel #9
0
def testMininetCluster():
    "Test MininetCluster()"
    servers = ['localhost', 'ubuntu2']
    topo = TreeTopo(depth=3, fanout=3)
    net = MininetCluster(topo=topo, servers=servers, placement=SwitchBinPlacer)
    net.start()
    net.pingAll()
    net.stop()
Beispiel #10
0
def demo():
    "Simple Demo of Tree Topo"

    topo = TreeTopo(depth=2, fanout=3)
    net = Mininet(topo)
    net.start()
    net.pingAll()
    net.stop()
Beispiel #11
0
def demo():
    "Simple Demo of Cluster Mode"
    servers = ['localhost', 'ubuntu2', 'ubuntu3']
    topo = TreeTopo(depth=3, fanout=3)
    net = MininetCluster(topo=topo, servers=servers, placement=SwitchBinPlacer)
    net.start()
    CLI(net)
    net.stop()
def testRemoteSwitches():
    "Test with local hosts and remote switches"
    servers = [ 'localhost', 'ubuntu2']
    topo = TreeTopo( depth=4, fanout=2 )
    net = MininetCluster( topo=topo, servers=servers,
                          placement=RoundRobinPlacer )
    net.start()
    net.pingAll()
    net.stop()
Beispiel #13
0
def testMininetCluster( remote='ubuntu2', link=RemoteGRELink ):
    "Test MininetCluster()"
    servers = [ 'localhost', remote ]
    topo = TreeTopo( depth=3, fanout=3 )
    net = MininetCluster( topo=topo, servers=servers, link=link,
                          placement=SwitchBinPlacer )
    net.start()
    net.pingAll()
    net.stop()
Beispiel #14
0
def testRemoteSwitches( remote=remoteServer, link=RemoteGRELink ):
    "Test with local hosts and remote switches"
    servers = [ 'localhost', remote]
    topo = TreeTopo( depth=4, fanout=2 )
    net = MininetCluster( topo=topo, servers=servers, link=link,
                          placement=RoundRobinPlacer )
    net.start()
    net.pingAll()
    net.stop()
Beispiel #15
0
def test():
    "Test OVSNS switch"
    setLogLevel( 'info' )
    topo = TreeTopo( depth=4, fanout=2 )
    net = Mininet( topo=topo, switch=OVSSwitchNS )
    # Add connectivity to controller which is on LAN or in root NS
    # net.addNAT().configDefault()
    net.start()
    CLI( net )
    net.stop()
Beispiel #16
0
 def __init__(self, topotype='templet'):
     #        sw_count * link_count_per_sw must be even
     #        交换机与每个交换机的链路的乘积必须是一个偶数
     sw_count = 4
     link_count_per_sw = 3
     host_count = 4
     host_count_per_sw = 1
     self.server = "127.0.0.1"
     topo = TempletTopo()  #要创建的拓扑
     if 'mesh' in topotype:
         topotype = topotype[topotype.index('=') + 1:len(topotype)]
         arr = topotype.split(',')
         sw_count = int(arr[0])
         link_count_per_sw = int(arr[1])
         host_count = int(arr[2])
         host_count_per_sw = int(arr[3])
         topo = MeshTopo(sw_count=sw_count,
                         link_count_per_sw=link_count_per_sw,
                         host_count=host_count,
                         host_count_per_sw=host_count_per_sw)
     elif 'ring' in topotype:
         topotype = topotype[topotype.index('=') + 1:len(topotype)]
         arr = topotype.split(',')
         ringlength = int(arr[0])
         hostnum = int(arr[1])
         topo = RingTopo(ringlength=ringlength, hostnum=hostnum)
     elif 'fattree' in topotype:
         topotype = topotype[topotype.index('=') + 1:len(topotype)]
         arr = topotype.split(',')
         k = int(arr[0])
         density = int(arr[1])
         topo = Fattree(k, density)
         topo.createTopo()
         topo.createLink(bw_c2a=0.2, bw_a2e=0.1, bw_h2a=0.05)
     elif 'tree' in topotype:
         topotype = topotype[topotype.index('=') + 1:len(topotype)]
         arr = topotype.split(',')
         treedepth = int(arr[0])
         treefanout = int(arr[1])
         topo = TreeTopo()
         topo.build(treedepth, treefanout)
     elif 'custom' in topotype:
         topotype = topotype[topotype.index('=') + 1:len(topotype)]
         arr = topotype.split(',')
         exec 'from %s import %s' % (py, module)
         exec 'topo=%s()' % (module)
     setLogLevel('info')  #开启日志功能
     self.network = Mininet(topo=topo,
                            controller=RemoteController,
                            autoSetMacs=True,
                            link=TCLink,
                            intf=TCIntf)  #要创建的网络
     self.network.addController('qosoverlldp')  #加入控制器qosoverlldp
def main():
    #Tree topology with 7 switches with a depth of 3 and fanout of 2
    topo = TreeTopo(3, 2)
    #topo = TorusTopo(3,3)
    #controller=RemoteController('c0', ip='10.10.10.10', port=6633)
    net = Mininet(topo=topo, controller=RemoteController, switch=OVSSwitch)
    net.start()
    print "Dumping host connections"
    dumpNodeConnections(net.switches)
    dumpNodeConnections(net.hosts)
    net.pingAll()
    CLI(net)
    net.stop()
Beispiel #18
0
def limit(bw=10, cpu=.1):
    """Example/test of link and CPU bandwidth limits
       bw: interface bandwidth limit in Mbps
       cpu: cpu limit as fraction of overall CPU time"""
    intf = custom(TCIntf, bw=bw)
    myTopo = TreeTopo(depth=1, fanout=2)
    for sched in 'rt', 'cfs':
        print '*** Testing with', sched, 'bandwidth limiting'
        host = custom(CPULimitedHost, sched=sched, cpu=cpu)
        net = Mininet(topo=myTopo, intf=intf, host=host)
        net.start()
        testLinkLimit(net, bw=bw)
        net.runCpuLimitTest(cpu=cpu)
        net.stop()
Beispiel #19
0
def startNetworkWithTreeTopo():
    global net
    topo = TreeTopo(depth=2, fanout=3)
    net = Mininet(topo=topo, build=False)

    remote_ip = getControllerIP()
    info('** Adding Floodlight Controller\n')
    net.addController('c1',
                      controller=RemoteController,
                      ip=remote_ip,
                      port=6653)

    # Build the network
    net.build()
    net.start()
def test_ue1():
    # Parametros de la unidad experimental
    setLogLevel("info")
    info("Configurando unidad experimental\n")
    c_ryu = RYU('c0')
    topo_tree = TreeTopo(depth=2, fanout=2)
    ue1 = UnidadExperimental(topo=topo_tree, controller=c_ryu)
    ue1.definirNodosClaves('h1', 'h2', 'h3')
    # Iniciando mininet a partir de la unidad experimental
    info("Configurando e inicializando la red\n")
    net = Mininet(topo=ue1.getTopo(), controller=ue1.getController())
    net.start()
    net.pingAll()
    CLI(net)
    net.stop()
Beispiel #21
0
def RegularTreeNet(depth=4, fanout=2, bw=BW, cpu=-1, queue=100):
    "Create an empty network and add nodes to it."
    topo = TreeTopo(depth, fanout)
    host = custom(CPULimitedHost, cpu=cpu)
    link = custom(TCLink, bw=bw, max_queue_size=queue)
    #net = Mininet(host=host, link=link, switch=OVSKernelSwitch, controller=RemoteController, autoSetMacs=True, autoStaticArp=False)
    net = Mininet(topo,
                  host=host,
                  link=link,
                  switch=OVSKernelSwitch,
                  controller=OVSController,
                  autoSetMacs=True,
                  autoStaticArp=False)

    return net
Beispiel #22
0
def start_network():
    '''
    Start mininet network
    '''
    lg.setLogLevel('info')
    topo = TreeTopo(1, options.hosts)
    net = Mininet(topo=topo, switch=OVSBridge, controller=None, waitConnected=True)
    switch = net['s1']
    routes = ['10.0.0.0/24']
    root = Node('root', inNamespace=False)
    interface = net.addLink(root, switch).intf1
    root.setIP('10.123.123.1/32', intf=interface)
    net.start()
    for route in routes:
        root.cmd('route add -net {} dev {}'.format(route, interface))
    return net
Beispiel #23
0
 def c_build(topology: Topology):
     n = Network()
     # TODO MODULARIZE
     if topology == Topology.DEFAULT:
         pass  # TODO
     elif topology == Topology.MINIMAL:
         n.topology = MinimalTopo()
     elif topology == Topology.LINEAR:
         n.topology = LinearTopo()
     elif topology == Topology.RING:
         n.topology = RingTopo()
     elif topology == Topology.TREE:
         n.topology = TreeTopo()
     elif topology == Topology.TORUS:
         n.topology = TorusTopo()
     return n
Beispiel #24
0
def bwtest(cpuLimits, period_us=100000, seconds=10):
    """Example/test of link and CPU bandwidth limits
       cpu: cpu limit as fraction of overall CPU time"""

    topo = TreeTopo(depth=1, fanout=2)

    results = {}

    for sched in 'rt', 'cfs':
        info('*** Testing with', sched, 'bandwidth limiting\n')
        for cpu in cpuLimits:
            # cpu is the cpu fraction for all hosts, so we divide
            # it across two hosts
            host = custom(CPULimitedHost,
                          sched=sched,
                          period_us=period_us,
                          cpu=.5 * cpu)
            try:
                net = Mininet(topo=topo, host=host, waitConnected=True)
            # pylint: disable=bare-except
            except:
                info('*** Skipping scheduler %s and cleaning up\n' % sched)
                cleanup()
                break
            net.start()
            net.pingAll()
            hosts = [net.getNodeByName(h) for h in topo.hosts()]
            client, server = hosts[0], hosts[-1]
            info('*** Starting iperf with %d%% of CPU allocated to hosts\n' %
                 (100.0 * cpu))
            # We measure at the server because it doesn't include
            # the client's buffer fill rate
            popen = server.popen('iperf -yc -s -p 5001')
            waitListening(client, server, 5001)
            # ignore empty result from waitListening/telnet
            popen.stdout.readline()
            client.cmd('iperf -yc -t %s -c %s' % (seconds, server.IP()))
            result = decode(popen.stdout.readline()).split(',')
            bps = float(result[-1])
            popen.terminate()
            net.stop()
            updated = results.get(sched, [])
            updated += [(cpu, bps)]
            results[sched] = updated

    return results
Beispiel #25
0
def tree_topo_cluster():
    servers = ['mininet1', 'mininet2']
    topo = TreeTopo(depth=2, fanout=2)
    # Tunneling options: ssh (default), vxlan, gre
    net = MininetCluster(controller=RemoteController,
                         topo=topo,
                         servers=servers,
                         placement=SwitchBinPlacer,
                         tunneling="gre")
    net.addController('controller',
                      controller=RemoteController,
                      ip="192.168.59.100",
                      port=6633)
    net.start()
    net.pingAll()
    CLI(net)
    net.stop()
Beispiel #26
0
 def test_creation_of_tree_topology(self):
     try:
         topo = TreeTopo(depth=2,fanout=2)
         net = Mininet(topo=topo)
         net.start()
         ctrl = net.addController( 'onos', controller=RemoteController, ip=self.controller, port=6653)
         for switch in net.switches:
             switch.start( [ctrl] )
         response = net.pingAll()
         log.info('Pingall response is %s'%response)
         assert_equal(response,0.0)
         net.stop()
     except Exception as Error:
         log.info('Got unexpected error %s while creating topology'%Error)
         Cleanup.cleanup()
         raise
     Cleanup.cleanup()
Beispiel #27
0
def emulate(depth_, fanout_):

    # Create a network with tree topology
    tree_ = TreeTopo(depth=depth_, fanout=fanout_)

    # Initiating the Mininet instance
    net = Mininet(topo=tree_)

    # Start Execution of the Emulated System.
    net.start()

    # Name two of the instances as h1 and h2.
    h1, h2 = net.hosts[0], net.hosts[depth_]

    # Ping from an instance to another, and print the output.
    print(h1.cmd('ping -c1 %s' % h2.IP()))

    # Stop the Mininet Emulation.
    net.stop()
Beispiel #28
0
 def test_verifying_udp_bandwidth_measure_between_mininet_hosts_using_iperf(self):
     try:
         topo = TreeTopo(depth=2,fanout=2)
         net = Mininet( topo=topo, host=CPULimitedHost, link=TCLink, build=False)
         net.start()
         ctrl = net.addController( 'onos', controller=RemoteController, ip=self.controller, port=6653)
         for switch in net.switches:
             switch.start( [ctrl] )
         response = net.pingAll()
         log.info('pingAll response is %s'%response)
         bandwidth = net.iperf(l4Type = 'UDP')
         log.info('UDP Bandwidth between hosts measured using iperf is %s'%bandwidth)
         assert_equal(len(bandwidth),3)
         net.stop()
     except Exception as Error:
         log.info('Got unexpected error %s while creating topology'%Error)
         Cleanup.cleanup()
         raise
     Cleanup.cleanup()
Beispiel #29
0
def emulate(depth_, fanout_):
    # Start the MaxiNet as a Mininet cluster.
    cluster = maxinet.MininetCluster("pc1", "pc2", "pc3")
    cluster.start()

    # Emulate the network topology.
    emu = maxinet.Emulation(cluster, TreeTopo(depth_, fanout_))

    # Start Execution of the Emulated System.
    emu.setup()

    # Name two of the instances as h1 and h2.
    h1, h2 = net.hosts[0], net.hosts[depth_]

    # Ping from an instance to another, and print the output.
    print(h1.cmd('ping -c1 %s' % h2.IP()))

    # Stop the MaxiNet Emulation.
    emu.stop()
    cluster.stop()
Beispiel #30
0
    def linearToTree(self, netManager, name, ip):
        # 删除旧switch 连接
        # 作弊
        netManager.net.stop()
        netManager.net = Mininet(topo=TreeTopo(2, 4))
        netManager.net.start()
        # swicths = getattr( netManager.getNet(), 'switches')
        # cnt = 0
        # for s in swicths:
        #     cnt = cnt + 1
        #     if cnt == len(swicths):
        #         break
        #     netManager.delLink(s.name,swicths[cnt].name)
        # # 添加1个 switch
        # switchName = 's' + str(len(getattr( netManager.getNet(), 'switches')))
        # netManager.addSwitch(switchName)
        # for s in swicths:
        #     netManager.addLink(s.name, switchName)

        self.tree(netManager, name, ip)