示例#1
0
h1 = Host('h1')

root = Host('root', inNamespace=False)

print("*** Creating links")
h1.linkTo(root)

print(h1)

print("*** Configuring nodes")
h1.setIP('10.0.0.1', 8)
root.setIP('10.0.0.2', 8)

print("*** Creating banner file")
f = open('/tmp/%s.banner' % h1.name, 'w')
f.write('Welcome to %s at %s\n' % (h1.name, h1.IP()))
f.close()

print("*** Running sshd")
cmd = '/usr/sbin/sshd -o UseDNS=no -u0 -o "Banner /tmp/%s.banner"' % h1.name
# add arguments from the command line
if len(sys.argv) > 1:
    cmd += ' ' + ' '.join(sys.argv[1:])
h1.cmd(cmd)
listening = waitListening(server=h1, port=22, timeout=timeout)

if listening:
    print("*** You may now ssh into", h1.name, "at", h1.IP())
else:
    print("*** Warning: after %s seconds, %s is not listening on port 22" %
          (timeout, h1.name))
示例#2
0
from mininet.link import Link

h1 = Host('h1')
h2 = Host('h2')
h3 = Host('h3')
h4 = Host('h4')
s1 = OVSSwitch('s1', inNamespace=False)
s2 = OVSSwitch('s2', inNamespace=False)
c0 = Controller('c0', inNamespace=False)
Link(h1, s1)
Link(h2, s1)
Link(h3, s2)
Link(h4, s2)
Link(s1, s2)
h1.setIP('10.0.0.1/24')
h2.setIP('10.0.0.2/24')
h3.setIP('10.0.0.3/24')
h4.setIP('10.0.0.4/24')
c0.start()
s1.start([c0])
s2.start([c0])
print h1.IP
print h2.IP
print h3.IP
print h4.IP
print 'Pinging ...'
print h1.cmd('ping -c3 ', h2.IP())
print h1.cmd('ping -c3 ', h3.IP())
s1.stop()
s2.stop()
c0.stop()
示例#3
0
#!/usr/bin/python

from mininet.topo import Topo
from mininet.node import Host, OVSSwitch, Controller
from mininet.link import Link

h1 = Host('h1')
h2 = Host('h2')
s1 = OVSSwitch('s1', inNamespace=False)
c0 = Controller('c0', inNamespace=False)
Link(h1, s1)
Link(h2, s1)
h1.setIP('10.1/8')
h2.setIP('10.2/8')
c0.start()
s1.start([c0])
print h1.cmd('ping -c1', h2.IP())
s1.stop()
c0.stop()