Interdomain Routing                                       A. Shaikh, Ed.
Internet-Draft                                                    Google
Intended status: Standards Track                          R. Shakir, Ed.
Expires: July 10, 2016 January 19, 2017                            Jive Communications
                                                           K. Patel, Ed.
                                                                   Cisco
                                                           S. Hares, Ed.
                                                                  Huawei
                                                              K. D'Souza
                                                                    AT&T
                                                               D. Bansal
                                                               Microsoft
                                                                A. Clemm
                                                             A. Zhdankin
                                                                   Cisco
                                                         M. Jethanandani
                                                                   Ciena
                                                      Cisco Systems, Inc
                                                                  X. Liu
                                                                Ericsson
                                                         January 7,
                                                           July 18, 2016

                BGP Model for Service Provider Networks
                      draft-ietf-idr-bgp-model-01
                      draft-ietf-idr-bgp-model-02

Abstract

   This document defines a YANG data model for configuring and managing
   BGP, including protocol, policy, and operational aspects based on
   data center, carrier and content provider operational requirements.

Status of This Memo

   This Internet-Draft is submitted in full conformance with the
   provisions of BCP 78 and BCP 79.

   Internet-Drafts are working documents of the Internet Engineering
   Task Force (IETF).  Note that other groups may also distribute
   working documents as Internet-Drafts.  The list of current Internet-
   Drafts is at http://datatracker.ietf.org/drafts/current/.

   Internet-Drafts are draft documents valid for a maximum of six months
   and may be updated, replaced, or obsoleted by other documents at any
   time.  It is inappropriate to use Internet-Drafts as reference
   material or to cite them other than as "work in progress."

   This Internet-Draft will expire on July 10, 2016. January 19, 2017.

Copyright Notice

   Copyright (c) 2016 IETF Trust and the persons identified as the
   document authors.  All rights reserved.

   This document is subject to BCP 78 and the IETF Trust's Legal
   Provisions Relating to IETF Documents
   (http://trustee.ietf.org/license-info) in effect on the date of
   publication of this document.  Please review these documents
   carefully, as they describe your rights and restrictions with respect
   to this document.  Code Components extracted from this document must
   include Simplified BSD License text as described in Section 4.e of
   the Trust Legal Provisions and are provided without warranty as
   described in the Simplified BSD License.

Table of Contents

   1.  Introduction  . . . . . . . . . . . . . . . . . . . . . . . .   2
     1.1.  Goals and approach  . . . . . . . . . . . . . . . . . . .   3
   2.  Model overview  . . . . . . . . . . . . . . . . . . . . . . .   4
     2.1.  BGP protocol configuration  . . . . . . . . . . . . . . .   5
     2.2.  Policy configuration overview . . . . . . . . . . . . . .   6
     2.3.  Operational data state overview  . . . . . . . . . . . . . . . .   7
   3.  Relation to other YANG data models  . . . . . . . . . . . . .   8
   4.  Security Considerations . . . . . . . . . . . . . . . . . . .   8
   5.  IANA Considerations . . . . . . . . . . . . . . . . . . . . .   9   8
   6.  YANG modules  . . . . . . . . . . . . . . . . . . . . . . . .   9
     6.1.
   7.  BGP main module and submodule for base items  . . . . . . . . . . . . . . . . . . . . .   9
     6.2.
   8.  BGP base types . . . . . . . . . . . . . . . . . . . . .  28
     6.3.  BGP policy items  . . . . . . . . . . . . . . . . . . . .  34
     6.4.  60
   9.  BGP multiprotocol items . . . . . . . . . policy data . . . . . . . .  44
     6.5.  BGP operational data items . . . . . . . . . . . . . . .  56
   7.  69
   10. References  . . . . . . . . . . . . . . . . . . . . . . . . .  63
     7.1.  93
     10.1.  Normative references . . . . . . . . . . . . . . . . . .  63
     7.2.  93
     10.2.  Informative references . . . . . . . . . . . . . . . . .  64  95
   Appendix A.  Acknowledgements . . . . . . . . . . . . . . . . . .  65  95
   Appendix B.  Change summary . . . . . . . . . . . . . . . . . . .  65  96
     B.1.  Changes between revisions -01 and -02 . . . . . . . . . .  96
     B.2.  Changes between revisions -00 and -01 . . . . . . . . . .  65  96
   Authors' Addresses  . . . . . . . . . . . . . . . . . . . . . . .  65  96

1.  Introduction

   YANG [RFC6020] is a data modeling language that was introduced to
   define the contents of a conceptual data store that allows for managing networked devices to be managed using NETCONF [RFC6241].
   YANG is proving relevant beyond its initial confines, as bindings to
   other interfaces (e.g.  ReST) and encodings other than XML (e.g.
   JSON) are being defined.  Furthermore, YANG data models can be used
   as the basis of implementation for a number of interfaces, such as
   CLIs and programmatic APIs. APIs (e.g., see
   [I-D.talwar-rtgwg-grpc-use-cases]).

   This document describes a YANG data model for the BGP [RFC4271]
   protocol, including various protocol extensions, policy
   configuration, as well as defining key operational state data.  The
   model is intended to be vendor-neutral, in order to allow operators
   to manage BGP configuration in heterogeneous environments with
   routers supplied by multiple vendors.  The model is also intended to
   be readily mapped to existing implementations to facilitate support
   from as large a set of routing hardware and software vendors as
   possible.

1.1.  Goals and approach

   The model covers the base BGP features that are deployed across major
   implementations and the common BGP configurations in use across a
   number of operator network deployments.  In particular, this model
   attempts to cover BGP features defined in [RFC4271], [RFC1997],
   [RFC4456], [RFC4760], [RFC3065], [RFC2439], [RFC4724], and [RFC6811].

   Along with configuration of base BGP features, this model also
   addresses policy configuration, by providing "hooks" for applying
   policies, and also defining BGP-specific policy features.  The BGP
   policy features are intended to be used with the general routing
   policy model defined in [I-D.shaikh-rtgwg-policy-model]. [I-D.ietf-rtgwg-policy-model].  The model
   also supports operational state data to enable provide a common model for
   reading BGP-related state from a BGP speaker.

   For the base BGP features, the focus of the model described in this
   document is on providing configuration and operational state
   information relating to:

   o  The global BGP instance, and neighbors whose configuration is
      specified individually, or templated with the use of peer-groups.

   o  The address families that are supported by peers, and the global
      configuration which relates to them.

   o  The policy configuration "hooks" and BGP-specific policy features
      that relate to a neighbor - controlling the import and export of
      NLRIs.

   As mentioned earlier, any configuration items that are deemed to be
   widely available in existing major BGP implementations are included
   in the model.  Additional, more esoteric, configuration items that
   are not commonly used, or only available from a single
   implementation, are omitted from the model with an expectation that
   they will be available in companion modules that augment or extend
   the current model.  This allows clarity in identifying data that is
   part of the vendor-neutral base model.

   Where possible, naming in the model follows conventions used in
   available standards documents, and otherwise tries to be self-
   explanatory with sufficient descriptions of the intended behavior.
   Similarly, configuration data value constraints and default values,
   where used, are based on recommendations in current standards
   documentation.
   documentation, or those commonly used in multiple implementations.
   Since implementations can vary widely in this respect, this version
   of the model specifies only a limited set of defaults and ranges with
   the expectation of being more prescriptive in future versions based
   on actual operator use.

2.  Model overview

   The BGP model is defined across several YANG modules and submodules,
   but at a high level is organized into Six six elements:

   o  base protocol configuration -- configuration affecting BGP
      protocol-related operations, defined at various levels of
      hierarchy.

   o  multiprotocol configuration -- configuration affecting individual
      address-families within BGP [RFC4760].

   o  neighbor configuration -- configuration affecting an individual
      neighbor within BGP.

   o  neighbor multiprotocol configuration -- configuration affecting
      individual address-families for a neighbor within BGP.

   o  policy configuration -- hooks for application of the policies
      defined in [I-D.shaikh-rtgwg-policy-model] [I-D.ietf-rtgwg-policy-model] that act on routes sent
      (received) to (from) peers or other routing protocols and BGP-
      specific policy features.

   o  operational state -- variables used for monitoring, management,
      etc. monitoring and management
      of BGP operations.

   These modules also make use of standard Internet types, such as IP
   addresses and prefixes, autonomous system numbers, etc., defined in
   RFC 6991 [RFC6991].

   Throughout the model, the approach described in
   [I-D.openconfig-netmod-opstate] is used to represent configuration
   (intended state), operational and derived state data.  That is to
   say, that each container holds a "config" and "state" sub-container -
   with the config container being used for configurable parameters, and
   the state container container holding representing both the operational state of
   configurable leaves, and derived counters and statistical
   information.

2.1.  BGP protocol configuration

   The BGP protocol configuration model is organized hierarchically,
   much like the majority of router implementations.  That is,
   configuration items can be specified at multiple levels, as shown
   below.

                 +--rw bgp!
                    +--rw global
                    |  +-- (global-configuration-options)
                    +--rw neighbors
                    |  +--rw neighbor* [neighbor-address]
                    |  +-- (neighbor-configuration-options)
                    +--rw peer-groups
                       +--rw peer-group* [peer-group-name]
                       +-- (neighbor-configuration-options)

   Users may specify configuration at a higher level and have it apply
   to all lower-level items, or provide overriding configuration at a
   lower level of the hierarchy.  Overriding configuration items are
   optional, with neighbor specific configuration being the most
   specific or lowest level, followed by peer-group, and finally global.
   Global configuration options reflect a subset of the peer-group or
   neighbor specific configuration options which are relevant to the
   entire BGP instance.

   The model makes the simplifying assumption that most of the
   configuration items are available at all levels of the hierarchy.
   That is, very little configuration is specific to a particular level
   in the hierarchy, other than obvious items such as "group-name" only
   being available for the peer group-level config.  A notable exception
   is for sub-address family configuration where some items are only
   applicable for a given AFI-SAFI combination.

   In order to allow common configuration to be applied to a set of
   neighbors, all neighbor configuration options are available within a
   peer-group.  A neighbor is associated to a particular peer-group
   through the use of a peer-group leaf (which provides a reference to a
   configured item in the peer-group list).

   Address-family configuration is made available in multiple points
   within the model - primarily within the global container, where
   instance-wide configuration can be set (for example, global protocol
   parameters, the BGP best path route selection options, or global
   policies relating to the address-family); and on a per-neighbor or
   per-peer-group basis, where address-families can be enabled or
   disabled, and policy associated with the parent entity applied.
   Within the afi-safi container, generic configuration that applies to
   all address-families (e.g., whether the AFI-SAFI is enabled) is
   presented at the top-level, with address-family specific containers
   made available for options relating to only that AFI-SAFI.  Within
   the current revision of the model a generic set of address-families,
   and common configuration and state options are included - further
   work is expected to add additional parameters to this area of the
   model.

   The following address-families are currently supported by the model:

           +--rw bgp!
             +--rw global
                +--rw afi-safis
                   +--rw afi-safi* [afi-safi-name]
                      +--rw afi-safi-name    -> ../config/afi-safi-name
                      |
                      +--rw ipv4-unicast
                      |     ...
                      +--rw ipv6-unicast
                      |     ...
                      +--rw ipv4-labelled-unicast
                      |     ...
                      +--rw ipv6-labelled-unicast
                      |     ...
                      +--rw l3vpn-ipv4-unicast
                      |     ...
                      +--rw l3vpn-ipv6-unicast
                      |     ...
                      +--rw l3vpn-ipv4-multicast
                      |     ...
                      +--rw l3vpn-ipv6-multicast
                      |     ...
                      +--rw l2vpn-vpls
                      |     ...
                      +--rw l2vpn-evpn
                      |     ...

2.2.  Policy configuration overview

   The BGP policy configuration model references the generic YANG
   routing policy model described in [I-D.shaikh-rtgwg-policy-model], [I-D.ietf-rtgwg-policy-model],
   which represents a condition-action policy framework for routing.

   This model adds BGP-specific conditions (e.g., matching on the
   community attribute), and actions (e.g., setting local preference) to
   the generic policy framework.

   Policies that are defined in the routing-policy model are referenced
   in multiple places within the model:

   o  within the global instance, where a policy applies to all address-
      families for all peers.

   o  on a global AFI-SAFI basis, where policies apply to all peers for
      a particular address-family.

   o  on a per-peer-group or per-neighbor basis - where the policy
      applies to all address-families for the particular parent entity. group or
      neighbor.

   o  on a per-afi-safi basis within a neighbor or peer-group context,
      where the policy is specific to the AFI-SAFI for a a specific
      neighbor or group.

              +--rw bgp
                 +--rw global
                 |  +--rw afi-safi
                 |  |  +--rw afi-safi* [afi-safi-name]
                 |  |     +--rw apply-policy
                 |  +--rw apply-policy
                 +--rw neighbors
                 |  +--rw neighbor* [neighbor-address]
                 |     +--rw afi-safi
                 |     |  +--rw afi-safi* [afi-safi-name]
                 |     |     +--rw apply-policy
                 |     +--rw apply-policy
                 +--rw peer-groups
                    +--rw peer-group* [peer-group-name]
                       +--rw afi-safi
                       |  +--rw afi-safi* [afi-safi-name]
                       |     +--rw apply-policy
                       +--rw apply-policy

2.3.  Operational data state overview

   The BGP operational model contains a set of parameters data which relate relates to the
   operational state of the various elements of the BGP router.  As
   noted in Section 2 - the approach described in
   [I-D.openconfig-netmod-opstate] is utilized for the inclusion of
   operational and statistical data.  To this end, the "_state" "-state"
   groupings (those that contain derived operational parameters) are
   contained within the BGP operational model - and included within the
   relevant "state" containers throughout the core BGP model.  In some
   cases, operational information may be relevant to one instance of a
   common grouping, but not another - for example, the number of
   received, advertised, and installed prefixes is relevant on a per-
   neighbor-basis, but is not required (or meaningful) in the peer-group
   context.  To enable state to be added to particular contexts, the
   tree is augmented through  Groupings are defined with the base BGP module to add these variables,
   without requiring separate groupings. appropriate operational
   state data accordingly.

3.  Relation to other YANG data models

   The BGP model is intended to work within a larger framework model,
   such as the Network Instance model
   [I-D.openconfig-rtgwg-network-instance] which provides a
   comprehensive model for defining VRFs, associated routing protocols,
   multiple protocol instances, and inter-protocol and inter-instance
   routing policies.  The current version of the model imports and
   instantiates the BGP model in its tree at /network-instances/network-
   instance/protocols/protocol/bgp/...

   It is also possible to integrate the BGP model with the Routing
   Management model [I-D.ietf-netmod-routing-cfg] or the Network Device
   Organizational Model [I-D.rtgyangdt-rtgwg-device-model], both of
   which define the notion of routing instances, or VRFs.

   For example, for integration with the Routing Management model, the
   following additions to the BGP model could be made:

   o  a new identity type for BGP that is derived from rt:routing-
      protocol

   o  augmentation of the "/rt:routing/rt:routing-instance/rt:routing-
      protocols/routing-protocol" container with BGP-specific parameters

   o  possible addition of BGP-specific route attributes in
      "/rt:routing-state/rt:ribs/rt:rib/rt:routes/rt:route" and
      "/rt:active-route/rt:output/rt:route"

   Future updates of the BGP model and this document will further
   develop the integration with other framework models related to
   routing protocols.

4.  Security Considerations

   BGP configuration has a significant impact on network operations, and
   as such any related protocol or model carries potential security
   risks.

   YANG data models are generally designed to be used with the NETCONF
   protocol over an SSH transport.  This provides an authenticated and
   secure channel over which to transfer BGP configuration and
   operational data.  Note that use of alternate transport or data
   encoding (e.g., JSON over HTTPS) would require similar mechanisms for
   authenticating and securing access to configuration data.

   Most of the data elements in the configuration model could be
   considered sensitive from a security standpoint.  Unauthorized access
   or invalid data could cause major disruption.

5.  IANA Considerations

   An appropriate namespace URI will be registered in the IETF XML
   Registry" [RFC3688].  The BGP YANG modules will be registered in the
   "YANG Module Names" registry [RFC6020].

6.  YANG modules

   The modules comprising the BGP configuration and operational model
   are described by the YANG modules and submodules in the sections
   below.

   The base
   module imports main module, openconfig-bgp.yang, includes the other modules following
   submodules:

   o  openconfig-bgp-common - defines the groupings that are common
      across more than one context (where contexts are neighbor, group,
      global)

   o  openconfig-bgp-common-multiprotocol - defines the groupings that
      are common across more than one context, and relate to
      multiprotocol BGP

   o  openconfig-bgp-common-structure - defines groupings that are
      shared by multiple contexts, but are used only to create
      structural elements, i.e., containers (leaf nodes are defined in
      separate groupings)

   o  openconfig-bgp-global - groupings with data specific to the overall model.

6.1. global
      context

   o  openconfig-bgp-peer-group - groupings with data specific to the
      peer group context

   o  openconfig-bgp-neighbor - groupings with data specific to the
      neighbor context

   Additional modules include:

   o  openconfig-bgp-types - common type and identity definitions for
      BGP, including BGP policy

   o  openconfig-bgp-policy - BGP-specific policy data definitions for
      use with [I-D.ietf-rtgwg-policy-model] (described in more detail
      Section 2.2)

7.  BGP main module and submodule for base items

<CODE BEGINS> file "ietf-bgp.yang"

module ietf-bgp {

  yang-version "1";
  // namespace
  namespace "urn:ietf:params:xml:ns:yang:ietf-bgp";

  prefix "bgp";

  // import some basic inet types
  import ietf-inet-types { prefix inet; }
     import ietf-bgp-multiprotocol openconfig-extensions { prefix bgp-mp; oc-ext; }
  import ietf-routing-policy { prefix rpol; }
     import ietf-bgp-types { prefix bgp-types; }
     import ietf-bgp-operational { prefix bgp-op; }

  // Include the OpenConfig BGP submodules
  // Common: defines the groupings that are common across more than
  //         one context (where contexts are neighbor, group, global)
  include ietf-bgp-common;
  // Multiprotocol: defines the groupings that are common across more
  //                than one context, and relate to Multiprotocol
  include ietf-bgp-common-multiprotocol;
  // Structure: defines groupings that are shared but are solely used for
  //            structural reasons.
  include ietf-bgp-common-structure;
  // Include peer-group/neighbor/global - these define the groupings
  // that are specific to one context
  include ietf-bgp-peer-group;
  include ietf-bgp-neighbor;
  include ietf-bgp-global;

  // meta
  organization
    "OpenConfig working group";

  contact
    "OpenConfig working group
    netopenconfig@googlegroups.com";

  description
    "This module describes a YANG model for BGP protocol
    configuration.It is a limited subset of all of the configuration
    parameters available in the variety of vendor implementations,
    hence it is expected that it would be augmented with vendor-
    specific configuration data as needed. Additional modules or
    submodules to handle other aspects of BGP configuration,
    including policy, VRFs, VPNs, and additional address families
    are also expected.

    This model supports the following BGP configuration level
    hierarchy:

      BGP
        |
        +-> [ global BGP configuration ]
          +-> AFI / SAFI global
        +-> peer group
          +-> [ peer group config ]
          +-> AFI / SAFI [ per-AFI overrides ]
        +-> neighbor
          +-> [ neighbor config ]
          +-> [ optional pointer to peer-group ]
          +-> AFI / SAFI [ per-AFI overrides ]";

  oc-ext:openconfig-version "2.1.1";

  revision "2016-01-06" "2016-06-21" {
    description
           "Updated filename and namespace";
      "OpenConfig BGP refactor";
    reference "2.1.1";
  }

  revision "2016-06-06" {
    description
      "OpenConfig public release";
    reference "TBD"; "2.1.0";
  }

  revision "2016-03-31" {
    description
      "OpenConfig public release";
    reference "2.0.1";
  }

  grouping bgp-global_config bgp-top {
    description
         "Global configuration options
      "Top-level grouping for the BGP router.";
       leaf as model data";

    container bgp {
         type inet:as-number;
         mandatory "true";
      description
           "Local autonomous system number of the router.  Uses
        "Top-level configuration and state for the 32-bit as-number type from BGP router";

      container global {
        description
          "Global configuration for the model in RFC 6991."; BGP router";
          uses bgp-global-base;
          uses rpol:apply-policy-group;
      }
       leaf router-id

      container neighbors {
         type inet:ipv4-address;
        description
           "Router id of the router, expressed as an
           32-bit value, IPv4 address.";
       }
          "Configuration for BGP neighbors";

        uses bgp-neighbor-list;
      }
     grouping bgp-default-route-distance_config

      container peer-groups {
        description
          "Configuration options relating to the administrative distance
         (or preference) assigned to routes received from different
         sources (external, internal, and local).";
       leaf external-route-distance {
         type uint8 {
           range "1..255";
         }
         description
           "Administrative distance for routes learned from external BGP (eBGP)."; peer-groups";
        uses bgp-peer-group-list;
      }
       leaf internal-route-distance
    }
  }

  uses bgp-top;

}

<CODE ENDS>

   <CODE BEGINS> file "ietf-bgp-common.yang"

   submodule ietf-bgp-common {
         type uint8

     belongs-to ietf-bgp {
           range "1..255";
       prefix "bgp";
     }
         description
           "Administrative distance for routes learned from internal
           BGP (iBGP).";

     import openconfig-extensions { prefix oc-ext; }
     import ietf-bgp-types { prefix oc-bgp-types; }
     grouping bgp-confederation_config
     import ietf-routing-policy { prefix rpol; }
     import ietf-inet-types { prefix inet; }

     // meta
     organization
       "OpenConfig working group";

     contact
       "OpenConfig working group
       netopenconfig@googlegroups.com";

     description
         "Configuration options specifying parameters when the local
         router is
       "This sub-module contains common groupings that are common across
       multiple contexts within an autonomous system which the BGP module. That is part of to say that they
       may be application to a subset of global, peer-group or neighbor
       contexts.";

     oc-ext:openconfig-version "2.1.1";

     revision "2016-06-21" {
       description
         "OpenConfig BGP
         confederation.";
       leaf enabled refactor";
       reference "2.1.1";
     }

     grouping bgp-common-neighbor-group-timers-config {
         type boolean;
       description
           "When this leaf is set
         "Config parameters related to true it indicates that timers associated with the local-AS is part of a BGP confederation";
       }
         peer";

       leaf identifier connect-retry {
         type inet:as-number; decimal64 {
           fraction-digits 2;
         }
         default 30;
         description
           "Confederation identifier for
           "Time interval in seconds between attempts to establish a
           session with the autonomous system."; peer.";
       }
       leaf-list member-as

       leaf hold-time {
         type inet:as-number; decimal64 {
           fraction-digits 2;
         }
         default 90;
         description
           "Remote autonomous systems
           "Time interval in seconds that are to a BGP session will be treated
           as part
           considered active in the absence of keepalive or other
           messages from the local confederation."; peer.  The hold-time is typically
           set to 3x the keepalive-interval.";
         reference
           "RFC 4271 - A Border Gateway Protocol 4, Sec. 10";
       }

       leaf keepalive-interval {
         type decimal64 {
           fraction-digits 2;
         }
         default 30;
         description
           "Time interval in seconds between transmission of keepalive
           messages to the neighbor.  Typically set to 1/3 the
           hold-time.";
       }

       leaf minimum-advertisement-interval {
         type decimal64 {
           fraction-digits 2;

         }
         default 30;
         description
           "Minimum time which must elapse between subsequent UPDATE
           messages relating to a common set of NLRI being transmitted
           to a peer. This timer is referred to as
           MinRouteAdvertisementIntervalTimer by RFC 4721 and serves to
           reduce the number of UPDATE messages transmitted when a
           particular set of NLRI exhibit instability.";
         reference
           "RFC 4271 - A Border Gateway Protocol 4, Sec 9.2.1.1";
       }
     }

     grouping bgp-neighbor_config bgp-common-neighbor-group-config {
       description
         "Neighbor level configuration items.";

       leaf peer-as {
         type inet:as-number;
         description
           "AS number of the peer.";
       }

       leaf local-as {
         type inet:as-number;
         description
           "The local autonomous system number that is to be used
           when establishing sessions with the remote peer or peer
           group, if this differs from the global BGP router
           autonomous system number.";
       }

       leaf peer-type {
           type bgp-types:peer-type; oc-bgp-types:peer-type;
           description
             "Explicitly designate the peer or peer group as internal
             (iBGP) or external (eBGP).";
       }

       leaf auth-password {
         type string;
         description
           "Configures an MD5 authentication password for use with
           neighboring devices.";
       }

       leaf remove-private-as {
         // could also make this a container with a flag to enable
         // remove-private and separate option.  here, option implies
         // remove-private is enabled.
         type bgp-types:remove-private-as-option; oc-bgp-types:remove-private-as-option;
         description
           "Remove private AS numbers from updates sent to peers."; peers - when
           this leaf is not specified, the AS_PATH attribute should be
           sent to the peer unchanged";
       }

       leaf route-flap-damping {
         type boolean;
         default false;
         description
           "Enable route flap damping.";
       }

       leaf send-community {
         type bgp-types:community-type; oc-bgp-types:community-type;
         default "NONE";
         description
           "Specify which types of community should be sent to the
           neighbor or group. The default is to not send the
           community attribute";
       }

       leaf description {
         type string;
         description
           "An optional textual description (intended primarily for use
           with a peer or group";
       }
     }

     grouping bgp-neighbor-timers_config bgp-common-neighbor-group-transport-config {
       description
         "Config
         "Configuration parameters related relating to timers associated with the transport protocol
         used by the BGP session to the peer";

       leaf connect-retry tcp-mss {
         type decimal64 uint16;
         description
           "Sets the max segment size for BGP TCP sessions.";
       }

       leaf mtu-discovery {
           fraction-digits 2;
         type boolean;
         default false;
         description
           "Turns path mtu discovery for BGP TCP sessions on (true)
           or off (false)";
       }

       leaf passive-mode {
         type boolean;
         default 30; false;
         description
           "Time interval in seconds between attempts
           "Wait for peers to establish issue requests to open a
           session with BGP session,
           rather than initiating sessions from the peer."; local router.";
       }

       leaf hold-time local-address {
         type decimal64 union {
           fraction-digits 2;
         }
         default 90;
         description
           "Time interval in seconds that a BGP session will be
           considered active in the absence of keepalive or other
           messages from the peer.  The hold-time is typically
           set to 3x the keepalive-interval.";
         reference
           "RFC 4271 - A Border Gateway Protocol 4, Sec. 10";
       }
       leaf keepalive-interval {
         type decimal64 {
           fraction-digits 2;
         }
         default 30;
         description
           "Time interval in seconds between transmission of keepalive
           messages to the neighbor.  Typically set to 1/3 the
           hold-time.";
       }
       leaf minimum-advertisement-interval {
         type decimal64 {
           fraction-digits 2;
         }
         default 30;
         description
           "Minimum time which must elapse between subsequent UPDATE
           messages relating to a common set of NLRI being transmitted
           to a peer. This timer is referred to as
           MinRouteAdvertisementIntervalTimer by RFC 4721 and serves to
           reduce the number of UPDATE messages transmitted when a
           particular set of NLRI exhibit instability.";
         reference
           "RFC 4271 - A Border Gateway Protocol 4, Sec 9.2.1.1";
       }
     }
     grouping bgp-neighbor-transport_config {
       description
         "Configuration parameters relating to the transport protocol
         used by the BGP session to the peer";
       leaf tcp-mss {
         type uint16;
         description
           "Sets the max segment size for BGP TCP sessions.";
       }
       leaf mtu-discovery {
         type boolean;
         default false;
         description
           "Turns path mtu discovery for BGP TCP sessions on (true)
           or off (false)";
       }
       leaf passive-mode {
         type boolean;
         default false;
         description
           "Wait for peers to issue requests to open a BGP session,
           rather than initiating sessions from the local router.";
       }
       leaf local-address {
         type union {
           type inet:ip-address;
           type string;
           type inet:ip-address;
           type string;
         }
         //TODO:  the string should be converted to a leafref type
         //to point to an interface when YANG 1.1 is available with
         //leafrefs in union types.
         description
           "Set the local IP (either IPv4 or IPv6) address to use
           for the session when sending BGP update messages.  This
           may be expressed as either an IP address or reference
           to the name of an interface.";
       }
     }

     grouping bgp-neighbor-error-handling_config bgp-common-neighbor-group-error-handling-config {
       description
         "Configuration parameters relating to enhanced error handling
         behaviours for BGP";

       leaf treat-as-withdraw {
         type boolean;
         default "false";
         description
           "Specify whether erroneous UPDATE messages for which the
           NLRI can be extracted are reated as though the NLRI is
           withdrawn - avoiding session reset";
         reference "draft-ietf-idr-error-handling-16";
       }
     }

     grouping bgp-neighbor-logging-options_config bgp-common-neighbor-group-logging-options-config {
       description
         "Configuration parameters specifying the logging behaviour for
         BGP sessions to the peer";

       leaf log-neighbor-state-changes {
         type boolean;
         default "true";
         description
           "Configure logging of peer state changes.  Default is
           to enable logging of peer state changes.";
       }
     }

     grouping bgp-neighbor-multihop_config bgp-common-neighbor-group-multihop-config {
       description
         "Configuration parameters specifying the multihop behaviour for
         BGP sessions to the peer";

       leaf enabled {
         type boolean;
         default "false";
         description
           "When enabled the referenced group or neighbors are permitted
           to be indirectly connected - including cases where the TTL
           can be decremented between the BGP peers";
       }

       leaf multihop-ttl {
         type uint8;
         description
           "Time-to-live value to use when packets are sent to the
           referenced group or neighbors and ebgp-multihop is enabled";
       }
     }

     grouping bgp-neighbor-route-reflector_config bgp-common-neighbor-group-route-reflector-config {
       description
         "Configuration parameters determining whether the behaviour of
         the local system when acting as a route-reflector";

       leaf route-reflector-cluster-id {
         type bgp-types:rr-cluster-id-type; oc-bgp-types:rr-cluster-id-type;
         description
           "route-reflector cluster id to use when local router is
           configured as a route reflector.  Commonly set at the group
           level, but allows a different cluster
           id to be set for each neighbor.";
       }

       leaf route-reflector-client {
         type boolean;
         default "false";
         description
           "Configure the neighbor as a route reflector client.";
       }
     }

     grouping bgp-neighbor-as-path-options_config bgp-common-neighbor-group-as-path-options-config {
       description
         "Configuration parameters allowing manipulation of the AS_PATH
         attribute";

       leaf allow-own-as {
         type uint8;
         default 0;
         description
           "Specify the number of occurrences of the local BGP speaker's
           AS that can occur within the AS_PATH before it is rejected.";
       }

       leaf replace-peer-as {
         type boolean;
         default "false";
         description
           "Replace occurrences of the peer's AS in the AS_PATH
           with the local autonomous system number";
       }
     }

     grouping bgp-neighbor-add-paths_config bgp-common-neighbor-group-add-paths-config {
       description
         "Configuration parameters specfying whether the local system
         will send or receive multiple paths using ADD_PATHS";

       leaf receive {
         type boolean;
         default false;
         description
           "Enable ability to receive multiple path advertisements
           for an NLRI from the neighbor or group";
       }

       leaf send-max {
         type uint8;
         description
           "The maximum number of paths to advertise to neighbors
           for a single NLRI";
       }
     }
     grouping bgp-neighbor-peer-group_config
       leaf eligible-prefix-policy {
         type leafref {
           path "/rpol:routing-policy/rpol:policy-definitions/" +
             "rpol:policy-definition/rpol:name";
         }
         description
         "Configuration parameters indicating whether the specified peer
         is
           "A reference to be considered as part of a peer-group - and therefore
         inherit its configuration";
       leaf peer-group {
         type leafref {
           // we are at /bgp/neighbors/neighbor/
           path "/bgp/peer-groups/peer-group/peer-group-name";
           require-instance true;
         }
         description
           "The peer-group with which this neighbor is associated";
       }
     }
     grouping bgp-graceful-restart {
       description
         "Configures BGP graceful restart, routing policy which is a negotiated
         option that indicates that a BGP speaker is able can be used to retain
         forwarding state when a BGP session restarts";
       reference "RFC 4724: Graceful Restart Mechanism for BGP";
       container graceful-restart {
         description
           "Parameters relating
           restrict the graceful restart mechanism prefixes for BGP";
         container config {
           description
             "Configuration parameters relating to graceful-restart";
           uses bgp-neighbor-graceful-restart_config;
         }
         container state {
           config false;
           description
             "State information associated with graceful-restart";
           uses bgp-neighbor-graceful-restart_config;
         } which add-paths is enabled";
       }
     }

     grouping bgp-neighbor-graceful-restart_config bgp-common-graceful-restart-config {
       description
         "Configuration parameters relating to BGP graceful restart.";

       leaf enabled {
         type boolean;
         description
           "Enable or disable the graceful-restart capability.";
       }

       leaf restart-time {
         type uint16 {
           range 0..4096;
         }
         description
           "Estimated time (in seconds) for the local BGP speaker to
           restart a session. This value is advertise in the graceful
           restart BGP capability.  This is a 12-bit value, referred to
           as Restart Time in RFC4724.  Per RFC4724, the suggested
           default value is <= the hold-time value.";
       }

       leaf stale-routes-time {
         type decimal64 {
           fraction-digits 2;
         }
         description
           "An upper-bound on the time thate stale routes will be
           retained by a router after a session is restarted. If an
           End-of-RIB (EOR) marker is received prior to this timer
           expiring stale-routes will be flushed upon its receipt - if
           no EOR is received, then when this timer expires stale paths
           will be purged. This timer is referred to as the
           Selection_Deferral_Timer in RFC4724";
       }

       leaf helper-only {
         type boolean;
         description
           "Enable graceful-restart in helper mode only. When this
           leaf is set, the local system does not retain forwarding
           its own state during a restart, but supports procedures
           for the receiving speaker, as defined in RFC4724.";
       }
     }
     // ************************************************************
     // *              configuration context containers            *
     // ************************************************************

     grouping bgp-global-base bgp-common-use-multiple-paths-config {
       description
         "Global
         "Generic configuration parameters for the BGP router";
       container config {
         description
           "Configuration parameters options relating to the global BGP router";
         uses bgp-global_config;
       }
       container state use of multiple
         paths for a referenced AFI-SAFI, group or neighbor";

       leaf enabled {
         config
         type boolean;
         default false;
         description
           "State information relating to
           "Whether the global BGP router";
         uses bgp-global_config;
         uses bgp-op:bgp-global_state; use of multiple paths for the same NLRI is
           enabled for the neighbor. This value is overridden by
           any more specific configuration value.";
       }
       uses bgp-mp:bgp-route-selection-options;
       container default-route-distance {
         description
           "Administrative distance (or preference) assigned to
           routes received from different sources
           (external, internal, and local).";
         container config
     }

     grouping bgp-common-use-multiple-paths-ebgp-as-options-config {
       description
         "Configuration parameters relating specific to the default route
             distance";
           uses bgp-default-route-distance_config;

         }
         container state eBGP multipath applicable
         to all contexts";

       leaf allow-multiple-as {
           config false;
        type boolean;
        default "false";
        description
             "State information relating
         "Allow multipath to the use paths from different neighbouring
         ASes.  The default route distance";
           uses bgp-default-route-distance_config; is to only consider multiple paths from
         the same neighbouring AS.";
       }
     }

     grouping bgp-common-global-group-use-multiple-paths {
       description
         "Common grouping used for both global and groups which provides
         configuration and state parameters relating to use of multiple
         paths";

       container confederation use-multiple-paths {
         description
           "Parameters indicating whether related to the local system acts as part use of a BGP confederation"; multiple paths for the
           same NLRI";

         container config {
           description
             "Configuration parameters relating to BGP confederations"; multipath";
           uses bgp-confederation_config; bgp-common-use-multiple-paths-config;
         }
         container state {
           config false;
           description
             "State information parameters relating to the BGP confederations"; multipath";
           uses bgp-confederation_config;
         } bgp-common-use-multiple-paths-config;
         }
       uses bgp-mp:bgp-use-multiple-paths;
       uses bgp-graceful-restart;

         container afi-safis {
         description
           "Address family specific configuration";
         uses bgp-mp:bgp-common-afi-safi-list;
       }
     }
     grouping bgp-neighbors {
       description
         "BGP neighbors configured on the local system";
       list neighbor {
         key "neighbor-address";
         description
           "List of BGP neighbors configured on the local system,
           uniquely identified by peer IPv[46] address";
         leaf neighbor-address {
           type leafref {
             path "../config/neighbor-address";
           }
           description
             "Reference to the address of the BGP neighbor used as
             a key in the neighbor list";
         }
         uses bgp-neighbor-group;
       }
     }
     grouping bgp-peer-group {
       description
         "BGP peer-groups configured on the local system";
       list peer-group {
         key "peer-group-name";
         description
           "List of BGP peer-groups configured on the local system -
           uniquely identified by peer-group name";
       leaf peer-group-name {
         type leafref {
           path "../config/peer-group-name";
         }
         description
           "Reference to the name of the BGP peer-group used as a
           key in the peer-group list";
         }
         uses bgp-neighbor-group;
       }
     }
     grouping bgp-neighbor-group ebgp {
           description
         "Parameters related to a BGP neighbor or group";
             "Multipath parameters for eBGP";
           container config {
             description
               "Configuration parameters relating to the BGP neighbor or
           group"; eBGP multipath";
             uses bgp-neighbor_config; bgp-common-use-multiple-paths-ebgp-config;
           }
           container state {
             config false;
             description
               "State information relating to the BGP neighbor or group"; eBGP multipath";
             uses bgp-neighbor_config; bgp-common-use-multiple-paths-ebgp-config;
           }
         }

         container timers ibgp {
           description
           "Timers related to a BGP neighbor or group";
             "Multipath parameters for iBGP";
           container config {
             description
               "Configuration parameters relating to timers used for the
             BGP neighbor or group"; iBGP multipath";
             uses bgp-neighbor-timers_config; bgp-common-use-multiple-paths-ibgp-config;
           }
           container state {
             config false;
             description
               "State information relating to the timers used for the BGP
             neighbor or group"; iBGP multipath";
             uses bgp-neighbor-timers_config; bgp-common-use-multiple-paths-ibgp-config;
           }
         }
       container transport {
         description
           "Transport session parameters for the BGP neighbor or group";
         container config
       }
     }
     grouping bgp-common-use-multiple-paths-ebgp-config {
       description
         "Configuration parameters relating to the transport
             session(s) used multipath for the BGP neighbor or group";
           uses bgp-neighbor-transport_config;
         }
         container state eBGP";

       leaf allow-multiple-as {
           config false;
        type boolean;
        default "false";
        description
             "State information relating
         "Allow multipath to use paths from different neighbouring
         ASes.  The default is to only consider multiple paths from
         the transport session(s)
             used for the BGP neighbor or group";
           uses bgp-neighbor-transport_config;
         } same neighbouring AS.";
       }
       container error-handling

       leaf maximum-paths {
        type uint32;
        default 1;
        description
           "Error handling parameters used for the
         "Maximum number of parallel paths to consider when using
         BGP neighbor or
           group";
         container config multipath. The default is use a single path.";
       }
     }

     grouping bgp-common-use-multiple-paths-ibgp-config {
       description
         "Configuration parameters enabling or modifying the
             behavior or enhanced error handling mechanisms parmaeters relating to multipath for the BGP
             neighbor or group";
           uses bgp-neighbor-error-handling_config;
         }
         container state iBGP";

       leaf maximum-paths {
           config false;
         type uint32;
         default 1;
         description
             "State information relating
           "Maximum number of parallel paths to enhanced error handling
             mechanisms for the BGP neighbor or group";
           uses bgp-neighbor-error-handling_config; consider when using
           iBGP multipath. The default is to use a single path";
       }
     }
       container logging-options

     grouping bgp-common-route-selection-options-config {
       description
           "Logging
         "Set of configuration options for events related to the BGP neighbor or
           group";
         container config that govern best
          path selection.";

       leaf always-compare-med {
         type boolean;
         default "false";
         description
             "Configuration parameters enabling or modifying logging
             for events relating
           "Compare multi-exit discriminator (MED) value from
           different ASes when selecting the best route.  The
           default behavior is to only compare MEDs for paths
           received from the BGP neighbor or group";
           uses bgp-neighbor-logging-options_config; same AS.";

       }
         container state

       leaf ignore-as-path-length {
           config false;
         type boolean;
         default "false";
         description
             "State information relating
           "Ignore the AS path length when selecting the best path.
           The default is to logging for use the BGP neighbor
             or group";
           uses bgp-neighbor-logging-options_config;
         } AS path length and prefer paths
           with shorter length.";
       }
       container ebgp-multihop

       leaf external-compare-router-id {
         type boolean;
         default "true";
         description
           "eBGP multi-hop parameters for the
           "When comparing similar routes received from external
           BGP neighbor or group";
         container config peers, use the router-id as a criterion to select
           the active path.";
       }

       leaf advertise-inactive-routes {
         type boolean;
         default "false";
         description
             "Configuration parameters relating
           "Advertise inactive routes to eBGP multihop for the
             BGP neighbor or group";
           uses bgp-neighbor-multihop_config; external peers.  The
           default is to only advertise active routes.";
       }
         container state

       leaf enable-aigp {
           config
         type boolean;
         default false;
         description
             "State information for eBGP multihop, for the BGP neighbor
             or group";
           uses bgp-neighbor-multihop_config;
         }
           "Flag to enable sending / receiving accumulated IGP
           attribute in routing updates";
       }
       container route-reflector

       leaf ignore-next-hop-igp-metric {
         type boolean;
         default "false";
         description
           "Route reflector parameters for
           "Ignore the IGP metric to the next-hop when calculating
           BGP neighbor or group";
         container config {
           description
             "Configuraton parameters relating best-path. The default is to select the route reflection for
           which the BGP neighbor or group";
           uses bgp-neighbor-route-reflector_config; metric to the next-hop is lowest";
       }
         container state
     }

     grouping bgp-common-route-selection-options {
           config false;
       description
             "State information
         "Configuration and state relating to route reflection for the
             BGP neighbor or group";
           uses bgp-neighbor-route-reflector_config;
         }
       } selection options";

       container as-path-options route-selection-options {
         description
           "AS_PATH manipulation parameters
           "Parameters relating to options for the BGP neighbor or
           group"; route selection";
         container config {
           description
             "Configuration parameters relating to AS_PATH manipulation
             for the BGP peer or group"; route selection
             options";
           uses bgp-neighbor-as-path-options_config; bgp-common-route-selection-options-config;
         }
         container state {
           config false;
           description
             "State information relating to the AS_PATH manipulation
             mechanisms for the BGP peer or group";
           uses bgp-neighbor-as-path-options_config; route selection options";
           uses bgp-common-route-selection-options-config;
         }
       }
       container add-paths
     }

     grouping bgp-common-state {
       description
           "Parameters
         "Grouping containing common counters relating to the advertisement prefixes and receipt
         paths";

       leaf total-paths {
         type uint32;
         description
           "Total number of
           multiple BGP paths for a single NLRI (add-paths)";
         container config within the context";
       }

       leaf total-prefixes {
         type uint32;
         description
             "Configuration parameters relating to ADD_PATHS";
           uses bgp-neighbor-add-paths_config;
           "Total number of BGP prefixes received within the context";
       }
         container state
     }

   }

   <CODE ENDS>

   <CODE BEGINS> file "ietf-bgp-common-multiprotocol.yang"

   submodule ietf-bgp-common-multiprotocol {
           config false;
           description
             "State information associated with ADD_PATHS";
           uses bgp-neighbor-add-paths_config;
     belongs-to ietf-bgp {
       prefix "bgp";
     }

     import openconfig-extensions { prefix oc-ext; }
       container afi-safis
     import ietf-bgp-types {
         description
           "Per-address-family configuration parameters associated with
           the neighbor or group";
         uses bgp-mp:bgp-common-afi-safi-list; prefix oc-bgp-types; }
       uses bgp-graceful-restart;
       uses rpol:apply-policy-group;
     import ietf-routing-policy { prefix rpol; }
     grouping bgp-neighbor-neighbor-address_config
     import openconfig-types { prefix oc-types; }

     include ietf-bgp-common;

     // meta
     organization
       "OpenConfig working group";

     contact
       "OpenConfig working group
       netopenconfig@googlegroups.com";

     description
         "Configuration options relating
       "This sub-module contains groupings that are related to the support
       for multiple protocols in BGP. The groupings are common across
       multiple contexts.";

     oc-ext:openconfig-version "2.1.1";

     revision "2016-06-21" {
       description
         "OpenConfig BGP neighbor address"; refactor";
       reference "2.1.1";
     }

     grouping bgp-common-mp-afi-safi-graceful-restart-config {
       description
         "BGP graceful restart parameters that apply on a per-AFI-SAFI
         basis";

       leaf neighbor-address enabled {
         type inet:ip-address; boolean;
         default false;
         description
             "Address of the BGP peer, either in IPv4 or IPv6";
           "This leaf indicates whether graceful-restart is enabled for
           this AFI-SAFI";
       }
     }

     grouping bgp-peer-group-peer-group-name_config bgp-common-mp-afi-safi-config {
       description
         "Configuration options relating to the parameters used for all BGP peer-group name"; AFI-SAFIs";

       leaf peer-group-name afi-safi-name {
         type string; identityref {
           base oc-bgp-types:AFI_SAFI_TYPE;
         }
         description
           "Name of "AFI,SAFI";
       }

       leaf enabled {
         type boolean;
         default false;
         description
           "This leaf indicates whether the BGP peer-group"; IPv4 Unicast AFI,SAFI is
           enabled for the neighbour or group";
       }
     }
     // add peer-group pointer only

     grouping bgp-common-mp-all-afi-safi-list-contents {
       description
         "A common grouping used for contents of the neighbor list
     augment /bgp/neighbors/neighbor/config {
       description
         "Augmentation to allow association of a neighbor with a
         peer-group";
       uses bgp-neighbor-peer-group_config;
     }
     augment /bgp/neighbors/neighbor/state {
       description
         "Augmentation to reflect that is used
         for AFI-SAFI entries";

       // import and export policy included for the association of a neighbor with a
         peer-group"; afi/safi
       uses rpol:apply-policy-group;

       uses bgp-common-mp-ipv4-unicast-group;
       uses bgp-common-mp-ipv6-unicast-group;
       uses bgp-common-mp-ipv4-labeled-unicast-group;
       uses bgp-common-mp-ipv6-labeled-unicast-group;
       uses bgp-neighbor-peer-group_config; bgp-common-mp-l3vpn-ipv4-unicast-group;
       uses bgp-common-mp-l3vpn-ipv6-unicast-group;
       uses bgp-common-mp-l3vpn-ipv4-multicast-group;
       uses bgp-common-mp-l3vpn-ipv6-multicast-group;
       uses bgp-common-mp-l2vpn-vpls-group;
       uses bgp-common-mp-l2vpn-evpn-group;
     }
     augment /bgp/peer-groups/peer-group

     // Groupings relating to each address family
     grouping bgp-common-mp-ipv4-unicast-group {
       description
         "Augmentation to add multipath
         "Group for IPv4 Unicast configuration to a peer-group";
       uses bgp-mp:bgp-use-multiple-paths;
     }
     augment /bgp/neighbors/neighbor options";

       container ipv4-unicast {
         when "../afi-safi-name = 'oc-bgp-types:IPV4_UNICAST'" {
           description
         "Augmentation to add the multipath configuration to a
         neighbor";
       uses bgp-mp:bgp-use-multiple-paths-neighbor;
             "Include this container for IPv4 Unicast specific
             configuration";

         }
     augment /bgp/peer-groups/peer-group/afi-safis/afi-safi {

         description
         "Augmentation to add multipath "IPv4 unicast configuration to a peer-group
         on a per-AFI-SAFI basis"; options";

         // include common IPv[46] unicast options
         uses bgp-mp:bgp-use-multiple-paths; bgp-common-mp-ipv4-ipv6-unicast-common;

         // placeholder for IPv4 unicast  specific configuration
       }
     augment /bgp/neighbors/neighbor/afi-safis/afi-safi
     }

     grouping bgp-common-mp-ipv6-unicast-group {
       description
         "Augmentation to add multipath
         "Group for IPv6 Unicast configuration to a neighbor
         on a per-AFI-SAFI basis";
       uses bgp-mp:bgp-use-multiple-paths-neighbor;
     }
     augment /bgp/global/afi-safis/afi-safi options";

       container ipv6-unicast {
         when "../afi-safi-name = 'oc-bgp-types:IPV6_UNICAST'" {
           description
         "Augmentation to add global instance
             "Include this container for IPv6 Unicast specific AFI-SAFI
         configuration information";
       uses bgp-mp:bgp-global-afi-safi;
       uses bgp-mp:bgp-use-multiple-paths;
             configuration";
         }
     augment /bgp/peer-groups/peer-group/afi-safis/afi-safi {

         description
         "Augmentation that adds peer-group instance specific
         AFI-SAFI "IPv6 unicast configuration information"; options";

         // include common IPv[46] unicast options
         uses bgp-mp:bgp-group-afi-safi; bgp-common-mp-ipv4-ipv6-unicast-common;

         // placeholder for IPv6 unicast specific configuration
         // options
       }
     augment /bgp/neighbors/neighbor/config
     }

     grouping bgp-common-mp-ipv4-labeled-unicast-group {
       description
         "Augmentation adding the neighbor address to the
         neighbor
         "Group for IPv4 Labeled Unicast configuration container";
       uses bgp-neighbor-neighbor-address_config;
     }
     augment /bgp/neighbors/neighbor/state options";

       container ipv4-labeled-unicast {
         when "../afi-safi-name = 'oc-bgp-types:IPV4_LABELED_UNICAST'" {
           description
         "Augmentation adding the neighbor address to the
         neighbor state container";
       uses bgp-neighbor-neighbor-address_config;
             "Include this container for IPv4 Labeled Unicast specific
             configuration";
         }
     augment /bgp/peer-groups/peer-group/config {

         description
         "Augmentation adding the peer-group name to the
         peer-group "IPv4 Labeled Unicast configuration container"; options";

         uses bgp-peer-group-peer-group-name_config; bgp-common-mp-all-afi-safi-common;

         // placeholder for IPv4 Labeled Unicast specific config
         // options
       }
     augment /bgp/peer-groups/peer-group/state
     }

     grouping bgp-common-mp-ipv6-labeled-unicast-group {
       description
         "Augmentation adding the peer-group name to the
         peer-group state container";
       uses bgp-peer-group-peer-group-name_config;
     }
     // ************************************************************
     // *              Augmentations to add state                  *
     // *  (rjs: cleaner to have these in the base module to avoid *
     //     needing to specify which module - e.g. augment of      *
     //     /bgp:bgp/bgp:neighbors/bgp:neighbor...)                *
     // ************************************************************
     augment /bgp/neighbors/neighbor/state
         "Group for IPv6 Labeled Unicast configuration options";

       container ipv6-labeled-unicast {
         when "../afi-safi-name = 'oc-bgp-types:IPV6_LABELED_UNICAST'" {
           description
         "Augmentation to add operational state related to a particular
         BGP neighbor";
             "Include this container for IPv6 Labeled Unicast specific
             configuration";
         }

         description "IPv6 Labeled Unicast configuration options";

         uses bgp-op:bgp-neighbor_state; bgp-common-mp-all-afi-safi-common;

         // placeholder for IPv6 Labeled Unicast specific config
         // options.
       }
     augment /bgp/neighbors/bgp:neighbor/state
     }

     grouping bgp-common-mp-l3vpn-ipv4-unicast-group {
       description
         "Augmentation to add operational state related to a particular
         BGP neighbor";
         "Group for IPv4 Unicast L3VPN configuration options";

       container messages l3vpn-ipv4-unicast {
         when "../afi-safi-name = 'oc-bgp-types:L3VPN_IPV4_UNICAST'" {
           description
           "Counters for BGP messages sent and received from the
           neighbor";
             "Include this container sent { for IPv4 Unicast L3VPN specific
             configuration";
         }

         description
             "Counters relating to BGP messages sent to the neighbor"; "Unicast IPv4 L3VPN configuration options";

         // include common L3VPN configuration options
         uses bgp-op:bgp-neighbor-message-counters-sent_state; bgp-common-mp-l3vpn-ipv4-ipv6-unicast-common;

         // placeholder for IPv4 Unicast L3VPN specific config options.
       }
         container received
     }

     grouping bgp-common-mp-l3vpn-ipv6-unicast-group {
       description
             "Counters
         "Group for BGP messages received from the neighbor";
           uses bgp-op:bgp-neighbor-message-counters-received_state;
         }
       } IPv6 Unicast L3VPN configuration options";

       container queues l3vpn-ipv6-unicast {
         description
           "Counters related to queued messages associated with the
           BGP neighbor";
         uses bgp-op:bgp-neighbor-queue-counters_state;
       }
     }
     augment /bgp:bgp/bgp:neighbors/neighbor/timers/state
         when "../afi-safi-name = 'oc-bgp-types:L3VPN_IPV6_UNICAST'" {
           description
         "Augmentation to add the operational state of timers associated
         with the BGP neighbor";
       uses bgp-op:bgp-neighbor-timers_state;
             "Include this container for unicast IPv6 L3VPN specific
             configuration";
         }
     augment /bgp/neighbors/neighbor/transport/state {

         description
         "Augmentation to add the operational state of the transport
         session associated with the BGP neighbor"; "Unicast IPv6 L3VPN configuration options";

         // include common L3VPN configuration options
         uses bgp-op:bgp-neighbor-transport_state; bgp-common-mp-l3vpn-ipv4-ipv6-unicast-common;

         // placeholder for IPv6 Unicast L3VPN specific configuration
         // options
       }
     augment /bgp/neighbors/neighbor/error-handling/state
     }

     grouping bgp-common-mp-l3vpn-ipv4-multicast-group {
       description
         "Augmentation to add the operational state of the error
         handling associated with the BGP neighbor";
       uses bgp-op:bgp-neighbor-error-handling_state;
     }
     augment /bgp/neighbors/neighbor/graceful-restart/state
         "Group for IPv4 L3VPN multicast configuration options";

       container l3vpn-ipv4-multicast {
       description
         "Augmentation to add the operational state of graceful-restart
         associated with a BGP neighbor";

       uses bgp-op:bgp-afi-safi-graceful-restart_state;
     }
     augment /bgp/peer-groups/peer-group/state
         when "../afi-safi-name = 'oc-bgp-types:L3VPN_IPV4_MULTICAST'" {
           description
         "Augmentation to add the operational state and counters
         relating to a BGP peer-group";
       uses bgp-op:bgp-peer-group_state;
             "Include this container for multicast IPv6 L3VPN specific
             configuration";
         }
     augment /bgp/global/afi-safis/afi-safi/state {

         description
         "Augmentation to add operational state and counters
         on a per-AFI-SAFI basis to the global BGP router"; "Multicast IPv4 L3VPN configuration options";

         // include common L3VPN multicast options
         uses bgp-op:bgp-global-afi-safi_state; bgp-common-mp-l3vpn-ipv4-ipv6-multicast-common;

         // placeholder for IPv4 Multicast L3VPN specific configuration
         // options
       }
     augment /bgp/neighbors/neighbor/afi-safis/afi-safi/state
     }

     grouping bgp-common-mp-l3vpn-ipv6-multicast-group {
       description
         "Augmentation to add per-AFI-SAFI operational state
         and counters to the BGP neighbor";
       uses bgp-op:bgp-neighbor-afi-safi_state;
     }
     augment "/bgp/neighbors/neighbor/afi-safis/afi-safi/" +
       "graceful-restart/state"
         "Group for IPv6 L3VPN multicast configuration options";

       container l3vpn-ipv6-multicast {
         when "../afi-safi-name = 'oc-bgp-types:L3VPN_IPV6_MULTICAST'" {
           description
         "Augmentation to add per-AFI-SAFI operational state
             "Include this container for BGP
         graceful-restart";
       uses bgp-op:bgp-neighbor-afi-safi-graceful-restart_state; multicast IPv6 L3VPN specific
             configuration";
         }
         description "Multicast IPv6 L3VPN configuration options";

         // ************************************************************ include common L3VPN multicast options
         uses bgp-common-mp-l3vpn-ipv4-ipv6-multicast-common;

         // *              module structure containers                 * placeholder for IPv6 Multicast L3VPN specific configuration
         // ************************************************************
     container bgp options
       }
     }

     grouping bgp-common-mp-l2vpn-vpls-group {
       presence "Container for BGP protocol hierarchy";
       description
         "Top-level configuration and state
         "Group for the BGP router"; BGP-signalled VPLS configuration options";

       container global l2vpn-vpls {
         when "../afi-safi-name = 'oc-bgp-types:L2VPN_VPLS'" {
           description
           "Global configuration
             "Include this container for the BGP router";
           uses bgp-global-base; BGP-signalled VPLS specific
             configuration";
         }

         description "BGP-signalled VPLS configuration options";

         // include common L2VPN options
         uses rpol:apply-policy-group; bgp-common-mp-l2vpn-common;

         // placeholder for BGP-signalled VPLS specific configuration
         // options
       }
       container neighbors
     }

     grouping bgp-common-mp-l2vpn-evpn-group {
       description
           "Configuration
         "Group for BGP neighbors";
         uses bgp-neighbors;
       } EVPN configuration options";

       container peer-groups l2vpn-evpn {
         when "../afi-safi-name = 'oc-bgp-types:L2VPN_EVPN'" {
           description
           "Configuration
             "Include this container for BGP peer-groups";

         uses bgp-peer-group;
       }
     } EVPN specific
             configuration";
         }
   <CODE ENDS>

6.2.

         description "BGP EVPN configuration options";

         // include common L2VPN options
         uses bgp-common-mp-l2vpn-common;

         // placeholder for BGP base types

   <CODE BEGINS> file "ietf-bgp-types.yang"
   module ietf-bgp-types {
       yang-version "1";
       namespace "urn:ietf:params:xml:ns:yang:ietf-bgp-types";
       prefix "bgp-types";
       import ietf-inet-types { prefix inet; EVPN specific configuration options

       }
     }

     // meta
       organization
       "OpenConfig working group";
     contact
       "OpenConfig working group
       netopenconfig@googlegroups.com"; Common groupings across multiple AFI,SAFIs
     grouping bgp-common-mp-all-afi-safi-common {
       description
       "This module contains general data definitions
         "Grouping for use in BGP
       policy. It can be imported by modules that make use of BGP
       attributes";
     revision "2016-01-06" configuration common to all AFI,SAFI";

       container prefix-limit {
         description
         "Updated filename and namespace";
       reference "TBD";
     }
     identity bgp-capability
           "Configure the maximum number of prefixes that will be
           accepted from a peer";

         container config {
           description "Base identity
             "Configuration parameters relating to the prefix
             limit for a BGP capability"; the AFI-SAFI";
           uses bgp-common-mp-all-afi-safi-common-prefix-limit-config;
         }
     identity MPBGP

         container state {
       base "bgp-capability";
           config false;
           description
         "Multi-protocol extensions
             "State information relating to BGP";
       reference "RFC2858"; the prefix-limit for the
             AFI-SAFI";
           uses bgp-common-mp-all-afi-safi-common-prefix-limit-config;
         }
     identity ROUTE-REFRESH {
       base "bgp-capability";
       description
         "The BGP route-refresh functionality";
       reference "RFC2918";
       }
     identity ASN32 {
       base "bgp-capability";
       description
         "4-byte (32-bit) AS number functionality";
       reference "RFC6793";
     }
     identity GRACEFUL-RESTART

     grouping bgp-common-mp-ipv4-ipv6-unicast-common {
       base "bgp-capability";
       description
         "Graceful restart functionality";
       reference "RFC4724";
     }
     identity ADD-PATHS
         "Common configuration that is applicable for IPv4 and IPv6
         unicast";

       // include common afi-safi options.
       uses bgp-common-mp-all-afi-safi-common;

       // configuration options that are specific to IPv[46] unicast
       container config {
       base "bgp-capability";
         description
         "BGP add-paths";
       reference "draft-ietf-idr-add-paths";
           "Configuration parameters for common IPv4 and IPv6 unicast
           AFI-SAFI options";
         uses bgp-common-mp-ipv4-ipv6-unicast-common-config;
       }
     identity afi-safi-type
       container state {
         config false;
         description
         "Base identity type for AFI,SAFI tuples for BGP-4";
       reference "RFC4760 - multiprotocol extensions
           "State information for BGP-4"; common IPv4 and IPv6 unicast
           parameters";
         uses bgp-common-mp-ipv4-ipv6-unicast-common-config;
       }
     identity ipv4-unicast
     }

     grouping bgp-common-mp-l3vpn-ipv4-ipv6-unicast-common {
       base afi-safi-type;
       description
         "IPv4 unicast (AFI,SAFI = 1,1)";
       reference "RFC4760";
     }
     identity ipv6-unicast {
       base afi-safi-type;
       description
         "IPv6 unicast (AFI,SAFI = 2,1)";
       reference "RFC4760";
     }
     identity ipv4-labelled-unicast {
       base afi-safi-type;
       description
         "Labelled
         "Common configuration applied across L3VPN for IPv4
          and IPv6";

       // placeholder -- specific configuration options that are generic
       // across IPv[46] unicast (AFI,SAFI = 1,4)";
       reference "RFC3107";
     }
     identity ipv6-labelled-unicast {
       base afi-safi-type;
       description
         "Labelled IPv6 unicast (AFI,SAFI = 2,4)";
       reference "RFC3107"; address families.
       uses bgp-common-mp-all-afi-safi-common;
     }
     identity l3vpn-ipv4-unicast

     grouping bgp-common-mp-l3vpn-ipv4-ipv6-multicast-common {
       base afi-safi-type;
       description
         "Unicast IPv4 MPLS
         "Common configuration applied across L3VPN (AFI,SAFI = 1,128)";

       reference "RFC4364"; for IPv4
         and IPv6";

       // placeholder -- specific configuration options that are
       // generic across IPv[46] multicast address families.
       uses bgp-common-mp-all-afi-safi-common;
     }
     identity l3vpn-ipv6-unicast

     grouping bgp-common-mp-l2vpn-common {
       base afi-safi-type;
       description
         "Unicast IPv6 MPLS L3VPN (AFI,SAFI = 2,128)";
       reference "RFC4659";
         "Common configuration applied across L2VPN address
         families";

       // placeholder -- specific configuration options that are
       // generic across L2VPN address families
       uses bgp-common-mp-all-afi-safi-common;
     }
     identity l3vpn-ipv4-multicast

     // Config groupings for common groups
     grouping bgp-common-mp-all-afi-safi-common-prefix-limit-config {
       base afi-safi-type;
       description
         "Multicast IPv4 MPLS L3VPN (AFI,SAFI = 1,129)";
       reference "RFC6514";
     }
     identity l3vpn-ipv6-multicast
         "Configuration parameters relating to prefix-limits for an
         AFI-SAFI";

       leaf max-prefixes {
       base afi-safi-type;
         type uint32;
         description
         "Multicast IPv6 MPLS L3VPN (AFI,SAFI = 2,129)";
       reference "RFC6514";
           "Maximum number of prefixes that will be accepted
           from the neighbour";
       }
     identity l2vpn-vpls
       leaf shutdown-threshold-pct {
       base afi-safi-type;
         type oc-types:percentage;
         description
         "BGP-signalled VPLS (AFI,SAFI = 25,65)";
       reference "RFC4761";
           "Threshold on number of prefixes that can be received
           from a neighbour before generation of warning messages
           or log entries. Expressed as a percentage of
           max-prefixes";
       }
     identity l2vpn-evpn

       leaf restart-timer {
       base afi-safi-type;
       description
         "BGP MPLS Based Ethernet VPN (AFI,SAFI = 25,70)";
     }
     identity bgp-well-known-std-community
         type decimal64 {
           fraction-digits 2;
         }
         units "seconds";
         description
         "Reserved communities within
           "Time interval in seconds after which the standard community space
         defined by RFC1997. These communities must fall within the
         range 0x00000000 BGP session
           is re-established after being torn down due to 0xFFFFFFFF";
       reference "RFC1997"; exceeding
           the max-prefix limit.";
       }
     identity NO_EXPORT
     }

     grouping bgp-common-mp-ipv4-ipv6-unicast-common-config {
       base bgp-well-known-std-community;
       description
         "Do not export NLRI received carrying this community outside
         "Common configuration parameters for IPv4 and IPv6 Unicast
         address families";

       leaf send-default-route {
         type boolean;
         default "false";
         description
           "If set to true, send the bounds of this autonomous system, or this confederation if default-route to the local autonomous system is a confederation member AS. This
         community has a value of 0xFFFFFF01.";
       reference "RFC1997"; neighbour(s)";
       }
     identity NO_ADVERTISE
     }

   }
   <CODE ENDS>

