UDP, broadcast and Multicast (7), udp Broadcast
(Reference) TCP/IP explanation, Volume 1: Protocol
UDP is a simple datagram-oriented transport layer protocol. Each output operation of a process generates a UDP datagram and assembles it into an IP datagram to be sent. UDp datagram is encapsulated into IP datagram format, for example:
UDP Header
The fields of the UDP header are as follows:
The port number indicates the sending and receiving processes. Because the IP layer has allocated the datagram to TCP or UDP (based on the protocol field value in the IP header), the TCP port number can be viewed over TCP, And the UDP port number can be 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 of this field is 8 bytes (that is, when there is no data ).
Both UDP and TCP have a checksum that overwrites their header and data. UDP checksum is optional, while TCP checksum is required.
IP sharding
The physical network layer generally limits the maximum length of data frames sent each time. When the IP layer receives an IP data report to be sent, it must determine which local interface to send data (select the path) and query the interface to obtain MTU. The IP address compares the MPU with the datagram, if needed. Then perform the sharding. Fragments can occur on the original sender or intermediate router.
After sharding a datagram, it is re-assembled only when it reaches the destination (the re-assembly here is different from other network protocols, they require that the next stop be re-assembled, rather than at the final destination ). Re-assembly is completed by the IP layer of the destination. Data packets that have already been split may be sharded again. The data bit shards and restructures contained in the IP header provide sufficient information.
For example, each IP datagram sent by the sender contains a unique value. This value is copied to each piece when the data packet is sharded. The flag field uses a bit to represent "more slices ". Except for the last piece, the bit must be set to one for each piece of data. The offset field refers to the position at the beginning of the offset of the original datagram. In addition, after the datagram is split, the total length value of each piece must be the length value of the piece.
Finally, a bit in the flag field is called the "not sharding" bit. If this bit is set to 1, the IP address does not shard the datagram. Instead, discard the datagram and send an ICMP error message (fragment is required but no fragment bit is set) to the start end.
When an IP datagram is sliced, each segment is a group with its own IP header and is independent from other groups when routing is selected. In this way, data packets may be out of order when they arrive at the target end, but there is enough information in the IP header to allow the receiver to correctly assemble these data slices.
IP datagram and grouping
IP datagram refers to the end-to-end transmission unit of the IP layer (Before and After grouping ). A group refers to a Data Unit transmitted between the IP layer and the link layer. A group can be an IP datagram or a part of an IP datagram.
Broadcast and Multicast
There are three types of IP addresses: unicast address, broadcast address, and multicast address.
Broadcast and multicast are only used in UDP. They are very important for applications that need to transmit packets to multiple receivers at the same time. TCP is a connection-oriented protocol, which means there is a connection between two processes running on the 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 the target host ). Generally, each Ethernet frame is sent only to a single destination host, and the destination address refers to a single receiving interface. Therefore, it is called unicast.
However, sometimes a host sends frames to all hosts on the network, which is broadcast. You can see this process through ARP and RARP. Multicast is between unicast and broadcast. frames are sent only to multiple hosts in multicast groups.
To understand broadcast and multicast, you need to understand the filtering process of frames transmitted by channels by the host.
First, check the frame transmitted by the channel to determine whether the frame is accepted. If the frame is received, upload it to the device driver. Generally, the network adapter only receives frames whose destination address is the physical address or broadcast address of the network adapter. In addition, most interfaces are set to the hybrid mode, which can receive a copy of each frame.
Currently, most NICs are configured to receive frames from multicast addresses or some subnet multicast addresses. For Ethernet, when the maximum bytes of the IP address are set to 1, the address is changed to a multicast address, which can be expressed as 01: 00: 00: 00 in hexadecimal format: 00: 00 (Ethernet broadcast address ff: ff can be seen as a special case of Ethernet multicast address ).
If the network adapter receives a frame, the frame is transmitted to the device driver (if the frame is checked and incorrect, the network adapter discards the frame ). The device driver filters additional frames. First, you must specify the protocol (IP address, ARP, etc.) to be used in the frame type. Second, perform multicast filtering to check whether the host belongs to the multicast group specified by the multicast address.
The device driver then transmits the data frame to the previous layer. For example, when the frame type is specified as IP data report, the data is transmitted to the IP layer. The IP address performs more filtering and monitoring based on the source address and destination address in the IP address. If it is normal, send the datagram to the previous layer (TCP or UDP layer ).
Each time UDP receives a datagram sent from an IP address, it filters the datagram based on the destination port number and sometimes the source port number. If no process currently uses the destination port number, discard the datagram and generate an ICMP inaccessible packet (TCP performs similar Processing Based on the port number ). If a UDP datagram is detected and incorrect, the datagram is discarded.
Why multicast occurs in Broadcast
The problem with broadcast is that it increases the processing load of hosts that are not interested in broadcast data. Take a UDP broadcast application as an example. If there are 50 hosts in the network, but only 20 are involved in the application, each time one of the 20 hosts sends UDP broadcast data, the other 30 hosts have to process these broadcast datagram. The broadcast datagram received by the UDP layer is discarded. These 30 hosts discard the datagram because these hosts do not use the destination port.
The emergence of multicast reduces the processing load of hosts that are not interested in applications. With multicast, the host can be added to one or more multicast groups, so that the NIC only receives the data frames in the multicast group where the host is located.
Broadcast
There are four types of broadcast addresses: Restricted broadcast, network broadcast, subnet broadcast, and all subnet broadcast.
Restricted Broadcast
The restricted broadcast address is 255.255.255.255.255. This address is used for the destination IP address of the IP datagram during host configuration. At this time, the host may not know the network mask of its network or even its IP address.
In any case, the vro does not forward a datagram whose destination address is a restricted broadcast address. Such a datagram only appears in the local network.
Broadcast to the network
The broadcast address pointing to the network is the address with host No. 1. The broadcast address of Class A network is netid.0000255, and netid is the network number of Class A network.
A vro must forward the broadcast to the network, but it must also have an option not to forward.
Broadcast pointing to Subnet
The address that points to the subnet's broadcast address. The master node number is all 1 and has a special subnet number. The subnet mask is required for IP addresses that serve as subnet direct broadcast addresses. For example, if the router receives a datagram sent to 128.1.2.255, when the subnet mask of Class B network 128.1 is 255.255.255.0, this address is the broadcast address pointing to the subnet; however, if the subnet mask is 255.255.254, this address is not a broadcast address pointing to the subnet.
Broadcast pointing to all subnets
To broadcast to all subnets, you also need to understand the subnet mask of the destination network so that the broadcast addresses pointing to the network can be distinguished. The subnet number and host number of the broadcast address pointing to all subnets are all 1. For example, if the destination address subnet mask is 255.255.255.0, the IP address 128.1.255.255 is a broadcast address pointing to all subnets. However, if the network is not divided into subnets, This is a broadcast pointing to the network.
Multicast
IP multicast provides two types of services:
1. send data to multiple destination addresses. There are many applications that transmit information to multiple recipients, such as interactive conference systems or sending emails or news to multiple recipients. If multicast is not used, these applications are currently completed using TCP (send a separate data copy to each destination address ). However, even if multicast is used, some applications still use TCP to ensure its reliability.
2. Customer requests to the server. For example, a diskless workstation needs to determine to start the boot server. Currently, this service is provided through broadcast, but if multicast is used, the burden on the host that does not provide this service can be reduced.
Multicast Group address
Unlike other IP addresses (class A, Class B, and class C addresses), the allocated 28bits are used as multicast group numbers instead of other IP addresses.
Multicast Group addresses include up to 4-bit multicast group numbers of 1110. It indicates the address range from 224.0.0.0 to 239.255.255.255.
A host group is a set of hosts that can receive data sent to a specific multicast group address. A host group can span multiple networks. Members in the Host group can join or leave the Host group at any time. There is no limit on the number of hosts in the Host group, and hosts that do not belong to a host group can send information to this group.
Some Multicast Group addresses are identified by IANA as well-known addresses. They are also treated as permanent host groups, which are similar to the well-known ports in TCP and UDP. For example, 224.0.0.1 represents "all system groups in this subnet", and 224.0.0.2 represents "All router groups in this subnet ". Multicast Group address 224.0.1.1 is used as the Network Time Protocol NTP
.