LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 01-03-2007, 12:28 PM   #1
myrto
LQ Newbie
 
Registered: Dec 2006
Posts: 29

Rep: Reputation: 15
ns-2 network simulator


I have recently installed ns-2 network simulator and I was wondering if there is someone who has any experience using it. I am trying to create a simple topology with two nodes connected by a simplex link over a udp connection. The only problem is that I want the traffic between the two nodes to be generated according to a Poisson distribution. I assume I will have to create a traffic generator of my own, but I can't find out how to do that. I have searched in several tutorials, as well as the ns-2 manual but I can't find anything.If anyone could tell me where to look for this information I would be very gratefull. Also, any suggestions about books or any other source concerning the simulator would be very welcome. Thank you very much.

Last edited by myrto; 01-08-2007 at 11:09 AM.
 
Old 01-03-2007, 03:06 PM   #2
Mara
Moderator
 
Registered: Feb 2002
Location: Grenoble
Distribution: Debian
Posts: 9,696

Rep: Reputation: 232Reputation: 232Reputation: 232
It may be a better idea to generate a trace with the parameters you need and then import it using TrafficTrace (or it had a similar name). Writing your own extensions to ns-2 is pain.

On the other hand, if you decide to write a traffic distribution extension, it should should not be such pain as routing protocol etc. But still pain, IMHO.
 
Old 01-04-2007, 02:44 AM   #3
myrto
LQ Newbie
 
Registered: Dec 2006
Posts: 29

Original Poster
Rep: Reputation: 15
Thank you very much for your help! The problem is, I am new at this, as well as programming in generall and I can't find how to do this. I was looking in the ns-2 manual for TrafficTrace or any way at all to create your own traffic pattern but I couldn't find anything. If you could tell me where to look I would be very gratefull. Perhaps there is some link or book that might be helpful?
Thank you again.
 
Old 01-04-2007, 02:58 AM   #4
myrto
LQ Newbie
 
Registered: Dec 2006
Posts: 29

Original Poster
Rep: Reputation: 15
I think I just found it in Polly Huang's tutorial. Still, any other sources that might help a newbie would be welcome. Thank you again!
 
Old 01-04-2007, 03:53 PM   #5
Mara
Moderator
 
Registered: Feb 2002
Location: Grenoble
Distribution: Debian
Posts: 9,696

Rep: Reputation: 232Reputation: 232Reputation: 232
Here you have NS-2 trace formats: http://nsnam.isi.edu/nsnam/index.php/NS-2_Trace_Formats and another howto: http://nile.wpi.edu/NS/
 
Old 01-06-2007, 04:04 AM   #6
myrto
LQ Newbie
 
Registered: Dec 2006
Posts: 29

Original Poster
Rep: Reputation: 15
Thank you very much! You have been most helpful.
 
Old 01-08-2007, 11:45 AM   #7
myrto
LQ Newbie
 
Registered: Dec 2006
Posts: 29

Original Poster
Rep: Reputation: 15
In the end I found this way of simulating the M/D/1 queue:

set lambda 16.0

set mu 20.0

set link [$ns simplex-link $n0 $n1 1Mb 0ms DropTail]

set InterArrivalTime [new RandomVariable/Exponential]
$InterArrivalTime set avg_ [expr 1/$lambda]
set pktSize [new RandomVariable/Constant]
$pktSize set val_ [expr 1500.0/$mu]


set src [new Agent/UDP]
$src set packetSize_ 1500
$ns attach-agent $n0 $src


set sink [new Agent/Null]
$ns attach-agent $n1 $sink
$ns connect $src $sink

proc sendpacket {} {
global ns src InterArrivalTime pktSize
set time [$ns now]
$ns at [expr $time + [$InterArrivalTime value]] "sendpacket"
set bytes [$pktSize value]
$src send $bytes
}


The problem I have concerns the constant variable pktSize. I found the simulation of an M/m/1 queue in a tutorial http://www-sop.inria.fr/maestro/pers....Altman/ns.htm It used this value for pktSize:

set pktSize [new RandomVariable/Exponential]
$pktSize set avg_ [expr round (100000.0/(8*$mu))]

In the tutorial it was implied that in order to simulate
an M/D/1 queue one has only to replace the exponential pktSize with its average.
Because I want the packet size to be 1500 bytes and the packet processing rate to be deterministic, I tried:

$pktSize set val_ 1500

$pktSize set val_ [expr 1500.0/$mu]

Both times the queue is empty and the number of packets received by the sink is 16.028. In the first case the size of the packets is 1 according to the trace file, while in the second case it is 7. And that even though I have specified that the packet size ought to be 1500bytes. Does anyone know the rate at which a null agent processes the packets it receives? Obviously I am doing something wrong with specifying the service rate and the packet size. Any help would be very welcome. Thanks.

