Suppose two computers and a router are connected to a layer 2 ethernet switch. Both computers are registered on the router's IP network. The user of computer 1 sends an ICMP ping request to computer 2 using computer 2's IP address. My understanding (which may not be correct) is that this communication will not pass through the router, only through the switch because computer 1 keeps an ARP table and is able to resolve computer 2's IP address to its MAC address before sending. My question is twofold:
1) What is the mechanism through which the source computer originally "learns" the MAC address of the destination computer and is therefore able to register this relationship in its ARP table?
2) Are these two computers technically still communicating over IP (layer 3)? Or are they technically implementing ICMP in layer 2? My confusion stems from the fact that ICMP is considered an "IP protocol".