# 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




- **Bandwidth-Delay Product**: $R \times d_{\text{prop}}$
- **Average longest**: Queuing delay

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

### 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

- **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**

- Attackers make resources (server, bandwidth) unavailable to legitimate traffic by overwhelming resource with bogus traffic
- **Packet sniffing** (Wireshark)

- **IP spoofing**

### 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


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

### SMTP
- Between mail servers to send email messages
- Multiple objects sent in multipart message

- **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

- 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

#### HTTP Request

#### Mail

### ==Socket Programming== {!}
- [**Tutorial**](https://github.com/davidleitw/socket)
- TCP

:::spoiler Others

---

:::
- ==**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

#### TCP
<font color="red" size="5em">Out of Range!!!</font>

### TCP & UDP
 

### RDT

#### rdt 1.0
- No bit errors
- No loss of packet

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

#### rdt 2.1
- **Check** ACK and NAK
- **Stop and wait**: two packet with seq 0 and 1
<font color="#CC0000" size="5em">**sender**</font>

<font color="#CC0000" size="5em">**receiver**</font>

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

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


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