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()
def runMultiLink(): "Create and run multiple link network" topo = simpleMultiLinkTopo(n=2) net = Mininet(topo=topo) net.start() CLI(net) net.stop()
def run(): "Create network and run the CLI" topo = InternetTopo() net = Mininet(topo=topo) net.start() CLI(net) net.stop()
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()
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()
def exampleCustomTags(): """Simple example that exercises VLANStarTopo""" net = Mininet(topo=VLANStarTopo()) net.start() CLI(net) net.stop()
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()
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()
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()
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()
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()
def interact(self): "Start network and run our simple CLI." self.start() result = CLI(self) self.stop() return result
""" 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()