Merge "BGPCEP-781: Add path-id to all AFI/SAFI guides"
[docs.git] / docs / user-guide / bgpcep-guide / bgp / bgp-user-guide-bgp-peering.rst
1 .. _bgp-user-guide-bgp-peering:
2
3 BGP Peering
4 ===========
5 To exchange routing information between two BGP systems (peers), it is required to configure a peering on both BGP speakers first.
6 This mean that each BGP speaker has a white list of neighbors, representing remote peers, with which the peering is allowed.
7 The TCP connection is established between two peers and they exchange messages to open and confirm the connection parameters followed by routes exchange.
8
9 Here is a sample basic neighbor configuration:
10
11 **URL:** ``/restconf/config/openconfig-network-instance:network-instances/network-instance/global-bgp/openconfig-network-instance:protocols/protocol/openconfig-policy-types:BGP/bgp-example/bgp/neighbors``
12
13 **Method:** ``POST``
14
15 **Content-Type:** ``application/xml``
16
17 **Request Body:**
18
19 .. code-block:: xml
20    :linenos:
21    :emphasize-lines: 2,5,6,11,12,17,19
22
23    <neighbor xmlns="urn:opendaylight:params:xml:ns:yang:bgp:openconfig-extensions">
24        <neighbor-address>192.0.2.1</neighbor-address>
25        <timers>
26            <config>
27                <hold-time>90</hold-time>
28                <connect-retry>10</connect-retry>
29            </config>
30        </timers>
31        <transport>
32            <config>
33                <remote-port>179</remote-port>
34                <passive-mode>false</passive-mode>
35                <!--<local-address>192.0.2.5</local-address>-->
36            </config>
37        </transport>
38        <config>
39            <peer-type>INTERNAL</peer-type>
40        </config>
41        <afi-safis>
42            ...
43        </afi-safis>
44    </neighbor>
45
46 @line 2: IP address of the remote BGP peer. Also serves as an unique identifier of a neighbor in a list of neighbors.
47
48 @line 5: Proposed number of seconds for value of the Hold Timer. Default value is **90**.
49
50 @line 6: Time interval in seconds between attempts to establish session with the peer. Effective in active mode only. Default value is **30**.
51
52 @line 11: Remote port number to which the local BGP is connecting. Effective in active mode only. Default value **179**.
53
54 @line 12: Wait for peers to issue requests to open a BGP session, rather than initiating sessions from the local router. Default value is **false**.
55
56 @line 13: Optional Local IP (either IPv4 or IPv6) address used to establish connections to the remote peer. Effective in active mode only.
57
58 @line 17: Explicitly designate the peer as internal or external. Default value is **INTERNAL**.
59
60 @line 19: Enable families.
61
62 -----
63
64 Once the remote peer is connected and it advertised routes to local BGP system, routes are stored in peer's RIBs.
65 The RIBs can be checked via REST:
66
67 **URL:** ``/restconf/operational/bgp-rib:bgp-rib/rib/bgp-example/peer/bgp:%2F%2F192.0.2.1``
68
69 **Method:** ``GET``
70
71 **Response Body:**
72
73 .. code-block:: xml
74    :linenos:
75    :emphasize-lines: 8,13,35,40,62,66
76
77    <peer xmlns="urn:opendaylight:params:xml:ns:yang:bgp-rib">
78        <peer-id>bgp://192.0.2.1</peer-id>
79        <supported-tables>
80            <afi xmlns:x="urn:opendaylight:params:xml:ns:yang:bgp-types">x:ipv4-address-family</afi>
81            <safi xmlns:x="urn:opendaylight:params:xml:ns:yang:bgp-types">x:unicast-subsequent-address-family</safi>
82        </supported-tables>
83        <peer-role>ibgp</peer-role>
84        <adj-rib-in>
85            <tables>
86                <afi xmlns:x="urn:opendaylight:params:xml:ns:yang:bgp-types">x:ipv4-address-family</afi>
87                <safi xmlns:x="urn:opendaylight:params:xml:ns:yang:bgp-types">x:unicast-subsequent-address-family</safi>
88                <ipv4-routes xmlns="urn:opendaylight:params:xml:ns:yang:bgp-inet">
89                    <ipv4-route>
90                        <path-id>0</path-id>
91                        <prefix>10.0.0.10/32</prefix>
92                        <attributes>
93                            <as-path></as-path>
94                            <origin>
95                                <value>igp</value>
96                            </origin>
97                            <local-pref>
98                                <pref>100</pref>
99                            </local-pref>
100                            <ipv4-next-hop>
101                                <global>10.10.1.1</global>
102                            </ipv4-next-hop>
103                        </attributes>
104                    </ipv4-route>
105                </ipv4-routes>
106                <attributes>
107                    <uptodate>true</uptodate>
108                </attributes>
109            </tables>
110        </adj-rib-in>
111        <effective-rib-in>
112            <tables>
113                <afi xmlns:x="urn:opendaylight:params:xml:ns:yang:bgp-types">x:ipv4-address-family</afi>
114                <safi xmlns:x="urn:opendaylight:params:xml:ns:yang:bgp-types">x:unicast-subsequent-address-family</safi>
115                <ipv4-routes xmlns="urn:opendaylight:params:xml:ns:yang:bgp-inet">
116                    <ipv4-route>
117                        <path-id>0</path-id>
118                        <prefix>10.0.0.10/32</prefix>
119                        <attributes>
120                            <as-path></as-path>
121                            <origin>
122                                <value>igp</value>
123                            </origin>
124                            <local-pref>
125                                <pref>100</pref>
126                            </local-pref>
127                            <ipv4-next-hop>
128                                <global>10.10.1.1</global>
129                            </ipv4-next-hop>
130                        </attributes>
131                    </ipv4-route>
132                </ipv4-routes>
133                <attributes>
134                    <uptodate>true</uptodate>
135                </attributes>
136            </tables>
137        </effective-rib-in>
138        <adj-rib-out>
139            <tables>
140                <afi xmlns:x="urn:opendaylight:params:xml:ns:yang:bgp-types">x:ipv4-address-family</afi>
141                <safi xmlns:x="urn:opendaylight:params:xml:ns:yang:bgp-types">x:unicast-subsequent-address-family</safi>
142                <ipv4-routes xmlns="urn:opendaylight:params:xml:ns:yang:bgp-inet"></ipv4-routes>
143                <attributes></attributes>
144            </tables>
145        </adj-rib-out>
146    </peer>
147
148 @line 8: **Adj-RIB-In** - Per-peer RIB, which contains unprocessed routes that has been advertised to local BGP speaker by the remote peer.
149
150 @line 13: Here is the reported route with destination *10.0.0.10/32* in Adj-RIB-In.
151
152 @line 35: **Effective-RIB-In** - Per-peer RIB, which contains processed routes as a result of applying inbound policy to Adj-RIB-In routes.
153
154 @line 40: Here is the reported route with destination *10.0.0.10/32*, same as in Adj-RIB-In, as it was not touched by import policy.
155
156 @line 62: **Adj-RIB-Out** - Per-peer RIB, which contains routes for advertisement to the peer by means of the local speaker's UPDATE message.
157
158 @line 66: The peer's Adj-RIB-Out is empty as there are no routes to be advertise from local BGP speaker.
159
160 -----
161
162 Also the same route should appeared in Loc-RIB now:
163
164 **URL:** ``/restconf/operational/bgp-rib:bgp-rib/rib/bgp-example/loc-rib/tables/bgp-types:ipv4-address-family/bgp-types:unicast-subsequent-address-family/ipv4-routes``
165
166 **Method:** ``GET``
167
168 **Response Body:**
169
170 .. code-block:: xml
171    :linenos:
172    :emphasize-lines: 4,6,8,11,14
173
174    <ipv4-routes xmlns="urn:opendaylight:params:xml:ns:yang:bgp-inet">
175        <ipv4-route>
176            <path-id>0</path-id>
177            <prefix>10.0.0.10/32</prefix>
178            <attributes>
179                <as-path></as-path>
180                <origin>
181                    <value>igp</value>
182                </origin>
183                <local-pref>
184                    <pref>100</pref>
185                </local-pref>
186                <ipv4-next-hop>
187                    <global>10.10.1.1</global>
188                </ipv4-next-hop>
189            </attributes>
190        </ipv4-route>
191    </ipv4-routes>
192
193 @line 4: **Destination** - IPv4 Prefix Address.
194
195 @line 6: **AS_PATH** - mandatory attribute, contains a list of the autonomous system numbers through that routing information has traversed.
196
197 @line 8: **ORIGIN** - mandatory attribute, indicates an origin of the route - **ibgp**, **egp**, **incomplete**.
198
199 @line 11: **LOCAL_PREF** - indicates a degree of preference for external routes, higher value is preferred.
200
201 @line 14: **NEXT_HOP** - mandatory attribute, defines IP address of the router that should be used as the next hop to the destination.
202
203 -----
204
205 There are much more attributes that may be carried along with the destination:
206
207 **BGP-4 Path Attributes**
208
209 * **MULTI_EXIT_DISC** (MED)
210    Optional attribute, to be used to discriminate among multiple exit/entry points on external links, lower number is preferred.
211
212    .. code-block:: xml
213
214       <multi-exit-disc>
215        <med>0</med>
216       </multi-exit-disc>
217
218
219 * **ATOMIC_AGGREGATE**
220    Indicates whether AS_SET was excluded from AS_PATH due to routes aggregation.
221
222    .. code-block:: xml
223
224       <atomic-aggregate/>
225
226 * **AGGREGATOR**
227    Optional attribute, contains AS number and IP address of a BGP speaker which performed routes aggregation.
228
229    .. code-block:: xml
230
231       <aggregator>
232           <as-number>65000</as-number>
233           <network-address>192.0.2.2</network-address>
234       </aggregator>
235
236 * **Unrecognised**
237    Optional attribute, used to store optional attributes, unrecognized by a local BGP speaker.
238
239    .. code-block:: xml
240
241       <unrecognized-attributes>
242           <partial>true</partial>
243           <transitive>true</transitive>
244           <type>101</type>
245           <value>0101010101010101</value>
246       </unrecognized-attributes>
247
248 **Route Reflector Attributes**
249
250 * **ORIGINATOR_ID**
251    Optional attribute, carries BGP Identifier of the originator of the route.
252
253    .. code-block:: xml
254
255       <originator-id>
256           <originator>41.41.41.41</originator>
257       </originator-id>
258
259 * **CLUSTER_LIST**
260    Optional attribute, contains a list of CLUSTER_ID values representing the path that the route has traversed.
261
262    .. code-block:: xml
263
264       <cluster-id>
265           <cluster>40.40.40.40</cluster>
266       </cluster-id>
267
268 * **Communities**
269    Optional attribute, may be used for policy routing.
270
271    .. code-block:: xml
272
273       <communities>
274           <as-number>65000</as-number>
275           <semantics>30740</semantics>
276       </communities>
277
278 **Extended Communities**
279
280 * **Route Target**
281    Identifies one or more routers that may receive a route.
282
283    .. code-block:: xml
284
285       <extended-communities>
286           <transitive>true</transitive>
287           <route-target-ipv4>
288               <global-administrator>192.0.2.2</global-administrator>
289               <local-administrator>123</local-administrator>
290           </route-target-ipv4>
291       </extended-communities>
292       <extended-communities>
293           <transitive>true</transitive>
294           <as-4-route-target-extended-community>
295                   <as-4-specific-common>
296                   <as-number>65000</as-number>
297                   <local-administrator>123</local-administrator>
298               </as-4-specific-common>
299           </as-4-route-target-extended-community>
300       </extended-communities>
301
302
303 * **Route Origin**
304    Identifies one or more routers that injected a route.
305
306    .. code-block:: xml
307
308       <extended-communities>
309           <transitive>true</transitive>
310           <route-origin-ipv4>
311               <global-administrator>192.0.2.2</global-administrator>
312               <local-administrator>123</local-administrator>
313           </route-origin-ipv4>
314       </extended-communities>
315       <extended-communities>
316           <transitive>true</transitive>
317           <as-4-route-origin-extended-community>
318               <as-4-specific-common>
319                   <as-number>65000</as-number>
320                   <local-administrator>123</local-administrator>
321               </as-4-origin-common>
322           </as-4-route-target-extended-community>
323       </extended-communities>
324
325
326 * **Link Bandwidth**
327    Carries the cost to reach external neighbor.
328
329    .. code-block:: xml
330
331       <extended-communities>
332           <transitive>true</transitive>
333           <link-bandwidth-extended-community>
334               <bandwidth>BH9CQAA=</bandwidth>
335           </link-bandwidth-extended-community>
336       </extended-communities>
337
338 * **AIGP**
339    Optional attribute, carries accumulated IGP metric.
340
341    .. code-block:: xml
342
343       <aigp>
344           <aigp-tlv>
345               <metric>120</metric>
346           </aigp-tlv>
347       </aigp>
348
349
350 .. note:: When the remote peer disconnects, it disappear from operational state of local speaker instance and advertised routes are removed too.
351
352 External peering configuration
353 ''''''''''''''''''''''''''''''
354 An example above provided configuration for internal peering only.
355 Following configuration sample is intended for external peering:
356
357 **URL:** ``/restconf/config/openconfig-network-instance:network-instances/network-instance/global-bgp/openconfig-network-instance:protocols/protocol/openconfig-policy-types:BGP/bgp-example/bgp/neighbors``
358
359 **Method:** ``POST``
360
361 **Content-Type:** ``application/xml``
362
363 **Request Body:**
364
365 .. code-block:: xml
366    :linenos:
367    :emphasize-lines: 5
368
369    <neighbor xmlns="urn:opendaylight:params:xml:ns:yang:bgp:openconfig-extensions">
370        <neighbor-address>192.0.2.3</neighbor-address>
371        <config>
372            <peer-type>EXTERNAL</peer-type>
373            <peer-as>64999</peer-as>
374        </config>
375    </neighbor>
376
377 @line 5: AS number of the remote peer.
378
379 Route reflector configuration
380 '''''''''''''''''''''''''''''
381 The local BGP speaker can be configured with a specific *cluster ID*.
382 Following example adds the cluster ID to the existing speaker instance:
383
384 **URL:** ``/restconf/config/openconfig-network-instance:network-instances/network-instance/global-bgp/openconfig-network-instance:protocols/protocol/openconfig-policy-types:BGP/bgp-example/bgp/global/config``
385
386 **Method:** ``PUT``
387
388 **Content-Type:** ``application/xml``
389
390 **Request Body:**
391
392 .. code-block:: xml
393    :linenos:
394    :emphasize-lines: 4
395
396    <config>
397        <router-id>192.0.2.2</router-id>
398        <as>65000</as>
399        <route-reflector-cluster-id>192.0.2.1</route-reflector-cluster-id>
400    </config>
401
402 @line 4: Route-reflector cluster id to use when local router is configured as a route reflector.
403    The *router-id* is used as a default value.
404
405 -----
406
407 Following configuration sample is intended for route reflector client peering:
408
409 **URL:** ``/restconf/config/openconfig-network-instance:network-instances/network-instance/global-bgp/openconfig-network-instance:protocols/protocol/openconfig-policy-types:BGP/bgp-example/bgp/neighbors``
410
411 **Method:** ``POST``
412
413 **Content-Type:** ``application/xml``
414
415 **Request Body:**
416
417 .. code-block:: xml
418    :linenos:
419    :emphasize-lines: 8
420
421    <neighbor xmlns="urn:opendaylight:params:xml:ns:yang:bgp:openconfig-extensions">
422        <neighbor-address>192.0.2.4</neighbor-address>
423        <config>
424            <peer-type>INTERNAL</peer-type>
425        </config>
426        <route-reflector>
427            <config>
428                <route-reflector-client>true</route-reflector-client>
429            </config>
430        </route-reflector>
431    </neighbor>
432
433 @line 8: Configure the neighbor as a route reflector client. Default value is *false*.
434
435 Route reflector and Multiple Cluster IDs
436 ''''''''''''''''''''''''''''''''''''''''
437
438 An optional non-transitive attribute called CLUSTER_LIST is modified when a route reflector reflects a prefix. 
439 For loop prevention the route reflector adds its own cluster ID to, and discards any update containing router's own cluster ID. 
440 Using multiple cluster IDs allows updates to propagate to nodes that reside in a different cluster.
441
442
443 .. figure:: ./images/MultipleClustersIds.png
444    :alt: BGP RR Multiple Cluster IDs setup.
445
446 Following configuration sample is intended for route reflector client peering using specific cluster id:
447
448 **URL:** ``/restconf/config/openconfig-network-instance:network-instances/network-instance/global-bgp/openconfig-network-instance:protocols/protocol/openconfig-policy-types:BGP/bgp-example/bgp/neighbors``
449
450 **Method:** ``POST``
451
452 **Content-Type:** ``application/xml``
453
454 **Request Body:**
455
456 .. code-block:: xml
457    :linenos:
458    :emphasize-lines: 5,8
459
460    <neighbor xmlns="urn:opendaylight:params:xml:ns:yang:bgp:openconfig-extensions">
461        <neighbor-address>192.0.2.4</neighbor-address>
462        <config>
463            <peer-type>INTERNAL</peer-type>
464            <route-reflector-cluster-id>192.0.2.4</route-reflector-cluster-id>
465        </config>
466        <route-reflector>
467            <config>
468                <route-reflector-client>true</route-reflector-client>
469            </config>
470        </route-reflector>
471    </neighbor>
472
473 @line 5: Route-reflector cluster id to use for this specific neighbor when local router is configured as a route reflector.
474
475 @line 8: Configure the neighbor as a route reflector client. Default value is *false*.
476
477 MD5 authentication configuration
478 ''''''''''''''''''''''''''''''''
479 The OpenDaylight BGP implementation is supporting TCP MD5 for authentication.
480 Sample configuration below shows how to set authentication password for a peer:
481
482 **URL:** ``/restconf/config/openconfig-network-instance:network-instances/network-instance/global-bgp/openconfig-network-instance:protocols/protocol/openconfig-policy-types:BGP/bgp-example/bgp/neighbors``
483
484 **Method:** ``POST``
485
486 **Content-Type:** ``application/xml``
487
488 **Request Body:**
489
490 .. code-block:: xml
491    :linenos:
492    :emphasize-lines: 4
493
494    <neighbor xmlns="urn:opendaylight:params:xml:ns:yang:bgp:openconfig-extensions">
495        <neighbor-address>192.0.2.5</neighbor-address>
496        <config>
497            <auth-password>topsecret</auth-password>
498        </config>
499    </neighbor>
500
501 @line 4: Configures an MD5 authentication password for use with neighboring devices.
502
503 BGP Peer Group
504 ''''''''''''''
505
506 Allows the creation of a peer group configuration that applies to all peers configured as part of the group.
507
508 A sample peer group configuration follows:
509
510 **URL:** ``/restconf/config/openconfig-network-instance:network-instances/network-instance/global-bgp/openconfig-network-instance:protocols/protocol/openconfig-policy-types:BGP/bgp-example/bgp/peer-groups``
511
512 **Method:** ``POST``
513
514 **Content-Type:** ``application/xml``
515
516 **Request Body:**
517
518 .. code-block:: xml
519    :linenos:
520    :emphasize-lines: 2
521
522    <peer-group xmlns="urn:opendaylight:params:xml:ns:yang:bgp:openconfig-extensions">
523        <peer-group-name>internal-neighbor</peer-group-name>
524        <config>
525            <peer-type>INTERNAL</peer-type>
526            <peer-as>64496</peer-as>
527        </config>
528        <transport>
529            <config>
530                <remote-port>179</remote-port>
531                <passive-mode>true</passive-mode>
532            </config>
533        </transport>
534        <timers>
535            <config>
536                <hold-time>180</hold-time>
537                <connect-retry>10</connect-retry>
538            </config>
539        </timers>
540        <route-reflector>
541            <config>
542                <route-reflector-client>false</route-reflector-client>
543            </config>
544        </route-reflector>
545        <afi-safis>
546            <afi-safi>
547                <afi-safi-name xmlns:x="http://openconfig.net/yang/bgp-types">x:IPV4-UNICAST</afi-safi-name>
548                <!--Advertise N Paths
549                <receive>true</receive>
550                <send-max>0</send-max>-->
551            </afi-safi>
552            <afi-safi>
553                <afi-safi-name xmlns:x="http://openconfig.net/yang/bgp-types">x:IPV6-UNICAST</afi-safi-name>
554            </afi-safi>
555            <afi-safi>
556                <afi-safi-name xmlns:x="http://openconfig.net/yang/bgp-types">x:IPV4-LABELLED-UNICAST</afi-safi-name>
557            </afi-safi>
558            <afi-safi>
559                <afi-safi-name xmlns:x="http://openconfig.net/yang/bgp-types">x:IPV6-LABELLED-UNICAST</afi-safi-name>
560            </afi-safi>
561            <afi-safi>
562                <afi-safi-name xmlns:x="http://openconfig.net/yang/bgp-types">x:L3VPN-IPV4-UNICAST</afi-safi-name>
563            </afi-safi>
564            <afi-safi>
565                <afi-safi-name xmlns:x="http://openconfig.net/yang/bgp-types">x:L3VPN-IPV6-UNICAST</afi-safi-name>
566            </afi-safi>
567            <afi-safi>
568                <afi-safi-name xmlns:x="http://openconfig.net/yang/bgp-types">x:L2VPN-EVPN</afi-safi-name>
569            </afi-safi>
570            <afi-safi>
571                <afi-safi-name>LINKSTATE</afi-safi-name>
572            </afi-safi>
573            <afi-safi>
574                <afi-safi-name>IPV4-FLOW</afi-safi-name>
575            </afi-safi>
576            <afi-safi>
577                <afi-safi-name>IPV6-FLOW</afi-safi-name>
578            </afi-safi>
579            <afi-safi>
580                <afi-safi-name>IPV4-L3VPN-FLOW</afi-safi-name>
581            </afi-safi>
582            <afi-safi>
583                <afi-safi-name>IPV6-L3VPN-FLOW</afi-safi-name>
584            </afi-safi>
585        </afi-safis>
586    </peer-group>
587
588 @line 2: Peer Group Identifier.
589
590 -----
591
592 A sample basic neighbor configuration using a peer group follows:
593
594 **URL:** ``/restconf/config/openconfig-network-instance:network-instances/network-instance/global-bgp/openconfig-network-instance:protocols/protocol/openconfig-policy-types:BGP/bgp-example/bgp/neighbors``
595
596 **Method:** ``POST``
597
598 **Content-Type:** ``application/xml``
599
600 **Request Body:**
601
602 .. code-block:: xml
603    :linenos:
604    :emphasize-lines: 4
605
606    <neighbor>
607       <neighbor-address>192.0.2.1</neighbor-address>
608       <config>
609          <peer-group>/bgp/neighbors/neighbor/bgp/peer-groups/peer-group[peer-group-name="internal-neighbor"]</peer-group>
610       </config>
611    </neighbor>
612
613 @line 4: Peer group identifier.
614
615 .. note:: Existing neighbor configuration can be reconfigured (change configuration parameters) anytime.
616    As a result, established connection is dropped, peer instance is recreated with a new configuration settings and connection re-established.
617
618 .. note:: The BGP configuration is persisted on OpendDaylight shutdown and restored after the re-start.