COMPUTER NETWORKING   - Overview

# Application Layer

"7" Layers:
- The application layer
The only layer that directly interacts with data from the user
e.g., **HTTP**(hypertext transfer protocol -Port **80**), HTTPS(Port **443**), DNS(Domain Name System -Port **53**), SMTP(Simple Mail Transfer Protocol -Port **25** / A part of the TCP(Transmission Control Protocol): sending Packet/IP protocol), **FTP**(file transfer protocol), TLS(Transport layer security)>SSL:(to secure the communicate on internet) 

![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/1089224/cd006d62-ec77-bb8a-f636-5256338cfa14.png)

- The **Presentation** layer
Allowing applications to interpret the meaning of data
e.g., encryption, compression, machine-specific conventions(message formatting)
![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/1089224/5a840394-bd2f-816b-9092-c6eac7da6c45.png)


- The **Session** layer
Responsible for *opening and closing* communication between two devices.
e.g., synchronization, checkpointing, recovery of data exchange
![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/1089224/59601f4f-a932-3c86-23b6-fc028fb70c94.png)

- The **Transport** layer
    - **Transfer of data between end users**
    - **Control reliability of links**
e.g., **TCP**, **socket**(combination of an IP address and port number)
![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/1089224/695283d4-3e74-f2e9-ac8a-3e5e972d2917.png)


- The **Network** layer
Responsible for facilitating data (Packet) transfer between two **different** networks
e.g., IP, Routing Protocols(Routers - (main security guard to allow local network to go outside))
![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/1089224/c57c09d0-34c2-7f4b-dd3c-9da26889aa4c.png)


- The **Data Link** layer
The data link layer facilitates data transfer between two devices on the SAME network
 e.g., Ethernet (Enterprise access networks), 802.111(wifi)
![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/1089224/10a2d200-140f-d2fd-0d46-cf9f46e35c6b.png)



- The **Physical** layer
local area network or router physically link to a network.
e.g., fiber
Consisting of cables that are longer than the prescribed length for that physical medium will cause "Data(Packet) Loss" or "Signal Attenuation (increase the attenuation level)".
![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/1089224/cc8f012f-6702-5ad6-882a-ed660ba25434.png)

<img width="300" src="https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/1089224/a70800cb-bd2f-d6f6-b820-588e1038f518.png">

![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/1089224/b2661b4e-788f-56fc-c026-a3d9842c5677.png)

https://commons.wikimedia.org/wiki/File:Osi-model-jb.svg
https://www.khanacademy.org/computing/computers-and-internet/xcae6f4a7ff015e7d:the-internet/xcae6f4a7ff015e7d:the-internet-protocol-suite/a/the-internet-protocols
https://www.cloudflare.com/learning/ddos/glossary/open-systems-interconnection-model-osi/

<a id="#kernel-mode"></a>
# PROTOCOL


<img width="250" src="https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/1089224/038373f3-4331-5d30-7850-98871b3ef1c7.png">

<img width="350" src="https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/1089224/a5fee6d9-22d8-2f2e-6aaa-4c1a730d90d7.png">
http://www2.ic.uff.br/~michael/kr1999/1-introduction/1_02-protocol.htm

.

# Application architectures : Client-server / P2P
2 possible structure of applications:
- **client-server architecture**
Server:
 ・always-on host
・permanent IP address
・data centers for scaling
Clients:
・communicate with server
・may be intermittently connected
・may have dynamic IP addresses
・do not communicate directly with each other

- **peer to peer (P2P)architecture**
・no always-on server
・arbitrary end systems directly communicate
・peers request service from other peers, provide service in return to other peers
・self scalability 
→new peers bring new service capacity, as well as new service demands
・peers are intermittently connected and change IP addresses
→complex management


<img width="600" src="https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/1089224/4be3dfe7-2a20-6647-f3d7-df01ce7562a7.png"> 
<img width="450" src="https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/1089224/38bbf3de-5974-a623-82cd-70f0c8028603.png">
https://www.resilio.com/blog/whats-the-difference-between-peer-to-peer-and-client-server
https://www.geeksforgeeks.org/how-p2p-can-scale-by-itself/

# Distributed Hash Table (DHT)
<img width="450" src="https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/1089224/bfa72338-0270-0fc8-9ecc-87a887c9a4a6.png"> 

# DNS(Domain Name System)
- The **domain name** www.abc.com might **translate** to 198.105.232.4 (**IP address**). 
   - (so that client can load the requested internet resources)
- The Port number for **DNS** is **53**. 
![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/1089224/506c75c7-7317-86d1-1d76-317581df8422.png)
1. **RootNameServer == DNS**
1. **Top-Level Domain (TLD) servers** : com, org, net, edu
1. **Authoritative** servers: organization’s own DNS server


![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/1089224/4d68806d-af76-d620-3861-107e1c3d7d8e.png)

- DNS records:
・type=A
　・name is hostname
　・value is IP address
・type=MX
　・value is name of mailserver associated with name

# Packet / Circuit Switching
- **Packet Switching**
   - **Packet switching is the transfer of small pieces (packets) of data across various networks.**
   - When a message is broken into parts that are sent **independently** depending on what is most **optimum** 
   - resource sharing - good for bursty data
   - excessive congestion possible (packet delay and loss)!!!!!
- **Circuit Switching**
   - Circuit switching is good for **voice transmission** because it has **little transmission delay** and a constant signal transmission signal rate. Well suited to analog transmission of voice signals. 
![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/1089224/d49ee968-ee32-be88-daf3-1f5d5a69f1c9.png)



# LAN, MAN and WAN
LAN stands for local area network.(e.g. university wifi) 
MAN stands for metropolitan area network.
WAN stands for wide area network.
![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/1089224/1eadd713-1dde-286a-0238-80c35439c004.png)

# TCP / UDP
- **TCP(Transmission Control Protocol)** sends packet data across the internet so that the application and computing devices can **communicate**
- Web servers typically bind to the **TCP port 80**
- **Additive Increase Multiplicative Decrease**: to handle TCP congestion control
    - When the source receives an unmarked control packet (i.e., with a 0 congestion control bit), it additively increases its rate; on the other hand, when the source receives a marked control packet, it multiplicatively decreases its rate (i.e., the rate is decreased by an amount proportional to the current rate).
- **UDP(User Datagram Protocol)** Port 443 is connectionless and does not guarantee reliable communication. i.g. someone can browse a website!

![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/1089224/d15565fa-b415-105a-020b-fcd9d1eb01b1.png)
https://www.wowza.com/blog/udp-vs-tcp

### TCP
- **Fast Retransmit**
   - Fast Retransmit occurs when the sender client retransmits a packet before the expiration of the ackowledgement timer.
   - Sender receive some packets which sequence number are bigger than the acknowledged packets. (3 duplicate ACKs) 
![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/1089224/edd47f84-2334-3e7f-818d-3bd08825aade.png)


# Handshake (TCP)
- ACK <TCP>
   - Ackowledgement
   - sent by TCP server
   - indicate that it has recieved cumulated data and its ready for the next segment
- seq <TCP>
   - TCP sequence
   - sent by TCP client
   - indicate how much datahas been sent for the session

- Time Outs <TCP>
   - TCP client sends a **timeout** when sending a data, and if the data is not aclwledged by ACK from client server, = expired **RTO()Retransmission timeout**, then TCP retransmits the data.
![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/1089224/8abc133c-e1a5-954e-23e3-586aeed31dcc.png)

- 3-Way-Handshake
  - just a reliable TCP connection.
    - SYN → SYN+ACK → SYN  

# DHCP
- **DHCP - Dynamic Host Configuration Protocol: provides an IP host with its IP address**.
- 2 DHCP servers on my network + each gave the same static IP address to 2 different machines => the router will fail to deliver.(= we will run into a duplicate error.)
- A DHCP client uses the DHCP protocol to acquire configuration information, such as an IP address, a default route, and one or more DNS server addresses from a DHCP server.


![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/1089224/70f491ba-7e18-1e24-b346-4259e7c14f2d.png)
https://bluecatnetworks.com/glossary/what-is-dhcp


# Delay (Processing / Queuing / Transmission / Propagation Delay)
**Delay** is defined as the amount of time taken by the **packet** to reach the destination
1. **Processing Delay**
   - Time taken by the processor to process the data packet 
1. **Queuing Delay**
   - Time spent by the data packet waiting in the queue before it is taken for execution
   - Depending on the congestion in the network
1. **Transmission** Delay
   - Time taken to put the data packet on the transmission link
   - **(Length / Size of data packet) / Bandwidth of Network**
1. **Propagation** Delay
   - Time taken for one bit to travel from sender to receiver end of the link 
   - **Distance between sender and receiver / Transmission Speed**

※Bandwidth: The maximum amount of data transmitted over an internet connection in a given amount of time.

![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/1089224/6a257928-f0dc-a162-1036-dd1426ff0e44.png)

# Network Traffic
**Network Traffic** is caused by **Bandwidth Usage** which refers to the maximum rate that data can move among a path.

# Packet Loss
Packet loss occurs by network congestion, hardware issues(loose cable connection), software bugs, a Faulty Router, **bandwidth restriction**

# RIP (Routing Information Protocol)
- Routing Information Protocol (RIP) is a distance-vector routing protocol 
- Routers using Distance Vector Protocols rely on the neighbor's information
- RIP only uses hop count (the number of routers) to determine the best way to a remote network.
- **Metric** : the minimum number of hops(routers crossed) to the network ID 

- Features of RIP:
    - Updates of the network are exchanged periodically
    - Full routing tables are sent in updates
    - Routing info is always broadcast
![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/1089224/4cf94d01-4d44-b2a7-979d-e549da07541c.png)


# Subnet Mask
- Subnet defines our Local Area Network Range 
- Subnet mask is used for partitioning a single physical network into the smaller sub-networks
-  A subnet mask is a number that distinguishes the Network address and the Host address within an IP address. 
-  benefits of subnet masks:
    - allowing orgs to surpass LAN constrains (e.g. max number of host)
    - reducing **network traffic**
       - **Network Traffic** is caused by **Bandwidth Usage** which refers to the maximum rate that data can move amoung a path.

    - reducing broadcast volume
- 
-  ![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/1089224/6ce345fa-434c-85c0-b89b-5af06ec50bbb.png)


※Subnet:  a smaller network within a larger one.
<img width="350" src="https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/1089224/c3c58237-a97d-7a8a-0631-39366022b06b.png">
https://ipcisco.com/lesson/subnetting-examples/

# Gateway
IP address of the Router

# Router / Modem
- Modem establishes and maintains a connection between internet service and our device. The router will take the signal from the modem and connect to more than one device.
- Routers are the devices that do routing and forwarding

<img width="350" src="https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/1089224/780ffa6d-b66a-e7f7-ae0b-2e2bce4fdb6e.png">

### Routing Algorithm
Global, Decentralized, Static, Dynamic
![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/1089224/314bba95-c7b2-699d-d93d-c59e23e7613f.png)



Two key network-core functions:
- Routing (determining source-destination route taken by packets)
- Forwarding (GO!)


### Dijkstra’s Algorithm / Bellman-Ford  Algorithm
- find the shortest path between any two vertices of a graph
- Dijkastra : only positive 
- Bellman-ford : negative ok
![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/1089224/a808470a-5d61-2bc1-6447-97733ecb8345.png)

### BGD (Border Gateway Protocol )
- BGP: Postal Service of the Internet
- AS(Automatic service) :individual post office branches
- 

# Multiplexing (Muxing)
Multiplexing is to gather data from multiple app processes and encelop them with header and send those multiple signals over a common link at the same time over a shared medium.
![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/1089224/56e7b016-afc4-a33e-129a-a0d58eada767.png)

# Broadcast / Multicast Routing
- Broadcast transfers a message to all recipients
- Multicast transmits to a *group* of destination computers simultaneously

# RTT
- **RTT - Round Trip Time**:The duration from when a **browser** sends a request to when the browser receives a response from a server
- **RTT = 2 x propagation time** : Persistent HTTP
- 2 types of HTTP connections:
   - **persistent HTTP** :  (response time: **RTT = 2 x propagation time**)
     - multi objects can be sent over single TCP connection between client-server
   - **non-persistent HTTP** (response time: **2** x RTT + file transmission time)

# HTTP
         
-  **HTTP** use **TCP**(reliable/connection base)
- HTTP request message : ASCII / request,response
- An **HTTP Status Code** is a message a website's **server** sends to the **browser** to indicate whether or not that request can be fulfilled.
  - HTTP **200** : the request(connection) has succeeded 
  - HTTP **404**: Not found
  - HTTP **505**: HTTP version not supported

# Internet

- transmission rate: bandwidth
- Packet switches: routers and switches
- cable network: sharing network access
- many processes can be running on same host
- to receive messages, process must have identifier (IP address, {prt numbers(HTTP 80(TCP), mail server: 25))
![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/1089224/1dee83cb-cb05-9f30-a42d-d6f9a19e42dc.png)

- DoS (Denial of Service)

- Cookies: keeping "**State**"
- **Web Caches** :
  -  Storing data for reuse, such as a copy of a web page served by a web server
  -   Stores the first time when a user visits the page so that from 2nd time, the page does not have to be overloaded from the origin server.

  - Conditional GET
     - Not to send an object if the cache has an up-to-date cached version

- **Proxy Server**
   - Provide a gateway between the client(requesting a resource) and the server(providing a resource)
   - e.g., (HTTP, SMTP, Proxy cache is to store inf at the intermediate server(not the visitor's local drives))

- Mail access protocols e.g., gmail. yahoo mail
・IMAP
・pop3 (**Receiving** email -Port **110**)
・SMTP(**sending NEW** email -Port **25**)
・HTTP (e.g., gmail, yahoo mail - Port **80**)

- IP address: Uniquely defines a device on a network

- ISP : internet service provider

- *Internet Protocols*:
   - HTTPS (Hyper text transfer protocol secure): google.com(any website)
   - HTTP
      - HTTPS is HTTP with **encryption**.
        HTTP uses TLS(SSL) to encrypt HTTP request and response.
   - FTP (File transfer protocol) ,e.g., Dropbox
   - SMTP(Simple mail transport protocol) e.g. smtp.
   - IP (Internet protocol)
   - TCP (Transmission Control Protocol)
   - UDP (User datagram protocol)
   - POP3
 
- PORTS:
   - •20 & 21 - FTP Data Transfer and Command Control
•22 - SSH
•25 - SMTP
•53 - DNS
•80 - HTTP
•110 - POP3
•443 - HTTPS
•139 & 445 - SMB
   -The Server Message Block protocol (SMB protocol) is a client-server communication protocol used for sharing access to files, printers, serial ports and other resources on a network.