writing proc avg in tcl script in ns2_new - tcl

I wrote a scenario in ns2 software that has 5 fixed nodes and 1 mobile sink.
The mobile sink should collect the nodes' information.
I want to calculate the mean avg (energy_level ,number of nodes & traffic's data on nodes) and store it in the mobile sink.
The my code that I wrote does not any error but it does not print out.
My code & trace file are in attachment
I have to calculate this avg with proc in tcl script code not with awk code.Please help me.
proc create_common_app {destination_id disseminating_type disseminating_interval energy_level } {
global val
#puts "executing create_common_app\n"
if { $val(commonApp) == "Application/SensorBaseApp/CommonNodeApp" }
{
set app_ [new $val(commonApp)]
$app_ set destination_id_ $destination_id
}
$app_ set disseminating_type_ $disseminating_type
$app_ set disseminating_interval_ $disseminating_interval
$app_ set energy_level _ $energy_level
return $app_
}
proc create_mobile_sink_app { source _id disseminating_type disseminating_interval energy_level outside_network} {
global val
set app_ [new $val(sinkApp)]
$app_ set source _id _ $source _id
$app_ set disseminating_type_ $disseminating_type
$app_ set disseminating_interval_ $disseminating_interval
$app_ set energy_level _ $energy_level
$app_ set outside_network_ $outside_network
#$app_ set avg_ $avg
return $app_
}
#########################################################################
#Me
####################################################################
proc avg { energy_level nn disseminating_interval } {
set avgen 0
for {set i 0} {$i < 5} {incr i} {
set $avgen [expr $energy_level(i) + $avgen ]
}
set $avgen [expr $avgen / $nn]
return $avgen
set xl [list $avgen $nn $disseminating_interval]
}
proc ArithmeticMean { $xl } {
set length [llength $xl]
if {$length == 0} {
return 0.0
}
set sum [::tcl::mathop::+ {*}$xl]
return [expr {double($sum) / $length}]
set avgt [expr {double($sum) / $length}]
puts "average is $avgt_"
}
#####################################################################
tracefile
M 0.00000 0 (9.00, 5.00, 0.00), (0.00, 0.00), 0.00
s 5.000000000 _1_ AGT --- 0 cbr 150 [0 0 0 0] [energy 0.050000 ei 0.000 es 0.000 et 0.000 er 0.000] ------- [1:0 2:0 32 0] [0] 0 0
r 5.000000000 _1_ RTR --- 0 cbr 150 [0 0 0 0] [energy 0.050000 ei 0.000 es 0.000 et 0.000 er 0.000] ------- [1:0 2:0 32 0] [0] 0 0
s 5.000000000 _1_ AGT --- 1 cbr 150 [0 0 0 0] [energy 0.050000 ei 0.000 es 0.000 et 0.000 er 0.000] ------- [1:0 2:0 32 0] [1] 0 0
r 5.000000000 _1_ RTR --- 1 cbr 150 [0 0 0 0] [energy 0.050000 ei 0.000 es 0.000 et 0.000 er 0.000] ------- [1:0 2:0 32 0] [1] 0 0
s 5.000000000 _1_ AGT --- 2 cbr 150 [0 0 0 0] [energy 0.050000 ei 0.000 es 0.000 et 0.000 er 0.000] ------- [1:0 2:0 32 0] [2] 0 0
r 5.000000000 _1_ RTR --- 2 cbr 150 [0 0 0 0] [energy 0.050000 ei 0.000 es 0.000 et 0.000 er 0.000] ------- [1:0 2:0 32 0] [2] 0 0
s 5.000000000 _1_ AGT --- 3 cbr 150 [0 0 0 0] [energy 0.050000 ei 0.000 es 0.000 et 0.000 er 0.000] ------- [1:0 2:0 32 0] [3] 0 0
r 5.000000000 _1_ RTR --- 3 cbr 150 [0 0 0 0] [energy 0.050000 ei 0.000 es 0.000 et 0.000 er 0.000] ------- [1:0 2:0 32 0] [3] 0 0
s 5.000000000 _1_ AGT --- 4 cbr 150 [0 0 0 0] [energy 0.050000 ei 0.000 es 0.000 et 0.000 er 0.000] ------- [1:0 2:0 32 0] [4] 0 0
r 5.000000000 _1_ RTR --- 4 cbr 150 [0 0 0 0] [energy 0.050000 ei 0.000 es 0.000 et 0.000 er 0.000] ------- [1:0 2:0 32 0] [4] 0 0
s 5.000000000 _1_ AGT --- 5 cbr 150 [0 0 0 0] [energy 0.050000 ei 0.000 es 0.000 et 0.000 er 0.000] ------- [1:0 2:0 32 0] [5] 0 0
r 5.000000000 _1_ RTR --- 5 cbr 150 [0 0 0 0] [energy 0.050000 ei 0.000 es 0.000 et 0.000 er 0.000] ------- [1:0 2:0 32 0] [5] 0 0
s 5.000000000 _1_ AGT --- 6 cbr 100 [0 0 0 0] [energy 0.050000 ei 0.000 es 0.000 et 0.000 er 0.000] ------- [1:0 2:0 32 0] [6] 0 0
r 5.000000000 _1_ RTR --- 6 cbr 100 [0 0 0 0] [energy 0.050000 ei 0.000 es 0.000 et 0.000 er 0.000] ------- [1:0 2:0 32 0] [6] 0 0
s 5.000000000 _1_ RTR --- 0 AODV 48 [0 0 0 0] [energy 0.050000 ei 0.000 es 0.000 et 0.000 er 0.000] ------- [1:255 -1:255 30 0] [0x2 1 1 [2 0] [1 4]] (REQUEST)
s 5.000535000 _1_ MAC --- 0 AODV 106 [0 ffffffff 2 800] [energy 0.050000 ei 0.000 es 0.000 et 0.000 er 0.000] ------- [1:255 -1:255 30 0] [0x2 1 1 [2 0] [1 4]] (REQUEST)
N -t 5.000535 -n 0 -e 0.049980
N -t 5.000535 -n 4 -e 0.049980
N -t 5.000535 -n 2 -e 0.049980
N -t 5.000535 -n 3 -e 0.049980
r 5.001383005 _0_ MAC --- 0 AODV 48 [0 ffffffff 2 800] [energy 0.049980 ei 0.000 es 0.000 et 0.000 er 0.000] ------- [1:255 -1:255 30 0] [0x2 1 1 [2 0] [1 4]] (REQUEST)
r 5.001383013 _4_ MAC --- 0 AODV 48 [0 ffffffff 2 800] [energy 0.049980 ei 0.000 es 0.000 et 0.000
.
.
.....

proc avg { energy_level nn disseminating_interval } {
set avgen 0
for {set i 0} {$i < 5} {incr i} {
set $avgen [expr $energy_level(i) + $avgen ]
}
set $avgen [expr $avgen / $nn]
return $avgen
set xl [list $avgen $nn $disseminating_interval]
}
Notes:
You can't pass arrays by value: you need to pass the array name and use upvar to connect the name to the actual array in the caller's context
Use braces around your expr expressions.
You need to dereference $i in the array expansion.
Don't use $ in the first argument to set
do you want to use $nn in the for loop, or the hard-coded value 5?
Corrected code
proc avg { energy_level_var nn disseminating_interval } {
upvar 1 $energy_level_var energy_level
if {$nn == 0} {
error "denominator cannot be zero"
}
set sum 0
for {set i 0} {$i < $nn} {incr i} {
set sum [expr {$energy_level($i) + $sum}]
}
return [expr {$sum / $nn}]
}
And call like this
array set energy_level {0 1.0 1 1.1 2 1.2 3 1.3 4 1.4 5 1.5}
puts "average is: [avg energy_level 6 "?"]" ;# average is: 1.25
Also, don't use $ in the declaration of the ArithmeticMean proc:
proc ArithmeticMean { xl } {

Related

Reverse engineering python .exe, can not find strings

I started with reverse engineering and using the IDA disassembler tool.
I wrote some programs in C++, made an .exe and reversed it in IDA to "hack" my own programs.
Now I wanted to do the same with a python program. As a start a made this simple program:
inp = input("What is your name?\n")
print("Hi", inp)
Then I built an .exe using:
pyinstaller main.py
Loaded it into IDA and searched for strings. IDA gives me a lot of strings but "What is your name" is not in its list. Why is that?
Yes, pyinstaller builds an executable but it is not a "normal" executable. Your Python code is actually in a compressed archive.
$ readelf -S main
There are 30 section headers, starting at offset 0x1ad400:
Section Headers:
[Nr] Name Type Address Offset
Size EntSize Flags Link Info Align
[ 0] NULL 0000000000000000 00000000
0000000000000000 0000000000000000 0 0 0
[ 1] .interp PROGBITS 00000000000002a8 000002a8
000000000000001c 0000000000000000 A 0 0 1
[ 2] .note.ABI-tag NOTE 00000000000002c4 000002c4
0000000000000020 0000000000000000 A 0 0 4
[ 3] .note.gnu.bu[...] NOTE 00000000000002e4 000002e4
0000000000000024 0000000000000000 A 0 0 4
[ 4] .gnu.hash GNU_HASH 0000000000000308 00000308
0000000000000034 0000000000000000 A 5 0 8
[ 5] .dynsym DYNSYM 0000000000000340 00000340
00000000000007b0 0000000000000018 A 6 1 8
[ 6] .dynstr STRTAB 0000000000000af0 00000af0
0000000000000348 0000000000000000 A 0 0 1
[ 7] .gnu.version VERSYM 0000000000000e38 00000e38
00000000000000a4 0000000000000002 A 5 0 2
[ 8] .gnu.version_r VERNEED 0000000000000ee0 00000ee0
00000000000000a0 0000000000000000 A 6 3 8
[ 9] .rela.dyn RELA 0000000000000f80 00000f80
0000000000000198 0000000000000018 A 5 0 8
[10] .rela.plt RELA 0000000000001118 00001118
00000000000006d8 0000000000000018 AI 5 24 8
[11] .init PROGBITS 0000000000002000 00002000
0000000000000017 0000000000000000 AX 0 0 4
[12] .plt PROGBITS 0000000000002020 00002020
00000000000004a0 0000000000000010 AX 0 0 16
[13] .plt.got PROGBITS 00000000000024c0 000024c0
0000000000000008 0000000000000008 AX 0 0 8
[14] .text PROGBITS 00000000000024d0 000024d0
0000000000003f21 0000000000000000 AX 0 0 16
[15] .fini PROGBITS 00000000000063f4 000063f4
0000000000000009 0000000000000000 AX 0 0 4
[16] .rodata PROGBITS 0000000000007000 00007000
0000000000001618 0000000000000000 A 0 0 8
[17] .eh_frame_hdr PROGBITS 0000000000008618 00008618
000000000000025c 0000000000000000 A 0 0 4
[18] .eh_frame PROGBITS 0000000000008878 00008878
0000000000000e90 0000000000000000 A 0 0 8
[19] .init_array INIT_ARRAY 000000000000ad70 00009d70
0000000000000008 0000000000000008 WA 0 0 8
[20] .fini_array FINI_ARRAY 000000000000ad78 00009d78
0000000000000008 0000000000000008 WA 0 0 8
[21] .data.rel.ro PROGBITS 000000000000ad80 00009d80
0000000000000040 0000000000000000 WA 0 0 32
[22] .dynamic DYNAMIC 000000000000adc0 00009dc0
0000000000000210 0000000000000010 WA 6 0 8
[23] .got PROGBITS 000000000000afd0 00009fd0
0000000000000028 0000000000000008 WA 0 0 8
[24] .got.plt PROGBITS 000000000000b000 0000a000
0000000000000260 0000000000000008 WA 0 0 8
[25] .data PROGBITS 000000000000b260 0000a260
0000000000000010 0000000000000000 WA 0 0 8
[26] .bss NOBITS 000000000000b280 0000a270
00000000000172c0 0000000000000000 WA 0 0 32
[27] .comment PROGBITS 0000000000000000 0000a270
000000000000001c 0000000000000001 MS 0 0 1
[28] pydata PROGBITS 0000000000000000 0000a28c
00000000001a3066 0000000000000000 0 0 1
[29] .shstrtab STRTAB 0000000000000000 001ad2f2
000000000000010b 0000000000000000 0 0 1
Key to Flags:
W (write), A (alloc), X (execute), M (merge), S (strings), I (info),
L (link order), O (extra OS processing required), G (group), T (TLS),
C (compressed), x (unknown), o (OS specific), E (exclude),
l (large), p (processor specific)
$
Note the pydata section!
You can use archive_viewer.py to view the archives in main:
$ python archive_viewer.py main
pos, length, uncompressed, iscompressed, type, name
[(0, 215, 285, 1, 'm', 'struct'),
(215, 1059, 1792, 1, 'm', 'pyimod01_os_path'),
(1274, 4080, 8938, 1, 'm', 'pyimod02_archive'),
(5354, 5518, 13005, 1, 'm', 'pyimod03_importers'),
(10872, 1825, 4051, 1, 's', 'pyiboot01_bootstrap'),
(12697, 1161, 2135, 1, 's', 'pyi_rth_multiprocessing'),
(13858, 125, 143, 1, 's', 'main'),
(13983, 1701919, 1701919, 0, 'z', 'PYZ-00.pyz')]
? x main
to filename? main.x
? q
$ xxd main.x
00000000: e300 0000 0000 0000 0000 0000 0000 0000 ................
00000010: 0003 0000 0040 0000 0073 1600 0000 6500 .....#...s....e.
00000020: 6400 8301 5a01 6502 6401 6501 8302 0100 d...Z.e.d.e.....
00000030: 6402 5300 2903 7a13 5768 6174 2069 7320 d.S.).z.What is
00000040: 796f 7572 206e 616d 653f 0ada 0248 694e your name?...HiN
00000050: 2903 da05 696e 7075 74da 0369 6e70 da05 )...input..inp..
00000060: 7072 696e 74a9 0072 0500 0000 7205 0000 print..r....r...
00000070: 007a 076d 6169 6e2e 7079 da08 3c6d 6f64 .z.main.py..<mod
00000080: 756c 653e 0100 0000 7302 0000 0008 01 ule>....s......
$
As you can see from the above output the string you are looking for is stored in a compressed archive called main which in turn is part of the main executable build by pyinstaller.

Unexpected exit during running a code in tcl

I am working on a structural engineering application using a software called "opensees V3.0.3" that is developed based on tcl (TCL8.6.9). When I run the code it stops in the middle and gives me an exit code (Exit code -1073740940) without certain errors. However, when i try running it on other devices, it works well without any problems. What could be causing this problem to happen only when I run the code on my PC. And I have windows 10.
this is the code of the model:
wipe ;
model BasicBuilder -ndm 2 -ndf 3;
# Define Parameters
set L 5.0 ; # beam length (m)
set H 3.5 ; # column height (m)
set Ly 4.0 ; # perpendicular length (m)
set Lb [expr sqrt(pow($L/2,2)+pow($H,2))] ; # brace length (m)
# Loads (KN/m2)
set DL [expr 4.50] ; # (KN/m2)
set LL [expr 2.0] ; # (KN/m2)
set g 9.81 ; # (m/s2)
set pi 3.14 ;
set RSteel 7.85 ; # mass per unit volume of steel (t/m3)
set FileName "GVOutPut";
file mkdir $FileName;
# Define Nodes
# Base Nodes
# tag X Y
node 1 0.0 0.0 ;
node 2 $L 0.0 ;
# First Floor Nodes
node 101 0.0 $H ;
node 102 $L $H ;
# Second Floor Nodes
node 201 0.0 [expr 2*$H] ;
node 202 $L [expr 2*$H] ;
# Third Floor Nodes
node 301 0.0 [expr 3*$H] ;
node 302 $L [expr 3*$H] ;
#Damper First Floor Nodes
node 105 [expr $L/2] $H ;
node 1055 [expr $L/2] $H ;
# #Damper Second Floor Nodes
node 205 [expr $L/2] [expr 2*$H] ;
node 2055 [expr $L/2] [expr 2*$H] ;
# #Damper Third Floor Nodes
node 305 [expr $L/2] [expr 3*$H] ;
node 3055 [expr $L/2] [expr 3*$H] ;
# # Define Constraint
# SPConstraint
# SPC tag Dx Dy Rz
fix 1 1 1 1 ;
fix 2 1 1 1 ;
# MP constraints
# $rNodeTag $cNodeTag $dof1 $dof2 $dof3.
equalDOF 105 1055 2 6 ;
equalDOF 205 2055 2 6 ;
equalDOF 305 3055 2 6 ;
# # Define passive slip-loads
set N11 42; # (KN)
set N12 126; # (KN)
set N21 32; # (KN)
set N22 96; # (KN)
set N31 18; # (KN)
set N32 54; # (KN)
set Fs1 [expr $N11];
puts "Fs1=$Fs1";
set Fs2 [expr $N21];
puts "Fs2=$Fs2";
set Fs3 [expr $N31];
puts "Fs3=$Fs3";
set dy 1.0e-5;
#
# Define Materials
# $matTag $E $dy
uniaxialMaterial ElasticPP 11 [expr $Fs1/$dy] $dy;
uniaxialMaterial ElasticPP 22 [expr $Fs2/$dy] $dy;
uniaxialMaterial ElasticPP 33 [expr $Fs3/$dy] $dy;
# Tag Fy E b $R0 $cR1 $cR2
uniaxialMaterial Steel02 2 275.e3 2.0e8 0.01 18 0.925 0.15 ; # Material of beams & columns
# Tag $E
uniaxialMaterial Elastic 3 2.0e8 ; # Material of braces
# Define Sections
# # IPE Sections
# IPE 300
set h1 0.3 ;
set b1 0.15 ;
set s1 0.0071 ;
set t1 0.0107 ;
set MatTag 2 ;
set dh11 [expr ($h1/2.0)-$t1] ;
set dh21 [expr ($h1/2.0)] ;
set db1 [expr ($b1/2.0)] ;
set ds1 [expr ($s1/2.0)] ;
section Fiber 300 { ;
# Mat Nij Njk yi zi yj zj yk zk yl zl
patch quad $MatTag 3 34 $dh11 -$db1 $dh21 -$db1 $dh21 $db1 $dh11 $db1
patch quad $MatTag 38 3 -$dh11 -$ds1 $dh11 -$ds1 $dh11 $ds1 -$dh11 $ds1
patch quad $MatTag 3 34 -$dh21 -$db1 -$dh11 -$db1 -$dh11 $db1 -$dh21 $db1
} ;
puts "Section I With Tag 300 Has Been Generated";
# IPE 270
set h2 0.27 ;
set b2 0.135 ;
set s2 0.0066 ;
set t2 0.0102 ;
set MatTag 2 ;
set dh12 [expr ($h2/2.0)-$t2] ;
set dh22 [expr ($h2/2.0)] ;
set db2 [expr ($b2/2.0)] ;
set ds2 [expr ($s2/2.0)] ;
section Fiber 270 { ;
# Mat NijNjk yi zi yj zj yk zk yl zl
patch quad $MatTag 3 34 $dh12 -$db2 $dh22 -$db2 $dh22 $db2 $dh12 $db2
patch quad $MatTag 38 3 -$dh12 -$ds2 $dh12 -$ds2 $dh12 $ds2 -$dh12 $ds2
patch quad $MatTag 3 34 -$dh22 -$db2 -$dh12 -$db2 -$dh12 $db2 -$dh22 $db2
} ;
puts "Section I With Tag 270 Has Been Generated";
# # Box Sections
# Box 25X2
set MatT 2 ;
set B2 0.25 ;
set tt2 0.02 ;
set dB12 [expr ($B2/2.0)-$tt2] ;
set dB22 [expr ($B2/2.0)] ;
section Fiber 2520 { ;
# MatTag Nij Njk yi zi yj zj yk zk yl zl
patch quad $MatT 3 30 $dB12 -$dB12 $dB22 -$dB12 $dB22 $dB12 $dB12 $dB12 ;
patch quad $MatT 3 30 -$dB22 -$dB12 -$dB12 -$dB12 -$dB12 $dB12 -$dB22 $dB12 ;
patch quad $MatT 34 3 -$dB22 -$dB22 $dB22 -$dB22 $dB22 -$dB12 -$dB22 -$dB12 ;
patch quad $MatT 34 3 -$dB22 $dB12 $dB22 $dB12 $dB22 $dB22 -$dB22 $dB22 ;
} ;
puts "Section Box With Tag 2520 Has Been Generated";
# Box 20X15
set MatT 2 ;
set B3 0.20 ;
set tt3 0.015 ;
set dB13 [expr ($B3/2.0)-$tt3] ;
set dB23 [expr ($B3/2.0)] ;
section Fiber 2015 { ;
# MatTag Nij Njk yi zi yj zj yk zk yl zl
patch quad $MatT 3 30 $dB13 -$dB13 $dB23 -$dB13 $dB23 $dB13 $dB13 $dB13
patch quad $MatT 3 30 -$dB23 -$dB13 -$dB13 -$dB13 -$dB13 $dB13 -$dB23 $dB13
patch quad $MatT 34 3 -$dB23 -$dB23 $dB23 -$dB23 $dB23 -$dB13 -$dB23 -$dB13
patch quad $MatT 34 3 -$dB23 $dB13 $dB23 $dB13 $dB23 $dB23 -$dB23 $dB23
} ;
puts "Section Box With Tag 2015 Has Been Generated";
# Define the fiber Circular Hollow fiber section
# Hot-Finished Circular Hollow Sections (D=88.9,t=10)
set MatID 3; # material ID tag --
set DSec 0.1683; # Hollow Section Diameter
set t 0.0125; # Hollow Section Thickness
set ro [expr $DSec/2]; # overall (outer) radius of the section
set ri [expr $ro-$t] ; # inner radius of the section, only for hollow sections
set nfCoreR 8; # number of radial divisions in the core (number of "rings")
set nfCoreT 8; # number of theta divisions in the core (number of "wedges")
section fiberSec 8810 {
# $matTag $numSubdivCirc $numSubdivRad $yCenter $zCenter $intRad $extRad $startAng $endAng
patch circ $MatID $nfCoreT $nfCoreR 0 0 $ri $ro 0 360; # Define the Circular Hollow section patch
};
puts "End of Define Sections";
# Define Transformation
#Columns
geomTransf PDelta 1;
#Beams
geomTransf Linear 2;
# braces
geomTransf Corotational 3;
# Define Elements
#Columns
set Acol1 0.0184; # Area of Box With Tag 2520
set Acol2 0.0141; # Area of Box With Tag 2015
set massCol1 [expr (($Acol1*$RSteel)*$H)]; # Mass of Box With Tag 2520 (t)
set massCol2 [expr (($Acol2*$RSteel)*$H)]; # Mass of Box With Tag 2015 (t)
#First Floor
# Tag iNode jNode nP SecTag TransTag
element nonlinearBeamColumn 11 1 101 5 2520 1 ;
element nonlinearBeamColumn 12 2 102 5 2520 1 ;
# $eleTag $iNode $jNode $A $E $Iz $transfTag
# element elasticBeamColumn 11 1 101 0.0184 2.0e8 1.635e-4 2 ;
# element elasticBeamColumn 12 2 102 0.0184 2.0e8 1.635e-4 2 ;
#Second Floor
# Tag iNode jNode nP SecTag TransTag
element nonlinearBeamColumn 21 101 201 5 2520 1 ;
element nonlinearBeamColumn 22 102 202 5 2520 1 ;
# $eleTag $iNode $jNode $A $E $Iz $transfTag
# element elasticBeamColumn 21 101 201 0.0184 2.0e8 1.635e-4 2 ;
# element elasticBeamColumn 22 102 202 0.0184 2.0e8 1.635e-4 2 ;
#Third Floor
# Tag iNode jNode nP SecTag TransTag
element nonlinearBeamColumn 31 201 301 5 2015 1 ;
element nonlinearBeamColumn 32 202 302 5 2015 1 ;
# $eleTag $iNode $jNode $A $E $Iz $transfTag
# element elasticBeamColumn 31 201 301 0.0141 2.0e8 6.373e-5 2 ;
# element elasticBeamColumn 32 202 302 0.0141 2.0e8 6.373e-5 2 ;
# Beams
set Asec300 0.00538; # Area of I section With Tag 300
set Asec270 0.00459; # Area of I section With Tag 270
set massBeam1 [expr (((($DL+(0.2*$LL))*$Ly)/$g+($Asec300*$RSteel))*$L)]; # Mass of I section With Tag 300 (t)
set massBeam2 [expr (((($DL+(0.2*$LL))*$Ly)/$g+($Asec300*$RSteel))*$L)]; # Mass of I section With Tag 300 (t)
set massBeam3 [expr (((($DL+(0.2*$LL))*$Ly)/$g+($Asec270*$RSteel))*$L)]; # Mass of I section With Tag 300 (t)
#First Floor
# Tag iNode jNode nP SecT TransTag
element nonlinearBeamColumn 1010 101 105 5 300 2 ;
element nonlinearBeamColumn 1020 105 102 5 300 2 ;
#Second Floor
# Tag iNode jNode nP SecT TransTag
element nonlinearBeamColumn 2010 201 205 5 300 2 ;
element nonlinearBeamColumn 2020 205 202 5 300 2 ;
#Third Floor
# Tag iNode jNode nP SecT TransTag
element nonlinearBeamColumn 3010 301 305 5 270 2 ;
element nonlinearBeamColumn 3020 305 302 5 270 2 ;
# Damper Elements (Braces)
set E 2.0e8;
set Abr 61.2e-4; # Area of Circular Hollow Section With Tag 8810
set massbr [expr ($Abr*$RSteel)*$Lb];
#First Floor
# $eleTag $iNode $jNode $secTag
element corotTrussSection 120 1 1055 8810; # Circular hollow section
element corotTrussSection 121 2 1055 8810; # Circular hollow section
# Friction Node
# $eleTag $iNode $jNode -mat $matTag -dir $dir
element zeroLength 122 105 1055 -mat 11 -dir 1;
#Second Floor
# $eleTag $iNode $jNode $secTag
element corotTrussSection 220 101 2055 8810; # Circular hollow section
element corotTrussSection 221 102 2055 8810; # Circular hollow section
# Friction Node
# $eleTag $iNode $jNode -mat $matTag -dir $dir
element zeroLength 222 205 2055 -mat 22 -dir 1;
#Third Floor
# $eleTag $iNode $jNode $secTag
element corotTrussSection 320 201 3055 8810; # Circular hollow section
element corotTrussSection 321 202 3055 8810; # Circular hollow section
# Friction Node
# $eleTag $iNode $jNode -mat $matTag -dir $dir
element zeroLength 322 305 3055 -mat 33 -dir 1;
# Nodal Mass
# Assign masses to the nodes that the columns are connected to each connection takes the mass of 1/2 of each element framing into it (mass=weight/$g)
# Mass tag mx my mIz
mass 101 [expr 5*($massCol1 + $massBeam1/2 + $massbr)] [expr 5*($massCol1 + $massBeam1/2 + $massbr)] 0.0 ; # level 1
mass 201 [expr 5*($massCol1/2 + $massCol2/2 + $massBeam2/2 + $massbr)] [expr 5*($massCol1/2 + $massCol2/2 + $massBeam2/2 + $massbr)] 0.0 ; # level 2
mass 202 [expr 5*($massCol1/2 + $massCol2/2 + $massBeam2/2 + $massbr)] [expr 5*($massCol1/2 + $massCol2/2 + $massBeam2/2 + $massbr)] 0.0 ; # level 2
mass 301 [expr 5*($massCol2/2 + $massBeam3/2)] [expr 5*($massCol2/2 + $massBeam3/2)] 0.0 ; # level 3
mass 302 [expr 5*($massCol2/2 + $massBeam3/2)] [expr 5*($massCol2/2 + $massBeam3/2)] 0.0 ; # level 3
puts "End of Define Model Elements" ;
# # Eigenvalue Analysis
set pi [expr 2.0*asin(1.0)]; # Definition of pi
set nEigenI 1; # mode i = 1
set nEigenJ 2; # mode j = 2
set lambdaN [eigen [expr $nEigenJ]]; # eigenvalue analysis for nEigenJ modes
set lambdaI [lindex $lambdaN [expr 0]]; # eigenvalue mode i = 1
set lambdaJ [lindex $lambdaN [expr $nEigenJ-1]]; # eigenvalue mode j = 2
set w1 [expr pow($lambdaI,0.5)]; # w1 (1st mode circular frequency)
set w2 [expr pow($lambdaJ,0.5)]; # w2 (2nd mode circular frequency)
set T1 [expr 2.0*$pi/$w1]; # 1st mode period of the structure
set T2 [expr 2.0*$pi/$w2]; # 2nd mode period of the structure
puts "W1=$w1 Rad/Sec";
puts "T1=$T1 Sec";
puts "************";
puts "W2=$w2 Rad/Sec";
puts "T2=$T2 Sec";
puts "************";
puts "End of Define Model Geometry" ;
recorder Node -file GVOutPut/BaseNodeReaction.out -time -node 1 2 -dof 2 reaction ;
# define gravity load applied to beams and columns -- eleLoad applies loads in local coordinate axis
# beams
set WzFloor1 [expr ((($DL+$LL)*$Ly)+($Asec300*$RSteel*$g))] ;
set WzFloor2 [expr ((($DL+$LL)*$Ly)+($Asec300*$RSteel*$g))] ;
set WzFloor3 [expr ((($DL+$LL)*$Ly)+($Asec270*$RSteel*$g))] ;
# columns
set WColF1 [expr ($Acol1*$RSteel*$g)] ;
set WColF2 [expr ($Acol1*$RSteel*$g)] ;
set WColF3 [expr ($Acol2*$RSteel*$g)] ;
# braces
set Wbr [expr ($massbr*$g)] ;
#
pattern Plain 1 Linear {
eleLoad -ele 1010 1020 -type -beamUniform -$WzFloor1; # beams level 1 (in -y direction)
eleLoad -ele 2010 2020 -type -beamUniform -$WzFloor2; # beams level 2 (in -y direction)
eleLoad -ele 3010 3020 -type -beamUniform -$WzFloor3; # beams level 3 (in -y direction)
eleLoad -ele 11 12 -type -beamUniform 0.0 -$WColF1; # Box section weight per length Level 1 (in -x direction)
eleLoad -ele 21 22 -type -beamUniform 0.0 -$WColF2; # Box section weight per length Level 2 (in -x direction)
eleLoad -ele 31 32 -type -beamUniform 0.0 -$WColF3; # Box section weight per length Level 3 (in -x direction)
} ;
# Static Analysis
constraints Transformation; # how it handles boundary conditions
numberer RCM; # renumber dof's to minimize band-width (optimization), if you want to
system BandGeneral; # how to store and solve the system of equations in the analysis (large model: try UmfPack)
test EnergyIncr 1.0e-5 50; #
algorithm Newton; #
set NstepGravity 10;
set DGravity [expr 1./$NstepGravity];
integrator LoadControl $DGravity; #
analyze $NstepGravity; # apply gravity
# maintain constant gravity loads and reset time to zero
loadConst -time 0.0;
puts "End of Static Analysis" ;

Finding "lsort" indices in .tcl

How can we obtain indices of lsort?
For example:
lsort -real {1 -4 6 0}
how can I obtain indices for the code above as idx = (1, 3, 0, 2)?
The -indices option to lsort does exactly what you want:
set values {1 -4 6 0}
set indices [lsort -indices -real $values]
foreach idx $indices {
puts "[lindex $values $idx] is at $idx"
}
Output:
-4 is at 1
0 is at 3
1 is at 0
6 is at 2

How can I improve performance on DRF with high CPU time

I have a REST api with DRF and start to see already a performance hit with 100 objects and 1 user requesting (me - testing).
When requesting the more complex query, I get these results for CPU, always 5 - 10s:
Resource Value
>User CPU time 5987.089 msec
System CPU time 463.929 msec
Total CPU time 6451.018 msec
Elapsed time 6800.938 msec
Context switches 9 voluntary, 773 involuntary
but the SQL query stays below 100 ms
The more simple queries show similar behaviour, with CPU times around 1s and query time around 20 ms
So far, what I have tried out:
I am doing select_related() and prefetch_related(), which did improve the query time but not CPU time
I am using Imagekit to generate pictures, on a S3 instance. I removed the whole specification to test and this had minor impact
I run a method field to fetch user-specific data. Removing this had only minor impact
I have checked logs files on the backend and nothing specific shows up here...
Backend is Nginx - supervisord - gunicorn - postgresql - django 1.8.1
Here are the serializer and view:
class ParticipationOrganizationSerializer(ModelSerializer):
organization = OrganizationSerializer(required=False, read_only=True, )
bookmark = SerializerMethodField(
required=False,
read_only=True,
)
location_map = LocationMapSerializer(
required=False,
read_only=True,
)
class Meta:
model = Participation
fields = (
'id',
'slug',
'organization',
'location_map',
'map_code',
'partner',
'looking_for',
'complex_profile',
'bookmark',
'confirmed',
)
read_only_fields = (
'id',
'slug',
'organization',
'location_map',
'map_code',
'partner',
'bookmark',
'confirmed',
)
def get_bookmark(self, obj):
request = self.context.get('request', None)
if request is not None:
if(request.user.is_authenticated()):
# print(obj.bookmarks.filter(author=request.user).count())
try:
bookmark = obj.bookmarks.get(author=request.user)
# bookmark = Bookmark.objects.get(
# author=request.user,
# participation=obj,
# )
return BookmarkSerializer(bookmark).data
except Bookmark.DoesNotExist:
# We have nothing yet
return None
except Bookmark.MultipleObjectsReturned:
# This should not happen, but in case it does, delete all
# the bookmarks for safety reasons.
Bookmark.objects.filter(
author=request.user,
participation=obj,
).delete()
return None
return None
class ParticipationOrganizationViewSet(ReadOnlyModelViewSet):
"""
A readonly ViewSet for viewing participations of a certain event.
"""
serializer_class = ParticipationOrganizationSerializer
queryset = Participation.objects.all().select_related(
'location_map',
'organization',
'organization__logo_image',
).prefetch_related(
'bookmarks',
)
lookup_field = 'slug'
def get_queryset(self):
event_slug = self.kwargs['event_slug']
# Filter for the current event
# Filter to show only the confirmed participations
participations = Participation.objects.filter(
event__slug=event_slug,
confirmed=True
).select_related(
'location_map',
'organization',
'organization__logo_image',
).prefetch_related(
'bookmarks',
)
# Filter on partners? This is a parameter passed on in the url
partners = self.request.query_params.get('partners', None)
if(partners == "true"):
participations = participations.filter(partner=True)
return participations
# http://stackoverflow.com/questions/22616973/django-rest-framework-use-different-serializers-in-the-same-modelviewset
def get_serializer_class(self):
if self.action == 'list':
return ParticipationOrganizationListSerializer
if self.action == 'retrieve':
return ParticipationOrganizationSerializer
return ParticipationOrganizationListSerializer
Any help is very much appreciated!
update
I dumped the data to my local machine and I am observing similar times. I guess this rules out the whole production setup (nginx, gunicorn)?
update 2
Here are the results of the profiler.
Also I made some progress in improving the speeds by
Simplifying my serializers
Doing the tests with curl and having Debug Toolbar off
ncalls tottime percall cumtime percall filename:lineno(function)
0 0 0 profile:0(profiler)
1 0 0 3.441 3.441 /home/my_app/.virtualenvs/my_app/local/lib/python2.7/site-packages/rest_framework/views.py:442(dispatch)
1 0 0 3.441 3.441 /home/my_app/.virtualenvs/my_app/local/lib/python2.7/site-packages/rest_framework/viewsets.py:69(view)
1 0 0 3.441 3.441 /home/my_app/.virtualenvs/my_app/local/lib/python2.7/site-packages/django/views/decorators/csrf.py:57(wrapped_view)
1 0 0 3.44 3.44 /home/my_app/.virtualenvs/my_app/local/lib/python2.7/site-packages/rest_framework/mixins.py:39(list)
1 0 0 3.438 3.438 /home/my_app/.virtualenvs/my_app/local/lib/python2.7/site-packages/rest_framework/serializers.py:605(to_representation)
1 0 0 3.438 3.438 /home/my_app/.virtualenvs/my_app/local/lib/python2.7/site-packages/rest_framework/serializers.py:225(data)
1 0 0 3.438 3.438 /home/my_app/.virtualenvs/my_app/local/lib/python2.7/site-packages/rest_framework/serializers.py:672(data)
344/114 0.015 0 3.318 0.029 /home/my_app/.virtualenvs/my_app/local/lib/python2.7/site-packages/rest_framework/serializers.py:454(to_representation)
805 0.01 0 2.936 0.004 /home/my_app/.virtualenvs/my_app/local/lib/python2.7/site-packages/rest_framework/fields.py:1368(to_representation)
2767 0.013 0 2.567 0.001 /home/my_app/.virtualenvs/my_app/local/lib/python2.7/site-packages/django/dispatch/dispatcher.py:166(send)
2070 0.002 0 2.52 0.001 /home/my_app/.virtualenvs/my_app/local/lib/python2.7/site-packages/imagekit/registry.py:52(existence_required_receiver)
2070 0.005 0 2.518 0.001 /home/my_app/.virtualenvs/my_app/local/lib/python2.7/site-packages/imagekit/registry.py:55(_receive)
2070 0.004 0 2.513 0.001 /home/my_app/.virtualenvs/my_app/local/lib/python2.7/site-packages/imagekit/utils.py:147(call_strategy_method)
2070 0.002 0 2.508 0.001 /home/my_app/.virtualenvs/my_app/local/lib/python2.7/site-packages/imagekit/cachefiles/strategies.py:14(on_existence_required)
2070 0.005 0 2.506 0.001 /home/my_app/.virtualenvs/my_app/local/lib/python2.7/site-packages/imagekit/cachefiles/__init__.py:86(generate)
2070 0.002 0 2.501 0.001 /home/my_app/.virtualenvs/my_app/local/lib/python2.7/site-packages/imagekit/cachefiles/backends.py:109(generate)
2070 0.003 0 2.499 0.001 /home/my_app/.virtualenvs/my_app/local/lib/python2.7/site-packages/imagekit/cachefiles/backends.py:94(generate_now)
2070 0.01 0 2.496 0.001 /home/my_app/.virtualenvs/my_app/local/lib/python2.7/site-packages/imagekit/cachefiles/backends.py:65(get_state)
690 0.001 0 2.292 0.003 /home/my_app/.virtualenvs/my_app/local/lib/python2.7/site-packages/imagekit/cachefiles/__init__.py:148(__nonzero__)
690 0.005 0 2.291 0.003 /home/my_app/.virtualenvs/my_app/local/lib/python2.7/site-packages/imagekit/cachefiles/__init__.py:124(__bool__)
2070 0.007 0 2.276 0.001 /home/my_app/.virtualenvs/my_app/local/lib/python2.7/site-packages/imagekit/cachefiles/backends.py:112(_exists)
2070 0.01 0 2.269 0.001 /home/my_app/.virtualenvs/my_app/local/lib/python2.7/site-packages/storages/backends/s3boto.py:409(exists)
4140 0.004 0 2.14 0.001 /home/my_app/.virtualenvs/my_app/local/lib/python2.7/site-packages/storages/backends/s3boto.py:282(entries)
1633 0.003 0 2.135 0.001 /home/my_app/.virtualenvs/my_app/local/lib/python2.7/site-packages/storages/backends/s3boto.py:288()
1633 0.001 0 2.129 0.001 /home/my_app/.virtualenvs/my_app/local/lib/python2.7/site-packages/boto/s3/bucketlistresultset.py:24(bucket_lister)
2 0 0 2.128 1.064 /home/my_app/.virtualenvs/my_app/local/lib/python2.7/site-packages/boto/s3/bucket.py:390(_get_all)
2 0 0 2.128 1.064 /home/my_app/.virtualenvs/my_app/local/lib/python2.7/site-packages/boto/s3/bucket.py:426(get_all_keys)
1331 0.003 0 1.288 0.001 /usr/lib/python2.7/ssl.py:335(recv)
1331 1.285 0.001 1.285 0.001 /usr/lib/python2.7/ssl.py:254(read)
2 0 0 0.983 0.491 /home/my_app/.virtualenvs/my_app/local/lib/python2.7/site-packages/boto/connection.py:886(_mexe)
2 0 0 0.983 0.491 /home/my_app/.virtualenvs/my_app/local/lib/python2.7/site-packages/boto/s3/connection.py:643(make_request)
2 0 0 0.983 0.491 /home/my_app/.virtualenvs/my_app/local/lib/python2.7/site-packages/boto/connection.py:1062(make_request)
2 0.004 0.002 0.896 0.448 /usr/lib/python2.7/httplib.py:585(_read_chunked)
2 0 0 0.896 0.448 /home/my_app/.virtualenvs/my_app/local/lib/python2.7/site-packages/boto/connection.py:393(read)
2 0 0 0.896 0.448 /usr/lib/python2.7/httplib.py:540(read)
166 0.002 0 0.777 0.005 /usr/lib/python2.7/httplib.py:643(_safe_read)
166 0.005 0 0.775 0.005 /usr/lib/python2.7/socket.py:336(read)
2 0 0 0.568 0.284 /usr/lib/python2.7/httplib.py:793(send)
2 0 0 0.568 0.284 /usr/lib/python2.7/httplib.py:998(_send_request)
2 0 0 0.568 0.284 /usr/lib/python2.7/httplib.py:820(_send_output)
2 0 0 0.568 0.284 /usr/lib/python2.7/httplib.py:977(request)
2 0 0 0.568 0.284 /usr/lib/python2.7/httplib.py:962(endheaders)
1 0 0 0.567 0.567 /usr/lib/python2.7/httplib.py:1174(connect)
1380 0.001 0 0.547 0 /home/my_app/.virtualenvs/my_app/local/lib/python2.7/site-packages/imagekit/cachefiles/__init__.py:82(url)
1380 0.007 0 0.546 0 /home/my_app/.virtualenvs/my_app/local/lib/python2.7/site-packages/imagekit/cachefiles/__init__.py:72(_storage_attr)
105 0.009 0 0.528 0.005 /usr/lib/python2.7/socket.py:406(readline)
2 0 0 0.413 0.207 /usr/lib/python2.7/httplib.py:408(begin)
2 0 0 0.413 0.207 /usr/lib/python2.7/httplib.py:1015(getresponse)
2 0 0 0.407 0.203 /usr/lib/python2.7/httplib.py:369(_read_status)
2750 0.003 0 0.337 0 /home/my_app/.virtualenvs/my_app/local/lib/python2.7/site-packages/rest_framework/fields.py:399(get_attribute)
1 0.223 0.223 0.335 0.335 /usr/lib/python2.7/socket.py:537(create_connection)
2865 0.012 0 0.334 0 /home/my_app/.virtualenvs/my_app/local/lib/python2.7/site-packages/rest_framework/fields.py:65(get_attribute)
1610 0.005 0 0.314 0 /home/my_app/.virtualenvs/my_app/src/django-s3-folder-storage/s3_folder_storage/s3.py:13(url)
1610 0.012 0 0.309 0 /home/my_app/.virtualenvs/my_app/local/lib/python2.7/site-packages/storages/backends/s3boto.py:457(url)
690 0.005 0 0.292 0 /home/my_app/.virtualenvs/my_app/local/lib/python2.7/site-packages/imagekit/models/fields/utils.py:10(__get__)
690 0.007 0 0.251 0 /home/my_app/.virtualenvs/my_app/local/lib/python2.7/site-packages/imagekit/cachefiles/__init__.py:20(__init__)
2 0 0 0.248 0.124
>>>> cutting here, low impact calls

NS2 NAM not displaying transmissions

I'm new to NS2 and trying to set up a basic dumbell-shaped network simulation; I have one node with n TCP agents (the gateway or "gw") transmitting across a link to a remote node (remote gateway, "rgw"), which is connected to n TCP sinks (each agent is connected with one sink).
Here is a picture with n = 5. Node 0 has five TCP agents with Pareto traffic generators; each is connected to a TCPSink agent attached to one of the nodes on the right.
I have the following TCL script to set up and test the network; it runs successfully, but when I view the trace in NAM, I can't see the packets moving. I ran a similar tutorial with NAM, and it looked fine, so there must be a bug in my own code. Can anyone help me find my error?
Thanks.
set ns [new Simulator]
# Set up trace
set trc [open out.trc w]
set namtrc [open out.nam w]
$ns trace-all $trc
$ns namtrace-all $namtrc
proc finish {} {
global ns trc
global ns namtrc
$ns flush-trace
close $trc
close $namtrc
exec nam out.nam &
exit 0
}
# Simulation parameters
set n 5
set bw 150000000 # 150 Mb/s
# Set up bottleneck link
set gw [$ns node]
set rgw [$ns node]
$ns duplex-link $gw $rgw $bw .30 DropTail
set snd {} # TCP senders sitting on the gateway node
set trf {} # Traffic generators for the senders
set dst {} # Destination nodes hosting the receivers
set rcv {} # TCP receivers sitting on the destination
for {set i 0} {$i<$n} {incr i} {
# Create the objects needed for a new connection
lappend snd [new Agent/TCP]
lappend rcv [new Agent/TCPSink]
lappend trf [new Application/Traffic/Pareto]
lappend srv [$ns node]
# set up source and destination nodes
$ns attach-agent $gw [lindex $snd $i]
$ns attach-agent [lindex $srv $i] [lindex $rcv $i]
[lindex $trf $i] attach-agent [lindex $snd $i]
# Connect nodes
$ns duplex-link $rgw [lindex $srv $i] 1000000000000 .100 DropTail
# Connect agents
$ns connect [lindex $snd $i] [lindex $rcv $i]
}
foreach traffic $trf {
$ns at 0.0 "$traffic start"
}
$ns at 10.0 "finish"
$ns run
And here's an excerpt from a trace generated with this code:
+ 0.214008 0 1 pareto 40 ------- 0 0.0 2.0 0 0
- 0.214008 0 1 pareto 40 ------- 0 0.0 2.0 0 0
+ 0.321715 0 1 pareto 40 ------- 0 0.3 5.0 0 1
- 0.321715 0 1 pareto 40 ------- 0 0.3 5.0 0 1
r 0.51401 0 1 pareto 40 ------- 0 0.0 2.0 0 0
+ 0.51401 1 2 pareto 40 ------- 0 0.0 2.0 0 0
- 0.51401 1 2 pareto 40 ------- 0 0.0 2.0 0 0
r 0.61401 1 2 pareto 40 ------- 0 0.0 2.0 0 0
+ 0.61401 2 1 ack 40 ------- 0 2.0 0.0 0 2
- 0.61401 2 1 ack 40 ------- 0 2.0 0.0 0 2
r 0.621717 0 1 pareto 40 ------- 0 0.3 5.0 0 1
+ 0.621717 1 5 pareto 40 ------- 0 0.3 5.0 0 1
- 0.621717 1 5 pareto 40 ------- 0 0.3 5.0 0 1
r 0.71401 2 1 ack 40 ------- 0 2.0 0.0 0 2
+ 0.71401 1 0 ack 40 ------- 0 2.0 0.0 0 2
- 0.71401 1 0 ack 40 ------- 0 2.0 0.0 0 2
r 0.721717 1 5 pareto 40 ------- 0 0.3 5.0 0 1
+ 0.721717 5 1 ack 40 ------- 0 5.0 0.3 0 3
- 0.721717 5 1 ack 40 ------- 0 5.0 0.3 0 3
+ 0.735936 0 1 pareto 40 ------- 0 0.2 4.0 0 4
- 0.735936 0 1 pareto 40 ------- 0 0.2 4.0 0 4
r 0.821717 5 1 ack 40 ------- 0 5.0 0.3 0 3
+ 0.821717 1 0 ack 40 ------- 0 5.0 0.3 0 3
- 0.821717 1 0 ack 40 ------- 0 5.0 0.3 0 3
+ 0.831634 0 1 pareto 40 ------- 0 0.4 6.0 0 5
- 0.831634 0 1 pareto 40 ------- 0 0.4 6.0 0 5
r 1.014013 1 0 ack 40 ------- 0 2.0 0.0 0 2
+ 1.014013 0 1 pareto 1040 ------- 0 0.0 2.0 0 6
- 1.014013 0 1 pareto 1040 ------- 0 0.0 2.0 0 6
+ 1.014013 0 1 pareto 1040 ------- 0 0.0 2.0 0 7
- 1.014068 0 1 pareto 1040 ------- 0 0.0 2.0 0 7
r 1.035938 0 1 pareto 40 ------- 0 0.2 4.0 0 4
+ 1.035938 1 4 pareto 40 ------- 0 0.2 4.0 0 4
- 1.035938 1 4 pareto 40 ------- 0 0.2 4.0 0 4
r 1.121719 1 0 ack 40 ------- 0 5.0 0.3 0 3
+ 1.121719 0 1 pareto 1040 ------- 0 0.3 5.0 0 8
- 1.121719 0 1 pareto 1040 ------- 0 0.3 5.0 0 8
+ 1.121719 0 1 pareto 1040 ------- 0 0.3 5.0 0 9
- 1.121775 0 1 pareto 1040 ------- 0 0.3 5.0 0 9
r 1.131636 0 1 pareto 40 ------- 0 0.4 6.0 0 5
Looks to be working fine.
Try the below code it's work fine
set ns [new Simulator]
# Set up trace
set trc [open out.trc w]
set namtrc [open out.nam w]
$ns trace-all $trc
$ns namtrace-all $namtrc
proc finish {} {
global ns trc
global ns namtrc
$ns flush-trace
close $trc
close $namtrc
exec nam out.nam &
exit 0
}
# Simulation parameters
set n 5
set bw 150000000; # 150 Mb/s
# Set up bottleneck link
set gw [$ns node]
set rgw [$ns node]
$ns duplex-link $gw $rgw $bw .3000 DropTail
set snd {}
# TCP senders sitting on the gateway node
set trf {}
# Traffic generators for the senders
set dst {}
# Destination nodes hosting the receivers
set rcv {}
# TCP receivers sitting on the destination
for {set i 0} {$i<$n} {incr i} {
# Create the objects needed for a new connection
lappend snd [new Agent/TCP]
lappend rcv [new Agent/TCPSink]
lappend trf [new Application/Traffic/Pareto]
lappend srv [$ns node]
# set up source and destination nodes
$ns attach-agent $gw [lindex $snd $i]
$ns attach-agent [lindex $srv $i] [lindex $rcv $i]
[lindex $trf $i] attach-agent [lindex $snd $i]
# Connect nodes
$ns duplex-link $rgw [lindex $srv $i] 10000 .10000 DropTail
# Connect agents
$ns connect [lindex $snd $i] [lindex $rcv $i]
}
foreach traffic $trf {
$ns at 0.0 "$traffic start"
}
$ns at 10.0 "finish"
$ns run