Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # integ.py
- #!/usr/bin/python2
- import shutil
- from mininet.log import setLogLevel
- from mininet.net import Mininet
- from mininet.cli import CLI
- def run():
- print 'Upload files.'
- shutil.rmtree('/tmp/mn-integ', True)
- for name in ['A', 'B', 'C', 'D']:
- try:
- shutil.copytree('/usr/local/etc/ndn', '/tmp/mn-integ/%s/usr/local/etc/ndn' % name)
- except:
- pass
- try:
- shutil.copytree('.ndn', '/tmp/mn-integ/%s/root/.ndn' % name)
- except:
- pass
- try:
- shutil.copytree('integration-tests', '/tmp/mn-integ/%s/root/integration-tests' % name)
- except:
- pass
- try:
- shutil.copyfile('multi-host.conf', '/tmp/mn-integ/%s/root/integration-tests/multi-host.conf' % name)
- except:
- pass
- print 'Build network.'
- net = Mininet()
- net.addController()
- net.addSwitch('lanABC', dpid='0')
- privateDirs = [
- ('/usr/local/etc/ndn', '/tmp/mn-integ/%(name)s/usr/local/etc/ndn'),
- ('/var/log/ndn', '/tmp/mn-integ/%(name)s/var/log/ndn'),
- ('/var/run', '/tmp/mn-integ/%(name)s/var/run'),
- ('/root', '/tmp/mn-integ/%(name)s/root')
- ]
- net.addHost('A', privateDirs=privateDirs)
- net.addHost('B', privateDirs=privateDirs)
- net.addHost('C', privateDirs=privateDirs)
- net.addHost('D', privateDirs=privateDirs)
- net.addHost('R')
- linkABCA = net.addLink('lanABC', 'A')
- linkABCB = net.addLink('lanABC', 'B')
- linkABCC = net.addLink('lanABC', 'C')
- linkRA = net.addLink('R', 'A')
- linkRD = net.addLink('R', 'D')
- net.start()
- print 'Setup IPv4.'
- net['A'].setIP('192.168.1.1', 24, linkABCA.intf2)
- net['B'].setIP('192.168.1.2', 24, linkABCB.intf2)
- net['C'].setIP('192.168.1.3', 24, linkABCC.intf2)
- net['R'].setIP('192.168.2.1', 24, linkRA.intf1)
- net['A'].setIP('192.168.2.2', 24, linkRA.intf2)
- net['R'].setIP('192.168.3.1', 24, linkRD.intf1)
- net['D'].setIP('192.168.3.2', 24, linkRD.intf2)
- net['A'].cmd('ip route add 192.168.3.0/24 via 192.168.2.1')
- net['D'].cmd('ip route add 192.168.2.0/24 via 192.168.3.1')
- net['R'].cmd('sysctl net.ipv4.ip_forward=1')
- print 'Setup IPv6.'
- net['A'].cmd('ip addr add fd01::1/64 dev %s' % linkABCA.intf2)
- net['B'].cmd('ip addr add fd01::2/64 dev %s' % linkABCB.intf2)
- net['C'].cmd('ip addr add fd01::3/64 dev %s' % linkABCC.intf2)
- net['R'].cmd('ip addr add fd02::1/64 dev %s' % linkRA.intf1)
- net['A'].cmd('ip addr add fd02::2/64 dev %s' % linkRA.intf2)
- net['R'].cmd('ip addr add fd03::1/64 dev %s' % linkRD.intf1)
- net['D'].cmd('ip addr add fd03::2/64 dev %s' % linkRD.intf2)
- net['A'].cmd('ip -6 route add fd03::/64 via fd02::1')
- net['D'].cmd('ip -6 route add fd02::/64 via fd03::1')
- net['R'].cmd('sysctl net.ipv6.conf.all.forwarding=1')
- print 'Configure SSH.'
- net['A'].pexec('/usr/bin/ssh-keygen', '-N', '', '-f', '/root/.ssh/id_rsa')
- sshConfig = open('/tmp/mn-integ/A/root/.ssh/config', 'w')
- sshConfig.write('StrictHostKeyChecking no')
- sshConfig.close()
- sshdProcesses = dict()
- for name in ['B', 'C', 'D', 'R']:
- net[name].cmd('mkdir -p /var/run/sshd')
- net[name].cmd('mkdir -p /root/.ssh')
- try:
- shutil.copyfile('/tmp/mn-integ/A/root/.ssh/id_rsa.pub', '/tmp/mn-integ/%s/root/.ssh/authorized_keys' % name)
- except:
- pass
- sshdProcesses[name] = net[name].popen('/usr/sbin/sshd', '-D', stdout=None, stderr=None)
- for host in net.hosts:
- host.cmd('export HOME=/root')
- host.cmd('cd $HOME/integration-tests')
- CLI(net)
- for process in sshdProcesses.itervalues():
- process.kill()
- process.wait()
- net.stop()
- if __name__ == '__main__':
- setLogLevel('info')
- run()
- # multi-host.conf
- """
- # This is configuration for multiple hosts testing scenarios.
- # Tests that involves multiple hosts should be run on host A from this topology:
- # B[1]---|
- # +---[1]A[2]---[1]R[2]---[1]D
- # C[1]---|
- #
- # CTRL_* are used to ssh into other hosts. (eg. `ssh $CTRL_B` gets you a shell on B)
- # IP4_* (and IP6_* if needed) are used to send experiment packets (eg. `nfdc create udp4://$IP4_C1` creates a tunnel).
- #
- # suggested subnet mask:
- # IPv4: /24
- # IPv6: /64
- #
- CTRL_B=192.168.1.2
- CTRL_C=192.168.1.3
- CTRL_D=192.168.3.2
- CTRL_R=192.168.2.1
- IP4_A1=192.168.1.1
- IP4_B1=192.168.1.2
- IP4_C1=192.168.1.3
- IP4_A2=192.168.2.2
- IP4_R1=192.168.2.1
- IP4_R2=192.168.3.1
- IP4_D1=192.168.3.2
- IP6_A1=fd01::1
- IP6_B1=fd01::2
- IP6_C1=fd01::3
- IP6_A2=fd02::2
- IP6_R1=fd02::1
- IP6_R2=fd03::1
- IP6_D1=fd03::2
- """
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement