[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

[K12OSN] Re: switches

> Hans Ekbrand a écrit :
> > Interesting to know, but how does switches work then (how does the
> > sender get the MAC address of the reciever)?

When A wants to send to B, A must get either the MAC address of B
or the MAC address of a router that knows how to get to B.  Which
is used depends on the routing table on A and the IP address of B.
In the case of A and B being on the same subnet, A will assume it
can send directly to B.

If A does not already know the MAC address of B, then it has to
ask for it using ARP (a broadcast message saying, "who has IP
address X", where the reply from B contains B's MAC address).
So, the direct answer to your question is that the switch is
not involved in helping A get the MAC address of B (except, of
course, in connecting the two machines together on the network.)

A then sends a packet to B by putting B's MAC address in as
the destination MAC in the ethernet frame and A's own MAC address
as the source MAC.  Two things happen when this packet hits the
switch.  First, the switch looks to see if it knows which port
B is on by checking its MAC address table.  If it finds B's MAC
in the table, it then knows precisely where to forward the packet.
If not, it must send the packet to all ports on which B might be
(possibly using VLANs).

Second, the switch looks at the source MAC in the packet.  If it
has not yet seen a packet from A, then A will not be in the MAC
address table.  Since the switch now knows where A is (since A
effectively just told it), it puts A's MAC into the MAC address
table and associates it with the port the packet came in on.
So when B replies to the packet from A, the switch already knows
where to find A (and it will learn where B is if it didn't
already know.)  (In reality, the ARP exchange earlier would have
provided A and B's MAC addresses to the switch, so when A and
B really started talking ot each other, the switch would already
know them.)

It might help to realize that switches store received packets for
a short period of time, long enough to process the packet and
figure out which port or ports the packet needs to be transmitted
on.  Hubs are essentially a way to connect a bunch of ethernet
cables together, with no packet processing or storage.

By the way, hubs are half-duplex, while switches can be full-duplex,
so using switches can effectively double the bandwidth of your
network.  See http://www.duxcw.com/faq/network/hubsw.htm for a
high-level comparison of hubs and switches.


PS. Another little technical detail... switches only remember a
MAC address for a limited amount of time, so if B doesn't send
any packets for a while (usually something like one or five minutes),
the switch will "forget" where B is and have to flood the next
packet for B on all ports again.  This is useful if you change
the port that B is connected to, for example.

Don Christensen       Senior Software Development Engineer
djc cisco com         Cisco Systems, Santa Cruz, CA
  "It was a new day yesterday, but it's an old day now."

[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]