Consider you want to test the performance of the network you designed for some certain application. You can use NS for the simulation of the network, but you need to select the right traffic generator or application which suits best for your real world application.
If your real world application is just web clients accessing some central applications on the webservers, you can use the WebCache class for your simulation. It has a simple example here, and can be modified to skip the cache node with any interarrival distribution function.
If you want to simulate the exact behavior of your application, considering you know its traffic pattern exactly, WebCache is not that good for you. Cause, you possibly will simulate the logging of your client to the application and then his access of certain pages at certain times. This means that you know the exact traffic pattern of your client, when and how much data travels on the network. For such a need, you can use TrafficTrace class for your simulation. It lets you to provide a previously created/generated traffic pattern with a file.
From the source file in /ns/ns-2.29/trace/traffictrace.cc:
/* module to implement a traffic generator in ns driven by a trace * file. records in the trace file consist of 2 32 bit fields, the * first indicating the inter-packet time in microseconds, and the * second indicating the packet length in bytes. multiple TraffficTrace * objects can use the same trace file, and different TrafficTrace * objects can use different trace files. For each TrafficTrace, a * random starting point within the trace file is selected. */
Once you create a trace file for your traffic pattern, you can take the example script and write your own scenario with the help of it. NS has a sample tcl file (tg.tcl) and a sample trace file (example-trace) at /ns/ns-2.29/tcl/ex folder. When you check the scenario and run it, you'll see that both node 4 and 5 are using the same trace file, but generating different traffic patterns.
The reason for this is the TrafficTrace class, which randomize the start of traffic in the trace file. You can see this in the source code (/ns/ns-2.29/trace/traffictrace.cc):
void TrafficTrace::init() { if (tfile_) ndx_ = tfile_->setup(); } int TraceFile::setup() { : : /* pick a random starting place in the trace file */ return (int(Random::uniform((double)nrec_)+.5)); }
If you do not like this behavior, and want it to start from the start of the trace, you'll need the following change:
bahrio@blue-pill /ns/ns-2.29 $ cp trace/traffictrace.cc trace/traffictrace-orig.cc bahrio@blue-pill /ns/ns-2.29 $ diff trace/traffictrace.cc trace/traffictrace-orig.cc 201c201 < return 0; --- > return (int(Random::uniform((double)nrec_)+.5));
and then rebuild the ns binary:
$ pwd /ns/ns-2.29 bahrio@blue-pill /ns/ns-2.29 $ make g++ -c -Wall -DTCP_DELAY_BIND_ALL -DNO_TK -DTCLCL_CLASSINSTVAR -DNDEBUG -DUSE_SHM -DHAVE_LIBTCLCL :
When you rerun the script, you'll see exactly the same traffic patterns for node 4 and 5: