--- /dev/null
+module ietf-bgp-policy {
+ yang-version "1.1";
+ namespace "urn:ietf:params:xml:ns:yang:ietf-bgp-policy";
+ prefix "bp";
+
+ // import some basic types
+ import ietf-inet-types {
+ prefix inet;
+ }
+ import ietf-routing-policy {
+ prefix rpol;
+ }
+ import ietf-bgp-types {
+ prefix bt;
+ }
+
+ import ietf-routing-types {
+ prefix rt-types;
+ }
+
+ organization
+ "IETF IDR Working Group";
+
+ contact
+ "WG Web: <http://tools.ietf.org/wg/idr>
+ WG List: <idr@ietf.org>
+
+ Authors: Mahesh Jethanandani (mjethanandani at gmail.com),
+ Keyur Patel (keyur at arrcus.com),
+ Susan Hares (shares at ndzh.com)";
+
+ description
+ "This module contains data definitions for BGP routing policy.
+ It augments the base routing-policy module with BGP-specific
+ options for conditions and actions.";
+
+ revision "2019-06-13" {
+ description
+ "Initial Version";
+ reference
+ "RFC XXX, BGP Model for Service Provider Network.";
+ }
+
+ // 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 uint32;
+ type string {
+ pattern "^[+-][0-9]+";
+ }
+ type enumeration {
+ enum IGP {
+ description
+ "Set the MED value to the IGP cost toward the
+ next hop for the route";
+ }
+ }
+ }
+ 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).";
+ }
+
+ // augment statements
+
+ augment "/rpol:routing-policy/rpol:defined-sets" {
+ description
+ "Adds BGP defined sets container to routing policy model.";
+
+ container bgp-defined-sets {
+ description
+ "BGP-related set definitions for policy match conditions";
+
+ container community-sets {
+ description
+ "Enclosing container for list of defined BGP community sets";
+
+ list community-set {
+ key "community-set-name";
+ description
+
+ "List of defined BGP community sets";
+
+ leaf community-set-name {
+ type string;
+ mandatory true;
+ description
+ "Name / label of the community set -- this is used to
+ reference the set in match conditions";
+ }
+
+ leaf-list community-member {
+ type union {
+ type bt:bgp-std-community-type;
+ type bt:bgp-community-regexp-type;
+ type bt:bgp-well-known-community-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 "ext-community-set-name";
+ description
+ "List of defined extended BGP community sets";
+
+ leaf ext-community-set-name {
+ type string;
+ description
+ "Name / label of the extended community set -- this is
+ used to reference the set in match conditions";
+ }
+
+ leaf-list ext-community-member {
+ type union {
+ type rt-types:route-target;
+ type bt:bgp-community-regexp-type;
+ }
+ description
+ "Members of the extended community set";
+ }
+ }
+ }
+
+ container as-path-sets {
+ description
+ "Enclosing container for list of define AS path sets";
+
+ list as-path-set {
+ key "as-path-set-name";
+ description
+ "List of defined AS path sets";
+
+ leaf as-path-set-name {
+ type string;
+ description
+ "Name of the AS path set -- this is used to reference the
+ set in match conditions";
+ }
+
+ leaf-list as-path-set-member {
+ // TODO: need to refine typedef for AS path expressions
+ type string;
+ description
+ "AS path expression -- list of ASes in the set";
+ }
+ }
+ }
+ }
+ }
+
+ grouping set-community-action-common {
+ description
+ "Common leaves for set-community and set-ext-community
+ actions";
+
+ leaf method {
+ type enumeration {
+ enum INLINE {
+ description
+ "The extended communities are specified inline as a
+ list";
+ }
+ enum REFERENCE {
+ description
+ "The extended communities are specified by referencing a
+ defined ext-community set";
+ }
+ }
+ description
+ "Indicates the method used to specify the extended
+ communities for the set-ext-community action";
+
+ }
+
+ 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.";
+ }
+ }
+
+ augment "/rpol:routing-policy/rpol:policy-definitions/" +
+ "rpol:policy-definition/rpol:statements/rpol:statement/" +
+ "rpol:conditions" {
+ description
+ "BGP policy conditions added to routing policy module";
+
+ container bgp-conditions {
+ description
+ "Top-level container for BGP specific policy conditions ";
+
+ leaf med-eq {
+ type uint32;
+ description
+ "Condition to check if the received MED value is equal to
+ the specified value";
+ }
+
+ leaf origin-eq {
+ type bt:bgp-origin-attr-type;
+ description
+ "Condition to check if the route origin is equal to the
+ specified value";
+ }
+
+ leaf-list next-hop-in {
+ type inet:ip-address-no-zone;
+ description
+ "List of next hop addresses to check for in the route
+ update";
+ }
+
+ leaf-list afi-safi-in {
+ type identityref {
+ base bt:afi-safi-type;
+ }
+ description
+ "List of address families which the NLRI may be within";
+
+ }
+
+ leaf local-pref-eq {
+ type uint32;
+ // TODO: add support for other comparisons if needed
+ description
+ "Condition to check if the local pref attribute is equal to
+ the specified value";
+ }
+
+ leaf route-type {
+ // TODO: verify extent of vendor support for this comparison
+ type enumeration {
+ enum INTERNAL {
+ description "route type is internal";
+ }
+ enum EXTERNAL {
+ description "route type is external";
+ }
+ }
+ description
+ "Condition to check the route type in the route update";
+ }
+
+ container community-count {
+ description
+ "Value and comparison operations for conditions based on the
+ number of communities in the route update";
+ }
+
+ container as-path-length {
+ description
+ "Value and comparison operations for conditions based on the
+ length of the AS path in the route update";
+ }
+
+ 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
+ "/rpol:routing-policy/rpol:defined-sets/" +
+ "bp:bgp-defined-sets/bp:community-sets/" +
+ "bp:community-set/bp:community-set-name";
+
+ }
+ description
+ "References a defined community set";
+ }
+
+ uses rpol: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
+ "/rpol:routing-policy/rpol:defined-sets/" +
+ "bp:bgp-defined-sets/bp:ext-community-sets/" +
+ "bp:ext-community-set/" +
+ "bp:ext-community-set-name";
+ }
+ description "References a defined extended community set";
+ }
+
+ uses rpol: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 "/rpol:routing-policy/rpol:defined-sets/" +
+ "bp:bgp-defined-sets/bp:as-path-sets/" +
+ "bp:as-path-set/bp:as-path-set-name";
+ }
+ description
+ "References a defined AS path set";
+ }
+ uses rpol:match-set-options-group;
+ }
+ }
+ }
+
+ augment "/rpol:routing-policy/rpol:policy-definitions/" +
+ "rpol:policy-definition/rpol:statements/rpol:statement/" +
+
+ "rpol:actions" {
+ description
+ "BGP policy actions added to routing policy module.";
+
+ container bgp-actions {
+ description
+ "Top-level container for BGP-specific actions";
+
+ leaf set-route-origin {
+ type bt:bgp-origin-attr-type;
+ description
+ "Set the origin attribute to the specified value";
+ }
+
+ 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.";
+ }
+ }
+
+ 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).";
+
+ uses set-community-action-common;
+ container inline {
+ when "../method = 'INLINE'" {
+ description
+ "Active only when the set-community method is INLINE";
+ }
+ description
+ "Set the community values for the action inline with
+ a list.";
+
+ leaf-list communities {
+ type union {
+ type bt:bgp-std-community-type;
+ type bt:bgp-well-known-community-type;
+ }
+ description
+ "Set the community values for the update inline with a
+ list.";
+ }
+ }
+
+ container reference {
+ when "../method = 'REFERENCE'" {
+ description
+ "Active only when the set-community method is REFERENCE";
+ }
+ description
+ "Provide a reference to a defined community set for the
+ set-community action";
+
+ leaf community-set-ref {
+ type leafref {
+ path "/rpol:routing-policy/rpol:defined-sets/" +
+ "bp:bgp-defined-sets/" +
+ "bp:community-sets/bp:community-set/" +
+ "bp: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).";
+
+ uses set-community-action-common;
+ container inline {
+ when "../method = 'INLINE'" {
+ description
+ "Active only when the set-community method is INLINE";
+ }
+ description
+ "Set the extended community values for the action inline
+ with a list.";
+
+ leaf-list communities {
+ type union {
+ type rt-types:route-target;
+ type bt:bgp-well-known-community-type;
+ }
+ description
+ "Set the extended community values for the update inline
+ with a list.";
+ }
+ }
+
+ container reference {
+ when "../method = 'REFERENCE'" {
+ description
+ "Active only when the set-community method is REFERENCE";
+ }
+ description
+ "Provide a reference to an extended community set for the
+ set-ext-community action";
+
+ leaf ext-community-set-ref {
+ type leafref {
+ path
+ "/rpol:routing-policy/rpol:defined-sets/" +
+ "bp:bgp-defined-sets/bp:ext-community-sets/" +
+ "bp:ext-community-set/" +
+ "bp:ext-community-set-name";
+ }
+
+ description
+ "References a defined extended community set by name";
+ }
+ }
+ }
+ }
+ }
+
+ // rpc statements
+
+ // notification statements
+}
+
\ No newline at end of file