DOC-ONLY: MFIB documentation
[vpp.git] / docs / gettingstarted / developers / fib20 / mplsfib.rst
1 .. _mplsfib:
2
3 MPLS FIB
4 --------
5
6 Implementation
7 ^^^^^^^^^^^^^^^
8
9 The MPLS FIB is implemented using exactly the same data structures as
10 the IP FIB.  The only difference is the implementation of the
11 table. Whereas for IPv4 this is an mtrie and for IPv6 a hash table,
12 for MPLS it is a flat array indexed by a 21 bit key (label & EOS
13 bit). This implementation is chosen to favour packet forwarding speed.
14
15 Basics
16 ^^^^^^
17
18 MPLS is not enabled by default. There are two steps to get
19 started. First, create the default MPLS FIB:
20
21 .. code-block:: console
22
23    $ mpls table add 0
24
25 With '0' being the magic number for the 'default' table (just like it
26 is for IPv[46]). One can create other MPLS tables, but, unlike IP
27 tables, one cannot 'bind' non-default MPLS tables to interfaces, in
28 other words all MPLS packets received on an interface will always
29 result in a lookup in the default table. One has to be more inventive
30 to use the non-default tables...
31
32 Secondly, for *each* interface on which you wish to *receive* MPLS
33 packets, that interface must be MPLS 'enabled'
34
35 .. code-block:: console
36
37    $ set interface mpls GigEthernet0/0/0 enable
38
39 there is no equivalent enable for transmit, all that is required is to
40 use an interface as an egress path.
41
42 Entries in the MPLS FIB can be displayed with:
43
44 .. code-block:: console
45
46    $ sh mpls fib [table X] [label]
47
48 There is a tight coupling between IP and MPLS forwarding. MPLS
49 forwarding equivalence classes (FECs) are often an IP prefix – that is
50 to say that traffic matching a given IP prefix is routed into a MPLS
51 label switch path (LSP). It is thus necessary to be able to associated
52 a given prefix/route with an [out-going] MPLS label that will be
53 imposed when the packet is forwarded. This is configured as:
54
55 .. code-block:: console
56
57    $ ip route add 1.1.1.1/32 via 10.10.10.10 GigEthernet0/0/0 out-labels 33
58
59 packets matching 1.1.1.1/32 will be forwarded out GigEthernet0/0/0 and have
60 MPLS label 33 imposed. More than one out-going label can be
61 specified. Out-going MPLS labels can be applied to recursive and
62 non-recursive routes, e.g;
63
64 .. code-block:: console
65
66    $ ip route add 2.2.2.0/24 via 1.1.1.1 out-labels 34
67
68 packets matching 2.2.2.0/24 will thus have two MPLS labels imposed; 34
69 and 33. This is the realisation of, e,g, an MPLS BGP VPNv4.
70
71 To associate/allocate a local-label for a prefix, and thus have
72 packets to that local-label forwarded equivalently to the prefix do;
73
74 .. code-block:: console
75
76    $ mpls local-label 99 2.2.2.0/24
77
78 In the API this action is called a ‘bind’.
79 The router receiving the MPLS encapsulated packets needs to be
80 programmed with actions associated which each label value – this is
81 the role of the MPLS FIB. The MPLS FIB Is a table, whose key is the
82 MPLS label value and end-of-stack (EOS) bit, which stores the action
83 to perform on packets with matching encapsulation. Currently supported
84 actions are:
85
86 #. Pop the label and perform an IPv[46] lookup in a specified table
87 #. Pop the label and forward via a specified next-hop (this is penultimate-hop-pop, PHP)
88 #. Swap the label and forward via a specified next-hop.
89
90 These can be programmed respectively by:        
91
92 .. code-block:: console
93
94    $ mpls local-label 33 eos ip4-lookup-in-table X
95    $ mpls local-label 33 [eos] via 10.10.10.10 GigEthernet0/0/0
96    $ mpls local-label 33 [eos] via 10.10.10.10 GigEthernet0/0/0 out-labels 66
97
98 the latter is an example of an MPLS cross connect. Any description of
99 a next-hop, recursive, non-recursive, labelled, non-labelled, etc,
100 that is valid for an IP prefix, is also valid for an MPLS
101 local-label. Note the use of the 'eos' keyword which indicates the
102 programming is for the case when the label is end-of-stack. The last
103 two operations can apply to both eos and non-eos packets, but the pop
104 and IP lookup only to an eos packet.
105
106
107 MPLS VPN
108 ^^^^^^^^
109
110 To configure an MPLS VPN for a PE the follow example can be used.
111
112 Step 1; Configure routes to the iBGP peers - note these route MUST
113 have out-going labels;
114
115 .. code-block:: console
116
117    $ ip route add 10.0.0.1/32 via 192.168.1.2 Eth0 out-labels 33
118    $ ip route add 10.0.0.2/32 via 192.168.2.2 Eth0 out-labels 34
119
120 Step 2; Configure the customer 'VRF'
121
122 .. code-block:: console
123
124    $ ip table add 2
125
126 Step 3; add a route via the iBGP peer[s] with the MPLS label
127 advertised by that peer
128
129 .. code-block:: console
130
131    $ ip route add table 2 10.10.10.0/24 via 10.0.0.2 next-hop-table 0 out-label 122
132    $ ip route add table 2 10.10.10.0/24 via 10.0.0.1 next-hop-table 0 out-label 121
133
134 Step 4; add a route via the eBGP peer
135
136 .. code-block:: console
137
138    $ ip route add table 2 10.10.20.0/24 via 172.16.0.1 next-hop-table 2
139
140 Step 5; depending on the label allocation scheme used, add routes to
141 the MPLS FIB to accept incoming labelled packets:
142
143 #. per-prefix label scheme - this command 'binds' the label to the same
144    forwarding as the IP route
145
146    .. code-block:: console
147
148       $ mpls local-label 99 10.10.20.0/24
149
150 #. per-CE label scheme - this pops the incoming label and forwards via
151    the next-hop provided. Append config for 'out-labels' if so desired.
152
153    .. code-block:: console
154
155       $ mpls local-label 99 via 172.16.0.1 next-hop-table 2
156
157 #. per-VRF label scheme
158
159    .. code-block:: console
160
161       $ mpls local-label 99 via ip4-lookup-in-table 2
162
163 MPLS Tunnels
164 ^^^^^^^^^^^^
165
166 MPLS tunnels are unidirectional and can impose a stack of labels. They
167 are 'normal' interfaces and thus can be used, for example, as the
168 target for IP routes and L2 cross-connects. To construct a tunnel:
169
170 .. code-block:: console
171
172    $ mpls tunnel add via 10.10.10.10 GigEthernet0/0/0 out-labels 33 44 55
173
174 and to then have that created tunnel to perform ECMP:
175
176 .. code-block:: console
177
178    $ mpls tunnel add mpls-tunnel0 via 10.10.10.11 GigEthernet0/0/0 out-labels 66 77 88
179
180 use
181
182 .. code-block:: console
183
184    $ sh mpls tunnel [X]
185
186 to see the monster you have created.
187
188 An MPLS tunnel interface is an interface like any other and now ready
189 for use with the usual set of interface commands, e.g.:
190
191 .. code-block:: console
192
193    $ set interface state mpls-tunnel0 up
194    $ set interface ip address mpls-tunnel0 192.168.1.1/30
195    $ ip route 1.1.1.1/32 via mpls-tunnel0