Last edited by myrto; 01-08-2007 at 11:48 AM.
 
Old 01-10-2007, 03:51 AM   #8
myrto
LQ Newbie
 
Registered: Dec 2006
Posts: 29

Original Poster
Rep: Reputation: 15
I also tried craeting a trace file and using Traffic/Trace
but I have two problems. When I try

set tfile [new Tracefile]
$tfile filename example-trace

I get the message "no class variable Tracefile"

When I try

set tfile [new Trace file]
$tfile filename example-trace

It is accepted but then I have a problem with creating the trace file itself. I can't find an example that shows how to do this. It says in the ns-2 manual that the trace file should be in binary format and should contain the time intervals between packets and the size of the packets, so I tried this:

set traffic [new Application/Traffic/Trace]
$traffic attach-agent $src
$traffic attach-trace file $tfile

set InterArrivalTime [new RandomVariable/Exponential]
$InterArrivalTime set avg_ [expr 1/$lambda]
set pktSize [new RandomVariable/Constant]
$pktSize set val_ 1500

proc sendpacket {} {
global ns tfile InterArrivalTime pktSize
set time [$ns now]
$ns at [expr $time + [$InterArrivalTime value]] "sendpacket"
set bytes [$pktSize value]
puts $tfile "$now $bytes"
}


but I get the message:

(_o10 cmd line 1)
invoked from within
"_o10 cmd filename example-trace"
invoked from within
"catch "$self cmd $args" ret"
invoked from within
"if [catch "$self cmd $args" ret] {
set cls [$self info class]
global errorInfo
set savedInfo $errorInfo
error "error when calling class $cls: $args" $..."
(procedure "_o10" line 2)
(SplitObject unknown line 2)
invoked from within
"$tfile filename example-trace"
(file "./example10.tcl" line 7)


I know the problem lies with the trace file because I have no idea how to make it. Could anyone tell me where to find some example or instructions on building the file? Thanks.
 
Old 01-11-2007, 03:25 PM   #9
Mara
Moderator
 
Registered: Feb 2002
Location: Grenoble
Distribution: Debian
Posts: 9,696

Rep: Reputation: 232Reputation: 232Reputation: 232
Try 'Trace Analysis Example' from the howto http://nile.wpi.edu/NS/
 
Old 01-12-2007, 08:22 AM   #10
myrto
LQ Newbie
 
Registered: Dec 2006
Posts: 29

Original Poster
Rep: Reputation: 15
Thank you again for your help. I do understand the general structure of the trace file. The problem is that this example opens a trace file and then stores into it all the information about the traffic in a predefined topology, where traffic across the links is generated by traffic agents included in ns-2.

What I want to do is the exact opposite. I want to create a trace file of my own and use the information stored in it in order to generate traffic across a link. In the manual it says that this type of trace file does not require all the information that a trace file can store, just the time and size of the packets. So I try to do just
that but It seems that the code contains some mistake.


set ns [new Simulator]

set tf [open out.tr w]
$ns trace-all $tf

set tfile [new Trace file]
$tfile filename example-trace

set qsize [open queuesize.tr w]

set lambda 16.0

set n0 [$ns node]
set n1 [$ns node]

set link [$ns simplex-link $n0 $n1 1Mb 0ms DropTail]

set InterArrivalTime [new RandomVariable/Exponential]
$InterArrivalTime set avg_ [expr 1/$lambda]
set pktSize [new RandomVariable/Constant]
$pktSize set val_ 1500


set src [new Agent/UDP]
$src set packetSize_ 1500
$ns attach-agent $n0 $src


set sink [new Agent/Null]
$ns attach-agent $n1 $sink
$ns connect $src $sink

set traffic [new Application/Traffic/Trace]
$traffic attach-agent $src
$traffic attach-trace file $tfile


set qmon [$ns monitor-queue $n0 $n1 [open qm.out w] 0.1]
$link queue-sample-timeout

proc finish {} {
global ns tf tfile qsize
$ns flush-trace
close $tf
close $tfile
close $qsize
exec xgraph queuesize.tr -geometry 800x400 -t "Queue Size" -x "secs" -y "#packets"
exit 0

}

proc sendpacket {} {
global ns tfile InterArrivalTime pktSize
set time [$ns now]
set bytes [$pktSize value]
puts $tfile "$now $bytes"
$ns at [expr $time + [$InterArrivalTime value]] "sendpacket"
}

proc record {} {
global ns qmon qsize
#Get an instance of the simulator
set ns [Simulator instance]
#Set the time after which the procedure should be called again
set time 0.1
set now [$ns now]
$qmon instvar parrivals_ pdepartures_ pdrops_
puts $qsize "$now [expr $parrivals_-$pdepartures_-$pdrops_]"
#Re-schedule the procedure
$ns at [expr $now+$time] "record"
}


