Exemple #1
0
def sshd(network,
         cmd='/usr/sbin/sshd',
         opts='-D',
         ip='10.123.123.1/32',
         routes=None,
         switch=None):
    """Start a network, connect it to root ns, and run sshd on all hosts.
       ip: root-eth0 IP address in root namespace (10.123.123.1/32)
       routes: Mininet host networks to route to (10.0/24)
       switch: Mininet switch to connect to root namespace (s1)"""
    if not switch:
        switch = network['s1']  # switch to use
    if not routes:
        routes = ['10.0.0.0/24']
    connectToRootNS(network, switch, ip, routes)
    for host in network.hosts:
        host.cmd(cmd + ' ' + opts + '&')
    print "*** Waiting for ssh daemons to start"
    for server in network.hosts:
        waitListening(server=server, port=22, timeout=5)

    print
    print "*** Hosts are running sshd at the following addresses:"
    print
    for host in network.hosts:
        print host.name, host.IP()
    print
    print "*** Type 'exit' or control-D to shut down network"
    CLI(network)
    for host in network.hosts:
        host.cmd('kill %' + cmd)
    network.stop()
Exemple #2
0
def runMultiLink():
    "Create and run multiple link network"
    topo = simpleMultiLinkTopo(n=2)
    net = Mininet(topo=topo)
    net.start()
    CLI(net)
    net.stop()
Exemple #3
0
def run():
    "Create network and run the CLI"
    topo = InternetTopo()
    net = Mininet(topo=topo)
    net.start()
    CLI(net)
    net.stop()
Exemple #4
0
def emptyNet():

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

    net = Mininet(controller=Controller)

    info('*** Adding controller\n')
    net.addController('c0')

    info('*** Adding hosts\n')
    h1 = net.addHost('h1', ip='10.0.0.1')
    h2 = net.addHost('h2', ip='10.0.0.2')

    info('*** Adding switch\n')
    s3 = net.addSwitch('s3')

    info('*** Creating links\n')
    net.addLink(h1, s3)
    net.addLink(h2, s3)

    info('*** Starting network\n')
    net.start()

    info('*** Running CLI\n')
    CLI(net)

    info('*** Stopping network')
    net.stop()
Exemple #5
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)
    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)
    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()
Exemple #6
0
def exampleCustomTags():
    """Simple example that exercises VLANStarTopo"""

    net = Mininet(topo=VLANStarTopo())
    net.start()
    CLI(net)
    net.stop()
Exemple #7
0
def exampleAllHosts(vlan):
    """Simple example of how VLANHost can be used in a script"""
    # This is where the magic happens...
    host = partial(VLANHost, vlan=vlan)
    # vlan (type: int): VLAN ID to be used by all hosts

    # Start a basic network using our VLANHost
    topo = SingleSwitchTopo(k=2)
    net = Mininet(host=host, topo=topo)
    net.start()
    CLI(net)
    net.stop()
Exemple #8
0
def testHostWithPrivateDirs():
    "Test bind mounts"
    topo = SingleSwitchTopo( 10 )
    privateDirs = [ ( '/var/log', '/tmp/%(name)s/var/log' ),
                    ( '/var/run', '/tmp/%(name)s/var/run' ),
                      '/var/mn' ]
    host = partial( Host,
                    privateDirs=privateDirs )
    net = Mininet( topo=topo, host=host )
    net.start()
    directories = [ directory[ 0 ] if isinstance( directory, tuple )
                    else directory for directory in privateDirs ]
    info( 'Private Directories:', directories, '\n' )
    CLI( net )
    net.stop()
Exemple #9
0
def multiControllerNet():
    "Create a network from semi-scratch with multiple controllers."

    net = Mininet(controller=Controller, switch=OVSSwitch)

    print "*** Creating (reference) controllers"
    c1 = net.addController('c1', port=6633)
    c2 = net.addController('c2', port=6634)

    print "*** Creating switches"
    s1 = net.addSwitch('s1')
    s2 = net.addSwitch('s2')

    print "*** Creating hosts"
    hosts1 = [net.addHost('h%d' % n) for n in 3, 4]
    hosts2 = [net.addHost('h%d' % n) for n in 5, 6]

    print "*** Creating links"
    for h in hosts1:
        net.addLink(s1, h)
    for h in hosts2:
        net.addLink(s2, h)
    net.addLink(s1, s2)

    print "*** Starting network"
    net.build()
    c1.start()
    c2.start()
    s1.start([c1])
    s2.start([c2])

    print "*** Testing network"
    net.pingAll()

    print "*** Running CLI"
    CLI(net)

    print "*** Stopping network"
    net.stop()
Exemple #10
0
def topology():

    "Create a network with some docker containers acting as hosts."

    net = Containernet(controller=Controller)

    info('*** Adding controller\n')
    net.addController('c0')

    info('*** Adding docker containers\n')
    d1 = net.addDocker('d1',
                       ip='10.0.0.251',
                       dimage="mpeuster/stress",
                       cpuset_cpus="0,1")
    d1.sendCmd("./start.sh")

    info('*** Starting network\n')
    net.start()

    info('*** Running CLI\n')
    CLI(net)

    info('*** Stopping network')
    net.stop()
Exemple #11
0
from src.mininet.cli import CLI
from src.mininet.log import lg, info
from src.mininet.net import Mininet
from src.mininet.node import OVSKernelSwitch
from src.mininet.topolib import TreeTopo


def ifconfigTest(net):
    "Run ifconfig on all hosts in net."
    hosts = net.hosts
    for host in hosts:
        info(host.cmd('ifconfig'))


if __name__ == '__main__':
    lg.setLogLevel('info')
    info("*** Initializing Mininet and kernel modules\n")
    OVSKernelSwitch.setup()
    info("*** Creating network\n")
    network = Mininet(TreeTopo(depth=2, fanout=2), switch=OVSKernelSwitch)
    info("*** Starting network\n")
    network.start()
    info("*** Running ping test\n")
    network.pingAll()
    info("*** Running ifconfig test\n")
    ifconfigTest(network)
    info("*** Starting CLI (type 'exit' to exit)\n")
    CLI(network)
    info("*** Stopping network\n")
    network.stop()
Exemple #12
0
 def interact(self):
     "Start network and run our simple CLI."
     self.start()
     result = CLI(self)
     self.stop()
     return result
Exemple #13
0
"""
from src.mininet.net import Containernet
from src.mininet.node import Controller
from src.mininet.cli import CLI
from src.mininet.link import TCLink
from src.mininet.log import info, setLogLevel
setLogLevel('info')

net = Containernet(controller=Controller)
info('*** Adding controller\n')
net.addController('c0')
info('*** Adding docker containers\n')
d1 = net.addDocker('d1', ip='10.0.0.251', dimage="ubuntu:trusty")
d2 = net.addDocker('d2', ip='10.0.0.252', dimage="ubuntu:trusty")
info('*** Adding switches\n')
s1 = net.addSwitch('s1')
s2 = net.addSwitch('s2')
info('*** Creating links\n')
net.addLink(d1, s1)
net.addLink(s1, s2, cls=TCLink, delay='100ms', bw=1)
net.addLink(s2, d2)
info('*** Starting network\n')
net.start()
info('*** Testing connectivity\n')
net.ping([d1, d2])
info('*** Running CLI\n')
CLI(net)
info('*** Stopping network')
net.stop()