<CODE BEGINS> file "ietf-bgp-common-structure.yang"

submodule ietf-bgp-common-structure {
       base bgp-well-known-std-community;

  belongs-to ietf-bgp {
    prefix "bgp";
  }

  import openconfig-extensions { prefix oc-ext; }
  include ietf-bgp-common-multiprotocol;
  include ietf-bgp-common;

  // meta
  organization
    "OpenConfig working group";

  contact
    "OpenConfig working group
    netopenconfig@googlegroups.com";

  description
         "All NLRI received carrying this community must not be
         advertised to
    "This sub-module contains groupings that are common across multiple BGP
    contexts and provide structure around other primitive groupings.";

  oc-ext:openconfig-version "2.1.1";

  revision "2016-06-21" {
    description
      "OpenConfig BGP peers. This community has a value of
         0xFFFFFF02."; refactor";
    reference "RFC1997"; "2.1.1";
  }
     identity NO_EXPORT_SUBCONFED

  grouping bgp-common-structure-neighbor-group-logging-options {
       base bgp-well-known-std-community;
    description
         "All NLRI received carrying this community must not be
         advertised
      "Structural grouping used to external include error handling configuration and
      state for both BGP peers - including over confederation
         sub-AS boundaries. This community has a value of 0xFFFFFF03.";
       reference "RFC1997";
     }
     identity NOPEER neighbors and groups";

    container logging-options {
       base bgp-well-known-std-community;
      description
         "An autonomous system receiving NLRI tagged with this community
         is advised not
        "Logging options for events related to readvertise the NLRI BGP neighbor or
        group";
      container config {
        description
          "Configuration parameters enabling or modifying logging
          for events relating to external bi-lateral
         peer autonomous systems. An AS may also filter received NLRI
         from bilateral peer sessions when they are tagged with this
         community value";
       reference "RFC3765"; the BGPgroup";
        uses bgp-common-neighbor-group-logging-options-config;
      }
     identity INTERNET
      container state {
       base bgp-well-known-std-community;
        config false;
        description
         "A community used by some implementations with
          "State information relating to logging for the value 0:0
         which represents all possible community values."; BGP neighbor
          or group";
        uses bgp-common-neighbor-group-logging-options-config;
      }
     typedef bgp-session-direction
    }
  }
  grouping bgp-common-structure-neighbor-group-ebgp-multihop {
       type enumeration
    description
      "Structural grouping used to include eBGP multihop configuration and
      state for both BGP neighbors and peer groups";

    container ebgp-multihop {
         enum INBOUND
      description
        "eBGP multi-hop parameters for the BGPgroup";
      container config {
        description
             "Refers
          "Configuration parameters relating to all NLRI received from eBGP multihop for the
          BGP peer"; group";
        uses bgp-common-neighbor-group-multihop-config;
      }
         enum OUTBOUND
      container state {
        config false;
        description
             "Refers to all NLRI advertised to
          "State information for eBGP multihop, for the BGP peer"; neighbor
          or group";
        uses bgp-common-neighbor-group-multihop-config;
      }
    }
       description
         "Type to describe the direction of NLRI transmission";
  }
     typedef bgp-well-known-community-type {
       type identityref

  grouping bgp-common-structure-neighbor-group-route-reflector {
         base bgp-well-known-std-community;

       }
    description
         "Type definition
      "Structural grouping used to include route reflector configuration and
      state for well-known IETF community attribute
         values";
       reference
         "IANA Border Gateway Protocol (BGP) Well Known Communities";
     }
     typedef bgp-std-community-type {
       // TODO: further refine restrictions both BGP neighbors and allowed patterns
       // 4-octet value:
       //  <as number> 2 octets
       //  <community value> 2 octets
       type union peer groups";

    container route-reflector {
         type uint32
      description
        "Route reflector parameters for the BGPgroup";
      container config {
         // per RFC 1997, 0x00000000 - 0x0000FFFF and 0xFFFF0000 -
         // 0xFFFFFFFF are reserved
           range "65536..4294901759"; // 0x00010000..0xFFFEFFFF
        description
          "Configuraton parameters relating to route reflection
          for the BGPgroup";
        uses bgp-common-neighbor-group-route-reflector-config;
      }
         type string
      container state {
           pattern '([0-9]+:[0-9]+)';
         }
       }
        config false;
        description
         "Type definition
          "State information relating to route reflection for standard commmunity attributes"; the
          BGPgroup";
        uses bgp-common-neighbor-group-route-reflector-config;
      }
    }
  }
  grouping bgp-common-structure-neighbor-group-as-path-options {
    description
      "Structural grouping used to include AS_PATH manipulation configuration
      and state for both BGP neighbors and peer groups";

    container as-path-options {
      description
        "AS_PATH manipulation parameters for the BGP neighbor or
        group";
      container config {
        description
          "Configuration parameters relating to AS_PATH manipulation
          for the BGP peer or group";
        uses bgp-common-neighbor-group-as-path-options-config;
      }
      container state {
        config false;
        description
          "State information relating to the AS_PATH manipulation
          mechanisms for the BGP peer or group";
        uses bgp-common-neighbor-group-as-path-options-config;
      }
    }
  }

  grouping bgp-common-structure-neighbor-group-add-paths {
    description
      "Structural grouping used to include ADD-PATHs configuration and state
      for both BGP neighbors and peer groups";

    container add-paths {
      description
        "Parameters relating to the advertisement and receipt of
        multiple paths for a single NLRI (add-paths)";
      container config {
        description
          "Configuration parameters relating to ADD_PATHS";
        uses bgp-common-neighbor-group-add-paths-config;
      }
      container state {
        config false;
        description
          "State information associated with ADD_PATHS";
        uses bgp-common-neighbor-group-add-paths-config;
      }
    }
  }

}

<CODE ENDS>

  <CODE BEGINS> file "ietf-bgp-peer-group.yang"

  submodule ietf-bgp-peer-group {

    belongs-to ietf-bgp {
      prefix "bgp";
    }

    import openconfig-extensions { prefix oc-ext; }
    import ietf-routing-policy { prefix rpol; }

    // Include the common submodule
    include ietf-bgp-common;
    include ietf-bgp-common-multiprotocol;
    include ietf-bgp-common-structure;

    // meta
    organization
      "OpenConfig working group";

    contact
      "OpenConfig working group
      netopenconfig@googlegroups.com";

    description
      "This sub-module contains groupings that are specific to the
      peer-group context of the OpenConfig BGP module.";

    oc-ext:openconfig-version "2.1.1";

    revision "2016-06-21" {
      description
        "OpenConfig BGP refactor";
      reference "RFC 1997 - "2.1.1";
    }

    grouping bgp-peer-group-config {
      description
        "Configuration parameters relating to a base BGP peer group that
        are not also applicable to any other context (e.g., neighbor)";

      leaf peer-group-name {
        type string;
        description
          "Name of the BGP peer-group";
      }

    }

    grouping bgp-peer-group-afi-safi-list {
      description
        "List of address-families associated with the BGP peer-group";

      list afi-safi {
        key "afi-safi-name";

        description
          "AFI,SAFI configuration available for the
          neighbour or group";

        leaf afi-safi-name {
          type leafref {
            path "../config/afi-safi-name";
          }
          description
            "Reference to the AFI-SAFI name used as a key
            for the AFI-SAFI list";
        }

        container config {
          description
            "Configuration parameters for the AFI-SAFI";
          uses bgp-common-mp-afi-safi-config;
        }
        container state {
          config false;
          description
            "State information relating to the AFI-SAFI";
          uses bgp-common-mp-afi-safi-config;
        }

        container graceful-restart {
          description
            "Parameters relating to BGP graceful-restart";
          container config {
            description
              "Configuration options for BGP graceful-restart";
            uses bgp-common-mp-afi-safi-graceful-restart-config;
          }
          container state {
            config false;
            description
              "State information for BGP graceful-restart";
            uses bgp-common-mp-afi-safi-graceful-restart-config;
          }
        }

        uses bgp-common-route-selection-options;
        uses bgp-common-global-group-use-multiple-paths;
        uses bgp-common-mp-all-afi-safi-list-contents;
      }
    }

    grouping bgp-peer-group-base {
      description
        "Parameters related to a BGP group";

      container config {
        description
          "Configuration parameters relating to the BGP neighbor or
          group";
        uses bgp-peer-group-config;
        uses bgp-common-neighbor-group-config;
      }
      container state {
        config false;
        description
          "State information relating to the BGP peer-group";
        uses bgp-peer-group-config;
        uses bgp-common-neighbor-group-config;
        uses bgp-common-state;
      }

      container timers {
        description
          "Timers related to a BGP peer-group";

        container config {
          description
            "Configuration parameters relating to timers used for the
            BGP neighbor or peer group";
          uses bgp-common-neighbor-group-timers-config;
        }
        container state {
          config false;
          description
            "State information relating to the timers used for the BGP
           group";
          uses bgp-common-neighbor-group-timers-config;

        }
      }

      container transport {
        description
          "Transport session parameters for the BGP peer-group";

        container config {
          description
            "Configuration parameters relating to the transport
            session(s) used for the BGP neighbor or group";
          uses bgp-common-neighbor-group-transport-config;
        }
        container state {
          config false;
          description
            "State information relating to the transport session(s)
            used for the BGP neighbor or group";
          uses bgp-common-neighbor-group-transport-config;
        }
      }

      container error-handling {
        description
          "Error handling parameters used for the BGP peer-group";

        container config {
          description
            "Configuration parameters enabling or modifying the
            behavior or enhanced error handling mechanisms for the BGP
            group";
          uses bgp-common-neighbor-group-error-handling-config;
        }
        container state {
          config false;
          description
            "State information relating to enhanced error handling
            mechanisms for the BGP group";
          uses bgp-common-neighbor-group-error-handling-config;
        }
      }

      container graceful-restart {
        description
          "Parameters relating the graceful restart mechanism for BGP";
        container config {
          description
            "Configuration parameters relating to graceful-restart";

          uses bgp-common-graceful-restart-config;
        }
        container state {
          config false;
          description
            "State information associated with graceful-restart";
          uses bgp-common-graceful-restart-config;
        }
      }

      uses bgp-common-structure-neighbor-group-logging-options;
      uses bgp-common-structure-neighbor-group-ebgp-multihop;
      uses bgp-common-structure-neighbor-group-route-reflector;
      uses bgp-common-structure-neighbor-group-as-path-options;
      uses bgp-common-structure-neighbor-group-add-paths;
      uses bgp-common-global-group-use-multiple-paths;
      uses rpol:apply-policy-group;

      container afi-safis {
        description
          "Per-address-family configuration parameters associated with
          thegroup";
        uses bgp-peer-group-afi-safi-list;
      }
    }

    grouping bgp-peer-group-list {
      description
        "The list of BGP peer groups";

      list peer-group {
        key "peer-group-name";
        description
          "List of BGP peer-groups configured on the local system -
          uniquely identified by peer-group name";

      leaf peer-group-name {
        type leafref {
          path "../config/peer-group-name";
        }
        description
          "Reference to the name of the BGP peer-group used as a
          key in the peer-group list";
        }

        uses bgp-peer-group-base;
      }
    }

  }

  <CODE ENDS>

   <CODE BEGINS> file "ietf-bgp-neighbor.yang"

   submodule ietf-bgp-neighbor {

     belongs-to ietf-bgp {
       prefix "bgp";
     }

     import openconfig-extensions { prefix oc-ext; }
     import ietf-routing-policy { prefix rpol; }
     import openconfig-types { prefix oc-types; }
     import ietf-bgp-types { prefix oc-bgp-types; }
     import ietf-inet-types { prefix inet; }
     import ietf-yang-types { prefix yang; }

     // Include the common submodule
     include ietf-bgp-common;
     include ietf-bgp-common-multiprotocol;
     include ietf-bgp-peer-group;
     include ietf-bgp-common-structure;

     // meta
     organization
       "OpenConfig working group";

     contact
       "OpenConfig working group
       netopenconfig@googlegroups.com";

     description
       "This sub-module contains groupings that are specific to the
       neighbor context of the OpenConfig BGP module.";

     oc-ext:openconfig-version "2.1.1";

     revision "2016-06-21" {
       description
         "OpenConfig BGP refactor";
       reference "2.1.1";
     }

     grouping bgp-neighbor-config {
       description
         "Configuration parameters relating to a base BGP neighbor that
         are not also applicable to any other context
         (e.g., peer group)";

       leaf peer-group {
         type leafref {
           path "../../../../peer-groups/peer-group/peer-group-name";
         }
         description
           "The peer-group with which this neighbor is associated";
       }

       leaf neighbor-address {
           type inet:ip-address;
           description
             "Address of the BGP peer, either in IPv4 or IPv6";
       }

       leaf enabled {
           type boolean;
           default true;
           description
             "Whether the BGP peer is enabled. In cases where the
             enabled leaf is set to false, the local system should not
             initiate connections to the neighbor, and should not
             respond to TCP connections attempts from the neighbor. If
             the state of the BGP session is ESTABLISHED at the time
             that this leaf is set to false, the BGP session should be
             ceased.";
       }
     }

     grouping bgp-neighbor-use-multiple-paths {
       description
         "Multipath configuration and state applicable to a BGP
         neighbor";

       container use-multiple-paths {
         description
           "Parameters related to the use of multiple-paths for the same
           NLRI when they are received only from this neighbor";

         container config {
           description
             "Configuration parameters relating to multipath";
           uses bgp-common-use-multiple-paths-config;
         }
         container state {
           config false;
           description
             "State parameters relating to multipath";
           uses bgp-common-use-multiple-paths-config;
         }

         container ebgp {
           description
             "Multipath configuration for eBGP";
           container config {
             description
               "Configuration parameters relating to eBGP multipath";
             uses bgp-common-use-multiple-paths-ebgp-as-options-config;
           }
           container state {
             config false;
             description
               "State information relating to eBGP multipath";
             uses bgp-common-use-multiple-paths-ebgp-as-options-config;
           }
         }
       }
     }

     grouping bgp-neighbor-state {
       description
         "Operational state parameters relating only to a BGP neighbor";

       leaf session-state {
         type enumeration {
             enum IDLE {
               description
                 "neighbor is down, and in the Idle state of the
                 FSM";
             }
             enum CONNECT {
               description
                 "neighbor is down, and the session is waiting for
                 the underlying transport session to be established";
             }
             enum ACTIVE {
               description
                 "neighbor is down, and the local system is awaiting
                 a conncetion from the remote peer";
             }
             enum OPENSENT {
               description
                 "neighbor is in the process of being established.

                 The local system has sent an OPEN message";
             }
             enum OPENCONFIRM {
               description
                 "neighbor is in the process of being established.
                 The local system is awaiting a NOTIFICATION or
                 KEEPALIVE message";
             }
             enum ESTABLISHED {
               description
                 "neighbor is up - the BGP session with the peer is
                 established";
             }
           }
         description
           "Operational state of the BGP peer";
       }

       leaf last-established {
         type oc-types:timeticks64;
         description
           "This timestamp indicates the time that the
           BGP session last transitioned in or out of the Established
           state.  The value is the timestamp in seconds relative to
           the Unix Epoch (Jan 1, 1970 00:00:00 UTC).

           The BGP session uptime can be computed by clients as the
           difference between this value and the current time in UTC
           (assuming the session is in the ESTABLISHED state, per the
           session-state leaf).";
       }

       leaf established-transitions {
         type yang:counter64;
         description
           "Number of transitions to the Established state for
           the neighbor session.  This value is analogous to the
           bgpPeerFsmEstablishedTransitions object from the standard
           BGP-4 MIB";
         reference
           "RFC 4273 - Definitions of Managed Objects for BGP-4";
       }

       leaf-list supported-capabilities {
         type identityref {
           base oc-bgp-types:BGP_CAPABILITY;
         }
         description
           "BGP capabilities negotiated as supported with the peer";
       }

       container messages {
         description
           "Counters for BGP messages sent and received from the
           neighbor";
         container sent {
           description
             "Counters relating to BGP messages sent to the neighbor";
           uses bgp-neighbor-counters-message-types-state;
           }

         container received {
           description
             "Counters for BGP messages received from the neighbor";
           uses bgp-neighbor-counters-message-types-state;
         }
       }

       container queues {
         description
           "Counters related to queued messages associated with the
           BGP neighbor";
         uses bgp-neighbor-queue-counters-state;
       }
     }

     grouping bgp-neighbor-counters-message-types-state {
       description
         "Grouping of BGP message types, included for re-use
         across counters";

       leaf UPDATE {
         type uint64;
         description
           "Number of BGP UPDATE messages announcing, withdrawing
           or modifying paths exchanged.";
       }

       leaf NOTIFICATION {
         type uint64;
         description
           "Number of BGP NOTIFICATION messages indicating an
           error condition has occurred exchanged.";
       }
     }
     grouping bgp-neighbor-queue-counters-state {
       description
         "Counters relating to the message queues associated with the
         BGP peer";

       leaf input {
         type uint32;
         description
           "The number of messages received from the peer currently
           queued";
       }

       leaf output {
         type uint32;
         description
           "The number of messages queued to be sent to the peer";
       }
     }

     grouping bgp-neighbor-transport-state {
       description
         "Operational state parameters relating to the transport session
         used for the BGP session";

       leaf local-port {
         type inet:port-number;
         description
           "Local TCP port being used for the TCP session supporting
           the BGP session";
       }

       leaf remote-address {
         type inet:ip-address;
         description
           "Remote address to which the BGP session has been
           established";
       }

       leaf remote-port {
         type inet:port-number;
         description
           "Remote port being used by the peer for the TCP session
           supporting the BGP session";
       }
     }

     grouping bgp-neighbor-error-handling-state {
       description
         "Operational state parameters relating to enhanced error
         error handling for BGP";

       leaf erroneous-update-messages {
         type uint32;
         description
           "The number of BGP UPDATE messages for which the
           treat-as-withdraw mechanism has been applied based
           on erroneous message contents";
       }
     }

     grouping bgp-neighbor-timers-state {
       description
         "Operational state parameters relating to BGP timers associated
         with the BGP session";

       leaf negotiated-hold-time {
         type decimal64 {
           fraction-digits 2;
         }
         description
           "The negotiated hold-time for the BGP Communities Attribute"; session";
       }
     typedef bgp-ext-community-type
     }

     grouping bgp-neighbor-afi-safi-graceful-restart-state {
       // TODO: needs more work
       description
         "Operational state variables relating to make this more precise given the
       // variability of extended community attribute specifications
       // 8-octet value:
       //  <type> 2 octects
       //  <value> 6 octets graceful-restart
         mechanism on a per-AFI-SAFI basis";

       leaf received {
         type string boolean;
         description
           "This leaf indicates whether the neighbor advertised the
           ability to support graceful-restart for this AFI-SAFI";
       }

       leaf advertised {
         pattern '([0-9\.]+(:[0-9]+)?:[0-9]+)';
         type boolean;
         description
           "This leaf indicates whether the ability to support
           graceful-restart has been advertised to the peer";
       }
     }

     grouping bgp-neighbor-graceful-restart-state {
       description
         "Type definition
         "Operational state information relevant to graceful restart
         for extended community attributes";
       reference "RFC 4360 - BGP";

       leaf peer-restart-time {
         type uint16 {
           range 0..4096;
         }
         description
           "The period of time (advertised by the peer) that
           the peer expects a restart of a BGP Extended Communities Attribute"; session to
           take";
       }
     typedef bgp-community-regexp-type

       leaf peer-restarting {
       // TODO: needs more work
         type boolean;
         description
           "This flag indicates whether the remote neighbor is currently
           in the process of restarting, and hence received routes are
           currently stale";
       }

       leaf local-restarting {
         type boolean;
         description
           "This flag indicates whether the local neighbor is currently
           restarting. The flag is unset after all NLRI have been
           advertised to decide what format these regexps can
       // take. the peer, and the End-of-RIB (EOR) marker has
           been unset";
       }

       leaf mode {
         type string; enumeration {
           enum HELPER_ONLY {
             description
         "Type definition for communities specified as regular
         expression patterns";
               "The local router is operating in helper-only mode, and
               hence will not retain forwarding state during a local
               session restart, but will do so during a restart of the
               remote peer";
           }
     typedef bgp-origin-attr-type {
       type enumeration {
           enum IGP BILATERAL {
             description "Origin of the NLRI
               "The local router is internal"; operating in both helper mode, and
               hence retains forwarding state during a remote restart,
               and also maintains forwarding state during local session
               restart";
           }
           enum EGP REMOTE_HELPER {
             description "Origin of
               "The local system is able to retain routes during restart
               but the NLRI remote system is EGP"; only able to act as a helper";
           }
         }
         enum INCOMPLETE {
         description "Origin
           "Ths leaf indicates the mode of operation of BGP graceful
           restart with the NLRI is neither IGP or EGP"; peer";
       }
     }

     grouping bgp-neighbor-afi-safi-state {
       description
         "Type definition
         "Operational state parameters relating to an individual AFI,
         SAFI for standard BGP origin attribute";
       reference "RFC 4271 - A Border Gateway Protocol 4 (BGP-4),
         Sec 4.3";
     }
     typedef peer-type a neighbor";

       leaf active {
         type enumeration {
         enum INTERNAL { boolean;
         description "internal (iBGP) peer";
           "This value indicates whether a particular AFI-SAFI has
           been succesfully negotiated with the peer. An AFI-SAFI
           may be enabled in the current running configuration, but a
           session restart may be required in order to negotiate the new
           capability.";
       }
         enum EXTERNAL

       container prefixes {
         description "external (eBGP) peer";
         }
       } "Prefix counters for the BGP session";
         leaf received {
           type uint32;
           description
         "labels a peer or peer group as explicitly internal or
         external";
             "The number of prefixes received from the neighbor";
         }
     typedef remove-private-as-option

         leaf sent {
           type enumeration {
         enum ALL uint32;
           description
             "The number of prefixes advertised to the neighbor";
         }

         leaf installed {
           type uint32;
           description "remove all private ASes
             "The number of advertised prefixes installed in the path";
             Loc-RIB";
         }
       }
     }
         enum REPLACE
     grouping bgp-neighbor-afi-safi-list {
       description "replace private ASes
         "List of address-families associated with local AS";
         }
       } the BGP neighbor";

       list afi-safi {
         key "afi-safi-name";

         description
         "set of options
           "AFI,SAFI configuration available for configuring how private AS path numbers
         are removed from advertisements";
     }
     typedef percentage the
           neighbour or group";

         leaf afi-safi-name {
           type uint8 leafref {
         range "0..100";
             path "../config/afi-safi-name";
           }
           description
         "Integer indicating
             "Reference to the AFI-SAFI name used as a percentage value"; key
             for the AFI-SAFI list";
         }
     typedef rr-cluster-id-type {
       type union

         container config {
         type uint32;
         type inet:ipv4-address;
       }
           description
         "union type
             "Configuration parameters for route reflector cluster ids:
         option 1: 4-byte number
         option 2: IP address"; the AFI-SAFI";
           uses bgp-common-mp-afi-safi-config;
         }
     typedef community-type {
       type enumeration {
         enum STANDARD
         container state {
           config false;
           description "send only standard communities";
             "State information relating to the AFI-SAFI";
           uses bgp-common-mp-afi-safi-config;
           uses bgp-neighbor-afi-safi-state;
         }
         enum EXTENDED

         container graceful-restart {
           description "send only extended communities";
         }
         enum BOTH
             "Parameters relating to BGP graceful-restart";
           container config {
             description "send both standard and extended communities";
               "Configuration options for BGP graceful-restart";
             uses bgp-common-mp-afi-safi-graceful-restart-config;
           }
         enum NONE
           container state {
             config false;
             description "do not send any community attribute";
               "State information for BGP graceful-restart";
             uses bgp-common-mp-afi-safi-graceful-restart-config;
             uses bgp-neighbor-afi-safi-graceful-restart-state;
           }
         }
       description
         "type describing variations of community attributes:
         STANDARD: standard BGP community [rfc1997]
         EXTENDED: extended BGP community [rfc4360]
         BOTH: both standard and extended community";

         uses bgp-common-mp-all-afi-safi-list-contents;
         uses bgp-neighbor-use-multiple-paths;
       }
     }
   <CODE ENDS>

6.3.  BGP policy items

   <CODE BEGINS> file "ietf-bgp-policy.yang"
   module ietf-bgp-policy

     grouping bgp-neighbor-base {
     yang-version "1";
     // namespace
     namespace "urn:ietf:params:xml:ns:yang:ietf-bgp-policy";
     prefix "bgp-pol";
     // import some basic types
     import ietf-inet-types
       description
         "Parameters related to a BGP neighbor";

       container config { prefix inet;
         description
           "Configuration parameters relating to the BGP neighbor or
           group";
         uses bgp-neighbor-config;
         uses bgp-common-neighbor-group-config;
       }
     import ietf-routing-policy {prefix rpol;
       container state {
         config false;
         description
           "State information relating to the BGP neighbor";
         uses bgp-neighbor-config;
         uses bgp-common-neighbor-group-config;
         uses bgp-neighbor-state;
       }
     import ietf-policy-types

       container timers { prefix pt;
         description
           "Timers related to a BGP neighbor";
         container config {
           description
             "Configuration parameters relating to timers used for the
             BGP neighbor";
           uses bgp-common-neighbor-group-timers-config;
         }
     import ietf-bgp-types
         container state { prefix bgp-types;
           config false;
           description
             "State information relating to the timers used for the BGP
             neighbor";
           uses bgp-common-neighbor-group-timers-config;
           uses bgp-neighbor-timers-state;
         }
     // meta
     organization
       "OpenConfig working group";
     contact
       "OpenConfig working group
       netopenconfig@googlegroups.com";
       }
       container transport {
         description
       "This module contains data definitions
           "Transport session parameters for the BGP routing policy.
       It augments neighbor";
         container config {
           description
             "Configuration parameters relating to the base routing-policy module with BGP-specific
       options transport
             session(s) used for conditions and actions.";
     revision "2016-01-06" the BGP neighbor";
           uses bgp-common-neighbor-group-transport-config;
         }
         container state {
           config false;
           description
         "Updated filename and namespace";
       reference "TBD";
             "State information relating to the transport session(s)
             used for the BGP neighbor";
           uses bgp-common-neighbor-group-transport-config;
           uses bgp-neighbor-transport-state;
         }
     // extension statements
     // feature statements
     // identity statements
     // typedef statements
     typedef bgp-as-path-prepend-repeat
       }

       container error-handling {
       type uint8;
         description
         "Option
           "Error handling parameters used for the BGP as-prepend policy action.  Prepends neighbor or
           group";
         container config {
           description
             "Configuration parameters enabling or modifying the
         local AS number repeated n times";
             behavior or enhanced error handling mechanisms for the BGP
             neighbor";
           uses bgp-common-neighbor-group-error-handling-config;
         }
     typedef bgp-set-community-option-type {
       type enumeration {
         enum ADD
         container state {
           config false;
           description
             "add the specified communities
             "State information relating to enhanced error handling
             mechanisms for the existing
             community attribute"; BGP neighbor";
           uses bgp-common-neighbor-group-error-handling-config;
           uses bgp-neighbor-error-handling-state;
         }
         enum REMOVE
       }

       container graceful-restart {
         description
             "remove the specified communities from
           "Parameters relating the
             existing community attribute"; graceful restart mechanism for BGP";
         container config {
           description
             "Configuration parameters relating to graceful-restart";
           uses bgp-common-graceful-restart-config;
         }
         container state {
           config false;
           description
             "State information associated with graceful-restart";
           uses bgp-common-graceful-restart-config;
           uses bgp-neighbor-graceful-restart-state;
         }
       }
         enum REPLACE

       uses bgp-common-structure-neighbor-group-logging-options;
       uses bgp-common-structure-neighbor-group-ebgp-multihop;
       uses bgp-common-structure-neighbor-group-route-reflector;
       uses bgp-common-structure-neighbor-group-as-path-options;
       uses bgp-common-structure-neighbor-group-add-paths;
       uses bgp-neighbor-use-multiple-paths;
       uses rpol:apply-policy-group;

       container afi-safis {
         description
             "replace the existing community attribute
           "Per-address-family configuration parameters associated with
           the specified communities. If an empty set is
             specified, this removes the community attribute
             from the route.";
         } neighbor";
         uses bgp-neighbor-afi-safi-list;
       }
       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;
         type enumeration

     grouping bgp-neighbor-list {
           enum SELF
       description
         "The list of BGP neighbors";

       list neighbor {
         key "neighbor-address";
         description "special designation for
           "List of BGP neighbors configured on the 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 system,
           uniquely identified by peer IPv[46] address";

         leaf neighbor-address {
           type uint32;
         type string leafref {
           pattern "^[+-][0-9]+";
             path "../config/neighbor-address";
           }
         type enumeration {
           enum IGP {
           description "set the MED value
             "Reference to the IGP cost toward address of the
             next hop for BGP neighbor used as
             a key in the route"; neighbor list";
         }

         uses bgp-neighbor-base;
       }

     }
       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).";

   }
     // grouping statements
     grouping bgp-match-conditions

   <CODE ENDS>

   <CODE BEGINS> file "ietf-bgp-global.yang"

   submodule ietf-bgp-global {
       description
         "Condition statement definitions for checking membership in a
         defined set";
       container match-community-set

     belongs-to ietf-bgp {
         presence
           "The presence of this container indicates
       prefix "bgp";
     }

     import openconfig-extensions { prefix oc-ext; }
     import ietf-inet-types { prefix inet; }
     import ietf-yang-types { prefix yang; }

     // Include common submodule
     include ietf-bgp-common;
     include ietf-bgp-common-multiprotocol;

     // meta
     organization
       "OpenConfig working group";

     contact
       "OpenConfig working group
       netopenconfig@googlegroups.com";

     description
       "This sub-module contains groupings that are specific to the routes
           should match
       global context of the referenced community-set"; OpenConfig BGP module";

     oc-ext:openconfig-version "2.1.1";

     revision "2016-06-21" {
       description
           "Match a referenced community-set according to the logic
           defined in
         "OpenConfig BGP refactor";
       reference "2.1.1";
     }

     grouping bgp-global-config {
       description
         "Global configuration options for the match-set-options leaf"; BGP router.";

       leaf community-set as {
         type leafref {
             path "/rpol:routing-policy/rpol:defined-sets/" +
               "bgp-pol:bgp-defined-sets/bgp-pol:community-sets/" +
               "bgp-pol:community-set/bgp-pol:community-set-name";
             require-instance inet:as-number;
         mandatory true;
           }
         description
             "References a defined community set";
         }
         uses rpol:match-set-options-group;
       }
       container match-ext-community-set {
         presence
           "The presence
           "Local autonomous system number of this container indicates that the routes
           should match router.  Uses
           the referenced extended community set";
         description
           "Match a referenced extended community-set according to 32-bit as-number type from the
           logic defined model in the match-set-options leaf"; RFC 6991.";
       }

       leaf ext-community-set router-id {
         type leafref {
             path "/rpol:routing-policy/rpol:defined-sets/" +
               "bgp-pol:bgp-defined-sets/bgp-pol:ext-community-sets/" +
               "bgp-pol:ext-community-set/" +
               "bgp-pol:ext-community-set-name";
             require-instance true;
           } yang:dotted-quad;
         description "References a defined extended community set";
           "Router id of the router - an unsigned 32-bit integer
           expressed in dotted quad notation.";
         reference
           "RFC4271 - A Border Gateway Protocol 4 (BGP-4),
           Section 4.2";
       }
         uses rpol:match-set-options-group;
     }
       container match-as-path-set

     grouping bgp-global-state {
         presence
           "The presence of this container indicates that the route
           should match
       description
         "Operational state parameters for the referenced as-path set"; BGP neighbor";

       uses bgp-common-state;
     }

     grouping bgp-global-default-route-distance-config {
       description
           "Match a referenced as-path set according
         "Configuration options relating to the logic
           defined in the match-set-options leaf"; administrative distance
         (or preference) assigned to routes received from different
         sources (external, internal, and local).";

       leaf as-path-set external-route-distance {
         type leafref uint8 {
             path "/rpol:routing-policy/rpol:defined-sets/" +
               "bgp-pol:bgp-defined-sets/bgp-pol:as-path-sets/" +
               "bgp-pol:as-path-set/bgp-pol:as-path-set-name";
             require-instance true;
           range "1..255";
         }
         description "References a defined AS path set";
         }
         uses rpol:match-set-options-group;
       }
           "Administrative distance for routes learned from external
           BGP (eBGP).";
       }
     grouping bgp-attribute-conditions
       leaf internal-route-distance {
         type uint8 {
           range "1..255";
         }
         description
         "Condition statement definitions
           "Administrative distance for comparing a BGP route
         attribute to a specified value";
       leaf med-eq routes learned from internal
           BGP (iBGP).";
       }
     }

     grouping bgp-global-confederation-config {
         type uint32;
       description
           "Condition to check if
         "Configuration options specifying parameters when the received MED value local
         router is equal to
           the specified value";
       } within an autonomous system which is part of a BGP
         confederation.";

       leaf origin-eq enabled {
         type bgp-types:bgp-origin-attr-type; boolean;
         description
           "Condition to check if the route origin
           "When this leaf is equal set to true it indicates that
           the
           specified value"; local-AS is part of a BGP confederation";
       }
       leaf-list next-hop-in

       leaf identifier {
         type inet:ip-address; inet:as-number;
         description
           "List of next hop addresses to check
           "Confederation identifier for in the route
           update"; autonomous system.";
       }
       leaf local-pref-eq

       leaf-list member-as {
         type uint32;
         // TODO: add support for other comparisons if needed inet:as-number;
         description
           "Condition
           "Remote autonomous systems that are to check if be treated
           as part of the local pref attribute is equal to
           the specified value"; confederation.";
       }
       container community-count
     }

     grouping bgp-global-afi-safi-list {
         presence "node is present in the config data to indicate a
         community-count condition";
       description
           "Value and comparison operations for conditions based on the
           number
         "List of communities in address-families associated with the route update";
         uses pt:attribute-compare-operators;
       }
       container as-path-length BGP instance";

       list afi-safi {
         presence "node is present in the config data to indicate a
         as-path-length condition";
         key "afi-safi-name";

         description
           "Value and comparison operations
           "AFI,SAFI configuration available for conditions based on the
           length of the AS path in the route update";
         uses pt:attribute-compare-operators;
       }
           neighbour or group";

         leaf route-type afi-safi-name {
         // TODO: verify extent of vendor support for this comparison
           type enumeration {
           enum INTERNAL leafref {
             path "../config/afi-safi-name";
           }
           description "route type is internal";
             "Reference to the AFI-SAFI name used as a key
             for the AFI-SAFI list";
         }
           enum EXTERNAL

         container config {
           description "route type is external";
           }
             "Configuration parameters for the AFI-SAFI";
           uses bgp-common-mp-afi-safi-config;
         }
         container state {
           config false;
           description
           "Condition
             "State information relating to check the route type in the route update";
       } AFI-SAFI";
           uses bgp-common-mp-afi-safi-config;
           uses bgp-common-state;
         }
     // augment statements
     augment "/rpol:routing-policy/rpol:defined-sets"

         container graceful-restart {
           description "adds BGP defined sets container
             "Parameters relating to routing policy
       model"; BGP graceful-restart";
           container bgp-defined-sets config {
             description
           "BGP-related set definitions
               "Configuration options for policy match conditions"; BGP graceful-restart";
             uses bgp-common-mp-afi-safi-graceful-restart-config;
           }
           container community-sets state {
             config false;
             description
             "Enclosing container
               "State information for community sets";
           list community-set BGP graceful-restart";
             uses bgp-common-mp-afi-safi-graceful-restart-config;
           }
         }

         uses bgp-common-route-selection-options;
         uses bgp-common-global-group-use-multiple-paths;
         uses bgp-common-mp-all-afi-safi-list-contents;
       }
     }

     // Structural groupings
     grouping bgp-global-base {
             key community-set-name;
       description
                 "Definitions
         "Global configuration parameters for community sets";
             leaf community-set-name the BGP router";

       container config {
               type string;
               mandatory true;
         description
                 "name / label of the community set -- this is used
           "Configuration parameters relating to
                 reference the set in match conditions"; global BGP router";
         uses bgp-global-config;
       }
             leaf-list community-member {
               type union
       container state {
                 type bgp-types:bgp-std-community-type;
                 type bgp-types:bgp-community-regexp-type;
                 type bgp-types:bgp-well-known-community-type;
               }
         config false;
         description
                 "members of
           "State information relating to the community set";
             }
           } global BGP router";
         uses bgp-global-config;
         uses bgp-global-state;
       }

       container ext-community-sets default-route-distance {
         description
             "Enclosing
           "Administrative distance (or preference) assigned to
           routes received from different sources
           (external, internal, and local).";

         container for extended community sets";
           list ext-community-set config {
             key ext-community-set-name;
           description
                 "Definitions for extended community sets";
             leaf ext-community-set-name
             "Configuration parameters relating to the default route
             distance";
           uses bgp-global-default-route-distance-config;
         }
         container state {
               type string;
           config false;
           description
                 "name / label of the extended community set -- this is
                 used
             "State information relating to reference the set in match conditions"; default route distance";
           uses bgp-global-default-route-distance-config;
         }
             leaf-list ext-community-member
       }

       container confederation {
               type union
         description
           "Parameters indicating whether the local system acts as part
           of a BGP confederation";

         container config {
                 type bgp-types:bgp-ext-community-type;
                 // TODO: is regexp support needed for extended
                 // communities?
                 type bgp-types:bgp-community-regexp-type;
           description
             "Configuration parameters relating to BGP confederations";
           uses bgp-global-confederation-config;
         }
         container state {
           config false;
           description
                   "members of
             "State information relating to the extended community set";
             } BGP confederations";
           uses bgp-global-confederation-config;
         }
       }

       container as-path-sets {
           description
             "Enclosing container for AS path sets";
           list as-path-set graceful-restart {
             key as-path-set-name;
         description
                 "Definitions
           "Parameters relating the graceful restart mechanism for AS path sets";
             leaf as-path-set-name BGP";
         container config {
               type string;
           description
                 "name of the AS path set -- this is used
             "Configuration parameters relating to reference
                 the set in match conditions"; graceful-restart";
           uses bgp-common-graceful-restart-config;

         }
             leaf-list as-path-set-member
         container state {
               // TODO: need to refine typedef for AS path expressions
               type string;
           config false;
           description
                   "AS path expression -- list of ASes in the set";
             "State information associated with graceful-restart";
           uses bgp-common-graceful-restart-config;
         }
       }

       uses bgp-common-global-group-use-multiple-paths;
       uses bgp-common-route-selection-options;

       container afi-safis {
         description
           "Address family specific configuration";
         uses bgp-global-afi-safi-list;
       }
     }

   }
     augment "/rpol:routing-policy/rpol:policy-definitions/" +
       "rpol:policy-definition/rpol:statements/rpol:statement/" +
       "rpol:conditions"
   <CODE ENDS>

