代做COMP5416/4416 Assignment 2 2024 S2代写Python语言

- 首页 >> Algorithm 算法

COMP5416/4416 Assignment 2 2024 S2

Due date: 27 Oct 2024 at 23:59

There are 7 mandatory tasks (1—7) plus one optional task (8). Each mandatory task is with 15 points and the optional task is with additional 10 points. However, your total mark is capped at

100 points. You need to show your progress for all tasks. Only giving the final result is not acceptable.

Submission instructions. In the “main file submission”, you can only upload your answers in a single pdf file. In the “supplementary file submission”, zip all your codes and captures in one file and upload.  This is one assignment with multiple pieces to submit. Your submission time equals to the submission time of the last piece. Late penalty will be calculated based on this submission time. The submission site is open one week before the due date.

Task 1. Chris, a new graduate student, takes an interview for a position as a wireless network engineer. Here are several interview questions. Please help him answer the questions during the interview.

(1) Wireless and mobile networks utilise two access modes: CSMA/CA and CDMA. Could you discuss the advantages and disadvantages of these two modes? Additionally, why is CDMA used in cellular networks while CSMA/CA is used in WiFi?

(2) In wireless and mobile networks, the data rate typically decreases as you move away from the base station or access point. Could you explain why increased distance results in a lower data rate?

(3) In wireless networks, the link from a mobile terminal to a base station or access point is called the uplink, while the link from the base station/access point to the mobile terminal is called the downlink. Are there any notable differences between the uplink and downlink? Generally, do you think the data rate is higher for the uplink or downlink, and why?

Task 2. Chris is a new graduate student looking for a job as a network administrator. Now he is taking a written interview test. Please help him complete the following task.

The following figure shows a token bucket scheduler. It consists of a bucket which can accommodate 3 tokens and a queue which can accommodate 8 packets. The arrival of packets follows Poisson process with rate a > 0. The arrival of tokens follows Poisson process with rate μ  > 0, which is independent of the arrival of packets. Each packet consumes exactly one token, and the packets are served by the first-in-first-out principle. If there is no token in the bucket: if there are at most 5 packets in the queue, arriving packet will wait at the queue; if there are 6 or 7 packets in the queue, arriving packet will be dropped with a probability of 0.5 (it will wait at the queue with a probability of 0.5); if there are 8 packets in the queue, arriving packet will always be dropped. If there are tokens in the bucket, each arriving packet consumes one token and leaves the system immediately. If the bucket is full, new token arrivals will be dropped. The system reaches the steady state after a sufficiently long time. We assume that a = 1 packet per second and μ  =  1 token per second. 

(1) Is it possible that there are both tokens and packets in the system at the same time? Why or why not.

(2) Let 1, 2, 3, 4, … denote the states where there are 1, 2, 3, 4… packets in the buffer. Let -1, -2, and -3 denote the states where there are 1, 2, and 3 tokens in the bucket respectively. Let 0 denote the state where there is 0 packet and 0 token. To model the system, Chris has created the following state transition diagram.

Is this state transition diagram correct? If yes, give your reason. If no, show how do you revise the diagram so that it becomes correct.

(3) Following (2), calculate the stationary distribution of each state. (If you think the diagram in (2) is correct, calculate the stationary distribution based on that diagram. If you think the diagram in (2) is not correct, calculate the stationary distribution based on your revised diagram.)

(4) In theM/M/1 queue, we must have a < μ. However, in this situation, we have a = μ . Is this allowed? Why or why not?


Task 3. Chris is a network engineer to optimise the network for the university. Please help him complete the task. The following figure shows the network structure. There are two schools of the university, connecting to the public Internet.

Chris has done the following evaluation of the network: Inside each school, the one-way propagation  delay from each host to the school’s gateway is 2ms. The link bandwidth is regarded to be infinity  (sufficient large). The link bandwidth from each school’s gateway to the university’s gateway is 10Mbps, and one-way propagation delay is 2ms. The access link bandwidth from the university’s gateway to the  Internet is 20Mbps, and the one-way propagation delay from the gateway to any server in the public  Internet is 8ms. On average, the requests from each school to view the webpage (of the public Internet)  arrive at the rate of 1000 requests per second and the webpage is 1000 bytes (which fits exactly one  packet). The header size can be ignored. The requests themselves are very small and we assume that  they do not take any bandwidth.

To analyse the delay, Chris models the system as there are three M/M/1 queues in the system: the downlink from the public Internet to the university ’s gateway (Queue  1);  the downlink from the university’s gateway to school A’s gateway (Queue 2); the downlink from the university’s gateway to school B’s gateway (Queue 3). Chris only considers the propagation delay (uplink and downlink) and the waiting time at the three queues (downlink only). For example, in Queue 2, the arrival rate is 1000

packets per second, and the service rate is 8000 bits per packet/10x106 bits per second = 1250 packets per second. The waiting time at the queue can be calculated as 1250 packet per second -1000 packet per second/1 = 0.004 second. The waiting time is calculated by the formula of M/M/1 queue, as μ-λ/1 .

(1) Without cache, what is the average overall delay for each user to derive its requested webpage? (Only one round trip propagation delay and the waiting delays at the queues are considered. All other delays are ignored. Do not consider TCP establishment delay. Please note that the waiting delay at the queue includes both transmission delay and queueing delay, so that the analysis itself is good enough to cover three delays: propagation delay, transmission delay, and queueing delay.)

(2) Now, Chris can install caches at the school’s gateway, so that  10% of the original requests can be served by the schools ’ proxies (proxies A and B). What is the average overall delay for each user to derive its requested webpage? Note that at some queues, the arrival rate a should be multiplied by a factor of 0.9.


(3) Now, Chris can install caches at the university’s gateway, so that 20% of the original requests can be served by the university’s proxy (proxy U). (There are no schools ’ proxies.) What is the average overall delay for each user to derive its requested webpage? Note that at some queues, the arrival rate a should be multiplied by a factor of 0.8.

(4) Chris is not satisfied with the performance of (2) or (3). He thinks that caches can be installed at all gateways (proxies A, B, and U). However, because Chris has limited equipment for storage: a% of the original requests can be served by the schools ’ proxies, and b% of the original requests can be served by the university’s proxy, but 2a%+b%  ≤ 20%. Please help Chris calculate the average overall delay for each user to derive its requested webpage as a function of a and b and find the optimal a and b. (Note, a% and b% are defined with respect to the original requests, do not use (1-a%)(1-b%), but to use (1-a%-b%) to calculate the rest of the requests served by the original Internet servers).


Task 4. Chris is a network engineer developing the handoff algorithm for a wireless service provider. He is instructed to use the RSS with hysteresis approach, i.e., a handover is made whenever Pnew> Pold+PH  and his job is to determine the best PH  value to avoid the ping-pong effect. In this task, please help Chris solve this problem and finalise the report.

First, Chris found that the two base stations are with a distance of 1000 m. Then, from the manual of the company, he found that RSS (in dBm) of the base stations follows the following formula

RSS(dBm) = -30 - 24 x in(10/D) + ε

where D is the distance, in meter, from the base station to the mobile terminal, and E follows normal distribution, with 0 mean and standard deviation 7. Please note that dBm means decibel-milliwatts. The conversion of power P in mW and x in dBm is as follows x  = 10 log10 1mW/P .   Through this definition, x (dBm) = y (dBm) + z (dB) means that when we increase y (dBm) by z (dB), the result is x (dBm).

When we compare Pnew  and Pold+PH, Pnew  and Pold  are in dBm, and PH  is in dB. In the next step, Chris develops the following simulation algorithm.

(0) Fix a PH  value.

(1) Let base station A locate at 0 m and base station B locate at 1000 m.

(2) Repeat the following many rounds (e.g., 10000) and find the average number of handoffs.  (2.1) Generate the RSS values from two base stations every 10 meters, from 10 m to 990 m. (2.2) Use PH  and the two RSS values to determine the number of handoffs made.

(Compare the RSS values every 10 meters from 10 m to 990 m.)

(3) Change PH  value and obtain the average number of handoffs under different PH.

For example, the following figure below shows one round of simulation when PH  = 0. In (2.1), the figure shows the RSS values from two base stations; in (2.2), 11 handoffs are made at the vertical lines because the two RSS curves cross each other. Please also note that because RSS values are random, each round you generate them in (2.1), they are different, and that’s why you need to generate them multiple rounds to find the average. 

Subtask (1). Please help Chris complete the Python simulation and draw the following curve: average number of handoffs vs. PH when PH=0, 1, 2, … , 30 (in dB).


Subtask (2). After drawing the figure: Chris makes the following conclusion.

Higher PH  will always reduce the number of handoffs so that PH   should be designed as large as possible.

Please comment on if this conclusion is correct or not, and give your reason.

In  this  task,  you  need  to  submit  your  Python  code.  You  need  to  submit  your  code  as LastnameFirstnameQ4.py.

5. BER vs SNR. Chris is a network scientist. He aims to plot BER vs SNR curves of several modulation schemes (similar to the one on Page 23 of Week 9 Slides), as the initial step to develop a rate adaptation algorithm.

(1) BPSK. 0 and 1 are transmitted as 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 Gaussian distribution n~N(0, σ2). σ2  is the power of the noise, and thus   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.

(2) 4PAM. Each signal now can represent two bits. We can transmit 00, 01, 11, 10 through

signals –3, –1, 1, and 3 respectively. The mean signal power of is = 5. This is called

