Showing posts with label dynagen. Show all posts
Showing posts with label dynagen. Show all posts

Friday, June 15, 2012

How to create dynagen network topology with multible dynamips service



I explained "Using dynagen & dynamips for multible cisco router simulation" in the http://stdioe.blogspot.com/2012/06/using-dynagen-dynamips-for-multible.html article before. I'm going to talk about how to create a dynagen configuration for multiple dynamips service. Also we are going to work about dynagen performance optimization. Let's create a network topology to try on our system.

Now, we have got three dynamips services. Each single dynamips service is creating three virtual routers and all of them are connected to each other. The first dynamips service contains R1, R2 and R3 routers, the second dynamips service contains R4, R5 and R6 routers, the third dynamips service contains R7, R8 and R9 routers. They are  seperated on configuration but logically they are connected to each other directly.

Start to practice,



1-) Starting dynamips services with different port numbers,

ismail@ismail-ThinkPad-T410:~$ dynamips -H 7200 &
ismail@ismail-ThinkPad-T410:~$ dynamips -H 7301 &
ismail@ismail-ThinkPad-T410:~$ dynamips -H 7402 &

2-) Create dynamips configuration file corresponding our network topology,

###############################1-Dynamips-1#############################
[localhost:7200]
  udp=10000
  workingdir = /tmp/workingdy1

[[3725]]
  image = /tmp/c3725-adventerprisek9-mz.124-15.T13.bin
  ram = 128
  #idlepc =  ?? # We will talk about this, later.
  ghostios = true
  sparsemem = true
  idlemax = 100 
  disk0=128

 [[Router R1]]
  model = 3725
  console = 2001
  autostart = false
  S0/0 = R2 S0/0

 [[Router R2]]
  model = 3725
  console = 2002
  autostart = false
  S0/0 = R1 S0/0
  S0/1 = R3 S0/0

 [[Router R3]]
  model = 3725
  console = 2003
  autostart = false
  WIC0/0 = WIC-2T
  S0/0 = R2 S0/1 
  S0/1 = R7 S0/1

###############################1-Dynamips-1#############################

###############################2-Dynamips-2#############################
[localhost:7201]
  udp=11000
  workingdir = /tmp/workingdy2

[[3725]]
  image = /tmp/c3725-adventerprisek9-mz.124-15.T13.bin
  ram = 128
  #idlepc =  ?? # We will talk about this, later.
  ghostios = true
  sparsemem = true
  idlemax = 100 
  disk0=128

 [[Router R4]]
  model = 3725
  console = 2004
  autostart = false
  S0/0 = R5 S0/0
  S0/1 = R8 S0/1

 [[Router R5]]
  model = 3725
  console = 2005
  autostart = false
  S0/0 = R4 S0/0
  S0/1 = R6 S0/0

 [[Router R6]]
  model = 3725
  console = 2006
  autostart = false
  S0/0 = R5 0/1

###############################2-Dynamips-2#############################

###############################3-Dynamips-3#############################
[localhost:7202]
  udp=12000
  workingdir = /tmp/workingdy3

[[3725]]
  image = /tmp/c3725-adventerprisek9-mz.124-15.T13.bin
  ram = 128
  #idlepc =  ?? # We will talk about this, later.
  ghostios = true
  sparsemem = true
  idlemax = 100 
  disk0=128

 [[Router R7]]
  model = 3725
  console = 2007
  autostart = false
  S0/0 = R9 S0/0
  S0/1 = R3 S0/1

 [[Router R8]]
  model = 3725
  console = 2008
  autostart = false
  WIC0/0 = WIC-2T
  S0/0 = R9 S0/1
  S0/1 = R4 S0/1

 [[Router R9]]
  model = 3725
  console = 2009
  autostart = false
  S0/0 = R7 0/0
  S0/1 = R8 0/0

###############################3-Dynamips-3#############################

I saved the content above with a file name of sample2.net name in /tmp directory.  We need working directories as below:

