Network Layer Routing and Application Layer Routing
In the IP connection network, the correct communication between hosts is ensured by the correct routing. Here, the routing is not a hardware router, but a routing policy. First, summarize the routing-related addresses in the Network: 1. MAC address: used for hop-by-hop routing in the Link Layer. That is, the source MAC address in the packet sent from the source host is the MAC address of the source host, the destination MAC address must be the MAC address of a host directly connected to the source host, therefore, each time an IP datagram is forwarded from the source host to the target host, the source/Target MAC address must be modified. 2. IP Address: Used for the network layer, that is, the IP layer routing. IP datagram is reaching the final target host (Note: from the network layer, it is the final target host, however, from the application layer, it is not necessarily the final target host), no matter how many forwards are processed, its source/destination IP address will never change; A router uses the destination IP address in the IP data packet and the route table to route the IP data packet. 3. application Layer Protocol address: This is related to the specific application layer protocol. Different Application layer protocols have different addresses. For example, the HTTP protocol uses domain names as the routing address; the SMTP protocol uses username @ domain as the routing address; diameter uses destination-host AVP and destination-realm AVP to address; SIP uses an email address to address user @ domain. After learning about these addresses, we now consider a problem. A message sent from the application layer may be forwarded many times from the source host to the destination host, in each forwarding process, how do the three types of routing addresses in the data packet change? First analyze a simple example, enter the http://www.baidu.com from the browser and then press enter, then the browser will send an HTTP request message to the Baidu web server port 80, what are the three types of routing addresses in this message? Application Layer address is obviously the web site http://www.baidu.com, so what is the IP address? Here, the IP address is the IP address of the Baidu Web server. How does the browser know this IP address? In the browser implementation, there should be an API call for gethostbyname (), which will be called Based on the entered URL, then, the source host sends a message to the DNS server to resolve the IP address of the Baidu Web server. Then, the DNS server returns the IP address to the source host browser, the browser uses the HTTP message and the returned Baidu IP address as the parameter to call the API for sending the message over TCP, so that the HTTP request message is added with the TCP Header. The destination IP address in the TCP header is the IP address of the Baidu web server, then, the request message is sent out, and the IP address remains unchanged no matter how many times the request message is forwarded to the Baidu server, but the MAC address changes each time it is forwarded. The above example is relatively simple. We can see that the application layer directly fills in the IP address of the final destination in the message and remains unchanged. Of course, this requires the participation of the DNS server. Can all application layer protocols directly obtain the IP address of the final target host, and then enter the IP address in the message for sending? We rely on the DNS server to obtain the IP address of the final target host, but not all application layer protocols use domain names as the routing address, so we cannot obtain the final IP address through the DNS server. Now let's consider an example of a diameter message routing: The S-CSCF In the IMS network wants to send a mar message to the HSS, because the diameter can carry over TCP or sctp, TCP is used as an example here. First, let's look at the routing address of the application layer. this is stipulated by the Basic Diameter protocol. The basic Diameter Protocol requires that the destination-host AVP and destination-realm AVP be used to route the diameter message; the Application Layer knows the HSS to which the MAR message will be sent and the destinationhost and destinationrealm Of The HSS, such as destinationhost = CTC_HCF-4, destinationrealm = IMS. CTC. com, the data should be configured in the S-CSCF. Destination-host AVP and destination-realm AVP use the DNS structure, but they are defined by the carrier internally and are not in the public DNS domain. So the application layer of the routing address, but diameter is ultimately sent through the TCP encapsulation, but the S-CSCF may not know the IP address of the HSS, then the MAR message next should be sent? The basic Diameter protocol defines relay agent, proxy agent, redirect agent, and other devices for message routing. These devices are used to route diameter messages. The difference in their functions is not described here, take the proxy agent as an example. There should be configuration data for a proxy agent on the S-CSCF, including the IP address or hostname of the proxy agent, from which diameter messages are sent to the proxy agent, therefore, the IP address in the Mar message should be the IP address of the proxy agent (if hostname is used in the configuration data, the corresponding IP address can be obtained through the internal DNS server of the carrier ). After receiving the MAR message, the proxy agent decodes the message to the diameter layer in sequence, and then checks whether its destinationhost and destinationrealm are consistent with their destinationhost and destinationrealm. If they are inconsistent, the proxy agent queries the realm route table and peer route table, depending on the destinationrealm and realm route tables in Mar, the route table determines where the next hop should be sent. For example, if it is another proxy agent or the destination HSS, it is assumed that the next hop is the destination HSS, then, the proxy agent changes the destination IP address in the Mar message to the IP address of the HSS and sends it out. After receiving the MAR message, the HSS decodes the message to the diameter layer. It finds that the destinationhost and destinationrealm are exactly the same as their destinationhost and destinationrealm, so it accepts the MAR message and the message is delivered. A detailed explanation of diameter message routing is described in a separate diameter article. The two examples above show that the MAC address is the simplest and must be constantly changed during message transmission. The IP addresses and application layer addresses must be analyzed based on specific protocols. The general principle is as follows: if the sender can directly obtain the IP address of the final target host, the IP address remains unchanged, and the message generally does not need to contain the application layer routing address, in this type of protocol, it is generally not necessary to define the application-layer routing device that routes messages (note that the application-layer routing device, such as the proxy agent in diameter), such as the HTTP protocol; if the sender cannot obtain the IP address of the final target host, the message must always carry the routing address of the application layer, and the address remains unchanged, in the protocol, you usually need to define the application-layer routing device that routes messages. The application-layer routing device parses the application-layer routing address to determine the next hop of the message, such as the diameter and SIP protocols. Finally, let's mention the port number. The port number does not have any relationship with the route between the host. It only serves to differentiate different processes of the same Protocol. When a data packet arrives at the target host, it is first sent to the IP layer, then, the fields indicated by the IP layer are sent to the upper-layer protocol stack, that is, TCP/UDP/sctp. Next, TCP/UDP/sctp sends the data to the corresponding process based on the port number in the header. Different protocols can reuse the same port number.