0% found this document useful (0 votes)
46 views

Doc1 - Merged (1) - Merged

The document describes the setup of a network simulator: 1. It creates a simulator object and defines options like the wireless channel model, MAC protocol, and routing protocol. 2. It then generates nodes, connects them with links, and defines their positions. Traffic sources and sinks are attached to nodes to generate and receive data packets. 3. Events are scheduled to start/stop the traffic and simulate link failures. The simulation is run and results including a NAM trace file are output for visualization and analysis.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
46 views

Doc1 - Merged (1) - Merged

The document describes the setup of a network simulator: 1. It creates a simulator object and defines options like the wireless channel model, MAC protocol, and routing protocol. 2. It then generates nodes, connects them with links, and defines their positions. Traffic sources and sinks are attached to nodes to generate and receive data packets. 3. Events are scheduled to start/stop the traffic and simulate link failures. The simulation is run and results including a NAM trace file are output for visualization and analysis.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 29

#Create a simulator object

set ns [new Simulator]

#Define different colors for data flows (for NAM)


$ns color 1 Blue
$ns color 2 Red

#Open the NAM trace file


set nf [open out.nam w]
$ns namtrace-all $nf

#open the trace file


set f [open simple.tr w]
$ns trace-all $f

#Define a 'finish' procedure


proc finish {} {
global ns nf f
$ns flush-trace
#Close the NAM trace file
close $nf
close $f
#Execute NAM on the trace file
exec nam out.nam &
exit 0
}

#Create four nodes


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

#Create links between the nodes


$ns duplex-link $n0 $n2 2Mb 10ms DropTail
$ns duplex-link $n1 $n2 2Mb 10ms DropTail
$ns duplex-link $n2 $n3 1.7Mb 20ms DropTail

#Set Queue Size of link (n2-n3) to 10


$ns queue-limit $n2 $n3 10

#Give node position (for NAM)


$ns duplex-link-op $n0 $n2 orient right-down
$ns duplex-link-op $n1 $n2 orient right-up
$ns duplex-link-op $n2 $n3 orient right

#Monitor the queue for link (n2-n3). (for NAM)


$ns duplex-link-op $n2 $n3 queuePos 0.5

#Setup a TCP connection


set tcp [new Agent/TCP]
$tcp set class_ 2
$ns attach-agent $n0 $tcp
set sink [new Agent/TCPSink]
$ns attach-agent $n3 $sink
$ns connect $tcp $sink
$tcp set fid_ 1

#Setup a FTP over TCP connection


set ftp [new Application/FTP]
$ftp attach-agent $tcp
$ftp set type_ FTP

#Setup a UDP connection


set udp [new Agent/UDP]
$ns attach-agent $n1 $udp
set null [new Agent/Null]
$ns attach-agent $n3 $null
$ns connect $udp $null
$udp set fid_ 2

#Setup a CBR over UDP connection (1000 bytes every 10ms)


set cbr [new Application/Traffic/CBR]
$cbr attach-agent $udp
$cbr set type_ CBR
$cbr set packet_size_ 1000
$cbr set interval_ 0.010
$cbr set random_ false

#Schedule events for the CBR and FTP agents


$ns at 0.1 "$cbr start"
$ns at 1.0 "$ftp start"
$ns at 4.0 "$ftp stop"
$ns at 4.5 "$cbr stop"

#Detach tcp and sink agents (not really necessary)


$ns at 4.5 "$ns detach-agent $n0 $tcp ; $ns detach-agent $n3 $sink"

#Call the finish procedure after 5 seconds of simulation time


$ns at 5.0 "finish"

#Print CBR packet size and interval


puts "CBR packet size = [$cbr set packet_size_]"
puts "CBR interval = [$cbr set interval_]"

#Run the simulation


$ns run
# wrls1.tcl
# A 3-node example for ad-hoc simulation with DSDV

# Define options
set val(chan) Channel/WirelessChannel ;# channel type
set val(prop) Propagation/TwoRayGround ;# radio-propagation
model
set val(netif) Phy/WirelessPhy ;# network interface
type
set val(mac) Mac/802_11 ;# MAC type
set val(ifq) CMUPriQueue ;# interface queue type
set val(ll) LL ;# link layer type
set val(ant) Antenna/OmniAntenna ;# antenna model
set val(ifqlen) 50 ;# max packet in ifq
set val(nn) 3 ;# number of
mobilenodes
set val(rp) DSR ;# routing protocol
set val(x) 500 ;# X dimension of
topography
set val(y) 400 ;# Y dimension of
topography
set val(stop) 150 ;# time of simulation end

set ns [new Simulator]


set tracefd [open simple.tr w]
set windowVsTime2 [open win.tr w]
set namtrace [open simwrls.nam w]

$ns trace-all $tracefd


$ns namtrace-all-wireless $namtrace $val(x) $val(y)

# set up topography object


set topo [new Topography]

$topo load_flatgrid $val(x) $val(y)

create-god $val(nn)

#
# Create nn mobilenodes [$val(nn)] and attach them to the channel.
#

# configure the nodes


$ns node-config -adhocRouting $val(rp) \
-llType $val(ll) \
-macType $val(mac) \
-ifqType $val(ifq) \
-ifqLen $val(ifqlen) \
-antType $val(ant) \
-propType $val(prop) \
-phyType $val(netif) \
-channelType $val(chan) \
-topoInstance $topo \
-agentTrace ON \
-routerTrace ON \
-macTrace OFF \
-movementTrace ON
for {set i 0} {$i < $val(nn) } { incr i } {
set node_($i) [$ns node]
}

# Provide initial location of mobilenodes


$node_(0) set X_ 5.0
$node_(0) set Y_ 5.0
$node_(0) set Z_ 0.0

$node_(1) set X_ 490.0


$node_(1) set Y_ 285.0
$node_(1) set Z_ 0.0

$node_(2) set X_ 150.0


$node_(2) set Y_ 240.0
$node_(2) set Z_ 0.0

# Generation of movements
$ns at 10.0 "$node_(0) setdest 250.0 250.0 3.0"
$ns at 15.0 "$node_(1) setdest 45.0 285.0 5.0"
$ns at 110.0 "$node_(0) setdest 480.0 300.0 5.0"

# Set a TCP connection between node_(0) and node_(1)


set tcp [new Agent/TCP/Newreno]
$tcp set class_ 2
set sink [new Agent/TCPSink]
$ns attach-agent $node_(0) $tcp
$ns attach-agent $node_(1) $sink
$ns connect $tcp $sink
set ftp [new Application/FTP]
$ftp attach-agent $tcp
$ns at 10.0 "$ftp start"

# Printing the window size


proc plotWindow {tcpSource file} {
global ns
set time 0.01
set now [$ns now]
set cwnd [$tcpSource set cwnd_]
puts $file "$now $cwnd"
$ns at [expr $now+$time] "plotWindow $tcpSource $file" }
$ns at 10.1 "plotWindow $tcp $windowVsTime2"

# Define node initial position in nam


for {set i 0} {$i < $val(nn)} { incr i } {
# 30 defines the node size for nam
$ns initial_node_pos $node_($i) 30
}

# Telling nodes when the simulation ends


for {set i 0} {$i < $val(nn) } { incr i } {
$ns at $val(stop) "$node_($i) reset";
}

# ending nam and the simulation


$ns at $val(stop) "$ns nam-end-wireless $val(stop)"
$ns at $val(stop) "stop"
$ns at 150.01 "puts \"end simulation\" ; $ns halt"
proc stop {} {
global ns tracefd namtrace
$ns flush-trace
close $tracefd
close $namtrace
exec nam simwrls.nam &
exit 0
}

$ns run
#Create a simulator object
set ns [new Simulator]

#Tell the simulator to use dynamic routing


$ns rtproto DV

#Open the nam trace file


set nf [open out.nam w]
$ns namtrace-all $nf

#Define a 'finish' procedure


proc finish {} {
global ns nf
$ns flush-trace
#Close the trace file
close $nf
#Execute nam on the trace file
exec nam out.nam &
exit 0
}

#Create seven nodes


for {set i 0} {$i < 7} {incr i} {
set n($i) [$ns node]
}

#Create links between the nodes


for {set i 0} {$i < 7} {incr i} {
$ns duplex-link $n($i) $n([expr ($i+1)%7]) 1Mb 10ms DropTail
}

#Create a UDP agent and attach it to node n(0)


set udp0 [new Agent/UDP]
$ns attach-agent $n(0) $udp0

# Create a CBR traffic source and attach it to udp0


set cbr0 [new Application/Traffic/CBR]
$cbr0 set packetSize_ 500
$cbr0 set interval_ 0.005
$cbr0 attach-agent $udp0

#Create a Null agent (a traffic sink) and attach it to node n(3)


set null0 [new Agent/Null]
$ns attach-agent $n(3) $null0

#Connect the traffic source with the traffic sink


$ns connect $udp0 $null0

#Schedule events for the CBR agent and the network dynamics
$ns at 0.5 "$cbr0 start"
$ns rtmodel-at 1.0 down $n(1) $n(2)
$ns rtmodel-at 2.0 up $n(1) $n(2)
$ns at 4.5 "$cbr0 stop"
#Call the finish procedure after 5 seconds of simulation time
$ns at 5.0 "finish"
#Run the simulation
$ns run
#####################################################################
################http://www.ns2blogger.blogspot.in/###################
#####################################################################
# ======================================================================
# Define options
# ======================================================================

set opt(chan) Channel/WirelessChannel ;# channel type


set opt(prop) Propagation/TwoRayGround ;# radio-propagation
model
set opt(netif) Phy/WirelessPhy ;# network interface
type
set opt(mac) Mac/802_11 ;# MAC type
set opt(ifq) Queue/DropTail/PriQueue ;# interface queue
type
set opt(ll) LL ;# link layer type
set opt(ant) Antenna/OmniAntenna ;# antenna model
set opt(ifqlen) 1000 ;# max packet in
ifq
set opt(nn) 4 ;# number of
mobilenodes
set opt(adhocRouting) DSDV ;# routing
protocol
set opt(threshold) 1.41828e-9 ;# the distance of coverage
75m
set opt(x) 100 ;# x coordinate of
topology
set opt(y) 100 ;# y coordinate of
topology
set opt(stop) 10 ;# time to stop
simulation
set num_wired_nodes 4
set num_bs_nodes 2 ;# this is not really used
here.
set size 500
# ======================================================================

set basic 1.0e6


set data 2.0e6

# create simulator instance

set ns_ [new Simulator]

# set up for hierarchical routing


$ns_ node-config -addressType hierarchical

AddrParams set domain_num_ 3 ;# number of domains


lappend cluster_num 1 1 1 ;# number of clusters in each
domain
AddrParams set cluster_num_ $cluster_num
lappend eilastlevel 7 3 3 ;# number of nodes in each cluster
AddrParams set nodes_num_ $eilastlevel ;# of each domain

set tracefd [open out.tr w]


set namtrace [open out.nam w]
$ns_ trace-all $tracefd
$ns_ namtrace-all $namtrace
$ns_ namtrace-all-wireless $namtrace $opt(x) $opt(y)

set f1 [open s1 a]
set f2 [open s2 a]
set f3 [open s3 a]
set f4 [open s4 a]

# Create topography object


set topo [new Topography]

# define topology
$topo load_flatgrid $opt(x) $opt(y)

# create God
create-god $opt(nn)

#-=-=-=-NAM=-=-=-=--=-=-=-=-=-=-=-=-=---=-=---=-=-=-=-=
#set ns_ [new Simulator]
set f0 [open wir7.tr w]
$ns_ trace-all $f0
$ns_ use-newtrace
set namtrace [open out.nam w]
$ns_ namtrace-all-wireless $namtrace $opt(x) $opt(y)
#=-=--=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
#create wired nodes

set W1 [$ns_ node 0.0.0]


set W2 [$ns_ node 0.0.1]
set W3 [$ns_ node 0.0.2]
set W4 [$ns_ node 0.0.3]
set W5 [$ns_ node 0.0.4]
#set W6 [$ns_ node 0.0.5]
#set W7 [$ns_ node 0.0.6]
set W8 [$ns_ node 0.0.5]
set W9 [$ns_ node 0.0.6]

# Configure for Basestation Node


$ns_ node-config -adhocRouting $opt(adhocRouting) \
-llType $opt(ll) \
-macType $opt(mac) \
-ifqType $opt(ifq) \
-ifqLen $opt(ifqlen) \
-antType $opt(ant) \
-propType $opt(prop) \
-phyType $opt(netif) \
-channelType $opt(chan) \
-topoInstance $topo \
-wiredRouting ON \
-agentTrace ON \
-routerTrace ON \
-macTrace OFF

Phy/WirelessPhy set RXThresh_ $opt(threshold)

# Position (fixed) for base-station nodes (HA & FA).


set BS1 [$ns_ node 1.0.0]
set BS2 [$ns_ node 2.0.0]

# create a mobilenode that would be moving between HA and FA.


# note address of MH indicates its in the same domain as HA.
$ns_ node-config -wiredRouting OFF

set R1 [$ns_ node 1.0.2]


set R2 [$ns_ node 1.0.3]
set R3 [$ns_ node 2.0.2]
set R4 [$ns_ node 2.0.3]

$R1 base-station [AddrParams addr2id [$BS1 node-addr]]


$R2 base-station [AddrParams addr2id [$BS1 node-addr]]
$R3 base-station [AddrParams addr2id [$BS2 node-addr]]
$R4 base-station [AddrParams addr2id [$BS2 node-addr]]

# position of the nodes


$R1 set X_ 120.000000000000
$R1 set Y_ 80.000000000000
$R1 set Z_ 0.000000000000

$R2 set X_ 160.000000000000


$R2 set Y_ 40.000000000000
$R2 set Z_ 0.000000000000

$R3 set X_ 160.000000000000


$R3 set Y_ 0.000000000000
$R3 set Z_ 0.000000000000

$R4 set X_ 160.000000000000


$R4 set Y_ -40.000000000000
$R4 set Z_ 0.000000000000

$ns_ at 2.0 "$R1 setdest 90.0 20.0 20.0"


$ns_ at 2.0 "$R3 setdest 90.0 82.0 20.0"

# create links between wired and BaseStation nodes


$ns_ duplex-link $W1 $W3 2Mb 20ms DropTail
$ns_ duplex-link $W2 $W4 2Mb 20ms DropTail
$ns_ duplex-link $W8 $W3 2Mb 20ms DropTail
$ns_ duplex-link $W9 $W4 2Mb 20ms DropTail

$ns_ duplex-link $W3 $W5 5Mb 20ms DropTail


$ns_ duplex-link $W4 $W5 5Mb 20ms DropTail
#$ns_ duplex-link $W5 $W6 10Mb 20ms DropTail
#$ns_ duplex-link $W5 $W7 10Mb 20ms DropTail
$ns_ duplex-link $W5 $BS1 5Mb 20ms DropTail
$ns_ duplex-link $W5 $BS2 5Mb 20ms DropTail

# set the layout of links in NAM


$ns_ duplex-link-op $W1 $W3 orient right
$ns_ duplex-link-op $W8 $W3 orient right-down

$ns_ duplex-link-op $W2 $W4 orient right-up


$ns_ duplex-link-op $W9 $W4 orient right

$ns_ duplex-link-op $W3 $W5 orient right-down


$ns_ duplex-link-op $W4 $W5 orient right-up

#$ns_ duplex-link-op $W5 $W6 orient right-up


#$ns_ duplex-link-op $W5 $W7 orient right-down
$ns_ duplex-link-op $W5 $BS1 orient right-up
$ns_ duplex-link-op $W5 $BS2 orient right-down

$ns_ at 0.0 "$W1 label W1"


$ns_ at 0.0 "$W2 label W2"
$ns_ at 0.0 "$W8 label W3"
$ns_ at 0.0 "$W9 label W4"
$ns_ at 0.0 "$W3 label R1"
$ns_ at 0.0 "$W4 label R2"
$ns_ at 0.0 "$W5 label R3"
#$ns_ at 0.0 "$W6 label R4"
#$ns_ at 0.0 "$W7 label R5"
$ns_ at 0.0 "$BS1 label BS1"
$ns_ at 0.0 "$BS2 label BS2"
$ns_ at 0.0 "$R1 label R1"
$ns_ at 0.0 "$R2 label R2"
$ns_ at 0.0 "$R3 label R3"
$ns_ at 0.0 "$R4 label R4"
$ns_ at 0.0 "$R1 add-mark m1 green circle"
$ns_ at 0.0 "$R2 add-mark m1 red circle"
$ns_ at 0.0 "$R3 add-mark m1 blue circle"
$ns_ at 0.0 "$R4 add-mark m1 purple circle"
# setup TCP connections

set tcp1 [new Agent/TCP/Newreno]


$tcp1 set packetSize_ $size
$ns_ attach-agent $W1 $tcp1
set sink1 [new Agent/TCPSink]
$ns_ attach-agent $R1 $sink1
$ns_ connect $tcp1 $sink1
set ftp1 [new Application/FTP]
$ftp1 attach-agent $tcp1
$ns_ at 1.0 "$ftp1 start"
$ns_ at 1.0 "$ns_ trace-annotate \"W1 Sends packets to R1 via Home
Agent(BS1). \""

set tcp2 [new Agent/TCP/Newreno]


$tcp2 set packetSize_ $size
$ns_ attach-agent $W8 $tcp2
set sink2 [new Agent/TCPSink]
$ns_ attach-agent $R2 $sink2
$ns_ connect $tcp2 $sink2
set ftp2 [new Application/FTP]
$ftp2 attach-agent $tcp2
$ns_ at 2.0 "$ftp2 start"
$ns_ at 2.0 "$ns_ trace-annotate \"W3 Sends packets to R2 via Home
Agent(BS1). \""

set tcp3 [new Agent/TCP/Newreno]


$tcp3 set packetSize_ $size
$ns_ attach-agent $W2 $tcp3
set sink3 [new Agent/TCPSink]
$ns_ attach-agent $R3 $sink3
$ns_ connect $tcp3 $sink3
set ftp3 [new Application/FTP]
$ftp3 attach-agent $tcp3
$ns_ at 3.0 "$ftp3 start"
$ns_ at 3.0 "$ns_ trace-annotate \"W2 Sends packets to R3 via Home
Agent(BS2). \""

set tcp4 [new Agent/TCP/Newreno]


$tcp4 set packetSize_ $size
$ns_ attach-agent $W9 $tcp4
set sink4 [new Agent/TCPSink]
$ns_ attach-agent $R4 $sink4
$ns_ connect $tcp4 $sink4
set ftp4 [new Application/FTP]
$ftp4 attach-agent $tcp4
$ns_ at 4.0 "$ftp4 start"
$ns_ at 4.0 "$ns_ trace-annotate \"W4 Sends packets to R4 via Home
Agent(BS2). \""

# Define initial node position in nam

$ns_ initial_node_pos $R1 10


$ns_ initial_node_pos $R2 10
$ns_ initial_node_pos $R3 10
$ns_ initial_node_pos $R4 10

# Tell all nodes when the siulation ends


$ns_ at $opt(stop).0 "$R1 reset";
$ns_ at $opt(stop).0 "$R2 reset";
$ns_ at $opt(stop).0 "$R3 reset";
$ns_ at $opt(stop).0 "$R4 reset";

$ns_ at $opt(stop).0002 "puts \"NS EXITING...\" ; $ns_ halt"


$ns_ at $opt(stop).0001 "stop"

proc stop {} {
global ns_ tracefd namtrace opt f0

global ns_ f1 f2 f3 f4 tcp1 tcp2 tcp3 tcp4 mbw1 mbw2 mbw3 mbw4 rate size
global sink
$ns_ flush-trace
close $tracefd
close $f0
close $namtrace
#received bytes
set bw1 [$tcp1 set ndatabytes_]
set bw2 [$tcp2 set ndatabytes_]
set bw3 [$tcp3 set ndatabytes_]
set bw4 [$tcp4 set ndatabytes_]

#set current time


set now [$ns_ now]
set time $now

# convert bytes into Mb/s


set mbw1 [expr $bw1/$time*8/1000000]
set mbw2 [expr $bw2/$time*8/1000000]
set mbw3 [expr $bw3/$time*8/1000000]
set mbw4 [expr $bw4/$time*8/1000000]

set tot [expr $mbw1 + $mbw2 + $mbw3 + $mbw4 ]


puts $tot
puts "NS Exiting ..."
puts $f1 "$mbw1"
puts $f2 "$mbw2"
puts $f3 "$mbw3"
puts $f4 "$mbw4"
# close $tracefd
# close $namtrace
exec nam out.nam &
exit 0
}

puts "Starting Simulation..."


$ns_ run
# ======================================================================
#Create a simulator object
set ns [new Simulator]

#Define different colors for data flows (for NAM)


$ns color 1 Blue

#Open the NAM trace file


set nf [open out.nam w]
$ns namtrace-all $nf

# Open the trace file


set f [open tcp.tr w]
$ns trace-all $f

#Define a 'finish' procedure


proc finish {} {
global ns nf f
$ns flush-trace
#Close the NAM trace file
close $nf
# Close the trace file
close $f
#Execute NAM on the trace file
exec nam out.nam &
exit 0
}

#Create three nodes


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

#Create links between the nodes


$ns duplex-link $n0 $n1 1Mb 50ms DropTail
$ns duplex-link $n1 $n2 100Kb 5ms DropTail

#Set Queue Size of link (n1-n2) to 10


$ns queue-limit $n1 $n2 10

#Give node position (for NAM)


$ns duplex-link-op $n0 $n1 orient right
$ns duplex-link-op $n1 $n2 orient right

