Document
last modified:
Protocols Overview Several data link layer protocol
examples are given in the Tanenbaum text. The network and physical
layer operations used by the data link layer in Tanenbaum have been
implemented in Java using the User Datagram Protocol of the Internet
protocol set. The Java implementation is very similar to that given in the text
on page 202 for C. Essentially, the network and physical layer protocols have
been implemented. Based upon those functions, it is possible to implement data
link protocols 1 through 4 on a single or multiple workstations running Java.
The Java
implementation follows that of the text as closely as reasonably possible,
remembering that Java is object-oriented and the text example is not. The Java
definitions that correspond to that of page 202 follow:
|
public class Protocol {
public static void to_network_layer(String s); public
class Frame {
Frame(int socket); |
Note that
only the functionality needed for Protocols 1-4 has been implemented in the two
following Java classes.
1. Protocol
o packet - A packet is the data load of a frame. Instead of packet
uses the Java String class.
1. public static void to_network_layer(String s); - Use String
rather than packet.
2. public static String from_network_layer( ); - Returns a
String as a function result rather than a packet as a parameter.
2. Frame
1. Frame(int port); - Creates a new Frame given a port number.
2. public String from_physical_layer( ); - Returns the message
data load as a String from the physical layer, and the fields of the frame
object (seq, ack, and info) are initialized.
3. public void to_physical_layer(String remoteAddress, int
remotePort); - Sends a Frame through the physical layer to the host at remoteAddress
and port number remotePort.
4. public int wait_for_event( ); - Wait for an event and return
the event number, one of either frame_arrival, chksum_err, or timeout.
5. public void start_timer(int k); - Start timer number k.
6. public void stop_timer(int k); - Stop timer number k.
1. Verify protocol 3 operation (given below) and implement
protocols 1, 2, and 4 from the text to further your understanding of each. Note
that the Protocol from_network_layer and to_network_layer
functions do not issue prompts in case you're using this protocol
interactively.
2. When running the protocols on one host, the to_physical_layer
parameter for remoteAddress will be "localhost". The sender
and receiver must send to the other's ports.
If the receiver listens for frames to arrive on port 888, the sender must
transmit to port 888. In sender3 of protocol 3, the following
instruction defines the local port that will be used to send and receive
frames:
|
Frame s = new Frame(777); |
The program instruction:
|
s.to_physical_layer("localhost",
888); |
actually
sends the frame s to, in this case on the same host localhost and
the receiver3 port 888.
Note
that protocol 4 is symmetric, having only one program that both sends
and receives. Since two programs cannot share the same port on the same
machine, two versions of protocol 4 are needed when run on one host. Name one protocol4A
and the other protocol4B and use two different ports in the Frame(
port) constructor in each version. Note that this is not necessary when
running on two different host machines, both machines can use the same
ports.
3. Run protocols 1, 2, 4 on two different hosts, sending on one
and receiving on the other. You will need to determine the IP of each machine
by entering arp -a at a DOS window (or by entering ipconfig /all
for W2K) on each which should display the machine's IP in a format similar to Interface:
149.160.29.93, then edit the IP into the to_physical_layer parameter
for remoteAddress of each program. In Protocol 3 below, the
change would be:
|
s.to_physical_layer("149.160.29.93",
888); |
Alternatively
make two separate directories with complete copies of files and change one
protocol copy to use different send and receive ports as was done in protocol
3.
4. Modify the timeout parameter in the Constants.java
file for protocol 4 until timeouts occur.
|
public static final int buffersize
= 13; |
5.
You
may need to insert an:
6. if (event != frame_arrival) System.out.println("timeout");
7.
in
protocol 4 to notify you that a timeout actually occurred.
8. Modify the Constants.java file to vary the size of
the data buffers. The buffersize determines the number of bytes
sent to the physical layer and received from the physical layer. Run for
protocols 1, 2, 4 for a large and small data buffer size. Note that both hosts
should use the same size buffers or truncation will occur.
9. Modify the Constants.java file to vary the number of
frames lost. Run for protocols 1, 2, 4 for a large and small number of
lost frames.
|
public static final int buffersize
= 13; |
1. Cover sheet with your name, date, Homework 2. Please staple
all pages together.
2. Listing of each sender/receiver file for protocol 1, 2, and
4 (protocol 4 needs only one).
3. Observations of running protocols on single or multiple
machines. Discuss differences and give supporting outputs or other evidence.
4. Observations on modifying timeout parameter in file Constants.java
on appropriate protocols. Use at least three different timeouts from
10 ms. to 5000 ms. Discuss differences, if any, witnessed for each protocol
tested and whether the behavior was as expected for each protocol. Give
supporting outputs or other evidence.
5. Observations on modifying buffersize parameters in
file Constants.java and sending a large file for protocols 1, 2, 4. Use
at least three different sizes from 1 to 2000. Discuss differences witnessed
for each and give supporting outputs or other evidence. Note that the testdata
file can be sent by:
o java -cp . sender3 < testdata
6. Observations on modifying lostframes parameter in
file Constants.java and sending a file for protocols 1, 2, 4. Use at
least three different numbers from 0 to 20. Discuss differences witnessed for
each protocol and give supporting outputs or other evidence. Note that the testdata
file can be sent by:
o java -cp . sender3 < testdata
7. The testdata is a large file filled with sequential
digits 0..9 to more easily recognize when a protocol failure occurs.
8. The protocols are designed for two communicating hosts.
Consider whether any (or all) of the protocols could be spoofed by a third
sender. Try one and discuss the results and give supporting outputs or other
evidence. Remember that the ports of all senders and receivers must be unique
on the same machine by changing the following:
Frame s = new Frame(777);
|
Frame s = new Frame(777); |
·
which
defines s on port 777 and r on port 888.
Protocol 3
from Tanenbaum is implemented below as an example using the Java network and
data link definitions. Note that one weakness of all the protocols is that the
network layer is expected to always have data available. Consult the text and
notes for details of Protocol 3.
1. sender3.java
4. Frame.java
7. testdata.txt
The
sender3 program should transmit to the receiver3 program the testdata
file for display to the screen. Note that both programs continue to execute
after the file is finished because of our assumption that there will always
be data available from the network layer. Control C will terminate a Java
program.
del *.class
|
public class Constants { |
|
receiver3.java on host with IP 149.160.27.222 s.to_physical_layer("149.160.27.111",
777); |
sender3.java on host with IP 149.160.27.111 s.to_physical_layer("149.160.27.222",
888); |
Sender3
and Receiver3
- Changeable parameters:
|
public class sender3
extends Protocol {
next_frame_to_send = 0; |
public class receiver3
extends Protocol {
frame_expected = 0; |
The
following four class definitions, Constants, Protocol, Frame, and DataGram,
implement the functionality described by the text. Only Constants will need to
be modified.
Constants.java
- Defines
three constants.
public class Constants { public static final int buffersize = 13; public static final int lostframes = 0; public static final int timeout = 1000;} |
Protocol.java
- Serves
to define events and network functions. When implementing a
protocol, one must inherit Protocol to have access to these definitions, for
example: public class sender3 extends Protocol.
|
public class Protocol {
public static void to_network_layer(String s)
public static String from_network_layer() |
Frame.java
- Frame
is actually the majority of the Data Link layer, providing access to the physical
layer. One key difference between the text and Java implementation is the
requirement that Frame's be created for a port number on the host for
sending and receiving and a time limit for waiting a Frame arrival. Note
that the port can only be in use by one Frame. Another point of
difference is the need to address the Frame to a specific destination host
and port on the destination.
|
public class Frame {
private boolean timer = false;
Frame(int port)
public String from_physical_layer()
int index; |
public void
to_physical_layer(
public int wait_for_event()
public void start_timer(int k)
public void stop_timer(int k) |
DataGram.java
- Used
by Frame to access the physical layer for sending and receiving.
Implemented using User Datagram Protocol. Whenever a datagram containing a
Frame is to be received, a thread is started that waits for its arrival. If a
timer runs out while waiting for arrival, the thread is stopped, terminating the
wait for arrival.
|
// Low-level User Datagram class
to send/receive datagram. import
java.net.*; public
class DataGram {
DataGram(int localPort)
public void send(String remoteAddress, int remotePort, String s) |
public void start_receive(int
timeout) public
String receive() |
Java
requires Win95, NT, W2K, Unix, or other multitasking operating system.
path = %path%;c:\sdkx.y.z\bin (where x.y.z is the
current version of the Java SDK)
javac
sender3.java
to
compile sender3.java source. To compile all Java files enter:
javac
*.java
Note
that since there is a sender and receiver program, both must be executed, each
in a separate DOS window, executing the receiver before the sender (so the
receiver is waiting on the sender). At DOS enter:
java
-cp . sender3
< sender3.java
to
execute sender3 and have it transmit sender3.java .
The
Sun Java documentation is available using a browser when the JDK is installed.
Look at file index.html in the Java docs directory. Note that you
must have installed the documentation.
Document last modified: