Collection of NS2 Reading Material [Tutorials and Documents] – Wired and Wireless

Hi Folks,

In this post i am posting a sea of (network simulator) NS2 reading material (files and resources) that i have collected over the years. Many of us researchers usually face the problem of finding good reading material on ns2 and usually just type ns2 in Google and hourly browse through hundreds of links that Google shows up. That may prove fruitful although its tiring and agonizing. (I have done that quite a lot now). Also we search for problems being faced by us when we carry out simulations and in the end we find no solutions. (NS2 problems will be like that for many years to come. 😦 ) As far as NS2 is concerned my personal experience is that you are on your own.

This post would somewhat enthrall you and you might eventually like it as it contains lots of reading materials and resources that could be of much help to budding researchers like me in the field of networking. This is just a small effort from my side to the little known NS2 Research Community.

Please leave comments, suggestions, and an encouraging word of thanks in the comments.

CATEGORY I) Learning NS2 (Tons of Introductory Tutorials and Presentations)

1. http://www.mediafire.com/view/3grw7npzv4arnj7/NS2_Exercises.pdf
2. http://www.mediafire.com/view/3grw7npzv4arnj7/NS2_Exercises.pdf
3. http://www.mediafire.com/view/ak2haa67o899yka/NS2_Source_Code_Analysis_Method.ppt
4. http://www.mediafire.com/view/8s3via5iw119hyi/Network_Simulation_and_Protocol_Implementation_Using_Network_Simulator_2.pdf
5. http://www.mediafire.com/view/k8gdmh2byer8b1s/Simulating_Networks_with_Network_Simulator_NS2.pdf
6. http://www.mediafire.com/view/wmxyf3emuib30kc/NS2_Tutorial_Part_II_-_Inteface_OTCL_Linkage.pdf
7. http://www.mediafire.com/view/6ycwpxrfnjeazee/NS2_Laboratory_-_Professor_Chansu_Yu.pdf
8. http://www.mediafire.com/view/di5vwln85cd3gat/ns2_for_the_Impatient.pdf
9. http://www.mediafire.com/view/qdwx2ghrdfm5zhd/NS_Tutorial_-_Padma_Haldar.ppt
10. http://www.mediafire.com/view/kcdbt9u9qv84icb/Wireless_world_in_NS.pptx
11. http://www.mediafire.com/view/0big047k7cbo3t3/Network_Simulator_Version_2_-_Abu.doc
12. http://www.mediafire.com/view/bdomhdewwi4k8bc/ns2_Tutorial_-_Haobo_Yu,_Nader_Salehi.pdf
13. http://www.mediafire.com/view/rw1yt9dqt3t5qpy/NS2_Tutorial_-_Sung_Park.pptx
14. http://www.mediafire.com/view/umi8ui999z3d77q/ns2_Tut.pdf
15. http://www.mediafire.com/view/tqy99nihjs0vhu5/Report_On_NS2.doc
16. http://www.mediafire.com/view/tqy99nihjs0vhu5/Report_On_NS2.doc
17. http://www.mediafire.com/view/yu5e8udx47isut0/Using_NS2.pdf
18. http://www.mediafire.com/view/u0vll0pgm73ffvk/Extensions_to_NS2_-_Notes_and_Documentation.pdf
19. http://www.mediafire.com/view/qxsdbv7e113zxgz/Introduction_to_ns2_-_Donald_C_Wunsch.pdf
20. http://www.mediafire.com/view/jal0eomo2xlk4dz/Marc_Greis_Tutorial.pdf
21. http://www.mediafire.com/view/pd04i7k1ktrwihe/NS2_Workshop.ppt
22. http://www.mediafire.com/view/43r77l1nsecg6cn/Intro_to_ns2__-_Gayatri.ppt
23. http://www.mediafire.com/view/my1cr878twyewoy/The_Network_Simulator_NS2_-_Claudia_Canali.pdf
24. http://www.mediafire.com/view/0o2yhxvb41u6n4b/NS_Internals.ppt
25. http://www.mediafire.com/view/b41kdglhubdcbp7/NS_Training_Course_-_ns_modules_-_Chau_Chi_Wang.pdf
26. http://www.mediafire.com/view/5alciaxhi0153eq/ns2_Laboratory_-_Chanso_Yu.pdf
27. http://www.mediafire.com/view/mntojpd59m3ahp4/3rd_NS2_Simulator_Workshop.pdf
28. http://www.mediafire.com/view/q80rwswwig46t47/NS_By_Examples.pdf
29. http://www.mediafire.com/view/g4ban3kiwbr6b4y/Introduction_to_Network_Simulator_-_Giovani_Neglia.pdf
30. http://www.mediafire.com/view/zxx77zilbmsnksc/NS2_Tutorial_-_Michael_Welzi.pdf
31. http://www.mediafire.com/view/96rd4e2h9952vk0/ns2_Tutorial_-_institut_fur_Telematik.pdf
32. http://www.mediafire.com/view/fgo0b09bcdcomhh/NS2_Tutorial_-_Chi_Heng_Ke.pptx
33. http://www.mediafire.com/view/sw60it08h6i1dia/NS2_Fundamentals.pdf
34. http://www.mediafire.com/view/vhbfdwyenceikyw/An_Introduction_to_NS,_NAM_and_OTCL_-_Paul_Meeneghan_and_Declan_Delaney.pdf
35. http://www.mediafire.com/view/9958z37icc6uhnl/Design_and_simulation_of_Network_Using_NS2.pdf
36. http://www.mediafire.com/view/7o8afovbnkrn17n/NS-2_Introduction_-_Bahador_Bakshi.pdf
37. http://www.mediafire.com/view/7opg8nz45dyqeco/Network_Simulator_-_Integrated_Communication_Systems_Group.pdf
38. http://www.mediafire.com/view/2vlqlqrly2s9l0k/How_to_use_ns2_-_Jae_Pil_Yoo.pdf
39. http://www.mediafire.com/view/aljlsmlu2zxz2so/Network_Performance_and_NS2_-_Mohammed_M_Kadhun.pdf
40. http://www.mediafire.com/view/tm7ep912y1d2sk2/ns2_Tutorial_-_Kameswari_Chebrolu.pdf
41. http://www.mediafire.com/view/ng4xzwsbsq4fydq/ns2_Simulator_for_Beginners.pdf
42. http://www.mediafire.com/view/n0bm6uh1abcf5pg/NS2_Tutorial.pdf
43. http://www.mediafire.com/view/8ja111fzd16w1zi/The_ns_manual.pdf
44. http://www.mediafire.com/view/854k7ck6bn4q8tp/IPAM_Tutorial_-_Network_Modeling_and_Traffic_Analysis_with_ns2.pdf
45. http://www.mediafire.com/view/3y16z7w4cx1dp9i/NS2_Introduction_-_Osman_Ghazali(2).pdf
46. http://www.mediafire.com/view/lbj2q4t4t9fw5t2/Wireless_world_in_NS2_-_Padma_Haldar.pdf

CATEGORY II) Reading Material on OTcl and Tcl Languages

1. http://www.mediafire.com/view/93fxhj23f8x3v5h/Interpreted_C++,_Object_Oriented_Tcl,_What_Next.pdf
2. http://www.mediafire.com/view/ap5eedimlscvdmt/Overloading_Comparison_Operators.pdf
3. http://www.mediafire.com/view/a2h1aqnxa33b1vo/TCP_Performance_Simulations_Using_ns2.pdf
4. http://www.mediafire.com/view/t4lxst4mh3wwsev/OTcl_-_Object_Tcl_Extensions.pdf
5. http://www.mediafire.com/view/vprs8t8zm0qe4c0/Tcl_Fundamentals.pdf
6. http://www.mediafire.com/view/u9ix6kp5van32dy/Introduction_to_MIT_Object_Tool_Command_Language_(OTCL)_Part_1.pdf
7. http://www.mediafire.com/view/80u028i48tq7233/Introduction_to_OTcl_1.pdf
8. http://www.mediafire.com/view/jdvp0hk4tkn0wf3/Tcl_and_ns2_Tutorial_Outline_OTcl_Basics.pdf
9. http://www.mediafire.com/view/zk5hbdgxx9d17v8/IEEE_802.11b_Ad_Hoc_Networks_-_Performance_Measurements.pdf
10. http://www.mediafire.com/view/p6m8xkg0j07k71w/TCL_OTCL.pdf
11. http://www.mediafire.com/view/t3ydkox86bbmqky/An_Introduction_to_NS,_Nam_and_OTcl_scripting.pdf
12. http://www.mediafire.com/view/3qubmw6m3599c9v/OTcl_-_The_User_Language.pdf
13. http://www.mediafire.com/view/cqf03edf73grkkm/Tcl_Basics.pdf
14. http://www.mediafire.com/view/14hz9ru2yeqs3j0/TCL_%26_OTCL.pdf
15. http://www.mediafire.com/view/o00157ttco35hi0/Practical_Programming_in_Tcl_and_Tk.pdf
16. http://www.mediafire.com/view/a8875v058butojp/Tcl_and_OTcl_for_ns.pdf
17. http://www.mediafire.com/view/vmkdgrs1xi5zco4/Objects_in_TCL.pdf
18. http://www.mediafire.com/view/1eg59u199e992ln/tcl_objects.pdf
19. http://www.mediafire.com/view/y3kbfxncfofyyzu/TclTk_Integration.pdf
20. http://www.mediafire.com/view/s949uv2mthbbely/Tcl_Tk_-_A_Developer’s_Guide.pdf

CATEGORY III) Reading Material on Perl and Awk Scripting Languages

1. http://www.mediafire.com/view/armp5z7biteorb6/Awk_Cheat_Sheet.pdf
2. http://www.mediafire.com/view/armp5z7biteorb6/Awk_Cheat_Sheet.pdf
3. http://www.mediafire.com/view/armp5z7biteorb6/Awk_Cheat_Sheet.pdf
4. http://www.mediafire.com/view/djqc59am0a6fc40/Learn_Perl_by_Examples_-_Perl_Handbook_for_Beginners_-_Basics_of_Perl_Scripting_Language.pdf
5. http://www.mediafire.com/view/px4bbrd31ii9nez/A_Quick,_Painless_Introduction_to_the_Perl_Scripting_Language.pdf
6. http://www.mediafire.com/view/qs5mx7mzos9317a/The_Awk_manual.pdf
7. http://www.mediafire.com/view/a5sm1k24ej0cdzo/Effective_Awk_Programming.pdf
8. http://www.mediafire.com/view/3n5zhicunp5xngk/Perl_Tutorial_for_Beginners.pdf
9. http://www.mediafire.com/view/g26q3frpsdjmzwh/Learning_Perl_-_O_Reilly.pdf
10. http://www.mediafire.com/view/rh7nxiphm4iwr76/Perl_5_Tutorial_-_1st_Edition.pdf

CATEGORY IV) NS2 Reading Material on Wireless Simulations and MANETs

1. http://www.mediafire.com/view/a4lds3w4p2962w9/NS2_Wireless_Simulation_Tutorial_-_Zhibin_Hu.pdf
2. http://www.mediafire.com/view/w5vv75272q3p7sz/Radio_Propagation_Models_Implemented_in_NS2.pdf
3. http://www.mediafire.com/view/o84fi16fi65j11j/Simulation_of_Networks_of_Queues_in_NS2.pdf
4. http://www.mediafire.com/view/tkbtfp2mizdfrdu/Effects_of_Detail_in_Wireless_Network_Simulation.pdf
5. http://www.mediafire.com/view/n3jelnj2o80mfo9/MANET_Extensions_to_NS2.pdf
6. http://www.mediafire.com/view/kngl9liwqnmdr16/New_Implementation_in_ns2_for_wireless_routing.pdf
7. http://www.mediafire.com/view/tm49gbxdso1g4wm/NS2_Tutorial_-_Wireless_Network_Lab.pdf
8. http://www.mediafire.com/view/53qkvdd23z6zqwr/Directed_Diffusion_for_Wireless_Sensor_Networking.pdf
9. http://www.mediafire.com/view/81at8tdfwgkbmc5/A_Survey_of_Network_Simulators_Supporting_Wireless_Networks.pdf
10. http://www.mediafire.com/view/2g1849e04geuadu/Design_and_Simulation_of_Wireless_Network_using_NS2.pdf
11. http://www.mediafire.com/view/d2heucd213mq8xq/NS2_Tutorial_-_Running_Simulations_-_Mathias.pdf
12. http://www.mediafire.com/view/p74wkc6g64rsc61/AdHoc_Networking_-_Christian_Bettsetter.pdf

CATEGORY V) NS2 Tutorials and Reading Material on Implementing Ad Hoc Routing Protocols in MANETs

1. http://www.mediafire.com/view/mnujyehjd7ff3vn/Sample_Coding_Wireless_NS2.docx
2. http://www.mediafire.com/view/s9plgl7rocbkpg8/Implementing_a_Routing_Agent_with_manually_configured_routing_table_(Static_Table).pdf
3. http://www.mediafire.com/view/r84smueu0rwe4m7/How_to_implement_protocol_in_NS2_-_Shi_Feng_Yan.pdf
4. http://www.mediafire.com/view/r7g8ulgr2uo7iub/Analysis_of_DSR_in_ns2.pdf
5. http://www.mediafire.com/view/d99yemfp29w9fm9/Simulation_of_MANET_Routing_Protocols.pdf
6. http://www.mediafire.com/view/vs32ypkg5sdx43o/Implementing_a_MANET_Unicast_Routing_Protocol_for_MANETs.pdf
7. http://www.mediafire.com/view/7ca1rs2uzoqrwez/A_Tutorial_on_the_Implementation_of_AODV_protocol_in_NS2_-_Mubashir_Husain_Rehmani.pdf
8. http://www.mediafire.com/view/8zo9vb0341p6wn4/TCP_over_Ad_hoc_networks.pdf
9. http://www.mediafire.com/view/owv51txu105q1d9/Implementation_and_Performance_Evaluation_of_MFlood_Protocols_for_Wireless_Ad_Hoc_Networks.pdf
10. http://www.mediafire.com/view/owv51txu105q1d9/Implementation_and_Performance_Evaluation_of_MFlood_Protocols_for_Wireless_Ad_Hoc_Networks.pdf
11. http://www.mediafire.com/view/nq3x73kbrnnucj1/An_Overview_of_MANETs_Simulation.pdf
12. http://www.mediafire.com/view/kb2vj7wpu1e5dj3/Implementing_GPSR_routing_protocol.pdf
13. http://www.mediafire.com/view/fzqjftfii4di3pu/Tutorial_for_Simulation-based_Performance_Analysis_of_MANET_Routing_Protocols_in_ns-2_-_Kartik.doc
14. http://www.mediafire.com/view/64b05satg1300jy/How_to_Add_a_New_Protocol_in_NS2_-_Xu_Leiming.ppt
15. http://www.mediafire.com/view/r5dx1ir4u1fgtg8/Design_Routing_Protocol_Performance_Comparison_in_ns2_-_AODV_comparing_to_DSR_as_Example.pdf
16. http://www.mediafire.com/view/hy2qhqh41lgw2ay/Porting_AODVUU_Implementation_to_NS2_and_Enabling_Trace_Based_Simulations.pdf
17. http://www.mediafire.com/view/uie4di69lqpf6du/Performance_Analysis_of_Reliable_Multicast_routing_protocols.pdf
18. http://www.mediafire.com/view/caryqtwb33yjd6t/On_Demand_Routing_in_Multihop_wireless_mobile_ad_hoc_networks.pdf
19. http://www.mediafire.com/view/dn01puy5okws0ol/Performance_Evaluation_of_Ad_Hoc_Routing_Protocols.doc
20. http://www.mediafire.com/view/fg2ac65tdk6ugvq/MANET_Implementation_and_Test_-_Jaehoon_Jeong.pdf
21. http://www.mediafire.com/view/6z0arhz5y2qc299/Inspect_-_A_Visual_and_Analysis_for_NS2_Wireless_Simulations.pdf
22. http://www.mediafire.com/view/kbn2f94t8bc4889/Mobile_Ad_Hoc_Network_Routing_Protocols_-_Methodologies_and_Applications.pdf
23. http://www.mediafire.com/view/37ste5ym1f3dc6c/Temporaly_Ordered_Routing_Algorithm.pdf
24. http://www.mediafire.com/view/8zat9z37x48eibv/Introduction_to_Geographic_Greedy_Forwarding.pdf
25. http://www.mediafire.com/view/k1k9nhhgf9yt7eb/Survey_of_Routing_Protocols_in_Wireless_Body_Sensor_Networks.pdf

CATEGORY VI) NS2 Tutorials and Material on 802.11 Interface

1. http://www.mediafire.com/view/mur276gx5367rq5/Wireless_Routing_in_NS2.pdf
2. http://www.mediafire.com/view/a148kxg7l9c1gqt/Effects_of_Detail_in_Wireless_Network_Simulations.pdf
3. http://www.mediafire.com/view/1xmfino42djv0n1/Understanding_the_Implementation_of_IEEE_802.11_Standard_in_NS-2_-_Ke_Liu.pdf
4. http://www.mediafire.com/view/5ftc1lz3dxw37xm/Simulate_802.11b_within_NS2_-_Wu_Xiuchao.pdf
5. http://www.mediafire.com/view/h5rnc2mbjb7j9fg/A_Tutorial_of_802.11_Implementation_in_ns2_-_Yue_Wang.pdf
6. http://www.mediafire.com/view/dycvfhsstnwb6wn/A_Tutorial_on_Wireless_Implementation_in_ns2.pdf
7. http://www.mediafire.com/view/4v98nai3ljaqipv/Realistic_802.11b_in_ns2_(Simulation_vs_Real).pdf
8. http://www.mediafire.com/view/cysv4y4l71msw3r/IEEE-802.11_Overview_-_Mustafa_Ergen.ppt
9. http://www.mediafire.com/view/smv0k45qr56f57q/Basic_802.11_Statistics_-_Evan_Jones.pdf
10. http://www.mediafire.com/view/45p83tqcuk7iwep/NS2_Module_for_IEEE_802.22_Standard.pdf
11. http://www.mediafire.com/view/kx9l0lf2pkwxvm7/ANSI_IEEE_Std_802.11.pdf
12. http://www.mediafire.com/view/2i0yl855q5idq0a/Adding_Multiple_Interface_Support_in_NS2.pdf
13. http://www.mediafire.com/view/97o14958iha21ah/Simulation_of_Wireless_Multi-_Networks_in_NS-2.pdf

CATEGORY VII) NS2 Tips and Tricks (My Favorite 🙂 )

1. http://www.mediafire.com/view/dkh5djq1xqw8ahm/How_to_change_transmiision_range_in_NS2.pdf
2. http://www.mediafire.com/view/mj6615qba6zka93/Improvements_on_MAC_802-11_simulation.pdf
3. http://www.mediafire.com/view/37157by3g3h7ybg/Learning_Timers_NS2.pdf
4. http://www.mediafire.com/view/adnjo27v9e64nrq/Pedro_Vale_Estrela_-_Assorted_NS2_Tips.pdf
5. http://www.mediafire.com/view/3nauc6666m39fuc/Simulate_Random_MAC_Protocol_in_NS2_(Part_I).pdf
6. http://www.mediafire.com/view/uvumf7dk4jjo2je/Simulate_Random_MAC_Protocol_in_NS2_(Part_II).pdf
7. http://www.mediafire.com/view/c9cb79obrx1joab/Simulate_Random_MAC_Protocol_in_NS2_(Part_III)_-_Pearls_in_Life.pdf
8. http://www.mediafire.com/view/oqn7ncylyh327a2/Simulate_Random_MAC_Protocol_in_NS2_(Part_IV).pdf
9. http://www.mediafire.com/view/k37pvk4y9y9qi4s/Cross_Layer_Access_in_NS2.pdf
10. http://www.mediafire.com/view/3369jfcr9bu0jfq/Turn_off_ARP_in_ns2.pdf
11. http://www.mediafire.com/view/idcakr7irci8r8g/Kie_Liu’s_NS2_Code.pdf
12. http://www.mediafire.com/view/dy9cccs55tmk417/Routing_Performance_Analysis_from_Trace_Files.pdf
13. http://www.mediafire.com/view/bjav6m2mx58507k/Timer_Usage.pdf
14. http://www.mediafire.com/view/1ws1o8st66tbwga/Enhanced_Carrier_Sensing_ns2.pdf
15. http://www.mediafire.com/view/in4din9q451nnfa/Turn_off_energy_log_in_ns2.pdf
16. http://www.mediafire.com/view/qdjvl3mmm32c7qe/Understanding_Headers_and_Addresses_in_ns2.pdf
17. http://www.mediafire.com/view/ebchhqbgs9xn7n5/Adding_new_application_and_agent.doc
18. http://www.mediafire.com/view/zu99seoyud6r77v/How_to_-_Wireless_Network_Emulation_Using_ns2_and_User_Mode_Linux.pdf
19. http://www.mediafire.com/view/xcih8h8oo7lmvdc/Timers.pdf
20. http://www.mediafire.com/view/62vr7ncz0lna16n/ns2_Adding_Modules.pdf
21. http://www.mediafire.com/view/f7u045e13ly49e5/Energy_model_update_in_NS-2.pdfhttp://www.mediafire.com/view/f7u045e13ly49e5/Energy_model_update_in_NS-2.pdf
22. http://www.mediafire.com/view/f9an42la2sx3avz/Myth_of_Power_Control_in_Routing.pdf
23. http://www.mediafire.com/view/sh3l01u6y5powk7/Timers_ns2.pdf
24. http://www.mediafire.com/view/vyx7k3lcqhu7w17/Finding_Node_Position,Velocity_and_Speed_in_NS2.34_Mano.pdf
25. http://www.mediafire.com/view/a5m9yk4wkf6zaaz/NS2_Simple_Method_to_Analyze_Traces_-_Causal_Nexus.pdf
26. http://www.mediafire.com/view/567gj7rjx1ugq66/How_to_get_Neighbor_Nodes_of_a_Mobile_Node_in_Wireless_Simulations.pdf
27. http://www.mediafire.com/view/pgvmmjw58fx16lm/Routing_Table_Print_in_AODV.pdf
28. http://www.mediafire.com/view/8i13xwyhseevlle/NS2_SetDest_Acceleration_Enhancement.pdf
29. http://www.mediafire.com/view/lwh59dx1rnl5bqy/Improvements_on_MAC_802.11_Simulation_when_link_loss_ration_or_contention_is_considered.pdf
30. http://www.mediafire.com/view/1bhq4b5gyp12j1r/Obtaining_Node_Position_and_Energy_Dynamically_in_ns2.pdf
31. http://www.mediafire.com/view/woktraus2d2yx3u/Timer_Usage_in_ns2.pdf
32. http://www.mediafire.com/view/locmlkm8lxymoso/How_to_Recompile_Network_ns2.pdf
33. http://www.mediafire.com/view/oe2cbwwix8x860v/ECS_-_An_Enhanced_Carrier_Sensing_Mechanism_in_ns2.pdf
34. http://www.mediafire.com/view/h57yiso5ezah41n/Dynamic_Transmission_Power_Control_in_ns2.pdf
35. http://www.mediafire.com/view/p80lbtsib834nq7/How_to_patch_GPSR_routing_to_ns-2.34_-_Page_2.pdf
36. http://www.mediafire.com/view/gaednxjkk18l8nt/How_to_patch_GPSR_routing_to_ns-2.34_-_Page_3.pdf
37. http://www.mediafire.com/view/lbjh55hm3ho5m8y/Bryan’s_NS-2_Dynamic_Source_Routing_FAQ.pdf

CATEGORY VIII) NS2 Miscellaneous Reading Material

1. http://www.mediafire.com/view/3y75e86vej79hmp/xgraph_utitlity_of_ns2(2).pdf
2. http://www.mediafire.com/view/aqzc6u7gm4uz9hs/Integration_of_NS_BGP_with_NS-2.34(2).pdf
3. http://www.mediafire.com/view/qcw3j0nca1y0j39/Using_Ns2(2).doc
4. http://www.mediafire.com/view/12zlrnvqint08pj/Trace_Analyzer_for_NS-2(2).pdf
5. http://www.mediafire.com/view/mbasaywr7e9qccy/Using_NSG_Wired(2).doc
6. http://www.mediafire.com/view/ejeaxfiweheftbq/BonnMotion_Docu(2).pdf

I shall strive to keep on updating this list as soon as I stumble upon new material. I shall constantly update this list. If you have any other document related to ns2 which u need to share (please do not hide any document if you have downloaded it from the internet) please post it in the comments.

Expand this list as much as possible and lets help each other !!.

Disclaimer: All these files are not mine and i have just collected them from the internet. If you have any issues regarding this post or any material that has been uploaded just throw a comment and i shall remove that link.

Understanding BSD Linked List used in AODV routing protocol in ns2.34

Hello Folks, It’s been a long time since i posted. i had been studying the AODV routing protocol and am still trying to make it energy aware. Most of the people who are reading this post must already know about BSD linked list. This list is under the directory /ns-2.34/lib/bsd-list.h. It contains few macros for defining a doubly linked list that is used in AODV for maintaining routing tables, precursor lists, neighbor caches and Broadcast ID cache.

I searched a lot trying to understand the aodv code but the usage of bsd-list was a major hindrance in understanding it. Even after a lot of searching i could not find good material to read as it involved complex use of pointers. In the end I studied the bsd-list.h and few help from the internet I was able to relate how things are actually working. In this post I would explain the working of BSD list and how it actually works. I would not go into the inner details as the macros defined do most of the functionality themselves therefore studying them in huge detail becomes irrelevant. And yes this post would assume that you first go and read about pointers and try implementing a singly linked list and a doubly linked list on your own in C++. (Believe me that would really help).

The source files needed for this program can be downloaded from here:

Step 1) bsd-list.h contains the following macros

#define LIST_HEAD(name, type) \
struct name { \
type *lh_first; /* first element */ \
}

#define LIST_ENTRY(type) \
struct { \
type *le_next; /* next element */ \
type **le_prev; /* address of previous next element */ \
}

#define LIST_INIT(head) { \
(head)->lh_first = NULL; \
}

#define LIST_INSERT_AFTER(listelm, elm, field) { \
if (((elm)->field.le_next = (listelm)->field.le_next) != NULL) \
(listelm)->field.le_next->field.le_prev = \
&(elm)->field.le_next; \
(listelm)->field.le_next = (elm); \
(elm)->field.le_prev = &(listelm)->field.le_next; \
}

#define LIST_INSERT_BEFORE(listelm, elm, field) { \
(elm)->field.le_prev = (listelm)->field.le_prev; \
(elm)->field.le_next = (listelm); \
*(listelm)->field.le_prev = (elm); \
(listelm)->field.le_prev = &(elm)->field.le_next; \
}

#define LIST_INSERT_HEAD(head, elm, field) { \
if (((elm)->field.le_next = (head)->lh_first) != NULL) \
(head)->lh_first->field.le_prev = &(elm)->field.le_next;\
(head)->lh_first = (elm); \
(elm)->field.le_prev = &(head)->lh_first; \
}

#define LIST_REMOVE(elm, field) { \
if ((elm)->field.le_next != NULL) \
(elm)->field.le_next->field.le_prev = \
(elm)->field.le_prev; \
*(elm)->field.le_prev = (elm)->field.le_next; \
}

Now i will give a certain example to understand the working of the above bsd-list.

Step 2) First of all create a .cpp file with the name workingbsdlist.cpp and inside the same directory copy the file bsd-list.h from /ns-2.34/lib/bsd-list.h directory.

The code for workingbsdlist.cpp is as follows (u can always copy paste)

#include
#include
#include"bsd-list.h"

using namespace std;

struct foo {
int a;
LIST_ENTRY(foo) pointers; // pointers is the object of the structure generated by List Entry
}*temp, *var, *ptr;

LIST_HEAD(foo_list, foo);

int main(void)
{
LIST_HEAD(foo_list, foo) head;
LIST_INIT(&head);

struct foo *item1 = new foo;
struct foo *item2 = new foo;
struct foo *item3 = new foo;
item1->a = 60;
item2->a = 120;
item3->a = 240;
LIST_INSERT_HEAD(&head, item1, pointers);
LIST_INSERT_AFTER(item1, item2, pointers);
LIST_INSERT_BEFORE(item2, item3, pointers);
//Displaying inner details of list
{
cout<<"HEAD's Address : "<<head.lh_first<<endl;
cout<<"Item 1 next value : "<pointers.le_next<<endl;
cout<<"Item 1 prev value : "<pointers.le_prev<<endl;
cout<<"HEAD's Address : "<<head.lh_first<<endl;
cout<<"Item 2 next value : "<pointers.le_next<<endl;
cout<<"Item 2 prev value : "<pointers.le_prev<<endl;
cout<<"HEAD's Address : "<<head.lh_first<<endl;
cout<<"Item 3 next value : "<pointers.le_next<<endl;
cout<<"Item 3 prev value : "<pointers.le_prev<pointers.le_next)
{
cout<a<<endl;
}
return (0);
}

Although the above example may be quite vague and non-coherent but it is good for an intermediate C++ programmer to learn.

Step 3) Now i shall explain each and every line of this program and how it uses the bsd-list.h header file to create a doubly linked list. Once u understand this it becomes very easy to understand code in aodv.cc

Firstly we create a structure named as foo and within it we declare a variable a.
Within the structure we call the macro using

LIST_ENTRY(foo) pointers;

Seeing the macro in bsd-list.h. This expands to the following (keep watching closely)

struct foo {
int a;
struct { // This is a nameless structure within a structure
struct foo *le_next; // pointer to structure foo
struct foo **le_prev; // pointer to a pointer that points to structure foo
} pointers; // structure variable of nameless structure
}*temp, *var, *ptr; // pointers to structure foo

Then we call the another macro in bsd-list.h as:

LIST_HEAD(foo_list, foo);

This expands to the following code:

struct foo_list // A new structure with the name foo_list that holds pointer to struct foo
{
foo *lh_first; //pointer to struct foo
}

Now in the main() function we call the same macro LIST_HEAD but this time an variable is also created for the structure foo_list. See below.

LIST_HEAD(foo_list, foo) head;

expands to

struct foo_list // A new structure with the name foo_list that holds pointer to struct foo
{
foo *lh_first; //pointer to struct foo
}head;

In the next statement another macro is called

LIST_INIT(&head);

This macro call expands to
(head)->lh_first = NULL;

This is same as head->lh_first = NULL, and it puts the value of the pointer lh_first to NULL. But see one thing the *lh_first is declared inside struct foo_list so it can only be accessed by variables of foo_list. Thus we can access it using head. Thus we write head->lh_first = NULL. This also means that the head element currently will point to NULL.

Next we declare 3 generate 3 new nodes item1, item2, item3 which are actually pointers to struct foo. We enter info in their variable a using item1->a = 60; etc.

Now we shall use the three macros that actually define the insertion operations. U do not need to study the internal details of these three macros. They shall do as they say. For example

The first macro we use is to insert at the head of the list.
LIST_INSERT_HEAD(&head, item1, pointers);

seeing this macro in bsd-list.h we have
#define LIST_INSERT_HEAD(head, elm, field)
This macro takes three arguments
1. address of head (remember that head initially points to nothing because we set its value to NULL initially).
2. node that you want to insert (item1, item2, item3 etc).
3. field which is structure variable of the nameless structure that resulted on macro expansion

The other two items are after and before that are defined in bsd-list.h as
#define LIST_INSERT_AFTER(listelm, elm, field) {....}
#define LIST_INSERT_BEFORE(listelm, elm, field) {....}

They take three arguments.
1. First argument is the listelm after or before which u want to insert.
2. Node which u want to insert such as item1, item2 etc.
3. field which is a structure variable of nameless structure defined above (pointers in our ex)

Similarly the remove macro. It becomes very easy to use and understand if above two are clear.

Then we display some inner details of the list and variables. Usually to see how addresses are used and nodes are referenced. What values are stored in next and prev. What are their addresses. Have we achieved success.

In the end we print all the elements of the list. This is a tricky for loop to understand and is quite different from the conventional method. Remember this for loop can be written in two ways. I shall explain both of them so that u do not face any difficulty when u see them in AODV code in ns-2.34.

1st One)

ptr = head.lh_first;
for(;;ptr = ptr->pointers.le_next)
{
cout<a<<endl;
}

First ptr is a pointer to struct foo. We want it to point to head of the list. And head is pointed to by lh_first. So we make it point using ptr = head.lh_first. (u should understand why we used head.lh_first).
This for loop will check for ptr is not equal to NULL and it will be incremented every time by
ptr = ptr->pointers.le_next.
Remember ptr is pointer variable of struct foo. And by definition we will have to use -> sign to access le_next. But le_next is inside a nameless structure whose variable is pointers.
Thus we write ptr = ptr->pointers.le_next.

2nd One) It is similar to earlier one except
for(;ptr;ptr = ptr->pointers.le_next)
This is one more method to access or traverse the list. This will check till ptr has a valid value or not.

Hope u understand this. And if any queries arise please feel free to ask.

Note:- These are my own views and I am not a professional C++ programmer. Some things may have totally different interpretations when seen by different experienced programmers. If i am wrong somewhere please correct it and accept my apologies.

[AWK Script] An Awk Script to Print Network Statistics

Image

Hi Folks,

In this post I, shall give u an awk file I wrote that prints several network statistics of interest (these are of course the basic ones cuz i ain’t that good at statistics). Being fed up with lots of awk files floating on the net and most of them don’t work or work on old trace formats of ns-2.34. So I planned to write my own awk script for my simulations.

[ AWK FILE SCRIPT DOWNLOAD]

This awk script i wrote is for 50 nodes and by minor modifications it can be changed to any no. I have used it for 150 nodes. The statistics u can calculate with this file are:

  • Total Packets Sent
  • Total Packets Received
  • Total Packets Dropped
  • Total Packets Forwarded
  • Packet Delivery Ratio %
  • The total hop counts are
  • Average Hop Count
  • Routing Overhead
  • Normalized Routing Load
  • Througphut of the network (KBps)
  • Average End to End Delay
  • Total Energy Consumed
  • Protocol Energy Consumption

Some of these metrics I have calculated using the above shown image. However energy consumption metrics have been calculated by me. When u run this awk script using the command :

awk -f statistics.awk xyz.tr   (xyz.tr is your trace file name)

statistics.awk creates 5 files (which contain info related with each node) in your directory they are:

  • energyleft.txt
  • pktdrop.txt
  • pktfwd.txt
  • pktrecvd.txt
  • pktsent.txt

Note:- This statistics.awk file was made for 50 nodes. However in the awk file i have put comments so as to where u need to make changes in order to run it for any number of nodes.

My view:- I wrote it according to my own logic and understanding however some logic may be wrong or may not be optimal or may be very time consuming. If any suggestions are there for improving this code. Please suggest. Thanks

Let’s support the research community by sharing our code and not hiding it.

[How To] Display Routing Table of AODV in ns-2.34

Hi Folks,

In this post I shall tell about how to display routing table of nodes while using AODV protocol. I read various tutorials online but most of them failed to exactly display the routing tables or were unable to exactly specify where to put the print_routing_table() function. And by using these methods I kept getting segmentation faults or huge files displaying routing tables even when the node count was 5 with only 1 traffic source. However i have used some of those tutorials and modded them to work fine “cuz u know no one writes code from scratch”. My grandfather did that and he is old by now.

Let’s begin:

Step 1) Open file aodv_rtable.h . Go to class aodv_rtable and in its public scope declare a member function

void rt_display(nsaddr_t id);

Step 2) Open file aodv_rtable.cc . Go to end and type this (read copy-paste 🙂 )

void
aodv_rtable::rt_display(nsaddr_t id)
{
FILE *dumpFile;
dumpFile = fopen("rtable.txt", "a+");
aodv_rt_entry *rt = rthead.lh_first;
for(; rt; rt = rt->rt_link.le_next) {
// You can add more route table entries if you want to. See aodv_rtable.h for more entries.
fprintf(dumpFile, "NODE: %d \t %f \t %d \t %d \t %d \t %d \t %.4f \t %d \n", id, CURRENT_TIME,
rt->rt_dst, rt->rt_nexthop, rt->rt_hops, rt->rt_seqno, rt->rt_expire, rt->rt_flags);
}
fclose(dumpFile);
}

Step 3) (Important One) Open file aodv.cc . Go to the function
AODV::rt_update(aodv_rt_entry *rt, .... )

At the end of inside this function call the rt_display() function as:

rtable.rt_display(index);

Step 4) Compile using make and sudo make install inside the ns-2.34 directory.

Step 5) run your tcl file (here is the file if u want to test). The rtable.txt should look like this rtable.txt  ..

[How To] Implementing a New Unicast Routing Protocol for MANETs* in ns-2.34.. (With tcl file)

Hi Folks,

In this post I would tell u about how to successfully perform the steps to Implement a New Unicast Routing Protocol for MANETs by F. J. Ros and P. M. Ruiz While performing this task I faced a no. of problems. The tutorial by F. J. Ros and P. M. Ruiz is complete for a beginner to start working with. However it has certain anomalies (not in the code) such as typographical errors or case sensitivity problems. The tutorial is also designed for earlier versions of ns2. So I tried working on this tutorial which is quite excellent and and after facing a lot of problems and issues I successfully implemented it in ns-2.34.

If u perform the steps according to this post. U shall be able to implement the protocol succesfully. I shall not go into explaining the source code as it has already been beautifully explained in the original document. The source of  the document is given at the end of this post. Thus, for successfull implementation u should read this post very carefully.

NOTE: Beware of Case Sensitiveness and perform as I shall tell below.

Step 1) First of all create a directory in your ns-2.34 directory with the following files.

protoname_pkt.h
protoname_rtable.cc
protoname_rtable.h
Protoname.cc        \\ Note the capital P in the beginning (it should be capital P)
protoname.h

Step 2) The code for protoname_pkt.h is given below (u can copy paste)

#ifndef PROTONAME_PKT_H_
#define PROTONAME_PKT_H_

#include <packet.h>
#include <config.h>
#include <random.h>
#include <timer-handler.h>
#include <trace.h>
#include <classifier-port.h>

#define HDR_PROTONAME_PKT(p) hdr_protoname_pkt::access(p)

struct hdr_protoname_pkt {

nsaddr_t pkt_src_;       //Node which originated this packet
u_int16_t pkt_len_;    //Packet length (in bytes)
u_int8_t pkt_seq_num_; //Packet Sequence Number

inline nsaddr_t& pkt_src() {return pkt_src_;}
inline u_int16_t& pkt_len() {return pkt_len_;}
inline u_int8_t& pkt_seq_num() {return pkt_seq_num_;}

static int offset_;
inline static int& offset() {return offset_;}

// To access the hdr_protoname_pkt packet header in a packet pointed by p, we use the access fn
inline static hdr_protoname_pkt* access(const Packet* p) {
return (hdr_protoname_pkt*)p->access(offset_);
}
};

#endif /* PROTONAME_PKT_H_ */

Step 3) The code for protoname_rtable.cc is given below

#include "protoname_rtable.h"
#include "ip.h"

protoname_rtable::protoname_rtable() { }

void protoname_rtable::print(Trace* out) {
sprintf(out->pt_->buffer(), "p\tdest\tnext");
out->pt_->dump();
for (rtable_t::iterator it = rt_.begin(); it != rt_.end(); it++) {
sprintf(out->pt_->buffer(), "P\t%d\t%d", (*it).first, (*it).second);
out->pt_->dump();
}
}

void
protoname_rtable::clear() {
rt_.clear();
}

void
protoname_rtable::rm_entry(nsaddr_t dest) {
rt_.erase(dest);
}

void
protoname_rtable::add_entry(nsaddr_t dest, nsaddr_t next) {
rt_[dest] = next;
}

nsaddr_t
protoname_rtable::lookup(nsaddr_t dest) {
rtable_t::iterator it = rt_.find(dest);
if (it == rt_.end())
return IP_BROADCAST;
else
return (*it).second;
}

u_int32_t
protoname_rtable::size() {
return rt_.size();
}

Step 4) The code for protoname_rtable.h is given below

#ifndef PROTONAME_RTABLE_H_
#define PROTONAME_RTABLE_H_

#include <trace.h>
#include <map>
#include <ip.h>

typedef std::map<nsaddr_t, nsaddr_t> rtable_t;

class protoname_rtable {
rtable_t rt_;

public:
protoname_rtable();
void print(Trace*);
void clear();
void rm_entry(nsaddr_t);
void add_entry(nsaddr_t, nsaddr_t);
nsaddr_t lookup(nsaddr_t);
u_int32_t size();
};

#endif /* PROTONAME_RTABLE_H_ */

Step 5) The code for Protoname.cc is given below

#include "protoname.h"
#include "protoname_pkt.h"
#include "protoname_rtable.h"
#include <timer-handler.h>
#include <node.h>
#include <random.h>
#include <cmu-trace.h>
#include <iostream>
#include <classifier-port.h>
#include <packet.h>
#include <address.h>

// To Bind our packet in OTcl Interface
int hdr_protoname_pkt::offset_;
static class ProtonameHeaderClass : public PacketHeaderClass {
public:
ProtonameHeaderClass() : PacketHeaderClass("PacketHeader/PROTONAME", sizeof(hdr_protoname_pkt)) {
bind_offset(&hdr_protoname_pkt::offset_);
}
}class_rtProtoProtoname_hdr;

static class ProtonameClass : public TclClass
{
public:
ProtonameClass() : TclClass("Agent/PROTONAME") {}
TclObject* create(int argc, const char*const* argv) {
assert(argc==5);
return(new Protoname((nsaddr_t)Address::instance().str2addr(argv[4])));
}
}class_rtProtoProtoname;

void
Protoname_PktTimer::expire(Event* e) {
agent_->send_protoname_pkt();
agent_->reset_protoname_pkt_timer();
}

Protoname::Protoname(nsaddr_t id) : Agent(PT_PROTONAME), pkt_timer_(this) {
bind_bool("accessible_var_", &accessible_var_);
ra_addr_ = id;
}

int
Protoname::command(int argc, const char*const* argv) {
if(argc == 2) {
if (strcasecmp(argv[1], "start") == 0) {
pkt_timer_.resched(0.0);
return TCL_OK;
}
else if (strcasecmp(argv[1],"print_rtable") == 0) {
if(logtarget_ != 0) {
sprintf(logtarget_->pt_->buffer(), "P %f _%d_ Routing Table", CURRENT_TIME, ra_addr());
logtarget_->pt_->dump();
rtable_.print(logtarget_);
}
else {
fprintf(stdout, "%f _%d_ If you want to print this routing table ""you must create a trace file in your TCL Script",CURRENT_TIME, ra_addr());
}
return TCL_OK;
}
}
else if (argc == 3) {
//Obtains corresponding dmux to carry packets to upper layer
if (strcmp(argv[1], "port-dmux") == 0) {
dmux_ = (PortClassifier*)TclObject::lookup(argv[2]);
if (dmux_ == 0) {
fprintf(stderr, "%s: %s lookup of %s failed \n", __FILE__,argv[1],argv[2]);
return TCL_ERROR;
}
return TCL_OK;
}
//Obtains corresponding tracer
else if (strcmp(argv[1], "log-target") == 0 || strcmp(argv[1], "tracetarget") == 0) {
logtarget_ = (Trace*)TclObject::lookup(argv[2]);
if (logtarget_ == 0)
return TCL_ERROR;
return TCL_OK;
}
}
//Pass the command to the base class
return Agent::command(argc, argv);
}

void
Protoname::recv(Packet* p, Handler* h) {
struct hdr_cmn* ch    = HDR_CMN(p);
struct hdr_ip* ih     = HDR_IP(p);

if (ih->saddr() == ra_addr()){
//If there exists a routing loop, drop the packet
if(ch->num_forwards() > 0) {
drop(p, DROP_RTR_ROUTE_LOOP);
return;
}

//else if this is a packet I am originating, must add IP header
else if(ch->num_forwards() == 0)
ch->size() += IP_HDR_LEN;
}

// If it is a protoname packet, must process it
if(ch->ptype() == PT_PROTONAME)
recv_protoname_pkt(p);

//Otherwise, must forward the packet (unless TTL reaches zero
else {
ih->ttl_--;
if(ih->ttl_ == 0) {
drop(p, DROP_RTR_TTL);
return;
}
forward_data(p);
}
}

void
Protoname::recv_protoname_pkt(Packet* p) {
struct hdr_ip* ih                = HDR_IP(p);
struct hdr_protoname_pkt* ph    = HDR_PROTONAME_PKT(p);

// All routing messages are sent from and to port RT_PORT, so we shall check it
assert(ih->sport() == RT_PORT);
assert(ih->dport() == RT_PORT);

/* processing of protoname packet */

// Release resources
Packet::free(p);
}

void
Protoname::send_protoname_pkt() {
Packet* p                        = allocpkt();
struct hdr_cmn* ch                = HDR_CMN(p);
struct hdr_ip* ih                = HDR_IP(p);
struct hdr_protoname_pkt* ph     = HDR_PROTONAME_PKT(p);

ph->pkt_src()                     = ra_addr();
ph->pkt_len()                    = 7;
ph->pkt_seq_num()                = seq_num_++;

ch->ptype()                        = PT_PROTONAME;
ch->direction()                    = hdr_cmn::DOWN;
ch->size()                        = IP_HDR_LEN + ph->pkt_len();
ch->error()                        = 0;
ch->next_hop()                    = IP_BROADCAST;
ch->addr_type()                    = NS_AF_INET;

ih->saddr()                     = ra_addr();
ih->daddr()                        = IP_BROADCAST;
ih->sport()                        = RT_PORT;
ih->dport()                        = RT_PORT;
ih->ttl()                        = IP_DEF_TTL;

Scheduler::instance().schedule(target_, p, JITTER);
}

void
Protoname::reset_protoname_pkt_timer() {
pkt_timer_.resched((double)5.0);
}

void
Protoname::forward_data(Packet* p) {
struct hdr_cmn* ch = HDR_CMN(p);
struct hdr_ip* ih = HDR_IP(p);

if(ch->direction() == hdr_cmn::UP && ((u_int32_t)ih->daddr() == IP_BROADCAST || ih->daddr() == ra_addr())) {
dmux_->recv(p, NULL);
return;
}
else {
ch->direction() = hdr_cmn::DOWN;
ch->addr_type() = NS_AF_INET;
if ((u_int32_t)ih->daddr() == IP_BROADCAST)
ch->next_hop() = IP_BROADCAST;
else {
nsaddr_t next_hop = rtable_.lookup(ih->daddr());
if(next_hop == IP_BROADCAST) {
debug("%f: Agent %d can not forward a packet destined to %d \n", CURRENT_TIME,ra_addr(),ih->daddr());
drop(p, DROP_RTR_NO_ROUTE);
return;
}
else
ch->next_hop() =  next_hop;
}
Scheduler::instance().schedule(target_, p, 0.0);
}
}

Step 6) The code for protoname.h is given below

#ifndef PROTONAME_H_
#define PROTONAME_H_

#include "protoname_pkt.h"
#include "protoname_rtable.h"
#include <agent.h>
#include <packet.h>
#include <trace.h>
#include <timer-handler.h>
#include <random.h>
#include <classifier-port.h>
#include "arp.h"
#include "ll.h"
#include "mac.h"
#include "ip.h"
#include "delay.h"

#define CURRENT_TIME Scheduler::instance().clock()
#define JITTER (Random::uniform()*0.5)

class Protoname;    //Forward Declaration

/* TIMERS */

class Protoname_PktTimer : public TimerHandler {
public :
Protoname_PktTimer(Protoname* agent) : TimerHandler() {
agent_ = agent;
}
protected:
Protoname* agent_;
virtual void expire(Event* e);
};

/* Agent */
class Protoname : public Agent {
/* Friends */
friend class Protoname_PktTimer;

/*Private Members*/
nsaddr_t             ra_addr_;
//protoname_state     state_;
protoname_rtable     rtable_;
int                 accessible_var_;
u_int8_t             seq_num_;

protected :

PortClassifier*     dmux_;            //For Passing Packets Up To Agents
Trace*                logtarget_;        //For Logging
Protoname_PktTimer     pkt_timer_;        //Timer for sending packets

inline nsaddr_t&         ra_addr()             {return ra_addr_; }
//inline protoname_state& state()                {return state_;}
inline int&             accessible_var()     {return accessible_var_;}

void forward_data(Packet*);
void recv_protoname_pkt(Packet*);
void send_protoname_pkt();

void reset_protoname_pkt_timer();

public:
Protoname(nsaddr_t);
int command(int, const char*const*);
void recv(Packet*, Handler*);

};

#endif /* PROTONAME_H_ */

Note: Now we have to make changes to certain ns-2.34 files. The steps given below are most important for successful implementation so perform them very carefully.

Step 7) Open file packet.h under ns-2.34/common/packet.h. Do the changes given below.

Under typedef unsigned int packet_t; lots of constants would have been defined.

Go down and at Line 182 u will find

// AOMDV packet
static const packet_t PT_AOMDV = 61;

After it insert the line as follows

// insert new packet types here
static const packet_t    PT_PROTONAME = 62;

and change PT_NTYPE value from 62 (earlier) to 63 now.

static packet_t PT_NTYPE = 63; // This MUST be the LAST one

Then in the same file move down till u find p_info(). In it search for the function
static packetClass classify(packet_t type) {

and perform the following changes in it by entering the 2nd line below.

type == PT_AODV ||
type == PT_PROTONAME)
return ROUTING;

In the same file, go below and search for the function static void initName(). Now at the end of this function u shall find this

// AOMDV patch
name_[PT_AOMDV]= "AOMDV";

After this enter the following line.

name_[PT_PROTONAME] = "PROTONAME";
name_[PT_NTYPE]= "undefined"; // let it remain as it is

Step 8) Open the file cmu-trace.h under ns-2.34/trace/cmu-trace.h

At line 162 u shall find

void    format_aomdv(Packet *p, int offset);

After it enter the following line

void format_protoname(Packet *p, int offset);

Step 9) Now open the file cmu-trace.cc in the same folder ns-2.34/trace/cmu-trace.h

Include the following header file at the beginning.

#include <protoname/protoname_pkt.h>

Now at the end write the following code ( u can always copy-paste) 🙂

void
CMUTrace::format_protoname(Packet* p, int offset)
{
struct hdr_protoname_pkt* ph = HDR_PROTONAME_PKT(p);

if(pt_->tagged()) {
sprintf(pt_->buffer() + offset, “-PROTONAME:o %d -PROTONAME:s %d -PROTONAME:l %d”, ph->pkt_src(), ph->pkt_seq_num(), ph->pkt_len());
}
else if (newtrace_) {
sprintf(pt_->buffer() + offset, “-P PROTONAME -Po %d -Ps %d -Pl %d “, ph->pkt_src(), ph->pkt_seq_num(), ph->pkt_len());
}
else {
sprintf(pt_->buffer() + offset, “[PROTONAME %d %d %d] “, ph->pkt_src(), ph->pkt_seq_num(), ph->pkt_len());
}
}

After the above steps search for the function (in the same file) at Line 1305 (most probably)

void CMUTrace::format(Packet* p, const char *why)

move down and after

case PT_PING:
break;

Enter the following lines

case PT_PROTONAME:
format_protoname(p, offset);
break;

Step 10) Open the file ns-packet.tcl under ns-2.34/tcl/lib/ns-packet.tcl

Search at Line 113 for
foreach prot {

Enter the following after to it to make it look like this

foreach prot {
PROTONAME
# Common:
Common
Flags
IP     # IP
# Routing Protocols:
NV     # NixVector classifier for stateless routing
....

Step 11) Open the file ns-default.tcl under ns-2.34/tcl/lib/ns-default.tcl

In the end of the file enter the following line

Agent/PROTONAME set accessible_var_ true

Step 12) Open the file ns-lib.tcl under ns-2.34/tcl/lib/ns-lib.tcl

Search at Line 604 for the function
Simulator instproc create-wireless-node args {

Go below and after

switch -exact $routingAgent_ {

Enter the following lines

PROTONAME {
set ragent [$self create-protoname-agent $node]
}

To make it look like this
switch -exact $routingAgent_ {
PROTONAME {
set ragent [$self create-protoname-agent $node]
}
DSDV {
set ragent [$self create-dsdv-agent $node]
}

Now in the same file go at last or end and enter the following lines

Simulator instproc create-protoname-agent { node } {
# Create Protoname Routing Agent
set ragent [new Agent/PROTONAME [$node node-addr]]
$self at 0.0 "$ragent start"
$node set ragent_ $ragent
return $ragent
}

Step 13) Open file priqueue.cc under ns-2.34/queue/priqueue.cc

Search for the function at Line 82.
PriQueue::recv(Packet *p, Handler *h)

After case PT_AOMDV: enter the following line

case PT_PROTONAME:

It should look like this

case PT_AOMDV:
case PT_PROTONAME:
recvHighPriority(p, h);
break;

Step 14) Now changes to be done in Makefile.in

Under INCLUDES add the following directory

-I./wpan \
-I./protoname

Under OBJ_CC do the following changes at the end.

protoname/Protoname.o protoname/protoname_rtable.o \
@V_STLOBJ@

Step 15) Now save your project and move to the command line Ctrl + Alt + T.

Browse to directory ns-2.34 under ns-allinone-2.34 directory.

Perform the following commands in order.

./configure

make clean

make depend // Optional

make

sudo make install

U shall get no errors. If you are getting any errors ask in the comments section.

Step 16) Now we have to make a tcl file to test the protocol.

In home directory. Create a tcl file with the name exproto.tcl. The contents of the tcl file are as follows (I have defined 6 nodes)

# Define options
set val(chan) Channel/WirelessChannel ;# channel type
set val(prop) Propagation/TwoRayGround ;# radio-propagation model
set val(netif) Phy/WirelessPhy ;# network interface type
set val(mac) Mac/802_11 ;# MAC type
set val(ifq) CMUPriQueue ;# interface queue type
set val(ll) LL ;# link layer type
set val(ant) Antenna/OmniAntenna ;# antenna model
set val(ifqlen) 50 ;# max packet in ifq
set val(nn) 6 ;# number of mobilenodes
set val(rp) PROTONAME ;# routing protocol
set val(x) 1000 ;# X dimension of topography
set val(y) 1000 ;# Y dimension of topography
set val(stop) 150 ;# time of simulation end

set ns [new Simulator]
set tracefd [open simple.tr w]
set namtrace [open simwrls.nam w]

$ns trace-all $tracefd
$ns namtrace-all-wireless $namtrace $val(x) $val(y)

# set up topography object
set topo [new Topography]

$topo load_flatgrid $val(x) $val(y)

create-god $val(nn)

# configure the nodes
$ns node-config -adhocRouting $val(rp) \
-llType $val(ll) \
-macType $val(mac) \
-ifqType $val(ifq) \
-ifqLen $val(ifqlen) \
-antType $val(ant) \
-propType $val(prop) \
-phyType $val(netif) \
-channelType $val(chan) \
-topoInstance $topo \
-agentTrace ON \
-routerTrace ON \
-macTrace OFF \
-movementTrace ON

for {set i 0} {$i < $val(nn) } { incr i } {
set n($i) [$ns node]
}

# Provide initial location of mobilenodes
$n(0) set X_ 100.0
$n(0) set Y_ 200.0
$n(0) set Z_ 0.0

$n(1) set X_ 200.0
$n(1) set Y_ 400.0
$n(1) set Z_ 0.0

$n(2) set X_ 500.0
$n(2) set Y_ 600.0
$n(2) set Z_ 0.0

$n(3) set X_ 400.0
$n(3) set Y_ 500.0
$n(3) set Z_ 0.0

$n(4) set X_ 700.0
$n(4) set Y_ 400.0
$n(4) set Z_ 0.0

$n(5) set X_ 500.0
$n(5) set Y_ 800.0
$n(5) set Z_ 0.0

# Set a TCP connection between n(1) and n(3)
set tcp [new Agent/TCP/Newreno]
$tcp set class_ 2
set sink [new Agent/TCPSink]
$ns attach-agent $n(1) $tcp
$ns attach-agent $n(3) $sink
$ns connect $tcp $sink
set ftp [new Application/FTP]
$ftp attach-agent $tcp
$ns at 10.0 “$ftp start”

# Set a TCP connection between n(2) and n(4)
set tcp [new Agent/TCP/Newreno]
$tcp set class_ 2
set sink [new Agent/TCPSink]
$ns attach-agent $n(2) $tcp
$ns attach-agent $n(4) $sink
$ns connect $tcp $sink

#defining heads
$ns at 0.0 “$n(0) label CH”
$ns at 0.0 “$n(1) label Source”
#$ns at 0.0 “$n(2) label N2”

$ns at 10.0 “$n(2) setdest 785.0 228.0 5.0”
$ns at 13.0 “$n(4) setdest 700.0 20.0 5.0”
$ns at 15.0 “$n(3) setdest 115.0 85.0 5.0”

#Color change while moving from one group to another
$ns at 73.0 “$n(2) delete-mark N2”
$ns at 73.0 “$n(2) add-mark N2 pink circle”
$ns at 124.0 “$n(1) delete-mark N11”
$ns at 124.0 “$n(1) add-mark N11 purple circle”
$ns at 103.0 “$n(5) delete-mark N5”
$ns at 103.0 “$n(5) add-mark N5 white circle”
$ns at 87.0 “$n(3) delete-mark N26”
$ns at 87.0 “$n(3) add-mark N26 yellow circle”
$ns at 92.0 “$n(0) delete-mark N14”
$ns at 92.0 “$n(0) add-mark N14 green circle”

# Define node initial position in nam
for {set i 0} {$i < $val(nn)} { incr i } {
# 20 defines the node size for nam
$ns initial_node_pos $n($i) 20
}

# Telling nodes when the simulation ends
for {set i 0} {$i < $val(nn) } { incr i } {
$ns at $val(stop) “$n($i) reset”;
}

# ending nam and the simulation
$ns at $val(stop) “$ns nam-end-wireless $val(stop)”
$ns at $val(stop) “stop”
$ns at 150.01 “puts \”end simulation\” ; $ns halt”
proc stop {} {
global ns tracefd namtrace
$ns flush-trace
close $tracefd
close $namtrace
exec nam simwrls.nam &
}

$ns run

Save and close it.

Step 17) Now open terminal and type ns exproto.tcl

It shall run perfectly and nam should open.

The trace file should look as follows.

s 0.007102330 _0_ RTR  --- 0 PROTONAME 27 [0 0 0 0] ------- [0:255 -1:255 32 0] [PROTONAME 0 0 7]
r 0.008123076 _1_ RTR  --- 0 PROTONAME 27 [0 ffffffff 0 800] ------- [0:255 -1:255 32 0] [PROTONAME 0 0 7]
s 0.044061336 _1_ RTR  --- 1 PROTONAME 27 [0 0 0 0] ------- [1:255 -1:255 32 0] [PROTONAME 1 0 7]
r 0.045102081 _0_ RTR  --- 1 PROTONAME 27 [0 ffffffff 1 800] ------- [1:255 -1:255 32 0] [PROTONAME 1 0 7]
r 0.045102081 _3_ RTR  --- 1 PROTONAME 27 [0 ffffffff 1 800] ------- [1:255 -1:255 32 0] [PROTONAME 1 0 7]
...........
...........

Step 18) Now u have successfully implemented the unicast routing protocol for MANETs. U should not face any problems if you follow the above steps. However I have used Eclipse Galileo for the developing environment and prefer u to also use the same. Search my blog for configuring ns-2.34 with eclipse.

* Source – Implementing a New Manet Unicast Routing Protocol in NS2 by Francisco J. Ros, and Pedro M. Ruiz <download tutorial>

[SOLVED] Ubuntu 12.04 boots to Command Line when Rebooting after Kernel Update

Hi Folks,

Recently I came around this problem, that whenever I used to update my linux (kernel) which is currently now (3.2.0-43-generic-pae), on restarting my machine after updation my machine would always boot to linux command line asking for the userid and password. It would not boot to the GUI. On searching quite a bit I found out that this problem was due to a problem with graphics card driver update. The kernel update was unable to load properly the previously installed driver and showed a message no graphics driver is installed. To overcome this problem and boot to your GUI simple steps have to be followed. These steps simply remove any installed graphics driver which cause problems and u can later install the graphics card driver specific to your machine later on when u boot to GUI.

Step 1) when u boot to command line enter your user id and password correctly. Then enter the following commands line by line.

sudo sh /usr/share/ati/fglrx-uninstall.sh

sudo apt-get remove --purge fglrx fglrx_* fglrx-amdcccle* fglrx-dev*

after these commands run successfully perform a reboot using

sudo reboot

Then u shall be able to boot into your GUI. Now u need to install your graphics card driver again. If you tend to have a AMD Radeon HD 6300 series graphics card u can follow how to install post <here>.

[GUIDE To] Installing AMD Radeon HD 6300 Series Graphics Card Driver in Ubuntu 12.04

AMD Radeon 6300 HD Series

Hello Folks,

In this post, I would tell you about installing Graphics Driver for AMD Radeon HD 6300 Series (on a laptop) in Ubuntu 12.04. I had a tough time installing this driver as I had to read a ton of tutorials to actually figure out the correct way.

Note: Do not download any AMD graphics card driver from the Ubuntu Software Centre or Hardware Settings.

