# Local Area Network design/Introduction to Local Area Networks
## Origins
### LAN definition

The IEEE 802 working group defined the Local Area Network (LAN) as a communication system through a shared medium, which allows independent devices to communicate together within a limited area, using an high-speed and reliable communication channel.

#### Keywords

* shared medium: everyone is attached to the same communication medium;
* independent devices: everyone is peer, that is it has the same privilege in being able to talk (no client-server interaction);
* limited area: everyone is located within the same local area (e.g. corporate, university campus) and is at most some kilometers far one from each other (no public soil crossing);
* high-speed: at that time LAN speeds were measured in Megabit per second (Mbps), while WAN speeds in bit per second;
* reliable: faults are little frequent → checks are less sophisticated to the benefit of performance.

### LAN vs. WAN comparison

Protocols for Wide Area Networks (WAN) and for Local Area Networks evolved independently until the 80s because purposes were different. In the 90s the IP technology finally allowed to interconnect these two worlds.

#### WAN

WANs were born in the 60s to connect remote terminals to the few existing mainframes:
* communication physical medium: point-to-point leased line over long distance;
* ownership of physical medium: the network administrator has to lease cables from government monopoly;
* usage pattern: smooth, that is bandwidth occupancy for long periods of time (e.g. terminal session);
* type of communication: always unicast, multiple communications at the same time;
* quality of physical medium: high fault frequency, low speeds, high presence of electromagnetic disturbances;
* costs: high, also in terms of operating costs (e.g. leasing fee for cables);
* intermediate communication system: required to manage large-scale communications (e.g. telephone switches) → switching devices can fault.

#### LAN

LANs appeared at the end of the 70s to share resources (such as printers, disks) among small working groups (e.g. departments):
* communication physical medium: multi-point shared bus architecture over short distance;
* ownership of physical medium: the network administrator owns cables;
* usage pattern: bursty, that is short-term data peaks (e.g. document printing) followed by long pauses;
* type of communication: always broadcast, just one communication at the same time;
* quality of physical medium: greater reliability against failures, high speeds, lower exposure to external disturbances;
* costs: reasonable, concentrated mainly when setting up the network;
* intermediate communication system: not required → lower cost, higher speed, greater reliability, greater flexibility in adding and removing stations.

### Communication medium sharing

Before the advent of hubs and bridges, the shared communication medium could be implemented in two ways:
* physical broadcast: broadcast-based technologies, such as the bus: the signal sent by a station propagates to all the other stations;
* logical broadcast: point-to-point technologies, such as the token ring: the signal sent by a station arrives at the following station, which duplicates it toward the station after that one, and so on.

#### Issues

* privacy: everyone can hear what crosses the shared medium → an addressing system should be made (nowadays: MAC addresses);
* concurrency: just one communication at a time is possible:
** collisions: if two stations transmit simultaneously, the data sent by a station may overlap the data sent by the other one → a mechanism for collision detection and recovery should be made (nowadays: CSMA/CD protocol);
** channel monopolization: in the back-to-back transmission, a station may occupy the channel for a long period of time preventing other stations from talking → a sort of statistical multiplexing, that is simulating multiple communications at the same time by defining a maximum transmission unit called chunk and by alternating chunks from a station with the ones from another one (nowadays: Ethernet frames), should be made.

## Data-link sub-layers

In LANs the data-link layer is split in two sub-layers:
* MAC: it arbitrates the access to the physical medium, and is specific for each physical-layer technology;
* LLC: it defines the interface toward the network layer, and is common in all physical-layer technologies.

## MAC

Every network card is identified uniquely by a MAC address. MAC addresses have the following format:
MAC address format (6 bytes). :
| 24 | 48 |
| OUI | NIC ID |
where the fields are:
* Organization Unique Identifier (OUI) field (3 bytes): code assigned uniquely by IEEE to identify the network card manufacturer:
** first least-significant bit in the first byte:
*** Individual (value 0): the address is associated to a single station (unicast);
*** Group (value 1): the address refers to multiple stations (multicast/broadcast);
** second least-significant bit in the first byte:
*** Universal (value 0): the address is assigned uniquely;
*** Local (value 1): the address is customized by the user;
* NIC Identifier (NIC ID) field (3 bytes): code assigned uniquely by the manufacturer to identify the specific network card (also called 'Network Interface Controller' [NIC]).
The Media Access Control (MAC) header has the following format:
MAC header format (18 bytes). :
| 48 | 96 | 112 | 46 to 1500 bytes | 4 bytes |
| Destination Address | Source Address | Length | payload | FCS |
where the fields are:
* Destination Address field (6 bytes): it specifies the destination MAC address.
    This is put before the source MAC address because in this way the destination can process it earlier and discard the frame if it is not addressed to it;
* Source Address field (6 bytes): it specifies the source MAC address (always unicast);
* Length field (2 bytes): it specifies the payload length;
* Frame Control Sequence (FCS) field (4 bytes): it includes the CRC code for integrity control over the entire frame.
    If the CRC code check fails, the arrived frame was corrupted (e.g. because of a collision) and is discarded; higher-layer mechanisms (e.g. TCP) will be responsible for recovering the error by sending again the frame.
A network card when receiving a frame:
* if the destination MAC address matches with the one of the network card or is of broadcast type ('FF-FF-FF-FF-FF-FF'), it accepts it and sends it to higher layers;
* if the destination MAC address does not match with the one of the network card, it discards it.
A network card set in promiscuous mode accepts all frames → it is useful for network sniffing.

### LLC

The Logical Link Control (LLC) header has the following format:
LLC header format (3 or 4 bytes). :
| 8 | 16 | 24 or 32 |
| DSAP | SSAP | CTRL |
where the fields are:
* DSAP field (1 byte, of which 2 bits reserved): it identifies the upper-layer protocol used by the destination;
* SSAP field (1 byte, of which 2 bits reserved): it identifies the upper-layer protocol used by the source;
* Control (CTRL) field (1 or 2 bytes): it derives from the HDLC control field, but is unused.

#### Issues of DSAP and SSAP fields

* limited set of values: just 64 protocols can be coded;
* codes assigned by ISO: just protocol published by an internationally recognized standard organization are corresponding to codes, while protocols defined by other bodies or pushed by some vendors (e.g. IP) are excluded;
* code redundancy: there is no reason to have two fields to defines protocols, because the source and the destination always talk the same protocol (e.g. both IPv4 or both IPv6).

#### SNAP

The Subnetwork Access Protocol (SNAP) is a particular implementation of LLC for protocols which have not a standard code.
The LLC SNAP header has the following format:
LLC SNAP header format (8 bytes). :
| 8 | 16 | 24 | 48 | 64 |
| DSAP (0xAA) | SSAP (0xAA) | CTRL (3) | OUI | Protocol Type |
where the fields are:
* DSAP, SSAP, CTRL fields: LLC fields are fixed to indicate the presence of the SNAP header;
* Organization Unique Identifier (OUI) field (3 bytes): it identifies the organization which defined the protocol.
    If it is equal to 0, the value in the 'Protocol Type' field is corresponding to the one used in Ethernet DIX;
* Protocol Type field (2 bytes): it identifies the upper-layer protocol (e.g. 0x800 = IP, 0x806 = ARP).
Actually, the LLC SNAP header is not very used due to waste of bytes, to the benefit of the 'Ethertype' field in Ethernet DIX.

## References

* 1 2 According to the canonical order (network byte order), which is the native order in IEEE 802.3 (Ethernet) but not in IEEE 802.5 (token ring) (please see section Bit-reversed notation in article MAC address on the English Wikipedia).