cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
180
Views
10
Helpful
2
Replies
Highlighted
Cisco Employee

Conditional mandatory leaf

Hi All,

 

I'm developing a service and one of the requirements is:

The primary IP address and mask is mandatory.

If the user entered the secondary IP address, then the secondary mask must be provided also.

 

I'm trying to implement this requirement using "when" statement but with no success. I don't know how can I do that.

 

The yang snippet:

list bvi {
    key id;

    uses ncs:service-data;
    ncs:servicepoint "bvi";

    leaf id {
        type int32 {
            range "1..65535";
        }
        mandatory true;
    }

    leaf device {
        type leafref {
            path "/ncs:devices/ncs:device/ncs:name";
        }
        mandatory true;
    }

    leaf-list vrf-name {
        type leafref {
            path "deref(../device)/../ncs:config/ios:vrf/ios:vrf-list/ios:name";
        }
    }

    leaf mtu {
        type int32 {
            range "1500..9212";
        }
    }

    leaf primary-ipv4-address {
        type inet:ipv4-address;
        mandatory true;
    }

    leaf primary-mask {
        type inet:ipv4-address;
        mandatory true;
    }

    leaf secondary-ipv4-address {
        type inet:ipv4-address;
    }

    when "deref(../secondary-ipv4-address) != ''";
    leaf secondary-mask {
        type inet:ipv4-address;
        mandatory true;
    }

    leaf ipv6-address {
        type inet:ipv6-address;
        mandatory true;
    }

    leaf mac-address {
        type string;
        default "1001.1111.1111";
        
    }
}

Can someone help me?

 

Thanks in advance!

 

Luciano Nunes

lnunesdo@cisco.com

 

2 ACCEPTED SOLUTIONS

Accepted Solutions
Highlighted
Cisco Employee

You were close.

 

Try:

    leaf secondary-mask {
when ../secondary-ipv4-address; type inet:ipv4-address; mandatory true; }  

View solution in original post

Highlighted
Cisco Employee

Hi Luciano,

You are pretty close, you need to move the when inside of the leaf that you are trying to control.

Here is a example - I just check for existence of sec-address:

 

      leaf address {

        type inet:ipv4-address {

          tailf:info "A.B.C.D;;IP address";

        }

        mandatory true;

      }

      leaf mask {

        type inet:ipv4-address {

          tailf:info "A.B.C.D;;IP subnet mask";

        }

        mandatory true;

      }

      leaf sec-address {

        type inet:ipv4-address {

          tailf:info "A.B.C.D;;IP address";

        }

      }

      leaf sec-mask {

        when "../sec-address";

        type inet:ipv4-address {

          tailf:info "A.B.C.D;;IP subnet mask";

        }

        mandatory true;

      }

without specitying sec-addr, primary is successful:

admin@ncs% set interface-mv if1 device iosxr-0 intf-iosxr GigabitEthernet 0/0/0/0 address 10.0.1.0 mask 255.255.255.0
[ok][2020-08-05 15:17:12]

If you specify sec-address, the sec-mask is mandatory:
admin@ncs% set interface-mv if1 device iosxr-0 intf-iosxr GigabitEthernet 0/0/0/0 address 10.0.1.0 mask 255.255.255.0 sec-address
Possible completions:
<A.B.C.D> - IP address
admin@ncs% set interface-mv if1 device iosxr-0 intf-iosxr GigabitEthernet 0/0/0/0 address 10.0.1.0 mask 255.255.255.0 sec-address 10.0.2.0 sec-mask
Possible completions:
<A.B.C.D> - IP subnet mask
admin@ncs% set interface-mv if1 device iosxr-0 intf-iosxr GigabitEthernet 0/0/0/0 address 10.0.1.0 mask 255.255.255.0 sec-address 10.0.2.0 sec-mask
(<A.B.C.D>): 255.255.255.0
[ok][2020-08-05 15:17:54]

View solution in original post

2 REPLIES 2
Highlighted
Cisco Employee

You were close.

 

Try:

    leaf secondary-mask {
when ../secondary-ipv4-address; type inet:ipv4-address; mandatory true; }  

View solution in original post

Highlighted
Cisco Employee

Hi Luciano,

You are pretty close, you need to move the when inside of the leaf that you are trying to control.

Here is a example - I just check for existence of sec-address:

 

      leaf address {

        type inet:ipv4-address {

          tailf:info "A.B.C.D;;IP address";

        }

        mandatory true;

      }

      leaf mask {

        type inet:ipv4-address {

          tailf:info "A.B.C.D;;IP subnet mask";

        }

        mandatory true;

      }

      leaf sec-address {

        type inet:ipv4-address {

          tailf:info "A.B.C.D;;IP address";

        }

      }

      leaf sec-mask {

        when "../sec-address";

        type inet:ipv4-address {

          tailf:info "A.B.C.D;;IP subnet mask";

        }

        mandatory true;

      }

without specitying sec-addr, primary is successful:

admin@ncs% set interface-mv if1 device iosxr-0 intf-iosxr GigabitEthernet 0/0/0/0 address 10.0.1.0 mask 255.255.255.0
[ok][2020-08-05 15:17:12]

If you specify sec-address, the sec-mask is mandatory:
admin@ncs% set interface-mv if1 device iosxr-0 intf-iosxr GigabitEthernet 0/0/0/0 address 10.0.1.0 mask 255.255.255.0 sec-address
Possible completions:
<A.B.C.D> - IP address
admin@ncs% set interface-mv if1 device iosxr-0 intf-iosxr GigabitEthernet 0/0/0/0 address 10.0.1.0 mask 255.255.255.0 sec-address 10.0.2.0 sec-mask
Possible completions:
<A.B.C.D> - IP subnet mask
admin@ncs% set interface-mv if1 device iosxr-0 intf-iosxr GigabitEthernet 0/0/0/0 address 10.0.1.0 mask 255.255.255.0 sec-address 10.0.2.0 sec-mask
(<A.B.C.D>): 255.255.255.0
[ok][2020-08-05 15:17:54]

View solution in original post