\documentclass{article}
\usepackage{amsmath, amssymb}
\usepackage[a4paper, total={6in, 9in}]{geometry}
\usepackage{listings} % For code formatting
\usepackage{xcolor} % For custom colors
\usepackage{graphicx}
\usepackage{fontspec}
\usepackage{subcaption}
\usepackage{wrapfig}
\usepackage{cancel}
\graphicspath{ {./figures/} }
\usepackage{xparse} % Allows advanced command definitions
\newcounter{problemcounter}
\NewDocumentCommand{\problem}{o}{
  \noindent
  \fbox{Problem %
    \IfNoValueTF{#1}
      {\stepcounter{problemcounter}\arabic{problemcounter}} % If no optional arg, use counter
      {#1} % Else, use custom label
  }
}

\setmainfont{UbuntuMono Nerd Font Mono}
% \setmainfont{Iosevka Term}

\title{Computer Networks - Midterm/Final Exam (Example 2)} % Added a placeholder title
\author{B11605076 Cheng-Ru}
\date{\today}

\begin{document}
\maketitle

\section*{Computer Networks Exam Questions}
\hrule
\vspace{0.5em}

\subsection*{Question 1: Quickies (45\%)}
Answer each of the following questions briefly, i.e., in at most a few sentences.

\begin{enumerate}
    \item [(a)] (10\%) What does it mean for a protocol to be \textbf{stateful}? What does it mean for a protocol to be \textbf{stateless}? Give an example of one stateful protocol and one stateless protocol.
    \vspace{2.5cm}
    \item [(b)] (10\%) List four factors that contribute to the \textbf{end-to-end delay} in a packet-switched network. Which of these are constant and which of these depend on the load in the network?
    \vspace{2.5cm}
    \item [(c)] (10\%) Suppose a web server has 500 ongoing TCP connections. How many \textbf{server-side sockets} are used? How many \textbf{server-side ports} are used? (Hint: remember the server implements \texttt{fork()} as introduced in the lecture)
    \vspace{2.5cm}
    \item [(d)] (5\%) What is the purpose/use of the \textbf{UDP checksum}?
    \vspace{1.5cm}
    \item [(e)] (10\%) Suppose you would like to urgently deliver 50 terabytes data from Boston to Los Angeles. You have an available \textbf{1Gbps dedicated link} for data transfer. Would you prefer to transmit the data via this link or instead use \textbf{FedEx overnight delivery}? Explain.
    \vspace{2.5cm}
\end{enumerate}

\hrule
\vspace{0.5em}

\subsection*{Question 2: DNS service (15\%)}
Suppose you open a startup company "sky" and want to set up your company network. Your network has the following servers:
\begin{itemize}
    \item DNS server: "\texttt{dns1.sky.com}" with IP "\texttt{140.112.12.40}"
    \item Web server: "\texttt{sky.com}" with IPs "\texttt{140.112.12.55}" and "\texttt{140.112.12.56}". The web server also has a name as "\texttt{www.sky.com}"
    \item Email server: "\texttt{galaxy.sky.com}" with IP "\texttt{140.112.12.60}"
\end{itemize}
Your company's email address is "\texttt{username@sky.com}"

\begin{enumerate}
    \item [(a)] (5\%) What \textbf{resource records (RRs)} do you need to provide to the upper-level "\texttt{.com}" Registrar?
    \vspace{2cm}
    \item [(b)] (10\%) What \textbf{RRs} do you need to put in your company's DNS server?
    \vspace{3cm}
\end{enumerate}

\hrule
\vspace{0.5em}

\subsection*{Question 3: Web (20\%)}
Consider an HTTP client that wants to retrieve a WWW document at a given URL. The IP address of the HTTP server is initially unknown. The WWW object at the URL has one embedded GIF image that resides at the same server as the original object.

\begin{enumerate}
    \item [(a)] (10\%) What \textbf{transport and application layer protocols} besides HTTP are needed in this scenario?
    \vspace{2cm}
    \item [(b)] (10\%) Suppose that the time needed to connect and receive a reply from any server (for any protocol) is $RTT$, and the time to transmit the WWW object and GIF image is $T$. How much time (in $RTT$ and $T$) is needed from when the user first enters the URL until the complete document is displayed? Assume that \textbf{non-persistent HTTP} is used. Consider delay of all protocols in your answer, not just those of HTTP.
    \vspace{2cm}
\end{enumerate}

\hrule
\vspace{0.5em}

\subsection*{Question 4: Socket Programming (6\%)}
Please fill in the corresponding system call (\texttt{socket()}, \texttt{connect()}, \texttt{bind()}, \texttt{accept()}, \texttt{send()}, \texttt{recv()}, \texttt{close()}).

% Using a placeholder for the image content, as actual image insertion is not possible.
% The user provided a link to an image, which typically shows a client-server code flow diagram.
\vspace{0.5cm}
\begin{center}
    \includegraphics[width=0.8\linewidth]{figures/q4.png} % Placeholder for the diagram from the image link
\end{center}
\textit{Fill-in-the-blank for the socket system calls in the provided diagram.}
\vspace{4cm}

\hrule
\vspace{0.5em}

\subsection*{Question 5: Homework Review (24\%)}
These problems are not the same as homework, which means that we have modified some description. Please be careful when answering.

\begin{enumerate}
    \item [(a)] (3\%) Suppose users share a \textbf{6Mbps link}. Also suppose each user requires \textbf{100Kbps} when transmitting, but each user transmits only \textbf{20\%} of the time. When \textbf{circuit switching} is used, how many users can be supported?
    \vspace{1cm}
    \item [(b)] (3\%) For the remainder of this problem, suppose \textbf{packet switching} is used. Find the probability that a given user is transmitting.
    \vspace{1cm}
    \item [(c)] (3\%) Suppose there are \textbf{120 users}. Find the probability that at any given time, exactly $n$ users are transmitting simultaneously. (Hint: Use the binomial distribution)
    \vspace{1cm}
    \item [(d)] (3\%) Find the probability that there are \textbf{21 or more users} transmitting simultaneously.
    \vspace{1cm}
\end{enumerate}

\subsubsection*{True or False (12\%)}
\begin{enumerate}
    \setcounter{enumi}{4} % Continue enumeration from the last part
    \item [(e)] (3\%) A user requests a Web page that consists of some text and three images. For this page, the client will send four request messages and receive four response messages.
    \vspace{1.5cm}
    \item [(f)] (3\%) With \textbf{non-persistent connection} between browser and origin server, it is possible for a single TCP segment to carry two distinct HTTP request messages.
    \vspace{1.5cm}
    \item [(g)] (3\%) HTTP response messages can have an \textbf{empty message body}.
    \vspace{1.5cm}
    \item [(h)] (3\%) The \texttt{Date:} header in the HTTP response message indicates when the object in the response was \textbf{last modified}.
    \vspace{1.5cm}
\end{enumerate}

\end{document}
