I have a network topoloty as follows
A --------- B --------- C
/|\ /|\ /|\
/ | \ / | \ / | \
A1 A2 A3 B1 B2 B3 C1 C2 C3
A, B, C are layer-3 switches, and they have their own subnets. Each switch has 3 servers A1~A3, B1~B3, C1~C3 attached to them, so A1~A3 are in subnet A, B1~B3 in subnet B, C1~C3 in subnet C.
There is intra-switch traffic, e.g., from A1 to A3, as well as inter-switch traffic, e.g., from A1 to C1. Obviously, intra-switch traffic will be switched (layer 2), and inter-switch will be routed (layer 3).
I would like to know how does a switch, say A, can figure out if a packet needs switching or routing?
My understanding is based on the ARP protocol, because it decides the packet's destination MAC address.
If A1 wants to send out a packet, it will look up the destination IP address in its local ARP table or query over the network. If the dst IP is within the same subnet as A1, say A3, then A3's MAC address will be returned, and encapsulated in the outgoing packet's dst MAC field. If the dst IP is in another subnet, say C3, then the MAC address of switch A's interface that connects to A1 (assume it is interface 1) will be returned, and then put into the outgoing packet's dst MAC field.
When this packet reaches switch A, switch A will examine the dst MAC address. If this MAC address does not match the MAC address of switch A's inteface 1, it will be looked up in the MAC table to find the egress port. Then this packet is switched to that port, and its src and dst MAC addresses remain the same. Otherwise, this MAC address matches the MAC address of switch A's inteface 1, switch A continues to lookup the packet's dst IP address in the routing table to find the egress port. Then this packet's src and dst MAC addresses will both be replaced by A's egress interface MAC address, and switch B's ingress interface MAC address (also obtained through the ARP protocol).
Is my understanding correct, do I miss something?