Wednesday, April 3, 2019

SIMULATION - INDIVIDUAL AND GROUP ASSIGNMENTS (TEMPLATES)

Contents of the Individual Assignments and Group Assignments like

  • Title Page
  • Content Page
  • Introduction & Motivation
  • Definition 
  • History or Technical Background
  • Diagram (Draw neately)
  • Tables (Can be used for comparison..)
  • Applications
  • Advantages and Disadvantages or issues
  • Conclusion (like short summary)
  • Reference (Books or Journals and Websites)
  • Note: Write neatly with proper document alignment. Include Page numbers at the bottom of the page.

GROUP ASSIGNMENT  - PRESENTATION GUIDELINES
  • The Presentation should last about 15-20 minutes, not including questions
  • The Presentation should consist of 20 to 30 slides (or the equivalent amount of material)
  • The Presentation should include diagrams and graphic illustrations
  • The quickest way to create a presentation is in PowerPoint.
    •  Do not go overboard with animations, sounds, or other forms of show business
    •  As an editor, PowerPoint is even worse than Word.
    •  As an editor, PowerPoint is even worse than Word.
  • The presentation should be in English
  • The lecture should cover the following issues:
  • Introduction to the topic under discussion, including
    •  Motivation: why this topic is needed or interesting, and how it will be used
    • Overview of the talk: what you will be talking about 
  • Technological background
    • Review of the environment in which the topic system will be applied
    • Technical details of the environment required to understand the topic 
  • Overview of the topic: hardware aspects, software aspects, protocols, etc.
  • Technical details of the topic system
    • Hardware details
    • Software details
    • Protocol details
    • Information flow and how the system functions in its environment
  • Practical Issues
    • Is the technology well-defined, effective, efficient?
    • Is the technology available and has it been accepted?
  • Short Summary and Future Scope
  • References (Books & Websites)

Wednesday, May 30, 2018

XGRAPH - NS2


#Create a simulator object
set ns [new Simulator]

#Open the output files
set f0 [open out0.tr w]
set f1 [open out1.tr w]
set f2 [open out2.tr w]

#Create 5 nodes
set n0 [$ns node]
set n1 [$ns node]
set n2 [$ns node]
set n3 [$ns node]
set n4 [$ns node]

#Connect the nodes
$ns duplex-link $n0 $n3 1Mb 100ms DropTail
$ns duplex-link $n1 $n3 1Mb 100ms DropTail
$ns duplex-link $n2 $n3 1Mb 100ms DropTail
$ns duplex-link $n3 $n4 1Mb 100ms DropTail

#Define a 'finish' procedure
proc finish {} {
global f0 f1 f2
#Close the output files
close $f0
close $f1
close $f2
#Call xgraph to display the results
exec xgraph out0.tr out1.tr out2.tr -geometry 800x400 &
        exit 0
}


#Define a procedure that attaches a UDP agent to a previously created node
#'node' and attaches an Expoo traffic generator to the agent with the
#characteristic values 'size' for packet size 'burst' for burst time,
#'idle' for idle time and 'rate' for burst peak rate. The procedure connects
#the source with the previously defined traffic sink 'sink' and returns the
#source object.
proc attach-expoo-traffic { node sink size burst idle rate } {
#Get an instance of the simulator
set ns [Simulator instance]

#Create a UDP agent and attach it to the node
set source [new Agent/UDP]
$ns attach-agent $node $source

#Create an Expoo traffic agent and set its configuration parameters
set traffic [new Application/Traffic/Exponential]
$traffic set packetSize_ $size
$traffic set burst_time_ $burst
$traffic set idle_time_ $idle
$traffic set rate_ $rate
       
        # Attach traffic source to the traffic generator
        $traffic attach-agent $source
#Connect the source and the sink
$ns connect $source $sink
return $traffic
}


#Define a procedure which periodically records the bandwidth received by the
#three traffic sinks sink0/1/2 and writes it to the three files f0/1/2.
proc record {} {
        global sink0 sink1 sink2 f0 f1 f2
#Get an instance of the simulator
set ns [Simulator instance]
#Set the time after which the procedure should be called again
        set time 0.5
#How many bytes have been received by the traffic sinks?
        set bw0 [$sink0 set bytes_]
        set bw1 [$sink1 set bytes_]
        set bw2 [$sink2 set bytes_]
#Get the current time
        set now [$ns now]
#Calculate the bandwidth (in MBit/s) and write it to the files
        puts $f0 "$now [expr $bw0/$time*8/1000000]"
        puts $f1 "$now [expr $bw1/$time*8/1000000]"
        puts $f2 "$now [expr $bw2/$time*8/1000000]"
#Reset the bytes_ values on the traffic sinks
        $sink0 set bytes_ 0
        $sink1 set bytes_ 0
        $sink2 set bytes_ 0
#Re-schedule the procedure
        $ns at [expr $now+$time] "record"
}


