Chapter3: Exercises

advertisement
Chapter3: Exercises
Silvia Giordano
ICA, EPFL
exercises
e-1
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-2
Solution of Exercise1
source port
numbers
a) A -> S
1467
b) B ->S
1513
c) S -> A
23
d) S -> B
23
destination port
numbers
23
23
1467
1513
e) yes, there is no relationship between port
numbers on different hosts.
f) no, a port number identify UNIVOCALLY a
process
exercises
e-3
Exercise2
1) UDP and TCP use 1’s complement for their
checksums. Suppose you have the following three 8bit 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 go
undetected? How about a 2-bit error?
exercises
e-4
Solution to Exercise2
11000101
+11010001
+10010110
=10010011
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-5
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-6
Solution to Exercise3
a.
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's
have been received by sender, then sender's window
is [k, k+N-1]. Suppose next that none of the ACKs
have 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-7
Solution to Exercise3
b. 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-8
Exercise4
Implement 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-9
Solution to Exercise4: GoBack n
Tout
Window
GbnSender
GbnRec
GbnAckmng
exercises
e-10
Solution to Exercise4: sender
public class GbnSender {
public static void main(String[] args){
……….
sliding window
timer
Window slidingWindow = new Window(wdim);
DatagramSocket Sout;
Tout tout;
try {
Sout=new DatagramSocket();
InetAddress IPadd;
exercises
e-11
Solution to Exercise4: sender
try{
IPadd= InetAddress.getByName("localhost");
byte[] sendData = new byte[3];
String Pinfo;
ack manager on
sender socket
GbnAckmng wmng = new GbnAckmng(Sout,
slidingWindow);
wmng.start();
int currpack = 0;
int end = 0;
while ((currpack <
transmission
not completed
npack )&&(end == 0)){
System.out.println(currpack + "
versus " + npack);
exercises
e-12
Solution to Exercise4: sender
synchronized(slidingWindow){
thread sync
if (slidingWindow.getdim() > 0){
mechanism on
//System.out.println("window is
sliding window
" + slidingWindow.getdim());
if sliding window not empty
transmission is possible
currpack++;
slidingWindow.sent(currpack);
tout =
start timeout
on currpack
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); exercises
e-13
Solution to Exercise4: sender
try{
Sout.send(Spack);
}
catch (IOException a){
}
//System.out.println("packet " +
currpack + " has been sent");
} else {
try {
sliding window
is empty:
GbnSender
waits for
either an ack
or a timeout
slidingWindow.wait();
currpack = slidingWindow.next()-1;
exercises
e-14
Solution to Exercise4: sender
System.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-15
Solution to Exercise4: ack
manager
public class GbnAckmng extends Thread {
private Window myns;
private int ackpack;
DatagramSocket LSout;
public GbnAckmng (DatagramSocket Sout, Window ws){
initialize the
sliding window
and the socket
myns=ws;
ackpack = 0;
LSout = Sout;
System.out.println("Wmng started");
}
exercises
e-16
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);
ack manager is
lung = Rpack.getLength();
in wait for the
received acks
String Resp = new
String(Rpack.getData(),0,lung);
Integer NewAck = new Integer(Resp);
ack sequence number
}
ackpack = NewAck.intValue();
exercises
e-17
Solution to Exercise4: ack
manager
}
catch (IOException e){
}
sync on sliding
window
synchronized (myns){
if (myns.acked(ackpack)){
System.out.println("Notify Wmng:
window is " + myns.getdim());
restarts the
}
GbnSender
myns.notify();
}
}
}
}
exercises
e-18
Solution to Exercise4: Timeout
import Window;
public class Tout extends Thread {
private int PacketNum;
private long timeout;
private Window mySlidingWindow;
public Tout (Window ws, int Pack, long exttimeout){
Parameters
initialization
mySlidingWindow=ws;
PacketNum=Pack;
timeout=exttimeout;
}
exercises
e-19
Solution to Exercise4: Timeout
public void run() {
System.out.println("Tout started on "
+ PacketNum);
try {
this.sleep(timeout);
Sync on
SlidingWindow
PacketNum){
synchronized (mySlidingWindow){
if (mySlidingWindow.next() ==
mySlidingWindow.reset(PacketNum);
mySlidingWindow.notify();
}
}
return;}
catch (InterruptedException e){}}
exercises
e-20
A
LAN 1
B
111.111.111.001
111.111.111.003
00-00-00-00-00-00
11-11-11-11-11-11
111.111.111.002
22-22-22-22-22-22
122.222.222.004
122.222.222.002
D
66-66-66-66-66-66
C
33-33-33-33-33-33
122.222.222.001
44-44-44-44-44-44
LAN 2
122.222.222.003
55-55-55-55-55-55
LAN 3
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
E
F
99-99-99-99-99-99
exercises
e-21
Download