\chapter{Networks}

A \textit{network} is a system involving two or more computers that are
connected, allowing them to \textbf{communicate}. A computer not
connected to a network is a \textit{stand alone computer}.

Networks allows the easy sharing of data, file, backups, and
peripherals (such as printers). Networks also allow for efficient and
high volume communication and can reduce the cost of computing.
However, a network can also allow hacking and the spread of viruses.
Networks require additional security measures and potentially
specialist equipment or staff at additional expense.

We typically identify three classes of network:

\begin{itemize}
    \item A personal area network (PAN) exists in the range of a
        single person. This may include an individuals devices that
        are networked such as a computer, mobile phone, or tablet and
        other devices connected by network such as Bluethooth
        headphones or USB devices.
    \item A large area network (LAN) covers a small geographical area.
        This could be anything from a single home to a university and
        thereby can vary in complexity and scale. Twisted pair cables
        (Ethernet) and Wi-Fi are commonplace in a LAN.
    \item A wide area network (WAN) covers a large geographical area.
        The Internet is a very large WAN through the use of fibre
        optic cables, often undersea, reaching every continent other
        than Antarctica
        \footnote{\url{https://en.wikipedia.org/wiki/Submarine_communications_cable}}
        (which is nonetheless served by satellite Internet links).
        Organisations with significant sums of money may also
        create a WAN for the transfer of large amounts of data or
        speed critical transfer.
\end{itemize}

\section{Wired networks}

In a wired network the \textit{communication media} is a physical
cable that transmits a signal. A \textit{coaxial cable} is a single
copper cable with shielding. A twisted pair cable is also copper but
can transmit data at a higher \textit{bandwidth} and is flexible
whilst coaxial cable is not. Fibre optic cables are made of glass and
transmit light.

Copper cables are cheap and generally compatible with existing
hardware, but are easy to \textit{eavesdrop} on and cannot transmit
data at longer distances. Fibre optic cables are better for long
distance communications and are much higher bandwidth than copper.
They are also lightweight and hard to eavesdrop on. However fibre
optic cables are very expensive and often require new infrastructure
in order to use.

\section{Wireless networks}

Wireless networks send data by transmitting and receiving
\textit{electromagnetic radiation} (generally radio waves). A wireless
access point (WAP) transmits and receives this data for many devices
and is often built into modern household routers. Wi-Fi removes the
need for cables which are expensive and inconvinient. However the
range, speed, and bandwidth of Wi-Fi are limited. Transmission is 
limited by interference (such as thick walls or metal construction)
and the signal can be easily intercepted causing the need for further
security measures.

\section{Network topology}

The topology of a network describes the layout of network devices and
allow the planning of suitable network infrastructure.

\subsection{Bus topology}

\begin{center}
\begin{tikzpicture}
    \draw (0,0) edge[*-*] (12,0);
    \draw [-o] (2,0) -- (2,-2);
    \draw [-o] (4,0) -- (4,2);
    \draw [-o] (6,0) -- (6,-2);
    \draw [-o] (8,0) -- (8,2);
    \draw [-o] (10,0) -- (10,-2);
\end{tikzpicture}
\end{center}

In the bus topology, nodes (devices or computers) are connected along
the \textit{backbone}, each sending and receiving data.
\textit{Terminators} are positioned at each end of the backbone to
prevent the signal \textit{bouncing} and transmitting to the devices
again.

A bus topology is cheap and scalable, but the backbone is a single
point of failure and can be eavesdropped on, leading to the compromise
of all data. Data sent by one device is received by all other devices
thus compromising privacy and only one device can send data on the
backbone at a time, thus slowing the network.

\subsection{Star topology}


\begin{center}
\begin{tikzpicture}
    \filldraw (0,0) circle (3pt);
    \draw [-o] (0,0) -- (7,0);
    \draw [-o] (0,0) -- (5,3);
    \draw [-o] (0,0) -- (-4,2);
    \draw [-o] (0,0) -- (-3,-1);
    \draw [-o] (0,0) -- (2,-2);
    \draw [-o] (0,0) -- (0,2.5);
\end{tikzpicture}
\end{center}

The star topology is designed with a central device; either a
\textbf{hub} or a \textbf{switch}. All devices are connected to this
central device. Naturally, this uses far more cable than the bus
topology. A hub will take data and send it to all other nodes in the
network, which creates excess traffic, lends itself to eavesdropping,
and is quite slow. However, hubs are generally outdated and switches
are used. A switch will only route data to the correct segment.
Switches are high performance, secure, scalable, and reliable,
however, they and the cost of cable in the star topology can be quite
expensive. Furthermore, although the backbone of the bus is no longer
a single point of failure, the hub or switch can be.

Modern networks are generally modified versions of the star topology
with a switch in the centre.

\section{The TCP/IP stack and protocols}

A protocol is an agreed method of communication for sharing data.
The \textit{TCP/IP network stack} is perhaps the most popular and
commonly used network protocol stack. Therefore, we consider the stack
and a simplified model of how data is transferred. These are the
\textit{layers} of the stack in order:

\subsection{Application layer}

The application layer is where the user interacts. Because of this the
most commonly known protocols exist on this layer. \textit{Hypertext
Transfer Protocol} (HTTP) is perhaps the most well known protocol. It
is used to describe web pages in a way that is understandable by
humans. Many websites today use HTTPS, the secure version of HTTP
which includes encryption so that a communication that is eavesdropped
on cannot be understood. Other protocols in this layer include the
\textit{File Transfer Protocol} (FTP), and the protcolos used for
email: the \textit{Internet Message Access Protocol} (IMAP) which
receives mail, the \textit{Simple Mail Transfer Protocol} (SMTP) which
sends mail, and the older \textit{Post Office Protocol 3} which also
receives mail.

\subsection{Transport later}

The transport layer establishes basic communications channels,
might ensure that data arrives in the correct order by numbering data,
and potentially ensuring reliability through error checking
information.

The \textit{Transmission Control Protocol} (TCP) is at this layer and
sends data with error checking and ordering information. Data is
ordered at the receiving end and if it is found incorrect by error
checking, then it requested by again. The TCP specifies a
\textit{handshake} procedure that the process must begin with in order
to establish the communication properly. This is therefore a very
reliable protocol, making it useful for message based communications
or transfer of data where there should not be mistakes.

The \textit{User Datagram Protocol} (UDP) is another protocol at this
layer. There is no handshake process, and data is simply sent as a
continuous \textit{bite stream}. If the data received contains errors
or is missing there is no process to repair this. The protocol is
therefore very fast but not as reliable as TCP. Therefore, it is used
in cases such as video streaming, where small errors or some missing
data is acceptable.

\subsection{Network layer}

The network layer is responsible for addressing and routing packets of
data. Each packet contains a source, destination, a small amount of
data, and error checking information. The \textit{Internet Protocol}
(IP) is the standard protocol at this layer, and specifies addresses
with the IPv4 standard, which uses a 32 bit address giving around 4.3
billion unique addresses. This is being replaced by IPv6 which uses
128 bit addresses to yield around $3.4 \times 10^{38}$ unique
addresses
\footnote{\url{https://en.wikipedia.org/wiki/Internet_Protocol}}.

\subsection{Data link layer}

The data link layer converts the data produced by the above layers
into signals that will be sent over the network. This consists of the
network hardware. In particular, networked computers have a
\textit{Network Interface Card}, which turns the data into electrical
signals. Consumer systems today typically contain a \textit{Wireless
Network Interface Card} which allows communications through Wi-Fi and
Bluetooth.

\subsection{Physical layer}

The physical layer is the communication media and method by which
data is transferred, such as the Ethernet standard over twisted pair
or Wi-Fi by the use of radio waves.
