5

If UDP and/or TCP send packets via IP to an Internet Protocol Address, how can a layer-2 switch forward these?

Is this possible or do you need a layer-3 switch?

  • 1
    How can the US mail send letters written in Swedish? Answer: It doesn't care what's in the letters. – David Schwartz Dec 30 '16 at 5:27
4

Layer-2 switches are oblivious to anything above layer-2. Layer-2 protocol carry a variety of layer-3 protocols (IPX, IPv4, IPv6, AppleTalk, etc.). The layer-2 switch knows nothing about this; it only sees the layer-2 frame header.

The layer-3 protocol can carry a variety of layer-4 protocols (TCP, UDP, etc.). The layer-2 switch would need to strip the layer-2 header to look in the layer-3 packet to see which layer-3 protocol the layer-2 frame is carrying, and it doesn't do that.

Routers (layer-3 devices, including layer-3 switches) will strip the layer-2 frame to reveal the layer-3 packet. A router will then switch the layer-3 packet, based on the layer-3 header to a new interface, and create a new layer-2 frame for the new interface.

A layer-3 switch is really a layer-2 switch, but with a router built in. The routing part of a layer-3 switch only gets involved when a frame is destined to a layer-3 interface in the switch.

Edit to answer your comment:

An application will send data to UDP, which encapsulates the data into layer-4 datagrams, including a UDP header, which are then sent to IP (either IPv4 or IPv6). IP encapsulates the UDP datagrams inside IP packets, including an IP header. IP sends the packets to ethernet, which encapsulates the IP packets inside ethernet frames, including an ethernet frame header. The ethernet frame header has the source and destination MAC addresses. Your host may not know the MAC address of the destination host. It will look in its ARP cache for the MAC address of the host with the destination IP address. If it is in the ARP cache, it uses that MAC address. If not, it will broadcast an ARP request, asking for the MAC address of the owner of the IP address. The destination host will reply with its MAC address, and the frame is built. The frame is then sent out the physical interface to the switch.

The next part involves the switch. A switch will build a MAC address table with the MAC address and port. Every time a switch receives a frame on a port, it will update its table with the MAC address and which port that MAC address comes from. When the switch receives a frame from your host, it will look at the destination MAC address, and it will look that up in its MAC address table so that it can deliver the frame to the port where the destination MAC address is. If it can't find that MAC address in its table, it will flood the frame to all ports.

When the destination host receives the frame, it will reverse the encapsulation process.

As you can see, each layer is independent of the other layers, and the switch knows nothing about IP or UDP.

The process is the same for a destination on a different network, except that your host will use the MAC address of its configured gateway (router, including the routing part of a layer-3 switch). The router will strip the frame, look at the packet, switch the packet to a different network interface, and build a new frame for the new interface.

| improve this answer | |
  • A UDP application knows nothing of a MAC address which is all a layer-2 switch does know. So, for any kind of IP routing a layer-3 switch is needed? – user_ABCD Jun 13 '16 at 16:39
  • IP routing requires a router, either a stand-alone router, or one built into a switch (layer-3 switch). Routers, including layer-3 switches, don't care about UDP, or any protocol above layer-3. – Ron Maupin Jun 13 '16 at 16:41
  • Essentially, I guess, how do I get my UDP message to someone else on the LAN if I send to xxx.xxx.xxx.xxx at port xxxx and a layer-2 switch is the only switch? – user_ABCD Jun 13 '16 at 16:58
  • I will edit my answer. – Ron Maupin Jun 13 '16 at 16:59
1

First of all, UDP and TCP are L4 terms, they exist on L4 on OSI model. If you have a L2 switch, no matter what you want to transmit, packet will be forwarded to it destination if the has a valid path, i guess a correct gateway or traffic to another pc in your LAN, no matter if they are UDP or TCP

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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