# Creates a simulator object set ns [new Simulator] #trace file name meshout.tr will keep record of network data flow set nf [open meshout.tr w] $ns trace-all $nf # trace file named meshout.nam will keep record of data flow set fr [open meshout.nam w] $ns namtrace-all $fr #colors for data flow in NAM $ns color 1 Blue $ns color 2 Orange $ns color 3 Red # defining all 6 workstation nodes for {set i 0} {$i<5} {incr i} { set n($i) [$ns node] } # finish procedure proc finish {} { global ns nf fr $ns flush-trace # Close NAM and TR trace files close $fr close $nf # Execute NAM on trace file exec nam meshout.nam & exit 0 } # Establish links between nodes $ns duplex-link $n(0) $n(1) 5Mb 2ms DropTail $ns duplex-link $n(0) $n(2) 5Mb 2ms DropTail $ns duplex-link $n(0) $n(3) 5Mb 2ms DropTail $ns duplex-link $n(0) $n(4) 5Mb 2ms DropTail $ns duplex-link $n(1) $n(2) 5Mb 2ms DropTail $ns duplex-link $n(1) $n(3) 5Mb 2ms DropTail $ns duplex-link $n(1) $n(4) 5Mb 2ms DropTail $ns duplex-link $n(2) $n(3) 5Mb 2ms DropTail $ns duplex-link $n(2) $n(4) 5Mb 2ms DropTail $ns duplex-link $n(3) $n(4) 5Mb 2ms DropTail # Queue Size for links set to 5 $ns queue-limit $n(1) $n(2) 5 $ns queue-limit $n(3) $n(4) 5 $ns queue-limit $n(4) $n(0) 5 #n1 to n3 # Setup a TCP connection set tcp1 [new Agent/TCP] $tcp1 set class_ 2 $ns attach-agent $n(1) $tcp1 set sink1 [new Agent/TCPSink] $ns attach-agent $n(3) $sink1 $ns connect $tcp1 $sink1 $tcp1 set fid_ 1 # Setup a FTP over TCP connection set ftp1 [new Application/FTP] $ftp1 attach-agent $tcp1 $ftp1 set type_ FTP #n2 to n1 # Setup a TCP connection set tcp2 [new Agent/TCP] $tcp2 set class_ 2 $ns attach-agent $n(2) $tcp2 set sink2 [new Agent/TCPSink] $ns attach-agent $n(1) $sink2 $ns connect $tcp2 $sink2 $tcp2 set fid_ 2 # Setup a FTP over TCP connection set ftp2 [new Application/FTP] $ftp2 attach-agent $tcp2 $ftp2 set type_ FTP #between n0 and n3 # Setup a UDP connection set udp [new Agent/UDP] $ns attach-agent $n(0) $udp set null [new Agent/Null] $ns attach-agent $n(3) $null $ns connect $udp $null $udp set fid_ 3 # 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_ 1mb $cbr set random_ false # Schedule events for the CBR and FTP agents $ns at 0.1 "$cbr start" $ns at 2.7 "$cbr stop" $ns at 0.3 "$ftp1 start" $ns at 2.3 "$ftp1 stop" $ns at 0.5 "$ftp2 start" $ns at 2.5 "$ftp2 stop" # Detach tcp and sink agents # (not really necessary) $ns at 3.0 "$ns detach-agent $n(1) $tcp1 ; $ns detach-agent $n(3) $sink1" $ns at 3.0 "$ns detach-agent $n(2) $tcp2 ; $ns detach-agent $n(1) $sink2" # Call the finish procedure after 3 seconds simulation $ns at 3.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
Write, Run & Share VB.net code online using OneCompiler's VB.net online compiler for free. It's one of the robust, feature-rich online compilers for VB.net language, running on the latest version 16. Getting started with the OneCompiler's VB.net compiler is simple and pretty fast. The editor shows sample boilerplate code when you choose language as VB.net
. OneCompiler also has reference programs, where you can look for the sample code to get started with.
OneCompiler's VB.net online editor supports stdin and users can give inputs to programs using the STDIN textbox under the I/O tab. Following is a sample VB.net program which takes name as input and prints hello message with your name.
Public Module Program
Public Sub Main(args() As string)
Dim name as String = Console.ReadLine() ' Reading input from STDIN
Console.WriteLine("Hello " & name) ' Writing output to STDOUT
End Sub
End Module
Visual Basic is a event driven programming language by Microsoft, first released in the year 1991.
Variable is a name given to the storage area in order to identify them in our programs.
Simple syntax of Variable declaration is as follows
Dim variableName [ As [ New ] dataType ] [ = initializer ]
variableName = value
If condition-expression Then
'code
End If
If(conditional-expression)Then
'code if the conditional-expression is true
Else
'code if the conditional-expression is false
End If
If(conditional-expression)Then
'code if the above conditional-expression is true
Else If(conditional-expression) Then
'code if the above conditional-expression is true
Else
'code if the above conditional-expression is false
End If
If(conditional-expression)Then
'code if the above conditional-expression is true
If(conditional-expression)Then
'code if the above conditional-expression is true
End If
End If
Select [ Case ] expression
[ Case expressionlist
'code ]
[ Case Else
'code ]
End Select
For counter [ As datatype ] = begin To end [ Step step ]
'code
[ Continue For ]
'code
[ Exit For ]
'code
Next [ counter ]
For Each element [ As datatype ] In group
'code
[ Continue For ]
'code
[ Exit For ]
'code
Next [ element ]
While conditional-expression
'Code
[ Continue While ]
'Code
[ Exit While ]
'Code
End While
Do { While | Until } conditional-expression
'Code
[ Continue Do ]
'Code
[ Exit Do ]
'Code
Loop
Do
'Code
[ Continue Do ]
'Code
[ Exit Do ]
'Code
Loop { While | Until } conditional-expression
Procedure is a sub-routine which contains set of statements. Usually Procedures are written when multiple calls are required to same set of statements which increases re-usuability and modularity.
Procedures are of two types.
Functions return a value when they are called.
[accessModifiers] Function functionName [(parameterList)] As returnType
'code
End Function
Sub-procedures are similar to functions but they don't return any value.
Sub ProcedureName (parameterList)
'Code
End Sub