# Create a new simulation object set ns [new Simulator] # Create four nodes set node0 [$ns node] set node1 [$ns node] set node2 [$ns node] set node3 [$ns node] # Create a link between nodes with a 10Mbps, 10ms link delay, and DropTail queue $ns duplex-link $node0 $node1 10Mb 10ms DropTail $ns duplex-link $node1 $node2 10Mb 10ms DropTail $ns duplex-link $node2 $node3 10Mb 10ms DropTail # Create TCP agents set tcp0 [new Agent/TCP] set tcp1 [new Agent/TCP] $ns attach-agent $node0 $tcp0 $ns attach-agent $node3 $tcp1 # Create a TCP connection $ns connect $tcp0 $tcp1 # Create UDP agents set udp0 [new Agent/UDP] set udp1 [new Agent/UDP] $ns attach-agent $node0 $udp0 $ns attach-agent $node3 $udp1 # Create a UDP traffic source and sink set udp_source [new Application/Traffic/UDP] $udp_source attach-agent $udp0 $udp_source set packetSize_ 1000 $udp_source set rate_ 1Mb ;# 1 Mbps UDP traffic $udp_source set random_ false set udp_sink [new Agent/Null] $ns attach-agent $node3 $udp_sink # Connect the UDP source and sink $ns connect $udp0 $udp_sink # Create a TCP traffic generator set ftp [new Application/FTP] $ftp attach-agent $tcp0 # Schedule the TCP traffic to start at 0.1 seconds and run for 1 second $ns at 0.1 "$ftp start" $ns at 1.1 "$ftp stop" # Define a trace file for capturing network events (optional) set tracefile [open out.tr w] $ns trace-all $tracefile # Define the simulation time $ns at 2.0 "finish" # Run the simulation $ns run # Close the trace file (optional) close $tracefile
Write, Run & Share TCL code online using OneCompiler's TCL online compiler for free. It's one of the robust, feature-rich online compilers for TCL language, running the latest TCL version 8.6. Getting started with the OneCompiler's TCL editor is easy and fast. The editor shows sample boilerplate code when you choose language as TCL and start coding.
OneCompiler's TCL online editor supports stdin and users can give inputs to programs using the STDIN textbox under the I/O tab. Following is a sample TCL program which takes name as input and prints hello message with your name.
set name [gets stdin]
puts "Hello $name"
Tool Command Language(TCL) is a general purpose scripting language which is commonly used for GUIs and for testing. Everything is by default string in TCL. It was created by John Osterhout in 1989.
Variable is a identifier which is used to hold the value. set
is used to create variables.
set name onecompiler
When ever you want to perform a set of operations based on a condition IF-ELSE is used.
if(conditional-expression) {
#code
} else {
#code
}
You can also use if-else for nested Ifs and If-Else-If ladder when multiple conditions are to be performed on a single variable.
Switch is an alternative to If-Else-If ladder.
switch(conditional-expression) {
value1 {
# code
}
value1 {
# code
}
...
default {
# code
}
For loop is used to iterate a set of statements based on a condition.
for{start}{test}{next}{
# code
}
While is also used to iterate a set of statements based on a condition. Usually while is preferred when number of iterations are not known in advance.
while(condition) {
# code
}
Array is a collection of similar data which is stored in continuous memory addresses. Array values can be fetched using index. Index starts from 0 to size-1.
set ArrayName(Index) value
Procedure is a sub-routine which contains set of statements. Uusually procedures are required when multiple calls are made to same set of statements. Procedures increases re-usuability and modularity.
proc procedureName {arguments} {
# code
}