8.  BGP types

   <CODE BEGINS> file "ietf-bgp-types.yang"

   module ietf-bgp-types {
       description "BGP policy conditions added to routing policy
       module";
       container bgp-conditions
     yang-version "1";

     namespace "urn:ietf:params:xml:ns:yang:ietf-bgp-types";

     prefix "oc-bgp-types";

     import ietf-inet-types { prefix inet; }
     import openconfig-types { prefix oc-types; }
     import openconfig-extensions { prefix oc-ext; }

     // meta
     organization
       "OpenConfig working group";

     contact
       "OpenConfig working group
       netopenconfig@googlegroups.com";

     description "Policy conditions
       "This module contains general data definitions for matching
         BGP-specific defined sets or comparing BGP-specific use in BGP
       policy. It can be imported by modules that make use of BGP
       attributes";
         uses bgp-match-conditions;
         uses bgp-attribute-conditions;
       }
     }
     augment "/rpol:routing-policy/rpol:policy-definitions/" +
       "rpol:policy-definition/rpol:statements/rpol:statement/" +
       "rpol:actions"

     oc-ext:openconfig-version "2.1.1";

     revision "2016-06-21" {
       description "BGP policy actions added to routing policy
       module";
       container bgp-actions
         "OpenConfig BGP refactor";
       reference "2.1.1";
     }

     identity BGP_CAPABILITY {
       description
           "Definitions "Base identity for policy action statements that
           change BGP-specific attributes of the route";
         container set-as-path-prepend a BGP capability";
     }

     identity MPBGP {
           presence "node is present in the config data to use the AS
         prepend action";
       base BGP_CAPABILITY;
       description
               "action
         "Multi-protocol extensions to prepend local BGP";
       reference "RFC2858";
     }

     identity ROUTE_REFRESH {
       base BGP_CAPABILITY;
       description
         "The BGP route-refresh functionality";
       reference "RFC2918";
     }

     identity ASN32 {
       base BGP_CAPABILITY;
       description
         "4-byte (32-bit) AS number to the AS-path a
           specified number of times";
           leaf repeat-n functionality";
       reference "RFC6793";
     }

     identity GRACEFUL_RESTART {
             type uint8;
       base BGP_CAPABILITY;
       description "number of times to prepend the local AS
             number";
         "Graceful restart functionality";
       reference "RFC4724";
     }

     identity ADD_PATHS {
       base BGP_CAPABILITY;
       description
         "BGP add-paths";

       reference "draft-ietf-idr-add-paths";
     }
         container set-community

     identity AFI_SAFI_TYPE {
           presence "node is present in the config data when
           set-community action is used";
       description
             "action to set the community attributes of the route, along
             with options to modify how the community is modified";
           choice set-community-method
         "Base identity type for AFI,SAFI tuples for BGP-4";
       reference "RFC4760 - multiprotocol extensions for BGP-4";
     }

     identity IPV4_UNICAST {
       base AFI_SAFI_TYPE;
       description
               "Option to set communities using an inline list or
         "IPv4 unicast (AFI,SAFI = 1,1)";
       reference to an existing defined set.";
             case inline "RFC4760";
     }

     identity IPV6_UNICAST {
               leaf-list communities
       base AFI_SAFI_TYPE;
       description
         "IPv6 unicast (AFI,SAFI = 2,1)";
       reference "RFC4760";
     }

     identity IPV4_LABELED_UNICAST {
                 type union
       base AFI_SAFI_TYPE;
       description
         "Labeled IPv4 unicast (AFI,SAFI = 1,4)";
       reference "RFC3107";
     }

     identity IPV6_LABELED_UNICAST {
                   type bgp-types:bgp-std-community-type;
                   type bgp-types:bgp-well-known-community-type;
       base AFI_SAFI_TYPE;
       description
         "Labeled IPv6 unicast (AFI,SAFI = 2,4)";
       reference "RFC3107";
     }

     identity L3VPN_IPV4_UNICAST {
       base AFI_SAFI_TYPE;
       description
                   "Set the community values for the update inline with
                   a list.";
         "Unicast IPv4 MPLS L3VPN (AFI,SAFI = 1,128)";
       reference "RFC4364";
     }

     identity L3VPN_IPV6_UNICAST {
       base AFI_SAFI_TYPE;
       description
         "Unicast IPv6 MPLS L3VPN (AFI,SAFI = 2,128)";

       reference "RFC4659";
     }
             case

     identity L3VPN_IPV4_MULTICAST {
       base AFI_SAFI_TYPE;
       description
         "Multicast IPv4 MPLS L3VPN (AFI,SAFI = 1,129)";
       reference "RFC6514";
     }

     identity L3VPN_IPV6_MULTICAST {
               leaf community-set-ref
       base AFI_SAFI_TYPE;
       description
         "Multicast IPv6 MPLS L3VPN (AFI,SAFI = 2,129)";
       reference "RFC6514";
     }

     identity L2VPN_VPLS {
                 type leafref
       base AFI_SAFI_TYPE;
       description
         "BGP-signalled VPLS (AFI,SAFI = 25,65)";
       reference "RFC4761";
     }

     identity L2VPN_EVPN {
                   path "/rpol:routing-policy/rpol:defined-sets/" +
                     "bgp-pol:bgp-defined-sets/" +
                     "bgp-pol:community-sets/bgp-pol:community-set/" +
                     "bgp-pol:community-set-name";
                   require-instance true;
       base AFI_SAFI_TYPE;
       description
         "BGP MPLS Based Ethernet VPN (AFI,SAFI = 25,70)";
     }

     identity BGP_WELL_KNOWN_STD_COMMUNITY {
       description
                   "References a defined
         "Reserved communities within the standard community set space
         defined by name";
               }
             } RFC1997. These communities must fall within the
         range 0x00000000 to 0xFFFFFFFF";
       reference "RFC1997";
     }
           leaf options

     identity NO_EXPORT {
             type bgp-set-community-option-type;
       base BGP_WELL_KNOWN_STD_COMMUNITY;
       description
               "Options for modifying the
         "Do not export NLRI received carrying this community attribute with outside
         the specified values.  These options apply to both
               methods bounds of setting this autonomous system, or this confederation if
         the local autonomous system is a confederation member AS. This
         community attribute.";
           } has a value of 0xFFFFFF01.";
       reference "RFC1997";
     }
         container set-ext-community
     identity NO_ADVERTISE {
           presence "node is present in the config data when
           set-community action is used";
       base BGP_WELL_KNOWN_STD_COMMUNITY;
       description
             "Action to set the extended
         "All NLRI received carrying this community attributes of the
             route, along with options must not be
         advertised to modify how the other BGP peers. This community is
             modified";
           choice set-ext-community-method has a value of
         0xFFFFFF02.";
       reference "RFC1997";
     }

     identity NO_EXPORT_SUBCONFED {
       base BGP_WELL_KNOWN_STD_COMMUNITY;
       description
               "Option
         "All NLRI received carrying this community must not be
         advertised to set communities using an inline list or external BGP peers - including over confederation
         sub-AS boundaries. This community has a value of 0xFFFFFF03.";
       reference to an existing defined set.";
             case inline {
               leaf-list communities {
                 type union {
                   type bgp-types:bgp-ext-community-type;
                   type bgp-types:bgp-well-known-community-type; "RFC1997";
     }

     identity NOPEER {
       base BGP_WELL_KNOWN_STD_COMMUNITY;
       description
                   "Set the
         "An autonomous system receiving NLRI tagged with this community values for
         is advised not to readvertise the update inline NLRI to external bi-lateral
         peer autonomous systems. An AS may also filter received NLRI
         from bilateral peer sessions when they are tagged with
                   a list.";
               }
             }
             case this
         community value";
       reference {
               leaf ext-community-set-ref "RFC3765";
     }

     typedef bgp-session-direction {
       type leafref enumeration {
         enum INBOUND {
                   path "/rpol:routing-policy/rpol:defined-sets/" +
                     "bgp-pol:bgp-defined-sets/" +
                     "bgp-pol:ext-community-sets/" +
                     "bgp-pol:ext-community-set/" +
                     "bgp-pol:ext-community-set-name";
                   require-instance true;
                 }
           description
                   "References a defined extended community set by
                   name";
               }
             }
             "Refers to all NLRI received from the BGP peer";
         }
           leaf options
         enum OUTBOUND {
             type bgp-set-community-option-type;
           description
               "options for modifying the extended community
               attribute with the specified values. These options
               apply
             "Refers to all NLRI advertised to both methods of setting the community
               attribute."; BGP peer";
         }
       }
         leaf set-route-origin {
           type bgp-types:bgp-origin-attr-type;
       description "set the origin attribute
         "Type to describe the specified
           value"; direction of NLRI transmission";
     }
         leaf set-local-pref

     typedef bgp-well-known-community-type {
       type uint32; identityref {
         base BGP_WELL_KNOWN_STD_COMMUNITY;
       }
       description "set the local pref
         "Type definition for well-known IETF community attribute on the route
           update";
         values";
       reference
         "IANA Border Gateway Protocol (BGP) Well Known Communities";
     }
         leaf set-next-hop

     typedef bgp-std-community-type {
       // TODO: further refine restrictions and allowed patterns
       // 4-octet value:
       //  <as number> 2 octets
       //  <community value> 2 octets
       type union {
         type bgp-next-hop-type;
           description "set the next-hop attribute in the route update";
         }
         leaf set-med uint32 {
         // per RFC 1997, 0x00000000 - 0x0000FFFF and 0xFFFF0000 -
         // 0xFFFFFFFF are reserved
           range "65536..4294901759"; // 0x00010000..0xFFFEFFFF
         }
         type bgp-set-med-type; string {
           pattern '([0-9]+:[0-9]+)';
         }
       }
       description "set
         "Type definition for standard commmunity attributes";
       reference "RFC 1997 - BGP Communities Attribute";
     }

     typedef bgp-ext-community-type {
       // TODO: needs more work to make this more precise given the med metric
       // variability of extended community attribute in the route
           update";
         } specifications
       // 8-octet value:
       //  <type> 2 octects
       //  <value> 6 octets

       type union {
         type string {
           // Type 1: 2-octet global and 4-octet local
           //         (AS number)        (Integer)
           pattern '(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]|[1-9])';
         }
         type string {
           // Type 2: 4-octet global and 2-octet local
           //         (ipv4-address)     (integer)
           pattern '(([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])';
         }
         type string {
           // rpc statements route-target with Type 1
           // notification statements route-target:(ASN):(local-part)
           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]|[1-9])';
         }
   <CODE ENDS>

6.4.  BGP multiprotocol items

   <CODE BEGINS> file "ietf-bgp-multiprotocol.yang"
   module ietf-bgp-multiprotocol
         type string {
     yang-version "1";
           // namespace
     namespace "urn:ietf:params:xml:ns:yang:ietf-bgp-multiprotocol";
     prefix "bgp-mp"; route-target with Type 2
           // import some basic inet types
     import ietf-routing-policy { prefix rpol; route-target:(IPv4):(local-part)
           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])';
         }
     import ietf-bgp-types
         type string { prefix bgp-types;
           // route-origin with Type 1
           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]|[1-9])';
         }
     import ietf-bgp-operational
         type string { prefix bgp-op; }
           // meta
     organization
       "OpenConfig working group";
     contact
       "OpenConfig working group
       netopenconfig@googlegroups.com"; route-origin with Type 2
           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
       "This module is part of a YANG model
         "Type definition for extended community attributes";
       reference "RFC 4360 - BGP protocol
       configuration, focusing on configuration of multiprotocol
       BGP, in particular various relevant address families (AFI) and
       sub-address families (SAFI).
       Identities (rather than enumerated types) are used Extended Communities Attribute";
     }

     typedef bgp-community-regexp-type {
       // TODO: needs more work to identify
       each AFI / SAFI decide what format these regexps can
       // take.

       type to make it easier for users to extend to
       pre-standard or custom AFI/SAFI types.  This module is only
       intended to capture the most";
     revision "2016-01-06" { oc-types:std-regexp;
       description
         "Updated filename and namespace";
       reference "TBD";
         "Type definition for communities specified as regular
         expression patterns";
     }
     grouping ipv4-unicast-group

     typedef bgp-origin-attr-type {
       description
         "Group for IPv4 Unicast configuration options";
       container ipv4-unicast
       type enumeration {
         when "../afi-safi-name = 'bgp-mp:ipv4-unicast'"
         enum IGP {
           description
             "Include this container for IPv4 Unicast specific
             configuration";
         }
         description "IPv4 unicast configuration options";
         // include common IPv[46] unicast options
         uses ipv4-ipv6-unicast-common;
         // placeholder for IPv4 unicast  specific configuration
       } "Origin of the NLRI is internal";
         }
     grouping ipv6-unicast-group
         enum EGP {
           description
         "Group for IPv6 Unicast configuration options";
       container ipv6-unicast {
         when "../afi-safi-name = 'bgp-mp:ipv6-unicast'" "Origin of the NLRI is EGP";
         }
         enum INCOMPLETE {
           description
             "Include this container for IPv6 Unicast specific
             configuration"; "Origin of the NLRI is neither IGP or EGP";
         }
       }
       description "IPv6 unicast configuration options";
         // include common IPv[46] unicast options
         uses ipv4-ipv6-unicast-common;
         // placeholder
         "Type definition for IPv6 unicast specific configuration
         // options
       } standard BGP origin attribute";
       reference "RFC 4271 - A Border Gateway Protocol 4 (BGP-4),
         Sec 4.3";
     }
     grouping ipv4-labelled-unicast-group

     typedef peer-type {
       description
         "Group for IPv4 Labelled Unicast configuration options";
       container ipv4-labelled-unicast
       type enumeration {
         when "../afi-safi-name = 'bgp-mp:ipv4-labelled-unicast'"
         enum INTERNAL {
           description
             "Include this container for IPv4 Labelled Unicast specific
             configuration"; "internal (iBGP) peer";
         }
         enum EXTERNAL {
           description "IPv4 Labelled Unicast configuration options";
         uses all-afi-safi-common;
         // placeholder for IPv4 Labelled Unicast specific config
         // options "external (eBGP) peer";
         }
       }
     grouping ipv6-labelled-unicast-group {
       description
         "Group for IPv6 Labelled Unicast configuration options";
       container ipv6-labelled-unicast {
         when "../afi-safi-name = 'bgp-mp:ipv6-labelled-unicast'"
         "labels a peer or peer group as explicitly internal or
         external";
     }

     identity REMOVE_PRIVATE_AS_OPTION {
       description
             "Include this container
         "Base identity for IPv6 Labelled Unicast specific
             configuration";
         }
         description "IPv6 Labelled Unicast configuration options";
         uses all-afi-safi-common;
         // placeholder options for IPv6 Labelled Unicast specific config
         // options.
       } removing private autonomous
         system numbers from the AS_PATH attribute";
     }
     grouping l3vpn-ipv4-unicast-group

     identity PRIVATE_AS_REMOVE_ALL {
       base REMOVE_PRIVATE_AS_OPTION;
       description
         "Group
         "Strip all private autonmous system numbers from the AS_PATH.

         This action is performed regardless of the other content of the
         AS_PATH attribute, and for IPv4 Unicast L3VPN configuration options";

       container l3vpn-ipv4-unicast {
         when "../afi-safi-name = 'bgp-mp:l3vpn-ipv4-unicast'" all instances of private AS numbers
         within that attribute.";
     }

     identity PRIVATE_AS_REPLACE_ALL {
       base REMOVE_PRIVATE_AS_OPTION;
       description
             "Include this container
         "Replace all instances of private autonomous system numbers in
         the AS_PATH with the local BGP speaker's autonomous system
         number. This action is performed regardless of the other
         content of the AS_PATH attribute, and for IPv4 Unicast L3VPN specific
             configuration"; all instances of
         private AS number within that attribute.";
     }

     typedef remove-private-as-option {
       type identityref {
         base REMOVE_PRIVATE_AS_OPTION;
       }
       description "Unicast IPv4 L3VPN configuration options";
         // include common L3VPN configuration
         "set of options
         uses l3vpn-ipv4-ipv6-unicast-common;
         // placeholder for IPv4 Unicast L3VPN specific config options.
       } configuring how private AS path numbers
         are removed from advertisements";
     }
     grouping l3vpn-ipv6-unicast-group

     typedef percentage {
       type uint8 {
         range "0..100";
       }
       description
         "Group for IPv6 Unicast L3VPN configuration options";
       container l3vpn-ipv6-unicast
         "Integer indicating a percentage value";
     }

     typedef rr-cluster-id-type {
         when "../afi-safi-name = 'bgp-mp:l3vpn-ipv6-unicast'"
       type union {
           description
             "Include this container for unicast IPv6 L3VPN specific
             configuration";
         type uint32;
         type inet:ipv4-address;
       }
       description "Unicast IPv6 L3VPN configuration options";
         // include common L3VPN configuration options
         uses l3vpn-ipv4-ipv6-unicast-common;
         // placeholder
         "union type for IPv6 Unicast L3VPN specific configuration
         // options route reflector cluster ids:
         option 1: 4-byte number
         option 2: IP address";
     }

     typedef community-type {
       type enumeration {
         enum STANDARD {
           description "send only standard communities";
         }
     grouping l3vpn-ipv4-multicast-group
         enum EXTENDED {
           description
         "Group for IPv4 L3VPN multicast configuration options";
       container l3vpn-ipv4-multicast "send only extended communities";
         }
         enum BOTH {
         when "../afi-safi-name = 'bgp-mp:l3vpn-ipv4-multicast'"
           description "send both standard and extended communities";
         }
         enum NONE {
           description
             "Include this container for multicast IPv6 L3VPN specific
             configuration"; "do not send any community attribute";
         }
       }
       description "Multicast IPv4 L3VPN configuration options";
         // include common L3VPN multicast options
         uses l3vpn-ipv4-ipv6-multicast-common;
         "type describing variations of community attributes:
         STANDARD: standard BGP community [rfc1997]
         EXTENDED: extended BGP community [rfc4360]
         BOTH: both standard and extended community";
     }
   }

   <CODE ENDS>

9.  BGP policy data

    <CODE BEGINS> file "ietf-bgp-policy.yang"

module ietf-bgp-policy {

  yang-version "1";

  // placeholder for IPv4 Multicast L3VPN specific configuration namespace
  namespace "urn:ietf:params:xml:ns:yang:ietf-bgp-policy";

  prefix "oc-bgp-pol";

  // options import some basic types
  import ietf-inet-types { prefix inet; }
  import ietf-routing-policy {prefix rpol; }
     grouping l3vpn-ipv6-multicast-group
  import openconfig-policy-types {
       description
         "Group for IPv6 L3VPN multicast configuration options";
       container l3vpn-ipv6-multicast prefix pol-types; }
  import ietf-bgp-types {
         when "../afi-safi-name = 'bgp-mp:l3vpn-ipv6-multicast'" prefix oc-bgp-types; }
  import openconfig-extensions {
           description
             "Include this container for multicast IPv6 L3VPN specific
             configuration"; prefix oc-ext; }
         description "Multicast IPv6 L3VPN configuration options";
         // include common L3VPN multicast options
         uses l3vpn-ipv4-ipv6-multicast-common;

  // placeholder meta
  organization
    "OpenConfig working group";

  contact
    "OpenConfig working group
    netopenconfig@googlegroups.com";

  description
    "This module contains data definitions for IPv6 Multicast L3VPN specific configuration
         // BGP routing policy.
    It augments the base routing-policy module with BGP-specific
    options for conditions and actions.";

  oc-ext:openconfig-version "2.1.1";

  revision "2016-06-21" {
    description
      "OpenConfig BGP refactor";
    reference "2.1.1";
  }
     }
     grouping l2vpn-vpls-group

  // typedef statements

