Initializing a Mininet topology from a bash script

849 views Asked by At

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

There are 1 answers

0
Ehsan Ab On

if you have that python topo in a file you can run the topo by just using

sudo -E python <nameofthefile>

For example, If you have your topo in file Pkt_Topo_with_loop.py, you could just use sudo -E python Pkt_Topo_with_loop.py to start up the mininet. So you would have that line in your bash script for automation.