1
COMP 5416 Assignment 2
Due: 6/November/2021 23:59
Question 1 (TCP, 20%). In the following network, node A transmits packets that pass through B, C, and D, and arrive at the
destination E. The bit rate of all links is R = 1 Mbit/sec. The maximum packet size in the network is 500 Bytes. Ignore the
header size. The one-way propagation delay on each link is 4 msec.
How long does it take to transmit 100 + s packets if TCP Reno is used, where s is the last two digits of your student number.
At the beginning, ssthresh is 8 segment size (4000 bytes). B, C, and D use Store-and-Forward. No packet is lost. There is
no bit-error in transmission. The size of ACK packets is negligible. The size of TCP header is negligible.
! ” # $ %
2
Question 2 (Token Bucket Simulation, 20%). In this task, you need to simulate and analyze a token bucket. You can reuse some
the codes in Week 6 Lab. You Python code must be submitted as supplementary material. Only Python 3 is allowed.
The token bucket scheduler consists of a bucket which can accommodate x tokens and a queue which can accommodate infinite
packets. The arrival of packets follows an independent Poisson process with rate λ > 0 unit/second. The arrival of tokens follows
a deterministic process. That it, the inter-arrival time is a constant, i.e., 1
µ
unit/second. We assume that λ = 1 unit/second, and
µ = 1.25 unit/second.
Let x = 3 + floor(s/2), where s is the last digit of your student number. For example, if your student number is 490012345,
then s = 5 and x = 5.
Let 1, 2, 3, 4, . . . denote the states where there are 1, 2, 3, 4, . . . packets in the buffer. Let −1,−2, . . . ,−x denote the states where
there are 1, 2, . . . , x tokens in the bucket. Let 0 denote the state where there are 0 packet and 0 token.
(1) By simulation, find out the unconditional stationary distribution of the system states −x,−x+ 1, . . . , 0, 1, 2, . . ..
(2) By simulation, find out the conditional distribution of the the system states when a packet arrives.
(3) By simulation, find out the conditional distribution of the the system states when a token arrives.
(4) By simulation, find out the mean time that a packet waits in the buffer.
(5) Find out the probability that a token is dropped.
3
Question 3 (Multi-thread Server: Implementation, 20%). You are given the complete code for the client in Lab in Week 8. Your
task is to write the TCP server. The client code is in client.py. You must not modify this code. (However, you are allowed
to change ServerName and ServerPort). Only Python 3 is allowed.
Different from the server in the lab, the new server must be able to serve multiple clients simultaneously. Please note that the
server code in Week 8 can only accept one client! In order to serve multiple clients simultaneously. The server should run multiple
threads. The server will establish a new connection socket to communicate with one new client, and each new connection socket
will be managed by a new thread. You should self-study the following function: _thread.start_new_thread().
The following figure shows an example of server when two clients are sending images at the same time. The two connections
are closed in the end, demonstrating that there are two concurrent transmissions before the first “Connection closed”.
You also need to capture the concurrent data transmission by Wireshark. In the example in the next page, we can see that the
two clients are running at 192.168.0.3, with port numbers 60458 and 60462. The server is running at 192.168.0.4, with port
number 12011. The throughputs of the two connections are both positive at around the 4th second.
Tasks and submissions:
(1) Build up a multi-thread server which can serve multiple clients at the same time. Submit your server-side Python code.
Submit your server code as Lastname_Firstname_Server.py. We will use the client in Week 8 to test against your server.
(2) Test your server with three clients sending images at the same time. Capture the packets by Wireshark at the server side.
You are allowed to run the server and clients in one computer using localhost. Submit your Wireshark capture. Your capture
file must be smaller than 10MB. Your capture will be ignored and will not be marked if it is greater than 10MB. Submit your
capture as Lastname_Firstname_Capture.pcapng (or .pcap).
(3) In the main submission file, based on your capture in (2), plot the throughput vs. time of the three connections (similar to
the figures in the next page). Show that they are operated in parallel. In the main file, you also need to give the three clients’
IP addresses, clients’ port numbers, server’s IP address, and server’s port number.
4
You overall mark will be zero if you do not submit code in (1), no matter if you submit (2) or (3).
You submission in (2) and (3) will be ignored and will not be marked if your submission in (1) does not work.
You overall mark will be zero if your Wireshark capture in (2) does not match the throughput plots in (3).
5
Question 4 (BER vs SNR with different modulation schemes, 20%). We aim to plot BER vs SNR curves of different modulation
schemes in this question.
(1) BPSK. In wireless communication, we can transmit 0 and 1 through signals −1 and 1 respectively. Both −1 and 1 signals
have power of 1, so that the mean signal power is 1. This is called Binary Phase Shift Keying (BPSK). Due to the existence of
noise, the received signal is −1+n or 1+n respectively, where n is the noise term. n follows normal distribution n ∼ N(0, σ2).
σ2 is the power of the noise, and thus 1
σ2
is SNR. If the received signal is ≥ 0, it is decoded as 1; if the received signal is < 0,
it is decoded as 0. We assume that 0 and 1 are sent with equal probabilities. Compute average BER vs SNR of BPSK when
SNR = [0,5,10,15,20,25] dB. Hint: What is dB?
(2) 4QAM. Now we consider another modulation scheme, where we can use two orthogonal signals (x, y) to represent 2 bits. (x
is usually carried by a cosine signal, and y is usually carried by a sine signal.) We can transmit 00, 01, 11, and 10 through signals
(−1,−1), (−1, 1), (1, 1), and (1,−1) respectively. The signal power is 2. This is called 4 quadrature amplitude modulation
(4QAM). Still, due to the existence of noise, the received signal (r1, r2) is (−1+n1,−1+n2), (−1+n1, 1+n2), (1+n1, 1+n2),
and (1 + n1,−1 + n2) respectively, where (n1, n2) is the noise term. n1 and n2 are independent random variables with normal
distribution, with mean 0 and variance σ2. The power of the noise calculated as E(n21 + n
2
2). The received signal is decoded as
• 00, if r1 < 0 and r2 < 0;
• 01, if r1 < 0 and r2 ≥ 0;
• 11, if r1 ≥ 0 and r2 ≥ 0;
• 10, if r1 ≥ 0 and r2 < 0;
where the regions r1 < 0 and r2 < 0; r1 < 0 and r2 ≥ 0; r1 ≥ 0 and r2 ≥ 0; and r1 ≥ 0 and r2 < 0 are called decision regions
(see the figure below).
Compute average BER vs SNR of 4QAM when SNR =[0,5,10,15,20,25] dB. Still, we assume that bits 0 and 1 are sent with
equal probabilities. You can make reasonable approximations to calculate the probabilities using Q function or erfc function
through computer. It is not necessary to calculate double integral.
11
00
01
10
x
y
(3) 16QAM. Now we consider an even more complicated modulation scheme. We use two orthogonal signals (x, y) to represent
4 bits. x and y can be −3, −1, 1, or 3, and the represented four bits are shown in the figure below. For example, (−1,−1)
represents 0101. Please note that through this arrangement, there is only one bit difference between two neighbors, which will
reduce bit error rate. Still, the noise is (n1, n2). n1 and n2 are independent random variables with normal distribution, with mean
0 and variance σ2. The power of the noise is calculated as E(n21 +n
2
2). The decision regions are shown in the figure below. For
example, for the received signal (r1, r2), if −2 ≤ r1 < 0 and −2 ≤ r2 < 0, it is decoded as 0101. The average signal power is
(32+32)+(32+12)+(12+32)+(12+12)
4
= 10.
6
y
x
0001
0011
0010
0000
0101
0111
0110
0100
1101
1111
1110
1100
1001
1011
1010
1000
-1-3 1 3
1
3
-1
-3
Compute average BER vs SNR of 16QAM when SNR =[0,5,10,15,20,25] dB. Still, we assume that bits 0 and 1 are sent with
equal probabilities. You can make reasonable approximations to calculate the probabilities using Q function or erfc function
through computer. It is not necessary to calculate double integral.
(4) Plot the BER vs SNR curves of BPSK, 4QAM, and 16QAM. You should derive a figure like Page 53 in the slides of Week
8. Discuss why improved data rate can cause higher BER.
7
Question 5 (Cellular network with guard channel, 20%). Consider one cell in a cellular network. There are 60 available channels
and each channel can be used by exactly one user. New user arrivals follow an independent Poisson Process with arrival rate λn
and handoff user arrivals follow an independent Poisson Process with arrival rate λh. Both new and handoff users stay active for
a random duration, following exponential distribution with mean 1
µ
. The cell reserves X channels for handoff user arrivals. As
discussed in the class, new arrivals will be blocked if 60−X or more channels are occupied. Handoff arrivals will be dropped
if 60 channels are occupied. We assume that λn = 2400 units/hour, λh = 600 units/hour, and
1
µ
= 1 minute.
(1) Let X = 5. Compute the probability that a new arrival is blocked. Compute the probability that a handoff arrival is dropped.
(2) If a new arrival is blocked, a $0.01 loss will be incurred; If a handoff arrival is dropped, a $0.1 loss will be incurred. Find
the optimal X so that the overall loss is minimised.
8
Submission Instructions: You should submit one main file and several supplementary files. You should include your answers
to Q1–Q5 and explanations of your answers in the main file. You should submit your main file at “main file submission”. The
main file is in the format of pdf. For Q2, you must submit your simulator at “Q2 code submission”. For Q3, you must submit
your Python code at “Q3 code submission” and Wireshark capture at “Q3 capture submission”. Your code and capture will be
examined against your answers in the main file. Penalty would be incurred if your code/capture does not match your answer
in the main file. For Q4/Q5, you may upload Python code to calculate the result in “Q4/Q5 calculation”. Please note that,
files uploaded in Q4/Q5 will be marked as intermediate steps. Wrong answers in Q4/Q5 without file uploads will incur heavier
penalties.
File upload File format Must upload?
main file submission pdf Yes
Q2 code submission Python 3 code Yes
Q3 code submission Python 3 code Yes
Q3 capture submission Wireshark capture Yes
Q4 calculation Python 3 code No
Q5 calculation Python 3 code No
TABLE I
FILE UPLOAD
All your submissions will be checked by plagiarism examination tools.
This is one assignment with multiple pieces to submit. Your submission time is equal to the submission time of the last piece.
Submission instruction of Q6 (bonus question) will be released when Q6 is available in Week 12.