L2 covers MAC address learning, VLAN. For me layer two is maily MAC layer.
If you want to get the MAC address of a host, ARP protocol will be used. For example, if A want to get the MAC address of B, A broadcast ARP request packets. If B receive the packets, it will reply ARP reply packets to A and then A learned MAC of B.
MAC
For thernet the priciple the MAC learning is CSMA/CD. It is kind of difficult to understand the principle. But the cocept of collision domain must be understood.
MAC address is 6 Bytes, 48 bits in total. OUI is special part used to differentiate various factories.
Broadcast addresses, unicast addresses and multicast addresses are divided. The port will learn the source MAC addresses of packets received.
VLAN
802.1Q tag is 2 Bytes in total. Priority, CFI, VLAN-ID are divided.
- The Priority comes from 0 to 7, 3bits. It is used for QoS such as bandwidth sheduling. For the switch different service flows are mapped into different queues. The sheduling method such as strict-priority, wrr can be used.
- VLAN-ID comes from 0 to 4094, 12bits.
VLAN(802.1q) is used to separate the broadcast domains. One vlan is one broadcast domain. if a L2 switch doesn't support VLAN, broadcast packets from a port will be received by any other port. On the other hand, if the L2 switch support the VLAN, the ports only receive the packets from the same vlan.
if port isolation is enabled, the UNI ports will not receive the packets from other UNI ports even if they are in the same broadcast domain.
Double tag services: The host such as PC send packets without tag to the switch ports. The ports add c-vlan to the packets received. When the upper class devices received the tagged packets another tag may also be added.
collision domains all ports in the same collision domain
HUB all ports in the same collision domain
L2 switch all ports in the same broadcast domain
L3 switch
router