ismail@ismail-ThinkPad-T410:~$ mkdir /tmp/workingdy1
ismail@ismail-ThinkPad-T410:~$ mkdir /tmp/workingdy2
ismail@ismail-ThinkPad-T410:~$ mkdir /tmp/workingdy3

3-) The working directories are ready. Right now, dynagen service is ready to start. I did a mistake to shown follow up how to troubleshooting.

ismail@ismail-ThinkPad-T410:~$ dynagen /tmp/sample2.net 
Reading configuration file...

Shutdown in progress...
Shutdown completed.
Shutdown in progress...
Shutdown completed.
Shutdown in progress...
Shutdown completed.
*** Warning:  Connecting R6 S0/0 to R5 0/1 resulted in:
 malformed destination interface: R5 0/1
*** Warning:  Connecting R9 S0/0 to R7 0/0 resulted in:
 malformed destination interface: R7 0/0
*** Warning:  Connecting R9 S0/1 to R8 0/0 resulted in:
 malformed destination interface: R8 0/0

*** Error:  errors during loading of the topology file, please correct them
Shutdown in progress...
Error: could not communicate with dynamips server localhost
It may have crashed. Check the dynamips server output.
Exiting...
Press ENTER to exit
[3]+  Segmentation fault      (core dumped) dynamips -H 7202
ismail@ismail-ThinkPad-T410:~$ 

Normally, you can define a connection on both ends of lines. But on our sample, dynagen service doesn't accept this duplicate defination. I removed " S0/1 = R6 S0/0" line in R5 router part. Also "  S0/0 = R9 S0/0" line in R7 part and " S0/0 = R9 S0/1" line in R8 part. After editing, sample2.net file has a content as seen below:


###############################1-Dynamips-1#############################
[localhost:7200]
  udp=10000
  workingdir = /tmp/workingdy1

[[3725]]
  image = /tmp/c3725-adventerprisek9-mz.124-15.T13.bin
  ram = 128
  #idlepc =  ?? # We will talk about this, later.
  ghostios = true
  sparsemem = true
  idlemax = 100
  disk0=128

 [[Router R1]]
  model = 3725
  console = 2001
  autostart = false
  S0/0 = R2 S0/0

 [[Router R2]]
  model = 3725
  console = 2002
  autostart = false
  #S0/0 = R1 S0/0
  S0/1 = R3 S0/0

 [[Router R3]]
  model = 3725
  console = 2003
  autostart = false
  #S0/0 = R2 S0/1
  S0/1 = R7 S0/1

###############################1-Dynamips-1#############################

###############################2-Dynamips-2#############################
[localhost:7201]
  udp=11000
  workingdir = /tmp/workingdy2

[[3725]]
  image = /tmp/c3725-adventerprisek9-mz.124-15.T13.bin
  ram = 128
  #idlepc =  ?? # We will talk about this, later.
  ghostios = true
  sparsemem = true
  idlemax = 100
  disk0=128

 [[Router R4]]
  model = 3725
  console = 2004
  autostart = false
  S0/0 = R5 S0/0
  S0/1 = R8 S0/1

 [[Router R5]]
  model = 3725
  console = 2005
  autostart = false
  #S0/0 = R4 S0/0
  S0/1 = R6 S0/0

 [[Router R6]]
  model = 3725
  console = 2006
  autostart = false
#  S0/0 = R5 0/1

###############################2-Dynamips-2#############################

###############################3-Dynamips-3#############################
[localhost:7202]
  udp=12000
  workingdir = /tmp/workingdy3

[[3725]]
  image = /tmp/c3725-adventerprisek9-mz.124-15.T13.bin
  ram = 128
  #idlepc =  ?? # We will talk about this, later.
  ghostios = true
  sparsemem = true
  idlemax = 100
  disk0=128

 [[Router R7]]
  model = 3725
  console = 2007
  autostart = false
  S0/0 = R9 S0/0
  #S0/1 = R3 S0/1

 [[Router R8]]
  model = 3725
  console = 2008
  autostart = false
  S0/0 = R9 S0/1
  #S0/1 = R4 S0/1

 [[Router R9]]
  model = 3725
  console = 2009
  autostart = false
#  S0/0 = R7 0/0
#  S0/1 = R8 0/0

###############################3-Dynamips-3#############################

We already started dynamips with 7200, 7201 and 7202 ports but dynagen service has been crashed. Some dynamips services may have been crashed. We have to check them before restarting dynages service.

ismail@ismail-ThinkPad-T410:~$ ps -ef | grep dynamips
ismail    3811  3756  1 10:15 pts/0    00:00:14 dynamips -H 7200
ismail    3829  3756  1 10:16 pts/0    00:00:14 dynamips -H 7201
ismail    4017  3756  0 10:27 pts/0    00:00:00 grep --color=auto dynamips

So One dynamips service crashed and other two ones still working. I want to kill all dynamips services and start them again to make sure about everything on the way. We can kill a PID using the "kill -9 3811" command but I selected pkill command in this sample to show first practice.

ismail@ismail-ThinkPad-T410:~$ pkill dynamips
[1]-  Terminated              dynamips -H 7200
[2]+  Terminated              dynamips -H 7201
ismail@ismail-ThinkPad-T410:~$ 

And now, there is no any running dynamip process. We can start all of them again,

ismail@ismail-ThinkPad-T410:~$ dynamips -H 7201 &
ismail@ismail-ThinkPad-T410:~$ dynamips -H 7202 &
ismail@ismail-ThinkPad-T410:~$ dynamips -H 7203 &
ismail@ismail-ThinkPad-T410:~$ dynagen /tmp/sample2.net 
Reading configuration file...
...
...
...
Dynagen management console for Dynamips and Pemuwrapper 0.11.0
Copyright (c) 2005-2007 Greg Anuzelli, contributions Pavel Skovajsa

=> 

Finally dynagen loaded our network topology. We can handle it now. We can start routers with "start" command on dynagen console and get console of routers with "telnet Rx" command (x is number of router name, for example R4).

We may need to use the "idlepc" parameter in this sample. If you need more performance, you have to use idlepc parameter. Dynagen can optimize itself using the value given for idlepc. We have to learn only what is our idlepc value for our system. We can use following command in the dynagen console,

=> start R1
=> idlepc get R1
Please wait while gathering statistics...

Please wait while gathering statistics...
Done. Suggested idling PC:
   0x60c08128 (count=22)
   0x60c08164 (count=33)
   0x60c08180 (count=35)
   0x60c081c0 (count=66)
   0x62b2823c (count=45)
   0x60c08bf8 (count=23)
   0x60c08c20 (count=20)
   0x614b0e34 (count=38)
   0x62b2b134 (count=20)
   0x6026bca4 (count=30)
Restart the emulator with "--idle-pc=0x60c08128" (for example)
   1: 0x60c08128 [22]
   2: 0x60c08164 [33]
   3: 0x60c08180 [35]
   4: 0x60c081c0 [66]
   5: 0x62b2823c [45]
   6: 0x60c08bf8 [23]
   7: 0x60c08c20 [20]
   8: 0x614b0e34 [38]
   9: 0x62b2b134 [20]
  10: 0x6026bca4 [30]
Potentially better idlepc values marked with "*"
Enter the number of the idlepc value to apply [1-10] or ENTER for no change: 
No changes made
=> 

If you find any "*" line, you can use this line value. If you don't have any marked line with "*", you can try to get idlepc value again.

Monday, June 4, 2012

Using dynagen & dynamips for multible cisco router simulation


dynage dynamips cisco linux console terminal network lab simulation


       If you want to simulate a Cisco router, you can use dynamips but if you want to create a network topology you have to use both of dynagen and dynamips. This blog post is about about creating a sample network topology, connecting routers to each other and testing all nodes in the topology.


       I'm using Ubuntu 12.04 to show an example now. First, we have to install dynagen (and dynamips) on Ubuntu 12.04. Actually we will also need dynamips but dynamips is a dependance of dynamips. So if we install dynagen, dynamips will be installed with dynagen.



ismail@ismail-ThinkPad-T410:~$ sudo apt-get install dynagen 
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following extra packages will be installed:
  dynamips python-configobj
The following NEW packages will be installed:
  dynagen dynamips python-configobj
0 upgraded, 3 newly installed, 0 to remove and 0 not upgraded.
Need to get 1,070 kB/1,418 kB of archives.
After this operation, 4,263 kB of additional disk space will be used.
Do you want to continue [Y/n]? 
Get:1 http://tr.archive.ubuntu.com/ubuntu/ precise/main python-configobj all 4.7.2+ds-3build1 [233 kB]
Get:2 http://tr.archive.ubuntu.com/ubuntu/ precise/multiverse dynagen all 0.11.0-6 [836 kB]
Fetched 1,070 kB in 0s (1,495 kB/s)
Selecting previously unselected package dynamips.
(Reading database ... 206573 files and directories currently installed.)
Unpacking dynamips (from .../dynamips_0.2.7-0.2.8RC2-5ubuntu1_amd64.deb) ...
Selecting previously unselected package python-configobj.
Unpacking python-configobj (from .../python-configobj_4.7.2+ds-3build1_all.deb) ...
Selecting previously unselected package dynagen.
Unpacking dynagen (from .../dynagen_0.11.0-6_all.deb) ...
Processing triggers for man-db ...
Processing triggers for doc-base ...
Processing 1 added doc-base file...
Registering documents with scrollkeeper...
Setting up dynamips (0.2.7-0.2.8RC2-5ubuntu1) ...
Setting up python-configobj (4.7.2+ds-3build1) ...
Setting up dynagen (0.11.0-6) ...
Processing triggers for python-support ...
ismail@ismail-ThinkPad-T410:~$ 

Let's start to work with sample network topology;



       There are only 3 routers on our sample network topology. Only one dynamips instance should be enough.

1-) Start dynamips instance


ismail@ismail-ThinkPad-T410:~$ dynamips -H 7100 &
[1] 16919
ismail@ismail-ThinkPad-T410:~$ Cisco Router Simulation Platform (version 0.2.8-RC2-amd64)
Copyright (c) 2005-2007 Christophe Fillot.
Build date: Jan 18 2011 19:25:29

Hypervisor TCP control server started (port 7100).

ismail@ismail-ThinkPad-T410:~$ ps -ef | grep dynamips
ismail   16919  8265  6 17:59 pts/2    00:00:00 dynamips -H 7100
ismail   16934  8265  0 17:59 pts/2    00:00:00 grep --color=auto dynamips
ismail@ismail-ThinkPad-T410:~$ 

       We are starting dynamips service with "dynamips -H 7100 &" and checking it with "ps -ef | grep dynamips" command.

2-) Create a dynagen configuration file


# [START INSTANCE1]

[localhost:7100]
  udp=10000
  workingdir = /tmp/working

[[3725]]
  image = /tmp/c3725-adventerprisek9-mz.124-15.T13.bin
  ram = 128
#  idlepc = ?? We will talk about it later.
  ghostios = true
  sparsemem = true
  idlemax = 100
  disk0=128

 [[Router R1]]
  model = 3725
  console = 2001
  autostart = false
#  F0/0 =
  S0/0 = R2 S0/0

 [[Router R2]]
  model = 3725
  console = 2002
  autostart = false
#  F0/0 =
  S0/0 = R1 S0/0
  S0/1 = R3 S0/0

 [[Router R3]]
  model = 3725
  console = 2003
  autostart = false
  S0/0 = R2 S0/1
# F0/0 =

# [FINISH INSTANCE1] 

       First stage is about connecting to an existing dynamips service. Dynamips will create some files when it is loading a topology. This files will be created in  the "workingdir" directory.

       Second stage is about creating a Cisco Router model. We have to define a Cisco ios file path and some hardware specifications in this stage.

       The last stages are about defining our virtual routers. If we create more than one models, we can select different models for earch virtual router. The "console" key defines the port number. We will use this port numbers to connect to console of router. Autostart key defines either manual or auto router booting while starting to dynagen process. Finally we will define  connections between virtual routers.

       I created a "working" directory under /tmp and the dynagen configuration file before starting the dynagen as shown below:

ismail@ismail-ThinkPad-T410:~$ vim /tmp/sample1.net
{write dynagen configuration file content as above INSTANCE1}
ismail@ismail-ThinkPad-T410:~$ 
ismail@ismail-ThinkPad-T410:~$ dynagen /tmp/sample1.net 
Reading configuration file...

Shutdown in progress...
Shutdown completed.
CPU0: carved JIT exec zone of 64 Mb into 2048 pages of 32 Kb.
NVRAM is empty, setting config register to 0x2142
C3725 instance 'ghost-c3725-adventerprisek9-mz.124-15.T13.bin-localhost.ghost' (id 3):
  VM Status  : 0
  RAM size   : 128 Mb
  NVRAM size : 128 Kb
  IOS image  : /tmp/c3725-adventerprisek9-mz.124-15.T13.bin

Loading ELF file '/tmp/c3725-adventerprisek9-mz.124-15.T13.bin'...
ELF entry point: 0x80008000

C3725 'ghost-c3725-adventerprisek9-mz.124-15.T13.bin-localhost.ghost': starting simulation (CPU0 PC=0xffffffffbfc00000), JIT enabled.

C3725 'ghost-c3725-adventerprisek9-mz.124-15.T13.bin-localhost.ghost': stopping simulation.
Network successfully loaded

Dynagen management console for Dynamips and Pemuwrapper 0.11.0
Copyright (c) 2005-2007 Greg Anuzelli, contributions Pavel Skovajsa

=> list
Name       Type       State      Server          Console   
R1         3725       stopped    localhost:7100  2001      
R2         3725       stopped    localhost:7100  2002      
R3         3725       stopped    localhost:7100  2003      
=> 
=> ?

Documented commands (type help <topic>):
========================================
capture  confreg  cpuinfo  export  hist    list  py      save   show   suspend
clear    console  end      filter  idlepc  no    reload  send   start  telnet 
conf     copy     exit     help    import  push  resume  shell  stop   ver    

=> 
=> start R1
Warning: Starting R1 with no idle-pc value
CPU0: carved JIT exec zone of 64 Mb into 2048 pages of 32 Kb.
C3725 instance 'R1' (id 0):
  VM Status  : 0
  RAM size   : 128 Mb
  NVRAM size : 128 Kb
  IOS image  : /tmp/c3725-adventerprisek9-mz.124-15.T13.bin

Loading ELF file '/tmp/c3725-adventerprisek9-mz.124-15.T13.bin'...
ELF loading skipped, using a ghost RAM file.
ELF entry point: 0x80008000

C3725 'R1': starting simulation (CPU0 PC=0xffffffffbfc00000), JIT enabled.
100-VM 'R1' started
=> 
=> start R2
Warning: Starting R2 with no idle-pc value
CPU0: carved JIT exec zone of 64 Mb into 2048 pages of 32 Kb.
NVRAM is empty, setting config register to 0x2142
C3725 instance 'R2' (id 1):
  VM Status  : 0
  RAM size   : 128 Mb
  NVRAM size : 128 Kb
  IOS image  : /tmp/c3725-adventerprisek9-mz.124-15.T13.bin

Loading ELF file '/tmp/c3725-adventerprisek9-mz.124-15.T13.bin'...
ELF loading skipped, using a ghost RAM file.
ELF entry point: 0x80008000

C3725 'R2': starting simulation (CPU0 PC=0xffffffffbfc00000), JIT enabled.
100-VM 'R2' started
=> start R3
Warning: Starting R3 with no idle-pc value
CPU0: carved JIT exec zone of 64 Mb into 2048 pages of 32 Kb.
NVRAM is empty, setting config register to 0x2142
C3725 instance 'R3' (id 2):
  VM Status  : 0
  RAM size   : 128 Mb
  NVRAM size : 128 Kb
  IOS image  : /tmp/c3725-adventerprisek9-mz.124-15.T13.bin

