You are on page 1of 55

University of Cape Town

Department of Computer Science

CSC3002F Class Test 1


March 2018
___________________________________________________________________
Answer all questions

Marks: 35 • Approximate marks per question are shown


in brackets

Time: 45 minutes • The use of calculators is permitted


Question 1 [15]

(i) What advantage does a circuit-switched network have over a packet-switched


network? [1]
A circuit-switched network can provide QoS guarantees, e.g a certain minimum
amount of end-to-end bandwidth for the duration of a call. Most packet-switched
networks (including the Internet) cannot make any end-to-end guarantees for
bandwidth.
______________________________________________________________

(ii) What is meant by a handshaking protocol? [1]


A protocol uses handshaking if the two communicating entities first exchange
control packets before sending data to each other. (TCP uses handshaking at the
transport layer whereas HTTP - at the application layer - does not.)

______________________________________________________________

(iii) What is the difference between routing and forwarding? [1]

Forwarding is about moving a packet from a router’s input port to the appropriate
output port. Routing is about determining the end-to-routes between sources and
destinations.

______________________________________________________________

(iv) Is it possible for an application to enjoy reliable data transfer even when the
application runs over UDP? If so, how? [2]
Yes. The application developer can put reliable data transfer into the application
layer protocol. This would require the sending/receiving applications to manage
acknowledgements, sequencings, and, where necessary, retransmissions.
______________________________________________________________

(v) In a reliable data transfer protocol, what would be the use for: [2]
a) Sequence numbers
b) Timers
_
Sequence numbers are required for a receiver to find out whether an arriving
packet contains new data or is a retransmission.

Timers are used for handling losses in the channel. If the ACK for a transmitted
packet is not received within the duration of the timer for the packet, the packet
(or its ACK or NACK) is assumed to have been lost. Hence, the packet is
retransmitted.

_____________________________________________________________

(vi) What are the five layers in the Internet protocol stack? Mention one principal
responsibility of each of these layers. [5]
__________________________________________________________
The five layers in the Internet protocol stack are – from top to bottom – the
application layer, the transport layer, the network layer, the link layer, and
the physical layer.
Application layer: network applications and their application-layer protocols reside
here; messages are exchanged between source and destination applications that
reside on end systems

Transport layer transports application-layer messages (segment) between application


endpoints

Network layer: responsible for moving network-layer packets known as datagrams


from one host to another (routes a datagram through a series of routers between the
source and destination)

Link layer: delivers frames between physically adjacent nodes along the route (ie
move entire frames from one network element to an adjacent network element)
Physical layer: transform individual bits within the frame into physical signal, and
move it from one node to the next
___________________________________________________________

(vii)

At which layers in the Internet protocol stack does each of the following process?
Justify your answer. [3]

a) Router
b) Switch
c) End-host

Routers process network, link and physical layers (from physical signal, to IP
forwarding, ie. layers 1 through 3). Link layer switches process link and
physical layers (physical signal up to mac addresses, ie layers 1
through2). Hosts process all five layers (host takes application messages,
encapsulate/decapsulate all layers up to physical signal).
___________________________________________________________
Question 2 [13]

Suppose users share a 2 Mbps link. Also suppose each user


transmits continuously at 1 Mbps when transmitting, but each user
transmits only 20 percent of the time.

(i) When circuit switching is used, how many users can be supported? [1]
2 users can be supported because each user requires half of the link bandwidth.
______________________________________________________________

(ii) Suppose packet switching is used: [2]


a) Why will there be essentially no queuing delay before the link if two or fewer
users transmit at the same time?
Since each user requires 1Mbps when transmitting, if two or fewer users transmit
simultaneously, a maximum of 2Mbps will be required. Since the available
bandwidth of the shared link is 2Mbps, there will be no queuing delay before
the link.
______________________________________________________________

b) Why will there be a queuing delay if three users transmit at the same time?
if three users transmit simultaneously, the bandwidth required will be 3Mbps
which is more than the available bandwidth of the shared link. In this case,
there will be queuing delay.
______________________________________________________________

(i) Consider sending a packet from a source host to a destination host over a fixed
route. List the delay components in the end-to-end delay. [2]
The delay components are 1)processing delays, 2)transmission delays,
3)propagation delays, and 4)queuing delays.
______________________________________________________________
(ii) Suppose Host A sends two TCP segments back to back to Host B over a TCP
connection. The first segment has sequence number 90; the second has
sequence number 110. [2]

a) How much data is in the first segment?


20 bytes
______________________________________________________________

b) Suppose that the first segment is lost but the second segment arrives at B. In
the acknowledgment that Host B sends to Host A, what will be the
acknowledgment number?
Ack number = 90
______________________________________________________________

(iii) Consider a packet of length L which begins at end system A and travels over
three links to a destination end system. These three links are connected by two
packet switches. Let di, si, and Ri denote the length, propagation speed, and the
transmission rate of link i, for i = 1, 2, 3. The packet switch delays each packet by
dproc. In terms of di, si, Ri, (i = 1,2,3), and L, what is the total end-to-end delay for
the packet? [2]

The first end system requires L/R 1 to transmit the packet onto the first link; the
packet propagates over the first link in d 1/s1; the packet switch adds a processing
delay of dproc; after receiving the entire packet, the packet switch connecting the
first and the second link requires L/R 2 to transmit the packet onto the second link;
the packet propagates over the second link in d 2/s2. Similarly, we can find the
delay caused by the second switch and the third link: L/R 3, dproc, and d3/s3.
Adding these five delays gives
dend-end = L/R1 + L/R2 + L/R3 + d1/s1 + d2/s2 + d3/s3+ dproc+ dproc

______________________________________________________________

(iv) Suppose that a Web server runs in Host C on port 80. Suppose this Web server
uses persistent connections, and is currently receiving requests from two different
Hosts, A and B. Explain how if and how the requests from the two connections
can be distinguished at Host C. [4]

For each persistent connection, the Web server creates a separate “connection
socket”. Each connection socket is identified with a four-tuple: (source IP
address, source port number, destination IP address, destination port number).
When host C receives and IP datagram, it examines these four fields in the
datagram/segment to determine to which socket it should pass the payload of the
TCP segment. Thus, the requests from A and B pass through different sockets.
The identifier for both of these sockets has 80 for the destination port; however,
the identifiers for these sockets have different values for source IP addresses.
______________________________________________________________

Question 3 [7]

A datagram with destination address 192.16.24.5 arrives at a router with the


following forwarding table.

Address range Output port

11000000 00010000 ******** ******** 0

11000000 00010000 0001**** ******** 1

11000000 00010000 00011*** ******** 2

else 3

(i) Which output port will the router forward the datagram to? Describe how you
arrived at the answer. [3]

First, convert 192.16.24.5 to binary:


11000000 00010000 00011000 00000101
Then look for the longest prefx matching, which is the underlined
part in the IP address above. Thus, output port: 2

______________________________________________________________

(ii) Assume you are in the Senior lab and you request the page www.ngo.org.za, in
your browser and there is no Web cache server. Describe or draw how DNS does
name resolution, when it does a recursive query. [4]
This diagram and some accompanying explanation of recursive query
______________________________________________________________
______________________________________________________________
______________________________________________________________
University of Cape Town
Department of Computer Science

CSC3002/CSC3023 Class Test 2 Memo


May 2018
___________________________________________________________________
CSC3002 students answer section1 and 2 (all questions).
CSC3023 students answer section 2 (questions 3-7) only.

Marks: 40 • Approximate marks per question are shown


in brackets

Time: 40 minutes • The use of calculators is permitted

Section 1: Networks
Question 1 [5]

Consider the network below where two subnets are linked through a
router.

a) Give the sequence of source and destination MAC addresses pairs in the
frame as the datagram is encapsulated/de-capsulated between:
a. A and B [1]
b. A and C [2]
(a) 74-29-9C-E8-FF-55 to CC-49-DE-D0-AB-7D
(b) 74-29-9C-E8-FF-55 to EC-E9-00-17-BB-4B; 1A-23F9-CD-06-9B to 88-B2-2F-54-
1A-0F

(ii) Describe the protocol and process that allows a sending host to determine the
MAC address for a destination host. [2]
An ARP (address resolution protocol) module in the sending host takes an IP
address on the same LAN as input, and returns the corresponding MAC
address. The sender constructs a special packet called an ARP packet to query
all the other hosts and routers on the subnet to determine the MAC address
corresponding to the IP address that is being resolved. Each of these ARP
modules checks to see if its IP address matches the IP address specified in the
ARP packet. The one with a match sends back to the querying host a response
ARP packet with the desired mapping. Hosts and routers maintain ARP tables
in their memory, containing mappings of IP addresses to MAC addresses

Question 2 [5]

Consider a router that interconnects three subnets: Subnet1,


Subnet2, and Subnet3. All of the interfaces in each of these three
subnets are required to be under the prefix 223.1.17/24. Subnet1 is
required to support at least 60 interfaces, Subnet2 is to support at
least 90 interfaces, and Subnet3 is to support at least 12 interfaces.

(i) Provide three network addresses (of the form a.b.c.d/x) that conservatively satisfy
these constraints. [3]

223.1.17.0/26
223.1.17.128/25
223.1.17.192/28

(ii) What is the 32-bit binary equivalent of the IP address 223.1.3.27/28? [2]
11011111 00000001 00000011 00010000 (or 11011111 00000001 00000011 0001)

Section 2: Operating Systems

Question 3 [10]

(i) What is the difference between a system call and a system program? [2]
System call provides an interface to the services made available by the OS [1]. System
programs provide an environment for program development and execution. [1]

(ii) What is the difference between a program and a process? How are programs
and processes related? [2]
Program is passive entity [1/2], process is active [1/2]. Program becomes a process
when executable file loaded into memory [1/2]. One program can be several processes
[1/2]
(iii) What is the difference between a process being in a new state, and being in a
ready state? Why is it necessary to draw a distinction between states in a new
and a ready state? [2]
new – Process has been created. That's it. ready – Process is placed in the ready queue
by the scheduler. [1] Why – new process not yet in line for execution, ready process is.
[1]

(iv) What is a context switch? [2]


The task of switching the CPU from one process to another [1] – performing a state save
of one process and a state restore of the other. [1] Context of a process is stored in the
Process Control Block.

(v) Explain what an orphan process is and how to deal with it. [2]
A process that has terminated (called exit()) but whose parent did not invoke wait() when it
terminated. [1] The initial process is then assigned as the parent of this orphan (invokes
wait() periodically). [1]

Question 4 [4]

Suppose that the following processes arrive for execution at the times
indicated. Each process will run for the amount of time listed. In
answering the question, use non-preemptive scheduling.

Process Arrival Time Burst Time


P1 0 8
P2 1 4
P3 2 1

(i) Suppose that the CPU is left idle for the first two time units. Give the order in
which the processes will be executed, and calculate the average turnaround
time (not waiting time) for these processes with the SJF (shortest-job-first)
scheduling algorithm. Show your calculations. [4]
P3 is executed first. Then P2, then P1 [1/2 mark].
Turnaround times:
P3: 3 – 2 = 1 [1 mark]
P2: 3 + 4 – 1 = 6 [1 mark]
P3: 7 + 8 – 0 = 15 [1 mark]
Average is (1 + 6 + 15)/3 = 7.333 [1/2 mark]
Question 5 [6]

For real-time SPU scheduling, consider the concurrent execution of


two processes P1 and P2, using earliest-deadline-first (EDF)
scheduling, where:

- P1 has a period of p1 = 50, a deadline of d1 = 45, and a CPU burst of t1 =20;


- P2 has a period of p2 = 80, a deadline of d2 = 80, and a CPU burst of t2 = 35.

(i) Redraw the time chart below in your answer book. On this redrawn time chart, do
the following: [6]

a) For each of the time points shown, if it is a decision point for the scheduler,
draw a downward arrow pointing to it. For example, point 0 is a decision point
because the scheduler needs to decide at point 0 which of P1 or P2 should
get access to the CPU, so there is a downward arrow pointing to it.

b) In each time block, indicate which process will be allocated to the CPU for that
block. For example, P1 is in the first time block because the scheduler will
allocate it to the CPU for that block.
Question 6 [5]

Suppose we have two processes, say P1 and P2, with P1 containing just the
instruction counter++; and P2 containing just the instruction
counter—;

Suppose that counter++ is implemented in P1 as:

register1 = counter; register1 = register1 + 1; counter =


register1

Suppose that counter-- is implemented in P2 as:

register2 = counter; register2 = register2 - 1; counter =


register2

(i) Suppose further that counter has the value 5 before the execution of P1 and P2.
Show by example that the concurrent execution of P1 and P2 can lead to a race
condition in which counter has the value 6 after the execution of both P1 and P2.
[5]
Consider this execution interleaving:
S0: P2 execute register2 = counter {register2 = 5}
S1: P2 execute register2 = register2 - 1 {register2 = 4}
S2: P1 execute register1 = counter {register1 = 5}
S3: P1 execute register1 = register1 + 1 {register1 = 6}
S4: P2 execute counter = register2 {counter = 4}
S5: P1 execute counter = register1 {counter = 6}
(1 mark for each from S1 - so one extra mark). Other versions are possible as well

Question 7 [5]

Consider the version of Peterson’s solution to the Critical Section


problem for three processes 0, 1 and 2 given below.
Algorithm for process i (where i = 0,1,2)

do {

flag[i] = true;

j = (i + 1) % 3;

turn = j;

while (flag[j] && turn == j);

critical section

flag[i] = false;

remainder section

} while (true);

(ii) Does this version satisfy mutual exclusion? If so, explain why. If not, explain why
not. [5]

Mutual exclusion: Does not satisfy it. [1 mark] Suppose we have the following sequence:
Process 0 sets turn to 1 [1 mark]. Process 1 checks the while condition [1 mark].

Process 2 checks the while condition [1 mark]. The condition is false for both process 1
and 2, so both will access their critical sections. [1 mark]. Other explanations are possible
as well.
Networks Section

Question 1 [4 marks]
A. Describe in 1-2 sentences the difference(s) between routing and switching. [1]
B. Describe the information necessary for forwarding that is added to data units at each of
the following layers of the TCP/IP stack:
i. Transport Layer [1]
ii. Network Layer [1]
iii. Link Layer [1]

A. Switching involves moving packets between devices on the same network; a switch
determines where a packet should be sent by examining the MAC address within the
packet. Routing/forwarding involves moving packets between different networks; routers
compute the shortest path and build forwarding tables to forward packets enroute to the
destination.
B.
i. Transport Layer: source and destination port numbers are added; these used for
identification of source/destination applications, and de-multiplexing of traffic at
destination host.
ii. Network Layer: source and destination IP addresses are added, used for
identification of source/destination networks and hosts.
iii. Link Layer: source/destination MAC addresses are added, for identification of
next hop interfaces.

Question 2 [4 marks]
True or False:
i. The size of the TCP rwnd never changes throughout the duration of the
connection. [1]
ii. Suppose Host A is sending Host B a large file over a TCP connection. The
number of unacknowledged bytes that A sends cannot exceed the size of the
receive buffer.
[1]
iii. Suppose that the last SampleRTT in a TCP connection is equal to 200 ms. The
current value of TimeoutInterval for the connection must also be set to 200 ms.
[1]
iv. Suppose Host A sends one segment with sequence number 38 and 4 bytes of
data over a TCP connection to Host B. In this same segment the
acknowledgment number is necessarily 42. [1]

i) False, ii) True, iii) False, iv) False

Question 3 [9 marks]
A. The internet uses both IPv4 and IPv6. How is the ‘backward compatibility’ with IPv4
handled? [1]
B. Router R routes has specified a subnet mask of 32.0.0.0/3 on port 1, yet a packet with IP
destination address is routed out to output port 2. Based on this information alone, what
precisely can be said about port 2’s subnet mask? [2]
C. You are a network administrator and have to manage the network below. There are four
subnets and two routers, R1 and R2. Subnets A-D each contain at most 31 hosts.
Assign network addresses, including the subnet masks (notation x.y.z/s), to the four
subnets shown above. [6]

A. IPv4/IPv6 tunneling; IPv4(IPv6) packets are encapsulated inside IPv6(IPv4)

B. Binary network number of 32.0.0.0/3 is 001. Upper bits of 48.0.1.5 in binary are
00110000, and its upper 3 bits (001) match to 32.0.0.0/3. However, if 48.0.1.5
(00110000...) gets a longest prefix match with port 2 instead, then it means port 2 has a
subnet mask longer than /3 (ie => /4); hence matching with at least with 0011.

C. Each subnet will have 31 hosts at most, hence we can allocate blocks of 32
addresses to each subnet. To represent 32 IP addresses in each subnet, we need = 2^5
host bits [1]; hence the required subnet mask is 32-5 = 27 [1].
Suppose we start with 10.10.0.0 (I didn’t specify the starting IP range, hence answers
will vary here; just check that the mask is correct, ie /27, and that the subnets span 32
IPs)
IP ranges (order not necessary):
10.10.0.0/27 [1]
10.10.0.32/27 [1]
10.10.0.64/27 [1]
10.10.0.96/27 [1]
Networks Section

Question 1 [4 marks]
A. Describe in 1-2 sentences the difference(s) between routing and switching. [1]
B. Describe the information necessary for forwarding that is added to data units at each of
the following layers of the TCP/IP stack:
i. Transport Layer [1]
ii. Network Layer [1]
iii. Link Layer [1]

A. Switching involves moving packets between devices on the same network; a switch
determines where a packet should be sent by examining the MAC address within the
packet. Routing/forwarding involves moving packets between different networks; routers
compute the shortest path and build forwarding tables to forward packets enroute to the
destination.
B.
i. Transport Layer: source and destination port numbers are added; these used for
identification of source/destination applications, and de-multiplexing of traffic at
destination host.
ii. Network Layer: source and destination IP addresses are added, used for
identification of source/destination networks and hosts.
iii. Link Layer: source/destination MAC addresses are added, for identification of
next hop interfaces.

Question 2 [4 marks]
True or False:
i. The size of the TCP rwnd never changes throughout the duration of the
connection. [1]
ii. Suppose Host A is sending Host B a large file over a TCP connection. The
number of unacknowledged bytes that A sends cannot exceed the size of the
receive buffer.
[1]
iii. Suppose that the last SampleRTT in a TCP connection is equal to 200 ms. The
current value of TimeoutInterval for the connection must also be set to 200 ms.
[1]
iv. Suppose Host A sends one segment with sequence number 38 and 4 bytes of
data over a TCP connection to Host B. In this same segment the
acknowledgment number is necessarily 42. [1]

i) False, ii) True, iii) False, iv) False

Question 3 [9 marks]
A. The internet uses both IPv4 and IPv6. How is the ‘backward compatibility’ with IPv4
handled? [1]
B. Router R routes has specified a subnet mask of 32.0.0.0/3 on port 1, yet a packet with IP
destination address is routed out to output port 2. Based on this information alone, what
precisely can be said about port 2’s subnet mask? [2]
C. You are a network administrator and have to manage the network below. There are four
subnets and two routers, R1 and R2. Subnets A-D each contain at most 31 hosts.
Assign network addresses, including the subnet masks (notation x.y.z/s), to the four
subnets shown above. [6]

A. IPv4/IPv6 tunneling; IPv4(IPv6) packets are encapsulated inside IPv6(IPv4)

B. Binary network number of 32.0.0.0/3 is 001. Upper bits of 48.0.1.5 in binary are
00110000, and its upper 3 bits (001) match to 32.0.0.0/3. However, if 48.0.1.5
(00110000...) gets a longest prefix match with port 2 instead, then it means port 2 has a
subnet mask longer than /3 (ie => /4); hence matching with at least with 0011.

C. Each subnet will have 31 hosts at most, hence we can allocate blocks of 32
addresses to each subnet. To represent 32 IP addresses in each subnet, we need = 2^5
host bits [1]; hence the required subnet mask is 32-5 = 27 [1].
Suppose we start with 10.10.0.0 (I didn’t specify the starting IP range, hence answers
will vary here; just check that the mask is correct, ie /27, and that the subnets span 32
IPs)
IP ranges (order not necessary):
10.10.0.0/27 [1]
10.10.0.32/27 [1]
10.10.0.64/27 [1]
10.10.0.96/27 [1]
University of Cape Town
Department of Computer Science
CSC3002F
Concession Test
14 May 2019

Marks: 35
Time: 45 Minutes
Instructions:
 Marks per question are shown in brackets.
 The use of calculators is permitted.
 Show all calculations where applicable.

Multiple Choice Section [5 Marks]


For each of the questions below, write down the most correct answer.

Question 1
1. A process in an operating system moves scheduling on the CPU is of the order of:
from the running state to the ready state a. 10 picoseconds
as a consequence of: b. 10 milliseconds
a. I/O c. 10 seconds
b. event completion d. 10 minutes
c. an interrupt e. 10 hours
d. termination ______________b_______________
e. scheduler dispatch
____________c________________ 4. To prevent deadlock in an operating
system, the most effective strategy is to:
2. In process scheduling, the term convoy a. remove cycles of threads waiting for
effect refers to: resources
a. A reduction in average waiting time b. remove mutual exclusion
for many processes with equal burst c. do not allow process pre-emption
times in the SFJ algorithm. d. do not allow processes to hold
b. An increase in average waiting time in resources while waiting for a resource
the FCFS algorithm. e. all of the above
c. The predicted CPU burst of a newly _____________a__________________
arrived process being shorter than
what is left of the currently executing
process in the SFJ algorithm. 5. In the Linux OS, the user thread - kernel
d. Pre-emption of a long-running process thread mapping is:
in the RR algorithm a. One-to-One
e. Starvation in the priority scheduling b. One-to-Many
algorithm. c. Many-to-One
______________b_________________ d. Many-to-Many
e. All of the above
3. The time slice in typical Round Robin ___________a____________________
Networks Section [17 Marks]

Question 2
a) Describe in 1-2 sentences the difference(s) between routing and switching. [1]
b) Describe the information necessary for forwarding that is added to data units at each of the
following layers of the TCP/IP stack:
i. Transport Layer [1]
ii. Network Layer [1]
iii. Link Layer [1]

Question 3
True or False:
i. The size of the TCP rwnd never changes throughout the duration of the connection.
[1]
ii. Suppose Host A is sending Host B a large file over a TCP connection. The number
of unacknowledged bytes that A sends cannot exceed the size of the receive buffer.
[1]
iii. Suppose that the last SampleRTT in a TCP connection is equal to 200 ms. The
current value of TimeoutInterval for the connection must also be set to 200 ms.
[1]
iv. Suppose Host A sends one segment with sequence number 38 and 4 bytes of data
over a TCP connection to Host B. In this same segment the acknowledgment number
is necessarily 42. [1]

Question 4
a) The internet uses both IPv4 and IPv6. How is the ‘backward compatibility’ with IPv4
handled? [1]
b) Router R routes has specified a subnet mask of 32.0.0.0/3 on port 1, yet a packet with IP
destination address 48.0.1.5 is routed out to output port 2. Based on this information
alone, what precisely can be said about port 2’s subnet mask?
[2]
c) You are a network administrator and have to manage the network below. There are four
subnets and two routers, R1 and R2. Subnets A-D each contain at most 31 hosts. Assign
network addresses, including the subnet masks (notation x.y.z/s), to the four subnets
shown above.
[6]
OS Part I Section [8 Marks]

Question 5
a) Briefly describe how multi-level page tables can reduce OS memory requirements. [2]
ANS:
Multi-level page tables reduce the memory requirements incurred by large virtual
address spaces (e.g. 64 bit). Each page table entry (at each page table level) references a page
table 1 level down – so only level 1 page table needs to be in main memory at all times – e.g. if a
page-table entry at level 1 is null then the corresponding level 2 page table does not have to
exist.

b) Briefly describe what virtual memory is and give one (1) key motivation for the use of virtual
memory in modern operating systems [2]
ANS: Definition: Virtual memory is the process of using secondary storage to create an
illusion of an even larger memory space without incurring the cost.
Motivation 1: To remove burden of programmers dealing with limited main memory
Motivation 2: To allow for the total memory required for all programs being larger than the
physical memory.
Motivation 3: To avoid changing addresses in programs to make them fit simultaneously in
memory.
Motivation 4: To allow efficient and safe sharing of memory among multiple programs.

c) Briefly describe the difference between temporal and spatial locality in programs [2]

ANS:
Both refer to the principle of locality: Programs tend to reuse data and instructions
near those they have used recently.

Temporal locality: recently referenced items are likely to be referenced in the near future.

Spatial locality: items with nearby addresses tend to be referenced close together in time.
d) Briefly describe what causes a page fault and how it is handled by the OS [2]

ANS:
If a page table entry indicates a virtual address is not in memory the OS exception
handler is invoked to move data from disk into memory (current process suspends). A page is
swapped from disk into a free frame, the page table entry updated and instruction is
restarted.

OS Part II Section
[5 Marks]
Question 6

a) For the priority scheduling algorithm, explain the problem of process starvation, how this
problem occurs and how it is solved. [2]

ANS:
The priority scheduling algorithms selects the process with the highest priority to run next.
Starvation (indefinite blocking) is the problem of low priority processes never getting the chance to
execute [1]. The solution is aging – as time progresses increase the priority of the process.[1]

b) A system has 4 threads executing and 3 resource types - A (4 instances), B (4), and C (3).
At a particular point in time, the resource allocation to the threads is as shown in the grid to
the right.
Allocation Max
i. Is this system in a safe state? Justify your answer. ABC ABC
[3] T0 011 432
T1 110 220
ANS: T2 200 302
T3 001 222
Yes, it is in a safe state[1]. There is (only) one possible ordering for
the threads to execute:
T1; T3; T2 ; T0 [2]

Allocation Need Available


ABC ABC ABC
T0 011 421 121
T1 110 110
T2 200 102
T3 001 221
University of Cape Town
Department of Computer Science
CSC3002F
Computer Networks – Test 1
26 March 2019

Marks: 35
Time: 45 Minutes
Instructions:
(1) Marks per question are shown in brackets.
(2) The use of calculators is permitted.
(3) Show all calculations where applicable.

Question 1 (8 Marks)
a) In networks architectures, what is:
(i) protocol 1 Mark
(ii) service 1 Mark

1a)
i. protocols define format, order of msgs sent and received among network entities, and
actions taken on msg transmission,
ii. service: capabilities provided by a layer to the upper layers, or more generally, capabilities
provided by a system to its users

b) Name one key function for each of the four upper layers of the TCP/IP reference model, and
describe one protocol that implements each function you have mentioned. 6 Mark

1b)
❖ application layer: supports communication of network applications (end to end
communication between applications). Examples include FTP, SMTP, DNS, HTTP. HTTP
supports interaction requests and exchange of html/files between web servers and web clients
(browsers)
❖ transport layer: enable process-process data transfer (end to end communication between
processes). Examples are Transport Control Protocol (TCP), which supports reliable
connection oriented communication, and the User Datagram Protocol (UDP), which provides
unreliable connectionless service between processes.
❖ network layer: the layer is responsible for routing of datagrams from source to destination
host. Examples include the Internet Protocol (IP), which is responsible for addressing and
forwarding of packets/datagrams. Routing protocols include LinkState and Distance Vector,
and these are responsible for computing the shortest paths from source to destination.
❖ link layer: responsible for data transfer between neighbouring network elements.
Examples include Ethernet (coordinated access control and communication over shared
medium through carrier sense multiple access with collision detection (CSMA/CD)). Also
802.111 (WiFi).

Question 2 (10 Marks)


a) In the Domain Name System (DNS), what is the purpose of:
i) 16 bit id field in the DNS message header 1 Mark
ii) Root Name Servers 1 Mark
iii) TLD Servers 1 Mark
iv) Authoritative Name Servers 1 Mark

2a
i. 16 bit# for identification and matching of query to reply
ii. root servers: return mapping of authoritative name servers responsible for top-level
domains, e.g list of servers for .com
iii. TLD servers are responsible for top-level-domains, e.g com, org, net, edu, and all top-level
country domains, e.g. uk, ao, mw, gh. TLDs will return list of authoritative name servers for
each specific domain under its zone, e.g list of authoritative servers for google.com
iv. authoritative DNS servers are each organization’s own DNS server(s), providing
authoritative hostname to IP mappings for organization’s named hosts.

b) In non-persistent HTTP, retrieving each object from a web server takes


2*RTT+file_transmission_time. Explain why this is the case. 2 Marks

2b
one RTT to initiate TCP connection + one RTT for HTTP request and first few bytes of
HTTP response to return + file transmission time = 2*RTT + transmission_time

c) Use a sequence diagram to explain how web cookies are used. 4 Marks
2c
similar to diagram above; marks for indication of cookie-set(server), cookie-save(client),
cookie+query (client), response based on query+cookie (server)

Question 3 (7 Marks)
Figures 3.A and 3.B below illustrate two kinds of pipelined transport protocols: Selective Repeat
and Go-Back-N.

Fig 3.A
a) Which one of the two diagrams above is likely to be Go-Back-N? Justify your answer. 1 Mark
3a
3A is go-back-n; acknowlegments are accumulative and there cannot be already acknowledged
segments within the window.
b) For each of the diagrams, describe the network event(s) that would cause the sliding window to
shift 5 steps to the right. 2 Marks
3b
For 3A (go-bk-n), the window will shift 5 steps to the right if ack received is for segment #4
(counting from the sending base). For 3B (selective repeat), the window will shift 5 steps after all
the un-acked segments prior to #5 have been acked; ie segments 3 and 4 have been acked.

c) Suppose the following RTT samples (in ms) are collected by TCP (in the given order): 90, 100,
95, 110, 90. Assuming the initial RTT estimate was 100ms, what will the Time_Out_Interval used
by TCP after the 3rd RTT sample. (Hint: assume α = 0.125 and β = 0.25). 4 Marks

EstimatedRTT = (1- α)*EstimatedRTT + α*SampleRTT:


100*0.875 + 90*0.125 = 98.75
98.75*0.875 + 100*0.125 = 98.91
98.91*0.875 + 95*0.125 = 98.42

DevRTT = (1-β)*DevRTT + β*|SampleRTT-EstimatedRTT|:


0.25*(100-90) = 2.5
2.5(0.75) + 0.25(100-98.75) = 2.19
2.19(0.75) + 0.25(98.91-95) = 2.62

TimeoutInterval = EstimatedRTT + 4*DevRTT


TimeoutInterval = 98.42 + 4*2.62 = 108.9
Question 4 (10 Marks)
a) Given an IP address 192.168.10.20/24:
i) What is the network to which the IP address belongs to? 2 Marks
ii) Divide the network in (a.i) into 8 equal subnets, and indicate which one of
subnets the address (192.168.10.20) belongs to. Clearly show your working. 6 Marks
4.a
i.
Given the IP address 192.168.10.20/24
In binary: 11000000 10101000 00001010 00010100
Since the subnet mask is /24, the higher order 24 bits represent the nework, and last 8 bits represent
the host numbers.
For a network number, the host bits are all zeros.
The network number is: 11000000 10101000 00001010 00000000 => 192.168.10.0/24

ii.
To have 8 subnets, 3 subnet bits are needed and should be borrowed from the host part of the
network address, ie the bits 25,26,27 will be used to represent the different subnets, and the subnet
mask becomes 24 + 3 = 27 (1 mark)

The subnets are: (1/2 mark each)


11000000 10101000 00001010 00000000 => 192.168.10.0/27
11000000 10101000 00001010 00100000 => 192.168.10.32/27
11000000 10101000 00001010 01000000 => 192.168.10.64/27
11000000 10101000 00001010 01100000 => 192.168.10.96/27
11000000 10101000 00001010 10000000 => 192.168.10.128/27
11000000 10101000 00001010 10100000 => 192.168.10.160/27
11000000 10101000 00001010 11000000 => 192.168.10.192/27
11000000 10101000 00001010 11100000 => 192.168.10.224/27

The IP address 192.168.10.20/24 => 11000000 10101000 00001010 00010100


belongs to subnet 192.168.10.0/27 => 11000000 10101000 00001010 00000000
(1 mark)

b) One of the arguments against NAT is that it violates the principle that network layer devices
(routers) should only process up to layer 3. How does NAT violate this principle? 2 Marks
4.b
In NAT operation, routers have to multiple traffic flows from multiple private IP addresses to
a single public IP address, and achieve this, the routers use the source/destination IP address
and port numbers. This means routers have to decapsulate transport layer headers to read/re-
write port numbers. Routers are Network layer devices and should not be reading/writing
transport layer headers (in the strict sence of layer function separation). (2 marks)
University of Cape Town
Department of Computer Science
CSC3002F
Computer Networks – Test 1
26 March 2019

Marks: 35
Time: 45 Minutes
Instructions:
(1) Marks per question are shown in brackets.
(2) The use of calculators is permitted.
(3) Show all calculations where applicable.

Question 1 (8 Marks)
a) In networks architectures, what is:
(i) protocol 1 Mark
(ii) service 1 Mark

1a)
i. protocols define format, order of msgs sent and received among network entities, and
actions taken on msg transmission,
ii. service: capabilities provided by a layer to the upper layers, or more generally, capabilities
provided by a system to its users

b) Name one key function for each of the four upper layers of the TCP/IP reference model, and
describe one protocol that implements each function you have mentioned. 6 Mark

1b)
❖ application layer: supports communication of network applications (end to end
communication between applications). Examples include FTP, SMTP, DNS, HTTP. HTTP
supports interaction requests and exchange of html/files between web servers and web clients
(browsers)
❖ transport layer: enable process-process data transfer (end to end communication between
processes). Examples are Transport Control Protocol (TCP), which supports reliable
connection oriented communication, and the User Datagram Protocol (UDP), which provides
unreliable connectionless service between processes.
❖ network layer: the layer is responsible for routing of datagrams from source to destination
host. Examples include the Internet Protocol (IP), which is responsible for addressing and
forwarding of packets/datagrams. Routing protocols include LinkState and Distance Vector,
and these are responsible for computing the shortest paths from source to destination.
❖ link layer: responsible for data transfer between neighbouring network elements.
Examples include Ethernet (coordinated access control and communication over shared
medium through carrier sense multiple access with collision detection (CSMA/CD)). Also
802.111 (WiFi).

Question 2 (10 Marks)


a) In the Domain Name System (DNS), what is the purpose of:
i) 16 bit id field in the DNS message header 1 Mark
ii) Root Name Servers 1 Mark
iii) TLD Servers 1 Mark
iv) Authoritative Name Servers 1 Mark

2a
i. 16 bit# for identification and matching of query to reply
ii. root servers: return mapping of authoritative name servers responsible for top-level
domains, e.g list of servers for .com
iii. TLD servers are responsible for top-level-domains, e.g com, org, net, edu, and all top-level
country domains, e.g. uk, ao, mw, gh. TLDs will return list of authoritative name servers for
each specific domain under its zone, e.g list of authoritative servers for google.com
iv. authoritative DNS servers are each organization’s own DNS server(s), providing
authoritative hostname to IP mappings for organization’s named hosts.

b) In non-persistent HTTP, retrieving each object from a web server takes


2*RTT+file_transmission_time. Explain why this is the case. 2 Marks

2b
one RTT to initiate TCP connection + one RTT for HTTP request and first few bytes of
HTTP response to return + file transmission time = 2*RTT + transmission_time

c) Use a sequence diagram to explain how web cookies are used. 4 Marks
2c
similar to diagram above; marks for indication of cookie-set(server), cookie-save(client),
cookie+query (client), response based on query+cookie (server)

Question 3 (7 Marks)
Figures 3.A and 3.B below illustrate two kinds of pipelined transport protocols: Selective Repeat
and Go-Back-N.

Fig 3.A
a) Which one of the two diagrams above is likely to be Go-Back-N? Justify your answer. 1 Mark
3a
3A is go-back-n; acknowlegments are accumulative and there cannot be already acknowledged
segments within the window.
b) For each of the diagrams, describe the network event(s) that would cause the sliding window to
shift 5 steps to the right. 2 Marks
3b
For 3A (go-bk-n), the window will shift 5 steps to the right if ack received is for segment #4
(counting from the sending base). For 3B (selective repeat), the window will shift 5 steps after all
the un-acked segments prior to #5 have been acked; ie segments 3 and 4 have been acked.

c) Suppose the following RTT samples (in ms) are collected by TCP (in the given order): 90, 100,
95, 110, 90. Assuming the initial RTT estimate was 100ms, what will the Time_Out_Interval used
by TCP after the 3rd RTT sample. (Hint: assume α = 0.125 and β = 0.25). 4 Marks

EstimatedRTT = (1- α)*EstimatedRTT + α*SampleRTT:


100*0.875 + 90*0.125 = 98.75
98.75*0.875 + 100*0.125 = 98.91
98.91*0.875 + 95*0.125 = 98.42

DevRTT = (1-β)*DevRTT + β*|SampleRTT-EstimatedRTT|:


0.25*(100-90) = 2.5
2.5(0.75) + 0.25(100-98.75) = 2.19
2.19(0.75) + 0.25(98.91-95) = 2.62

TimeoutInterval = EstimatedRTT + 4*DevRTT


TimeoutInterval = 98.42 + 4*2.62 = 108.9
Question 4 (10 Marks)
a) Given an IP address 192.168.10.20/24:
i) What is the network to which the IP address belongs to? 2 Marks
ii) Divide the network in (a.i) into 8 equal subnets, and indicate which one of
subnets the address (192.168.10.20) belongs to. Clearly show your working. 6 Marks
4.a
i.
Given the IP address 192.168.10.20/24
In binary: 11000000 10101000 00001010 00010100
Since the subnet mask is /24, the higher order 24 bits represent the nework, and last 8 bits represent
the host numbers.
For a network number, the host bits are all zeros.
The network number is: 11000000 10101000 00001010 00000000 => 192.168.10.0/24

ii.
To have 8 subnets, 3 subnet bits are needed and should be borrowed from the host part of the
network address, ie the bits 25,26,27 will be used to represent the different subnets, and the subnet
mask becomes 24 + 3 = 27 (1 mark)

The subnets are: (1/2 mark each)


11000000 10101000 00001010 00000000 => 192.168.10.0/27
11000000 10101000 00001010 00100000 => 192.168.10.32/27
11000000 10101000 00001010 01000000 => 192.168.10.64/27
11000000 10101000 00001010 01100000 => 192.168.10.96/27
11000000 10101000 00001010 10000000 => 192.168.10.128/27
11000000 10101000 00001010 10100000 => 192.168.10.160/27
11000000 10101000 00001010 11000000 => 192.168.10.192/27
11000000 10101000 00001010 11100000 => 192.168.10.224/27

The IP address 192.168.10.20/24 => 11000000 10101000 00001010 00010100


belongs to subnet 192.168.10.0/27 => 11000000 10101000 00001010 00000000
(1 mark)

b) One of the arguments against NAT is that it violates the principle that network layer devices
(routers) should only process up to layer 3. How does NAT violate this principle? 2 Marks
4.b
In NAT operation, routers have to multiple traffic flows from multiple private IP addresses to
a single public IP address, and achieve this, the routers use the source/destination IP address
and port numbers. This means routers have to decapsulate transport layer headers to read/re-
write port numbers. Routers are Network layer devices and should not be reading/writing
transport layer headers (in the strict sence of layer function separation). (2 marks)
University of Cape Town
Department of Computer Science
CSC3002F
Operating Systems – Test 2
29 April 2019

Marks: 35
Time: 45 Minutes
Instructions:
• Marks per question are shown in brackets.
• The use of calculators is permitted.
• Show all calculations where applicable.

Question 1 – Multiple Choice [10 Marks]


For each of the questions below, write down the most correct answer.

1. The OS system call interface to the kernel an OS to run on multi-core processors


uses which of the following? b. Multi-programming is dynamic
a. File system switching between job processes so
b. Disk drivers while one job waits for resources the
c. CPU scheduling CPU finds another job to run.
d. Virtual memory c. Multi-programming is an OS that
e. All of the above handles the concurrent development
____________________________ and testing of many user applications.
d. Multitasking and time sharing are the
2. OS system calls handle which of the same thing.
following? e. Multi-tasking is a form of concurrency
a. Accessing devices specific to parallel execution of kernel
b. Accessing files processes.
c. Inter-process communication _______________________________
d. All of the above
e. None of the above 5. A process in an operating system moves
_______________________________ from the ready state to the running state
as a consequence of:
3. OS system calls are needed for which of a. I/O
the following? b. event completion
a. String read and write operations. c. an interrupt
b. Instantiating an instance of a class in a d. termination
program class hierarchy e. scheduler dispatch
c. Recursive function calls _______________________________
d. Accessing network data
e. None of the above 6. An example of a thread library is
_______________________________ a. Pthreads
b. Windows threads
4. Which of the following is correct? c. Java threads
a. Multi-tasking implies the capability of d. All of the above
e. None of the above correctly implementing a simulation of
_______________________________ dishwashing in a kitchen. This was an
example of which classical
7. In the Linux OS, the user thread - kernel synchronization problem?
thread mapping is: a. The Dining Philosophers problem
a. One-to-One b. The Readers-Writers problem
b. One-to-Many c. The Producer-Consumer problem
c. Many-to-One d. The Critical Section problem
d. Many-to-Many e. The Barbershop problem
e. All of the above _______________________________
_______________________________
10. For deadlocks, the Windows operating
system:
8. The semaphore mechanism for process a. Ignores them
synchronization was invented by: b. Prevents them
a. John von Neumann c. Avoids them
b. Edsgar Dijkstra d. Allows them to happen and then
c. Allan Turing recovers from them
d. Ada Lovelace _______________________________
e. Linus Torvalds
_______________________________

9. Part II of the OS assignment involved

Question 2 – OS Part I [6 Marks]

a) Briefly describe the difference between an OS trap and OS context switch. [2]
ANS: Trap: is an OS system call – i.e. a software interrupt to request an OS service. Traps
are needed for context switching. [1]

Context-switch: Switching between kernel mode (OS is handling an exception or executing a


kernel-only process) and user mode (user applications running on OS as per normal). [1]

b) Briefly describe the difference between an OS and the kernel. [2]


ANS:

OS: Often refers to the complete system, including command interpreters, utility programs,
window managers, and so on. [1]
Kernel: Core component of the OS that manages resource access, memory, and process
scheduling, manages file system, and provides access to devices. [1]
c) Briefly describe the difference between the monolithic and micro-kernel OS structures. [2]
ANS:
In a monolithic kernel, all OS services run together as a single (monolithic) structure and reside
in the same memory area. Monolithic kernels contain all the OS core functions and device
drivers. [1]

A microkernel is designed for a specific hardware platform or device and uses a modular design
where OS functionality is split-up between a set of modules that communicate through a
minimal (micro) kernel. [1]

Question 3 – OS Part II [19 Marks]

a) Explain how a Process Control Block is used when an OS kernel performs a context switch.
[4]
ANS: The kernel performs a context switch when swapping the executing process.[1]
To keep track of processes, the operating system maintains a process table (or list). [1]
 Each entry in the process table is a Process Control Block (PCB)
 corresponds to a particular process [1]
 contains fields with information that the kernel needs to know about the process.[1]

b) Examine the Java code snippets shown below. This code uses semaphores to enforce a
specific synchronization pattern between Thread 1 and Thread 2.

Two semaphores are initialized as follows.


Semaphore sema1 = new Semaphore(0);
Semaphore sema2 = new Semaphore(0);

Thread 1 code
System.out.println("Hello Bob.");
sema1.release();
sema2.acquire();
System.out.println("Goodbye Bob");

Thread 2 code
System.out.println("Hello Anne.");
sema2.release();
sema1.acquire();
System.out.println("Goodbye Anne");
i. Explain clearly the synchronization pattern that is enforced by the code above. [3]
 ANS: This code enforces a rendezvous[1]: The semaphores ensure that “Hello
Anne” is printed before “Goodbye Bob”[1], and that “Hello Bob” is printed before
“Goodbye Anne”. [1]

ii. Explain what would happen if the semaphores are initialized as follows. [2]
Semaphore sema1 = new Semaphore(1);
Semaphore sema2 = new Semaphore(1);

ANS: The synchronization pattern would no longer be enforced: Thread 2 would no longer have to
wait for thread 1 and vice versa. [2]

c) For each of the resource allocation graphs shown below (i-iii), state whether threads are in
deadlock or not. For those situations where deadlock exists, provide the list of threads and
resources that are deadlocked. Where there is no deadlock, list an order in which threads
may complete execution.

[6]
Ans: i) deadlock : T3; T1 [2]
ii) No deadlock, can complete as T4; T1; T2;T3 OR T4;T1;T3;T2 OR T4;T2;T1;T3 [2]
iii) deadlock: T3;T1 [2]

d) A system has 4 threads executing and 3 resource types - A (5


Allocation Max
instances), B (4), and C (3). At a particular point in time, the ABC ABC
resource allocation to the threads is as shown in the grid to the T0 010 532
right. T1 200 322
T2 302 302
i. Which algorithm would you use to determine if this
T3 011 242
system is in a safe state? [1]
ii. Is this system in a safe state? Justify your answer. [3]

ANS:
i) The Banker’s Algorithm (safety calculation therein) [1]
ii) No, it is not safe[1]. There is no ordering of threads that satisfies the safety criterion: no thread
can run first, as their maximum request is greater than the resources currently available.[2]

Allocation Need Available It is SAFE. There is an oredering of


ABC ABC ABC processes that can execute and satisfy
T0 010 522 02 0 the safety requirement:
T1 200 122 T2,T1,T0,T3
T2 302 000
T3 011 231
UNIVERSITY OF CAPE TOWN


Department of Computer Science
CSC3002F/CSC3023F

Semester Test 1 16 March 2016


Read through the entire test paper before you start writing so that you can answer the easy
questions first. The relative importance of a question is indicated by the marks allocated to it.
Total Marks: 40 Approximate marks per question shown in brackets.
Time: 40 minutes for CSC3002F The use of a calculator is permitted.
Time: 16 only minutes for CSC3023F
CSC3002F students must answer all of the questions
CSC3023F students must answer only the questions in Section 1




Section 1 – Operating Systems (16 marks)

Question 1 – Processes (11 marks)

Question 1.1 (5 marks)


List the five states associated with processes, and draw a state diagram to show how
processes can change state.

Question 1.2 (6 marks)


List six of the seven types of information to be stored in the Process Control Block and
give a brief explanation of each.

Question 2 – Scheduling (5 marks)


Question 2.1 (5 marks)


Give five scheduling criteria with a short explanation of each.
Section 2 – Networks (24 marks)

Question 3 – Layering (7 marks)

Question 3.1 (4 marks)


Computer networks are conceptually structured using layering. Explain why layering is
used.

Question 3.2 (3 marks)


Consider the ISO/OSI stack and its seven layers. Assign the following three processes to the
(named) layer where it occurs. Put differently: which layer is responsible for this service?
a. Process-to-process communication
b. Routing of the packet from source to destination
c. Encryption


Question 4 – Protocols (13 marks)

Question 4.1 (1 mark)


What is a protocol?

Question 4.2 (12 marks)


Consider HTTP, whose message format is shown in Figure 1, below.
a. An HTTP message is shown in Figure 2. Identify: method, header field name, and
body. [1 mark]
b. HTTP can use a persistent and non-persistent mode of communication.
i. What is the difference? [2 marks]
ii. Which of the two applies to the message shown in Figure 2? Say how you
came to that answer. [1 mark]
c. HTTP itself is stateless, but cookies sort-of address this. Describe or draw briefly how
cookies work. [4 marks]
d. You want to open a web page in a browser, type in its URL, and an HTTP request
message is being created. To satisfy this request, it needs to avail of another
application layer protocol.
i. Which protocol? [1 mark]
ii. What does that protocol do? [1 mark]
e. What is the main difference between HTTP and FTP? [2 marks]

Figure 1. HTTP message format.

GET /cs3002F/index.html HTTP/1.1<cr><lf>


Host: cs.uct.ac.za<cr><lf>
User-Agent: Mozilla/5.0 (Windows;U; Windows NT 5.1; en-US; rv:1.7.2)
Gecko/20040804 Netscape/7.2 (ax) <cr><lf>
Accept:ext/xml,application/xml,application/xhtml+xml,text/html;q=0.9
,text/plain;q=0.8,image/png,*/*;q=0.5<cr><lf>
Accept-Language:en-us,en;q=0.5..Accept-Encoding: zip,deflate<cr><lf>
Accept-Charset:ISO-8859-1,utf-8;q=0.7,*;q=0.7..Keep-Alive:
300<cr><lf>
Connection:keep-alive<cr><lf><cr><lf>
Figure 2. An HTTP message.

Question 5 – Architectures (4 marks)

Question 5.1 (2 marks)


Telephone networks traditionally use circuit switching, whereas the Internet uses packet
switching in the network core. What are the consequences—good or bad—of this design
choice of having a packet switching-based core (with respect to circuit switching)?

Question 5.2 (2 marks)


Textbooks are quite expensive, but at least there are softcopies on the Web. Those
softcopies may be older editions that the authors themselves have made available or also
new editions. Some courses have as few as 15 students enrolled, but typically 30-80
students; several courses have about 1000 students who need a particular textbook. You
want to create a ‘one-stop-shop’ service for UCT students to download textbooks. Which
architecure—client-server or peer-to-peer—would you use to implement the service?
Justify your answer.







UNIVERSITY OF CAPE TOWN

Department of Computer Science


CSC3002F

Class Test 2 11 May 2015


Read through the entire test paper before you start writing so that you can answer the easy questions
first. The relative importance of a question is indicated by the marks allocated to it.

Total Marks: 40 Approximate marks per question shown in brackets.


Time: 40 minutes The use of a calculator is permitted.

You must answer all of the questions

Functional Programming
Question 1 Scheme [8 Marks]
a) Define a recursive Scheme function double-list that takes a list of numbers as an argument,
and returns a new list of numbers, each twice the number in the original. For example,
(double-list '(1 2 3)) should return '(2 4 6). (This version should not use higher
order functions such as map.) [5]
b) Define another version of double-list that is NOT recursive, using map. [3]

Question 2 Computability [2 Marks]


What do we mean when we say that the Halting Problem is undecidable? [2]

Question 3 Lambda Calculus [8 Marks]


Reduce the following in normal order. Give the steps of β- α- η-reduction, labelling them correctly
and showing which variables were substituted or renamed. Conclude with the simplest form or state
“diverges” if it does not terminate: [8]

(λh.(λa.(λf.f a) h) h) (λf.f f)
Question 4 Haskell [4 Marks]
Explain the computation performed by the Haskell fragment below, where length is a built-in
function to compute the size of a list. What will it return? [4]

length [ y | y <- "I love lambda calculus", y=='l']

Networks
Question 5 [3 Marks]
The TCP/IP suite has fewer layer(s) than the ISO/OSI stack.
a) Name the difference(s) [1]
b) What implication(s) do(es) this have for the design of network applications when using the
TCP/IP stack? [2]

Question 6 [4 Marks]
Some network consists of a 10 Mbps link. Each user connected to it sends continuously at 2 Mbps
when it is transmitting, but transmits only 50% of the time.
a) How many users can it support if the link were to use FDM circuit switching? [1]
b) If the link were to use packet switching instead, can this affect queuing delay when 6 users
are using the link? Justify your answer. [2]
c) What are the sources of delay in packet switching, other than queuing delay? [1]

Question 7 [7 Marks]
Application layer protocols.

a) The HTTP protocol is stateless, but it may be persistent. What does that mean? [2]
b) In contrast to HTTP, FTP is ‘stateful’. How does the FTP protocol handle that extra
management overhead? [1]
c) Webservers rely on the underlying TCP/IP protocol stack. How many sockets will it have
open when 50 users are requesting simultaneously a webpage that has three linked
objects? Justify your answer. [2]
d) Which host(s) would have sent the following HTTP message, if at all? Explain very briefly
why. [2]

GET /animal/rockdassie.jpg HTTP/1.1


Host: www.tablemountaintourism.co.za
If-modified-since: Wed, 7 May 2013 09:23:24
Question 8 [4 Marks]
The protocol specification in the figure below is an attempt at ensuring reliable transfer in the case
where bit errors may occur, i.e., packets transmitted between sender and receiver may arrive
corrupted, which it should be able to handle. It has several problems, however. Which ones? [4]

Figure 1: Use this figure to answer Question 8


UNIVERSITY OF CAPE TOWN


Department of Computer Science
CSC3002F/CSC3023F

Class Test 2 11 May 2016


Read through the entire test paper before you start writing so that you can answer the easy
questions first. The relative importance of a question is indicated by the marks allocated to it.
Total Marks: 45 Approximate marks per question shown in brackets.
Time: 40 minutes for CSC3002F The use of a calculator is permitted.
Time: 15 minutes only for CSC3023F
CSC3002F students must answer all of the questions
CSC3023F students must answer only the questions in Section 1

Section 1 – Operating Systems (15 marks)

Question 1 – Process Scheduling (4 marks)
a) Give an example to demonstrate that First-Come First-Served (FCFS) scheduling is
not always optimal. [2]
b) Mention a scheduling algorithm that is optimal, and provide the conditions under
which it will be optimal. [2]

Question 2 - Synchronization (4 marks)


a) Consider the following solution to the Dining Philosophers Problem (for 5
philosophers) where each entry in the array of semaphores, chopstick[5], is initialized
to 1, and Philosopher i has the structure given below. Observe that this is a modified
version of the solution provided in the textbook. How does this solution differ from
the one in the textbook? What is the problem with this solution?

do {
wait (chopStick[ (i + 1) % 5] );
wait (chopstick[i] );
// eat
signal (chopstick[ (i + 1) % 5] );
signal (chopstick[i] );
// think
} while (TRUE); [2]

b) Provide an asymmetric solution which avoids the problem encountered above.


[2]

Question 3 - Deadlock (3 marks)
Draw an example of a resource allocation graph containing a cycle, and with multiple
instances of at least one resource type, in which there is deadlock.

Question 4 – Memory Management (4 marks)


The dynamic storage-allocation problem is the problem of how to satisfy a memory
request of size n from a list of free memory holes. Give an advantage and a disadvantage
of the first-fit algorithm. Give a disadvantage of the best-fit algorithm. Give an advantage
of the worst-fit algorithm.

Section 2 – Networks (15 marks)



Question 5 (3 marks)
Consider the protocol specification in the figure below. For the reliable data transfer, it addresses one
of the core issues, but not all.
a) Which of the two core issues does it have a solution for? [1]
b) What still can go wrong such that we do not yet obtain fully reliable data transfer with this
protocol? [2]
Question 6 (12 marks)

a) Describe in 1-2 sentences the difference(s) between routing and switching. [2]
b) The internet uses IPv4 and IPv6. How is the ‘backward compatibility’ with IPv4 handled?
[1]
c) Router R routes has specified a subnet mask of 32.0.0.0/3 on port 1, yet an arriving packet
with IP destination address 48.0.1.5 is routed to output port 2. Based on this information
alone, what can be said about port 2’s subnet mask? Be as precise as possible in your
answer. [3]
d) Host A with IP address 10.10.10.10 wants to send a packet to Host B with IP address
10.10.10.11, which is on the same subnet. A’s ARP table contains only the addresses of
the DNS and DHCP servers and of the first-hop router. Describe what ARP does, i.e., the
process, given this scenario and configuration. [4]
e) There are three broad classes of multiple access protocols, being channel partitioning,
random access, and taking turns. The first two can be subdivided further. Name those 4.
[2]


Section 3 – Functional Programming (15 marks)

Question 7 – Functional Programming (9 marks)


a) Explain the fundamental reason that successive calls to an imperative procedure with the
same calling parameters can give different answers. [3]
b) Write a Scheme function called add-to-end that takes an element and a list and returns
a list with the element added to the end. [3]
For example:
;; > (add-to-end 'put '(something up with which I will not))
;; (something up with which I will not put).

c) Define a function end-adder that takes a single argument element and returns a function
that takes a list and it adds element to the end of the list. [3]
;; > ((end-adder 'snake) '(An adder is a kind))
;; (An adder is a kind snake)

Question 8 – Computability (6 marks)


a) What are partial functions and why are they important in computer science? [2]
b) Provide a formal definition of a partial function. [2]
c) Our intuition is that a function is computable if there is some program that computes it.
What is the problem with this intuitive definition of “computable”? [2]
University of Cape Town
Department of Computer Science

CSC3002/CSC3023 Concession Test


May 2018
___________________________________________________________________
CSC3002 students answer section1 and 2.
CSC3023 students answer section 2 only.

Marks: 40 • Approximate marks per question are shown


in brackets

Time: 45 minutes • The use of calculators is permitted

Section 1: Networks
Question 1 [5]

(i) What advantage does a circuit-switched network have over a packet-switched


network? [1]

A circuit-switched network can guarantee a certain amount of end-to-end


bandwidth for the duration of a call. Most packet-switched networks (including the
Internet) cannot make any end-to-end guarantees for bandwidth.

(ii) What advantages does TDM have over FDM in a circuit-switched network? [1]

FDM requires sophisticated analog hardware to shift signal into appropriate


frequency bands.

(iii) In Packet switching, what does 'store-and-forward' entail? [1]

Store-and-forward transmission means that the packet switch must receive the
entire packet before it can begin to transmit the first bit of the packet onto the
outbound link.

(iv) As a packet travels from one node to another along a path, the packet suffers
from several types of delays at each node along the path. Describe any two key
components of this delay? [2]
processing delay (time required to examine the packet’s header and determine
where to direct the packet),

queuing delay (as packet waits to be transmitted onto the link) ,

transmission delay (time required to push (that is, transmit) all of the packet’s bits
into the link)

propagation delay (time required to propagate from the beginning of the link to
router) ;

Question 2 [4]

Suppose the network layer provides the following service. The


network layer in the source host accepts a segment of maximum size
1,200 bytes and a destination host address from the transport layer.
The network layer then guarantees to deliver the segment to the
transport layer at the destination host. Suppose many network
application processes can be running at the destination host.

(i) Describe the working of the simplest possible transport layer protocol that will get
application data to the desired process at the destination host. Assume the
operating system in the destination host has assigned a 4-byte port number to
each running application process. [2]

Let call this protocol Simple Transport Protocol (STP).


1. At the sender side, STP accepts from the sending process a chunk of data
not exceeding 1196 bytes, a destination host address, and a destination port
number.
2. STP adds a four-byte header to each chunk and puts the port number of the
destination process in this header.
3. STP then gives the destination host address and the resulting segment to
the network layer.
4. The network layer delivers the segment to the STP at the destination host.
5. The receiver STP then examines the port number in the segment, extracts
the data from the segment, and passes the data to the process identified by the
port number.

(Any correct mention gets .5mark)

Modify this protocol so that it provides a "return address" to the destination


process. [2]

1. The segment now has two header fields: a source port field and destination
port field.
2. At the sender side, STP accepts a chunk of data not exceeding 1192 bytes,
a destination host address, a source port number, and a destination port number.

3. STP creates a segment which contains the application data, source port
number, and destination port number.
4. It then gives the segment and the destination host address to the network
layer.
5. After receiving the segment, STP at the receiving host gives the application
process the application data and the source port number.

(Any correct mention gets .5mark)

Question 3 [11]

Consider a datagram network using 8-bit host addresses. Suppose a


router uses longest prefix matching and has the forwarding table
below.

Prefix Match Interface


00 0
010 1
011 2
10 2
11 3

i. For each of the four interfaces, give the associated range of destination host
addresses (in binary) and the number of addresses in the range. [8]

Destination Address Range Link Interface


00000000 0
through
00111111
01000000 1
through
01011111
01100000 2
through
01111111
10000000 2
through
10111111
11000000 3
through
11111111
6
number of addresses for interface 0 = 2 =64
5
number of addresses for interface 1 = 2 =32
6 5
number of addresses for interface 2 = 2 +2 =64 +32=96
6
number of addresses for interface 3 = 2 =64

Consider three LANs interconnected by two routers, as shown in


Figure below.

ii. Suppose all of the ARP tables are empty, enumerate all the steps that are
undertaken when sending an IP datagram from Host B to Host E. [3]

1. B determines E is in a different subnet, needs to forwards IP datagram


through its gateway router
2. B determines MAC address of gateway router (left router) by sending
ARP query broadcast in Subnet1
3. Left router sends ARP reply to B
4. B forwards IP datagram through its gateway router (left router)
5. Left router forwards datagram to right router (assuming routers already
have each others’MAC addresses)
6. Right router sends ARP query broadcast in Subnet3 to determine MAC
address of E
7. E responds to right router with its MAC address
8. Right Router forwards IP datagram to E
(Any correct mention gets 0.5 mark)
Section 2: Operating Systems

Question 4 [15]

(i) Explain what a zombie process is and how to deal with it. [2]

A process that has terminated (called exit()), but whose parent has not yet called
wait(). [1] All processes exist as zombie processes at some point, but generally
only briefly. Nothing to be done. Once the parent calls wait(), it ceases to be a
zombie.[1]

(ii) Explain the steps that occur when a process terminates. [2]

Process calls exit(). [1/2] Process may return a status value to the parent via the
wait() system call. [1] All the resources of the process are then deallocated by the
OS. [1/2]

Suppose that the following processes arrive for execution at the times
indicated. Each process will run for the amount of time listed. In
answering the question, use non-preemptive scheduling.

Process Arrival Time Burst Time


P1 0 8
P2 1 4
P3 2 1

(iii) Give the order in which the processes will be executed, and calculate the
average turnaround time (not waiting time) for these processes with the SJF
(shortest-job-first) scheduling algorithm. Show your calculations. [3]
P1 will be executed first, then P3, then P2. [1 mark]
Turnaround times
P1: 8 – 0 = 8 [1/2 mark]
P2: 8 + 1 – 2 = 7 [1/2 mark]
P3: 9 + 4 – 1 = 12 [1/2 mark]
Average is (8 + 7 + 12)/3 = 9 [1/2 mark]
Consider the following variant of Peterson’s solution to the Critical
Section problem for two processes i and j.

Algorithm for process i


do {
flag[j] = true;l
turn = i;l
while (flag[i] && turn == i);l
critical section
flag[j] = false;l
remainder section
} while (true);l

(iv) For each of the three criteria for a solution to the Critical Section problem,
indicate whether Peterson’s solution satisfies it, and explain why. [6]

Note, all uses of i and j are simply swapped in the process i and j. So the solution
still works.

Mutual exclusion: Satisfies it. [1] i will access its critical section only if j has
indicated that it’s i’s turn (by setting turn to i). Then j can’t access critical section.
[1]

Progress: Satisfies it. [1] If j is ready then i’s setting of turn to i will ensure j enters
its critical section. And vice versa. [1]

Bounded waiting: Satisfies it. [1] When i leaves critical section, re-entering loop
will set turn to i at which point j will enter its critical section if it was ready (flag[i]
equal to true). [1]

Consider the following solution to the Dining Philosophers Problem (for 5


philosophers) where each entry in the array of semaphores, chopstick[5],
is initialized to 1, and Philosopher i has the structure given below.

do {
wait (chopStick[ (i + 1) % 5] );
wait (chopstick[i] );
// eat
signal (chopstick[ (i + 1) % 5] );
signal (chopstick[i] );
// think
} while (TRUE);

(v) Observe that this is a modified version of the solution provided in the textbook.

a) What is the problem with this solution? [1]

As with the solution provided in the textbook, there is the possibility of deadlock
[1 mark]

b) Provide an asymmetric solution which avoids the problem encountered


above. [3]

For each odd-numbered philosopher i

do {
wait (chopStick[ (i + 1) % 5] );
wait (chopstick[i] );
// eat
signal (chopstick[ (i + 1) % 5] );
signal (chopstick[i] );
// think
} while (TRUE);

For each even-numbered philosopher i

do {
wait (chopstick[i] );
wait (chopStick[ (i + 1) % 5] );
// eat
signal (chopstick[i] );
signal (chopstick[ (i + 1) % 5] );
// think
} while (TRUE);

1 mark for two processes. 1 mark each for switching the order in which the two
procedures pick up chopsticks
Consider the following modified version of the deadlock-
avoidance safety algorithm:
1. Let Work and Finish be vectors of length m and n, respectively,
where m is the number of resources, and n is the number of processes.
Initialize Work := Available and Finish[i] := false for i = 0, 1, ..., n
– 1

2. Find an index i such that both


a. Finish[i] == false

b. Need[i] ≤ Work
If no such i exists, go to step 4.
3. Available = Available + Allocation[i]
Finish[i] = true

Go to step 2

4. Available = Work
If Finish[i] == true for all i, then the system is in a safe state

(vi) Will this algorithm still work as it is supposed to? If not, explain why not. If it will,
explain why. [3]

Yes it will. [1] It stores the contents of Available in Work, then works directly on
Available (uses Available instead of the local variable Work) [1] and then resets
Available to Work. [1]

You might also like