In this laboratory, you will have the opportunity to write the physical layer of the protocol stack. This basically corresponds to the electrical signals used underneath something like Ethernet. We will use standard sockets to simulate the physical link. If you completed the sockets laboratory in CS345, this should be an easy programming assignment. Future labs will be different protocol layers in the protocol stack. This program will be the base of that stack. Make sure that you understand the code and add significant debug facilities that you can use in later labs. You will want to at least print out all of the data that passes in each direction. This code may help you in formatting your data.
The basic architecture of the protocol stack will have a single thread for packets flowing down the protocol stack and a single thread for packets flowing up. When the data has been processed by a particular layer, it will call the corresponding routine in the next layer of the stack. Each protocol layer will be an object. Below you can download the framework for this lab. In it will be the physical layer obect which you will modify. The physical layer object will support the following methods:
This pthreads tutorial should help you to figure out how to start a thread (look under "The Pthreads Library").You will save yourself some trouble if you compile using g++ with the "-lpthread" library and should include <pthread.h>. There should only be two threads, one that is continually reading (started in init), the other that is sending things down the protocol stack(Your main program).
The following figure should help you to understand the flow of data
through the completed protocol stack. You are just writing the
Physical layer piece at this time.

Implementation Details
If the writer on a socket sends 40 bytes and the reader is blocked in a read of 40 bytes, the reader may only receive 30 bytes when the read returns. This is due to the byte stream nature of a TCP socket.In order to make this easier, we are going to say that the physical layer always sends 90 byte packets.Your code should stay in a loop reading until it has received 90 bytes. This means YOU will have to pad the data you receive in push to make it 90 bytes, i.e. if you receive 10 bytes of data from main, pad it with 80 bytes of zeros before sending across the socket. The TA code will do the same thing.
We provide a framework for you to test your code with. You can find the template in ~cs460ta/labs/phys_template on the machines in the 460 lab. The code will send different sizes of message and will print out when they are received. The size of the payload will increase by 2 each iteration (i.e. 2 bytes, 4 bytes, 6 bytes, 8 bytes, ...., 90 bytes. You may want to modify the code to send a small subset of these requests until you are sure that your code works.
Run your program several times and debug any problems.If you have any bugs at this level, they will byte [:^)] you later.
For passoff, you will run the binary in ~cs460ta/labs/phys
on one of the 460 lab machines. On another machine you should run
your code and they ought to be able to talk to each other. You may want
to run some additional tests of your own to make sure that things are
working. You should show your source code to the
TA when he passes off your code.
The usage for the binary for this lab, and most of the other
protocol labs, is as follows:
phys <hostname> <port> <-s or -c>
<hostname>
is the name of the machine that your are running the server on
(cs460-1, cs460-2, etc).
<port>
is the port number. Just be sure to pick something over 1000 and that
someone else in the labs won't be using.
<-s or -c>
is to indicate whether you want it to be a server or a client
respectively.
Note that you may need a "./" in front of the binary in order to make
it run depending on your shell settings (I believe most of you will need
to do so). Also be sure to start the server before starting the
client.
The following passoff levels will apply to this lab:
| Passoff Level |
Behavior |
Points |
| Minimal Passoff |
At least one packet is sent and received |
2 Points |
| Buggy |
Passes Most of the tests, but fails
occasionally |
2 Points |
| Perfect behavior |
Passes all tests |
6 Points |