Skip to main content

TOUR DE NS2 REVEALING PROGRAMMING STYLE

TOUR DE NS2 REVEALING PROGRAMMING STYLE


Friends,
Today we are going to have a look in why we run ns2 program as "ns program.tcl"?
Before that we have to go through basic C++ programmings in ns2.Consider a basic C++ instruction only program i .e for example; we are considering a program to calculate time taken for a packet travel from uppermost node to lower most node with the time taken to travel packet between each nodes (t) are constant (say t=1ms) and the number of nodes as n. (say n=10). And we have to find out overall time taken to reach packet to lowermost node. The C++ program new.cc is given below and after compiling we get a executable file "new".
//new.cc
main(){
float time = 0 , t = 1;
int i, n = 10;
 for(i = 1; i < n; i++)
time = time+i ;
printf("Overall time is  %f seconds. ",time);
}
Now we execute the program from terminal, we can see the following results;
>> ./new
Overall time is 10.0 seconds.
But this programming style is not perfect. If the time to reach packet from one node to another is different and the number of nodes are changed then every time we have to change C++ program. To avoid this we can use input arguments. If we have more that one or two inputs we can provide it from terminal by using input arguments. For that normally we use argc and argv commands. The variable argc shows the number of input arguments and the variable argv contains all the inputs needed for programmer. The following C++ program shows it.
//new.cc
int main(int argc, char* argv[]) {
float time = 0, t = atof(argv[0]);
int i, n = atoi(argv[1]);
for(i = 1; i < n; i++)
time = time + i ;
printf("Overall time is %f seconds ",time);
}
Now we execute the program from terminal, we can see the following results;
>> ./new 1 10
Overall time  is 10.0 seconds.
>> ./new 3 8
Overall time  is 24.0 seconds.
This programming scheme also have flexibility problem and which is inconvenient as input increases. So we went for most convenient form of  programming using configuration file. In this scheme the input data is used to pick input arguments. Consider a C++ program new.cc with configuration file con.txt and Function readArgFromFile(fp,a) reads the configuration file associated with a file pointer �fp,� and sets variables.
//new.cc
int main(int argc, char* argv[]) {
float time = 0, t[9];
FILE* fp = fopen(argv[1],"w");
int i, n = readArgFromFile(fp,a);
for(i = 1; i < n; i++)
time = time + i ;
printf("Overall time is %f seconds ",time);
fclose(fp);
}
//con.txt
Number of node = 10
Time = 1 4 3 5 2 7 9 5 3
Now we execute the program from terminal, we can see the following results;
>> ./new con.txt
Overall time  is 30.0 seconds.
By modifying that con.txt file, we get various results.

Now we are looking towards the ns2 and i hope you all get some clue about what i am talking too. In ns2, we know that program is run by using command "ns programname.tcl". The TCL file programname.tcl is used as the input argument providing configuration file and  �ns� is a C++ executable file that generate after compiling using make and install function. The input configuration file specifies system parameters and all other configurations related to it.

I hope you all get it. 
Stay tuned for more updates........!!!!!!!!!

download file now

Popular posts from this blog

Tokyo Ghoul Season 1 BD Subtitle Indonesia

Tokyo Ghoul Season 1 BD Subtitle Indonesia Tokyo Ghoul Season 1 BD Subtitle Indonesia Type: BD Series Episode: 12 Status: Completed Genres: Action, Mystery, Drama, Horror, Supernatural, Psychological, Seinen Skor : 8.10 (http://myanimelist.net/anime/22319/Tokyo_Ghoul) Tahun Rilis : 2014 Subtitle : Indonesia Credit : http://anime-bd.com/ Deskripsi: Ketegangan horor yang berada di kota Tokyo dihantui oleh hantu misterius yang memakan manusia. Orang-orang dicekam rasa takut hantu ini yang identitasnya disembunyikan. Seorang mahasiswa biasa bernama Kaneki bertemu ceweknya yang bernama Rize, seorang gadis yang merupakan pembaca  novel seperti dia, di kafe dia sering berjumpa denganya. Perlahan dia kemudian menyadari bahwa nasibnya akan berubah dalam semalam setelah bertemu Rize. Link download 720p & 480p: ===================================================== ========= Resolusi 720p: Tusfiles: Ani-BD_Tokyo_Ghoul_BD_ED01_animesave.mkv � 11.5 MB Ani-BD_Tokyo_Ghoul_BD_ED02_animesave.m...

TOP TEN MOST POPULAR UNIVERSITY in Indonesia

TOP TEN MOST POPULAR UNIVERSITY in Indonesia Top ten most popular University in Indonesia based on METRO TV. the top ten most favourite University in Indonesia were taken from MetroTv. ITB Bandung => Institut Teknologi Bandung is the most favourite university which is elected by the most voters Universitas Indonesia => claimed to be the most advanced university in Indonesia.it has lots of Network as so many people graduated from UI. UGM => Universitas Gajah mada (UGM) is the oldest University (after the declaration of independence).it has 18 Fakulty (and 1 PascaSarjana).this university was the merger from others. Institut Teknologi Sepuluh November => built in 1957,ITS or Institut Teknologi Sepuluh Nopember now specialized in the technology about boat and Information Technology. Universitas Padjajaran (Unpad) => I got no Information about this university and Im sleepy atm. hehehe... Universitas Brawijaya => often called as UB / UNIBRAW, this univer...

Tarzan

Tarzan Tarzan Action Game (PC/Full/Eng) Game Platforme(s) : PC | Language : English | Release Date : Feb 16, 1999 Publisher & Developer : Disney Interactive | Genre : Action/Adventure | Size : 38 Mb Tarzan Action GameSummer. The days are hot and long, and its time for bar-b-ques, camping, and baseball. Summer doesnt just happen outside, though. Its also blockbuster movie season, when theaters screen entertainment thats typically a little lighter in content and more technically dazzling than the award-oriented films shown in the colder, darker, shorter days of fall and winter. Accordingly, summer big-screen fun has come to belong to Disney, which releases an animated feature every year to coincide with the conditions that make it easy to spend an afternoon in an air conditioned movie house, often time and time again to see the same feature over and over. If youve spent any time near fast-food franchises or a department store, then you know from all the merchandise that this years ...