コード例 #1
0
def emptyNet():

    "Create an empty network and add nodes to it."

    net = Mininet( controller=Controller)

    info( '*** Adding controller\n' )
    ctrlRemote = RemoteController( 'c0', ip=ipControladorOF )
    net.addController(ctrlRemote)
    info('--> remote IP controller - c0:' + ctrlRemote.IP() +'\n')
    
    #ctrlLocal = RemoteController('c1', port=6633, ip="127.0.0.1")
    ctrlLocal = Controller('c1', port=6634)
    net.addController(ctrlLocal)
    info('--> local IP controller - c1:' + ctrlLocal.IP() +'\n')
    
    
    
    info( '*** Adding hosts\n' )
    lanH1 = net.addHost('h1', ip='10.0.0.1')
    lanH2 = net.addHost('h2', ip='10.0.0.2')
    lanIDS = net.addHost('h3', ip='10.0.0.3')
    lanRouter = net.addHost('h4')
    wanH1 = net.addHost('h5', ip='192.168.0.5')
    wanH2 = net.addHost('h6', ip='192.168.0.6')

    info( '*** Adding switch\n' )
    lanSw = net.addSwitch('s1')
    wanSw = net.addSwitch('s2')

    info( '*** Creating links\n' )
    net.addLink(lanH1, lanSw)
    net.addLink(lanH2, lanSw)
    net.addLink(lanIDS, lanSw)
    net.addLink(lanRouter, lanSw)
    net.addLink(lanRouter, wanSw)
    net.addLink(wanH1, wanSw)
    net.addLink(wanH2, wanSw)

    info( '*** Starting network\n')
    net.start()
    
    info('*** Starting controllers and switches')
    #link remote controller to s0 internal network swith
    ctrlRemote.start()
    #use remote controller
    lanSw.start([ctrlRemote])
    
    #use local controller
    #info('\n\n\n************ using local controller for swLAN')
    #lanSw.start([ctrlLocal])
    
    #start local controller to switch from s1 external network
    ctrlLocal.start()
    wanSw.start([ctrlLocal])
    
    info( '*** Executing hosts scripts\n')
    execCmds(net)
    
    sleep(5) # wai 5 seconds to start IDS!
    
    #log tests in files, the name of file and directory will be composed by date/time of start execution of test
    hst1 = net.getNodeByName('h1')
    hst1.cmdPrint('mkdir /var/log/tcpdump/'+date)
    arquivo = open('/var/log/tcpdump/'+date+'/teste.txt', 'w')
    textoTeste = """
    Test -
    \n Begin at:\n
    """
    data = datetime.datetime.now()
    textoTeste=textoTeste+"%s/%s/%s as %s:%s:%s:%s\n"%(data.year,data.month,data.day,data.hour,data.minute,data.second,data.microsecond)
    arquivo.write(textoTeste)
    
    ### Tests
    
    #
    # Start the testes here!
    #
    # Select the test to run. For that uncomment the line of the desired test.
	   
    info( '*** Executing Tests\n')
    textoTeste = textoTeste =teste1(net)
    #textoTeste = testeIperf(net)
    #textoTeste = testeIDSWakeupExternoInterno(net)
    #textoTeste = testeDDoSExtInt(net)
    #textoTeste = testeDDoSIntExt(net)
    #textoTeste = testeDDoSIntInt(net)
    
    # record attack test!
    textoTeste = textoTeste+"""
     
    put comment of test here
    
    """
    
    arquivo.write(textoTeste)

    ### end of test!
    
    # register the time that test was finished
    data = datetime.datetime.now()
    textoTeste=' \nFinished at:\n '+"%s/%s/%s as %s:%s:%s:%s\n"%(data.year,data.month,data.day,data.hour,data.minute,data.second,data.microsecond)
    arquivo.write(textoTeste)
    arquivo.close()

    info( '*** Running CLI\n' )
    #Uncomment below line for execute the test with CLI console
    #CLI( net )
    sleep(5)
    info('*** Stoping IDS process\n')
    desligarIDS(net,'h3')
    #thIds.join()

    info( '*** Stopping network\n' )
    lanSw.stop()
    ctrlRemote.stop()

    net.stop() 
    exit()
コード例 #2
0
#		intf.link.intf1 = None

l2 = Link(s2, h0, s2.newPort(), 0)

h0.setIP('10.1.0.1/16')
h0.setMAC(temp.mac)
h0.intfList()[0].mac = temp.mac
h0.intfList()[0].ip = temp.ip

print s2.cmd('ovs-vsctl add-port s2 s2-eth3')
print '**********'
print h0.cmd('ifconfig')

dumpNodeConnections([s0, s1, s2, s3, h0, h1, h2, h3])
#output('%s\n' % repr(h0))
#makeTerms([s2],'xterm')

string = raw_input()
while string != 'exit':
    string = raw_input()

s0.stop()
s1.stop()
s2.stop()
s3.stop()

c0.stop()
c1.stop()
c2.stop()
c3.stop()
コード例 #3
0
#		intf.link.intf1 = None

l2 = Link(s2,h0,s2.newPort(),0)

h0.setIP( '10.1.0.1/16' )
h0.setMAC(temp.mac)
h0.intfList()[0].mac = temp.mac
h0.intfList()[0].ip = temp.ip

print s2.cmd('ovs-vsctl add-port s2 s2-eth3')
print '**********'
print h0.cmd('ifconfig')

dumpNodeConnections([s0,s1,s2,s3,h0,h1,h2,h3])
#output('%s\n' % repr(h0))
#makeTerms([s2],'xterm')

string = raw_input()
while string != 'exit':
    string = raw_input()

s0.stop()
s1.stop()
s2.stop()
s3.stop()

c0.stop() 
c1.stop()
c2.stop()
c3.stop()
コード例 #4
0
ファイル: killRyu.py プロジェクト: yagorezende/MLProvide
from mininet.net import Mininet
from mininet.node import Controller, RemoteController, UserSwitch
from mininet.clean import cleanup
"""
This script kills local Ryu execution
"""

SERVER_IP = 'localhost'
ryu = RemoteController('ame', ip=SERVER_IP, port=6633)
net = Mininet(controller=ryu)
net.start()
net.stop()
cleanup()
ryu.stop()