(reference) TCP/IP detailed, Volume 1: protocol
UDP is a simple datagram-oriented Transport layer protocol: each output of a process produces exactly one UDP datagram and is assembled into a copy of the IP datagram to be sent. The UDP datagram is encapsulated into an IP datagram format such as:
UDP header
The various fields of the UDP header are as follows:
The port number indicates the sending process and the receive process. Because the IP layer has already assigned datagrams to TCP or UDP (based on the protocol field values in the IP header), TCP port numbers are viewed by TCP and UDP port numbers are viewed by UDP. The TCP port number is relatively independent from the UDP port number.
The UDP length field refers to the byte length of the UDP header and UDP data. The minimum value for this field is 8 bytes (that is, when no data is in the case).
Both UDP and TCP have a checksum that overrides their header and data in the header. The UDP checksum is optional, and the TCP checksum is required.
IP Shard
The physical network layer typically limits the maximum length of each data frame that is sent. At any time the IP layer receives a copy of the IP datagram to be sent, he determines which interface is sent to the local data (routing), and queries the interface to obtain the MTU. IP compares MPU and datagram, if necessary. Is fragmented. Shards can occur on the original send side or on an intermediate router.
Once a datagram is fragmented, it can only be reassembled when it arrives at the destination (the reassembly here differs from other network protocols, requiring the next station to be reassembled instead of the final destination). Reassembly is done by the destination IP layer. Datagrams that have already been sliced may be fragmented again. The data bits that are contained in the IP header are fragmented and reorganized to provide sufficient information.
For example, for each IP datagram sent by the sending side, its target literate segment contains a unique value. This value is copied to each slice when the datagram is fragmented. The flag field uses a bit to denote "more slices." In addition to the last piece, each of the other components of the datagram is to put the bit one. The Slice offset field refers to the position at which the slice is offset from the beginning of the original datagram. In addition, after the datagram is fragmented, the total length value of each slice is the length value of the slice.
Finally, a bit in the flag field is called a "non-shard" bit. If you place this bit 1,ip, the datagram will not be fragmented. Instead, the datagram discards and sends an ICMP error message (which needs to be fragmented but has no shard bits set) to the starting end.
When the IP datagram is fragmented, each piece becomes a grouping that has its own IP header and is independent of the other groupings when routing is selected. In this way, the data may be out of order when reporting to the destination, but there is enough information in the IP header to allow the receiver to assemble the data slices correctly.
IP datagram and Grouping
IP datagram refers to the end-to-end transmission unit of the IP layer (after grouping and reassembly). Grouping refers to the data unit that is transferred between the IP layer and the link layer, a grouping can be an IP datagram, or it can be a shard of an IP datagram.
Broadcast and multicast
There are three types of IP addresses: unicast addresses, broadcast addresses, and multicast addresses.
Broadcast and multicast are only applied to UDP, and they are important for applications that need to transmit messages to multiple receivers at the same time. TCP is a connection-oriented protocol that means that there is a connection between two processes running in two hosts, respectively.
Consider a shared channel network that contains multiple hosts, such as Ethernet. Each Ethernet frame contains the Ethernet address (48bit) of the source host and destination host. Typically, each Ethernet frame is sent only to a single destination host, and the destination address is referred to a single receive interface, thus called unicast.
However, sometimes a host sends frames to all hosts on the network, which is the broadcast. This process can be seen through ARP and RARP. Multicast is between unicast and broadcast, and frames only send multiple hosts that belong to a multicast group.
To understand broadcast and multicast, it is necessary to understand the filtering process of the host to the frame transmitted by the channel.
First, the network card view the frame transmitted by the channel, determine whether to accept the frame, if received after the transfer to the device driver. Usually the NIC receives only those frames whose destination address is the physical address or broadcast address of the network card. In addition, most interfaces are set to promiscuous mode, which can receive a copy of each frame.
Currently, most network cards are configured to receive frames with destination addresses of multicast addresses or some subnet multicast addresses. For Ethernet, when the lowest bit of the address is set to 1, the change address is a multicast address, and hexadecimal can be represented as 01:00:00:00:00:00 (the Ethernet broadcast address FF:FF:FF:FF:FF:FF can be considered a special case of an Ethernet multicast address).
If the NIC receives a frame, the frame is passed to the device driver (the NIC discards the frame if the frame is checked and wrong). The device driver will perform additional frame filtering. First, the frame type must specify the protocol to use (IP, ARP, and so on), followed by multicast filtering to check whether the host is a multicast group with multicast address descriptions.
The device driver then transmits the data frame to the previous layer, for example, when the frame type is specified as an IP datagram, it is passed to the IP layer. IP based on the IP address of the source address and destination address for more filtering monitoring. If normal, send the datagram back to the previous layer (TCP or UDP layer).
Each time the UDP receives the datagram which the IP transmits, according to the destination port number, sometimes also carries on the datagram filtering according to the source port number. If no process currently uses the destination port number, the datagram is discarded and an ICMP unreachable message is generated (TCP handles similar processing based on the port number). If the UDP datagram is checked and wrong, the datagram is discarded.
Multicast is the reason for the radio to appear
The problem with broadcasting is that it increases the processing load for hosts that are not interested in broadcast data. Take an example using a UDP broadcast application. If there are 50 hosts in the network, but only 20 participate in the application, each of the 20 hosts sends UDP broadcast data, the remaining 30 hosts have to process these broadcast datagrams. The broadcast datagram received until the UDP layer is discarded. The reason these 30 hosts dropped the datagram is because these hosts are not using the destination port.
The advent of multicasting reduces the processing load on hosts that are not interested in the application. With multicasting, a host can join one or more multicast groups so that the network card receives only those data frames that host the multicast group.
Broadcasting
There are 4 main broadcast addresses: Restricted broadcasts, broadcasts to networks, broadcasts to subnets, broadcasts to all subnets.
Restricted broadcasts
The restricted broadcast address is 255.255.255.255. This address is used for the destination address of the IP datagram during host configuration, at which point the host may not know the network mask of the network or even his IP address.
In any case, the router does not forward datagrams with the destination address as a restricted broadcast address, and such datagrams only appear on the local network.
Broadcast to Network
The broadcast address to the network is the address where the host number is all 1. The Class A network broadcast address is netid.255.255.255, where NetID is the network number of the Class A network.
A router must forward a broadcast that points to a network, but it must also have a choice not to forward.
Broadcast to Subnet
The broadcast address to the subnet is an address with a host number of 1 and a specific subnet number. The IP address that is the subnet's direct broadcast address requires an understanding of the subnet's mask. For example If the router receives a datagram destined for 128.1.2.255, when the subnet mask for Class B network 128.1 is 255.255.255.0, that address is the broadcast address that points to the subnet, but if the subnet's mask is 255.255.254, the address is not a broadcast address to the subnet.
Broadcasts that point to all subnets
Broadcasts that point to all subnets also need to know the subnet mask of the destination network so that it is separated from the broadcast address area of the network. The subnet number and host number of the broadcast address to all subnets is 1 for example, if the destination address subnet mask is 255.255.255.0, then the IP address 128.1.255.255 is a broadcast address that points to all subnets. However, if the network is not divided into subnets, this is a broadcast to the network.
Multicast
IP multicasting provides two types of services:
1. Transfer data to multiple destination addresses. There are many applications that deliver information to multiple recipients: such as an interactive conferencing system or distributing mail or news to multiple recipients. If multicast is not used, these applications are currently using TCP to complete (transfer a separate copy of the data to each destination address). However, even with multicasting, some applications use TCP to ensure his reliability.
2. Client requests to the server. For example, a diskless workstation needs to determine the boot server, which is currently provided by broadcast, but if multicast is used, it can reduce the burden of not providing the service host.
Multicast group Address
Unlike other IP addresses (A, B, Class C addresses), the assigned 28bit is used as the multicast group number and no longer represents the other.
The multicast group address includes a maximum of 4bit and a multicast group number of 1110. It represents a range of addresses from 224.0.0.0 to 239.255.255.255.
A collection of hosts that can receive data destined for a specific multicast group address is called a host group. A host group can span multiple networks. A member of a host group can join or leave a cluster at any time. There is no limit to the number of hosts in the host group, and hosts that are not part of a host group can send information to the groups.
Some multicast group addresses are identified by IANA as well-known addresses. They are also treated as permanent host groups, which are similar to well-known ports in TCP and UDP. For example: 224.0.0.1 represents "all system groups within this subnet", and 224.0.0.2 represents "all router groups within this subnet". Multicast group address 224.0.1.1 as Network Time Protocol NTP
。
UDP, broadcast, and multicast (vii)