ConfD User Community

Lists should be disjoint based on the values of the leaf

There are 2 lists.

 list ip-v4 {
                leaf ip {
                    type inet:ipv4-address;
                }
                leaf port {
                    type inet:port-number;
                }
}
 list ip-v6 {
                leaf ip {
                    type inet:ipv6-address;
                }
                leaf port {
                    type inet:port-number;
                }
}

I want to have ports in the list ip-v4 and ip-v6 as disjoint.

Example:

1. Valid case:

ip-v4 = [{ip:1.1.1.1, port:2000 },{ip:1.1.1.2, port:2001}]
ip-v6 = [{ip:1::1, port:2002},{ip:1::2, port:2003}]

Reason: 
[2000,2001] and [2002,2003] are disjoint

2. Invalid case:

ip-v4 = [{ip:1.1.1.1, port:2000 },{ip:1.1.1.2, port:2001}]
ip-v6 = [{ip:1::1, port:2000},{ip:1::2, port:2003}]

Reason: 
[2000,2001] and [2000,2003] are not disjoint

Can someone help me to solve this?

I found the solution.

 list ip-v4 {
                leaf ip {
                    type inet:ipv4-address;
                }
                leaf port {
                    type inet:port-number;
                }
}
 list ip-v6 {
                leaf ip {
                    type inet:ipv6-address;
                }
                leaf port {
                    type inet:port-number;
                    must "count(../../ip-v4) = 0 or count(../../ip-v4[port=current()]) = 0" {
                               error-message
                               "ip-v4 port and ip-v6 port should be different.";
                    }
                }
}

you can save some performance i guess by simplifying the must statement to:

must "not(../../ip-v4[port=current()]) {
   ...
}

(~ there is no record in ip-v4 list that has current port value)

1 Like