Question

I'm new to NS2 and trying to set up a basic dumbell-shaped network simulation; I have one node with n TCP agents (the gateway or "gw") transmitting across a link to a remote node (remote gateway, "rgw"), which is connected to n TCP sinks (each agent is connected with one sink).

enter image description here

Here is a picture with n = 5. Node 0 has five TCP agents with Pareto traffic generators; each is connected to a TCPSink agent attached to one of the nodes on the right.

I have the following TCL script to set up and test the network; it runs successfully, but when I view the trace in NAM, I can't see the packets moving. I ran a similar tutorial with NAM, and it looked fine, so there must be a bug in my own code. Can anyone help me find my error?

Thanks.

set ns [new Simulator]

# Set up trace
set trc [open out.trc w]
set namtrc [open out.nam w]
$ns trace-all $trc
$ns namtrace-all $namtrc

proc finish {} {
    global ns trc
    global ns namtrc
    $ns flush-trace
    close $trc
    close $namtrc
    exec nam out.nam &
    exit 0
}

# Simulation parameters
set n 5
set bw 150000000 # 150 Mb/s

# Set up bottleneck link
set gw  [$ns node]
set rgw [$ns node]
$ns duplex-link $gw $rgw $bw .30 DropTail

set snd {} # TCP senders sitting on the gateway node
set trf {} # Traffic generators for the senders
set dst {} # Destination nodes hosting the receivers
set rcv {} # TCP receivers sitting on the destination

for {set i 0} {$i<$n} {incr i} {
    # Create the objects needed for a new connection
    lappend snd [new Agent/TCP]
    lappend rcv [new Agent/TCPSink]
    lappend trf [new Application/Traffic/Pareto]    
    lappend srv [$ns node]

    # set up source and destination nodes
    $ns attach-agent $gw [lindex $snd $i]
    $ns attach-agent [lindex $srv $i] [lindex $rcv $i]
    [lindex $trf $i] attach-agent [lindex $snd $i]

    # Connect nodes
    $ns duplex-link $rgw [lindex $srv $i] 1000000000000 .100 DropTail
    # Connect agents
    $ns connect [lindex $snd $i] [lindex $rcv $i]
}

foreach traffic $trf {
    $ns at 0.0 "$traffic start"
}
$ns at 10.0 "finish"

$ns run

And here's an excerpt from a trace generated with this code:

+ 0.214008 0 1 pareto 40 ------- 0 0.0 2.0 0 0
- 0.214008 0 1 pareto 40 ------- 0 0.0 2.0 0 0
+ 0.321715 0 1 pareto 40 ------- 0 0.3 5.0 0 1
- 0.321715 0 1 pareto 40 ------- 0 0.3 5.0 0 1
r 0.51401 0 1 pareto 40 ------- 0 0.0 2.0 0 0
+ 0.51401 1 2 pareto 40 ------- 0 0.0 2.0 0 0
- 0.51401 1 2 pareto 40 ------- 0 0.0 2.0 0 0
r 0.61401 1 2 pareto 40 ------- 0 0.0 2.0 0 0
+ 0.61401 2 1 ack 40 ------- 0 2.0 0.0 0 2
- 0.61401 2 1 ack 40 ------- 0 2.0 0.0 0 2
r 0.621717 0 1 pareto 40 ------- 0 0.3 5.0 0 1
+ 0.621717 1 5 pareto 40 ------- 0 0.3 5.0 0 1
- 0.621717 1 5 pareto 40 ------- 0 0.3 5.0 0 1
r 0.71401 2 1 ack 40 ------- 0 2.0 0.0 0 2
+ 0.71401 1 0 ack 40 ------- 0 2.0 0.0 0 2
- 0.71401 1 0 ack 40 ------- 0 2.0 0.0 0 2
r 0.721717 1 5 pareto 40 ------- 0 0.3 5.0 0 1
+ 0.721717 5 1 ack 40 ------- 0 5.0 0.3 0 3
- 0.721717 5 1 ack 40 ------- 0 5.0 0.3 0 3
+ 0.735936 0 1 pareto 40 ------- 0 0.2 4.0 0 4
- 0.735936 0 1 pareto 40 ------- 0 0.2 4.0 0 4
r 0.821717 5 1 ack 40 ------- 0 5.0 0.3 0 3
+ 0.821717 1 0 ack 40 ------- 0 5.0 0.3 0 3
- 0.821717 1 0 ack 40 ------- 0 5.0 0.3 0 3
+ 0.831634 0 1 pareto 40 ------- 0 0.4 6.0 0 5
- 0.831634 0 1 pareto 40 ------- 0 0.4 6.0 0 5
r 1.014013 1 0 ack 40 ------- 0 2.0 0.0 0 2
+ 1.014013 0 1 pareto 1040 ------- 0 0.0 2.0 0 6
- 1.014013 0 1 pareto 1040 ------- 0 0.0 2.0 0 6
+ 1.014013 0 1 pareto 1040 ------- 0 0.0 2.0 0 7
- 1.014068 0 1 pareto 1040 ------- 0 0.0 2.0 0 7
r 1.035938 0 1 pareto 40 ------- 0 0.2 4.0 0 4
+ 1.035938 1 4 pareto 40 ------- 0 0.2 4.0 0 4
- 1.035938 1 4 pareto 40 ------- 0 0.2 4.0 0 4
r 1.121719 1 0 ack 40 ------- 0 5.0 0.3 0 3
+ 1.121719 0 1 pareto 1040 ------- 0 0.3 5.0 0 8
- 1.121719 0 1 pareto 1040 ------- 0 0.3 5.0 0 8
+ 1.121719 0 1 pareto 1040 ------- 0 0.3 5.0 0 9
- 1.121775 0 1 pareto 1040 ------- 0 0.3 5.0 0 9
r 1.131636 0 1 pareto 40 ------- 0 0.4 6.0 0 5

Looks to be working fine.

Was it helpful?

Solution

Try the below code it's work fine

 set ns [new Simulator]

# Set up trace
set trc [open out.trc w]
set namtrc [open out.nam w]
$ns trace-all $trc
$ns namtrace-all $namtrc

proc finish {} {
    global ns trc
    global ns namtrc
    $ns flush-trace
    close $trc
    close $namtrc
    exec nam out.nam &
    exit 0
}

# Simulation parameters
set n 5
set bw 150000000; # 150 Mb/s

# Set up bottleneck link
set gw  [$ns node]
set rgw [$ns node]
$ns duplex-link $gw $rgw $bw .3000 DropTail

set snd {}
 # TCP senders sitting on the gateway node
set trf {}
 # Traffic generators for the senders
set dst {}
 # Destination nodes hosting the receivers
set rcv {}
 # TCP receivers sitting on the destination

for {set i 0} {$i<$n} {incr i} {
    # Create the objects needed for a new connection
    lappend snd [new Agent/TCP]
    lappend rcv [new Agent/TCPSink]
    lappend trf [new Application/Traffic/Pareto]    
    lappend srv [$ns node]

    # set up source and destination nodes
    $ns attach-agent $gw [lindex $snd $i]
    $ns attach-agent [lindex $srv $i] [lindex $rcv $i]
    [lindex $trf $i] attach-agent [lindex $snd $i]

    # Connect nodes
    $ns duplex-link $rgw [lindex $srv $i] 10000 .10000 DropTail
    # Connect agents
    $ns connect [lindex $snd $i] [lindex $rcv $i]
}

foreach traffic $trf {
    $ns at 0.0 "$traffic start"
}
$ns at 10.0 "finish"

$ns run
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top