$ns at 0.0 "record"
$ns at 0.0001 "$traffic start"
$ns at 1000.0 "finish"

$ns run

When I try to run this I get this message:

Myrto@ma:~/ns-exercise> ns ./example10.tcl

(_o10 cmd line 1)
invoked from within
"_o10 cmd filename example-trace"
invoked from within
"catch "$self cmd $args" ret"
invoked from within
"if [catch "$self cmd $args" ret] {
set cls [$self info class]
global errorInfo
set savedInfo $errorInfo
error "error when calling class $cls: $args" $..."
(procedure "_o10" line 2)
(SplitObject unknown line 2)
invoked from within
"$tfile filename example-trace"
(file "./example10.tcl" line 7)


The problem is that I don't understand what the mistake is or how to fix it. Sorry for persisting but I really don't know what else to do. Thanks again!

Last edited by myrto; 01-12-2007 at 09:12 AM.
 
Old 01-14-2007, 01:35 PM   #11
Mara
Moderator
 
Registered: Feb 2002
Location: Grenoble
Distribution: Debian
Posts: 9,696

Rep: Reputation: 232Reputation: 232Reputation: 232
One of my old manuals (in Polish, so I don't think you're able to read it) says something like this:
Code:
set tfile [new Tracefile]
$tfile filename <file>
set src [new Application/Traffic/Trace]
$src attach-tracefile $tfile
Try to play with that.

Also, it'd be much easier to debug your code if you point out which line is line 7. I haven't used ns for years, but I may be able to find the problem when knowing where to look exactly.
 
Old 01-14-2007, 02:45 PM   #12
myrto
LQ Newbie
 
Registered: Dec 2006
Posts: 29

Original Poster
Rep: Reputation: 15
Thank you very much. Don't trouble yourself. It probably is a pretty unique case, as problems go.
Perhaps, only someone specialized on the subject of networks and the ns-simulator can help. Thanks again.
 
Old 01-19-2007, 01:37 PM   #13
realos
Member
 
Registered: Jul 2002
Location: Germany
Distribution: Redhat 7.3, Debian 3.1, Knoppix 3.1, Ubuntu 6.10
Posts: 113

Rep: Reputation: 15
I would suggest using a conforming (existing) traffic trace file to begin with. There is such a traffic trace file
under:

Ns2/ns-allinone-2.30/ns-2.30/tcl/ex/example-trace

A file called "tg.tcl" is also in the same directory which generate traffic according to tracefile "example-trace".

When you create you own tracefile make sure there is no space between the time and packet size. You can use a hex editor to edit some values manually or create a short c function.

I have also just begun using TrafficTrace in ns-2 and face some really strange problem. Sometimes my simulation runs smoothly while mostly it behaves in non-expected ways:

- sometimes a few entries from the traffic trace files are not read at all. There are no corresponding entries in resulting out.tr for a few packets in the starting lines.

- Skipping of first few entries seems to be random. S
- Sometimes simulation does not end at all. out.tr does not change itself but simulation seem to wait for some event that never occurs.

- Sometimes following error is shown:

Scheduler: Event UID not valid!


I never faced any such behavior before working with TrafficTrace. CBR traffic is working fine.
Can anybody give a hint where to look for possible bugs in the code.
 
Old 03-01-2007, 01:12 AM   #14
bind
LQ Newbie
 
Registered: Feb 2007
Posts: 3

Rep: Reputation: 0
Sir,
I am doing project in networking by using ns2 simulator. Now I want to known" How can I trace a graph from trace file(*.tr) in ns2 with example".
Actually I have to plat graph of packet delivery ratio with respect to advertissement intervals in AODV routing.The packet delivery ratio is defined as the number of received data packets divided by the number of generated data packets.
 
Old 03-01-2007, 01:15 AM   #15
bind
LQ Newbie
 
Registered: Feb 2007
Posts: 3

Rep: Reputation: 0
Sir,
I am doing project in networking by using ns2 simulator. Now I want to known" How can I trace a graph from trace file(*.tr) in ns2 with example".
Actually I have to plat graph of packet delivery ratio with respect to advertissement intervals in AODV routing.The packet delivery ratio is defined as the number of received data packets divided by the number of generated data packets.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
NS2 - network simulator liquid.o Linux - Networking 0 11-24-2006 11:36 AM
network simulator alaios Linux - Software 3 09-20-2006 04:34 AM
Network Simulator query bhuvan007 Linux - Networking 1 03-04-2006 02:12 AM
can any network simulator/emulator do this... hedpe Linux - Networking 2 02-28-2006 02:34 AM
Is there any network simulator? kizersouzay Linux - Networking 6 02-17-2006 12:00 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 05:09 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration