Written by Tom Laramee for use in the senior level ECE course in Computer Networks 597A, and for use in the graduate-level course ECE671.
Presented is a sample Data Link Layer protocol (Selective Repeat) simulation with sample output.
[ Tutorial Index | Lecture Notes | Skeleton Simulation Code | Media Access Simulation Code | Data Link Layer Simulation Code ]This example is fairly complex and likely to be of marginal value in helping you write your own simulations (due to the time constraint). I recommend reading this section, running the simulation (all 3), and viewing the OP. The code/scripts can also be used for ideas and enhancements, and for syntactical examples.
There are 3 zip files:
Download the 1st file, gunzip it, and untar it.
NOTE: The contents of this tape archive should reside in their own directory. If it is untarred in the same directory as either the skeleton or the other example, there will be a file collision and some files will be overwritten and lost.
The filelist should be as follows:
There are 3 scripts for this example:
They all run the same simulation - each collecting different statistics. This means that each has it's own sim.gnuplot.sh script:
If you type:
You will see the following:
sim: This script will generate 2 plots: sim: 1) Channel utilization vs. Channel Length for varying Window size sim: 2) Channel utilization vs. Window Size for varying Channel Length sim: sim: Command line parameters are as follows... sim: ------------------------------------------------ sim: Bits per ack................................: 8 sim: Channel capacity (bps)......................: 14400 sim: Channel length ( in frames )................: 0 sim: Number of bits / data frame.................: 2000 sim: Header bits / frame.........................: 400 sim: Prob that a frame or ack is lost or damaged.: 0.0 sim: Prob that a data frame is lost or damaged...: 0.0 sim: Prob that an ACK frame is lost or damaged...: 0.0 sim: Channel arrival rate........................: 25 sim: Window size.................................: 1 sim: Debugging mode..............................: 0 sim: MAXEVENTS for simulation....................: 32000 sim: MAXPACKETS for simulation...................: 1000 sim: sim: Ready to begin (y/n) ?? sim: Reminder: some files are about to be removed here... y ( <----- entered by the user) sim: Removing old output files... sim: Creating permanent data files... sim: Creating GNUplot files to generate the plots... sim.gnuplot.sh: sim.gnuplot.sh: Gnuplot driver file: data1.plot1 sim.gnuplot.sh: Gnuplot data file: a.Final sim.gnuplot.sh: Gnuplot .ps plot: data1.plot1.ps sim.gnuplot.sh: sim.gnuplot.sh: Gnuplot driver file: data1.plot2 sim.gnuplot.sh: Gnuplot data file: b.Final sim.gnuplot.sh: Gnuplot .ps plot: data1.plot2.ps sim.gnuplot.sh: sim: Compiling... gcc -c main.c -o main.o gcc -c event.c -o event.o gcc -o p5 main.o event.o -lm sim: sim: Running for several Window sizes (W=1, 3, 7) sim: Hitto continue...
NOTE: If you get:
sim: Compiling... sim.gnuplot.sh: sim: Compiling... `sim' is up to date. sim:
...instead of:
sim: Compiling... gcc -c main.c -o main.o gcc -c event.c -o event.o gcc -o p5 main.o event.o -lm
...this is o.k. - it just means the program doesn't need to be recompiled - it can be run as is.
The script will produce 2 plots:
So, the script runs in 2 cycles.
Then, the 2 plots may be Ghostviewed.
sim2.sh produces 2 plots:
sim3.sh produces 2 plots:
They are run (and they work) similary to sim1.sh.
This protocol is one of the "Sliding Window" protocols which is illustrated in the text:
Computer NetworksIt is outlined in Chapter 4. I specifically used section 4.5 to code this protocol - which is referred to as "Selective Repeat" in the book.
Once again, it is beyond the scope of this module to detail how the actual protocol works.
The genEvent? functions I added (to the skeleton) are:
The utility functions I added (to the skeleton) are:
The processEvent? function I added (to the skeleton) are:
Again, an explanation of the way these functions work is beyond the scope of this module. They are all quite short, so if you're interested in the data flow, it is obtainable directly from the code.
I modified main.c to add the above functions.
Specifically, I added:
The "printstatus()" function of the skeleton is called "postCycleOP()" here
Also, since this program is collecting 2 statistics, in the "showReport" function, I open 2 data files, "a", and "b". Each of these has it's own 2 number pair representing a statistic from the simulation.
After 1 run, the files look something like this:
(a) | (b) |
---|---|
1.0 0.0549 | 1.0 0.0651 |
Since the program is being run but the script "sim1.sh", (or sim2.sh or sim3.sh) these files are being concatenated to 2 data files for plotting.
So, after 5 program runs, those data files look like this:
(a.Final) | (b.Final) |
---|---|
1.0 0.0549 | 1.0 0.0651 |
2.0 0.0809 | 3.0 0.1121 |
3.0 0.1341 | 5.0 0.1765 |
4.0 0.3453 | 7.0 0.2310 |
5.0 0.4611 | 9.0 0.3541 |
These programs will be plotted using 2 GNUplot driver files:
The sim.sh script required the most extensive modificaiton. Again, if you are unfamiliar with the UNIX operating system, no amount of explanation will make this script clear.
This script esentially works the same way as the skeleton version - except it keeps track of only 2 statistics, and collecting them is more complicated in this example.
The script runs in 2 cycles (this was alluded to earlier).
The statistics are collected separately during each of these 2 cycles for plotting in the end.
Essentially: sim1.sh = sim2.sh = sim3.sh and
sim1.gnuplot.sh = sim2.gnuplot.sh = sim3.gnuplot.sh
where "=" means is quite similar to.
The major differences are mentioned above - the plots which are produced vary slightly.
The scripts are liberally commented - so it is entirely possible to understand what it is doing by running it and looking at the source.