#Create three traffic sinks and attach them to the node n4
set sink0 [new Agent/LossMonitor]
set sink1 [new Agent/LossMonitor]
set sink2 [new Agent/LossMonitor]
$ns attach-agent $n4 $sink0
$ns attach-agent $n4 $sink1
$ns attach-agent $n4 $sink2

#Create three traffic sources
set source0 [attach-expoo-traffic $n0 $sink0 200 2s 1s 100k]
set source1 [attach-expoo-traffic $n1 $sink1 200 2s 1s 200k]
set source2 [attach-expoo-traffic $n2 $sink2 200 2s 1s 300k]

#Start logging the received bandwidth
$ns at 0.0 "record"
#Start the traffic sources
$ns at 10.0 "$source0 start"
$ns at 10.0 "$source1 start"
$ns at 10.0 "$source2 start"
#Stop the traffic sources
$ns at 50.0 "$source0 stop"
$ns at 50.0 "$source1 stop"
$ns at 50.0 "$source2 stop"
#Call the finish procedure after 60 seconds simulation time
$ns at 60.0 "finish"

#Run the simulation

$ns run


OUTPUT


WIRELESS - AODV


# 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)            Queue/DropTail/PriQueue    ;# 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)             AODV                       ;# 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
}

$ns run


OUTPUT


WIRELESS - 50 NODES


# 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) Queue/DropTail/PriQueue ;# 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) 50 ;# number of mobilenodes
set val(rp) DSDV ;# routing protocol
set val(x) 1000 ;# X dimension of topography
set val(y) 1000 ;# Y dimension of topography
set val(stop) 150 ;# time of simulation end

set ns [new Simulator]
set tracefd [open simple.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)



# 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 n($i) [$ns node]
}

# Provide initial location of mobilenodes
$n(0) set X_ 347.0
$n(0) set Y_ 3.0
$n(0) set Z_ 0.0

$n(1) set X_ 345.0
$n(1) set Y_ 36.0
$n(1) set Z_ 0.0

$n(2) set X_ 330.0
$n(2) set Y_ 121.0
$n(2) set Z_ 0.0

$n(3) set X_ 316.0
$n(3) set Y_ 152.0
$n(3) set Z_ 0.0

$n(4) set X_ 246.0
$n(4) set Y_ 90.0
$n(4) set Z_ 0.0

$n(5) set X_ 379.0
$n(5) set Y_ 6.0
$n(5) set Z_ 0.0



# Set a TCP connection between n(1) and n(31)
set tcp [new Agent/TCP/Newreno]
$tcp set class_ 2
set sink [new Agent/TCPSink]
$ns attach-agent $n(1) $tcp
$ns attach-agent $n(31) $sink
$ns connect $tcp $sink
set ftp [new Application/FTP]
$ftp attach-agent $tcp
$ns at 10.0 "$ftp start"

# Set a TCP connection between n(31) and n(43)
set tcp [new Agent/TCP/Newreno]
$tcp set class_ 2
set sink [new Agent/TCPSink]
$ns attach-agent $n(31) $tcp
$ns attach-agent $n(43) $sink
$ns connect $tcp $sink

#defining heads
$ns at 0.0 "$n(0) label CH"
$ns at 0.0 "$n(1) label Source"
#$ns at 0.0 "$n(2) label N2"



$ns at 10.0 "$n(5) setdest 785.0 228.0 5.0"
$ns at 13.0 "$n(26) setdest 700.0 20.0 5.0"
$ns at 15.0 "$n(14) setdest 115.0 85.0 5.0"

#Color change while moving from one group to another
$ns at 73.0 "$n(2) delete-mark N2"
$ns at 73.0 "$n(2) add-mark N2 pink circle"
$ns at 124.0 "$n(11) delete-mark N11"
$ns at 124.0 "$n(11) add-mark N11 purple circle"
$ns at 103.0 "$n(5) delete-mark N5"
$ns at 103.0 "$n(5) add-mark N5 white circle"
$ns at 87.0 "$n(26) delete-mark N26"
$ns at 87.0 "$n(26) add-mark N26 yellow circle"
$ns at 92.0 "$n(14) delete-mark N14"
$ns at 92.0 "$n(14) add-mark N14 green circle"

# Define node initial position in nam
for {set i 0} {$i < $val(nn)} { incr i } {
# 20 defines the node size for nam
$ns initial_node_pos $n($i) 20
}

# Telling nodes when the simulation ends
for {set i 0} {$i < $val(nn) } { incr i } {
$ns at $val(stop) "$n($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 &
}


$ns run

OUTPUT

WIRELESS - NODE MOVEMENTS


set val(chan) Channel/WirelessChannel
set val(prop) Propagation/TwoRayGround
set val(netif) Phy/WirelessPhy
set val(mac)            Mac/802_11
set val(ifq) Queue/DropTail/PriQueue
set val(ll) LL
set val(ant)            Antenna/OmniAntenna
set val(x) 500
set val(y) 500
set val(ifqlen) 50
set val(nn) 7
set val(stop) 200.0
set val(rp)             AODV     

##################################################################
#     Creating New Instance of a Scheduler #
##################################################################

set ns_ [new Simulator]

##################################################################
# Creating Trace files #
##################################################################

set tracefd [open 001.tr w]
$ns_ trace-all $tracefd

##################################################################
#         Creating NAM Trace files #
##################################################################

set namtrace [open 001.nam w]
$ns_ namtrace-all-wireless $namtrace $val(x) $val(y)

set prop [new $val(prop)]

set topo [new Topography]
$topo load_flatgrid $val(x) $val(y)

create-god $val(nn)

##################################################################
# Node Configuration #
##################################################################

        $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 ON

##################################################################
# Creating Nodes #
##################################################################

for {set i 0} {$i < $val(nn) } {incr i} {
     set node_($i) [$ns_ node]
     $node_($i) random-motion 0
}

##################################################################
# Initial Positions of Nodes #
##################################################################

for {set i 0} {$i < $val(nn)} {incr i} {
$ns_ initial_node_pos $node_($i) 40
}

##################################################################
# Topology Design #
##################################################################

$ns_ at 10.0 "$node_(0) setdest 10.0 10.0 20.0"
$ns_ at 10.0 "$node_(6) setdest 310.0 10.0 20.0"
$ns_ at 10.0 "$node_(1) setdest 10.0 160.0 20.0"
$ns_ at 10.0 "$node_(4) setdest 160.0 160.0 20.0"
$ns_ at 10.0 "$node_(2) setdest 10.0 310.0 20.0"
$ns_ at 10.0 "$node_(5) setdest 310.0 310.0 20.0"
$ns_ at 10.0 "$node_(3) setdest 10.0 460.0 20.0"

##################################################################
# Generating Traffic #
##################################################################

set tcp0 [new Agent/TCP]
set sink0 [new Agent/TCPSink]
$ns_ attach-agent $node_(0) $tcp0
$ns_ attach-agent $node_(5) $sink0
$ns_ connect $tcp0 $sink0
set ftp0 [new Application/FTP]
$ftp0 attach-agent $tcp0
$ns_ at 30.0 "$ftp0 start"
$ns_ at 48.0 "$ftp0 stop"

set tcp1 [new Agent/TCP]
set sink1 [new Agent/TCPSink]
$ns_ attach-agent $node_(1) $tcp1
$ns_ attach-agent $node_(5) $sink1
$ns_ connect $tcp1 $sink1
set ftp1 [new Application/FTP]
$ftp1 attach-agent $tcp1
$ns_ at 30.0 "$ftp1 start"
$ns_ at 48.0 "$ftp1 stop"
$ns_ at 60.0 "$ftp1 start"
$ns_ at 70.0 "$ftp1 stop"

set tcp2 [new Agent/TCP]
set sink2 [new Agent/TCPSink]
$ns_ attach-agent $node_(2) $tcp2
$ns_ attach-agent $node_(6) $sink2
$ns_ connect $tcp2 $sink2
set ftp2 [new Application/FTP]
$ftp2 attach-agent $tcp2
$ns_ at 30.0 "$ftp2 start"
$ns_ at 48.0 "$ftp2 stop"

set tcp3 [new Agent/TCP]
set sink3 [new Agent/TCPSink]
$ns_ attach-agent $node_(3) $tcp3
$ns_ attach-agent $node_(6) $sink3
$ns_ connect $tcp3 $sink3
set ftp3 [new Application/FTP]
$ftp3 attach-agent $tcp3
$ns_ at 30.0 "$ftp3 start"
$ns_ at 48.0 "$ftp3 stop"

set tcp4 [new Agent/TCP]
set sink4 [new Agent/TCPSink]
$ns_ attach-agent $node_(4) $tcp4
$ns_ attach-agent $node_(6) $sink4
$ns_ connect $tcp4 $sink4
set ftp4 [new Application/FTP]
$ftp4 attach-agent $tcp4
$ns_ at 30.0 "$ftp4 start"
$ns_ at 48.0 "$ftp4 stop"

set tcp5 [new Agent/TCP]
set sink5 [new Agent/TCPSink]
$ns_ attach-agent $node_(5) $tcp5
$ns_ attach-agent $node_(6) $sink5
$ns_ connect $tcp5 $sink5
set ftp5 [new Application/FTP]
$ftp5 attach-agent $tcp5
$ns_ at 30.0 "$ftp5 start"
$ns_ at 48.0 "$ftp5 stop"

set tcp6 [new Agent/TCP]
set sink6 [new Agent/TCPSink]
$ns_ attach-agent $node_(6) $tcp6
$ns_ attach-agent $node_(5) $sink6
$ns_ connect $tcp6 $sink6
set ftp6 [new Application/FTP]
$ftp6 attach-agent $tcp6
$ns_ at 100.0 "$ftp6 produce 3"

##################################################################
# Simulation Termination #
##################################################################

for {set i 0} {$i < $val(nn) } {incr i} {
    $ns_ at $val(stop) "$node_($i) reset";
}
$ns_ at $val(stop) "puts \"NS EXITING...\" ; $ns_ halt"

puts "Starting Simulation..."

$ns_ run


OUTPUT

WIRED - TCP WITH CLIENTS


# 7 - WIRED TCP AND 4 CLIENTS
#-------Event scheduler object creation--------#
     
     
set ns [ new Simulator]

# ----------- CREATING NAM OBJECTS -----------------#

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

#Open the trace file
set nt [open Tcpred3.tr w]
$ns trace-all $nt

set proto rlm

$ns color 1 red
$ns color 2 blue
$ns color 3 yellow
$ns color 4 cyan
$ns color 5 maroon

# --------- CREATING CLIENT - ROUTER -ENDSERVER NODES-----------#

set Client1 [$ns node]
set Client2 [$ns node]
set Client3 [$ns node]
set Client4 [$ns node]
set Router1 [$ns node]
set Router2 [$ns node]
set Router3 [$ns node]
set Router4 [$ns node]
set Router5 [$ns node]
set Router6 [$ns node]
set Endserver1 [$ns node]

# --------------CREATING DUPLEX LINK -----------------------#
                       
$ns duplex-link $Client1 $Router1  5Mb 50ms DropTail
$ns duplex-link $Client2 $Router1  5Mb 50ms DropTail
$ns duplex-link $Client3 $Router1 5Mb 50ms DropTail
$ns duplex-link $Client4 $Router1 5Mb 50ms DropTail
$ns duplex-link $Router1 $Router2 5Mb 50ms DropTail
$ns duplex-link $Router2 $Router3 150Kb 50ms DropTail
$ns duplex-link $Router3 $Router4 300Kb 50ms DropTail
$ns duplex-link $Router4 $Router5 100Kb 50ms DropTail
$ns duplex-link $Router5 $Router6 300Kb 50ms DropTail
$ns duplex-link $Router6 $Endserver1 300Kb 50ms DropTail
#$ns duplex-link $Router6 $Endserver2 300Kb 50ms DropTail



#-----------CREATING ORIENTATION -------------------------#
                 
$ns duplex-link-op $Client1 $Router1 orient down-right
$ns duplex-link-op $Client2 $Router1 orient right
$ns duplex-link-op $Client3 $Router1 orient up-right
$ns duplex-link-op $Client4 $Router1 orient up
$ns duplex-link-op $Router1 $Router2 orient right
$ns duplex-link-op $Router2 $Router3 orient down
$ns duplex-link-op $Router3 $Router4 orient right
$ns duplex-link-op $Router4 $Router5 orient up
$ns duplex-link-op $Router5 $Router6 orient right
$ns duplex-link-op $Router6 $Endserver1 orient up-right
#$ns duplex-link-op $Router6 $Endserver2 orient right



# --------------CREATING LABELLING -----------------------------#

$ns at 0.0 "$Client1 label Client1"
$ns at 0.0 "$Client2 label Client2"
$ns at 0.0 "$Client3 label Client3"
$ns at 0.0 "$Client4 label Client4"
$ns at 0.0 "$Router1 label Router1"
$ns at 0.0 "$Router2 label Router2"
$ns at 0.0 "$Router3 label Router3"
$ns at 0.0 "$Router4 label Router4"
$ns at 0.0 "$Router5 label Router5"
$ns at 0.0 "$Router6 label Router6"
$ns at 0.0 "$Endserver1 label Endserver"
#$ns at 0.0 "$Endserver2 label Endserver2"

