Subject: [netmod] Question about condition in must-statement

From: Gerhard Muenz <[email-masked]>
Date: Fri, 21 Aug 2009 17:08:30 +0200

Hi,

In PSAMP, there are packet filters using hash functions which are
applied to specific header or payload bits. Which bits are used as input
of the hash function is specified with an octet string. This octet
string is applied like a mask to the header or payload section, however
the zero bits will be removed (not kept).

Currently, the YANG part to configure such a filter looks like this
(which hopefully can be understood with the descriptions):

      container filterHash {
        leaf ipVersion {
          type inet:ip-version;
          description "IP version of packets to be selected.";
        }
        leaf headerBits {
          type binary;
          must "not(addrType = 'ipv4') or not(addrType = 'ipv6')
            or (../addrType = 'ipv4' and string-length() = 20)
            or (../addrType = 'ipv6' and string-length() = 40)";
          description "This parameter specifies an octet string
            defining the IP header bits used as input to the hash
            function, starting with the first header octet.
            The length of the octet string must be 20 if addrType is
            'ipv4', and 40 if addrType is 'ipv6'.";
        }
        leaf payloadBytes {
          type uint32;
          units octets;
          default 0;
          description "Number of IP payload octets used as input to
            the hash function, counted from the beginning of the
            payload section. If the IP payload is shorter than the
            configured value, all payload octets are used as
            input.";
        }
        leaf payloadBits {
          type binary;
          must "string-length() = ../payloadBytes";
          description "This parameter specifies an octet string
            defining the IP payload bits used as input to the hash
            function, starting with the first payload octet.
            If this parameter is configured, the length of the octet
            string must equal the maximum number of payload octets
            specified by payloadBytes.";
        }
        ...
      }

I have three questions:

1) Should I use binary or string for headerBits and payloadBits?

2) Can I restrict the length of a binary leaf with string-length()?

3) If yes, does string-length() return the length in base64 symbols or
in octets?

Thanks,
Gerhard

---

From: Juergen Schoenwaelder <[email-masked]>
Date: Fri, 21 Aug 2009 21:53:22 +0200

> 1) Should I use binary or string for headerBits and payloadBits?

What speaks against binary for binary data?
 
> 2) Can I restrict the length of a binary leaf with string-length()?

The xpath expression is evaluated on the canonical stringified value
representation (section 7.5.3 of the YANG ID), which for the binary
YANG type would be a base64 encoding. So you have to be careful.

> 3) If yes, does string-length() return the length in base64 symbols or

See above - it will be the number of characters needed for the base64
encoding. Note that there is always a description clause; sometimes it
might be simpler to spell things out in written words. ;-)

/js

PS: We prefer the header-bits and payload-bits writing style in YANG
    models so far.

-- 
Juergen Schoenwaelder           Jacobs University Bremen gGmbH
Phone: +49 421 200 3587         Campus Ring 1, 28759 Bremen, Germany
Fax:   +49 421 200 3103         <http://www.jacobs-university.de/>

---

From: Andy Bierman <[email-masked]>
Date: Fri, 21 Aug 2009 13:01:52 -0700

> What speaks against binary for binary data?

indeed -- this would be a good test for the binary data type.
It is so user-unfriendly that it will be interesting to
see how the support for the binary built-in type varies across tools.
Entering base64 by hand or reading it raw is beyond unlikely.

> PS: We prefer the header-bits and payload-bits writing style in YANG

Andy