exercises e-1
Chapter3: Exercises
Silvia Giordano
ICA, EPFL
exercises e-2
Exercise1
q Suppose client A initiates a Telnet session with server S. AT about the same time, client B also initiates a Telnet session with server S. Provide possible source and destination port number for:a. the segment sent from A to S.b. the segment sent from B to S.c. the segment sent from S to A.d. the segment sent from S to B.e. if A and B are different hosts, is it possible that
the source port number in the segments from A to S is the same as that from B to S?
f. how about if they are the same host?
exercises e-3
Solution of Exercise1source port destination port
numbers numbersa) A -> S 1467 23b) B ->S 1513 23c) S -> A 23 1467d) S -> B 23 1513
e) yes, there is no relationship between port numbers on different hosts.
f) no, a port number identify UNIVOCALLY a process
exercises e-4
Exercise2
1) UDP and TCP use 1’s complement for their checksums. Suppose you have the following three 8-bit words: 01010101, 01100000, 11001100.
a) What is the 1’s complement of the sum of these words?
b) With the 1’s complement scheme, how does the receiver detect errors?
c) Is it possible that a 1-bit error will goundetected? How about a 2-bit error?
exercises e-5
Solution to Exercise21 1 0 0 0 1 0 1
+ 1 1 0 1 0 0 0 1+ 1 0 0 1 0 1 1 0= 1 0 0 1 0 0 1 1
One's complement =01 1 0 11 0 0.b) To detect errors, the receiver adds the four words (the three
original words and the checksum). If the sum contains a zero, the receiver knows there has been an error.
c) All one-bit errors will be detected, but two-bit errors can be undetected (e.g., if the last digit of the first word is converted to a 0 and the last digit of the second word is converted to a 1).
exercises e-6
Exercise3
r Consider the Go-Back-N protocol with a sender window size of 3 and a sequence number range of 1,024. Suppose that at time t, the next in-order packet that the receiver is expecting has a sequence number of k. Assume that the medium does not reorder messages. Answer the following questions:a. What are the possible sets of sequence
numbers inside the sender’s window at time t?b. What are all possible values of the ACK field
in the message currently propagating back to the sender at time t?
exercises e-7
Solution to Exercise3a. Here we have a window size of N=3. Suppose the
receiver has received packet k-1, and has ACKed that and all other preceding packets. If all of these ACK'shave been received by sender, then sender's window is [k, k+N-1]. Suppose next that none of the ACKshave been received at the sender. In this second case, the sender's window contains k-1 and the N packets up to and including k-1. The sender's window is thus [k-N,k-1]. By these arguments, the senders window is of size 3 and begins somewhere in the range [k-3,k].
exercises e-8
Solution to Exercise3b. If the receiver is waiting for packet k, then it has
received (and ACKed) packet k-1 and the N-1 packets before that. If none of those N ACKs have been yet received by the sender, then ACK messages with values of [k-N,k-1] may still be propagating back. Because the sender has sent packets [k-N, k-1], it must be the case that the sender has already received an ACK for k-N-1. Once the receiver has sent an ACK for k-N-1 it will never send an ACK that is less that k-N-1. Thus the range of in- flight ACK values can range from k-4 to k-1.
exercises e-9
Exercise4Implement in Java a Client-Server pair with a
dummy application (that sends non-significant data) that realizes at application layer the GBN scheme.
exercises e-10
Solution to Exercise4: GoBack n
GbnSender
GbnAckmng
Tout Window
GbnRec
exercises e-11
Solution to Exercise4: sender
public class GbnSender {
public static void main(String[] args){
……….Window slidingWindow = new Window(wdim);
DatagramSocket Sout;
Tout tout;
try {
Sout=new DatagramSocket();
InetAddress IPadd;
sliding window
timer
exercises e-12
Solution to Exercise4: sendertry{
IPadd= InetAddress.getByName("localhost");
byte[] sendData = new byte[3];
String Pinfo;
GbnAckmng wmng = new GbnAckmng(Sout, slidingWindow);
wmng.start();
int currpack = 0;
int end = 0;
while ((currpack < npack )&&(end == 0)){
System.out.println(currpack + " versus " + npack);
ack manager on sender socket
transmission not completed
exercises e-13
Solution to Exercise4: sendersynchronized(slidingWindow){
if (slidingWindow.getdim() > 0){
//System.out.println("window is " + slidingWindow.getdim());
currpack++;
slidingWindow.sent(currpack);
tout = new Tout (slidingWindow, currpack, 3000);
tout.start();
Npack = new Integer(currpack);
Pinfo = new String(Npack.toString());
sendData = Pinfo.getBytes();
DatagramPacket Spack = new DatagramPacket(sendData,Pinfo.length(),IPadd,60000);
thread sync mechanism on sliding window
start timeout on currpack
if sliding window not empty transmission is possible
exercises e-14
Solution to Exercise4: sendertry{
Sout.send(Spack);
}
catch (IOException a){
}
//System.out.println("packet " + currpack + " has been sent");
} else {
try {
slidingWindow.wait();
currpack = slidingWindow.next()-1;sliding window is empty: GbnSender waits for either an ack or a timeout
exercises e-15
Solution to Exercise4: senderSystem.out.println("RESTART from " + currpack );
}
catch (InterruptedException e){
}
}
if ((currpack == npack)&&(slidingWindow.next() == npack)){
end = 1;
}
}
}
System.out.println("all packets sent");
}
catch(UnknownHostException a){
}
}
catch (SocketException a){
}
}
}
exercises e-16
Solution to Exercise4: ack manager
public class GbnAckmng extends Thread {
private Window myns;
private int ackpack;
DatagramSocket LSout;
public GbnAckmng (DatagramSocket Sout, Window ws){
myns=ws;
ackpack = 0;
LSout = Sout;
System.out.println("Wmng started");
}
initialize the sliding window and the socket
exercises e-17
Solution to Exercise4: ack manager
public void run() {
while (true){
byte[] recData = new byte[1024];
DatagramPacket Rpack = new DatagramPacket(recData,recData.length);
try {
int lung;
LSout.receive(Rpack);
lung = Rpack.getLength();
String Resp = new String(Rpack.getData(),0,lung);
Integer NewAck = new Integer(Resp);
ackpack = NewAck.intValue();
}
ack manager is in wait for the received acks
ack sequence number
exercises e-18
Solution to Exercise4: ack manager
}
catch (IOException e){
}
synchronized (myns){
if (myns.acked(ackpack)){
System.out.println("Notify Wmng: window is " + myns.getdim());
myns.notify();
}
}
}
}
}
sync on sliding window
restarts the GbnSender
exercises e-19
Solution to Exercise4: Timeoutimport Window;
public class Tout extends Thread {
private int PacketNum;
private long timeout;
private Window mySlidingWindow;
public Tout (Window ws, int Pack, long exttimeout){
mySlidingWindow=ws;
PacketNum=Pack;
timeout=exttimeout;
}
Parameters initialization
exercises e-20
Solution to Exercise4: Timeoutpublic void run() {
System.out.println("Tout started on " + PacketNum);
try {
this.sleep(timeout);
synchronized (mySlidingWindow){
if (mySlidingWindow.next() == PacketNum){
mySlidingWindow.reset(PacketNum);
mySlidingWindow.notify();
}
}
return;}
catch (InterruptedException e){}}
Sync on SlidingWindow
exercises e-21
A B
CD
E F
LAN 2
A B
CD
E F
LAN 2
LAN 3
LAN 1 111.111.111.001
00-00-00-00-00-00
111.111.111.003
11-11-11-11-11-11
111.111.111.002
22-22-22-22-22-22
122.222.222.002
33-33-33-33-33-33
122.222.222.004
66-66-66-66-66-66
122.222.222.003
55-55-55-55-55-55
122.222.222.001
44-44-44-44-44-44
133.333.333.002
88-88-88-88-88-88
133.333.333.001
77-77-77-77-77-77-77
133.333.333.003
99-99-99-99-99-99