The problem that made me install this particular driver was that if u do not install this driver, Ubuntu just tends to constantly use your graphics card for rendering normal graphics (i.e. graphics that really do not need the use of your graphics card). This leads to heat up of the laptop so frequently that everytime it gave me thermal heatup shutdowns. It was really annoying. Thus I would recommend everyone to install graphics driver on their Ubuntu if their laptop comes with a separate graphics card.

Note: No need to install graphics driver if u have your graphics card onboard. Ubuntu just works fine with an onboard intel graphics card.

Step 1) Download the graphics card driver for your linux version from the AMD website here.

Step 2) Save the downloaded file in your home directory and Extract it in the home directory by using archive manager. Right click on the file and open with archive manager and extract it in home directory.

Step 3) Rename the extracted file to driver.run

Step 4) Now open terminal using Ctrl + Alt + T and type

sudo chmod +x driver.run

sudo ./driver.run

Step 5) An AMD catalyst control window would open. U can proceed by pressing next and performing the installation. After successful installation Reboot your laptop.

Step 6) Open Terminal Ctrl + Alt + T and type

fglrxinfo

u should get the following output

fglrxinfo
display: :0 screen: 0
OpenGL vendor string: Advanced Micro Devices, Inc.
OpenGL renderer string: AMD Radeon HD 6300M Series
OpenGL version string: 4.2.11733 Compatibility Profile Context

The graphics driver has been installed successfully.

[GUIDE TO] Configuring ns-2.34 with Eclipse Galileo in Ubuntu 12.04

Hi Folks,

In this post I shall explain about how to configure ns-2.34 with Eclipse Galileo. I faced certain problems while configuring ns-2.34 with eclipse as after successful configuration ns-2.34 would compile with errors. This gave me headaches and after lot of working around I found the correct method. So this guide would configure ns-2.34 with eclipse and ns-2.34 would build and compile without giving any errors.

Operating System   : Ubuntu 12.04
Network Simulator v: ns-2.34

Note: Hope u have downloaded and installed ns-allinone-2.34 fixed and patched by me. If you have not u can follow the guide <here>.

First of all in order to run eclipse u need to set up a JAVA environment on your UBUNTU 12.04. Three easy commands in the terminal will set it up for u, if JAVA environment is not present on your Ubuntu.

Open Terminal using Ctrl + Alt + T. And enter the following commands one after the another..

sudo apt-get install openjdk-7-jre
sudo apt-get install openjdk-7-jdk
sudo apt-get install icedtea6-plugin

This setups a Java environment for you.

Step 1) Download Eclipse Galileo (Eclipse IDE for C/C++ developers) from the eclipse website. Or u can download it from <here>.
U also need to download the CDT plugin for Eclipse. U can download it from <here> or from eclipse website.

Step 2) Extract eclipse in the home directory by right clicking on the file eclipse-cpp-galileo-linux-gtk.tar.gz and selecting open with archive manager. Now extract it using the extract button in the home directory. After extraction a directory with the name eclipse should be created in your home directory.

Step 3) Now right click on the file (i.e. the CDT plugin downloaded) cdt-master-6.0.2.zip and select open with archive manager. Now extract it using the extract button on top. Note: When u extract it, extract it inside the eclipse directory created earlier in your home directory and not anywhere else.

Step 4) Now open the eclipse folder and run eclipse. It will ask to select a workspace. Browse to the ns-allinone-2.34 directory in your home folder and select it. U can also make it default and set it to not ask each and every time u start eclipse.

Step 5) After eclipse opens. Browse to File –> New –> C++ Project.

Step 6) A window will open asking u to create a C++ Project. (Now u need to be careful)
In the Project Name field enter ns-2.34. It shall prompt that a directory/project with that name already exists. Ignore it.
Now under the Project Type. Select MakeFile Project.
And Under MakeFile Project. Select Empty Project.
Now Under the ToolChains section (on the right). Select Linux GCC.
And press Next.

Step 7) Now ns-2.34 will be added under your projects listing. To the left of the eclipse window.
Now go to Project –> Build All (It shall build without any errors.)
Now go to Project –> Clean and select ns-2.34 and press OK. (It shall compile without any errors).
Now go to Run –> Run (A % sign should appear on the console below).

[GUIDE TO] Installing ns-2.34 (network simulator) in Ubuntu 12.04 LTS (specifically)..

Hi Folks,

Recently, I had been trying to install ns-2.34 in my ubuntu 12.04 which i have on a HP G62 pavilion notebook. Although i successfully installed it many a times but it was just a basic install (i.e. for a noob to work upon with basic tcl scripting and viewing simulations). Installing it completely without any compilation errors was the most challenging task as in order to modify ns2 u have to install it flawlessly.

In this post I shall teach you how to install ns-2.34 in ubuntu 12.04 (specifically).

First of all u need to download my version of ns-2.34 from the link given below. In this version of ns-2.34, I have made all the necessary changes (i.e. to Makefile and certain other files in ns-2.34 directory).

Download it from here.

The package is a complete ns-allinone-package with all changes done without the need of having u to make any further changes. If the following steps are followed in order u might get a full clean install of ns2.

Note : We shall install ns-2.34 in the home directory and no where else. So please copy the downloaded file in your home directory. And if u do not know where the home directory is u can google it 🙂 .

Step 1) Remove any previous ns2 versions installed on your OS

rm -rf /home/<your-homedirectory-name>/ns-allinone-2.34

instead of ns-allinone-2.34 u can put prior versions of ns2 if installed. And to find your home directory open terminal using Ctrl + Alt + T and then type pwd in it.

Step 2) After step 1, enter the following commands

sudo apt-get update

sudo apt-get install build-essential autoconf automake libxmu-dev libxt-dev libx11-dev xorg-dev xgraph gcc g++

The above command will install all necessary dependencies in order for ns-2.34 to run and install successfully.

Step 3) Now unzip the downloaded ns-allinone-2.34.tar.gz folder by right clicking on it and selecting open with archive manager and extract it in your home folder. Then open terminal using Ctrl + Alt + T.

Browse to the ns-allinone-2.34 directory by typing :

cd ns-allinone-2.34

now browse to ns-2.34 directory by typing :

cd ns-2.34

now type the following commands in order.

./configure

make clean

make depend

make

They should run successfully without showing any error. If you get any problems ask in comments.

Now go back to ns-allinone-2.34 directory by typing

cd ..

Now install ns-2.34 by typing

./install

It should install successfully. Now close the terminal by typing exit. If u get any errors ask in comments section.

Step 4) Now its time to setup your environment variables. This is the tricky part.

open terminal by pressing Ctrl + Alt + T. And enter the following command:

sudo gedit ~/.bashrc

bashrc file would open in gedit. At the end of the file add the following lines (Do it carefully)

# LD_LIBRARY_PATH
OTCL_LIB=/home/arya/ns-allinone-2.34/otcl-1.13
NS2_LIB=/home/arya/ns-allinone-2.34/lib
X11_LIB=/usr/X11R6/lib
USR_LOCAL_LIB=/usr/local/lib
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$OTCL_LIB:$NS2_LIB:$X11_LIB:$USR_LOCAL_LIB
# TCL_LIBRARY
TCL_LIB=/home/arya/ns-allinone-2.34/tcl8.4.18/library
USR_LIB=/usr/lib
export TCL_LIBRARY=$TCL_LIB:$USR_LIB
# PATH
XGRAPH=/home/arya/ns-allinone-2.34/bin:/home/arya/ns-allinone-2.34/tcl8.4.18/unix:/home/arya/ns-allinone-2.34/tk8.4.18/unix:/home/arya/ns-allinone-2.34/xgraph-12.1/
NS=/home/arya/ns-allinone-2.34/ns-2.34/
NAM=/home/arya/ns-allinone-2.34/nam-1.13/
export PATH=$PATH:$XGRAPH:$NS:$NAM

NOTE: change arya in the above paths to your home directory’s name. (DO NOT FORGET THAT).

Close the bashrc file. Log off and log in again.

Step 5) Now open terminal using Ctrl + Alt + T and type ns.

A % sign should appears and that marks a clean installation of ns-2.34.

Voila! Success.

In the next post, I shall write about configuring ns-2.34 in Eclipse (Galileo version) for development purposes and for modifying and compiling ns-2.34 from eclipse.

Beginning a blog that answers questions which researchers come across while pursuing research in wireless ad hoc networks..!!!

Image

In this blog I would post answers to problems (if I seem to find one) that I face during my research on wireless networks. The researchers in the wireless community seem to be somewhat reserved in sharing their research experiences. In the previous years, very few of them have come out and shared with the community their experiences, challenges and issues faced by them. Many are there on LinkedIn, Facebook, Blogspot, Groups, Forums, etc. to help you out but still sometimes u may face problems to which none have the answer not even Google. So what do you do, u indulge in that problem extensively (with everything  i.e. your heart and mind) and if u tend to solve it u share it with the community. This blog is all about that. I may answer those problems which I solved and sometimes answers problems of others (of which sometimes I may not have the time to solve). And yes this blog is all about ns2 simulator or wireless simulations.