# --------------- CONFIGURING NODES -----------------#

$Endserver1 shape hexagon
$Router1 shape box
$Router2 shape square
$Router3 shape square
$Router4 shape square
$Router5 shape square
$Router6 shape square

# ----------------ESTABLISHING QUEUES -------------#

$ns duplex-link-op $Client1 $Router1 queuePos 0.1
$ns duplex-link-op $Client2 $Router1 queuePos 0.1
$ns duplex-link-op $Client3 $Router1 queuePos 0.5
$ns duplex-link-op $Client4 $Router1 queuePos 0.5
$ns duplex-link-op $Router1 $Router2 queuePos 0.1
$ns duplex-link-op $Router2 $Router3 queuePos 0.1
$ns duplex-link-op $Router3 $Router4 queuePos 0.1
$ns duplex-link-op $Router4 $Router5 queuePos 0.1
$ns duplex-link-op $Router5 $Router6 queuePos 0.5
$ns duplex-link-op $Router6 $Endserver1 queuePos 0.5

# ----------------ESTABLISHING COMMUNICATION -------------#
           
#-------CLIENT1 TO ENDSERVER1 -------------#

set tcp0 [new Agent/TCP]
$tcp0 set maxcwnd_ 16
$tcp0 set fid_ 4
$ns attach-agent $Client1 $tcp0

set sink0 [new Agent/TCPSink]
$ns attach-agent $Endserver1 $sink0

$ns connect $tcp0 $sink0

set ftp0 [new Application/FTP]
$ftp0 attach-agent $tcp0

$ns add-agent-trace $tcp0 tcp
$tcp0 tracevar cwnd_

$ns at 0.5 "$ftp0 start"
$ns at 28.5 "$ftp0 stop"

# ---------------- CLIENT2 TO ENDSERVER1 -------------#



set tcp1 [new Agent/TCP]
$tcp1 set fid_ 2
$tcp1 set maxcwnd_ 16
$ns attach-agent $Client2 $tcp1

set sink1 [new Agent/TCPSink]
$ns attach-agent $Endserver1 $sink1

$ns connect $tcp1 $sink1

set ftp1 [new Application/FTP]
$ftp1 attach-agent $tcp1

$ns add-agent-trace $tcp1 tcp1
$tcp1 tracevar cwnd_

$ns at 0.58 "$ftp1 start"
$ns at 28.5 "$ftp1 stop"

# ----------------CLIENT3 TO ENDSERVER1------------#



set tcp2 [new Agent/TCP]
$tcp2 set fid_ 0
$tcp2 set maxcwnd_ 16
$tcp2 set packetsize_ 100
$ns attach-agent $Client3 $tcp2
set sink2 [new Agent/TCPSink]
$ns attach-agent $Endserver1 $sink2
$ns connect $tcp2 $sink2

set ftp2 [new Application/FTP]
$ftp2 attach-agent $tcp2
$ns add-agent-trace $tcp2 tcp2
$tcp2 tracevar cwnd_

$ns at 0.65 "$ftp2 start"
$ns at 28.5 "$ftp2 stop"

 #--------------------CLIENT4 TO ENDSERVER1----------------#

set tcp3 [new Agent/TCP]
$tcp3 set fid_ 3
$tcp3 set maxcwnd_ 16
$tcp2 set packetsize_ 100
$ns attach-agent $Client4 $tcp3

set sink3 [new Agent/TCPSink]
$ns attach-agent $Endserver1 $sink3

$ns connect $tcp3 $sink3

set ftp3 [new Application/FTP]
$ftp3 attach-agent $tcp3

$ns add-agent-trace $tcp3 tcp3
$tcp3 tracevar cwnd_

$ns at 0.60 "$ftp3 start"
$ns at 28.5 "$ftp3 stop"
# ---------------- FINISH PROCEDURE -------------#
proc finish {} {
                 
               global ns nf nt
             
               $ns flush-trace
               close $nf
               puts "running nam..."         
               exec nam Tcpred3.nam &
               exit 0
            }

#Calling finish procedure
$ns at 15.0 "finish"

$ns run


OUTPUT


WIRED - RING TOPOLOGY



# Ring Topolog
# Node0-Node1-Node2-Node3-Node4-Node5-Node6-Node0
# Node0 is the sender and Node3 is the Receiver

#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


OUTPUT