MAC Algorithm
The smarts of Ethernet resides in how the sender sends frames it needs to send. It uses the following transmitter algorithm:
- If a network adaptor has a frame to send, and the line is idle, then the adaptor sends the frame immediately.
- If a network adaptor has a frame to send, and the line is busy, the adaptor waits for the line to become idle and then immediately send the frame. This
is called 1-persistence; p-persistence would be to transmit with probability p and wait for the next frame "time slot" to consider transmitting with probability 1-p.
- If two transmitters try to transmit at the same time, then the frames are said to collide. The time it takes for a signal to transmit the whole Ethernet line length determines how many bits someone might have transmitted before noticing a collision. Once a collision is noticed, the transmitter is supposed to transmit a special 32-bit jamming sequence. This jammed frame is called a runt frame and contains at least the preamble and the jamming sequence (96 bits), and at most 512 bytes.
- Once the adaptor has detected a collision and stopped its transmission, it chooses to wait either 0s or 51.2μs at random; after which it starts transmitting again. If it fails again, the adaptor flips a four-sided coin and depending on its value tries again in either 0s, 51.2μs, 102.4μs, 153.6μs. If the kth try fails it flips a 2k sided coin to get a number r between 0 and 2k-1 and tries to transmit at time 51.2*r. An adaptor tries this up to k=16 before failing with an error. This is called exponential backoff.
In fast ethernet pseudo-random number generation is done using Linear feedback shift registers.
The worst case for detecting a collision is when the hosts are on opposite ends of the Ethernet. If d is the time for a signal to go the complete length of the Ethernet. Then Host A might transmit for d seconds and Host B might just start transmitting and immediately send a jamming sequence, this takes d second to get back to A. So A might transmit for 2*d before detecting a collision. On a 10Mbps Ethernet limited to 2500m, the delay would be at most 51.2μs and this would correspond to 512 bits = 96 bytes, which is why this is used as the shortest frame length.