# Simulation of "n" homogeneous On_Off Pareto Sources representing # Aggregate of "n" flows #Create a simulator object set ns [new Simulator] #Open the output files set f0 [open out0.tr w] set f1 [open out1.tr w] #Define number of sources = 100 for homogeneous sources "st0" set st0 100 set SimTime 50 #set Link BW in Mbps set linkbw 29.21Mb set linkdlay 1ms #creat a router and a destination link set rtr [$ns node] set dst [$ns node] $ns simplex-link $rtr $dst $linkbw $linkdlay DropTail #Define a 'finish' procedure proc finish {} { global f0 f1 #Close the output files close $f0 close $f1 #Call xgraph to display the results exec xgraph out0.tr out1.tr -geometry 800x400 & exit 0 } # Define a procedure that attaches a UDP agent to a previously created node 'node' # and attaches a pareto 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 and 'shape' for shape. The procedure connects the source with the # previously defined traffic sink 'sink' and returns thesource object. proc attach-pareto-traffic { node sink size burst idle rate shape } { #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/Pareto] $traffic set packetSize_ $size $traffic set burst_time_ $burst $traffic set idle_time_ $idle $traffic set rate_ $rate $traffic set shape_ $shape # Attach traffic source to the traffic generator $traffic attach-agent $source #Connect the source and the sink $ns connect $source $sink return $traffic } #Create a traffic sink and attach it to the destination (dst) set sink0 [new Agent/LossMonitor] $ns attach-agent $dst $sink0 # Define a procedure which periodically records the rate in packets/sec received by the # traffic sink sink0 and writes it to the file f0 then calculates the model parameters # for the periodic duration of the source period #set LinkBW in Packets per second set linkbwp 5000.0 set ston 0.0 ;#initialize sum time-on set sron 0.0 ;#initialize sum rate-on set ronavg 0.0 ;#initialize average rate-on set stoff 0.0 ;#initialize sum time-off set sroff 0.0 ;#initialize sum rate-off set roffavg 0.0 ;#initialize average rate-off set srcperiod 1.0 ;#set the source period to 1 second set period 0.0 ;#intialise time period counter set step 0.01 ;# set time step to read record to 0.01 seconds set agrate 0.0 ;#iniyialize aggregate rate proc record {} { global sink0 f0 f1 linkbwp srcperiod ston stoff sron sroff ronavg roffavg step period agrate #Get an instance of the simulator set ns [Simulator instance] #Set the time after which the procedure should be called again set time $step #How many packets have been received by the traffic sinks? # get the current time set now [$ns now] set bw0 [$sink0 set npkts_] #Calculate the bandwidth (in packets/s) and write it to the files set rate [expr $bw0/$time] #Begin to aggregate traffic on last srcperiod if {$rate <= $linkbwp} { set stoff [expr $stoff+$now] set sroff [expr $sroff+$rate] } else { set ston [expr $ston+$now] set sron [expr $sron+$rate] } set period [expr $ston+$stoff] if {$period == $srcperiod} { if {$ston > 0.0} { set ronavg [expr $sron/$ston] } set roffavg [expr $sroff/$stoff] set ton $ston set toff $stoff set ston 0.0 set sron 0.0 set stoff 0.0 set sroff 0.0 while {$ton > 0.0} { set agrate $ronavg set ton [expr $ton-$step] } while {$toff > 0.0} { set agrate $roffavg set toff [expr $toff-$step] } } puts $f0 "$now $rate" puts $f1 "$now $agrate" #Reset the packets_ values on the traffic sinks $sink0 set npkts_ 0.0 #Re-schedule the procedure $ns at [expr $time+$now] "record" } #Create type(0)traffic sources for {set i 0} {$i < $st0} {incr i} { set s($i) [$ns node] #Create links between type(0) sources and router $ns simplex-link $s($i) $rtr 1Mb 1ms DropTail #set the sources as pareto sources and attach them to their nodes set source($i) [attach-pareto-traffic $s($i) $sink0 500 0.35s 0.65s 668k 1.2] #Start logging the received bandwidth $ns at $step "record" #Start the traffic sources set FlowArrival [new RandomVariable/Exponential] $FlowArrival set avg_ 0.01 $ns at $FlowArrival "$source($i) start" #Stop the traffic sources $ns at $SimTime "$source($i) stop" } #Call the finish procedure after $simtime seconds (simulation time) $ns at $SimTime "finish" #Run the simulation $ns run