Loading ELF file '/tmp/c3725-adventerprisek9-mz.124-15.T13.bin'...
ELF loading skipped, using a ghost RAM file.
ELF entry point: 0x80008000

C3725 'R3': starting simulation (CPU0 PC=0xffffffffbfc00000), JIT enabled.
100-VM 'R3' started
=> 

Open another terminal and execute this command:

ismail@ismail-ThinkPad-T410:~$ telnet localhost 2001
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
Connected to Dynamips VM "R1" (ID 0, type c3725) - Console port

when press enter will appear this;

% Please answer 'yes' or 'no'.
Would you like to enter the initial configuration dialog? [yes/no]: 

press Ctrl+c and enter and enter again:

Press RETURN to get started!


*Mar  1 00:00:03.843: %LINEPROTO-5-UPDOWN: Line protocol on Interface VoIP-Null0, changed state to up
*Mar  1 00:00:03.847: %LINEPROTO-5-UPDOWN: Line protocol on Interface IPv6-mpls, changed state to up
*Mar  1 00:00:03.927: %LINK-3-UPDOWN: Interface Serial0/0, changed state to up
*Mar  1 00:00:03.935: %LINK-3-UPDOWN: Interface Serial0/1, changed state to up
*Mar  1 00:00:04.927: %LINEPROTO-5-UPDOWN: Line protocol on Interface Serial0/0, changed state to up
*Mar  1 00:00:04.935: %LINEPROTO-5-UPDOWN: Line protocol on Interface Serial0/1, changed state to up
*Mar  1 00:00:32.927: %LINEPROTO-5-UPDOWN: Line protocol on Interface Serial0/1, changed state to down
*Mar  1 00:01:26.839: %LINEPROTO-5-UPDOWN: Line protocol on Interface Serial0/0, changed state to down
*Mar  1 00:01:32.875: %LINEPROTO-5-UPDOWN: Line protocol on Interface Serial0/0, changed state to up
*Mar  1 00:01:39.015: %LINK-5-CHANGED: Interface FastEthernet0/1, changed state to administratively down
*Mar  1 00:0
Router>1:39.075: %LINK-5-CHANGED: Interface FastEthernet0/0, changed state to administratively down
*Mar  1 00:01:40.115: %SYS-5-RESTART: System restarted --
Cisco IOS Software, 3700 Software (C3725-ADVENTERPRISEK9-M), Version 12.4(15)T13, RELEASE SOFTWARE (fc3)
Technical Support: http://www.cisco.com/techsupport
Copyright (c) 1986-2010 by Cisco Systems, Inc.
Compiled Wed 07-Apr-10 12:44 by prod_rel_team
*Mar  1 00:01:40.123: %SNMP-5-COLDSTART: SNMP agent on host Router is undergoing a cold start
*Mar  1 00:01:40.147: %LINEPROTO-5-UPDOWN: Line protocol on Interface FastEthernet0/1, changed state to down
*Mar  1 00:01:40.147: %LINEPROTO-5-UPDOWN: Line protocol on Interface FastEthernet0/0, changed state to down
*Mar  1 00:01:40.159: %CRYPTO-6-ISAKMP_ON_OFF: ISAKMP is OFF
*Mar  1 00:01:40.159: %CRYPTO-6-GDOI_ON_OFF: GDOI is OFF
*Mar  1 00:01:40.951: %LINK-5-CHANGED: Interface Serial0/0, changed state to administratively down
*Mar  1 00:01:40.951: %LINK-5-CHANGED: Interface Serial0/1, changed state to administratively down
*Mar  1 00:01:41.951: %LINEPROTO-5-UPDOWN: Line protocol on Interface Serial0/0, changed state to down
*Mar  1 00:01:43.839: %IP-5-WEBINST_KILL: Terminating DNS process
Router>

        So you can get console for other virtual routers with "telnet localhost 2002", "telnet localhost 2003" and "telnet localhost 2004" commands.   

        I'm preparing more samples for multiple instances, physical ethernet connectivity and switch simulation with dynagen&dynamips.