Search code examples
network-programminglanmac-addressswitchingdata-link-layer

How does a Frame reach the Network Switch?


While studying about packet traversal in Networks, I understood that in a LAN we use MAC address for traversal of the frame.

I also Understand how the frame reaches from PCa to PCb in a network through the switch and how Switch learns the MAC addresses of both the end devices.

But what I don't understand is that how the frame move from PCa to the switch it is connected.How does the PCa know how to send the frame?


Solution

  • PCa IP-address: X.X.X.A
    PCa MAC-address:AAAA.AAAA.AAAA

    PCa IP-address: X.X.X.B
    PCa MAC-address: BBBB.BBBB.BBBB

    PCa has an application that wants to send an IP packet to PCb. PCa application knows that PCb is at X.X.X.B (IP-address). PCa checks its ARP table to see if there is a mapping from PCb IP-address to PCb MAC-address. To keep things simple, lets say there is a mapping so now PCa knows PCb IP-address and PCb MAC-address. PCa builds the packet and places the source and dest MAC and IP info into it as well as the upper layer data (IP Payload). PCa passes packet to the network interface driver to actually send the packet out the network interface. The network interface driver converts the digital packet into electrical signals on the physical layer medium (most likely Ethernet). PCa is connected directly to a switch with this Ethernet cable so the switch receives the electrical signals that represent the packet. The switch knows how to make sense of those electrical signals so it passes on the packet to PCb.