Please note, this is a STATIC archive of website www.tutorialspoint.com from 11 May 2019, cach3.com does not collect or store any user information, there is no "phishing" involved.
Tutorialspoint

ns2 code for point to point network for duplex link

tcl

set ns [new Simulator]
set nf [open lab1.nam w] /* open a nam trace file in write mode */
$ns namtrace-all $nf /* nf – nam file */
set tf [open lab1.tr w] /* tf- trace file */
$ns trace-all $tf
proc finish { } { /* provide space b/w proc and finish and all are in small case */ global ns nf tf
$ns flush-trace /* clears trace file contents */ close $nf
close $tf
exec nam lab1.nam & exit 0
}
set n0 [$ns node] /* creates 4 nodes */ set n1 [$ns node]
set n2 [$ns node] set n3 [$ns node]
$ns duplex-link $n0 $n2 200Mb 10ms DropTail /*Letter M is capital Mb*/
$ns duplex-link $n1 $n2 100Mb 5ms DropTail /*D and T are capital*/
$ns duplex-link $n2 $n3 1Mb 1000ms DropTail
$ns queue-limit $n0 $n2 10
$ns queue-limit $n1 $n2 10
set udp0 [new Agent/UDP] /* Letters A,U,D and P are capital */
$ns attach-agent $n0 $udp0
set cbr0 [new Application/Traffic/CBR] /* A,T,C,B and R are capital*/
$cbr0 set packetSize_ 500 /*S is capital, space after underscore*/
$cbr0 set interval_ 0.005
$cbr0 attach-agent $udp0
set udp1 [new Agent/UDP]
$ns attach-agent $n1 $udp1
set cbr1 [new Application/Traffic/CBR]
$cbr1 attach-agent $udp1
set udp2 [new Agent/UDP]
$ns attach-agent $n2 $udp2
set cbr2 [new Application/Traffic/CBR]
$cbr2 attach-agent $udp2
set null0 [new Agent/Null] /* A and N are capital */
$ns attach-agent $n3 $null0
$ns connect $udp0 $null0
$ns connect $udp1 $null0
$ns at 0.1 "$cbr0 start"
$ns at 0.2 "$cbr1 start"
$ns at 1.0 "finish"
$ns run

Abch

tcl

#!/usr/bin/tclsh

set a 100

#check the boolean condition 
if {$a < 20 } {
   #if condition is true then print the following 
   puts "a is less than 20"
} else {
   #if condition is false then print the following 
   puts "a is not less than 20"
}
puts "value of a is : $a"

Execute Tcl Online

tcl

proc SteinsGCD { u v } {
    #begin with simple cases
    if { $u == $v } { return $u }
    if { $u == 0 } { return $v }
    if { $v == 0 } { return $u } 
    
    #looking for factors of 2, u is even
    if { (~( $u )) & 1 } { 
    #v is odd
    if { $v & 1 } { return [SteinsGCD [expr $u >> 1] $v ] } } 
    #both u and v are even
    if { ((~( $u )) & 1) & ((~( $u )) & 1)} { return [expr [ SteinsGCD [expr $u >> 1] [expr $v >> 1 ] ] <<1]  }
    
    #u is odd, v is even
    if { (~( $v )) & 1 } {
        return [SteinsGCD $u [expr $v >> 1] ]
    } 
    #reduce larger argument
    if {  $u > $v } { return [SteinsGCD  [expr [ expr $u - $v]>>1] $v] }
    
    return [SteinsGCD  [expr [ expr $v - $u] >> 1] $u] 
    
}

puts "First Number\t Second Number\t GCD"
puts "------------\t -------------\t ---"
for { set x 0 } { $x < 100 } { incr x } {
set q [expr int([expr rand() * 100])]
set w [expr int([expr rand() * 100])]
set a [SteinsGCD $q $w]
puts "$q\t\t$w\t\t$a"
}

switches command example

tcl

#!/usr/bin/tclsh

regexp -nocase -line -- {([A-Z]*.([A-Z]*))} "Tcl \nTutorial" a b 
puts "Full Match: $a"
puts "Sub Match1: $b"
regexp -nocase -start 4 -line -- {([A-Z]*.([A-Z]*))} "Tcl \nTutorial" a b  
puts "Full Match: $a"
puts "Sub Match1: $b"

switches command

tcl

#!/usr/bin/tclsh

regexp -nocase {([A-Z]*.([A-Z]*))} "Tcl Tutorial" a b c  
puts "Full Match: $a"
puts "Sub Match1: $b"
puts "Sub Match2: $c"

modified pattern

tcl

#!/usr/bin/tclsh

regexp {([A-Z,a-z]*.([A-Z,a-z]*))} "Tcl Tutorial" a b c  
puts "Full Match: $a"
puts "Sub Match1: $b"
puts "Sub Match2: $c"

multiple pattterns

tcl

#!/usr/bin/tclsh

regexp {([A-Z,a-z]*).([A-Z,a-z]*)} "Tcl Tutorial" a b c  
puts "Full Match: $a"
puts "Sub Match1: $b"
puts "Sub Match2: $c"

simple regular expression

tcl

#!/usr/bin/tclsh

regexp {([A-Z,a-z]*)} "Tcl Tutorial" a b 
puts "Full Match: $a"
puts "Sub Match1: $b"

math function

tcl

#!/usr/bin/tclsh

namespace import ::tcl::mathfunc::*
puts [tan 10]
puts [pow 10 2]
puts [ceil 10.34]
puts [hypot 10 20]
puts [srand 45]
puts [log 10]
puts [srand 45]

custom error handling

tcl

#!/usr/bin/tclsh

catch {set file [open myNonexistingfile.txt]} result
puts "ErrorMsg: $result"
puts "ErrorCode: $errorCode"
puts "ErrorInfo:\n$errorInfo\n"

Advertisements
Loading...

We use cookies to provide and improve our services. By using our site, you consent to our Cookies Policy.