Use the original socket to measure the forwarding table capacity of the link layer switch

Source: Internet
Author: User

Using the raw socket to measure the forwarding table capacity of the link layer switch using the original socket, we can build data frames in the network according to our own ideas. Because it is for the Ethernet frame at the link layer, we do not need to focus on other layers. For details about the use of the original socket programming, you can refer to some tutorials on the network, or read related books. Here, I use the filter and forwarding features of the switch to test the forwarding table capacity of the switch. Using the interface provided by the original socket, we can forge an Ethernet frame, and then send these forged Ethernet frames to host B to receive the Ethernet frame, in this way, the forwarding table capacity is determined based on the received Ethernet frame content on the B end. A is responsible for sending Ethernet frames, and host B captures and analyzes the received frames to output the final results. Host A is used to send ethereum frames. After each group is sent, all sent ethereum frames are resent immediately, and A new group is sent to repeat the above process. (But in order to make the program simple, I defined only three groups in implementation, each group contains a number of Ethernet frames .) When an Ethernet frame is sent for the first time, the target mac address of the group uses the broadcast address ff-ff, and the source mac address uses its own forged address, for example, if the number is increased from 0, 00-00-00-00-00-00 for the first frame, and 00-00-00-00-01 for the second frame, the subsequent increments. In this case, because the source mac address is a new address each time the forwarding table is not full, the switch creates a table item for this address. The broadcast address is used. The packet is captured at the receiving end and recorded. During retransmission, the destination mac address of the group uses the source address in the last Ethernet frame of the previous group, and the destination mac address is the source mac address of the group that has already been sent. Now, the filter function of the switch comes in handy. When re-transmitting a data frame, if the destination address X already exists in the exchange table, the switch filters out the Ethernet frame (because the data entry and exit are on the same port), but if X is not in the exchange table (the exchange table has been filled up ), then the switch broadcasts the Ethernet frame so that the packet can be captured on the B end. When all the Ethernet frames in this group are sent, end B can calculate the forwarding table capacity of the switch based on its own records. For example, there are two groups, each of which has two Ethernet frames. The first group is G1: 00-00-00-00-00-00-00, 00-00-00-00-00-01 second group G2: 00-00-00-00-00-00-02, 00-00-00-00-00-03 host A's ethereframe at the first sending is: (as for the "Frame Type" field, I am using the ARP type during implementation. You can try other types) source mac target mac Frame Type 00-00-00-00-00-00 ff-ff 00-00-00-00-00-00-01 ff -ff after this group is sent, the re-transmission Ethernet frames are: 00-00-00-00-00-01 00-00-00-00-00-00 00-00-00-00-00-00-00-00-00-00-00 -00-01 then the host sends the Second group: 00-00-00-00-00-02 ff-ff 00-00-00-00- 00-03 ff-ff after this group is sent, you need to send all the sent groups: 00-00-00-00-00-03 00-00-00-00-00-00 00-00 00-00-00-00-00-00-00-00-00-00 -00-01 00-00-00-00-00-03 00-00-00-00-00-00-00-02 00-00-00-00-03 00-00 -00-00-00-03 Test Platform: fedora18 (but there should be no problem on other platforms, and the small Layer 3 switch in the dormitory can also be measured ). Usage: connect the two computers to the vswitch, and set the network connection to a local connection. Acceptor: sudo. /receiver p4p1 (this is the name of the network card, different system names, use the ifconfig command to view) sending end: sudo. /sender p4p1 1000 (number of sent frames, which is sent three times in this Code, 1000/500/250 respectively) Result: After the receiver exits the program, some statistics are displayed, the displayed English word records the number of frames received. The option "two" is the number of table items in the forwarding table (but there are still some details, as described below ). (Note: Enable the acceptor before sending it. After each test, you need to unplug the power of the switch and plug it in before you can perform the next test. The program will stop for 50 milliseconds after each frame is sent. If it feels slow, the pause time can be reduced, for example, 10 milliseconds or less)

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.