Installing Dynamips and Dynagen on Ubuntu 7.10
Overview
Dynamips is a free Open-source router emulator for Cisco routers. It currently supports Cisco 3600 series (3620, 3640 and 3660), 3700 series (3725, 3745) and 2600 series (2610 to 2650XM, 2691), in addition to the 7200 platform with its associated NPEs. It uses actual Cisco IOS software (as opposed to the cruddy, featureless simulators that come with some study guides) so you can run any feature or command that you wish. You can emulate Serial, Ethernet, ATM, and POS interfaces. You can also set up a Frame Relay or ATM switch.
Dynagen is a front-end to the Dynamips Hypervisor. It uses a simple syntax to provision virtual router instances and allows you to connect routers together to form a virtual network.
By combining both applications, you can create very intricate labs which you can use to study for Cisco certifications or just to test a particular case. I've labs of my own for that very purpose. One very useful application would be to create test labs to train yourself in particular areas (BGP, OSPF, access-lists, etc...).
Getting Started
To begin, simply fire up a terminal window and do the following:
[ubuntu@ubuntu.localdomain:~] sudo apt-get install dynamips dynagen
Apt-get will fetch everything and install it for you (under /usr/bin by default).
Obtaining an IOS image
First, decide which platform or platforms you want to emulate. Throughout this document, I'm using the Cisco 3640 since it is relatively easy to configure. You'll need to obtain an IOS image. Where you find an image is totally up to you. If you don't work for a company with a Cisco support contract, you're probably not going to obtain it legally. Either way, I'd suggest placing it under a ~/dynamips directory since when you run dynamips, it creates virtual RAM, nvram, and configuration files. With several routers, this can get messy.
Obtaining idle-pc values
Before setting up a full-blown lab, you'll want to obtain the idle PC values for your given IOS image. The idle PC value allows you to run the IOS image without consuming 100% CPU. As you could imagine, running at 100% CPU usage wouldn't work well with multiple routers. To obtain the idle PC values, first run dynamips on the IOS image you downloaded:
[ubuntu@ubuntu.localdomain:~/dynamips> dynamips -P 3600 images/c3640-js-mz.124-18.bin
If you're set up properly, you should see the image boot:
Cisco Router Simulation Platform (version 0.2.7-x86)
Copyright (c) 2005-2007 Christophe Fillot.
Build date: May 26 2007 11:51:28
IOS image file: images/c3640-js-mz.124-18.bin
CPU0: carved JIT exec zone of 64 Mb into 2048 pages of 32 Kb.
NVRAM is empty, setting config register to 0x2142
C3600 instance 'default' (id 0):
VM Status : 0
RAM size : 128 Mb
NVRAM size : 128 Kb
Chassis : 3640
IOS image : images/c3640-js-mz.124-18.bin
Loading ELF file 'images/c3640-js-mz.124-18.bin'...
ELF entry point: 0x80008000
C3600 'default': starting simulation (CPU0 PC=0xffffffffbfc00000), JIT enabled.
ROMMON emulation microcode.
Launching IOS image at 0x80008000...
Self decompressing the image : ############################################ [OK]
Then, just like a real router, you'll be prompted to enter the configuration dialog. Type no and press enter. Then press enter again to be dropped to the CLI. You'll see a "Router>" prompt. Congratulations, you're running a virtual router!
Next, hit control, right bracket, then the i key (Ctrl+]+i). Dynamips will begin gathering system statistics and generate several idle pc values:
Router>
Please wait while gathering statistics...
Done. Suggested idling PC:
0x60428c4c (count=54)
0x60428cac (count=49)
0x60428ce0 (count=39)
0x60428cf4 (count=34)
0x605a1bac (count=64)
0x605a1c24 (count=39)
0x604c4470 (count=33)
0x6042d000 (count=48)
0x604f65e4 (count=37)
0x604f7070 (count=34)
Restart the emulator with "--idle-pc=0x60428c4c" (for example)
Copy these to a text file. We'll use them later when we configure a few routers for Dynagen. You can hit enter again to return to the router and play around if you like. To exit the simulator, hit Control, right bracket, the q (Ctrl+]+q). NOTE: idle pc values are IOS image specific! Whenever you use a different IOS image, you'll have to obtain the idle PC values specific to that image and input them into your Dynagen configurations.
Starting up the Dynamips Hypervisor
Dynamips has a Hypervisor mode that allows you to run several router instances and interconnect them. This is the key to running Dynagen - it connects to the Hypervisor and creates router instances you can then telnet to.
To start the Hypervisor, simply do the following:
[ubuntu@ubuntu.localdomain:~/dynamips> dynamips -H 7200
Cisco Router Simulation Platform (version 0.2.7-x86)
Copyright (c) 2005-2007 Christophe Fillot.
Build date: May 26 2007 11:51:28
ILT: loaded table "mips64j" from cache.
ILT: loaded table "mips64e" from cache.
ILT: loaded table "ppc32j" from cache.
ILT: loaded table "ppc32e" from cache.
Hypervisor TCP control server started (port 7200).
The default port to listen on is 7200 though you can change that to be anything you want. I suggest adding an ampersand after the port number to send the Hypervisor to the background (dynamips -H 7200 &). If you use something other than the default, remember which port you started the Hypervisor on as you'll need it for your Dynagen configuration.
Creating a simple Dynagen configuration
Let's begin by just connecting two routers. Open a blank text file and paste the following text into it, saving the text file as 'lab1.net':
#Simple two router lab
autostart = False
[localhost]
[[3640]]
#Specify an image to use
image = /home/ubuntu/dynamips/images/c3640-js-mz.124-18.bin
#Specify the amount of RAM to use (in MB).
ram = 128
disk0 = 0
disk1 = 0
#Define router instances
[[Router RTA]]
model = 3640
console = 2001
autostart = False
slot0 = NM-1FE-TX
F0/0 = RTB F0/0
idlepc = 0x60428c4c
[[Router RTB]]
model = 3640
console = 2002
autostart = False
slot0 = NM-1FE-TX
#F0/0 = RTA F0/0
idlepc = 0x60428cac
An explanation of the values is probably needed. The first line is a comment and is ignored by Dynagen. The second line tells the Hypervisor to NOT automatically start up your router instances. I'd recommend always using this since Dynamips can be VERY CPU and memory intensive. The third line tells Dynagen which host and port to connect the Hypervisor is running on.
Since we used the default port (7200) we didn't have to specify a port. The next line defines a router instance. Notice it is double-bracketed. The next few lines define some common configurations we want to apply to each of our virtual instances. You should change the 'image=' line to specify your own path to your IOS image. The next line is plain whitespace which is ignored by Dynagen. Next, we specify our first virtual router, RTA. We then specify the model we want to use (all 3600 routers are supported), then the console port we watn to connect to it on. Again we specify that we do not want to autostart the router when Dynagen is first run. The next line specifies that slot0 (bottom left of the router if you're facing the back) should contain a NM-1FE-TX. This is just a single port Fast Ethernet interface. The next line is where we connect the two routers together. Note that in the RTB instance I've commented it out. Dynagen doesn't like when you double reference connections, so I only put it there for clarity. It's useful to do so in larger configurations. The last line under RTA is the idle pc value we obtained when first running our IOS image. Use one value per virtual router.
Running our simple lab
With our simple lab saved into a text file, let's run Dynagen on it:
[ubuntu@ubuntu.localdomain:~/dynamips> dynagen lab1.net
Reading configuration file...
Shutdown in progress...
Shutdown completed.
Network successfully started
Dynagen management console for Dynamips
=>
Dynagen will read the configuration file, checking it for syntax errors, then start up the Hypervisor frontend. If you see the "=>" prompt, you've successfully connected to the Hypervisor. Issue a 'list':
=> list
Name Type State Server Console
RTA 3640 stopped localhost:7200 2001
RTB 3640 stopped localhost:7200 2002
=>
This shows that our two routers are present but stopped. It also shows to which console ports they are connected.
Start a router instance
To start a router instance, just issue the start command as follows:
=> start RTA
CPU0: carved JIT exec zone of 64 Mb into 2048 pages of 32 Kb.
NVRAM is empty, setting config register to 0x2142
C3600 instance 'RTA' (id 0):
VM Status : 0
RAM size : 128 Mb
NVRAM size : 128 Kb
Chassis : 3640
IOS image : /home/staff/ubuntu/dynamips/images/c3640-js-mz.124-18.bin
Loading ELF file '/home/staff/ubuntu/dynamips/images/c3640-js-mz.124-18.bin'...
ELF entry point: 0x80008000
C3600 'RTA': starting simulation (CPU0 PC=0xffffffffbfc00000), JIT enabled.
100-C3600 'RTA' started
At this point you can connect to the router on its console port:
[ubuntu@ubuntu.localdomain:~> telnet localhost 2001
Trying 127.0.0.1...
Connected to localhost.pnap.net.
Escape character is '^]'.
Connected to Dynamips VM "RTA" (ID 0, type c3600) - Console port
######################################### [OK]
Smart Init is disabled. IOMEM set to: 5
Using iomem percentage: 5
The above output is the virtual router instance booting up. It should drop you to the CLI as before when we were obtaining idle PC value. Issue the same start command on RTB to start it up. Once they are both booted up, enjoy!
Stopping a router instance
You can also stop a router instance:
=> stop RTA
C3600 'RTA': stopping simulation.
100-C3600 'RTA' stopped
To list the commands available in the Dynagen management console, just type help. I'd suggest reading the Dynagen help file for more information. To completely stop the simulator, type exit in the management console and do a "killall dynamips" to stop the Hypervisor.
Conclusions
Though this was a pretty simple lab, you can certainly make infinitely more complex ones. Use your imagination! These tools are great for practicing for certification tests, making mock labs for problem replication, or just to keep up your networking abilities.