Packet Traveling

Two models of network: TCP/IP model, OSI model

concept

The client is the entity that initiates the request, the server is the entity that receives the request, and the network is simply two or more connected devices connected together

Comparison between TCP/IP model and OSI model

The OSI model:

  • First physical layer: anything that carries ones and zeros between two nodes, network cables, Repeaters, wifi

  • Layer 2 data link layer: Combine these ones and zeros into blocks called frames. There is an addressing system called a media access control address or MAC address. A MAC address uniquely identifies each individual NIC (network card). Each nic is preconfigured with a MAC address by the manufacturer; In fact, it is sometimes called a Burned address (BIA). Passing packets from one NIC to another (passing packets from one hop to another.

  • Layer 3 Network layer: Responsible for end-to-end packet transfer. An addressing scheme that uses IP addresses (Internet protocol addresses). The main device is a router, which facilitates communication between networks.

  • The fourth transport layer is responsible for distinguishing network traffic using an addressing scheme called port numbers

  • Layers five, six, and seven: The session, presentation, and application layers handle the final steps before data transmitted over the network (facilitated by layers 1-4) is displayed to the end user.

OSI layer 2 and 3

  • Layer 2 uses MAC addresses and is responsible for passing packets from hop to hop.
  • Layer 3 uses IP addresses and is responsible for the end-to-end transmission of packets.

IP header: includes source IP address and destination IP address

MAC address header: includes the source MAC address and destination MAC address

Between each router, the MAC address header is stripped and regenerated to make it to the next hop. The first computer-generated IP header was stripped only by the last computer, so the IP header handles “end-to-end” delivery, whereas each of the four different MAC headers involved in the animation handles “skip” delivery.

summary

The primary purpose of the OSI layers

  • OSI Layer 1 is the physical medium that transmits 1s and 0s over a network
  • OSI Layer 2 is responsible for skip delivery and uses MAC addresses
  • OSI Layer 3 is responsible for end-to-end delivery and the use of IP addresses
  • OSI Layer 4 is responsible for service-to-service delivery and uses port numbers

The actor who passes the packet

  • Switches facilitate communication within the network and operate at Layer 2
  • Routers facilitate communication between networks and operate at Layer 3
  • ARP resolves unknown MAC addresses using known IP addresses

Storage of table

  • The switch uses a MAC address table that maps the switch port to the connected MAC address
  • A router uses a routing table, which is a mapping of a known network to an interface or next-hop address
  • All L3 devices use the ARP table, which maps IP addresses to MAC addresses

Address Resolution Protocol (ARP)

  • ARP obtains MAC addresses from IP addresses and stores the obtained results in the ARP table, which is a mapping between IP addresses and MAC addresses. ARP tables are populated “on demand”. ARP helps clients create correct L2 headers based on L3 headers to pass packets from one hop to the next.

ARP table:

ARP request example:

  • When a client attempts to talk with a host on the same network, the client sends an ARP request for the host MAC address.

    Layer 2 header:

  • When a client attempts to talk with a host on the external network, the client sends an ARP request for the MAC address of the default gateway.

    Layer 2 header:

  • ARP When a client talks with a host on the same network, it ARP for the MAC address of the host. When a client talks with a host on a different network, it ARP for the MAC address of the default gateway

  • Note that any device that intends to forward packets based on IP address (L3) must also be capable of passing packets to the next hop (L2). Therefore, any device that uses an IP address must also use ARP to transmit packets using a MAC address. Therefore, all Layer 3 devices must maintain an ARP table.

Interhost communication

The two hosts are directly connected

  • Host A sends A request to host B

The host is an L3 device and has an ARP table that is initially empty. To send a request, it needs to construct an L3 L2 header, construct an L2 header, and send an ARP request. The ARP request is sent as a broadcast (ARP request is a separate packet, essentially a query: “If anyone is using IP 10.10.10.20, please send me your MAC address. “), the host receives the request, sends an ARP response as a unicast message, and adds the host IP-MAC address to the ARP table

Connect to hosts through switches

  • Host A sends A request to host B

Host B stores the IP-MAC address in the ARP table. Host A obtains the MAC address and constructs A request to initiate A request.

switches

  • The main purpose is to facilitate communication within the network, which operates by maintaining a MAC address table (mapping the MAC addresses of the devices plugged into each switch port), which is populated by looking at the source MAC address field of any received frame.

To forward the frame, the switch searches the MAC address table to find the port used by the target MAC address. If it cannot find the port, it floods the port that obtained the MAC address

  • function

(1) Learning: Create a MAC address table and map each switch port to the MAC address of the connected device.

(2) Flooding: It is inevitable that at some point the switch will receive a frame destined for a MAC address whose location the switch does not know. In this case, the only option for the switch is to simply copy the frame and send it to all ports. The NIC of each connected device will receive the frame and view the target MAC address field. If they are not the intended recipient, they will simply silently drop frames. When the target device receives this frame, a response is generated that, when sent to the switch, allows the switch to learn and create a MAC address table that maps the unknown device to its switch port.

(3) Forwarding: The switch can forward frames in three ways:

  • Store and forward. The switch copies the entire frame (header + data) into the memory buffer and checks the frame for errors before forwarding it. The slowest

    • Straight through. The switch stores nothing and only checks the minimum required to read the target MAC address and forward the frame. Speed is fast
  • A mixture of the first two methods. Before forwarding the frame, the switch checks only the first part (64 bytes) of the frame. If a transmission error occurs, it is usually noticed within the first 64 bytes. Provides “good enough” error detection for speed and efficiency to avoid storing the entire frame in its memory before forwarding.

    • In modern times, with wire speed switching, the speed difference between these three is negligible, and most switches operate in store and forward mode.

(4) Filtering: The switch will never forward a frame back to the same port as the sender.

(5) Broadcast: Broadcast frames are sent to everyone on the local network. The target MAC address field is filled with a special address: FFff.FFff.FFFF. The “all F” address is reserved exclusively for broadcasting purposes. Because the address FFff.FFff.FFFF is reserved, the switch cannot learn MAC address table mapping for it. Therefore, any frames sent to that MAC address will always be flooded.

The router

  • The main purpose is to facilitate communication between networks and to maintain the operation of routing tables, which contain paths to all networks that the router knows how to reach.

  • Route self-learning: direct routes, static routes, and dynamic routes

  • From each router’s point of view, the routing table is a mapping that exists for each network. Therefore, when a router receives a packet destined for a network that is not in its routing table, the packet is discarded.

  • function

(1) Fill and maintain routing tables and ARP tables

(2) Populate routes

  • Direct routing: When a router interface is configured with a specific IP address, the router knows the network to which it is directly connected.

  • Static routes: Static routes are manually configured by the administrator.

  • Dynamic routing: Routers automatically detect and talk to each other to inform each other of their known routes. Multiple protocols can be used for dynamic routing, each representing a different policy

(3) If a router receives a packet from a network that is not in the routing table, the network must not exist as far as the router is concerned.

Packet encapsulation and decapsulation

How data moves from top to bottom when it is sent and from bottom to top when it is received.

As data is passed from one layer to another, each layer adds the information needed to accomplish its goals before the complete datagram is converted into ones and zeros and sent over the wire. Such as:

  • Layer 4 adds a TCP header that includes both source and destination ports
  • Layer 3 adds an IP header that includes both source and destination IP addresses
  • Layer 2 adds an Ethernet header that includes both source and destination MAC addresses

The Ethernet header, IP header, and TCP header are reversely stripped during decapsulation

Transmission of packets

  • The network topology is as follows:

For simplicity, the following MAC addresses are in hexadecimal notation

  • 1. Host A sends data to host B. Host A encapsulates the data packet and sends it to router R1, which forwards the data packet to host B. Host B receives the data packet and decapsulates it

    Host A sends A packet to router R1

    Router R1 is the default gateway of 11.11.11.x. If router R1 is not recorded in host A’s ARP table, host A sends an ARP request to obtain the MAC address of router R1. The data packet is as follows:

    L3 L2
    The SRC (source IP) : 11.11.11.17 SRC(source MAC address): aAAA
    DST(target IP address): 22.22.22.88 DST(destination MAC address): AA11

    R1 forwards packets to host B

    If the ARP table of router R1 has the MAC address of host B (if no MAC address is available, router R1 sends an ARP request to obtain the MAC address), router R1 strips out the L2 header and generates a new L2 header (the MAC address is transmitted from this hop to the next hop). The generated data packets are as follows:

    L3 L2
    The SRC (source IP) : 11.11.11.17 SRC(source MAC address): bb11
    DST(target IP address): 22.22.22.88 DST(destination MAC address): BBBB
  • 2. Host A sends data packets to host C. Host A sends data packets to router R1, which forwards the data packets to Router R2, which forwards the data packets to host C. Host C receives the data packets and decapsulates them

    Host A sends A packet to router R1

    Router R1 is the default gateway of 11.11.11.x. If router R1 is not recorded in host A’s ARP table, host A sends an ARP request to obtain the MAC address of router R1. The data packet is as follows:

    L3 L2
    The SRC (source IP) : 11.11.11.17 SRC(source MAC address): aAAA
    DST(target IP address): 22.22.22.88 DST(destination MAC address): AA11

    R1 forwards packets to router R2

    If the ARP table of router R1 has the MAC address of router R2 (if there is no MAC address, an ARP request is sent to obtain the MAC address), the ROUTER removes the L2 header and generates a new L2 header (the MAC address is transmitted from this hop to the next hop). The generated data packets are as follows:

    L3 L2
    The SRC (source IP) : 11.11.11.17 SRC(source MAC address): bb11
    DST(target IP address): 22.22.22.88 DST(destination MAC address): BB22

    R2 forwards data packets to host C

    If the ARP table of Router R2 has the MAC address of host C (if no MAC address is available, an ARP request is sent to obtain the MAC address), the ROUTER strips out the L2 header and generates a new L2 header (the MAC address is transmitted from this hop to the next hop). The generated data packets are as follows:

    L3 L2
    The SRC (source IP) : 11.11.11.17 SRC: cc22
    DST(target IP address): 22.22.22.88 DST(destination MAC address): CCCC

Most of the materials in this article are from the Internet. I just wrote a blog to sort out the summary for deeper understanding. If there are any shortcomings, please point out in the comments section.