4 pulse-amplitude modulation (4PAM). Still, due to the existence of noise, the received signal is –3+n, –1+n,  1+n, or 3+n respectively, where n is the noise term. Still, n follows Gaussian distribution n~N(0, σ2). σ2  is the power of the noise, and thus  is SNR. If the received signal is in (−∞, –2], (–2, 0], (0, 2], and (2, ∞), it is decoded as 00, 01, 11, and 10 respectively. We assume that 00, 01, 11, and 10 are sent with equal probabilities. Compute average BER vs SNR of 4PAM when SNR = [0,5,10,15,20,25] dB. Note that if 00 is decoded as 01, it is regarded as one-bit error; if 00 is decoded as 11, it is regarded as two-bit error. To compute Q function,

you can use Python math.erfc() function. math.erfc() returns result of erfc function, and Q(x) =  erfc  .

(3) Plot the BER vs SNR curves of BPSK and 4PAM. Discuss why improved data rate can cause higher BER.

(4) In 4PAM, signals –3, –1, 1, 3 represent 00, 01, 11, 10 respectively. Why don’t we use signals –3, –1, 1, 3 to represent 00, 01, 10, 11 respectively?

(5) 8PAM. Each signal now can represent three bits. The signals levels are –7, –5, –3, –1, 1, 3, 5, and 7. Could you find a best mapping between [–7, –5, –3, –1, 1, 3, 5, 7] and [000, 001, 010,

011, 100, 101, 110, 111]? Then, can you calculate the BER vs SNR curve of 8PAM when SNR = [0,5,10,15,20,25] dB? [This subtask is optional and offers bonus marks for Task 5; however, the total marks for Task 5 are capped at 15.]

If you use any form. of programming to complete this task, you need to submit your code as LastnameFirstnameQ5.py.

Task 6. Erlang. Chris is asked to establish Erlang B and Erlang C Charts, through Erlang B and Erlang C formulas. The plotted Erlang B or Erlang C Charts should exactly match Page 31 and Page 45 of lecture slides. Please help Chris complete this task.

You will need to use Erlang B and Erlang C formulas to plot the chart. You will need to calculate the probability under different traffic intensities and the number of channels. Please show your plotted charts in the main file. In additional, please submit your Python code as LastnameFirstnameQ6ErlangB.py and LastnameFirstnameQ6ErlangC.py.

Task 7. Chris is a software engineer, and he should build a multicasting server for a chatroom. The chatroom works as follows: Each client will first connect to the server. Then, if the client sends a message to the server, all connected clients will receive the message. The client side is already established by Chris’s colleagues, which is in Q7client.py.

Chris’s task is to build the server based on the client. The server should achieve the following function for multiple clients. (1) It accepts connection from clients. (2) It asks for a name for each connected client. (3) When a client types and sends a message, all clients will receive the message.  The  message  format  is  as  follows:  [timestamp]  name:  message.  The  following screenshot shows 3 clients are connected to the server and each of them sends a message.

(1) Write the code for the server. (Hint: your server should support multiple clients at the same time, so that you need to establish multiple threads for each new client.)

(2) Run your server and at least three clients in your own computer and test if they can work correctly. In this step, the server is run on your local machine so that the server’s IP address should be 127.0.0.1. Also, the server socket should bind with port number 34000.

(3) After (2), use one of the clients to send your own SID. Use Wireshark to capture what packets are sent from this client to the server and what packets are sent from the server to all clients. Use screenshots to show that all clients receive the message.

You   need    to   submit    your   server    code    in   Python    3.   You    should    name   it    as LastnameFirstnameQ7Server.py. You need to submit your Wireshark trace. You should name it as LastnameFirstnameQ7Capture.pcapng

We will  test  your  server  code  by  the  following  approach.  We  will  run  three  clients  of Q7client.py (without any change, i.e., with 127.0.0.1 and 34000) and your server code (without any change) in one computer. You will get significant penalty if your submitted code does not work (e.g., we need to modify or fix your code).

Task 8. (Bonus 10 marks.) If you want to complete the problem, please merge your solution altogether with other tasks in the “main file submission”.

Chris is a PhD student in a University in North America, and he must pass the qualification exam in the first year. The following question shows a sample question and please help him solve it.

N users are sharing a wireless channel in a TDMA mode. Each user will get  portion oftimeslots. The N  users experience different noise levels n = (n1, n2, … , nN). The base station will allocate power of transmitted signals to different users, and the total power is limited to 1. If the power allocated to user

i is xi , according to Shannon Theorem, user i will experience a data rate of  log2  . We want

to study how to allocate the power to different users to maximize sum data rates. Therefore, we can formulate the optimization problem as follows

(1) Solve the above problem. Hint: You need to use KKT condition and find the optimal solution accordingly.

(2) Let N = 9 and user i’s noise is (1 + α i)4/1 , where α i  is the i-th digit of your student number. For example, if your  student number is 460123456, then n = (1.4953,  1.6266,  1.0000,  1.1892,  1.3161, 1.4142, 1.4953, 1.5651, 1.6266). Use your own student number and calculate the numerical optimal solution. You need to get the optimal xi  values for i = 1,2, … , 9 , and the optimal value of the objective function.





站长地图