Initializing a Mininet topology from a bash script

时间:2015-06-26 10:04:50

标签: linux bash shell mininet

I'd like to automate the process of setting up a Mininet virtual machine, SSHing into the VM, starting Mininet within the VM, and initializing a topology. I need the session to remain open so I can issue commands to Mininet using the created network. Everything works, including initializing the network, but once the bash script ends, Mininet tears down the topology and exits the virtual machine. The relevant parts of my code are as follows:

vboxmanage startvm "Mininet-VM_1" --type=headless

ssh -t -Y -l mininet -p 2222 localhost << HERPDERP

    # Start the network
    sudo mn --controller=remote,ip=$ip --custom /home/mininet/sf_mininet_vm/mininet/topo_basic.py --topo clos_tree --switch ovsk --link tc

HERPDERP

Things I've tried:

  1. Ending the here document with s0 bash;
  2. Ending it with s0 $SHELL;
  3. Removing the delimiter at the end of the here document (shot in the dark).

(1) and (2) exited Mininet and left me with a prompt in the VM, but for some reason I can't issue commands from it. (3) does nothing.

1 个答案:

答案 0 :(得分:0)

如果你在文件中有python topo,你只需使用

就可以运行topo
sudo -E python <nameofthefile>

例如,如果您的文件Pkt_Topo_with_loop.py中有topo,则可以使用sudo -E python Pkt_Topo_with_loop.py启动mininet。因此,您可以在bash脚本中使用该行进行自动化。