程序代写案例-COMP222101
时间:2022-05-18
Module Code: COMP222101
c© UNIVERSITY OF LEEDS
Semester 2 2020/2021
Module Title: Networks
School of Computing
Examination Information
- There are 8 pages to this exam.
- Answer all 3 questions.
- The total number of marks for this examination paper is 60.
- The number in brackets [ ] indicates the marks available for each question or part
question.
- You may lose marks for including extensive discussions that are not relevant to the
question.
- You will not receive any marks, and may lose marks, for simply copying material from
your notes verbatim.
- You are reminded of the need for clear presentation in your answers.
Page 1 of 8 Turn the page over
Module Code: COMP222101
Question 1
(a) State one example of a network for which the 7-layer OSI model may provide a more suitable
description than the 5-layer TCP/IP model.
[1 mark]
(b) How many unique IPv4 addresses are there in the range 129.11.192.0/22?
[1 mark]
(c) Does the address 129.11.195.212 belong to the range 129.11.192.0/22? Explain your
answer.
[2 marks]
(d) Expand the following IPv6 address to its full, 16-byte form.
2001:2f9::ffcc:18:1234
[2 marks]
(e) For each of the following applications, state whether you would use TCP or UDP, and
provide a brief justification in each case.
(i) An email client that connects to a server to upload or download messages.
(ii) An online chess game with one other opponent.
(iii) An online multi-player vehicle racing game.
[6 marks]
(f) Someone is writing a multi-threaded web browser that makes multiple connections to the
same web server. The hope is that by sending and receiving HTTP queries simultane-
ously, all of the data for a web page (text, images, movies etc.) could be downloaded
simultaneously, speeding up the browser. Some key parts of the code are shown below.
1 public class HTTPThread extends Thread {
2 private int numThreads = 10;
3 private int port = 80;
4 private String hostname = ...; // (not shown)
5
6 public void run() {
7 Socket s = new Socket(hostname,port);
8 // ... (remainder not shown)
9 }
Page 2 of 8 Turn the page over
Module Code: COMP222101
10
11 public static void main(String[] args) {
12 for( int i=0; i13 HTTPThread t = new HTTPThread();
14 t.start();
15 }
16 // (see question)
17 }
18 }
(i) Identify the two mistakes in the given code that will stop it from compiling. For each
mistake, state the line number(s) where the problem lies, and briefly explain how you
would rectify the mistake.
[4 marks]
(ii) Why is the port number fixed to be 80 in the code, rather than taking an optional
value set by e.g. a command line argument?
[1 mark]
(iii) Suppose you wanted to add new code at line 16 that required all of the threads to
have finished their tasks before continuing. How would you modify the existing code
to achieve this synchronisation?
[2 marks]
(iv) Someone suggests replacing lines 12 to 15 with an Executor from the Java library
java.util.concurrent. State one potential advantage of this choice.
[1 mark]
[Question 1 Total: 20 marks]
Page 3 of 8 Turn the page over
Module Code: COMP222101
Question 2
Figure 1 gives code for a simple ‘Quote Of The Day’ server that sends a randomly-selected quote
to each client that contacts it. The corresponding client application that communicates with the
server is also provided. Inspect both pieces of code, then answer the following questions.
(a) For each of the following statements, say whether they are true or false, and provide a brief
explanation to justify your decision, giving line numbers from the code where relevant.
(i) The code uses TCP as implemented by java.net.
(ii) The protocol is for the client to send a zero-size message to the server, which returns
a random quote to the same client.
(iii) Both applications use the reserved port number 8787.
(iv) The maximum quote length that the server can send is defined by rSize.
[4 marks]
(b) While the code seems to work correctly when both the server and client applications are
running on the same machine, the client sometimes hangs when the applications are run-
ning on remote hosts. The only modification made to the client code was to initialise
serverAddr with the server’s address in line 8, and this is known to work correctly.
(i) Give the line in the given client code where you think the application hangs.
[1 mark]
(ii) Why do you think this problem occurs?
[2 marks]
(iii) It is suggested that you modify the code to wait for a response from the server for some
period of time, and give an error message if this time is exceeded. Give pseudo-code
for how you would implement this. You do not need to provide working Java code,
but should use the correct class and method names from java.net. Only provide
pseudo-code specific to this new feature.
[4 marks]
(iv) It is further suggested that the client should make multiple attempts to communicate
with the server before giving an error message. Briefly describe how you would achieve
this. Only discuss this new feature in your answer.
[3 marks]
(c) It is now decided to upgrade both the client and server applications to use multi-casting.
(i) Name one real-world application (as opposed to this ‘Quote Of The Day’ example)
that might benefit from using multi-casting.
[1 mark]
(ii) Why did you choose this example?
[1 mark]
Page 4 of 8 Turn the page over
Module Code: COMP222101
(iii) You are asked to alter the client application to use multi-casting. List the key steps
that you would include, in the order they should be performed, using correct names
from java.net wherever possible. Only list steps that relate specifically to multi-
casting.
[3 marks]
(iv) What is the smallest change you could make to the server application to make it work
with the new multi-casting client?
[1 mark]
[Question 2 Total: 20 marks]
Page 5 of 8 Turn the page over
Module Code: COMP222101
Code for the ‘Quote Of The Day’ (QOTD) server application:
1 import java.net .*;
2 import java.io.*;
3
4 public class QOTDServer {
5 private static String [] quotes ={"Quote1","Quote2","Quote3"};
6
7 public static void main(String [] args) throws IOException {
8 DatagramSocket socket = new DatagramSocket (8787);
9
10 while(true) {
11 DatagramPacket rPack=new DatagramPacket(new byte [10] ,10);
12 socket.receive(rPack);
13
14 String quote=quotes [(int)(Math.random ()*quotes.length)];
15 DatagramPacket sPack=new DatagramPacket(quote.getBytes (),
quote.length (),rPack.getAddress (),rPack.getPort ());
16 socket.send(sPack);
17 }
18 }
19 }
Code for the ‘Quote Of The Day’ (QOTD) client application:
1 import java.net .*;
2 import java.io.*;
3
4 public class QOTDClient {
5 private static int rSize = 1000;
6
7 public static void main(String [] args) throws IOException {
8 InetAddress serverAddr = InetAddress.getLocalHost ();
9 DatagramSocket socket = new DatagramSocket ();
10
11 DatagramPacket sPack = new DatagramPacket(new byte[0],0,
serverAddr ,8787);
12 socket.send(sPack);
13
14 DatagramPacket rPack = new DatagramPacket(new byte[rSize],
rSize);
15 socket.receive(rPack);
16
17 if( rPack.getAddress ().equals(serverAddr) )
18 System.out.println(new String(rPack.getData (),"UTF -8"));
19 }
20 }
Figure 1: Code for question 2.
Page 6 of 8 Turn the page over
Module Code: COMP222101
Question 3
(a) To which layer in the protocol stack is ICMP most relevant?
[1 mark]
(b) Messages sent over the internet are typically broken down into packets.
(i) Suggest one advantage of doing this.
[1 mark]
(ii) Now suggest one disadvantage.
[1 mark]
(c) A student is trying to develop their own transport protocol to send data reliably over an
unreliable channel. So far they have implemented rdt send() and rdt receive() func-
tions, where rdt receive() sends an acknowledgment to the sender whenever a packet
is received. When rdt send() receives the acknowledgement it sends the next packet. If
rdt send() does not receive any acknowledgement after a predefined time-out, it resends
the original packet. There are no sequence numbers in the protocol’s header.
(i) If packets can be lost during transmission but are not corrupted, will the student’s
current implementation work? Explain your answer.
[2 marks]
(ii) The student now includes a checksum in the packet header, and rdt receive() sends
a negative acknowledgement to the sender if packet corruption is detected, which then
re-sends the packet. The corrupted packet itself is dropped. The receiver still sends a
positive acknowledgement if the packet was received uncorrupted. If packets cannot
be lost but may be corrupted, will this new scheme work?
[2 marks]
(iii) Irrespective of its reliability, timing tests suggest that the performance of the new
protocol is poor. Why is this? Suggest one modification you would make to improve
performance.
[2 marks]
(d) Consider the network of five nodes u, v, w, x and y and their corresponding link costs shown
in Fig. 2. Determine the optimal routing from node u for this network using Dijkstra’s
algorithm. To help you, the first row of the table of the set of nodes with known least cost
path N ′, the current value of path cost D, and predecessor node along the path p, is as
follows:
Step N ′ D(v), p(v) D(w), p(w) D(x), p(x) D(y), p(y)
0 u 3,u 2,u 5,u ∞
Complete this table as per Dijkstra’s algorithm, then answer the following questions.
(i) What is the step number in the final row of your table?
Page 7 of 8 Turn the page over
Module Code: COMP222101
[1 mark]
(ii) Copy the column N’ from your table into this box, starting from (and including) the
entry u given above.
[4 marks]
(iii) What is the final value in the column D(v), p(v) on your table?
[1 mark]
(iv) What is the final value in the column D(x), p(x) on your table?
[1 mark]
(v) Finally, what is the final value in the column D(y), p(y) on your table?
[1 mark]
u v
w x
y2
2
3
5 2
4
1
Figure 2: Figure for question 3(d).
(e) Give two reasons why Dijkstra’s algorithm is typically only used for small sub-networks.
[2 marks]
(f) What class of algorithm could be considered instead for larger networks?
[1 mark]
[Question 3 Total: 20 marks]
[Grand Total: 60 marks]
Page 8 of 8 End