clicon / clixon

YANG-based toolchain including NETCONF and RESTCONF interfaces and an interactive CLI
http://www.clicon.org/
Other
215 stars 72 forks source link

OpenConfig BGP afi-safi and when condition issues #249

Closed pheller closed 3 years ago

pheller commented 3 years ago

Hello,

I have loaded the OpenConfig BGP model into Clixon and it works mostly fine.

However, while working on adding in a backend statedata callback, I noticed that when a particular afi-safi is configured, all specific family details are shown even though there is a when within each family-specific container.

It then occurred to me that I may not have added all the necessary configuration to satisfy the when.

Here's a good example of what I add, the odd validation failure, and what I see in the config:

clixon> set bgp neighbors neighbor 10.0.0.1 afi-safis afi-safi oc-bgp-types:IPV6_UNICAST config afi-safi-name oc-bgp-types:IPV6_UNICAST
clixon> validate
Jul 26 22:29:20: Validate failed. Edit and try again or discard changes: application operation-failed Failed WHEN condition of ipv6-unicast in module openconfig-bgp

An excerpt from the candidate configuration showing that it's picking up defaults from every address family:

bgp neighbors neighbor 10.0.0.1 afi-safis afi-safi oc-bgp-types:IPV6_UNICAST
bgp neighbors neighbor 10.0.0.1 afi-safis afi-safi oc-bgp-types:IPV6_UNICAST config afi-safi-name oc-bgp-types:IPV6_UNICAST
bgp neighbors neighbor 10.0.0.1 afi-safis afi-safi oc-bgp-types:IPV6_UNICAST config enabled false
bgp neighbors neighbor 10.0.0.1 afi-safis afi-safi oc-bgp-types:IPV6_UNICAST graceful-restart config enabled false
bgp neighbors neighbor 10.0.0.1 afi-safis afi-safi oc-bgp-types:IPV6_UNICAST add-paths config receive false
bgp neighbors neighbor 10.0.0.1 afi-safis afi-safi oc-bgp-types:IPV6_UNICAST add-paths config send false
bgp neighbors neighbor 10.0.0.1 afi-safis afi-safi oc-bgp-types:IPV6_UNICAST apply-policy config default-import-policy REJECT_ROUTE
bgp neighbors neighbor 10.0.0.1 afi-safis afi-safi oc-bgp-types:IPV6_UNICAST apply-policy config default-export-policy REJECT_ROUTE
bgp neighbors neighbor 10.0.0.1 afi-safis afi-safi oc-bgp-types:IPV6_UNICAST ipv4-unicast prefix-limit config prevent-teardown false
bgp neighbors neighbor 10.0.0.1 afi-safis afi-safi oc-bgp-types:IPV6_UNICAST ipv4-unicast config send-default-route false
bgp neighbors neighbor 10.0.0.1 afi-safis afi-safi oc-bgp-types:IPV6_UNICAST ipv6-unicast prefix-limit config prevent-teardown false
bgp neighbors neighbor 10.0.0.1 afi-safis afi-safi oc-bgp-types:IPV6_UNICAST ipv6-unicast config send-default-route false
bgp neighbors neighbor 10.0.0.1 afi-safis afi-safi oc-bgp-types:IPV6_UNICAST ipv4-labeled-unicast prefix-limit config prevent-teardown false
bgp neighbors neighbor 10.0.0.1 afi-safis afi-safi oc-bgp-types:IPV6_UNICAST ipv6-labeled-unicast prefix-limit config prevent-teardown false
bgp neighbors neighbor 10.0.0.1 afi-safis afi-safi oc-bgp-types:IPV6_UNICAST l3vpn-ipv4-unicast prefix-limit config prevent-teardown false
bgp neighbors neighbor 10.0.0.1 afi-safis afi-safi oc-bgp-types:IPV6_UNICAST l3vpn-ipv6-unicast prefix-limit config prevent-teardown false
bgp neighbors neighbor 10.0.0.1 afi-safis afi-safi oc-bgp-types:IPV6_UNICAST l3vpn-ipv4-multicast prefix-limit config prevent-teardown false
bgp neighbors neighbor 10.0.0.1 afi-safis afi-safi oc-bgp-types:IPV6_UNICAST l3vpn-ipv6-multicast prefix-limit config prevent-teardown false
bgp neighbors neighbor 10.0.0.1 afi-safis afi-safi oc-bgp-types:IPV6_UNICAST l2vpn-vpls prefix-limit config prevent-teardown false
bgp neighbors neighbor 10.0.0.1 afi-safis afi-safi oc-bgp-types:IPV6_UNICAST l2vpn-evpn prefix-limit config prevent-teardown false

And, from the yang model, you can see that these different address families should be conditioned on the afi-safi-name matching: (from public/release/models/bgp/openconfig-bgp-common-multiprotocol.yang)

  grouping bgp-common-mp-ipv4-labeled-unicast-group {
    description
      "Group for IPv4 Labeled Unicast configuration options";

    container ipv4-labeled-unicast {
      when "../afi-safi-name = 'oc-bgp-types:IPV4_LABELED_UNICAST'" {
        description
          "Include this container for IPv4 Labeled Unicast specific
          configuration";
      }
     ...

Let me know if I can provide any more data that might be helpful.

pheller commented 3 years ago

In reviewing the structure here (uses / grouping, when), I wonder if this might be the same as described in https://github.com/clicon/clixon/issues/218.

olofhagsand commented 3 years ago

Confirmed, that ipv6-unicast clause should not exist when address is IPV4_UNICAST. Problem is, default values are generated without considering WHEN statement. More closely I see that WHEN statements are only considered when child to augment and uses, not when (as is the case here) for containers.

pheller commented 3 years ago

Fix appears to work as intended. Thanks!