4

A router structure would look like linecards all connected by a routing fabric(switchplane) so if a packet is received by a linecard it will remove the ethernet header then make changes to ip header and lookup in routing table using destination ip to get the output interface and next-hop ip. Then passes the packet without the ethernet header to the fabric with an internal header containing the output interface number then according to the internal header the fabric puts the packet(without ethernet header) in the output interface now since the packet doesnt have the ethernet header. It will need to add one but how will the output port know what will be the destination mac since the destination ip is not always the same as the next-hop ip and the destination mac will be based on that.

Problem: So would the output interface again lookup in the routing table for next-hop ip and according to that lookup in the ARP table or does the receiving interface pass the next-hop ip to the output interface in the internal header as well ?

If there are any conceptual gaps please explain them as well if possible.

3 Answers 3

8

The routing table is only consulted once. It provides the interface and the next-hop gateway address, which may be identical with the destination address itself, for the last hop.

Any hardware address necessary for that egress interface is determined in the next step. For IPv4 over a MAC-based network like Ethernet ARP is used. The MAC address may be already present in the ARP cache, so an actual request might not be required.

From the layering perspective, the lookup in the routing table belongs to the network layer (L3), and an ARP query/cache lookup is for the data link layer (L2).

It's also possible to cache a next hop's hardware address within the routing table to save the ARP lookup, but that is specific to the implementation at hand and there's no general rule.

1
  • @Zac69 Thank you for your help. It seems I have been looking into only ione mplementation and thinking that there are no other implementation and just filling the conceptual gap with my imagination without facts. I will look further and look at other implementation as well. Commented Aug 3 at 7:11
5

Your are talking about a specific implementation of a data plane in a router. If you want your router to forward packets as fast as possible you don't do extra lookups. Instead, try to calculate all required info for packet processing in advance and store it in FIB. In case of ARP, if there is a route in FIB for which there is no resolved Destination MAC address info for the NH IP address, the router, ideally, should perform ARP and store the answer in FIB for that specific route entry. So when a packet arrives, the router already has all relevant forwarding information stored in FIB - and obtained from a single route lookup.

0
4

This is one possible way to make a router but probably not the most efficient.

In a better design the input line card's routing table would contain all needed information, including the next hop ethernet address from the output interface. Keeping this in sync between the different line cards would be the software's job. It might keep the address in the ethernet header on the backplane alongside the internal header, or it might keep this information in the internal header.

A different design which uses slightly less backplane bandwidth would put a "next hop number" in the internal header, and the output line card would look up that number in a "next hop table" to find the next hop ethernet address. This design avoids sending the next hop ethernet address across the backplane in every packet.

3
  • I agree, and would not in the general case expect a router to rewrite an IP header. Commented Aug 4 at 7:27
  • I was trying to create a network in cpp just for learning and was trying to create according an implementation in mind so it would be as close to a real life device. After reading all the answers and comments it seemed that there would be a lot of moving parts required if i tried those option so I have just created an internal header with the length, output_port and nexthop_mac fields so the fabric can route it easily and output interface doesn't need to do any extra lookup and just disect this internal header and place it's own mac and the next_hop_mac from the internal header. Commented Aug 5 at 6:33
  • But it seems that i might need to make changes to the internal header so that it also has the ethertype field so then the output port wouldn't need to see in the packet at all and just by disecting the internal heade can create the ethernet header for the packet and send it along the link. This seems the easier method for me. Commented Aug 5 at 6:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.