blob: f66724ea81be844a371bfa4760845533ac0eb68a [file] [log] [blame]
jdenisco0923a232018-08-29 13:19:43 -04001.. _mplsfib:
2
3MPLS FIB
Neale Ranns75c276f2018-08-31 00:45:19 -07004--------
jdenisco0923a232018-08-29 13:19:43 -04005
Neale Ranns75c276f2018-08-31 00:45:19 -07006Implementation
7^^^^^^^^^^^^^^^
8
9The MPLS FIB is implemented using exactly the same data structures as
10the IP FIB. The only difference is the implementation of the
11table. Whereas for IPv4 this is an mtrie and for IPv6 a hash table,
12for MPLS it is a flat array indexed by a 21 bit key (label & EOS
13bit). This implementation is chosen to favour packet forwarding speed.
14
Neale Rannsdfd39542020-11-09 10:09:42 +000015It can be the case in MPLS forwarding that packets received with the
16EOS bit set in the MPLS label need to be forwarded differently from
17those without. The most common example of this is if the path set
18contains a path that does not have an output label. In this case the
19non-EOS packets cannot take this path, because to do so would expose
20the neighbouring router to a label that it did not allocate.
21
22The desgin choice to make with an MPLS FIB table is therefore:
23- 20 bit key: label only. When the EOS and non-EOS actions differ the result is a 'EOS-choice' object.
24- 21 bit key: label and EOS-bit. The result is then the specific action based on EOS-bit.
25
2620 bit key
27 - Advantages:lower memory overhead, since there are few DB entries.
28 - Disadvantages: slower DP performance in the case the path-lists
29 differ, as more objects are encounterd in the switch path
30
3121 bit key
32 - Advantages: faster DP performance
33 Disadvantages: increased memory footprint.
34
35Switching between schemes based on observed/measured action similarity
36is not considered on the grounds of complexity and flip-flopping.
37
38VPP mantra - favour performance over memory. We choose a 21 bit key.
39
Neale Ranns75c276f2018-08-31 00:45:19 -070040Basics
41^^^^^^
42
43MPLS is not enabled by default. There are two steps to get
44started. First, create the default MPLS FIB:
jdenisco0923a232018-08-29 13:19:43 -040045
46.. code-block:: console
47
Neale Ranns75c276f2018-08-31 00:45:19 -070048 $ mpls table add 0
jdenisco0923a232018-08-29 13:19:43 -040049
Neale Ranns75c276f2018-08-31 00:45:19 -070050With '0' being the magic number for the 'default' table (just like it
51is for IPv[46]). One can create other MPLS tables, but, unlike IP
52tables, one cannot 'bind' non-default MPLS tables to interfaces, in
53other words all MPLS packets received on an interface will always
54result in a lookup in the default table. One has to be more inventive
55to use the non-default tables...
56
57Secondly, for *each* interface on which you wish to *receive* MPLS
58packets, that interface must be MPLS 'enabled'
jdenisco0923a232018-08-29 13:19:43 -040059
60.. code-block:: console
61
Neale Ranns75c276f2018-08-31 00:45:19 -070062 $ set interface mpls GigEthernet0/0/0 enable
jdenisco0923a232018-08-29 13:19:43 -040063
Neale Ranns75c276f2018-08-31 00:45:19 -070064there is no equivalent enable for transmit, all that is required is to
65use an interface as an egress path.
jdenisco0923a232018-08-29 13:19:43 -040066
Neale Ranns75c276f2018-08-31 00:45:19 -070067Entries in the MPLS FIB can be displayed with:
68
69.. code-block:: console
70
71 $ sh mpls fib [table X] [label]
72
73There is a tight coupling between IP and MPLS forwarding. MPLS
74forwarding equivalence classes (FECs) are often an IP prefix that is
75to say that traffic matching a given IP prefix is routed into a MPLS
Neale Rannsdfd39542020-11-09 10:09:42 +000076label switch path (LSP). It is thus necessary to be able to associate
Neale Ranns75c276f2018-08-31 00:45:19 -070077a given prefix/route with an [out-going] MPLS label that will be
78imposed when the packet is forwarded. This is configured as:
79
80.. code-block:: console
81
82 $ ip route add 1.1.1.1/32 via 10.10.10.10 GigEthernet0/0/0 out-labels 33
83
84packets matching 1.1.1.1/32 will be forwarded out GigEthernet0/0/0 and have
85MPLS label 33 imposed. More than one out-going label can be
86specified. Out-going MPLS labels can be applied to recursive and
87non-recursive routes, e.g;
88
89.. code-block:: console
90
91 $ ip route add 2.2.2.0/24 via 1.1.1.1 out-labels 34
92
93packets matching 2.2.2.0/24 will thus have two MPLS labels imposed; 34
94and 33. This is the realisation of, e,g, an MPLS BGP VPNv4.
95
96To associate/allocate a local-label for a prefix, and thus have
97packets to that local-label forwarded equivalently to the prefix do;
jdenisco0923a232018-08-29 13:19:43 -040098
99.. code-block:: console
100
101 $ mpls local-label 99 2.2.2.0/24
102
Neale Ranns75c276f2018-08-31 00:45:19 -0700103In the API this action is called a bind’.
104The router receiving the MPLS encapsulated packets needs to be
105programmed with actions associated which each label value this is
Neale Rannsdfd39542020-11-09 10:09:42 +0000106the role of the MPLS FIB. The MPLS FIB is a table, whose key is the
Neale Ranns75c276f2018-08-31 00:45:19 -0700107MPLS label value and end-of-stack (EOS) bit, which stores the action
108to perform on packets with matching encapsulation. Currently supported
109actions are:
jdenisco0923a232018-08-29 13:19:43 -0400110
111#. Pop the label and perform an IPv[46] lookup in a specified table
112#. Pop the label and forward via a specified next-hop (this is penultimate-hop-pop, PHP)
113#. Swap the label and forward via a specified next-hop.
114
115These can be programmed respectively by:
116
Neale Ranns995ff062018-12-06 08:36:55 -0800117.. code-block:: console
118
119 $ mpls local-label 33 eos ip4-lookup-in-table X
120 $ mpls local-label 33 [eos] via 10.10.10.10 GigEthernet0/0/0
121 $ mpls local-label 33 [eos] via 10.10.10.10 GigEthernet0/0/0 out-labels 66
jdenisco0923a232018-08-29 13:19:43 -0400122
Neale Ranns75c276f2018-08-31 00:45:19 -0700123the latter is an example of an MPLS cross connect. Any description of
124a next-hop, recursive, non-recursive, labelled, non-labelled, etc,
125that is valid for an IP prefix, is also valid for an MPLS
126local-label. Note the use of the 'eos' keyword which indicates the
127programming is for the case when the label is end-of-stack. The last
128two operations can apply to both eos and non-eos packets, but the pop
129and IP lookup only to an eos packet.
jdenisco0923a232018-08-29 13:19:43 -0400130
jdenisco0923a232018-08-29 13:19:43 -0400131
Neale Ranns75c276f2018-08-31 00:45:19 -0700132MPLS VPN
133^^^^^^^^
jdenisco0923a232018-08-29 13:19:43 -0400134
Neale Rannsdfd39542020-11-09 10:09:42 +0000135To configure an MPLS VPN for a PE the following example can be used.
jdenisco0923a232018-08-29 13:19:43 -0400136
Neale Ranns75c276f2018-08-31 00:45:19 -0700137Step 1; Configure routes to the iBGP peers - note these route MUST
138have out-going labels;
jdenisco0923a232018-08-29 13:19:43 -0400139
140.. code-block:: console
141
Neale Ranns75c276f2018-08-31 00:45:19 -0700142 $ ip route add 10.0.0.1/32 via 192.168.1.2 Eth0 out-labels 33
143 $ ip route add 10.0.0.2/32 via 192.168.2.2 Eth0 out-labels 34
jdenisco0923a232018-08-29 13:19:43 -0400144
Neale Ranns75c276f2018-08-31 00:45:19 -0700145Step 2; Configure the customer 'VRF'
jdenisco0923a232018-08-29 13:19:43 -0400146
Neale Ranns75c276f2018-08-31 00:45:19 -0700147.. code-block:: console
148
149 $ ip table add 2
150
151Step 3; add a route via the iBGP peer[s] with the MPLS label
152advertised by that peer
153
154.. code-block:: console
155
156 $ ip route add table 2 10.10.10.0/24 via 10.0.0.2 next-hop-table 0 out-label 122
157 $ ip route add table 2 10.10.10.0/24 via 10.0.0.1 next-hop-table 0 out-label 121
158
159Step 4; add a route via the eBGP peer
160
161.. code-block:: console
162
163 $ ip route add table 2 10.10.20.0/24 via 172.16.0.1 next-hop-table 2
164
165Step 5; depending on the label allocation scheme used, add routes to
166the MPLS FIB to accept incoming labelled packets:
167
168#. per-prefix label scheme - this command 'binds' the label to the same
169 forwarding as the IP route
170
171 .. code-block:: console
172
173 $ mpls local-label 99 10.10.20.0/24
174
175#. per-CE label scheme - this pops the incoming label and forwards via
176 the next-hop provided. Append config for 'out-labels' if so desired.
177
178 .. code-block:: console
179
180 $ mpls local-label 99 via 172.16.0.1 next-hop-table 2
181
182#. per-VRF label scheme
183
184 .. code-block:: console
185
186 $ mpls local-label 99 via ip4-lookup-in-table 2
187
188MPLS Tunnels
189^^^^^^^^^^^^
190
191MPLS tunnels are unidirectional and can impose a stack of labels. They
192are 'normal' interfaces and thus can be used, for example, as the
193target for IP routes and L2 cross-connects. To construct a tunnel:
194
195.. code-block:: console
196
197 $ mpls tunnel add via 10.10.10.10 GigEthernet0/0/0 out-labels 33 44 55
198
199and to then have that created tunnel to perform ECMP:
200
201.. code-block:: console
202
203 $ mpls tunnel add mpls-tunnel0 via 10.10.10.11 GigEthernet0/0/0 out-labels 66 77 88
204
205use
206
207.. code-block:: console
208
209 $ sh mpls tunnel [X]
210
211to see the monster you have created.
212
213An MPLS tunnel interface is an interface like any other and now ready
214for use with the usual set of interface commands, e.g.:
215
216.. code-block:: console
217
218 $ set interface state mpls-tunnel0 up
219 $ set interface ip address mpls-tunnel0 192.168.1.1/30
220 $ ip route 1.1.1.1/32 via mpls-tunnel0