---
# System prepended metadata

title: IEFT 1115

---

# IEFT 1115

---

[TOC]

---

## Chapter 1

### Access network
- **DSL**
    - Dedicated
- **Cable network**
    - Shared
    - FDM

### Physical media
- **Twisted pair (TP)**
    - Two insulated copper wires
- **Coaxial cable**
    - Two concentric copper conductors
- **Fiber optic cable**
    - Glass fiber carrying light pulses, each pulse a bit
    - High speed
    - Low error rate

### Network core
#### Packet Switching
- Shared
- Hosts break application-layer messages into packets
- **Store and forward**
    - Get ENTIRE packet and transmit it
- **Queuing and loss**

#### Circuit switching
- Dedicated
- End-end resources allocated to, reserved for “call” between source & dest
- **FDM** & **TDM**

### Packet Delay
![](https://i.imgur.com/OSKFSoR.png =400x)
![](https://i.imgur.com/Q3BAUtg.png =400x)
![](https://i.imgur.com/Xr8FqM7.png =400x)
![](https://i.imgur.com/ub5vFco.png =500x)
- **Bandwidth-Delay Product**: $R \times d_{\text{prop}}$
- **Average longest**: Queuing delay
    ![](https://i.imgur.com/NLB9Ikf.png =250x)

### Traceroute
- **TTL** (Time to live)

![](https://i.imgur.com/HydDnhS.png =500x)


### Model layers
|   ISO/OSI model    |   TCP/IP model    |                 PDU                  |
|:------------------:|:-----------------:|:------------------------------------:|
| Application Layer  | Application Layer |               Message                |
| Presentation Layer |         ▲         |                  ▲                   |
|   Session Layer    |         ▲         |                  ▲                   |
|  Transport Layer   |  Transport Layer  | <!--*TCP:* Segment </br> *UDP:* Datagram--> Segment |
|   Network Layer    |   Network Layer   |    <!--IP Datagram </br> (IP Packet)--> Datagram    |
|     Link Layer     |  Data Link Layer  |            <!--Ethernet Frame--> Frame           |
|   Physical Layer   |  Physical Layer   |                 Bits                 |

### Encapsulation & Decapsulation
![](https://i.imgur.com/4ayYudt.png =500x)
- **Repeater**
    - Physical Layer
- **Switch**
    - Link layer
    - MAC address in header
- **Router**
    - Network layer
    - IP address in header
- **Gateway**
    - More

### Attacks
- **Virus**
    - self-replicating infection by receiving/executing object (e.g., e-mail attachment)
- **Worm**
    - self-replicating infection by passively receiving object that gets itself executed
- **Botnet**
    - Enrolling infected hosts
- **DDoS**
    ![](https://i.imgur.com/4Q3z4Pj.png =500x)
    - Attackers make resources (server, bandwidth) unavailable to legitimate traffic by overwhelming resource with bogus traffic
- **Packet sniffing** (Wireshark)
    ![](https://i.imgur.com/d3wCWY3.png =500x)
- **IP spoofing**
    ![](https://i.imgur.com/NXal6is.png =500x)

### Cerf and Kahn’s Internet Working Principles
- **Minimalism**, **autonomy**
    no internal changes required to interconnect networks
- **Best effort service model**
- **Stateless routers**
- **Decentralized control**


## Chapter 2

### Socket
- **Identifiers**
    - IP address
    - Port numbers
- **SSL** in app layer

### ==Application use TCP or UDP== {!}
- **TCP**
    - E-mail: **SMTP**
    - Remote terminal access: **Telnet**
    - Web: **HTTP**
    - File transfer: **FTP**
- **TCP** or **UDP**
    - Streaming multimedia: **HTTP**, **RTP**
    - Internet telephony: **SIP**, **RTP**, proprietary (Skype)
- Wiki:
    - **TCP**
        - **HTTP**, **HTTPS**, **FTP**, **POP3**, **SMTP**, **TELNET**, **SSH**
    - **UDP**
        - **BOOTP**, **NTP**, **DHCP**
    - **TCP** and **UDP**
        - **DNS**, **ECHO**, **SNMP**, **ARP**

### HTTP
- **Client-server**, **TCP**, **Stateless**
- **Cookies**
    - User-server state
- **Conditional GET**
    - **`If-modified-since: <date>`**
    - 304 Not Modified
- **Non-persistent**
    - Sent one object in one TCP connection
    - One object
        - 2 * **RTT** + transmission time
- **Persistent**
    - Sent multiple objects in one TCP connection
    - All Objects
        - 1 * **RTT**
        - as little as one RTT for all the referenced objects

![](https://i.imgur.com/9sk4diA.png =500x)
![](https://i.imgur.com/atPhOGH.png =200x)

### Proxy server / web caches
- **Goal**
    - Satisfy client request without involving origin server

![](https://i.imgur.com/ikLPc2k.png =200x)


### SMTP
- Between mail servers to send email messages
- Multiple objects sent in multipart message
![](https://i.imgur.com/0WcjeaX.png =500x)
- **Mail access protocol**
    - **POP**
        - **Stateless**, **Users**, **Download**
    - **IMAP**
        - **Keep user state**, **Keep mails in server**

### ==DNS== {i}
- Hostname to IP address translation
- **Distributed** (**hierarchical**) database
    Application-layer protocol
- Root name servers
    Top-level domain (TLD) servers
    Authoritative DNS servers
    Local (default) DNS name server
- **Caches** when learning mapping
    Out-of-date perhaps
- Insert Record
    - **DNS registrar**
    - Create A and NS record
- Attack DNS
    - **DDoS**
        - Root servers
        - TLD
    - **Redirect attack**
    - **Exploit DNS for DDoS**

### ==DNS resolution== {!}
- **Iterated query**
    - Contacted server replies with name of server to contact
- **Recursive query**
    - Puts burden of name resolution on contacted name server
    - Heavy load at upper levels of hierarchy

### ==DNS RR format== {!}
- **Format**: **`(name, value, type, ttl)`**
- **Hostname**: name of end-point
    **Domain**: name of network
- **`type`: `A`**
    - `name`: hostname
    - `value`: IP address
- **`type`: `NS`**
    - `name`: domain
    - `value`: hostname of authoritative name server for this domain
- **`type`: `CNAME`**
    - `name`: alias name for some “canonical” (the real) name
    - `value`: canonical name
- **`type`: `MX`**
    - `value`: name of mailserver associated with `name`

### P2P
- **Torrent**
    - Group of peers exchanging  chunks of a file
- **Tracker**
    - Tracks peers participating in torrent
- **churn**
    - peers may come and go
- **BitTorrent**
    - Requesting chunks
    - Sending chunks: **tit-for-tat**
        - every 30 secs: randomly select another peer, starts sending chunks

### File Distribution Time
![](https://i.imgur.com/pT1imow.png =400x)
- Time to distribute $F$ to $N$ clients
    - **Client-server**:
        $D_{\text{C-S}} \ge \max{\{N\frac{F}{u_s},\ \frac{F}{d_{\text{min}}}\}}$
    - **P2P**:
        $D_{\text{P2P}} \ge \max{\{\frac{F}{u_s},\ \frac{F}{d_{\text{min}}},\ N\frac{F}{(u_s + \sum{u_i})}\}}$
        - **Self scalability**

### CDN
- **Video**
    - Coding
        - **Spatial** (witin image)
        - **Temporal** (between images)
    - Bit rate
        - **CBR** (constant bit rate)
        - **VBR** (variable bit rate)
- **DASH** (Dynamic, Adaptive Streaming over HTTP)
    - Server
        - Videos into **chunks** in different rates
        - **Manifest File**: provides URLs for different chunks
    - Client
        - Measure **bandwidth**
        - **Request one chunk** at a time
    - Intelligence at client
        - **When** to request
        - **What** encoding rate
        - **Where** to request
- **CDN**
    - Stores copies of content at CDN nodes
    - **OTT** challenges

### Message Formats
#### DNS Query & Reply
![](https://i.imgur.com/2nKF01Y.png =200x)![](https://i.imgur.com/yJOz6Qu.png =450x)

#### HTTP Request
![](https://i.imgur.com/swQaIl4.png =500x)

#### Mail
![](https://i.imgur.com/Yy7kofn.png =500x)

### ==Socket Programming== {!}
- [**Tutorial**](https://github.com/davidleitw/socket)
- TCP
    ![](https://i.imgur.com/pzTVt3c.png =400x)
:::spoiler Others
![](https://i.imgur.com/yEzkQB5.png =500x)

---
![](https://i.imgur.com/7PBPdp5.png =500x)
:::
- ==**Functions**==
    Include **`<sys/socket.h>`**
    - [**socket()**](https://man7.org/linux/man-pages/man2/socket.2.html)
        - Create an endpoint for communication
    - [**bind()**](https://man7.org/linux/man-pages/man2/bind.2.html)
        - Bind a name to a socket
        - ==Attaches a local address to a socket.==
    - [**listen()**](https://man7.org/linux/man-pages/man2/listen.2.html)
        - Listen for connections on a socket
        - ==**`backlog`**==
            - 允許進入 queue 的最大連線數量
                在 server 端還沒有 accept 之前，最多能允許幾個 socket 申請 connect
            - The maximum length to which the queue of pending connections for `sockfd` may grow
    - [**accept()**](https://man7.org/linux/man-pages/man2/accept.2.html)
        - Accept a connection on a socket
    - [**connect()**](https://man7.org/linux/man-pages/man2/connect.2.html)
        - Initiate a connection on a socket
    - [**recvfrom()**](https://man7.org/linux/man-pages/man2/recv.2.html)
        - Receive a message from a socket
    - [**sendto()**](https://man7.org/linux/man-pages/man2/send.2.html)
        - Send a message on a socket
    - [**close()**](https://man7.org/linux/man-pages/man2/close.2.html)
        - Close a file descriptor


## Chapter 3

### Transport layer
- Comparison
    - Network layer
        - Logical communication between **hosts**
    - Transport layer
        - logical communication between **processes**

### Multiplexing & demultiplexing
- **Multiplexing at sender**
    **Demultiplexing at receiver**
- **TCP socket identifying**
    - Source IP address
    - Source port number
    - Destination IP address
    - Destination port number

### Segment Formats
#### UDP
![](https://i.imgur.com/S0qbR4f.png =500x)

#### TCP
<font color="red" size="5em">Out of Range!!!</font>
![](https://i.imgur.com/Kntp4ct.png =500x)

### TCP & UDP
![](https://i.imgur.com/1EYuE95.png =250x) ![](https://i.imgur.com/xP9XOeX.png =250x)
![](https://i.imgur.com/4p2ef3p.png =500x)

### RDT
![](https://i.imgur.com/2HqQtly.png =500x)

#### rdt 1.0
- No bit errors
- No loss of packet
![](https://i.imgur.com/rzJU6ss.png =500x)

#### rdt 2.0
- Bit error
    - **Checksum** to detect bit errors
    - **ACK**, **NAK**
- No loss of packet

![](https://i.imgur.com/DrHAe0G.png =500x)

#### rdt 2.1
- **Check** ACK and NAK
- **Stop and wait**: two packet with seq 0 and 1
<font color="#CC0000" size="5em">**sender**</font>
![](https://i.imgur.com/qTRwIGz.png =500x)
<font color="#CC0000" size="5em">**receiver**</font>
![](https://i.imgur.com/uP87t9a.png =600x)

#### rdt 2.2
- **NAK-free**
    - Receiver sends **ACK** for last pkt received OK
- **Explicitly include seq number** in **ACK**

![](https://i.imgur.com/uuaQwvZ.png =500x)

#### rdt 3.0
- Bit error
- Loss of packet
    - **Timer** for sender to wait ACKs

![](https://i.imgur.com/XBHiEM0.png =500x)
![](https://i.imgur.com/MVu63Pk.png =500x)

#### Performance of rdt 3.0
- **Utilization**: fraction of time busy sending
    $U_{\text{sender}} = \frac{L / R}{RTT + L / R}$

