NS 2 - Tutorial for beginners 1
This would set the simulator with the simulator object which is to be accessed in the script.
Step 2: Then, to set the nam (network animation) file with that 'ns' object and associate with it:
Step 3: Now the nodes could be set as many as you want, for loop could be used if many nodes are to be made.
Step 4: Creating connection for the various nodes with each other with the band width and rate.
Step 5: The nodes could be given with various orientations with this option. right, right-up and right down could be used depending on the node.
Step 6: For the application like TCP or UDP to run, we need to set two agents and the application which should run in between.
When using TCP, we have FTP as the application and TCPsink as the end agent. Connection must be made between TCP and TCPsink , same in udp with cbr and null respectively.
This would make a tcp agent and connect it with the node.
Step 7: Connecting the FTP application with TCP
Step 8: Setting TCPSink to the node where the TCP packets are received:
Step 9: Connecting TCP and sink(agents) for making the network flow:
Step 10: Similarly, for UDP,
Step 11: Routing protocols can be used in the simulator using rtmodel (to break the link), rtproto (to use the protocol)
For distance vector we could use
For linkstate we could use
When all this is done, the TCP could be started at some point and could call the finish procedure to end. The out.tr file is used to trace the packets. A normal awk command could be used to analyse the packets.
Step 13: 'run' is used to run the whole simulation.