# Router

![](https://3928478158-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FhjMjdRXwO33Lfo7uCpl6%2Fuploads%2Fgit-blob-847f7a1f700e1752906bd1628fad84ffecd70769%2Fgateway.png?alt=media)

## Router

A router is a device that does two main functions:

1. ***Routing***
2. ***Switching***

### ***Routing***

It decides on which outbound link send the packet. This decision is based on destination address and its router table (Table 4.1). In each routing table, a network address is associated to an outbound interface, where the packet will be forwarded.

Each network address is followed by a "/" and a number that defines how many most significant bits of net mask are set to 1. The default adddress, that is always in each routing table, is 0.0.0.0. This one is associated to the interface on which the packet will be sent if no one of the previous messages matches with the one of the destination.

For each entry of the routing table, the network address is ANDed with its net mask and the IP address, we are looking for, ANDed with that net mask gives us the same result of the first one, the packet is sent to the corresponding interface.

The default address 0.0.0.0 is associated with a net mask, composed by all 0's. Hence every address, ANDed with this net mask, matches with default address 0.0.0.0.

| Address prefix | Outbound interface |
| -------------- | ------------------ |
| 147.162.0.0/16 | 2                  |
| 88.80.187.0/24 | 4                  |
| ...            | ...                |
| 0.0.0.0        | 1                  |

### ***Switching***

It sends the packet to the link previously selected.

Each router manages all the incoming packets, storing them in a input FIFO bufer (Standard Service Layer ). By default, if packets arrive too fast to in the buffer, w\.r.t. velocity of incoming data processing, new packets are dropped if buffer is already full according to some policy.

Hence routers has not responsability if some packets are dropped because of it declares it in advance and its goal is to give user the best effort. The behaviour of the router management of the input buffer is based on different policy, according to a goal:

* ***To reduce latency*** the packets are sorted by precedence index
* ***To reduce loss rate*** dropped packets are the last enetered without R bit set
* ***To reduce throughput*** the packets are stored by index, calculated by the router, based on the amount of data transfered from each source/destination in a time unit (e.g. RSUP, virtual clock, MPLS, Stop & GO criteria) The user cannot set all the possible criteria, because these depend from agreement developed with Service Provider. Hence the Internet Service Provider, if all criteria are set, reset them all before sending packets to Internet.
