1.) Install dynagen and dynamips
2.) Also configure your bridge or br0
If you don't have a br0 on your Linux machine then follow this guide or video for Debian:
Alternatively you can use NIO_linux_eth:eth0 for f0/0 below but remember the host machine cannot talk to the router then.
3.) Create your dynagen config
Save the file below to something.conf
#Example config:
autostart = False
[127.0.0.1:2000]
workingdir = /home/mint/router
udp = 10100
[[7200]]
image = c7200-adventerprisek9-mz.151-4.M.bin
disk0 = 256
#idlepc = 0x60be916c
[[ROUTER r1]]
model = 7200
console = 2521
aux = 2119
#wic0/0 = WIC-1T
#wic0/1 = WIC-1T
#wic0/2 = WIC-1T
#instead youcould use f0/0=NIO_linux_eth:eth0 but your host would not have communication with the router
f0/0 = nio_tap:tap1
x = 22.0
y = -351.0
4.) Start dynamips
sudo dynamips -H 2000&
5.) Start your router
dynagen yourconffromstep3.conf
6.) Connect to your router and configure
telnet localhost 2521
enable
conf t
int fa0/0
ip address 192.168.5.1 255.255.255.0
no shut
7.) Test connectivity
Make sure you put your tap1 on the bridge and put up tap1. After this you should be able to ping your router but remember your host's br0:0 should be created and be on the same subnet to work.
sudo brctl addif br0 tap1
sudo ifconfig tap1 up
Performance Tuning
I recommend you set calculate and set idlepc, as a wrong value or no value will guarantee it will use at least ~100% of the CPU core dynamips is on. Check this guide here to set idlepc for dynamips with dynagen
This script as it is will get your r1 and r2 router up without typing any commands. All you have to do is change the .conf file name to your own and make sure to save the contents of the script to an "something.sh", chmod +x something.sh and then ./something.sh and it will automatically get you going. It also kills any other instances of dynamips or dynagen to avoid conflicts. The only thing it does need is sudo so it will ask for your sudo password.
Remember that you need "expect" installed or this script will not work (use apt install expect or yum install expect).
The script makes a few assumptions but you can of course change it.
1.) Dynamips is to be started on port 2000 if not change it!
2.) That you want to create two tap devices "tap1" and "tap2" and add them to your bridge br0
3.) It also assumes you are in the directory of "yourconffile.conf" in bold in the script below. Change that name to the name of yours
4.) Finally it also assumes that you have routers r1 and r2 that you want to be started automatically in the send "start r1\n" area. You can add more lines for more routers or change the names according to your needs.
#!/bin/bash
sudo killall dynamips dynagen
sudo dynamips -H 2000 &
sudo ip tuntap add tap1 mode tap
sudo ip tuntap add tap2 mode tap
sudo brctl addif br0 tap1
sudo brctl addif br0 tap2
sudo ifconfig tap1 up
sudo ifconfig tap2 up
expect <(cat <<'EOD'
spawn dynagen yourconffile.conf
expect "Dynagen management console for Dynamips"
send "start r1\n"
send "start r2\n"
interact
exit
EOD
)
cisco, cme, virtual, router, linux, dynamips, dynagenexample, config, autostart, workingdir, mint, udp, adventerprisek, mz, bin, disk, idlepc, console, aux, wic, nio_tap,