  typedef bgp-set-community-option-type {
    type enumeration {
      enum ADD {
        description
         "Group for BGP-signalled VPLS configuration options";
       container l2vpn-vpls
          "add the specified communities to the existing
          community attribute";
      }
      enum REMOVE {
         when "../afi-safi-name = 'bgp-mp:l2vpn-vpls'"
        description
          "remove the specified communities from the
          existing community attribute";
      }
      enum REPLACE {
        description
             "Include
          "replace the existing community attribute with
          the specified communities. If an empty set is
          specified, this container for BGP-signalled VPLS specific
             configuration"; removes the community attribute
          from the route.";
      }
    }
    description "BGP-signalled VPLS configuration options";
         // include common L2VPN options
         uses l2vpn-common;
         // placeholder
      "Type definition for BGP-signalled VPLS specific configuration
         // options when setting the community
      attribute in a policy action";
  }
     }
     grouping l2vpn-evpn-group

  typedef bgp-next-hop-type {
       description
         "Group for BGP EVPN configuration options";
       container l2vpn-evpn
    type union {
         when "../afi-safi-name = 'bgp-mp:l2vpn-evpn'"
      type inet:ip-address-no-zone;
      type enumeration {
        enum SELF {
          description
             "Include this container for BGP EVPN specific
             configuration";
         }
         description "BGP EVPN configuration options";
         // include common L2VPN options
         uses l2vpn-common;
         // placeholder "special designation for BGP EVPN specific configuration options local router's own
          address, i.e., next-hop-self";
        }
      }
    }
     grouping bgp-route-selection-options_config {
    description
         "Set of configuration options that govern best
          path selection.";
       leaf always-compare-med
      "type definition for specifying next-hop in policy actions";
  }

  typedef bgp-set-med-type {
    type boolean;
         default "false"; union {
      type uint32;
      type string {
        pattern "^[+-][0-9]+";
      }
      type enumeration {
        enum IGP {
          description
           "Compare multi-exit discriminator (MED) value from
           different ASes when selecting "set the best route.  The
           default behavior is MED value to only compare MEDs the IGP cost toward the
          next hop for paths
           received from the same AS."; route";
        }
      }
    }
       leaf ignore-as-path-length {
         type boolean;
         default "false";
    description
           "Ignore the AS path length when selecting
      "Type definition for specifying how the best path. BGP MED can
      be set in BGP policy actions. The default is three choices are to use set
      the AS path length MED directly, increment/decrement using +/- notation,
      and prefer paths
           with shorter length.";
       }
       leaf external-compare-router-id {
         type boolean;
         default "true";
         description
           "When comparing similar routes received from external
           BGP peers, use the router-id as a criterion setting it to select the active path."; IGP cost (predefined value).";
  }

  // grouping statements

  grouping match-community-config {
    description
      "Configuration data for match conditions on communities";

    leaf advertise-inactive-routes community-set {
      type boolean;
         default "false"; leafref {
        path "/rpol:routing-policy/rpol:defined-sets/" +
          "oc-bgp-pol:bgp-defined-sets/oc-bgp-pol:community-sets/" +
          "oc-bgp-pol:community-set/oc-bgp-pol:community-set-name";
      }
      description
           "Advertise inactive routes to external peers.  The
           default is to only advertise active routes.";
        "References a defined community set";
    }
       leaf enable-aigp

    uses rpol:match-set-options-group;
  }
  grouping match-community-state {
         type boolean;
         default false;
    description
           "Flag to enable sending / receiving accumulated IGP
           attribute in routing updates";
      "Operational state data for match conditions on communities";
  }
       leaf ignore-next-hop-igp-metric

  grouping match-community-top {
    description
      "Top-level grouping for match conditions on communities";

    container match-community-set {
         type boolean;
         default "false";
      description
           "Ignore the IGP metric
        "Top-level container for match conditions on communities.
        Match a referenced community-set according to the next-hop when calculating
           BGP best-path. The default is to select logic
        defined in the route match-set-options leaf";

      container config {
        description
          "Configuration data for
           which the metric to the next-hop is lowest"; match conditions on communities";

        uses match-community-config;
      }

      container state {

        config false;

        description
          "Operational state data ";

        uses match-community-config;
        uses match-community-state;
      }
    }
  }

  grouping bgp-use-multiple-paths-ebgp-as-options_config match-ext-community-config {
    description
      "Configuration parameters specific to eBGP multipath applicable
         to all contexts"; data for match conditions on extended
      communities";

      leaf allow-multiple-as ext-community-set {
        type boolean;
        default "false"; leafref {
          path "/rpol:routing-policy/rpol:defined-sets/" +
            "oc-bgp-pol:bgp-defined-sets/oc-bgp-pol:ext-community-sets/" +
            "oc-bgp-pol:ext-community-set/" +
            "oc-bgp-pol:ext-community-set-name";
        }
        description
         "Allow multipath to use paths from different neighbouring
         ASes.  The default is to only consider multiple paths from
         the same neighbouring AS."; "References a defined extended community set";

      }

      uses rpol:match-set-options-group;
  }

  grouping bgp-use-multiple-paths-ebgp_config match-ext-community-state {
    description
         "Configuration parameters relating
      "Operational state data for match conditions on extended
      communities";
  }

  grouping match-ext-community-top {
    description
      "Top-level grouping for match conditions on extended
      communities";

    container match-ext-community-set {
      description
        "Match a referenced extended community-set according to multipath the
        logic defined in the match-set-options leaf";

      container config {
        description
          "Configuration data for eBGP"; match conditions on extended
          communities";

        uses bgp-use-multiple-paths-ebgp-as-options_config;
       leaf maximum-paths match-ext-community-config;
      }

      container state {
        type uint32;
        default 1;

        config false;

        description
         "Maximum number of parallel paths to consider when using
         BGP multipath. The default is use a single path.";
          "Operational state data for match conditions on extended
          communities";

        uses match-ext-community-config;
        uses match-ext-community-state;
      }
    }
  }

  grouping bgp-use-multiple-paths-ibgp_config match-as-path-config {
    description
      "Configuration parmaeters relating to multipath data for iBGP"; match conditions on AS path set";

    leaf maximum-paths as-path-set {
      type uint32;
         default 1;
         description
           "Maximum number of parallel paths to consider when using
           iBGP multipath. The default is to use leafref {
        path "/rpol:routing-policy/rpol:defined-sets/" +
          "oc-bgp-pol:bgp-defined-sets/oc-bgp-pol:as-path-sets/" +
          "oc-bgp-pol:as-path-set/oc-bgp-pol:as-path-set-name";
      }
      description "References a single path"; defined AS path set";
    }
    uses rpol:match-set-options-group;
  }

  grouping bgp-use-multiple-paths match-as-path-state {
    description
         "Configuration parameters relating to multipath
      "Operational state data for BGP - both
         iBGP and eBGP"; match conditions on AS path set";
  }

  grouping match-as-path-top {
    description
      "Top-level grouping for match conditions on AS path set";

    container use-multiple-paths match-as-path-set {
      description
           "Parameters related
        "Match a referenced as-path set according to the use of multiple paths for logic
        defined in the
           same NLRI"; match-set-options leaf";

      container config {
        description
          "Configuration parameters relating to multipath"; data for match conditions on AS path set";

        uses bgp-use-multiple-paths_config; match-as-path-config;
      }

      container state {

        config false;

        description
             "State parameters relating to multipath";
          "Operational state data for match conditions on AS
          path set";

        uses match-as-path-config;
        uses bgp-use-multiple-paths_config; match-as-path-state;
      }
         container ebgp
    }
  }

  grouping bgp-match-set-conditions {
    description
             "Multipath parameters
      "Condition statement definitions for eBGP";
           container config checking membership in a
      defined set";

    uses match-community-top;
    uses match-ext-community-top;
    uses match-as-path-top;
  }

  grouping community-count-config {
    description
      "Configuration parameters relating to eBGP multipath"; data for community count condition";

    uses bgp-use-multiple-paths-ebgp_config; pol-types:attribute-compare-operators;
  }
           container state

  grouping community-count-state {
             config false;
    description
               "State information relating to eBGP multipath";
             uses bgp-use-multiple-paths-ebgp_config;
           }
      "Operational state data for community count condition";
  }

  grouping community-count-top {
    description
      "Top-level grouping for community count condition";

    container ibgp community-count {
      description
             "Multipath parameters
        "Value and comparison operations for iBGP"; conditions based on the
        number of communities in the route update";

      container config {
        description
          "Configuration parameters relating to iBGP multipath"; data for community count condition";

        uses bgp-use-multiple-paths-ibgp_config; community-count-config;
      }

      container state {

        config false;

        description
               "State information relating to iBGP multipath";
          "Operational state data for community count condition";

        uses bgp-use-multiple-paths-ibgp_config;
           } community-count-config;
        uses community-count-state;
      }
    }
  }
  grouping bgp-use-multiple-paths-neighbor {
       description
         "Per-neighbor configuration for multipath for BGP";
       container use-multiple-paths {
         description
           "Parameters related to the use of multiple-paths for the same
           NLRI when they are received only from this neighbor";
         container config as-path-length-config {
    description
      "Configuration parameters relating to multipath"; data for AS path length condition";

    uses bgp-use-multiple-paths_config; pol-types:attribute-compare-operators;
  }
         container

  grouping as-path-length-state {
    description
      "Operational state data for AS path length condition";
  }

  grouping as-path-length-top {
    description
             "State parameters relating to multipath";
           uses bgp-use-multiple-paths_config;
         }
      "Top-level grouping for AS path length condition";

    container ebgp as-path-length {
      description
             "Multipath configuration
        "Value and comparison operations for eBGP"; conditions based on the
        length of the AS path in the route update";

      container config {
        description
          "Configuration parameters relating to eBGP multipath"; data for AS path length condition";

        uses bgp-use-multiple-paths-ebgp-as-options_config; as-path-length-config;
      }

      container state {

        config false;

        description
               "State information relating to eBGP multipath";
          "Operational state data for AS path length condition";

        uses bgp-use-multiple-paths-ebgp-as-options_config;
           } as-path-length-config;
        uses as-path-length-state;
      }
    }
  }

  grouping bgp-use-multiple-paths_config bgp-conditions-config {
    description
         "Generic configuration options relating to use of multiple
         paths
      "Configuration data for a referenced AFI-SAFI, group or neighbor"; BGP-specific policy conditions";

    leaf enabled med-eq {
      type boolean;
         default false; uint32;
      description
           "Whether
        "Condition to check if the use received MED value is equal to
        the specified value";
    }

    leaf origin-eq {
      type oc-bgp-types: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 multiple paths next hop addresses to check for in the route
        update";
    }

    leaf-list afi-safi-in {
      type identityref {
        base oc-bgp-types:AFI_SAFI_TYPE;
      }
      description
        "List of address families which the same NLRI is
           enabled may be
        within";
    }

    leaf local-pref-eq {
      type uint32;
      // TODO: add support for other comparisons if needed
      description
        "Condition to check if the neighbor. This value local pref attribute is overridden by
           any more specific configuration value."; 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";
    }

  }

  grouping bgp-conditions-state {
    description
      "Operational state data for BGP-specific policy conditions";
  }

  grouping bgp-afi-safi-graceful-restart_config bgp-conditions-top {
    description
         "BGP graceful restart parameters that apply on a per-AFI-SAFI
         basis";
       leaf enabled
      "Top-level grouping for BGP-specific policy conditions";

    container bgp-conditions {
         type boolean;
         default
      description
        "Top-level container ";

      container config {
        description
          "Configuration data for BGP-specific policy conditions";

        uses bgp-conditions-config;
      }

      container state {

        config false;

        description
           "This leaf indicates whether graceful-restart is enabled
          "Operational state data for
           this AFI-SAFI"; BGP-specific policy
          conditions";

        uses bgp-conditions-config;
        uses bgp-conditions-state;
      }

      uses community-count-top;
      uses as-path-length-top;
      uses bgp-match-set-conditions;
    }
  }

  grouping bgp-afi-safi_config community-set-config {
    description
      "Configuration parameters used data for all BGP AFI-SAFIs"; community sets";

    leaf afi-safi-name community-set-name {
      type identityref {
           base bgp-types:afi-safi-type;
         } string;
      mandatory true;
      description "AFI,SAFI";
        "name / label of the community set -- this is used to
        reference the set in match conditions";
    }
       leaf enabled

    leaf-list community-member {
      type boolean;
         default false; union {
        type oc-bgp-types:bgp-std-community-type;
        type oc-bgp-types:bgp-community-regexp-type;
        type oc-bgp-types:bgp-well-known-community-type;
      }
      description
           "This leaf indicates whether the IPv4 Unicast AFI,SAFI is
           enabled for
        "members of the neighbour or group"; community set";
    }
  }

  grouping all-afi-safi-common-prefix-limit_config community-set-state {
    description
         "Configuration parameters relating to prefix-limits
      "Operational state data for an
         AFI-SAFI";
       leaf max-prefixes BGP community sets";
  }

  grouping community-set-top {
         type uint32;
    description
           "Maximum number of prefixes that will be accepted
           from the neighbour";
       }
       leaf shutdown-threshold-pct
      "Top-level grouping for BGP community sets";

    container community-sets {
         type bgp-types:percentage;
      description
           "Threshold on number of prefixes that can be received
           from a neighbour before generation
        "Enclosing container for list of warning messages
           or log entries. Expressed as a percentage defined BGP community sets";

      list community-set {
        key "community-set-name";
        description
          "List of
           max-prefixes";
       } defined BGP community sets";

        leaf restart-timer community-set-name {
          type decimal64 leafref {
           fraction-digits 2;
            path "../config/community-set-name";
          }
         units "seconds";
          description
           "Time interval in seconds after which the
            "Reference to list key";
        }

        container config {
          description
            "Configuration data for BGP community sets";

          uses community-set-config;
        }
        container state {

          config false;

          description
            "Operational state data for BGP session
           is re-established after being torn down due to exceeding
           the max-prefix limit."; community sets";

          uses community-set-config;
          uses community-set-state;
        }
      }
    }
  }

  grouping ipv4-ipv6-unicast-common_config ext-community-set-config {
    description
         "Common configuration parameters
      "Configuration data for IPv4 and IPv6 Unicast
         address families"; extended BGP community sets";

    leaf send-default-route ext-community-set-name {
      type boolean;
         default "false"; string;
      description
           "If
        "name / label of the extended community set -- this is
        used to true, send reference the default-route to set in match conditions";
    }

    leaf-list ext-community-member {
      type union {
        type oc-bgp-types:bgp-ext-community-type;
        type oc-bgp-types:bgp-community-regexp-type;
      }
      description
          "members of the neighbour(s)"; extended community set";
    }
  }

  grouping all-afi-safi-common ext-community-set-state {
    description
         "Grouping
      "Operational state data for configuration common to all AFI,SAFI"; extended BGP community sets";
  }

  grouping ext-community-set-top {
    description
      "Top-level grouping for extended BGP community sets";

    container prefix-limit ext-community-sets {
      description
           "Configure the maximum number
        "Enclosing container for list of prefixes that will be
           accepted from a peer"; 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 leafref {
            path "../config/ext-community-set-name";
          }
          description
            "Reference to list key";
        }

        container config {
          description
            "Configuration parameters relating to the prefix
             limit data for the AFI-SAFI"; extended BGP community sets";

          uses all-afi-safi-common-prefix-limit_config; ext-community-set-config;
        }

        container state {

          config false;

          description
             "State information relating to the prefix-limit
            "Operational state data for the
             AFI-SAFI"; extended BGP community sets";

          uses all-afi-safi-common-prefix-limit_config; ext-community-set-config;
          uses ext-community-set-state;
        }
      }
    }
  }

  grouping ipv4-ipv6-unicast-common {
       description
         "Common configuration that is applicable for IPv4 and IPv6
         unicast";
       // include common afi-safi options.
       uses all-afi-safi-common;
       // configuration options that are specific to IPv[46] unicast
       container config as-path-set-config {
    description
      "Configuration parameters data for common IPv4 and IPv6 unicast
           AFI-SAFI options";
         uses ipv4-ipv6-unicast-common_config;
       }
       container state AS path sets";

    leaf as-path-set-name {
         config false;
      type string;
      description
           "State information for common IPv4 and IPv6 unicast
           parameters";
         uses ipv4-ipv6-unicast-common_config;
       }
        "name of the AS path set -- this is used to reference
        the set in match conditions";
    }
     grouping l3vpn-ipv4-ipv6-unicast-common

    leaf-list as-path-set-member {
       description
         "Common configuration applied across L3VPN for IPv4
          and IPv6";
      // placeholder TODO: need to refine typedef for AS path expressions
      type string;
      description
          "AS path expression -- specific configuration options that are generic
       // across IPv[46] unicast address families.
       uses all-afi-safi-common; list of ASes in the set";
    }
  }

  grouping l3vpn-ipv4-ipv6-multicast-common as-path-set-state {
    description
         "Common configuration applied across L3VPN
      "Operational state data for IPv4
         and IPv6";
       // placeholder -- specific configuration options that are
       // generic across IPv[46] multicast address families.
       uses all-afi-safi-common; AS path sets";
  }

  grouping l2vpn-common as-path-set-top {
    description
         "Common configuration applied across L2VPN address
         families";
       // placeholder -- specific configuration options that are
       // generic across L2VPN address families
       uses all-afi-safi-common;
     }
      "Top-level grouping bgp-route-selection-options for AS path sets";

    container as-path-sets {
      description
         "Parameters relating to the BGP route selection process";
        "Enclosing container route-selection-options for list of define AS path sets";

      list as-path-set {
        key "as-path-set-name";
        description
           "Parameters relating
          "List of defined AS path sets";

        leaf as-path-set-name {
          type leafref {
            path "../config/as-path-set-name";
          }
          description
            "Reference to options for route selection"; list key";
        }

        container config {
          description
            "Configuration parameters relating to route selection
             options"; data for AS path sets";

          uses bgp-route-selection-options_config; as-path-set-config;
        }

        container state {

          config false;

          description
             "State information
            "Operational state data for the route selection options"; AS path sets";

          uses bgp-route-selection-options_config; as-path-set-config;
          uses as-path-set-state;
        }

      }
    }
  }

  // *********** STRUCTURE GROUPINGS **********************
     grouping bgp-global-afi-safi augment statements

  augment "/rpol:routing-policy/rpol:defined-sets" {
    description
         "Parameters and route selection options for MP-BGP
         specific "adds BGP defined sets container to the Global AFI-SAFI";
       uses bgp-route-selection-options;
     }
     grouping bgp-group-afi-safi routing policy
    model";

    container bgp-defined-sets {
      description
         "Parameters and route selection options
        "BGP-related set definitions for MP-BGP
         specific to peer groups"; policy match conditions";

      uses community-set-top;
      uses bgp-route-selection-options; ext-community-set-top;
      uses as-path-set-top;
    }
  }

  grouping bgp-common-afi-safi-list {
       description
         "List of address-families associated with the BGP instance,
         a peer-group or neighbor";
       list afi-safi as-path-prepend-config {
         key "afi-safi-name";
    description
           "AFI,SAFI configuration available
      "Configuration data for the
           neighbour or group"; AS path prepend action";

    leaf afi-safi-name repeat-n {
      type leafref uint8 {
             path "../config/afi-safi-name";
        range 1..max;
      }
      description
             "Reference
        "Number of times to prepend the AFI-SAFI name used as a key
             for local AS number to the AFI-SAFI list"; AS
        path.  The value should be between 1 and the maximum
        supported by the implementation.";
    }
         container graceful-restart
  }

  grouping as-path-prepend-state {
    description
             "Parameters relating to BGP graceful-restart";
           container config
      "Operational state data for the AS path prepend action";
  }

  grouping as-path-prepend-top {
    description
               "Configuration options
      "Top-level grouping for BGP graceful-restart";
             uses bgp-afi-safi-graceful-restart_config;
           } the AS path prepend action";

    container state set-as-path-prepend {
             config false;
      description
               "State information for BGP graceful-restart";
             uses bgp-afi-safi-graceful-restart_config;
           }
         }
        "action to prepend local AS number to the AS-path a
        specified number of times";

      container config {
        description
          "Configuration parameters data for the AFI-SAFI"; AS path prepend action";

        uses bgp-afi-safi_config; as-path-prepend-config;
      }

      container state {

        config false;

        description
             "State information relating to the AFI-SAFI";
           uses bgp-afi-safi_config;
           uses bgp-op:bgp-afi-safi_state;
         }
         // import and export policy included
          "Operational state data for the afi/safi
         uses rpol:apply-policy-group;
         uses ipv4-unicast-group;
         uses ipv6-unicast-group;
         uses ipv4-labelled-unicast-group;
         uses ipv6-labelled-unicast-group;
         uses l3vpn-ipv4-unicast-group;
         uses l3vpn-ipv6-unicast-group;
         uses l3vpn-ipv4-multicast-group;
         uses l3vpn-ipv6-multicast-group; AS path prepend action";

        uses l2vpn-vpls-group; as-path-prepend-config;
        uses l2vpn-evpn-group;
       }
     }
   }
   <CODE ENDS>

