0% found this document useful (0 votes)
29 views3 pages

Document

This document contains code snippets for calculating energy remaining for nodes, number of packets received, and throughput in a network simulation. It includes for loops to iterate through nodes and packets to collect data and perform calculations.

Uploaded by

ben fradj hajer
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
29 views3 pages

Document

This document contains code snippets for calculating energy remaining for nodes, number of packets received, and throughput in a network simulation. It includes for loops to iterate through nodes and packets to collect data and perform calculations.

Uploaded by

ben fradj hajer
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

Creation des fichiers

set tracefd [open simple.tr w]

Exercice 1 “calcule d’energie restante”


for {set i 0} {$i < $val(nn)} {incr i} {
set energie [$node_($i) energy]
puts "noeud $i a comme energie initiale $energie"

$ns run
set somme 0
for {set i 0} {$i < $val(nn)} {incr i} {
set energie [$node_($i) energy]

set somme [expr $somme+$energie]

}
puts " $val(nn) $somme"

Exercice 2 “calcule nombre des paquets recus”


#Throuput
BEGIN {

nb_packets = 0
}
{

if( $1=="r") {
#printf("%f\n",$8)
nb_packets++

}
END {
printf("%f", nb_packets)

Exercice 2 “calcule de debit”


BEGIN {
seqno = -1;
count = 0;
}
{
if($4 == "AGT" && $1 == "s" && seqno < $6) {
seqno = $6;
}
if($4 == "AGT" && $1 == "s") {
start_time[$6] = $2;
} else if(($7 == "tcp") && ($1 == "r")) {
end_time[$6] = $2;
} else if($1 == "s" && $7 == "tcp") {
end_time[$6] = -1;
}
}
END {
for(i=0; i<=seqno; i++) {
if(end_time[i] > 0) {
delay[i] = end_time[i] - start_time[i];
count++;
}
else
{
delay[i] = -1;
}
}
for(i=0; i<=seqno; i++) {
if(delay[i] > 0) {
n_to_n_delay = n_to_n_delay + delay[i];
}
}
n_to_n_delay = n_to_n_delay/count;
print "\n";
print " Delay = " n_to_n_delay * 1000 " ms";
print "\n";
}

You might also like