#Monitor the queue for link (n1-n2). (for NAM)


$ns duplex-link-op $n1 $n2 queuePos 0.5

#Setup a TCP connection


set tcp [new Agent/TCP]
$tcp set class_ 1
$ns attach-agent $n0 $tcp
set sink [new Agent/TCPSink]
$ns attach-agent $n2 $sink
$ns connect $tcp $sink

#Setup a FTP over TCP connection


set ftp [new Application/FTP]
$ftp attach-agent $tcp
#Start and stop FTP
$ns at 0.5 "$ftp start"
$ns at 50.5 "$ftp stop"

#Call the finish procedure after 51 seconds of simulation time


$ns at 51.0 "finish"

#Run the simulation


$ns run
#####################################################################
################http://www.ns2blogger.blogspot.in/###################
#####################################################################
set ns [new Simulator]

#Define different colors for data flows (for NAM)


$ns color 1 Blue
$ns color 2 Green

#Open the Trace files


set file1 [open out.tr w]
set winfile [open WinFile w]
$ns trace-all $file1

#Open the NAM trace file


set file2 [open out.nam w]
$ns namtrace-all $file2

#Define a 'finish' procedure


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

#Create six nodes


set n0 [$ns node]
set n1 [$ns node]
set n2 [$ns node]
set n3 [$ns node]
set n4 [$ns node]
set n5 [$ns node]

$n1 color green


$n1 shape box
$n5 color green
$n5 shape box
$n0 color blue
$n0 shape circle
$n4 color blue
$n4 shape circle
# $n1 shape box

#Create links between the nodes


$ns duplex-link $n0 $n2 2Mb 10ms DropTail
$ns duplex-link $n1 $n2 2Mb 10ms DropTail
$ns simplex-link $n2 $n3 0.3Mb 100ms DropTail
$ns simplex-link $n3 $n2 0.3Mb 100ms DropTail

set lan [$ns newLan "$n3 $n4 $n5" 0.5Mb 40ms LL Queue/DropTail MAC/802_3
Channel]

# $ns duplex-link $n3 $n4 0.5Mb 40ms DropTail


# $ns duplex-link $n3 $n5 0.5Mb 30ms DropTail
#Give node position (for NAM)
# $ns duplex-link-op $n0 $n2 orient right-down
# $ns duplex-link-op $n1 $n2 orient right-up
# $ns simplex-link-op $n2 $n3 orient right
# $ns simplex-link-op $n3 $n2 orient left
# $ns duplex-link-op $n3 $n4 orient right-up
# $ns duplex-link-op $n3 $n5 orient right-down

#Set Queue Size of link (n2-n3) to 10


# $ns queue-limit $n2 $n3 20

#Setup a TCP connection


set tcp [new Agent/TCP/Newreno]
$ns attach-agent $n0 $tcp
set sink [new Agent/TCPSink/DelAck]
$ns attach-agent $n4 $sink
$ns connect $tcp $sink
$tcp set fid_ 1
$tcp set window_ 8000
$tcp set packetSize_ 552

#Setup a FTP over TCP connection


set ftp [new Application/FTP]
$ftp attach-agent $tcp
$ftp set type_ FTP

#Setup a UDP connection


set udp [new Agent/UDP]
$ns attach-agent $n1 $udp
set null [new Agent/Null]
$ns attach-agent $n5 $null
$ns connect $udp $null
$udp set fid_ 2

#Setup a CBR over UDP connection


set cbr [new Application/Traffic/CBR]
$cbr attach-agent $udp
$cbr set type_ CBR
$cbr set packet_size_ 1000
$cbr set rate_ 0.01mb
$cbr set random_ false

$ns at 0.1 "$cbr start"


$ns at 1.0 "$ftp start"
$ns at 124.0 "$ftp stop"
$ns at 124.5 "$cbr stop"

# next procedure gets two arguments: the name of the


# tcp source node, will be called here "tcp",
# and the name of output file.

proc plotWindow {tcpSource file} {


global ns
set time 0.1
set now [$ns now]
set cwnd [$tcpSource set cwnd_]
set wnd [$tcpSource set window_]
puts $file "$now $cwnd"
$ns at [expr $now+$time] "plotWindow $tcpSource $file" }
$ns at 0.1 "plotWindow $tcp $winfile"

$ns at 5 "$ns trace-annotate \"packet drop\""

# PPP

$ns at 125.0 "finish"


$ns run

You might also like