Theory, Laboratories and Exercises For Mikrotik RouterOS
Theory, Laboratories and Exercises For Mikrotik RouterOS
Theory, Laboratories and Exercises For Mikrotik RouterOS
Basic routing
1. Routing classification
2. RouterOS routing components
3. Default route
4. Connected Routes
5. Static routing
6. Labs
7. Summary questions
2. Advanced static routing
1. Types of load balancing
2. Equal Cost Multi Path (ECMP)
3. Administrative distance (distance)
4. Check-gateway-option
5. Routing policies
6. Life time (time to live - TTL)
7. Scope
8. Types of routes
9. Preferred source
10. Summary questions
3. OSPF: Open Shortest Path First
1. Dynamic routing
2. OSPF
3. OSPF for RouterOS
4. Common problems of an OSPF installation and comparisons
5. Summary questions
4. BGP: Border Gateway Protocol
1. How BGP works
2. BGP with Mikrotik RouterOS
5. 802.1q
1. The 802.1q standard
2. VLAN on RouterOS
3. RouterOS /32 and IP addresses unnumbered IP
4. Summary questions
6. Tunnel
1. Virtual Private Network
2. Tunnel
3. IP-in-IP
4. EoIP
5. IPsec
6. IPsec/XAuth
7. MPLS
7. Useful schemes and tables
1. Block diagram of packet flow
2. Differences between Cisco IOS and Mikrotik RouterOS
1. Basic routing
1. Routing classification
2. RouterOS routing components
3. Default route
4. Connected Routes
5. Static routing
6. Labs
7. Summary questions
2. Advanced static routing
1. Types of load balancing
2. Equal Cost Multi Path (ECMP)
3. Administrative distance (distance)
4. Check-gateway-option
5. Routing policies
6. Life time (time to live - TTL)
7. Scope
8. Types of routes
9. Preferred source
10. Summary questions
3. OSPF: Open Shortest Path First
1. Dynamic routing
2. OSPF
3. OSPF for RouterOS
4. Common problems of an OSPF installation and comparisons
5. Summary questions
4. BGP: Border Gateway Protocol
1. How BGP works
2. BGP with Mikrotik RouterOS
5. 802.1q
1. The 802.1q standard
2. VLAN on RouterOS
3. RouterOS /32 and IP addresses unnumbered IP
4. Summary questions
6. Tunnel
1. Virtual Private Network
2. Tunnel
3. IP-in-IP
4. EoIP
5. IPsec
6. IPsec/XAuth
7. MPLS
7. Useful schemes and tables
1. Block diagram of packet flow
2. Differences between Cisco IOS and Mikrotik RouterOS
After the second edition of the book "Theory, laboratories and exercises for
Mikrotik RouterOS" (actually only in italian language) some readers asked
to extend the work to other key topics of Mikrotik's RouterOS system. This
booklet was born starting from this request and sorting out my notes on
advanced routing, it wants to deepen the main themes of routing through the
lens of the RouterOS system exploration used in Mikrotik products. At the
same time, this book aims to be a concrete preparation for the Mikrotik
Certified Routing Engineer (MTCRE) exam even through the analysis of
real cases in which advanced routing is a fundamental and decisive tool. If
you want you can tweet tagging @vittore. Due to the complexity of the
topics I had to left out some guidelines that had helped me in the first book:
in almost all the laboratories of this book more than one router is needed
and the laboratories are not located at the end of each chapter but have been
moved in useful points to reinforce the knowledge just acquired.
This text is a work-in-progress. All suggestions are welcome. If you have
directions, write to [email protected] . A special thanks goes to my
colleagues who have sacrificed themselves in trying all the exercises.
Basic routing
«Second star to the right, ...and straight on till morning!» Edoardo Bennato
Routing.
The task of the network layer is therefore the transmission of packets
between two arbitrary hosts, which in general are not directly connected,
that is they do not have a direct connection between them. In the ISO / OSI
model, the network layer software is present in all the nodes of the network,
while that of the higher levels is present only in the terminal nodes. In
detail, the functions of the network layer are:
Routing classification
Routing, ie the process for forwarding packets from a network to other
networks can be done using:
rib The routing table is a table of data that in a specific router lists all the
known routes to certain networks. For each route the metric that represents
the cost that is spent along this route is indicated. The routing table consists
of:
In RouterOS the routing table can be displayed using menu IP > Route >
List .
For each entry in the routing table there are letters indicating the route
status according to the abbreviations shown in the table table:route-flag :
Labe
Property Description
l
disabled X The route is disabled ie it is not used.
active A The route is used to forward packets.
dynamic D The route was created by the software automatically.
It will not be exported and cannot be modified
directly.
connected C Connected route.
statica S Static Route.
rip r Created through the RIP protocol.
bgp b Created through the BGP protocol.
ospf o Created through the OSPF protocol.
mme m Created through the MME protocol.
blackhole B Do not consider packets addressed to this route and
do not notify anyone of the action.
unreachabl
U Do not consider packages addressed to this route but
e
notify the situation with an ICMP message.
prohibited P Do not consider packets addressed to this route but
notify the situation with an ICMP message.
Labels that can be associated with a route
table:route-fla g
fib Routing tables (RIB) are generally not used directly for packet
forwarding; the data present in the RIB are used to generate smaller and
specific tables called forwarding tables: Forwarding Information Base
(FIB). A forwarding table contains only the path selected by the routing
algorithm to continue routing the packet to its destination. This path is often
in the form of a cache in compressed or precompiled format, in a format
optimized for archiving and searching for the specific hardware of the
router. In Cisco devices this component is called Cisco Express Forwarding
(CEF). Then the forwarding table:
sourcing address,
destination address,
source interface,
possible marking of routing,
ToS (type of service) - field currently not used by the IPv4 protocol -
not used by RouterOS in the routing rules, but part of the search key in
the routing cache.
The results of the routing decision are remembered in the routing cache
(FIB) to improve forwarding performance. When another packet with the
same source address, destination address, source interface, routing mark
and ToS is routed, the cached results are used. This also allows the
implementation of load balancing by connection (per-connection load
balancing) via ECMP routes, since the values used to look up the entry in
the routing cache are the same for all the packets belonging to the same
connection and going in the same direction.
Forwarding Information Base (FIB)
If there is no routing entry in the cache for a packet then this is created by
executing a routing decision according to the following process:
The result of this routing decision is stored in the new routing cache entry.
Notice how a routing decision is returned from the indicated process which
can be:
Default route
The route with destination address 0.0.0.0/0 applies to all destination
addresses. This path is called the default route and indicated router is called
the default gateway. If the routing table contains an active default route then
the routing table search will always be successful. To use an analogy is like
traveling in a city and finding a road sign indicating "all directions".
Connected Routes
Connected routes are automatically created for each IP network that has at
least one interface connected to it (as specified in the IP address
configuration). RIB keeps track of the status of the connected routes but
does not change them. For each connected route there is an ip address so
that:
Static routing
Static routes are added by creating an entry in the RIB and defining a static
route to route packets. The destination network and router (gateway) to be
used for this destination is indicated. The gateway can be:
IP address,
the interface.
Remember that if Dst-address indicates 0.0.0.0/0, all IPs on the internet are
included and a default route is created.
destination;
destination address and netmask;
0.0.0.0/0 if it is a default route.
gateway:
the IP address of the gateway, must be the IP address of a subnet
with IP installed on one of the router interfaces;
the gateway in the form of an interface: it is used when the IP
gateway is unknown or is dynamic, for example in the case of a
point-to-point or serial connection.
pref source:
the source IP address of the packet that will leave the router,
usually it is the IP address installed on the interface where the
gateway is located.
distance:
it is used for route calculation and route selection;
value is between 0 and 255
by default the value is decided on the routing protocol used:
connected routes: 0
static routes: 1
eBGP: 20
OSPF: 110
RIP: 120
MME: 130
iBGP: 200
note that a distance of 255 means "rejected".
scope and target scope:
used for nexthop recursive lookup (see section scope on page
scope ).
Labs
Before carrying out the following laboratories make sure you have
answered correctly to the summary questions on the page domande-1 .
The lab runs correctly if you can ping the three laptops.
Labs solutions
{R1}
/system identity set name=R1
/ip address
add address=192.168.1.1/24 interface=ether1 network=192.168.1.0
add address=12.12.12.1/24 interface=ether2 network=12.12.12.0
/ip route
add distance=1 dst-address=23.23.23.0/24 gateway=12.12.12.2
add distance=1 dst-address=192.168.2.0/24 gateway=12.12.12.2
add distance=1 dst-address=192.168.3.0/24 gateway=12.12.12.2
{R2}
/system identity set name=R2
/ip address
add address=192.168.2.1/24 interface=ether1 network=192.168.2.0
add address=12.12.12.2/24 interface=ether2 network=12.12.12.0
add address=23.23.23.2/24 interface=ether3 network=23.23.23.0
/ip route
add distance=1 dst-address=192.168.1.0/24 gateway=12.12.12.1
add distance=1 dst-address=192.168.3.0/24 gateway=23.23.23.3
{R3}
/system identity set name=R3
/ip address
add address=192.168.3.1/24 interface=ether1 network=192.168.3.0
add address=23.23.23.3/24 interface=ether2 network=23.23.23.0
/ip route
add distance=1 dst-address=192.168.1.0/24 gateway=23.23.23.2
add distance=1 dst-address=192.168.2.0/24 gateway=23.23.23.2
Summary questions
domande-1
Solutions
Advanced static routing
«Friend, from there on sooner or later somewhere we will come» Jovanotti
ECMP - step 2
ecmp-add-masquerade
Lab
ecmp
Three routers and two PCs are required for this laboratory.
ECMP
The objective of this laboratory is to understand how to add static routes
that have the same destination but different gateways in order to achieve a
simple balancing of the ECMP type output load. The objective is to carry
out the configuration of figure ecmp-lab1 . Specifically, the two PCs must
be able to surf the internet using the two routers R2 and R3, a situation that
can be verified using the trace command performed by the two PCs.
ECMP - lab
ecmp-lab1
{R3}
/system identity set name=R3
/ip address
add address=192.168.13.3/24 interface=ether3
network=192.168.13.0
/ip dhcp-client add disabled=no interface=ether1
/ip firewall nat
add action=masquerade chain=srcnat out-interface=ether1
{R1}
/system identity set name=R1
/interface bridge add fast-forward=no name=bridge-lan
/interface bridge port
add bridge=bridge-lan interface=ether1
add bridge=bridge-lan interface=ether5
/ip address
add address=192.168.12.1/24 interface=ether2
network=192.168.12.0
add address=192.168.13.1/24 interface=ether3
network=192.168.13.0
add address=192.168.1.1/24 interface=bridge-lan
network=192.168.1.0
/ip pool add name=lan ranges=192.168.1.100-192.168.1.200
/ip dhcp-server
add address-pool=lan disabled=no interface=bridge-lan
name=lan
/ip dhcp-server network
add address=192.168.1.0/24 dns-server=8.8.8.8
gateway=192.168.1.1 \
netmask=24
#
# Relevant part for this laboratory
#
/ip firewall nat
add action=masquerade chain=srcnat out-interface=ether2
add action=masquerade chain=srcnat out-interface=ether3
/ip route add distance=1 gateway=192.168.13.3,192.168.12.2
2. From the first PC execute the command ping 8.8.8.8 and then
analyze the result of the command trace 8.8.8.8 (or tracert, or
traceroute depending on the platform used).
Note the address of the second router passed to reach the server
8.8.8.8.
PC-1> ip dhcp
IP 192.168.1.199/24 GW 192.168.1.1
3. From the second PC run the command ping 8.8.8.8 and then analyze
the result of the command trace 8.8.8.8 (or tracert, or traceroute
depending on the platform used).
Note the address of the second router passed to reach the server
8.8.8.8.
PC-2> ip dhcp
IP 192.168.1.198/24 GW 192.168.1.1
Lab
distance
Three routers and two PCs are required for this laboratory.
Distance
The aim of this workshop is to understand how the distance value affects
the selection of the active route.
4. From the two PCs the output paths are analyzed with the command
trace or equivalent.
5. Disconnect the cable that connect router R1 to router R2.
6. From the two PCs the output paths are analyzed with the command
trace or equivalent.
"Check-gateway" option
check-gateway RouterOS provides a gateway control mechanism that runs
in the background. Periodically (every 10 seconds) the gateway is checked
by sending an ICMP echo request (ping) or an ARP request (arp); if no
response is received from the gateway within 10 seconds, the request
expires (timeout). After two timeouts the gateway is considered
unreachable. Vice versa, for a gateway considered unreachable, after
receiving a reply again, the gateway is considered reachable and the timeout
counter is restored.
It is important to note that if the Check-Gateway function is activated for a
route then all routes with the same gateway will undergo the same control.
Lab
check-gateway
Three routers and two PCs are required for this laboratory.
Check-gateway
The objective of this laboratory is to understand how the control
mechanism of the router vitality (check-gateway) affects the selection of
the active route.
Check-Gateway
3. Check that the routes are correct:
Routing policies
When the decision to forward the package uses additional information, such
as the source address of the package, it is called a "routing policy". The
routing policy is implemented through lists from which the different routing
tables are selected based on destination address, source address, source
interface and a possible routing marking. To do this it is necessary to mark
the traffic and then assign it to a specific routing table. The package
marking for a specific routing table is managed by the firewall (IP >
Firewall > Mangle ) and can concern the single packet or the entire
connection. For performance reasons we prefer to mark the first packet of a
connection and then mark the entire connection accordingly: in this way the
firewall will use a smaller amount of CPU for management. The second
step for a routing policy is the creation of specific routing tables for heavy
traffic. By default, the router uses the main routing table but you can create
additional routing tables and configure the router to use a specific table. To
do this you can act on two sides:
Using IP > Route > Rules you can specify the use of a routing table based
on some parameters (see figure policy-routing-rule ) such as:
destination address,
marking the route in the package,
destination interface.
Routing mark
Routing marking takes place using what is available in the window that can
be accessed via the IP > Firewall > Mangle menu. To drive more specific
traffic through a route, it must be identified before it goes through the
routing process. In the appendix, on page packet-flow , it is schematized
how packets pass through RouterOS. To achieve this we need to act at
different points depending on the type of traffic we want to intercept and
mark:
for the traffic that passes through the router the prerouting chain is
used;
for the traffic coming from the router and out of the router the output
chain is used;
You need to be very careful at this stage because each packet can only have
one routing sign. Furthermore, if there is at least one route that uses the
routing mark for a specific traffic then the main routing table will be
ignored.
Lab
Three routers and two PCs are required for this laboratory.
Routing mark
The objective of this laboratory is to understand how the routing marking
mechanism works: ICMP traffic will have to use R3 router while the
remaining traffic will have to pass through R2 router.
Routing mark - lab
ecmp-lab-routing-mark
To better analyze the effect of this configuration we have to use to a small
stratagem that we will later use also for other laboratories of this text. Two
routers connected to internet will be used but with queues that reduce the
available bandwidth to very low values (1k) in order to immediately detect
the desired effect. Probably that it is necessary to modify the value 1 k with
a higher value (32k or 64k) in the case in which on the PCs from which the
test is performed there is background traffic (updates of windows,
Dropbox, ...).
{R3}
/system identity set name=R3
/ip address
add address=192.168.13.3/24 interface=ether3
network=192.168.13.0
/ip dhcp-client add disabled=no interface=ether1
/ip firewall nat
add action=masquerade chain=srcnat out-interface=ether1
#
# Setting the queue with 1k / 1k limitation
#
/queue simple add target=0.0.0.0/0 max-limit=1k/1k
{R1}
/system identity set name=R1
/interface bridge add fast-forward=no name=bridge-lan
/interface bridge port
add bridge=bridge-lan interface=ether1
add bridge=bridge-lan interface=ether5
/ip address
add address=192.168.12.1/24 interface=ether2
network=192.168.12.0
add address=192.168.13.1/24 interface=ether3
network=192.168.13.0
add address=192.168.1.1/24 interface=bridge-lan
network=192.168.1.0
/ip pool add name=lan ranges=192.168.1.100-192.168.1.200
/ip dhcp-server
add address-pool=lan disabled=no interface=bridge-lan
name=lan
/ip dhcp-server network
add address=192.168.1.0/24 dns-server=8.8.8.8
gateway=192.168.1.1 \
netmask=24
/ip firewall nat
add action=masquerade chain=srcnat out-interface=ether2
add action=masquerade chain=srcnat out-interface=ether3
2. Before proceeding, check the correct queues set operation. For this
reason, from one of the two PCs, generate internet traffic (http, https,
ftp, ...) and check that the queue of the R2 router goes from green to
red in Queue > Simple .
Queue limited to 1k / 1k with no traffic passing through the R2 router
Real case
Bill has a Mikrotik router with an ADSL line provided by the ISP1 provider
that connects the clients of his network to internet. Bill adds a second
ADSL line with ISP2 provider and wants this to be only for some specific
users, VIPs who are paying a little extra money for better speed, as the
current connection with ISP1 is clogged by the traffic of others users.
Solution
1. Two lists of IP addresses are created and the IPs of the VIP or
NORMAL users are added.
2. Two traffic marking rules (mangle) are added to mark the packets
generated by VIP and NORMAL users.
3. Two default routes are specified with the appropriate routing marks
and gateways.
4. Add the NAT rules.
# Adding IP addresses on interfaces
#
/ip address
add address=192.168.2.1/24 disabled=no interface=LAN
network=192.168.2.0
Scope
scope The check gateway mechanism, described in section check-gateway
on page check-gateway , can detect connection problems only in the nearest
router. If the problem occurs after the nearest gateway, the gateway check
cannot detect it. To overcome this drawback and to efficiently select the
next router to which to forward the traffic, techniques can be used that
define the scope (scope) of the routing itself. The search for the nexthop is
part of the path selection process: the routes installed in the FIB must have
an interface associated with each gateway address, in this way the gateway
address is directly accessible via this interface. The expression recursive
search of the nexthop means the search for the gateway and the interface to
use to follow the route even if there is a gateway not directly connected to
the router. This is due to the fact that some routes (eg IBGP) may have a
gateway address that is located at different hops from this router. To install
these paths in the FIB it is necessary to find the address of the gateway that
can be reached directly (an immediate nexthop), which will be used to reach
the gateway address of this route.
The search for nexthop is performed only in the main routing table even
for routes with a different routing marking.
During this search it is necessary to limit the series of paths that can be used
to search for immediate nexthops; this result is obtained using the scope and
target-scope properties.
Routes that have the interface name as a gateway value are not used
for nexthop search.
If the route has both an interface and an active IP address nexthop then
the nexthop with the interface is ignored.
Routes with scopes greater than the maximum accepted value are not
used for the nexthop search: in fact each route specifies the maximum
scope value accepted for its nexthops in the target-scope property. The
default value of this property allows the search for nexthop only
through connected paths, with the exception of iBGP routes which
have a wider default value and can therefore search for nexthop also
via iBGP and static routes. For the scope and target scope defaults, see
figure default-scope-target-scope .
Example
Real case
Suppose we have several WAN links and we want to monitor if the internet
is accessible through each one. The problem can be anywhere. If the ADSL
modem does not work, check-gateway with ping is clearly the solution (and
no problem); but what happens if the modem is active and the telephone
line is not working? Or if one of the ISPs has a problem in it, then
traceroute only shows a few hops - and then it stops ... Some people use the
NetWatch tool to monitor remote locations; others use scripts to ping
remote hosts periodically and consequently disable routes or in some other
way modify routing behavior. But the RouterOS features allow us to have a
solution to these problems only by using \ip routes , no scripting and
netwatch.
Example
Suppose we have two uplinks GW1 and GW2 . These can be the ADSL
modem address (like 192.168.1.1 and 192.168.2.1) or PPP interface
addresses (like pppoe-out1 and pptp-out1). Then we have some routing
rules that for example specify that all outgoing traffic is marked with the
marks ISP1 (which goes to GW1) and ISP2 (which goes to GW2). What
interests us is to monitor host1 via GW1 and host2 via GW2; where host1
and host2 can be some popular Internet sites, like Google, Yahoo, etc. First
of all, routes are created for these hosts via the corresponding GW1
gateway using a scope = 10:
/ip route
add dst-address=Host1 gateway=GW1 scope=10
add dst-address=Host2 gateway=GW2 scope=10
These paths will be resolved recursively and will be active only if host N is
reachable by ping. Similarly, routes are created for these hosts via the
corresponding GW2 gateway using a scope = 10:
/ip route
add dst-address=Host1 gateway=GW2 scope=10
add dst-address=Host2 gateway=GW2 scope=10
Types of routes
There are types of routes that are used to block the network or a destination
address with different behaviors:
Lab
Three routers and two PCs are required for this laboratory.
Tipi di rotte
The aim of this workshop is to understand the use of different types of
routes.
{R2}
/system identity set name=R2
/ip address add address=12.12.12.2/24 interface=ether1
/ip address add address=23.23.23.2/24 interface=ether2
/ip route
add distance=1 dst-address=192.168.1.0/24
gateway=12.12.12.1
add distance=1 dst-address=192.168.3.0/24
gateway=23.23.23.3
{R3}
/system identity set name=R3
/ip address add address=23.23.23.3/24 interface=ether1
/ip address add address=192.168.3.1/24 interface=ether2
/ip route
add distance=1 dst-address=192.168.1.0/24
gateway=23.23.23.2
# Second test
dst-address=192.168.3.0/24 gateway=23.23.23.3
type=blackhole
# Third test
dst-address=192.168.3.0/24 gateway=23.23.23.3 route-
type=prohibit
# First test
dst-address=192.168.3.0/24 gateway=23.23.23.3 route-
type=unreachable
Using route:
{R2}
/ip route add dst-address=192.168.3.0/24
gateway=23.23.23.3
You get:
PC-1> ping 192.168.3.2
84 bytes from 192.168.3.2 icmp_seq=1 ttl=61 time=6.317
ms
84 bytes from 192.168.3.2 icmp_seq=2 ttl=61 time=1.753
ms
84 bytes from 192.168.3.2 icmp_seq=3 ttl=61 time=1.607
ms
84 bytes from 192.168.3.2 icmp_seq=4 ttl=61 time=2.905
ms
84 bytes from 192.168.3.2 icmp_seq=5 ttl=61 time=3.034
ms
Using route:
{R2}
/ip route add dst-address=192.168.3.0/24 type=blackhole
You get:
PC-1> ping 192.168.3.2
192.168.3.2 icmp_seq=1 timeout
192.168.3.2 icmp_seq=2 timeout
192.168.3.2 icmp_seq=3 timeout
192.168.3.2 icmp_seq=4 timeout
192.168.3.2 icmp_seq=5 timeout
Using route:
{R2}
/ip route add dst-address=192.168.3.0/24 type=prohibit
You get:
PC-1> ping 192.168.3.2
*12.12.12.2 icmp_seq=1 Communication administratively
prohibited
*12.12.12.2 icmp_seq=2 Communication administratively
prohibited
*12.12.12.2 icmp_seq=3 Communication administratively
prohibited
*12.12.12.2 icmp_seq=4 Communication administratively
prohibited
*12.12.12.2 icmp_seq=5 Communication administratively
prohibited
Using route:
{R2}
/ip route add dst-address=192.168.3.0/24
type=unreachable
You get:
PC-1> ping 192.168.3.2
*12.12.12.2 icmp_seq=1 Destination host unreachable
*12.12.12.2 icmp_seq=2 Destination host unreachable
*12.12.12.2 icmp_seq=3 Destination host unreachable
*12.12.12.2 icmp_seq=4 Destination host unreachable
*12.12.12.2 icmp_seq=5 Destination host unreachable
Preferred source
pref-src The pref-src property, which can be used when writing a static
route, indicates which of the local IP addresses has to be used for packets
originating locally and sent via this route. It is important to consider that:
As previously mentioned, if the route has not set the pref-src property then
the source address of a locally originated packet is selected from the router's
local addresses:
this local address is assigned to the output interface;
the gateway is corresponding to this local address.
Summary questions
domande-2
Solutions
1. 10.
2. Yes.
3. Before (see the diagram on page packet-flow ).
4. No, the property pref-src indicates which of the local IP addresses is to
be used for packets originating locally and sent via a specific route.
5. Yes.
6. No, all reachable nexthop gateways are copied to the FIB.
7. No, you must indicate all the addresses to which the masquerade acts.
8. by connection. See the in-depth questions on page ecmp-domanda .
OSPF: Open Shortest Path First
«And at this mad speed maybe only a round dance will save us...» Edoardo
Bennato
Dynamic routing
Advanced routing uses static and dynamic routing protocols (see figure
routing-protocols on page routing-protocols ); routers that use static type
protocols manage a routing table created and updated manually by the
network administrator, while routers using dynamic protocols provide by
themselves to create and update this table by finding information at other
dynamic routers and on all of their segments. Dynamic routers contain
constantly updated information on possible routes through the network, as
well as information on bottlenecks and connection interruptions. This
information allows them to find the most efficient way, available at a given
time, to forward a data packet to its destination. The networks are grouped
in Autonomous system (AS), that is in groups of routers and networks
controlled and managed by a single entity. AS are identified by a global
number, univocal, assigned by the same authority that issues the internet
addresses. Routers that route messages within the same AS are called
interior router or internal router , while those that route messages between
different AS are called exterior router .
This type of approach is based on the fact that each router keeps track of the
distance and direction (vector ) of all possible destinations within the
internetwork. The way in which the distances present in the routing tables
can be calculated depend on different characteristics of the communication
such as:
In first instance, the router itself will detect which networks are directly
connected to it, assigning a zero distance in routing table. Then it will pass
its table to neighboring routers, ie those connected to it. Each table will then
be replicated to all adjacent routers at 60 second intervals. From this it
follows that this kind of protocols doesn't allow to have a knowledge of the
network in its entirety, but only of the successive jumps (next hop) that will
allow to forward the packets to the final destination.
Link state based protocols have a different approach than distance vector
based protocols to collect the information needed to perform dynamic
routing and to calculate routes to be added to routing tables. An important
feature of these protocols is to maintain a complete view of the network
topology, ie each router is aware of the existence of any other router on the
network and how they are connected to each other, for this result a network
map is built. Link state protocols are based on the concept of "distributed
map": all the nodes have a copy of the map of the network, which is
regularly updated. The link state protocol maintains a complex database to
store topology information, which is used to calculate routes to possible
destinations. In this database each record represents a link in the network.
With this information, each node can easily calculate the shortest path from
itself to all other nodes. Since all the nodes contain the same database and
run the same route-generation algorithm, the paths are consistent and no
loops occur. To do this, each router uses an SPF algorithm (shortest path
first ): the shortest path among the possible for a given destination is
chosen. This algorithm is also known as the Dijkstra algorithm. This allows
each router to identify the routes by creating a tree structure representing
the network and having the router itself as root.
OSPF
OSPF stands for Open Shortest Path First. This routing protocol is based on
link state technology, unlike RIP which is based on the distance vector
algorithm. In OSPF there is a distributed database, a flooding procedure and
an adjacency definition. OSPF belongs to the IGP class and therefore
operates internally in each Autonomous System (AS). The protocol
exchanges LSA messages (Link State Advertisement), literally
"announcement on the status of the link", with all those routers belonging to
the same AS, being of the link state type, uses the SPF algorithm to
calculate the shortest route to each destination. Furthermore, since the
Internet is made up of many AS, sometimes quite large and not easily
manageable, OSPF offers the possibility of dividing the AS into numbered
areas, (called OSPF areas and identified by a number of 32 bits called area-
id) each of which is formed from one or more networks. This means that the
topology and the details inside a certain area are not visible outside it. Each
AS has a backbone area (backbone) called Area 0, which has the purpose of
communicating the different areas belonging to the same AS. Within each
area, each router maintains the same database created with the exchange of
LSA messages, calculates the minimum path by itself, towards each other
routers belonging to the same area, including the router that is connected to
the backbone ("area-border routers" ABR). As described in figure ospf-
definizioni there must be at least an ABR in each area, to connect it to the
backbone. The ABRs maintain numerous databases, one for each area to
which they belong and each area includes a set of IP subnets. In addition to
ABRs, we can still distinguish 2 types of routers:
Internal routers : these are the routers that manage the traffic within
the same area
Autonomous System Boundary Routers (ASBR) : they are gateways
for external traffic and convert paths in the OSPF domain learned by
other protocols such as BGP and EIGRP.
Intra-area : in this case the source router knows the minimum path to
the destination router, thanks to the database that has been built;
Inter-Area : the total path can be divided into three stages, the first
concerns the search for a route from the source to the backbone, the
second from the backbone to the destination area, and the third to the
destination router inside of the previously identified area.
Inter-Autonomous system : in this case Border router routers will be
designated, which allow connections to be made between different
ASs, using an EGP protocol.
Each area behaves like an independent network; the database includes only
the link status of the area, the flooding protocol stops at the borders of the
area and the routers calculate only the routes within the area. The cost of the
routing protocol is thus proportional to the format of the area and not to that
of the network. Thanks to hierarchical subdivision, it is possible both to
reduce the routing traffic exchanged between the nodes of the OSPF
network, and to reduce the size of the routing tables of the routers within
each individual area. Furthermore, the convergence time of the OSPF
protocol is reduced since the routers will have to apply the Dijkstra
algorithm on a smaller graph and therefore with a smaller CPU and,
consequently, in less time. The AS routers periodically send to their
neighbors (every 10 seconds in the case of local networks), or in
correspondence with topological changes in the network, "Hello" packets,
which have the task of verifying which of the directly connected routers, is
active. In this phase, each router will acquire a knowledge of its neighbors
and build a "partial" map of the network containing the topological
information. The OSPF routers communicate via the OSPF protocol, which
is directly encapsulated in IP (protocol type = 89) and is, in turn, composed
of 3 sub-protocols:
Now we are ready to face the OSPF protocol. Let's summarize what has
been described so far:
Area
OSFP areas
aree
The OSPF protocol allows routers to be grouped into sets called area . Each
area makes a separate copy of the routing algorithm, which means that each
area has its own link-state database and the corresponding shortest path
tree. The structure of an area is invisible to other areas, this knowledge
isolation makes the protocol more scalable because the calculation of
routing table requires less CPU resources and routing traffic is reduced.
However, the multi-area settings create further complexity and for this
reason it is not advisable to separate the areas with less than 50 routers even
if the maximum number of routers in an area mainly depends on the CPU
power that is available for the calculation of the routing table. Each area is
identified by a unique area-id within an AS. In each AS there must always
be an area with area-id = 0.0.0.0 (the backbone). This special area, the
backbone literally "backbone", always contains all the boundary routers of
the area and is responsible for the distribution of routing information
between non-backbone areas. Given this particular role the backbone area
must be contiguous, ie there must not be any disconnected segments;
however, it is not necessary for the area border routers to be physically
connected to the backbone: the connection to it can be simulated using a
virtual connection. The topic will be covered in the section virtual-link on
page virtual-link through a specific laboratory. Therefore a network with
active OSPF protocol is initially identified as Area 0. In the case of network
expansion, other areas adjacent to area 0 can be created, with values in the
range 0-4294967295. A group of areas generates an autonomous OSPF
system (OSPF Autonomous System). Some abbreviations used by the
protocol:
The OSPF routers establish and maintain a relationship with the neighbors,
technically called adjacency or contiguity. After initialization or after some
change in routing, a router with active OSPF generates announcements,
called LSA (Link State Advertisement ), containing topological information
about the network. Through a process called flooding, announcements are
exchanged with all the routers on the network. As soon as a router receives
the LSAs, it creates a Link-State Database on which it applies the Dijkstra
SPF (Shortest Path First) algorithm to create a network topology tree, or
more simply a network map. Each router creates a Link-State Database and
builds its SPF tree starting from the same link-state information; however
each one generates its own view of the network topology, different from
that created on the other routers. Initially, each router identifies itself as the
root of the tree; then, starting from this root, the algorithm identifies the
shortest path for each destination, with its cost. Schematically, each router
with OSPF must:
Discovery of neighbors
To know the entire topology of a network, each router sends a Hello packet
to all the available point-to-point connections and receives their answer,
from the directly connected routers, their identifier, called Router ID. The
time that elapses between sending two Hello packets is regulated by the
Hello Interval field, by default 10" on Ethernet networks and point-to-point,
30" on serial links in Multiaccess networks such as Frame Relay. The
maximum time a router waits for the Hello Packet is regulated by the Dead
Interval field, by default 40" on Ethernet networks and on point-to-point
serial links, 120" on Multiaccess networks such as Frame Relay, therefore
quadruple values compared to Hello Interval. To calculate the connection
cost with neighboring routers, an Echo packet is used with which the time
required to obtain a response is measured. Before reaching the "perfect"
knowledge of neighbors, called textit{neighbor adjacency}, the router goes
through various state changes. The full state, and therefore the adjacency
neighbor between two routers, is only possible if all the following
conditions are met:
To learn more about the OSPF protocol, see also the documents:
OSPF calculates the cost of the metric based on the bandwidth and speed of
a specific connection. The equation used to calculate the cost of an OSPF
connection is: Cost = 100.000.000 / bandwidth of the link in bps The results
of this equation, applied to some connection types, are shown in the table
table:metrica .
Link bandwidth in Cos
Interface type
bps t
Fast ethernet e
100.000.000 1
oltre
Ethernet 10.000.000 10
E1 2.048.000 48
Metric
table:metrica
add-area
Adding a network connected to the area.
add-network
Lab
Three routers and two PCs are required for this laboratory.
Aree e network OSPF
The objective of this laboratory is to create a simple OSPF configuration
divided into three areas.
{R2}
/ip address add interface=ether1 address=12.12.12.2/24
/ip address add interface=ether2 address=23.23.23.2/24
{R3}
/ip address add interface=ether2 address=23.23.23.3/24
/ip address add interface=ether1 address=192.168.3.1/24
From PC-2:
PC-2> ping 192.168.3.1
84 bytes from 192.168.3.1 icmp_seq=1 ttl=64 time=2.903 ms
84 bytes from 192.168.3.1 icmp_seq=2 ttl=64 time=0.484 ms
4. Notice how the last ping fails because the necessary routes for packet
transit are missing.
5. For this we check the routing tables on R1, R2 and R3:
R1:
[admin@R1] > /ip route print
Flags: X - disabled, A - active, D - dynamic, C -
connect, o - ospf
# DST-ADDRESS PREF-
SRC GATEWAY DISTANCE
0
ADC 12.12.12.0/24 12.12.12.1 ether2
0
1
ADC 192.168.1.0/24 192.168.1.1 ether1
0
R2:
[admin@R2] > /ip route print
Flags: X - disabled, A - active, D - dynamic, C -
connect, o - ospf
# DST-ADDRESS PREF-
SRC GATEWAY DISTANCE
0
ADC 12.12.12.0/24 12.12.12.2 ether1
0
1
ADC 23.23.23.0/24 23.23.23.2 ether2
0
R3:
[admin@R3] > /ip route print
Flags: X - disabled, A - active, D - dynamic, C -
connect, o - ospf
# DST-ADDRESS PREF-
SRC GATEWAY DISTANCE
0
ADC 23.23.22.0/24 23.23.23.3 ether2
0
1
ADC 192.168.2.0/24 192.168.3.1 ether1
0
7. For each router we define the ospf areas of which the router is a part;
the backbone area is already present by default on all routers:
{R1}
/routing ospf area add name=area-1 area-id=0.0.0.1
{R2}
/routing ospf area add name=area-1 area-id=0.0.0.1
/routing ospf area add name=area-2 area-id=0.0.0.2
{R3}
/routing ospf area add name=area-2 area-id=0.0.0.2
8. For each router we add the networks on which OSPF will operate and
associate them with the respective area:
{R1}
/routing ospf network add network=192.168.1.0/24 area=area-
1
/routing ospf network add network=12.12.12.0/24
area=backbone
{R2}
/routing ospf network add network=12.12.12.0/24
area=backbone
/routing ospf network add network=23.23.23.0/24
area=backbone
{R3}
/routing ospf network add network=192.168.3.0/24 area=area-
2
/routing ospf network add network=23.23.23.0/24
area=backbone
R3:
[admin@R3] > /ip route print
Flags: X - disabled, A - active, D - dynamic, C -
connect, o - ospf
# DST-ADDRESS PREF-
SRC GATEWAY DISTANCE
0
ADo 12.12.12.0/24 23.23.23.2
110
1
ADC 23.23.23.0/24 23.23.23.3 ether2
0
2
ADo 192.168.1.0/24 23.23.23.2
110
3
ADC 192.168.3.0/24 192.168.3.1 ether1
0
10. To confirm the correct operation of our network we can try the two
pings that failed first or the ping between the two PCs:
PC-1> ping 12.12.12.2
84 bytes from 12.12.12.2 icmp_seq=1 ttl=63 time=6.154 ms
84 bytes from 12.12.12.2 icmp_seq=2 ttl=63 time=1.477 ms
Loopback interface
Virtual link
Lab
lab-virtual-link
Three routers and two PCs are required for this laboratory.
Virtual link between areas
The objective of this laboratory is to connect areas not adjacent to the
backbone area through a virtual link.
4. As can be seen, on the R2 router, OSPF has not collected the area-
3 area routes as it is not connected to the backbone area:
[admin@R2] > /ip route print
Flags: X - disabled, A - active, D - dynamic,
C - connect, S - static, r - rip, b - bgp, o - ospf, m
- mme,
B - blackhole, U - unreachable, P - prohibit
# DST-ADDRESS PREF-
SRC GATEWAY DISTANCE
0
ADo 1.1.1.1/32 12.12.12.1
110
1
ADC 2.2.2.2/32 2.2.2.2 loopback
0
2
ADC 12.12.12.0/24 12.12.12.2 ether1
0
3
ADC 23.23.23.0/24 23.23.23.2 ether2
0
4
ADo 192.168.1.0/24 12.12.12.1
110
DR e BDR
Neighbors State
Using the Routing > OSPF > Neighbors menu, you can view the
status of nearby routers (figure neighbors-state ).
Neighbors State
neighbors-state
The possible states are:
In the link type protocols state the packets sent by a router and that
allow the construction of the network map, once received by the
various routers of the network, are called Link State Packet (LSP):
packet of the state of the connections. Each LSP can contain multiple
Link State Advertisement (LSA) message on the status of the links,
which disseminate information on the status of links such as traditional
LSPs but are not packets. LSAs are generated by each router of the AS
depending on the skills assigned to it. There are five types of LSAs:
LSAs are propagated through a Link State Update package which can
contain more than one ad, but each propagated only one forward hop.
Conversely, to guarantee the reliability of the propagation process it is
good that the acknowledgments are retransmitted one at a time
(although they can also be grouped together) in a packet of the Link
State Acknowledgment type. One of the typical elements of the
propagation process is also the Retrasmission List which, in each
router, takes into account the received LSAs that have not yet been
acknowledged. Each interface will therefore have a specific
retransmission list appropriately set taking into account the speed of
this interface. This information is visible using the Routing > OSPF >
LSA menu (see figure lsa ).
Types of networks
This is by far the simplest type of network and the easiest starting
point for understanding other topologies. A point-to-point network is a
connection between exactly two points (or routers). A packet sent by
one of the routers will always have exactly one recipient on the local
link.
Point-to-Point
Broadcast
Broadcast
broadcast
In Ethernet networks a single packet transmitted by a device can be
multiplied by the medium (in this case an Ethernet swith) so that every
other end point receives a copy. This is advantageous not only for the
resulting bandwidth savings but also because this facilitates the
automatic discovery of neighbors. In the example shown in figure
broadcast , R1 can multicast (a transmission destined only to certain
recipients) of a Hello OSPF message on the entire segment, knowing
that all the other OSPF routers connected to the segment will receive it
and will reply with your own multicast message. As a result, neighbors
can quickly identify and form adjacencies without first knowing the
addresses. OSPF routers on a multiaccess segment will elect a
designated router (DR) and a designated backup router (BDR) with
which all non-designated routers will form an adjacency. This is to
ensure that the maintained number of adjacencies does not grow too
much; a segment containing ten routers would require 45 connections
to form a mesh, but only 17 when there is a DR and a BDR.
Non-Broadcast
Non-Broadcast
non-broadcast
Note that in the frame relay topology shown in figure non-broadcast ,
R1 must prepare and transmit a single package for each destination it
wishes to reach. In addition to being inefficient in terms of bandwidth,
this limitation requires the router to know the addresses of its
neighbors before it can communicate with them. OSPF can operate on
a non-broadcast network in two non-broadcast (NBMA) or point-to-
multipoint multi-access modes. Each of these topologies addresses the
absence of transmission capacity from a different perspective. {Non-
Broadcast Multi-Access (NBMA)} An NBMA segment emulates the
typical function of a broadcast network. Each router on the segment
must be configured with the IP address of each of its neighbors. The
OSPF Hello packages are then transmitted individually as unicast
packages to each adjacent neighbor. As in a real broadcast network, a
DR and BDR are elected to limit the number of formed adjacencies. It
is important to remember that in an NBMA network it is necessary to
specify the neighbors manually (see figure add-nbma ).
Lab
Type-1
type-1
5. Set the OSPF instance of router R1 to redistribute the static route
with Type-2 metric:
{R1}
/routing ospf instance set redistribute-static=as-type-
2 numbers=0
Types of areas
Standard area
Standard area
The following LSAs are propagated:
Area stub
Stub area
Stub Area refers to those types of areas that do not receive external
routes. External routes will then be defined and distributed by another
routing protocol. Thus, the stub area needs to relegate to a default
route the exchange traffic with routes outside the belonging domain.
The following LSAs are propagated:
1. Type 1 - Router LSA : information on the routers adjacent to
those who generate the LSA
2. Type 2 - Network LSA : generated by designated routers to
describe the LAN to which the designated is connected
3. Type 3 - Summary LSA : generated by the area border router to
communicate the reachability of the other areas to the internal
routers
Not-So-Stubby Area
Area Not-So-Stubb y
Also identified as NSSA, a not-so-stubby area is a type of stub area
that can import external AS routes and send them to the backbone, but
cannot receive such external AS routes from the backbone or other
areas. The following LSAs are propagated:
Passive interfaces
When using OSPF, two things will occur: All interfaces that have IP
addresses within a network will send LSA announcements. Hello
OSPF packets are sent on these interfaces. In large ISPs and corporate
networks, some routers at the distribution level often have a large
number of interfaces, for example on the edge of the WAN. A common
practice on such routers is to enable routing processes on a network
interval corresponding to different interfaces. While this technique
facilitates the routing protocol configuration, enabling indiscriminate
routing on more or all interfaces can increase the chances of entering
unauthorized routing peers. Furthermore, the exchange of unnecessary
routing protocols increases the CPU overhead on the router. For this
reason it is sometimes not desirable to send OSPF Hello packets on
certain interfaces. This functionality is obtained by putting the specific
interface in passive mode (figure interface-passive ).
Passive interface
interface-passive
Cost
All OSPF interfaces have a cost, which is a routing metric used in the
calculation of the link state. Paths with lower total metrics are
preferred to those with higher path metrics. By default, OSPF assigns a
default cost metric of 1 to any link faster than 100 Mbps. This means
that all interfaces faster than 100 Mbps have the same default cost
metric of 1. Having the same default metric may not be a problem if all
the interfaces are running at the same speed but if the interfaces
operate at different speeds, you may notice that the traffic is not routed
on the faster interface because OSPF addresses packets equally
through the different interfaces. For example, if the routing device has
Fast Ethernet and Gigabit Ethernet interfaces with OSPF, each of these
interfaces has a default cost metric of 1. There is an interesting thread
in the Mikrotik forums where through a script it is suggested to set the
cost of each interface based on the speed of the interface:
http://bit.ly/2VxVDOG .
Redundancy
Summary questions
domande-3
Solutions
1. No.
Only Type-1 routes include internal metrics. Type 2 external
metrics use only the external cost for the destination and ignore
the cost (metric) to reach the AS border router. On this see the
two figures on page type-1 which summarize the result of the
laboratory type-1-2 .
2. No, only one DR and one BDR.
3. No. The backbone area always exists.
4. Yes. It is precisely this characteristic combined with the fact of
executing the same routing generation algorithm that ensures that
the paths are consistent and no loops occur.
BGP: Border Gateway Protocol
{«Give me hope in better time \\ with open eyes but no borders...»} Pooh
Lab
Two routers and two PCs are required for this laboratory.
Simple BGP communication between two ASs.
The goal of this laboratory is to create a simple configuration in which two
routers belonging to different AS communicate the routes of their
knowledge to each other.
Simple BGP communication between two ASs.
bgp-lab1
dhcp server interface: ether1 Select network for DHCP addresses dhcp
address space: 192.168.1.0/29 Select gateway for given network
gateway for dhcp network: 192.168.1.1 Select pool of ip addresses
given out by DHCP server addresses to give out: 192.168.1.2-
192.168.1.6 Select DNS servers dns servers: Select lease time lease
time: 10m
3. We check that the PC-1 has obtained a valid ip address and is able to
communicate with R1:
PC-1> ping 192.168.1.1
84 bytes from 192.168.1.1 icmp_seq=1 ttl=64 time=2.637 ms
84 bytes from 192.168.1.1 icmp_seq=2 ttl=64 time=0.503 ms
84 bytes from 192.168.1.1 icmp_seq=3 ttl=64 time=0.418 ms
84 bytes from 192.168.1.1 icmp_seq=4 ttl=64 time=0.360 ms
84 bytes from 192.168.1.1 icmp_seq=5 ttl=64 time=0.401 ms
dns servers:
Select lease time
6. Now let's configure the connection that allows the two routers to
communicate with each other:
[admin@R1] > /ip address add interface=ether2
address=192.168.100.1/30
8. Now we have connected all the infrastructure but clearly PC-1 cannot
reach the 192.168.2.0/30 subnet:
PC-1> ping 192.168.2.6
*192.168.1.1 (ICMP type:3, code:0, Destination network
unreachable)
*192.168.1.1 (ICMP type:3, code:0, Destination network
unreachable)
*192.168.1.1 (ICMP type:3, code:0, Destination network
unreachable)
*192.168.1.1 (ICMP type:3, code:0, Destination network
unreachable)
10. We expose the known network and verify the routing table:
[admin@R1] > routing bgp network add network=192.168.1.0/29
12. We expose the known network and verify the routing table:
[admin@R1] > ip route print interval=1s
Flags: X - disabled, A - active, D - dynamic,
C - connect, S - static, r - rip, b - bgp, o - ospf, m -
mme,
B - blackhole, U - unreachable, P - prohibit
# DST-ADDRESS PREF-
SRC GATEWAY DISTANCE
0
ADC 192.168.1.0/29 192.168.1.1 ether1
0
2
ADb 192.168.2.0/29 192.168.100.2
20
1
ADC 192.168.100.0/30 192.168.100.1 ether2
0
13. As you can see, the route known from AS111 has been transferred via
BGP.
14. Similarly the AS111 received the routes known and exhibited by the
AS222:
[admin@R2] > ip route print
Flags: X - disabled, A - active, D - dynamic,
C - connect, S - static, r - rip, b - bgp, o - ospf, m -
mme,
B - blackhole, U - unreachable, P - prohibit
# DST-ADDRESS PREF-
SRC GATEWAY DISTANCE
0
ADb 192.168.1.0/29 192.168.100.1
20
1
ADC 192.168.2.0/29 192.168.2.1 ether1
0
2
ADC 192.168.100.0/30 192.168.100.2 ether2
0
15. Now the routers are aware of the entire infrastructure and the ping
from PC-1, which had previously failed in step 8., now reaches the
goal:
PC-1> ping 192.168.2.6
84 bytes from 192.168.2.6 icmp_seq=1 ttl=62 time=6.653 ms
84 bytes from 192.168.2.6 icmp_seq=2 ttl=62 time=1.085 ms
84 bytes from 192.168.2.6 icmp_seq=3 ttl=62 time=0.947 ms
84 bytes from 192.168.2.6 icmp_seq=5 ttl=62 time=1.078 ms
Lab
bgp-lab2
Three routers and a PC are required for this laboratory.
Simple multihomed BGP infrastructure.
The goal of this laboratory is to create this configuration that can be
used for sharing the load between ISPs or an ISP as the main and
other ISPs as backup links.
{R2}
/system identity set name=R2
/ip address
add address=192.168.2.1/24 interface=ether1
network=192.168.2.0
{R3}
/system identity set name=R3
/ip pool
add name=dhcp_pool0 ranges=10.1.1.2-10.1.1.254
add name=dhcp_pool1 ranges=10.1.2.2-10.1.2.126
add name=dhcp_pool2 ranges=10.1.2.130-10.1.2.254
/ip dhcp-server
add address-pool=dhcp_pool0 disabled=no
interface=ether3 name=dhcp1
add address-pool=dhcp_pool1 disabled=no
interface=ether4 name=dhcp2
add address-pool=dhcp_pool2 disabled=no
interface=ether5 name=dhcp3
/ip address
add address=192.168.1.2/24 interface=ether1
network=192.168.1.0
add address=192.168.2.2/24 interface=ether2
network=192.168.2.0
add address=10.1.1.1/24 interface=ether3
network=10.1.1.0
add address=10.1.2.1/25 interface=ether4
network=10.1.2.0
add address=10.1.2.129/25 interface=ether5
network=10.1.2.128
/ip dhcp-server network
add address=10.1.1.0/24 gateway=10.1.1.1
add address=10.1.2.0/25 gateway=10.1.2.1
add address=10.1.2.128/25 gateway=10.1.2.129
/ip route
add gateway=192.168.1.1 check-gateway=ping
add gateway=192.168.2.1 distance=30 check-gateway=ping
Useful links
For more laboratories on the BGP protocol the following links can be
consulted:
802.1q
vlan
{«Oh, when the saints go marching in \\ Oh, when the saints go marching in
\\ Lord, how I want to be in that number»} Gospel tradizionale statunitense
This last method guarantees greater security, because one is sure of the
belonging of a specific host to a Virtual LAN; while in the first method, by
simply changing the physical interface, the host is assigned to another
VLAN. In this chapter we will analyze the VLANs realized with the
method that labels the ports of the connection device (port tagged VLAN).
VLANs can also be useful in order to restrict access to resources without
having to change the physical topology of the network. VLANs operate at
level 2 (the Data Link Layer) of the ISO / OSI Stack. The VLANs are
defined inside the switch, through a name and an ID (VID: VLAN
Identificator), this with range 0-4095. To manage multiple VLANs on the
same physical structure, the switch must be able to perform functions of:
At this point it is useful to pay attention to the used terms, in fact different
switch and router manufacturers use different terms to indicate the same
type of ports. The table table:terms on page table:terms shows the most
common matches. In the VLAN context, the term trunk or core denotes a
network connection transposing multiple VLANs, identified by labels
(called tag ) inserted in their packets. Trunks must be connected to ports
that analyze the tags, the tagged-port , of a VLAN-enabled device: often
these are switch-switch or switch-router connections.
A 802.1q packet
frame
In the 4 added bytes we have:
The first modified 2 bytes concern the tag protocol identifier (TPID)
.
This contains the EtherType tag which is changed to 0x8100, a number
that highlights the new frame format.
The next 2 bytes concern the tag control information (TCI) (also
called VLAN Tag) divided as follows:
user_priority : This 3-bit field can be used to indicate a priority
level for the frame.
The use of this field is defined by the IEEE 802.1p standard.
CFI : 1-bit field that indicates whether the MAC addresses in the
frame are in canonical form.
VID : 12-bit field indicating the ID of the VLANs, which can
thus be up to 4096 (ie 2^{12}).
Of the 4096 possible VLANs, VLANs 0, 1 and 4095 are reserved.
Ports types
The ports of a switch can be access, used to connect hosts, or trunks, used
for uplinks among switches or among switches and routers. The trunk is
therefore a link that allows the transport of frames belonging to different
VLANs. Here we have to highlight a very important concept: the frames
run in 802.1q format only on the trunk ports. When forwarded to hosts or
hosts on access ports, the VLAN tag is deleted and the frame format returns
to that of the Ethernet standard. Summarizing what has been explained so
far, in a switch we find two types of ports:
Generi
Cisco HP What it does
c term
Insert the VLAN tag (hence tag) to incoming
Acces Untagge
Edge traffic on the port and remove the VLAN tag to
s d
outbound traffic (directed to hosts).
These are the ports where traffic travels with the
Core Trunk Tagged
VLAN tag, which is then left unchanged.
Comparison of the VLAN terms used by the various producers
table:terms
VLAN on RouterOS
vlan-simple To understand how RouterOS manages VLANs, consider the
diagram in figure lab-vlan1 .
#
# Definition of vlan and core link (trunk)
#
/interface vlan
add interface=ether1 name=vlan10 vlan-id=10
add interface=ether1 name=vlan20 vlan-id=20
/ ip pool
add name=vlan10 ranges=10.10.10.100-10.10.10.200
add name=vlan20 ranges=10.20.20.100-10.20.20.200
/ip dhcp-server
add address-pool=vlan10 disabled=no interface=vlan10
name=vlan10
add address-pool=vlan20 disabled=no interface=vlan20
name=vlan20
/ip address
add address=10.10.10.1/24 interface=vlan10 network=10.10.10.0
add address=10.20.20.1/24 interface=vlan20 network=10.20.20.0
{R2}
/system identity set name=R2
#
# Definition of core port (trunk)
#
/interface vlan
add interface=ether1 name=vlan10 vlan-id=10
add interface=ether1 name=vlan20 vlan-id=20
#
# Definition of bridges for edge ports
#
/interface bridge
add fast-forward=no name=bridgevlan10
add fast-forward=no name=bridgevlan20
#
# Vlan extraction from bridges
#
/interface bridge port
add bridge=bridgevlan10 interface=vlan10
add bridge=bridgevlan20 interface=vlan20
add bridge=bridgevlan20 interface=ether3
add bridge=bridgevlan10 interface=ether2
trunk-lab
Three routers and at least one PC are required for this laboratory.
VLAN
The aim of this workshop is to learn how to propagate a trunk among
different switches.
{R2}
/system identity set name=R2
/interface bridge
add fast-forward=no name=bridgevlan10
add fast-forward=no name=bridgevlan20
add name=bridgevlan1030
/interface vlan
add interface=bridgevlan1030 name=vlan10 vlan-id=10
add interface=bridgevlan1030 name=vlan20 vlan-id=20
add interface=bridgevlan1030 name=vlan30 vlan-id=30
/interface bridge port
add bridge=bridgevlan10 interface=vlan10
add bridge=bridgevlan20 interface=vlan20
add bridge=bridgevlan10 interface=ether1
add bridge=bridgevlan20 interface=ether2
add bridge=bridgevlan1030 interface=ether4
add bridge=bridgevlan1030 interface=ether3
/interface bridge vlan
add bridge=bridgevlan1030 tagged=ether3,ether4 vlan-ids=10,30
{R3}
/system identity set name=R3
/interface bridge
add fast-forward=no name=bridgevlan10
add fast-forward=no name=bridgevlan30
/interface vlan
add interface=ether4 name=vlan10 vlan-id=10
add interface=ether4 name=vlan30 vlan-id=30
/interface bridge port
add bridge=bridgevlan10 interface=vlan10
add bridge=bridgevlan30 interface=vlan30
add bridge=bridgevlan10 interface=ether1
add bridge=bridgevlan30 interface=ether3
Lab
Two routers and at least one PC are required for this laboratory.
VLAN
The goal of this workshop is to start handling VLANs in RouterOS using
the WinBox interface.
VLAN - lab
lab-vlan2
The network infrastructure to be configured is that of figure lab-vlan2 . On
the router R1, in the network cards ether1, ether2 and ether3 three dhcp
servers are active which release the IP addresses related to each of the three
VLANs. The R2 router behaves like a switch with VLAN.
1. First of all, new interfaces are created by indicating the VLAN ID.
Each VLAN interface refers to a physical interface that determines the
trunk.
2. The process is repeated for each VLAN:
3. Subsequently, bridge type interfaces are created which will be useful
for configuring the access/untagged ports.
4. Among the ports of each switch there will always be the vlan
concerned and the ethernet NIC:
5. At this point, we need to configure the three dhcp servers with their
pools.
Remember that ip addresses and dhcp servers must be anchored to the
respective bridge interfaces.
6. The following are the final configurations of the two routers:
{R1}
/system identity set name=R1
/interface vlan
add interface=ether4 name=vlan10 vlan-id=10
add interface=ether4 name=vlan20 vlan-id=20
add interface=ether4 name=vlan30 vlan-id=30
/interface bridge
add fast-forward=no name=bridgevlan10
add fast-forward=no name=bridgevlan20
add fast-forward=no name=bridgevlan30
/interface bridge port
add bridge=bridgevlan10 interface=ether1
add bridge=bridgevlan10 interface=vlan10
add bridge=bridgevlan20 interface=ether2
add bridge=bridgevlan20 interface=vlan20
add bridge=bridgevlan30 interface=vlan30
add bridge=bridgevlan30 interface=ether3
/ip address
add address=10.10.10.1/24 interface=bridgevlan10
network=10.10.10.0
add address=10.20.20.1/24 interface=bridgevlan20
network=10.20.20.0
add address=10.30.30.1/24 interface=bridgevlan30
network=10.30.30.0
/ip pool
add name=vlan10 ranges=10.10.10.100-10.10.10.200
add name=vlan20 ranges=10.20.20.100-10.20.20.200
add name=vlan30 ranges=10.30.30.100-10.30.30.200
/ip dhcp-server
add address-pool=vlan10 disabled=no interface=bridgevlan10
name=vlan10
add address-pool=vlan20 disabled=no interface=bridgevlan20
name=vlan20
add address-pool=vlan30 disabled=no interface=bridgevlan30
name=vlan30
/ip dhcp-server network
add address=10.10.10.0/24 netmask=24
add address=10.20.20.0/24 netmask=24
add address=10.30.30.0/24 netmask=24
For further examples see the link http://bit.ly/2Fje2dp which also includes a
detailed explanation.
Comparison of configurations
In this chapter we have repeatedly mentioned brands like Cisco and HP, for
completeness in the next two pages we report in synopsis the R2
configurations of the laboratory of figure lab-vlan1 on page lab-vlan1 is the
R2 configurations of the laboratory of figure lab-vlan3 on page lab-vlan3
comparing what happens in Mikrotik RouterOS, in HP and in Cisco IOS.
Mikrotik RouterOS
/system identity set name=R2
/interface vlan
add interface=ether1 name=vlan10 \
vlan-id=10
add interface=ether1 name=vlan20 \
vlan-id=20
/interface bridge
add fast-forward=no \
name=bridgevlan10
add fast-forward=no \
name=bridgevlan20
HP
vlan 10
name "vlan10"
untagged 1
tagged 3
exit
vlan 20
name "vlan20"
untagged 2
tagged 3
exit
Cisco IOS
vlan database
vlan 10
vlan 20
exit
configure terminal
interface FastEthernet1/2
switchport mode access
switchport access vlan 10
!
interface FastEthernet1/3
switchport mode access
switchport access vlan 20
!
interface FastEthernet1/1
switchport mode trunk
switchport trunk allowed vlan all
!
Mikrotik RouterOS
/system identity set name=R2
/interface bridge
add fast-forward=no \
name=bridgevlan10
add fast-forward=no \
name=bridgevlan20
add name=bridgevlan1030
/interface vlan
add interface=bridgevlan1030 \
name=vlan10 vlan-id=10
add interface=bridgevlan1030 \
name=vlan20 vlan-id=20
add interface=bridgevlan1030 \
name=vlan30 vlan-id=30
/interface bridge port
add bridge=bridgevlan10 \
interface=vlan10
add bridge=bridgevlan20 \
interface=vlan20
add bridge=bridgevlan10 \
interface=ether1
add bridge=bridgevlan20 \
interface=ether2
add bridge=bridgevlan1030 \
interface=ether4
add bridge=bridgevlan1030 \
interface=ether3
/interface bridge vlan
add bridge=bridgevlan1030 \
tagged=ether3,ether4 \
vlan-ids=10,30
HP
vlan 10
name "vlan10"
untagged 1
tagged 3-4
exit
vlan 20
name "vlan20"
untagged 2
tagged 3
exit
vlan 30
name "vlan30"
tagged 3-4
exit
Cisco IOS
vlan database
vlan 10
vlan 20
vlan 30
exit
configure terminal
interface FastEthernet1/1
switchport mode access
switchport access vlan 10
!
interface FastEthernet1/2
switchport mode access
switchport access vlan 20
!
interface FastEthernet1/3
switchport mode trunk
switchport trunk allowed vlan all
!
interface FastEthernet1/4
switchport mode trunk
switchport trunk allowed vlan all
!
Many MikroTik devices have built-in switch chips that typically have the
ability to perform VLAN switching at the hardware level, which means that
wire-speed performance can be achieved using VLANs if an appropriate
configuration method is used. The configuration method changes between
different models. For configuration examples that follow the hardware
specifications, see the link http://bit.ly/2Fg8jVu .
Unnumbered IP
unnumbered
In the infrastructure of figure unnumbered there are two routers R1 and R2,
each of which is part of the networks 10.22.0.0/24 and 10.23.0.0/24
respectively. The following configurations using IP unnumbered are used to
connect these routers using VLANs as carriers: {R1}
/system identity set name=R1
/ip address add address=10.22.0.1/24 interface=ether1
/interface vlan add interface= ether2 vlan-id=10 name=vlan10
/ip address add address=10.22.0.1/32 interface=vlan10
network=10.23.0.1
/ip route add gateway=10.23.0.1 dst-address=10.23.0.0/24
{R2}
/system identity set name=R2
/ip address add address=10.23.0.1/24 interface=ether1
/interface vlan add interface=ether2 vlan-id=10 name=vlan10
/ip address add address=10.23.0.1/32 interface=vlan10
network=10.22.0.1
/ip route add gateway=10.22.0.1 dst-address=10.22.0.0/24
Summary questions
domande-4
Solutions
1. Overlay: the public network offered by the ISP offers only transport
functions and the routing information is exchanged only among
company sites.
In this case the topology (logical and physical) is composed of point-
to-point links defined by the customer (customer). If we consider these
point-to-point links we can identify a "superimposed" network (lett.
Overlay) to the physical network.
2. Peer-to-peer: the public network offered by the ISP also exchanges
routing information with the company sites.
In this case the logical topology is defined by the customer, the
physical topology that realizes the logical topology, is decided by the
provider according to specific traffic engineering criteria in its
network.
Tunnel
The term tunneling refers to a techniques set for which a protocol is
encapsulated in a protocol of the same level or higher level to realize
particular configurations. The security of the communication is obtained
through the encryption of the data that are inserted inside the tunnel and the
authentication of the end-points. The data packets are modified upon
sending by adding a header that will allow you to go through the tunnel;
subsequently, when they reach the destination, at the end of the tunnel, the
header will be removed returning the original package. Often the terms
"tunnel" and "VPN" are used interchangeably, but it is not a correct
approach. Protocols defining tunnels:
IPIP – IP Tunnel
EoIP – Ethernet Over IP
VLAN – Virtual Lan
MPLS – Multi Protocol Label Switching
Gre Tunnel
After the PPTP tunnel is created, a new IP address will be displayed on both
sides of the router with subnet /32. Comparing the server side and the client
side of the VPN we note the different position of the IP address:
Point-to-point addressing.
Static route to be set on R1 towards router R2. This route has the point-to-
point address as gateway:
For the R2 router we use the description on page loopback about the
loopback interface. In this case the IP address is installed on the fictitious
bridge interface, ie the bridge was created without any bridge port assigned.
At this point proceed in the configuration as usual, the only changes
concern the NAT settings and the default gateway that must take into
account the exit address from the router:
NAT configuration of the R2 router
NAT settings are made so that the client can access the internet. According
to the above, internet access is made through the public IP, not through the
point-to-point IP, so the address must be forced, ie it must be 222.152.211.1,
when the client packet leaves the router:
IP-in-IP
ipip The IP-in-IP tunneling implementation, also briefly referred to as IPIP,
on MikroTik RouterOS complies with RFC 2003; many routers, including
Cisco and Linux, support this protocol. The IPIP tunnel is a simple protocol
that encapsulates IP packets in a tunnel between two routers. The IPIP
tunnel interface appears as an interface below the list of interfaces but it is
not possible to insert the IPIP interface as a port in a bridge. The protocol
adds the following possibilities to a network infrastructure:
IP-in-IP encapsulation.
IP_in_IP_Encapsulation
To encapsulate an IP packet in another IP packet (see figure
IP_in_IP_Encapsulation ), an external header is added with the SourceIP,
the entry point of the tunnel and the destination, the exit point of the tunnel.
While doing this, the internal packet is not modified (except the TTL field,
which is decremented). The Do not Fragment and Type Of Service fields
are copied to the external package. If the packet size is larger than the path
MTU then the packet is fragmented during encapsulation because the
external header must be included. Upon arrival at destination the package
will be reassembled.
GRE vs IPIP
The encapsulation of generic routing (GRE) and IP-in-IP (IPIP) are two
rather similar tunneling mechanisms that are often confused. IP-in-IP
encapsulation is exactly what it seems: one IP packet encapsulated within
another (see figure ipip_encapsulation ). The external header protocol field
is set to 4 for IPv4 or 41 for IPv6.
IPIP encapsulation.
ipip_encapsulation
The GRE (defined in RFC 2784 and updated by RFC 2890) goes one step
further than IP-in-IP, adding an additional header inside and outside the IP
headers (see figure gre_encapsulation ).
GRE encapsulation.
gre_encapsulation
This addition allows the GRE protocol to:
Lab
Three routers and two PCs are required for this laboratory.
IPIP tunnel
The objective of this laboratory is to realize the infrastructure of figure
ipip2 starting from that of figure ipip .
IPIP tunnel.
ipip
1. Connect the routers as shown in fig ipip .
2. We configure the R1, R2 and R3 routers for basic connectivity:
{R1}
/system identity set name=R1
/ip address
add address=10.10.10.30/24 interface=ether1
{R2}
/system identity set name=R2
/interface bridge add name=bridge1
/interface bridge port add
interface=ether1 bridge=bridge1
/interface bridge port add
interface=ether2 bridge=bridge1
/ip address
add address=10.10.10.30/24 interface=bridge1
{R3}
/system identity set name=R3
/ip address
add address=10.10.10.31/24 interface=ether1
{R3}
/interface ipip add name=ipip local-address=10.10.10.31 \
remote-address=10.10.10.30
/ip address add address=192.168.200.2/30 interface=ipip
{R3}
/ip address
add address=192.168.2.1/24 interface=ether2
/ip pool
add name=dhcp_pool0 ranges=192.168.2.2-192.168.2.254
/ip dhcp-server
add address-pool=dhcp_pool0 disabled=no interface=ether2
name=dhcp1
/ip dhcp-server network
add address=192.168.2.0/24 gateway=192.168.2.1
8. We check that the PC-1 has obtained a valid ip address and is able to
communicate with R1:
PC-1> ping 192.168.1.1
84 bytes from 192.168.1.1 icmp_seq=1 ttl=64 time=2.637 ms
84 bytes from 192.168.1.1 icmp_seq=2 ttl=64 time=0.503 ms
84 bytes from 192.168.1.1 icmp_seq=3 ttl=64 time=0.418 ms
84 bytes from 192.168.1.1 icmp_seq=4 ttl=64 time=0.360 ms
84 bytes from 192.168.1.1 icmp_seq=5 ttl=64 time=0.401 ms
9. We check that the PC-2 has obtained a valid ip address and is able to
communicate with R3:
PC-2> ping 192.168.2.1
84 bytes from 192.168.2.1 icmp_seq=1 ttl=64 time=2.416 ms
84 bytes from 192.168.2.1 icmp_seq=2 ttl=64 time=0.417 ms
84 bytes from 192.168.2.1 icmp_seq=3 ttl=64 time=2.128 ms
84 bytes from 192.168.2.1 icmp_seq=4 ttl=64 time=0.401 ms
84 bytes from 192.168.2.1 icmp_seq=5 ttl=64 time=0.354 ms
{R3}
/ip route add dst-address=192.168.1.0/24
gateway=192.168.200.1
EoIP
eoip
Lab
Three routers and two PCs are required for this laboratory.
Tunnel EoIP
The objective of this laboratory is to realize the infrastructure of figure
eoip-lab with a dhcp server between the two external routers.
Tunnel EoIP.
eoip-lab
{R2}
/system identity set name=R2
/interface bridge add name=bridge1
/interface bridge port add
interface=ether1 bridge=bridge1
/interface bridge port add
interface=ether2 bridge=bridge1
/ip address
add address=10.10.10.30/24 interface=bridge1
{R3}
/system identity set name=R3
/ip address
add address=10.10.10.31/24 interface=ether1
{R3}
/interface eoip add name=eoip local-address=10.10.10.31 \
remote-address=10.10.10.30 tunnel-id=0
{R3}
/interface bridge add name=bridge1
/interface bridge port add interface=ether2 bridge=bridge1
/interface bridge port add interface=eoip bridge=bridge1
/ip address
add address=192.168.200.2/24 interface=bridge1
7. We check that the PC-1 and PC-2 have obtained a valid ip address and
are able to communicate with each other:
PC-1> show ip
NAME : PC-1
IP/MASK : 192.168.200.198/24
PC-2> show ip
NAME : PC-2
IP/MASK : 192.168.200.197/24
IPsec
ipsec
The issues that affect IPv4 and that IPsec tries to overcome are:
IPsec does not define the specific security algorithm (encryption, ...) to be
used but provides a way to indicate which algorithm is chosen, allowing
the use of the algorithms most suited to the needs of the moment. For
example, integrity is normally controlled using the MD5 or SHA
algorithm, while encryption is often done using DES.
We must distinguish two modes of operation of IPsec:
1. the case in which IPsec is used between two hosts that are the traffic
extreme points, called transport mode. In this case L4 datagrams are
encapsulated.
2. all other cases (router-router, computer-router etc.) where at least one
of the two extremes is not the final destination of the traffic (Gateway),
called tunnel mode; in this case the
gateway sends and receives traffic to and from the final recipient using
the usual IP protocol. In this case the entire L3 packet is encapsulated.
The most significant logical difference between the two modes is that in the
second case in the packet carried by IPsec there must be both an indication
of the gateway and of the final non-IPsec recipient, while in the first case
the latter is not necessary. All communications between the two hosts
connected by an IPsec tunnel and identified by their IPv4 address must pass
via IPsec: therefore if a host receives a non-IPsec IPv4 packet with an IP
address of an IPsec partner, it must discard it. It should be noted that each
tunnel is unidirectional, so to communicate the two hosts must establish two
tunnels, one for each direction. The IPsec initialization procedure is called
IKE (Internet Key Exchange), we will discuss some details of which later.
Once the procedure has been successfully completed, two Security
Association (SA) are created, which are the collection of all the parameters
that characterize the two IPsec tunnels that connect the two hosts; in
practice, the SA uniquely identifies the tunnels. At this point, finally, host
A, using the appropriate SA, transforms the original package into an IPsec
package and sends it to B. B, also having the two SAs, can transform the
IPsec package in the original package. Then, similarly, B can respond to A.
After the initial phase of tunnel creation (IKE), IPsec finally begins to
exchange data between the two hosts. For this operation two protocols are
available: Authentication Header (AH) and Encapsulating Security Payload
(ESP). It should be noted that AH does not offer confidentiality, ie the data,
the payload, are not encrypted, while ESP allows the data to be encrypted.
On the other hand, AH also guarantees the integrity of the packet IP Header
(with the exception of some parts that can be changed as discussed below),
while ESP guarantees the integrity only of the payload of the IP packet.
Putting together the two transmission modes (Tunnel and Transport) with
the two IPsec Protocols (AH and ESP), we obtain the four main types of
data packets created and transported by IPsec. Since the initialization phase
is slow and complicated, we therefore have that an IPsec tunnel is created
and remains active for a certain period of time, whether there is traffic or
not. When the time expires, if there is no traffic the tunnel is closed or the
SAs are regenerated. We have said that each SA can be associated with
different security features and that it takes two SAs to have complete
protection of a two-way channel, to manage this you use two local IPsec
databases that store the necessary information:
SAD (SA Database): lists the active SAs and specifies their
characteristics for each SA:
Sequence number counter (32 bit)
AH information (algorithms, keys, validity time,...)
ESP information (algorithms, keys, validity time,,...)
Lifetime of SA: time or numbers of bytes after which the SA
must be replaced or terminated
IPsec mode: transport or tunnel
SPD (Security Policy Database): contains the security policies to be
applied to the different types of communication, ie it specifies which
services must be offered to the different types of IP traffic, such as:
All traffic to 192.168.2.1 must be protected by ESP in transport
mode using DES
All FTP traffic (TCP, port 20) to 192.168.2.2 must be protected
by ESP in tunnel mode using 3DES
All traffic to 192.168.2.3 must not be protected.
Therefore SPD consists of policy entries with, for example, one or
more selectors that specify the IP traffic managed by this entry, from
the indication whether the matching traffic must be discarded, bypass
IPsec or be subjected to IPsec processing.
IPsec on RouterOS
Configure phase 1: it is the phase that generates the SAs that will be
used later to encrypt all the traffic:
using the IP > IPsec > Peers entry it is necessary to add a new
peer indicating the address of the other IPsec point, the shared
password to start the generation of the certificates and if the
packets must be encapsulated inside a UDP packet to traverse the
NATs;
indicate the encryption and authentication algorithms that will be
used;
indicate the DPD values (Dead Peer Detection) to automatically
detect any timeouts.
Configure phase 2: this phase tells the router what to encrypt and
which one to use:
using the IP > IPsec > Policies entry you define the traffic to be
encrypted, for example by indicating the source address or the
recipient, ...
using the IP > IPsec > Policies Proposals entry, you indicate to
the router which algorithm to use for encryption and the hash
function to be used for phase 2.
/ip ipsec peer - defines the settings for phase 1 for IPsec peers;
/ip ipsec policy - defines which traffic to process and how to
process it;
/ip ipsec proposal - defines the encryption and algorithms to use.
Hint. To enable the specific log for IPsec use the command: \\ /system
logging add topics=ipsec
Now we are ready to set up a simple site-to-site IPsec VPN. For the two
configurations that follow refer to the infrastructure in figure ipsec-site-to-
site .
Tunnel mode
/system identity set name=R1
# Define peer (Phase 1)
/ip ipsec peer
add address=2.2.2.2/32
dh-group=modp2048
dpd-interval=10s
dpd-maximum-failures=3
encalgorithm=aes-256
hash-algorithm=sha512
secret=superSecret
# Define policy (Phase 2)
/ip ipsec policy
add dst-address=10.2.2.0/24
sa-dst-address=2.2.2.2
sa-src-address=1.1.1.1
src-address=10.1.1.0/24
tunnel=yes
# IPsec tunnel traffic
# don't be into NAT
/ip firewall nat
add action=accept chain=srcnat
dst-address=10.2.2.0/24
Transport mode
/system identity set name=R1
# Configurazione IPsec
/ip ipsec peer
add address=2.2.2.2/32
dh-group=modp2048
dpdinterval=10s
dpd-maximum-failures=3
enc-algorithm=aes256
hash-algorithm=sha512
secret=superSecret
/ip ipsec policy
add dst-address=2.2.2.2/32
protocol=gre
src-address=1.1.1.1/32
# Tunnel GRE per il traffico
/interface gre
add clamp-tcp-mss=no
dont-fragment=inherit
keepalive=10s,3 mtu=1400
name=gre-tunnel1
remote-address=2.2.2.2
# routing
/ip address
add address=10.255.0.1/24
interface=gre-tunnel1
/ip route
add distance=1
dst-address=10.2.2.0/24
gateway=10.255.0.2
IPsec/XAuth
At MUM 2018 in Berlin, Tomas Kirnak gave an interesting talk on the
IPsec / XAuth protocol often called "Cisco IPsec". The talk slides are
available at the link http://bit.ly/2RlSeEg while a detailed description of the
protocol is available at the link http://bit.ly/2RmuWOD . VPNs are often
used by network administrators to remotely manage customer networks,
other times there are requests from some user who has to work from remote
locations or from companies that need access to manage some equipment.
In summary we can say that often the required configuration is client-to-site
with the client located behind a NAT network. There are many options that
can be used to offer the customer these opportunities:
# Define peer
/ip ipsec peer profile
add dpd-interval=10s dpd-maximum-failures=3
enc-algorithm=aes-256,3des
hash-algorithm=sha512 name=vpn-admins
# Adding user
/ip ipsec user
add name=username password=password
Now all that remains to do is to configure the client. In this case we show
the client configuration for OSX, for other clients like Microsoft Windows
or Android see the document http://bit.ly/2C9S2xn . To configure the Apple
OSX VPN client:
MPLS
How the protocol works
mpls The idea behind the MPLS protocol (Multi Protocol Label Switching )
is to forward packets based on a label instead of the destination IP address.
This approach produces faster searches in the forwarding table since the
label can be used as an index instead of the longest prefix matching and also
allows a more refined control of the traffic. The idea behind the MPLS
protocol (Multi Protocol Label Switching) is to forward packets based on a
label (label) instead of the destination IP address. This approach produces
faster searches in the forwarding table since the label can be used as an
index instead of the longest prefix matching and also allows a more refined
control of the traffic. The MPLS protocol was created in response to the
problems that the network was encountering in its development in the early
1990s. Among these we have the complexity of routing, the use of different
technologies that are difficult to integrate like IP and ATM and scalability
problems. MPLS solves these problems in a simple and effective way: it
places itself between the data of the second level protocol and those of the
third level protocol, adding its own header, which contains a label in which
all the necessary information for routing are defined of the package. In this
way the data of the third level protocol are transparent to the routers of the
network; thanks to MPLS I can therefore use the same router to pass
different protocol packets, even if it is typically used with IP type packets.
MPLS completely separates the control component (communication
between nodes and update routing tables) and the component that realizes
the actual routing of the packets based on the routing tables, called
forwarding component. The heart of an MPLS network is formed by a set
of routers capable of routing packets solely through the content of the
MPLS labels. These routers are called LSRs (Label Switch Routers), which
form together an area called the MPLS backbone as exemplified in figure
mpls-dominio .
Multi Protocol Label Switching (MPLS) domain.
mpls-dominio
However, the packets start from the users' routers without MPLS header,
but only with the protocol data of the third level. We will have special
routers located at the border of the MPLS backbone that add the MPLS
label based on the data of the third level and route the packet to the
backbone. On the other hand, normal LSRs usually do not use the third
level protocol header. The path followed by a packet through multiple LSRs
is called LSP (Label Switched Path ).
MPLS packet.
mpls-label
Now a bit of routing theory: in a connectionless network, like the IP
network, the path followed by a packet between the source and the
destination is determined by the composition of elementary and
independent routing operations performed by the routers that are traversed
from the package. Each router chooses the next router to which re-launch
the packet. This choice is performed by examining the header of the packet
and accessing a updated routing table by using a routing protocol. This is
the Router Information Base (RIB) table introduced on page rib . The
choice of the next-hop operated by a router can be modeled as the
concatenation of two distinct functions:
According to this model, the packets belonging to the same FEC will be
relayed by a router to the same nexthop. In particular, in an IP network, a
router will classify two packets, which carry two different destination
addresses A and B, as belonging to the same FEC if in the routing table of
the router there is an X prefix for which this prefix represents the greatest
correspondence length (longest match ) for both addresses A and B. In this
view, each router executes, independently of the others, its packet
classification in FEC and therefore two packets that are classified as
belonging to the same FEC in a router can belong to different FECs in
another router. The MPLS protocol acts differently: as defined in RFC 3031
the MPLS protocol assigns a FEC to a package once and for all, at the time
when the package enters an MPLS network. The FEC assigned to the
package is encoded in a label , of short and fixed length, transported in the
header of the package 6 itself. When the router through which the packet
has entered an MPLS network raises the packet, the packet itself assigns to
the packet the value of the label that will be used by the next router to carry
out the switching. When a packet enters a router, the label is used as an
index for direct access to a table that will contain the value of the next-hop
and the value of the new label. The old label is replaced with the new one
and the package is sent back to the next router. It should be emphasized that
once a packet has been assigned a label, the packet is switched by
examining the label exclusively without taking into account the value of the
other fields of the IP header.
In the previous section the concept of FEC has been defined as a set of IP
packets that must be treated by a router in the same way, for example that
must be re-launched towards the same next-hop and belonging to the same
class of service. In MPLS every FEC is assigned a label that will be used by
the routers to perform the packet switching function. A router that supports
the MPLS technique is called the Label Switching Router (LSR) and the
type of switching is generally referred to as label switching. An MPLS
network domain is thus formed by a set of LSRs connected directly to each
other. The incoming traffic to an MPLS domain can come either from
networks external to the domain, such as for example local user networks,
or from traditional IP routers belonging to IP network sections that do not
support MPLS technology as illustrated in figure mpls-dominio . An LSR
that connects an MPLS domain with other nodes that are outside the
domain is called Edge LSR, while an LSR that is connected only to other
LSRs is called Core LSR. A label is therefore a fixed-length identifier that
is used to identify a FEC. A label has local validity, this means that the
association between FEC and a specific value of a label is valid only on one
section of the network, the same FEC can therefore be identified by
different labels on different sections of the network.
LSP tunnel
For the purposes of this text our introduction to the MPLS protocol stops
here. For those wishing to learn more, we recommend the excellent
dispensation produced by Marco Listanti of the INFOCOM Department of
the "La Sapienza" University of Rome available at the link
http://bit.ly/2F0SrFl . An interesting talk was presented at the MUM 2009
in Prague entitled "MikroTik RouterOS Introduction to MPLS" which
included the MPLS protocol with Mikrotik products. The slides are
available at the link http://bit.ly/2GRW1Eq .
Those familiar with the services that Service Providers offer on their IP +
MPLS networks will know that one of the most interesting of these is the
VPLS (Virtual Private LAN Service) service, which is a Multipoint-to-
Multipoint service that allows emulation of LAN Ethernet on an IP + MPLS
network. From a logical point of view, the VPLS service can be seen as a
service that allows emulating Ethernet switches. For example, connecting N
geographically dispersed routers with a VPLS service is equivalent to
connecting the routers locally to an Ethernet switch with straight-through
cables. The CE (Customer Edge), that is the customer's devices that
interface with the CE Service Provider network,, can be any device that
generates tagged and/or untagged Ethernet frames (Ethernet or Host routers
or switches), and the connection among the CE and the ISP network routers
(PE router) can be in any technology (ex. Ethernet back-to-back, Ethernet
over SONET / SDH using GFP encapsulation, Ethernet over ATM using
AAL5 (RFC 2684), etc. ). The service model is very similar to the classic
L3VPN service on IP + MPLS networks, with the substantial difference that
between L3VPN sites IP packets are transported and the ISP network
participates in inter-site routing, while between VPLS sites Ethernet frames
are exchanged (tagged or untagged). This theoretically allows the exchange
of Level 3 packages that are not IP, although this is actually no longer
considered an important advantage of VPLS, since all applications are
based on the TCP/IP architecture. From a physical point of view, the
operating model is similar to that of the L3VPN, with some substantial
differences. For each client, the virtual L2 instances called VSI (Virtual
Switch Interface) are created on the PEs where the sites are certified. Each
VSI can be seen as a set of two elements: a MAC table (usually referred to
as VFI, Virtual Forwarding Instance), and a set of physical or logical
Ethernet interfaces that form a broadcast domain (usually referred to as a
Bridge Domain). The CE access interfaces on the PE (attachment circuit)
are associated with the appropriate VSI via configuration. The VSIs must
emulate all the ethernet switch functions:
Flooding: send to all other VSIs of the same VPLS the frames with
destination MAC addresses Broadcast, or Multicast or Unicast but
unknown (the so-called BUM traffic, Broadcast-Unknown-Unicast-
Multicast).
MAC address learning: automatically create associations (MAC, Port).
MAC address limiting: set a limit to the number of associations (MAC,
Port)
present in a VFI.
MAC Address aging: assign a life time to each entry in the VFI.
Loop prevention: avoid the Broadcast Storm phenomenon.
Recall that in switched ethernet networks, this function is performed
by the Spanning Tree protocol.
Forwarding: use of the entries created to forward LAN / VLAN traffic.
For each VPLS, a complete pseudowire mesh is created between the PEs
where the VPLS sites are attested; a pseudowire emulates a point-to-point
connection within which it is possible to carry any Level 2 frames, in this
case Ethernet frames. The reason why you need a complete pseudowire
mesh is related to the transport of BUM traffic, ie to Broadcast, Unknown-
Unicast and Multicast traffic.
Architecture for performance testing.
vpn-test
But MPLS and VPLS are also interesting for small architectures as they are
very efficient. If we consider the architecture of figure vpn-test using
RB1000 RouterBoard as hardware then the table table:tunnel-performance
that collects the performance tests highlights the winning protocols.
64 byte pps 512 byte pps
Bridge 414.000 359.000
MPLS 410.000 358.000
VPLS 332.500 301.000
Routin
236.000 229.700
g
EoIP 190.000 183.900
Performance test.
table:tunnel-performance
Remember that in order for the MPLS menu to be present, the MPLS
package must be installed and active as shown in fig mpls-package .
MPLS package.
mpls-package
Lab
For this laboratory, two routers with a wireless interface and two PCs are
required.
VPLS tunnel
The objective of this laboratory is to realize the infrastructure of figure
mpls-tunnel using MPLS. This approach has the following advantages:
the VPLS tunnel is about 60 faster and with less overload than an
EoIP tunnel, \item in WDS bridges with 802.11n protocol the speed is
limited by the protocol but not in the MPLS case.
VPLS tunnel using a radio bridge.
mpls-tunnel
For educational convenience this laboratory is available in two versions:
through the graphical interface of WinBox or through the terminal
commands.
{Using WinBox}
4. After a few seconds check the status of the LDP connectivity in MPLS
> MPLS > LDP Neighbor :
D=Dynamic, O=Operational
5. Add a new VPLS interface using the MPLS > VPLS > VPLS menu.
The address to indicate in the remote peer field is the ip address of the
other end of the radio link:
6. After a few seconds, check how the status of the LDP connectivity was
changed in MPLS > MPLS > LDP Neighbor menu:
# Configuration of IP address
/ip address
add address=172.16.0.1/30 interface=wlan1
# Enable LDP
/mpls ldp
set enabled=yes lsr-id=172.16.0.1 transport-
address=172.16.0.1
/mpls ldp interface
add interface=wlan1
{station}
/system identity set name=station
# Configuration of IP address
/ip address
add address=172.16.0.2/30 interface=wlan1
# Enable LDP
/mpls ldp
set enabled=yes lsr-id=172.16.0.2 transport-
address=172.16.0.2
/mpls ldp interface
add interface=wlan1
If you want to go deeper into the topic always the excellent Tomas Kirnak
at MUM 2013 gave a talk entitled "MPLS for ISPs - PPPoE over VPLS
MPLS, VPLS, PPPoE" whose slides are available at link
http://bit.ly/2VrgCCB .
Useful schemes and tables
«...with the same shoes walking on different roads or with different shoes on
a single road.» Fiorella Mannoi a
OSPF
MPLS