In order to better promote the research and development of the Internet, the international organization for Standardization ISO developed the network interconnection model in 1985

OSI (Open System Interconnect Reference Model), with 7 layers structure

7 Application Layer
6 Presentation Layer
5 Session Layer
4 Transport Layer
3 Network Layer
2 Data Link Layer
1 Physical Layer

TCP/IP protocol

4 Application Layer
3 Transport Layer
2 Internet Layer
1 Network Access

Study the

5 Application Layer
4 Transport Layer
3 Network Layer
2 Data Link Layer
1 Physical Layer

The network layer

5 Application Layer FTP, HTTP, SMTP, DNS, DHCP Packets and user data
4 Transport Layer TCP UDP Segment (Segments)
3 Network Layer IP ARP ICMP Packets (Packets)
2 Data Link Layer CSMA/CD PPP The frame (Frames)
1 Physical Layer Bit streams (Bits)

1. Physical layer

The physical layer defines interface standards, cable standards, transmission rates, and transmission modes

Analog Signal

Continuous signal suitable for long distance transmission

Poor anti-interference ability, waveform distortion is difficult to correct when disturbed

Digital Signal

Discrete signals, not suitable for long distance transmission

Strong anti-interference ability, waveform distortion can be repaired when disturbed

Data communication model

Channel

Channel: The channel through which information is transmitted. There can be more than one channel on a transmission medium (such as a network cable)

  • Simplex communication

    A signal can only be transmitted in one direction, and the direction of transmission cannot be changed at any time

    Such as radio broadcasting, cable television broadcasting

  • Half duplex communication

    Signals can be transmitted in both directions, but they must be transmitted alternately, only in one direction at a time

    Like walkie-talkies

  • Full duplex communication

    Signals can be transmitted both ways simultaneously

    Like cell phones (making calls, hearing at the same time)

2. Data Link layer

Link: A physical line (wired or wireless) from one node to an adjacent node, with no other switching nodes in between

Data link: When data is transmitted over a link, a corresponding communication protocol is required to control data transmission

Different types of data links may use different communication protocols

  • Broadcast channel: CSMA/CD protocol (e.g. network of coaxial cables, hubs, etc.)

  • Point-to-point channel: PPP (e.g. channel between 2 routers)

Three basic problems with the data link layer

  • Encapsulated into a frame
  • Transparent transmission
  • Error inspection

Encapsulated into a frame

  • The data part of a Frame

    Is the Packet (IP Packet, Packet) transmitted from the network layer.

  • Maximum Transfer Unit (MTU)

    Each data link layer protocol sets an upper limit on the data length of frames that can be transmitted. The MTU on the Ethernet is 1500 bytes

Transparent transmission

Use SOH (Start Of Header) : as the frame Start character

End Of Transmission (EOT) : is used as the frame terminator

Once SOH and EOT appear in the data part, it needs to be escaped

Error inspection

FCS: calculated according to the data part + head

CSMA/CD protocol

CSMA/CD (Carrier Sense Multiple Access with Collision Detection)

Carrier sense multiple access, collision detection

A network using CSMA/CD is called Ethernet, which transmits Ethernet frames

Ethernet frames are in Ethernet V2 standard and IEEE 802.3 standard

The most used standard is Ethernet V2

Ethernet frames need to be at least 64 bytes in order to be able to detect whether a conflict is occurring

Networks built with switches already support full-duplex communication, eliminating the need for CSMA/CD, but still transmit Ethernet frames

So a network of switches can still be called an Ethernet

Ethernet

Ethernet V2 frame format

  • Header: Destination MAC address + source MAC address + network type

  • Ethernet frames: header + data + FCS

  • The data length must be at least 46 bytes

  • When the length of the data part is less than 46 bytes, the data link layer adds some bytes to the end of the data, and the receiver removes the added bytes

Length summary:

  • Ethernet frame data length: 46-1500 bytes
  • Ethernet frame length: 64-1518 bytes (destination MAC + source MAC + network type + Data + FCS)

When a nic receives a frame, it checks the frame for errors. If the frame passes the check, it receives the frame. Otherwise, it discards the frame

Point to Point Protocol (PPP)

  • Address field: the value in the figure is 0xFF, which is imaginary. The source MAC Address and destination MAC Address are not required in the point-to-point channel
  • Control field: the value in the graph is 0x03
  • Protocol field: Indicates the Protocol type used internally
  • Frame start and end characters: 0x7E

Byte padding:

Replace 0x7E with 0x7D5E

Replace 0x7D with 0x7D5D

3. Network Layer

Network layer Packet (IP Packet, Packet) consists of header and data

  • Data section

    Most of the time these are segments that are passed down from the transport layer.

Header data format

  • Version

    The value contains four characters and identifies the version number of the IP header

    0 b0100: IPV4

    0 b0110: IPV6

  • Header Length (IHL: Internet Header Length)

    Four bits, indicating the size of the IP header, binary times four is the final length

    0b0101:20 (Minimum)

    0B1111:60 (Max.)

  • TOS: Type Of Service

    It occupies 8 bits and can be used to improve the network QoS (Quality Of Service).

  • Total Length (Total Length)

    Accounted for 16

    Sum of header + data length, Max. 65535 (2^16)

    The frame data cannot exceed 1500 bytes. Therefore, large IP packets must be fragmented into fragments and transmitted to the data link layer

    Each slice has its own network layer header (IP header)

  • ID: Identification

    Accounted for 16

    The ID of the packet is obtained. When the packet is too large for fragmentation, the identifications of all the slices of the same packet are the same. There is a counter to manage the ID of the packet

  • Flags

    Of the three

    • The first (Reserved Bit) : Reserved

    • 2. Don’t Fragment

      Indicates whether sharding is possible

      1 indicates that sharding is not allowed, and 0 indicates that sharding is allowed

    • (More Fragment)

      If the packet is fragmented, it indicates whether the packet is the last one

      1 means not the last slice, 0 means the last slice

  • Fragment Offset (FO: Fragment Offset)

    Of 13

    Used to identify the position of each segment to be sharded relative to the original data. The first shard corresponds to a value of 0. Since FO has 13 bits, it can represent up to 8192 (2^13) relative positions. The unit is 8 bytes, so it can represent the maximum position of the original data 8*8192=65536 bytes

  • TTL: Time To Live

    For eight

    Each router will decrease the TTL by 1 before forwarding the packet. If the TTL is reduced to 0, the router will return an error report

    By observing the TTL after the ping command is run, you can guess the operating system of the other party and how many routers pass through it

    The operating system version The default TTL
    Windows Server 2003, XP, 7, 10 128
    Linux X kernel and Red Hat 9 64
    Linux 2.2.14 kernel and 2.4 kernel 255
    Mac OS 60
    Mac OS X 64
  • Protocol

    For eight

    What protocol is used to indicate encapsulated data

    agreement ICMP IGMP IP TCP EGP IGP UDP IPV6 ESP OSPF
    Value (decimal) 1 2 4 6 8 9 17 41 50 89
  • Header Checksum

    Accounted for 16

    This field validates the header of the datagram, not the data portion. It mainly ensures that IP datagrams are not corrupted

  • Source IP Address

    It is a 32-bit IP address of the sender

  • Destination IP Address

    It is a 32-bit IP address of the receiver

  • Options available

    The maximum length is 40 bytes. It is usually only used for testing or diagnosis. The field contains the following information

    • Security level
    • The source path
    • Path to the record
    • The time stamp
  • Padding

    Also called fillings. If optional, the header length may not be a multiple of 32 bits. To do this, adjust to a multiple of 32 bits by padding the field with 0