2.1 KiB
3. Network Layer
The Network Layer is responsible for handling the data transfer between two different networks. This means that this layer is not needed if the receiving device is on the same network.
The Network Layer breaks up segments from the Transport layer into smaller chunks called Packets. The reverse happens on the receiving device (reassembling packets into segments).
Furthermore the Network Layer also finds the optimal path to travel from origin network to the destination network. This is called routing.
Routing
Routing is finding the shortest (most efficient) path from source to destination and forwarding the messages over that calculated path.
Routing is difficult because it has to deal with a lot of things:
- Network topology may change.
- New hosts may be added.
- Some connections/hosts may be removed.
- Distance between hosts may change.
Routers use tables called routing tables. The table contains the next point on the shortest path to each destination.
Steps:
- Routing: Finding the most efficient path(s)
- Forwarding: Send info to the nest point from the routing table.
A router can not practically store all hosts in the table as that would be way to many.
So instead the router stores only possible destination networks.
The address to identify a host on a networks should have the format: {Network, Host}
Forwarding
When a router receives a packet:
- Extracts the destination address from packet.
- Separates the network ID from the rest of the address.
- Looks if it can match the networks id in routing table.
- If Match found: Sends packet using suggested paths in its table for that destination.
- If no match found: Send packet over the default path which is the path to the next (probably a higher level) router.
Separating network ID from address
Router needs to know how many digits are used as network ID. Routers keep this information in their routing table.
A binary number named a netmask is used to show the network ID where 1's show the network ID.
Example:
Network ID is marked as bold.
- Netmask: 11111111.11111111.00000000.00000000
- Address: 195.210.23.14