module org-openroadm-routing-policy-bgp { yang-version 1.1; namespace "http://org/openroadm/routing-policy-bgp"; prefix rt-pol-bgp; import ietf-inet-types { prefix inet; reference "RFC 6991: Common YANG Data Types"; } import org-openroadm-device { prefix org-openroadm-device; revision-date 2025-05-30; } import org-openroadm-routing-policy { prefix rt-pol; revision-date 2025-05-30; } organization "Open ROADM MSA"; contact "OpenROADM.org"; description "This model defines Yang model for BGP routing policy. This model reuses data items defined in the IETF YANG model for routing policy by RFC9067 and draft-ietf-idr-bgp-model-18. Some attributes which are not required in Open ROADM MSA are removed. Yang file included are changed to fit into Open ROADM MSA yang structure. IETF code is subject to the following copyright and license: Copyright (c) IETF Trust and the persons identified as authors of the code. All rights reserved. Redistribution and use in source and binary forms, with or without modification, is permitted pursuant to, and subject to the license terms contained in, the Simplified BSD License set forth in Section 4.c of the IETF Trust's Legal Provisions Relating to IETF Documents (http://trustee.ietf.org/license-info)."; revision 2025-05-30 { description "Version 17.1.0"; } revision 2025-03-28 { description "Version 17.0"; } /* * typedef statements */ typedef bgp-set-community-option-type { type enumeration { enum add { description "Add the specified communities to the existing community attribute."; } enum remove { description "Remove the specified communities from the existing community attribute."; } enum replace { description "Replace the existing community attribute with the specified communities. If an empty set is specified, this removes the community attribute from the route."; } } description "Type definition for options when setting the community attribute in a policy action."; } typedef bgp-next-hop-type { type union { type inet:ip-address-no-zone; type enumeration { enum self { description "Special designation for local router's own address, i.e., next-hop-self."; } } } description "Type definition for specifying next-hop in policy actions."; } typedef bgp-set-med-type { type union { type string { pattern '[+-]([0-9]{1,8}|[0-3][0-9]{1,9}|4[0-1][0-9]{1,8}|' + '428[0-9]{1,7}|429[0-3][0-9]{1,6}|42948[0-9]{1,5}|' + '42949[0-5][0-9]{1,4}|429496[0-6][0-9]{1,3}|' + '4294971[0-9]{1,2}|42949728[0-9]|42949729[0-5])'; } type enumeration { enum igp { description "Set the MED value to the IGP cost toward the next hop for the route."; } enum med-plus-igp { description "Before comparing MED values for path selection, adds to the MED the cost of the IGP route to the BGP next-hop destination. This option replaces the MED value for the router, but does not affect the IGP metric comparison. As a result, when multiple routes have the same value after the MED-plus-IPG comparison, and route selection continues, the IGP route metric is also compared, even though it was added to the MED value and compared earlier in the selection process. Useful when the downstream AS requires the complete cost of a certain route that is received across multiple ASs."; } } type uint32; } description "Type definition for specifying how the BGP MED can be set in BGP policy actions. The three choices are to set the MED directly, increment/decrement using +/- notation, and setting it to the IGP cost (predefined value)."; } /* BGP Origin Attribute Types. */ typedef bgp-origin-attr-type { type enumeration { enum igp { description "Origin of the NLRI is internal"; } enum egp { description "Origin of the NLRI is EGP"; } enum incomplete { description "Origin of the NLRI is neither IGP or EGP"; } } description "Type definition for standard BGP origin attribute"; reference "RFC 4271: A Border Gateway Protocol 4 (BGP-4), Sec 4.3."; } /* * Identities. */ /* BGP Well-Known Standard (RFC 1997) Community Identities. */ identity bgp-well-known-std-community { description "Base identity for reserved communities within the standard community space defined by RFC 1997. These communities must fall within the range 0xFFFF0000 to 0xFFFFFFFF"; reference "RFC 1997: BGP Communities Attribute."; } identity no-export { base bgp-well-known-std-community; description "Do not export NLRI received carrying this community outside the bounds of this autonomous system, or this confederation (if the local autonomous system is a confederation member AS). This community has a value of 0xFFFFFF01."; reference "RFC 1997: BGP Communities Attribute."; } identity no-advertise { base bgp-well-known-std-community; description "All NLRI received carrying this community must not be advertised to other BGP peers. This community has a value of 0xFFFFFF02."; reference "RFC 1997: BGP Communities Attribute."; } identity no-export-subconfed { base bgp-well-known-std-community; description "All NLRI received carrying this community must not be advertised to external BGP peers - including over confederation sub-AS boundaries. This community has a value of 0xFFFFFF03."; reference "RFC 1997: BGP Communities Attribute."; } identity no-peer { base bgp-well-known-std-community; description "An autonomous system receiving NLRI tagged with this community is advised not to re-advertise the NLRI to external bilateral peer autonomous systems. An AS may also filter received NLRI from bilateral peer sessions when they are tagged with this community value. This community has a value of 0xFFFFFF04."; reference "RFC 3765: NOPEER Community for BGP."; } /* * Features. */ feature send-communities { description "Enable the propagation of communities."; } /* BGP Community Send Identities. */ identity send-community-feature { description "Base identity to identify send-community feature."; } identity standard { base send-community-feature; description "Send standard communities."; reference "RFC 1997: BGP Communities Attribute."; } identity extended { base send-community-feature; description "Send extended communities."; reference "RFC 4360: BGP Extended Communities Attribute."; } /* * Typedefs. */ /* BGP Community Types. */ typedef bgp-community-regexp-type { type string; description "Type definition for communities specified as regular expression patterns. A compliant implementation of this type MUST accept a POSIX.2 Extended Regular Expression excluding the following features: - character class expressions (Section 9.3.5) - collating symbols (Section 9.3.5) - equivalence classes (Section 9.3.5) - back-reference expressions (Section 9.3.6) Implementations MAY accept additional forms of regular expressions as long as the minimally compliant form documented above is accepted."; reference "IEEE Std 1003.1-2017: The Open Group Base Specifications Issue 7, 2018 edition."; } typedef bgp-std-community-type { type union { type uint32; type string { pattern '([0-9]|[1-9][0-9]{1,3}|[1-5][0-9]{4}|' + '6[0-5][0-9]{3}|66[0-4][0-9]{2}|' + '665[0-2][0-9]|6653[0-5]):' + '([0-9]|[1-9][0-9]{1,3}|[1-5][0-9]{4}|' + '6[0-5][0-9]{3}|66[0-4][0-9]{2}|' + '665[0-2][0-9]|6653[0-5])'; } } description "Type definition for standard community attributes."; reference "RFC 1997: BGP Communities Attribute."; } typedef bgp-well-known-community-type { type identityref { base bgp-well-known-std-community; } description "Type definition for well-known IETF community attribute values."; reference "IANA Border Gateway Protocol (BGP) Well Known Communities"; } /* BGP Extended Community Types. */ typedef bgp-ext-community-type { type union { type string { pattern 'route\-target:(6[0-5][0-5][0-3][0-5]|' + '[1-5][0-9]{4}|[1-9][0-9]{1,4}|[0-9]):' + '(4[0-2][0-9][0-4][0-9][0-6][0-7][0-2][0-9][0-6]|' + '[1-3][0-9]{9}|[1-9]([0-9]{1,7})?[0-9]|[0-9])'; /* * description * "Type 0x00, Sub-Type 0x02: Route-Target * route-target:(ASN):(local-admin) * 2 octets global administrator and 4 octets local * administrator."; * reference * "RFC 4360: BGP Extended Communities Attribute, * Section 4."; */ } type string { pattern 'route\-target:' + '(([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|' + '25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9][0-9]|' + '2[0-4][0-9]|25[0-5]):' + '(6[0-5][0-5][0-3][0-5]|[1-5][0-9]{4}|' + '[1-9][0-9]{1,4}|[0-9])'; /* * description * "Type 0x01, Sub-Type 0x02: Route-Target * route-target:(IPv4):(local-admin) * 4 octets IP address global administrator and 2 octets * local administrator."; * reference * "RFC 4360: BGP Extended Communities Attribute, * Section 4."; */ } type string { pattern 'route\-target:' + '(4[0-2][0-9][0-4][0-9][0-6][0-7][0-2][0-9][0-6]|' + '[1-3][0-9]{9}|[1-9]([0-9]{1,7})?[0-9]|[0-9])' + '(6[0-5][0-5][0-3][0-5]|[1-5][0-9]{4}|' + '[1-9][0-9]{1,4}|[0-9])'; /* * description * "Type 0x02, Sub-Type 0x02: Route-Target * route-target:(ASN):(local-admin) * 4 octets global administrator and 2 octets local * administrator."; * reference * "RFC 5668: 4-Octet AS Specific BGP Extended Community, * Section 4."; */ } type string { pattern 'route\-origin:(6[0-5][0-5][0-3][0-5]|' + '[1-5][0-9]{4}|[1-9][0-9]{1,4}|[0-9]):' + '(4[0-2][0-9][0-4][0-9][0-6][0-7][0-2][0-9][0-6]|' + '[1-3][0-9]{9}|[1-9]([0-9]{1,7})?[0-9]|[0-9])'; /* * description * "Type 0x01, Sub-Type 0x03: Route-Origin * route-target:(ASN):(local-admin) * 2 octets global administrator and 4 octets local * administrator."; * reference * "RFC 4360: BGP Extended Communities Attribute, * Section 5."; */ } type string { pattern 'route\-origin:' + '(([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|' + '25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9][0-9]|' + '2[0-4][0-9]|25[0-5]):' + '(6[0-5][0-5][0-3][0-5]|[1-5][0-9]{4}|' + '[1-9][0-9]{1,4}|[0-9])'; /* * description * "Type 0x01, Sub-Type 0x03: Route-Target * route-target:(IPv4):(local-admin) * 4 octets IP address global administrator and 2 octets * local administrator."; * reference * "RFC 4360: BGP Extended Communities Attribute, * Section 5."; */ } type string { pattern 'route\-origin:' + '(4[0-2][0-9][0-4][0-9][0-6][0-7][0-2][0-9][0-6]|' + '[1-3][0-9]{9}|[1-9]([0-9]{1,7})?[0-9]|[0-9])' + '(6[0-5][0-5][0-3][0-5]|[1-5][0-9]{4}|' + '[1-9][0-9]{1,4}|[0-9])'; /* * description * "Type 0x02, Sub-Type 0x03: Route-Origin * route-origin:(ASN):(local-admin) * 4 octets global administrator and 2 octets local * administrator."; * reference * "RFC 5668: 4-Octet AS Specific BGP Extended Community, * Section 4."; */ } type string { // raw with 8 octets pattern 'raw:' + '([0-9A-Fa-f][0-9A-Fa-f]:){7}' + '[0-9A-Fa-f][0-9A-Fa-f]'; } } description "Type definition for extended community attributes. It includes a way to specify a 'raw' string that is followed by 8 bytes of octet string to support new and experimental type definitions."; reference "RFC 4360: BGP Extended Communities Attribute."; } /* Defined set definition */ grouping bgp-policy-sets { description "Parameters for BGP policy set"; container bgp-defined-sets { description "BGP-related set definitions for policy match conditions or actions."; container as-path-sets { description "Enclosing container for list of define AS path sets."; list as-path-set { key "name"; description "List of defined AS path sets."; leaf name { type string; description "Name of the AS path set -- this is used to reference the set in match conditions."; } leaf-list member { type string; description "AS path regular expression using BGP YANG AS_PATH regular expression syntax. If any of the regular expressions in the lists are matched, the as-path-set is considered matched."; reference "RFC XXXX: YANG Model for Border Gateway Protocol (BGP-4), Appendix F.3."; } } } container community-sets { description "Enclosing container for list of defined BGP community sets."; list community-set { key "name"; description "List of defined BGP community sets."; leaf name { type string; description "Name / label of the community set -- this is used to reference the set in match conditions."; } leaf-list member { type union { type bgp-well-known-community-type; type bgp-std-community-type; type bgp-community-regexp-type; } description "Members of the community set"; } } } container ext-community-sets { description "Enclosing container for list of extended BGP community sets"; list ext-community-set { key "name"; description "List of defined extended BGP community sets"; leaf name { type string; description "Name / label of the extended community set -- this is used to reference the set in match conditions"; } leaf-list member { type union { type bgp-ext-community-type; type bgp-community-regexp-type; } description "Members of the extended community set."; } } } } } /* Condition definition */ grouping bgp-match-conditions { description "Parameters for BGP match conditions"; container bgp-conditions { description "Top-level container for BGP specific policy conditions "; container match-community-set { description "Top-level container for match conditions on communities. Match a referenced community-set according to the logic defined in the match-set-options leaf."; leaf community-set { type leafref { path "../../../../../../../../../" + "rt-pol:routing-policy/rt-pol:defined-sets/" + "bgp-defined-sets/community-sets/" + "community-set/name"; } description "References a defined community set."; } uses rt-pol:match-set-options-group; } container match-ext-community-set { description "Match a referenced extended community-set according to the logic defined in the match-set-options leaf."; leaf ext-community-set { type leafref { path "../../../../../../../../../" + "rt-pol:routing-policy/rt-pol:defined-sets/" + "bgp-defined-sets/ext-community-sets/" + "ext-community-set/name"; } description "References a defined extended community set."; } leaf ext-community-match-kind { type enumeration { enum ext-community { description "Perform the match against the ext-community RIB attribute."; } enum ext-community-raw { description "Perform the match against the ext-community-raw RIB attribute."; } } default ext-community; description "Extended communities may be matched by the ext-community RIB attribute, or the ext-community-raw RIB attribute. This leaf selects which leaf to perform the match operation against."; } uses rt-pol:match-set-options-group; } container match-as-path-set { description "Match a referenced as-path set according to the logic defined in the match-set-options leaf."; leaf as-path-set { type leafref { path "../../../../../../../../../" + "rt-pol:routing-policy/rt-pol:defined-sets/" + "bgp-defined-sets/as-path-sets/" + "as-path-set/name"; } description "References a defined AS path set"; } uses rt-pol:match-set-options-group; } leaf med-eq { type uint32; description "Condition to check if the received MED value is equal to the specified value"; } leaf origin-eq { type rt-pol-bgp:bgp-origin-attr-type; description "Condition to check if the route origin is equal to the specified value"; } } } grouping bgp-match-actions { description "Parameters for BGP actions"; container bgp-actions { description "Top-level container for BGP specific policy conditions "; leaf set-local-pref { type uint32; description "Set the local pref attribute on the route update"; } leaf set-next-hop { type bgp-next-hop-type; description "Set the next-hop attribute in the route update"; } leaf set-med { type bgp-set-med-type; description "Set the med metric attribute in the route update"; } container set-as-path-prepend { description "Action to prepend local AS number to the AS-path a specified number of times"; leaf repeat-n { type uint8 { range "1..max"; } description "Number of times to prepend the local AS number to the AS path. The value should be between 1 and the maximum supported by the implementation."; } leaf asn { type inet:as-number; description "The AS number to prepend to the AS path. If neither this leaf nor use-last-as leaf is specified but repeat-n is set, then the local AS number will be used for prepending."; } } container set-community { description "Action to set the community attributes of the route, along with options to modify how the community is modified. Communities may be set using an inline list OR reference to an existing defined set (not both)."; leaf options { type bgp-set-community-option-type; description "Options for modifying the community attribute with the specified values. These options apply to both methods of setting the community attribute."; } choice method { description "Indicates the method used to specify the extended communities for the set-community action"; case inline { leaf-list communities { type union { type bgp-well-known-community-type; type bgp-std-community-type; } description "Set the community values for the update inline with a list."; } } case reference { leaf community-set-ref { type leafref { path "../../../../../../../../../" + "rt-pol:routing-policy/rt-pol:defined-sets/" + "bgp-defined-sets/" + "community-sets/community-set/name"; } description "References a defined community set by name"; } } } } container set-ext-community { description "Action to set the extended community attributes of the route, along with options to modify how the community is modified. Extended communities may be set using an inline list OR a reference to an existing defined set (but not both)."; leaf options { type bgp-set-community-option-type; description "Options for modifying the community attribute with the specified values. These options apply to both methods of setting the community attribute."; } choice method { description "Indicates the method used to specify the extended communities for the set-ext-community action"; case inline { leaf-list communities { type bgp-ext-community-type; description "Set the extended community values for the update inline with a list."; } } case reference { leaf ext-community-set-ref { type leafref { path "../../../../../../../../../" + "rt-pol:routing-policy/rt-pol:defined-sets/" + "bgp-defined-sets/ext-community-sets/" + "ext-community-set/name"; } description "References a defined extended community set by name."; } } } } } } /* augment the groupings into the routing policy model */ augment "/org-openroadm-device:org-openroadm-device/" + "rt-pol:routing-policy/rt-pol:policy-definitions/" + "rt-pol:policy-definition/rt-pol:statements/rt-pol:statement/" + "rt-pol:conditions" { description "Add BGP specific match conditions to the routing policy model"; uses bgp-match-conditions; } augment "/org-openroadm-device:org-openroadm-device/" + "rt-pol:routing-policy/rt-pol:policy-definitions/" + "rt-pol:policy-definition/rt-pol:statements/rt-pol:statement/" + "rt-pol:actions" { description "Add BGP specific actions to the routing policy model"; uses bgp-match-actions; } augment "/org-openroadm-device:org-openroadm-device/" + "rt-pol:routing-policy/rt-pol:defined-sets" { description "Adds BGP defined sets container to routing policy model."; uses bgp-policy-sets; } }