Packet forwarding principle-Layer 3

Source: Internet
Author: User

R1 --------------- (vlan10) SW (vlan20) ------------------ R2
Condition: R1: 192.168.1.1 mac: a R2: 192.168.1.2 mac: B
Sw is a layer-3 Switch
 
When R1 packets are forwarded to R2:
When R1 receives the data packet, it queries the route table of R1. The purpose of querying the route table is to find the data packet from that interface. After finding the interface, what type of frames are encapsulated for the purpose. After the layer-2 frame encapsulation is completed, query the ARP table to find the MAC address of R2. There are two cases:
(1) R1 is found in the ARP table item to complete layer-2 encapsulation and release
(2) If R1 is not found in ARP, the packet is discarded (the second-layer Ethernet frame is discarded), which causes ARP table query on R1. The first packet cannot be pinged. R1 uses mac: a as the source mac, 192.168.1.1 as the source IP, R2 IP: 192.168.1.2 as the destination IP, and mac as the broadcast of all F.
After receiving the arp request frame sent from R1, SW opens the frame header, checks the source and target mac, and finds that the target mac is its own mac. In the ip layer, it finds that the target ip address is not its own, find the route table, view the ip address from the outbound interface, and find the Encapsulation Format and encapsulation of the interface. Sw uses its own mac interface as the source mac, R1 IP as the source IP, R2 mac as the target mac, R2 ip as the destination ip, and sends an arp request frame. In this case, r1 and sw create an arp table.
After R2 receives the arp request frame, R2 uses its mac as the source mac and its ip as the source ip, and sends an arp response frame to sw,
After receiving the arp request frame sent by r2, sw establishes an arp table entry with r2,
At this point, r1 sends the second icmp echo request to the target ip address of r2 through sw. After receiving the second icmp echo Request, the sw has an arp table entry of r2, sw rewrites the source mac to its own mac, changes the target ip address to the ip address of r2, and then transmits the frame to r2. After r2 receives the icmp echo request, send an icmp echo response to the r1 ip address on the target mac address of the sw, and ping the response.
 
Layer-3 forwarding
(Layer-3 headers do not change, and layer-2 encapsulation changes)
The target IP address of the source IP address does not change the source mac address and target mac address.
 
R1
1. query the route table to find the next hop address of the destination address, and obtain the outgoing packet interface that finally reaches the destination address through recursive query, because the routing protocol is run here, therefore, the result of R1 route table query must pass the Layer 3 interface on SW to reach the destination address, and the output packet interface indicates the interface to reach the next hop.
2. determine the encapsulation of layer 2 and query the corresponding ARP table items to complete encapsulation of the data packet. At this time, the query will obtain the layer 2 address corresponding to the IP address of the next hop, we will not discuss the results of ARP table queries here. For details, refer to layer-2 forwarding.
Note: The IP address queried by ARP is also the MAC address of the same subnet.
Sw:
1. receive the data frame from R1 and check the mac address of the data frame source.
2. Check the target mac address of the data frame and find that the address is a local mac address. This means there are two possibilities:
2.1 If the packet does not reach the destination, sw will try to split the packet to detect the upper-layer application.
2.2 The packet does not reach the destination. sw is only an intermediate node in the packet forwarding process. sw detects the packet header to obtain the destination IP address of the packet.
The above two results will result in sw detection data packet header, and the detection packet header will obtain the IP address of the data packet. At this time, the corresponding query table item is RoutingTable sw enabling layer3 forwording.
3. After querying the route table in sw, find the next hop to the destination address and the outgoing packet interface.
4. query the corresponding ARP table items to complete encapsulation. In this case, SW uses the Layer 2 address corresponding to its next hop address as the target, and the layer-2 address of the packet output interface as the source to encapsulate the packet.
 
The target mac is unknown. It must be a wildcard forwarding.
The destination mac address is known and the destination mac address is the switch itself.
Conclusion:
When sw detects the received data frame and finds that the target mac address is a local interface address and the target IP address is not me, layer 3 forwarding is automatically enabled and the original data frame is changed.
When layer 3 forwarding is enabled, the following conditions must be met:
1. sw supports layer-3 forwarding and enables IP routing (conditions that can generate a routing table)
2. layer-3 interfaces (SVI, routing port) exist on sw)
 
L2 Switch
The router forwards data packets to the route table and ARP table. The layer-2 switch forwards data frames to the c am table. The ARP table stores the ing information between IP addresses and MAC addresses.
 
 
Author: "Wang bozhi's blog"

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.