# Create simulator object set ns [new Simulator] # Open files to write trace-data for NAM and Xgraph set nf [open mm.nam w] $ns namtrace-all $nf set f0 [open mm.tr w] $ns trace-all $f0 # Finish procedure which closes the trace file and opens Xgraph and NAM proc finish {} { global ns nf f0 $ns flush-trace close $nf close $f0 exec nam mm.nam & exit 0 } proc attach-expoo-traffic { node sink size burst idle rate } { global ns set udp [new Agent/UDP] $ns attach-agent $node $udp set traffic [new Application/Traffic/Exponential] $traffic set packetSize_ $size $traffic set burst_time_ $burst $traffic set idle_time_ $idle $traffic set rate_ $rate $traffic attach-agent $udp $ns connect $udp $sink return $traffic } Agent/LDP set trace_ldp_ 1 Classifier/Addr/MPLS set trace_mpls_ 1 $ns use-scheduler List $ns rtproto DV set node0 [$ns node] $ns node-config -MPLS ON set LSR1 [$ns node] set LSR2 [$ns node] set LSR3 [$ns node] set LSR4 [$ns node] set LSR5 [$ns node] $ns node-config -MPLS OFF set node6 [$ns node] # # Define links, bandwidth 1 Mb, delay 10ms, queue managementDropTail # $ns duplex-link $node0 $LSR1 1Mb 10ms DropTail $ns duplex-link $LSR1 $LSR2 1Mb 10ms DropTail $ns duplex-link $LSR2 $LSR3 1Mb 10ms DropTail $ns duplex-link $LSR3 $LSR4 1Mb 10ms DropTail $ns duplex-link $LSR1 $LSR5 1Mb 10ms DropTail $ns duplex-link $LSR5 $LSR4 1Mb 10ms DropTail $ns duplex-link $LSR4 $node6 1Mb 10ms DropTail # # configure ldp agents on all mpls nodes # for {set i 1} {$i < 6} {incr i} { set a LSR$i for {set j [expr $i+1]} {$j < 6} {incr j} { set b LSR$j eval $ns LDP-peer $$a $$b } set m [eval $$a get-module "MPLS"] $m enable-reroute "new" } # # set ldp-message clolr # $ns ldp-request-color blue $ns ldp-mapping-color red $ns ldp-withdraw-color magenta $ns ldp-release-color orange $ns ldp-notification-color yellow Classifier/Addr/MPLS enable-on-demand Classifier/Addr/MPLS enable-ordered-control [$LSR1 get-module "MPLS"] enable-data-driven [$LSR2 get-module "MPLS"] enable-data-driven # Create a traffic sink and attach it to the node node8 set sink0 [new Agent/LossMonitor] $ns attach-agent $node6 $sink0 # Create a traffic source set src0 [ attach-expoo-traffic $node0 $sink0 200 0 0 400k] $ns at 0.0 "$src0 start" #for working path $ns at 0.0 "[$LSR1 get-module MPLS] make-explicit-route 4 1_2_3_4 2000 -1" # for reroute $ns at 0.0 "[$LSR1 get-module MPLS] make-explicit-route 4 5_4 3000 -1" $ns at 0.1 "[$LSR4 get-module MPLS] make-explicit-route 4 3_2_1_3000 3005 -1" $ns at 0.2 "[$LSR1 get-module MPLS] flow-erlsp-install 6 -1 2000" #routing binding $ns at 0.3 "[$LSR1 get-module MPLS] reroute-binding 6 -1 3005" $ns at 0.3 "[$LSR2 get-module MPLS] reroute-binding 6 -1 3005" $ns at 0.3 "[$LSR3 get-module MPLS] reroute-binding 6 -1 3005" $ns rtmodel-at 0.5 down $LSR2 $LSR3 $ns rtmodel-at 0.7 up $LSR2 $LSR3 $ns at 0.8 "$src0 stop" # # Displays the erb/lib/pft-table of the given LSR at the command prompt # $ns at 0.9 "[$LSR1 get-module MPLS] erb-dump" $ns at 0.9 "[$LSR1 get-module MPLS] lib-dump" $ns at 0.9 "[$LSR1 get-module MPLS] pft-dump" # Calls the procedure "finish" $ns at 1.0 "finish" # The last line finally starts the simulation $ns run