6.5.  BGP operational data items

   <CODE BEGINS> file "ietf-bgp-operational.yang"
   module ietf-bgp-operational {
     yang-version "1";

     namespace "urn:ietf:params:xml:ns:yang:ietf-bgp-operational";
     prefix "bgp-op";
     // import some basic inet types
     import ietf-inet-types { prefix inet; as-path-prepend-state;
      }
     import ietf-yang-types { prefix yang; }
     import ietf-bgp-types { prefix bgp-types;
    }
     // meta
     organization
       "OpenConfig working group";
     contact
       "OpenConfig working group
       netopenconfig@googlegroups.com";
     description
       "This module is part of a YANG model for BGP protocol
       configuration, focusing on operational data (i.e., state
       variables) related to BGP operations";
     revision "2016-01-06" {
       description
         "Updated filename and namespace";
       reference "TBD";
  }
     // extension statements
     // feature statements
     // identity statements
     // typedef statements
     // grouping statements

  grouping bgp-counters-message-types_common {
       description
         "Grouping of BGP message types, included for re-use
         across counters";
       leaf UPDATE set-community-action-common {
         type uint64;
         description
           "Number of BGP UPDATE messages announcing, withdrawing
           or modifying paths exchanged.";
       }
    description
      "Common leaves for set-community and set-ext-community
      actions";

    leaf NOTIFICATION method {
      type uint64; enumeration {
        enum INLINE {
          description
           "Number of BGP NOTIFICATION messages indicating an
           error condition has occurred exchanged.";
       }
            "The extended communities are specified inline as a
            list";
        }
     grouping bgp-context-pfx-path-counters_common
        enum REFERENCE {
          description
         "Grouping containing common counters relating
            "The extended communities are specified by referencing a
            defined ext-community set";
        }
      }
      description
        "Indicates the method used to prefixes and
         paths"; specify the extended
        communities for the set-ext-community action";
    }

    leaf total-paths options {
      type uint32; bgp-set-community-option-type;
      description
           "Total number
        "Options for modifying the community attribute with
        the specified values.  These options apply to both
        methods of BGP paths within setting the context"; community attribute.";
    }
       leaf total-prefixes
  }

  grouping set-community-inline-config {
    description
      "Configuration data for inline specification of set-community
      action";

    leaf-list communities {
      type uint32; union {
        type oc-bgp-types:bgp-std-community-type;
        type oc-bgp-types:bgp-well-known-community-type;
      }
      description
           "";
        "Set the community values for the update inline with
        a list.";
    }
  }

  grouping bgp-global_state set-community-inline-state {
    description
         "Grouping containing operational parameters relating to the
         global BGP instance";
       uses bgp-context-pfx-path-counters_common;
      "Operational state data or inline specification of
      set-community action";
  }

  grouping bgp-global-afi-safi_state set-community-inline-top {
    description
         "Grouping containing operational parameters relating to each
         AFI-SAFI within
      "Top-level grouping or inline specification of set-community
      action";

    container inline {
      when "../config/method=INLINE" {
        description
          "Active only when the BGP global instance"; set-community method is INLINE";
      }
      description
        "Set the community values for the action inline with
        a list.";

      container config {
        description
          "Configuration data or inline specification of set-community
      action";

        uses bgp-context-pfx-path-counters_common; set-community-inline-config;
      }
     grouping bgp-peer-group_state
      container state {

        config false;

        description
         "Grouping containing operational parameters relating to a BGP
         peer group";
          "Operational state data or inline specification of
          set-community action";

        uses bgp-context-pfx-path-counters_common; set-community-inline-config;
        uses set-community-inline-state;
      }
    }
  }

  grouping bgp-neighbor_state set-community-reference-config {
    description
         "Grouping containing operational state variables relating to
      "Configuration data for referening a
         BGP neighbor"; community-set in the
      set-community action";

    leaf session-state community-set-ref {
      type enumeration leafref {
             enum IDLE
        path "/rpol:routing-policy/rpol:defined-sets/" +
          "oc-bgp-pol:bgp-defined-sets/" +
          "oc-bgp-pol:community-sets/oc-bgp-pol:community-set/" +
          "oc-bgp-pol:community-set-name";
      }
      description
        "References a defined community set by name";
    }
  }

  grouping set-community-reference-state {
    description
                 "neighbor is down, and in the Idle
      "Operational state of data for referening a community-set in the
                 FSM";
      set-community action";
  }
             enum CONNECT

  grouping set-community-reference-top {
    description
                 "neighbor is down, and the session is waiting
      "Top-level grouping for referening a community-set in the underlying transport session to be established";
             }
             enum ACTIVE
      set-community action";

    container reference {
      when "../config/method=REFERENCE" {
        description
                 "neighbor is down, and
          "Active only when the local system set-community method is awaiting REFERENCE";
      }
      description
        "Provide a conncetion from reference to a defined community set for the remote peer";
             }
             enum OPENSENT
        set-community action";

      container config {
        description
                 "neighbor is
          "Configuration data for referening a community-set in the process of being established.
                 The local system has sent an OPEN message";
      set-community action";

        uses set-community-reference-config;
      }
             enum OPENCONFIRM

      container state {

        config false;

        description
                 "neighbor is
          "Operational state data for referening a community-set
          in the process of being established.
                 The local system is awaiting a NOTIFICATION or
                 KEEPALIVE message"; set-community action";

        uses set-community-reference-config;
        uses set-community-reference-state;
      }
             enum ESTABLISHED {
               description
                 "neighbor is up - the BGP session with the peer is
                 established";
    }
  }

  grouping set-community-action-config {
    description
           "Operational state of
      "Configuration data for the BGP peer"; set-community action";

    uses set-community-action-common;
  }
       leaf-list supported-capabilities {
         type identityref

  grouping set-community-action-state {
           base bgp-types:bgp-capability;
         }
    description
           "BGP capabilities negotiated as supported with
      "Operational state data for the peer";
       } set-community action";
  }

  grouping bgp-neighbor-afi-safi_state set-community-action-top {
    description
         "Operational state on a per-AFI-SAFI basis
      "Top-level grouping for a BGP
         neighbor";
       leaf active the set-community action";

    container set-community {
         type boolean;
      description
           "This value indicates whether a particular AFI-SAFI has
           been succesfully negotiated with
        "Action to set the peer. An AFI-SAFI
           may be enabled in community attributes of the current running configuration, but a
           session restart route, along
        with options to modify how the community is modified.
        Communities may be required in order set using an inline list OR
        reference to negotiate an existing defined set (not both).";

      container config {
        description
          "Configuration data for the new
           capability.";
       } set-community action";

        uses bgp-neighbor-prefix-counters_state; set-community-action-config;
      }
     grouping bgp-neighbor-prefix-counters_state

      container state {

        config false;

        description
         "Counters
          "Operational state data for BGP neighbor sessions";
       container prefixes the set-community action";

        uses set-community-action-config;
        uses set-community-action-state;
      }

      uses set-community-inline-top;
      uses set-community-reference-top;
    }
  }

  grouping set-ext-community-inline-config {
    description "Prefix counters
      "Configuration data for the BGP session";
         leaf received inline specification of
      set-ext-community action";

    leaf-list communities {
      type uint32; union {
        type oc-bgp-types:bgp-ext-community-type;
        type oc-bgp-types:bgp-well-known-community-type;
      }
      description
             "The number of prefixes received from
        "Set the neighbor"; extended community values for the update inline
        with a list.";
    }
         leaf sent
  }

  grouping set-ext-community-inline-state {
           type uint32;
    description
             "The number
      "Operational state data or inline specification of prefixes advertised to the neighbor";
      set-ext-community action";
  }
         leaf installed

  grouping set-ext-community-inline-top {
           type uint32;
    description
             "The number
      "Top-level grouping or inline specification of advertised prefixes installed in set-ext-community
      action";

    container inline {
      when "../config/method=INLINE" {
        description
          "Active only when the
             Loc-RIB";
         }
       } set-community method is INLINE";
      }
     grouping bgp-neighbor-message-counters-sent_state {
      description
         "Counters relating to messages sent to
        "Set the extended community values for the action inline with
        a BGP neighbor"; list.";

      container config {
        description
          "Configuration data or inline specification of
          set-ext-community action";

        uses bgp-counters-message-types_common; set-ext-community-inline-config;
      }
     grouping bgp-neighbor-message-counters-received_state

      container state {

        config false;

        description
         "Counters relating to the mesages received from a BGP
         neighbor";
          "Operational state data or inline specification of
          set-ext-community action";

        uses bgp-counters-message-types_common; set-ext-community-inline-config;
        uses set-ext-community-inline-state;
      }
    }
  }

  grouping bgp-neighbor-queue-counters_state set-ext-community-reference-config {
    description
         "Counters relating to the message queues associated with
      "Configuration data for referening a extended community-set
      in the
         BGP peer"; set-ext-community action";

    leaf input ext-community-set-ref {
      type uint32;
         description
           "The number of messages received from the peer currently
           queued";
       }
       leaf output leafref {
         type uint32;
        path "/rpol:routing-policy/rpol:defined-sets/" +
          "oc-bgp-pol:bgp-defined-sets/" +
          "oc-bgp-pol:ext-community-sets/" +
          "oc-bgp-pol:ext-community-set/" +
          "oc-bgp-pol:ext-community-set-name";
      }
      description
           "The number of messages queued to be sent to the peer";
        "References a defined extended community set by
        name";
    }
  }

  grouping bgp-neighbor-transport_state set-ext-community-reference-state {
    description
      "Operational state parameters relating to the transport session
         used data for referening an extended
      community-set in the BGP session";
       leaf local-port set-ext-community action";
  }

  grouping set-ext-community-reference-top {
         type inet:port-number;
    description
           "Local TCP port being used
      "Top-level grouping for referening an extended community-set
      in the TCP session supporting
           the BGP session";
       }
       leaf remote-address set-community action";

    container reference {
      when "../config/method=REFERENCE" {
         type inet:ip-address;
        description
           "Remote port being used by
          "Active only when the peer set-community method is REFERENCE";
      }
      description
        "Provide a reference to an extended community set for the TCP session
           supporting the BGP session";
       }
       leaf remote-port
        set-ext-community action";

      container config {
         type inet:port-number;
        description
           "Remote address to which
          "Configuration data for referening an extended
          community-set in the BGP session has been
           established";
       } set-ext-community action";

        uses set-ext-community-reference-config;
      }
     grouping bgp-neighbor-error-handling_state

      container state {

        config false;

        description
          "Operational state parameters relating to enhanced error
         error handling data for BGP";
       leaf erroneous-update-messages referening an extended
          community-set in the set-ext-community action";

        uses set-ext-community-reference-config;
        uses set-ext-community-reference-state;
      }
    }
  }

  grouping set-ext-community-action-config {
         type uint32;
    description
           "The number of BGP UPDATE messages
      "Configuration data for which the
           treat-as-withdraw mechanism has been applied based
           on erroneous message contents";
       } set-ext-community action";

    uses set-community-action-common;
  }

  grouping bgp-neighbor-timers_state set-ext-community-action-state {
    description
      "Operational state parameters relating to BGP timers associated
         with data for the BGP session";
       leaf uptime set-ext-community action";
  }

  grouping set-ext-community-action-top {
         type yang:timeticks;
    description
           "This timer determines
      "Top-level grouping for the amount of time since set-ext-community action";

    container set-ext-community {
      description
        "Action to set the
           BGP last transitioned in or out extended community attributes of the Established
           state";
       }
       leaf negotiated-hold-time {
         type decimal64
        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).";

      container config {
           fraction-digits 2;
         }
        description
           "The negotiated hold-time
          "Configuration data for the BGP session";
       } set-ext-community action";

        uses set-ext-community-action-config;
      }
     grouping bgp-afi-safi_state

      container state {

        config false;

        description
          "Operational state information relevant to all address
         families that may be carried by the BGP session";
       // placeholder - options in this container are
       // valid in both data for the global and per-neighbor
       // paths set-ext-community action";

        uses set-ext-community-action-config;
        uses set-ext-community-action-state;
      }
      uses set-ext-community-inline-top;
      uses set-ext-community-reference-top;
    }
  }

  grouping bgp-afi-safi-graceful-restart_state bgp-actions-config {
    description
         "Operational state information relevant to graceful restart
      "Configuration data for BGP"; BGP-specific actions";

    leaf peer-restart-time set-route-origin {
      type uint16 {
           range 0..4096;
         } oc-bgp-types:bgp-origin-attr-type;
      description
           "The period of time (advertised by the peer) that "set the peer expects a restart of a BGP session origin attribute to
           take";
       }
       leaf peer-restarting {
         type boolean;
         description
           "This flag indicates whether the remote neighbor is currently
           in the process of restarting, and hence received routes are
           currently stale"; specified
      value";
    }

    leaf local-restarting set-local-pref {
      type boolean; uint32;
      description
           "This flag indicates whether "set the local neighbor is currently
           restarting. The flag is unset after all NLRI have been
           advertised to the peer, and pref attribute on the End-of-RIB (EOR) marker has
           been unset"; route
      update";
    }

    leaf mode set-next-hop {
      type enumeration {
           enum HELPER-ONLY { bgp-next-hop-type;
      description
               "The local router is operating in helper-only mode, and
               hence will not retain forwarding state during a local
               session restart, but will do so during a restart of "set the
               remote peer";
           }
           enum BILATERAL {
             description
               "The local router is operating next-hop attribute in both helper mode, and
               hence retains forwarding state during a remote restart,
               and also maintains forwarding state during local session
               restart";
           }
           enum REMOTE-HELPER {
             description
               "The local system is able to retain routes during restart
               but the remote system is only able to act as a helper";
           } route update";
    }

    leaf set-med {
      type bgp-set-med-type;
      description
           "Ths leaf indicates "set the mode of operation of BGP graceful
           restart with med metric attribute in the peer"; route
      update";
    }
  }

  grouping bgp-neighbor-afi-safi-graceful-restart_state bgp-actions-state {
    description
      "Operational state variables relating to the graceful-restart
         mechanism on a per-AFI-SAFI basis";
       leaf received data for BGP-specific actions";
  }

  grouping bgp-actions-top {
         type boolean;
    description
           "This leaf indicates whether the neighbor advertised the
           ability to support graceful-restart
      "Top-level grouping for this AFI-SAFI"; BGP-specific actions";

    container bgp-actions {
      description
        "Top-level container for BGP-specific actions";

      container config {
        description
          "Configuration data for BGP-specific actions";

        uses bgp-actions-config;
      }
       leaf advertised

      container state {
         type boolean;

        config false;
        description
           "This leaf indicates whether the ability to support
           graceful-restart has been advertised
          "Operational state data for BGP-specific actions";

        uses bgp-actions-config;
        uses bgp-actions-state;
      }
      uses as-path-prepend-top;
      uses set-community-action-top;
      uses set-ext-community-action-top;
    }
  }

  augment "/rpol:routing-policy/rpol:policy-definitions/" +
    "rpol:policy-definition/rpol:statements/rpol:statement/" +
    "rpol:conditions" {
    description
      "BGP policy conditions added to the peer"; routing policy module";

    uses bgp-conditions-top;
  }

  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";

    uses bgp-actions-top;
  }

  // rpc statements

  // notification statements
}

    <CODE ENDS>

7.

10.  References

7.1.

10.1.  Normative references

   [RFC6020]  Bjorklund, M., Ed., "YANG - A Data Modeling Language for
              the Network Configuration Protocol (NETCONF)", RFC 6020,
              DOI 10.17487/RFC6020, October 2010,
              <http://www.rfc-editor.org/info/rfc6020>.

   [RFC6241]  Enns, R., Ed., Bjorklund, M., Ed., Schoenwaelder, J., Ed.,
              and A. Bierman, Ed., "Network Configuration Protocol
              (NETCONF)", RFC 6241, DOI 10.17487/RFC6241, June 2011,
              <http://www.rfc-editor.org/info/rfc6241>.

   [RFC4271]  Rekhter, Y., Ed., Li, T., Ed., and S. Hares, Ed., "A
              Border Gateway Protocol 4 (BGP-4)", RFC 4271,
              DOI 10.17487/RFC4271, January 2006,
              <http://www.rfc-editor.org/info/rfc4271>.

   [RFC1997]  Chandra, R., Traina, P., and T. Li, "BGP Communities
              Attribute", RFC 1997, DOI 10.17487/RFC1997, August 1996,
              <http://www.rfc-editor.org/info/rfc1997>.

   [RFC4456]  Bates, T., Chen, E., and R. Chandra, "BGP Route
              Reflection: An Alternative to Full Mesh Internal BGP
              (IBGP)", RFC 4456, DOI 10.17487/RFC4456, April 2006,
              <http://www.rfc-editor.org/info/rfc4456>.

   [RFC3065]  Traina, P., McPherson, D., and J. Scudder, "Autonomous
              System Confederations for BGP", RFC 3065,
              DOI 10.17487/
              RFC3065, 10.17487/RFC3065, February 2001,
              <http://www.rfc-editor.org/info/rfc3065>.

   [RFC2439]  Villamizar, C., Chandra, R., and R. Govindan, "BGP Route
              Flap Damping", RFC 2439, DOI 10.17487/RFC2439, November
              1998, <http://www.rfc-editor.org/info/rfc2439>.

   [RFC4724]  Sangli, S., Chen, E., Fernando, R., Scudder, J., and Y.
              Rekhter, "Graceful Restart Mechanism for BGP", RFC 4724,
              DOI 10.17487/RFC4724, January 2007,
              <http://www.rfc-editor.org/info/rfc4724>.

   [RFC6811]  Mohapatra, P., Scudder, J., Ward, D., Bush, R., and R.
              Austein, "BGP Prefix Origin Validation", RFC 6811,
              DOI 10.17487/RFC6811, January 2013,
              <http://www.rfc-editor.org/info/rfc6811>.

   [RFC4760]  Bates, T., Chandra, R., Katz, D., and Y. Rekhter,
              "Multiprotocol Extensions for BGP-4", RFC 4760,
              DOI 10.17487/RFC4760, January 2007,
              <http://www.rfc-editor.org/info/rfc4760>.

   [RFC6991]  Schoenwaelder, J., Ed., "Common YANG Data Types",
              RFC 6991, DOI 10.17487/RFC6991, July 2013,
              <http://www.rfc-editor.org/info/rfc6991>.

   [RFC3688]  Mealling, M., "The IETF XML Registry", BCP 81, RFC 3688,
              DOI 10.17487/RFC3688, January 2004,
              <http://www.rfc-editor.org/info/rfc3688>.

7.2.

10.2.  Informative references

   [I-D.shaikh-rtgwg-policy-model]

   [I-D.ietf-rtgwg-policy-model]
              Shaikh, A., Shakir, R., D'Souza, K., and C. Chase,
              "Routing Policy Configuration Model for Service Provider
              Networks", draft-shaikh-rtgwg-policy-model-01 draft-ietf-rtgwg-policy-model-01 (work in
              progress), July 2015. April 2016.

   [I-D.openconfig-netmod-opstate]
              Shakir, R., Shaikh, A., and M. Hines, "Consistent Modeling
              of Operational State Data in YANG", draft-openconfig-
              netmod-opstate-01 (work in progress), July 2015.

   [I-D.ietf-netmod-routing-cfg]
              Lhotka, L. and A. Lindem, "A YANG Data Model for Routing
              Management", draft-ietf-netmod-routing-cfg-20 draft-ietf-netmod-routing-cfg-22 (work in
              progress), October 2015. July 2016.

   [I-D.rtgyangdt-rtgwg-device-model]
              Lindem, A., Berger, L., Bogdanovic, D., and C. Hopps,
              "Network Device YANG Organizational Model", Models", draft-
              rtgyangdt-rtgwg-device-model-01
              rtgyangdt-rtgwg-device-model-04 (work in progress), May
              2016.

   [I-D.openconfig-rtgwg-network-instance]
              Shakir, R., "A Data Model for Network Instances in Service
              Provider Networks", draft-openconfig-rtgwg-network-
              instance-01 (work in progress),
              September November 2015.

   [I-D.talwar-rtgwg-grpc-use-cases]
              Specification, g., Kolhe, J., Shaikh, A., and J. George,
              "Use cases for gRPC in network management", draft-talwar-
              rtgwg-grpc-use-cases-00 (work in progress), July 2016.

Appendix A.  Acknowledgements

   The authors are grateful for valuable contributions to this document
   and the associated models from: Ebben Aires, Pavan Beeram, Chris
   Chase, Ed Crabbe, Luyuan Fang, Bill Fenner, Akshay Gattani, Josh
   George, Vijay Gill, Matt John, Jeff Haas, Dhanendra Jain, Acee
   Lindem, Ina Minei, Carl Moberg, Ashok Narayanan, Einar Nilsen-Nygaard, Nilsen-
   Nygaard, Adam Simpson, Puneet Sood, Jason Sterne, Jeff Tantsura, Jim
   Uttaro, and Gunter Vandevelde.

Appendix B.  Change summary

B.1.  Changes between revisions -01 and -02

   o  Refactored BGP model such that it is comprised of multiple sub-
      modules rather than independent modules.

   o  Remove the need for self-augmentation of the BGP model to allow
      the ability to import the model in wider structures more easily.

   o  Added new operational state values for BGP session established
      transitions and last-established timestamp.  Also deprecated
      uptime operational state leaf.

   o  Added ability to select eligible paths for add-paths based on a
      policy.

B.2.  Changes between revisions -00 and -01

   o  Updated module namespaces to reflect IETF standard namespace.

   o  Updated module filenames with ietf- prefix per RFC 6087
      guidelines.

Authors' Addresses

   Anees Shaikh (editor)
   Google
   1600 Amphitheatre Pkwy
   Mountain View, CA  94043
   US

   Email: aashaikh@google.com

   Rob Shakir (editor)
   Jive Communications, Inc.
   1275 West 1600 North, Suite 100
   Orem, UT  84057

   Email: rjs@rob.sh
   Keyur Patel (editor)
   Cisco
   170 W. Tasman Drive
   San Jose, CA  95134
   USA

   Email: keyupate@cisco.com

   Susan Hares (editor)
   Huawei
   7453 Hickory Hill
   Saline, MI  48176
   USA

   Email: shares@ndzh.com

   Kevin D'Souza
   AT&T
   200 S. Laurel Ave
   Middletown, NJ
   US

   Email: kd6913@att.com

   Deepak Bansal
   Microsoft
   205 108th Ave. NE, Suite 400
   Bellevue, WA
   US

   Email: dbansal@microsoft.com

   Alexander Clemm
   Cisco
   170 W. Tasman Drive
   San Jose, CA  95134
   USA

   Email: alex@cisco.com
   Aleksandr Zhdankin
   Cisco
   170 W. Tasman Drive
   San Jose, CA  95134
   USA

   Email: azhdanki@cisco.com

   Mahesh Jethanandani
   Ciena
   1741 Technology
   Cisco Systems, Inc
   180 W. Tasman Drive
   San Jose, CA  95110  95134
   USA

   Phone: +1 408.526.8763
   Email: mjethanandani@gmail.com

   Xyfeng Liu
   Ericsson
   1595 Spring Hill Road, Suite 500
   Vienna, VA  22182
   USA

   Email: xufeng.liu@ericsson.com